Overview
S Balance
S Value
$0.00More Info
Private Name Tags
ContractCreator
Loading...
Loading
Similar Match Source Code This contract matches the deployed Bytecode of the Source Code for Contract 0x752433a3...E747CFaeb The constructor portion of the code might be different and could alter the actual behaviour of the contract
Contract Name:
PoolOracle
Compiler Version
v0.8.28+commit.7893614a
Optimization Enabled:
Yes with 999999 runs
Other Settings:
paris EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT pragma solidity 0.8.28; import "../interfaces/IPool.sol"; /** * @title PoolOracle * @notice Provides TWAP price consultations for a liquidity pool (pair) using a new Pair implementation. * @dev This contract reads observations from the pool to compute a time-weighted average price (TWAP). * It also allows updating the pool state by calling sync. */ contract PoolOracle { // The two tokens in the pair. address public token0; address public token1; // The liquidity pool (pair) from which the oracle reads price data. IPool public pair; /** * @notice Initializes the PoolOracle with the given pair. * @param _pair The liquidity pool contract. */ constructor(IPool _pair) { pair = _pair; token0 = pair.token0(); token1 = pair.token1(); // Check that the pair has non-zero reserves. (uint256 reserve0, uint256 reserve1,) = pair.getReserves(); require(reserve0 != 0 && reserve1 != 0, "PoolOracle: No reserves"); } /** * @notice Updates the pool's internal state by calling sync. */ function update() external { pair.sync(); } /** * @notice Consults the oracle for a quote based on historical data. * @param _token The token address for which to get the quote (must be token0 or token1). * @param _amountIn The amount of input token. * @return amountOut The quoted output amount. * @dev Uses a granularity of 12 observations (e.g. 6 hours if each observation is 30min). */ function consult( address _token, uint256 _amountIn ) external view returns (uint256 amountOut) { if (_token == token0 || _token == token1) { amountOut = _quote(_token, _amountIn, 12); } else { revert("PoolOracle: Invalid token"); } } /** * @notice Returns the time-weighted average price (TWAP) for a given token. * @param _token The token address for which to get the TWAP (must be token0 or token1). * @param _amountIn The amount of input token. * @return amountOut The TWAP quoted output amount. * @dev Uses a granularity of 2 observations (e.g. 1 hour if each observation is 30min). */ function twap( address _token, uint256 _amountIn ) external view returns (uint256 amountOut) { if (_token == token0 || _token == token1) { amountOut = _quote(_token, _amountIn, 2); } else { revert("PoolOracle: Invalid token"); } } /** * @dev Internal function to obtain a price quote from the pool. * @param tokenIn The input token address. * @param amountIn The input token amount. * @param granularity The number of historical observations to use. * @return amountOut The quoted output amount. * @notice The granularity parameter effectively sets the time window for TWAP calculations. * For example, if each observation represents 30 minutes, a granularity of 12 gives a 6-hour window. */ function _quote( address tokenIn, uint256 amountIn, uint256 granularity ) internal view returns (uint256 amountOut) { uint256 observationLength = pair.observationLength(); require(granularity <= observationLength, "PoolOracle: Not enough observations"); amountOut = pair.quote(tokenIn, amountIn, granularity); } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity ^0.8.26; interface IPool { error NOT_AUTHORIZED(); error UNSTABLE_RATIO(); /// @dev safe transfer failed error STF(); error OVERFLOW(); /// @dev skim disabled error SD(); /// @dev insufficient liquidity minted error ILM(); /// @dev insufficient liquidity burned error ILB(); /// @dev insufficient output amount error IOA(); /// @dev insufficient input amount error IIA(); error IL(); error IT(); error K(); event Mint(address indexed sender, uint256 amount0, uint256 amount1); event Burn( address indexed sender, uint256 amount0, uint256 amount1, address indexed to ); event Swap( address indexed sender, uint256 amount0In, uint256 amount1In, uint256 amount0Out, uint256 amount1Out, address indexed to ); event Sync(uint112 reserve0, uint112 reserve1); /// @notice Same as prices with with an additional window argument. /// Window = 2 means 2 * 30min (or 1 hr) between observations /// @param tokenIn . /// @param amountIn . /// @param points . /// @param window . /// @return Array of TWAP prices function sample( address tokenIn, uint256 amountIn, uint256 points, uint256 window ) external view returns (uint256[] memory); function observations(uint256 index) external view returns (uint256 timestamp, uint256 reserve0Cumulative, uint256 reserve1Cumulative); function current(address tokenIn, uint256 amountIn) external view returns (uint256 amountOut); /// @notice Provides twap price with user configured granularity, up to the full window size /// @param tokenIn . /// @param amountIn . /// @param granularity . /// @return amountOut . function quote(address tokenIn, uint256 amountIn, uint256 granularity) external view returns (uint256 amountOut); /// @notice Get the number of observations recorded function observationLength() external view returns (uint256); /// @notice Address of token in the pool with the lower address value function token0() external view returns (address); /// @notice Address of token in the poool with the higher address value function token1() external view returns (address); /// @notice initialize the pool, called only once programatically function initialize( address _token0, address _token1, bool _stable ) external; /// @notice calculate the current reserves of the pool and their last 'seen' timestamp /// @return _reserve0 amount of token0 in reserves /// @return _reserve1 amount of token1 in reserves /// @return _blockTimestampLast the timestamp when the pool was last updated function getReserves() external view returns ( uint112 _reserve0, uint112 _reserve1, uint32 _blockTimestampLast ); /// @notice mint the pair tokens (LPs) /// @param to where to mint the LP tokens to /// @return liquidity amount of LP tokens to mint function mint(address to) external returns (uint256 liquidity); /// @notice burn the pair tokens (LPs) /// @param to where to send the underlying /// @return amount0 amount of amount0 /// @return amount1 amount of amount1 function burn( address to ) external returns (uint256 amount0, uint256 amount1); /// @notice direct swap through the pool function swap( uint256 amount0Out, uint256 amount1Out, address to, bytes calldata data ) external; /// @notice force balances to match reserves, can be used to harvest rebases from rebasing tokens or other external factors /// @param to where to send the excess tokens to function skim(address to) external; /// @notice force reserves to match balances, prevents skim excess if skim is enabled function sync() external; /// @notice set the pair fees contract address function setFeeRecipient(address _pairFees) external; /// @notice set the feesplit variable function setFeeSplit(uint256 _feeSplit) external; /// @notice sets the swap fee of the pair /// @dev max of 10_000 (10%) /// @param _fee the fee function setFee(uint256 _fee) external; /// @notice 'mint' the fees as LP tokens /// @dev this is used for protocol/voter fees function mintFee() external; /// @notice calculates the amount of tokens to receive post swap /// @param amountIn the token amount /// @param tokenIn the address of the token function getAmountOut( uint256 amountIn, address tokenIn ) external view returns (uint256 amountOut); /// @notice returns various metadata about the pair function metadata() external view returns ( uint256 _decimals0, uint256 _decimals1, uint256 _reserve0, uint256 _reserve1, bool _stable, address _token0, address _token1 ); /// @notice returns the feeSplit of the pair function feeSplit() external view returns (uint256); /// @notice returns the fee of the pair function fee() external view returns (uint256); /// @notice returns the feeRecipient of the pair function feeRecipient() external view returns (address); }
{ "optimizer": { "enabled": true, "runs": 999999 }, "evmVersion": "paris", "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "metadata": { "useLiteralContent": true }, "libraries": {} }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"contract IPool","name":"_pair","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"_token","type":"address"},{"internalType":"uint256","name":"_amountIn","type":"uint256"}],"name":"consult","outputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pair","outputs":[{"internalType":"contract IPool","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"token0","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"token1","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_token","type":"address"},{"internalType":"uint256","name":"_amountIn","type":"uint256"}],"name":"twap","outputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"update","outputs":[],"stateMutability":"nonpayable","type":"function"}]
Deployed Bytecode
0x608060405234801561001057600080fd5b50600436106100725760003560e01c8063a2e6204511610050578063a2e62045146100f5578063a8aa1b31146100ff578063d21220a71461011f57600080fd5b80630dfe1681146100775780633ddac953146100c15780636808a128146100e2575b600080fd5b6000546100979073ffffffffffffffffffffffffffffffffffffffff1681565b60405173ffffffffffffffffffffffffffffffffffffffff90911681526020015b60405180910390f35b6100d46100cf3660046104b2565b61013f565b6040519081526020016100b8565b6100d46100f03660046104b2565b610208565b6100fd61025d565b005b6002546100979073ffffffffffffffffffffffffffffffffffffffff1681565b6001546100979073ffffffffffffffffffffffffffffffffffffffff1681565b6000805473ffffffffffffffffffffffffffffffffffffffff84811691161480610183575060015473ffffffffffffffffffffffffffffffffffffffff8481169116145b1561019b576101948383600c6102e1565b9050610202565b6040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601960248201527f506f6f6c4f7261636c653a20496e76616c696420746f6b656e0000000000000060448201526064015b60405180910390fd5b92915050565b6000805473ffffffffffffffffffffffffffffffffffffffff8481169116148061024c575060015473ffffffffffffffffffffffffffffffffffffffff8481169116145b1561019b57610194838360026102e1565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663fff6cae96040518163ffffffff1660e01b8152600401600060405180830381600087803b1580156102c757600080fd5b505af11580156102db573d6000803e3d6000fd5b50505050565b600080600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663ebeb31db6040518163ffffffff1660e01b8152600401602060405180830381865afa158015610351573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061037591906104f7565b905080831115610407576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602360248201527f506f6f6c4f7261636c653a204e6f7420656e6f756768206f627365727661746960448201527f6f6e73000000000000000000000000000000000000000000000000000000000060648201526084016101f9565b6002546040517f9e8cc04b00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8781166004830152602482018790526044820186905290911690639e8cc04b90606401602060405180830381865afa158015610485573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104a991906104f7565b95945050505050565b600080604083850312156104c557600080fd5b823573ffffffffffffffffffffffffffffffffffffffff811681146104e957600080fd5b946020939093013593505050565b60006020828403121561050957600080fd5b505191905056fea2646970667358221220e4280feb8c05ffe708de2b6b85e3dfac7442f59f95d4971b498c665a1aa7b04864736f6c634300081c0033
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 35 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.