Polygon Sponsored slots available. Book your slot here!
Contract Overview
My Name Tag:
Not Available, login to update
[ Download CSV Export ]
Similar Match Source Code
Note: This contract matches the deployed ByteCode of the Source Code for Contract 0xd43EB9BA257f6f60f58D731D801F71ff8eDCD65a
Contract Name:
ChainlinkPriceFeed
Compiler Version
v0.8.4+commit.c7e474f2
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; interface AggregatorV3Interface { function decimals() external view returns ( uint8 ); function description() external view returns ( string memory ); function version() external view returns ( uint256 ); // getRoundData and latestRoundData should both raise "No data present" // if they do not have data to report, instead of returning unset values // which could be misinterpreted as actual reported values. function getRoundData( uint80 _roundId ) external view returns ( uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound ); function latestRoundData() external view returns ( uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound ); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "../utils/Context.sol"; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor() { _setOwner(_msgSender()); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { _setOwner(address(0)); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); _setOwner(newOwner); } function _setOwner(address newOwner) private { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; /* * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } }
// SPDX-License-Identifier: MIT pragma solidity 0.8.4; import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; import "./libs/UniswapLib.sol"; import "./IRToken.sol"; contract ChainlinkPriceFeed is Ownable { using FixedPoint for *; struct TokenConfig { address rToken; address underlying; bytes32 symbolHash; uint256 baseUnit; address chainlinkPriceFeed; } struct Observation { uint256 timestamp; uint256 acc; } uint256 public constant PRECISION = 1e18; mapping(address => TokenConfig) public getTokenConfigFromRToken; mapping(bytes32 => address) public getRTokenFromSymbolHash; mapping(address => address) public getRTokenFromUnderlying; function getUnderlyingPrice(IRToken _rToken) external view returns (uint256) { TokenConfig storage config = getTokenConfigFromRToken[address(_rToken)]; // IronController needs prices in the format: ${raw price} * 1e(36 - baseUnit) // Since the prices in this view have 6 decimals, we must scale them by 1e(36 - 6 - baseUnit) return 1e18 * getFromChainlink(config.chainlinkPriceFeed) / config.baseUnit; } function setTokenConfig( address _rToken, address _underlying, string memory _symbol, uint256 _decimals, address _chainlinkPriceFeed ) external onlyOwner { require(getRTokenFromUnderlying[_underlying] == address(0), "RToken & underlying existed"); require(_chainlinkPriceFeed != address(0), "!chainlink"); bytes32 symbolHash = keccak256(abi.encodePacked(_symbol)); TokenConfig storage _newToken = getTokenConfigFromRToken[_rToken]; _newToken.rToken = _rToken; _newToken.underlying = _underlying; _newToken.baseUnit = 10**_decimals; _newToken.symbolHash = symbolHash; _newToken.chainlinkPriceFeed = _chainlinkPriceFeed; getRTokenFromUnderlying[_newToken.underlying] = _rToken; getRTokenFromSymbolHash[_newToken.symbolHash] = _rToken; } function price(string calldata _symbol) external view returns (uint256) { TokenConfig memory config = getTokenConfigBySymbol(_symbol); return getFromChainlink(config.chainlinkPriceFeed); } /** * @return price in USD with 6 decimals */ function getFromChainlink(address _chainlinkPriceFeed) internal view returns (uint256) { assert(_chainlinkPriceFeed != address(0)); AggregatorV3Interface _priceFeed = AggregatorV3Interface(_chainlinkPriceFeed); (, int256 _price, , , ) = _priceFeed.latestRoundData(); uint8 _decimals = _priceFeed.decimals(); return (uint256(_price) * PRECISION) / (10**_decimals); } function getTokenConfigBySymbolHash(bytes32 _symbolHash) internal view returns (TokenConfig memory) { address rToken = getRTokenFromSymbolHash[_symbolHash]; require(rToken != address(0), "token config not found"); return getTokenConfigFromRToken[rToken]; } function getTokenConfigBySymbol(string memory symbol) public view returns (TokenConfig memory) { bytes32 symbolHash = keccak256(abi.encodePacked(symbol)); return getTokenConfigBySymbolHash(symbolHash); } }
// SPDX-License-Identifier: MIT pragma solidity 0.8.4; interface IRToken { function underlying() external returns (address); }
// SPDX-License-Identifier: MIT pragma solidity 0.8.4; // computes square roots using the babylonian method // https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method library Babylonian { function sqrt(uint256 y) internal pure returns (uint256 z) { if (y > 3) { z = y; uint256 x = y / 2 + 1; while (x < z) { z = x; x = (y / x + x) / 2; } } else if (y != 0) { z = 1; } // else z = 0 } }
// SPDX-License-Identifier: MIT pragma solidity >=0.5.16; import "./Babylonian.sol"; // a library for handling binary fixed point numbers (https://en.wikipedia.org/wiki/Q_(number_format)) library FixedPoint { // range: [0, 2**112 - 1] // resolution: 1 / 2**112 struct uq112x112 { uint224 _x; } // range: [0, 2**144 - 1] // resolution: 1 / 2**112 struct uq144x112 { uint256 _x; } uint8 private constant RESOLUTION = 112; uint256 private constant Q112 = uint256(1) << RESOLUTION; uint256 private constant Q224 = Q112 << RESOLUTION; // encode a uint112 as a UQ112x112 function encode(uint112 x) internal pure returns (uq112x112 memory) { return uq112x112(uint224(x) << RESOLUTION); } // encodes a uint144 as a UQ144x112 function encode144(uint144 x) internal pure returns (uq144x112 memory) { return uq144x112(uint256(x) << RESOLUTION); } // divide a UQ112x112 by a uint112, returning a UQ112x112 function div(uq112x112 memory self, uint112 x) internal pure returns (uq112x112 memory) { require(x != 0, "FixedPoint: DIV_BY_ZERO"); return uq112x112(self._x / uint224(x)); } // multiply a UQ112x112 by a uint, returning a UQ144x112 // reverts on overflow function mul(uq112x112 memory self, uint256 y) internal pure returns (uq144x112 memory) { uint256 z; require(y == 0 || (z = uint256(self._x) * y) / y == uint256(self._x), "FixedPoint: MULTIPLICATION_OVERFLOW"); return uq144x112(z); } // returns a UQ112x112 which represents the ratio of the numerator to the denominator // equivalent to encode(numerator).div(denominator) function fraction(uint112 numerator, uint112 denominator) internal pure returns (uq112x112 memory) { require(denominator > 0, "FixedPoint: DIV_BY_ZERO"); return uq112x112((uint224(numerator) << RESOLUTION) / denominator); } // decode a UQ112x112 into a uint112 by truncating after the radix point function decode(uq112x112 memory self) internal pure returns (uint112) { return uint112(self._x >> RESOLUTION); } // decode a UQ144x112 into a uint144 by truncating after the radix point function decode144(uq144x112 memory self) internal pure returns (uint144) { return uint144(self._x >> RESOLUTION); } // take the reciprocal of a UQ112x112 function reciprocal(uq112x112 memory self) internal pure returns (uq112x112 memory) { require(self._x != 0, "FixedPoint: ZERO_RECIPROCAL"); return uq112x112(uint224(Q224 / self._x)); } // square root of a UQ112x112 function sqrt(uq112x112 memory self) internal pure returns (uq112x112 memory) { return uq112x112(uint224(Babylonian.sqrt(uint256(self._x)) << 56)); } // decode a uq112x112 into a uint with 18 decimals of precision function decode112with18(uq112x112 memory self) internal pure returns (uint) { // we only have 256 - 224 = 32 bits to spare, so scaling up by ~60 bits is dangerous // instead, get close to: // (x * 1e18) >> 112 // without risk of overflowing, e.g.: // (x) / 2 ** (112 - lg(1e18)) return uint(self._x) / 5192296858534827; } }
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.4; import "./FixedPoint.sol"; // library with helper methods for oracles that are concerned with computing average prices library UniswapV2OracleLibrary { using FixedPoint for *; // helper function that returns the current block timestamp within the range of uint32, i.e. [0, 2**32 - 1] function currentBlockTimestamp() internal view returns (uint32) { return uint32(block.timestamp % 2 ** 32); } // produces the cumulative price using counterfactuals to save gas and avoid a call to sync. function currentCumulativePrices( address pair ) internal view returns (uint price0Cumulative, uint price1Cumulative, uint32 blockTimestamp) { blockTimestamp = currentBlockTimestamp(); price0Cumulative = IUniswapV2Pair(pair).price0CumulativeLast(); price1Cumulative = IUniswapV2Pair(pair).price1CumulativeLast(); // if time has elapsed since the last update on the pair, mock the accumulated price values (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast) = IUniswapV2Pair(pair).getReserves(); if (blockTimestampLast != blockTimestamp) { // subtraction overflow is desired uint32 timeElapsed = blockTimestamp - blockTimestampLast; // addition overflow is desired // counterfactual price0Cumulative += uint(FixedPoint.fraction(reserve1, reserve0)._x) * timeElapsed; // counterfactual price1Cumulative += uint(FixedPoint.fraction(reserve0, reserve1)._x) * timeElapsed; } } } interface IUniswapV2Pair { function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast); function price0CumulativeLast() external view returns (uint); function price1CumulativeLast() external view returns (uint); function token0() external view returns (address); function token1() external view returns (address); }
{ "evmVersion": "istanbul", "libraries": {}, "metadata": { "bytecodeHash": "ipfs", "useLiteralContent": true }, "optimizer": { "enabled": true, "runs": 200 }, "remappings": [], "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "abi" ] } } }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[],"name":"PRECISION","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"getRTokenFromSymbolHash","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"getRTokenFromUnderlying","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"symbol","type":"string"}],"name":"getTokenConfigBySymbol","outputs":[{"components":[{"internalType":"address","name":"rToken","type":"address"},{"internalType":"address","name":"underlying","type":"address"},{"internalType":"bytes32","name":"symbolHash","type":"bytes32"},{"internalType":"uint256","name":"baseUnit","type":"uint256"},{"internalType":"address","name":"chainlinkPriceFeed","type":"address"}],"internalType":"struct ChainlinkPriceFeed.TokenConfig","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"getTokenConfigFromRToken","outputs":[{"internalType":"address","name":"rToken","type":"address"},{"internalType":"address","name":"underlying","type":"address"},{"internalType":"bytes32","name":"symbolHash","type":"bytes32"},{"internalType":"uint256","name":"baseUnit","type":"uint256"},{"internalType":"address","name":"chainlinkPriceFeed","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IRToken","name":"_rToken","type":"address"}],"name":"getUnderlyingPrice","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"_symbol","type":"string"}],"name":"price","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_rToken","type":"address"},{"internalType":"address","name":"_underlying","type":"address"},{"internalType":"string","name":"_symbol","type":"string"},{"internalType":"uint256","name":"_decimals","type":"uint256"},{"internalType":"address","name":"_chainlinkPriceFeed","type":"address"}],"name":"setTokenConfig","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"}]
Contract Creation Code
608060405234801561001057600080fd5b5061001a3361001f565b61006f565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b610d2d8061007e6000396000f3fe608060405234801561001057600080fd5b50600436106100a95760003560e01c80638da5cb5b116100715780638da5cb5b146101ee578063aaf5eb68146101ff578063ee01962e1461021c578063f2fde38b14610245578063fc57d4df14610258578063fe2c61981461026b57600080fd5b806314bab2e4146100ae578063248d81ec146100c3578063276c2cba14610147578063715018a6146101a5578063785774fd146101ad575b600080fd5b6100c16100bc366004610967565b61027e565b005b61010e6100d136600461094b565b6001602081905260009182526040909120805491810154600282015460038301546004909301546001600160a01b03948516949283169391921685565b604080516001600160a01b03968716815294861660208601528401929092526060830152909116608082015260a0015b60405180910390f35b61015a610155366004610a6b565b610440565b60405161013e919081516001600160a01b0390811682526020808401518216908301526040808401519083015260608084015190830152608092830151169181019190915260a00190565b6100c16104a6565b6101d66101bb3660046109e6565b6002602052600090815260409020546001600160a01b031681565b6040516001600160a01b03909116815260200161013e565b6000546001600160a01b03166101d6565b61020e670de0b6b3a764000081565b60405190815260200161013e565b6101d661022a36600461094b565b6003602052600090815260409020546001600160a01b031681565b6100c161025336600461094b565b6104dc565b61020e61026636600461094b565b610577565b61020e6102793660046109fe565b6105c6565b6000546001600160a01b031633146102b15760405162461bcd60e51b81526004016102a890610b47565b60405180910390fd5b6001600160a01b0384811660009081526003602052604090205416156103195760405162461bcd60e51b815260206004820152601b60248201527f52546f6b656e202620756e6465726c79696e672065786973746564000000000060448201526064016102a8565b6001600160a01b03811661035c5760405162461bcd60e51b815260206004820152600a60248201526921636861696e6c696e6b60b01b60448201526064016102a8565b60008360405160200161036f9190610b0e565b60408051808303601f1901815291815281516020928301206001600160a01b0389811660008181526001958690529390932080546001600160a01b0319908116909417815593840180549093169089161790915591506103d084600a610bdf565b60038083019190915560028083019384556004830180546001600160a01b039687166001600160a01b031991821617909155600190930154851660009081526020928352604080822080549b9097169a85168b179096559354845290529190208054909116909417909355505050565b6040805160a08101825260008082526020820181905291810182905260608101829052608081019190915260008260405160200161047e9190610b0e565b60405160208183030381529060405280519060200120905061049f81610621565b9392505050565b6000546001600160a01b031633146104d05760405162461bcd60e51b81526004016102a890610b47565b6104da600061070c565b565b6000546001600160a01b031633146105065760405162461bcd60e51b81526004016102a890610b47565b6001600160a01b03811661056b5760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084016102a8565b6105748161070c565b50565b6001600160a01b038082166000908152600160205260408120600381015460048201549293919290916105aa911661075c565b6105bc90670de0b6b3a7640000610c97565b61049f9190610b7c565b60008061060884848080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525061044092505050565b9050610617816080015161075c565b9150505b92915050565b6040805160a0810182526000808252602082018190529181018290526060810182905260808101919091526000828152600260205260409020546001600160a01b0316806106aa5760405162461bcd60e51b81526020600482015260166024820152751d1bdad95b8818dbdb999a59c81b9bdd08199bdd5b9960521b60448201526064016102a8565b6001600160a01b03908116600090815260016020818152604092839020835160a0810185528154861681529281015485169183019190915260028101549282019290925260038201546060820152600490910154909116608082015292915050565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b60006001600160a01b03821661078257634e487b7160e01b600052600160045260246000fd5b60008290506000816001600160a01b031663feaf968c6040518163ffffffff1660e01b815260040160a06040518083038186803b1580156107c257600080fd5b505afa1580156107d6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107fa9190610a9e565b5050509150506000826001600160a01b031663313ce5676040518163ffffffff1660e01b815260040160206040518083038186803b15801561083b57600080fd5b505afa15801561084f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108739190610aed565b905061088081600a610beb565b610892670de0b6b3a764000084610c97565b61089c9190610b7c565b95945050505050565b600082601f8301126108b5578081fd5b813567ffffffffffffffff808211156108d0576108d0610ccc565b604051601f8301601f19908116603f011681019082821181831017156108f8576108f8610ccc565b81604052838152866020858801011115610910578485fd5b8360208701602083013792830160200193909352509392505050565b805169ffffffffffffffffffff8116811461094657600080fd5b919050565b60006020828403121561095c578081fd5b813561049f81610ce2565b600080600080600060a0868803121561097e578081fd5b853561098981610ce2565b9450602086013561099981610ce2565b9350604086013567ffffffffffffffff8111156109b4578182fd5b6109c0888289016108a5565b9350506060860135915060808601356109d881610ce2565b809150509295509295909350565b6000602082840312156109f7578081fd5b5035919050565b60008060208385031215610a10578182fd5b823567ffffffffffffffff80821115610a27578384fd5b818501915085601f830112610a3a578384fd5b813581811115610a48578485fd5b866020828501011115610a59578485fd5b60209290920196919550909350505050565b600060208284031215610a7c578081fd5b813567ffffffffffffffff811115610a92578182fd5b610617848285016108a5565b600080600080600060a08688031215610ab5578081fd5b610abe8661092c565b9450602086015193506040860151925060608601519150610ae16080870161092c565b90509295509295909350565b600060208284031215610afe578081fd5b815160ff8116811461049f578182fd5b60008251815b81811015610b2e5760208186018101518583015201610b14565b81811115610b3c5782828501525b509190910192915050565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b600082610b9757634e487b7160e01b81526012600452602481fd5b500490565b600181815b80851115610bd7578160001904821115610bbd57610bbd610cb6565b80851615610bca57918102915b93841c9390800290610ba1565b509250929050565b600061049f8383610bf6565b600061049f60ff8416835b600082610c055750600161061b565b81610c125750600061061b565b8160018114610c285760028114610c3257610c4e565b600191505061061b565b60ff841115610c4357610c43610cb6565b50506001821b61061b565b5060208310610133831016604e8410600b8410161715610c71575081810a61061b565b610c7b8383610b9c565b8060001904821115610c8f57610c8f610cb6565b029392505050565b6000816000190483118215151615610cb157610cb1610cb6565b500290565b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052604160045260246000fd5b6001600160a01b038116811461057457600080fdfea26469706673582212208e3f6040db8fe961c53efc9fb59de8b41f209a58819dbe14212f5cc5b3ceb41a64736f6c63430008040033
Age | Block | Fee Address | BC Fee Address | Voting Power | Jailed | Incoming |
---|
Make sure to use the "Vote Down" button for any spammy posts, and the "Vote Up" for interesting conversations.