30-Decimal Precision System

Precision Architecture

The IFA Oracle implements a sophisticated 30-decimal precision system for maximum financial accuracy:
Standard Precision:    18 decimals (typical ERC-20)
IFA Oracle Precision:  30 decimals (enhanced financial precision)
Precision Gain:        12 additional decimal places = 10^12 improvement

Why 30 Decimals?

  • Micro-transactions: Supports fractional cent transactions without rounding errors
  • High-value Operations: Maintains precision for large institutional transactions
  • Cross-rate Accuracy: Prevents compounding errors in multi-hop calculations
  • DeFi Compatibility: Enables precise collateralization ratios and liquidation thresholds

Precision Examples

// BTC/USD: $45,123.456789012345678901234567890
// Traditional: $45,123.456789012345678901 (18 decimals)
// IFA Oracle: $45,123.456789012345678901234567890 (30 decimals)

// Micro-payment: $0.000000000000000000000001 (1 yocto-dollar)
// Still representable with 6 decimal places to spare

Gas Optimization

Function Gas Costs (Ethereum Mainnet)

FunctionSingle CallBatch (10 assets)Optimization
getAssetInfo()~2,500 gasN/AMinimal reads
getAssetsInfo()N/A~17,500 gas30% batch savings
getPairById()~5,000 gasN/AIn-memory calculation
getPairsbyIdForward()N/A~35,000 gas25% batch savings
submitPriceFeed() (1 asset)~45,000 gasN/AStorage update
submitPriceFeed() (10 assets)N/A~310,000 gas31% batch savings

Optimization Strategies

For Relayers:
// Batch submissions for gas efficiency
bytes32[] memory assetIds = [keccak256("BTC"), keccak256("ETH"), keccak256("USDC")];
PriceFeed[] memory prices = [btcPrice, ethPrice, usdcPrice];
verifier.submitPriceFeed(assetIds, prices); // Single transaction
For DApp Consumers:
// Batch queries save ~30% gas
bytes32[] memory assets = [keccak256("BTC"), keccak256("ETH")];
(PriceFeed[] memory prices, bool[] memory exists) = oracle.getAssetsInfo(assets);

// Parallel pair calculations
bytes32[] memory assets0 = [keccak256("BTC"), keccak256("ETH")];
bytes32[] memory assets1 = [keccak256("USDC"), keccak256("USDC")];
DerivedPair[] memory pairs = oracle.getPairsbyIdForward(assets0, assets1);

Performance Characteristics

Update Frequency

  • Target Frequency: 60-second intervals for major assets
  • Maximum Staleness: Configurable per integration (typically 300 seconds)
  • Emergency Updates: Sub-minute updates during high volatility
  • Network Adaptation: Frequency adjusts based on network congestion

Calculation Performance

Single Exchange Rate:     ~5,000 gas (~0.1ms computation)
Batch (10 pairs):        ~35,000 gas (~0.7ms computation)  
Precision Operations:     No performance penalty vs 18-decimal
Storage Efficiency:       Optimized layout minimizes slot usage

Scaling Considerations

  • Read Operations: Linear scaling with number of assets
  • Batch Operations: Sub-linear scaling due to fixed costs amortization
  • Storage Growth: O(n) where n = number of supported assets
  • Network Impact: Minimal - primarily read-heavy workload

Precision Trade-offs

Benefits

Maximum Accuracy: Eliminates rounding errors in financial calculations
Composability: Enables accurate multi-hop exchange rate calculations
Future-proof: Supports micro-payments and high-value transactions
DeFi Integration: Perfect precision for lending, AMM, and derivatives protocols

Considerations

⚠️ Gas Cost: Slightly higher gas costs for arithmetic operations
⚠️ Integration Complexity: Requires careful decimal handling in consumer contracts
⚠️ Display Formatting: UI layers need appropriate decimal place handling

Best Practice Integration

contract ConsumerExample {
    IIfaPriceFeed oracle;
    
    function getAdjustedPrice(bytes32 assetId, uint8 targetDecimals) 
        external view returns (uint256) {
        (PriceFeed memory price, bool exists) = oracle.getAssetInfo(assetId);
        require(exists, "Asset not found");
        
        // Safe decimal adjustment
        if (price.decimal >= 0) {
            // Positive decimal: scale down
            return price.price / (10 ** uint256(price.decimal - int256(targetDecimals)));
        } else {
            // Negative decimal: scale up  
            return price.price * (10 ** uint256(int256(targetDecimals) - price.decimal));
        }
    }
}