Architecture Overview
The Dynamic Fees module serves as a DenomResolver for the fee market module, providing asset price conversion capabilities to enable multi-asset fee payments. It maintains a registry of NTRN-denominated prices for supported assets.Core Functionality
DenomResolver Implementation
The module implements thefeemarkettypes.DenomResolver
interface with two key methods:
ConvertToDenom
Converts between NTRN and other supported denominations:- NTRN → Other Asset: Divide NTRN amount by the asset’s NTRN price
- Other Asset → NTRN: Multiply asset amount by the asset’s NTRN price
- Unknown Asset: Return
ErrUnknownDenom
error
ExtraDenoms
Returns the list of all supported denominations beyond NTRN:Parameter Management
NTRN Prices Registry
The module maintains a registry of asset prices denominated in NTRN:- DecCoin Array: Each entry represents an asset and its NTRN-denominated price
- Denom Field: Asset identifier (e.g., “uatom”, “uosmo”)
- Amount Field: Price ratio relative to NTRN as a decimal
Governance-Only Updates
Parameter updates are restricted to governance:Integration with Fee Market
Price Conversion Flow
- User Transaction: User submits transaction with gas price in any supported asset
- Fee Market Query: Fee market module queries Dynamic Fees for conversion
- Price Lookup: Dynamic Fees looks up the asset price in NTRN registry
- Conversion Calculation: Applies conversion formula based on direction
- Return Result: Fee market receives converted amount for processing
Supported Conversion Patterns
Pattern 1: Asset to NTRN
Pattern 2: NTRN to Asset
Error Handling
Unknown Denomination Error
When a requested denomination is not in the registry:- Asset not configured in NTRN prices registry
- Typo in denomination string
- Asset removed from supported list
- Fee market falls back to NTRN-only fees
- Transaction may fail if user only has unsupported assets
- Governance can add support through parameter updates
Authority Validation
Parameter updates validate the governance authority:State Management
Parameter Storage
Parameters are stored using the standard Cosmos SDK parameter store:No Additional State
The module maintains no additional state beyond parameters:- No historical price data
- No transaction records
- No user-specific information
- Stateless conversion operations
Security Considerations
Price Manipulation Resistance
Governance Control: Only governance can update prices, preventing individual manipulation Atomic Updates: All price changes happen atomically through governance proposals Community Oversight: Price updates require community approval through DAO votingPrecision and Accuracy
Decimal Precision: Usessdk.DecCoin
for high-precision decimal calculations
Overflow Protection: Cosmos SDK decimal types prevent arithmetic overflow
Rounding Behavior: Follows standard decimal rounding rules
Performance Characteristics
Conversion Efficiency
Linear Search: O(n) lookup where n is number of supported assets- Acceptable for small asset lists (< 100 assets)
- Could be optimized with maps for larger registries
- No network latency
- Deterministic execution time
Optimization Opportunities
Caching: Could cache price lookups for frequently accessed pairs Indexing: Could use maps instead of array iteration for O(1) lookupsBatch Operations: Could support batch conversions for efficiency
Future Considerations
Price Oracle Integration
Currently uses static governance-set prices. Future enhancements could include:- Oracle price feeds for dynamic pricing
- Time-weighted average prices (TWAP)
- Multi-source price aggregation
Enhanced Asset Support
- Automatic asset discovery from IBC channels
- Support for LP tokens and synthetic assets
- Cross-chain asset price relationships
Advanced Conversion Features
- Conversion fee mechanisms
- Slippage protection for large conversions
- Historical price tracking and analytics