Polygon Sponsored slots available. Book your slot here!
Contract Overview
My Name Tag:
Not Available, login to update
[ Download CSV Export ]
Contract Name:
ChainlinkOracle
Compiler Version
v0.7.4+commit.3f05b770
Optimization Enabled:
Yes with 200 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: agpl-3.0 pragma solidity 0.7.4; import "@openzeppelin/contracts/math/SafeMath.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; import "../libraries/PercentageMath.sol"; import "../interfaces/IERC20WithDecimal.sol"; contract ChainlinkOracle is Ownable { using SafeMath for uint256; using PercentageMath for uint256; uint256 priceSlippage = 50; // 0.5% mapping(address => address) public oracleFeed; constructor(address _owner) { transferOwnership(_owner); } // Calculates the lastest exchange rate // Uses both divide and multiply only for tokens not supported directly by Chainlink, for example MKR/USD function get( address inputToken, address outputToken, uint256 inputAmount ) public view returns (uint256 amountOut, uint256 amountOutWithSlippage) { uint256 price = uint256(1e36); require( oracleFeed[inputToken] != address(0), "Oracle feed doesn't exist for the input asset." ); require( oracleFeed[outputToken] != address(0), "Oracle feed doesn't exist for the output asset." ); if (inputToken != address(0)) { address inputFeedAddress = oracleFeed[inputToken]; price = price.mul( uint256(IAggregator(inputFeedAddress).latestAnswer()) ); } if (outputToken != address(0)) { address outputFeedAddress = oracleFeed[outputToken]; price = price / uint256(IAggregator(outputFeedAddress).latestAnswer()); } amountOut = price.mul(inputAmount) / uint256(1e36); if (outputToken != address(0)) amountOut = amountOut.mul( 10**IERC20WithDecimal(outputToken).decimals() ); if (inputToken != address(0)) amountOut = amountOut.div( 10**IERC20WithDecimal(inputToken).decimals() ); amountOutWithSlippage = amountOut.percentMul( uint256(10000).sub(priceSlippage) ); } function updateTokenFeed(address asset, address feed) external onlyOwner { oracleFeed[asset] = feed; } function updatePriceSlippage(uint256 newSlippage) external onlyOwner { priceSlippage = newSlippage; } } // Chainlink Aggregator interface IAggregator { function latestAnswer() external view returns (int256 answer); }
// SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMath { /** * @dev Returns the addition of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) { uint256 c = a + b; if (c < a) return (false, 0); return (true, c); } /** * @dev Returns the substraction of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b > a) return (false, 0); return (true, a - b); } /** * @dev Returns the multiplication of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) return (true, 0); uint256 c = a * b; if (c / a != b) return (false, 0); return (true, c); } /** * @dev Returns the division of two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b == 0) return (false, 0); return (true, a / b); } /** * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b == 0) return (false, 0); return (true, a % b); } /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { require(b <= a, "SafeMath: subtraction overflow"); return a - b; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { if (a == 0) return 0; uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers, reverting on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { require(b > 0, "SafeMath: division by zero"); return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { require(b > 0, "SafeMath: modulo by zero"); return a % b; } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {trySub}. * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); return a - b; } /** * @dev Returns the integer division of two unsigned integers, reverting with custom message on * division by zero. The result is rounded towards zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryDiv}. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting with custom message when dividing by zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryMod}. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); return a % b; } }
// SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <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 () internal { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), 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 { emit OwnershipTransferred(_owner, address(0)); _owner = 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"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } }
// SPDX-License-Identifier: agpl-3.0 pragma solidity 0.7.4; /** * @title PercentageMath library * @author Aave * @notice Provides functions to perform percentage calculations * @dev Percentages are defined by default with 2 decimals of precision (100.00). The precision is indicated by PERCENTAGE_FACTOR * @dev Operations are rounded half up **/ library PercentageMath { uint256 constant PERCENTAGE_FACTOR = 1e4; //percentage plus two decimals uint256 constant HALF_PERCENT = PERCENTAGE_FACTOR / 2; /** * @dev Executes a percentage multiplication * @param value The value of which the percentage needs to be calculated * @param percentage The percentage of the value to be calculated * @return The percentage of value **/ function percentMul(uint256 value, uint256 percentage) internal pure returns (uint256) { if (value == 0 || percentage == 0) { return 0; } require( value <= (type(uint256).max - HALF_PERCENT) / percentage, "PercentageMath: MATH_MULTIPLICATION_OVERFLOW" ); return (value * percentage + HALF_PERCENT) / PERCENTAGE_FACTOR; } /** * @dev Executes a percentage division * @param value The value of which the percentage needs to be calculated * @param percentage The percentage of the value to be calculated * @return The value divided the percentage **/ function percentDiv(uint256 value, uint256 percentage) internal pure returns (uint256) { require(percentage != 0, "PercentageMath: MATH_DIVISION_BY_ZERO"); uint256 halfPercentage = percentage / 2; require( value <= (type(uint256).max - halfPercentage) / PERCENTAGE_FACTOR, "PercentageMath: MATH_MULTIPLICATION_OVERFLOW" ); return (value * PERCENTAGE_FACTOR + halfPercentage) / percentage; } }
// SPDX-License-Identifier: MIT pragma solidity 0.7.4; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20WithDecimal { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the decimals of tokens in existence. */ function decimals() external view returns (uint8); /** * @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 `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, 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 `sender` to `recipient` 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 sender, address recipient, uint256 amount ) external returns (bool); /** * @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 ); }
// SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <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 GSN 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 payable) { return msg.sender; } function _msgData() internal view virtual returns (bytes memory) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } }
{ "optimizer": { "enabled": true, "runs": 200 }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "abi" ] } }, "libraries": {} }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"inputs":[{"internalType":"address","name":"_owner","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[{"internalType":"address","name":"inputToken","type":"address"},{"internalType":"address","name":"outputToken","type":"address"},{"internalType":"uint256","name":"inputAmount","type":"uint256"}],"name":"get","outputs":[{"internalType":"uint256","name":"amountOut","type":"uint256"},{"internalType":"uint256","name":"amountOutWithSlippage","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"oracleFeed","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newSlippage","type":"uint256"}],"name":"updatePriceSlippage","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"asset","type":"address"},{"internalType":"address","name":"feed","type":"address"}],"name":"updateTokenFeed","outputs":[],"stateMutability":"nonpayable","type":"function"}]
Contract Creation Code
6080604052603260015534801561001557600080fd5b50604051610c73380380610c738339818101604052602081101561003857600080fd5b5051600061004461008b565b600080546001600160a01b0319166001600160a01b038316908117825560405192935091600080516020610c53833981519152908290a3506100858161008f565b506101a0565b3390565b61009761008b565b6001600160a01b03166100a8610191565b6001600160a01b031614610103576040805162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015290519081900360640190fd5b6001600160a01b0381166101485760405162461bcd60e51b8152600401808060200182810382526026815260200180610c2d6026913960400191505060405180910390fd5b600080546040516001600160a01b0380851693921691600080516020610c5383398151915291a3600080546001600160a01b0319166001600160a01b0392909216919091179055565b6000546001600160a01b031690565b610a7e806101af6000396000f3fe608060405234801561001057600080fd5b506004361061007d5760003560e01c8063921357141161005b57806392135714146100ff578063b90ff23614610125578063bd22fb6014610153578063f2fde38b146101705761007d565b8063715018a6146100825780637373e4eb1461008c5780638da5cb5b146100db575b600080fd5b61008a610196565b005b6100c2600480360360608110156100a257600080fd5b506001600160a01b03813581169160208101359091169060400135610242565b6040805192835260208301919091528051918290030190f35b6100e3610597565b604080516001600160a01b039092168252519081900360200190f35b6100e36004803603602081101561011557600080fd5b50356001600160a01b03166105a6565b61008a6004803603604081101561013b57600080fd5b506001600160a01b03813581169160200135166105c1565b61008a6004803603602081101561016957600080fd5b5035610651565b61008a6004803603602081101561018657600080fd5b50356001600160a01b03166106b8565b61019e6107ba565b6001600160a01b03166101af610597565b6001600160a01b0316146101f8576040805162461bcd60e51b815260206004820181905260248201526000805160206109fa833981519152604482015290519081900360640190fd5b600080546040516001600160a01b03909116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600080546001600160a01b0319169055565b6001600160a01b03838116600090815260026020526040812054909182916ec097ce7bc90715b34b9f100000000091166102ad5760405162461bcd60e51b815260040180806020018281038252602e8152602001806109ab602e913960400191505060405180910390fd5b6001600160a01b03858116600090815260026020526040902054166103035760405162461bcd60e51b815260040180806020018281038252602f815260200180610a1a602f913960400191505060405180910390fd5b6001600160a01b0386161561039e576001600160a01b038087166000908152600260209081526040918290205482516350d25bcd60e01b8152925193169261039a9284926350d25bcd92600480840193829003018186803b15801561036757600080fd5b505afa15801561037b573d6000803e3d6000fd5b505050506040513d602081101561039157600080fd5b505183906107be565b9150505b6001600160a01b03851615610439576001600160a01b038086166000908152600260209081526040918290205482516350d25bcd60e01b8152925193169283926350d25bcd926004808301939192829003018186803b15801561040057600080fd5b505afa158015610414573d6000803e3d6000fd5b505050506040513d602081101561042a57600080fd5b5051828161043457fe5b049150505b6ec097ce7bc90715b34b9f100000000061045382866107be565b8161045a57fe5b0492506001600160a01b038516156104e4576104e1856001600160a01b031663313ce5676040518163ffffffff1660e01b815260040160206040518083038186803b1580156104a857600080fd5b505afa1580156104bc573d6000803e3d6000fd5b505050506040513d60208110156104d257600080fd5b5051849060ff16600a0a6107be565b92505b6001600160a01b0386161561056b57610568866001600160a01b031663313ce5676040518163ffffffff1660e01b815260040160206040518083038186803b15801561052f57600080fd5b505afa158015610543573d6000803e3d6000fd5b505050506040513d602081101561055957600080fd5b5051849060ff16600a0a610820565b92505b61058c61058560015461271061088790919063ffffffff16565b84906108e4565b915050935093915050565b6000546001600160a01b031690565b6002602052600090815260409020546001600160a01b031681565b6105c96107ba565b6001600160a01b03166105da610597565b6001600160a01b031614610623576040805162461bcd60e51b815260206004820181905260248201526000805160206109fa833981519152604482015290519081900360640190fd5b6001600160a01b03918216600090815260026020526040902080546001600160a01b03191691909216179055565b6106596107ba565b6001600160a01b031661066a610597565b6001600160a01b0316146106b3576040805162461bcd60e51b815260206004820181905260248201526000805160206109fa833981519152604482015290519081900360640190fd5b600155565b6106c06107ba565b6001600160a01b03166106d1610597565b6001600160a01b03161461071a576040805162461bcd60e51b815260206004820181905260248201526000805160206109fa833981519152604482015290519081900360640190fd5b6001600160a01b03811661075f5760405162461bcd60e51b81526004018080602001828103825260268152602001806109856026913960400191505060405180910390fd5b600080546040516001600160a01b03808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a3600080546001600160a01b0319166001600160a01b0392909216919091179055565b3390565b6000826107cd5750600061081a565b828202828482816107da57fe5b04146108175760405162461bcd60e51b81526004018080602001828103825260218152602001806109d96021913960400191505060405180910390fd5b90505b92915050565b6000808211610876576040805162461bcd60e51b815260206004820152601a60248201527f536166654d6174683a206469766973696f6e206279207a65726f000000000000604482015290519081900360640190fd5b81838161087f57fe5b049392505050565b6000828211156108de576040805162461bcd60e51b815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b50900390565b60008215806108f1575081155b156108fe5750600061081a565b81611388198161090a57fe5b048311156109495760405162461bcd60e51b815260040180806020018281038252602c815260200180610959602c913960400191505060405180910390fd5b6127108383026113880161087f56fe50657263656e746167654d6174683a204d4154485f4d554c5449504c49434154494f4e5f4f564552464c4f574f776e61626c653a206e6577206f776e657220697320746865207a65726f20616464726573734f7261636c65206665656420646f65736e277420657869737420666f722074686520696e7075742061737365742e536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f774f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65724f7261636c65206665656420646f65736e277420657869737420666f7220746865206f75747075742061737365742ea264697066735822122028e8f5775727ed0e21481c9c243111894a19896e05e5f42a0d6be95b9fce606764736f6c634300070400334f776e61626c653a206e6577206f776e657220697320746865207a65726f20616464726573738be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e00000000000000000000000003a893a7525c4263052c3c04f9c32d919c75cb8e0
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
0000000000000000000000003a893a7525c4263052c3c04f9c32d919c75cb8e0
-----Decoded View---------------
Arg [0] : _owner (address): 0x3a893a7525c4263052c3c04f9c32d919c75cb8e0
-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 0000000000000000000000003a893a7525c4263052c3c04f9c32d919c75cb8e0
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.