Overview
S Balance
0 S
S Value
$0.00More Info
Private Name Tags
ContractCreator
Loading...
Loading
Contract Source Code Verified (Exact Match)
Contract Name:
BeefyOraclePyth
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 { IPyth } from "../../interfaces/oracle/IPyth.sol"; import { BeefyOracleHelper, BeefyOracleErrors } from "./BeefyOracleHelper.sol"; /// @title Beefy Oracle using Pyth /// @author Beefy, @kexley /// @notice On-chain oracle using Pyth library BeefyOraclePyth { /// @notice Fetch price from the Pyth feed and scale to 18 decimals /// @param _data Payload from the central oracle with the address of the Pyth feed /// @return price Retrieved price from the Pyth feed /// @return success Successful price fetch or not function getPrice(bytes calldata _data) external view returns (uint256 price, bool success) { (address pyth, bytes32 priceId) = abi.decode(_data, (address, bytes32)); try IPyth(pyth).getPriceUnsafe(priceId) returns (IPyth.Price memory priceData) { price = BeefyOracleHelper.scaleAmount(uint256(uint64(priceData.price)), uint8(uint32(-1 * priceData.expo))); success = true; } catch {} } /// @notice Data validation for new oracle data being added to central oracle /// @param _data Encoded Pyth feed address function validateData(bytes calldata _data) external view { (address pyth, bytes32 priceId) = abi.decode(_data, (address, bytes32)); try IPyth(pyth).getPriceUnsafe(priceId) returns (IPyth.Price memory) { } 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 IPyth { struct Price { // Price int64 price; // Confidence interval around the price uint64 conf; // Price exponent int32 expo; // Unix timestamp describing when the price was published uint publishTime; } function getPriceUnsafe(bytes32 priceId) external view returns (Price memory price); }
{ "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
[{"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
61051f61003a600b82828239805160001a60731461002d57634e487b7160e01b600052600060045260246000fd5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600436106100405760003560e01c80636b4dd15814610045578063a6ffa36c14610071575b600080fd5b610058610053366004610215565b610086565b6040805192835290151560208301520160405180910390f35b61008461007f366004610215565b61013a565b005b600080808061009785870187610287565b6040516396834ad360e01b81526004810182905291935091506001600160a01b038316906396834ad390602401608060405180830381865afa9250505080156100fd575060408051601f3d908101601f191682019092526100fa918101906102ee565b60015b1561013157805160408201516101299167ffffffffffffffff169061012490600019610394565b6101d3565b945060019350505b50509250929050565b60008061014983850185610287565b6040516396834ad360e01b81526004810182905291935091506001600160a01b038316906396834ad390602401608060405180830381865afa9250505080156101af575060408051601f3d908101601f191682019092526101ac918101906102ee565b60015b6101cc57604051630561770560e31b815260040160405180910390fd5b5050505050565b60008160ff1660121461020c576101eb82600a6104a1565b6101fd84670de0b6b3a76400006104b0565b61020791906104c7565b61020e565b825b9392505050565b6000806020838503121561022857600080fd5b823567ffffffffffffffff8082111561024057600080fd5b818501915085601f83011261025457600080fd5b81358181111561026357600080fd5b86602082850101111561027557600080fd5b60209290920196919550909350505050565b6000806040838503121561029a57600080fd5b82356001600160a01b03811681146102b157600080fd5b946020939093013593505050565b805167ffffffffffffffff811681146102d757600080fd5b919050565b8051600381900b81146102d757600080fd5b60006080828403121561030057600080fd5b6040516080810181811067ffffffffffffffff8211171561033157634e487b7160e01b600052604160045260246000fd5b6040528251600781900b811461034657600080fd5b8152610354602084016102bf565b6020820152610365604084016102dc565b6040820152606083015160608201528091505092915050565b634e487b7160e01b600052601160045260246000fd5b60008260030b8260030b028060030b91508082146103b4576103b461037e565b5092915050565b600181815b808511156103f65781600019048211156103dc576103dc61037e565b808516156103e957918102915b93841c93908002906103c0565b509250929050565b60008261040d5750600161049b565b8161041a5750600061049b565b8160018114610430576002811461043a57610456565b600191505061049b565b60ff84111561044b5761044b61037e565b50506001821b61049b565b5060208310610133831016604e8410600b8410161715610479575081810a61049b565b61048383836103bb565b80600019048211156104975761049761037e565b0290505b92915050565b600061020e60ff8416836103fe565b808202811582820484141761049b5761049b61037e565b6000826104e457634e487b7160e01b600052601260045260246000fd5b50049056fea2646970667358221220d01f2f61b013f5cc77b94ab8dea03acc4e016094a3cbeda585573d7e5740eb1664736f6c63430008170033
Deployed Bytecode
0x73eeed25069578c84897840011f10574ddeea3a06a30146080604052600436106100405760003560e01c80636b4dd15814610045578063a6ffa36c14610071575b600080fd5b610058610053366004610215565b610086565b6040805192835290151560208301520160405180910390f35b61008461007f366004610215565b61013a565b005b600080808061009785870187610287565b6040516396834ad360e01b81526004810182905291935091506001600160a01b038316906396834ad390602401608060405180830381865afa9250505080156100fd575060408051601f3d908101601f191682019092526100fa918101906102ee565b60015b1561013157805160408201516101299167ffffffffffffffff169061012490600019610394565b6101d3565b945060019350505b50509250929050565b60008061014983850185610287565b6040516396834ad360e01b81526004810182905291935091506001600160a01b038316906396834ad390602401608060405180830381865afa9250505080156101af575060408051601f3d908101601f191682019092526101ac918101906102ee565b60015b6101cc57604051630561770560e31b815260040160405180910390fd5b5050505050565b60008160ff1660121461020c576101eb82600a6104a1565b6101fd84670de0b6b3a76400006104b0565b61020791906104c7565b61020e565b825b9392505050565b6000806020838503121561022857600080fd5b823567ffffffffffffffff8082111561024057600080fd5b818501915085601f83011261025457600080fd5b81358181111561026357600080fd5b86602082850101111561027557600080fd5b60209290920196919550909350505050565b6000806040838503121561029a57600080fd5b82356001600160a01b03811681146102b157600080fd5b946020939093013593505050565b805167ffffffffffffffff811681146102d757600080fd5b919050565b8051600381900b81146102d757600080fd5b60006080828403121561030057600080fd5b6040516080810181811067ffffffffffffffff8211171561033157634e487b7160e01b600052604160045260246000fd5b6040528251600781900b811461034657600080fd5b8152610354602084016102bf565b6020820152610365604084016102dc565b6040820152606083015160608201528091505092915050565b634e487b7160e01b600052601160045260246000fd5b60008260030b8260030b028060030b91508082146103b4576103b461037e565b5092915050565b600181815b808511156103f65781600019048211156103dc576103dc61037e565b808516156103e957918102915b93841c93908002906103c0565b509250929050565b60008261040d5750600161049b565b8161041a5750600061049b565b8160018114610430576002811461043a57610456565b600191505061049b565b60ff84111561044b5761044b61037e565b50506001821b61049b565b5060208310610133831016604e8410600b8410161715610479575081810a61049b565b61048383836103bb565b80600019048211156104975761049761037e565b0290505b92915050565b600061020e60ff8416836103fe565b808202811582820484141761049b5761049b61037e565b6000826104e457634e487b7160e01b600052601260045260246000fd5b50049056fea2646970667358221220d01f2f61b013f5cc77b94ab8dea03acc4e016094a3cbeda585573d7e5740eb1664736f6c63430008170033
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 30 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.