Feature Tip: Add private address tag to any address under My Name Tag !
Overview
ETH Balance
0 ETH
Eth Value
$0.00More Info
Private Name Tags
ContractCreator
View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Loading...
Loading
Contract Source Code Verified (Exact Match)
Contract Name:
PriceRouter
Compiler Version
v0.8.16+commit.07a7930e
Optimization Enabled:
Yes with 200 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.16; import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol"; import { FeedRegistryInterface } from "@chainlink/contracts/src/v0.8/interfaces/FeedRegistryInterface.sol"; import { AggregatorV2V3Interface } from "@chainlink/contracts/src/v0.8/interfaces/AggregatorV2V3Interface.sol"; import { IChainlinkAggregator } from "src/interfaces/external/IChainlinkAggregator.sol"; import { Denominations } from "@chainlink/contracts/src/v0.8/Denominations.sol"; import { SafeCast } from "@openzeppelin/contracts/utils/math/SafeCast.sol"; import { Math } from "src/utils/Math.sol"; /** * @title Sommelier Price Router * @notice Provides a universal interface allowing Sommelier contracts to retrieve secure pricing * data from Chainlink. * @author crispymangoes, Brian Le */ contract PriceRouter is Ownable { using SafeERC20 for ERC20; using SafeCast for int256; using Math for uint256; event AddAsset(address indexed asset); // =========================================== ASSETS CONFIG =========================================== /** * @param minPrice minimum price in USD for the asset before reverting * @param maxPrice maximum price in USD for the asset before reverting * @param isPriceRangeInETH if true price range values are given in ETH, if false price range is given in USD * @param heartbeat maximum allowed time that can pass with no update before price data is considered stale * @param isSupported whether this asset is supported by the platform or not */ struct AssetConfig { uint256 minPrice; uint256 maxPrice; bool isPriceRangeInETH; uint96 heartbeat; bool isSupported; } /** * @notice Get the asset data for a given asset. */ mapping(ERC20 => AssetConfig) public getAssetConfig; uint96 public constant DEFAULT_HEART_BEAT = 1 days; // ======================================= ADAPTOR OPERATIONS ======================================= /** * @notice Attempted to set a minimum price below the Chainlink minimum price (with buffer). * @param minPrice minimum price attempted to set * @param bufferedMinPrice minimum price that can be set including buffer */ error PriceRouter__InvalidMinPrice(uint256 minPrice, uint256 bufferedMinPrice); /** * @notice Attempted to set a maximum price above the Chainlink maximum price (with buffer). * @param maxPrice maximum price attempted to set * @param bufferedMaxPrice maximum price that can be set including buffer */ error PriceRouter__InvalidMaxPrice(uint256 maxPrice, uint256 bufferedMaxPrice); /** * @notice Attempted to add an invalid asset. * @param asset address of the invalid asset */ error PriceRouter__InvalidAsset(address asset); /** * @notice Attempted to add an asset with a certain price range denomination, but actual denomination was different. * @param expected price range denomination * @param actual price range denomination * @dev If an asset has price feeds in USD and ETH, the feed in USD is favored */ error PriceRouter__PriceRangeDenominationMisMatch(bool expected, bool actual); /** * @notice Attempted to add an asset with invalid min/max prices. * @param min price * @param max price */ error PriceRouter__MinPriceGreaterThanMaxPrice(uint256 min, uint256 max); /** * @notice Add an asset for the price router to support. * @param asset address of asset to support on the platform * @param minPrice minimum price in USD with 8 decimals for the asset before reverting, * set to `0` to use Chainlink's default * @param maxPrice maximum price in USD with 8 decimals for the asset before reverting, * set to `0` to use Chainlink's default * @param heartbeat maximum amount of time that can pass without the price data being updated * before reverting, set to `0` to use the default of 1 day */ function addAsset( ERC20 asset, uint256 minPrice, uint256 maxPrice, bool rangeInETH, uint96 heartbeat ) external onlyOwner { if (address(asset) == address(0)) revert PriceRouter__InvalidAsset(address(asset)); // Use Chainlink to get the min and max of the asset. ERC20 assetToQuery = _remap(asset); (uint256 minFromChainklink, uint256 maxFromChainlink, bool isETH) = _getPriceRange(assetToQuery); // Check if callers expected price range denomination matches actual. if (rangeInETH != isETH) revert PriceRouter__PriceRangeDenominationMisMatch(rangeInETH, isETH); // Add a ~10% buffer to minimum and maximum price from Chainlink because Chainlink can stop updating // its price before/above the min/max price. uint256 bufferedMinPrice = minFromChainklink.mulWadDown(1.1e18); uint256 bufferedMaxPrice = maxFromChainlink.mulWadDown(0.9e18); if (minPrice == 0) { minPrice = bufferedMinPrice; } else { if (minPrice < bufferedMinPrice) revert PriceRouter__InvalidMinPrice(minPrice, bufferedMinPrice); } if (maxPrice == 0) { maxPrice = bufferedMaxPrice; } else { if (maxPrice > bufferedMaxPrice) revert PriceRouter__InvalidMaxPrice(maxPrice, bufferedMaxPrice); } if (minPrice >= maxPrice) revert PriceRouter__MinPriceGreaterThanMaxPrice(minPrice, maxPrice); getAssetConfig[asset] = AssetConfig({ minPrice: minPrice, maxPrice: maxPrice, isPriceRangeInETH: isETH, heartbeat: heartbeat != 0 ? heartbeat : DEFAULT_HEART_BEAT, isSupported: true }); emit AddAsset(address(asset)); } function isSupported(ERC20 asset) external view returns (bool) { return getAssetConfig[asset].isSupported; } // ======================================= PRICING OPERATIONS ======================================= /** * @notice Get the value of an asset in terms of another asset. * @param baseAsset address of the asset to get the price of in terms of the quote asset * @param amount amount of the base asset to price * @param quoteAsset address of the asset that the base asset is priced in terms of * @return value value of the amount of base assets specified in terms of the quote asset */ function getValue( ERC20 baseAsset, uint256 amount, ERC20 quoteAsset ) external view returns (uint256 value) { value = amount.mulDivDown(getExchangeRate(baseAsset, quoteAsset), 10**baseAsset.decimals()); } /** * @notice Attempted an operation with arrays of unequal lengths that were expected to be equal length. */ error PriceRouter__LengthMismatch(); /** * @notice Get the total value of multiple assets in terms of another asset. * @param baseAssets addresses of the assets to get the price of in terms of the quote asset * @param amounts amounts of each base asset to price * @param quoteAsset address of the assets that the base asset is priced in terms of * @return value total value of the amounts of each base assets specified in terms of the quote asset */ function getValues( ERC20[] memory baseAssets, uint256[] memory amounts, ERC20 quoteAsset ) external view returns (uint256 value) { uint256 numOfAssets = baseAssets.length; if (numOfAssets != amounts.length) revert PriceRouter__LengthMismatch(); uint8 quoteAssetDecimals = quoteAsset.decimals(); for (uint256 i; i < numOfAssets; i++) { ERC20 baseAsset = baseAssets[i]; value += amounts[i].mulDivDown( _getExchangeRate(baseAsset, quoteAsset, quoteAssetDecimals), 10**baseAsset.decimals() ); } } /** * @notice Get the exchange rate between two assets. * @param baseAsset address of the asset to get the exchange rate of in terms of the quote asset * @param quoteAsset address of the asset that the base asset is exchanged for * @return exchangeRate rate of exchange between the base asset and the quote asset */ function getExchangeRate(ERC20 baseAsset, ERC20 quoteAsset) public view returns (uint256 exchangeRate) { exchangeRate = _getExchangeRate(baseAsset, quoteAsset, quoteAsset.decimals()); } /** * @notice Get the exchange rates between multiple assets and another asset. * @param baseAssets addresses of the assets to get the exchange rates of in terms of the quote asset * @param quoteAsset address of the asset that the base assets are exchanged for * @return exchangeRates rate of exchange between the base assets and the quote asset */ function getExchangeRates(ERC20[] memory baseAssets, ERC20 quoteAsset) external view returns (uint256[] memory exchangeRates) { uint8 quoteAssetDecimals = quoteAsset.decimals(); uint256 numOfAssets = baseAssets.length; exchangeRates = new uint256[](numOfAssets); for (uint256 i; i < numOfAssets; i++) exchangeRates[i] = _getExchangeRate(baseAssets[i], quoteAsset, quoteAssetDecimals); } /** * @notice Get the minimum and maximum valid price for an asset. * @param asset address of the asset to get the price range of * @return min minimum valid price for the asset * @return max maximum valid price for the asset */ function getPriceRange(ERC20 asset) public view returns ( uint256 min, uint256 max, bool isETH ) { AssetConfig memory config = getAssetConfig[asset]; if (!config.isSupported) revert PriceRouter__UnsupportedAsset(address(asset)); (min, max, isETH) = (config.minPrice, config.maxPrice, config.isPriceRangeInETH); } /** * @notice Get the minimum and maximum valid prices for an asset. * @param _assets addresses of the assets to get the price ranges for * @return min minimum valid price for each asset * @return max maximum valid price for each asset */ function getPriceRanges(ERC20[] memory _assets) external view returns ( uint256[] memory min, uint256[] memory max, bool[] memory isETH ) { uint256 numOfAssets = _assets.length; (min, max, isETH) = (new uint256[](numOfAssets), new uint256[](numOfAssets), new bool[](numOfAssets)); for (uint256 i; i < numOfAssets; i++) (min[i], max[i], isETH[i]) = getPriceRange(_assets[i]); } // =========================================== HELPER FUNCTIONS =========================================== ERC20 private constant WETH = ERC20(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2); ERC20 private constant WBTC = ERC20(0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599); function _remap(ERC20 asset) internal pure returns (ERC20) { if (asset == WETH) return ERC20(Denominations.ETH); if (asset == WBTC) return ERC20(Denominations.BTC); return asset; } /** * @notice Gets the exchange rate between a base and a quote asset * @param baseAsset the asset to convert into quoteAsset * @param quoteAsset the asset base asset is converted into * @return exchangeRate value of base asset in terms of quote asset */ function _getExchangeRate( ERC20 baseAsset, ERC20 quoteAsset, uint8 quoteAssetDecimals ) internal view returns (uint256 exchangeRate) { exchangeRate = getValueInUSD(baseAsset).mulDivDown(10**quoteAssetDecimals, getValueInUSD(quoteAsset)); } /** * @notice Attempted to update the asset to one that is not supported by the platform. * @param asset address of the unsupported asset */ error PriceRouter__UnsupportedAsset(address asset); /** * @notice Attempted an operation to price an asset that under its minimum valid price. * @param asset address of the asset that is under its minimum valid price * @param price price of the asset * @param minPrice minimum valid price of the asset */ error PriceRouter__AssetBelowMinPrice(address asset, uint256 price, uint256 minPrice); /** * @notice Attempted an operation to price an asset that under its maximum valid price. * @param asset address of the asset that is under its maximum valid price * @param price price of the asset * @param maxPrice maximum valid price of the asset */ error PriceRouter__AssetAboveMaxPrice(address asset, uint256 price, uint256 maxPrice); /** * @notice Attempted to fetch a price for an asset that has not been updated in too long. * @param asset address of the asset thats price is stale * @param timeSinceLastUpdate seconds since the last price update * @param heartbeat maximum allowed time between price updates */ error PriceRouter__StalePrice(address asset, uint256 timeSinceLastUpdate, uint256 heartbeat); // =========================================== CHAINLINK PRICING FUNCTIONS ===========================================\ /** * @notice Feed Registry contract used to get chainlink data feeds, use getFeed!! */ FeedRegistryInterface public constant feedRegistry = FeedRegistryInterface(0x47Fb2585D2C56Fe188D0E6ec628a38b74fCeeeDf); /** * @notice Could not find an asset's price in USD or ETH. * @param asset address of the asset */ error PriceRouter__PriceNotAvailable(address asset); /** * @notice Interacts with Chainlink feed registry and first tries to get `asset` price in USD, * if that fails, then it tries to get `asset` price in ETH, and then converts the answer into USD. * @param asset the ERC20 token to get the price of. * @return price the price of `asset` in USD */ function getValueInUSD(ERC20 asset) public view returns (uint256 price) { AssetConfig memory config = getAssetConfig[asset]; // Make sure asset is supported. if (!config.isSupported) revert PriceRouter__UnsupportedAsset(address(asset)); // Remap asset if need be. asset = _remap(asset); if (!config.isPriceRangeInETH) { // Price feed is in USD. (, int256 _price, , uint256 _timestamp, ) = feedRegistry.latestRoundData(address(asset), Denominations.USD); price = _price.toUint256(); _checkPriceFeed(asset, price, _timestamp, config); } else { // Price feed is in ETH. (, int256 _price, , uint256 _timestamp, ) = feedRegistry.latestRoundData(address(asset), Denominations.ETH); price = _price.toUint256(); _checkPriceFeed(asset, price, _timestamp, config); // Convert price from ETH to USD. price = _price.toUint256().mulWadDown(_getExchangeRateFromETHToUSD()); } } /** * @notice Could not find an asset's price range in USD or ETH. * @param asset address of the asset */ error PriceRouter__PriceRangeNotAvailable(address asset); /** * @notice Interacts with Chainlink feed registry and first tries to get `asset` price range in USD, * if that fails, then it tries to get `asset` price range in ETH, and then converts the range into USD. * @param asset the ERC20 token to get the price range of. * @return min the minimum price where Chainlink nodes stop updating the oracle * @return max the maximum price where Chainlink nodes stop updating the oracle */ function _getPriceRange(ERC20 asset) internal view returns ( uint256 min, uint256 max, bool isETH ) { try feedRegistry.getFeed(address(asset), Denominations.USD) returns (AggregatorV2V3Interface aggregator) { IChainlinkAggregator chainlinkAggregator = IChainlinkAggregator(address(aggregator)); min = uint256(uint192(chainlinkAggregator.minAnswer())); max = uint256(uint192(chainlinkAggregator.maxAnswer())); isETH = false; } catch { // If we can't find the USD price, then try the ETH price. try feedRegistry.getFeed(address(asset), Denominations.ETH) returns (AggregatorV2V3Interface aggregator) { IChainlinkAggregator chainlinkAggregator = IChainlinkAggregator(address(aggregator)); min = uint256(uint192(chainlinkAggregator.minAnswer())); max = uint256(uint192(chainlinkAggregator.maxAnswer())); isETH = true; } catch { revert PriceRouter__PriceRangeNotAvailable(address(asset)); } } } /** * @notice helper function to grab pricing data for ETH in USD * @return exchangeRate the exchange rate for ETH in terms of USD * @dev It is inefficient to re-calculate _checkPriceFeed for ETH -> USD multiple times for a single TX, * but this is done in the explicit way because it is simpler and less prone to logic errors. */ function _getExchangeRateFromETHToUSD() internal view returns (uint256 exchangeRate) { (, int256 _price, , uint256 _timestamp, ) = feedRegistry.latestRoundData(Denominations.ETH, Denominations.USD); exchangeRate = _price.toUint256(); _checkPriceFeed(WETH, exchangeRate, _timestamp, getAssetConfig[WETH]); } /** * @notice helper function to validate a price feed is safe to use. * @param asset ERC20 asset price feed data is for. * @param value the price value the price feed gave. * @param timestamp the last timestamp the price feed was updated. * @param config the assets config storing min price, max price, and heartbeat requirements. */ function _checkPriceFeed( ERC20 asset, uint256 value, uint256 timestamp, AssetConfig memory config ) internal view { uint256 minPrice = config.minPrice; if (value < minPrice) revert PriceRouter__AssetBelowMinPrice(address(asset), value, minPrice); uint256 maxPrice = config.maxPrice; if (value > maxPrice) revert PriceRouter__AssetAboveMaxPrice(address(asset), value, maxPrice); uint256 heartbeat = config.heartbeat; uint256 timeSinceLastUpdate = block.timestamp - timestamp; if (timeSinceLastUpdate > heartbeat) revert PriceRouter__StalePrice(address(asset), timeSinceLastUpdate, heartbeat); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/ERC20.sol) pragma solidity ^0.8.0; import "./IERC20.sol"; import "./extensions/IERC20Metadata.sol"; import "../../utils/Context.sol"; /** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin Contracts guidelines: functions revert * instead returning `false` on failure. This behavior is nonetheless * conventional and does not conflict with the expectations of ERC20 * applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */ contract ERC20 is Context, IERC20, IERC20Metadata { mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; /** * @dev Sets the values for {name} and {symbol}. * * The default value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5.05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overridden; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `to` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address to, uint256 amount) public virtual override returns (bool) { address owner = _msgSender(); _transfer(owner, to, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on * `transferFrom`. This is semantically equivalent to an infinite approval. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { address owner = _msgSender(); _approve(owner, spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * NOTE: Does not update the allowance if the current allowance * is the maximum `uint256`. * * Requirements: * * - `from` and `to` cannot be the zero address. * - `from` must have a balance of at least `amount`. * - the caller must have allowance for ``from``'s tokens of at least * `amount`. */ function transferFrom( address from, address to, uint256 amount ) public virtual override returns (bool) { address spender = _msgSender(); _spendAllowance(from, spender, amount); _transfer(from, to, amount); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { address owner = _msgSender(); _approve(owner, spender, allowance(owner, spender) + addedValue); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { address owner = _msgSender(); uint256 currentAllowance = allowance(owner, spender); require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); unchecked { _approve(owner, spender, currentAllowance - subtractedValue); } return true; } /** * @dev Moves `amount` of tokens from `from` to `to`. * * This internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `from` must have a balance of at least `amount`. */ function _transfer( address from, address to, uint256 amount ) internal virtual { require(from != address(0), "ERC20: transfer from the zero address"); require(to != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(from, to, amount); uint256 fromBalance = _balances[from]; require(fromBalance >= amount, "ERC20: transfer amount exceeds balance"); unchecked { _balances[from] = fromBalance - amount; } _balances[to] += amount; emit Transfer(from, to, amount); _afterTokenTransfer(from, to, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply += amount; _balances[account] += amount; emit Transfer(address(0), account, amount); _afterTokenTransfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); unchecked { _balances[account] = accountBalance - amount; } _totalSupply -= amount; emit Transfer(account, address(0), amount); _afterTokenTransfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve( address owner, address spender, uint256 amount ) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Updates `owner` s allowance for `spender` based on spent `amount`. * * Does not update the allowance amount in case of infinite allowance. * Revert if not enough allowance is available. * * Might emit an {Approval} event. */ function _spendAllowance( address owner, address spender, uint256 amount ) internal virtual { uint256 currentAllowance = allowance(owner, spender); if (currentAllowance != type(uint256).max) { require(currentAllowance >= amount, "ERC20: insufficient allowance"); unchecked { _approve(owner, spender, currentAllowance - amount); } } } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 amount ) internal virtual {} /** * @dev Hook that is called after any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * has been transferred to `to`. * - when `from` is zero, `amount` tokens have been minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens have been burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _afterTokenTransfer( address from, address to, uint256 amount ) internal virtual {} }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC20/utils/SafeERC20.sol) pragma solidity ^0.8.0; import "../IERC20.sol"; import "../../../utils/Address.sol"; /** * @title SafeERC20 * @dev Wrappers around ERC20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20 { using Address for address; function safeTransfer( IERC20 token, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom( IERC20 token, address from, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } /** * @dev Deprecated. This function has issues similar to the ones found in * {IERC20-approve}, and its usage is discouraged. * * Whenever possible, use {safeIncreaseAllowance} and * {safeDecreaseAllowance} instead. */ function safeApprove( IERC20 token, address spender, uint256 value ) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' require( (value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function safeIncreaseAllowance( IERC20 token, address spender, uint256 value ) internal { uint256 newAllowance = token.allowance(address(this), spender) + value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } function safeDecreaseAllowance( IERC20 token, address spender, uint256 value ) internal { unchecked { uint256 oldAllowance = token.allowance(address(this), spender); require(oldAllowance >= value, "SafeERC20: decreased allowance below zero"); uint256 newAllowance = oldAllowance - value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */ function _callOptionalReturn(IERC20 token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that // the target address contains contract code and also asserts for success in the low-level call. bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/Ownable.sol) 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() { _transferOwnership(_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 { _transferOwnership(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"); _transferOwnership(newOwner); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Internal function without access restriction. */ function _transferOwnership(address newOwner) internal virtual { address oldOwner = _owner; _owner = newOwner; emit OwnershipTransferred(oldOwner, newOwner); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; pragma abicoder v2; import "./AggregatorV2V3Interface.sol"; interface FeedRegistryInterface { struct Phase { uint16 phaseId; uint80 startingAggregatorRoundId; uint80 endingAggregatorRoundId; } event FeedProposed( address indexed asset, address indexed denomination, address indexed proposedAggregator, address currentAggregator, address sender ); event FeedConfirmed( address indexed asset, address indexed denomination, address indexed latestAggregator, address previousAggregator, uint16 nextPhaseId, address sender ); // V3 AggregatorV3Interface function decimals(address base, address quote) external view returns (uint8); function description(address base, address quote) external view returns (string memory); function version(address base, address quote) external view returns (uint256); function latestRoundData(address base, address quote) external view returns ( uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound ); function getRoundData( address base, address quote, uint80 _roundId ) external view returns ( uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound ); // V2 AggregatorInterface function latestAnswer(address base, address quote) external view returns (int256 answer); function latestTimestamp(address base, address quote) external view returns (uint256 timestamp); function latestRound(address base, address quote) external view returns (uint256 roundId); function getAnswer( address base, address quote, uint256 roundId ) external view returns (int256 answer); function getTimestamp( address base, address quote, uint256 roundId ) external view returns (uint256 timestamp); // Registry getters function getFeed(address base, address quote) external view returns (AggregatorV2V3Interface aggregator); function getPhaseFeed( address base, address quote, uint16 phaseId ) external view returns (AggregatorV2V3Interface aggregator); function isFeedEnabled(address aggregator) external view returns (bool); function getPhase( address base, address quote, uint16 phaseId ) external view returns (Phase memory phase); // Round helpers function getRoundFeed( address base, address quote, uint80 roundId ) external view returns (AggregatorV2V3Interface aggregator); function getPhaseRange( address base, address quote, uint16 phaseId ) external view returns (uint80 startingRoundId, uint80 endingRoundId); function getPreviousRoundId( address base, address quote, uint80 roundId ) external view returns (uint80 previousRoundId); function getNextRoundId( address base, address quote, uint80 roundId ) external view returns (uint80 nextRoundId); // Feed management function proposeFeed( address base, address quote, address aggregator ) external; function confirmFeed( address base, address quote, address aggregator ) external; // Proposed aggregator function getProposedFeed(address base, address quote) external view returns (AggregatorV2V3Interface proposedAggregator); function proposedGetRoundData( address base, address quote, uint80 roundId ) external view returns ( uint80 id, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound ); function proposedLatestRoundData(address base, address quote) external view returns ( uint80 id, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound ); // Phases function getCurrentPhaseId(address base, address quote) external view returns (uint16 currentPhaseId); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; import "./AggregatorInterface.sol"; import "./AggregatorV3Interface.sol"; interface AggregatorV2V3Interface is AggregatorInterface, AggregatorV3Interface {}
// SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.16; import "@chainlink/contracts/src/v0.8/interfaces/AggregatorV2V3Interface.sol"; interface IChainlinkAggregator is AggregatorV2V3Interface { function maxAnswer() external view returns (int192); function minAnswer() external view returns (int192); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; library Denominations { address public constant ETH = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; address public constant BTC = 0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB; // Fiat currencies follow https://en.wikipedia.org/wiki/ISO_4217 address public constant USD = address(840); address public constant GBP = address(826); address public constant EUR = address(978); address public constant JPY = address(392); address public constant KRW = address(410); address public constant CNY = address(156); address public constant AUD = address(36); address public constant CAD = address(124); address public constant CHF = address(756); address public constant ARS = address(32); address public constant PHP = address(608); address public constant NZD = address(554); address public constant SGD = address(702); address public constant NGN = address(566); address public constant ZAR = address(710); address public constant RUB = address(643); address public constant INR = address(356); address public constant BRL = address(986); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.4.1) (utils/math/SafeCast.sol) pragma solidity ^0.8.0; /** * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow * checks. * * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can * easily result in undesired exploitation or bugs, since developers usually * assume that overflows raise errors. `SafeCast` restores this intuition by * reverting the transaction when such 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. * * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing * all math on `uint256` and `int256` and then downcasting. */ library SafeCast { /** * @dev Returns the downcasted uint248 from uint256, reverting on * overflow (when the input is greater than largest uint248). * * Counterpart to Solidity's `uint248` operator. * * Requirements: * * - input must fit into 248 bits * * _Available since v4.7._ */ function toUint248(uint256 value) internal pure returns (uint248) { require(value <= type(uint248).max, "SafeCast: value doesn't fit in 248 bits"); return uint248(value); } /** * @dev Returns the downcasted uint240 from uint256, reverting on * overflow (when the input is greater than largest uint240). * * Counterpart to Solidity's `uint240` operator. * * Requirements: * * - input must fit into 240 bits * * _Available since v4.7._ */ function toUint240(uint256 value) internal pure returns (uint240) { require(value <= type(uint240).max, "SafeCast: value doesn't fit in 240 bits"); return uint240(value); } /** * @dev Returns the downcasted uint232 from uint256, reverting on * overflow (when the input is greater than largest uint232). * * Counterpart to Solidity's `uint232` operator. * * Requirements: * * - input must fit into 232 bits * * _Available since v4.7._ */ function toUint232(uint256 value) internal pure returns (uint232) { require(value <= type(uint232).max, "SafeCast: value doesn't fit in 232 bits"); return uint232(value); } /** * @dev Returns the downcasted uint224 from uint256, reverting on * overflow (when the input is greater than largest uint224). * * Counterpart to Solidity's `uint224` operator. * * Requirements: * * - input must fit into 224 bits * * _Available since v4.2._ */ function toUint224(uint256 value) internal pure returns (uint224) { require(value <= type(uint224).max, "SafeCast: value doesn't fit in 224 bits"); return uint224(value); } /** * @dev Returns the downcasted uint216 from uint256, reverting on * overflow (when the input is greater than largest uint216). * * Counterpart to Solidity's `uint216` operator. * * Requirements: * * - input must fit into 216 bits * * _Available since v4.7._ */ function toUint216(uint256 value) internal pure returns (uint216) { require(value <= type(uint216).max, "SafeCast: value doesn't fit in 216 bits"); return uint216(value); } /** * @dev Returns the downcasted uint208 from uint256, reverting on * overflow (when the input is greater than largest uint208). * * Counterpart to Solidity's `uint208` operator. * * Requirements: * * - input must fit into 208 bits * * _Available since v4.7._ */ function toUint208(uint256 value) internal pure returns (uint208) { require(value <= type(uint208).max, "SafeCast: value doesn't fit in 208 bits"); return uint208(value); } /** * @dev Returns the downcasted uint200 from uint256, reverting on * overflow (when the input is greater than largest uint200). * * Counterpart to Solidity's `uint200` operator. * * Requirements: * * - input must fit into 200 bits * * _Available since v4.7._ */ function toUint200(uint256 value) internal pure returns (uint200) { require(value <= type(uint200).max, "SafeCast: value doesn't fit in 200 bits"); return uint200(value); } /** * @dev Returns the downcasted uint192 from uint256, reverting on * overflow (when the input is greater than largest uint192). * * Counterpart to Solidity's `uint192` operator. * * Requirements: * * - input must fit into 192 bits * * _Available since v4.7._ */ function toUint192(uint256 value) internal pure returns (uint192) { require(value <= type(uint192).max, "SafeCast: value doesn't fit in 192 bits"); return uint192(value); } /** * @dev Returns the downcasted uint184 from uint256, reverting on * overflow (when the input is greater than largest uint184). * * Counterpart to Solidity's `uint184` operator. * * Requirements: * * - input must fit into 184 bits * * _Available since v4.7._ */ function toUint184(uint256 value) internal pure returns (uint184) { require(value <= type(uint184).max, "SafeCast: value doesn't fit in 184 bits"); return uint184(value); } /** * @dev Returns the downcasted uint176 from uint256, reverting on * overflow (when the input is greater than largest uint176). * * Counterpart to Solidity's `uint176` operator. * * Requirements: * * - input must fit into 176 bits * * _Available since v4.7._ */ function toUint176(uint256 value) internal pure returns (uint176) { require(value <= type(uint176).max, "SafeCast: value doesn't fit in 176 bits"); return uint176(value); } /** * @dev Returns the downcasted uint168 from uint256, reverting on * overflow (when the input is greater than largest uint168). * * Counterpart to Solidity's `uint168` operator. * * Requirements: * * - input must fit into 168 bits * * _Available since v4.7._ */ function toUint168(uint256 value) internal pure returns (uint168) { require(value <= type(uint168).max, "SafeCast: value doesn't fit in 168 bits"); return uint168(value); } /** * @dev Returns the downcasted uint160 from uint256, reverting on * overflow (when the input is greater than largest uint160). * * Counterpart to Solidity's `uint160` operator. * * Requirements: * * - input must fit into 160 bits * * _Available since v4.7._ */ function toUint160(uint256 value) internal pure returns (uint160) { require(value <= type(uint160).max, "SafeCast: value doesn't fit in 160 bits"); return uint160(value); } /** * @dev Returns the downcasted uint152 from uint256, reverting on * overflow (when the input is greater than largest uint152). * * Counterpart to Solidity's `uint152` operator. * * Requirements: * * - input must fit into 152 bits * * _Available since v4.7._ */ function toUint152(uint256 value) internal pure returns (uint152) { require(value <= type(uint152).max, "SafeCast: value doesn't fit in 152 bits"); return uint152(value); } /** * @dev Returns the downcasted uint144 from uint256, reverting on * overflow (when the input is greater than largest uint144). * * Counterpart to Solidity's `uint144` operator. * * Requirements: * * - input must fit into 144 bits * * _Available since v4.7._ */ function toUint144(uint256 value) internal pure returns (uint144) { require(value <= type(uint144).max, "SafeCast: value doesn't fit in 144 bits"); return uint144(value); } /** * @dev Returns the downcasted uint136 from uint256, reverting on * overflow (when the input is greater than largest uint136). * * Counterpart to Solidity's `uint136` operator. * * Requirements: * * - input must fit into 136 bits * * _Available since v4.7._ */ function toUint136(uint256 value) internal pure returns (uint136) { require(value <= type(uint136).max, "SafeCast: value doesn't fit in 136 bits"); return uint136(value); } /** * @dev Returns the downcasted uint128 from uint256, reverting on * overflow (when the input is greater than largest uint128). * * Counterpart to Solidity's `uint128` operator. * * Requirements: * * - input must fit into 128 bits * * _Available since v2.5._ */ function toUint128(uint256 value) internal pure returns (uint128) { require(value <= type(uint128).max, "SafeCast: value doesn't fit in 128 bits"); return uint128(value); } /** * @dev Returns the downcasted uint120 from uint256, reverting on * overflow (when the input is greater than largest uint120). * * Counterpart to Solidity's `uint120` operator. * * Requirements: * * - input must fit into 120 bits * * _Available since v4.7._ */ function toUint120(uint256 value) internal pure returns (uint120) { require(value <= type(uint120).max, "SafeCast: value doesn't fit in 120 bits"); return uint120(value); } /** * @dev Returns the downcasted uint112 from uint256, reverting on * overflow (when the input is greater than largest uint112). * * Counterpart to Solidity's `uint112` operator. * * Requirements: * * - input must fit into 112 bits * * _Available since v4.7._ */ function toUint112(uint256 value) internal pure returns (uint112) { require(value <= type(uint112).max, "SafeCast: value doesn't fit in 112 bits"); return uint112(value); } /** * @dev Returns the downcasted uint104 from uint256, reverting on * overflow (when the input is greater than largest uint104). * * Counterpart to Solidity's `uint104` operator. * * Requirements: * * - input must fit into 104 bits * * _Available since v4.7._ */ function toUint104(uint256 value) internal pure returns (uint104) { require(value <= type(uint104).max, "SafeCast: value doesn't fit in 104 bits"); return uint104(value); } /** * @dev Returns the downcasted uint96 from uint256, reverting on * overflow (when the input is greater than largest uint96). * * Counterpart to Solidity's `uint96` operator. * * Requirements: * * - input must fit into 96 bits * * _Available since v4.2._ */ function toUint96(uint256 value) internal pure returns (uint96) { require(value <= type(uint96).max, "SafeCast: value doesn't fit in 96 bits"); return uint96(value); } /** * @dev Returns the downcasted uint88 from uint256, reverting on * overflow (when the input is greater than largest uint88). * * Counterpart to Solidity's `uint88` operator. * * Requirements: * * - input must fit into 88 bits * * _Available since v4.7._ */ function toUint88(uint256 value) internal pure returns (uint88) { require(value <= type(uint88).max, "SafeCast: value doesn't fit in 88 bits"); return uint88(value); } /** * @dev Returns the downcasted uint80 from uint256, reverting on * overflow (when the input is greater than largest uint80). * * Counterpart to Solidity's `uint80` operator. * * Requirements: * * - input must fit into 80 bits * * _Available since v4.7._ */ function toUint80(uint256 value) internal pure returns (uint80) { require(value <= type(uint80).max, "SafeCast: value doesn't fit in 80 bits"); return uint80(value); } /** * @dev Returns the downcasted uint72 from uint256, reverting on * overflow (when the input is greater than largest uint72). * * Counterpart to Solidity's `uint72` operator. * * Requirements: * * - input must fit into 72 bits * * _Available since v4.7._ */ function toUint72(uint256 value) internal pure returns (uint72) { require(value <= type(uint72).max, "SafeCast: value doesn't fit in 72 bits"); return uint72(value); } /** * @dev Returns the downcasted uint64 from uint256, reverting on * overflow (when the input is greater than largest uint64). * * Counterpart to Solidity's `uint64` operator. * * Requirements: * * - input must fit into 64 bits * * _Available since v2.5._ */ function toUint64(uint256 value) internal pure returns (uint64) { require(value <= type(uint64).max, "SafeCast: value doesn't fit in 64 bits"); return uint64(value); } /** * @dev Returns the downcasted uint56 from uint256, reverting on * overflow (when the input is greater than largest uint56). * * Counterpart to Solidity's `uint56` operator. * * Requirements: * * - input must fit into 56 bits * * _Available since v4.7._ */ function toUint56(uint256 value) internal pure returns (uint56) { require(value <= type(uint56).max, "SafeCast: value doesn't fit in 56 bits"); return uint56(value); } /** * @dev Returns the downcasted uint48 from uint256, reverting on * overflow (when the input is greater than largest uint48). * * Counterpart to Solidity's `uint48` operator. * * Requirements: * * - input must fit into 48 bits * * _Available since v4.7._ */ function toUint48(uint256 value) internal pure returns (uint48) { require(value <= type(uint48).max, "SafeCast: value doesn't fit in 48 bits"); return uint48(value); } /** * @dev Returns the downcasted uint40 from uint256, reverting on * overflow (when the input is greater than largest uint40). * * Counterpart to Solidity's `uint40` operator. * * Requirements: * * - input must fit into 40 bits * * _Available since v4.7._ */ function toUint40(uint256 value) internal pure returns (uint40) { require(value <= type(uint40).max, "SafeCast: value doesn't fit in 40 bits"); return uint40(value); } /** * @dev Returns the downcasted uint32 from uint256, reverting on * overflow (when the input is greater than largest uint32). * * Counterpart to Solidity's `uint32` operator. * * Requirements: * * - input must fit into 32 bits * * _Available since v2.5._ */ function toUint32(uint256 value) internal pure returns (uint32) { require(value <= type(uint32).max, "SafeCast: value doesn't fit in 32 bits"); return uint32(value); } /** * @dev Returns the downcasted uint24 from uint256, reverting on * overflow (when the input is greater than largest uint24). * * Counterpart to Solidity's `uint24` operator. * * Requirements: * * - input must fit into 24 bits * * _Available since v4.7._ */ function toUint24(uint256 value) internal pure returns (uint24) { require(value <= type(uint24).max, "SafeCast: value doesn't fit in 24 bits"); return uint24(value); } /** * @dev Returns the downcasted uint16 from uint256, reverting on * overflow (when the input is greater than largest uint16). * * Counterpart to Solidity's `uint16` operator. * * Requirements: * * - input must fit into 16 bits * * _Available since v2.5._ */ function toUint16(uint256 value) internal pure returns (uint16) { require(value <= type(uint16).max, "SafeCast: value doesn't fit in 16 bits"); return uint16(value); } /** * @dev Returns the downcasted uint8 from uint256, reverting on * overflow (when the input is greater than largest uint8). * * Counterpart to Solidity's `uint8` operator. * * Requirements: * * - input must fit into 8 bits * * _Available since v2.5._ */ function toUint8(uint256 value) internal pure returns (uint8) { require(value <= type(uint8).max, "SafeCast: value doesn't fit in 8 bits"); return uint8(value); } /** * @dev Converts a signed int256 into an unsigned uint256. * * Requirements: * * - input must be greater than or equal to 0. * * _Available since v3.0._ */ function toUint256(int256 value) internal pure returns (uint256) { require(value >= 0, "SafeCast: value must be positive"); return uint256(value); } /** * @dev Returns the downcasted int248 from int256, reverting on * overflow (when the input is less than smallest int248 or * greater than largest int248). * * Counterpart to Solidity's `int248` operator. * * Requirements: * * - input must fit into 248 bits * * _Available since v4.7._ */ function toInt248(int256 value) internal pure returns (int248) { require(value >= type(int248).min && value <= type(int248).max, "SafeCast: value doesn't fit in 248 bits"); return int248(value); } /** * @dev Returns the downcasted int240 from int256, reverting on * overflow (when the input is less than smallest int240 or * greater than largest int240). * * Counterpart to Solidity's `int240` operator. * * Requirements: * * - input must fit into 240 bits * * _Available since v4.7._ */ function toInt240(int256 value) internal pure returns (int240) { require(value >= type(int240).min && value <= type(int240).max, "SafeCast: value doesn't fit in 240 bits"); return int240(value); } /** * @dev Returns the downcasted int232 from int256, reverting on * overflow (when the input is less than smallest int232 or * greater than largest int232). * * Counterpart to Solidity's `int232` operator. * * Requirements: * * - input must fit into 232 bits * * _Available since v4.7._ */ function toInt232(int256 value) internal pure returns (int232) { require(value >= type(int232).min && value <= type(int232).max, "SafeCast: value doesn't fit in 232 bits"); return int232(value); } /** * @dev Returns the downcasted int224 from int256, reverting on * overflow (when the input is less than smallest int224 or * greater than largest int224). * * Counterpart to Solidity's `int224` operator. * * Requirements: * * - input must fit into 224 bits * * _Available since v4.7._ */ function toInt224(int256 value) internal pure returns (int224) { require(value >= type(int224).min && value <= type(int224).max, "SafeCast: value doesn't fit in 224 bits"); return int224(value); } /** * @dev Returns the downcasted int216 from int256, reverting on * overflow (when the input is less than smallest int216 or * greater than largest int216). * * Counterpart to Solidity's `int216` operator. * * Requirements: * * - input must fit into 216 bits * * _Available since v4.7._ */ function toInt216(int256 value) internal pure returns (int216) { require(value >= type(int216).min && value <= type(int216).max, "SafeCast: value doesn't fit in 216 bits"); return int216(value); } /** * @dev Returns the downcasted int208 from int256, reverting on * overflow (when the input is less than smallest int208 or * greater than largest int208). * * Counterpart to Solidity's `int208` operator. * * Requirements: * * - input must fit into 208 bits * * _Available since v4.7._ */ function toInt208(int256 value) internal pure returns (int208) { require(value >= type(int208).min && value <= type(int208).max, "SafeCast: value doesn't fit in 208 bits"); return int208(value); } /** * @dev Returns the downcasted int200 from int256, reverting on * overflow (when the input is less than smallest int200 or * greater than largest int200). * * Counterpart to Solidity's `int200` operator. * * Requirements: * * - input must fit into 200 bits * * _Available since v4.7._ */ function toInt200(int256 value) internal pure returns (int200) { require(value >= type(int200).min && value <= type(int200).max, "SafeCast: value doesn't fit in 200 bits"); return int200(value); } /** * @dev Returns the downcasted int192 from int256, reverting on * overflow (when the input is less than smallest int192 or * greater than largest int192). * * Counterpart to Solidity's `int192` operator. * * Requirements: * * - input must fit into 192 bits * * _Available since v4.7._ */ function toInt192(int256 value) internal pure returns (int192) { require(value >= type(int192).min && value <= type(int192).max, "SafeCast: value doesn't fit in 192 bits"); return int192(value); } /** * @dev Returns the downcasted int184 from int256, reverting on * overflow (when the input is less than smallest int184 or * greater than largest int184). * * Counterpart to Solidity's `int184` operator. * * Requirements: * * - input must fit into 184 bits * * _Available since v4.7._ */ function toInt184(int256 value) internal pure returns (int184) { require(value >= type(int184).min && value <= type(int184).max, "SafeCast: value doesn't fit in 184 bits"); return int184(value); } /** * @dev Returns the downcasted int176 from int256, reverting on * overflow (when the input is less than smallest int176 or * greater than largest int176). * * Counterpart to Solidity's `int176` operator. * * Requirements: * * - input must fit into 176 bits * * _Available since v4.7._ */ function toInt176(int256 value) internal pure returns (int176) { require(value >= type(int176).min && value <= type(int176).max, "SafeCast: value doesn't fit in 176 bits"); return int176(value); } /** * @dev Returns the downcasted int168 from int256, reverting on * overflow (when the input is less than smallest int168 or * greater than largest int168). * * Counterpart to Solidity's `int168` operator. * * Requirements: * * - input must fit into 168 bits * * _Available since v4.7._ */ function toInt168(int256 value) internal pure returns (int168) { require(value >= type(int168).min && value <= type(int168).max, "SafeCast: value doesn't fit in 168 bits"); return int168(value); } /** * @dev Returns the downcasted int160 from int256, reverting on * overflow (when the input is less than smallest int160 or * greater than largest int160). * * Counterpart to Solidity's `int160` operator. * * Requirements: * * - input must fit into 160 bits * * _Available since v4.7._ */ function toInt160(int256 value) internal pure returns (int160) { require(value >= type(int160).min && value <= type(int160).max, "SafeCast: value doesn't fit in 160 bits"); return int160(value); } /** * @dev Returns the downcasted int152 from int256, reverting on * overflow (when the input is less than smallest int152 or * greater than largest int152). * * Counterpart to Solidity's `int152` operator. * * Requirements: * * - input must fit into 152 bits * * _Available since v4.7._ */ function toInt152(int256 value) internal pure returns (int152) { require(value >= type(int152).min && value <= type(int152).max, "SafeCast: value doesn't fit in 152 bits"); return int152(value); } /** * @dev Returns the downcasted int144 from int256, reverting on * overflow (when the input is less than smallest int144 or * greater than largest int144). * * Counterpart to Solidity's `int144` operator. * * Requirements: * * - input must fit into 144 bits * * _Available since v4.7._ */ function toInt144(int256 value) internal pure returns (int144) { require(value >= type(int144).min && value <= type(int144).max, "SafeCast: value doesn't fit in 144 bits"); return int144(value); } /** * @dev Returns the downcasted int136 from int256, reverting on * overflow (when the input is less than smallest int136 or * greater than largest int136). * * Counterpart to Solidity's `int136` operator. * * Requirements: * * - input must fit into 136 bits * * _Available since v4.7._ */ function toInt136(int256 value) internal pure returns (int136) { require(value >= type(int136).min && value <= type(int136).max, "SafeCast: value doesn't fit in 136 bits"); return int136(value); } /** * @dev Returns the downcasted int128 from int256, reverting on * overflow (when the input is less than smallest int128 or * greater than largest int128). * * Counterpart to Solidity's `int128` operator. * * Requirements: * * - input must fit into 128 bits * * _Available since v3.1._ */ function toInt128(int256 value) internal pure returns (int128) { require(value >= type(int128).min && value <= type(int128).max, "SafeCast: value doesn't fit in 128 bits"); return int128(value); } /** * @dev Returns the downcasted int120 from int256, reverting on * overflow (when the input is less than smallest int120 or * greater than largest int120). * * Counterpart to Solidity's `int120` operator. * * Requirements: * * - input must fit into 120 bits * * _Available since v4.7._ */ function toInt120(int256 value) internal pure returns (int120) { require(value >= type(int120).min && value <= type(int120).max, "SafeCast: value doesn't fit in 120 bits"); return int120(value); } /** * @dev Returns the downcasted int112 from int256, reverting on * overflow (when the input is less than smallest int112 or * greater than largest int112). * * Counterpart to Solidity's `int112` operator. * * Requirements: * * - input must fit into 112 bits * * _Available since v4.7._ */ function toInt112(int256 value) internal pure returns (int112) { require(value >= type(int112).min && value <= type(int112).max, "SafeCast: value doesn't fit in 112 bits"); return int112(value); } /** * @dev Returns the downcasted int104 from int256, reverting on * overflow (when the input is less than smallest int104 or * greater than largest int104). * * Counterpart to Solidity's `int104` operator. * * Requirements: * * - input must fit into 104 bits * * _Available since v4.7._ */ function toInt104(int256 value) internal pure returns (int104) { require(value >= type(int104).min && value <= type(int104).max, "SafeCast: value doesn't fit in 104 bits"); return int104(value); } /** * @dev Returns the downcasted int96 from int256, reverting on * overflow (when the input is less than smallest int96 or * greater than largest int96). * * Counterpart to Solidity's `int96` operator. * * Requirements: * * - input must fit into 96 bits * * _Available since v4.7._ */ function toInt96(int256 value) internal pure returns (int96) { require(value >= type(int96).min && value <= type(int96).max, "SafeCast: value doesn't fit in 96 bits"); return int96(value); } /** * @dev Returns the downcasted int88 from int256, reverting on * overflow (when the input is less than smallest int88 or * greater than largest int88). * * Counterpart to Solidity's `int88` operator. * * Requirements: * * - input must fit into 88 bits * * _Available since v4.7._ */ function toInt88(int256 value) internal pure returns (int88) { require(value >= type(int88).min && value <= type(int88).max, "SafeCast: value doesn't fit in 88 bits"); return int88(value); } /** * @dev Returns the downcasted int80 from int256, reverting on * overflow (when the input is less than smallest int80 or * greater than largest int80). * * Counterpart to Solidity's `int80` operator. * * Requirements: * * - input must fit into 80 bits * * _Available since v4.7._ */ function toInt80(int256 value) internal pure returns (int80) { require(value >= type(int80).min && value <= type(int80).max, "SafeCast: value doesn't fit in 80 bits"); return int80(value); } /** * @dev Returns the downcasted int72 from int256, reverting on * overflow (when the input is less than smallest int72 or * greater than largest int72). * * Counterpart to Solidity's `int72` operator. * * Requirements: * * - input must fit into 72 bits * * _Available since v4.7._ */ function toInt72(int256 value) internal pure returns (int72) { require(value >= type(int72).min && value <= type(int72).max, "SafeCast: value doesn't fit in 72 bits"); return int72(value); } /** * @dev Returns the downcasted int64 from int256, reverting on * overflow (when the input is less than smallest int64 or * greater than largest int64). * * Counterpart to Solidity's `int64` operator. * * Requirements: * * - input must fit into 64 bits * * _Available since v3.1._ */ function toInt64(int256 value) internal pure returns (int64) { require(value >= type(int64).min && value <= type(int64).max, "SafeCast: value doesn't fit in 64 bits"); return int64(value); } /** * @dev Returns the downcasted int56 from int256, reverting on * overflow (when the input is less than smallest int56 or * greater than largest int56). * * Counterpart to Solidity's `int56` operator. * * Requirements: * * - input must fit into 56 bits * * _Available since v4.7._ */ function toInt56(int256 value) internal pure returns (int56) { require(value >= type(int56).min && value <= type(int56).max, "SafeCast: value doesn't fit in 56 bits"); return int56(value); } /** * @dev Returns the downcasted int48 from int256, reverting on * overflow (when the input is less than smallest int48 or * greater than largest int48). * * Counterpart to Solidity's `int48` operator. * * Requirements: * * - input must fit into 48 bits * * _Available since v4.7._ */ function toInt48(int256 value) internal pure returns (int48) { require(value >= type(int48).min && value <= type(int48).max, "SafeCast: value doesn't fit in 48 bits"); return int48(value); } /** * @dev Returns the downcasted int40 from int256, reverting on * overflow (when the input is less than smallest int40 or * greater than largest int40). * * Counterpart to Solidity's `int40` operator. * * Requirements: * * - input must fit into 40 bits * * _Available since v4.7._ */ function toInt40(int256 value) internal pure returns (int40) { require(value >= type(int40).min && value <= type(int40).max, "SafeCast: value doesn't fit in 40 bits"); return int40(value); } /** * @dev Returns the downcasted int32 from int256, reverting on * overflow (when the input is less than smallest int32 or * greater than largest int32). * * Counterpart to Solidity's `int32` operator. * * Requirements: * * - input must fit into 32 bits * * _Available since v3.1._ */ function toInt32(int256 value) internal pure returns (int32) { require(value >= type(int32).min && value <= type(int32).max, "SafeCast: value doesn't fit in 32 bits"); return int32(value); } /** * @dev Returns the downcasted int24 from int256, reverting on * overflow (when the input is less than smallest int24 or * greater than largest int24). * * Counterpart to Solidity's `int24` operator. * * Requirements: * * - input must fit into 24 bits * * _Available since v4.7._ */ function toInt24(int256 value) internal pure returns (int24) { require(value >= type(int24).min && value <= type(int24).max, "SafeCast: value doesn't fit in 24 bits"); return int24(value); } /** * @dev Returns the downcasted int16 from int256, reverting on * overflow (when the input is less than smallest int16 or * greater than largest int16). * * Counterpart to Solidity's `int16` operator. * * Requirements: * * - input must fit into 16 bits * * _Available since v3.1._ */ function toInt16(int256 value) internal pure returns (int16) { require(value >= type(int16).min && value <= type(int16).max, "SafeCast: value doesn't fit in 16 bits"); return int16(value); } /** * @dev Returns the downcasted int8 from int256, reverting on * overflow (when the input is less than smallest int8 or * greater than largest int8). * * Counterpart to Solidity's `int8` operator. * * Requirements: * * - input must fit into 8 bits * * _Available since v3.1._ */ function toInt8(int256 value) internal pure returns (int8) { require(value >= type(int8).min && value <= type(int8).max, "SafeCast: value doesn't fit in 8 bits"); return int8(value); } /** * @dev Converts an unsigned uint256 into a signed int256. * * Requirements: * * - input must be less than or equal to maxInt256. * * _Available since v3.0._ */ function toInt256(uint256 value) internal pure returns (int256) { // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive require(value <= uint256(type(int256).max), "SafeCast: value doesn't fit in an int256"); return int256(value); } }
// SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.16; library Math { /** * @notice Substract with a floor of 0 for the result. */ function subMinZero(uint256 x, uint256 y) internal pure returns (uint256) { return x > y ? x - y : 0; } /** * @notice Used to change the decimals of precision used for an amount. */ function changeDecimals( uint256 amount, uint8 fromDecimals, uint8 toDecimals ) internal pure returns (uint256) { if (fromDecimals == toDecimals) { return amount; } else if (fromDecimals < toDecimals) { return amount * 10**(toDecimals - fromDecimals); } else { return amount / 10**(fromDecimals - toDecimals); } } // ===================================== OPENZEPPELIN'S MATH ===================================== function min(uint256 a, uint256 b) internal pure returns (uint256) { return a < b ? a : b; } // ================================= SOLMATE's FIXEDPOINTMATHLIB ================================= uint256 public constant WAD = 1e18; // The scalar of ETH and most ERC20s. function mulWadDown(uint256 x, uint256 y) internal pure returns (uint256) { return mulDivDown(x, y, WAD); // Equivalent to (x * y) / WAD rounded down. } function mulDivDown( uint256 x, uint256 y, uint256 denominator ) internal pure returns (uint256 z) { assembly { // Store x * y in z for now. z := mul(x, y) // Equivalent to require(denominator != 0 && (x == 0 || (x * y) / x == y)) if iszero(and(iszero(iszero(denominator)), or(iszero(x), eq(div(z, x), y)))) { revert(0, 0) } // Divide z by the denominator. z := div(z, denominator) } } function mulDivUp( uint256 x, uint256 y, uint256 denominator ) internal pure returns (uint256 z) { assembly { // Store x * y in z for now. z := mul(x, y) // Equivalent to require(denominator != 0 && (x == 0 || (x * y) / x == y)) if iszero(and(iszero(iszero(denominator)), or(iszero(x), eq(div(z, x), y)))) { revert(0, 0) } // First, divide z - 1 by the denominator and add 1. // We allow z - 1 to underflow if z is 0, because we multiply the // end result by 0 if z is zero, ensuring we return 0 if z is zero. z := mul(iszero(iszero(z)), add(div(sub(z, 1), denominator), 1)) } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @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 // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol) pragma solidity ^0.8.0; import "../IERC20.sol"; /** * @dev Interface for the optional metadata functions from the ERC20 standard. * * _Available since v4.1._ */ interface IERC20Metadata is IERC20 { /** * @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 v4.4.1 (utils/Context.sol) 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 // OpenZeppelin Contracts (last updated v4.5.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== * * [IMPORTANT] * ==== * You shouldn't rely on `isContract` to protect against flash loan attacks! * * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract * constructor. * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize/address.code.length, which returns 0 // for contracts in construction, since the code is only stored at the end // of the constructor execution. return account.code.length > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { require(isContract(target), "Address: delegate call to non-contract"); (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly /// @solidity memory-safe-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; interface AggregatorInterface { function latestAnswer() external view returns (int256); function latestTimestamp() external view returns (uint256); function latestRound() external view returns (uint256); function getAnswer(uint256 roundId) external view returns (int256); function getTimestamp(uint256 roundId) external view returns (uint256); event AnswerUpdated(int256 indexed current, uint256 indexed roundId, uint256 updatedAt); event NewRound(uint256 indexed roundId, address indexed startedBy, uint256 startedAt); }
// 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 ); }
{ "remappings": [ "@chainlink/=lib/chainlink/", "@ds-test/=lib/forge-std/lib/ds-test/src/", "@ensdomains/=node_modules/@ensdomains/", "@forge-std/=lib/forge-std/src/", "@openzeppelin/=lib/openzeppelin-contracts/", "@solmate/=lib/solmate/src/", "@uniswap/v3-core/=lib/v3-core/", "@uniswap/v3-periphery/=lib/v3-periphery/", "chainlink/=lib/chainlink/", "ds-test/=lib/forge-std/lib/ds-test/src/", "eth-gas-reporter/=node_modules/eth-gas-reporter/", "forge-std/=lib/forge-std/src/", "hardhat/=node_modules/hardhat/", "openzeppelin-contracts/=lib/openzeppelin-contracts/", "solmate/=lib/solmate/src/" ], "optimizer": { "enabled": true, "runs": 200 }, "metadata": { "bytecodeHash": "ipfs" }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "evmVersion": "london", "libraries": {} }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"inputs":[{"internalType":"address","name":"asset","type":"address"},{"internalType":"uint256","name":"price","type":"uint256"},{"internalType":"uint256","name":"maxPrice","type":"uint256"}],"name":"PriceRouter__AssetAboveMaxPrice","type":"error"},{"inputs":[{"internalType":"address","name":"asset","type":"address"},{"internalType":"uint256","name":"price","type":"uint256"},{"internalType":"uint256","name":"minPrice","type":"uint256"}],"name":"PriceRouter__AssetBelowMinPrice","type":"error"},{"inputs":[{"internalType":"address","name":"asset","type":"address"}],"name":"PriceRouter__InvalidAsset","type":"error"},{"inputs":[{"internalType":"uint256","name":"maxPrice","type":"uint256"},{"internalType":"uint256","name":"bufferedMaxPrice","type":"uint256"}],"name":"PriceRouter__InvalidMaxPrice","type":"error"},{"inputs":[{"internalType":"uint256","name":"minPrice","type":"uint256"},{"internalType":"uint256","name":"bufferedMinPrice","type":"uint256"}],"name":"PriceRouter__InvalidMinPrice","type":"error"},{"inputs":[],"name":"PriceRouter__LengthMismatch","type":"error"},{"inputs":[{"internalType":"uint256","name":"min","type":"uint256"},{"internalType":"uint256","name":"max","type":"uint256"}],"name":"PriceRouter__MinPriceGreaterThanMaxPrice","type":"error"},{"inputs":[{"internalType":"address","name":"asset","type":"address"}],"name":"PriceRouter__PriceNotAvailable","type":"error"},{"inputs":[{"internalType":"bool","name":"expected","type":"bool"},{"internalType":"bool","name":"actual","type":"bool"}],"name":"PriceRouter__PriceRangeDenominationMisMatch","type":"error"},{"inputs":[{"internalType":"address","name":"asset","type":"address"}],"name":"PriceRouter__PriceRangeNotAvailable","type":"error"},{"inputs":[{"internalType":"address","name":"asset","type":"address"},{"internalType":"uint256","name":"timeSinceLastUpdate","type":"uint256"},{"internalType":"uint256","name":"heartbeat","type":"uint256"}],"name":"PriceRouter__StalePrice","type":"error"},{"inputs":[{"internalType":"address","name":"asset","type":"address"}],"name":"PriceRouter__UnsupportedAsset","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"asset","type":"address"}],"name":"AddAsset","type":"event"},{"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":"DEFAULT_HEART_BEAT","outputs":[{"internalType":"uint96","name":"","type":"uint96"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract ERC20","name":"asset","type":"address"},{"internalType":"uint256","name":"minPrice","type":"uint256"},{"internalType":"uint256","name":"maxPrice","type":"uint256"},{"internalType":"bool","name":"rangeInETH","type":"bool"},{"internalType":"uint96","name":"heartbeat","type":"uint96"}],"name":"addAsset","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"feedRegistry","outputs":[{"internalType":"contract FeedRegistryInterface","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract ERC20","name":"","type":"address"}],"name":"getAssetConfig","outputs":[{"internalType":"uint256","name":"minPrice","type":"uint256"},{"internalType":"uint256","name":"maxPrice","type":"uint256"},{"internalType":"bool","name":"isPriceRangeInETH","type":"bool"},{"internalType":"uint96","name":"heartbeat","type":"uint96"},{"internalType":"bool","name":"isSupported","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract ERC20","name":"baseAsset","type":"address"},{"internalType":"contract ERC20","name":"quoteAsset","type":"address"}],"name":"getExchangeRate","outputs":[{"internalType":"uint256","name":"exchangeRate","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract ERC20[]","name":"baseAssets","type":"address[]"},{"internalType":"contract ERC20","name":"quoteAsset","type":"address"}],"name":"getExchangeRates","outputs":[{"internalType":"uint256[]","name":"exchangeRates","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract ERC20","name":"asset","type":"address"}],"name":"getPriceRange","outputs":[{"internalType":"uint256","name":"min","type":"uint256"},{"internalType":"uint256","name":"max","type":"uint256"},{"internalType":"bool","name":"isETH","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract ERC20[]","name":"_assets","type":"address[]"}],"name":"getPriceRanges","outputs":[{"internalType":"uint256[]","name":"min","type":"uint256[]"},{"internalType":"uint256[]","name":"max","type":"uint256[]"},{"internalType":"bool[]","name":"isETH","type":"bool[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract ERC20","name":"baseAsset","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"contract ERC20","name":"quoteAsset","type":"address"}],"name":"getValue","outputs":[{"internalType":"uint256","name":"value","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract ERC20","name":"asset","type":"address"}],"name":"getValueInUSD","outputs":[{"internalType":"uint256","name":"price","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract ERC20[]","name":"baseAssets","type":"address[]"},{"internalType":"uint256[]","name":"amounts","type":"uint256[]"},{"internalType":"contract ERC20","name":"quoteAsset","type":"address"}],"name":"getValues","outputs":[{"internalType":"uint256","name":"value","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract ERC20","name":"asset","type":"address"}],"name":"isSupported","outputs":[{"internalType":"bool","name":"","type":"bool"}],"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"}]
Contract Creation Code
608060405234801561001057600080fd5b5061001a3361001f565b61006f565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b611c2a8061007e6000396000f3fe608060405234801561001057600080fd5b50600436106100f55760003560e01c806390238c3911610097578063d062d55911610066578063d062d559146102c2578063f2fde38b146102f2578063f56aa43114610305578063f96a71291461031857600080fd5b806390238c3914610260578063a8ea52c81461027b578063b333a1751461029c578063baaa61be146102af57600080fd5b80635f0c5e4a116100d35780635f0c5e4a1461018b5780636ec3ab67146101ad578063715018a6146102315780638da5cb5b1461023b57600080fd5b806301595997146100fa5780632982e0fa146101235780634f129c5314610145575b600080fd5b61010d61010836600461168c565b61032b565b60405161011a9190611719565b60405180910390f35b61013661013136600461172c565b610442565b60405161011a93929190611761565b61017b6101533660046117cc565b6001600160a01b0316600090815260016020526040902060020154600160681b900460ff1690565b604051901515815260200161011a565b6101956201518081565b6040516001600160601b03909116815260200161011a565b6101f96101bb3660046117cc565b600160208190526000918252604090912080549181015460029091015460ff808216916001600160601b0361010082041691600160681b9091041685565b604080519586526020860194909452911515928401929092526001600160601b0390911660608301521515608082015260a00161011a565b6102396105c0565b005b6000546001600160a01b03165b6040516001600160a01b03909116815260200161011a565b6102487347fb2585d2c56fe188d0e6ec628a38b74fceeedf81565b61028e6102893660046117e9565b6105ff565b60405190815260200161011a565b61028e6102aa36600461182b565b61068b565b61028e6102bd3660046118f6565b61080f565b6102d56102d03660046117cc565b610884565b60408051938452602084019290925215159082015260600161011a565b6102396103003660046117cc565b610933565b610239610313366004611924565b6109ce565b61028e6103263660046117cc565b610c57565b60606000826001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa15801561036d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103919190611994565b84519091508067ffffffffffffffff8111156103af576103af611588565b6040519080825280602002602001820160405280156103d8578160200160208202803683370190505b50925060005b818110156104395761040a8682815181106103fb576103fb6119b7565b60200260200101518685610e89565b84828151811061041c5761041c6119b7565b602090810291909101015280610431816119e3565b9150506103de565b50505092915050565b60608060606000845190508067ffffffffffffffff81111561046657610466611588565b60405190808252806020026020018201604052801561048f578160200160208202803683370190505b508167ffffffffffffffff8111156104a9576104a9611588565b6040519080825280602002602001820160405280156104d2578160200160208202803683370190505b508267ffffffffffffffff8111156104ec576104ec611588565b604051908082528060200260200182016040528015610515578160200160208202803683370190505b509195509350915060005b818110156105b75761054a86828151811061053d5761053d6119b7565b6020026020010151610884565b87848151811061055c5761055c6119b7565b60200260200101878581518110610575576105756119b7565b6020026020010187868151811061058e5761058e6119b7565b9315156020948502919091019093019290925291905252806105af816119e3565b915050610520565b50509193909250565b6000546001600160a01b031633146105f35760405162461bcd60e51b81526004016105ea906119fc565b60405180910390fd5b6105fd6000610eb2565b565b600061068361060e858461080f565b856001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa15801561064c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106709190611994565b61067b90600a611b15565b859190610f02565b949350505050565b825182516000919081146106b257604051630c86c3b360e21b815260040160405180910390fd5b6000836001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa1580156106f2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107169190611994565b905060005b82811015610805576000878281518110610737576107376119b7565b602002602001015190506107e561074f828886610e89565b826001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa15801561078d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107b19190611994565b6107bc90600a611b15565b8985815181106107ce576107ce6119b7565b6020026020010151610f029092919063ffffffff16565b6107ef9086611b24565b94505080806107fd906119e3565b91505061071b565b5050509392505050565b600061087d8383846001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015610854573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108789190611994565b610e89565b9392505050565b6001600160a01b0381166000908152600160208181526040808420815160a08101835281548152938101549284019290925260029091015460ff8082161515928401929092526001600160601b036101008204166060840152600160681b9004161515608082018190528291829161091a576040516341556d0560e11b81526001600160a01b03861660048201526024016105ea565b8051602082015160409092015190969195509350915050565b6000546001600160a01b0316331461095d5760405162461bcd60e51b81526004016105ea906119fc565b6001600160a01b0381166109c25760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084016105ea565b6109cb81610eb2565b50565b6000546001600160a01b031633146109f85760405162461bcd60e51b81526004016105ea906119fc565b6001600160a01b038516610a2a57604051635e6668c960e01b81526001600160a01b03861660048201526024016105ea565b6000610a3586610f21565b90506000806000610a4584610fa7565b92509250925080151586151514610a7b57604051639dc9e49960e01b8152861515600482015281151560248201526044016105ea565b6000610a8f84670f43fc2c04ee00006112bb565b90506000610aa584670c7d713b49da00006112bb565b905089600003610ab757819950610ae2565b818a1015610ae25760405163f3658d1d60e01b8152600481018b9052602481018390526044016105ea565b88600003610af257809850610b1d565b80891115610b1d57604051632428a71960e01b8152600481018a9052602481018290526044016105ea565b888a10610b47576040516313f2305560e11b8152600481018b9052602481018a90526044016105ea565b6040518060a001604052808b81526020018a81526020018415158152602001886001600160601b0316600003610b805762015180610b82565b885b6001600160601b039081168252600160209283018190526001600160a01b038f1660008181528285526040808220875181559587015193860193909355858301516002909501805460608801516080909801511515600160681b0260ff60681b1998909616610100026cffffffffffffffffffffffff0019971515979097166cffffffffffffffffffffffffff1990911617959095179590951692909217909255905190917fb38e19e04618f9502008311560587c597fe11e8867226353a0c01aab7e4df29391a25050505050505050505050565b6001600160a01b0381166000908152600160208181526040808420815160a08101835281548152938101549284019290925260029091015460ff8082161515928401929092526001600160601b036101008204166060840152600160681b900416151560808201819052610ce9576040516341556d0560e11b81526001600160a01b03841660048201526024016105ea565b610cf283610f21565b92508060400151610dab5760405163bcfd032d60e01b81526001600160a01b0384166004820152610348602482015260009081907347fb2585d2c56fe188d0e6ec628a38b74fceeedf9063bcfd032d9060440160a060405180830381865afa158015610d62573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d869190611b51565b50935050925050610d96826112d6565b9350610da485858386611328565b5050610e83565b60405163bcfd032d60e01b81526001600160a01b038416600482015273eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee602482015260009081907347fb2585d2c56fe188d0e6ec628a38b74fceeedf9063bcfd032d9060440160a060405180830381865afa158015610e22573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e469190611b51565b50935050925050610e56826112d6565b9350610e6485858386611328565b610e7e610e6f611403565b610e78846112d6565b906112bb565b935050505b50919050565b6000610683610e9983600a611b15565b610ea285610c57565b610eab87610c57565b9190610f02565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b828202811515841585830485141716610f1a57600080fd5b0492915050565b600073c02aaa39b223fe8d0a0e5c4f27ead9083c756cc1196001600160a01b03831601610f63575073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee919050565b732260fac5e5542a773aa44fbcfedf7c193bc2c598196001600160a01b03831601610fa3575073bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb919050565b5090565b60405163d2edb6dd60e01b81526001600160a01b03821660048201526103486024820152600090819081907347fb2585d2c56fe188d0e6ec628a38b74fceeedf9063d2edb6dd90604401602060405180830381865afa92505050801561102a575060408051601f3d908101601f1916820190925261102791810190611ba1565b60015b6111ce5760405163d2edb6dd60e01b81526001600160a01b038516600482015273eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee60248201527347fb2585d2c56fe188d0e6ec628a38b74fceeedf9063d2edb6dd90604401602060405180830381865afa9250505080156110bc575060408051601f3d908101601f191682019092526110b991810190611ba1565b60015b6110e4576040516318738eff60e31b81526001600160a01b03851660048201526024016105ea565b6000819050806001600160a01b03166322adbc786040518163ffffffff1660e01b8152600401602060405180830381865afa158015611127573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061114b9190611bbe565b6001600160c01b03169450806001600160a01b03166370da2f676040518163ffffffff1660e01b8152600401602060405180830381865afa158015611194573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111b89190611bbe565b6001600160c01b031693506001925050506112b4565b6000819050806001600160a01b03166322adbc786040518163ffffffff1660e01b8152600401602060405180830381865afa158015611211573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112359190611bbe565b6001600160c01b03169450806001600160a01b03166370da2f676040518163ffffffff1660e01b8152600401602060405180830381865afa15801561127e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112a29190611bbe565b6001600160c01b031693506000925050505b9193909250565b600061087d8383670de0b6b3a7640000610f02565b92915050565b600080821215610fa35760405162461bcd60e51b815260206004820181905260248201527f53616665436173743a2076616c7565206d75737420626520706f73697469766560448201526064016105ea565b80518084101561136457604051635edcbe8f60e01b81526001600160a01b038616600482015260248101859052604481018290526064016105ea565b6020820151808511156113a35760405163644d805360e01b81526001600160a01b038716600482015260248101869052604481018290526064016105ea565b60608301516001600160601b031660006113bd8642611be1565b9050818111156113f957604051630c99c63560e11b81526001600160a01b038916600482015260248101829052604481018390526064016105ea565b5050505050505050565b60405163bcfd032d60e01b815273eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee60048201526103486024820152600090819081907347fb2585d2c56fe188d0e6ec628a38b74fceeedf9063bcfd032d9060440160a060405180830381865afa158015611475573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114999190611b51565b509350509250506114a9826112d6565b73c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26000819052600160209081526040805160a0810182527f49e349d4f386739afdf8e55db7675b584d46c3b2a603eef62554e21dc437b5db5481527f49e349d4f386739afdf8e55db7675b584d46c3b2a603eef62554e21dc437b5dc54928101929092527f49e349d4f386739afdf8e55db7675b584d46c3b2a603eef62554e21dc437b5dd5460ff8082161515928401929092526001600160601b036101008204166060840152600160681b900416151560808201529194506115839185908490611328565b505090565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff811182821017156115c7576115c7611588565b604052919050565b600067ffffffffffffffff8211156115e9576115e9611588565b5060051b60200190565b6001600160a01b03811681146109cb57600080fd5b8035611613816115f3565b919050565b600082601f83011261162957600080fd5b8135602061163e611639836115cf565b61159e565b82815260059290921b8401810191818101908684111561165d57600080fd5b8286015b84811015611681578035611674816115f3565b8352918301918301611661565b509695505050505050565b6000806040838503121561169f57600080fd5b823567ffffffffffffffff8111156116b657600080fd5b6116c285828601611618565b92505060208301356116d3816115f3565b809150509250929050565b600081518084526020808501945080840160005b8381101561170e578151875295820195908201906001016116f2565b509495945050505050565b60208152600061087d60208301846116de565b60006020828403121561173e57600080fd5b813567ffffffffffffffff81111561175557600080fd5b61068384828501611618565b60608152600061177460608301866116de565b60208382038185015261178782876116de565b8481036040860152855180825282870193509082019060005b818110156117be5784511515835293830193918301916001016117a0565b509098975050505050505050565b6000602082840312156117de57600080fd5b813561087d816115f3565b6000806000606084860312156117fe57600080fd5b8335611809816115f3565b9250602084013591506040840135611820816115f3565b809150509250925092565b60008060006060848603121561184057600080fd5b833567ffffffffffffffff8082111561185857600080fd5b61186487838801611618565b945060209150818601358181111561187b57600080fd5b86019050601f8101871361188e57600080fd5b803561189c611639826115cf565b81815260059190911b820183019083810190898311156118bb57600080fd5b928401925b828410156118d9578335825292840192908401906118c0565b80965050505050506118ed60408501611608565b90509250925092565b6000806040838503121561190957600080fd5b8235611914816115f3565b915060208301356116d3816115f3565b600080600080600060a0868803121561193c57600080fd5b8535611947816115f3565b945060208601359350604086013592506060860135801515811461196a57600080fd5b915060808601356001600160601b038116811461198657600080fd5b809150509295509295909350565b6000602082840312156119a657600080fd5b815160ff8116811461087d57600080fd5b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b6000600182016119f5576119f56119cd565b5060010190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b600181815b80851115611a6c578160001904821115611a5257611a526119cd565b80851615611a5f57918102915b93841c9390800290611a36565b509250929050565b600082611a83575060016112d0565b81611a90575060006112d0565b8160018114611aa65760028114611ab057611acc565b60019150506112d0565b60ff841115611ac157611ac16119cd565b50506001821b6112d0565b5060208310610133831016604e8410600b8410161715611aef575081810a6112d0565b611af98383611a31565b8060001904821115611b0d57611b0d6119cd565b029392505050565b600061087d60ff841683611a74565b808201808211156112d0576112d06119cd565b805169ffffffffffffffffffff8116811461161357600080fd5b600080600080600060a08688031215611b6957600080fd5b611b7286611b37565b9450602086015193506040860151925060608601519150611b9560808701611b37565b90509295509295909350565b600060208284031215611bb357600080fd5b815161087d816115f3565b600060208284031215611bd057600080fd5b81518060170b811461087d57600080fd5b818103818111156112d0576112d06119cd56fea26469706673582212203232303d3e8e16a658a5bee5db6b08e2222b22c1e5a43de8f4a087e61646436764736f6c63430008100033
Deployed Bytecode
0x608060405234801561001057600080fd5b50600436106100f55760003560e01c806390238c3911610097578063d062d55911610066578063d062d559146102c2578063f2fde38b146102f2578063f56aa43114610305578063f96a71291461031857600080fd5b806390238c3914610260578063a8ea52c81461027b578063b333a1751461029c578063baaa61be146102af57600080fd5b80635f0c5e4a116100d35780635f0c5e4a1461018b5780636ec3ab67146101ad578063715018a6146102315780638da5cb5b1461023b57600080fd5b806301595997146100fa5780632982e0fa146101235780634f129c5314610145575b600080fd5b61010d61010836600461168c565b61032b565b60405161011a9190611719565b60405180910390f35b61013661013136600461172c565b610442565b60405161011a93929190611761565b61017b6101533660046117cc565b6001600160a01b0316600090815260016020526040902060020154600160681b900460ff1690565b604051901515815260200161011a565b6101956201518081565b6040516001600160601b03909116815260200161011a565b6101f96101bb3660046117cc565b600160208190526000918252604090912080549181015460029091015460ff808216916001600160601b0361010082041691600160681b9091041685565b604080519586526020860194909452911515928401929092526001600160601b0390911660608301521515608082015260a00161011a565b6102396105c0565b005b6000546001600160a01b03165b6040516001600160a01b03909116815260200161011a565b6102487347fb2585d2c56fe188d0e6ec628a38b74fceeedf81565b61028e6102893660046117e9565b6105ff565b60405190815260200161011a565b61028e6102aa36600461182b565b61068b565b61028e6102bd3660046118f6565b61080f565b6102d56102d03660046117cc565b610884565b60408051938452602084019290925215159082015260600161011a565b6102396103003660046117cc565b610933565b610239610313366004611924565b6109ce565b61028e6103263660046117cc565b610c57565b60606000826001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa15801561036d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103919190611994565b84519091508067ffffffffffffffff8111156103af576103af611588565b6040519080825280602002602001820160405280156103d8578160200160208202803683370190505b50925060005b818110156104395761040a8682815181106103fb576103fb6119b7565b60200260200101518685610e89565b84828151811061041c5761041c6119b7565b602090810291909101015280610431816119e3565b9150506103de565b50505092915050565b60608060606000845190508067ffffffffffffffff81111561046657610466611588565b60405190808252806020026020018201604052801561048f578160200160208202803683370190505b508167ffffffffffffffff8111156104a9576104a9611588565b6040519080825280602002602001820160405280156104d2578160200160208202803683370190505b508267ffffffffffffffff8111156104ec576104ec611588565b604051908082528060200260200182016040528015610515578160200160208202803683370190505b509195509350915060005b818110156105b75761054a86828151811061053d5761053d6119b7565b6020026020010151610884565b87848151811061055c5761055c6119b7565b60200260200101878581518110610575576105756119b7565b6020026020010187868151811061058e5761058e6119b7565b9315156020948502919091019093019290925291905252806105af816119e3565b915050610520565b50509193909250565b6000546001600160a01b031633146105f35760405162461bcd60e51b81526004016105ea906119fc565b60405180910390fd5b6105fd6000610eb2565b565b600061068361060e858461080f565b856001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa15801561064c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106709190611994565b61067b90600a611b15565b859190610f02565b949350505050565b825182516000919081146106b257604051630c86c3b360e21b815260040160405180910390fd5b6000836001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa1580156106f2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107169190611994565b905060005b82811015610805576000878281518110610737576107376119b7565b602002602001015190506107e561074f828886610e89565b826001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa15801561078d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107b19190611994565b6107bc90600a611b15565b8985815181106107ce576107ce6119b7565b6020026020010151610f029092919063ffffffff16565b6107ef9086611b24565b94505080806107fd906119e3565b91505061071b565b5050509392505050565b600061087d8383846001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015610854573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108789190611994565b610e89565b9392505050565b6001600160a01b0381166000908152600160208181526040808420815160a08101835281548152938101549284019290925260029091015460ff8082161515928401929092526001600160601b036101008204166060840152600160681b9004161515608082018190528291829161091a576040516341556d0560e11b81526001600160a01b03861660048201526024016105ea565b8051602082015160409092015190969195509350915050565b6000546001600160a01b0316331461095d5760405162461bcd60e51b81526004016105ea906119fc565b6001600160a01b0381166109c25760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084016105ea565b6109cb81610eb2565b50565b6000546001600160a01b031633146109f85760405162461bcd60e51b81526004016105ea906119fc565b6001600160a01b038516610a2a57604051635e6668c960e01b81526001600160a01b03861660048201526024016105ea565b6000610a3586610f21565b90506000806000610a4584610fa7565b92509250925080151586151514610a7b57604051639dc9e49960e01b8152861515600482015281151560248201526044016105ea565b6000610a8f84670f43fc2c04ee00006112bb565b90506000610aa584670c7d713b49da00006112bb565b905089600003610ab757819950610ae2565b818a1015610ae25760405163f3658d1d60e01b8152600481018b9052602481018390526044016105ea565b88600003610af257809850610b1d565b80891115610b1d57604051632428a71960e01b8152600481018a9052602481018290526044016105ea565b888a10610b47576040516313f2305560e11b8152600481018b9052602481018a90526044016105ea565b6040518060a001604052808b81526020018a81526020018415158152602001886001600160601b0316600003610b805762015180610b82565b885b6001600160601b039081168252600160209283018190526001600160a01b038f1660008181528285526040808220875181559587015193860193909355858301516002909501805460608801516080909801511515600160681b0260ff60681b1998909616610100026cffffffffffffffffffffffff0019971515979097166cffffffffffffffffffffffffff1990911617959095179590951692909217909255905190917fb38e19e04618f9502008311560587c597fe11e8867226353a0c01aab7e4df29391a25050505050505050505050565b6001600160a01b0381166000908152600160208181526040808420815160a08101835281548152938101549284019290925260029091015460ff8082161515928401929092526001600160601b036101008204166060840152600160681b900416151560808201819052610ce9576040516341556d0560e11b81526001600160a01b03841660048201526024016105ea565b610cf283610f21565b92508060400151610dab5760405163bcfd032d60e01b81526001600160a01b0384166004820152610348602482015260009081907347fb2585d2c56fe188d0e6ec628a38b74fceeedf9063bcfd032d9060440160a060405180830381865afa158015610d62573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d869190611b51565b50935050925050610d96826112d6565b9350610da485858386611328565b5050610e83565b60405163bcfd032d60e01b81526001600160a01b038416600482015273eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee602482015260009081907347fb2585d2c56fe188d0e6ec628a38b74fceeedf9063bcfd032d9060440160a060405180830381865afa158015610e22573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e469190611b51565b50935050925050610e56826112d6565b9350610e6485858386611328565b610e7e610e6f611403565b610e78846112d6565b906112bb565b935050505b50919050565b6000610683610e9983600a611b15565b610ea285610c57565b610eab87610c57565b9190610f02565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b828202811515841585830485141716610f1a57600080fd5b0492915050565b600073c02aaa39b223fe8d0a0e5c4f27ead9083c756cc1196001600160a01b03831601610f63575073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee919050565b732260fac5e5542a773aa44fbcfedf7c193bc2c598196001600160a01b03831601610fa3575073bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb919050565b5090565b60405163d2edb6dd60e01b81526001600160a01b03821660048201526103486024820152600090819081907347fb2585d2c56fe188d0e6ec628a38b74fceeedf9063d2edb6dd90604401602060405180830381865afa92505050801561102a575060408051601f3d908101601f1916820190925261102791810190611ba1565b60015b6111ce5760405163d2edb6dd60e01b81526001600160a01b038516600482015273eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee60248201527347fb2585d2c56fe188d0e6ec628a38b74fceeedf9063d2edb6dd90604401602060405180830381865afa9250505080156110bc575060408051601f3d908101601f191682019092526110b991810190611ba1565b60015b6110e4576040516318738eff60e31b81526001600160a01b03851660048201526024016105ea565b6000819050806001600160a01b03166322adbc786040518163ffffffff1660e01b8152600401602060405180830381865afa158015611127573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061114b9190611bbe565b6001600160c01b03169450806001600160a01b03166370da2f676040518163ffffffff1660e01b8152600401602060405180830381865afa158015611194573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111b89190611bbe565b6001600160c01b031693506001925050506112b4565b6000819050806001600160a01b03166322adbc786040518163ffffffff1660e01b8152600401602060405180830381865afa158015611211573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112359190611bbe565b6001600160c01b03169450806001600160a01b03166370da2f676040518163ffffffff1660e01b8152600401602060405180830381865afa15801561127e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112a29190611bbe565b6001600160c01b031693506000925050505b9193909250565b600061087d8383670de0b6b3a7640000610f02565b92915050565b600080821215610fa35760405162461bcd60e51b815260206004820181905260248201527f53616665436173743a2076616c7565206d75737420626520706f73697469766560448201526064016105ea565b80518084101561136457604051635edcbe8f60e01b81526001600160a01b038616600482015260248101859052604481018290526064016105ea565b6020820151808511156113a35760405163644d805360e01b81526001600160a01b038716600482015260248101869052604481018290526064016105ea565b60608301516001600160601b031660006113bd8642611be1565b9050818111156113f957604051630c99c63560e11b81526001600160a01b038916600482015260248101829052604481018390526064016105ea565b5050505050505050565b60405163bcfd032d60e01b815273eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee60048201526103486024820152600090819081907347fb2585d2c56fe188d0e6ec628a38b74fceeedf9063bcfd032d9060440160a060405180830381865afa158015611475573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114999190611b51565b509350509250506114a9826112d6565b73c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26000819052600160209081526040805160a0810182527f49e349d4f386739afdf8e55db7675b584d46c3b2a603eef62554e21dc437b5db5481527f49e349d4f386739afdf8e55db7675b584d46c3b2a603eef62554e21dc437b5dc54928101929092527f49e349d4f386739afdf8e55db7675b584d46c3b2a603eef62554e21dc437b5dd5460ff8082161515928401929092526001600160601b036101008204166060840152600160681b900416151560808201529194506115839185908490611328565b505090565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff811182821017156115c7576115c7611588565b604052919050565b600067ffffffffffffffff8211156115e9576115e9611588565b5060051b60200190565b6001600160a01b03811681146109cb57600080fd5b8035611613816115f3565b919050565b600082601f83011261162957600080fd5b8135602061163e611639836115cf565b61159e565b82815260059290921b8401810191818101908684111561165d57600080fd5b8286015b84811015611681578035611674816115f3565b8352918301918301611661565b509695505050505050565b6000806040838503121561169f57600080fd5b823567ffffffffffffffff8111156116b657600080fd5b6116c285828601611618565b92505060208301356116d3816115f3565b809150509250929050565b600081518084526020808501945080840160005b8381101561170e578151875295820195908201906001016116f2565b509495945050505050565b60208152600061087d60208301846116de565b60006020828403121561173e57600080fd5b813567ffffffffffffffff81111561175557600080fd5b61068384828501611618565b60608152600061177460608301866116de565b60208382038185015261178782876116de565b8481036040860152855180825282870193509082019060005b818110156117be5784511515835293830193918301916001016117a0565b509098975050505050505050565b6000602082840312156117de57600080fd5b813561087d816115f3565b6000806000606084860312156117fe57600080fd5b8335611809816115f3565b9250602084013591506040840135611820816115f3565b809150509250925092565b60008060006060848603121561184057600080fd5b833567ffffffffffffffff8082111561185857600080fd5b61186487838801611618565b945060209150818601358181111561187b57600080fd5b86019050601f8101871361188e57600080fd5b803561189c611639826115cf565b81815260059190911b820183019083810190898311156118bb57600080fd5b928401925b828410156118d9578335825292840192908401906118c0565b80965050505050506118ed60408501611608565b90509250925092565b6000806040838503121561190957600080fd5b8235611914816115f3565b915060208301356116d3816115f3565b600080600080600060a0868803121561193c57600080fd5b8535611947816115f3565b945060208601359350604086013592506060860135801515811461196a57600080fd5b915060808601356001600160601b038116811461198657600080fd5b809150509295509295909350565b6000602082840312156119a657600080fd5b815160ff8116811461087d57600080fd5b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b6000600182016119f5576119f56119cd565b5060010190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b600181815b80851115611a6c578160001904821115611a5257611a526119cd565b80851615611a5f57918102915b93841c9390800290611a36565b509250929050565b600082611a83575060016112d0565b81611a90575060006112d0565b8160018114611aa65760028114611ab057611acc565b60019150506112d0565b60ff841115611ac157611ac16119cd565b50506001821b6112d0565b5060208310610133831016604e8410600b8410161715611aef575081810a6112d0565b611af98383611a31565b8060001904821115611b0d57611b0d6119cd565b029392505050565b600061087d60ff841683611a74565b808201808211156112d0576112d06119cd565b805169ffffffffffffffffffff8116811461161357600080fd5b600080600080600060a08688031215611b6957600080fd5b611b7286611b37565b9450602086015193506040860151925060608601519150611b9560808701611b37565b90509295509295909350565b600060208284031215611bb357600080fd5b815161087d816115f3565b600060208284031215611bd057600080fd5b81518060170b811461087d57600080fd5b818103818111156112d0576112d06119cd56fea26469706673582212203232303d3e8e16a658a5bee5db6b08e2222b22c1e5a43de8f4a087e61646436764736f6c63430008100033
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 30 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
Loading...
Loading
[ Download: CSV Export ]
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.