MAP Protocol v2 accurately estimates gas fees for each chain to ensure cross-chain transactions execute successfully without overcharging users. This document covers gas calculation, caching, oracles, and fee update mechanisms.
EVM Chain Gas Calculation
Gas Data Collection
Maintainer nodes obtain gas data by monitoring blocks, extracting the base fee and priority fees from block transactions.
Priority Fee Calculation
The system calculates a reasonable priority fee using the 25th percentile of priority fees from block transactions. This approach avoids outliers while ensuring transactions get included. The final gas price combines the base fee with the selected priority fee, with a minimum threshold applied.
Gas Cache Mechanism
To smooth gas price fluctuations, the system maintains a rolling cache of recent gas prices. The cache size is configurable via the gas_cache_blocks parameter, keeping only the most recent entries.
Transaction Gas Calculation
When sending transactions, the system uses statistical analysis:
Calculate the mean of cached gas prices
Calculate the standard deviation
Set gas fee cap = mean + 3 × standard deviation
Calculate tip cap as a percentage of fee cap
Minimum gas price per chain
Number of blocks for gas cache
Bitcoin Chain Fee Calculation
Fee Data Retrieval
The system retrieves network fee information including minimum relay fee and block average fee rate from Bitcoin RPC calls.
Fee Rate Calculation
The fee rate is calculated to ensure the estimated transaction fee meets the network minimum relay fee requirement. If the initial estimate falls short, the rate is adjusted upward. A minimum sats-per-vbyte threshold is also enforced.
Transaction Size Estimation
Bitcoin transaction sizes are estimated based on:
The system estimates sizes before UTXO selection to predict fees accurately.
Oracle Architecture
Reporting Process
Each Maintainer observes gas prices on external chains
Maintainers periodically report observations to GasOracle contract
Contract aggregates reports, using median value for consensus
Aggregated gas prices stored on-chain for cross-chain fee calculation
Aggregation Method
The oracle uses median aggregation to resist manipulation:
Collects reports from multiple Maintainers
Takes median as the consensus price
Updates only when sufficient reports received
Cross-chain Fee Calculation
Estimated execution cost on target chain
Fee for protocol operation and LP rewards
Safety margin for gas price fluctuations
Calculation Flow
Cross-chain fees are deducted from the transfer amount:
User sends X tokens on source chain
Fee F is calculated based on target chain costs
User receives (X - F) tokens on target chain
Gas Price Updates
Update Triggers
Regular updates every N blocks
Update when price changes > threshold
Emergency updates by governance
Staleness Protection
The system includes staleness checks:
Gas prices have a maximum age
Stale prices trigger warnings or fallback to defaults
Critical operations may be paused if gas data too old
Chain-specific Considerations
Support EIP-1559 fee model (base fee + priority fee)
Dynamic base fee adjustment based on network congestion
Priority fee for transaction ordering preference
Bitcoin-like Chains
Fee rate in satoshis per virtual byte
UTXO-based transaction size estimation
Replace-By-Fee (RBF) support for stuck transactions
Each chain type may have unique gas/fee models:
Compute units + priority fee
Gas units with conversion rate
Gas units with forwarding fees
Configuration Parameters
Parameter
Description
Default
Blocks to cache for averaging