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
TokenTracker
Sponsored
View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Loading...
Loading
This contract may be a proxy contract. Click on More Options and select Is this a proxy? to confirm and enable the "Read as Proxy" & "Write as Proxy" tabs.
Contract Name:
CellarInitializableV2_1
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 { Cellar, Registry, ERC20 } from "src/base/Cellar.sol"; import { Initializable } from "@openzeppelin/contracts/proxy/utils/Initializable.sol"; contract CellarInitializableV2_1 is Cellar, Initializable { /** * @notice Constructor is only called for the implementation contract, * so it can be safely filled with mostly zero inputs. */ constructor(Registry _registry) Cellar( _registry, ERC20(address(0)), "", "", abi.encode(new uint32[](0), new uint32[](0), new bytes[](0), new bytes[](0), 0, address(0), 0, 0) ) {} /** * @notice Initialize function called by factory contract immediately after deployment. * @param params abi encoded parameter containing * - Registry contract * - ERC20 cellar asset * - String name of cellar * - String symbol of cellar * - bytes abi encoded parameter containing * - uint32[] array of credit positions * - uint32[] array of debt positions * - bytes[] array of credit config data * - bytes[] array of debt config data * - uint32 holding position id * - address strategist payout address * - uint128 asset risk tolerance * - uint128 protocol risk tolerance */ function initialize(bytes calldata params) external initializer { ( address tmpOwner, Registry _registry, ERC20 _asset, string memory _name, string memory _symbol, bytes memory _params ) = abi.decode(params, (address, Registry, ERC20, string, string, bytes)); // Initialize Cellar registry = _registry; asset = _asset; owner = tmpOwner; shareLockPeriod = MAXIMUM_SHARE_LOCK_PERIOD; allowedRebalanceDeviation = 0.003e18; aavePool = 0x7d2768dE32b0b80b7a3454c06BdAc94A69DDc7A9; // Initialize ERC20 name = _name; symbol = _symbol; decimals = 18; INITIAL_CHAIN_ID = block.chainid; INITIAL_DOMAIN_SEPARATOR = computeDomainSeparator(); // Initialize Reentrancy Guard locked = 1; // Initialize positions. ( uint32[] memory _creditPositions, uint32[] memory _debtPositions, bytes[] memory _creditConfigurationData, bytes[] memory _debtConfigurationData, uint32 _holdingPosition, address _strategistPayout, uint128 _assetRiskTolerance, uint128 _protocolRiskTolerance ) = abi.decode(_params, (uint32[], uint32[], bytes[], bytes[], uint32, address, uint128, uint128)); for (uint32 i; i < _creditPositions.length; i++) _addPosition(i, _creditPositions[i], _creditConfigurationData[i], false); for (uint32 i; i < _debtPositions.length; i++) _addPosition(i, _debtPositions[i], _debtConfigurationData[i], true); _setHoldingPosition(_holdingPosition); // Initialize remaining values. assetRiskTolerance = _assetRiskTolerance; protocolRiskTolerance = _protocolRiskTolerance; feeData = FeeData({ strategistPlatformCut: 0.8e18, platformFee: 0.005e18, lastAccrual: uint64(block.timestamp), strategistPayoutAddress: _strategistPayout }); } }
// 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; import "./AggregatorInterface.sol"; import "./AggregatorV3Interface.sol"; interface AggregatorV2V3Interface is AggregatorInterface, AggregatorV3Interface {}
// 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); function getRoundData(uint80 _roundId) external view returns ( uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound ); function latestRoundData() external view returns ( uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound ); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; interface AutomationCompatibleInterface { /** * @notice method that is simulated by the keepers to see if any work actually * needs to be performed. This method does does not actually need to be * executable, and since it is only ever simulated it can consume lots of gas. * @dev To ensure that it is never called, you may want to add the * cannotExecute modifier from KeeperBase to your implementation of this * method. * @param checkData specified in the upkeep registration so it is always the * same for a registered upkeep. This can easily be broken down into specific * arguments using `abi.decode`, so multiple upkeeps can be registered on the * same contract and easily differentiated by the contract. * @return upkeepNeeded boolean to indicate whether the keeper should call * performUpkeep or not. * @return performData bytes that the keeper should call performUpkeep with, if * upkeep is needed. If you would like to encode data to decode later, try * `abi.encode`. */ function checkUpkeep(bytes calldata checkData) external returns (bool upkeepNeeded, bytes memory performData); /** * @notice method that is actually executed by the keepers, via the registry. * The data returned by the checkUpkeep simulation will be passed into * this method to actually be executed. * @dev The input to this method should not be trusted, and the caller of the * method should not even be restricted to any single registry. Anyone should * be able call it, and the input should be validated, there is no guarantee * that the data passed in is the performData returned from checkUpkeep. This * could happen due to malicious keepers, racing keepers, or simply a state * change while the performUpkeep transaction is waiting for confirmation. * Always validate the data passed in. * @param performData is the data which was passed back from the checkData * simulation. If it is encoded, it can easily be decoded into other types by * calling `abi.decode`. This data should not be trusted, and should be * validated against the contract's current state. */ function performUpkeep(bytes calldata performData) external; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (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 Throws if called by any account other than the owner. */ modifier onlyOwner() { _checkOwner(); _; } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if the sender is not the owner. */ function _checkOwner() internal view virtual { 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 // OpenZeppelin Contracts (last updated v4.7.0) (proxy/utils/Initializable.sol) pragma solidity ^0.8.2; import "../../utils/Address.sol"; /** * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. * * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in * case an upgrade adds a module that needs to be initialized. * * For example: * * [.hljs-theme-light.nopadding] * ``` * contract MyToken is ERC20Upgradeable { * function initialize() initializer public { * __ERC20_init("MyToken", "MTK"); * } * } * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable { * function initializeV2() reinitializer(2) public { * __ERC20Permit_init("MyToken"); * } * } * ``` * * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}. * * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. * * [CAUTION] * ==== * Avoid leaving a contract uninitialized. * * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed: * * [.hljs-theme-light.nopadding] * ``` * /// @custom:oz-upgrades-unsafe-allow constructor * constructor() { * _disableInitializers(); * } * ``` * ==== */ abstract contract Initializable { /** * @dev Indicates that the contract has been initialized. * @custom:oz-retyped-from bool */ uint8 private _initialized; /** * @dev Indicates that the contract is in the process of being initialized. */ bool private _initializing; /** * @dev Triggered when the contract has been initialized or reinitialized. */ event Initialized(uint8 version); /** * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope, * `onlyInitializing` functions can be used to initialize parent contracts. * * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a * constructor. * * Emits an {Initialized} event. */ modifier initializer() { bool isTopLevelCall = !_initializing; require( (isTopLevelCall && _initialized < 1) || (!Address.isContract(address(this)) && _initialized == 1), "Initializable: contract is already initialized" ); _initialized = 1; if (isTopLevelCall) { _initializing = true; } _; if (isTopLevelCall) { _initializing = false; emit Initialized(1); } } /** * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be * used to initialize parent contracts. * * A reinitializer may be used after the original initialization step. This is essential to configure modules that * are added through upgrades and that require initialization. * * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer` * cannot be nested. If one is invoked in the context of another, execution will revert. * * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in * a contract, executing them in the right order is up to the developer or operator. * * WARNING: setting the version to 255 will prevent any future reinitialization. * * Emits an {Initialized} event. */ modifier reinitializer(uint8 version) { require(!_initializing && _initialized < version, "Initializable: contract is already initialized"); _initialized = version; _initializing = true; _; _initializing = false; emit Initialized(version); } /** * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the * {initializer} and {reinitializer} modifiers, directly or indirectly. */ modifier onlyInitializing() { require(_initializing, "Initializable: contract is not initializing"); _; } /** * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call. * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized * to any version. It is recommended to use this to lock implementation contracts that are designed to be called * through proxies. * * Emits an {Initialized} event the first time it is successfully executed. */ function _disableInitializers() internal virtual { require(!_initializing, "Initializable: contract is initializing"); if (_initialized < type(uint8).max) { _initialized = type(uint8).max; emit Initialized(type(uint8).max); } } /** * @dev Internal function that returns the initialized version. Returns `_initialized` */ function _getInitializedVersion() internal view returns (uint8) { return _initialized; } /** * @dev Internal function that returns the initialized version. Returns `_initializing` */ function _isInitializing() internal view returns (bool) { return _initializing; } }
// 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 (last updated v4.6.0) (token/ERC721/IERC721Receiver.sol) pragma solidity ^0.8.0; /** * @title ERC721 token receiver interface * @dev Interface for any contract that wants to support safeTransfers * from ERC721 asset contracts. */ interface IERC721Receiver { /** * @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom} * by `operator` from `from`, this function is called. * * It must return its Solidity selector to confirm the token transfer. * If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted. * * The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`. */ function onERC721Received( address operator, address from, uint256 tokenId, bytes calldata data ) external returns (bytes4); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC721/utils/ERC721Holder.sol) pragma solidity ^0.8.0; import "../IERC721Receiver.sol"; /** * @dev Implementation of the {IERC721Receiver} interface. * * Accepts all token transfers. * Make sure the contract is able to use its token with {IERC721-safeTransferFrom}, {IERC721-approve} or {IERC721-setApprovalForAll}. */ contract ERC721Holder is IERC721Receiver { /** * @dev See {IERC721Receiver-onERC721Received}. * * Always returns `IERC721Receiver.onERC721Received.selector`. */ function onERC721Received( address, address, uint256, bytes memory ) public virtual override returns (bytes4) { return this.onERC721Received.selector; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.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://consensys.net/diligence/blog/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 functionCallWithValue(target, data, 0, "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"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResultFromTarget(target, 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) { (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResultFromTarget(target, 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) { (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract. * * _Available since v4.8._ */ function verifyCallResultFromTarget( address target, bool success, bytes memory returndata, string memory errorMessage ) internal view returns (bytes memory) { if (success) { if (returndata.length == 0) { // only check isContract if the call was successful and the return data is empty // otherwise we already know that it was a contract require(isContract(target), "Address: call to non-contract"); } return returndata; } else { _revert(returndata, errorMessage); } } /** * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason or 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 { _revert(returndata, errorMessage); } } function _revert(bytes memory returndata, string memory errorMessage) private pure { // 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 // 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.7.0) (utils/math/SafeCast.sol) // This file was procedurally generated from scripts/generate/templates/SafeCast.js. 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 downcasted) { downcasted = int248(value); require(downcasted == value, "SafeCast: value doesn't fit in 248 bits"); } /** * @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 downcasted) { downcasted = int240(value); require(downcasted == value, "SafeCast: value doesn't fit in 240 bits"); } /** * @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 downcasted) { downcasted = int232(value); require(downcasted == value, "SafeCast: value doesn't fit in 232 bits"); } /** * @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 downcasted) { downcasted = int224(value); require(downcasted == value, "SafeCast: value doesn't fit in 224 bits"); } /** * @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 downcasted) { downcasted = int216(value); require(downcasted == value, "SafeCast: value doesn't fit in 216 bits"); } /** * @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 downcasted) { downcasted = int208(value); require(downcasted == value, "SafeCast: value doesn't fit in 208 bits"); } /** * @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 downcasted) { downcasted = int200(value); require(downcasted == value, "SafeCast: value doesn't fit in 200 bits"); } /** * @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 downcasted) { downcasted = int192(value); require(downcasted == value, "SafeCast: value doesn't fit in 192 bits"); } /** * @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 downcasted) { downcasted = int184(value); require(downcasted == value, "SafeCast: value doesn't fit in 184 bits"); } /** * @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 downcasted) { downcasted = int176(value); require(downcasted == value, "SafeCast: value doesn't fit in 176 bits"); } /** * @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 downcasted) { downcasted = int168(value); require(downcasted == value, "SafeCast: value doesn't fit in 168 bits"); } /** * @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 downcasted) { downcasted = int160(value); require(downcasted == value, "SafeCast: value doesn't fit in 160 bits"); } /** * @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 downcasted) { downcasted = int152(value); require(downcasted == value, "SafeCast: value doesn't fit in 152 bits"); } /** * @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 downcasted) { downcasted = int144(value); require(downcasted == value, "SafeCast: value doesn't fit in 144 bits"); } /** * @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 downcasted) { downcasted = int136(value); require(downcasted == value, "SafeCast: value doesn't fit in 136 bits"); } /** * @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 downcasted) { downcasted = int128(value); require(downcasted == value, "SafeCast: value doesn't fit in 128 bits"); } /** * @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 downcasted) { downcasted = int120(value); require(downcasted == value, "SafeCast: value doesn't fit in 120 bits"); } /** * @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 downcasted) { downcasted = int112(value); require(downcasted == value, "SafeCast: value doesn't fit in 112 bits"); } /** * @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 downcasted) { downcasted = int104(value); require(downcasted == value, "SafeCast: value doesn't fit in 104 bits"); } /** * @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 downcasted) { downcasted = int96(value); require(downcasted == value, "SafeCast: value doesn't fit in 96 bits"); } /** * @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 downcasted) { downcasted = int88(value); require(downcasted == value, "SafeCast: value doesn't fit in 88 bits"); } /** * @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 downcasted) { downcasted = int80(value); require(downcasted == value, "SafeCast: value doesn't fit in 80 bits"); } /** * @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 downcasted) { downcasted = int72(value); require(downcasted == value, "SafeCast: value doesn't fit in 72 bits"); } /** * @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 downcasted) { downcasted = int64(value); require(downcasted == value, "SafeCast: value doesn't fit in 64 bits"); } /** * @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 downcasted) { downcasted = int56(value); require(downcasted == value, "SafeCast: value doesn't fit in 56 bits"); } /** * @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 downcasted) { downcasted = int48(value); require(downcasted == value, "SafeCast: value doesn't fit in 48 bits"); } /** * @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 downcasted) { downcasted = int40(value); require(downcasted == value, "SafeCast: value doesn't fit in 40 bits"); } /** * @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 downcasted) { downcasted = int32(value); require(downcasted == value, "SafeCast: value doesn't fit in 32 bits"); } /** * @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 downcasted) { downcasted = int24(value); require(downcasted == value, "SafeCast: value doesn't fit in 24 bits"); } /** * @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 downcasted) { downcasted = int16(value); require(downcasted == value, "SafeCast: value doesn't fit in 16 bits"); } /** * @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 downcasted) { downcasted = int8(value); require(downcasted == value, "SafeCast: value doesn't fit in 8 bits"); } /** * @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: AGPL-3.0-only pragma solidity >=0.8.0; /// @notice Simple single owner authorization mixin. /// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/auth/Owned.sol) abstract contract Owned { /*////////////////////////////////////////////////////////////// EVENTS //////////////////////////////////////////////////////////////*/ event OwnershipTransferred(address indexed user, address indexed newOwner); /*////////////////////////////////////////////////////////////// OWNERSHIP STORAGE //////////////////////////////////////////////////////////////*/ address public owner; modifier onlyOwner() virtual { require(msg.sender == owner, "UNAUTHORIZED"); _; } /*////////////////////////////////////////////////////////////// CONSTRUCTOR //////////////////////////////////////////////////////////////*/ constructor(address _owner) { owner = _owner; emit OwnershipTransferred(address(0), _owner); } /*////////////////////////////////////////////////////////////// OWNERSHIP LOGIC //////////////////////////////////////////////////////////////*/ function transferOwnership(address newOwner) public virtual onlyOwner { owner = newOwner; emit OwnershipTransferred(msg.sender, newOwner); } }
// SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.16; import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol"; import { Cellar } from "src/base/Cellar.sol"; import { ERC20 } from "src/base/ERC20.sol"; import { BaseAdaptor } from "src/modules/adaptors/BaseAdaptor.sol"; import { PriceRouter } from "src/modules/price-router/PriceRouter.sol"; contract Registry is Ownable { // ============================================= ADDRESS CONFIG ============================================= /** * @notice Emitted when the address of a contract is changed. * @param id value representing the unique ID tied to the changed contract * @param oldAddress address of the contract before the change * @param newAddress address of the contract after the contract */ event AddressChanged(uint256 indexed id, address oldAddress, address newAddress); /** * @notice Attempted to set the address of a contract that is not registered. * @param id id of the contract that is not registered */ error Registry__ContractNotRegistered(uint256 id); /** * @notice Emitted when depositor privilege changes. * @param depositor depositor address * @param state the new state of the depositor privilege */ event DepositorOnBehalfChanged(address depositor, bool state); /** * @notice The unique ID that the next registered contract will have. */ uint256 public nextId; /** * @notice Get the address associated with an id. */ mapping(uint256 => address) public getAddress; /** * @notice In order for an address to make deposits on behalf of users they must be approved. */ mapping(address => bool) public approvedForDepositOnBehalf; /** * @notice toggles a depositors ability to deposit into cellars on behalf of users. */ function setApprovedForDepositOnBehalf(address depositor, bool state) external onlyOwner { approvedForDepositOnBehalf[depositor] = state; emit DepositorOnBehalfChanged(depositor, state); } /** * @notice Set the address of the contract at a given id. */ function setAddress(uint256 id, address newAddress) external onlyOwner { if (id >= nextId) revert Registry__ContractNotRegistered(id); emit AddressChanged(id, getAddress[id], newAddress); getAddress[id] = newAddress; } // ============================================= INITIALIZATION ============================================= /** * @param gravityBridge address of GravityBridge contract * @param swapRouter address of SwapRouter contract * @param priceRouter address of PriceRouter contract */ constructor( address gravityBridge, address swapRouter, address priceRouter ) Ownable() { _register(gravityBridge); _register(swapRouter); _register(priceRouter); } // ============================================ REGISTER CONFIG ============================================ /** * @notice Emitted when a new contract is registered. * @param id value representing the unique ID tied to the new contract * @param newContract address of the new contract */ event Registered(uint256 indexed id, address indexed newContract); /** * @notice Register the address of a new contract. * @param newContract address of the new contract to register */ function register(address newContract) external onlyOwner { _register(newContract); } function _register(address newContract) internal { getAddress[nextId] = newContract; emit Registered(nextId, newContract); nextId++; } // ============================================ FEE DISTRIBUTOR LOGIC ============================================ /** * @notice Emitted when fees distributor is changed. * @param oldFeesDistributor address of fee distributor was changed from * @param newFeesDistributor address of fee distributor was changed to */ event FeesDistributorChanged(bytes32 oldFeesDistributor, bytes32 newFeesDistributor); /** * @notice Attempted to use an invalid cosmos address. */ error Registry__InvalidCosmosAddress(); bytes32 public feesDistributor = hex"000000000000000000000000b813554b423266bbd4c16c32fa383394868c1f55"; /** * @notice Set the address of the fee distributor on the Sommelier chain. * @dev IMPORTANT: Ensure that the address is formatted in the specific way that the Gravity contract * expects it to be. * @param newFeesDistributor formatted address of the new fee distributor module */ function setFeesDistributor(bytes32 newFeesDistributor) external onlyOwner { if (uint256(newFeesDistributor) > type(uint160).max) revert Registry__InvalidCosmosAddress(); emit FeesDistributorChanged(feesDistributor, newFeesDistributor); feesDistributor = newFeesDistributor; } // ============================================ POSITION LOGIC ============================================ /** * @notice stores data related to Cellar positions. * @param adaptors address of the adaptor to use for this position * @param isDebt bool indicating whether this position takes on debt or not * @param adaptorData arbitrary data needed to correclty set up a position * @param configurationData arbitrary data settable by strategist to change cellar <-> adaptor interaction */ struct PositionData { address adaptor; bool isDebt; bytes adaptorData; bytes configurationData; } /** * @notice stores data to help cellars manage their risk. * @param assetRisk number 0 -> type(uint128).max indicating how risky a cellars assets can be * 0: Safest * 1: Riskiest * @param protocolRisk number 0 -> type(uint128).max indicating how risky a cellars position protocol can be * 0: Safest * 1: Riskiest */ struct RiskData { uint128 assetRisk; uint128 protocolRisk; } /** * @notice Emitted when a new position is added to the registry. * @param id the positions id * @param adaptor address of the adaptor this position uses * @param isDebt bool indicating whether this position takes on debt or not * @param adaptorData arbitrary bytes used to configure this position */ event PositionAdded(uint32 id, address adaptor, bool isDebt, bytes adaptorData); /** * @notice Attempted to trust a position not being used. * @param position address of the invalid position */ error Registry__PositionPricingNotSetUp(address position); /** * @notice Attempted to add a position with bad input values. */ error Registry__InvalidPositionInput(); /** * @notice Attempted to add a position with a risky asset. */ error Registry__AssetTooRisky(); /** * @notice Attempted to add a position with a risky protocol. */ error Registry__ProtocolTooRisky(); /** * @notice Attempted to add a position that does not exist. */ error Registry__PositionDoesNotExist(); /** * @notice Addresses of the positions currently used by the cellar. */ uint256 public constant PRICE_ROUTER_REGISTRY_SLOT = 2; /** * @notice Maps a position Id to its risk data. */ mapping(uint32 => RiskData) public getRiskData; /** * @notice Maps an adaptor to its risk data. */ mapping(address => RiskData) public getAdaptorRiskData; /** * @notice Stores the number of positions that have been added to the registry. * Starts at 1. */ uint32 public positionCount; /** * @notice Maps a position hash to a position Id. * @dev can be used by adaptors to verify that a certain position is open during Cellar `callOnAdaptor` calls. */ mapping(bytes32 => uint32) public getPositionHashToPositionId; /** * @notice Maps a position id to its position data. * @dev used by Cellars when adding new positions. */ mapping(uint32 => PositionData) public getPositionIdToPositionData; /** * @notice Trust a position to be used by the cellar. * @param adaptor the adaptor address this position uses * @param adaptorData arbitrary bytes used to configure this position * @param assetRisk the risk rating of this positions asset * @param protocolRisk the risk rating of this positions underlying protocol * @return positionId the position id of the newly added position */ function trustPosition( address adaptor, bytes memory adaptorData, uint128 assetRisk, uint128 protocolRisk ) external onlyOwner returns (uint32 positionId) { bytes32 identifier = BaseAdaptor(adaptor).identifier(); bool isDebt = BaseAdaptor(adaptor).isDebt(); bytes32 positionHash = keccak256(abi.encode(identifier, isDebt, adaptorData)); positionId = positionCount + 1; //Add one so that we do not use Id 0. // Check that... // `adaptor` is a non zero address // position has not been already set up if (adaptor == address(0) || getPositionHashToPositionId[positionHash] != 0) revert Registry__InvalidPositionInput(); if (!isAdaptorTrusted[adaptor]) revert Registry__AdaptorNotTrusted(); // Set position data. getPositionIdToPositionData[positionId] = PositionData({ adaptor: adaptor, isDebt: isDebt, adaptorData: adaptorData, configurationData: abi.encode(0) }); getRiskData[positionId] = RiskData({ assetRisk: assetRisk, protocolRisk: protocolRisk }); getPositionHashToPositionId[positionHash] = positionId; // Check that assets position uses are supported for pricing operations. ERC20[] memory assets = BaseAdaptor(adaptor).assetsUsed(adaptorData); PriceRouter priceRouter = PriceRouter(getAddress[PRICE_ROUTER_REGISTRY_SLOT]); for (uint256 i; i < assets.length; i++) { if (!priceRouter.isSupported(assets[i])) revert Registry__PositionPricingNotSetUp(address(assets[i])); } positionCount = positionId; emit PositionAdded(positionId, adaptor, isDebt, adaptorData); } /** * @notice Called by Cellars to add a new position to themselves. * @param positionId the id of the position the cellar wants to add * @param assetRiskTolerance the cellars risk tolerance for assets * @param protocolRiskTolerance the cellars risk tolerance for protocols * @return adaptor the address of the adaptor, isDebt bool indicating whether position is * debt or not, and adaptorData needed to interact with position */ function cellarAddPosition( uint32 positionId, uint128 assetRiskTolerance, uint128 protocolRiskTolerance ) external view returns ( address adaptor, bool isDebt, bytes memory adaptorData ) { if (positionId > positionCount || positionId == 0) revert Registry__PositionDoesNotExist(); RiskData memory data = getRiskData[positionId]; if (assetRiskTolerance < data.assetRisk) revert Registry__AssetTooRisky(); if (protocolRiskTolerance < data.protocolRisk) revert Registry__ProtocolTooRisky(); PositionData memory positionData = getPositionIdToPositionData[positionId]; return (positionData.adaptor, positionData.isDebt, positionData.adaptorData); } // ============================================ ADAPTOR LOGIC ============================================ /** * @notice Attempted to trust an adaptor with non unique identifier. */ error Registry__IdentifierNotUnique(); /** * @notice Attempted to use an untrusted adaptor. */ error Registry__AdaptorNotTrusted(); /** * @notice Maps an adaptor address to bool indicating whether it has been set up in the registry. */ mapping(address => bool) public isAdaptorTrusted; /** * @notice Maps an adaptors identier to bool, to track if the indentifier is unique wrt the registry. */ mapping(bytes32 => bool) public isIdentifierUsed; /** * @notice Trust an adaptor to be used by cellars * @param adaptor address of the adaptor to trust * @param assetRisk the asset risk level associated with this adaptor * @param protocolRisk the protocol risk level associated with this adaptor */ function trustAdaptor( address adaptor, uint128 assetRisk, uint128 protocolRisk ) external onlyOwner { bytes32 identifier = BaseAdaptor(adaptor).identifier(); if (isIdentifierUsed[identifier]) revert Registry__IdentifierNotUnique(); isAdaptorTrusted[adaptor] = true; isIdentifierUsed[identifier] = true; getAdaptorRiskData[adaptor] = RiskData({ assetRisk: assetRisk, protocolRisk: protocolRisk }); } /** * @notice Called by Cellars to allow them to use new adaptors. * @param adaptor address of the adaptor to use * @param assetRiskTolerance asset risk tolerance of the caller * @param protocolRiskTolerance protocol risk tolerance of the cellar */ function cellarSetupAdaptor( address adaptor, uint128 assetRiskTolerance, uint128 protocolRiskTolerance ) external view { RiskData memory data = getAdaptorRiskData[adaptor]; if (assetRiskTolerance < data.assetRisk) revert Registry__AssetTooRisky(); if (protocolRiskTolerance < data.protocolRisk) revert Registry__ProtocolTooRisky(); if (!isAdaptorTrusted[adaptor]) revert Registry__AdaptorNotTrusted(); } }
// SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.16; import { ERC4626, SafeTransferLib, Math, ERC20 } from "./ERC4626.sol"; import { Registry } from "src/Registry.sol"; import { PriceRouter } from "src/modules/price-router/PriceRouter.sol"; import { IGravity } from "src/interfaces/external/IGravity.sol"; import { Uint32Array } from "src/utils/Uint32Array.sol"; import { BaseAdaptor } from "src/modules/adaptors/BaseAdaptor.sol"; import { Address } from "@openzeppelin/contracts/utils/Address.sol"; import { ERC721Holder } from "@openzeppelin/contracts/token/ERC721/utils/ERC721Holder.sol"; import { Owned } from "@solmate/auth/Owned.sol"; /** * @title Sommelier Cellar * @notice A composable ERC4626 that can use arbitrary DeFi assets/positions using adaptors. * @author crispymangoes */ contract Cellar is ERC4626, Owned, ERC721Holder { using Uint32Array for uint32[]; using SafeTransferLib for ERC20; using Math for uint256; using Address for address; // ========================================= REENTRANCY GUARD ========================================= /** * @notice `locked` is public, so that the state can be checked even during view function calls. */ uint256 public locked = 1; modifier nonReentrant() { require(locked == 1, "REENTRANCY"); locked = 2; _; locked = 1; } // ========================================= POSITIONS CONFIG ========================================= /** * @notice Emitted when a position is added. * @param position id of position that was added * @param index index that position was added at */ event PositionAdded(uint32 position, uint256 index); /** * @notice Emitted when a position is removed. * @param position id of position that was removed * @param index index that position was removed from */ event PositionRemoved(uint32 position, uint256 index); /** * @notice Emitted when the positions at two indexes are swapped. * @param newPosition1 id of position (previously at index2) that replaced index1. * @param newPosition2 id of position (previously at index1) that replaced index2. * @param index1 index of first position involved in the swap * @param index2 index of second position involved in the swap. */ event PositionSwapped(uint32 newPosition1, uint32 newPosition2, uint256 index1, uint256 index2); /** * @notice Attempted to add a position that is already being used. * @param position id of the position */ error Cellar__PositionAlreadyUsed(uint32 position); /** * @notice Attempted to make an unused position the holding position. * @param position id of the position */ error Cellar__PositionNotUsed(uint32 position); /** * @notice Attempted an action on a position that is required to be empty before the action can be performed. * @param position address of the non-empty position * @param sharesRemaining amount of shares remaining in the position */ error Cellar__PositionNotEmpty(uint32 position, uint256 sharesRemaining); /** * @notice Attempted an operation with an asset that was different then the one expected. * @param asset address of the asset * @param expectedAsset address of the expected asset */ error Cellar__AssetMismatch(address asset, address expectedAsset); /** * @notice Attempted to add a position when the position array is full. * @param maxPositions maximum number of positions that can be used */ error Cellar__PositionArrayFull(uint256 maxPositions); /** * @notice Attempted to add a position, with mismatched debt. * @param position the posiiton id that was mismatched */ error Cellar__DebtMismatch(uint32 position); /** * @notice Attempted to remove the Cellars holding position. */ error Cellar__RemovingHoldingPosition(); /** * @notice Attempted to add an invalid holding position. * @param positionId the id of the invalid position. */ error Cellar__InvalidHoldingPosition(uint32 positionId); /** * @notice Array of uint32s made up of cellars credit positions Ids. */ uint32[] public creditPositions; /** * @notice Array of uint32s made up of cellars debt positions Ids. */ uint32[] public debtPositions; /** * @notice Tell whether a position is currently used. */ mapping(uint256 => bool) public isPositionUsed; /** * @notice Get position data given position id. */ mapping(uint32 => Registry.PositionData) public getPositionData; /** * @notice Get the ids of the credit positions currently used by the cellar. */ function getCreditPositions() external view returns (uint32[] memory) { return creditPositions; } /** * @notice Get the ids of the debt positions currently used by the cellar. */ function getDebtPositions() external view returns (uint32[] memory) { return debtPositions; } /** * @notice Maximum amount of positions a cellar can have in it's credit/debt arrays. */ uint256 public constant MAX_POSITIONS = 16; /** * @notice Stores the index of the holding position in the creditPositions array. */ uint32 public holdingPosition; /** * @notice Allows owner to change the holding position. */ function setHoldingPosition(uint32 positionId) external onlyOwner { _setHoldingPosition(positionId); } function _setHoldingPosition(uint32 positionId) internal { if (!isPositionUsed[positionId]) revert Cellar__PositionNotUsed(positionId); if (_assetOf(positionId) != asset) revert Cellar__AssetMismatch(address(asset), address(_assetOf(positionId))); if (getPositionData[positionId].isDebt) revert Cellar__InvalidHoldingPosition(positionId); holdingPosition = positionId; } /** * @notice Insert a trusted position to the list of positions used by the cellar at a given index. * @param index index at which to insert the position * @param positionId id of position to add * @param configurationData data used to configure how the position behaves */ function addPosition( uint32 index, uint32 positionId, bytes memory configurationData, bool inDebtArray ) external onlyOwner whenNotShutdown { _addPosition(index, positionId, configurationData, inDebtArray); } /** * @notice Internal function ise used by `addPosition` and initialize function. */ function _addPosition( uint32 index, uint32 positionId, bytes memory configurationData, bool inDebtArray ) internal { // Check if position is already being used. if (isPositionUsed[positionId]) revert Cellar__PositionAlreadyUsed(positionId); // Grab position data from registry. (address adaptor, bool isDebt, bytes memory adaptorData) = registry.cellarAddPosition( positionId, assetRiskTolerance, protocolRiskTolerance ); if (isDebt != inDebtArray) revert Cellar__DebtMismatch(positionId); // Copy position data from registry to here. getPositionData[positionId] = Registry.PositionData({ adaptor: adaptor, isDebt: isDebt, adaptorData: adaptorData, configurationData: configurationData }); if (isDebt) { if (debtPositions.length >= MAX_POSITIONS) revert Cellar__PositionArrayFull(MAX_POSITIONS); // Add new position at a specified index. debtPositions.add(index, positionId); } else { if (creditPositions.length >= MAX_POSITIONS) revert Cellar__PositionArrayFull(MAX_POSITIONS); // Add new position at a specified index. creditPositions.add(index, positionId); } isPositionUsed[positionId] = true; emit PositionAdded(positionId, index); } /** * @notice Remove the position at a given index from the list of positions used by the cellar. * @param index index at which to remove the position */ function removePosition(uint32 index, bool inDebtArray) external onlyOwner { // Get position being removed. uint32 positionId = inDebtArray ? debtPositions[index] : creditPositions[index]; if (positionId == holdingPosition) revert Cellar__RemovingHoldingPosition(); // Only remove position if it is empty, and if it is not the holding position. uint256 positionBalance = _balanceOf(positionId); if (positionBalance > 0) revert Cellar__PositionNotEmpty(positionId, positionBalance); if (inDebtArray) { // Remove position at the given index. debtPositions.remove(index); } else { creditPositions.remove(index); } isPositionUsed[positionId] = false; delete getPositionData[positionId]; emit PositionRemoved(positionId, index); } /** * @notice Swap the positions at two given indexes. * @param index1 index of first position to swap * @param index2 index of second position to swap * @param inDebtArray bool indicating to switch positions in the debt array, or the credit array. */ function swapPositions( uint32 index1, uint32 index2, bool inDebtArray ) external onlyOwner { // Get the new positions that will be at each index. uint32 newPosition1; uint32 newPosition2; if (inDebtArray) { newPosition1 = debtPositions[index2]; newPosition2 = debtPositions[index1]; // Swap positions. (debtPositions[index1], debtPositions[index2]) = (newPosition1, newPosition2); } else { newPosition1 = creditPositions[index2]; newPosition2 = creditPositions[index1]; // Swap positions. (creditPositions[index1], creditPositions[index2]) = (newPosition1, newPosition2); } emit PositionSwapped(newPosition1, newPosition2, index1, index2); } // =============================================== FEES CONFIG =============================================== /** * @notice Emitted when platform fees is changed. * @param oldPlatformFee value platform fee was changed from * @param newPlatformFee value platform fee was changed to */ event PlatformFeeChanged(uint64 oldPlatformFee, uint64 newPlatformFee); /** * @notice Emitted when strategist platform fee cut is changed. * @param oldPlatformCut value strategist platform fee cut was changed from * @param newPlatformCut value strategist platform fee cut was changed to */ event StrategistPlatformCutChanged(uint64 oldPlatformCut, uint64 newPlatformCut); /** * @notice Emitted when strategists payout address is changed. * @param oldPayoutAddress value strategists payout address was changed from * @param newPayoutAddress value strategists payout address was changed to */ event StrategistPayoutAddressChanged(address oldPayoutAddress, address newPayoutAddress); /** * @notice Attempted to change strategist fee cut with invalid value. */ error Cellar__InvalidFeeCut(); /** * @notice Attempted to change platform fee with invalid value. */ error Cellar__InvalidFee(); /** * @notice Data related to fees. * @param strategistPlatformCut Determines how much platform fees go to strategist. * This should be a value out of 1e18 (ie. 1e18 represents 100%, 0 represents 0%). * @param platformFee The percentage of total assets accrued as platform fees over a year. This should be a value out of 1e18 (ie. 1e18 represents 100%, 0 represents 0%). * @param strategistPayoutAddress Address to send the strategists fee shares. */ struct FeeData { uint64 strategistPlatformCut; uint64 platformFee; uint64 lastAccrual; address strategistPayoutAddress; } /** * @notice Stores all fee data for cellar. */ FeeData public feeData = FeeData({ strategistPlatformCut: 0.75e18, platformFee: 0.01e18, lastAccrual: 0, strategistPayoutAddress: address(0) }); /** * @notice Sets the max possible performance fee for this cellar. */ uint64 public constant MAX_PLATFORM_FEE = 0.2e18; /** * @notice Sets the max possible fee cut for this cellar. */ uint64 public constant MAX_FEE_CUT = 1e18; /** * @notice Set the percentage of platform fees accrued over a year. * @param newPlatformFee value out of 1e18 that represents new platform fee percentage */ function setPlatformFee(uint64 newPlatformFee) external onlyOwner { if (newPlatformFee > MAX_PLATFORM_FEE) revert Cellar__InvalidFee(); emit PlatformFeeChanged(feeData.platformFee, newPlatformFee); feeData.platformFee = newPlatformFee; } /** * @notice Sets the Strategists cut of platform fees * @param cut the platform cut for the strategist */ function setStrategistPlatformCut(uint64 cut) external onlyOwner { if (cut > MAX_FEE_CUT) revert Cellar__InvalidFeeCut(); emit StrategistPlatformCutChanged(feeData.strategistPlatformCut, cut); feeData.strategistPlatformCut = cut; } /** * @notice Sets the Strategists payout address * @param payout the new strategist payout address */ function setStrategistPayoutAddress(address payout) external onlyOwner { emit StrategistPayoutAddressChanged(feeData.strategistPayoutAddress, payout); feeData.strategistPayoutAddress = payout; } // =========================================== EMERGENCY LOGIC =========================================== /** * @notice Emitted when cellar emergency state is changed. * @param isShutdown whether the cellar is shutdown */ event ShutdownChanged(bool isShutdown); /** * @notice Attempted action was prevented due to contract being shutdown. */ error Cellar__ContractShutdown(); /** * @notice Attempted action was prevented due to contract not being shutdown. */ error Cellar__ContractNotShutdown(); /** * @notice Whether or not the contract is shutdown in case of an emergency. */ bool public isShutdown; /** * @notice Prevent a function from being called during a shutdown. */ modifier whenNotShutdown() { if (isShutdown) revert Cellar__ContractShutdown(); _; } /** * @notice Shutdown the cellar. Used in an emergency or if the cellar has been deprecated. * @dev In the case where */ function initiateShutdown() external whenNotShutdown onlyOwner { isShutdown = true; emit ShutdownChanged(true); } /** * @notice Restart the cellar. */ function liftShutdown() external onlyOwner { if (!isShutdown) revert Cellar__ContractNotShutdown(); isShutdown = false; emit ShutdownChanged(false); } // =========================================== CONSTRUCTOR =========================================== /** * @notice Id to get the gravity bridge from the registry. */ uint256 public constant GRAVITY_BRIDGE_REGISTRY_SLOT = 0; /** * @notice Id to get the price router from the registry. */ uint256 public constant PRICE_ROUTER_REGISTRY_SLOT = 2; /** * @notice Address of the platform's registry contract. Used to get the latest address of modules. */ Registry public registry; /** * @notice Determines this cellars risk tolerance in regards to assets it is exposed to. * @dev 0: safest * type(uint128).max: no restrictions */ uint128 public assetRiskTolerance; /** * @notice Determines this cellars risk tolerance in regards to protocols it uses. * @dev 0: safest * type(uint128).max: no restrictions */ uint128 public protocolRiskTolerance; /** * @dev Owner should be set to the Gravity Bridge, which relays instructions from the Steward * module to the cellars. * https://github.com/PeggyJV/steward * https://github.com/cosmos/gravity-bridge/blob/main/solidity/contracts/Gravity.sol * @param _registry address of the platform's registry contract * @param _asset address of underlying token used for the for accounting, depositing, and withdrawing * @param _name name of this cellar's share token * @param _symbol symbol of this cellar's share token * @param params abi encode values. * - _creditPositions ids of the credit positions to initialize the cellar with * - _debtPositions ids of the credit positions to initialize the cellar with * - _creditConfigurationData configuration data for each position * - _debtConfigurationData configuration data for each position * - _holdingIndex the index in _creditPositions to use as the holding position. * - _strategistPayout the address to send the strategists fee shares. * - _assetRiskTolerance this cellars risk tolerance for assets it is exposed to * - _protocolRiskTolerance this cellars risk tolerance for protocols it will use */ constructor( Registry _registry, ERC20 _asset, string memory _name, string memory _symbol, bytes memory params ) ERC4626(_asset, _name, _symbol, 18) Owned(_registry.getAddress(GRAVITY_BRIDGE_REGISTRY_SLOT)) { registry = _registry; { ( uint32[] memory _creditPositions, uint32[] memory _debtPositions, bytes[] memory _creditConfigurationData, bytes[] memory _debtConfigurationData, uint32 _holdingPosition ) = abi.decode(params, (uint32[], uint32[], bytes[], bytes[], uint8)); // Initialize positions. for (uint32 i; i < _creditPositions.length; ++i) { _addPosition(i, _creditPositions[i], _creditConfigurationData[i], false); } for (uint32 i; i < _debtPositions.length; ++i) { _addPosition(i, _debtPositions[i], _debtConfigurationData[i], true); } // This check allows us to deploy an implementation contract. /// @dev No cellars will be deployed with a zero length credit positions array. if (_creditPositions.length > 0) _setHoldingPosition(_holdingPosition); } // Initialize last accrual timestamp to time that cellar was created, otherwise the first // `accrue` will take platform fees from 1970 to the time it is called. feeData.lastAccrual = uint64(block.timestamp); (, , , , , address _strategistPayout, uint128 _assetRiskTolerance, uint128 _protocolRiskTolerance) = abi.decode( params, (uint32[], uint32[], bytes[], bytes[], uint8, address, uint128, uint128) ); feeData.strategistPayoutAddress = _strategistPayout; assetRiskTolerance = _assetRiskTolerance; protocolRiskTolerance = _protocolRiskTolerance; } // =========================================== CORE LOGIC =========================================== /** * @notice Emitted when share locking period is changed. * @param oldPeriod the old locking period * @param newPeriod the new locking period */ event ShareLockingPeriodChanged(uint256 oldPeriod, uint256 newPeriod); /** * @notice Attempted an action with zero shares. */ error Cellar__ZeroShares(); /** * @notice Attempted an action with zero assets. */ error Cellar__ZeroAssets(); /** * @notice Withdraw did not withdraw all assets. * @param assetsOwed the remaining assets owed that were not withdrawn. */ error Cellar__IncompleteWithdraw(uint256 assetsOwed); /** * @notice Attempted to withdraw an illiquid position. * @param illiquidPosition the illiquid position. */ error Cellar__IlliquidWithdraw(address illiquidPosition); /** * @notice Attempted to set `shareLockPeriod` to an invalid number. */ error Cellar__InvalidShareLockPeriod(); /** * @notice Attempted to burn shares when they are locked. * @param timeSharesAreUnlocked time when caller can transfer/redeem shares * @param currentBlock the current block number. */ error Cellar__SharesAreLocked(uint256 timeSharesAreUnlocked, uint256 currentBlock); /** * @notice Attempted deposit on behalf of a user without being approved. */ error Cellar__NotApprovedToDepositOnBehalf(address depositor); /** * @notice Shares must be locked for at least 5 minutes after minting. */ uint256 public constant MINIMUM_SHARE_LOCK_PERIOD = 5 * 60; /** * @notice Shares can be locked for at most 2 days after minting. */ uint256 public constant MAXIMUM_SHARE_LOCK_PERIOD = 2 days; /** * @notice After deposits users must wait `shareLockPeriod` time before being able to transfer or withdraw their shares. */ uint256 public shareLockPeriod = MAXIMUM_SHARE_LOCK_PERIOD; /** * @notice mapping that stores every users last time stamp they minted shares. */ mapping(address => uint256) public userShareLockStartTime; /** * @notice Allows share lock period to be updated. * @param newLock the new lock period */ function setShareLockPeriod(uint256 newLock) external onlyOwner { if (newLock < MINIMUM_SHARE_LOCK_PERIOD || newLock > MAXIMUM_SHARE_LOCK_PERIOD) revert Cellar__InvalidShareLockPeriod(); uint256 oldLockingPeriod = shareLockPeriod; shareLockPeriod = newLock; emit ShareLockingPeriodChanged(oldLockingPeriod, newLock); } /** * @notice helper function that checks enough time has passed to unlock shares. * @param owner the address of the user to check */ function _checkIfSharesLocked(address owner) internal view { uint256 lockTime = userShareLockStartTime[owner]; if (lockTime != 0) { uint256 timeSharesAreUnlocked = lockTime + shareLockPeriod; if (timeSharesAreUnlocked > block.timestamp) revert Cellar__SharesAreLocked(timeSharesAreUnlocked, block.timestamp); } } /** * @notice Override `transfer` to add share lock check. */ function transfer(address to, uint256 amount) public override returns (bool) { _checkIfSharesLocked(msg.sender); return super.transfer(to, amount); } /** * @notice Override `transferFrom` to add share lock check. */ function transferFrom( address from, address to, uint256 amount ) public override returns (bool) { _checkIfSharesLocked(from); return super.transferFrom(from, to, amount); } /** * @notice Attempted deposit more than the max deposit. * @param assets the assets user attempted to deposit * @param maxDeposit the max assets that can be deposited */ error Cellar__DepositRestricted(uint256 assets, uint256 maxDeposit); /** * @notice called at the beginning of deposit. * @param assets amount of assets deposited by user. * @param receiver address receiving the shares. */ function beforeDeposit( uint256 assets, uint256, address receiver ) internal view override whenNotShutdown { if (msg.sender != receiver) { if (!registry.approvedForDepositOnBehalf(msg.sender)) revert Cellar__NotApprovedToDepositOnBehalf(msg.sender); } uint256 maxAssets = maxDeposit(receiver); if (assets > maxAssets) revert Cellar__DepositRestricted(assets, maxAssets); } /** * @notice called at the end of deposit. * @param assets amount of assets deposited by user. */ function afterDeposit( uint256 assets, uint256, address receiver ) internal override { _depositTo(holdingPosition, assets); userShareLockStartTime[receiver] = block.timestamp; } /** * @notice called at the beginning of withdraw. */ function beforeWithdraw( uint256, uint256, address, address owner ) internal view override { // Make sure users shares are not locked. _checkIfSharesLocked(owner); } function _enter( uint256 assets, uint256 shares, address receiver ) internal { beforeDeposit(assets, shares, receiver); // Need to transfer before minting or ERC777s could reenter. asset.safeTransferFrom(msg.sender, address(this), assets); _mint(receiver, shares); emit Deposit(msg.sender, receiver, assets, shares); afterDeposit(assets, shares, receiver); } /** * @notice Deposits assets into the cellar, and returns shares to receiver. * @param assets amount of assets deposited by user. * @param receiver address to receive the shares. * @return shares amount of shares given for deposit. */ function deposit(uint256 assets, address receiver) public override nonReentrant returns (uint256 shares) { // Use `_accounting` instead of totalAssets bc re-entrancy is already checked in this function. uint256 _totalAssets = _accounting(false); // Check for rounding error since we round down in previewDeposit. if ((shares = _convertToShares(assets, _totalAssets)) == 0) revert Cellar__ZeroShares(); _enter(assets, shares, receiver); } /** * @notice Mints shares from the cellar, and returns shares to receiver. * @param shares amount of shares requested by user. * @param receiver address to receive the shares. * @return assets amount of assets deposited into the cellar. */ function mint(uint256 shares, address receiver) public override nonReentrant returns (uint256 assets) { // Use `_accounting` instead of totalAssets bc re-entrancy is already checked in this function. uint256 _totalAssets = _accounting(false); // previewMint rounds up, but initial mint could return zero assets, so check for rounding error. if ((assets = _previewMint(shares, _totalAssets)) == 0) revert Cellar__ZeroAssets(); _enter(assets, shares, receiver); } function _exit( uint256 assets, uint256 shares, address receiver, address owner ) internal { beforeWithdraw(assets, shares, receiver, owner); if (msg.sender != owner) { uint256 allowed = allowance[owner][msg.sender]; // Saves gas for limited approvals. if (allowed != type(uint256).max) allowance[owner][msg.sender] = allowed - shares; } _burn(owner, shares); emit Withdraw(msg.sender, receiver, owner, assets, shares); _withdrawInOrder(assets, receiver); /// @notice `afterWithdraw` is currently not used. // afterWithdraw(assets, shares, receiver, owner); } /** * @notice Withdraw assets from the cellar by redeeming shares. * @dev Unlike conventional ERC4626 contracts, this may not always return one asset to the receiver. * Since there are no swaps involved in this function, the receiver may receive multiple * assets. The value of all the assets returned will be equal to the amount defined by * `assets` denominated in the `asset` of the cellar (eg. if `asset` is USDC and `assets` * is 1000, then the receiver will receive $1000 worth of assets in either one or many * tokens). * @param assets equivalent value of the assets withdrawn, denominated in the cellar's asset * @param receiver address that will receive withdrawn assets * @param owner address that owns the shares being redeemed * @return shares amount of shares redeemed */ function withdraw( uint256 assets, address receiver, address owner ) public override nonReentrant returns (uint256 shares) { // Use `_accounting` instead of totalAssets bc re-entrancy is already checked in this function. uint256 _totalAssets = _accounting(false); // No need to check for rounding error, `previewWithdraw` rounds up. shares = _previewWithdraw(assets, _totalAssets); _exit(assets, shares, receiver, owner); } /** * @notice Redeem shares to withdraw assets from the cellar. * @dev Unlike conventional ERC4626 contracts, this may not always return one asset to the receiver. * Since there are no swaps involved in this function, the receiver may receive multiple * assets. The value of all the assets returned will be equal to the amount defined by * `assets` denominated in the `asset` of the cellar (eg. if `asset` is USDC and `assets` * is 1000, then the receiver will receive $1000 worth of assets in either one or many * tokens). * @param shares amount of shares to redeem * @param receiver address that will receive withdrawn assets * @param owner address that owns the shares being redeemed * @return assets equivalent value of the assets withdrawn, denominated in the cellar's asset */ function redeem( uint256 shares, address receiver, address owner ) public override nonReentrant returns (uint256 assets) { // Use `_accounting` instead of totalAssets bc re-entrancy is already checked in this function. uint256 _totalAssets = _accounting(false); // Check for rounding error since we round down in previewRedeem. if ((assets = _convertToAssets(shares, _totalAssets)) == 0) revert Cellar__ZeroAssets(); _exit(assets, shares, receiver, owner); } /** * @notice Struct used in `_withdrawInOrder` in order to hold multiple pricing values in a single variable. * @dev Prevents stack too deep errors. */ struct WithdrawPricing { uint256 priceBaseUSD; uint256 oneBase; uint256 priceQuoteUSD; uint256 oneQuote; } /** * @notice Multipler used to insure calculations use very high precision. */ uint256 private constant PRECISION_MULTIPLIER = 1e18; /** * @dev Withdraw from positions in the order defined by `positions`. * @param assets the amount of assets to withdraw from cellar * @param receiver the address to sent withdrawn assets to * @dev Only loop through credit array because debt can not be withdraw by users. */ function _withdrawInOrder(uint256 assets, address receiver) internal { // Get the price router. PriceRouter priceRouter = PriceRouter(registry.getAddress(PRICE_ROUTER_REGISTRY_SLOT)); // Save asset price in USD, and decimals to reduce external calls. WithdrawPricing memory pricingInfo; pricingInfo.priceQuoteUSD = priceRouter.getPriceInUSD(asset); pricingInfo.oneQuote = 10**asset.decimals(); uint256 creditLength = creditPositions.length; for (uint256 i; i < creditLength; ++i) { uint32 position = creditPositions[i]; uint256 withdrawableBalance = _withdrawableFrom(position); // Move on to next position if this one is empty. if (withdrawableBalance == 0) continue; ERC20 positionAsset = _assetOf(position); pricingInfo.priceBaseUSD = priceRouter.getPriceInUSD(positionAsset); pricingInfo.oneBase = 10**positionAsset.decimals(); uint256 totalWithdrawableBalanceInAssets; { uint256 withdrawableBalanceInUSD = (PRECISION_MULTIPLIER * withdrawableBalance).mulDivDown( pricingInfo.priceBaseUSD, pricingInfo.oneBase ); totalWithdrawableBalanceInAssets = withdrawableBalanceInUSD.mulDivDown( pricingInfo.oneQuote, pricingInfo.priceQuoteUSD ); totalWithdrawableBalanceInAssets = totalWithdrawableBalanceInAssets / PRECISION_MULTIPLIER; } // We want to pull as much as we can from this position, but no more than needed. uint256 amount; if (totalWithdrawableBalanceInAssets > assets) { // Convert assets into position asset. uint256 assetsInUSD = (PRECISION_MULTIPLIER * assets).mulDivDown( pricingInfo.priceQuoteUSD, pricingInfo.oneQuote ); amount = assetsInUSD.mulDivDown(pricingInfo.oneBase, pricingInfo.priceBaseUSD); amount = amount / PRECISION_MULTIPLIER; assets = 0; } else { amount = withdrawableBalance; assets = assets - totalWithdrawableBalanceInAssets; } // Withdraw from position. _withdrawFrom(position, amount, receiver); // Stop if no more assets to withdraw. if (assets == 0) break; } // If withdraw did not remove all assets owed, revert. if (assets > 0) revert Cellar__IncompleteWithdraw(assets); } // ========================================= ACCOUNTING LOGIC ========================================= /** * @notice Internal accounting function that can report total assets, or total assets withdrawable. * @param reportWithdrawable if true, then the withdrawable total assets is reported, * if false, then the total assets is reported */ function _accounting(bool reportWithdrawable) internal view returns (uint256 assets) { uint256 numOfCreditPositions = creditPositions.length; ERC20[] memory creditAssets = new ERC20[](numOfCreditPositions); uint256[] memory creditBalances = new uint256[](numOfCreditPositions); PriceRouter priceRouter = PriceRouter(registry.getAddress(PRICE_ROUTER_REGISTRY_SLOT)); // If we just need the withdrawable, then query credit array value. if (reportWithdrawable) { for (uint256 i; i < numOfCreditPositions; ++i) { uint32 position = creditPositions[i]; // If the withdrawable balance is zero there is no point to query the asset since a zero balance has zero value. if ((creditBalances[i] = _withdrawableFrom(position)) == 0) continue; creditAssets[i] = _assetOf(position); } assets = priceRouter.getValues(creditAssets, creditBalances, asset); } else { uint256 numOfDebtPositions = debtPositions.length; ERC20[] memory debtAssets = new ERC20[](numOfDebtPositions); uint256[] memory debtBalances = new uint256[](numOfDebtPositions); for (uint256 i; i < numOfCreditPositions; ++i) { uint32 position = creditPositions[i]; // If the balance is zero there is no point to query the asset since a zero balance has zero value. if ((creditBalances[i] = _balanceOf(position)) == 0) continue; creditAssets[i] = _assetOf(position); } for (uint256 i; i < numOfDebtPositions; ++i) { uint32 position = debtPositions[i]; // If the balance is zero there is no point to query the asset since a zero balance has zero value. if ((debtBalances[i] = _balanceOf(position)) == 0) continue; debtAssets[i] = _assetOf(position); } assets = priceRouter.getValuesDelta(creditAssets, creditBalances, debtAssets, debtBalances, asset); } } /** * @notice The total amount of assets in the cellar. * @dev EIP4626 states totalAssets needs to be inclusive of fees. * Since performance fees mint shares, total assets remains unchanged, * so this implementation is inclusive of fees even though it does not explicitly show it. * @dev EIP4626 states totalAssets must not revert, but it is possible for `totalAssets` to revert * so it does NOT conform to ERC4626 standards. * @dev Run a re-entrancy check because totalAssets can be wrong if re-entering from deposit/withdraws. */ function totalAssets() public view override returns (uint256 assets) { require(locked == 1, "REENTRANCY"); assets = _accounting(false); } /** * @notice The total amount of withdrawable assets in the cellar. * @dev Run a re-entrancy check because totalAssetsWithdrawable can be wrong if re-entering from deposit/withdraws. */ function totalAssetsWithdrawable() public view returns (uint256 assets) { require(locked == 1, "REENTRANCY"); assets = _accounting(true); } /** * @notice The amount of assets that the cellar would exchange for the amount of shares provided. * @param shares amount of shares to convert * @return assets the shares can be exchanged for */ function convertToAssets(uint256 shares) public view override returns (uint256 assets) { assets = _convertToAssets(shares, totalAssets()); } /** * @notice The amount of shares that the cellar would exchange for the amount of assets provided. * @param assets amount of assets to convert * @return shares the assets can be exchanged for */ function convertToShares(uint256 assets) public view override returns (uint256 shares) { shares = _convertToShares(assets, totalAssets()); } /** * @notice Simulate the effects of minting shares at the current block, given current on-chain conditions. * @param shares amount of shares to mint * @return assets that will be deposited */ function previewMint(uint256 shares) public view override returns (uint256 assets) { uint256 _totalAssets = totalAssets(); assets = _previewMint(shares, _totalAssets); } /** * @notice Simulate the effects of withdrawing assets at the current block, given current on-chain conditions. * @param assets amount of assets to withdraw * @return shares that will be redeemed */ function previewWithdraw(uint256 assets) public view override returns (uint256 shares) { uint256 _totalAssets = totalAssets(); shares = _previewWithdraw(assets, _totalAssets); } /** * @notice Simulate the effects of depositing assets at the current block, given current on-chain conditions. * @param assets amount of assets to deposit * @return shares that will be minted */ function previewDeposit(uint256 assets) public view override returns (uint256 shares) { uint256 _totalAssets = totalAssets(); shares = _convertToShares(assets, _totalAssets); } /** * @notice Simulate the effects of redeeming shares at the current block, given current on-chain conditions. * @param shares amount of shares to redeem * @return assets that will be returned */ function previewRedeem(uint256 shares) public view override returns (uint256 assets) { uint256 _totalAssets = totalAssets(); assets = _convertToAssets(shares, _totalAssets); } /** * @notice Finds the max amount of value an `owner` can remove from the cellar. * @param owner address of the user to find max value. * @param inShares if false, then returns value in terms of assets * if true then returns value in terms of shares */ function _findMax(address owner, bool inShares) internal view returns (uint256 maxOut) { // Check if owner shares are locked, return 0 if so. uint256 lockTime = userShareLockStartTime[owner]; if (lockTime != 0) { uint256 timeSharesAreUnlocked = lockTime + shareLockPeriod; if (timeSharesAreUnlocked > block.timestamp) return 0; } // Get amount of assets to withdraw. uint256 _totalAssets = _accounting(false); uint256 assets = _convertToAssets(balanceOf[owner], _totalAssets); uint256 withdrawable = _accounting(true); maxOut = assets <= withdrawable ? assets : withdrawable; if (inShares) maxOut = _convertToShares(maxOut, _totalAssets); // else leave maxOut in terms of assets. } /** * @notice Returns the max amount withdrawable by a user inclusive of performance fees * @dev EIP4626 states maxWithdraw must not revert, but it is possible for `totalAssets` to revert * so it does NOT conform to ERC4626 standards. * @param owner address to check maxWithdraw of. * @return the max amount of assets withdrawable by `owner`. */ function maxWithdraw(address owner) public view override returns (uint256) { require(locked == 1, "REENTRANCY"); return _findMax(owner, false); } /** * @notice Returns the max amount shares redeemable by a user * @dev EIP4626 states maxRedeem must not revert, but it is possible for `totalAssets` to revert * so it does NOT conform to ERC4626 standards. * @param owner address to check maxRedeem of. * @return the max amount of shares redeemable by `owner`. */ function maxRedeem(address owner) public view override returns (uint256) { require(locked == 1, "REENTRANCY"); return _findMax(owner, true); } /** * @dev Used to more efficiently convert amount of shares to assets using a stored `totalAssets` value. */ function _convertToAssets(uint256 shares, uint256 _totalAssets) internal view returns (uint256 assets) { uint256 totalShares = totalSupply; assets = totalShares == 0 ? shares.changeDecimals(18, asset.decimals()) : shares.mulDivDown(_totalAssets, totalShares); } /** * @dev Used to more efficiently convert amount of assets to shares using a stored `totalAssets` value. */ function _convertToShares(uint256 assets, uint256 _totalAssets) internal view returns (uint256 shares) { uint256 totalShares = totalSupply; shares = totalShares == 0 ? assets.changeDecimals(asset.decimals(), 18) : assets.mulDivDown(totalShares, _totalAssets); } /** * @dev Used to more efficiently simulate minting shares using a stored `totalAssets` value. */ function _previewMint(uint256 shares, uint256 _totalAssets) internal view returns (uint256 assets) { uint256 totalShares = totalSupply; assets = totalShares == 0 ? shares.changeDecimals(18, asset.decimals()) : shares.mulDivUp(_totalAssets, totalShares); } /** * @dev Used to more efficiently simulate withdrawing assets using a stored `totalAssets` value. */ function _previewWithdraw(uint256 assets, uint256 _totalAssets) internal view returns (uint256 shares) { uint256 totalShares = totalSupply; shares = totalShares == 0 ? assets.changeDecimals(asset.decimals(), 18) : assets.mulDivUp(totalShares, _totalAssets); } // =========================================== ADAPTOR LOGIC =========================================== /** * @notice Emitted on when the rebalance deviation is changed. * @param oldDeviation the old rebalance deviation * @param newDeviation the new rebalance deviation */ event RebalanceDeviationChanged(uint256 oldDeviation, uint256 newDeviation); /** * @notice totalAssets deviated outside the range set by `allowedRebalanceDeviation`. * @param assets the total assets in the cellar * @param min the minimum allowed assets * @param max the maximum allowed assets */ error Cellar__TotalAssetDeviatedOutsideRange(uint256 assets, uint256 min, uint256 max); /** * @notice Total shares in a cellar changed when they should stay constant. * @param current the current amount of total shares * @param expected the expected amount of total shares */ error Cellar__TotalSharesMustRemainConstant(uint256 current, uint256 expected); /** * @notice Total shares in a cellar changed when they should stay constant. * @param requested the requested rebalance deviation * @param max the max rebalance deviation. */ error Cellar__InvalidRebalanceDeviation(uint256 requested, uint256 max); /** * @notice Strategist attempted to use an adaptor that was not set up to be used with this cellar. * @param adaptor the adaptor address that is not set up */ error Cellar__AdaptorNotSetUp(address adaptor); /** * @notice Maps an address to a bool indicating whether or not an adaptor * has been set up to be used with this cellar. */ mapping(address => bool) public isAdaptorSetup; /** * @notice Allows owner to add new adaptors for the cellar to use. */ function setupAdaptor(address _adaptor) external onlyOwner { // Following call reverts if adaptor does not exist, or if it does not meet cellars risk appetite. registry.cellarSetupAdaptor(_adaptor, assetRiskTolerance, protocolRiskTolerance); isAdaptorSetup[_adaptor] = true; } /** * @notice Stores the max possible rebalance deviation for this cellar. */ uint64 public constant MAX_REBALANCE_DEVIATION = 0.1e18; /** * @notice The percent the total assets of a cellar may deviate during a `callOnAdaptor`(rebalance) call. */ uint256 public allowedRebalanceDeviation = 0.0003e18; /** * @notice Allows governance to change this cellars rebalance deviation. * @param newDeviation the new rebalance deviation value. */ function setRebalanceDeviation(uint256 newDeviation) external onlyOwner { if (newDeviation > MAX_REBALANCE_DEVIATION) revert Cellar__InvalidRebalanceDeviation(newDeviation, MAX_REBALANCE_DEVIATION); uint256 oldDeviation = allowedRebalanceDeviation; allowedRebalanceDeviation = newDeviation; emit RebalanceDeviationChanged(oldDeviation, newDeviation); } // Set to true before any adaptor calls are made. /** * @notice This bool is used to stop strategists from abusing Base Adaptor functions(deposit/withdraw). */ bool public blockExternalReceiver; /** * @notice Struct used to make calls to adaptors. * @param adaptor the address of the adaptor to make calls to * @param the abi encoded function calls to make to the `adaptor` */ struct AdaptorCall { address adaptor; bytes[] callData; } /** * @notice Allows strategists to manage their Cellar using arbitrary logic calls to adaptors. * @dev There are several safety checks in this function to prevent strategists from abusing it. * - `blockExternalReceiver` * - `totalAssets` must not change by much * - `totalShares` must remain constant * - adaptors must be set up to be used with this cellar * @dev Since `totalAssets` is allowed to deviate slightly, strategists could abuse this by sending * multiple `callOnAdaptor` calls rapidly, to gradually change the share price. * To mitigate this, rate limiting will be put in place on the Sommelier side. */ function callOnAdaptor(AdaptorCall[] memory data) external onlyOwner whenNotShutdown nonReentrant { blockExternalReceiver = true; // Record `totalAssets` and `totalShares` before making any external calls. uint256 minimumAllowedAssets; uint256 maximumAllowedAssets; uint256 totalShares; { uint256 assetsBeforeAdaptorCall = _accounting(false); minimumAllowedAssets = assetsBeforeAdaptorCall.mulDivUp((1e18 - allowedRebalanceDeviation), 1e18); maximumAllowedAssets = assetsBeforeAdaptorCall.mulDivUp((1e18 + allowedRebalanceDeviation), 1e18); totalShares = totalSupply; } // Run all adaptor calls. for (uint8 i = 0; i < data.length; ++i) { address adaptor = data[i].adaptor; if (!isAdaptorSetup[adaptor]) revert Cellar__AdaptorNotSetUp(adaptor); for (uint8 j = 0; j < data[i].callData.length; j++) { adaptor.functionDelegateCall(data[i].callData[j]); } } // After making every external call, check that the totalAssets haas not deviated significantly, and that totalShares is the same. uint256 assets = _accounting(false); if (assets < minimumAllowedAssets || assets > maximumAllowedAssets) { revert Cellar__TotalAssetDeviatedOutsideRange(assets, minimumAllowedAssets, maximumAllowedAssets); } if (totalShares != totalSupply) revert Cellar__TotalSharesMustRemainConstant(totalSupply, totalShares); blockExternalReceiver = false; } // ========================================= Aave Flash Loan Support ========================================= /** * @notice External contract attempted to initiate a flash loan. */ error Cellar__ExternalInitiator(); /** * @notice executeOperation was not called by the Aave Pool. */ error Cellar__CallerNotAavePool(); /** * @notice The Aave V2 Pool contract on Ethereum Mainnet. */ address public aavePool = 0x7d2768dE32b0b80b7a3454c06BdAc94A69DDc7A9; /** * @notice Allows strategist to utilize Aave V2 flashloans while rebalancing the cellar. */ function executeOperation( address[] calldata assets, uint256[] calldata amounts, uint256[] calldata premiums, address initiator, bytes calldata params ) external returns (bool) { if (initiator != address(this)) revert Cellar__ExternalInitiator(); if (msg.sender != aavePool) revert Cellar__CallerNotAavePool(); AdaptorCall[] memory data = abi.decode(params, (AdaptorCall[])); // Run all adaptor calls. for (uint8 i = 0; i < data.length; ++i) { address adaptor = data[i].adaptor; if (!isAdaptorSetup[adaptor]) revert Cellar__AdaptorNotSetUp(adaptor); for (uint8 j = 0; j < data[i].callData.length; j++) { adaptor.functionDelegateCall(data[i].callData[j]); } } // Approve pool to repay all debt. for (uint256 i = 0; i < amounts.length; ++i) { ERC20(assets[i]).safeApprove(aavePool, (amounts[i] + premiums[i])); } return true; } // ============================================ LIMITS LOGIC ============================================ /** * @notice Total amount of assets that can be deposited for a user. * @return assets maximum amount of assets that can be deposited */ function maxDeposit(address) public view override returns (uint256) { if (isShutdown) return 0; return type(uint256).max; } /** * @notice Total amount of shares that can be minted for a user. * @return shares maximum amount of shares that can be minted */ function maxMint(address) public view override returns (uint256) { if (isShutdown) return 0; return type(uint256).max; } // ========================================= FEES LOGIC ========================================= /** * @notice Attempted to send fee shares to strategist payout address, when address is not set. */ error Cellar__PayoutNotSet(); /** * @dev Calculate the amount of fees to mint such that value of fees after minting is not diluted. */ function _convertToFees(uint256 feesInShares) internal view returns (uint256 fees) { // Saves an SLOAD. uint256 totalShares = totalSupply; // Get the amount of fees to mint. Without this, the value of fees minted would be slightly // diluted because total shares increased while total assets did not. This counteracts that. if (totalShares > feesInShares) { // Denominator is greater than zero uint256 denominator = totalShares - feesInShares; fees = feesInShares.mulDivUp(totalShares, denominator); } // If denominator is less than or equal to zero, `fees` should be zero. } /** * @notice Emitted when platform fees are send to the Sommelier chain. * @param feesInSharesRedeemed amount of fees redeemed for assets to send * @param feesInAssetsSent amount of assets fees were redeemed for that were sent */ event SendFees(uint256 feesInSharesRedeemed, uint256 feesInAssetsSent); /** * @notice Transfer accrued fees to the Sommelier chain to distribute. * @dev Fees are accrued as shares and redeemed upon transfer. * @dev assumes cellar's accounting asset is able to be transferred and sent to Cosmos */ function sendFees() external nonReentrant { address strategistPayoutAddress = feeData.strategistPayoutAddress; if (strategistPayoutAddress == address(0)) revert Cellar__PayoutNotSet(); uint256 _totalAssets = _accounting(false); // Calculate platform fees earned. uint256 elapsedTime = block.timestamp - feeData.lastAccrual; uint256 platformFeeInAssets = (_totalAssets * elapsedTime * feeData.platformFee) / 1e18 / 365 days; uint256 platformFees = _convertToFees(_convertToShares(platformFeeInAssets, _totalAssets)); _mint(address(this), platformFees); uint256 strategistFeeSharesDue = platformFees.mulWadDown(feeData.strategistPlatformCut); if (strategistFeeSharesDue > 0) { //transfer shares to strategist // Take from Solmate ERC20.sol { balanceOf[address(this)] -= strategistFeeSharesDue; // Cannot overflow because the sum of all user // balances can't exceed the max uint256 value. unchecked { balanceOf[strategistPayoutAddress] += strategistFeeSharesDue; } emit Transfer(address(this), strategistPayoutAddress, strategistFeeSharesDue); } // _transfer(address(this), strategistPayoutAddress, strategistFeeSharesDue); platformFees -= strategistFeeSharesDue; } feeData.lastAccrual = uint32(block.timestamp); // Redeem our fee shares for assets to send to the fee distributor module. uint256 assets = _convertToAssets(platformFees, _totalAssets); if (assets > 0) { _burn(address(this), platformFees); // Transfer assets to a fee distributor on the Sommelier chain. IGravity gravityBridge = IGravity(registry.getAddress(GRAVITY_BRIDGE_REGISTRY_SLOT)); asset.safeApprove(address(gravityBridge), assets); gravityBridge.sendToCosmos(address(asset), registry.feesDistributor(), assets); } emit SendFees(platformFees, assets); } // ========================================== HELPER FUNCTIONS ========================================== /** * @dev Deposit into a position according to its position type and update related state. * @param position address to deposit funds into * @param assets the amount of assets to deposit into the position */ function _depositTo(uint32 position, uint256 assets) internal { address adaptor = getPositionData[position].adaptor; adaptor.functionDelegateCall( abi.encodeWithSelector( BaseAdaptor.deposit.selector, assets, getPositionData[position].adaptorData, getPositionData[position].configurationData ) ); } /** * @dev Withdraw from a position according to its position type and update related state. * @param position address to withdraw funds from * @param assets the amount of assets to withdraw from the position * @param receiver the address to sent withdrawn assets to */ function _withdrawFrom( uint32 position, uint256 assets, address receiver ) internal { address adaptor = getPositionData[position].adaptor; adaptor.functionDelegateCall( abi.encodeWithSelector( BaseAdaptor.withdraw.selector, assets, receiver, getPositionData[position].adaptorData, getPositionData[position].configurationData ) ); } /** * @dev Get the withdrawable balance of a position according to its position type. * @param position position to get the withdrawable balance of */ function _withdrawableFrom(uint32 position) internal view returns (uint256) { // Debt positions always return 0 for their withdrawable. if (getPositionData[position].isDebt) return 0; return BaseAdaptor(getPositionData[position].adaptor).withdrawableFrom( getPositionData[position].adaptorData, getPositionData[position].configurationData ); } /** * @dev Get the balance of a position according to its position type. * @dev For ERC4626 position balances, this uses `previewRedeem` as opposed * to `convertToAssets` so that balanceOf ERC4626 positions includes fees taken on withdraw. * @param position position to get the balance of */ function _balanceOf(uint32 position) internal view returns (uint256) { address adaptor = getPositionData[position].adaptor; return BaseAdaptor(adaptor).balanceOf(getPositionData[position].adaptorData); } /** * @dev Get the asset of a position according to its position type. * @param position to get the asset of */ function _assetOf(uint32 position) internal view returns (ERC20) { address adaptor = getPositionData[position].adaptor; return BaseAdaptor(adaptor).assetOf(getPositionData[position].adaptorData); } /** * @notice Get all the credit positions underlying assets. */ function getPositionAssets() external view returns (ERC20[] memory assets) { assets = new ERC20[](creditPositions.length); for (uint256 i = 0; i < creditPositions.length; ++i) { assets[i] = _assetOf(creditPositions[i]); } } }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity >=0.8.0; /// @notice Modern and gas efficient ERC20 + EIP-2612 implementation. /// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/tokens/ERC20.sol) /// @author Modified from Uniswap (https://github.com/Uniswap/uniswap-v2-core/blob/master/contracts/UniswapV2ERC20.sol) /// @dev Do not manually set balances without updating totalSupply, as the sum of all user balances must not exceed it. abstract contract ERC20 { /*////////////////////////////////////////////////////////////// EVENTS //////////////////////////////////////////////////////////////*/ event Transfer(address indexed from, address indexed to, uint256 amount); event Approval(address indexed owner, address indexed spender, uint256 amount); /*////////////////////////////////////////////////////////////// METADATA STORAGE //////////////////////////////////////////////////////////////*/ string public name; string public symbol; uint8 public decimals; /*////////////////////////////////////////////////////////////// ERC20 STORAGE //////////////////////////////////////////////////////////////*/ uint256 public totalSupply; mapping(address => uint256) public balanceOf; mapping(address => mapping(address => uint256)) public allowance; /*////////////////////////////////////////////////////////////// EIP-2612 STORAGE //////////////////////////////////////////////////////////////*/ uint256 internal INITIAL_CHAIN_ID; bytes32 internal INITIAL_DOMAIN_SEPARATOR; mapping(address => uint256) public nonces; /*////////////////////////////////////////////////////////////// CONSTRUCTOR //////////////////////////////////////////////////////////////*/ constructor( string memory _name, string memory _symbol, uint8 _decimals ) { name = _name; symbol = _symbol; decimals = _decimals; INITIAL_CHAIN_ID = block.chainid; INITIAL_DOMAIN_SEPARATOR = computeDomainSeparator(); } /*////////////////////////////////////////////////////////////// ERC20 LOGIC //////////////////////////////////////////////////////////////*/ function approve(address spender, uint256 amount) public virtual returns (bool) { allowance[msg.sender][spender] = amount; emit Approval(msg.sender, spender, amount); return true; } function transfer(address to, uint256 amount) public virtual returns (bool) { balanceOf[msg.sender] -= amount; // Cannot overflow because the sum of all user // balances can't exceed the max uint256 value. unchecked { balanceOf[to] += amount; } emit Transfer(msg.sender, to, amount); return true; } function transferFrom( address from, address to, uint256 amount ) public virtual returns (bool) { uint256 allowed = allowance[from][msg.sender]; // Saves gas for limited approvals. if (allowed != type(uint256).max) allowance[from][msg.sender] = allowed - amount; balanceOf[from] -= amount; // Cannot overflow because the sum of all user // balances can't exceed the max uint256 value. unchecked { balanceOf[to] += amount; } emit Transfer(from, to, amount); return true; } /*////////////////////////////////////////////////////////////// EIP-2612 LOGIC //////////////////////////////////////////////////////////////*/ function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) public virtual { require(deadline >= block.timestamp, "PERMIT_DEADLINE_EXPIRED"); // Unchecked because the only math done is incrementing // the owner's nonce which cannot realistically overflow. unchecked { address recoveredAddress = ecrecover( keccak256( abi.encodePacked( "\x19\x01", DOMAIN_SEPARATOR(), keccak256( abi.encode( keccak256( "Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)" ), owner, spender, value, nonces[owner]++, deadline ) ) ) ), v, r, s ); require(recoveredAddress != address(0) && recoveredAddress == owner, "INVALID_SIGNER"); allowance[recoveredAddress][spender] = value; } emit Approval(owner, spender, value); } function DOMAIN_SEPARATOR() public view virtual returns (bytes32) { return block.chainid == INITIAL_CHAIN_ID ? INITIAL_DOMAIN_SEPARATOR : computeDomainSeparator(); } function computeDomainSeparator() internal view virtual returns (bytes32) { return keccak256( abi.encode( keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"), keccak256(bytes(name)), keccak256("1"), block.chainid, address(this) ) ); } /*////////////////////////////////////////////////////////////// INTERNAL MINT/BURN LOGIC //////////////////////////////////////////////////////////////*/ function _mint(address to, uint256 amount) internal virtual { totalSupply += amount; // Cannot overflow because the sum of all user // balances can't exceed the max uint256 value. unchecked { balanceOf[to] += amount; } emit Transfer(address(0), to, amount); } function _burn(address from, uint256 amount) internal virtual { balanceOf[from] -= amount; // Cannot underflow because a user's balance // will never be larger than the total supply. unchecked { totalSupply -= amount; } emit Transfer(from, address(0), amount); } }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity >=0.8.0; import { ERC20 } from "src/base/ERC20.sol"; import { SafeTransferLib } from "src/base/SafeTransferLib.sol"; import { Math } from "src/utils/Math.sol"; /// @notice Minimal ERC4626 tokenized Vault implementation. /// @author Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/mixins/ERC4626.sol) abstract contract ERC4626 is ERC20 { using SafeTransferLib for ERC20; using Math for uint256; /*////////////////////////////////////////////////////////////// EVENTS //////////////////////////////////////////////////////////////*/ event Deposit(address indexed caller, address indexed owner, uint256 assets, uint256 shares); event Withdraw( address indexed caller, address indexed receiver, address indexed owner, uint256 assets, uint256 shares ); /*////////////////////////////////////////////////////////////// IMMUTABLES //////////////////////////////////////////////////////////////*/ ERC20 public asset; constructor( ERC20 _asset, string memory _name, string memory _symbol, uint8 _decimals ) ERC20(_name, _symbol, _decimals) { asset = _asset; } /*////////////////////////////////////////////////////////////// DEPOSIT/WITHDRAWAL LOGIC //////////////////////////////////////////////////////////////*/ function deposit(uint256 assets, address receiver) public virtual returns (uint256 shares) { // Check for rounding error since we round down in previewDeposit. require((shares = previewDeposit(assets)) != 0, "ZERO_SHARES"); beforeDeposit(assets, shares, receiver); // Need to transfer before minting or ERC777s could reenter. asset.safeTransferFrom(msg.sender, address(this), assets); _mint(receiver, shares); emit Deposit(msg.sender, receiver, assets, shares); afterDeposit(assets, shares, receiver); } function mint(uint256 shares, address receiver) public virtual returns (uint256 assets) { assets = previewMint(shares); // No need to check for rounding error, previewMint rounds up. beforeDeposit(assets, shares, receiver); // Need to transfer before minting or ERC777s could reenter. asset.safeTransferFrom(msg.sender, address(this), assets); _mint(receiver, shares); emit Deposit(msg.sender, receiver, assets, shares); afterDeposit(assets, shares, receiver); } function withdraw( uint256 assets, address receiver, address owner ) public virtual returns (uint256 shares) { shares = previewWithdraw(assets); // No need to check for rounding error, previewWithdraw rounds up. if (msg.sender != owner) { uint256 allowed = allowance[owner][msg.sender]; // Saves gas for limited approvals. if (allowed != type(uint256).max) allowance[owner][msg.sender] = allowed - shares; } beforeWithdraw(assets, shares, receiver, owner); _burn(owner, shares); emit Withdraw(msg.sender, receiver, owner, assets, shares); asset.safeTransfer(receiver, assets); afterWithdraw(assets, shares, receiver, owner); } function redeem( uint256 shares, address receiver, address owner ) public virtual returns (uint256 assets) { if (msg.sender != owner) { uint256 allowed = allowance[owner][msg.sender]; // Saves gas for limited approvals. if (allowed != type(uint256).max) allowance[owner][msg.sender] = allowed - shares; } // Check for rounding error since we round down in previewRedeem. require((assets = previewRedeem(shares)) != 0, "ZERO_ASSETS"); beforeWithdraw(assets, shares, receiver, owner); _burn(owner, shares); emit Withdraw(msg.sender, receiver, owner, assets, shares); asset.safeTransfer(receiver, assets); afterWithdraw(assets, shares, receiver, owner); } /*////////////////////////////////////////////////////////////// ACCOUNTING LOGIC //////////////////////////////////////////////////////////////*/ function totalAssets() public view virtual returns (uint256); function convertToShares(uint256 assets) public view virtual returns (uint256) { uint256 supply = totalSupply; // Saves an extra SLOAD if totalSupply is non-zero. return supply == 0 ? assets : assets.mulDivDown(supply, totalAssets()); } function convertToAssets(uint256 shares) public view virtual returns (uint256) { uint256 supply = totalSupply; // Saves an extra SLOAD if totalSupply is non-zero. return supply == 0 ? shares : shares.mulDivDown(totalAssets(), supply); } function previewDeposit(uint256 assets) public view virtual returns (uint256) { return convertToShares(assets); } function previewMint(uint256 shares) public view virtual returns (uint256) { uint256 supply = totalSupply; // Saves an extra SLOAD if totalSupply is non-zero. return supply == 0 ? shares : shares.mulDivUp(totalAssets(), supply); } function previewWithdraw(uint256 assets) public view virtual returns (uint256) { uint256 supply = totalSupply; // Saves an extra SLOAD if totalSupply is non-zero. return supply == 0 ? assets : assets.mulDivUp(supply, totalAssets()); } function previewRedeem(uint256 shares) public view virtual returns (uint256) { return convertToAssets(shares); } /*////////////////////////////////////////////////////////////// DEPOSIT/WITHDRAWAL LIMIT LOGIC //////////////////////////////////////////////////////////////*/ function maxDeposit(address) public view virtual returns (uint256) { return type(uint256).max; } function maxMint(address) public view virtual returns (uint256) { return type(uint256).max; } function maxWithdraw(address owner) public view virtual returns (uint256) { return convertToAssets(balanceOf[owner]); } function maxRedeem(address owner) public view virtual returns (uint256) { return balanceOf[owner]; } /*////////////////////////////////////////////////////////////// INTERNAL HOOKS LOGIC //////////////////////////////////////////////////////////////*/ function beforeDeposit( uint256 assets, uint256 shares, address receiver ) internal virtual {} function afterDeposit( uint256 assets, uint256 shares, address receiver ) internal virtual {} function beforeWithdraw( uint256 assets, uint256 shares, address receiver, address owner ) internal virtual {} function afterWithdraw( uint256 assets, uint256 shares, address receiver, address owner ) internal virtual {} }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.8.0; import { IMulticall } from "src/interfaces/IMulticall.sol"; /** * @title Multicall * @notice Enables calling multiple methods in a single call to the contract * From: https://github.com/Uniswap/v3-periphery/blob/1d69caf0d6c8cfeae9acd1f34ead30018d6e6400/contracts/base/Multicall.sol */ abstract contract Multicall is IMulticall { /// @inheritdoc IMulticall function multicall(bytes[] calldata data) public payable override returns (bytes[] memory results) { results = new bytes[](data.length); for (uint256 i = 0; i < data.length; i++) { (bool success, bytes memory result) = address(this).delegatecall(data[i]); if (!success) { // Next 5 lines from https://ethereum.stackexchange.com/a/83577 // solhint-disable-next-line reason-string if (result.length < 68) revert(); assembly { result := add(result, 0x04) } revert(abi.decode(result, (string))); } results[i] = result; } } }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity >=0.8.0; import { ERC20 } from "src/base/ERC20.sol"; /// @notice Safe ETH and ERC20 transfer library that gracefully handles missing return values. /// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/SafeTransferLib.sol) /// @dev Use with caution! Some functions in this library knowingly create dirty bits at the destination of the free memory pointer. /// @dev Note that none of the functions in this library check that a token has code at all! That responsibility is delegated to the caller. library SafeTransferLib { /*////////////////////////////////////////////////////////////// ETH OPERATIONS //////////////////////////////////////////////////////////////*/ function safeTransferETH(address to, uint256 amount) internal { bool success; assembly { // Transfer the ETH and store if it succeeded or not. success := call(gas(), to, amount, 0, 0, 0, 0) } require(success, "ETH_TRANSFER_FAILED"); } /*////////////////////////////////////////////////////////////// ERC20 OPERATIONS //////////////////////////////////////////////////////////////*/ function safeTransferFrom( ERC20 token, address from, address to, uint256 amount ) internal { bool success; assembly { // Get a pointer to some free memory. let freeMemoryPointer := mload(0x40) // Write the abi-encoded calldata into memory, beginning with the function selector. mstore(freeMemoryPointer, 0x23b872dd00000000000000000000000000000000000000000000000000000000) mstore(add(freeMemoryPointer, 4), from) // Append the "from" argument. mstore(add(freeMemoryPointer, 36), to) // Append the "to" argument. mstore(add(freeMemoryPointer, 68), amount) // Append the "amount" argument. success := and( // Set success to whether the call reverted, if not we check it either // returned exactly 1 (can't just be non-zero data), or had no return data. or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())), // We use 100 because the length of our calldata totals up like so: 4 + 32 * 3. // We use 0 and 32 to copy up to 32 bytes of return data into the scratch space. // Counterintuitively, this call must be positioned second to the or() call in the // surrounding and() call or else returndatasize() will be zero during the computation. call(gas(), token, 0, freeMemoryPointer, 100, 0, 32) ) } require(success, "TRANSFER_FROM_FAILED"); } function safeTransfer( ERC20 token, address to, uint256 amount ) internal { bool success; assembly { // Get a pointer to some free memory. let freeMemoryPointer := mload(0x40) // Write the abi-encoded calldata into memory, beginning with the function selector. mstore(freeMemoryPointer, 0xa9059cbb00000000000000000000000000000000000000000000000000000000) mstore(add(freeMemoryPointer, 4), to) // Append the "to" argument. mstore(add(freeMemoryPointer, 36), amount) // Append the "amount" argument. success := and( // Set success to whether the call reverted, if not we check it either // returned exactly 1 (can't just be non-zero data), or had no return data. or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())), // We use 68 because the length of our calldata totals up like so: 4 + 32 * 2. // We use 0 and 32 to copy up to 32 bytes of return data into the scratch space. // Counterintuitively, this call must be positioned second to the or() call in the // surrounding and() call or else returndatasize() will be zero during the computation. call(gas(), token, 0, freeMemoryPointer, 68, 0, 32) ) } require(success, "TRANSFER_FAILED"); } function safeApprove( ERC20 token, address to, uint256 amount ) internal { bool success; assembly { // Get a pointer to some free memory. let freeMemoryPointer := mload(0x40) // Write the abi-encoded calldata into memory, beginning with the function selector. mstore(freeMemoryPointer, 0x095ea7b300000000000000000000000000000000000000000000000000000000) mstore(add(freeMemoryPointer, 4), to) // Append the "to" argument. mstore(add(freeMemoryPointer, 36), amount) // Append the "amount" argument. success := and( // Set success to whether the call reverted, if not we check it either // returned exactly 1 (can't just be non-zero data), or had no return data. or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())), // We use 68 because the length of our calldata totals up like so: 4 + 32 * 2. // We use 0 and 32 to copy up to 32 bytes of return data into the scratch space. // Counterintuitively, this call must be positioned second to the or() call in the // surrounding and() call or else returndatasize() will be zero during the computation. call(gas(), token, 0, freeMemoryPointer, 68, 0, 32) ) } require(success, "APPROVE_FAILED"); } }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.8.0; /// @title Multicall interface /// @notice Enables calling multiple methods in a single call to the contract // From: https://github.com/Uniswap/v3-periphery/contracts/interfaces/IMulticall.sol interface IMulticall { /// @notice Call multiple functions in the current contract and return the data from all of them if they all succeed /// @dev The `msg.value` should not be trusted for any method callable from multicall. /// @param data The encoded function data for each of the calls to make to this contract /// @return results The results from each of the calls passed in via data function multicall(bytes[] calldata data) external payable returns (bytes[] memory results); }
// SPDX-License-Identifier: MIT pragma solidity 0.8.16; import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; interface IAaveToken { function UNDERLYING_ASSET_ADDRESS() external view returns (address); }
// 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); function aggregator() external view returns (address); }
// SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.16; interface ICurvePool { function coins(uint256 i) external view returns (address); function get_virtual_price() external view returns (uint256); function claim_admin_fees() external; // For USDT/WETH/WBTC function withdraw_admin_fees() external; function gamma() external view returns (uint256); function A() external view returns (uint256); function lp_price() external view returns (uint256); function price_oracle() external view returns (uint256); function price_oracle(uint256 i) external view returns (uint256); }
// SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.16; interface IGravity { function sendToCosmos( address _tokenContract, bytes32 _destination, uint256 _amount ) external; }
// SPDX-License-Identifier: Apache-2.0 pragma solidity >=0.8.0; interface IUniswapV2Router01 { function factory() external pure returns (address); function WETH() external pure returns (address); function addLiquidity( address tokenA, address tokenB, uint256 amountADesired, uint256 amountBDesired, uint256 amountAMin, uint256 amountBMin, address to, uint256 deadline ) external returns ( uint256 amountA, uint256 amountB, uint256 liquidity ); function addLiquidityETH( address token, uint256 amountTokenDesired, uint256 amountTokenMin, uint256 amountETHMin, address to, uint256 deadline ) external payable returns ( uint256 amountToken, uint256 amountETH, uint256 liquidity ); function removeLiquidity( address tokenA, address tokenB, uint256 liquidity, uint256 amountAMin, uint256 amountBMin, address to, uint256 deadline ) external returns (uint256 amountA, uint256 amountB); function removeLiquidityETH( address token, uint256 liquidity, uint256 amountTokenMin, uint256 amountETHMin, address to, uint256 deadline ) external returns (uint256 amountToken, uint256 amountETH); function removeLiquidityWithPermit( address tokenA, address tokenB, uint256 liquidity, uint256 amountAMin, uint256 amountBMin, address to, uint256 deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint256 amountA, uint256 amountB); function removeLiquidityETHWithPermit( address token, uint256 liquidity, uint256 amountTokenMin, uint256 amountETHMin, address to, uint256 deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint256 amountToken, uint256 amountETH); function swapExactTokensForTokens( uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external returns (uint256[] memory amounts); function swapTokensForExactTokens( uint256 amountOut, uint256 amountInMax, address[] calldata path, address to, uint256 deadline ) external returns (uint256[] memory amounts); function swapExactETHForTokens( uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external payable returns (uint256[] memory amounts); function swapTokensForExactETH( uint256 amountOut, uint256 amountInMax, address[] calldata path, address to, uint256 deadline ) external returns (uint256[] memory amounts); function swapExactTokensForETH( uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external returns (uint256[] memory amounts); function swapETHForExactTokens( uint256 amountOut, address[] calldata path, address to, uint256 deadline ) external payable returns (uint256[] memory amounts); function quote( uint256 amountA, uint256 reserveA, uint256 reserveB ) external pure returns (uint256 amountB); function getAmountOut( uint256 amountIn, uint256 reserveIn, uint256 reserveOut ) external pure returns (uint256 amountOut); function getAmountIn( uint256 amountOut, uint256 reserveIn, uint256 reserveOut ) external pure returns (uint256 amountIn); function getAmountsOut(uint256 amountIn, address[] calldata path) external view returns (uint256[] memory amounts); function getAmountsIn(uint256 amountOut, address[] calldata path) external view returns (uint256[] memory amounts); } interface IUniswapV2Router02 is IUniswapV2Router01 { function removeLiquidityETHSupportingFeeOnTransferTokens( address token, uint256 liquidity, uint256 amountTokenMin, uint256 amountETHMin, address to, uint256 deadline ) external returns (uint256 amountETH); function removeLiquidityETHWithPermitSupportingFeeOnTransferTokens( address token, uint256 liquidity, uint256 amountTokenMin, uint256 amountETHMin, address to, uint256 deadline, bool approveMax, uint8 v, bytes32 r, bytes32 s ) external returns (uint256 amountETH); function swapExactTokensForTokensSupportingFeeOnTransferTokens( uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external; function swapExactETHForTokensSupportingFeeOnTransferTokens( uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external payable; function swapExactTokensForETHSupportingFeeOnTransferTokens( uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external; }
// SPDX-License-Identifier: GPL-2.0-or-later pragma solidity >=0.8.0; /// @title Callback for IUniswapV3PoolActions#swap /// @notice Any contract that calls IUniswapV3PoolActions#swap must implement this interface interface IUniswapV3SwapCallback { /// @notice Called to `msg.sender` after executing a swap via IUniswapV3Pool#swap. /// @dev In the implementation you must pay the pool tokens owed for the swap. /// The caller of this method must be checked to be a UniswapV3Pool deployed by the canonical UniswapV3Factory. /// amount0Delta and amount1Delta can both be 0 if no tokens were swapped. /// @param amount0Delta The amount of token0 that was sent (negative) or must be received (positive) by the pool by /// the end of the swap. If positive, the callback must send that amount of token0 to the pool. /// @param amount1Delta The amount of token1 that was sent (negative) or must be received (positive) by the pool by /// the end of the swap. If positive, the callback must send that amount of token1 to the pool. /// @param data Any data passed through by the caller via the IUniswapV3PoolActions#swap call function uniswapV3SwapCallback( int256 amount0Delta, int256 amount1Delta, bytes calldata data ) external; } /// @title Router token swapping functionality /// @notice Functions for swapping tokens via Uniswap V3 interface IUniswapV3Router is IUniswapV3SwapCallback { struct ExactInputSingleParams { address tokenIn; address tokenOut; uint24 fee; address recipient; uint256 deadline; uint256 amountIn; uint256 amountOutMinimum; uint160 sqrtPriceLimitX96; } /// @notice Swaps `amountIn` of one token for as much as possible of another token /// @param params The parameters necessary for the swap, encoded as `ExactInputSingleParams` in calldata /// @return amountOut The amount of the received token function exactInputSingle(ExactInputSingleParams calldata params) external payable returns (uint256 amountOut); struct ExactInputParams { bytes path; address recipient; uint256 deadline; uint256 amountIn; uint256 amountOutMinimum; } /// @notice Swaps `amountIn` of one token for as much as possible of another along the specified path /// @param params The parameters necessary for the multi-hop swap, encoded as `ExactInputParams` in calldata /// @return amountOut The amount of the received token function exactInput(ExactInputParams calldata params) external payable returns (uint256 amountOut); struct ExactOutputSingleParams { address tokenIn; address tokenOut; uint24 fee; address recipient; uint256 deadline; uint256 amountOut; uint256 amountInMaximum; uint160 sqrtPriceLimitX96; } /// @notice Swaps as little as possible of one token for `amountOut` of another token /// @param params The parameters necessary for the swap, encoded as `ExactOutputSingleParams` in calldata /// @return amountIn The amount of the input token function exactOutputSingle(ExactOutputSingleParams calldata params) external payable returns (uint256 amountIn); struct ExactOutputParams { bytes path; address recipient; uint256 deadline; uint256 amountOut; uint256 amountInMaximum; } /// @notice Swaps as little as possible of one token for `amountOut` of another along the specified path (reversed) /// @param params The parameters necessary for the multi-hop swap, encoded as `ExactOutputParams` in calldata /// @return amountIn The amount of the input token function exactOutput(ExactOutputParams calldata params) external payable returns (uint256 amountIn); }
// SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.16; import { ERC20, SafeTransferLib, Math } from "src/base/ERC4626.sol"; import { Registry } from "src/Registry.sol"; import { Cellar } from "src/base/Cellar.sol"; import { SwapRouter } from "src/modules/swap-router/SwapRouter.sol"; import { PriceRouter } from "src/modules/price-router/PriceRouter.sol"; /** * @title Base Adaptor * @notice Base contract all adaptors must inherit from. * @dev Allows Cellars to interact with arbritrary DeFi assets and protocols. * @author crispymangoes */ abstract contract BaseAdaptor { using SafeTransferLib for ERC20; using Math for uint256; /** * @notice Attempted to specify an external receiver during a Cellar `callOnAdaptor` call. */ error BaseAdaptor__ExternalReceiverBlocked(); /** * @notice Attempted to deposit to a position where user deposits were not allowed. */ error BaseAdaptor__UserDepositsNotAllowed(); /** * @notice Attempted to withdraw from a position where user withdraws were not allowed. */ error BaseAdaptor__UserWithdrawsNotAllowed(); //============================================ Global Functions =========================================== /** * @dev Identifier unique to this adaptor for a shared registry. * Normally the identifier would just be the address of this contract, but this * Identifier is needed during Cellar Delegate Call Operations, so getting the address * of the adaptor is more difficult. */ function identifier() public pure virtual returns (bytes32) { return keccak256(abi.encode("Base Adaptor V 0.0")); } function SWAP_ROUTER_REGISTRY_SLOT() internal pure returns (uint256) { return 1; } function PRICE_ROUTER_REGISTRY_SLOT() internal pure returns (uint256) { return 2; } //============================================ Implement Base Functions =========================================== //==================== Base Function Specification ==================== // Base functions are functions designed to help the Cellar interact with // an adaptor position, strategists are not intended to use these functions. // Base functions MUST be implemented in adaptor contracts, even if that is just // adding a revert statement to make them uncallable by normal user operations. // // All view Base functions will be called used normal staticcall. // All mutative Base functions will be called using delegatecall. //===================================================================== /** * @notice Function Cellars call to deposit users funds into holding position. * @param assets the amount of assets to deposit * @param adaptorData data needed to deposit into a position * @param configurationData data settable when strategists add positions to their Cellar * Allows strategist to control how the adaptor interacts with the position */ function deposit( uint256 assets, bytes memory adaptorData, bytes memory configurationData ) public virtual; /** * @notice Function Cellars call to withdraw funds from positions to send to users. * @param receiver the address that should receive withdrawn funds * @param adaptorData data needed to withdraw from a position * @param configurationData data settable when strategists add positions to their Cellar * Allows strategist to control how the adaptor interacts with the position */ function withdraw( uint256 assets, address receiver, bytes memory adaptorData, bytes memory configurationData ) public virtual; /** * @notice Function Cellars use to determine `assetOf` balance of an adaptor position. * @param adaptorData data needed to interact with the position * @return balance of the position in terms of `assetOf` */ function balanceOf(bytes memory adaptorData) public view virtual returns (uint256); /** * @notice Functions Cellars use to determine the withdrawable balance from an adaptor position. * @dev Debt positions MUST return 0 for their `withdrawableFrom` * @notice accepts adaptorData and configurationData * @return withdrawable balance of the position in terms of `assetOf` */ function withdrawableFrom(bytes memory, bytes memory) public view virtual returns (uint256); /** * @notice Function Cellars use to determine the underlying ERC20 asset of a position. * @param adaptorData data needed to withdraw from a position * @return the underlying ERC20 asset of a position */ function assetOf(bytes memory adaptorData) public view virtual returns (ERC20); /** * @notice When positions are added to the Registry, this function can be used in order to figure out * what assets this adaptor needs to price, and confirm pricing is properly setup. */ function assetsUsed(bytes memory adaptorData) public view virtual returns (ERC20[] memory assets) { assets = new ERC20[](1); assets[0] = assetOf(adaptorData); } /** * @notice Functions Registry/Cellars use to determine if this adaptor reports debt values. * @dev returns true if this adaptor reports debt values. */ function isDebt() public view virtual returns (bool); //============================================ Strategist Functions =========================================== //==================== Strategist Function Specification ==================== // Strategist functions are only callable by strategists through the Cellars // `callOnAdaptor` function. A cellar will never call any of these functions, // when a normal user interacts with a cellar(depositing/withdrawing) // // All strategist functions will be called using delegatecall. // Strategist functions are intentionally "blind" to what positions the cellar // is currently holding. This allows strategists to enter temporary positions // while rebalancing. // To mitigate strategist from abusing this and moving funds in untracked // positions, the cellar will enforce a Total Value Locked check that // insures TVL has not deviated too much from `callOnAdaptor`. //=========================================================================== //============================================ Helper Functions =========================================== /** * @notice Helper function that allows adaptor calls to use the max available of an ERC20 asset * by passing in type(uint256).max * @param token the ERC20 asset to work with * @param amount when `type(uint256).max` is used, this function returns `token`s `balanceOf` * otherwise this function returns amount. */ function _maxAvailable(ERC20 token, uint256 amount) internal view virtual returns (uint256) { if (amount == type(uint256).max) return token.balanceOf(address(this)); else return amount; } /** * @notice Helper function that allows adaptors to make swaps using the Swap Router * @param assetIn the asset to make a swap with * @param assetOut the asset to get out of the swap * @param amountIn the amount of `assetIn` to swap with * @param exchange enum value that determines what exchange to make the swap on * see SwapRouter.sol * @param params swap params needed to perform the swap, dependent on which exchange is selected * see SwapRouter.sol * @return amountOut the amount of `assetOut` received from the swap. */ function swap( ERC20 assetIn, ERC20 assetOut, uint256 amountIn, SwapRouter.Exchange exchange, bytes memory params ) public returns (uint256 amountOut) { // Get the address of the latest swap router. SwapRouter swapRouter = SwapRouter(Cellar(address(this)).registry().getAddress(SWAP_ROUTER_REGISTRY_SLOT())); // Approve swap router to swap assets. assetIn.safeApprove(address(swapRouter), amountIn); // Perform swap. amountOut = swapRouter.swap(exchange, params, address(this), assetIn, assetOut); } /** * @notice Helper function that validates external receivers are allowed. */ function _externalReceiverCheck(address receiver) internal view { if (receiver != address(this) && Cellar(address(this)).blockExternalReceiver()) revert BaseAdaptor__ExternalReceiverBlocked(); } /** * @notice Attempted oracle swap did not pass slippage check. */ error BaseAdaptor__BadSlippage(); /** * @notice Attempted to make an oracle swap on an unsupported exchange. */ error BaseAdaptor__ExchangeNotSupported(); /** * @notice Helper function to make safe "blind" Uniswap Swaps by comparing value in vs value out of the swap. * @dev Only works for Uniswap V2 or V3 exchanges. * @param assetIn the asset to make a swap with * @param assetOut the asset to get out of the swap * @param amountIn the amount of `assetIn` to swap with, can be type(uint256).max * @param exchange enum value that determines what exchange to make the swap on * see SwapRouter.sol * @param params swap params needed to perform the swap, dependent on which exchange is selected * see SwapRouter.sol * @param slippage number less than 1e18, defining the max swap slippage * @return amountOut the amount of `assetOut` received from the swap. */ function oracleSwap( ERC20 assetIn, ERC20 assetOut, uint256 amountIn, SwapRouter.Exchange exchange, bytes memory params, uint64 slippage ) public returns (uint256 amountOut) { amountIn = _maxAvailable(assetIn, amountIn); // Copy over the path/fees then set the amount and minAmount. if (exchange == SwapRouter.Exchange.UNIV2) { address[] memory path = abi.decode(params, (address[])); params = abi.encode(path, amountIn, 0); } else if (exchange == SwapRouter.Exchange.UNIV3) { (address[] memory path, uint24[] memory poolFees) = abi.decode(params, (address[], uint24[])); params = abi.encode(path, poolFees, amountIn, 0); } else revert BaseAdaptor__ExchangeNotSupported(); // Get the address of the latest swap router. SwapRouter swapRouter = SwapRouter(Cellar(address(this)).registry().getAddress(SWAP_ROUTER_REGISTRY_SLOT())); // Get the address of the latest price router. PriceRouter priceRouter = PriceRouter( Cellar(address(this)).registry().getAddress(PRICE_ROUTER_REGISTRY_SLOT()) ); // Approve swap router to swap assets. assetIn.safeApprove(address(swapRouter), amountIn); // Perform swap. amountOut = swapRouter.swap(exchange, params, address(this), assetIn, assetOut); // Make sure amountIn vs amountOut is reasonable. amountIn = priceRouter.getValue(assetIn, amountIn, assetOut); uint256 amountInWithSlippage = amountIn.mulDivDown(slippage, 1e18); if (amountOut < amountInWithSlippage) revert BaseAdaptor__BadSlippage(); } /** * @notice Allows strategists to zero out an approval for a given `asset`. * @param asset the ERC20 asset to revoke `spender`s approval for * @param spender the address to revoke approval for */ function revokeApproval(ERC20 asset, address spender) public { asset.safeApprove(spender, 0); } }
// SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.16; import { ERC20, SafeTransferLib } from "src/base/ERC4626.sol"; import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol"; import { AutomationCompatibleInterface } from "@chainlink/contracts/src/v0.8/interfaces/AutomationCompatibleInterface.sol"; import { IChainlinkAggregator } from "src/interfaces/external/IChainlinkAggregator.sol"; import { SafeCast } from "@openzeppelin/contracts/utils/math/SafeCast.sol"; import { Math } from "src/utils/Math.sol"; import { Address } from "@openzeppelin/contracts/utils/Address.sol"; import { ICurvePool } from "src/interfaces/external/ICurvePool.sol"; import { IAaveToken } from "src/interfaces/external/IAaveToken.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, AutomationCompatibleInterface { using SafeTransferLib for ERC20; using SafeCast for int256; using Math for uint256; using Address for address; event AddAsset(address indexed asset); // =========================================== ASSETS CONFIG =========================================== /** * @notice Bare minimum settings all derivatives support. * @param derivative the derivative used to price the asset * @param source the address used to price the asset */ struct AssetSettings { uint8 derivative; address source; } /** * @notice Mapping between an asset to price and its `AssetSettings`. */ mapping(ERC20 => AssetSettings) public getAssetSettings; // ======================================= 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, but actual answer was outside range of expectedAnswer. */ error PriceRouter__BadAnswer(uint256 answer, uint256 expectedAnswer); /** * @notice Attempted to perform an operation using an unkown derivative. */ error PriceRouter__UnkownDerivative(uint8 unkownDerivative); /** * @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 The allowed deviation between the expected answer vs the actual answer. */ uint256 public constant EXPECTED_ANSWER_DEVIATION = 0.02e18; /** * @notice Stores pricing information during calls. * @param asset the address of the asset * @param price the USD price of the asset * @dev If the price does not fit into a uint96, the asset is NOT added to the cache. */ struct PriceCache { address asset; uint96 price; } /** * @notice The size of the price cache. A larger cache can hold more values, * but incurs a larger gas cost overhead. A smaller cache has a * smaller gas overhead but caches less prices. */ uint8 private constant PRICE_CACHE_SIZE = 8; /** * @notice Allows owner to add assets to the price router. * @dev Performs a sanity check by comparing the price router computed price to * a user input `_expectedAnswer`. * @param _asset the asset to add to the pricing router * @param _settings the settings for `_asset` * @dev The `derivative` value in settings MUST be non zero. * @param _storage arbitrary bytes data used to configure `_asset` pricing * @param _expectedAnswer the expected answer for the asset from `_getPriceInUSD` */ function addAsset( ERC20 _asset, AssetSettings memory _settings, bytes memory _storage, uint256 _expectedAnswer ) external onlyOwner { if (address(_asset) == address(0)) revert PriceRouter__InvalidAsset(address(_asset)); // Zero is an invalid derivative. if (_settings.derivative == 0) revert PriceRouter__UnkownDerivative(_settings.derivative); // Call setup function for appropriate derivative. if (_settings.derivative == 1) { _setupPriceForChainlinkDerivative(_asset, _settings.source, _storage); } else if (_settings.derivative == 2) { _setupPriceForCurveDerivative(_asset, _settings.source, _storage); } else if (_settings.derivative == 3) { _setupPriceForCurveV2Derivative(_asset, _settings.source, _storage); } else if (_settings.derivative == 4) { _setupPriceForAaveDerivative(_asset, _settings.source, _storage); } else revert PriceRouter__UnkownDerivative(_settings.derivative); // Check `_getPriceInUSD` against `_expectedAnswer`. uint256 minAnswer = _expectedAnswer.mulWadDown((1e18 - EXPECTED_ANSWER_DEVIATION)); uint256 maxAnswer = _expectedAnswer.mulWadDown((1e18 + EXPECTED_ANSWER_DEVIATION)); // Create an empty Price Cache. PriceCache[PRICE_CACHE_SIZE] memory cache; getAssetSettings[_asset] = _settings; uint256 answer = _getPriceInUSD(_asset, _settings, cache); if (answer < minAnswer || answer > maxAnswer) revert PriceRouter__BadAnswer(answer, _expectedAnswer); emit AddAsset(address(_asset)); } /** * @notice return bool indicating whether or not an asset has been set up. * @dev Since `addAsset` enforces the derivative is non zero, checking if the stored setting * is nonzero is sufficient to see if the asset is set up. */ function isSupported(ERC20 asset) external view returns (bool) { return getAssetSettings[asset].derivative > 0; } // ======================================= CHAINLINK AUTOMATION ======================================= /** * @notice `checkUpkeep` is set up to allow for multiple derivatives to use Chainlink Automation. */ function checkUpkeep(bytes calldata checkData) external view returns (bool upkeepNeeded, bytes memory performData) { (uint8 derivative, bytes memory derivativeCheckData) = abi.decode(checkData, (uint8, bytes)); if (derivative == 2) { (upkeepNeeded, performData) = _checkVirtualPriceBound(derivativeCheckData); } else if (derivative == 3) { (upkeepNeeded, performData) = _checkVirtualPriceBound(derivativeCheckData); } else revert PriceRouter__UnkownDerivative(derivative); } /** * @notice `performUpkeep` is set up to allow for multiple derivatives to use Chainlink Automation. */ function performUpkeep(bytes calldata performData) external { (uint8 derivative, bytes memory derivativePerformData) = abi.decode(performData, (uint8, bytes)); if (derivative == 2) { _updateVirtualPriceBound(derivativePerformData); } else if (derivative == 3) { _updateVirtualPriceBound(derivativePerformData); } else revert PriceRouter__UnkownDerivative(derivative); } // ======================================= PRICING OPERATIONS ======================================= /** * @notice Get `asset` price in USD. * @dev Returns price in USD with 8 decimals. */ function getPriceInUSD(ERC20 asset) external view returns (uint256) { AssetSettings memory assetSettings = getAssetSettings[asset]; // Create an empty Price Cache. PriceCache[PRICE_CACHE_SIZE] memory cache; return _getPriceInUSD(asset, assetSettings, cache); } /** * @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) { AssetSettings memory baseSettings = getAssetSettings[baseAsset]; AssetSettings memory quoteSettings = getAssetSettings[quoteAsset]; if (baseSettings.derivative == 0) revert PriceRouter__UnsupportedAsset(address(baseAsset)); if (quoteSettings.derivative == 0) revert PriceRouter__UnsupportedAsset(address(quoteAsset)); PriceCache[PRICE_CACHE_SIZE] memory cache; uint256 priceBaseUSD = _getPriceInUSD(baseAsset, baseSettings, cache); uint256 priceQuoteUSD = _getPriceInUSD(quoteAsset, quoteSettings, cache); value = _getValueInQuote(priceBaseUSD, priceQuoteUSD, baseAsset.decimals(), quoteAsset.decimals(), amount); } /** * @notice Helper function that compares `_getValues` between input 0 and input 1. */ function getValuesDelta( ERC20[] calldata baseAssets0, uint256[] calldata amounts0, ERC20[] calldata baseAssets1, uint256[] calldata amounts1, ERC20 quoteAsset ) external view returns (uint256) { // Create an empty Price Cache. PriceCache[PRICE_CACHE_SIZE] memory cache; uint256 value0 = _getValues(baseAssets0, amounts0, quoteAsset, cache); uint256 value1 = _getValues(baseAssets1, amounts1, quoteAsset, cache); return value0 - value1; } /** * @notice Helper function that determines the value of assets using `_getValues`. */ function getValues( ERC20[] calldata baseAssets, uint256[] calldata amounts, ERC20 quoteAsset ) external view returns (uint256) { // Create an empty Price Cache. PriceCache[PRICE_CACHE_SIZE] memory cache; return _getValues(baseAssets, amounts, quoteAsset, cache); } /** * @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) { AssetSettings memory baseSettings = getAssetSettings[baseAsset]; AssetSettings memory quoteSettings = getAssetSettings[quoteAsset]; if (baseSettings.derivative == 0) revert PriceRouter__UnsupportedAsset(address(baseAsset)); if (quoteSettings.derivative == 0) revert PriceRouter__UnsupportedAsset(address(quoteAsset)); // Create an empty Price Cache. PriceCache[PRICE_CACHE_SIZE] memory cache; // Pass in zero for ethToUsd, since it has not been set yet. exchangeRate = _getExchangeRate( baseAsset, baseSettings, quoteAsset, quoteSettings, quoteAsset.decimals(), cache ); } /** * @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(); AssetSettings memory quoteSettings = getAssetSettings[quoteAsset]; if (quoteSettings.derivative == 0) revert PriceRouter__UnsupportedAsset(address(quoteAsset)); // Create an empty Price Cache. PriceCache[PRICE_CACHE_SIZE] memory cache; uint256 numOfAssets = baseAssets.length; exchangeRates = new uint256[](numOfAssets); for (uint256 i; i < numOfAssets; i++) { AssetSettings memory baseSettings = getAssetSettings[baseAssets[i]]; if (baseSettings.derivative == 0) revert PriceRouter__UnsupportedAsset(address(baseAssets[i])); exchangeRates[i] = _getExchangeRate( baseAssets[i], baseSettings, quoteAsset, quoteSettings, quoteAssetDecimals, cache ); } } // =========================================== HELPER FUNCTIONS =========================================== ERC20 private constant WETH = ERC20(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2); /** * @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 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, AssetSettings memory baseSettings, ERC20 quoteAsset, AssetSettings memory quoteSettings, uint8 quoteAssetDecimals, PriceCache[PRICE_CACHE_SIZE] memory cache ) internal view returns (uint256) { uint256 basePrice = _getPriceInUSD(baseAsset, baseSettings, cache); uint256 quotePrice = _getPriceInUSD(quoteAsset, quoteSettings, cache); uint256 exchangeRate = basePrice.mulDivDown(10**quoteAssetDecimals, quotePrice); return exchangeRate; } /** * @notice Helper function to get an assets price in USD. * @dev Returns price in USD with 8 decimals. * @dev Favors using cached prices if available. */ function _getPriceInUSD( ERC20 asset, AssetSettings memory settings, PriceCache[PRICE_CACHE_SIZE] memory cache ) internal view returns (uint256) { // First check if the price is in the price cache. uint8 lastIndex = PRICE_CACHE_SIZE; for (uint8 i; i < PRICE_CACHE_SIZE; ++i) { // Did not find our price in the cache. if (cache[i].asset == address(0)) { // Save the last index. lastIndex = i; break; } // Did find our price in the cache. if (cache[i].asset == address(asset)) return cache[i].price; } // Call get price function using appropriate derivative. uint256 price; if (settings.derivative == 1) { price = _getPriceForChainlinkDerivative(asset, settings.source, cache); } else if (settings.derivative == 2) { price = _getPriceForCurveDerivative(asset, settings.source, cache); } else if (settings.derivative == 3) { price = _getPriceForCurveV2Derivative(asset, settings.source, cache); } else if (settings.derivative == 4) { price = _getPriceForAaveDerivative(asset, settings.source, cache); } else revert PriceRouter__UnkownDerivative(settings.derivative); // If there is room in the cache, the price fits in a uint96, then find the next spot available. if (lastIndex < PRICE_CACHE_SIZE && price <= type(uint96).max) { for (uint8 i = lastIndex; i < PRICE_CACHE_SIZE; ++i) { // Found an empty cache slot, so fill it. if (cache[i].asset == address(0)) { cache[i] = PriceCache(address(asset), uint96(price)); break; } } } return price; } /** * @notice math function that preserves precision by multiplying the amountBase before dividing. * @param priceBaseUSD the base asset price in USD * @param priceQuoteUSD the quote asset price in USD * @param baseDecimals the base asset decimals * @param quoteDecimals the quote asset decimals * @param amountBase the amount of base asset */ function _getValueInQuote( uint256 priceBaseUSD, uint256 priceQuoteUSD, uint8 baseDecimals, uint8 quoteDecimals, uint256 amountBase ) internal pure returns (uint256 valueInQuote) { // Get value in quote asset, but maintain as much precision as possible. // Cleaner equations below. // baseToUSD = amountBase * priceBaseUSD / 10**baseDecimals. // valueInQuote = baseToUSD * 10**quoteDecimals / priceQuoteUSD valueInQuote = amountBase.mulDivDown((priceBaseUSD * 10**quoteDecimals), (10**baseDecimals * priceQuoteUSD)); } /** * @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[] calldata baseAssets, uint256[] calldata amounts, ERC20 quoteAsset, PriceCache[PRICE_CACHE_SIZE] memory cache ) internal view returns (uint256) { if (baseAssets.length != amounts.length) revert PriceRouter__LengthMismatch(); uint256 quotePrice; { AssetSettings memory quoteSettings = getAssetSettings[quoteAsset]; if (quoteSettings.derivative == 0) revert PriceRouter__UnsupportedAsset(address(quoteAsset)); quotePrice = _getPriceInUSD(quoteAsset, quoteSettings, cache); } uint256 valueInQuote; // uint256 price; uint8 quoteDecimals = quoteAsset.decimals(); for (uint8 i = 0; i < baseAssets.length; i++) { // Skip zero amount values. if (amounts[i] == 0) continue; ERC20 baseAsset = baseAssets[i]; if (baseAsset == quoteAsset) valueInQuote += amounts[i]; else { uint256 basePrice; { AssetSettings memory baseSettings = getAssetSettings[baseAsset]; if (baseSettings.derivative == 0) revert PriceRouter__UnsupportedAsset(address(baseAsset)); basePrice = _getPriceInUSD(baseAsset, baseSettings, cache); } valueInQuote += _getValueInQuote( basePrice, quotePrice, baseAsset.decimals(), quoteDecimals, amounts[i] ); // uint256 valueInUSD = (amounts[i].mulDivDown(price, 10**baseAsset.decimals())); // valueInQuote += valueInUSD.mulDivDown(10**quoteDecimals, quotePrice); } } return valueInQuote; } // =========================================== CHAINLINK PRICE DERIVATIVE ===========================================\ /** * @notice Stores data for Chainlink derivative assets. * @param max the max valid price of the asset * @param min the min valid price of the asset * @param heartbeat the max amount of time between price updates * @param inETH bool indicating whether the price feed is * denominated in ETH(true) or USD(false) */ struct ChainlinkDerivativeStorage { uint144 max; uint80 min; uint24 heartbeat; bool inETH; } /** * @notice Returns Chainlink Derivative Storage */ mapping(ERC20 => ChainlinkDerivativeStorage) public getChainlinkDerivativeStorage; /** * @notice If zero is specified for a Chainlink asset heartbeat, this value is used instead. */ uint24 public constant DEFAULT_HEART_BEAT = 1 days; /** * @notice Setup function for pricing Chainlink derivative assets. * @dev _source The address of the Chainlink Data feed. * @dev _storage A ChainlinkDerivativeStorage value defining valid prices. */ function _setupPriceForChainlinkDerivative( ERC20 _asset, address _source, bytes memory _storage ) internal { ChainlinkDerivativeStorage memory parameters = abi.decode(_storage, (ChainlinkDerivativeStorage)); // Use Chainlink to get the min and max of the asset. IChainlinkAggregator aggregator = IChainlinkAggregator(IChainlinkAggregator(_source).aggregator()); uint256 minFromChainklink = uint256(uint192(aggregator.minAnswer())); uint256 maxFromChainlink = uint256(uint192(aggregator.maxAnswer())); // 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 * 1.1e18) / 1e18; uint256 bufferedMaxPrice = (maxFromChainlink * 0.9e18) / 1e18; if (parameters.min == 0) { // Revert if bufferedMinPrice overflows because uint80 is too small to hold the minimum price, // and lowering it to uint80 is not safe because the price feed can stop being updated before // it actually gets to that lower price. if (bufferedMinPrice > type(uint80).max) revert("Buffered Min Overflow"); parameters.min = uint80(bufferedMinPrice); } else { if (parameters.min < bufferedMinPrice) revert PriceRouter__InvalidMinPrice(parameters.min, bufferedMinPrice); } if (parameters.max == 0) { //Do not revert even if bufferedMaxPrice is greater than uint144, because lowering it to uint144 max is more conservative. parameters.max = bufferedMaxPrice > type(uint144).max ? type(uint144).max : uint144(bufferedMaxPrice); } else { if (parameters.max > bufferedMaxPrice) revert PriceRouter__InvalidMaxPrice(parameters.max, bufferedMaxPrice); } if (parameters.min >= parameters.max) revert PriceRouter__MinPriceGreaterThanMaxPrice(parameters.min, parameters.max); parameters.heartbeat = parameters.heartbeat != 0 ? parameters.heartbeat : DEFAULT_HEART_BEAT; getChainlinkDerivativeStorage[_asset] = parameters; } /** * @notice Get the price of a Chainlink derivative in terms of USD. */ function _getPriceForChainlinkDerivative( ERC20 _asset, address _source, PriceCache[PRICE_CACHE_SIZE] memory cache ) internal view returns (uint256) { ChainlinkDerivativeStorage memory parameters = getChainlinkDerivativeStorage[_asset]; IChainlinkAggregator aggregator = IChainlinkAggregator(_source); (, int256 _price, , uint256 _timestamp, ) = aggregator.latestRoundData(); uint256 price = _price.toUint256(); _checkPriceFeed(address(_asset), price, _timestamp, parameters.max, parameters.min, parameters.heartbeat); // If price is in ETH, then convert price into USD. if (parameters.inETH) { uint256 _ethToUsd = _getPriceInUSD(WETH, getAssetSettings[WETH], cache); price = price.mulWadDown(_ethToUsd); } return price; } /** * @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); /** * @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 max the upper price bound * @param min the lower price bound * @param heartbeat the max amount of time between price updates */ function _checkPriceFeed( address asset, uint256 value, uint256 timestamp, uint144 max, uint88 min, uint24 heartbeat ) internal view { if (value < min) revert PriceRouter__AssetBelowMinPrice(address(asset), value, min); if (value > max) revert PriceRouter__AssetAboveMaxPrice(address(asset), value, max); uint256 timeSinceLastUpdate = block.timestamp - timestamp; if (timeSinceLastUpdate > heartbeat) revert PriceRouter__StalePrice(address(asset), timeSinceLastUpdate, heartbeat); } // ======================================== CURVE VIRTUAL PRICE BOUND ======================================== /** * @notice Curve virtual price is susceptible to re-entrancy attacks, if the attacker adds/removes pool liquidity, * and re-enters into one of our contracts. To mitigate this, all curve pricing operations check * the current `pool.get_virtual_price()` against logical bounds. * @notice These logical bounds are updated when `addAsset` is called, or Chainlink Automation detects that * the bounds need to be updated, and that the gas price is reasonable. * @notice Once the on chain virtual price goes out of bounds, all pricing operations will revert for that Curve LP, * which means any Cellars using that Curve LP are effectively frozen until the virtual price bounds are updated * by Chainlink. If this is not happening in a timely manner( IE network is abnormally busy), the owner of this * contract can raise the `gasConstant` to a value that better reflects the floor gas price of the network. * Which will cause Chainlink nodes to update virtual price bounds faster. */ /** * @param datum the virtual price to base posDelta and negDelta off of, 8 decimals * @param timeLastUpdated the timestamp this datum was updated * @param posDelta multipler >= 1e8 defining the logical upper bound for this virtual price, 8 decimals * @param negDelta multipler <= 1e8 defining the logical lower bound for this virtual price, 8 decimals * @param rateLimit the minimum amount of time that must pass between updates * @dev Curve virtual price values should update slowly, hence why this contract enforces a rate limit. * @dev During datum updates, the max/min new datum corresponds to the current upper/lower bound. */ struct VirtualPriceBound { uint96 datum; uint64 timeLastUpdated; uint32 posDelta; uint32 negDelta; uint32 rateLimit; } /** * @notice Returns a Curve asset virtual price bound */ mapping(address => VirtualPriceBound) public getVirtualPriceBound; /** * @dev If ZERO is specified for an assets `rateLimit` this value is used instead. */ uint32 public constant DEFAULT_RATE_LIMIT = 1 days; /** * @notice Chainlink Fast Gas Feed for ETH Mainnet. */ address public ETH_FAST_GAS_FEED = 0x169E633A2D1E6c10dD91238Ba11c4A708dfEF37C; /** * @notice Allows owner to set a new gas feed. * @notice Can be set to zero address to skip gas check. */ function setGasFeed(address gasFeed) external onlyOwner { ETH_FAST_GAS_FEED = gasFeed; } /** * @notice Dictates how aggressive keepers are with updating Curve pool virtual price values. * @dev A larger `gasConstant` will raise the `gasPriceLimit`, while a smaller `gasConstant` * will lower the `gasPriceLimit`. */ uint256 public gasConstant = 200e9; /** * @notice Allows owner to set a new gas constant. */ function setGasConstant(uint256 newConstant) external onlyOwner { gasConstant = newConstant; } /** * @notice Dictates the minimum delta required for an upkeep. * @dev If the max delta found is less than this, then checkUpkeep returns false. */ uint256 public minDelta = 0.05e18; /** * @notice Allows owner to set a new minimum delta. */ function setMinDelta(uint256 newMinDelta) external onlyOwner { minDelta = newMinDelta; } /** * @notice Stores all Curve Assets this contract prices, so Automation can loop through it. */ address[] public curveAssets; /** * @notice Allows owner to update a Curve asset's virtual price parameters.. */ function updateVirtualPriceBound( address _asset, uint32 _posDelta, uint32 _negDelta, uint32 _rateLimit ) external onlyOwner { VirtualPriceBound storage vpBound = getVirtualPriceBound[_asset]; vpBound.posDelta = _posDelta; vpBound.negDelta = _negDelta; vpBound.rateLimit = _rateLimit == 0 ? DEFAULT_RATE_LIMIT : _rateLimit; } /** * @notice Logic ran by Chainlink Automation to determine if virtual price bounds need to be updated. * @dev `checkData` should be a start and end value indicating where to start and end in the `curveAssets` array. * @dev The end index can be zero, or greater than the current length of `curveAssets`. * Doing this makes end = curveAssets.length. * @dev `performData` is the target index in `curveAssets` that needs its bounds updated. */ function _checkVirtualPriceBound(bytes memory checkData) internal view returns (bool upkeepNeeded, bytes memory performData) { // Decode checkData to get start and end index. (uint256 start, uint256 end) = abi.decode(checkData, (uint256, uint256)); if (end == 0 || end > curveAssets.length) end = curveAssets.length; // Loop through all curve assets, and find the asset with the largest delta(the one that needs to be updated the most). uint256 maxDelta; uint256 targetIndex; for (uint256 i = start; i < end; i++) { address asset = curveAssets[i]; VirtualPriceBound memory vpBound = getVirtualPriceBound[asset]; // Check to see if this virtual price was updated recently. if ((block.timestamp - vpBound.timeLastUpdated) < vpBound.rateLimit) continue; // Check current virtual price against upper and lower bounds to find the delta. uint256 currentVirtualPrice = ICurvePool(getAssetSettings[ERC20(asset)].source).get_virtual_price(); currentVirtualPrice = currentVirtualPrice.changeDecimals(18, 8); uint256 delta; if (currentVirtualPrice > vpBound.datum) { uint256 upper = uint256(vpBound.datum).mulDivDown(vpBound.posDelta, 1e8); uint256 ceiling = upper - vpBound.datum; uint256 current = currentVirtualPrice - vpBound.datum; delta = _getDelta(ceiling, current); } else { uint256 lower = uint256(vpBound.datum).mulDivDown(vpBound.negDelta, 1e8); uint256 ceiling = vpBound.datum - lower; uint256 current = vpBound.datum - currentVirtualPrice; delta = _getDelta(ceiling, current); } // Save the largest delta for the upkeep. if (delta > maxDelta) { maxDelta = delta; targetIndex = i; } } // If the largest delta must be greater/equal to `minDelta` to continue. if (maxDelta >= minDelta) { // If gas feed is not set, skip the gas check. if (ETH_FAST_GAS_FEED == address(0)) { // No Gas Check needed. upkeepNeeded = true; performData = abi.encode(targetIndex); } else { // Run a gas check to determine if it makes sense to update the target curve asset. uint256 gasPriceLimit = gasConstant.mulDivDown(maxDelta**3, 1e54); // 54 comes from 18 * 3. uint256 currentGasPrice = uint256(IChainlinkAggregator(ETH_FAST_GAS_FEED).latestAnswer()); if (currentGasPrice <= gasPriceLimit) { upkeepNeeded = true; performData = abi.encode(targetIndex); } } } } /** * @notice Attempted to call a function only the Chainlink Registry can call. */ error PriceRouter__OnlyAutomationRegistry(); /** * @notice Attempted to update a virtual price too soon. */ error PriceRouter__VirtualPriceRateLimiter(); /** * @notice Attempted to update a virtual price bound that did not need to be updated. */ error PriceRouter__NothingToUpdate(); /** * @notice Chainlink's Automation Registry contract address. */ address public automationRegistry = 0x02777053d6764996e594c3E88AF1D58D5363a2e6; /** * @notice Allows owner to update the Automation Registry. * @dev In rare cases, Chainlink's registry CAN change. */ function setAutomationRegistry(address newRegistry) external onlyOwner { automationRegistry = newRegistry; } /** * @notice Curve virtual price is susceptible to re-entrancy attacks, if the attacker adds/removes pool liquidity. * To stop this we check the virtual price against logical bounds. * @dev Only the chainlink registry can call this function, so we know that Chainlink nodes will not be * re-entering into the Curve pool, so it is safe to use the current on chain virtual price. * @notice Updating the virtual price is rate limited by `VirtualPriceBound.raetLimit` and can only be * updated at most to the lower or upper bound of the current datum. * This is intentional since curve pool price should not be volatile, and if they are, then * we WANT that Curve LP pools TX pricing to revert. */ function _updateVirtualPriceBound(bytes memory performData) internal { // Make sure only the Automation Registry can call this function. if (msg.sender != automationRegistry) revert PriceRouter__OnlyAutomationRegistry(); // Grab the target index from performData. uint256 index = abi.decode(performData, (uint256)); address asset = curveAssets[index]; VirtualPriceBound storage vpBound = getVirtualPriceBound[asset]; // Enfore rate limit check. if ((block.timestamp - vpBound.timeLastUpdated) < vpBound.rateLimit) revert PriceRouter__VirtualPriceRateLimiter(); // Determine what the new Datum should be. uint256 currentVirtualPrice = ICurvePool(getAssetSettings[ERC20(asset)].source).get_virtual_price(); currentVirtualPrice = currentVirtualPrice.changeDecimals(18, 8); if (currentVirtualPrice > vpBound.datum) { uint256 upper = uint256(vpBound.datum).mulDivDown(vpBound.posDelta, 1e8); vpBound.datum = uint96(currentVirtualPrice > upper ? upper : currentVirtualPrice); } else if (currentVirtualPrice < vpBound.datum) { uint256 lower = uint256(vpBound.datum).mulDivDown(vpBound.negDelta, 1e8); vpBound.datum = uint96(currentVirtualPrice < lower ? lower : currentVirtualPrice); } else { revert PriceRouter__NothingToUpdate(); } // Update the stored timestamp. vpBound.timeLastUpdated = uint64(block.timestamp); } /** * @notice Returns a percent delta representing where `current` is in reference to `ceiling`. * Example, if current == 0, this would return a 0. * if current == ceiling, this would return a 1e18. * if current == (ceiling) / 2, this would return 0.5e18. */ function _getDelta(uint256 ceiling, uint256 current) internal pure returns (uint256) { return current.mulDivDown(1e18, ceiling); } /** * @notice Attempted to price a curve asset that was below its logical minimum price. */ error PriceRouter__CurrentBelowLowerBound(uint256 current, uint256 lower); /** * @notice Attempted to price a curve asset that was above its logical maximum price. */ error PriceRouter__CurrentAboveUpperBound(uint256 current, uint256 upper); /** * @notice Enforces a logical price bound on Curve pool tokens. */ function _checkBounds( uint256 lower, uint256 upper, uint256 current ) internal pure { if (current < lower) revert PriceRouter__CurrentBelowLowerBound(current, lower); if (current > upper) revert PriceRouter__CurrentAboveUpperBound(current, upper); } // =========================================== CURVE PRICE DERIVATIVE =========================================== /** * @notice Curve Derivative Storage * @dev Stores an array of the underlying token addresses in the curve pool. */ mapping(ERC20 => address[]) public getCurveDerivativeStorage; /** * @notice Setup function for pricing Curve derivative assets. * @dev _source The address of the Curve Pool. * @dev _storage A VirtualPriceBound value for this asset. * @dev Assumes that curve pools never add or remove tokens. */ function _setupPriceForCurveDerivative( ERC20 _asset, address _source, bytes memory _storage ) internal { ICurvePool pool = ICurvePool(_source); uint8 coinsLength = 0; // Figure out how many tokens are in the curve pool. while (true) { try pool.coins(coinsLength) { coinsLength++; } catch { break; } } // Save the pools tokens to reduce gas for pricing calls. address[] memory coins = new address[](coinsLength); for (uint256 i = 0; i < coinsLength; i++) { coins[i] = pool.coins(i); } getCurveDerivativeStorage[_asset] = coins; curveAssets.push(address(_asset)); // Setup virtual price bound. VirtualPriceBound memory vpBound = abi.decode(_storage, (VirtualPriceBound)); uint256 upper = uint256(vpBound.datum).mulDivDown(vpBound.posDelta, 1e8); upper = upper.changeDecimals(8, 18); uint256 lower = uint256(vpBound.datum).mulDivDown(vpBound.negDelta, 1e8); lower = lower.changeDecimals(8, 18); _checkBounds(lower, upper, pool.get_virtual_price()); if (vpBound.rateLimit == 0) vpBound.rateLimit = DEFAULT_RATE_LIMIT; vpBound.timeLastUpdated = uint64(block.timestamp); getVirtualPriceBound[address(_asset)] = vpBound; } /** * @notice Get the price of a CurveV1 derivative in terms of USD. */ function _getPriceForCurveDerivative( ERC20 asset, address _source, PriceCache[PRICE_CACHE_SIZE] memory cache ) internal view returns (uint256 price) { ICurvePool pool = ICurvePool(_source); address[] memory coins = getCurveDerivativeStorage[asset]; uint256 minPrice = type(uint256).max; for (uint256 i = 0; i < coins.length; i++) { ERC20 poolAsset = ERC20(coins[i]); uint256 tokenPrice = _getPriceInUSD(poolAsset, getAssetSettings[poolAsset], cache); if (tokenPrice < minPrice) minPrice = tokenPrice; } if (minPrice == type(uint256).max) revert("Min price not found."); // Check that virtual price is within bounds. uint256 virtualPrice = pool.get_virtual_price(); VirtualPriceBound memory vpBound = getVirtualPriceBound[address(asset)]; uint256 upper = uint256(vpBound.datum).mulDivDown(vpBound.posDelta, 1e8); upper = upper.changeDecimals(8, 18); uint256 lower = uint256(vpBound.datum).mulDivDown(vpBound.negDelta, 1e8); lower = lower.changeDecimals(8, 18); _checkBounds(lower, upper, virtualPrice); // Virtual price is based off the Curve Token decimals. uint256 curveTokenDecimals = ERC20(asset).decimals(); price = minPrice.mulDivDown(virtualPrice, 10**curveTokenDecimals); } // =========================================== CURVEV2 PRICE DERIVATIVE =========================================== /** * @notice Setup function for pricing CurveV2 derivative assets. * @dev _source The address of the CurveV2 Pool. * @dev _storage A VirtualPriceBound value for this asset. * @dev Assumes that curve pools never add or remove tokens. */ function _setupPriceForCurveV2Derivative( ERC20 _asset, address _source, bytes memory _storage ) internal { ICurvePool pool = ICurvePool(_source); uint8 coinsLength = 0; // Figure out how many tokens are in the curve pool. while (true) { try pool.coins(coinsLength) { coinsLength++; } catch { break; } } address[] memory coins = new address[](coinsLength); for (uint256 i = 0; i < coinsLength; i++) { coins[i] = pool.coins(i); } getCurveDerivativeStorage[_asset] = coins; curveAssets.push(address(_asset)); // Setup virtual price bound. VirtualPriceBound memory vpBound = abi.decode(_storage, (VirtualPriceBound)); uint256 upper = uint256(vpBound.datum).mulDivDown(vpBound.posDelta, 1e8); upper = upper.changeDecimals(8, 18); uint256 lower = uint256(vpBound.datum).mulDivDown(vpBound.negDelta, 1e8); lower = lower.changeDecimals(8, 18); _checkBounds(lower, upper, pool.get_virtual_price()); if (vpBound.rateLimit == 0) vpBound.rateLimit = DEFAULT_RATE_LIMIT; vpBound.timeLastUpdated = uint64(block.timestamp); getVirtualPriceBound[address(_asset)] = vpBound; } uint256 private constant GAMMA0 = 28000000000000; uint256 private constant A0 = 2 * 3**3 * 10000; uint256 private constant DISCOUNT0 = 1087460000000000; // x has 36 decimals // result has 18 decimals. function _cubicRoot(uint256 x) internal pure returns (uint256) { uint256 D = x / 1e18; for (uint8 i; i < 256; i++) { uint256 diff; uint256 D_prev = D; D = (D * (2 * 1e18 + ((((x / D) * 1e18) / D) * 1e18) / D)) / (3 * 1e18); if (D > D_prev) diff = D - D_prev; else diff = D_prev - D; if (diff <= 1 || diff * 10**18 < D) return D; } revert("Did not converge"); } /** * Inspired by https://etherscan.io/address/0xE8b2989276E2Ca8FDEA2268E3551b2b4B2418950#code * @notice Get the price of a CurveV1 derivative in terms of USD. */ function _getPriceForCurveV2Derivative( ERC20 asset, address _source, PriceCache[PRICE_CACHE_SIZE] memory cache ) internal view returns (uint256) { ICurvePool pool = ICurvePool(_source); // Check that virtual price is within bounds. uint256 virtualPrice = pool.get_virtual_price(); VirtualPriceBound memory vpBound = getVirtualPriceBound[address(asset)]; uint256 upper = uint256(vpBound.datum).mulDivDown(vpBound.posDelta, 1e8); upper = upper.changeDecimals(8, 18); uint256 lower = uint256(vpBound.datum).mulDivDown(vpBound.negDelta, 1e8); lower = lower.changeDecimals(8, 18); _checkBounds(lower, upper, virtualPrice); address[] memory coins = getCurveDerivativeStorage[asset]; ERC20 token0 = ERC20(coins[0]); if (coins.length == 2) { return pool.lp_price().mulDivDown(_getPriceInUSD(token0, getAssetSettings[token0], cache), 1e18); } else if (coins.length == 3) { uint256 t1Price = pool.price_oracle(0); uint256 t2Price = pool.price_oracle(1); uint256 maxPrice = (3 * virtualPrice * _cubicRoot(t1Price * t2Price)) / 1e18; { uint256 g = pool.gamma().mulDivDown(1e18, GAMMA0); uint256 a = pool.A().mulDivDown(1e18, A0); uint256 coefficient = (g**2 / 1e18) * a; uint256 discount = coefficient > 1e34 ? coefficient : 1e34; discount = _cubicRoot(discount).mulDivDown(DISCOUNT0, 1e18); maxPrice -= maxPrice.mulDivDown(discount, 1e18); } return maxPrice.mulDivDown(_getPriceInUSD(token0, getAssetSettings[token0], cache), 1e18); } else revert("Unsupported Pool"); } // =========================================== AAVE PRICE DERIVATIVE =========================================== /** * @notice Aave Derivative Storage */ mapping(ERC20 => ERC20) public getAaveDerivativeStorage; /** * @notice Setup function for pricing Aave derivative assets. * @dev _source The address of the aToken. * @dev _storage is not used. */ function _setupPriceForAaveDerivative( ERC20 _asset, address _source, bytes memory ) internal { IAaveToken aToken = IAaveToken(_source); getAaveDerivativeStorage[_asset] = ERC20(aToken.UNDERLYING_ASSET_ADDRESS()); } /** * @notice Get the price of an Aave derivative in terms of USD. */ function _getPriceForAaveDerivative( ERC20 asset, address, PriceCache[PRICE_CACHE_SIZE] memory cache ) internal view returns (uint256) { asset = getAaveDerivativeStorage[asset]; return _getPriceInUSD(asset, getAssetSettings[asset], cache); } }
// SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.16; import { ERC20, SafeTransferLib } from "src/base/ERC4626.sol"; import { Multicall } from "src/base/Multicall.sol"; import { IUniswapV2Router02 as IUniswapV2Router } from "src/interfaces/external/IUniswapV2Router02.sol"; import { IUniswapV3Router } from "src/interfaces/external/IUniswapV3Router.sol"; /** * @title Sommelier Swap Router * @notice Provides a universal interface allowing Sommelier contracts to interact with multiple * different exchanges to perform swaps. * @dev Perform multiple swaps using Multicall. * @author crispymangoes, Brian Le */ contract SwapRouter is Multicall { using SafeTransferLib for ERC20; /** * @param UNIV2 Uniswap V2 * @param UNIV3 Uniswap V3 */ enum Exchange { UNIV2, UNIV3 } /** * @notice Get the selector of the function to call in order to perform swap with a given exchange. */ mapping(Exchange => bytes4) public getExchangeSelector; // ========================================== CONSTRUCTOR ========================================== /** * @notice Uniswap V2 swap router contract. */ IUniswapV2Router public immutable uniswapV2Router; // 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D /** * @notice Uniswap V3 swap router contract. */ IUniswapV3Router public immutable uniswapV3Router; // 0xE592427A0AEce92De3Edee1F18E0157C05861564 /** * @param _uniswapV2Router address of the Uniswap V2 swap router contract * @param _uniswapV3Router address of the Uniswap V3 swap router contract */ constructor(IUniswapV2Router _uniswapV2Router, IUniswapV3Router _uniswapV3Router) { // Set up all exchanges. uniswapV2Router = _uniswapV2Router; uniswapV3Router = _uniswapV3Router; // Set up mapping between IDs and selectors. getExchangeSelector[Exchange.UNIV2] = SwapRouter(this).swapWithUniV2.selector; getExchangeSelector[Exchange.UNIV3] = SwapRouter(this).swapWithUniV3.selector; } // ======================================= SWAP OPERATIONS ======================================= /** * @notice Attempted to perform a swap that reverted without a message. */ error SwapRouter__SwapReverted(); /** * @notice Attempted to perform a swap with mismatched assetIn and swap data. * @param actual the address encoded into the swap data * @param expected the address passed in with assetIn */ error SwapRouter__AssetInMisMatch(address actual, address expected); /** * @notice Attempted to perform a swap with mismatched assetOut and swap data. * @param actual the address encoded into the swap data * @param expected the address passed in with assetIn */ error SwapRouter__AssetOutMisMatch(address actual, address expected); /** * @notice Perform a swap using a supported exchange. * @param exchange value dictating which exchange to use to make the swap * @param swapData encoded data used for the swap * @param receiver address to send the received assets to * @return amountOut amount of assets received from the swap */ function swap( Exchange exchange, bytes memory swapData, address receiver, ERC20 assetIn, ERC20 assetOut ) external returns (uint256 amountOut) { // Route swap call to appropriate function using selector. (bool success, bytes memory result) = address(this).delegatecall( abi.encodeWithSelector(getExchangeSelector[exchange], swapData, receiver, assetIn, assetOut) ); if (!success) { // If there is return data, the call reverted with a reason or a custom error so we // bubble up the error message. if (result.length > 0) { assembly { let returndata_size := mload(result) revert(add(32, result), returndata_size) } } else { revert SwapRouter__SwapReverted(); } } amountOut = abi.decode(result, (uint256)); } /** * @notice Perform a swap using Uniswap V2. * @param swapData bytes variable storing the following swap information: * address[] path: array of addresses dictating what swap path to follow * uint256 amount: amount of the first asset in the path to swap * uint256 amountOutMin: the minimum amount of the last asset in the path to receive * @param receiver address to send the received assets to * @return amountOut amount of assets received from the swap */ function swapWithUniV2( bytes memory swapData, address receiver, ERC20 assetIn, ERC20 assetOut ) public returns (uint256 amountOut) { (address[] memory path, uint256 amount, uint256 amountOutMin) = abi.decode( swapData, (address[], uint256, uint256) ); // Check that path matches assetIn and assetOut. if (assetIn != ERC20(path[0])) revert SwapRouter__AssetInMisMatch(path[0], address(assetIn)); if (assetOut != ERC20(path[path.length - 1])) revert SwapRouter__AssetOutMisMatch(path[path.length - 1], address(assetOut)); // Transfer assets to this contract to swap. assetIn.safeTransferFrom(msg.sender, address(this), amount); // Approve assets to be swapped through the router. assetIn.safeApprove(address(uniswapV2Router), amount); // Execute the swap. uint256[] memory amountsOut = uniswapV2Router.swapExactTokensForTokens( amount, amountOutMin, path, receiver, block.timestamp + 60 ); amountOut = amountsOut[amountsOut.length - 1]; _checkApprovalIsZero(assetIn, address(uniswapV2Router)); } /** * @notice Perform a swap using Uniswap V3. * @param swapData bytes variable storing the following swap information * address[] path: array of addresses dictating what swap path to follow * uint24[] poolFees: array of pool fees dictating what swap pools to use * uint256 amount: amount of the first asset in the path to swap * uint256 amountOutMin: the minimum amount of the last asset in the path to receive * @param receiver address to send the received assets to * @return amountOut amount of assets received from the swap */ function swapWithUniV3( bytes memory swapData, address receiver, ERC20 assetIn, ERC20 assetOut ) public returns (uint256 amountOut) { (address[] memory path, uint24[] memory poolFees, uint256 amount, uint256 amountOutMin) = abi.decode( swapData, (address[], uint24[], uint256, uint256) ); // Check that path matches assetIn and assetOut. if (assetIn != ERC20(path[0])) revert SwapRouter__AssetInMisMatch(path[0], address(assetIn)); if (assetOut != ERC20(path[path.length - 1])) revert SwapRouter__AssetOutMisMatch(path[path.length - 1], address(assetOut)); // Transfer assets to this contract to swap. assetIn.safeTransferFrom(msg.sender, address(this), amount); // Approve assets to be swapped through the router. assetIn.safeApprove(address(uniswapV3Router), amount); // Encode swap parameters. bytes memory encodePackedPath = abi.encodePacked(address(assetIn)); for (uint256 i = 1; i < path.length; i++) encodePackedPath = abi.encodePacked(encodePackedPath, poolFees[i - 1], path[i]); // Execute the swap. amountOut = uniswapV3Router.exactInput( IUniswapV3Router.ExactInputParams({ path: encodePackedPath, recipient: receiver, deadline: block.timestamp + 60, amountIn: amount, amountOutMinimum: amountOutMin }) ); _checkApprovalIsZero(assetIn, address(uniswapV3Router)); } // ======================================= HELPER FUNCTIONS ======================================= /** * @notice Emitted when a swap does not use all the assets swap router approved. */ error SwapRouter__UnusedApproval(); /** * @notice Helper function that reverts if the Swap Router has unused approval after a swap is made. */ function _checkApprovalIsZero(ERC20 asset, address spender) internal view { if (asset.allowance(address(this), spender) != 0) revert SwapRouter__UnusedApproval(); } }
// 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: Apache-2.0 pragma solidity 0.8.16; /** * @notice A library to extend the uint32 array data type. */ library Uint32Array { // =========================================== ADDRESS STORAGE =========================================== /** * @notice Add an uint32 to the array at a given index. * @param array uint32 array to add the uint32 to * @param index index to add the uint32 at * @param value uint32 to add to the array */ function add( uint32[] storage array, uint32 index, uint32 value ) internal { uint256 len = array.length; if (len > 0) { array.push(array[len - 1]); for (uint256 i = len - 1; i > index; i--) array[i] = array[i - 1]; array[index] = value; } else { array.push(value); } } /** * @notice Remove a uint32 from the array at a given index. * @param array uint32 array to remove the uint32 from * @param index index to remove the uint32 at */ function remove(uint32[] storage array, uint32 index) internal { uint256 len = array.length; require(index < len, "Index out of bounds"); for (uint256 i = index; i < len - 1; i++) array[i] = array[i + 1]; array.pop(); } /** * @notice Check whether an array contains an uint32. * @param array uint32 array to check * @param value uint32 to check for */ function contains(uint32[] storage array, uint32 value) internal view returns (bool) { for (uint256 i; i < array.length; i++) if (value == array[i]) return true; return false; } }
{ "remappings": [ "@chainlink/=lib/chainlink/", "@compound/=lib/compound-protocol/contracts/", "@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/", "@uniswapV3C/=lib/v3-core.git/contracts/", "@uniswapV3P/=lib/v3-periphery.git/contracts/", "chainlink/=lib/chainlink/contracts/src/v0.8/dev/vendor/@arbitrum/nitro-contracts/src/", "compound-protocol/=lib/compound-protocol/", "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/", "v3-core.git/=lib/v3-core.git/contracts/", "v3-periphery.git/=lib/v3-periphery.git/contracts/" ], "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":"contract Registry","name":"_registry","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"adaptor","type":"address"}],"name":"Cellar__AdaptorNotSetUp","type":"error"},{"inputs":[{"internalType":"address","name":"asset","type":"address"},{"internalType":"address","name":"expectedAsset","type":"address"}],"name":"Cellar__AssetMismatch","type":"error"},{"inputs":[],"name":"Cellar__CallerNotAavePool","type":"error"},{"inputs":[],"name":"Cellar__ContractNotShutdown","type":"error"},{"inputs":[],"name":"Cellar__ContractShutdown","type":"error"},{"inputs":[{"internalType":"uint32","name":"position","type":"uint32"}],"name":"Cellar__DebtMismatch","type":"error"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"uint256","name":"maxDeposit","type":"uint256"}],"name":"Cellar__DepositRestricted","type":"error"},{"inputs":[],"name":"Cellar__ExternalInitiator","type":"error"},{"inputs":[{"internalType":"address","name":"illiquidPosition","type":"address"}],"name":"Cellar__IlliquidWithdraw","type":"error"},{"inputs":[{"internalType":"uint256","name":"assetsOwed","type":"uint256"}],"name":"Cellar__IncompleteWithdraw","type":"error"},{"inputs":[],"name":"Cellar__InvalidFee","type":"error"},{"inputs":[],"name":"Cellar__InvalidFeeCut","type":"error"},{"inputs":[{"internalType":"uint32","name":"positionId","type":"uint32"}],"name":"Cellar__InvalidHoldingPosition","type":"error"},{"inputs":[{"internalType":"uint256","name":"requested","type":"uint256"},{"internalType":"uint256","name":"max","type":"uint256"}],"name":"Cellar__InvalidRebalanceDeviation","type":"error"},{"inputs":[],"name":"Cellar__InvalidShareLockPeriod","type":"error"},{"inputs":[{"internalType":"address","name":"depositor","type":"address"}],"name":"Cellar__NotApprovedToDepositOnBehalf","type":"error"},{"inputs":[],"name":"Cellar__PayoutNotSet","type":"error"},{"inputs":[{"internalType":"uint32","name":"position","type":"uint32"}],"name":"Cellar__PositionAlreadyUsed","type":"error"},{"inputs":[{"internalType":"uint256","name":"maxPositions","type":"uint256"}],"name":"Cellar__PositionArrayFull","type":"error"},{"inputs":[{"internalType":"uint32","name":"position","type":"uint32"},{"internalType":"uint256","name":"sharesRemaining","type":"uint256"}],"name":"Cellar__PositionNotEmpty","type":"error"},{"inputs":[{"internalType":"uint32","name":"position","type":"uint32"}],"name":"Cellar__PositionNotUsed","type":"error"},{"inputs":[],"name":"Cellar__RemovingHoldingPosition","type":"error"},{"inputs":[{"internalType":"uint256","name":"timeSharesAreUnlocked","type":"uint256"},{"internalType":"uint256","name":"currentBlock","type":"uint256"}],"name":"Cellar__SharesAreLocked","type":"error"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"uint256","name":"min","type":"uint256"},{"internalType":"uint256","name":"max","type":"uint256"}],"name":"Cellar__TotalAssetDeviatedOutsideRange","type":"error"},{"inputs":[{"internalType":"uint256","name":"current","type":"uint256"},{"internalType":"uint256","name":"expected","type":"uint256"}],"name":"Cellar__TotalSharesMustRemainConstant","type":"error"},{"inputs":[],"name":"Cellar__ZeroAssets","type":"error"},{"inputs":[],"name":"Cellar__ZeroShares","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"}],"name":"Deposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint64","name":"oldPlatformFee","type":"uint64"},{"indexed":false,"internalType":"uint64","name":"newPlatformFee","type":"uint64"}],"name":"PlatformFeeChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint32","name":"position","type":"uint32"},{"indexed":false,"internalType":"uint256","name":"index","type":"uint256"}],"name":"PositionAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint32","name":"position","type":"uint32"},{"indexed":false,"internalType":"uint256","name":"index","type":"uint256"}],"name":"PositionRemoved","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint32","name":"newPosition1","type":"uint32"},{"indexed":false,"internalType":"uint32","name":"newPosition2","type":"uint32"},{"indexed":false,"internalType":"uint256","name":"index1","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"index2","type":"uint256"}],"name":"PositionSwapped","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"oldDeviation","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newDeviation","type":"uint256"}],"name":"RebalanceDeviationChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"feesInSharesRedeemed","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"feesInAssetsSent","type":"uint256"}],"name":"SendFees","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"oldPeriod","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newPeriod","type":"uint256"}],"name":"ShareLockingPeriodChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"isShutdown","type":"bool"}],"name":"ShutdownChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"oldPayoutAddress","type":"address"},{"indexed":false,"internalType":"address","name":"newPayoutAddress","type":"address"}],"name":"StrategistPayoutAddressChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint64","name":"oldPlatformCut","type":"uint64"},{"indexed":false,"internalType":"uint64","name":"newPlatformCut","type":"uint64"}],"name":"StrategistPlatformCutChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"},{"indexed":true,"internalType":"address","name":"receiver","type":"address"},{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"}],"name":"Withdraw","type":"event"},{"inputs":[],"name":"DOMAIN_SEPARATOR","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"GRAVITY_BRIDGE_REGISTRY_SLOT","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAXIMUM_SHARE_LOCK_PERIOD","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_FEE_CUT","outputs":[{"internalType":"uint64","name":"","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_PLATFORM_FEE","outputs":[{"internalType":"uint64","name":"","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_POSITIONS","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_REBALANCE_DEVIATION","outputs":[{"internalType":"uint64","name":"","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MINIMUM_SHARE_LOCK_PERIOD","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PRICE_ROUTER_REGISTRY_SLOT","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"aavePool","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"index","type":"uint32"},{"internalType":"uint32","name":"positionId","type":"uint32"},{"internalType":"bytes","name":"configurationData","type":"bytes"},{"internalType":"bool","name":"inDebtArray","type":"bool"}],"name":"addPosition","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"allowedRebalanceDeviation","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"asset","outputs":[{"internalType":"contract ERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"assetRiskTolerance","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"blockExternalReceiver","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"adaptor","type":"address"},{"internalType":"bytes[]","name":"callData","type":"bytes[]"}],"internalType":"struct Cellar.AdaptorCall[]","name":"data","type":"tuple[]"}],"name":"callOnAdaptor","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"name":"convertToAssets","outputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"name":"convertToShares","outputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"creditPositions","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"debtPositions","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"}],"name":"deposit","outputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"assets","type":"address[]"},{"internalType":"uint256[]","name":"amounts","type":"uint256[]"},{"internalType":"uint256[]","name":"premiums","type":"uint256[]"},{"internalType":"address","name":"initiator","type":"address"},{"internalType":"bytes","name":"params","type":"bytes"}],"name":"executeOperation","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"feeData","outputs":[{"internalType":"uint64","name":"strategistPlatformCut","type":"uint64"},{"internalType":"uint64","name":"platformFee","type":"uint64"},{"internalType":"uint64","name":"lastAccrual","type":"uint64"},{"internalType":"address","name":"strategistPayoutAddress","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getCreditPositions","outputs":[{"internalType":"uint32[]","name":"","type":"uint32[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getDebtPositions","outputs":[{"internalType":"uint32[]","name":"","type":"uint32[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getPositionAssets","outputs":[{"internalType":"contract ERC20[]","name":"assets","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"","type":"uint32"}],"name":"getPositionData","outputs":[{"internalType":"address","name":"adaptor","type":"address"},{"internalType":"bool","name":"isDebt","type":"bool"},{"internalType":"bytes","name":"adaptorData","type":"bytes"},{"internalType":"bytes","name":"configurationData","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"holdingPosition","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"params","type":"bytes"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"initiateShutdown","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"isAdaptorSetup","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"isPositionUsed","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"isShutdown","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"liftShutdown","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"locked","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"maxDeposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"maxMint","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"maxRedeem","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"maxWithdraw","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"}],"name":"mint","outputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"nonces","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"onERC721Received","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"permit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"name":"previewDeposit","outputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"name":"previewMint","outputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"name":"previewRedeem","outputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"name":"previewWithdraw","outputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"protocolRiskTolerance","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"owner","type":"address"}],"name":"redeem","outputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"registry","outputs":[{"internalType":"contract Registry","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"index","type":"uint32"},{"internalType":"bool","name":"inDebtArray","type":"bool"}],"name":"removePosition","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"sendFees","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"positionId","type":"uint32"}],"name":"setHoldingPosition","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint64","name":"newPlatformFee","type":"uint64"}],"name":"setPlatformFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newDeviation","type":"uint256"}],"name":"setRebalanceDeviation","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newLock","type":"uint256"}],"name":"setShareLockPeriod","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"payout","type":"address"}],"name":"setStrategistPayoutAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint64","name":"cut","type":"uint64"}],"name":"setStrategistPlatformCut","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_adaptor","type":"address"}],"name":"setupAdaptor","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"shareLockPeriod","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"index1","type":"uint32"},{"internalType":"uint32","name":"index2","type":"uint32"},{"internalType":"bool","name":"inDebtArray","type":"bool"}],"name":"swapPositions","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalAssets","outputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalAssetsWithdrawable","outputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"userShareLockStartTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"address","name":"owner","type":"address"}],"name":"withdraw","outputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"stateMutability":"nonpayable","type":"function"}]
Contract Creation Code
6001600b55610100604052670a688906bd8b0000608052662386f26fc1000060a052600060c081905260e052601180546001600160c01b0319166e2386f26fc100000a688906bd8b0000179055601280546001600160a01b03191690556202a300601555660110d9316ec00060185560198054747d2768de32b0b80b7a3454c06bdac94a69ddc7a900610100600160a81b0319909116179055348015620000a557600080fd5b506040516200717238038062007172833981016040819052620000c89162000b7f565b604080516020808201835260008083528351808301855281815284518281529283018281528386018381526060850190965286959294939192856200011e565b6060815260200190600190039081620001085790505b5060408051600080825260208201909252906200014c565b6060815260200190600190039081620001365790505b506000806000806040516020016200016c98979695949392919062000c8f565b60408051808303601f1901815290829052635c9fcd8560e11b825260006004830152906001600160a01b0386169063b93f9b0a90602401602060405180830381865afa158015620001c1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190620001e7919062000b7f565b84848460128282826000620001fd848262000daf565b5060016200020c838262000daf565b506002805460ff191660ff8316179055466006556200022a62000487565b6007555050600980546001600160a01b039687166001600160a01b031991821617909155600a805496881696909116861790555050604051600092507f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091508290a35084601360016101000a8154816001600160a01b0302191690836001600160a01b03160217905550600080600080600085806020019051810190620002d291906200106f565b60ff169450945094509450945060005b85518163ffffffff1610156200035e576200034b81878363ffffffff16815181106200031257620003126200113b565b6020026020010151868463ffffffff16815181106200033557620003356200113b565b602002602001015160006200052360201b60201c565b620003568162001167565b9050620002e2565b5060005b84518163ffffffff161015620003de57620003cb81868363ffffffff16815181106200039257620003926200113b565b6020026020010151858463ffffffff1681518110620003b557620003b56200113b565b602002602001015160016200052360201b60201c565b620003d68162001167565b905062000362565b50845115620003f257620003f281620007e6565b505060118054600160801b600160c01b031916600160801b426001600160401b031602179055505081516000915081908190620004399060209086018101908601620011b2565b601280546001600160a01b039094166001600160a01b0319909416939093179092556001600160801b03918216600160801b02911617601455506200146c9c50505050505050505050505050565b60007f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f6000604051620004bb9190620012b6565b6040805191829003822060208301939093528101919091527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc660608201524660808201523060a082015260c00160405160208183030381529060405280519060200120905090565b63ffffffff83166000908152600e602052604090205460ff1615620005685760405163335894fb60e11b815263ffffffff841660048201526024015b60405180910390fd5b60135460145460405163a5b3bddd60e01b815263ffffffff861660048201526001600160801b038083166024830152600160801b90920490911660448201526000918291829161010090046001600160a01b03169063a5b3bddd90606401600060405180830381865afa158015620005e4573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526200060e919081019062001334565b925092509250831515821515146200064257604051632b1d0bd360e11b815263ffffffff871660048201526024016200055f565b604080516080810182526001600160a01b0380861682528415156020808401918252838501868152606085018b905263ffffffff8c166000908152600f9092529490208351815492511515600160a01b026001600160a81b031990931693169290921717815591519091906001820190620006be908262000daf565b5060608201516002820190620006d5908262000daf565b5090505081156200072b57600d54601011620007085760405163f025236d60e01b8152601060048201526024016200055f565b620007258787600d620008f460201b62002bea179092919060201c565b62000770565b600c54601011620007535760405163f025236d60e01b8152601060048201526024016200055f565b620007708787600c620008f460201b62002bea179092919060201c565b63ffffffff86166000908152600e602052604090819020805460ff19166001179055517fc4f8cb57c016f0b294fff2666f86fa6cfee9b03aed19f816ae4bf44b7e837bbb90620007d59088908a9063ffffffff92831681529116602082015260400190565b60405180910390a150505050505050565b63ffffffff81166000908152600e602052604090205460ff1662000826576040516370abe85960e01b815263ffffffff821660048201526024016200055f565b6009546001600160a01b03166200083d8262000ad1565b6001600160a01b03161462000890576009546001600160a01b0316620008638262000ad1565b60405163298473c760e11b81526001600160a01b039283166004820152911660248201526044016200055f565b63ffffffff81166000908152600f6020526040902054600160a01b900460ff1615620008d857604051630a42c0f960e41b815263ffffffff821660048201526024016200055f565b6010805463ffffffff191663ffffffff92909216919091179055565b8254801562000a905783806200090c600184620013a3565b815481106200091f576200091f6200113b565b60009182526020808320600880840490910154855460018082018855968652928520918304909101805463ffffffff60046007958616810261010090810a83810219909416969097160290950a9092049093160217905590620009839083620013a3565b90505b8363ffffffff1681111562000a3a5784620009a3600183620013a3565b81548110620009b657620009b66200113b565b90600052602060002090600891828204019190066004029054906101000a900463ffffffff16858281548110620009f157620009f16200113b565b90600052602060002090600891828204019190066004026101000a81548163ffffffff021916908363ffffffff160217905550808062000a3190620013bf565b91505062000986565b5081848463ffffffff168154811062000a575762000a576200113b565b90600052602060002090600891828204019190066004026101000a81548163ffffffff021916908363ffffffff16021790555062000acb565b83546001810185556000858152602090206008820401805460079092166004026101000a63ffffffff81810219909316928516029190911790555b50505050565b63ffffffff81166000908152600f60205260408082208054915163e170a9bf60e01b81526001600160a01b0390921691829163e170a9bf9162000b1b9160010190600401620013d9565b602060405180830381865afa15801562000b39573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019062000b5f919062000b7f565b9392505050565b6001600160a01b038116811462000b7c57600080fd5b50565b60006020828403121562000b9257600080fd5b815162000b5f8162000b66565b634e487b7160e01b600052604160045260246000fd5b600081518084526020808501945080840160005b8381101562000bed57815163ffffffff168752958201959082019060010162000bc9565b509495945050505050565b60005b8381101562000c1557818101518382015260200162000bfb565b50506000910152565b600081518084526020808501808196508360051b8101915082860160005b8581101562000c825782840389528151805180865262000c628188880189850162000bf8565b99860199601f01601f191694909401850193509084019060010162000c3c565b5091979650505050505050565b600061010080835262000ca58184018c62000bb5565b9050828103602084015262000cbb818b62000bb5565b9050828103604084015262000cd1818a62000c1e565b9050828103606084015262000ce7818962000c1e565b60ff97881660808501526001600160a01b039690961660a0840152505091841660c083015290921660e090920191909152949350505050565b600181811c9082168062000d3557607f821691505b60208210810362000d5657634e487b7160e01b600052602260045260246000fd5b50919050565b601f82111562000daa57600081815260208120601f850160051c8101602086101562000d855750805b601f850160051c820191505b8181101562000da65782815560010162000d91565b5050505b505050565b81516001600160401b0381111562000dcb5762000dcb62000b9f565b62000de38162000ddc845462000d20565b8462000d5c565b602080601f83116001811462000e1b576000841562000e025750858301515b600019600386901b1c1916600185901b17855562000da6565b600085815260208120601f198616915b8281101562000e4c5788860151825594840194600190910190840162000e2b565b508582101562000e6b5787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b604051601f8201601f191681016001600160401b038111828210171562000ea65762000ea662000b9f565b604052919050565b60006001600160401b0382111562000eca5762000eca62000b9f565b5060051b60200190565b600082601f83011262000ee657600080fd5b8151602062000eff62000ef98362000eae565b62000e7b565b82815260059290921b8401810191818101908684111562000f1f57600080fd5b8286015b8481101562000f5057805163ffffffff8116811462000f425760008081fd5b835291830191830162000f23565b509695505050505050565b600082601f83011262000f6d57600080fd5b81516001600160401b0381111562000f895762000f8962000b9f565b62000f9e601f8201601f191660200162000e7b565b81815284602083860101111562000fb457600080fd5b62000fc782602083016020870162000bf8565b949350505050565b600082601f83011262000fe157600080fd5b8151602062000ff462000ef98362000eae565b82815260059290921b840181019181810190868411156200101457600080fd5b8286015b8481101562000f505780516001600160401b03811115620010395760008081fd5b620010498986838b010162000f5b565b84525091830191830162001018565b805160ff811681146200106a57600080fd5b919050565b600080600080600060a086880312156200108857600080fd5b85516001600160401b0380821115620010a057600080fd5b620010ae89838a0162000ed4565b96506020880151915080821115620010c557600080fd5b620010d389838a0162000ed4565b95506040880151915080821115620010ea57600080fd5b620010f889838a0162000fcf565b945060608801519150808211156200110f57600080fd5b506200111e8882890162000fcf565b9250506200112f6080870162001058565b90509295509295909350565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b600063ffffffff80831681810362001183576200118362001151565b6001019392505050565b80516200106a8162000b66565b80516001600160801b03811681146200106a57600080fd5b600080600080600080600080610100898b031215620011d057600080fd5b88516001600160401b0380821115620011e857600080fd5b620011f68c838d0162000ed4565b995060208b01519150808211156200120d57600080fd5b6200121b8c838d0162000ed4565b985060408b01519150808211156200123257600080fd5b620012408c838d0162000fcf565b975060608b01519150808211156200125757600080fd5b50620012668b828c0162000fcf565b9550506200127760808a0162001058565b93506200128760a08a016200118d565b92506200129760c08a016200119a565b9150620012a760e08a016200119a565b90509295985092959890939650565b6000808354620012c68162000d20565b60018281168015620012e15760018114620012f75762001328565b60ff198416875282151583028701945062001328565b8760005260208060002060005b858110156200131f5781548a82015290840190820162001304565b50505082870194505b50929695505050505050565b6000806000606084860312156200134a57600080fd5b8351620013578162000b66565b602085015190935080151581146200136e57600080fd5b60408501519092506001600160401b038111156200138b57600080fd5b620013998682870162000f5b565b9150509250925092565b81810381811115620013b957620013b962001151565b92915050565b600081620013d157620013d162001151565b506000190190565b6000602080835260008454620013ef8162000d20565b808487015260406001808416600081146200141357600181146200142e576200145e565b60ff1985168984015283151560051b8901830195506200145e565b896000528660002060005b85811015620014565781548b820186015290830190880162001439565b8a0184019650505b509398975050505050505050565b615cf6806200147c6000396000f3fe608060405234801561001057600080fd5b50600436106104535760003560e01c80637b10399911610241578063b5292a991161013b578063d505accf116100c3578063e753e60011610087578063e753e600146109f7578063eef33eca14610a67578063ef8b30f714610a76578063f2fde38b14610a89578063f7b24e0814610a9c57600080fd5b8063d505accf1461098b578063d905777e1461099e578063dd62ed3e146109b1578063dff90b5b146109dc578063e1b1acb7146109e457600080fd5b8063c63d75b61161010a578063c63d75b614610625578063c6e6f59214610954578063cd82f8b114610967578063ce96cb771461096f578063cf3090121461098257600080fd5b8063b5292a9914610918578063ba0876521461092b578063bf86d6901461093e578063c244245a1461094b57600080fd5b80639c552ca8116101c9578063a9059cbb1161018d578063a9059cbb146108b2578063b0a75d36146108c5578063b2c69eed146108d8578063b3d7f6b9146108f2578063b460af941461090557600080fd5b80639c552ca8146108665780639c5f00c2146108795780639fdb11b614610889578063a03e4bc314610892578063a8144e48146108aa57600080fd5b806393bbeac01161021057806393bbeac0146107ea57806394bf804d1461080d57806395d89b41146108205780639955a9d4146108285780639babf9fd1461083b57600080fd5b80637b1039991461078c5780637ecebe00146107a45780638da5cb5b146107c4578063920f5c84146107d757600080fd5b80633998a681116103525780635a400d25116102da578063709ffa181161029e578063709ffa181461070b57806370a082311461072e57806370af7df61461074e57806371e99dc2146107615780637384504f1461076957600080fd5b80635a400d25146106b95780635e2c576e146106c1578063687c2b50146106c95780636e553f65146106e95780636ff1c02a146106fc57600080fd5b80634c4602da116103215780634c4602da1461064b5780634cdad506146106585780634e84befe1461066b578063530a37141461067e57806359d20b4e1461069157600080fd5b80633998a681146105e95780633e3382ba14610610578063402d267d14610625578063439fab911461063857600080fd5b80630a680e18116103e0578063313ce567116103a4578063313ce5671461057157806333e15be2146105905780633644e515146105a3578063379e0b13146105ab57806338d52e0f146105be57600080fd5b80630a680e181461050e578063150b7a021461051657806318160ddd1461054257806323689f051461054b57806323b872dd1461055e57600080fd5b80630780fd3a116104275780630780fd3a1461049b57806307a2d13a146104b0578063087ed837146104c3578063095ea7b3146104d85780630a28a477146104fb57600080fd5b806251a3b71461045857806301e1d114146104745780630402ab631461047c57806306fdde0314610486575b600080fd5b61046161012c81565b6040519081526020015b60405180910390f35b610461610aa4565b6104616202a30081565b61048e610ae0565b60405161046b91906149a7565b6104ae6104a93660046149cc565b610b6e565b005b6104616104be3660046149e9565b610ba4565b6104cb610bbd565b60405161046b9190614a46565b6104eb6104e6366004614a6e565b610c92565b604051901515815260200161046b565b6104616105093660046149e9565b610cfe565b6104ae610d1c565b610529610524366004614b85565b610db0565b6040516001600160e01b0319909116815260200161046b565b61046160035481565b6104ae610559366004614bf0565b610dc1565b6104eb61056c366004614c0d565b610e95565b60025461057e9060ff1681565b60405160ff909116815260200161046b565b6104ae61059e366004614c5c565b610eab565b610461611084565b6104ae6105b9366004614c95565b61109e565b6009546105d1906001600160a01b031681565b6040516001600160a01b03909116815260200161046b565b6105f86702c68af0bb14000081565b6040516001600160401b03909116815260200161046b565b610618611376565b60405161046b9190614ce0565b610461610633366004614bf0565b6113fa565b6104ae610646366004614d72565b611419565b6019546104eb9060ff1681565b6104616106663660046149e9565b6117e4565b6104ae610679366004614dd6565b6117fb565b6104ae61068c3660046149e9565b611a92565b6106a461069f3660046149e9565b611b3c565b60405163ffffffff909116815260200161046b565b610461600281565b6104ae611b76565b6104616106d7366004614bf0565b60166020526000908152604090205481565b6104616106f7366004614f47565b611bfe565b6105f867016345785d8a000081565b6104eb610719366004614bf0565b60176020526000908152604090205460ff1681565b61046161073c366004614bf0565b60046020526000908152604090205481565b6104ae61075c366004614f6c565b611c78565b610618611d54565b61077c6107773660046149cc565b611db1565b60405161046b9493929190614f95565b6013546105d19061010090046001600160a01b031681565b6104616107b2366004614bf0565b60086020526000908152604090205481565b600a546105d1906001600160a01b031681565b6104eb6107e5366004615022565b611efa565b6104eb6107f83660046149e9565b600e6020526000908152604090205460ff1681565b61046161081b366004614f47565b612103565b61048e612171565b6104ae6108363660046150fc565b61217e565b60145461084e906001600160801b031681565b6040516001600160801b03909116815260200161046b565b6104ae6108743660046149e9565b6121de565b6010546106a49063ffffffff1681565b61046160155481565b6019546105d19061010090046001600160a01b031681565b610461612276565b6104eb6108c0366004614a6e565b6122a4565b6104ae6108d3366004614bf0565b6122b9565b60145461084e90600160801b90046001600160801b031681565b6104616109003660046149e9565b61234c565b610461610913366004615170565b612363565b6104ae610926366004614f6c565b6123be565b610461610939366004615170565b612484565b6013546104eb9060ff1681565b61046160185481565b6104616109623660046149e9565b6124f3565b610461600081565b61046161097d366004614bf0565b612506565b610461600b5481565b6104ae6109993660046151b6565b612535565b6104616109ac366004614bf0565b612779565b6104616109bf366004615227565b600560209081526000928352604080842090915290825290205481565b6104ae6127a8565b6106a46109f23660046149e9565b612b4d565b601154601254610a2e916001600160401b0380821692600160401b8304821692600160801b9004909116906001600160a01b031684565b604080516001600160401b039586168152938516602085015291909316908201526001600160a01b03909116606082015260800161046b565b6105f8670de0b6b3a764000081565b610461610a843660046149e9565b612b5d565b6104ae610a97366004614bf0565b612b74565b610461601081565b6000600b54600114610ad15760405162461bcd60e51b8152600401610ac890615255565b60405180910390fd5b610adb6000612daf565b905090565b60008054610aed90615279565b80601f0160208091040260200160405190810160405280929190818152602001828054610b1990615279565b8015610b665780601f10610b3b57610100808354040283529160200191610b66565b820191906000526020600020905b815481529060010190602001808311610b4957829003601f168201915b505050505081565b600a546001600160a01b03163314610b985760405162461bcd60e51b8152600401610ac8906152ad565b610ba1816132ac565b50565b6000610bb782610bb2610aa4565b6133b0565b92915050565b600c546060906001600160401b03811115610bda57610bda614a9a565b604051908082528060200260200182016040528015610c03578160200160208202803683370190505b50905060005b600c54811015610c8e57610c54600c8281548110610c2957610c296152d3565b90600052602060002090600891828204019190066004029054906101000a900463ffffffff16613450565b828281518110610c6657610c666152d3565b6001600160a01b0390921660209283029190910190910152610c87816152ff565b9050610c09565b5090565b3360008181526005602090815260408083206001600160a01b038716808552925280832085905551919290917f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92590610ced9086815260200190565b60405180910390a350600192915050565b600080610d09610aa4565b9050610d1583826134d9565b9392505050565b60135460ff1615610d40576040516337a5332d60e11b815260040160405180910390fd5b600a546001600160a01b03163314610d6a5760405162461bcd60e51b8152600401610ac8906152ad565b6013805460ff191660019081179091556040519081527fb8527b93c36dabdfe078af41be789ba946a4adcfeafcf9d8de21d51629859e3c906020015b60405180910390a1565b630a85bd0160e11b5b949350505050565b600a546001600160a01b03163314610deb5760405162461bcd60e51b8152600401610ac8906152ad565b60135460145460405163a46089cf60e01b81526001600160a01b0384811660048301526001600160801b038084166024840152600160801b9093049092166044820152610100909204169063a46089cf9060640160006040518083038186803b158015610e5757600080fd5b505afa158015610e6b573d6000803e3d6000fd5b5050506001600160a01b039091166000908152601760205260409020805460ff1916600117905550565b6000610ea084613568565b610db98484846135c7565b600a546001600160a01b03163314610ed55760405162461bcd60e51b8152600401610ac8906152ad565b600081610f2057600c8363ffffffff1681548110610ef557610ef56152d3565b90600052602060002090600891828204019190066004029054906101000a900463ffffffff16610f60565b600d8363ffffffff1681548110610f3957610f396152d3565b90600052602060002090600891828204019190066004029054906101000a900463ffffffff165b60105490915063ffffffff90811690821603610f8f576040516319ded73160e21b815260040160405180910390fd5b6000610f9a826136a7565b90508015610fca57604051631c7b946d60e31b815263ffffffff8316600482015260248101829052604401610ac8565b8215610fe057610fdb600d85613730565b610feb565b610feb600c85613730565b63ffffffff82166000908152600e60209081526040808320805460ff19169055600f909152812080546001600160a81b03191681559061102e600183018261490d565b61103c60028301600061490d565b50506040805163ffffffff8085168252861660208201527fa5cd0099b78b279c04987aa80ffffaf8fc8c8af4e7c7bce2686e8d01e2e1bd51910160405180910390a150505050565b6000600654461461109757610adb613875565b5060075490565b600a546001600160a01b031633146110c85760405162461bcd60e51b8152600401610ac8906152ad565b60008082156111fa57600d8463ffffffff16815481106110ea576110ea6152d3565b90600052602060002090600891828204019190066004029054906101000a900463ffffffff169150600d8563ffffffff168154811061112b5761112b6152d3565b90600052602060002090600891828204019190066004029054906101000a900463ffffffff1690508181600d8763ffffffff168154811061116e5761116e6152d3565b9060005260206000209060089182820401919006600402600d8863ffffffff168154811061119e5761119e6152d3565b90600052602060002090600891828204019190066004028491906101000a81548163ffffffff021916908363ffffffff1602179055508391906101000a81548163ffffffff021916908363ffffffff160217905550505061131f565b600c8463ffffffff1681548110611213576112136152d3565b90600052602060002090600891828204019190066004029054906101000a900463ffffffff169150600c8563ffffffff1681548110611254576112546152d3565b90600052602060002090600891828204019190066004029054906101000a900463ffffffff1690508181600c8763ffffffff1681548110611297576112976152d3565b9060005260206000209060089182820401919006600402600c8863ffffffff16815481106112c7576112c76152d3565b90600052602060002090600891828204019190066004028491906101000a81548163ffffffff021916908363ffffffff1602179055508391906101000a81548163ffffffff021916908363ffffffff16021790555050505b6040805163ffffffff84811682528381166020830152878116828401528616606082015290517fb7c5df04749a3a06a9a7bf1a8142ccf2a4ee6cbf4709489e876a6e4eb3301e8a9181900360800190a15050505050565b6060600d8054806020026020016040519081016040528092919081815260200182805480156113f057602002820191906000526020600020906000905b82829054906101000a900463ffffffff1663ffffffff16815260200190600401906020826003010492830192600103820291508084116113b35790505b5050505050905090565b60135460009060ff161561141057506000919050565b50600019919050565b601954600160b01b900460ff161580801561144157506019546001600160a81b90910460ff16105b806114625750303b1580156114625750601954600160a81b900460ff166001145b6114c55760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610ac8565b6019805460ff60a81b1916600160a81b17905580156114f2576019805460ff60b01b1916600160b01b1790555b60008080808080611505888a018a615318565b601380546001600160a01b0380881661010002610100600160a81b031992831617909255600980548388166001600160a01b031991821617909155600a8054938a1693909116929092179091556202a300601555660aa87bee53800060185560198054747d2768de32b0b80b7a3454c06bdac94a69ddc7a9009216919091179055949a5092985090965094509250905060006115a18482615424565b5060016115ae8382615424565b506002805460ff19166012179055466006556115c8613875565b6007819055506001600b81905550600080600080600080600080888060200190518101906115f69190615648565b9750975097509750975097509750975060005b88518163ffffffff16101561167557611663818a8363ffffffff1681518110611634576116346152d3565b6020026020010151898463ffffffff1681518110611654576116546152d3565b6020026020010151600061390f565b8061166d81615737565b915050611609565b5060005b87518163ffffffff1610156116e5576116d381898363ffffffff16815181106116a4576116a46152d3565b6020026020010151888463ffffffff16815181106116c4576116c46152d3565b6020026020010151600161390f565b806116dd81615737565b915050611679565b506116ef846132ac565b6001600160801b03908116600160801b908102919092161760145560408051608081018252670b1a2bc2ec50000081526611c37937e080006020820152426001600160401b03169181018290526001600160a01b03909316606090930183905260118054919092026001600160c01b0319909116176e11c37937e080000b1a2bc2ec500000179055601280546001600160a01b03191690911790555050891598506117df975050505050505050576019805460ff60b01b19169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b505050565b6000806117ef610aa4565b9050610d1583826133b0565b600a546001600160a01b031633146118255760405162461bcd60e51b8152600401610ac8906152ad565b60135460ff1615611849576040516337a5332d60e11b815260040160405180910390fd5b600b5460011461186b5760405162461bcd60e51b8152600401610ac890615255565b6002600b556019805460ff19166001179055600080808061188b81612daf565b90506118b6601854670de0b6b3a76400006118a6919061575a565b8290670de0b6b3a7640000613b9a565b93506118d1601854670de0b6b3a76400006118a6919061576d565b925060035491505060005b84518160ff161015611a01576000858260ff16815181106118ff576118ff6152d3565b602090810291909101810151516001600160a01b0381166000908152601790925260409091205490915060ff16611954576040516352873a5160e11b81526001600160a01b0382166004820152602401610ac8565b60005b868360ff168151811061196c5761196c6152d3565b602002602001015160200151518160ff1610156119ee576119db878460ff168151811061199b5761199b6152d3565b6020026020010151602001518260ff16815181106119bb576119bb6152d3565b6020026020010151836001600160a01b0316613bc890919063ffffffff16565b50806119e681615780565b915050611957565b5050806119fa90615780565b90506118dc565b506000611a0e6000612daf565b905083811080611a1d57508281115b15611a4c5760405163628cc47560e11b8152600481018290526024810185905260448101849052606401610ac8565b6003548214611a7c57600354604051632b40145960e21b8152600481019190915260248101839052604401610ac8565b50506019805460ff1916905550506001600b5550565b600a546001600160a01b03163314611abc5760405162461bcd60e51b8152600401610ac8906152ad565b67016345785d8a0000811115611af6576040516302d2a90f60e51b81526004810182905267016345785d8a00006024820152604401610ac8565b601880549082905560408051828152602081018490527fdf4be33b2e9e3dd4d9e0e85645aea428494a0644a72c51d6a15aedae6b66a3ff91015b60405180910390a15050565b600c8181548110611b4c57600080fd5b9060005260206000209060089182820401919006600402915054906101000a900463ffffffff1681565b600a546001600160a01b03163314611ba05760405162461bcd60e51b8152600401610ac8906152ad565b60135460ff16611bc35760405163ec7165bf60e01b815260040160405180910390fd5b6013805460ff19169055604051600081527fb8527b93c36dabdfe078af41be789ba946a4adcfeafcf9d8de21d51629859e3c90602001610da6565b6000600b54600114611c225760405162461bcd60e51b8152600401610ac890615255565b6002600b556000611c3281612daf565b9050611c3e8482613bed565b915081600003611c615760405163426f153760e11b815260040160405180910390fd5b611c6c848385613c04565b506001600b5592915050565b600a546001600160a01b03163314611ca25760405162461bcd60e51b8152600401610ac8906152ad565b6702c68af0bb1400006001600160401b0382161115611cd457604051632e15286d60e11b815260040160405180910390fd5b60115460408051600160401b9092046001600160401b039081168352831660208301527f44ada261ff5c9aacbf8d0687294799c8e3e0810ecc1eafd97419dfc31db5d523910160405180910390a1601180546001600160401b03909216600160401b026fffffffffffffffff000000000000000019909216919091179055565b6060600c8054806020026020016040519081016040528092919081815260200182805480156113f0576000918252602091829020805463ffffffff1684529082028301929091600491018084116113b35790505050505050905090565b600f60205260009081526040902080546001820180546001600160a01b03831693600160a01b90930460ff16929190611de990615279565b80601f0160208091040260200160405190810160405280929190818152602001828054611e1590615279565b8015611e625780601f10611e3757610100808354040283529160200191611e62565b820191906000526020600020905b815481529060010190602001808311611e4557829003601f168201915b505050505090806002018054611e7790615279565b80601f0160208091040260200160405190810160405280929190818152602001828054611ea390615279565b8015611ef05780601f10611ec557610100808354040283529160200191611ef0565b820191906000526020600020905b815481529060010190602001808311611ed357829003601f168201915b5050505050905084565b60006001600160a01b0384163014611f25576040516304a246dd60e51b815260040160405180910390fd5b60195461010090046001600160a01b03163314611f55576040516349456ad960e01b815260040160405180910390fd5b6000611f6383850185614dd6565b905060005b81518160ff16101561204d576000828260ff1681518110611f8b57611f8b6152d3565b602090810291909101810151516001600160a01b0381166000908152601790925260409091205490915060ff16611fe0576040516352873a5160e11b81526001600160a01b0382166004820152602401610ac8565b60005b838360ff1681518110611ff857611ff86152d3565b602002602001015160200151518160ff16101561203a57612027848460ff168151811061199b5761199b6152d3565b508061203281615780565b915050611fe3565b50508061204690615780565b9050611f68565b5060005b888110156120f1576019546120e19061010090046001600160a01b0316898984818110612080576120806152d3565b905060200201358c8c85818110612099576120996152d3565b905060200201356120aa919061576d565b8e8e858181106120bc576120bc6152d3565b90506020020160208101906120d19190614bf0565b6001600160a01b03169190613c82565b6120ea816152ff565b9050612051565b5060019b9a5050505050505050505050565b6000600b546001146121275760405162461bcd60e51b8152600401610ac890615255565b6002600b55600061213781612daf565b90506121438482613cf9565b91508160000361216657604051639768300560e01b815260040160405180910390fd5b611c6c828585613c04565b60018054610aed90615279565b600a546001600160a01b031633146121a85760405162461bcd60e51b8152600401610ac8906152ad565b60135460ff16156121cc576040516337a5332d60e11b815260040160405180910390fd5b6121d88484848461390f565b50505050565b600a546001600160a01b031633146122085760405162461bcd60e51b8152600401610ac8906152ad565b61012c81108061221a57506202a30081115b1561223857604051633a60233f60e21b815260040160405180910390fd5b601580549082905560408051828152602081018490527f227ff5c6b5ffb395236b09fd1b472bb128b36eaa17556633feefe28e94411f249101611b30565b6000600b5460011461229a5760405162461bcd60e51b8152600401610ac890615255565b610adb6001612daf565b60006122af33613568565b610d158383613d10565b600a546001600160a01b031633146122e35760405162461bcd60e51b8152600401610ac8906152ad565b601254604080516001600160a01b03928316815291831660208301527f51dbb5a65bb22737861a63ec12ba6ce78a98631e9404b0567a2eaf7a06fc544d910160405180910390a1601280546001600160a01b0319166001600160a01b0392909216919091179055565b600080612357610aa4565b9050610d158382613cf9565b6000600b546001146123875760405162461bcd60e51b8152600401610ac890615255565b6002600b55600061239781612daf565b90506123a385826134d9565b91506123b185838686613d76565b506001600b559392505050565b600a546001600160a01b031633146123e85760405162461bcd60e51b8152600401610ac8906152ad565b670de0b6b3a76400006001600160401b038216111561241a57604051633d0203e560e01b815260040160405180910390fd5b601154604080516001600160401b03928316815291831660208301527fb5cc994a260a85a42d6588668221571ae0a14f0a28f9e4817a5195262102c868910160405180910390a16011805467ffffffffffffffff19166001600160401b0392909216919091179055565b6000600b546001146124a85760405162461bcd60e51b8152600401610ac890615255565b6002600b5560006124b881612daf565b90506124c485826133b0565b9150816000036124e757604051639768300560e01b815260040160405180910390fd5b6123b182868686613d76565b6000610bb782612501610aa4565b613bed565b6000600b5460011461252a5760405162461bcd60e51b8152600401610ac890615255565b610bb7826000613e4f565b428410156125855760405162461bcd60e51b815260206004820152601760248201527f5045524d49545f444541444c494e455f455850495245440000000000000000006044820152606401610ac8565b60006001612591611084565b6001600160a01b038a811660008181526008602090815260409182902080546001810190915582517f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c98184015280840194909452938d166060840152608083018c905260a083019390935260c08083018b90528151808403909101815260e08301909152805192019190912061190160f01b6101008301526101028201929092526101228101919091526101420160408051601f198184030181528282528051602091820120600084529083018083525260ff871690820152606081018590526080810184905260a0016020604051602081039080840390855afa15801561269d573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b038116158015906126d35750876001600160a01b0316816001600160a01b0316145b6127105760405162461bcd60e51b815260206004820152600e60248201526d24a72b20a624a22fa9a4a3a722a960911b6044820152606401610ac8565b6001600160a01b0390811660009081526005602090815260408083208a8516808552908352928190208990555188815291928a16917f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a350505050505050565b6000600b5460011461279d5760405162461bcd60e51b8152600401610ac890615255565b610bb7826001613e4f565b600b546001146127ca5760405162461bcd60e51b8152600401610ac890615255565b6002600b556012546001600160a01b0316806127f95760405163dc13611360e01b815260040160405180910390fd5b60006128056000612daf565b60115490915060009061282890600160801b90046001600160401b03164261575a565b6011549091506000906301e1338090670de0b6b3a764000090600160401b90046001600160401b031661285b858761579f565b612865919061579f565b61286f91906157be565b61287991906157be565b9050600061288f61288a8386613bed565b613f07565b905061289b3082613f38565b6011546000906128b59083906001600160401b0316613f92565b905080156129365730600090815260046020526040812080548392906128dc90849061575a565b90915550506001600160a01b03861660008181526004602052604090819020805484019055513090600080516020615ca1833981519152906129219085815260200190565b60405180910390a3612933818361575a565b91505b6011805467ffffffffffffffff60801b19164263ffffffff16600160801b02179055600061296483876133b0565b90508015612b06576129763084613fa7565b601354604051635c9fcd8560e11b81526000600482018190529161010090046001600160a01b03169063b93f9b0a90602401602060405180830381865afa1580156129c5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129e991906157e0565b600954909150612a03906001600160a01b03168284613c82565b806001600160a01b0316631ffbe7f9600960009054906101000a90046001600160a01b0316601360019054906101000a90046001600160a01b03166001600160a01b0316638e0bae7f6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612a7b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612a9f91906157fd565b6040516001600160e01b031960e085901b1681526001600160a01b039092166004830152602482015260448101859052606401600060405180830381600087803b158015612aec57600080fd5b505af1158015612b00573d6000803e3d6000fd5b50505050505b60408051848152602081018390527f15e3e2a76a6839c244c1ed0a821c233ce8af552dffcb856089eae6cbbbb71ea6910160405180910390a150506001600b555050505050565b600d8181548110611b4c57600080fd5b600080612b68610aa4565b9050610d158382613bed565b600a546001600160a01b03163314612b9e5760405162461bcd60e51b8152600401610ac8906152ad565b600a80546001600160a01b0319166001600160a01b03831690811790915560405133907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a350565b82548015612d6e578380612bff60018461575a565b81548110612c0f57612c0f6152d3565b60009182526020808320600880840490910154855460018082018855968652928520918304909101805463ffffffff60046007958616810261010090810a83810219909416969097160290950a9092049093160217905590612c71908361575a565b90505b8363ffffffff16811115612d1c5784612c8e60018361575a565b81548110612c9e57612c9e6152d3565b90600052602060002090600891828204019190066004029054906101000a900463ffffffff16858281548110612cd657612cd66152d3565b90600052602060002090600891828204019190066004026101000a81548163ffffffff021916908363ffffffff1602179055508080612d1490615816565b915050612c74565b5081848463ffffffff1681548110612d3657612d366152d3565b90600052602060002090600891828204019190066004026101000a81548163ffffffff021916908363ffffffff1602179055506121d8565b508254600181018455600093845260209093206008840401805460079094166004026101000a63ffffffff8181021990951692909416939093021790915550565b600c5460009081816001600160401b03811115612dce57612dce614a9a565b604051908082528060200260200182016040528015612df7578160200160208202803683370190505b5090506000826001600160401b03811115612e1457612e14614a9a565b604051908082528060200260200182016040528015612e3d578160200160208202803683370190505b50601354604051635c9fcd8560e11b8152600260048201529192506000916101009091046001600160a01b03169063b93f9b0a90602401602060405180830381865afa158015612e91573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612eb591906157e0565b905085156130035760005b84811015612f85576000600c8281548110612edd57612edd6152d3565b90600052602060002090600891828204019190066004029054906101000a900463ffffffff169050612f0e81614009565b848381518110612f2057612f206152d3565b6020026020010181815250600003612f385750612f75565b612f4181613450565b858381518110612f5357612f536152d3565b60200260200101906001600160a01b031690816001600160a01b031681525050505b612f7e816152ff565b9050612ec0565b5060095460405163b333a17560e01b81526001600160a01b038084169263b333a17592612fbb928892889291169060040161585d565b602060405180830381865afa158015612fd8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ffc91906157fd565b94506132a3565b600d546000816001600160401b0381111561302057613020614a9a565b604051908082528060200260200182016040528015613049578160200160208202803683370190505b5090506000826001600160401b0381111561306657613066614a9a565b60405190808252806020026020018201604052801561308f578160200160208202803683370190505b50905060005b8781101561315a576000600c82815481106130b2576130b26152d3565b90600052602060002090600891828204019190066004029054906101000a900463ffffffff1690506130e3816136a7565b8783815181106130f5576130f56152d3565b602002602001018181525060000361310d575061314a565b61311681613450565b888381518110613128576131286152d3565b60200260200101906001600160a01b031690816001600160a01b031681525050505b613153816152ff565b9050613095565b5060005b83811015613223576000600d828154811061317b5761317b6152d3565b90600052602060002090600891828204019190066004029054906101000a900463ffffffff1690506131ac816136a7565b8383815181106131be576131be6152d3565b60200260200101818152506000036131d65750613213565b6131df81613450565b8483815181106131f1576131f16152d3565b60200260200101906001600160a01b031690816001600160a01b031681525050505b61321c816152ff565b905061315e565b50600954604051637563738b60e11b81526001600160a01b038087169263eac6e7169261325c928b928b9289928992169060040161589b565b602060405180830381865afa158015613279573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061329d91906157fd565b97505050505b50505050919050565b63ffffffff81166000908152600e602052604090205460ff166132ea576040516370abe85960e01b815263ffffffff82166004820152602401610ac8565b6009546001600160a01b03166132ff82613450565b6001600160a01b03161461334e576009546001600160a01b031661332282613450565b60405163298473c760e11b81526001600160a01b03928316600482015291166024820152604401610ac8565b63ffffffff81166000908152600f6020526040902054600160a01b900460ff161561339457604051630a42c0f960e41b815263ffffffff82166004820152602401610ac8565b6010805463ffffffff191663ffffffff92909216919091179055565b60035460009080156133cc576133c78484836140c3565b610db9565b610db96012600960009054906101000a90046001600160a01b03166001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015613424573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906134489190615903565b8691906140e2565b63ffffffff81166000908152600f60205260408082208054915163e170a9bf60e01b81526001600160a01b0390921691829163e170a9bf91613498916001019060040161599d565b602060405180830381865afa1580156134b5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d1591906157e0565b60035460009080156134f0576133c7848285613b9a565b6009546040805163313ce56760e01b81529051610db9926001600160a01b03169163313ce5679160048083019260209291908290030181865afa15801561353b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061355f9190615903565b859060126140e2565b6001600160a01b03811660009081526016602052604090205480156135c357600060155482613597919061576d565b9050428111156117df576040516306f8ee3f60e21b815260048101829052426024820152604401610ac8565b5050565b6001600160a01b03831660009081526005602090815260408083203384529091528120546000198114613623576135fe838261575a565b6001600160a01b03861660009081526005602090815260408083203384529091529020555b6001600160a01b0385166000908152600460205260408120805485929061364b90849061575a565b90915550506001600160a01b0380851660008181526004602052604090819020805487019055519091871690600080516020615ca1833981519152906136949087815260200190565b60405180910390a3506001949350505050565b63ffffffff81166000908152600f602052604080822080549151637841536560e01b81526001600160a01b039092169182916378415365916136ef916001019060040161599d565b602060405180830381865afa15801561370c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d1591906157fd565b815463ffffffff8216811161377d5760405162461bcd60e51b8152602060048201526013602482015272496e646578206f7574206f6620626f756e647360681b6044820152606401610ac8565b63ffffffff82165b61379060018361575a565b81101561383157836137a382600161576d565b815481106137b3576137b36152d3565b90600052602060002090600891828204019190066004029054906101000a900463ffffffff168482815481106137eb576137eb6152d3565b90600052602060002090600891828204019190066004026101000a81548163ffffffff021916908363ffffffff1602179055508080613829906152ff565b915050613785565b5082805480613842576138426159b0565b600082815260209020600860001990920191820401805463ffffffff600460078516026101000a02191690559055505050565b60007f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f60006040516138a791906159c6565b6040805191829003822060208301939093528101919091527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc660608201524660808201523060a082015260c00160405160208183030381529060405280519060200120905090565b63ffffffff83166000908152600e602052604090205460ff161561394e5760405163335894fb60e11b815263ffffffff84166004820152602401610ac8565b60135460145460405163a5b3bddd60e01b815263ffffffff861660048201526001600160801b038083166024830152600160801b90920490911660448201526000918291829161010090046001600160a01b03169063a5b3bddd90606401600060405180830381865afa1580156139c9573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526139f19190810190615a3c565b92509250925083151582151514613a2357604051632b1d0bd360e11b815263ffffffff87166004820152602401610ac8565b604080516080810182526001600160a01b0380861682528415156020808401918252838501868152606085018b905263ffffffff8c166000908152600f9092529490208351815492511515600160a01b026001600160a81b031990931693169290921717815591519091906001820190613a9d9082615424565b5060608201516002820190613ab29082615424565b509050508115613af357600d54601011613ae25760405163f025236d60e01b815260106004820152602401610ac8565b613aee600d8888612bea565b613b25565b600c54601011613b195760405163f025236d60e01b815260106004820152602401610ac8565b613b25600c8888612bea565b63ffffffff86166000908152600e602052604090819020805460ff19166001179055517fc4f8cb57c016f0b294fff2666f86fa6cfee9b03aed19f816ae4bf44b7e837bbb90613b899088908a9063ffffffff92831681529116602082015260400190565b60405180910390a150505050505050565b828202811515841585830485141716613bb257600080fd5b6001826001830304018115150290509392505050565b6060610d158383604051806060016040528060278152602001615c7a6027913961414b565b60035460009080156134f0576133c78482856140c3565b613c0f8383836141c3565b600954613c27906001600160a01b03163330866142be565b613c318183613f38565b60408051848152602081018490526001600160a01b0383169133917fdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d7910160405180910390a36117df838383614348565b600060405163095ea7b360e01b8152836004820152826024820152602060006044836000895af13d15601f3d11600160005114161716915050806121d85760405162461bcd60e51b815260206004820152600e60248201526d1054141493d59157d1905253115160921b6044820152606401610ac8565b60035460009080156133cc576133c7848483613b9a565b33600090815260046020526040812080548391908390613d3190849061575a565b90915550506001600160a01b03831660008181526004602052604090819020805485019055513390600080516020615ca183398151915290610ced9086815260200190565b613d8284848484614379565b336001600160a01b03821614613df0576001600160a01b03811660009081526005602090815260408083203384529091529020546000198114613dee57613dc9848261575a565b6001600160a01b03831660009081526005602090815260408083203384529091529020555b505b613dfa8184613fa7565b60408051858152602081018590526001600160a01b03808416929085169133917ffbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db910160405180910390a46121d88483614382565b6001600160a01b0382166000908152601660205260408120548015613e9557600060155482613e7e919061576d565b905042811115613e9357600092505050610bb7565b505b6000613ea16000612daf565b6001600160a01b03861660009081526004602052604081205491925090613ec890836133b0565b90506000613ed66001612daf565b905080821115613ee65780613ee8565b815b94508515613efd57613efa8584613bed565b94505b5050505092915050565b60035460009082811115613f32576000613f21848361575a565b9050613f2e848383613b9a565b9250505b50919050565b8060036000828254613f4a919061576d565b90915550506001600160a01b038216600081815260046020908152604080832080548601905551848152600080516020615ca183398151915291015b60405180910390a35050565b6000610d158383670de0b6b3a76400006140c3565b6001600160a01b03821660009081526004602052604081208054839290613fcf90849061575a565b90915550506003805482900390556040518181526000906001600160a01b03841690600080516020615ca183398151915290602001613f86565b63ffffffff81166000908152600f6020526040812054600160a01b900460ff161561403657506000919050565b63ffffffff82166000908152600f60205260409081902080549151637d2872e960e11b81526001600160a01b039092169163fa50e5d29161408291600182019160020190600401615a9f565b602060405180830381865afa15801561409f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bb791906157fd565b8282028115158415858304851417166140db57600080fd5b0492915050565b60008160ff168360ff16036140f8575082610d15565b8160ff168360ff16101561412c576141108383615acd565b61411b90600a615bca565b614125908561579f565b9050610d15565b6141368284615acd565b61414190600a615bca565b61412590856157be565b6060600080856001600160a01b0316856040516141689190615bd9565b600060405180830381855af49150503d80600081146141a3576040519150601f19603f3d011682016040523d82523d6000602084013e6141a8565b606091505b50915091506141b98683838761478e565b9695505050505050565b60135460ff16156141e7576040516337a5332d60e11b815260040160405180910390fd5b336001600160a01b0382161461428657601354604051635551e1b560e01b81523360048201526101009091046001600160a01b031690635551e1b590602401602060405180830381865afa158015614243573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906142679190615bf5565b614286576040516334871f2560e21b8152336004820152602401610ac8565b6000614291826113fa565b9050808411156121d857604051632d21eb8760e21b81526004810185905260248101829052604401610ac8565b60006040516323b872dd60e01b81528460048201528360248201528260448201526020600060648360008a5af13d15601f3d11600160005114161716915050806143415760405162461bcd60e51b81526020600482015260146024820152731514905394d1915497d19493d357d1905253115160621b6044820152606401610ac8565b5050505050565b60105461435b9063ffffffff1684614807565b6001600160a01b031660009081526016602052604090204290555050565b6121d881613568565b601354604051635c9fcd8560e11b81526002600482015260009161010090046001600160a01b03169063b93f9b0a90602401602060405180830381865afa1580156143d1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906143f591906157e0565b90506144226040518060800160405280600081526020016000815260200160008152602001600081525090565b600954604051630226614760e01b81526001600160a01b03918216600482015290831690630226614790602401602060405180830381865afa15801561446c573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061449091906157fd565b604080830191909152600954815163313ce56760e01b815291516001600160a01b039091169163313ce5679160048083019260209291908290030181865afa1580156144e0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906145049190615903565b61450f90600a615bca565b6060820152600c5460005b8181101561476b576000600c8281548110614537576145376152d3565b60009182526020822060088204015460079091166004026101000a900463ffffffff16915061456582614009565b90508060000361457657505061475b565b600061458183613450565b604051630226614760e01b81526001600160a01b03808316600483015291925090881690630226614790602401602060405180830381865afa1580156145cb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906145ef91906157fd565b866000018181525050806001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015614636573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061465a9190615903565b61466590600a615bca565b60208701819052865160009182916146909161468987670de0b6b3a764000061579f565b91906140c3565b90506146af88606001518960400151836140c39092919063ffffffff16565b91506146c3670de0b6b3a7640000836157be565b91505060008a8211156147295760006146f389604001518a606001518e670de0b6b3a7640000614689919061579f565b60208a01518a51919250614709918391906140c3565b915061471d670de0b6b3a7640000836157be565b915060009b5050614738565b5082614735828c61575a565b9a505b61474385828c614894565b8a60000361475557505050505061476b565b50505050505b614764816152ff565b905061451a565b5084156143415760405163cc5ea39b60e01b815260048101869052602401610ac8565b606083156147fd5782516000036147f6576001600160a01b0385163b6147f65760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610ac8565b5081610db9565b610db983836148e3565b63ffffffff82166000908152600f602052604090819020805491516001600160a01b03909216916121d8916369445c3160e01b91614852918691600182019160020190602401615c12565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b0319909316929092179091526001600160a01b03831690613bc8565b63ffffffff83166000908152600f602052604090819020805491516001600160a01b03909216916143419163c9111bd760e01b9161485291879187916001810191600290910190602401615c3d565b8151156148f35781518083602001fd5b8060405162461bcd60e51b8152600401610ac891906149a7565b50805461491990615279565b6000825580601f10614929575050565b601f016020900490600052602060002090810190610ba191905b80821115610c8e5760008155600101614943565b60005b8381101561497257818101518382015260200161495a565b50506000910152565b60008151808452614993816020860160208601614957565b601f01601f19169290920160200192915050565b602081526000610d15602083018461497b565b63ffffffff81168114610ba157600080fd5b6000602082840312156149de57600080fd5b8135610d15816149ba565b6000602082840312156149fb57600080fd5b5035919050565b600081518084526020808501945080840160005b83811015614a3b5781516001600160a01b031687529582019590820190600101614a16565b509495945050505050565b602081526000610d156020830184614a02565b6001600160a01b0381168114610ba157600080fd5b60008060408385031215614a8157600080fd5b8235614a8c81614a59565b946020939093013593505050565b634e487b7160e01b600052604160045260246000fd5b604080519081016001600160401b0381118282101715614ad257614ad2614a9a565b60405290565b604051601f8201601f191681016001600160401b0381118282101715614b0057614b00614a9a565b604052919050565b60006001600160401b03821115614b2157614b21614a9a565b50601f01601f191660200190565b600082601f830112614b4057600080fd5b8135614b53614b4e82614b08565b614ad8565b818152846020838601011115614b6857600080fd5b816020850160208301376000918101602001919091529392505050565b60008060008060808587031215614b9b57600080fd5b8435614ba681614a59565b93506020850135614bb681614a59565b92506040850135915060608501356001600160401b03811115614bd857600080fd5b614be487828801614b2f565b91505092959194509250565b600060208284031215614c0257600080fd5b8135610d1581614a59565b600080600060608486031215614c2257600080fd5b8335614c2d81614a59565b92506020840135614c3d81614a59565b929592945050506040919091013590565b8015158114610ba157600080fd5b60008060408385031215614c6f57600080fd5b8235614c7a816149ba565b91506020830135614c8a81614c4e565b809150509250929050565b600080600060608486031215614caa57600080fd5b8335614cb5816149ba565b92506020840135614cc5816149ba565b91506040840135614cd581614c4e565b809150509250925092565b6020808252825182820181905260009190848201906040850190845b81811015614d1e57835163ffffffff1683529284019291840191600101614cfc565b50909695505050505050565b60008083601f840112614d3c57600080fd5b5081356001600160401b03811115614d5357600080fd5b602083019150836020828501011115614d6b57600080fd5b9250929050565b60008060208385031215614d8557600080fd5b82356001600160401b03811115614d9b57600080fd5b614da785828601614d2a565b90969095509350505050565b60006001600160401b03821115614dcc57614dcc614a9a565b5060051b60200190565b600060208284031215614de857600080fd5b6001600160401b038083351115614dfe57600080fd5b8235830184601f820112614e1157600080fd5b614e1e614b4e8235614db3565b81358082526020808301929160051b84010187811115614e3d57600080fd5b602084015b81811015614f3a578581351115614e5857600080fd5b803585016040818b03601f19011215614e7057600080fd5b614e78614ab0565b6020820135614e8681614a59565b8152604082013588811115614e9a57600080fd5b8083019250508a603f830112614eaf57600080fd5b6020820135614ec0614b4e82614db3565b81815260059190911b83016040019060208101908d831115614ee157600080fd5b604085015b83811015614f1a578b81351115614efc57600080fd5b614f0c8f60408335890101614b2f565b835260209283019201614ee6565b508060208501525050508086525050602084019350602081019050614e42565b5090979650505050505050565b60008060408385031215614f5a57600080fd5b823591506020830135614c8a81614a59565b600060208284031215614f7e57600080fd5b81356001600160401b0381168114610d1557600080fd5b6001600160a01b03851681528315156020820152608060408201819052600090614fc19083018561497b565b8281036060840152614fd3818561497b565b979650505050505050565b60008083601f840112614ff057600080fd5b5081356001600160401b0381111561500757600080fd5b6020830191508360208260051b8501011115614d6b57600080fd5b600080600080600080600080600060a08a8c03121561504057600080fd5b89356001600160401b038082111561505757600080fd5b6150638d838e01614fde565b909b50995060208c013591508082111561507c57600080fd5b6150888d838e01614fde565b909950975060408c01359150808211156150a157600080fd5b6150ad8d838e01614fde565b909750955060608c013591506150c282614a59565b90935060808b013590808211156150d857600080fd5b506150e58c828d01614d2a565b915080935050809150509295985092959850929598565b6000806000806080858703121561511257600080fd5b843561511d816149ba565b9350602085013561512d816149ba565b925060408501356001600160401b0381111561514857600080fd5b61515487828801614b2f565b925050606085013561516581614c4e565b939692955090935050565b60008060006060848603121561518557600080fd5b83359250602084013561519781614a59565b91506040840135614cd581614a59565b60ff81168114610ba157600080fd5b600080600080600080600060e0888a0312156151d157600080fd5b87356151dc81614a59565b965060208801356151ec81614a59565b95506040880135945060608801359350608088013561520a816151a7565b9699959850939692959460a0840135945060c09093013592915050565b6000806040838503121561523a57600080fd5b823561524581614a59565b91506020830135614c8a81614a59565b6020808252600a90820152695245454e5452414e435960b01b604082015260600190565b600181811c9082168061528d57607f821691505b602082108103613f3257634e487b7160e01b600052602260045260246000fd5b6020808252600c908201526b15539055551213d49256915160a21b604082015260600190565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b600060018201615311576153116152e9565b5060010190565b60008060008060008060c0878903121561533157600080fd5b863561533c81614a59565b9550602087013561534c81614a59565b9450604087013561535c81614a59565b935060608701356001600160401b038082111561537857600080fd5b6153848a838b01614b2f565b9450608089013591508082111561539a57600080fd5b6153a68a838b01614b2f565b935060a08901359150808211156153bc57600080fd5b506153c989828a01614b2f565b9150509295509295509295565b601f8211156117df57600081815260208120601f850160051c810160208610156153fd5750805b601f850160051c820191505b8181101561541c57828155600101615409565b505050505050565b81516001600160401b0381111561543d5761543d614a9a565b6154518161544b8454615279565b846153d6565b602080601f831160018114615486576000841561546e5750858301515b600019600386901b1c1916600185901b17855561541c565b600085815260208120601f198616915b828110156154b557888601518255948401946001909101908401615496565b50858210156154d35787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b80516154ee816149ba565b919050565b600082601f83011261550457600080fd5b81516020615514614b4e83614db3565b82815260059290921b8401810191818101908684111561553357600080fd5b8286015b8481101561555757805161554a816149ba565b8352918301918301615537565b509695505050505050565b600082601f83011261557357600080fd5b8151615581614b4e82614b08565b81815284602083860101111561559657600080fd5b610db9826020830160208701614957565b600082601f8301126155b857600080fd5b815160206155c8614b4e83614db3565b82815260059290921b840181019181810190868411156155e757600080fd5b8286015b848110156155575780516001600160401b0381111561560a5760008081fd5b6156188986838b0101615562565b8452509183019183016155eb565b80516154ee81614a59565b80516001600160801b03811681146154ee57600080fd5b600080600080600080600080610100898b03121561566557600080fd5b88516001600160401b038082111561567c57600080fd5b6156888c838d016154f3565b995060208b015191508082111561569e57600080fd5b6156aa8c838d016154f3565b985060408b01519150808211156156c057600080fd5b6156cc8c838d016155a7565b975060608b01519150808211156156e257600080fd5b506156ef8b828c016155a7565b9550506156fe60808a016154e3565b935061570c60a08a01615626565b925061571a60c08a01615631565b915061572860e08a01615631565b90509295985092959890939650565b600063ffffffff808316818103615750576157506152e9565b6001019392505050565b81810381811115610bb757610bb76152e9565b80820180821115610bb757610bb76152e9565b600060ff821660ff8103615796576157966152e9565b60010192915050565b60008160001904831182151516156157b9576157b96152e9565b500290565b6000826157db57634e487b7160e01b600052601260045260246000fd5b500490565b6000602082840312156157f257600080fd5b8151610d1581614a59565b60006020828403121561580f57600080fd5b5051919050565b600081615825576158256152e9565b506000190190565b600081518084526020808501945080840160005b83811015614a3b57815187529582019590820190600101615841565b6060815260006158706060830186614a02565b8281036020840152615882818661582d565b91505060018060a01b0383166040830152949350505050565b60a0815260006158ae60a0830188614a02565b82810360208401526158c0818861582d565b905082810360408401526158d48187614a02565b905082810360608401526158e8818661582d565b91505060018060a01b03831660808301529695505050505050565b60006020828403121561591557600080fd5b8151610d15816151a7565b6000815461592d81615279565b80855260206001838116801561594a576001811461596457615992565b60ff1985168884015283151560051b880183019550615992565b866000528260002060005b8581101561598a5781548a820186015290830190840161596f565b890184019650505b505050505092915050565b602081526000610d156020830184615920565b634e487b7160e01b600052603160045260246000fd5b60008083546159d481615279565b600182811680156159ec5760018114615a0157615a30565b60ff1984168752821515830287019450615a30565b8760005260208060002060005b85811015615a275781548a820152908401908201615a0e565b50505082870194505b50929695505050505050565b600080600060608486031215615a5157600080fd5b8351615a5c81614a59565b6020850151909350615a6d81614c4e565b60408501519092506001600160401b03811115615a8957600080fd5b615a9586828701615562565b9150509250925092565b604081526000615ab26040830185615920565b8281036020840152615ac48185615920565b95945050505050565b60ff8281168282160390811115610bb757610bb76152e9565b600181815b80851115615b21578160001904821115615b0757615b076152e9565b80851615615b1457918102915b93841c9390800290615aeb565b509250929050565b600082615b3857506001610bb7565b81615b4557506000610bb7565b8160018114615b5b5760028114615b6557615b81565b6001915050610bb7565b60ff841115615b7657615b766152e9565b50506001821b610bb7565b5060208310610133831016604e8410600b8410161715615ba4575081810a610bb7565b615bae8383615ae6565b8060001904821115615bc257615bc26152e9565b029392505050565b6000610d1560ff841683615b29565b60008251615beb818460208701614957565b9190910192915050565b600060208284031215615c0757600080fd5b8151610d1581614c4e565b838152606060208201526000615c2b6060830185615920565b82810360408401526141b98185615920565b8481526001600160a01b0384166020820152608060408201819052600090615c6790830185615920565b8281036060840152614fd3818561592056fe416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efa26469706673582212204f088424aa06a67b6341902deccd76379dfa7566f446ff2321dd2c1e2e6cf27064736f6c634300081000330000000000000000000000002cbd27e034fee53f79b607430da7771b22050741
Deployed Bytecode
0x608060405234801561001057600080fd5b50600436106104535760003560e01c80637b10399911610241578063b5292a991161013b578063d505accf116100c3578063e753e60011610087578063e753e600146109f7578063eef33eca14610a67578063ef8b30f714610a76578063f2fde38b14610a89578063f7b24e0814610a9c57600080fd5b8063d505accf1461098b578063d905777e1461099e578063dd62ed3e146109b1578063dff90b5b146109dc578063e1b1acb7146109e457600080fd5b8063c63d75b61161010a578063c63d75b614610625578063c6e6f59214610954578063cd82f8b114610967578063ce96cb771461096f578063cf3090121461098257600080fd5b8063b5292a9914610918578063ba0876521461092b578063bf86d6901461093e578063c244245a1461094b57600080fd5b80639c552ca8116101c9578063a9059cbb1161018d578063a9059cbb146108b2578063b0a75d36146108c5578063b2c69eed146108d8578063b3d7f6b9146108f2578063b460af941461090557600080fd5b80639c552ca8146108665780639c5f00c2146108795780639fdb11b614610889578063a03e4bc314610892578063a8144e48146108aa57600080fd5b806393bbeac01161021057806393bbeac0146107ea57806394bf804d1461080d57806395d89b41146108205780639955a9d4146108285780639babf9fd1461083b57600080fd5b80637b1039991461078c5780637ecebe00146107a45780638da5cb5b146107c4578063920f5c84146107d757600080fd5b80633998a681116103525780635a400d25116102da578063709ffa181161029e578063709ffa181461070b57806370a082311461072e57806370af7df61461074e57806371e99dc2146107615780637384504f1461076957600080fd5b80635a400d25146106b95780635e2c576e146106c1578063687c2b50146106c95780636e553f65146106e95780636ff1c02a146106fc57600080fd5b80634c4602da116103215780634c4602da1461064b5780634cdad506146106585780634e84befe1461066b578063530a37141461067e57806359d20b4e1461069157600080fd5b80633998a681146105e95780633e3382ba14610610578063402d267d14610625578063439fab911461063857600080fd5b80630a680e18116103e0578063313ce567116103a4578063313ce5671461057157806333e15be2146105905780633644e515146105a3578063379e0b13146105ab57806338d52e0f146105be57600080fd5b80630a680e181461050e578063150b7a021461051657806318160ddd1461054257806323689f051461054b57806323b872dd1461055e57600080fd5b80630780fd3a116104275780630780fd3a1461049b57806307a2d13a146104b0578063087ed837146104c3578063095ea7b3146104d85780630a28a477146104fb57600080fd5b806251a3b71461045857806301e1d114146104745780630402ab631461047c57806306fdde0314610486575b600080fd5b61046161012c81565b6040519081526020015b60405180910390f35b610461610aa4565b6104616202a30081565b61048e610ae0565b60405161046b91906149a7565b6104ae6104a93660046149cc565b610b6e565b005b6104616104be3660046149e9565b610ba4565b6104cb610bbd565b60405161046b9190614a46565b6104eb6104e6366004614a6e565b610c92565b604051901515815260200161046b565b6104616105093660046149e9565b610cfe565b6104ae610d1c565b610529610524366004614b85565b610db0565b6040516001600160e01b0319909116815260200161046b565b61046160035481565b6104ae610559366004614bf0565b610dc1565b6104eb61056c366004614c0d565b610e95565b60025461057e9060ff1681565b60405160ff909116815260200161046b565b6104ae61059e366004614c5c565b610eab565b610461611084565b6104ae6105b9366004614c95565b61109e565b6009546105d1906001600160a01b031681565b6040516001600160a01b03909116815260200161046b565b6105f86702c68af0bb14000081565b6040516001600160401b03909116815260200161046b565b610618611376565b60405161046b9190614ce0565b610461610633366004614bf0565b6113fa565b6104ae610646366004614d72565b611419565b6019546104eb9060ff1681565b6104616106663660046149e9565b6117e4565b6104ae610679366004614dd6565b6117fb565b6104ae61068c3660046149e9565b611a92565b6106a461069f3660046149e9565b611b3c565b60405163ffffffff909116815260200161046b565b610461600281565b6104ae611b76565b6104616106d7366004614bf0565b60166020526000908152604090205481565b6104616106f7366004614f47565b611bfe565b6105f867016345785d8a000081565b6104eb610719366004614bf0565b60176020526000908152604090205460ff1681565b61046161073c366004614bf0565b60046020526000908152604090205481565b6104ae61075c366004614f6c565b611c78565b610618611d54565b61077c6107773660046149cc565b611db1565b60405161046b9493929190614f95565b6013546105d19061010090046001600160a01b031681565b6104616107b2366004614bf0565b60086020526000908152604090205481565b600a546105d1906001600160a01b031681565b6104eb6107e5366004615022565b611efa565b6104eb6107f83660046149e9565b600e6020526000908152604090205460ff1681565b61046161081b366004614f47565b612103565b61048e612171565b6104ae6108363660046150fc565b61217e565b60145461084e906001600160801b031681565b6040516001600160801b03909116815260200161046b565b6104ae6108743660046149e9565b6121de565b6010546106a49063ffffffff1681565b61046160155481565b6019546105d19061010090046001600160a01b031681565b610461612276565b6104eb6108c0366004614a6e565b6122a4565b6104ae6108d3366004614bf0565b6122b9565b60145461084e90600160801b90046001600160801b031681565b6104616109003660046149e9565b61234c565b610461610913366004615170565b612363565b6104ae610926366004614f6c565b6123be565b610461610939366004615170565b612484565b6013546104eb9060ff1681565b61046160185481565b6104616109623660046149e9565b6124f3565b610461600081565b61046161097d366004614bf0565b612506565b610461600b5481565b6104ae6109993660046151b6565b612535565b6104616109ac366004614bf0565b612779565b6104616109bf366004615227565b600560209081526000928352604080842090915290825290205481565b6104ae6127a8565b6106a46109f23660046149e9565b612b4d565b601154601254610a2e916001600160401b0380821692600160401b8304821692600160801b9004909116906001600160a01b031684565b604080516001600160401b039586168152938516602085015291909316908201526001600160a01b03909116606082015260800161046b565b6105f8670de0b6b3a764000081565b610461610a843660046149e9565b612b5d565b6104ae610a97366004614bf0565b612b74565b610461601081565b6000600b54600114610ad15760405162461bcd60e51b8152600401610ac890615255565b60405180910390fd5b610adb6000612daf565b905090565b60008054610aed90615279565b80601f0160208091040260200160405190810160405280929190818152602001828054610b1990615279565b8015610b665780601f10610b3b57610100808354040283529160200191610b66565b820191906000526020600020905b815481529060010190602001808311610b4957829003601f168201915b505050505081565b600a546001600160a01b03163314610b985760405162461bcd60e51b8152600401610ac8906152ad565b610ba1816132ac565b50565b6000610bb782610bb2610aa4565b6133b0565b92915050565b600c546060906001600160401b03811115610bda57610bda614a9a565b604051908082528060200260200182016040528015610c03578160200160208202803683370190505b50905060005b600c54811015610c8e57610c54600c8281548110610c2957610c296152d3565b90600052602060002090600891828204019190066004029054906101000a900463ffffffff16613450565b828281518110610c6657610c666152d3565b6001600160a01b0390921660209283029190910190910152610c87816152ff565b9050610c09565b5090565b3360008181526005602090815260408083206001600160a01b038716808552925280832085905551919290917f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92590610ced9086815260200190565b60405180910390a350600192915050565b600080610d09610aa4565b9050610d1583826134d9565b9392505050565b60135460ff1615610d40576040516337a5332d60e11b815260040160405180910390fd5b600a546001600160a01b03163314610d6a5760405162461bcd60e51b8152600401610ac8906152ad565b6013805460ff191660019081179091556040519081527fb8527b93c36dabdfe078af41be789ba946a4adcfeafcf9d8de21d51629859e3c906020015b60405180910390a1565b630a85bd0160e11b5b949350505050565b600a546001600160a01b03163314610deb5760405162461bcd60e51b8152600401610ac8906152ad565b60135460145460405163a46089cf60e01b81526001600160a01b0384811660048301526001600160801b038084166024840152600160801b9093049092166044820152610100909204169063a46089cf9060640160006040518083038186803b158015610e5757600080fd5b505afa158015610e6b573d6000803e3d6000fd5b5050506001600160a01b039091166000908152601760205260409020805460ff1916600117905550565b6000610ea084613568565b610db98484846135c7565b600a546001600160a01b03163314610ed55760405162461bcd60e51b8152600401610ac8906152ad565b600081610f2057600c8363ffffffff1681548110610ef557610ef56152d3565b90600052602060002090600891828204019190066004029054906101000a900463ffffffff16610f60565b600d8363ffffffff1681548110610f3957610f396152d3565b90600052602060002090600891828204019190066004029054906101000a900463ffffffff165b60105490915063ffffffff90811690821603610f8f576040516319ded73160e21b815260040160405180910390fd5b6000610f9a826136a7565b90508015610fca57604051631c7b946d60e31b815263ffffffff8316600482015260248101829052604401610ac8565b8215610fe057610fdb600d85613730565b610feb565b610feb600c85613730565b63ffffffff82166000908152600e60209081526040808320805460ff19169055600f909152812080546001600160a81b03191681559061102e600183018261490d565b61103c60028301600061490d565b50506040805163ffffffff8085168252861660208201527fa5cd0099b78b279c04987aa80ffffaf8fc8c8af4e7c7bce2686e8d01e2e1bd51910160405180910390a150505050565b6000600654461461109757610adb613875565b5060075490565b600a546001600160a01b031633146110c85760405162461bcd60e51b8152600401610ac8906152ad565b60008082156111fa57600d8463ffffffff16815481106110ea576110ea6152d3565b90600052602060002090600891828204019190066004029054906101000a900463ffffffff169150600d8563ffffffff168154811061112b5761112b6152d3565b90600052602060002090600891828204019190066004029054906101000a900463ffffffff1690508181600d8763ffffffff168154811061116e5761116e6152d3565b9060005260206000209060089182820401919006600402600d8863ffffffff168154811061119e5761119e6152d3565b90600052602060002090600891828204019190066004028491906101000a81548163ffffffff021916908363ffffffff1602179055508391906101000a81548163ffffffff021916908363ffffffff160217905550505061131f565b600c8463ffffffff1681548110611213576112136152d3565b90600052602060002090600891828204019190066004029054906101000a900463ffffffff169150600c8563ffffffff1681548110611254576112546152d3565b90600052602060002090600891828204019190066004029054906101000a900463ffffffff1690508181600c8763ffffffff1681548110611297576112976152d3565b9060005260206000209060089182820401919006600402600c8863ffffffff16815481106112c7576112c76152d3565b90600052602060002090600891828204019190066004028491906101000a81548163ffffffff021916908363ffffffff1602179055508391906101000a81548163ffffffff021916908363ffffffff16021790555050505b6040805163ffffffff84811682528381166020830152878116828401528616606082015290517fb7c5df04749a3a06a9a7bf1a8142ccf2a4ee6cbf4709489e876a6e4eb3301e8a9181900360800190a15050505050565b6060600d8054806020026020016040519081016040528092919081815260200182805480156113f057602002820191906000526020600020906000905b82829054906101000a900463ffffffff1663ffffffff16815260200190600401906020826003010492830192600103820291508084116113b35790505b5050505050905090565b60135460009060ff161561141057506000919050565b50600019919050565b601954600160b01b900460ff161580801561144157506019546001600160a81b90910460ff16105b806114625750303b1580156114625750601954600160a81b900460ff166001145b6114c55760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201526d191e481a5b9a5d1a585b1a5e995960921b6064820152608401610ac8565b6019805460ff60a81b1916600160a81b17905580156114f2576019805460ff60b01b1916600160b01b1790555b60008080808080611505888a018a615318565b601380546001600160a01b0380881661010002610100600160a81b031992831617909255600980548388166001600160a01b031991821617909155600a8054938a1693909116929092179091556202a300601555660aa87bee53800060185560198054747d2768de32b0b80b7a3454c06bdac94a69ddc7a9009216919091179055949a5092985090965094509250905060006115a18482615424565b5060016115ae8382615424565b506002805460ff19166012179055466006556115c8613875565b6007819055506001600b81905550600080600080600080600080888060200190518101906115f69190615648565b9750975097509750975097509750975060005b88518163ffffffff16101561167557611663818a8363ffffffff1681518110611634576116346152d3565b6020026020010151898463ffffffff1681518110611654576116546152d3565b6020026020010151600061390f565b8061166d81615737565b915050611609565b5060005b87518163ffffffff1610156116e5576116d381898363ffffffff16815181106116a4576116a46152d3565b6020026020010151888463ffffffff16815181106116c4576116c46152d3565b6020026020010151600161390f565b806116dd81615737565b915050611679565b506116ef846132ac565b6001600160801b03908116600160801b908102919092161760145560408051608081018252670b1a2bc2ec50000081526611c37937e080006020820152426001600160401b03169181018290526001600160a01b03909316606090930183905260118054919092026001600160c01b0319909116176e11c37937e080000b1a2bc2ec500000179055601280546001600160a01b03191690911790555050891598506117df975050505050505050576019805460ff60b01b19169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b505050565b6000806117ef610aa4565b9050610d1583826133b0565b600a546001600160a01b031633146118255760405162461bcd60e51b8152600401610ac8906152ad565b60135460ff1615611849576040516337a5332d60e11b815260040160405180910390fd5b600b5460011461186b5760405162461bcd60e51b8152600401610ac890615255565b6002600b556019805460ff19166001179055600080808061188b81612daf565b90506118b6601854670de0b6b3a76400006118a6919061575a565b8290670de0b6b3a7640000613b9a565b93506118d1601854670de0b6b3a76400006118a6919061576d565b925060035491505060005b84518160ff161015611a01576000858260ff16815181106118ff576118ff6152d3565b602090810291909101810151516001600160a01b0381166000908152601790925260409091205490915060ff16611954576040516352873a5160e11b81526001600160a01b0382166004820152602401610ac8565b60005b868360ff168151811061196c5761196c6152d3565b602002602001015160200151518160ff1610156119ee576119db878460ff168151811061199b5761199b6152d3565b6020026020010151602001518260ff16815181106119bb576119bb6152d3565b6020026020010151836001600160a01b0316613bc890919063ffffffff16565b50806119e681615780565b915050611957565b5050806119fa90615780565b90506118dc565b506000611a0e6000612daf565b905083811080611a1d57508281115b15611a4c5760405163628cc47560e11b8152600481018290526024810185905260448101849052606401610ac8565b6003548214611a7c57600354604051632b40145960e21b8152600481019190915260248101839052604401610ac8565b50506019805460ff1916905550506001600b5550565b600a546001600160a01b03163314611abc5760405162461bcd60e51b8152600401610ac8906152ad565b67016345785d8a0000811115611af6576040516302d2a90f60e51b81526004810182905267016345785d8a00006024820152604401610ac8565b601880549082905560408051828152602081018490527fdf4be33b2e9e3dd4d9e0e85645aea428494a0644a72c51d6a15aedae6b66a3ff91015b60405180910390a15050565b600c8181548110611b4c57600080fd5b9060005260206000209060089182820401919006600402915054906101000a900463ffffffff1681565b600a546001600160a01b03163314611ba05760405162461bcd60e51b8152600401610ac8906152ad565b60135460ff16611bc35760405163ec7165bf60e01b815260040160405180910390fd5b6013805460ff19169055604051600081527fb8527b93c36dabdfe078af41be789ba946a4adcfeafcf9d8de21d51629859e3c90602001610da6565b6000600b54600114611c225760405162461bcd60e51b8152600401610ac890615255565b6002600b556000611c3281612daf565b9050611c3e8482613bed565b915081600003611c615760405163426f153760e11b815260040160405180910390fd5b611c6c848385613c04565b506001600b5592915050565b600a546001600160a01b03163314611ca25760405162461bcd60e51b8152600401610ac8906152ad565b6702c68af0bb1400006001600160401b0382161115611cd457604051632e15286d60e11b815260040160405180910390fd5b60115460408051600160401b9092046001600160401b039081168352831660208301527f44ada261ff5c9aacbf8d0687294799c8e3e0810ecc1eafd97419dfc31db5d523910160405180910390a1601180546001600160401b03909216600160401b026fffffffffffffffff000000000000000019909216919091179055565b6060600c8054806020026020016040519081016040528092919081815260200182805480156113f0576000918252602091829020805463ffffffff1684529082028301929091600491018084116113b35790505050505050905090565b600f60205260009081526040902080546001820180546001600160a01b03831693600160a01b90930460ff16929190611de990615279565b80601f0160208091040260200160405190810160405280929190818152602001828054611e1590615279565b8015611e625780601f10611e3757610100808354040283529160200191611e62565b820191906000526020600020905b815481529060010190602001808311611e4557829003601f168201915b505050505090806002018054611e7790615279565b80601f0160208091040260200160405190810160405280929190818152602001828054611ea390615279565b8015611ef05780601f10611ec557610100808354040283529160200191611ef0565b820191906000526020600020905b815481529060010190602001808311611ed357829003601f168201915b5050505050905084565b60006001600160a01b0384163014611f25576040516304a246dd60e51b815260040160405180910390fd5b60195461010090046001600160a01b03163314611f55576040516349456ad960e01b815260040160405180910390fd5b6000611f6383850185614dd6565b905060005b81518160ff16101561204d576000828260ff1681518110611f8b57611f8b6152d3565b602090810291909101810151516001600160a01b0381166000908152601790925260409091205490915060ff16611fe0576040516352873a5160e11b81526001600160a01b0382166004820152602401610ac8565b60005b838360ff1681518110611ff857611ff86152d3565b602002602001015160200151518160ff16101561203a57612027848460ff168151811061199b5761199b6152d3565b508061203281615780565b915050611fe3565b50508061204690615780565b9050611f68565b5060005b888110156120f1576019546120e19061010090046001600160a01b0316898984818110612080576120806152d3565b905060200201358c8c85818110612099576120996152d3565b905060200201356120aa919061576d565b8e8e858181106120bc576120bc6152d3565b90506020020160208101906120d19190614bf0565b6001600160a01b03169190613c82565b6120ea816152ff565b9050612051565b5060019b9a5050505050505050505050565b6000600b546001146121275760405162461bcd60e51b8152600401610ac890615255565b6002600b55600061213781612daf565b90506121438482613cf9565b91508160000361216657604051639768300560e01b815260040160405180910390fd5b611c6c828585613c04565b60018054610aed90615279565b600a546001600160a01b031633146121a85760405162461bcd60e51b8152600401610ac8906152ad565b60135460ff16156121cc576040516337a5332d60e11b815260040160405180910390fd5b6121d88484848461390f565b50505050565b600a546001600160a01b031633146122085760405162461bcd60e51b8152600401610ac8906152ad565b61012c81108061221a57506202a30081115b1561223857604051633a60233f60e21b815260040160405180910390fd5b601580549082905560408051828152602081018490527f227ff5c6b5ffb395236b09fd1b472bb128b36eaa17556633feefe28e94411f249101611b30565b6000600b5460011461229a5760405162461bcd60e51b8152600401610ac890615255565b610adb6001612daf565b60006122af33613568565b610d158383613d10565b600a546001600160a01b031633146122e35760405162461bcd60e51b8152600401610ac8906152ad565b601254604080516001600160a01b03928316815291831660208301527f51dbb5a65bb22737861a63ec12ba6ce78a98631e9404b0567a2eaf7a06fc544d910160405180910390a1601280546001600160a01b0319166001600160a01b0392909216919091179055565b600080612357610aa4565b9050610d158382613cf9565b6000600b546001146123875760405162461bcd60e51b8152600401610ac890615255565b6002600b55600061239781612daf565b90506123a385826134d9565b91506123b185838686613d76565b506001600b559392505050565b600a546001600160a01b031633146123e85760405162461bcd60e51b8152600401610ac8906152ad565b670de0b6b3a76400006001600160401b038216111561241a57604051633d0203e560e01b815260040160405180910390fd5b601154604080516001600160401b03928316815291831660208301527fb5cc994a260a85a42d6588668221571ae0a14f0a28f9e4817a5195262102c868910160405180910390a16011805467ffffffffffffffff19166001600160401b0392909216919091179055565b6000600b546001146124a85760405162461bcd60e51b8152600401610ac890615255565b6002600b5560006124b881612daf565b90506124c485826133b0565b9150816000036124e757604051639768300560e01b815260040160405180910390fd5b6123b182868686613d76565b6000610bb782612501610aa4565b613bed565b6000600b5460011461252a5760405162461bcd60e51b8152600401610ac890615255565b610bb7826000613e4f565b428410156125855760405162461bcd60e51b815260206004820152601760248201527f5045524d49545f444541444c494e455f455850495245440000000000000000006044820152606401610ac8565b60006001612591611084565b6001600160a01b038a811660008181526008602090815260409182902080546001810190915582517f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c98184015280840194909452938d166060840152608083018c905260a083019390935260c08083018b90528151808403909101815260e08301909152805192019190912061190160f01b6101008301526101028201929092526101228101919091526101420160408051601f198184030181528282528051602091820120600084529083018083525260ff871690820152606081018590526080810184905260a0016020604051602081039080840390855afa15801561269d573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b038116158015906126d35750876001600160a01b0316816001600160a01b0316145b6127105760405162461bcd60e51b815260206004820152600e60248201526d24a72b20a624a22fa9a4a3a722a960911b6044820152606401610ac8565b6001600160a01b0390811660009081526005602090815260408083208a8516808552908352928190208990555188815291928a16917f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a350505050505050565b6000600b5460011461279d5760405162461bcd60e51b8152600401610ac890615255565b610bb7826001613e4f565b600b546001146127ca5760405162461bcd60e51b8152600401610ac890615255565b6002600b556012546001600160a01b0316806127f95760405163dc13611360e01b815260040160405180910390fd5b60006128056000612daf565b60115490915060009061282890600160801b90046001600160401b03164261575a565b6011549091506000906301e1338090670de0b6b3a764000090600160401b90046001600160401b031661285b858761579f565b612865919061579f565b61286f91906157be565b61287991906157be565b9050600061288f61288a8386613bed565b613f07565b905061289b3082613f38565b6011546000906128b59083906001600160401b0316613f92565b905080156129365730600090815260046020526040812080548392906128dc90849061575a565b90915550506001600160a01b03861660008181526004602052604090819020805484019055513090600080516020615ca1833981519152906129219085815260200190565b60405180910390a3612933818361575a565b91505b6011805467ffffffffffffffff60801b19164263ffffffff16600160801b02179055600061296483876133b0565b90508015612b06576129763084613fa7565b601354604051635c9fcd8560e11b81526000600482018190529161010090046001600160a01b03169063b93f9b0a90602401602060405180830381865afa1580156129c5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129e991906157e0565b600954909150612a03906001600160a01b03168284613c82565b806001600160a01b0316631ffbe7f9600960009054906101000a90046001600160a01b0316601360019054906101000a90046001600160a01b03166001600160a01b0316638e0bae7f6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612a7b573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612a9f91906157fd565b6040516001600160e01b031960e085901b1681526001600160a01b039092166004830152602482015260448101859052606401600060405180830381600087803b158015612aec57600080fd5b505af1158015612b00573d6000803e3d6000fd5b50505050505b60408051848152602081018390527f15e3e2a76a6839c244c1ed0a821c233ce8af552dffcb856089eae6cbbbb71ea6910160405180910390a150506001600b555050505050565b600d8181548110611b4c57600080fd5b600080612b68610aa4565b9050610d158382613bed565b600a546001600160a01b03163314612b9e5760405162461bcd60e51b8152600401610ac8906152ad565b600a80546001600160a01b0319166001600160a01b03831690811790915560405133907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a350565b82548015612d6e578380612bff60018461575a565b81548110612c0f57612c0f6152d3565b60009182526020808320600880840490910154855460018082018855968652928520918304909101805463ffffffff60046007958616810261010090810a83810219909416969097160290950a9092049093160217905590612c71908361575a565b90505b8363ffffffff16811115612d1c5784612c8e60018361575a565b81548110612c9e57612c9e6152d3565b90600052602060002090600891828204019190066004029054906101000a900463ffffffff16858281548110612cd657612cd66152d3565b90600052602060002090600891828204019190066004026101000a81548163ffffffff021916908363ffffffff1602179055508080612d1490615816565b915050612c74565b5081848463ffffffff1681548110612d3657612d366152d3565b90600052602060002090600891828204019190066004026101000a81548163ffffffff021916908363ffffffff1602179055506121d8565b508254600181018455600093845260209093206008840401805460079094166004026101000a63ffffffff8181021990951692909416939093021790915550565b600c5460009081816001600160401b03811115612dce57612dce614a9a565b604051908082528060200260200182016040528015612df7578160200160208202803683370190505b5090506000826001600160401b03811115612e1457612e14614a9a565b604051908082528060200260200182016040528015612e3d578160200160208202803683370190505b50601354604051635c9fcd8560e11b8152600260048201529192506000916101009091046001600160a01b03169063b93f9b0a90602401602060405180830381865afa158015612e91573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612eb591906157e0565b905085156130035760005b84811015612f85576000600c8281548110612edd57612edd6152d3565b90600052602060002090600891828204019190066004029054906101000a900463ffffffff169050612f0e81614009565b848381518110612f2057612f206152d3565b6020026020010181815250600003612f385750612f75565b612f4181613450565b858381518110612f5357612f536152d3565b60200260200101906001600160a01b031690816001600160a01b031681525050505b612f7e816152ff565b9050612ec0565b5060095460405163b333a17560e01b81526001600160a01b038084169263b333a17592612fbb928892889291169060040161585d565b602060405180830381865afa158015612fd8573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612ffc91906157fd565b94506132a3565b600d546000816001600160401b0381111561302057613020614a9a565b604051908082528060200260200182016040528015613049578160200160208202803683370190505b5090506000826001600160401b0381111561306657613066614a9a565b60405190808252806020026020018201604052801561308f578160200160208202803683370190505b50905060005b8781101561315a576000600c82815481106130b2576130b26152d3565b90600052602060002090600891828204019190066004029054906101000a900463ffffffff1690506130e3816136a7565b8783815181106130f5576130f56152d3565b602002602001018181525060000361310d575061314a565b61311681613450565b888381518110613128576131286152d3565b60200260200101906001600160a01b031690816001600160a01b031681525050505b613153816152ff565b9050613095565b5060005b83811015613223576000600d828154811061317b5761317b6152d3565b90600052602060002090600891828204019190066004029054906101000a900463ffffffff1690506131ac816136a7565b8383815181106131be576131be6152d3565b60200260200101818152506000036131d65750613213565b6131df81613450565b8483815181106131f1576131f16152d3565b60200260200101906001600160a01b031690816001600160a01b031681525050505b61321c816152ff565b905061315e565b50600954604051637563738b60e11b81526001600160a01b038087169263eac6e7169261325c928b928b9289928992169060040161589b565b602060405180830381865afa158015613279573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061329d91906157fd565b97505050505b50505050919050565b63ffffffff81166000908152600e602052604090205460ff166132ea576040516370abe85960e01b815263ffffffff82166004820152602401610ac8565b6009546001600160a01b03166132ff82613450565b6001600160a01b03161461334e576009546001600160a01b031661332282613450565b60405163298473c760e11b81526001600160a01b03928316600482015291166024820152604401610ac8565b63ffffffff81166000908152600f6020526040902054600160a01b900460ff161561339457604051630a42c0f960e41b815263ffffffff82166004820152602401610ac8565b6010805463ffffffff191663ffffffff92909216919091179055565b60035460009080156133cc576133c78484836140c3565b610db9565b610db96012600960009054906101000a90046001600160a01b03166001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015613424573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906134489190615903565b8691906140e2565b63ffffffff81166000908152600f60205260408082208054915163e170a9bf60e01b81526001600160a01b0390921691829163e170a9bf91613498916001019060040161599d565b602060405180830381865afa1580156134b5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d1591906157e0565b60035460009080156134f0576133c7848285613b9a565b6009546040805163313ce56760e01b81529051610db9926001600160a01b03169163313ce5679160048083019260209291908290030181865afa15801561353b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061355f9190615903565b859060126140e2565b6001600160a01b03811660009081526016602052604090205480156135c357600060155482613597919061576d565b9050428111156117df576040516306f8ee3f60e21b815260048101829052426024820152604401610ac8565b5050565b6001600160a01b03831660009081526005602090815260408083203384529091528120546000198114613623576135fe838261575a565b6001600160a01b03861660009081526005602090815260408083203384529091529020555b6001600160a01b0385166000908152600460205260408120805485929061364b90849061575a565b90915550506001600160a01b0380851660008181526004602052604090819020805487019055519091871690600080516020615ca1833981519152906136949087815260200190565b60405180910390a3506001949350505050565b63ffffffff81166000908152600f602052604080822080549151637841536560e01b81526001600160a01b039092169182916378415365916136ef916001019060040161599d565b602060405180830381865afa15801561370c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d1591906157fd565b815463ffffffff8216811161377d5760405162461bcd60e51b8152602060048201526013602482015272496e646578206f7574206f6620626f756e647360681b6044820152606401610ac8565b63ffffffff82165b61379060018361575a565b81101561383157836137a382600161576d565b815481106137b3576137b36152d3565b90600052602060002090600891828204019190066004029054906101000a900463ffffffff168482815481106137eb576137eb6152d3565b90600052602060002090600891828204019190066004026101000a81548163ffffffff021916908363ffffffff1602179055508080613829906152ff565b915050613785565b5082805480613842576138426159b0565b600082815260209020600860001990920191820401805463ffffffff600460078516026101000a02191690559055505050565b60007f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f60006040516138a791906159c6565b6040805191829003822060208301939093528101919091527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc660608201524660808201523060a082015260c00160405160208183030381529060405280519060200120905090565b63ffffffff83166000908152600e602052604090205460ff161561394e5760405163335894fb60e11b815263ffffffff84166004820152602401610ac8565b60135460145460405163a5b3bddd60e01b815263ffffffff861660048201526001600160801b038083166024830152600160801b90920490911660448201526000918291829161010090046001600160a01b03169063a5b3bddd90606401600060405180830381865afa1580156139c9573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526139f19190810190615a3c565b92509250925083151582151514613a2357604051632b1d0bd360e11b815263ffffffff87166004820152602401610ac8565b604080516080810182526001600160a01b0380861682528415156020808401918252838501868152606085018b905263ffffffff8c166000908152600f9092529490208351815492511515600160a01b026001600160a81b031990931693169290921717815591519091906001820190613a9d9082615424565b5060608201516002820190613ab29082615424565b509050508115613af357600d54601011613ae25760405163f025236d60e01b815260106004820152602401610ac8565b613aee600d8888612bea565b613b25565b600c54601011613b195760405163f025236d60e01b815260106004820152602401610ac8565b613b25600c8888612bea565b63ffffffff86166000908152600e602052604090819020805460ff19166001179055517fc4f8cb57c016f0b294fff2666f86fa6cfee9b03aed19f816ae4bf44b7e837bbb90613b899088908a9063ffffffff92831681529116602082015260400190565b60405180910390a150505050505050565b828202811515841585830485141716613bb257600080fd5b6001826001830304018115150290509392505050565b6060610d158383604051806060016040528060278152602001615c7a6027913961414b565b60035460009080156134f0576133c78482856140c3565b613c0f8383836141c3565b600954613c27906001600160a01b03163330866142be565b613c318183613f38565b60408051848152602081018490526001600160a01b0383169133917fdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d7910160405180910390a36117df838383614348565b600060405163095ea7b360e01b8152836004820152826024820152602060006044836000895af13d15601f3d11600160005114161716915050806121d85760405162461bcd60e51b815260206004820152600e60248201526d1054141493d59157d1905253115160921b6044820152606401610ac8565b60035460009080156133cc576133c7848483613b9a565b33600090815260046020526040812080548391908390613d3190849061575a565b90915550506001600160a01b03831660008181526004602052604090819020805485019055513390600080516020615ca183398151915290610ced9086815260200190565b613d8284848484614379565b336001600160a01b03821614613df0576001600160a01b03811660009081526005602090815260408083203384529091529020546000198114613dee57613dc9848261575a565b6001600160a01b03831660009081526005602090815260408083203384529091529020555b505b613dfa8184613fa7565b60408051858152602081018590526001600160a01b03808416929085169133917ffbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db910160405180910390a46121d88483614382565b6001600160a01b0382166000908152601660205260408120548015613e9557600060155482613e7e919061576d565b905042811115613e9357600092505050610bb7565b505b6000613ea16000612daf565b6001600160a01b03861660009081526004602052604081205491925090613ec890836133b0565b90506000613ed66001612daf565b905080821115613ee65780613ee8565b815b94508515613efd57613efa8584613bed565b94505b5050505092915050565b60035460009082811115613f32576000613f21848361575a565b9050613f2e848383613b9a565b9250505b50919050565b8060036000828254613f4a919061576d565b90915550506001600160a01b038216600081815260046020908152604080832080548601905551848152600080516020615ca183398151915291015b60405180910390a35050565b6000610d158383670de0b6b3a76400006140c3565b6001600160a01b03821660009081526004602052604081208054839290613fcf90849061575a565b90915550506003805482900390556040518181526000906001600160a01b03841690600080516020615ca183398151915290602001613f86565b63ffffffff81166000908152600f6020526040812054600160a01b900460ff161561403657506000919050565b63ffffffff82166000908152600f60205260409081902080549151637d2872e960e11b81526001600160a01b039092169163fa50e5d29161408291600182019160020190600401615a9f565b602060405180830381865afa15801561409f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610bb791906157fd565b8282028115158415858304851417166140db57600080fd5b0492915050565b60008160ff168360ff16036140f8575082610d15565b8160ff168360ff16101561412c576141108383615acd565b61411b90600a615bca565b614125908561579f565b9050610d15565b6141368284615acd565b61414190600a615bca565b61412590856157be565b6060600080856001600160a01b0316856040516141689190615bd9565b600060405180830381855af49150503d80600081146141a3576040519150601f19603f3d011682016040523d82523d6000602084013e6141a8565b606091505b50915091506141b98683838761478e565b9695505050505050565b60135460ff16156141e7576040516337a5332d60e11b815260040160405180910390fd5b336001600160a01b0382161461428657601354604051635551e1b560e01b81523360048201526101009091046001600160a01b031690635551e1b590602401602060405180830381865afa158015614243573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906142679190615bf5565b614286576040516334871f2560e21b8152336004820152602401610ac8565b6000614291826113fa565b9050808411156121d857604051632d21eb8760e21b81526004810185905260248101829052604401610ac8565b60006040516323b872dd60e01b81528460048201528360248201528260448201526020600060648360008a5af13d15601f3d11600160005114161716915050806143415760405162461bcd60e51b81526020600482015260146024820152731514905394d1915497d19493d357d1905253115160621b6044820152606401610ac8565b5050505050565b60105461435b9063ffffffff1684614807565b6001600160a01b031660009081526016602052604090204290555050565b6121d881613568565b601354604051635c9fcd8560e11b81526002600482015260009161010090046001600160a01b03169063b93f9b0a90602401602060405180830381865afa1580156143d1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906143f591906157e0565b90506144226040518060800160405280600081526020016000815260200160008152602001600081525090565b600954604051630226614760e01b81526001600160a01b03918216600482015290831690630226614790602401602060405180830381865afa15801561446c573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061449091906157fd565b604080830191909152600954815163313ce56760e01b815291516001600160a01b039091169163313ce5679160048083019260209291908290030181865afa1580156144e0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906145049190615903565b61450f90600a615bca565b6060820152600c5460005b8181101561476b576000600c8281548110614537576145376152d3565b60009182526020822060088204015460079091166004026101000a900463ffffffff16915061456582614009565b90508060000361457657505061475b565b600061458183613450565b604051630226614760e01b81526001600160a01b03808316600483015291925090881690630226614790602401602060405180830381865afa1580156145cb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906145ef91906157fd565b866000018181525050806001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa158015614636573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061465a9190615903565b61466590600a615bca565b60208701819052865160009182916146909161468987670de0b6b3a764000061579f565b91906140c3565b90506146af88606001518960400151836140c39092919063ffffffff16565b91506146c3670de0b6b3a7640000836157be565b91505060008a8211156147295760006146f389604001518a606001518e670de0b6b3a7640000614689919061579f565b60208a01518a51919250614709918391906140c3565b915061471d670de0b6b3a7640000836157be565b915060009b5050614738565b5082614735828c61575a565b9a505b61474385828c614894565b8a60000361475557505050505061476b565b50505050505b614764816152ff565b905061451a565b5084156143415760405163cc5ea39b60e01b815260048101869052602401610ac8565b606083156147fd5782516000036147f6576001600160a01b0385163b6147f65760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610ac8565b5081610db9565b610db983836148e3565b63ffffffff82166000908152600f602052604090819020805491516001600160a01b03909216916121d8916369445c3160e01b91614852918691600182019160020190602401615c12565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b0319909316929092179091526001600160a01b03831690613bc8565b63ffffffff83166000908152600f602052604090819020805491516001600160a01b03909216916143419163c9111bd760e01b9161485291879187916001810191600290910190602401615c3d565b8151156148f35781518083602001fd5b8060405162461bcd60e51b8152600401610ac891906149a7565b50805461491990615279565b6000825580601f10614929575050565b601f016020900490600052602060002090810190610ba191905b80821115610c8e5760008155600101614943565b60005b8381101561497257818101518382015260200161495a565b50506000910152565b60008151808452614993816020860160208601614957565b601f01601f19169290920160200192915050565b602081526000610d15602083018461497b565b63ffffffff81168114610ba157600080fd5b6000602082840312156149de57600080fd5b8135610d15816149ba565b6000602082840312156149fb57600080fd5b5035919050565b600081518084526020808501945080840160005b83811015614a3b5781516001600160a01b031687529582019590820190600101614a16565b509495945050505050565b602081526000610d156020830184614a02565b6001600160a01b0381168114610ba157600080fd5b60008060408385031215614a8157600080fd5b8235614a8c81614a59565b946020939093013593505050565b634e487b7160e01b600052604160045260246000fd5b604080519081016001600160401b0381118282101715614ad257614ad2614a9a565b60405290565b604051601f8201601f191681016001600160401b0381118282101715614b0057614b00614a9a565b604052919050565b60006001600160401b03821115614b2157614b21614a9a565b50601f01601f191660200190565b600082601f830112614b4057600080fd5b8135614b53614b4e82614b08565b614ad8565b818152846020838601011115614b6857600080fd5b816020850160208301376000918101602001919091529392505050565b60008060008060808587031215614b9b57600080fd5b8435614ba681614a59565b93506020850135614bb681614a59565b92506040850135915060608501356001600160401b03811115614bd857600080fd5b614be487828801614b2f565b91505092959194509250565b600060208284031215614c0257600080fd5b8135610d1581614a59565b600080600060608486031215614c2257600080fd5b8335614c2d81614a59565b92506020840135614c3d81614a59565b929592945050506040919091013590565b8015158114610ba157600080fd5b60008060408385031215614c6f57600080fd5b8235614c7a816149ba565b91506020830135614c8a81614c4e565b809150509250929050565b600080600060608486031215614caa57600080fd5b8335614cb5816149ba565b92506020840135614cc5816149ba565b91506040840135614cd581614c4e565b809150509250925092565b6020808252825182820181905260009190848201906040850190845b81811015614d1e57835163ffffffff1683529284019291840191600101614cfc565b50909695505050505050565b60008083601f840112614d3c57600080fd5b5081356001600160401b03811115614d5357600080fd5b602083019150836020828501011115614d6b57600080fd5b9250929050565b60008060208385031215614d8557600080fd5b82356001600160401b03811115614d9b57600080fd5b614da785828601614d2a565b90969095509350505050565b60006001600160401b03821115614dcc57614dcc614a9a565b5060051b60200190565b600060208284031215614de857600080fd5b6001600160401b038083351115614dfe57600080fd5b8235830184601f820112614e1157600080fd5b614e1e614b4e8235614db3565b81358082526020808301929160051b84010187811115614e3d57600080fd5b602084015b81811015614f3a578581351115614e5857600080fd5b803585016040818b03601f19011215614e7057600080fd5b614e78614ab0565b6020820135614e8681614a59565b8152604082013588811115614e9a57600080fd5b8083019250508a603f830112614eaf57600080fd5b6020820135614ec0614b4e82614db3565b81815260059190911b83016040019060208101908d831115614ee157600080fd5b604085015b83811015614f1a578b81351115614efc57600080fd5b614f0c8f60408335890101614b2f565b835260209283019201614ee6565b508060208501525050508086525050602084019350602081019050614e42565b5090979650505050505050565b60008060408385031215614f5a57600080fd5b823591506020830135614c8a81614a59565b600060208284031215614f7e57600080fd5b81356001600160401b0381168114610d1557600080fd5b6001600160a01b03851681528315156020820152608060408201819052600090614fc19083018561497b565b8281036060840152614fd3818561497b565b979650505050505050565b60008083601f840112614ff057600080fd5b5081356001600160401b0381111561500757600080fd5b6020830191508360208260051b8501011115614d6b57600080fd5b600080600080600080600080600060a08a8c03121561504057600080fd5b89356001600160401b038082111561505757600080fd5b6150638d838e01614fde565b909b50995060208c013591508082111561507c57600080fd5b6150888d838e01614fde565b909950975060408c01359150808211156150a157600080fd5b6150ad8d838e01614fde565b909750955060608c013591506150c282614a59565b90935060808b013590808211156150d857600080fd5b506150e58c828d01614d2a565b915080935050809150509295985092959850929598565b6000806000806080858703121561511257600080fd5b843561511d816149ba565b9350602085013561512d816149ba565b925060408501356001600160401b0381111561514857600080fd5b61515487828801614b2f565b925050606085013561516581614c4e565b939692955090935050565b60008060006060848603121561518557600080fd5b83359250602084013561519781614a59565b91506040840135614cd581614a59565b60ff81168114610ba157600080fd5b600080600080600080600060e0888a0312156151d157600080fd5b87356151dc81614a59565b965060208801356151ec81614a59565b95506040880135945060608801359350608088013561520a816151a7565b9699959850939692959460a0840135945060c09093013592915050565b6000806040838503121561523a57600080fd5b823561524581614a59565b91506020830135614c8a81614a59565b6020808252600a90820152695245454e5452414e435960b01b604082015260600190565b600181811c9082168061528d57607f821691505b602082108103613f3257634e487b7160e01b600052602260045260246000fd5b6020808252600c908201526b15539055551213d49256915160a21b604082015260600190565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b600060018201615311576153116152e9565b5060010190565b60008060008060008060c0878903121561533157600080fd5b863561533c81614a59565b9550602087013561534c81614a59565b9450604087013561535c81614a59565b935060608701356001600160401b038082111561537857600080fd5b6153848a838b01614b2f565b9450608089013591508082111561539a57600080fd5b6153a68a838b01614b2f565b935060a08901359150808211156153bc57600080fd5b506153c989828a01614b2f565b9150509295509295509295565b601f8211156117df57600081815260208120601f850160051c810160208610156153fd5750805b601f850160051c820191505b8181101561541c57828155600101615409565b505050505050565b81516001600160401b0381111561543d5761543d614a9a565b6154518161544b8454615279565b846153d6565b602080601f831160018114615486576000841561546e5750858301515b600019600386901b1c1916600185901b17855561541c565b600085815260208120601f198616915b828110156154b557888601518255948401946001909101908401615496565b50858210156154d35787850151600019600388901b60f8161c191681555b5050505050600190811b01905550565b80516154ee816149ba565b919050565b600082601f83011261550457600080fd5b81516020615514614b4e83614db3565b82815260059290921b8401810191818101908684111561553357600080fd5b8286015b8481101561555757805161554a816149ba565b8352918301918301615537565b509695505050505050565b600082601f83011261557357600080fd5b8151615581614b4e82614b08565b81815284602083860101111561559657600080fd5b610db9826020830160208701614957565b600082601f8301126155b857600080fd5b815160206155c8614b4e83614db3565b82815260059290921b840181019181810190868411156155e757600080fd5b8286015b848110156155575780516001600160401b0381111561560a5760008081fd5b6156188986838b0101615562565b8452509183019183016155eb565b80516154ee81614a59565b80516001600160801b03811681146154ee57600080fd5b600080600080600080600080610100898b03121561566557600080fd5b88516001600160401b038082111561567c57600080fd5b6156888c838d016154f3565b995060208b015191508082111561569e57600080fd5b6156aa8c838d016154f3565b985060408b01519150808211156156c057600080fd5b6156cc8c838d016155a7565b975060608b01519150808211156156e257600080fd5b506156ef8b828c016155a7565b9550506156fe60808a016154e3565b935061570c60a08a01615626565b925061571a60c08a01615631565b915061572860e08a01615631565b90509295985092959890939650565b600063ffffffff808316818103615750576157506152e9565b6001019392505050565b81810381811115610bb757610bb76152e9565b80820180821115610bb757610bb76152e9565b600060ff821660ff8103615796576157966152e9565b60010192915050565b60008160001904831182151516156157b9576157b96152e9565b500290565b6000826157db57634e487b7160e01b600052601260045260246000fd5b500490565b6000602082840312156157f257600080fd5b8151610d1581614a59565b60006020828403121561580f57600080fd5b5051919050565b600081615825576158256152e9565b506000190190565b600081518084526020808501945080840160005b83811015614a3b57815187529582019590820190600101615841565b6060815260006158706060830186614a02565b8281036020840152615882818661582d565b91505060018060a01b0383166040830152949350505050565b60a0815260006158ae60a0830188614a02565b82810360208401526158c0818861582d565b905082810360408401526158d48187614a02565b905082810360608401526158e8818661582d565b91505060018060a01b03831660808301529695505050505050565b60006020828403121561591557600080fd5b8151610d15816151a7565b6000815461592d81615279565b80855260206001838116801561594a576001811461596457615992565b60ff1985168884015283151560051b880183019550615992565b866000528260002060005b8581101561598a5781548a820186015290830190840161596f565b890184019650505b505050505092915050565b602081526000610d156020830184615920565b634e487b7160e01b600052603160045260246000fd5b60008083546159d481615279565b600182811680156159ec5760018114615a0157615a30565b60ff1984168752821515830287019450615a30565b8760005260208060002060005b85811015615a275781548a820152908401908201615a0e565b50505082870194505b50929695505050505050565b600080600060608486031215615a5157600080fd5b8351615a5c81614a59565b6020850151909350615a6d81614c4e565b60408501519092506001600160401b03811115615a8957600080fd5b615a9586828701615562565b9150509250925092565b604081526000615ab26040830185615920565b8281036020840152615ac48185615920565b95945050505050565b60ff8281168282160390811115610bb757610bb76152e9565b600181815b80851115615b21578160001904821115615b0757615b076152e9565b80851615615b1457918102915b93841c9390800290615aeb565b509250929050565b600082615b3857506001610bb7565b81615b4557506000610bb7565b8160018114615b5b5760028114615b6557615b81565b6001915050610bb7565b60ff841115615b7657615b766152e9565b50506001821b610bb7565b5060208310610133831016604e8410600b8410161715615ba4575081810a610bb7565b615bae8383615ae6565b8060001904821115615bc257615bc26152e9565b029392505050565b6000610d1560ff841683615b29565b60008251615beb818460208701614957565b9190910192915050565b600060208284031215615c0757600080fd5b8151610d1581614c4e565b838152606060208201526000615c2b6060830185615920565b82810360408401526141b98185615920565b8481526001600160a01b0384166020820152608060408201819052600090615c6790830185615920565b8281036060840152614fd3818561592056fe416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efa26469706673582212204f088424aa06a67b6341902deccd76379dfa7566f446ff2321dd2c1e2e6cf27064736f6c63430008100033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
0000000000000000000000002cbd27e034fee53f79b607430da7771b22050741
-----Decoded View---------------
Arg [0] : _registry (address): 0x2Cbd27E034FEE53f79b607430dA7771B22050741
-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 0000000000000000000000002cbd27e034fee53f79b607430da7771b22050741
Loading...
Loading
Loading...
Loading
Make sure to use the "Vote Down" button for any spammy posts, and the "Vote Up" for interesting conversations.
[ 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.