Feature Tip: Add private address tag to any address under My Name Tag !
Overview
ETH Balance
0 ETH
Eth Value
$0.00More Info
Private Name Tags
ContractCreator
View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Loading...
Loading
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:
EthVault
Compiler Version
v0.8.16+commit.07a7930e
Optimization Enabled:
Yes with 2000000 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: BUSL-1.1 pragma solidity =0.8.16; import {Vault, MathUpgradeable, Math, SafeTransferLib, ERC20} from "src/vaults/Vault.sol"; import {IWETH} from "src/interfaces/IWETH.sol"; /// @notice The same as Vault, but ONLY raw ether can be withdrawn. contract EthVault is Vault { using SafeTransferLib for ERC20; /// @dev We need this to receive ETH when calling WETH.withdraw() receive() external payable {} function weth() public pure virtual returns (IWETH) { return IWETH(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2); } function _withdraw(address caller, address receiver, address owner, uint256 assets, uint256 shares) internal virtual override { _liquidate(assets); // Slippage during liquidation means we might get less than `assets` amount of `_asset` assets = Math.min(_asset.balanceOf(address(this)), assets); uint256 assetsFee = _getWithdrawalFee(assets); uint256 assetsToUser = assets - assetsFee; // Burn shares and give user equivalent value in `_asset` (minus withdrawal fees) if (caller != owner) _spendAllowance(owner, caller, shares); _burn(owner, shares); emit Withdraw(caller, receiver, owner, assets, shares); // Convert WETH to ETH and send to user weth().withdraw(assetsToUser); (bool success,) = receiver.call{value: assetsToUser}(""); require(success, "EthVault: ETH transfer failed"); // Send withdrawal fee to governance _asset.safeTransfer(governance, assetsFee); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (utils/Strings.sol) pragma solidity ^0.8.0; /** * @dev String operations. */ library Strings { bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef"; uint8 private constant _ADDRESS_LENGTH = 20; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT licence // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { if (value == 0) { return "0x00"; } uint256 temp = value; uint256 length = 0; while (temp != 0) { length++; temp >>= 8; } return toHexString(value, length); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _HEX_SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } /** * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation. */ function toHexString(address addr) internal pure returns (string memory) { return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (utils/math/Math.sol) pragma solidity ^0.8.0; /** * @dev Standard math utilities missing in the Solidity language. */ library Math { enum Rounding { Down, // Toward negative infinity Up, // Toward infinity Zero // Toward zero } /** * @dev Returns the largest of two numbers. */ function max(uint256 a, uint256 b) internal pure returns (uint256) { return a >= b ? a : b; } /** * @dev Returns the smallest of two numbers. */ function min(uint256 a, uint256 b) internal pure returns (uint256) { return a < b ? a : b; } /** * @dev Returns the average of two numbers. The result is rounded towards * zero. */ function average(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b) / 2 can overflow. return (a & b) + (a ^ b) / 2; } /** * @dev Returns the ceiling of the division of two numbers. * * This differs from standard division with `/` in that it rounds up instead * of rounding down. */ function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b - 1) / b can overflow on addition, so we distribute. return a == 0 ? 0 : (a - 1) / b + 1; } /** * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0 * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) * with further edits by Uniswap Labs also under MIT license. */ function mulDiv( uint256 x, uint256 y, uint256 denominator ) internal pure returns (uint256 result) { unchecked { // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256 // variables such that product = prod1 * 2^256 + prod0. uint256 prod0; // Least significant 256 bits of the product uint256 prod1; // Most significant 256 bits of the product assembly { let mm := mulmod(x, y, not(0)) prod0 := mul(x, y) prod1 := sub(sub(mm, prod0), lt(mm, prod0)) } // Handle non-overflow cases, 256 by 256 division. if (prod1 == 0) { return prod0 / denominator; } // Make sure the result is less than 2^256. Also prevents denominator == 0. require(denominator > prod1); /////////////////////////////////////////////// // 512 by 256 division. /////////////////////////////////////////////// // Make division exact by subtracting the remainder from [prod1 prod0]. uint256 remainder; assembly { // Compute remainder using mulmod. remainder := mulmod(x, y, denominator) // Subtract 256 bit number from 512 bit number. prod1 := sub(prod1, gt(remainder, prod0)) prod0 := sub(prod0, remainder) } // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1. // See https://cs.stackexchange.com/q/138556/92363. // Does not overflow because the denominator cannot be zero at this stage in the function. uint256 twos = denominator & (~denominator + 1); assembly { // Divide denominator by twos. denominator := div(denominator, twos) // Divide [prod1 prod0] by twos. prod0 := div(prod0, twos) // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one. twos := add(div(sub(0, twos), twos), 1) } // Shift in bits from prod1 into prod0. prod0 |= prod1 * twos; // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for // four bits. That is, denominator * inv = 1 mod 2^4. uint256 inverse = (3 * denominator) ^ 2; // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works // in modular arithmetic, doubling the correct bits in each step. inverse *= 2 - denominator * inverse; // inverse mod 2^8 inverse *= 2 - denominator * inverse; // inverse mod 2^16 inverse *= 2 - denominator * inverse; // inverse mod 2^32 inverse *= 2 - denominator * inverse; // inverse mod 2^64 inverse *= 2 - denominator * inverse; // inverse mod 2^128 inverse *= 2 - denominator * inverse; // inverse mod 2^256 // Because the division is now exact we can divide by multiplying with the modular inverse of denominator. // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1 // is no longer required. result = prod0 * inverse; return result; } } /** * @notice Calculates x * y / denominator with full precision, following the selected rounding direction. */ function mulDiv( uint256 x, uint256 y, uint256 denominator, Rounding rounding ) internal pure returns (uint256) { uint256 result = mulDiv(x, y, denominator); if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) { result += 1; } return result; } /** * @dev Returns the square root of a number. It the number is not a perfect square, the value is rounded down. * * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11). */ function sqrt(uint256 a) internal pure returns (uint256) { if (a == 0) { return 0; } // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target. // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have // `msb(a) <= a < 2*msb(a)`. // We also know that `k`, the position of the most significant bit, is such that `msb(a) = 2**k`. // This gives `2**k < a <= 2**(k+1)` → `2**(k/2) <= sqrt(a) < 2 ** (k/2+1)`. // Using an algorithm similar to the msb conmputation, we are able to compute `result = 2**(k/2)` which is a // good first aproximation of `sqrt(a)` with at least 1 correct bit. uint256 result = 1; uint256 x = a; if (x >> 128 > 0) { x >>= 128; result <<= 64; } if (x >> 64 > 0) { x >>= 64; result <<= 32; } if (x >> 32 > 0) { x >>= 32; result <<= 16; } if (x >> 16 > 0) { x >>= 16; result <<= 8; } if (x >> 8 > 0) { x >>= 8; result <<= 4; } if (x >> 4 > 0) { x >>= 4; result <<= 2; } if (x >> 2 > 0) { result <<= 1; } // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128, // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision // into the expected uint128 result. unchecked { result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; return min(result, a / result); } } /** * @notice Calculates sqrt(a), following the selected rounding direction. */ function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) { uint256 result = sqrt(a); if (rounding == Rounding.Up && result * result < a) { result += 1; } return result; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (access/AccessControl.sol) pragma solidity ^0.8.0; import "./IAccessControlUpgradeable.sol"; import "../utils/ContextUpgradeable.sol"; import "../utils/StringsUpgradeable.sol"; import "../utils/introspection/ERC165Upgradeable.sol"; import "../proxy/utils/Initializable.sol"; /** * @dev Contract module that allows children to implement role-based access * control mechanisms. This is a lightweight version that doesn't allow enumerating role * members except through off-chain means by accessing the contract event logs. Some * applications may benefit from on-chain enumerability, for those cases see * {AccessControlEnumerable}. * * Roles are referred to by their `bytes32` identifier. These should be exposed * in the external API and be unique. The best way to achieve this is by * using `public constant` hash digests: * * ``` * bytes32 public constant MY_ROLE = keccak256("MY_ROLE"); * ``` * * Roles can be used to represent a set of permissions. To restrict access to a * function call, use {hasRole}: * * ``` * function foo() public { * require(hasRole(MY_ROLE, msg.sender)); * ... * } * ``` * * Roles can be granted and revoked dynamically via the {grantRole} and * {revokeRole} functions. Each role has an associated admin role, and only * accounts that have a role's admin role can call {grantRole} and {revokeRole}. * * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means * that only accounts with this role will be able to grant or revoke other * roles. More complex role relationships can be created by using * {_setRoleAdmin}. * * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to * grant and revoke this role. Extra precautions should be taken to secure * accounts that have been granted it. */ abstract contract AccessControlUpgradeable is Initializable, ContextUpgradeable, IAccessControlUpgradeable, ERC165Upgradeable { function __AccessControl_init() internal onlyInitializing { } function __AccessControl_init_unchained() internal onlyInitializing { } struct RoleData { mapping(address => bool) members; bytes32 adminRole; } mapping(bytes32 => RoleData) private _roles; bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00; /** * @dev Modifier that checks that an account has a specific role. Reverts * with a standardized message including the required role. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ * * _Available since v4.1._ */ modifier onlyRole(bytes32 role) { _checkRole(role); _; } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IAccessControlUpgradeable).interfaceId || super.supportsInterface(interfaceId); } /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole(bytes32 role, address account) public view virtual override returns (bool) { return _roles[role].members[account]; } /** * @dev Revert with a standard message if `_msgSender()` is missing `role`. * Overriding this function changes the behavior of the {onlyRole} modifier. * * Format of the revert message is described in {_checkRole}. * * _Available since v4.6._ */ function _checkRole(bytes32 role) internal view virtual { _checkRole(role, _msgSender()); } /** * @dev Revert with a standard message if `account` is missing `role`. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ */ function _checkRole(bytes32 role, address account) internal view virtual { if (!hasRole(role, account)) { revert( string( abi.encodePacked( "AccessControl: account ", StringsUpgradeable.toHexString(uint160(account), 20), " is missing role ", StringsUpgradeable.toHexString(uint256(role), 32) ) ) ); } } /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) { return _roles[role].adminRole; } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. * * Requirements: * * - the caller must have ``role``'s admin role. * * May emit a {RoleGranted} event. */ function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) { _grantRole(role, account); } /** * @dev Revokes `role` from `account`. * * If `account` had been granted `role`, emits a {RoleRevoked} event. * * Requirements: * * - the caller must have ``role``'s admin role. * * May emit a {RoleRevoked} event. */ function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) { _revokeRole(role, account); } /** * @dev Revokes `role` from the calling account. * * Roles are often managed via {grantRole} and {revokeRole}: this function's * purpose is to provide a mechanism for accounts to lose their privileges * if they are compromised (such as when a trusted device is misplaced). * * If the calling account had been revoked `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `account`. * * May emit a {RoleRevoked} event. */ function renounceRole(bytes32 role, address account) public virtual override { require(account == _msgSender(), "AccessControl: can only renounce roles for self"); _revokeRole(role, account); } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. Note that unlike {grantRole}, this function doesn't perform any * checks on the calling account. * * May emit a {RoleGranted} event. * * [WARNING] * ==== * This function should only be called from the constructor when setting * up the initial roles for the system. * * Using this function in any other way is effectively circumventing the admin * system imposed by {AccessControl}. * ==== * * NOTE: This function is deprecated in favor of {_grantRole}. */ function _setupRole(bytes32 role, address account) internal virtual { _grantRole(role, account); } /** * @dev Sets `adminRole` as ``role``'s admin role. * * Emits a {RoleAdminChanged} event. */ function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual { bytes32 previousAdminRole = getRoleAdmin(role); _roles[role].adminRole = adminRole; emit RoleAdminChanged(role, previousAdminRole, adminRole); } /** * @dev Grants `role` to `account`. * * Internal function without access restriction. * * May emit a {RoleGranted} event. */ function _grantRole(bytes32 role, address account) internal virtual { if (!hasRole(role, account)) { _roles[role].members[account] = true; emit RoleGranted(role, account, _msgSender()); } } /** * @dev Revokes `role` from `account`. * * Internal function without access restriction. * * May emit a {RoleRevoked} event. */ function _revokeRole(bytes32 role, address account) internal virtual { if (hasRole(role, account)) { _roles[role].members[account] = false; emit RoleRevoked(role, account, _msgSender()); } } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[49] private __gap; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol) pragma solidity ^0.8.0; /** * @dev External interface of AccessControl declared to support ERC165 detection. */ interface IAccessControlUpgradeable { /** * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole` * * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite * {RoleAdminChanged} not being emitted signaling this. * * _Available since v3.1._ */ event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole); /** * @dev Emitted when `account` is granted `role`. * * `sender` is the account that originated the contract call, an admin role * bearer except when using {AccessControl-_setupRole}. */ event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender); /** * @dev Emitted when `account` is revoked `role`. * * `sender` is the account that originated the contract call: * - if using `revokeRole`, it is the admin role bearer * - if using `renounceRole`, it is the role bearer (i.e. `account`) */ event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender); /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole(bytes32 role, address account) external view returns (bool); /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {AccessControl-_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) external view returns (bytes32); /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function grantRole(bytes32 role, address account) external; /** * @dev Revokes `role` from `account`. * * If `account` had been granted `role`, emits a {RoleRevoked} event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function revokeRole(bytes32 role, address account) external; /** * @dev Revokes `role` from the calling account. * * Roles are often managed via {grantRole} and {revokeRole}: this function's * purpose is to provide a mechanism for accounts to lose their privileges * if they are compromised (such as when a trusted device is misplaced). * * If the calling account had been granted `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `account`. */ function renounceRole(bytes32 role, address account) external; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (interfaces/IERC4626.sol) pragma solidity ^0.8.0; import "../token/ERC20/IERC20Upgradeable.sol"; import "../token/ERC20/extensions/IERC20MetadataUpgradeable.sol"; /** * @dev Interface of the ERC4626 "Tokenized Vault Standard", as defined in * https://eips.ethereum.org/EIPS/eip-4626[ERC-4626]. * * _Available since v4.7._ */ interface IERC4626Upgradeable is IERC20Upgradeable, IERC20MetadataUpgradeable { 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 ); /** * @dev Returns the address of the underlying token used for the Vault for accounting, depositing, and withdrawing. * * - MUST be an ERC-20 token contract. * - MUST NOT revert. */ function asset() external view returns (address assetTokenAddress); /** * @dev Returns the total amount of the underlying asset that is “managed” by Vault. * * - SHOULD include any compounding that occurs from yield. * - MUST be inclusive of any fees that are charged against assets in the Vault. * - MUST NOT revert. */ function totalAssets() external view returns (uint256 totalManagedAssets); /** * @dev Returns the amount of shares that the Vault would exchange for the amount of assets provided, in an ideal * scenario where all the conditions are met. * * - MUST NOT be inclusive of any fees that are charged against assets in the Vault. * - MUST NOT show any variations depending on the caller. * - MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange. * - MUST NOT revert. * * NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the * “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and * from. */ function convertToShares(uint256 assets) external view returns (uint256 shares); /** * @dev Returns the amount of assets that the Vault would exchange for the amount of shares provided, in an ideal * scenario where all the conditions are met. * * - MUST NOT be inclusive of any fees that are charged against assets in the Vault. * - MUST NOT show any variations depending on the caller. * - MUST NOT reflect slippage or other on-chain conditions, when performing the actual exchange. * - MUST NOT revert. * * NOTE: This calculation MAY NOT reflect the “per-user” price-per-share, and instead should reflect the * “average-user’s” price-per-share, meaning what the average user should expect to see when exchanging to and * from. */ function convertToAssets(uint256 shares) external view returns (uint256 assets); /** * @dev Returns the maximum amount of the underlying asset that can be deposited into the Vault for the receiver, * through a deposit call. * * - MUST return a limited value if receiver is subject to some deposit limit. * - MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of assets that may be deposited. * - MUST NOT revert. */ function maxDeposit(address receiver) external view returns (uint256 maxAssets); /** * @dev Allows an on-chain or off-chain user to simulate the effects of their deposit at the current block, given * current on-chain conditions. * * - MUST return as close to and no more than the exact amount of Vault shares that would be minted in a deposit * call in the same transaction. I.e. deposit should return the same or more shares as previewDeposit if called * in the same transaction. * - MUST NOT account for deposit limits like those returned from maxDeposit and should always act as though the * deposit would be accepted, regardless if the user has enough tokens approved, etc. * - MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees. * - MUST NOT revert. * * NOTE: any unfavorable discrepancy between convertToShares and previewDeposit SHOULD be considered slippage in * share price or some other type of condition, meaning the depositor will lose assets by depositing. */ function previewDeposit(uint256 assets) external view returns (uint256 shares); /** * @dev Mints shares Vault shares to receiver by depositing exactly amount of underlying tokens. * * - MUST emit the Deposit event. * - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the * deposit execution, and are accounted for during deposit. * - MUST revert if all of assets cannot be deposited (due to deposit limit being reached, slippage, the user not * approving enough underlying tokens to the Vault contract, etc). * * NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token. */ function deposit(uint256 assets, address receiver) external returns (uint256 shares); /** * @dev Returns the maximum amount of the Vault shares that can be minted for the receiver, through a mint call. * - MUST return a limited value if receiver is subject to some mint limit. * - MUST return 2 ** 256 - 1 if there is no limit on the maximum amount of shares that may be minted. * - MUST NOT revert. */ function maxMint(address receiver) external view returns (uint256 maxShares); /** * @dev Allows an on-chain or off-chain user to simulate the effects of their mint at the current block, given * current on-chain conditions. * * - MUST return as close to and no fewer than the exact amount of assets that would be deposited in a mint call * in the same transaction. I.e. mint should return the same or fewer assets as previewMint if called in the * same transaction. * - MUST NOT account for mint limits like those returned from maxMint and should always act as though the mint * would be accepted, regardless if the user has enough tokens approved, etc. * - MUST be inclusive of deposit fees. Integrators should be aware of the existence of deposit fees. * - MUST NOT revert. * * NOTE: any unfavorable discrepancy between convertToAssets and previewMint SHOULD be considered slippage in * share price or some other type of condition, meaning the depositor will lose assets by minting. */ function previewMint(uint256 shares) external view returns (uint256 assets); /** * @dev Mints exactly shares Vault shares to receiver by depositing amount of underlying tokens. * * - MUST emit the Deposit event. * - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the mint * execution, and are accounted for during mint. * - MUST revert if all of shares cannot be minted (due to deposit limit being reached, slippage, the user not * approving enough underlying tokens to the Vault contract, etc). * * NOTE: most implementations will require pre-approval of the Vault with the Vault’s underlying asset token. */ function mint(uint256 shares, address receiver) external returns (uint256 assets); /** * @dev Returns the maximum amount of the underlying asset that can be withdrawn from the owner balance in the * Vault, through a withdraw call. * * - MUST return a limited value if owner is subject to some withdrawal limit or timelock. * - MUST NOT revert. */ function maxWithdraw(address owner) external view returns (uint256 maxAssets); /** * @dev Allows an on-chain or off-chain user to simulate the effects of their withdrawal at the current block, * given current on-chain conditions. * * - MUST return as close to and no fewer than the exact amount of Vault shares that would be burned in a withdraw * call in the same transaction. I.e. withdraw should return the same or fewer shares as previewWithdraw if * called * in the same transaction. * - MUST NOT account for withdrawal limits like those returned from maxWithdraw and should always act as though * the withdrawal would be accepted, regardless if the user has enough shares, etc. * - MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees. * - MUST NOT revert. * * NOTE: any unfavorable discrepancy between convertToShares and previewWithdraw SHOULD be considered slippage in * share price or some other type of condition, meaning the depositor will lose assets by depositing. */ function previewWithdraw(uint256 assets) external view returns (uint256 shares); /** * @dev Burns shares from owner and sends exactly assets of underlying tokens to receiver. * * - MUST emit the Withdraw event. * - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the * withdraw execution, and are accounted for during withdraw. * - MUST revert if all of assets cannot be withdrawn (due to withdrawal limit being reached, slippage, the owner * not having enough shares, etc). * * Note that some implementations will require pre-requesting to the Vault before a withdrawal may be performed. * Those methods should be performed separately. */ function withdraw( uint256 assets, address receiver, address owner ) external returns (uint256 shares); /** * @dev Returns the maximum amount of Vault shares that can be redeemed from the owner balance in the Vault, * through a redeem call. * * - MUST return a limited value if owner is subject to some withdrawal limit or timelock. * - MUST return balanceOf(owner) if owner is not subject to any withdrawal limit or timelock. * - MUST NOT revert. */ function maxRedeem(address owner) external view returns (uint256 maxShares); /** * @dev Allows an on-chain or off-chain user to simulate the effects of their redeemption at the current block, * given current on-chain conditions. * * - MUST return as close to and no more than the exact amount of assets that would be withdrawn in a redeem call * in the same transaction. I.e. redeem should return the same or more assets as previewRedeem if called in the * same transaction. * - MUST NOT account for redemption limits like those returned from maxRedeem and should always act as though the * redemption would be accepted, regardless if the user has enough shares, etc. * - MUST be inclusive of withdrawal fees. Integrators should be aware of the existence of withdrawal fees. * - MUST NOT revert. * * NOTE: any unfavorable discrepancy between convertToAssets and previewRedeem SHOULD be considered slippage in * share price or some other type of condition, meaning the depositor will lose assets by redeeming. */ function previewRedeem(uint256 shares) external view returns (uint256 assets); /** * @dev Burns exactly shares from owner and sends assets of underlying tokens to receiver. * * - MUST emit the Withdraw event. * - MAY support an additional flow in which the underlying tokens are owned by the Vault contract before the * redeem execution, and are accounted for during redeem. * - MUST revert if all of shares cannot be redeemed (due to withdrawal limit being reached, slippage, the owner * not having enough shares, etc). * * NOTE: some implementations will require pre-requesting to the Vault before a withdrawal may be performed. * Those methods should be performed separately. */ function redeem( uint256 shares, address receiver, address owner ) external returns (uint256 assets); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (proxy/utils/Initializable.sol) pragma solidity ^0.8.2; import "../../utils/AddressUpgradeable.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. Equivalent to `reinitializer(1)`. */ modifier initializer() { bool isTopLevelCall = !_initializing; require( (isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.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. * * `initializer` is equivalent to `reinitializer(1)`, so 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. * * 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. */ 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. */ function _disableInitializers() internal virtual { require(!_initializing, "Initializable: contract is initializing"); if (_initialized < type(uint8).max) { _initialized = type(uint8).max; emit Initialized(type(uint8).max); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol) pragma solidity ^0.8.0; import "../utils/ContextUpgradeable.sol"; import "../proxy/utils/Initializable.sol"; /** * @dev Contract module which allows children to implement an emergency stop * mechanism that can be triggered by an authorized account. * * This module is used through inheritance. It will make available the * modifiers `whenNotPaused` and `whenPaused`, which can be applied to * the functions of your contract. Note that they will not be pausable by * simply including this module, only once the modifiers are put in place. */ abstract contract PausableUpgradeable is Initializable, ContextUpgradeable { /** * @dev Emitted when the pause is triggered by `account`. */ event Paused(address account); /** * @dev Emitted when the pause is lifted by `account`. */ event Unpaused(address account); bool private _paused; /** * @dev Initializes the contract in unpaused state. */ function __Pausable_init() internal onlyInitializing { __Pausable_init_unchained(); } function __Pausable_init_unchained() internal onlyInitializing { _paused = false; } /** * @dev Modifier to make a function callable only when the contract is not paused. * * Requirements: * * - The contract must not be paused. */ modifier whenNotPaused() { _requireNotPaused(); _; } /** * @dev Modifier to make a function callable only when the contract is paused. * * Requirements: * * - The contract must be paused. */ modifier whenPaused() { _requirePaused(); _; } /** * @dev Returns true if the contract is paused, and false otherwise. */ function paused() public view virtual returns (bool) { return _paused; } /** * @dev Throws if the contract is paused. */ function _requireNotPaused() internal view virtual { require(!paused(), "Pausable: paused"); } /** * @dev Throws if the contract is not paused. */ function _requirePaused() internal view virtual { require(paused(), "Pausable: not paused"); } /** * @dev Triggers stopped state. * * Requirements: * * - The contract must not be paused. */ function _pause() internal virtual whenNotPaused { _paused = true; emit Paused(_msgSender()); } /** * @dev Returns to normal state. * * Requirements: * * - The contract must be paused. */ function _unpause() internal virtual whenPaused { _paused = false; emit Unpaused(_msgSender()); } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[49] private __gap; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/ERC20.sol) pragma solidity ^0.8.0; import "./IERC20Upgradeable.sol"; import "./extensions/IERC20MetadataUpgradeable.sol"; import "../../utils/ContextUpgradeable.sol"; import "../../proxy/utils/Initializable.sol"; /** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin Contracts guidelines: functions revert * instead returning `false` on failure. This behavior is nonetheless * conventional and does not conflict with the expectations of ERC20 * applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */ contract ERC20Upgradeable is Initializable, ContextUpgradeable, IERC20Upgradeable, IERC20MetadataUpgradeable { mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; /** * @dev Sets the values for {name} and {symbol}. * * The default value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ function __ERC20_init(string memory name_, string memory symbol_) internal onlyInitializing { __ERC20_init_unchained(name_, symbol_); } function __ERC20_init_unchained(string memory name_, string memory symbol_) internal onlyInitializing { _name = name_; _symbol = symbol_; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5.05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overridden; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `to` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address to, uint256 amount) public virtual override returns (bool) { address owner = _msgSender(); _transfer(owner, to, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on * `transferFrom`. This is semantically equivalent to an infinite approval. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { address owner = _msgSender(); _approve(owner, spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * NOTE: Does not update the allowance if the current allowance * is the maximum `uint256`. * * Requirements: * * - `from` and `to` cannot be the zero address. * - `from` must have a balance of at least `amount`. * - the caller must have allowance for ``from``'s tokens of at least * `amount`. */ function transferFrom( address from, address to, uint256 amount ) public virtual override returns (bool) { address spender = _msgSender(); _spendAllowance(from, spender, amount); _transfer(from, to, amount); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { address owner = _msgSender(); _approve(owner, spender, allowance(owner, spender) + addedValue); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { address owner = _msgSender(); uint256 currentAllowance = allowance(owner, spender); require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); unchecked { _approve(owner, spender, currentAllowance - subtractedValue); } return true; } /** * @dev Moves `amount` of tokens from `from` to `to`. * * This internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `from` must have a balance of at least `amount`. */ function _transfer( address from, address to, uint256 amount ) internal virtual { require(from != address(0), "ERC20: transfer from the zero address"); require(to != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(from, to, amount); uint256 fromBalance = _balances[from]; require(fromBalance >= amount, "ERC20: transfer amount exceeds balance"); unchecked { _balances[from] = fromBalance - amount; } _balances[to] += amount; emit Transfer(from, to, amount); _afterTokenTransfer(from, to, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply += amount; _balances[account] += amount; emit Transfer(address(0), account, amount); _afterTokenTransfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); unchecked { _balances[account] = accountBalance - amount; } _totalSupply -= amount; emit Transfer(account, address(0), amount); _afterTokenTransfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve( address owner, address spender, uint256 amount ) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Updates `owner` s allowance for `spender` based on spent `amount`. * * Does not update the allowance amount in case of infinite allowance. * Revert if not enough allowance is available. * * Might emit an {Approval} event. */ function _spendAllowance( address owner, address spender, uint256 amount ) internal virtual { uint256 currentAllowance = allowance(owner, spender); if (currentAllowance != type(uint256).max) { require(currentAllowance >= amount, "ERC20: insufficient allowance"); unchecked { _approve(owner, spender, currentAllowance - amount); } } } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 amount ) internal virtual {} /** * @dev Hook that is called after any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * has been transferred to `to`. * - when `from` is zero, `amount` tokens have been minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens have been burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _afterTokenTransfer( address from, address to, uint256 amount ) internal virtual {} /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[45] private __gap; }
// 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 IERC20Upgradeable { /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `to`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address to, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `from` to `to` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom( address from, address to, uint256 amount ) external returns (bool); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/extensions/ERC4626.sol) pragma solidity ^0.8.0; import "../ERC20Upgradeable.sol"; import "../utils/SafeERC20Upgradeable.sol"; import "../../../interfaces/IERC4626Upgradeable.sol"; import "../../../utils/math/MathUpgradeable.sol"; import "../../../proxy/utils/Initializable.sol"; /** * @dev Implementation of the ERC4626 "Tokenized Vault Standard" as defined in * https://eips.ethereum.org/EIPS/eip-4626[EIP-4626]. * * This extension allows the minting and burning of "shares" (represented using the ERC20 inheritance) in exchange for * underlying "assets" through standardized {deposit}, {mint}, {redeem} and {burn} workflows. This contract extends * the ERC20 standard. Any additional extensions included along it would affect the "shares" token represented by this * contract and not the "assets" token which is an independent contract. * * CAUTION: Deposits and withdrawals may incur unexpected slippage. Users should verify that the amount received of * shares or assets is as expected. EOAs should operate through a wrapper that performs these checks such as * https://github.com/fei-protocol/ERC4626#erc4626router-and-base[ERC4626Router]. * * _Available since v4.7._ */ abstract contract ERC4626Upgradeable is Initializable, ERC20Upgradeable, IERC4626Upgradeable { using MathUpgradeable for uint256; IERC20MetadataUpgradeable private _asset; /** * @dev Set the underlying asset contract. This must be an ERC20-compatible contract (ERC20 or ERC777). */ function __ERC4626_init(IERC20MetadataUpgradeable asset_) internal onlyInitializing { __ERC4626_init_unchained(asset_); } function __ERC4626_init_unchained(IERC20MetadataUpgradeable asset_) internal onlyInitializing { _asset = asset_; } /** @dev See {IERC4262-asset}. */ function asset() public view virtual override returns (address) { return address(_asset); } /** @dev See {IERC4262-totalAssets}. */ function totalAssets() public view virtual override returns (uint256) { return _asset.balanceOf(address(this)); } /** @dev See {IERC4262-convertToShares}. */ function convertToShares(uint256 assets) public view virtual override returns (uint256 shares) { return _convertToShares(assets, MathUpgradeable.Rounding.Down); } /** @dev See {IERC4262-convertToAssets}. */ function convertToAssets(uint256 shares) public view virtual override returns (uint256 assets) { return _convertToAssets(shares, MathUpgradeable.Rounding.Down); } /** @dev See {IERC4262-maxDeposit}. */ function maxDeposit(address) public view virtual override returns (uint256) { return _isVaultCollateralized() ? type(uint256).max : 0; } /** @dev See {IERC4262-maxMint}. */ function maxMint(address) public view virtual override returns (uint256) { return type(uint256).max; } /** @dev See {IERC4262-maxWithdraw}. */ function maxWithdraw(address owner) public view virtual override returns (uint256) { return _convertToAssets(balanceOf(owner), MathUpgradeable.Rounding.Down); } /** @dev See {IERC4262-maxRedeem}. */ function maxRedeem(address owner) public view virtual override returns (uint256) { return balanceOf(owner); } /** @dev See {IERC4262-previewDeposit}. */ function previewDeposit(uint256 assets) public view virtual override returns (uint256) { return _convertToShares(assets, MathUpgradeable.Rounding.Down); } /** @dev See {IERC4262-previewMint}. */ function previewMint(uint256 shares) public view virtual override returns (uint256) { return _convertToAssets(shares, MathUpgradeable.Rounding.Up); } /** @dev See {IERC4262-previewWithdraw}. */ function previewWithdraw(uint256 assets) public view virtual override returns (uint256) { return _convertToShares(assets, MathUpgradeable.Rounding.Up); } /** @dev See {IERC4262-previewRedeem}. */ function previewRedeem(uint256 shares) public view virtual override returns (uint256) { return _convertToAssets(shares, MathUpgradeable.Rounding.Down); } /** @dev See {IERC4262-deposit}. */ function deposit(uint256 assets, address receiver) public virtual override returns (uint256) { require(assets <= maxDeposit(receiver), "ERC4626: deposit more than max"); uint256 shares = previewDeposit(assets); _deposit(_msgSender(), receiver, assets, shares); return shares; } /** @dev See {IERC4262-mint}. */ function mint(uint256 shares, address receiver) public virtual override returns (uint256) { require(shares <= maxMint(receiver), "ERC4626: mint more than max"); uint256 assets = previewMint(shares); _deposit(_msgSender(), receiver, assets, shares); return assets; } /** @dev See {IERC4262-withdraw}. */ function withdraw( uint256 assets, address receiver, address owner ) public virtual override returns (uint256) { require(assets <= maxWithdraw(owner), "ERC4626: withdraw more than max"); uint256 shares = previewWithdraw(assets); _withdraw(_msgSender(), receiver, owner, assets, shares); return shares; } /** @dev See {IERC4262-redeem}. */ function redeem( uint256 shares, address receiver, address owner ) public virtual override returns (uint256) { require(shares <= maxRedeem(owner), "ERC4626: redeem more than max"); uint256 assets = previewRedeem(shares); _withdraw(_msgSender(), receiver, owner, assets, shares); return assets; } /** * @dev Internal conversion function (from assets to shares) with support for rounding direction. * * Will revert if assets > 0, totalSupply > 0 and totalAssets = 0. That corresponds to a case where any asset * would represent an infinite amout of shares. */ function _convertToShares(uint256 assets, MathUpgradeable.Rounding rounding) internal view virtual returns (uint256 shares) { uint256 supply = totalSupply(); return (assets == 0 || supply == 0) ? assets.mulDiv(10**decimals(), 10**_asset.decimals(), rounding) : assets.mulDiv(supply, totalAssets(), rounding); } /** * @dev Internal conversion function (from shares to assets) with support for rounding direction. */ function _convertToAssets(uint256 shares, MathUpgradeable.Rounding rounding) internal view virtual returns (uint256 assets) { uint256 supply = totalSupply(); return (supply == 0) ? shares.mulDiv(10**_asset.decimals(), 10**decimals(), rounding) : shares.mulDiv(totalAssets(), supply, rounding); } /** * @dev Deposit/mint common workflow. */ function _deposit( address caller, address receiver, uint256 assets, uint256 shares ) internal virtual { // If _asset is ERC777, `transferFrom` can trigger a reenterancy BEFORE the transfer happens through the // `tokensToSend` hook. On the other hand, the `tokenReceived` hook, that is triggered after the transfer, // calls the vault, which is assumed not malicious. // // Conclusion: we need to do the transfer before we mint so that any reentrancy would happen before the // assets are transfered and before the shares are minted, which is a valid state. // slither-disable-next-line reentrancy-no-eth SafeERC20Upgradeable.safeTransferFrom(_asset, caller, address(this), assets); _mint(receiver, shares); emit Deposit(caller, receiver, assets, shares); } /** * @dev Withdraw/redeem common workflow. */ function _withdraw( address caller, address receiver, address owner, uint256 assets, uint256 shares ) internal virtual { if (caller != owner) { _spendAllowance(owner, caller, shares); } // If _asset is ERC777, `transfer` can trigger a reentrancy AFTER the transfer happens through the // `tokensReceived` hook. On the other hand, the `tokensToSend` hook, that is triggered before the transfer, // calls the vault, which is assumed not malicious. // // Conclusion: we need to do the transfer after the burn so that any reentrancy would happen after the // shares are burned and after the assets are transfered, which is a valid state. _burn(owner, shares); SafeERC20Upgradeable.safeTransfer(_asset, receiver, assets); emit Withdraw(caller, receiver, owner, assets, shares); } function _isVaultCollateralized() private view returns (bool) { return totalAssets() > 0 || totalSupply() == 0; } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[49] private __gap; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol) pragma solidity ^0.8.0; import "../IERC20Upgradeable.sol"; /** * @dev Interface for the optional metadata functions from the ERC20 standard. * * _Available since v4.1._ */ interface IERC20MetadataUpgradeable is IERC20Upgradeable { /** * @dev Returns the name of the token. */ function name() external view returns (string memory); /** * @dev Returns the symbol of the token. */ function symbol() external view returns (string memory); /** * @dev Returns the decimals places of the token. */ function decimals() external view returns (uint8); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612]. * * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't * need to send a transaction, and thus is not required to hold Ether at all. */ interface IERC20PermitUpgradeable { /** * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens, * given ``owner``'s signed approval. * * IMPORTANT: The same issues {IERC20-approve} has related to transaction * ordering also apply here. * * Emits an {Approval} event. * * Requirements: * * - `spender` cannot be the zero address. * - `deadline` must be a timestamp in the future. * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner` * over the EIP712-formatted function arguments. * - the signature must use ``owner``'s current nonce (see {nonces}). * * For more information on the signature format, see the * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP * section]. */ function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external; /** * @dev Returns the current nonce for `owner`. This value must be * included whenever a signature is generated for {permit}. * * Every successful call to {permit} increases ``owner``'s nonce by one. This * prevents a signature from being used multiple times. */ function nonces(address owner) external view returns (uint256); /** * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}. */ // solhint-disable-next-line func-name-mixedcase function DOMAIN_SEPARATOR() external view returns (bytes32); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/utils/SafeERC20.sol) pragma solidity ^0.8.0; import "../IERC20Upgradeable.sol"; import "../extensions/draft-IERC20PermitUpgradeable.sol"; import "../../../utils/AddressUpgradeable.sol"; /** * @title SafeERC20 * @dev Wrappers around ERC20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20Upgradeable { using AddressUpgradeable for address; function safeTransfer( IERC20Upgradeable token, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom( IERC20Upgradeable token, address from, address to, uint256 value ) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } /** * @dev Deprecated. This function has issues similar to the ones found in * {IERC20-approve}, and its usage is discouraged. * * Whenever possible, use {safeIncreaseAllowance} and * {safeDecreaseAllowance} instead. */ function safeApprove( IERC20Upgradeable token, address spender, uint256 value ) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' require( (value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function safeIncreaseAllowance( IERC20Upgradeable token, address spender, uint256 value ) internal { uint256 newAllowance = token.allowance(address(this), spender) + value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } function safeDecreaseAllowance( IERC20Upgradeable token, address spender, uint256 value ) internal { unchecked { uint256 oldAllowance = token.allowance(address(this), spender); require(oldAllowance >= value, "SafeERC20: decreased allowance below zero"); uint256 newAllowance = oldAllowance - value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } } function safePermit( IERC20PermitUpgradeable token, address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) internal { uint256 nonceBefore = token.nonces(owner); token.permit(owner, spender, value, deadline, v, r, s); uint256 nonceAfter = token.nonces(owner); require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed"); } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */ function _callOptionalReturn(IERC20Upgradeable token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that // the target address contains contract code and also asserts for success in the low-level call. bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ library AddressUpgradeable { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== * * [IMPORTANT] * ==== * You shouldn't rely on `isContract` to protect against flash loan attacks! * * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract * constructor. * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize/address.code.length, which returns 0 // for contracts in construction, since the code is only stored at the end // of the constructor execution. return account.code.length > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCall(target, data, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly /// @solidity memory-safe-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) pragma solidity ^0.8.0; import "../proxy/utils/Initializable.sol"; /** * @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 ContextUpgradeable is Initializable { function __Context_init() internal onlyInitializing { } function __Context_init_unchained() internal onlyInitializing { } function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[50] private __gap; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (utils/Strings.sol) pragma solidity ^0.8.0; /** * @dev String operations. */ library StringsUpgradeable { bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef"; uint8 private constant _ADDRESS_LENGTH = 20; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { // Inspired by OraclizeAPI's implementation - MIT licence // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { if (value == 0) { return "0x00"; } uint256 temp = value; uint256 length = 0; while (temp != 0) { length++; temp >>= 8; } return toHexString(value, length); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _HEX_SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } /** * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation. */ function toHexString(address addr) internal pure returns (string memory) { return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol) pragma solidity ^0.8.0; import "./IERC165Upgradeable.sol"; import "../../proxy/utils/Initializable.sol"; /** * @dev Implementation of the {IERC165} interface. * * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check * for the additional interface id that will be supported. For example: * * ```solidity * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); * } * ``` * * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation. */ abstract contract ERC165Upgradeable is Initializable, IERC165Upgradeable { function __ERC165_init() internal onlyInitializing { } function __ERC165_init_unchained() internal onlyInitializing { } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IERC165Upgradeable).interfaceId; } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[50] private __gap; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165Upgradeable { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (utils/math/Math.sol) pragma solidity ^0.8.0; /** * @dev Standard math utilities missing in the Solidity language. */ library MathUpgradeable { enum Rounding { Down, // Toward negative infinity Up, // Toward infinity Zero // Toward zero } /** * @dev Returns the largest of two numbers. */ function max(uint256 a, uint256 b) internal pure returns (uint256) { return a >= b ? a : b; } /** * @dev Returns the smallest of two numbers. */ function min(uint256 a, uint256 b) internal pure returns (uint256) { return a < b ? a : b; } /** * @dev Returns the average of two numbers. The result is rounded towards * zero. */ function average(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b) / 2 can overflow. return (a & b) + (a ^ b) / 2; } /** * @dev Returns the ceiling of the division of two numbers. * * This differs from standard division with `/` in that it rounds up instead * of rounding down. */ function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b - 1) / b can overflow on addition, so we distribute. return a == 0 ? 0 : (a - 1) / b + 1; } /** * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0 * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) * with further edits by Uniswap Labs also under MIT license. */ function mulDiv( uint256 x, uint256 y, uint256 denominator ) internal pure returns (uint256 result) { unchecked { // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256 // variables such that product = prod1 * 2^256 + prod0. uint256 prod0; // Least significant 256 bits of the product uint256 prod1; // Most significant 256 bits of the product assembly { let mm := mulmod(x, y, not(0)) prod0 := mul(x, y) prod1 := sub(sub(mm, prod0), lt(mm, prod0)) } // Handle non-overflow cases, 256 by 256 division. if (prod1 == 0) { return prod0 / denominator; } // Make sure the result is less than 2^256. Also prevents denominator == 0. require(denominator > prod1); /////////////////////////////////////////////// // 512 by 256 division. /////////////////////////////////////////////// // Make division exact by subtracting the remainder from [prod1 prod0]. uint256 remainder; assembly { // Compute remainder using mulmod. remainder := mulmod(x, y, denominator) // Subtract 256 bit number from 512 bit number. prod1 := sub(prod1, gt(remainder, prod0)) prod0 := sub(prod0, remainder) } // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1. // See https://cs.stackexchange.com/q/138556/92363. // Does not overflow because the denominator cannot be zero at this stage in the function. uint256 twos = denominator & (~denominator + 1); assembly { // Divide denominator by twos. denominator := div(denominator, twos) // Divide [prod1 prod0] by twos. prod0 := div(prod0, twos) // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one. twos := add(div(sub(0, twos), twos), 1) } // Shift in bits from prod1 into prod0. prod0 |= prod1 * twos; // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for // four bits. That is, denominator * inv = 1 mod 2^4. uint256 inverse = (3 * denominator) ^ 2; // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works // in modular arithmetic, doubling the correct bits in each step. inverse *= 2 - denominator * inverse; // inverse mod 2^8 inverse *= 2 - denominator * inverse; // inverse mod 2^16 inverse *= 2 - denominator * inverse; // inverse mod 2^32 inverse *= 2 - denominator * inverse; // inverse mod 2^64 inverse *= 2 - denominator * inverse; // inverse mod 2^128 inverse *= 2 - denominator * inverse; // inverse mod 2^256 // Because the division is now exact we can divide by multiplying with the modular inverse of denominator. // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1 // is no longer required. result = prod0 * inverse; return result; } } /** * @notice Calculates x * y / denominator with full precision, following the selected rounding direction. */ function mulDiv( uint256 x, uint256 y, uint256 denominator, Rounding rounding ) internal pure returns (uint256) { uint256 result = mulDiv(x, y, denominator); if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) { result += 1; } return result; } /** * @dev Returns the square root of a number. It the number is not a perfect square, the value is rounded down. * * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11). */ function sqrt(uint256 a) internal pure returns (uint256) { if (a == 0) { return 0; } // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target. // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have // `msb(a) <= a < 2*msb(a)`. // We also know that `k`, the position of the most significant bit, is such that `msb(a) = 2**k`. // This gives `2**k < a <= 2**(k+1)` → `2**(k/2) <= sqrt(a) < 2 ** (k/2+1)`. // Using an algorithm similar to the msb conmputation, we are able to compute `result = 2**(k/2)` which is a // good first aproximation of `sqrt(a)` with at least 1 correct bit. uint256 result = 1; uint256 x = a; if (x >> 128 > 0) { x >>= 128; result <<= 64; } if (x >> 64 > 0) { x >>= 64; result <<= 32; } if (x >> 32 > 0) { x >>= 32; result <<= 16; } if (x >> 16 > 0) { x >>= 16; result <<= 8; } if (x >> 8 > 0) { x >>= 8; result <<= 4; } if (x >> 4 > 0) { x >>= 4; result <<= 2; } if (x >> 2 > 0) { result <<= 1; } // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128, // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision // into the expected uint128 result. unchecked { result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; return min(result, a / result); } } /** * @notice Calculates sqrt(a), following the selected rounding direction. */ function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) { uint256 result = sqrt(a); if (rounding == Rounding.Up && result * result < a) { result += 1; } return result; } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; /// @notice Contract that enables a single call to call multiple methods on itself. /// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/Multicallable.sol) /// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/Multicallable.sol) /// @dev WARNING! /// Multicallable is NOT SAFE for use in contracts with checks / requires on `msg.value` /// (e.g. in NFT minting / auction contracts) without a suitable nonce mechanism. /// It WILL open up your contract to double-spend vulnerabilities / exploits. /// See: (https://www.paradigm.xyz/2021/08/two-rights-might-make-a-wrong/) abstract contract Multicallable { function multicall(bytes[] calldata data) public payable returns (bytes[] memory results) { assembly { if data.length { results := mload(0x40) // Point `results` to start of free memory. mstore(results, data.length) // Store `data.length` into `results`. results := add(results, 0x20) // `shl` 5 is equivalent to multiplying by 0x20. let end := shl(5, data.length) // Copy the offsets from calldata into memory. calldatacopy(results, data.offset, end) // Pointer to the top of the memory (i.e. start of the free memory). let memPtr := add(results, end) end := add(results, end) // prettier-ignore for {} 1 {} { // The offset of the current bytes in the calldata. let o := add(data.offset, mload(results)) // Copy the current bytes from calldata to the memory. calldatacopy( memPtr, add(o, 0x20), // The offset of the current bytes' bytes. calldataload(o) // The length of the current bytes. ) if iszero(delegatecall(gas(), address(), memPtr, calldataload(o), 0x00, 0x00)) { // Bubble up the revert if the delegatecall reverts. returndatacopy(0x00, 0x00, returndatasize()) revert(0x00, returndatasize()) } // Append the current `memPtr` into `results`. mstore(results, memPtr) results := add(results, 0x20) // Append the `returndatasize()`, and the return data. mstore(memPtr, returndatasize()) returndatacopy(add(memPtr, 0x20), 0x00, returndatasize()) // Advance the `memPtr` by `returndatasize() + 0x20`, // rounded up to the next multiple of 32. memPtr := and(add(add(memPtr, returndatasize()), 0x3f), 0xffffffffffffffe0) // prettier-ignore if iszero(lt(results, end)) { break } } // Restore `results` and allocate memory for it. results := mload(0x40) mstore(0x40, memPtr) } } } }
// 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/Rari-Capital/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 immutable decimals; /*////////////////////////////////////////////////////////////// ERC20 STORAGE //////////////////////////////////////////////////////////////*/ uint256 public totalSupply; mapping(address => uint256) public balanceOf; mapping(address => mapping(address => uint256)) public allowance; /*////////////////////////////////////////////////////////////// EIP-2612 STORAGE //////////////////////////////////////////////////////////////*/ uint256 internal immutable INITIAL_CHAIN_ID; bytes32 internal immutable 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; /// @notice Arithmetic library with operations for fixed-point numbers. /// @author Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/utils/FixedPointMathLib.sol) /// @author Inspired by USM (https://github.com/usmfum/USM/blob/master/contracts/WadMath.sol) library FixedPointMathLib { /*////////////////////////////////////////////////////////////// SIMPLIFIED FIXED POINT OPERATIONS //////////////////////////////////////////////////////////////*/ uint256 internal 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 mulWadUp(uint256 x, uint256 y) internal pure returns (uint256) { return mulDivUp(x, y, WAD); // Equivalent to (x * y) / WAD rounded up. } function divWadDown(uint256 x, uint256 y) internal pure returns (uint256) { return mulDivDown(x, WAD, y); // Equivalent to (x * WAD) / y rounded down. } function divWadUp(uint256 x, uint256 y) internal pure returns (uint256) { return mulDivUp(x, WAD, y); // Equivalent to (x * WAD) / y rounded up. } /*////////////////////////////////////////////////////////////// LOW LEVEL FIXED POINT OPERATIONS //////////////////////////////////////////////////////////////*/ 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)) } } function rpow( uint256 x, uint256 n, uint256 scalar ) internal pure returns (uint256 z) { assembly { switch x case 0 { switch n case 0 { // 0 ** 0 = 1 z := scalar } default { // 0 ** n = 0 z := 0 } } default { switch mod(n, 2) case 0 { // If n is even, store scalar in z for now. z := scalar } default { // If n is odd, store x in z for now. z := x } // Shifting right by 1 is like dividing by 2. let half := shr(1, scalar) for { // Shift n right by 1 before looping to halve it. n := shr(1, n) } n { // Shift n right by 1 each iteration to halve it. n := shr(1, n) } { // Revert immediately if x ** 2 would overflow. // Equivalent to iszero(eq(div(xx, x), x)) here. if shr(128, x) { revert(0, 0) } // Store x squared. let xx := mul(x, x) // Round to the nearest number. let xxRound := add(xx, half) // Revert if xx + half overflowed. if lt(xxRound, xx) { revert(0, 0) } // Set x to scaled xxRound. x := div(xxRound, scalar) // If n is even: if mod(n, 2) { // Compute z * x. let zx := mul(z, x) // If z * x overflowed: if iszero(eq(div(zx, x), z)) { // Revert if x is non-zero. if iszero(iszero(x)) { revert(0, 0) } } // Round to the nearest number. let zxRound := add(zx, half) // Revert if zx + half overflowed. if lt(zxRound, zx) { revert(0, 0) } // Return properly scaled zxRound. z := div(zxRound, scalar) } } } } } /*////////////////////////////////////////////////////////////// GENERAL NUMBER UTILITIES //////////////////////////////////////////////////////////////*/ function sqrt(uint256 x) internal pure returns (uint256 z) { assembly { // Start off with z at 1. z := 1 // Used below to help find a nearby power of 2. let y := x // Find the lowest power of 2 that is at least sqrt(x). if iszero(lt(y, 0x100000000000000000000000000000000)) { y := shr(128, y) // Like dividing by 2 ** 128. z := shl(64, z) // Like multiplying by 2 ** 64. } if iszero(lt(y, 0x10000000000000000)) { y := shr(64, y) // Like dividing by 2 ** 64. z := shl(32, z) // Like multiplying by 2 ** 32. } if iszero(lt(y, 0x100000000)) { y := shr(32, y) // Like dividing by 2 ** 32. z := shl(16, z) // Like multiplying by 2 ** 16. } if iszero(lt(y, 0x10000)) { y := shr(16, y) // Like dividing by 2 ** 16. z := shl(8, z) // Like multiplying by 2 ** 8. } if iszero(lt(y, 0x100)) { y := shr(8, y) // Like dividing by 2 ** 8. z := shl(4, z) // Like multiplying by 2 ** 4. } if iszero(lt(y, 0x10)) { y := shr(4, y) // Like dividing by 2 ** 4. z := shl(2, z) // Like multiplying by 2 ** 2. } if iszero(lt(y, 0x8)) { // Equivalent to 2 ** z. z := shl(1, z) } // Shifting right by 1 is like dividing by 2. z := shr(1, add(z, div(x, z))) z := shr(1, add(z, div(x, z))) z := shr(1, add(z, div(x, z))) z := shr(1, add(z, div(x, z))) z := shr(1, add(z, div(x, z))) z := shr(1, add(z, div(x, z))) z := shr(1, add(z, div(x, z))) // Compute a rounded down version of z. let zRoundDown := div(x, z) // If zRoundDown is smaller, use it. if lt(zRoundDown, z) { z := zRoundDown } } } }
// SPDX-License-Identifier: AGPL-3.0-only pragma solidity >=0.8.0; import {ERC20} from "../tokens/ERC20.sol"; /// @notice Safe ETH and ERC20 transfer library that gracefully handles missing return values. /// @author Solmate (https://github.com/Rari-Capital/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: BUSL-1.1 pragma solidity =0.8.16; interface IWETH { function deposit() external payable; function transfer(address to, uint256 value) external returns (bool); function withdraw(uint256) external; }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity =0.8.16; /* solhint-disable func-visibility */ function uncheckedInc(uint256 i) pure returns (uint256) { unchecked { return i + 1; } }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity =0.8.16; import {ERC20} from "solmate/src/tokens/ERC20.sol"; import {AffineVault} from "src/vaults/AffineVault.sol"; import {SafeTransferLib} from "solmate/src/utils/SafeTransferLib.sol"; import {Strings} from "@openzeppelin/contracts/utils/Strings.sol"; /// @notice Base strategy contract abstract contract BaseStrategy { using SafeTransferLib for ERC20; constructor(AffineVault _vault) { vault = _vault; asset = ERC20(_vault.asset()); } /// @notice The vault which will deposit/withdraw from the this contract AffineVault public immutable vault; modifier onlyVault() { require(msg.sender == address(vault), "BS: only vault"); _; } modifier onlyGovernance() { require(msg.sender == vault.governance(), "BS: only governance"); _; } /// @notice Returns the underlying ERC20 asset the strategy accepts. ERC20 public immutable asset; /// @notice Strategy's balance of underlying asset. /// @return assets Strategy's balance. function balanceOfAsset() public view returns (uint256 assets) { assets = asset.balanceOf(address(this)); } /// @notice Deposit vault's underlying asset into strategy. /// @param amount The amount to invest. /// @dev This function must revert if investment fails. function invest(uint256 amount) external { asset.safeTransferFrom(msg.sender, address(this), amount); _afterInvest(amount); } /// @notice After getting money from the vault, do something with it. /// @param amount The amount received from the vault. /// @dev Since investment is often gas-intensive and may require off-chain data, this will often be unimplemented. /// @dev Strategists will call custom functions for handling deployment of capital. function _afterInvest(uint256 amount) internal virtual {} /// @notice Withdraw vault's underlying asset from strategy. /// @param amount The amount to withdraw. /// @return The amount of `asset` divested from the strategy function divest(uint256 amount) external onlyVault returns (uint256) { return _divest(amount); } /// @dev This function should not revert if we get less than `amount` out of the strategy function _divest(uint256 amount) internal virtual returns (uint256) {} /// @notice The total amount of `asset` that the strategy is managing /// @dev This should not overestimate, and should account for slippage during divestment /// @return The strategy tvl function totalLockedValue() external virtual returns (uint256); function sweep(ERC20 token) external onlyGovernance { token.safeTransfer(vault.governance(), token.balanceOf(address(this))); } }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity =0.8.16; contract AffineGovernable { /// @notice The governance address address public governance; modifier onlyGovernance() { _onlyGovernance(); _; } function _onlyGovernance() internal view { require(msg.sender == governance, "Only Governance."); } }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity =0.8.16; abstract contract DetailedShare { /** * @notice A representation of a floating point number. * `decimals` is the number of digits before the where the decimal point would be placeds */ struct Number { uint256 num; uint8 decimals; } /// @notice The tvl is a dollar amount representing the total value locked in the vault. function detailedTVL() external virtual returns (Number memory); /** * @notice The number of dollars that "one" share is worth. * @dev "One" share is always 1 * 10 ^ (decimals). Note that `decimals` refers * to the ERC20 property. */ function detailedPrice() external virtual returns (Number memory); /** * @notice The total supply of the token. The value of Number.num here is the same as `totalSupply()` * @dev detailedTVL() / detailedTotalSupply() == detailedPrice() */ function detailedTotalSupply() external virtual returns (Number memory); }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity =0.8.16; import {AccessControlUpgradeable} from "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol"; import {Math} from "@openzeppelin/contracts/utils/math/Math.sol"; import {ERC20} from "solmate/src/tokens/ERC20.sol"; import {SafeTransferLib} from "solmate/src/utils/SafeTransferLib.sol"; import {Multicallable} from "solady/src/utils/Multicallable.sol"; import {AffineGovernable} from "src/utils/AffineGovernable.sol"; import {BaseStrategy as Strategy} from "src/strategies/BaseStrategy.sol"; import {uncheckedInc} from "src/libs/Unchecked.sol"; /** * @notice A core contract to be inherited by the L1 and L2 vault contracts. This contract handles adding * and removing strategies, investing in (and divesting from) strategies, harvesting gains/losses, and * strategy liquidation. */ contract AffineVault is AffineGovernable, AccessControlUpgradeable, Multicallable { using SafeTransferLib for ERC20; /*////////////////////////////////////////////////////////////// INITIALIZATION //////////////////////////////////////////////////////////////*/ ERC20 _asset; /// @notice The token that the vault takes in and tries to get more of, e.g. USDC function asset() public view virtual returns (address) { return address(_asset); } /** * @dev Initialize the vault. * @param _governance The governance address. * @param vaultAsset The vault's input asset. */ function baseInitialize(address _governance, ERC20 vaultAsset) internal virtual { governance = _governance; _asset = vaultAsset; // All roles use the default admin role // Governance has the admin role and all roles _grantRole(DEFAULT_ADMIN_ROLE, governance); _grantRole(HARVESTER, governance); lastHarvest = uint128(block.timestamp); } /*////////////////////////////////////////////////////////////// AUTHENTICATION //////////////////////////////////////////////////////////////*/ /// @notice Role with authority to call "harvest", i.e. update this vault's tvl bytes32 public constant HARVESTER = keccak256("HARVESTER"); /*////////////////////////////////////////////////////////////// WITHDRAWAL QUEUE //////////////////////////////////////////////////////////////*/ uint8 constant MAX_STRATEGIES = 20; /** * @notice An ordered array of strategies representing the withdrawal queue. The withdrawal queue is used * whenever the vault wants to pull money out of strategies. * @dev The first strategy in the array (index 0) is withdrawn from first. * This is a list of the currently active strategies (all non-zero addresses are active). */ Strategy[MAX_STRATEGIES] public withdrawalQueue; /** * @notice Gets the full withdrawal queue. * @return The withdrawal queue. * @dev This gives easy access to the whole array (by default we can only get one index at a time) */ function getWithdrawalQueue() external view returns (Strategy[MAX_STRATEGIES] memory) { return withdrawalQueue; } /** * @notice Sets a new withdrawal queue. * @param newQueue The new withdrawal queue. */ function setWithdrawalQueue(Strategy[MAX_STRATEGIES] calldata newQueue) external onlyGovernance { // Maintain queue size require(newQueue.length == MAX_STRATEGIES, "BV: bad qu size"); // Replace the withdrawal queue. withdrawalQueue = newQueue; emit WithdrawalQueueSet(newQueue); } /** * @notice Emitted when the withdrawal queue is updated. * @param newQueue The new withdrawal queue. */ event WithdrawalQueueSet(Strategy[MAX_STRATEGIES] newQueue); /*////////////////////////////////////////////////////////////// STRATEGIES //////////////////////////////////////////////////////////////*/ /// @notice The total amount of underlying assets held in strategies at the time of the last harvest. uint256 public totalStrategyHoldings; struct StrategyInfo { bool isActive; uint16 tvlBps; uint232 balance; } /// @notice A map of strategy addresses to details mapping(Strategy => StrategyInfo) public strategies; uint256 constant MAX_BPS = 10_000; /// @notice The number of bps of the vault's tvl which may be given to strategies (at most MAX_BPS) uint256 public totalBps; /// @notice Emitted when a strategy is added by governance event StrategyAdded(Strategy indexed strategy); /// @notice Emitted when a strategy is removed by governance event StrategyRemoved(Strategy indexed strategy); /** * @notice Add a strategy * @param strategy The strategy to add * @param tvlBps The number of bps of our tvl the strategy will get when funds are distributed to strategies */ function addStrategy(Strategy strategy, uint16 tvlBps) external onlyGovernance { _increaseTVLBps(tvlBps); strategies[strategy] = StrategyInfo({isActive: true, tvlBps: tvlBps, balance: 0}); // Add strategy to withdrawal queue withdrawalQueue[MAX_STRATEGIES - 1] = strategy; emit StrategyAdded(strategy); _organizeWithdrawalQueue(); } /// @notice A helper function for increasing `totalBps`. Used when adding strategies or updating strategy allocs function _increaseTVLBps(uint256 tvlBps) internal { uint256 newTotalBps = totalBps + tvlBps; require(newTotalBps <= MAX_BPS, "BV: too many bps"); totalBps = newTotalBps; } /** * @notice Push all zero addresses to the end of the array. This function is used whenever a strategy is * added or removed from the withdrawal queue * @dev Relative ordering of non-zero values is maintained. */ function _organizeWithdrawalQueue() internal { // number or empty values we've seen iterating from left to right uint256 offset; for (uint256 i = 0; i < MAX_STRATEGIES; i = uncheckedInc(i)) { Strategy strategy = withdrawalQueue[i]; if (address(strategy) == address(0)) { offset += 1; } else if (offset > 0) { // index of first empty value seen takes on value of `strategy` withdrawalQueue[i - offset] = strategy; withdrawalQueue[i] = Strategy(address(0)); } } } /** * @notice Remove a strategy from the withdrawal queue. Fully divest from the strategy. * @param strategy The strategy to remove * @dev removeStrategy MUST be called with harvest via multicall. This helps get the most accurate tvl numbers * and allows us to add any realized profits to our lockedProfit */ function removeStrategy(Strategy strategy) external onlyGovernance { for (uint256 i = 0; i < MAX_STRATEGIES; i = uncheckedInc(i)) { if (strategy != withdrawalQueue[i]) { continue; } strategies[strategy].isActive = false; // The vault can re-allocate bps to a new strategy totalBps -= strategies[strategy].tvlBps; strategies[strategy].tvlBps = 0; // Remove strategy from withdrawal queue withdrawalQueue[i] = Strategy(address(0)); emit StrategyRemoved(strategy); _organizeWithdrawalQueue(); // Take all money out of strategy. _withdrawFromStrategy(strategy, strategy.totalLockedValue()); break; } } /** * @notice Update tvl bps assigned to the given list of strategies * @param strategyList The list of strategies * @param strategyBps The new bps */ function updateStrategyAllocations(Strategy[] calldata strategyList, uint16[] calldata strategyBps) external onlyRole(HARVESTER) { for (uint256 i = 0; i < strategyList.length; i = uncheckedInc(i)) { // Get the strategy at the current index. Strategy strategy = strategyList[i]; // Ignore inactive (removed) strategies if (!strategies[strategy].isActive) continue; // update tvl bps totalBps -= strategies[strategy].tvlBps; _increaseTVLBps(strategyBps[i]); strategies[strategy].tvlBps = strategyBps[i]; } emit StrategyAllocsUpdated(strategyList, strategyBps); } /** * @notice Emitted when we update tvl bps for a list of strategies. * @param strategyList The list of strategies. * @param strategyBps The new tvl bps for the strategies */ event StrategyAllocsUpdated(Strategy[] strategyList, uint16[] strategyBps); /*////////////////////////////////////////////////////////////// STRATEGY DEPOSIT/WITHDRAWAL //////////////////////////////////////////////////////////////*/ /** * @notice Emitted after the Vault deposits into a strategy contract. * @param strategy The strategy that was deposited into. * @param assets The amount of assets deposited. */ event StrategyDeposit(Strategy indexed strategy, uint256 assets); /** * @notice Emitted after the Vault withdraws funds from a strategy contract. * @param strategy The strategy that was withdrawn from. * @param assetsRequested The amount of assets we tried to divest from the strategy. * @param assetsReceived The amount of assets actually withdrawn. */ event StrategyWithdrawal(Strategy indexed strategy, uint256 assetsRequested, uint256 assetsReceived); /// @notice Deposit `assetAmount` amount of `asset` into strategies according to each strategy's `tvlBps`. function _depositIntoStrategies(uint256 assetAmount) internal { // All non-zero strategies are active for (uint256 i = 0; i < MAX_STRATEGIES; i = uncheckedInc(i)) { Strategy strategy = withdrawalQueue[i]; if (address(strategy) == address(0)) { break; } _depositIntoStrategy(strategy, (assetAmount * strategies[strategy].tvlBps) / MAX_BPS); } } function _depositIntoStrategy(Strategy strategy, uint256 assets) internal { // Don't allow empty investments if (assets == 0) return; // Increase totalStrategyHoldings to account for the deposit. totalStrategyHoldings += assets; unchecked { // Without this the next harvest would count the deposit as profit. // Cannot overflow as the balance of one strategy can't exceed the sum of all. strategies[strategy].balance += uint232(assets); } // Approve assets to the strategy so we can deposit. _asset.safeApprove(address(strategy), assets); // Deposit into the strategy, will revert upon failure strategy.invest(assets); emit StrategyDeposit(strategy, assets); } /** * @notice Withdraw a specific amount of underlying tokens from a strategy. * @dev This is a "best effort" withdrawal. It could potentially withdraw nothing. * @param strategy The strategy to withdraw from. * @param assets The amount of underlying tokens to withdraw. * @return The amount of assets actually received. */ function _withdrawFromStrategy(Strategy strategy, uint256 assets) internal returns (uint256) { // Withdraw from the strategy uint256 amountWithdrawn = _divest(strategy, assets); // Without this the next harvest would count the withdrawal as a loss. // We update the balance to the current tvl because a withdrawal can reduce the tvl by more than the amount // withdrawn (e.g. fees during a swap) uint256 oldStratTVL = strategies[strategy].balance; uint256 newStratTvl = strategy.totalLockedValue(); strategies[strategy].balance = uint232(newStratTvl); // Decrease totalStrategyHoldings to account for the withdrawal. // If we haven't harvested in a long time, newStratTvl could be bigger than oldStratTvl totalStrategyHoldings -= oldStratTVL > newStratTvl ? oldStratTVL - newStratTvl : 0; emit StrategyWithdrawal({strategy: strategy, assetsRequested: assets, assetsReceived: amountWithdrawn}); return amountWithdrawn; } /// @dev A small wrapper around divest(). We try-catch to make sure that a bad strategy does not pause withdrawals. function _divest(Strategy strategy, uint256 assets) internal returns (uint256) { try strategy.divest(assets) returns (uint256 amountDivested) { return amountDivested; } catch { return 0; } } /*////////////////////////////////////////////////////////////// HARVESTING //////////////////////////////////////////////////////////////*/ /** * @notice A timestamp representing when the most recent harvest occurred. * @dev Since the time since the last harvest is used to calculate management fees, this is set * to `block.timestamp` (instead of 0) during initialization. */ uint128 public lastHarvest; /// @notice The amount of profit *originally* locked after harvesting from a strategy uint128 public maxLockedProfit; /// @notice Amount of time in seconds that profit takes to fully unlock. See lockedProfit(). uint256 public constant LOCK_INTERVAL = 24 hours; /** * @notice Emitted after a successful harvest. * @param user The authorized user who triggered the harvest. * @param strategies The trusted strategies that were harvested. */ event Harvest(address indexed user, Strategy[] strategies); /** * @notice Harvest a set of trusted strategies. * @param strategyList The trusted strategies to harvest. * @dev Will always revert if profit from last harvest has not finished unlocking. */ function harvest(Strategy[] calldata strategyList) external onlyRole(HARVESTER) { // Profit must not be unlocking require(block.timestamp >= lastHarvest + LOCK_INTERVAL, "BV: profit unlocking"); // Get the Vault's current total strategy holdings. uint256 oldTotalStrategyHoldings = totalStrategyHoldings; // Used to store the new total strategy holdings after harvesting. uint256 newTotalStrategyHoldings = oldTotalStrategyHoldings; // Used to store the total profit accrued by the strategies. uint256 totalProfitAccrued; // Will revert if any of the specified strategies are untrusted. for (uint256 i = 0; i < strategyList.length; i = uncheckedInc(i)) { // Get the strategy at the current index. Strategy strategy = strategyList[i]; // Ignore inactive (removed) strategies if (!strategies[strategy].isActive) { continue; } // Get the strategy's previous and current balance. uint232 balanceLastHarvest = strategies[strategy].balance; uint256 balanceThisHarvest = strategy.totalLockedValue(); // Update the strategy's stored balance. strategies[strategy].balance = uint232(balanceThisHarvest); // Increase/decrease newTotalStrategyHoldings based on the profit/loss registered. // We cannot wrap the subtraction in parenthesis as it would underflow if the strategy had a loss. newTotalStrategyHoldings = newTotalStrategyHoldings + balanceThisHarvest - balanceLastHarvest; unchecked { // Update the total profit accrued while counting losses as zero profit. // Cannot overflow as we already increased total holdings without reverting. totalProfitAccrued += balanceThisHarvest > balanceLastHarvest ? balanceThisHarvest - balanceLastHarvest // Profits since last harvest. : 0; // If the strategy registered a net loss we don't have any new profit. } } // Update max unlocked profit based on any remaining locked profit plus new profit. maxLockedProfit = uint128(lockedProfit() + totalProfitAccrued); // Set strategy holdings to our new total. totalStrategyHoldings = newTotalStrategyHoldings; // Assess fees (using old lastHarvest) and update the last harvest timestamp. _assessFees(); lastHarvest = uint128(block.timestamp); emit Harvest(msg.sender, strategyList); } /** * @notice Current locked profit amount. * @dev Profit unlocks uniformly over `LOCK_INTERVAL` seconds after the last harvest */ function lockedProfit() public view virtual returns (uint256) { if (block.timestamp >= lastHarvest + LOCK_INTERVAL) { return 0; } uint256 unlockedProfit = (maxLockedProfit * (block.timestamp - lastHarvest)) / LOCK_INTERVAL; return maxLockedProfit - unlockedProfit; } /*////////////////////////////////////////////////////////////// LIQUIDATION/REBALANCING //////////////////////////////////////////////////////////////*/ /// @notice The total amount of the underlying asset the vault has. function vaultTVL() public view returns (uint256) { return _asset.balanceOf(address(this)) + totalStrategyHoldings; } /** * @notice Emitted when the vault must make a certain amount of assets available * @dev We liquidate during cross chain rebalancing or withdrawals. * @param assetsRequested The amount we wanted to make available for withdrawal. * @param assetsLiquidated The amount we actually liquidated. */ event Liquidation(uint256 assetsRequested, uint256 assetsLiquidated); /** * @notice Withdraw `amount` of underlying asset from strategies. * @dev Always check the return value when using this function, we might not liquidate anything! * @param amount The amount we want to liquidate * @return The amount we actually liquidated */ function _liquidate(uint256 amount) internal returns (uint256) { uint256 amountLiquidated; for (uint256 i = 0; i < MAX_STRATEGIES; i = uncheckedInc(i)) { Strategy strategy = withdrawalQueue[i]; if (address(strategy) == address(0)) { break; } uint256 balance = _asset.balanceOf(address(this)); if (balance >= amount) { break; } uint256 amountNeeded = amount - balance; amountNeeded = Math.min(amountNeeded, strategies[strategy].balance); // Force withdraw of token from strategy uint256 withdrawn = _withdrawFromStrategy(strategy, amountNeeded); amountLiquidated += withdrawn; } emit Liquidation({assetsRequested: amount, assetsLiquidated: amountLiquidated}); return amountLiquidated; } /** * @notice Assess fees. * @dev This is called during harvest() to assess management fees. */ function _assessFees() internal virtual {} /** * @notice Emitted when we do a strategy rebalance, i.e. when we make the strategy tvls match their tvl bps * @param caller The caller */ event Rebalance(address indexed caller); /// @notice Rebalance strategies according to given tvl bps function rebalance() external onlyRole(HARVESTER) { uint256 tvl = vaultTVL(); // Loop through all strategies. Divesting from those whose tvl is too high, // Invest in those whose tvl is too low // MAX_STRATEGIES is always equal to withdrawalQueue.length uint256[MAX_STRATEGIES] memory amountsToInvest; for (uint256 i = 0; i < MAX_STRATEGIES; i = uncheckedInc(i)) { Strategy strategy = withdrawalQueue[i]; if (address(strategy) == address(0)) { break; } uint256 idealStrategyTVL = (tvl * strategies[strategy].tvlBps) / MAX_BPS; uint256 currStrategyTVL = strategy.totalLockedValue(); if (idealStrategyTVL < currStrategyTVL) { _withdrawFromStrategy(strategy, currStrategyTVL - idealStrategyTVL); } if (idealStrategyTVL > currStrategyTVL) { amountsToInvest[i] = idealStrategyTVL - currStrategyTVL; } } // Loop through the strategies to invest in, and invest in them for (uint256 i = 0; i < MAX_STRATEGIES; i = uncheckedInc(i)) { uint256 amountToInvest = amountsToInvest[i]; if (amountToInvest == 0) { continue; } // We aren't guaranteed that the vault has `amountToInvest` since there can be slippage // when divesting from strategies // NOTE: Strategies closer to the start of the queue are more likely to get the exact // amount of money needed amountToInvest = Math.min(amountToInvest, _asset.balanceOf(address(this))); if (amountToInvest == 0) { break; } // Deposit into strategy, making sure to not count this investment as a profit _depositIntoStrategy(withdrawalQueue[i], amountToInvest); } emit Rebalance(msg.sender); } }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity =0.8.16; import {ERC4626Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC4626Upgradeable.sol"; import {IERC20MetadataUpgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/IERC20MetadataUpgradeable.sol"; import {ERC20Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol"; import {AccessControlUpgradeable} from "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol"; import {MathUpgradeable} from "@openzeppelin/contracts-upgradeable/utils/math/MathUpgradeable.sol"; import {PausableUpgradeable} from "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol"; import {Math} from "@openzeppelin/contracts/utils/math/Math.sol"; import {ERC20} from "solmate/src/tokens/ERC20.sol"; import {SafeTransferLib} from "solmate/src/utils/SafeTransferLib.sol"; import {FixedPointMathLib} from "solmate/src/utils/FixedPointMathLib.sol"; import {AffineVault} from "src/vaults/AffineVault.sol"; import {DetailedShare} from "src/utils/Detailed.sol"; contract Vault is AffineVault, ERC4626Upgradeable, PausableUpgradeable, DetailedShare { using SafeTransferLib for ERC20; using MathUpgradeable for uint256; function initialize(address _governance, address vaultAsset, string memory _name, string memory _symbol) external initializer { AffineVault.baseInitialize(_governance, ERC20(vaultAsset)); __ERC20_init(_name, _symbol); __ERC4626_init(IERC20MetadataUpgradeable(vaultAsset)); _grantRole(GUARDIAN_ROLE, governance); } function asset() public view override(AffineVault, ERC4626Upgradeable) returns (address) { return AffineVault.asset(); } /// @dev E.g. if the asset has 18 decimals, and initialSharesPerAsset is 1e8, then the vault has 26 decimals. And /// "one" `asset` will be worth "one" share (where "one" means 10 ** token.decimals()). function decimals() public view virtual override(ERC20Upgradeable, IERC20MetadataUpgradeable) returns (uint8) { return _asset.decimals() + _initialShareDecimals(); } /// @notice The amount of shares to mint per wei of `asset` at genesis. function initialSharesPerAsset() public pure virtual returns (uint256) { return 10 ** _initialShareDecimals(); } /// @notice Each wei of `asset` at genesis is worth 10 ** (initialShareDecimals) shares. function _initialShareDecimals() internal pure virtual returns (uint8) { return 8; } /// @notice See {IERC4626-totalAssets} function totalAssets() public view virtual override returns (uint256) { return vaultTVL() - lockedProfit(); } bytes32 public constant GUARDIAN_ROLE = keccak256("GUARDIAN"); /// @notice Pause the contract function pause() external onlyRole(GUARDIAN_ROLE) { _pause(); } /// @notice Unpause the contract function unpause() external onlyRole(GUARDIAN_ROLE) { _unpause(); } function maxDeposit(address) public view virtual override returns (uint256) { return type(uint256).max; } /** * @dev See {IERC4262-deposit}. */ function deposit(uint256 assets, address receiver) public virtual override whenNotPaused returns (uint256) { uint256 shares = previewDeposit(assets); _deposit(_msgSender(), receiver, assets, shares); return shares; } /** * @dev See {IERC4262-mint}. */ function mint(uint256 shares, address receiver) public virtual override whenNotPaused returns (uint256) { uint256 assets = previewMint(shares); _deposit(_msgSender(), receiver, assets, shares); return assets; } /** * @dev See {IERC4262-withdraw}. */ function withdraw(uint256 assets, address receiver, address owner) public virtual override whenNotPaused returns (uint256) { uint256 shares = _convertToShares(assets, MathUpgradeable.Rounding.Up); _withdraw(_msgSender(), receiver, owner, assets, shares); return shares; } /** * @dev See {IERC4262-redeem}. */ function redeem(uint256 shares, address receiver, address owner) public virtual override whenNotPaused returns (uint256) { uint256 assets = _convertToAssets(shares, MathUpgradeable.Rounding.Down); _withdraw(_msgSender(), receiver, owner, assets, shares); return assets; } function _deposit(address caller, address receiver, uint256 assets, uint256 shares) internal virtual override { require(shares > 0, "Vault: zero shares"); _mint(receiver, shares); _asset.safeTransferFrom(caller, address(this), assets); emit Deposit(caller, receiver, assets, shares); } function _withdraw(address caller, address receiver, address owner, uint256 assets, uint256 shares) internal virtual override { _liquidate(assets); // Slippage during liquidation means we might get less than `assets` amount of `_asset` assets = Math.min(_asset.balanceOf(address(this)), assets); uint256 assetsFee = _getWithdrawalFee(assets); uint256 assetsToUser = assets - assetsFee; // Burn shares and give user equivalent value in `_asset` (minus withdrawal fees) if (caller != owner) _spendAllowance(owner, caller, shares); _burn(owner, shares); emit Withdraw(caller, receiver, owner, assets, shares); _asset.safeTransfer(receiver, assetsToUser); _asset.safeTransfer(governance, assetsFee); } /*////////////////////////////////////////////////////////////// EXCHANGE RATES //////////////////////////////////////////////////////////////*/ /** * @dev See {IERC4262-previewWithdraw}. */ function previewWithdraw(uint256 assetsToUser) public view virtual override returns (uint256) { // assets * ((1e4 - feeBps) / 1e4) = assetsToUser uint256 assets = assetsToUser.mulDiv(MAX_BPS, MAX_BPS - withdrawalFee, MathUpgradeable.Rounding.Up); return _convertToShares(assets, MathUpgradeable.Rounding.Up); } /** * @dev See {IERC4262-previewRedeem}. */ function previewRedeem(uint256 shares) public view virtual override returns (uint256) { uint256 assets = _convertToAssets(shares, MathUpgradeable.Rounding.Down); return assets - _getWithdrawalFee(assets); } function _convertToShares(uint256 assets, MathUpgradeable.Rounding rounding) internal view virtual override returns (uint256 shares) { uint256 _totalSupply = totalSupply() + initialSharesPerAsset(); uint256 _totalAssets = totalAssets() + 1; return assets.mulDiv(_totalSupply, _totalAssets, rounding); } function _convertToAssets(uint256 shares, MathUpgradeable.Rounding rounding) internal view virtual override returns (uint256 assets) { uint256 _totalSupply = totalSupply() + initialSharesPerAsset(); uint256 _totalAssets = totalAssets() + 1; return shares.mulDiv(_totalAssets, _totalSupply, rounding); } /*////////////////////////////////////////////////////////////// FEES //////////////////////////////////////////////////////////////*/ /// @notice Fee charged to vault over a year, number is in bps uint256 public managementFee; /// @notice Fee charged on redemption of shares, number is in bps uint256 public withdrawalFee; event ManagementFeeSet(uint256 oldFee, uint256 newFee); event WithdrawalFeeSet(uint256 oldFee, uint256 newFee); function setManagementFee(uint256 feeBps) external onlyGovernance { emit ManagementFeeSet({oldFee: managementFee, newFee: feeBps}); managementFee = feeBps; } function setWithdrawalFee(uint256 feeBps) external onlyGovernance { emit WithdrawalFeeSet({oldFee: withdrawalFee, newFee: feeBps}); withdrawalFee = feeBps; } uint256 constant SECS_PER_YEAR = 365 days; function _assessFees() internal virtual override { // duration / SECS_PER_YEAR * feebps / MAX_BPS * totalSupply uint256 duration = block.timestamp - lastHarvest; uint256 feesBps = (duration * managementFee) / SECS_PER_YEAR; uint256 numSharesToMint = (feesBps * totalSupply()) / MAX_BPS; if (numSharesToMint == 0) { return; } _mint(governance, numSharesToMint); } /// @dev Return amount of `asset` to be given to user after applying withdrawal fee function _getWithdrawalFee(uint256 assets) internal view virtual returns (uint256) { return assets.mulDiv(withdrawalFee, MAX_BPS, MathUpgradeable.Rounding.Up); } /*////////////////////////////////////////////////////////////// CAPITAL MANAGEMENT //////////////////////////////////////////////////////////////*/ /** * @notice Deposit idle assets into strategies. */ function depositIntoStrategies(uint256 amount) external whenNotPaused onlyRole(HARVESTER) { // Deposit entire balance of `_asset` into strategies _depositIntoStrategies(amount); } /*////////////////////////////////////////////////////////////// DETAILED PRICE INFO //////////////////////////////////////////////////////////////*/ function detailedTVL() external view override returns (Number memory tvl) { tvl = Number({num: totalAssets(), decimals: _asset.decimals()}); } function detailedPrice() external view override returns (Number memory price) { price = Number({num: convertToAssets(10 ** decimals()), decimals: _asset.decimals()}); } function detailedTotalSupply() external view override returns (Number memory supply) { supply = Number({num: totalSupply(), decimals: decimals()}); } }
{ "remappings": [ "@opengsn/=node_modules/@opengsn/", "@openzeppelin/=node_modules/@openzeppelin/", "@uniswap/=node_modules/@uniswap/", "base64-sol/=node_modules/base64-sol/", "ds-test/=lib/forge-std/lib/ds-test/src/", "forge-std/=lib/forge-std/src/", "hardhat/=node_modules/hardhat/", "script/=script/", "solady/=node_modules/solady/", "solmate/=node_modules/solmate/", "src/=src/" ], "optimizer": { "enabled": true, "runs": 2000000 }, "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
[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","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":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"contract BaseStrategy[]","name":"strategies","type":"address[]"}],"name":"Harvest","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"assetsRequested","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"assetsLiquidated","type":"uint256"}],"name":"Liquidation","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"oldFee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newFee","type":"uint256"}],"name":"ManagementFeeSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"caller","type":"address"}],"name":"Rebalance","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"previousAdminRole","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"newAdminRole","type":"bytes32"}],"name":"RoleAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleRevoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"contract BaseStrategy","name":"strategy","type":"address"}],"name":"StrategyAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract BaseStrategy[]","name":"strategyList","type":"address[]"},{"indexed":false,"internalType":"uint16[]","name":"strategyBps","type":"uint16[]"}],"name":"StrategyAllocsUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"contract BaseStrategy","name":"strategy","type":"address"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"}],"name":"StrategyDeposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"contract BaseStrategy","name":"strategy","type":"address"}],"name":"StrategyRemoved","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"contract BaseStrategy","name":"strategy","type":"address"},{"indexed":false,"internalType":"uint256","name":"assetsRequested","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"assetsReceived","type":"uint256"}],"name":"StrategyWithdrawal","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":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","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"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"oldFee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newFee","type":"uint256"}],"name":"WithdrawalFeeSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract BaseStrategy[20]","name":"newQueue","type":"address[20]"}],"name":"WithdrawalQueueSet","type":"event"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"GUARDIAN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"HARVESTER","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"LOCK_INTERVAL","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract BaseStrategy","name":"strategy","type":"address"},{"internalType":"uint16","name":"tvlBps","type":"uint16"}],"name":"addStrategy","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","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":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","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":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"address","name":"receiver","type":"address"}],"name":"deposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"depositIntoStrategies","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"detailedPrice","outputs":[{"components":[{"internalType":"uint256","name":"num","type":"uint256"},{"internalType":"uint8","name":"decimals","type":"uint8"}],"internalType":"struct DetailedShare.Number","name":"price","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"detailedTVL","outputs":[{"components":[{"internalType":"uint256","name":"num","type":"uint256"},{"internalType":"uint8","name":"decimals","type":"uint8"}],"internalType":"struct DetailedShare.Number","name":"tvl","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"detailedTotalSupply","outputs":[{"components":[{"internalType":"uint256","name":"num","type":"uint256"},{"internalType":"uint8","name":"decimals","type":"uint8"}],"internalType":"struct DetailedShare.Number","name":"supply","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getWithdrawalQueue","outputs":[{"internalType":"contract BaseStrategy[20]","name":"","type":"address[20]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"governance","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"grantRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract BaseStrategy[]","name":"strategyList","type":"address[]"}],"name":"harvest","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"initialSharesPerAsset","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"_governance","type":"address"},{"internalType":"address","name":"vaultAsset","type":"address"},{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_symbol","type":"string"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"lastHarvest","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lockedProfit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"managementFee","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":[],"name":"maxLockedProfit","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"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":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes[]","name":"data","type":"bytes[]"}],"name":"multicall","outputs":[{"internalType":"bytes[]","name":"results","type":"bytes[]"}],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"name":"previewDeposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"name":"previewMint","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"name":"previewRedeem","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"assetsToUser","type":"uint256"}],"name":"previewWithdraw","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rebalance","outputs":[],"stateMutability":"nonpayable","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":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract BaseStrategy","name":"strategy","type":"address"}],"name":"removeStrategy","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"feeBps","type":"uint256"}],"name":"setManagementFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"feeBps","type":"uint256"}],"name":"setWithdrawalFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract BaseStrategy[20]","name":"newQueue","type":"address[20]"}],"name":"setWithdrawalQueue","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract BaseStrategy","name":"","type":"address"}],"name":"strategies","outputs":[{"internalType":"bool","name":"isActive","type":"bool"},{"internalType":"uint16","name":"tvlBps","type":"uint16"},{"internalType":"uint232","name":"balance","type":"uint232"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalAssets","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalBps","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalStrategyHoldings","outputs":[{"internalType":"uint256","name":"","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":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract BaseStrategy[]","name":"strategyList","type":"address[]"},{"internalType":"uint16[]","name":"strategyBps","type":"uint16[]"}],"name":"updateStrategyAllocations","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"vaultTVL","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"weth","outputs":[{"internalType":"contract IWETH","name":"","type":"address"}],"stateMutability":"pure","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":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"withdrawalFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"withdrawalQueue","outputs":[{"internalType":"contract BaseStrategy","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"stateMutability":"payable","type":"receive"}]
Contract Creation Code
608060405234801561001057600080fd5b5061587f80620000216000396000f3fe6080604052600436106104335760003560e01c80637d7c2a1c11610228578063c6e6f59211610128578063d905777e116100bb578063f1a392da1161008a578063f26edf351161006f578063f26edf3514610d95578063f6df5a7814610daa578063fe56e23214610dbf57600080fd5b8063f1a392da14610d56578063f20dd15d14610d7f57600080fd5b8063d905777e14610ccd578063dd62ed3e14610ced578063ecad956514610d40578063ef8b30f714610b7b57600080fd5b8063ce96cb77116100f7578063ce96cb7714610c0f578063d00364be14610c2f578063d11f519c14610c8d578063d547741f14610cad57600080fd5b8063c6e6f59214610b7b578063c822adda14610b9b578063c89d346014610bbb578063cb9d9fa714610bdb57600080fd5b8063a457c2d7116101bb578063ac9650d81161018a578063b460af941161016f578063b460af9414610b3b578063ba08765214610b5b578063c63d75b61461080757600080fd5b8063ac9650d814610afb578063b3d7f6b914610b1b57600080fd5b8063a457c2d714610a84578063a6f7f5d614610aa4578063a9059cbb14610abb578063ac1e502514610adb57600080fd5b806394148415116101f75780639414841514610a1a57806394bf804d14610a3a57806395d89b4114610a5a578063a217fddf14610a6f57600080fd5b80637d7c2a1c146109865780638456cb591461099b5780638bc7e8c4146109b057806391d14854146109c757600080fd5b806336568abe116103335780634cdad506116102c65780635da6a6911161029557806368bb9a971161027a57806368bb9a971461090c5780636e553f651461092357806370a082311461094357600080fd5b80635da6a691146108d75780636071abed146108f757600080fd5b80634cdad5061461085c5780634e637ba91461087c5780635aa6e675146108915780635c975abb146108be57600080fd5b80633f4ba83a116103025780633f4ba83a146107cb5780633fc8cef3146107e0578063402d267d1461080757806344b813961461084757600080fd5b806336568abe146106b057806338d52e0f146106d0578063395093511461070a57806339ebf8231461072a57600080fd5b80630e73ecef116103c657806323b872dd1161039557806324ea54f41161037a57806324ea54f4146106355780632f2ff15d14610669578063313ce5671461068957600080fd5b806323b872dd146105e5578063248a9ca31461060557600080fd5b80630e73ecef1461056e578063175188e81461059057806318160ddd146105b05780632016a0d2146105c557600080fd5b806306fdde031161040257806306fdde03146104ec57806307a2d13a1461050e578063095ea7b31461052e5780630a28a4771461054e57600080fd5b806301106d4d1461043f57806301e1d1141461047757806301ffc9a71461049a57806305efa876146104ca57600080fd5b3661043a57005b600080fd5b34801561044b57600080fd5b50610454610ddf565b604080518251815260209283015160ff1692810192909252015b60405180910390f35b34801561048357600080fd5b5061048c610eb5565b60405190815260200161046e565b3480156104a657600080fd5b506104ba6104b5366004614bf1565b610ed6565b604051901515815260200161046e565b3480156104d657600080fd5b506104ea6104e5366004614c33565b610f6f565b005b3480156104f857600080fd5b50610501610fae565b60405161046e9190614cba565b34801561051a57600080fd5b5061048c610529366004614c33565b611040565b34801561053a57600080fd5b506104ba610549366004614cef565b61104d565b34801561055a57600080fd5b5061048c610569366004614c33565b611065565b34801561057a57600080fd5b5061058361109d565b60405161046e9190614d1b565b34801561059c57600080fd5b506104ea6105ab366004614d63565b6110f0565b3480156105bc57600080fd5b5060b25461048c565b3480156105d157600080fd5b506104ea6105e0366004614e5a565b611301565b3480156105f157600080fd5b506104ba610600366004614ee3565b611561565b34801561061157600080fd5b5061048c610620366004614c33565b60009081526065602052604090206001015490565b34801561064157600080fd5b5061048c7f8b5b16d04624687fcf0d0228f19993c9157c1ed07b41d8d430fd9100eb099fe881565b34801561067557600080fd5b506104ea610684366004614f24565b611585565b34801561069557600080fd5b5061069e6115aa565b60405160ff909116815260200161046e565b3480156106bc57600080fd5b506104ea6106cb366004614f24565b611649565b3480156106dc57600080fd5b506106e56116f8565b60405173ffffffffffffffffffffffffffffffffffffffff909116815260200161046e565b34801561071657600080fd5b506104ba610725366004614cef565b611719565b34801561073657600080fd5b5061078c610745366004614d63565b60ad6020526000908152604090205460ff811690610100810461ffff1690630100000090047cffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1683565b60408051931515845261ffff90921660208401527cffffffffffffffffffffffffffffffffffffffffffffffffffffffffff169082015260600161046e565b3480156107d757600080fd5b506104ea611765565b3480156107ec57600080fd5b5073c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26106e5565b34801561081357600080fd5b5061048c610822366004614d63565b507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff90565b34801561085357600080fd5b5061048c61179a565b34801561086857600080fd5b5061048c610877366004614c33565b61186d565b34801561088857600080fd5b5061048c611890565b34801561089d57600080fd5b506000546106e59073ffffffffffffffffffffffffffffffffffffffff1681565b3480156108ca57600080fd5b506101145460ff166104ba565b3480156108e357600080fd5b506104ea6108f2366004614fa0565b611931565b34801561090357600080fd5b50610454611b03565b34801561091857600080fd5b5061048c6201518081565b34801561092f57600080fd5b5061048c61093e366004614f24565b611b2a565b34801561094f57600080fd5b5061048c61095e366004614d63565b73ffffffffffffffffffffffffffffffffffffffff16600090815260b0602052604090205490565b34801561099257600080fd5b506104ea611b4d565b3480156109a757600080fd5b506104ea611e37565b3480156109bc57600080fd5b5061048c6101475481565b3480156109d357600080fd5b506104ba6109e2366004614f24565b600091825260656020908152604080842073ffffffffffffffffffffffffffffffffffffffff93909316845291905290205460ff1690565b348015610a2657600080fd5b506104ea610a3536600461500c565b611e69565b348015610a4657600080fd5b5061048c610a55366004614f24565b611eb9565b348015610a6657600080fd5b50610501611edc565b348015610a7b57600080fd5b5061048c600081565b348015610a9057600080fd5b506104ba610a9f366004614cef565b611eeb565b348015610ab057600080fd5b5061048c6101465481565b348015610ac757600080fd5b506104ba610ad6366004614cef565b611fbc565b348015610ae757600080fd5b506104ea610af6366004614c33565b611fca565b610b0e610b09366004615037565b612015565b60405161046e9190615079565b348015610b2757600080fd5b5061048c610b36366004614c33565b612091565b348015610b4757600080fd5b5061048c610b563660046150f9565b61209e565b348015610b6757600080fd5b5061048c610b763660046150f9565b6120cc565b348015610b8757600080fd5b5061048c610b96366004614c33565b6120f2565b348015610ba757600080fd5b506106e5610bb6366004614c33565b6120ff565b348015610bc757600080fd5b506104ea610bd6366004615037565b61212c565b348015610be757600080fd5b5061048c7f27e3e4d29d60af3ae6456513164bb5db737d6fc8610aa36ad458736c9efb884c81565b348015610c1b57600080fd5b5061048c610c2a366004614d63565b6124c0565b348015610c3b57600080fd5b5060af54610c6c9070010000000000000000000000000000000090046fffffffffffffffffffffffffffffffff1681565b6040516fffffffffffffffffffffffffffffffff909116815260200161046e565b348015610c9957600080fd5b506104ea610ca8366004615152565b6124f1565b348015610cb957600080fd5b506104ea610cc8366004614f24565b612678565b348015610cd957600080fd5b5061048c610ce8366004614d63565b61269d565b348015610cf957600080fd5b5061048c610d08366004615187565b73ffffffffffffffffffffffffffffffffffffffff918216600090815260b16020908152604080832093909416825291909152205490565b348015610d4c57600080fd5b5061048c60ac5481565b348015610d6257600080fd5b5060af54610c6c906fffffffffffffffffffffffffffffffff1681565b348015610d8b57600080fd5b5061048c60ae5481565b348015610da157600080fd5b506104546126c8565b348015610db657600080fd5b5061048c6126fd565b348015610dcb57600080fd5b506104ea610dda366004614c33565b61270b565b60408051808201909152600080825260208201526040518060400160405280610e14610e096115aa565b61052990600a615304565b8152609754604080517f313ce567000000000000000000000000000000000000000000000000000000008152905160209384019373ffffffffffffffffffffffffffffffffffffffff9093169263313ce56792600480820193918290030181865afa158015610e87573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610eab9190615313565b60ff169052919050565b6000610ebf61179a565b610ec7611890565b610ed19190615336565b905090565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f7965db0b000000000000000000000000000000000000000000000000000000001480610f6957507f01ffc9a7000000000000000000000000000000000000000000000000000000007fffffffff000000000000000000000000000000000000000000000000000000008316145b92915050565b610f77612756565b7f27e3e4d29d60af3ae6456513164bb5db737d6fc8610aa36ad458736c9efb884c610fa1816127c6565b610faa826127d0565b5050565b606060b38054610fbd90615349565b80601f0160208091040260200160405190810160405280929190818152602001828054610fe990615349565b80156110365780601f1061100b57610100808354040283529160200191611036565b820191906000526020600020905b81548152906001019060200180831161101957829003601f168201915b5050505050905090565b6000610f69826000612870565b60003361105b8185856128b6565b5060019392505050565b6000806110896127106101475461271061107f9190615336565b8591906001612a69565b9050611096816001612ac4565b9392505050565b6110a5614b42565b604080516102808101918290529060989060149082845b815473ffffffffffffffffffffffffffffffffffffffff1681526001909101906020018083116110bc575050505050905090565b6110f8612b01565b60005b6014811015610faa57609881601481106111175761111761539c565b015473ffffffffffffffffffffffffffffffffffffffff908116908316036112f95773ffffffffffffffffffffffffffffffffffffffff8216600090815260ad6020526040812080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00169081905560ae805461010090920461ffff169290916111a2908490615336565b909155505073ffffffffffffffffffffffffffffffffffffffff8216600090815260ad6020526040812080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000ff169055609882601481106112055761120561539c565b0180547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff928316179055604051908316907f09a1db4b80c32706328728508c941a6b954f31eb5affd32f236c1fd405f8fea490600090a261127a612b82565b6112f4828373ffffffffffffffffffffffffffffffffffffffff1663357be4466040518163ffffffff1660e01b81526004016020604051808303816000875af11580156112cb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112ef91906153cb565b612c9f565b505050565b6001016110fb565b6000547501000000000000000000000000000000000000000000900460ff161580801561134c575060005460017401000000000000000000000000000000000000000090910460ff16105b8061137e5750303b15801561137e575060005474010000000000000000000000000000000000000000900460ff166001145b61140f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201527f647920696e697469616c697a656400000000000000000000000000000000000060648201526084015b60405180910390fd5b600080547fffffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffff1674010000000000000000000000000000000000000000179055801561149557600080547fffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffffff1675010000000000000000000000000000000000000000001790555b61149f8585612e56565b6114a98383612f37565b6114b284612fec565b6000546114f6907f8b5b16d04624687fcf0d0228f19993c9157c1ed07b41d8d430fd9100eb099fe89073ffffffffffffffffffffffffffffffffffffffff166130a0565b801561155a57600080547fffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffffff169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb3847402498906020015b60405180910390a15b5050505050565b60003361156f858285613194565b61157a85858561326b565b506001949350505050565b6000828152606560205260409020600101546115a0816127c6565b6112f483836130a0565b60006008609760009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa15801561161b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061163f9190615313565b610ed191906153e4565b73ffffffffffffffffffffffffffffffffffffffff811633146116ee576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201527f20726f6c657320666f722073656c6600000000000000000000000000000000006064820152608401611406565b610faa828261351e565b6000610ed160975473ffffffffffffffffffffffffffffffffffffffff1690565b33600081815260b16020908152604080832073ffffffffffffffffffffffffffffffffffffffff8716845290915281205490919061105b90829086906117609087906153fd565b6128b6565b7f8b5b16d04624687fcf0d0228f19993c9157c1ed07b41d8d430fd9100eb099fe861178f816127c6565b6117976135d9565b50565b60af546000906117c09062015180906fffffffffffffffffffffffffffffffff166153fd565b42106117cc5750600090565b60af5460009062015180906117f3906fffffffffffffffffffffffffffffffff1642615336565b60af54611826919070010000000000000000000000000000000090046fffffffffffffffffffffffffffffffff16615410565b611830919061547c565b60af5490915061186790829070010000000000000000000000000000000090046fffffffffffffffffffffffffffffffff16615336565b91505090565b60008061187b836000612870565b905061188681613657565b6110969082615336565b60ac546097546040517f70a082310000000000000000000000000000000000000000000000000000000081523060048201526000929173ffffffffffffffffffffffffffffffffffffffff16906370a0823190602401602060405180830381865afa158015611903573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061192791906153cb565b610ed191906153fd565b7f27e3e4d29d60af3ae6456513164bb5db737d6fc8610aa36ad458736c9efb884c61195b816127c6565b60005b84811015611acd57600086868381811061197a5761197a61539c565b905060200201602081019061198f9190614d63565b73ffffffffffffffffffffffffffffffffffffffff8116600090815260ad602052604090205490915060ff166119c55750611ac5565b73ffffffffffffffffffffffffffffffffffffffff8116600090815260ad602052604081205460ae805461010090920461ffff16929091611a07908490615336565b90915550611a409050858584818110611a2257611a2261539c565b9050602002016020810190611a3791906154b7565b61ffff1661366e565b848483818110611a5257611a5261539c565b9050602002016020810190611a6791906154b7565b73ffffffffffffffffffffffffffffffffffffffff909116600090815260ad60205260409020805461ffff92909216610100027fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000ff9092169190911790555b60010161195e565b507f545a2901c84c72b5a338684cd0228cbc2663ed302c4cede1041a4cb05d4abe0b858585856040516115519493929190615528565b60408051808201909152600080825260208201526040518060400160405280610e14610eb5565b6000611b34612756565b6000611b3f846120f2565b9050611096338486846136f2565b7f27e3e4d29d60af3ae6456513164bb5db737d6fc8610aa36ad458736c9efb884c611b77816127c6565b6000611b81611890565b9050611b8b614b42565b60005b6014811015611ce557600060988260148110611bac57611bac61539c565b015473ffffffffffffffffffffffffffffffffffffffff16905080611bd15750611ce5565b73ffffffffffffffffffffffffffffffffffffffff8116600090815260ad602052604081205461271090611c0e90610100900461ffff1687615410565b611c18919061547c565b905060008273ffffffffffffffffffffffffffffffffffffffff1663357be4466040518163ffffffff1660e01b81526004016020604051808303816000875af1158015611c69573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c8d91906153cb565b905080821015611ca757611ca5836112ef8484615336565b505b80821115611cd157611cb98183615336565b858560148110611ccb57611ccb61539c565b60200201525b505050611cde8160010190565b9050611b8e565b5060005b6014811015611e06576000828260148110611d0657611d0661539c565b6020020151905080600003611d1b5750611dfe565b6097546040517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152611db891839173ffffffffffffffffffffffffffffffffffffffff909116906370a0823190602401602060405180830381865afa158015611d8f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611db391906153cb565b613801565b905080600003611dc85750611e06565b611dfc60988360148110611dde57611dde61539c565b015473ffffffffffffffffffffffffffffffffffffffff1682613817565b505b600101611ce9565b5060405133907fa61bd16ebda9d1c8ec2a61970b39e6640e55ed8433a22765a1b5217b72c4a81290600090a2505050565b7f8b5b16d04624687fcf0d0228f19993c9157c1ed07b41d8d430fd9100eb099fe8611e61816127c6565b61179761397d565b611e71612b01565b611e7e6098826014614b61565b507fc90c5dd90d97be559acbfb4e6798e48198fe77071c419afcaa6bd25f4d3d2ef581604051611eae9190615586565b60405180910390a150565b6000611ec3612756565b6000611ece84612091565b9050611096338483876136f2565b606060b48054610fbd90615349565b33600081815260b16020908152604080832073ffffffffffffffffffffffffffffffffffffffff8716845290915281205490919083811015611faf576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f7760448201527f207a65726f0000000000000000000000000000000000000000000000000000006064820152608401611406565b61157a82868684036128b6565b60003361105b81858561326b565b611fd2612b01565b6101475460408051918252602082018390527f28a572c8c759d40c2d26dcdaaefd9650e9e37ff11ee147ce0f645cd7664048cb910160405180910390a161014755565b60608115610f695750604051818152602001600582901b808483378101805b825185018035602082018337600080823584305af4612057573d6000803e3d6000fd5b508083526020830192503d81523d6000602083013e3d01603f0167ffffffffffffffe0168183106120345760408051919052949350505050565b6000610f69826001612870565b60006120a8612756565b60006120b5856001612ac4565b90506120c433858588856139d9565b949350505050565b60006120d6612756565b60006120e3856000612870565b90506120c433858584896139d9565b6000610f69826000612ac4565b6098816014811061210f57600080fd5b015473ffffffffffffffffffffffffffffffffffffffff16905081565b7f27e3e4d29d60af3ae6456513164bb5db737d6fc8610aa36ad458736c9efb884c612156816127c6565b60af546121799062015180906fffffffffffffffffffffffffffffffff166153fd565b4210156121e2576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f42563a2070726f66697420756e6c6f636b696e670000000000000000000000006044820152606401611406565b60ac54806000805b858110156123ec5760008787838181106122065761220661539c565b905060200201602081019061221b9190614d63565b73ffffffffffffffffffffffffffffffffffffffff8116600090815260ad602052604090205490915060ff1661225157506123e4565b73ffffffffffffffffffffffffffffffffffffffff8116600081815260ad602090815260408083205481517f357be446000000000000000000000000000000000000000000000000000000008152915163010000009091047cffffffffffffffffffffffffffffffffffffffffffffffffffffffffff16949263357be4469260048082019391829003018187875af11580156122f1573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061231591906153cb565b73ffffffffffffffffffffffffffffffffffffffff8416600090815260ad6020526040902080547cffffffffffffffffffffffffffffffffffffffffffffffffffffffffff80841663010000000262ffffff90921691909117909155909150821661238082886153fd565b61238a9190615336565b9550817cffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1681116123b95760006123dc565b817cffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1681035b850194505050505b6001016121ea565b50806123f661179a565b61240091906153fd565b60af80546fffffffffffffffffffffffffffffffff92831670010000000000000000000000000000000002921691909117905560ac829055612440613ce5565b60af80547fffffffffffffffffffffffffffffffff0000000000000000000000000000000016426fffffffffffffffffffffffffffffffff1617905560405133907f69e9c71f6799744a94d9897e77c3ed426cc2f92ba0ef3300785368209b6f4b2d906124b090899089906155cf565b60405180910390a2505050505050565b73ffffffffffffffffffffffffffffffffffffffff8116600090815260b06020526040812054610f69906000612870565b6124f9612b01565b6125068161ffff1661366e565b60408051606081018252600180825261ffff8481166020808501918252600085870181815273ffffffffffffffffffffffffffffffffffffffff8a16825260ad9092529590952093518454915195517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000009092169015157fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000ff161761010095909216949094021762ffffff1663010000007cffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9094169390930292909217905582906098906125f09060146155e3565b60ff16601481106126035761260361539c565b0180547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff928316179055604051908316907f3f008fd510eae7a9e7bee13513d7b83bef8003d488b5a3d0b0da4de71d6846f190600090a2610faa612b82565b600082815260656020526040902060010154612693816127c6565b6112f4838361351e565b73ffffffffffffffffffffffffffffffffffffffff8116600090815260b06020526040812054610f69565b604080518082019091526000808252602082015260405180604001604052806126f060b25490565b8152602001610eab6115aa565b6000610ed16008600a615304565b612713612b01565b6101465460408051918252602082018390527f4e874b007ab14f7e263baefd44951834c8266f4f224d1092e49e9c254354cc54910160405180910390a161014655565b6101145460ff16156127c4576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601060248201527f5061757361626c653a20706175736564000000000000000000000000000000006044820152606401611406565b565b6117978133613d7f565b60005b6014811015610faa576000609882601481106127f1576127f161539c565b015473ffffffffffffffffffffffffffffffffffffffff1690508061281557505050565b73ffffffffffffffffffffffffffffffffffffffff8116600090815260ad60205260409020546128679082906127109061285890610100900461ffff1687615410565b612862919061547c565b613817565b506001016127d3565b60008061287b6126fd565b60b25461288891906153fd565b90506000612894610eb5565b61289f9060016153fd565b90506128ad85828487612a69565b95945050505050565b73ffffffffffffffffffffffffffffffffffffffff8316612958576040517f08c379a0000000000000000000000000000000000000000000000000000000008152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f2061646460448201527f72657373000000000000000000000000000000000000000000000000000000006064820152608401611406565b73ffffffffffffffffffffffffffffffffffffffff82166129fb576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f20616464726560448201527f73730000000000000000000000000000000000000000000000000000000000006064820152608401611406565b73ffffffffffffffffffffffffffffffffffffffff838116600081815260b1602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b600080612a77868686613e51565b90506001836002811115612a8d57612a8d6155fc565b148015612aaa575060008480612aa557612aa561544d565b868809115b156128ad57612aba6001826153fd565b9695505050505050565b600080612acf6126fd565b60b254612adc91906153fd565b90506000612ae8610eb5565b612af39060016153fd565b90506128ad85838387612a69565b60005473ffffffffffffffffffffffffffffffffffffffff1633146127c4576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601060248201527f4f6e6c7920476f7665726e616e63652e000000000000000000000000000000006044820152606401611406565b6000805b6014811015610faa57600060988260148110612ba457612ba461539c565b015473ffffffffffffffffffffffffffffffffffffffff16905080612bd557612bce6001846153fd565b9250612c96565b8215612c9657806098612be88585615336565b60148110612bf857612bf861539c565b0180547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055600060988360148110612c5157612c5161539c565b0180547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff929092169190911790555b50600101612b86565b600080612cac8484613f1e565b73ffffffffffffffffffffffffffffffffffffffff8516600081815260ad602090815260408083205481517f357be4460000000000000000000000000000000000000000000000000000000081529151959650630100000090047cffffffffffffffffffffffffffffffffffffffffffffffffffffffffff169492939263357be44692600480840193919291829003018187875af1158015612d52573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d7691906153cb565b73ffffffffffffffffffffffffffffffffffffffff8716600090815260ad60205260409020805462ffffff1663010000007cffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8416021790559050808211612ddb576000612de5565b612de58183615336565b60ac6000828254612df69190615336565b9091555050604080518681526020810185905273ffffffffffffffffffffffffffffffffffffffff8816917f88f0c01d2402991a2098e1cf989cb2c54cefe3b20ccb83c55989866f419a6ff5910160405180910390a25090949350505050565b600080547fffffffffffffffffffffffff000000000000000000000000000000000000000090811673ffffffffffffffffffffffffffffffffffffffff85811691821784556097805490931690851617909155612eb391906130a0565b600054612ef7907f27e3e4d29d60af3ae6456513164bb5db737d6fc8610aa36ad458736c9efb884c9073ffffffffffffffffffffffffffffffffffffffff166130a0565b505060af80547fffffffffffffffffffffffffffffffff0000000000000000000000000000000016426fffffffffffffffffffffffffffffffff16179055565b6000547501000000000000000000000000000000000000000000900460ff16612fe2576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201527f6e697469616c697a696e670000000000000000000000000000000000000000006064820152608401611406565b610faa8282613fdb565b6000547501000000000000000000000000000000000000000000900460ff16613097576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201527f6e697469616c697a696e670000000000000000000000000000000000000000006064820152608401611406565b6117978161409f565b600082815260656020908152604080832073ffffffffffffffffffffffffffffffffffffffff8516845290915290205460ff16610faa57600082815260656020908152604080832073ffffffffffffffffffffffffffffffffffffffff85168452909152902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001660011790556131363390565b73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b73ffffffffffffffffffffffffffffffffffffffff838116600090815260b160209081526040808320938616835292905220547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff81146132655781811015613258576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e63650000006044820152606401611406565b61326584848484036128b6565b50505050565b73ffffffffffffffffffffffffffffffffffffffff831661330e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f20616460448201527f64726573730000000000000000000000000000000000000000000000000000006064820152608401611406565b73ffffffffffffffffffffffffffffffffffffffff82166133b1576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201527f65737300000000000000000000000000000000000000000000000000000000006064820152608401611406565b73ffffffffffffffffffffffffffffffffffffffff8316600090815260b0602052604090205481811015613467576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e742065786365656473206260448201527f616c616e636500000000000000000000000000000000000000000000000000006064820152608401611406565b73ffffffffffffffffffffffffffffffffffffffff808516600090815260b060205260408082208585039055918516815290812080548492906134ab9084906153fd565b925050819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161351191815260200190565b60405180910390a3613265565b600082815260656020908152604080832073ffffffffffffffffffffffffffffffffffffffff8516845290915290205460ff1615610faa57600082815260656020908152604080832073ffffffffffffffffffffffffffffffffffffffff8516808552925280832080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b6135e1614191565b61011480547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b60405173ffffffffffffffffffffffffffffffffffffffff909116815260200160405180910390a1565b61014754600090610f699083906127106001612a69565b60008160ae5461367e91906153fd565b90506127108111156136ec576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601060248201527f42563a20746f6f206d616e7920627073000000000000000000000000000000006044820152606401611406565b60ae5550565b6000811161375c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601260248201527f5661756c743a207a65726f2073686172657300000000000000000000000000006044820152606401611406565b61376683826141fe565b60975461378b9073ffffffffffffffffffffffffffffffffffffffff1685308561431e565b8273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d784846040516137f3929190918252602082015260400190565b60405180910390a350505050565b60008183106138105781611096565b5090919050565b80600003613823575050565b8060ac600082825461383591906153fd565b909155505073ffffffffffffffffffffffffffffffffffffffff808316600090815260ad6020526040902080547cffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6301000000808304821686019091160262ffffff9091161790556097546138a9911683836143dd565b6040517f2afcf4800000000000000000000000000000000000000000000000000000000081526004810182905273ffffffffffffffffffffffffffffffffffffffff831690632afcf48090602401600060405180830381600087803b15801561391157600080fd5b505af1158015613925573d6000803e3d6000fd5b505050508173ffffffffffffffffffffffffffffffffffffffff167fc6f6f91a48277d76f232cc08a9a30f6b05b3fd9b92c3180c25936e17a22a10258260405161397191815260200190565b60405180910390a25050565b613985612756565b61011480547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a25861362d3390565b6139e282614496565b506097546040517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152613a7d9173ffffffffffffffffffffffffffffffffffffffff16906370a0823190602401602060405180830381865afa158015613a53573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613a7791906153cb565b83613801565b91506000613a8a83613657565b90506000613a988285615336565b90508473ffffffffffffffffffffffffffffffffffffffff168773ffffffffffffffffffffffffffffffffffffffff1614613ad857613ad8858885613194565b613ae28584614659565b8473ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff168873ffffffffffffffffffffffffffffffffffffffff167ffbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db8787604051613b61929190918252602082015260400190565b60405180910390a46040517f2e1a7d4d0000000000000000000000000000000000000000000000000000000081526004810182905273c02aaa39b223fe8d0a0e5c4f27ead9083c756cc290632e1a7d4d90602401600060405180830381600087803b158015613bcf57600080fd5b505af1158015613be3573d6000803e3d6000fd5b5050505060008673ffffffffffffffffffffffffffffffffffffffff168260405160006040518083038185875af1925050503d8060008114613c41576040519150601f19603f3d011682016040523d82523d6000602084013e613c46565b606091505b5050905080613cb1576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f4574685661756c743a20455448207472616e73666572206661696c65640000006044820152606401611406565b600054609754613cdb9173ffffffffffffffffffffffffffffffffffffffff918216911685614846565b5050505050505050565b60af54600090613d07906fffffffffffffffffffffffffffffffff1642615336565b905060006301e133806101465483613d1f9190615410565b613d29919061547c565b90506000612710613d3960b25490565b613d439084615410565b613d4d919061547c565b905080600003613d5c57505050565b6000546112f49073ffffffffffffffffffffffffffffffffffffffff16826141fe565b600082815260656020908152604080832073ffffffffffffffffffffffffffffffffffffffff8516845290915290205460ff16610faa57613dd78173ffffffffffffffffffffffffffffffffffffffff1660146148ff565b613de28360206148ff565b604051602001613df392919061562b565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0818403018152908290527f08c379a000000000000000000000000000000000000000000000000000000000825261140691600401614cba565b600080807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff85870985870292508281108382030391505080600003613ea957838281613e9f57613e9f61544d565b0492505050611096565b808411613eb557600080fd5b60008486880960026001871981018816978890046003810283188082028403028082028403028082028403028082028403028082028403029081029092039091026000889003889004909101858311909403939093029303949094049190911702949350505050565b6040517f8ca179950000000000000000000000000000000000000000000000000000000081526004810182905260009073ffffffffffffffffffffffffffffffffffffffff841690638ca17995906024016020604051808303816000875af1925050508015613fc8575060408051601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0168201909252613fc5918101906153cb565b60015b613fd457506000610f69565b9050610f69565b6000547501000000000000000000000000000000000000000000900460ff16614086576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201527f6e697469616c697a696e670000000000000000000000000000000000000000006064820152608401611406565b60b361409283826156fa565b5060b46112f482826156fa565b6000547501000000000000000000000000000000000000000000900460ff1661414a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201527f6e697469616c697a696e670000000000000000000000000000000000000000006064820152608401611406565b60e280547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b6101145460ff166127c4576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f5061757361626c653a206e6f74207061757365640000000000000000000000006044820152606401611406565b73ffffffffffffffffffffffffffffffffffffffff821661427b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152606401611406565b8060b2600082825461428d91906153fd565b909155505073ffffffffffffffffffffffffffffffffffffffff8216600090815260b06020526040812080548392906142c79084906153fd565b909155505060405181815273ffffffffffffffffffffffffffffffffffffffff8316906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a35050565b60006040517f23b872dd0000000000000000000000000000000000000000000000000000000081528460048201528360248201528260448201526020600060648360008a5af13d15601f3d116001600051141617169150508061155a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f5452414e534645525f46524f4d5f4641494c45440000000000000000000000006044820152606401611406565b60006040517f095ea7b3000000000000000000000000000000000000000000000000000000008152836004820152826024820152602060006044836000895af13d15601f3d1160016000511416171691505080613265576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600e60248201527f415050524f56455f4641494c45440000000000000000000000000000000000006044820152606401611406565b60008060005b6014811015614619576000609882601481106144ba576144ba61539c565b015473ffffffffffffffffffffffffffffffffffffffff169050806144df5750614619565b6097546040517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015260009173ffffffffffffffffffffffffffffffffffffffff16906370a0823190602401602060405180830381865afa15801561454e573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061457291906153cb565b9050858110614582575050614619565b600061458e8288615336565b73ffffffffffffffffffffffffffffffffffffffff8416600090815260ad60205260409020549091506145e8908290630100000090047cffffffffffffffffffffffffffffffffffffffffffffffffffffffffff16613801565b905060006145f68483612c9f565b905061460281876153fd565b9550505050506146128160010190565b905061449c565b5060408051848152602081018390527fd2f6618ba448f8b76ee0e823f8bb8c568b748f1687e1bc6bd625306fc4fb5035910160405180910390a192915050565b73ffffffffffffffffffffffffffffffffffffffff82166146fc576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f2061646472657360448201527f73000000000000000000000000000000000000000000000000000000000000006064820152608401611406565b73ffffffffffffffffffffffffffffffffffffffff8216600090815260b06020526040902054818110156147b2576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e60448201527f63650000000000000000000000000000000000000000000000000000000000006064820152608401611406565b73ffffffffffffffffffffffffffffffffffffffff8316600090815260b060205260408120838303905560b280548492906147ee908490615336565b909155505060405182815260009073ffffffffffffffffffffffffffffffffffffffff8516907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a3505050565b60006040517fa9059cbb000000000000000000000000000000000000000000000000000000008152836004820152826024820152602060006044836000895af13d15601f3d1160016000511416171691505080613265576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600f60248201527f5452414e534645525f4641494c454400000000000000000000000000000000006044820152606401611406565b6060600061490e836002615410565b6149199060026153fd565b67ffffffffffffffff81111561493157614931614d80565b6040519080825280601f01601f19166020018201604052801561495b576020820181803683370190505b5090507f3000000000000000000000000000000000000000000000000000000000000000816000815181106149925761499261539c565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053507f7800000000000000000000000000000000000000000000000000000000000000816001815181106149f5576149f561539c565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053506000614a31846002615410565b614a3c9060016153fd565b90505b6001811115614ad9577f303132333435363738396162636465660000000000000000000000000000000085600f1660108110614a7d57614a7d61539c565b1a60f81b828281518110614a9357614a9361539c565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535060049490941c93614ad281615814565b9050614a3f565b508315611096576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401611406565b6040518061028001604052806014906020820280368337509192915050565b8260148101928215614bcc579160200282015b82811115614bcc5781547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff843516178255602090920191600190910190614b74565b50614bd8929150614bdc565b5090565b5b80821115614bd85760008155600101614bdd565b600060208284031215614c0357600080fd5b81357fffffffff000000000000000000000000000000000000000000000000000000008116811461109657600080fd5b600060208284031215614c4557600080fd5b5035919050565b60005b83811015614c67578181015183820152602001614c4f565b50506000910152565b60008151808452614c88816020860160208601614c4c565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169290920160200192915050565b6020815260006110966020830184614c70565b73ffffffffffffffffffffffffffffffffffffffff8116811461179757600080fd5b60008060408385031215614d0257600080fd5b8235614d0d81614ccd565b946020939093013593505050565b6102808101818360005b6014811015614d5a57815173ffffffffffffffffffffffffffffffffffffffff16835260209283019290910190600101614d25565b50505092915050565b600060208284031215614d7557600080fd5b813561109681614ccd565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b600082601f830112614dc057600080fd5b813567ffffffffffffffff80821115614ddb57614ddb614d80565b604051601f83017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0908116603f01168101908282118183101715614e2157614e21614d80565b81604052838152866020858801011115614e3a57600080fd5b836020870160208301376000602085830101528094505050505092915050565b60008060008060808587031215614e7057600080fd5b8435614e7b81614ccd565b93506020850135614e8b81614ccd565b9250604085013567ffffffffffffffff80821115614ea857600080fd5b614eb488838901614daf565b93506060870135915080821115614eca57600080fd5b50614ed787828801614daf565b91505092959194509250565b600080600060608486031215614ef857600080fd5b8335614f0381614ccd565b92506020840135614f1381614ccd565b929592945050506040919091013590565b60008060408385031215614f3757600080fd5b823591506020830135614f4981614ccd565b809150509250929050565b60008083601f840112614f6657600080fd5b50813567ffffffffffffffff811115614f7e57600080fd5b6020830191508360208260051b8501011115614f9957600080fd5b9250929050565b60008060008060408587031215614fb657600080fd5b843567ffffffffffffffff80821115614fce57600080fd5b614fda88838901614f54565b90965094506020870135915080821115614ff357600080fd5b5061500087828801614f54565b95989497509550505050565b600061028080838503121561502057600080fd5b83818401111561502f57600080fd5b509092915050565b6000806020838503121561504a57600080fd5b823567ffffffffffffffff81111561506157600080fd5b61506d85828601614f54565b90969095509350505050565b6000602080830181845280855180835260408601915060408160051b870101925083870160005b828110156150ec577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc08886030184526150da858351614c70565b945092850192908501906001016150a0565b5092979650505050505050565b60008060006060848603121561510e57600080fd5b83359250602084013561512081614ccd565b9150604084013561513081614ccd565b809150509250925092565b803561ffff8116811461514d57600080fd5b919050565b6000806040838503121561516557600080fd5b823561517081614ccd565b915061517e6020840161513b565b90509250929050565b6000806040838503121561519a57600080fd5b82356151a581614ccd565b91506020830135614f4981614ccd565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b600181815b8085111561523d57817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff04821115615223576152236151b5565b8085161561523057918102915b93841c93908002906151e9565b509250929050565b60008261525457506001610f69565b8161526157506000610f69565b816001811461527757600281146152815761529d565b6001915050610f69565b60ff841115615292576152926151b5565b50506001821b610f69565b5060208310610133831016604e8410600b84101617156152c0575081810a610f69565b6152ca83836151e4565b807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff048211156152fc576152fc6151b5565b029392505050565b600061109660ff841683615245565b60006020828403121561532557600080fd5b815160ff8116811461109657600080fd5b81810381811115610f6957610f696151b5565b600181811c9082168061535d57607f821691505b602082108103615396577f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b50919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b6000602082840312156153dd57600080fd5b5051919050565b60ff8181168382160190811115610f6957610f696151b5565b80820180821115610f6957610f696151b5565b6000817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0483118215151615615448576154486151b5565b500290565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b6000826154b2577f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b500490565b6000602082840312156154c957600080fd5b6110968261513b565b8183526000602080850194508260005b8581101561551d5781356154f581614ccd565b73ffffffffffffffffffffffffffffffffffffffff16875295820195908201906001016154e2565b509495945050505050565b60408152600061553c6040830186886154d2565b8281036020848101919091528482528591810160005b868110156155795761ffff6155668561513b565b1682529282019290820190600101615552565b5098975050505050505050565b6102808101818360005b6014811015614d5a5781356155a481614ccd565b73ffffffffffffffffffffffffffffffffffffffff1683526020928301929190910190600101615590565b6020815260006120c46020830184866154d2565b60ff8281168282160390811115610f6957610f696151b5565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b7f416363657373436f6e74726f6c3a206163636f756e7420000000000000000000815260008351615663816017850160208801614c4c565b7f206973206d697373696e6720726f6c652000000000000000000000000000000060179184019182015283516156a0816028840160208801614c4c565b01602801949350505050565b601f8211156112f457600081815260208120601f850160051c810160208610156156d35750805b601f850160051c820191505b818110156156f2578281556001016156df565b505050505050565b815167ffffffffffffffff81111561571457615714614d80565b615728816157228454615349565b846156ac565b602080601f83116001811461577b57600084156157455750858301515b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff600386901b1c1916600185901b1785556156f2565b6000858152602081207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08616915b828110156157c8578886015182559484019460019091019084016157a9565b508582101561580457878501517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff600388901b60f8161c191681555b5050505050600190811b01905550565b600081615823576158236151b5565b507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff019056fea264697066735822122098f366f5117aba780a79971d1e11e23a375c582d6c87814152f35456f19d725a64736f6c63430008100033
Deployed Bytecode
0x6080604052600436106104335760003560e01c80637d7c2a1c11610228578063c6e6f59211610128578063d905777e116100bb578063f1a392da1161008a578063f26edf351161006f578063f26edf3514610d95578063f6df5a7814610daa578063fe56e23214610dbf57600080fd5b8063f1a392da14610d56578063f20dd15d14610d7f57600080fd5b8063d905777e14610ccd578063dd62ed3e14610ced578063ecad956514610d40578063ef8b30f714610b7b57600080fd5b8063ce96cb77116100f7578063ce96cb7714610c0f578063d00364be14610c2f578063d11f519c14610c8d578063d547741f14610cad57600080fd5b8063c6e6f59214610b7b578063c822adda14610b9b578063c89d346014610bbb578063cb9d9fa714610bdb57600080fd5b8063a457c2d7116101bb578063ac9650d81161018a578063b460af941161016f578063b460af9414610b3b578063ba08765214610b5b578063c63d75b61461080757600080fd5b8063ac9650d814610afb578063b3d7f6b914610b1b57600080fd5b8063a457c2d714610a84578063a6f7f5d614610aa4578063a9059cbb14610abb578063ac1e502514610adb57600080fd5b806394148415116101f75780639414841514610a1a57806394bf804d14610a3a57806395d89b4114610a5a578063a217fddf14610a6f57600080fd5b80637d7c2a1c146109865780638456cb591461099b5780638bc7e8c4146109b057806391d14854146109c757600080fd5b806336568abe116103335780634cdad506116102c65780635da6a6911161029557806368bb9a971161027a57806368bb9a971461090c5780636e553f651461092357806370a082311461094357600080fd5b80635da6a691146108d75780636071abed146108f757600080fd5b80634cdad5061461085c5780634e637ba91461087c5780635aa6e675146108915780635c975abb146108be57600080fd5b80633f4ba83a116103025780633f4ba83a146107cb5780633fc8cef3146107e0578063402d267d1461080757806344b813961461084757600080fd5b806336568abe146106b057806338d52e0f146106d0578063395093511461070a57806339ebf8231461072a57600080fd5b80630e73ecef116103c657806323b872dd1161039557806324ea54f41161037a57806324ea54f4146106355780632f2ff15d14610669578063313ce5671461068957600080fd5b806323b872dd146105e5578063248a9ca31461060557600080fd5b80630e73ecef1461056e578063175188e81461059057806318160ddd146105b05780632016a0d2146105c557600080fd5b806306fdde031161040257806306fdde03146104ec57806307a2d13a1461050e578063095ea7b31461052e5780630a28a4771461054e57600080fd5b806301106d4d1461043f57806301e1d1141461047757806301ffc9a71461049a57806305efa876146104ca57600080fd5b3661043a57005b600080fd5b34801561044b57600080fd5b50610454610ddf565b604080518251815260209283015160ff1692810192909252015b60405180910390f35b34801561048357600080fd5b5061048c610eb5565b60405190815260200161046e565b3480156104a657600080fd5b506104ba6104b5366004614bf1565b610ed6565b604051901515815260200161046e565b3480156104d657600080fd5b506104ea6104e5366004614c33565b610f6f565b005b3480156104f857600080fd5b50610501610fae565b60405161046e9190614cba565b34801561051a57600080fd5b5061048c610529366004614c33565b611040565b34801561053a57600080fd5b506104ba610549366004614cef565b61104d565b34801561055a57600080fd5b5061048c610569366004614c33565b611065565b34801561057a57600080fd5b5061058361109d565b60405161046e9190614d1b565b34801561059c57600080fd5b506104ea6105ab366004614d63565b6110f0565b3480156105bc57600080fd5b5060b25461048c565b3480156105d157600080fd5b506104ea6105e0366004614e5a565b611301565b3480156105f157600080fd5b506104ba610600366004614ee3565b611561565b34801561061157600080fd5b5061048c610620366004614c33565b60009081526065602052604090206001015490565b34801561064157600080fd5b5061048c7f8b5b16d04624687fcf0d0228f19993c9157c1ed07b41d8d430fd9100eb099fe881565b34801561067557600080fd5b506104ea610684366004614f24565b611585565b34801561069557600080fd5b5061069e6115aa565b60405160ff909116815260200161046e565b3480156106bc57600080fd5b506104ea6106cb366004614f24565b611649565b3480156106dc57600080fd5b506106e56116f8565b60405173ffffffffffffffffffffffffffffffffffffffff909116815260200161046e565b34801561071657600080fd5b506104ba610725366004614cef565b611719565b34801561073657600080fd5b5061078c610745366004614d63565b60ad6020526000908152604090205460ff811690610100810461ffff1690630100000090047cffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1683565b60408051931515845261ffff90921660208401527cffffffffffffffffffffffffffffffffffffffffffffffffffffffffff169082015260600161046e565b3480156107d757600080fd5b506104ea611765565b3480156107ec57600080fd5b5073c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26106e5565b34801561081357600080fd5b5061048c610822366004614d63565b507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff90565b34801561085357600080fd5b5061048c61179a565b34801561086857600080fd5b5061048c610877366004614c33565b61186d565b34801561088857600080fd5b5061048c611890565b34801561089d57600080fd5b506000546106e59073ffffffffffffffffffffffffffffffffffffffff1681565b3480156108ca57600080fd5b506101145460ff166104ba565b3480156108e357600080fd5b506104ea6108f2366004614fa0565b611931565b34801561090357600080fd5b50610454611b03565b34801561091857600080fd5b5061048c6201518081565b34801561092f57600080fd5b5061048c61093e366004614f24565b611b2a565b34801561094f57600080fd5b5061048c61095e366004614d63565b73ffffffffffffffffffffffffffffffffffffffff16600090815260b0602052604090205490565b34801561099257600080fd5b506104ea611b4d565b3480156109a757600080fd5b506104ea611e37565b3480156109bc57600080fd5b5061048c6101475481565b3480156109d357600080fd5b506104ba6109e2366004614f24565b600091825260656020908152604080842073ffffffffffffffffffffffffffffffffffffffff93909316845291905290205460ff1690565b348015610a2657600080fd5b506104ea610a3536600461500c565b611e69565b348015610a4657600080fd5b5061048c610a55366004614f24565b611eb9565b348015610a6657600080fd5b50610501611edc565b348015610a7b57600080fd5b5061048c600081565b348015610a9057600080fd5b506104ba610a9f366004614cef565b611eeb565b348015610ab057600080fd5b5061048c6101465481565b348015610ac757600080fd5b506104ba610ad6366004614cef565b611fbc565b348015610ae757600080fd5b506104ea610af6366004614c33565b611fca565b610b0e610b09366004615037565b612015565b60405161046e9190615079565b348015610b2757600080fd5b5061048c610b36366004614c33565b612091565b348015610b4757600080fd5b5061048c610b563660046150f9565b61209e565b348015610b6757600080fd5b5061048c610b763660046150f9565b6120cc565b348015610b8757600080fd5b5061048c610b96366004614c33565b6120f2565b348015610ba757600080fd5b506106e5610bb6366004614c33565b6120ff565b348015610bc757600080fd5b506104ea610bd6366004615037565b61212c565b348015610be757600080fd5b5061048c7f27e3e4d29d60af3ae6456513164bb5db737d6fc8610aa36ad458736c9efb884c81565b348015610c1b57600080fd5b5061048c610c2a366004614d63565b6124c0565b348015610c3b57600080fd5b5060af54610c6c9070010000000000000000000000000000000090046fffffffffffffffffffffffffffffffff1681565b6040516fffffffffffffffffffffffffffffffff909116815260200161046e565b348015610c9957600080fd5b506104ea610ca8366004615152565b6124f1565b348015610cb957600080fd5b506104ea610cc8366004614f24565b612678565b348015610cd957600080fd5b5061048c610ce8366004614d63565b61269d565b348015610cf957600080fd5b5061048c610d08366004615187565b73ffffffffffffffffffffffffffffffffffffffff918216600090815260b16020908152604080832093909416825291909152205490565b348015610d4c57600080fd5b5061048c60ac5481565b348015610d6257600080fd5b5060af54610c6c906fffffffffffffffffffffffffffffffff1681565b348015610d8b57600080fd5b5061048c60ae5481565b348015610da157600080fd5b506104546126c8565b348015610db657600080fd5b5061048c6126fd565b348015610dcb57600080fd5b506104ea610dda366004614c33565b61270b565b60408051808201909152600080825260208201526040518060400160405280610e14610e096115aa565b61052990600a615304565b8152609754604080517f313ce567000000000000000000000000000000000000000000000000000000008152905160209384019373ffffffffffffffffffffffffffffffffffffffff9093169263313ce56792600480820193918290030181865afa158015610e87573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610eab9190615313565b60ff169052919050565b6000610ebf61179a565b610ec7611890565b610ed19190615336565b905090565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f7965db0b000000000000000000000000000000000000000000000000000000001480610f6957507f01ffc9a7000000000000000000000000000000000000000000000000000000007fffffffff000000000000000000000000000000000000000000000000000000008316145b92915050565b610f77612756565b7f27e3e4d29d60af3ae6456513164bb5db737d6fc8610aa36ad458736c9efb884c610fa1816127c6565b610faa826127d0565b5050565b606060b38054610fbd90615349565b80601f0160208091040260200160405190810160405280929190818152602001828054610fe990615349565b80156110365780601f1061100b57610100808354040283529160200191611036565b820191906000526020600020905b81548152906001019060200180831161101957829003601f168201915b5050505050905090565b6000610f69826000612870565b60003361105b8185856128b6565b5060019392505050565b6000806110896127106101475461271061107f9190615336565b8591906001612a69565b9050611096816001612ac4565b9392505050565b6110a5614b42565b604080516102808101918290529060989060149082845b815473ffffffffffffffffffffffffffffffffffffffff1681526001909101906020018083116110bc575050505050905090565b6110f8612b01565b60005b6014811015610faa57609881601481106111175761111761539c565b015473ffffffffffffffffffffffffffffffffffffffff908116908316036112f95773ffffffffffffffffffffffffffffffffffffffff8216600090815260ad6020526040812080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00169081905560ae805461010090920461ffff169290916111a2908490615336565b909155505073ffffffffffffffffffffffffffffffffffffffff8216600090815260ad6020526040812080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000ff169055609882601481106112055761120561539c565b0180547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff928316179055604051908316907f09a1db4b80c32706328728508c941a6b954f31eb5affd32f236c1fd405f8fea490600090a261127a612b82565b6112f4828373ffffffffffffffffffffffffffffffffffffffff1663357be4466040518163ffffffff1660e01b81526004016020604051808303816000875af11580156112cb573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112ef91906153cb565b612c9f565b505050565b6001016110fb565b6000547501000000000000000000000000000000000000000000900460ff161580801561134c575060005460017401000000000000000000000000000000000000000090910460ff16105b8061137e5750303b15801561137e575060005474010000000000000000000000000000000000000000900460ff166001145b61140f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201527f647920696e697469616c697a656400000000000000000000000000000000000060648201526084015b60405180910390fd5b600080547fffffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffff1674010000000000000000000000000000000000000000179055801561149557600080547fffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffffff1675010000000000000000000000000000000000000000001790555b61149f8585612e56565b6114a98383612f37565b6114b284612fec565b6000546114f6907f8b5b16d04624687fcf0d0228f19993c9157c1ed07b41d8d430fd9100eb099fe89073ffffffffffffffffffffffffffffffffffffffff166130a0565b801561155a57600080547fffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffffff169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb3847402498906020015b60405180910390a15b5050505050565b60003361156f858285613194565b61157a85858561326b565b506001949350505050565b6000828152606560205260409020600101546115a0816127c6565b6112f483836130a0565b60006008609760009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa15801561161b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061163f9190615313565b610ed191906153e4565b73ffffffffffffffffffffffffffffffffffffffff811633146116ee576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201527f20726f6c657320666f722073656c6600000000000000000000000000000000006064820152608401611406565b610faa828261351e565b6000610ed160975473ffffffffffffffffffffffffffffffffffffffff1690565b33600081815260b16020908152604080832073ffffffffffffffffffffffffffffffffffffffff8716845290915281205490919061105b90829086906117609087906153fd565b6128b6565b7f8b5b16d04624687fcf0d0228f19993c9157c1ed07b41d8d430fd9100eb099fe861178f816127c6565b6117976135d9565b50565b60af546000906117c09062015180906fffffffffffffffffffffffffffffffff166153fd565b42106117cc5750600090565b60af5460009062015180906117f3906fffffffffffffffffffffffffffffffff1642615336565b60af54611826919070010000000000000000000000000000000090046fffffffffffffffffffffffffffffffff16615410565b611830919061547c565b60af5490915061186790829070010000000000000000000000000000000090046fffffffffffffffffffffffffffffffff16615336565b91505090565b60008061187b836000612870565b905061188681613657565b6110969082615336565b60ac546097546040517f70a082310000000000000000000000000000000000000000000000000000000081523060048201526000929173ffffffffffffffffffffffffffffffffffffffff16906370a0823190602401602060405180830381865afa158015611903573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061192791906153cb565b610ed191906153fd565b7f27e3e4d29d60af3ae6456513164bb5db737d6fc8610aa36ad458736c9efb884c61195b816127c6565b60005b84811015611acd57600086868381811061197a5761197a61539c565b905060200201602081019061198f9190614d63565b73ffffffffffffffffffffffffffffffffffffffff8116600090815260ad602052604090205490915060ff166119c55750611ac5565b73ffffffffffffffffffffffffffffffffffffffff8116600090815260ad602052604081205460ae805461010090920461ffff16929091611a07908490615336565b90915550611a409050858584818110611a2257611a2261539c565b9050602002016020810190611a3791906154b7565b61ffff1661366e565b848483818110611a5257611a5261539c565b9050602002016020810190611a6791906154b7565b73ffffffffffffffffffffffffffffffffffffffff909116600090815260ad60205260409020805461ffff92909216610100027fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000ff9092169190911790555b60010161195e565b507f545a2901c84c72b5a338684cd0228cbc2663ed302c4cede1041a4cb05d4abe0b858585856040516115519493929190615528565b60408051808201909152600080825260208201526040518060400160405280610e14610eb5565b6000611b34612756565b6000611b3f846120f2565b9050611096338486846136f2565b7f27e3e4d29d60af3ae6456513164bb5db737d6fc8610aa36ad458736c9efb884c611b77816127c6565b6000611b81611890565b9050611b8b614b42565b60005b6014811015611ce557600060988260148110611bac57611bac61539c565b015473ffffffffffffffffffffffffffffffffffffffff16905080611bd15750611ce5565b73ffffffffffffffffffffffffffffffffffffffff8116600090815260ad602052604081205461271090611c0e90610100900461ffff1687615410565b611c18919061547c565b905060008273ffffffffffffffffffffffffffffffffffffffff1663357be4466040518163ffffffff1660e01b81526004016020604051808303816000875af1158015611c69573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611c8d91906153cb565b905080821015611ca757611ca5836112ef8484615336565b505b80821115611cd157611cb98183615336565b858560148110611ccb57611ccb61539c565b60200201525b505050611cde8160010190565b9050611b8e565b5060005b6014811015611e06576000828260148110611d0657611d0661539c565b6020020151905080600003611d1b5750611dfe565b6097546040517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152611db891839173ffffffffffffffffffffffffffffffffffffffff909116906370a0823190602401602060405180830381865afa158015611d8f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611db391906153cb565b613801565b905080600003611dc85750611e06565b611dfc60988360148110611dde57611dde61539c565b015473ffffffffffffffffffffffffffffffffffffffff1682613817565b505b600101611ce9565b5060405133907fa61bd16ebda9d1c8ec2a61970b39e6640e55ed8433a22765a1b5217b72c4a81290600090a2505050565b7f8b5b16d04624687fcf0d0228f19993c9157c1ed07b41d8d430fd9100eb099fe8611e61816127c6565b61179761397d565b611e71612b01565b611e7e6098826014614b61565b507fc90c5dd90d97be559acbfb4e6798e48198fe77071c419afcaa6bd25f4d3d2ef581604051611eae9190615586565b60405180910390a150565b6000611ec3612756565b6000611ece84612091565b9050611096338483876136f2565b606060b48054610fbd90615349565b33600081815260b16020908152604080832073ffffffffffffffffffffffffffffffffffffffff8716845290915281205490919083811015611faf576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f7760448201527f207a65726f0000000000000000000000000000000000000000000000000000006064820152608401611406565b61157a82868684036128b6565b60003361105b81858561326b565b611fd2612b01565b6101475460408051918252602082018390527f28a572c8c759d40c2d26dcdaaefd9650e9e37ff11ee147ce0f645cd7664048cb910160405180910390a161014755565b60608115610f695750604051818152602001600582901b808483378101805b825185018035602082018337600080823584305af4612057573d6000803e3d6000fd5b508083526020830192503d81523d6000602083013e3d01603f0167ffffffffffffffe0168183106120345760408051919052949350505050565b6000610f69826001612870565b60006120a8612756565b60006120b5856001612ac4565b90506120c433858588856139d9565b949350505050565b60006120d6612756565b60006120e3856000612870565b90506120c433858584896139d9565b6000610f69826000612ac4565b6098816014811061210f57600080fd5b015473ffffffffffffffffffffffffffffffffffffffff16905081565b7f27e3e4d29d60af3ae6456513164bb5db737d6fc8610aa36ad458736c9efb884c612156816127c6565b60af546121799062015180906fffffffffffffffffffffffffffffffff166153fd565b4210156121e2576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f42563a2070726f66697420756e6c6f636b696e670000000000000000000000006044820152606401611406565b60ac54806000805b858110156123ec5760008787838181106122065761220661539c565b905060200201602081019061221b9190614d63565b73ffffffffffffffffffffffffffffffffffffffff8116600090815260ad602052604090205490915060ff1661225157506123e4565b73ffffffffffffffffffffffffffffffffffffffff8116600081815260ad602090815260408083205481517f357be446000000000000000000000000000000000000000000000000000000008152915163010000009091047cffffffffffffffffffffffffffffffffffffffffffffffffffffffffff16949263357be4469260048082019391829003018187875af11580156122f1573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061231591906153cb565b73ffffffffffffffffffffffffffffffffffffffff8416600090815260ad6020526040902080547cffffffffffffffffffffffffffffffffffffffffffffffffffffffffff80841663010000000262ffffff90921691909117909155909150821661238082886153fd565b61238a9190615336565b9550817cffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1681116123b95760006123dc565b817cffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1681035b850194505050505b6001016121ea565b50806123f661179a565b61240091906153fd565b60af80546fffffffffffffffffffffffffffffffff92831670010000000000000000000000000000000002921691909117905560ac829055612440613ce5565b60af80547fffffffffffffffffffffffffffffffff0000000000000000000000000000000016426fffffffffffffffffffffffffffffffff1617905560405133907f69e9c71f6799744a94d9897e77c3ed426cc2f92ba0ef3300785368209b6f4b2d906124b090899089906155cf565b60405180910390a2505050505050565b73ffffffffffffffffffffffffffffffffffffffff8116600090815260b06020526040812054610f69906000612870565b6124f9612b01565b6125068161ffff1661366e565b60408051606081018252600180825261ffff8481166020808501918252600085870181815273ffffffffffffffffffffffffffffffffffffffff8a16825260ad9092529590952093518454915195517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000009092169015157fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000ff161761010095909216949094021762ffffff1663010000007cffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9094169390930292909217905582906098906125f09060146155e3565b60ff16601481106126035761260361539c565b0180547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff928316179055604051908316907f3f008fd510eae7a9e7bee13513d7b83bef8003d488b5a3d0b0da4de71d6846f190600090a2610faa612b82565b600082815260656020526040902060010154612693816127c6565b6112f4838361351e565b73ffffffffffffffffffffffffffffffffffffffff8116600090815260b06020526040812054610f69565b604080518082019091526000808252602082015260405180604001604052806126f060b25490565b8152602001610eab6115aa565b6000610ed16008600a615304565b612713612b01565b6101465460408051918252602082018390527f4e874b007ab14f7e263baefd44951834c8266f4f224d1092e49e9c254354cc54910160405180910390a161014655565b6101145460ff16156127c4576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601060248201527f5061757361626c653a20706175736564000000000000000000000000000000006044820152606401611406565b565b6117978133613d7f565b60005b6014811015610faa576000609882601481106127f1576127f161539c565b015473ffffffffffffffffffffffffffffffffffffffff1690508061281557505050565b73ffffffffffffffffffffffffffffffffffffffff8116600090815260ad60205260409020546128679082906127109061285890610100900461ffff1687615410565b612862919061547c565b613817565b506001016127d3565b60008061287b6126fd565b60b25461288891906153fd565b90506000612894610eb5565b61289f9060016153fd565b90506128ad85828487612a69565b95945050505050565b73ffffffffffffffffffffffffffffffffffffffff8316612958576040517f08c379a0000000000000000000000000000000000000000000000000000000008152602060048201526024808201527f45524332303a20617070726f76652066726f6d20746865207a65726f2061646460448201527f72657373000000000000000000000000000000000000000000000000000000006064820152608401611406565b73ffffffffffffffffffffffffffffffffffffffff82166129fb576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602260248201527f45524332303a20617070726f766520746f20746865207a65726f20616464726560448201527f73730000000000000000000000000000000000000000000000000000000000006064820152608401611406565b73ffffffffffffffffffffffffffffffffffffffff838116600081815260b1602090815260408083209487168084529482529182902085905590518481527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925910160405180910390a3505050565b600080612a77868686613e51565b90506001836002811115612a8d57612a8d6155fc565b148015612aaa575060008480612aa557612aa561544d565b868809115b156128ad57612aba6001826153fd565b9695505050505050565b600080612acf6126fd565b60b254612adc91906153fd565b90506000612ae8610eb5565b612af39060016153fd565b90506128ad85838387612a69565b60005473ffffffffffffffffffffffffffffffffffffffff1633146127c4576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601060248201527f4f6e6c7920476f7665726e616e63652e000000000000000000000000000000006044820152606401611406565b6000805b6014811015610faa57600060988260148110612ba457612ba461539c565b015473ffffffffffffffffffffffffffffffffffffffff16905080612bd557612bce6001846153fd565b9250612c96565b8215612c9657806098612be88585615336565b60148110612bf857612bf861539c565b0180547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055600060988360148110612c5157612c5161539c565b0180547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff929092169190911790555b50600101612b86565b600080612cac8484613f1e565b73ffffffffffffffffffffffffffffffffffffffff8516600081815260ad602090815260408083205481517f357be4460000000000000000000000000000000000000000000000000000000081529151959650630100000090047cffffffffffffffffffffffffffffffffffffffffffffffffffffffffff169492939263357be44692600480840193919291829003018187875af1158015612d52573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d7691906153cb565b73ffffffffffffffffffffffffffffffffffffffff8716600090815260ad60205260409020805462ffffff1663010000007cffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8416021790559050808211612ddb576000612de5565b612de58183615336565b60ac6000828254612df69190615336565b9091555050604080518681526020810185905273ffffffffffffffffffffffffffffffffffffffff8816917f88f0c01d2402991a2098e1cf989cb2c54cefe3b20ccb83c55989866f419a6ff5910160405180910390a25090949350505050565b600080547fffffffffffffffffffffffff000000000000000000000000000000000000000090811673ffffffffffffffffffffffffffffffffffffffff85811691821784556097805490931690851617909155612eb391906130a0565b600054612ef7907f27e3e4d29d60af3ae6456513164bb5db737d6fc8610aa36ad458736c9efb884c9073ffffffffffffffffffffffffffffffffffffffff166130a0565b505060af80547fffffffffffffffffffffffffffffffff0000000000000000000000000000000016426fffffffffffffffffffffffffffffffff16179055565b6000547501000000000000000000000000000000000000000000900460ff16612fe2576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201527f6e697469616c697a696e670000000000000000000000000000000000000000006064820152608401611406565b610faa8282613fdb565b6000547501000000000000000000000000000000000000000000900460ff16613097576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201527f6e697469616c697a696e670000000000000000000000000000000000000000006064820152608401611406565b6117978161409f565b600082815260656020908152604080832073ffffffffffffffffffffffffffffffffffffffff8516845290915290205460ff16610faa57600082815260656020908152604080832073ffffffffffffffffffffffffffffffffffffffff85168452909152902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001660011790556131363390565b73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b73ffffffffffffffffffffffffffffffffffffffff838116600090815260b160209081526040808320938616835292905220547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff81146132655781811015613258576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e63650000006044820152606401611406565b61326584848484036128b6565b50505050565b73ffffffffffffffffffffffffffffffffffffffff831661330e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602560248201527f45524332303a207472616e736665722066726f6d20746865207a65726f20616460448201527f64726573730000000000000000000000000000000000000000000000000000006064820152608401611406565b73ffffffffffffffffffffffffffffffffffffffff82166133b1576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602360248201527f45524332303a207472616e7366657220746f20746865207a65726f206164647260448201527f65737300000000000000000000000000000000000000000000000000000000006064820152608401611406565b73ffffffffffffffffffffffffffffffffffffffff8316600090815260b0602052604090205481811015613467576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f45524332303a207472616e7366657220616d6f756e742065786365656473206260448201527f616c616e636500000000000000000000000000000000000000000000000000006064820152608401611406565b73ffffffffffffffffffffffffffffffffffffffff808516600090815260b060205260408082208585039055918516815290812080548492906134ab9084906153fd565b925050819055508273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161351191815260200190565b60405180910390a3613265565b600082815260656020908152604080832073ffffffffffffffffffffffffffffffffffffffff8516845290915290205460ff1615610faa57600082815260656020908152604080832073ffffffffffffffffffffffffffffffffffffffff8516808552925280832080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b6135e1614191565b61011480547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b60405173ffffffffffffffffffffffffffffffffffffffff909116815260200160405180910390a1565b61014754600090610f699083906127106001612a69565b60008160ae5461367e91906153fd565b90506127108111156136ec576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601060248201527f42563a20746f6f206d616e7920627073000000000000000000000000000000006044820152606401611406565b60ae5550565b6000811161375c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601260248201527f5661756c743a207a65726f2073686172657300000000000000000000000000006044820152606401611406565b61376683826141fe565b60975461378b9073ffffffffffffffffffffffffffffffffffffffff1685308561431e565b8273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d784846040516137f3929190918252602082015260400190565b60405180910390a350505050565b60008183106138105781611096565b5090919050565b80600003613823575050565b8060ac600082825461383591906153fd565b909155505073ffffffffffffffffffffffffffffffffffffffff808316600090815260ad6020526040902080547cffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6301000000808304821686019091160262ffffff9091161790556097546138a9911683836143dd565b6040517f2afcf4800000000000000000000000000000000000000000000000000000000081526004810182905273ffffffffffffffffffffffffffffffffffffffff831690632afcf48090602401600060405180830381600087803b15801561391157600080fd5b505af1158015613925573d6000803e3d6000fd5b505050508173ffffffffffffffffffffffffffffffffffffffff167fc6f6f91a48277d76f232cc08a9a30f6b05b3fd9b92c3180c25936e17a22a10258260405161397191815260200190565b60405180910390a25050565b613985612756565b61011480547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a25861362d3390565b6139e282614496565b506097546040517f70a08231000000000000000000000000000000000000000000000000000000008152306004820152613a7d9173ffffffffffffffffffffffffffffffffffffffff16906370a0823190602401602060405180830381865afa158015613a53573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613a7791906153cb565b83613801565b91506000613a8a83613657565b90506000613a988285615336565b90508473ffffffffffffffffffffffffffffffffffffffff168773ffffffffffffffffffffffffffffffffffffffff1614613ad857613ad8858885613194565b613ae28584614659565b8473ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff168873ffffffffffffffffffffffffffffffffffffffff167ffbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db8787604051613b61929190918252602082015260400190565b60405180910390a46040517f2e1a7d4d0000000000000000000000000000000000000000000000000000000081526004810182905273c02aaa39b223fe8d0a0e5c4f27ead9083c756cc290632e1a7d4d90602401600060405180830381600087803b158015613bcf57600080fd5b505af1158015613be3573d6000803e3d6000fd5b5050505060008673ffffffffffffffffffffffffffffffffffffffff168260405160006040518083038185875af1925050503d8060008114613c41576040519150601f19603f3d011682016040523d82523d6000602084013e613c46565b606091505b5050905080613cb1576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f4574685661756c743a20455448207472616e73666572206661696c65640000006044820152606401611406565b600054609754613cdb9173ffffffffffffffffffffffffffffffffffffffff918216911685614846565b5050505050505050565b60af54600090613d07906fffffffffffffffffffffffffffffffff1642615336565b905060006301e133806101465483613d1f9190615410565b613d29919061547c565b90506000612710613d3960b25490565b613d439084615410565b613d4d919061547c565b905080600003613d5c57505050565b6000546112f49073ffffffffffffffffffffffffffffffffffffffff16826141fe565b600082815260656020908152604080832073ffffffffffffffffffffffffffffffffffffffff8516845290915290205460ff16610faa57613dd78173ffffffffffffffffffffffffffffffffffffffff1660146148ff565b613de28360206148ff565b604051602001613df392919061562b565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0818403018152908290527f08c379a000000000000000000000000000000000000000000000000000000000825261140691600401614cba565b600080807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff85870985870292508281108382030391505080600003613ea957838281613e9f57613e9f61544d565b0492505050611096565b808411613eb557600080fd5b60008486880960026001871981018816978890046003810283188082028403028082028403028082028403028082028403028082028403029081029092039091026000889003889004909101858311909403939093029303949094049190911702949350505050565b6040517f8ca179950000000000000000000000000000000000000000000000000000000081526004810182905260009073ffffffffffffffffffffffffffffffffffffffff841690638ca17995906024016020604051808303816000875af1925050508015613fc8575060408051601f3d9081017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0168201909252613fc5918101906153cb565b60015b613fd457506000610f69565b9050610f69565b6000547501000000000000000000000000000000000000000000900460ff16614086576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201527f6e697469616c697a696e670000000000000000000000000000000000000000006064820152608401611406565b60b361409283826156fa565b5060b46112f482826156fa565b6000547501000000000000000000000000000000000000000000900460ff1661414a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201527f6e697469616c697a696e670000000000000000000000000000000000000000006064820152608401611406565b60e280547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b6101145460ff166127c4576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f5061757361626c653a206e6f74207061757365640000000000000000000000006044820152606401611406565b73ffffffffffffffffffffffffffffffffffffffff821661427b576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152606401611406565b8060b2600082825461428d91906153fd565b909155505073ffffffffffffffffffffffffffffffffffffffff8216600090815260b06020526040812080548392906142c79084906153fd565b909155505060405181815273ffffffffffffffffffffffffffffffffffffffff8316906000907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a35050565b60006040517f23b872dd0000000000000000000000000000000000000000000000000000000081528460048201528360248201528260448201526020600060648360008a5af13d15601f3d116001600051141617169150508061155a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f5452414e534645525f46524f4d5f4641494c45440000000000000000000000006044820152606401611406565b60006040517f095ea7b3000000000000000000000000000000000000000000000000000000008152836004820152826024820152602060006044836000895af13d15601f3d1160016000511416171691505080613265576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600e60248201527f415050524f56455f4641494c45440000000000000000000000000000000000006044820152606401611406565b60008060005b6014811015614619576000609882601481106144ba576144ba61539c565b015473ffffffffffffffffffffffffffffffffffffffff169050806144df5750614619565b6097546040517f70a0823100000000000000000000000000000000000000000000000000000000815230600482015260009173ffffffffffffffffffffffffffffffffffffffff16906370a0823190602401602060405180830381865afa15801561454e573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061457291906153cb565b9050858110614582575050614619565b600061458e8288615336565b73ffffffffffffffffffffffffffffffffffffffff8416600090815260ad60205260409020549091506145e8908290630100000090047cffffffffffffffffffffffffffffffffffffffffffffffffffffffffff16613801565b905060006145f68483612c9f565b905061460281876153fd565b9550505050506146128160010190565b905061449c565b5060408051848152602081018390527fd2f6618ba448f8b76ee0e823f8bb8c568b748f1687e1bc6bd625306fc4fb5035910160405180910390a192915050565b73ffffffffffffffffffffffffffffffffffffffff82166146fc576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f2061646472657360448201527f73000000000000000000000000000000000000000000000000000000000000006064820152608401611406565b73ffffffffffffffffffffffffffffffffffffffff8216600090815260b06020526040902054818110156147b2576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e60448201527f63650000000000000000000000000000000000000000000000000000000000006064820152608401611406565b73ffffffffffffffffffffffffffffffffffffffff8316600090815260b060205260408120838303905560b280548492906147ee908490615336565b909155505060405182815260009073ffffffffffffffffffffffffffffffffffffffff8516907fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9060200160405180910390a3505050565b60006040517fa9059cbb000000000000000000000000000000000000000000000000000000008152836004820152826024820152602060006044836000895af13d15601f3d1160016000511416171691505080613265576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600f60248201527f5452414e534645525f4641494c454400000000000000000000000000000000006044820152606401611406565b6060600061490e836002615410565b6149199060026153fd565b67ffffffffffffffff81111561493157614931614d80565b6040519080825280601f01601f19166020018201604052801561495b576020820181803683370190505b5090507f3000000000000000000000000000000000000000000000000000000000000000816000815181106149925761499261539c565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053507f7800000000000000000000000000000000000000000000000000000000000000816001815181106149f5576149f561539c565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053506000614a31846002615410565b614a3c9060016153fd565b90505b6001811115614ad9577f303132333435363738396162636465660000000000000000000000000000000085600f1660108110614a7d57614a7d61539c565b1a60f81b828281518110614a9357614a9361539c565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535060049490941c93614ad281615814565b9050614a3f565b508315611096576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401611406565b6040518061028001604052806014906020820280368337509192915050565b8260148101928215614bcc579160200282015b82811115614bcc5781547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff843516178255602090920191600190910190614b74565b50614bd8929150614bdc565b5090565b5b80821115614bd85760008155600101614bdd565b600060208284031215614c0357600080fd5b81357fffffffff000000000000000000000000000000000000000000000000000000008116811461109657600080fd5b600060208284031215614c4557600080fd5b5035919050565b60005b83811015614c67578181015183820152602001614c4f565b50506000910152565b60008151808452614c88816020860160208601614c4c565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169290920160200192915050565b6020815260006110966020830184614c70565b73ffffffffffffffffffffffffffffffffffffffff8116811461179757600080fd5b60008060408385031215614d0257600080fd5b8235614d0d81614ccd565b946020939093013593505050565b6102808101818360005b6014811015614d5a57815173ffffffffffffffffffffffffffffffffffffffff16835260209283019290910190600101614d25565b50505092915050565b600060208284031215614d7557600080fd5b813561109681614ccd565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b600082601f830112614dc057600080fd5b813567ffffffffffffffff80821115614ddb57614ddb614d80565b604051601f83017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0908116603f01168101908282118183101715614e2157614e21614d80565b81604052838152866020858801011115614e3a57600080fd5b836020870160208301376000602085830101528094505050505092915050565b60008060008060808587031215614e7057600080fd5b8435614e7b81614ccd565b93506020850135614e8b81614ccd565b9250604085013567ffffffffffffffff80821115614ea857600080fd5b614eb488838901614daf565b93506060870135915080821115614eca57600080fd5b50614ed787828801614daf565b91505092959194509250565b600080600060608486031215614ef857600080fd5b8335614f0381614ccd565b92506020840135614f1381614ccd565b929592945050506040919091013590565b60008060408385031215614f3757600080fd5b823591506020830135614f4981614ccd565b809150509250929050565b60008083601f840112614f6657600080fd5b50813567ffffffffffffffff811115614f7e57600080fd5b6020830191508360208260051b8501011115614f9957600080fd5b9250929050565b60008060008060408587031215614fb657600080fd5b843567ffffffffffffffff80821115614fce57600080fd5b614fda88838901614f54565b90965094506020870135915080821115614ff357600080fd5b5061500087828801614f54565b95989497509550505050565b600061028080838503121561502057600080fd5b83818401111561502f57600080fd5b509092915050565b6000806020838503121561504a57600080fd5b823567ffffffffffffffff81111561506157600080fd5b61506d85828601614f54565b90969095509350505050565b6000602080830181845280855180835260408601915060408160051b870101925083870160005b828110156150ec577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc08886030184526150da858351614c70565b945092850192908501906001016150a0565b5092979650505050505050565b60008060006060848603121561510e57600080fd5b83359250602084013561512081614ccd565b9150604084013561513081614ccd565b809150509250925092565b803561ffff8116811461514d57600080fd5b919050565b6000806040838503121561516557600080fd5b823561517081614ccd565b915061517e6020840161513b565b90509250929050565b6000806040838503121561519a57600080fd5b82356151a581614ccd565b91506020830135614f4981614ccd565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b600181815b8085111561523d57817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff04821115615223576152236151b5565b8085161561523057918102915b93841c93908002906151e9565b509250929050565b60008261525457506001610f69565b8161526157506000610f69565b816001811461527757600281146152815761529d565b6001915050610f69565b60ff841115615292576152926151b5565b50506001821b610f69565b5060208310610133831016604e8410600b84101617156152c0575081810a610f69565b6152ca83836151e4565b807fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff048211156152fc576152fc6151b5565b029392505050565b600061109660ff841683615245565b60006020828403121561532557600080fd5b815160ff8116811461109657600080fd5b81810381811115610f6957610f696151b5565b600181811c9082168061535d57607f821691505b602082108103615396577f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b50919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b6000602082840312156153dd57600080fd5b5051919050565b60ff8181168382160190811115610f6957610f696151b5565b80820180821115610f6957610f696151b5565b6000817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0483118215151615615448576154486151b5565b500290565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b6000826154b2577f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b500490565b6000602082840312156154c957600080fd5b6110968261513b565b8183526000602080850194508260005b8581101561551d5781356154f581614ccd565b73ffffffffffffffffffffffffffffffffffffffff16875295820195908201906001016154e2565b509495945050505050565b60408152600061553c6040830186886154d2565b8281036020848101919091528482528591810160005b868110156155795761ffff6155668561513b565b1682529282019290820190600101615552565b5098975050505050505050565b6102808101818360005b6014811015614d5a5781356155a481614ccd565b73ffffffffffffffffffffffffffffffffffffffff1683526020928301929190910190600101615590565b6020815260006120c46020830184866154d2565b60ff8281168282160390811115610f6957610f696151b5565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b7f416363657373436f6e74726f6c3a206163636f756e7420000000000000000000815260008351615663816017850160208801614c4c565b7f206973206d697373696e6720726f6c652000000000000000000000000000000060179184019182015283516156a0816028840160208801614c4c565b01602801949350505050565b601f8211156112f457600081815260208120601f850160051c810160208610156156d35750805b601f850160051c820191505b818110156156f2578281556001016156df565b505050505050565b815167ffffffffffffffff81111561571457615714614d80565b615728816157228454615349565b846156ac565b602080601f83116001811461577b57600084156157455750858301515b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff600386901b1c1916600185901b1785556156f2565b6000858152602081207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08616915b828110156157c8578886015182559484019460019091019084016157a9565b508582101561580457878501517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff600388901b60f8161c191681555b5050505050600190811b01905550565b600081615823576158236151b5565b507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff019056fea264697066735822122098f366f5117aba780a79971d1e11e23a375c582d6c87814152f35456f19d725a64736f6c63430008100033
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 30 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
Loading...
Loading
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.