OpenPayPriceFeed
TheOpenPayPriceFeed contract aggregates price data from Chainlink decentralized oracles to convert between USD and token amounts. It includes stablecoin shortcuts and staleness protection.
Address (BSC Testnet): 0x1f34e070D4BB1eD3AaF37D8E3297b0a9A12a3399
Explorer: View on BscScan
How It Works
Key Design Decisions
Stablecoin Shortcut
Stablecoin Shortcut
Tokens marked as stablecoins (USDT, USDC) skip the oracle call entirely and return a fixed price of
$1.00 (represented as 100000000 with 8 decimals). This saves gas and avoids unnecessary oracle dependencies.Staleness Protection
Staleness Protection
The contract rejects price data older than the
stalenessThreshold (default: 3600 seconds / 1 hour). If the Chainlink oracle has not updated within this window, all price queries revert with “Stale price”.Native Token Support
Native Token Support
BNB (native token,
address(0)) uses a dedicated nativeFeed Chainlink oracle rather than the token config mapping. This is set separately via setNativeFeed().Read Functions
getPrice
Get the current USD price and decimal precision for a token.
Behavior:
- For stablecoins: returns
(100000000, 8)— equivalent to $1.00 - For
address(0): queries thenativeFeedChainlink oracle - For other tokens: queries the token-specific Chainlink feed
getAmountInToken
Convert a USD amount to the equivalent token amount at the current price.
Example: “How many BNB tokens do I need to pay $25?“
getAmountInUsd
Convert a token amount to its USD equivalent at the current price.
Example: “How much USD is 0.5 BNB worth?”
Token Configuration
configureToken
Register a token with its Chainlink price feed. Owner only.
Example configurations: