Overview
S Balance
S Value
$0.00More Info
Private Name Tags
ContractCreator
Loading...
Loading
Contract Source Code Verified (Exact Match)
Contract Name:
BeefyOracleChainlink
Compiler Version
v0.8.23+commit.f704f362
Optimization Enabled:
Yes with 200 runs
Other Settings:
paris EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import { IChainlink } from "../../interfaces/oracle/IChainlink.sol"; import { BeefyOracleHelper, BeefyOracleErrors } from "./BeefyOracleHelper.sol"; /// @title Beefy Oracle using Chainlink /// @author Beefy, @kexley /// @notice On-chain oracle using Chainlink library BeefyOracleChainlink { /// @notice Fetch price from the Chainlink feed and scale to 18 decimals /// @param _data Payload from the central oracle with the address of the Chainlink feed /// @return price Retrieved price from the Chainlink feed /// @return success Successful price fetch or not function getPrice(bytes calldata _data) external view returns (uint256 price, bool success) { address chainlink = abi.decode(_data, (address)); try IChainlink(chainlink).decimals() returns (uint8 decimals) { try IChainlink(chainlink).latestAnswer() returns (int256 latestAnswer) { price = BeefyOracleHelper.scaleAmount(uint256(latestAnswer), decimals); success = true; } catch {} } catch {} } /// @notice Data validation for new oracle data being added to central oracle /// @param _data Encoded Chainlink feed address function validateData(bytes calldata _data) external view { address chainlink = abi.decode(_data, (address)); try IChainlink(chainlink).decimals() returns (uint8) { try IChainlink(chainlink).latestAnswer() returns (int256) { } catch { revert BeefyOracleErrors.NoAnswer(); } } catch { revert BeefyOracleErrors.NoAnswer(); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol) pragma solidity ^0.8.0; import "../IERC20Upgradeable.sol"; /** * @dev Interface for the optional metadata functions from the ERC20 standard. * * _Available since v4.1._ */ interface IERC20MetadataUpgradeable is IERC20Upgradeable { /** * @dev Returns the name of the token. */ function name() external view returns (string memory); /** * @dev Returns the symbol of the token. */ function symbol() external view returns (string memory); /** * @dev Returns the decimals places of the token. */ function decimals() external view returns (uint8); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20Upgradeable { /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `to`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address to, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `from` to `to` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address from, address to, uint256 amount) external returns (bool); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /// @title Beefy Oracle Errors /// @author Beefy, @kexley /// @notice Error list for Beefy Oracles contract BeefyOracleErrors { /// @dev No response from the Chainlink feed error NoAnswer(); /// @dev No price for base token /// @param token Base token error NoBasePrice(address token); /// @dev Token is not present in the pair /// @param token Input token /// @param pair Pair token error TokenNotInPair(address token, address pair); /// @dev Array length is not correct error ArrayLength(); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import { IERC20MetadataUpgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/IERC20MetadataUpgradeable.sol"; import { IBeefyOracle } from "../../interfaces/oracle/IBeefyOracle.sol"; import { BeefyOracleErrors } from "./BeefyOracleErrors.sol"; /// @title Beefy Oracle Helper /// @author Beefy, @kexley /// @notice Helper functions for Beefy oracles library BeefyOracleHelper { /// @dev Calculate the price of the output token in 18 decimals given the base token price /// and the amount out received from swapping 1 unit of the base token /// @param _oracle Central Beefy oracle which stores the base token price /// @param _token Address of token to calculate the price of /// @param _baseToken Address of the base token used in the price chain /// @param _amountOut Amount received from swapping 1 unit of base token into the target token /// @return price Price of the target token in 18 decimals function priceFromBaseToken( address _oracle, address _token, address _baseToken, uint256 _amountOut ) internal returns (uint256 price) { (uint256 basePrice,) = IBeefyOracle(_oracle).getFreshPrice(_baseToken); uint8 decimals = IERC20MetadataUpgradeable(_token).decimals(); _amountOut = scaleAmount(_amountOut, decimals); price = basePrice * 1 ether / _amountOut; } /// @dev Scale an input amount to 18 decimals /// @param _amount Amount to be scaled up or down /// @param _decimals Decimals that the amount is already in /// @return scaledAmount New scaled amount in 18 decimals function scaleAmount( uint256 _amount, uint8 _decimals ) internal pure returns (uint256 scaledAmount) { scaledAmount = _decimals == 18 ? _amount : _amount * 10 ** 18 / 10 ** _decimals; } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; interface IBeefyOracle { function getPrice(address token) external view returns (uint256 price); function getPrice(address[] calldata tokens) external view returns (uint256[] memory prices); function getFreshPrice(address token) external returns (uint256 price, bool success); function getFreshPrice(address[] calldata tokens) external returns (uint256[] memory prices, bool[] memory successes); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; interface IChainlink { function decimals() external view returns (uint8); function latestAnswer() external view returns (int256); }
{ "optimizer": { "enabled": true, "runs": 200 }, "evmVersion": "paris", "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "libraries": {} }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[],"name":"NoAnswer","type":"error"},{"inputs":[{"internalType":"bytes","name":"_data","type":"bytes"}],"name":"getPrice","outputs":[{"internalType":"uint256","name":"price","type":"uint256"},{"internalType":"bool","name":"success","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"_data","type":"bytes"}],"name":"validateData","outputs":[],"stateMutability":"view","type":"function"}]
Contract Creation Code
61050261003a600b82828239805160001a60731461002d57634e487b7160e01b600052600060045260246000fd5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600436106100405760003560e01c80636b4dd15814610045578063a6ffa36c14610071575b600080fd5b6100586100533660046102b9565b610086565b6040805192835290151560208301520160405180910390f35b61008461007f3660046102b9565b610172565b005b600080806100968486018661032b565b9050806001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa9250505080156100f2575060408051601f3d908101601f191682019092526100ef91810190610354565b60015b1561016a57816001600160a01b03166350d25bcd6040518163ffffffff1660e01b8152600401602060405180830381865afa925050508015610151575060408051601f3d908101601f1916820190925261014e91810190610377565b60015b15610168576101608183610277565b945060019350505b505b509250929050565b60006101808284018461032b565b9050806001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa9250505080156101dc575060408051601f3d908101601f191682019092526101d991810190610354565b60015b6101f957604051630561770560e31b815260040160405180910390fd5b816001600160a01b03166350d25bcd6040518163ffffffff1660e01b8152600401602060405180830381865afa925050508015610253575060408051601f3d908101601f1916820190925261025091810190610377565b60015b61027057604051630561770560e31b815260040160405180910390fd5b5050505050565b60008160ff166012146102b05761028f82600a610484565b6102a184670de0b6b3a7640000610493565b6102ab91906104aa565b6102b2565b825b9392505050565b600080602083850312156102cc57600080fd5b823567ffffffffffffffff808211156102e457600080fd5b818501915085601f8301126102f857600080fd5b81358181111561030757600080fd5b86602082850101111561031957600080fd5b60209290920196919550909350505050565b60006020828403121561033d57600080fd5b81356001600160a01b03811681146102b257600080fd5b60006020828403121561036657600080fd5b815160ff811681146102b257600080fd5b60006020828403121561038957600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b600181815b8085111561016a5781600019048211156103c7576103c7610390565b808516156103d457918102915b93841c93908002906103ab565b6000826103f05750600161047e565b816103fd5750600061047e565b8160018114610413576002811461041d57610439565b600191505061047e565b60ff84111561042e5761042e610390565b50506001821b61047e565b5060208310610133831016604e8410600b841016171561045c575081810a61047e565b61046683836103a6565b806000190482111561047a5761047a610390565b0290505b92915050565b60006102b260ff8416836103e1565b808202811582820484141761047e5761047e610390565b6000826104c757634e487b7160e01b600052601260045260246000fd5b50049056fea2646970667358221220a623b017d5dc5fa6c2c6ec198982da22b7bcd4072836375fb40b00f9212b673064736f6c63430008170033
Deployed Bytecode
0x737cac900b2f504047b40f5554f633248f78bd960a30146080604052600436106100405760003560e01c80636b4dd15814610045578063a6ffa36c14610071575b600080fd5b6100586100533660046102b9565b610086565b6040805192835290151560208301520160405180910390f35b61008461007f3660046102b9565b610172565b005b600080806100968486018661032b565b9050806001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa9250505080156100f2575060408051601f3d908101601f191682019092526100ef91810190610354565b60015b1561016a57816001600160a01b03166350d25bcd6040518163ffffffff1660e01b8152600401602060405180830381865afa925050508015610151575060408051601f3d908101601f1916820190925261014e91810190610377565b60015b15610168576101608183610277565b945060019350505b505b509250929050565b60006101808284018461032b565b9050806001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa9250505080156101dc575060408051601f3d908101601f191682019092526101d991810190610354565b60015b6101f957604051630561770560e31b815260040160405180910390fd5b816001600160a01b03166350d25bcd6040518163ffffffff1660e01b8152600401602060405180830381865afa925050508015610253575060408051601f3d908101601f1916820190925261025091810190610377565b60015b61027057604051630561770560e31b815260040160405180910390fd5b5050505050565b60008160ff166012146102b05761028f82600a610484565b6102a184670de0b6b3a7640000610493565b6102ab91906104aa565b6102b2565b825b9392505050565b600080602083850312156102cc57600080fd5b823567ffffffffffffffff808211156102e457600080fd5b818501915085601f8301126102f857600080fd5b81358181111561030757600080fd5b86602082850101111561031957600080fd5b60209290920196919550909350505050565b60006020828403121561033d57600080fd5b81356001600160a01b03811681146102b257600080fd5b60006020828403121561036657600080fd5b815160ff811681146102b257600080fd5b60006020828403121561038957600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b600181815b8085111561016a5781600019048211156103c7576103c7610390565b808516156103d457918102915b93841c93908002906103ab565b6000826103f05750600161047e565b816103fd5750600061047e565b8160018114610413576002811461041d57610439565b600191505061047e565b60ff84111561042e5761042e610390565b50506001821b61047e565b5060208310610133831016604e8410600b841016171561045c575081810a61047e565b61046683836103a6565b806000190482111561047a5761047a610390565b0290505b92915050565b60006102b260ff8416836103e1565b808202811582820484141761047e5761047e610390565b6000826104c757634e487b7160e01b600052601260045260246000fd5b50049056fea2646970667358221220a623b017d5dc5fa6c2c6ec198982da22b7bcd4072836375fb40b00f9212b673064736f6c63430008170033
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 31 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.