An upgradeable Solidity contract for converting USD fees to native token (ETH/BNB/etc.) amounts using Chainlink price feeds.
The DecubateFeeConverter contract provides a secure and reliable way to convert USD-denominated
fees into their equivalent value in the blockchain's native currency. It uses Chainlink oracles for
accurate, real-time price data and includes safety mechanisms to prevent the use of stale or invalid
pricing information.
- Chainlink Oracle Integration: Fetches real-time price data from Chainlink aggregators
- UUPS Upgradeable: Implements the UUPS (Universal Upgradeable Proxy Standard) pattern for contract upgradeability
- Safety Checks: Multiple safeguards against stale prices, invalid data, and oracle failures
- Owner-Controlled: Price feed can be updated by the contract owner
- Gas Optimized: Efficient calculation logic with minimal gas consumption
- Price Feed: Chainlink
AggregatorV3Interfacefor fetching ETH/USD (or other native token/USD) prices - Ownership: Inherits from OpenZeppelin's
OwnableUpgradeable - Upgradeability: Implements
UUPSUpgradeablefor safe contract upgrades - Storage Gap: Reserved slots for future upgrades without storage collisions
Converts a USD fee amount to its equivalent in wei.
Parameters:
minFeeUSD: The fee amount in USD (scaled appropriately)
Returns:
uint256: The equivalent amount in wei, or 0 if conversion fails
Safety Mechanisms:
- Returns 0 if price feed is not set
- Returns 0 if USD fee is 0
- Returns 0 if oracle price is ≤ 0
- Returns 0 if price data is more than 24 hours old
- Returns 0 if
updatedAttimestamp is in the future (reorg protection) - Gracefully handles oracle call failures
Updates the Chainlink price feed address (owner only).
Parameters:
newPriceFeed: Address of the new Chainlink aggregator
Emits:
SetPriceFeedevent with previous and new price feed addresses
npm install- Node.js >= 24
- Hardhat v3
- OpenZeppelin Contracts Upgradeable
- Chainlink Contracts
{
"dependencies": {
"@openzeppelin/contracts-upgradeable": "^5.0.0",
"@chainlink/contracts": "^1.0.0"
},
"devDependencies": {
"hardhat": "^3.0.0",
"@nomicfoundation/hardhat-toolbox": "^5.0.0"
}
}- Deploy:
npx hardhat run ./scripts/deployFeeConverter.ts --network <network>- Verify:
npx hardhat ignition verify <deployment-id> --network <network>- Ethereum:
0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419(ETH/USD) - Arbitrum:
0x639Fe6ab55C921f74e7fac1ee960C0B6293ba612(ETH/USD) - Avalanche:
0x0A77230d17318075983913bC2145DB16C7366156(AVAX/USD) - Base:
0x71041dddad3595F9CEd3DcCFBe3D1F4b0a16Bb70(ETH/USD) - BSC:
0x0567F2323251f0Aab15c8dFb1967E4e8A7D42aeE(BNB/USD) - Linea:
0x3c6Cd9Cc7c7a4c2Cf5a82734CD249D7D593354dA(ETH/USD) - Polygon:
0xAB594600376Ec9fD91F8e885dADF0CE036862dE0(MATIC/USD)
- BSC Testnet:
0x2514895c72f50D8bd4B4F9b1110F0D6bD2c97526(BNB/USD)
See Chainlink Data Feeds for more addresses.
npx hardhat test- Oracle Dependency: Contract relies on Chainlink oracles; ensure price feeds are actively maintained
- 24-Hour Staleness Check: Prices older than 24 hours are rejected
- Upgrade Authorization: Only the owner can authorize upgrades
- Zero Address Checks: Price feed can be set to zero address to disable conversions
- Reorg Protection: Future timestamps are rejected to prevent reorg-based attacks
- Uses
uncheckedblocks where overflow is impossible - Minimal storage reads through caching
- Early returns to avoid unnecessary computations
GPL-3.0-or-later