Price Oracle
TWAP price oracle interface backed by Uniswap V3 / HyperSwap / Kumbaya.
The Oracle contract provides time-weighted average price (TWAP) feeds for all token pairs used by SIR Protocol. It interfaces with the chain's native Uniswap V3-style DEX and automatically selects the most liquid fee tier for each pair.
The Oracle is fully permissionless โ anyone can initialize new token pairs or register new fee tiers.
Chain differences:
DEX backend: Uniswap V3 (Ethereum) / HyperSwap (HyperEVM) / Kumbaya (MegaETH)
TWAP delta: 5 minutes on Ethereum vs 1 minute on HyperEVM/MegaETH
Fee tier update cadence: 23 hours on Ethereum vs 1 hour on HyperEVM/MegaETH
TWAP duration: 30 minutes (same on all chains)
getPrice
getPriceReturns the TWAP price for a collateral-debt token pair as a Q21.42 fixed-point tick value. This is a view function that does not modify state.
function getPrice(
address collateralToken,
address debtToken
) external view returns (int64)collateralToken
address
The collateral token address
debtToken
address
The debt token address
Returns: int64 โ TWAP price as a Q21.42 fixed-point tick. The sign convention ensures the price represents collateral/debt.
Reverts with
OracleNotInitializedif the token pair has not been initialized.
updateOracleState
updateOracleStateUpdates the oracle price for a token pair and stores it so subsequent calls in the same block don't need to query the DEX again. Also periodically checks if a better fee tier is available.
collateralToken
address
The collateral token address
debtToken
address
The debt token address
Returns:
tickPriceX42โ updated TWAP price (Q21.42 fixed point)uniswapPoolAddressโ address of the DEX pool currently being used
This function is called internally by the Vault during mints/burns. External callers (e.g., keepers) can call it to keep prices fresh.
initialize
initializeInitializes the oracle for a token pair. Permissionless โ anyone can call it. Scans all known fee tiers to find the most liquid pool and sets up the TWAP.
tokenA
address
First token address
tokenB
address
Second token address (order does not matter)
No-op if already initialized (does not revert). Reverts with
NoUniswapPoolif no pool exists for any fee tier.
uniswapFeeTierOf
uniswapFeeTierOfReturns the fee tier currently being used as the oracle source for a token pair.
tokenA
address
First token address
tokenB
address
Second token address (order does not matter)
Returns: uint24 โ fee tier in hundredths of a basis point (e.g., 3000 = 0.30%).
getUniswapFeeTiers
getUniswapFeeTiersReturns all fee tiers known to the Oracle โ the 4 default tiers plus any custom ones that have been registered.
Returns: Array of UniswapFeeTier structs:
Default fee tiers: 100 (0.01%), 500 (0.05%), 3000 (0.30%), 10000 (1.00%).
newUniswapFeeTier
newUniswapFeeTierRegisters a new DEX fee tier so the Oracle can consider it when selecting the best pool. Permissionless โ anyone can call it. The fee tier must exist in the DEX factory.
fee
uint24
The fee tier to register (must exist in the DEX factory)
Maximum of 9 total fee tiers (4 default + 5 custom). Reverts if the fee tier already exists or if the limit is reached.
state
stateReturns the full oracle state for a token pair. Tokens must be provided in lexicographic order (token0 < token1).
token0
address
Lower address token
token1
address
Higher address token
Returns: OracleState:
Constants
TWAP_DURATION
30 minutes
Duration of the TWAP window (all chains)
UNISWAPV3_FACTORY
varies
Address of the DEX factory
POOL_INIT_CODE_HASH
varies
Pool creation code hash for address computation
Last updated