Problem
Users don't know gas costs before executing contract operations. Need accurate gas estimation for tag registration, deposits, swaps, and withdrawals.
Proposed Solution
Build gas estimation service that simulates contract calls and returns accurate gas estimates with current prices.
Technical Implementation
New Files:
contracts/solidity_contract/src/GasEstimator.sol - Gas estimation helper
contracts/solidity_contract/test/GasEstimator.t.sol - Test suite
backend/services/ContractGasEstimator.js - Gas estimation service
backend/controllers/gasEstimationController.js - Estimation endpoints
backend/routes/gasEstimation.js - Estimation routes
backend/tests/gasEstimation.test.js - Test suite
Modify:
backend/contracts/evm.js - Add gas estimation methods
backend/contracts/starknet.js - Add Starknet gas estimation
backend/services/FeeEstimationService.js - Use contract gas estimates
Gas Estimation Contract
contract GasEstimator {
function estimateRegisterTag(string memory tag) external returns (uint256) {
uint256 gasBefore = gasleft();
// Simulate tag registration
uint256 gasAfter = gasleft();
return gasBefore - gasAfter;
}
function estimateDeposit(string memory tag, uint256 amount) external returns (uint256) {
// Simulate deposit
}
function estimateSwap(address token, uint256 amount) external returns (uint256) {
// Simulate swap
}
}
API Endpoints
POST /api/gas/estimate/register-tag
Body: { tag: "@newuser", chain: "base" }
Response: {
gasLimit: 150000,
gasPrice: "15",
estimatedCost: {
eth: "0.00225",
usd: "5.40"
}
}
POST /api/gas/estimate/deposit
Body: { tag: "@john", amount: "100", token: "USDC", chain: "base" }
POST /api/gas/estimate/swap
Body: { fromToken: "ETH", toToken: "USDC", amount: "1", chain: "base" }
Acceptance Criteria
Priority
High - Important for user experience
Problem
Users don't know gas costs before executing contract operations. Need accurate gas estimation for tag registration, deposits, swaps, and withdrawals.
Proposed Solution
Build gas estimation service that simulates contract calls and returns accurate gas estimates with current prices.
Technical Implementation
New Files:
contracts/solidity_contract/src/GasEstimator.sol- Gas estimation helpercontracts/solidity_contract/test/GasEstimator.t.sol- Test suitebackend/services/ContractGasEstimator.js- Gas estimation servicebackend/controllers/gasEstimationController.js- Estimation endpointsbackend/routes/gasEstimation.js- Estimation routesbackend/tests/gasEstimation.test.js- Test suiteModify:
backend/contracts/evm.js- Add gas estimation methodsbackend/contracts/starknet.js- Add Starknet gas estimationbackend/services/FeeEstimationService.js- Use contract gas estimatesGas Estimation Contract
API Endpoints
Acceptance Criteria
Priority
High - Important for user experience