Source Code
Overview
S Balance
S Value
$0.00View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Cross-Chain Transactions
Loading...
Loading
Contract Name:
BeefyOracleSolidly
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 { IERC20MetadataUpgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/IERC20MetadataUpgradeable.sol";
import { ISolidlyPair} from "../../interfaces/common/ISolidlyPair.sol";
import { BeefyOracleHelper, IBeefyOracle, BeefyOracleErrors } from "./BeefyOracleHelper.sol";
/// @title Beefy Oracle for Solidly
/// @author Beefy, @kexley
/// @notice On-chain oracle using Solidly
contract BeefyOracleSolidly {
/// @notice Fetch price from the Solidly pairs using the TWAP observations
/// @param _data Payload from the central oracle with the addresses of the token route, pool
/// route and TWAP periods counted in 30 minute increments
/// @return price Retrieved price from the chained quotes
/// @return success Successful price fetch or not
function getPrice(bytes calldata _data) external returns (uint256 price, bool success) {
(address[] memory tokens, address[] memory pools, uint256[] memory twapPeriods) =
abi.decode(_data, (address[], address[], uint256[]));
uint256 amount = 10 ** IERC20MetadataUpgradeable(tokens[0]).decimals();
for (uint i; i < pools.length; i++) {
amount = ISolidlyPair(pools[i]).quote(tokens[i], amount, twapPeriods[i]);
}
price = BeefyOracleHelper.priceFromBaseToken(
msg.sender, tokens[tokens.length - 1], tokens[0], amount
);
if (price != 0) success = true;
}
/// @notice Data validation for new oracle data being added to central oracle
/// @param _data Encoded addresses of the token route, pool route and TWAP periods
function validateData(bytes calldata _data) external view {
(address[] memory tokens, address[] memory pools, uint256[] memory twapPeriods) =
abi.decode(_data, (address[], address[], uint256[]));
if (tokens.length != pools.length + 1 || tokens.length != twapPeriods.length + 1) {
revert BeefyOracleErrors.ArrayLength();
}
uint256 basePrice = IBeefyOracle(msg.sender).getPrice(tokens[0]);
if (basePrice == 0) revert BeefyOracleErrors.NoBasePrice(tokens[0]);
uint256 poolLength = pools.length;
for (uint i; i < poolLength;) {
address fromToken = tokens[i];
address toToken = tokens[i + 1];
address pool = pools[i];
address token0 = ISolidlyPair(pool).token0();
address token1 = ISolidlyPair(pool).token1();
if (fromToken != token0 && fromToken != token1) {
revert BeefyOracleErrors.TokenNotInPair(fromToken, pool);
}
if (toToken != token0 && toToken != token1) {
revert BeefyOracleErrors.TokenNotInPair(toToken, pool);
}
unchecked { ++i; }
}
}
}// 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.6.0 <0.9.0;
interface ISolidlyPair {
function factory() external view returns (address);
function token0() external view returns (address);
function token1() external view returns (address);
function burn(address to) external returns (uint amount0, uint amount1);
function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
function stable() external view returns (bool);
function getAmountOut(uint256 amountIn, address tokenIn) external view returns (uint256);
function quote(address tokenIn, uint256 amountIn, uint256 granularity) external returns (uint256 amountOut);
}// 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);
}{
"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":"ArrayLength","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"NoBasePrice","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"pair","type":"address"}],"name":"TokenNotInPair","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":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes","name":"_data","type":"bytes"}],"name":"validateData","outputs":[],"stateMutability":"view","type":"function"}]Contract Creation Code
608060405234801561001057600080fd5b50610bbf806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c80636b4dd1581461003b578063a6ffa36c14610067575b600080fd5b61004e610049366004610730565b61007c565b6040805192835290151560208301520160405180910390f35b61007a610075366004610730565b610271565b005b60008080808061008e8688018861089d565b9250925092506000836000815181106100a9576100a961097b565b60200260200101516001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa1580156100ee573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101129190610991565b61011d90600a610ab0565b905060005b835181101561020c5783818151811061013d5761013d61097b565b60200260200101516001600160a01b0316639e8cc04b8683815181106101655761016561097b565b6020026020010151848685815181106101805761018061097b565b60209081029190910101516040516001600160e01b031960e086901b1681526001600160a01b039093166004840152602483019190915260448201526064016020604051808303816000875af11580156101de573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102029190610abf565b9150600101610122565b506102593385600187516102209190610ad8565b815181106102305761023061097b565b60200260200101518660008151811061024b5761024b61097b565b6020026020010151846105e1565b9550851561026657600194505b505050509250929050565b600080806102818486018661089d565b925092509250815160016102959190610aeb565b83511415806102b1575080516102ac906001610aeb565b835114155b156102cf576040516305c3d17360e11b815260040160405180910390fd5b6000336001600160a01b03166341976e09856000815181106102f3576102f361097b565b60200260200101516040518263ffffffff1660e01b815260040161032691906001600160a01b0391909116815260200190565b602060405180830381865afa158015610343573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103679190610abf565b9050806000036103be57836000815181106103845761038461097b565b602002602001015160405163089bfea760e01b81526004016103b591906001600160a01b0391909116815260200190565b60405180910390fd5b825160005b818110156105d75760008682815181106103df576103df61097b565b602002602001015190506000878360016103f99190610aeb565b815181106104095761040961097b565b6020026020010151905060008784815181106104275761042761097b565b602002602001015190506000816001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa158015610471573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104959190610afe565b90506000826001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa1580156104d7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104fb9190610afe565b9050816001600160a01b0316856001600160a01b0316141580156105315750806001600160a01b0316856001600160a01b031614155b1561056257604051638a9bb81760e01b81526001600160a01b038087166004830152841660248201526044016103b5565b816001600160a01b0316846001600160a01b0316141580156105965750806001600160a01b0316846001600160a01b031614155b156105c757604051638a9bb81760e01b81526001600160a01b038086166004830152841660248201526044016103b5565b85600101955050505050506103c3565b5050505050505050565b60405163baeb325b60e01b81526001600160a01b038381166004830152600091829187169063baeb325b9060240160408051808303816000875af115801561062d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106519190610b1b565b5090506000856001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015610694573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106b89190610991565b90506106c484826106ee565b9350836106d983670de0b6b3a7640000610b50565b6106e39190610b67565b979650505050505050565b60008160ff166012146107275761070682600a610ab0565b61071884670de0b6b3a7640000610b50565b6107229190610b67565b610729565b825b9392505050565b6000806020838503121561074357600080fd5b823567ffffffffffffffff8082111561075b57600080fd5b818501915085601f83011261076f57600080fd5b81358181111561077e57600080fd5b86602082850101111561079057600080fd5b60209290920196919550909350505050565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff811182821017156107e1576107e16107a2565b604052919050565b600067ffffffffffffffff821115610803576108036107a2565b5060051b60200190565b6001600160a01b038116811461082257600080fd5b50565b600082601f83011261083657600080fd5b8135602061084b610846836107e9565b6107b8565b8083825260208201915060208460051b87010193508684111561086d57600080fd5b602086015b848110156108925780356108858161080d565b8352918301918301610872565b509695505050505050565b6000806000606084860312156108b257600080fd5b833567ffffffffffffffff808211156108ca57600080fd5b6108d687838801610825565b94506020915081860135818111156108ed57600080fd5b6108f988828901610825565b94505060408601358181111561090e57600080fd5b86019050601f8101871361092157600080fd5b803561092f610846826107e9565b81815260059190911b8201830190838101908983111561094e57600080fd5b928401925b8284101561096c57833582529284019290840190610953565b80955050505050509250925092565b634e487b7160e01b600052603260045260246000fd5b6000602082840312156109a357600080fd5b815160ff8116811461072957600080fd5b634e487b7160e01b600052601160045260246000fd5b600181815b80851115610a055781600019048211156109eb576109eb6109b4565b808516156109f857918102915b93841c93908002906109cf565b509250929050565b600082610a1c57506001610aaa565b81610a2957506000610aaa565b8160018114610a3f5760028114610a4957610a65565b6001915050610aaa565b60ff841115610a5a57610a5a6109b4565b50506001821b610aaa565b5060208310610133831016604e8410600b8410161715610a88575081810a610aaa565b610a9283836109ca565b8060001904821115610aa657610aa66109b4565b0290505b92915050565b600061072960ff841683610a0d565b600060208284031215610ad157600080fd5b5051919050565b81810381811115610aaa57610aaa6109b4565b80820180821115610aaa57610aaa6109b4565b600060208284031215610b1057600080fd5b81516107298161080d565b60008060408385031215610b2e57600080fd5b8251915060208301518015158114610b4557600080fd5b809150509250929050565b8082028115828204841417610aaa57610aaa6109b4565b600082610b8457634e487b7160e01b600052601260045260246000fd5b50049056fea26469706673582212208305b9af15ef5ee59eeff410d31c1d720b679495c057ff4970c7f060beff3a4a64736f6c63430008170033
Deployed Bytecode
0x608060405234801561001057600080fd5b50600436106100365760003560e01c80636b4dd1581461003b578063a6ffa36c14610067575b600080fd5b61004e610049366004610730565b61007c565b6040805192835290151560208301520160405180910390f35b61007a610075366004610730565b610271565b005b60008080808061008e8688018861089d565b9250925092506000836000815181106100a9576100a961097b565b60200260200101516001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa1580156100ee573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101129190610991565b61011d90600a610ab0565b905060005b835181101561020c5783818151811061013d5761013d61097b565b60200260200101516001600160a01b0316639e8cc04b8683815181106101655761016561097b565b6020026020010151848685815181106101805761018061097b565b60209081029190910101516040516001600160e01b031960e086901b1681526001600160a01b039093166004840152602483019190915260448201526064016020604051808303816000875af11580156101de573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102029190610abf565b9150600101610122565b506102593385600187516102209190610ad8565b815181106102305761023061097b565b60200260200101518660008151811061024b5761024b61097b565b6020026020010151846105e1565b9550851561026657600194505b505050509250929050565b600080806102818486018661089d565b925092509250815160016102959190610aeb565b83511415806102b1575080516102ac906001610aeb565b835114155b156102cf576040516305c3d17360e11b815260040160405180910390fd5b6000336001600160a01b03166341976e09856000815181106102f3576102f361097b565b60200260200101516040518263ffffffff1660e01b815260040161032691906001600160a01b0391909116815260200190565b602060405180830381865afa158015610343573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103679190610abf565b9050806000036103be57836000815181106103845761038461097b565b602002602001015160405163089bfea760e01b81526004016103b591906001600160a01b0391909116815260200190565b60405180910390fd5b825160005b818110156105d75760008682815181106103df576103df61097b565b602002602001015190506000878360016103f99190610aeb565b815181106104095761040961097b565b6020026020010151905060008784815181106104275761042761097b565b602002602001015190506000816001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa158015610471573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104959190610afe565b90506000826001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa1580156104d7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104fb9190610afe565b9050816001600160a01b0316856001600160a01b0316141580156105315750806001600160a01b0316856001600160a01b031614155b1561056257604051638a9bb81760e01b81526001600160a01b038087166004830152841660248201526044016103b5565b816001600160a01b0316846001600160a01b0316141580156105965750806001600160a01b0316846001600160a01b031614155b156105c757604051638a9bb81760e01b81526001600160a01b038086166004830152841660248201526044016103b5565b85600101955050505050506103c3565b5050505050505050565b60405163baeb325b60e01b81526001600160a01b038381166004830152600091829187169063baeb325b9060240160408051808303816000875af115801561062d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106519190610b1b565b5090506000856001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015610694573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106b89190610991565b90506106c484826106ee565b9350836106d983670de0b6b3a7640000610b50565b6106e39190610b67565b979650505050505050565b60008160ff166012146107275761070682600a610ab0565b61071884670de0b6b3a7640000610b50565b6107229190610b67565b610729565b825b9392505050565b6000806020838503121561074357600080fd5b823567ffffffffffffffff8082111561075b57600080fd5b818501915085601f83011261076f57600080fd5b81358181111561077e57600080fd5b86602082850101111561079057600080fd5b60209290920196919550909350505050565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff811182821017156107e1576107e16107a2565b604052919050565b600067ffffffffffffffff821115610803576108036107a2565b5060051b60200190565b6001600160a01b038116811461082257600080fd5b50565b600082601f83011261083657600080fd5b8135602061084b610846836107e9565b6107b8565b8083825260208201915060208460051b87010193508684111561086d57600080fd5b602086015b848110156108925780356108858161080d565b8352918301918301610872565b509695505050505050565b6000806000606084860312156108b257600080fd5b833567ffffffffffffffff808211156108ca57600080fd5b6108d687838801610825565b94506020915081860135818111156108ed57600080fd5b6108f988828901610825565b94505060408601358181111561090e57600080fd5b86019050601f8101871361092157600080fd5b803561092f610846826107e9565b81815260059190911b8201830190838101908983111561094e57600080fd5b928401925b8284101561096c57833582529284019290840190610953565b80955050505050509250925092565b634e487b7160e01b600052603260045260246000fd5b6000602082840312156109a357600080fd5b815160ff8116811461072957600080fd5b634e487b7160e01b600052601160045260246000fd5b600181815b80851115610a055781600019048211156109eb576109eb6109b4565b808516156109f857918102915b93841c93908002906109cf565b509250929050565b600082610a1c57506001610aaa565b81610a2957506000610aaa565b8160018114610a3f5760028114610a4957610a65565b6001915050610aaa565b60ff841115610a5a57610a5a6109b4565b50506001821b610aaa565b5060208310610133831016604e8410600b8410161715610a88575081810a610aaa565b610a9283836109ca565b8060001904821115610aa657610aa66109b4565b0290505b92915050565b600061072960ff841683610a0d565b600060208284031215610ad157600080fd5b5051919050565b81810381811115610aaa57610aaa6109b4565b80820180821115610aaa57610aaa6109b4565b600060208284031215610b1057600080fd5b81516107298161080d565b60008060408385031215610b2e57600080fd5b8251915060208301518015158114610b4557600080fd5b809150509250929050565b8082028115828204841417610aaa57610aaa6109b4565b600082610b8457634e487b7160e01b600052601260045260246000fd5b50049056fea26469706673582212208305b9af15ef5ee59eeff410d31c1d720b679495c057ff4970c7f060beff3a4a64736f6c63430008170033
Loading...
Loading
Loading...
Loading
Loading...
Loading
Net Worth in USD
$0.00
Net Worth in S
Multichain Portfolio | 35 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
Loading...
Loading
Loading...
Loading
Loading...
Loading
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.