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
Latest 1 from a total of 1 transactions
Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
---|---|---|---|---|---|---|---|---|---|
0x60a08060 | 19840407 | 111 days ago | IN | 0 ETH | 0.05911835 |
Advanced mode: Intended for advanced users or developers and will display all Internal Transactions including zero value transfers. Name tag integration is not available in advanced view.
Latest 16 internal transactions
Advanced mode:
Parent Transaction Hash | Block | From | To | ||||
---|---|---|---|---|---|---|---|
20230899 | 56 days ago | 0 ETH | |||||
20221296 | 58 days ago | 0.2 ETH | |||||
20159108 | 66 days ago | 0 ETH | |||||
20151368 | 67 days ago | 0.01 ETH | |||||
20149154 | 68 days ago | 0 ETH | |||||
20137343 | 69 days ago | 2 ETH | |||||
20088995 | 76 days ago | 1 ETH | |||||
19921067 | 100 days ago | 0.1 ETH | |||||
19920093 | 100 days ago | 0.25 ETH | |||||
19888193 | 104 days ago | 0.05 ETH | |||||
19887187 | 104 days ago | 0.043 ETH | |||||
19886110 | 105 days ago | 0 ETH | |||||
19883725 | 105 days ago | 1.2 ETH | |||||
19883009 | 105 days ago | 0.65 ETH | |||||
19863937 | 108 days ago | 0.002 ETH | |||||
19840407 | 111 days ago | 0 ETH |
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 Source Code Verified (Exact Match)
Contract Name:
StakeRaise
Compiler Version
v0.8.25+commit.b61c2a91
Optimization Enabled:
Yes with 20000 runs
Other Settings:
paris EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT pragma solidity ^0.8.20; import {UnityVault} from "./UnityVault.sol"; import {AssetVault, ERC4626} from "./AssetVault.sol"; import {ILido} from "./ILido.sol"; import {Ownable} from "solady/src/auth/Ownable.sol"; import {Initializable} from "solady/src/utils/Initializable.sol"; import {UUPSUpgradeable} from "solady/src/utils/UUPSUpgradeable.sol"; import {SafeTransferLib} from "solady/src/utils/SafeTransferLib.sol"; import {FixedPointMathLib} from "solady/src/utils/FixedPointMathLib.sol"; /// @dev To get the number of stETH deposited by an account, use balanceOf(account) /// Reward token distributions handled separately contract StakeRaise is Initializable, UUPSUpgradeable, Ownable, UnityVault { /// ------------------ Types ------------------ /// error DepositTooSmall(); error WithdrawsLocked(); event WithdrawalsLocked(); event WithdrawalsUnlocked(); /// ------------------ Storage ------------------ /// struct StakeRaiseStorage { address asset; string name; string symbol; uint8 decimals; address assetVault; mapping(address => uint256) vaultBalances; mapping(address => uint256) accruedPoints; uint256 totalAccruedPoints; bool withdrawLocked; } // keccak256(abi.encode(uint256(keccak256("solidviolet.storage.StakeRaise")) - 1)) & ~bytes32(uint256(0xff)) bytes32 private constant STAKERAISE_STORAGE_POSITION = 0x58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e6000; function getStakeRaiseStorage() internal pure returns (StakeRaiseStorage storage $) { assembly { $.slot := STAKERAISE_STORAGE_POSITION } } /// ------------------ Initializer ------------------ /// function initialize(address asset_, string memory name_, string memory symbol_) public initializer { _initializeOwner(msg.sender); StakeRaiseStorage storage $ = getStakeRaiseStorage(); $.asset = asset_; $.name = name_; $.symbol = symbol_; (bool success, uint8 decimals_) = _tryGetAssetDecimals(asset_); $.decimals = success ? decimals_ : _DEFAULT_UNDERLYING_DECIMALS; address _assetVault = address(new AssetVault(asset_, string.concat(name_, " Stake Vault"), string.concat("stvlt", symbol_))); $.assetVault = _assetVault; // unlimited approval for asset vault SafeTransferLib.safeApprove(asset_, _assetVault, type(uint256).max); SafeTransferLib.safeApprove(asset_, address(this), type(uint256).max); } function _authorizeUpgrade(address) internal override onlyOwner {} constructor() { _disableInitializers(); } /// ------------------ Getters ------------------ /// function asset() public view override returns (address) { return getStakeRaiseStorage().asset; } function assetVault() public view returns (address) { return getStakeRaiseStorage().assetVault; } function name() public view override returns (string memory) { return getStakeRaiseStorage().name; } function symbol() public view override returns (string memory) { return getStakeRaiseStorage().symbol; } function decimals() public view override returns (uint8) { return getStakeRaiseStorage().decimals; } /// @dev Returns total accrued contribution for an account function contribution(address account) public view returns (uint256) { StakeRaiseStorage storage $ = getStakeRaiseStorage(); // Add unharvested yield to accrued contribution uint256 _unwrappedAssets = ERC4626($.assetVault).previewRedeem($.vaultBalances[account]); uint256 _balance = balanceOf(account); uint256 _points = $.accruedPoints[account]; if (_unwrappedAssets > _balance) { _points += _unwrappedAssets - _balance; } return _points; } function totalContributions() public view returns (uint256) { StakeRaiseStorage storage $ = getStakeRaiseStorage(); uint256 _totalVaultAssets = ERC4626($.assetVault).totalAssets(); uint256 _totalSupply = totalSupply(); uint256 _totalPoints = $.totalAccruedPoints; if (_totalVaultAssets > _totalSupply) { _totalPoints += _totalVaultAssets - _totalSupply; } return _totalPoints; } /// ------------------ Admin ------------------ /// function lockWithdrawals() public onlyOwner { StakeRaiseStorage storage $ = getStakeRaiseStorage(); $.withdrawLocked = true; emit WithdrawalsLocked(); } function unlockWithdrawals() public onlyOwner { StakeRaiseStorage storage $ = getStakeRaiseStorage(); $.withdrawLocked = false; emit WithdrawalsUnlocked(); } /// ------------------ Vault ------------------ /// function stakeEthAndDeposit() public payable virtual returns (uint256 shares) { if (msg.value > maxEthDeposit() || msg.value > maxDeposit(msg.sender)) revert DepositMoreThanMax(); StakeRaiseStorage storage $ = getStakeRaiseStorage(); address _asset = $.asset; shares = ILido(_asset).submit{value: msg.value}(address(0)); _deposit(address(this), msg.sender, shares, shares); } function maxEthDeposit() public view returns (uint256) { return ILido(getStakeRaiseStorage().asset).getCurrentStakeLimit(); } function _deposit(address by, address to, uint256 assets, uint256 shares) internal override { super._deposit(by, to, assets, shares); StakeRaiseStorage storage $ = getStakeRaiseStorage(); address _assetVault = $.assetVault; // Validate deposit too small if (ERC4626(_assetVault).previewDeposit(assets) == 0) revert DepositTooSmall(); uint256 _vaultShares = ERC4626(_assetVault).deposit(assets, address(this)); // Store additional vault balance for user $.vaultBalances[to] += _vaultShares; } function _withdraw(address by, address to, address owner, uint256 assets, uint256 shares) internal override { StakeRaiseStorage storage $ = getStakeRaiseStorage(); if ($.withdrawLocked) revert WithdrawsLocked(); uint256 _vaultBalance = $.vaultBalances[owner]; uint256 _tokenBalance = balanceOf(owner); uint256 _unwrap; if (assets < _tokenBalance) { _unwrap = FixedPointMathLib.fullMulDiv(assets, _vaultBalance, _tokenBalance); } else { _unwrap = _vaultBalance; } address _assetVault = $.assetVault; uint256 _unwrappedAssets; if (ERC4626(_assetVault).previewRedeem(_unwrap) < assets) { // Withdraw assets exactly uint256 _wrappedAssetsBurned = ERC4626(_assetVault).withdraw(assets, address(this), address(this)); if (_wrappedAssetsBurned < _vaultBalance) { $.vaultBalances[owner] = _vaultBalance - _wrappedAssetsBurned; } else { delete $.vaultBalances[owner]; } _unwrappedAssets = assets; } else { // Redeem wrapped assets proportionally $.vaultBalances[owner] = _vaultBalance - _unwrap; _unwrappedAssets = ERC4626(_assetVault).redeem(_unwrap, address(this), address(this)); } // Credit user with excess assets if (_unwrappedAssets > assets) { uint256 _points = _unwrappedAssets - assets; $.accruedPoints[owner] += _points; $.totalAccruedPoints += _points; } // Untransferred assets accumulate on this contract, these are accrued contributions super._withdraw(by, to, owner, assets, shares); } /// @dev Realize accrued contributions for an account // TODO: function compound(address account) public onlyOwner /// @dev Withdraw accrued asset contributions /// All asset balance on this contract is considered accrued contributions function withdrawContributions() public onlyOwner { StakeRaiseStorage storage $ = getStakeRaiseStorage(); address _asset = $.asset; uint256 _accruedContributions = SafeTransferLib.balanceOf(_asset, address(this)); SafeTransferLib.safeTransfer(_asset, msg.sender, _accruedContributions); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; import {ERC20} from "solady/src/tokens/ERC20.sol"; import {SafeTransferLib} from "solady/src/utils/SafeTransferLib.sol"; /// @notice Stripped down ERC4626-ish 1:1 tokenized Vault implementation. /// @author Modified from Solady (https://github.com/vectorized/solady/blob/main/src/tokens/ERC4626.sol) abstract contract UnityVault is ERC20 { /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CONSTANTS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The default underlying decimals. uint8 internal constant _DEFAULT_UNDERLYING_DECIMALS = 18; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CUSTOM ERRORS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Cannot deposit more than the max limit. error DepositMoreThanMax(); /// @dev Cannot mint more than the max limit. error MintMoreThanMax(); /// @dev Cannot withdraw more than the max limit. error WithdrawMoreThanMax(); /// @dev Cannot redeem more than the max limit. error RedeemMoreThanMax(); /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* EVENTS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Emitted during a mint call or deposit call. event Deposit(address indexed by, address indexed owner, uint256 assets, uint256 shares); /// @dev Emitted during a withdraw call or redeem call. event Withdraw(address indexed by, address indexed to, address indexed owner, uint256 assets, uint256 shares); /// @dev `keccak256(bytes("Deposit(address,address,uint256,uint256)"))`. uint256 private constant _DEPOSIT_EVENT_SIGNATURE = 0xdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d7; /// @dev `keccak256(bytes("Withdraw(address,address,address,uint256,uint256)"))`. uint256 private constant _WITHDRAW_EVENT_SIGNATURE = 0xfbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* ERC4626 CONSTANTS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev To be overridden to return the address of the underlying asset. /// /// - MUST be an ERC20 token contract. /// - MUST NOT revert. function asset() public view virtual returns (address); /// @dev Returns the decimals places of the token. /// To be overridden to return the number of decimals of the underlying asset. /// Default: 18. /// /// - MUST NOT revert. function decimals() public view virtual override(ERC20) returns (uint8) { return _DEFAULT_UNDERLYING_DECIMALS; } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* ASSET DECIMALS GETTER HELPER */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Helper function to get the decimals of the underlying asset. /// Useful for setting the return value of `decimals` during initialization. /// If the retrieval succeeds, `success` will be true, and `result` will hold the result. /// Otherwise, `success` will be false, and `result` will be zero. /// /// Example usage: /// ``` /// (bool success, uint8 result) = _tryGetAssetDecimals(underlying); /// _decimals = success ? result : _DEFAULT_UNDERLYING_DECIMALS; /// ``` function _tryGetAssetDecimals(address underlying) internal view returns (bool success, uint8 result) { /// @solidity memory-safe-assembly assembly { // Store the function selector of `decimals()`. mstore(0x00, 0x313ce567) // Arguments are evaluated last to first. success := and( // Returned value is less than 256, at left-padded to 32 bytes. and(lt(mload(0x00), 0x100), gt(returndatasize(), 0x1f)), // The staticcall succeeds. staticcall(gas(), underlying, 0x1c, 0x04, 0x00, 0x20) ) result := mul(mload(0x00), success) } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* DEPOSIT / WITHDRAWAL LIMIT LOGIC */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Returns the maximum amount of the underlying asset that can be deposited /// into the Vault for `to`, via a deposit call. /// /// - MUST return a limited value if `to` is subject to some deposit limit. /// - MUST return `2**256-1` if there is no maximum limit. /// - MUST NOT revert. function maxDeposit(address to) public view virtual returns (uint256 maxAssets) { to = to; // Silence unused variable warning. maxAssets = type(uint256).max; } /// @dev Returns the maximum amount of the Vault shares that can be minter for `to`, /// via a mint call. /// /// - MUST return a limited value if `to` is subject to some mint limit. /// - MUST return `2**256-1` if there is no maximum limit. /// - MUST NOT revert. function maxMint(address to) public view virtual returns (uint256 maxShares) { to = to; // Silence unused variable warning. maxShares = type(uint256).max; } /// @dev Returns the maximum amount of the underlying asset that can be withdrawn /// from the `owner`'s balance in the Vault, via 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) public view virtual returns (uint256 maxAssets) { maxAssets = balanceOf(owner); } /// @dev Returns the maximum amount of Vault shares that can be redeemed /// from the `owner`'s balance in the Vault, via a redeem call. /// /// - MUST return a limited value if `owner` is subject to some withdrawal limit or timelock. /// - MUST return `balanceOf(owner)` otherwise. /// - MUST NOT revert. function maxRedeem(address owner) public view virtual returns (uint256 maxShares) { maxShares = balanceOf(owner); } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* DEPOSIT / WITHDRAWAL LOGIC */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Mints `shares` Vault shares to `to` by depositing exactly `assets` /// 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, such as due to deposit limit, /// slippage, insufficient approval, etc. /// /// Note: Most implementations will require pre-approval of the Vault with the /// Vault's underlying `asset` token. function deposit(uint256 assets, address to) public virtual returns (uint256 shares) { if (assets > maxDeposit(to)) _revert(0xb3c61a83); // `DepositMoreThanMax()`. shares = assets; _deposit(msg.sender, to, assets, shares); } /// @dev Mints exactly `shares` Vault shares to `to` by depositing `assets` /// 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 deposited, such as due to deposit limit, /// slippage, insufficient approval, etc. /// /// Note: Most implementations will require pre-approval of the Vault with the /// Vault's underlying `asset` token. function mint(uint256 shares, address to) public virtual returns (uint256 assets) { if (shares > maxMint(to)) _revert(0x6a695959); // `MintMoreThanMax()`. assets = shares; _deposit(msg.sender, to, assets, shares); } /// @dev Burns `shares` from `owner` and sends exactly `assets` of underlying tokens to `to`. /// /// - 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, such as due to withdrawal limit, /// slippage, insufficient balance, etc. /// /// Note: 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 to, address owner) public virtual returns (uint256 shares) { if (assets > maxWithdraw(owner)) _revert(0x936941fc); // `WithdrawMoreThanMax()`. shares = assets; _withdraw(msg.sender, to, owner, assets, shares); } /// @dev Burns exactly `shares` from `owner` and sends `assets` of underlying tokens to `to`. /// /// - 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, such as due to withdrawal limit, /// slippage, insufficient balance, etc. /// /// Note: Some implementations will require pre-requesting to the Vault before a redeem /// may be performed. Those methods should be performed separately. function redeem(uint256 shares, address to, address owner) public virtual returns (uint256 assets) { if (shares > maxRedeem(owner)) _revert(0x4656425a); // `RedeemMoreThanMax()`. assets = shares; _withdraw(msg.sender, to, owner, assets, shares); } /// @dev Internal helper for reverting efficiently. function _revert(uint256 s) private pure { /// @solidity memory-safe-assembly assembly { mstore(0x00, s) revert(0x1c, 0x04) } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* INTERNAL HELPERS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev For deposits and mints. /// /// Emits a {Deposit} event. function _deposit(address by, address to, uint256 assets, uint256 shares) internal virtual { SafeTransferLib.safeTransferFrom(asset(), by, address(this), assets); _mint(to, shares); /// @solidity memory-safe-assembly assembly { // Emit the {Deposit} event. mstore(0x00, assets) mstore(0x20, shares) let m := shr(96, not(0)) log3(0x00, 0x40, _DEPOSIT_EVENT_SIGNATURE, and(m, by), and(m, to)) } _afterDeposit(assets, shares); } /// @dev For withdrawals and redemptions. /// /// Emits a {Withdraw} event. function _withdraw(address by, address to, address owner, uint256 assets, uint256 shares) internal virtual { if (by != owner) _spendAllowance(owner, by, shares); _beforeWithdraw(assets, shares); _burn(owner, shares); SafeTransferLib.safeTransfer(asset(), to, assets); /// @solidity memory-safe-assembly assembly { // Emit the {Withdraw} event. mstore(0x00, assets) mstore(0x20, shares) let m := shr(96, not(0)) log4(0x00, 0x40, _WITHDRAW_EVENT_SIGNATURE, and(m, by), and(m, to), and(m, owner)) } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* HOOKS TO OVERRIDE */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Hook that is called before any withdrawal or redemption. function _beforeWithdraw(uint256 assets, uint256 shares) internal virtual {} /// @dev Hook that is called after any deposit or mint. function _afterDeposit(uint256 assets, uint256 shares) internal virtual {} }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; import {ERC4626} from "solady/src/tokens/ERC4626.sol"; import {Ownable} from "solady/src/auth/Ownable.sol"; /// @dev Internal vault to capture rebasing value. Deposits/withdrawals restricted to single deployer. contract AssetVault is ERC4626, Ownable { error TransferNotAllowed(); address private _asset; string private _name; string private _symbol; function asset() public view override returns (address) { return _asset; } function name() public view override returns (string memory) { return _name; } function symbol() public view override returns (string memory) { return _symbol; } constructor(address asset_, string memory name_, string memory symbol_) { _initializeOwner(msg.sender); _asset = asset_; _name = name_; _symbol = symbol_; } function deposit(uint256 assets, address to) public virtual override onlyOwner returns (uint256 shares) { shares = super.deposit(assets, to); } function mint(uint256 shares, address to) public virtual override onlyOwner returns (uint256 assets) { assets = super.mint(shares, to); } function withdraw(uint256 assets, address to, address owner) public virtual override onlyOwner returns (uint256 shares) { shares = super.withdraw(assets, to, owner); } function redeem(uint256 shares, address to, address owner) public virtual override onlyOwner returns (uint256 assets) { assets = super.redeem(shares, to, owner); } function transfer(address, uint256) public virtual override returns (bool) { revert TransferNotAllowed(); } function transferFrom(address, address, uint256) public virtual override returns (bool) { revert TransferNotAllowed(); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.20; interface ILido { function submit(address _referral) external payable returns (uint256); function getCurrentStakeLimit() external view returns (uint256); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; /// @notice Simple single owner authorization mixin. /// @author Solady (https://github.com/vectorized/solady/blob/main/src/auth/Ownable.sol) /// /// @dev Note: /// This implementation does NOT auto-initialize the owner to `msg.sender`. /// You MUST call the `_initializeOwner` in the constructor / initializer. /// /// While the ownable portion follows /// [EIP-173](https://eips.ethereum.org/EIPS/eip-173) for compatibility, /// the nomenclature for the 2-step ownership handover may be unique to this codebase. abstract contract Ownable { /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CUSTOM ERRORS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The caller is not authorized to call the function. error Unauthorized(); /// @dev The `newOwner` cannot be the zero address. error NewOwnerIsZeroAddress(); /// @dev The `pendingOwner` does not have a valid handover request. error NoHandoverRequest(); /// @dev Cannot double-initialize. error AlreadyInitialized(); /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* EVENTS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The ownership is transferred from `oldOwner` to `newOwner`. /// This event is intentionally kept the same as OpenZeppelin's Ownable to be /// compatible with indexers and [EIP-173](https://eips.ethereum.org/EIPS/eip-173), /// despite it not being as lightweight as a single argument event. event OwnershipTransferred(address indexed oldOwner, address indexed newOwner); /// @dev An ownership handover to `pendingOwner` has been requested. event OwnershipHandoverRequested(address indexed pendingOwner); /// @dev The ownership handover to `pendingOwner` has been canceled. event OwnershipHandoverCanceled(address indexed pendingOwner); /// @dev `keccak256(bytes("OwnershipTransferred(address,address)"))`. uint256 private constant _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE = 0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0; /// @dev `keccak256(bytes("OwnershipHandoverRequested(address)"))`. uint256 private constant _OWNERSHIP_HANDOVER_REQUESTED_EVENT_SIGNATURE = 0xdbf36a107da19e49527a7176a1babf963b4b0ff8cde35ee35d6cd8f1f9ac7e1d; /// @dev `keccak256(bytes("OwnershipHandoverCanceled(address)"))`. uint256 private constant _OWNERSHIP_HANDOVER_CANCELED_EVENT_SIGNATURE = 0xfa7b8eab7da67f412cc9575ed43464468f9bfbae89d1675917346ca6d8fe3c92; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* STORAGE */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The owner slot is given by: /// `bytes32(~uint256(uint32(bytes4(keccak256("_OWNER_SLOT_NOT")))))`. /// It is intentionally chosen to be a high value /// to avoid collision with lower slots. /// The choice of manual storage layout is to enable compatibility /// with both regular and upgradeable contracts. bytes32 internal constant _OWNER_SLOT = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffff74873927; /// The ownership handover slot of `newOwner` is given by: /// ``` /// mstore(0x00, or(shl(96, user), _HANDOVER_SLOT_SEED)) /// let handoverSlot := keccak256(0x00, 0x20) /// ``` /// It stores the expiry timestamp of the two-step ownership handover. uint256 private constant _HANDOVER_SLOT_SEED = 0x389a75e1; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* INTERNAL FUNCTIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Override to return true to make `_initializeOwner` prevent double-initialization. function _guardInitializeOwner() internal pure virtual returns (bool guard) {} /// @dev Initializes the owner directly without authorization guard. /// This function must be called upon initialization, /// regardless of whether the contract is upgradeable or not. /// This is to enable generalization to both regular and upgradeable contracts, /// and to save gas in case the initial owner is not the caller. /// For performance reasons, this function will not check if there /// is an existing owner. function _initializeOwner(address newOwner) internal virtual { if (_guardInitializeOwner()) { /// @solidity memory-safe-assembly assembly { let ownerSlot := _OWNER_SLOT if sload(ownerSlot) { mstore(0x00, 0x0dc149f0) // `AlreadyInitialized()`. revert(0x1c, 0x04) } // Clean the upper 96 bits. newOwner := shr(96, shl(96, newOwner)) // Store the new value. sstore(ownerSlot, or(newOwner, shl(255, iszero(newOwner)))) // Emit the {OwnershipTransferred} event. log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, 0, newOwner) } } else { /// @solidity memory-safe-assembly assembly { // Clean the upper 96 bits. newOwner := shr(96, shl(96, newOwner)) // Store the new value. sstore(_OWNER_SLOT, newOwner) // Emit the {OwnershipTransferred} event. log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, 0, newOwner) } } } /// @dev Sets the owner directly without authorization guard. function _setOwner(address newOwner) internal virtual { if (_guardInitializeOwner()) { /// @solidity memory-safe-assembly assembly { let ownerSlot := _OWNER_SLOT // Clean the upper 96 bits. newOwner := shr(96, shl(96, newOwner)) // Emit the {OwnershipTransferred} event. log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, sload(ownerSlot), newOwner) // Store the new value. sstore(ownerSlot, or(newOwner, shl(255, iszero(newOwner)))) } } else { /// @solidity memory-safe-assembly assembly { let ownerSlot := _OWNER_SLOT // Clean the upper 96 bits. newOwner := shr(96, shl(96, newOwner)) // Emit the {OwnershipTransferred} event. log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, sload(ownerSlot), newOwner) // Store the new value. sstore(ownerSlot, newOwner) } } } /// @dev Throws if the sender is not the owner. function _checkOwner() internal view virtual { /// @solidity memory-safe-assembly assembly { // If the caller is not the stored owner, revert. if iszero(eq(caller(), sload(_OWNER_SLOT))) { mstore(0x00, 0x82b42900) // `Unauthorized()`. revert(0x1c, 0x04) } } } /// @dev Returns how long a two-step ownership handover is valid for in seconds. /// Override to return a different value if needed. /// Made internal to conserve bytecode. Wrap it in a public function if needed. function _ownershipHandoverValidFor() internal view virtual returns (uint64) { return 48 * 3600; } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* PUBLIC UPDATE FUNCTIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Allows the owner to transfer the ownership to `newOwner`. function transferOwnership(address newOwner) public payable virtual onlyOwner { /// @solidity memory-safe-assembly assembly { if iszero(shl(96, newOwner)) { mstore(0x00, 0x7448fbae) // `NewOwnerIsZeroAddress()`. revert(0x1c, 0x04) } } _setOwner(newOwner); } /// @dev Allows the owner to renounce their ownership. function renounceOwnership() public payable virtual onlyOwner { _setOwner(address(0)); } /// @dev Request a two-step ownership handover to the caller. /// The request will automatically expire in 48 hours (172800 seconds) by default. function requestOwnershipHandover() public payable virtual { unchecked { uint256 expires = block.timestamp + _ownershipHandoverValidFor(); /// @solidity memory-safe-assembly assembly { // Compute and set the handover slot to `expires`. mstore(0x0c, _HANDOVER_SLOT_SEED) mstore(0x00, caller()) sstore(keccak256(0x0c, 0x20), expires) // Emit the {OwnershipHandoverRequested} event. log2(0, 0, _OWNERSHIP_HANDOVER_REQUESTED_EVENT_SIGNATURE, caller()) } } } /// @dev Cancels the two-step ownership handover to the caller, if any. function cancelOwnershipHandover() public payable virtual { /// @solidity memory-safe-assembly assembly { // Compute and set the handover slot to 0. mstore(0x0c, _HANDOVER_SLOT_SEED) mstore(0x00, caller()) sstore(keccak256(0x0c, 0x20), 0) // Emit the {OwnershipHandoverCanceled} event. log2(0, 0, _OWNERSHIP_HANDOVER_CANCELED_EVENT_SIGNATURE, caller()) } } /// @dev Allows the owner to complete the two-step ownership handover to `pendingOwner`. /// Reverts if there is no existing ownership handover requested by `pendingOwner`. function completeOwnershipHandover(address pendingOwner) public payable virtual onlyOwner { /// @solidity memory-safe-assembly assembly { // Compute and set the handover slot to 0. mstore(0x0c, _HANDOVER_SLOT_SEED) mstore(0x00, pendingOwner) let handoverSlot := keccak256(0x0c, 0x20) // If the handover does not exist, or has expired. if gt(timestamp(), sload(handoverSlot)) { mstore(0x00, 0x6f5e8818) // `NoHandoverRequest()`. revert(0x1c, 0x04) } // Set the handover slot to 0. sstore(handoverSlot, 0) } _setOwner(pendingOwner); } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* PUBLIC READ FUNCTIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Returns the owner of the contract. function owner() public view virtual returns (address result) { /// @solidity memory-safe-assembly assembly { result := sload(_OWNER_SLOT) } } /// @dev Returns the expiry timestamp for the two-step ownership handover to `pendingOwner`. function ownershipHandoverExpiresAt(address pendingOwner) public view virtual returns (uint256 result) { /// @solidity memory-safe-assembly assembly { // Compute the handover slot. mstore(0x0c, _HANDOVER_SLOT_SEED) mstore(0x00, pendingOwner) // Load the handover slot. result := sload(keccak256(0x0c, 0x20)) } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* MODIFIERS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Marks a function as only callable by the owner. modifier onlyOwner() virtual { _checkOwner(); _; } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; /// @notice Initializable mixin for the upgradeable contracts. /// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/Initializable.sol) /// @author Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/tree/master/contracts/proxy/utils/Initializable.sol) abstract contract Initializable { /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CUSTOM ERRORS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The contract is already initialized. error InvalidInitialization(); /// @dev The contract is not initializing. error NotInitializing(); /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* EVENTS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Triggered when the contract has been initialized. event Initialized(uint64 version); /// @dev `keccak256(bytes("Initialized(uint64)"))`. bytes32 private constant _INTIALIZED_EVENT_SIGNATURE = 0xc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d2; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* STORAGE */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The default initializable slot is given by: /// `bytes32(~uint256(uint32(bytes4(keccak256("_INITIALIZABLE_SLOT")))))`. /// /// Bits Layout: /// - [0] `initializing` /// - [1..64] `initializedVersion` bytes32 private constant _INITIALIZABLE_SLOT = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffbf601132; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Override to return a custom storage slot if required. function _initializableSlot() internal pure virtual returns (bytes32) { return _INITIALIZABLE_SLOT; } /// @dev Guards an initializer function so that it can be invoked at most once. /// /// You can guard a function with `onlyInitializing` such that it can be called /// through a function guarded with `initializer`. /// /// This is similar to `reinitializer(1)`, except that in the context of a constructor, /// an `initializer` guarded function can be invoked multiple times. /// This can be useful during testing and is not expected to be used in production. /// /// Emits an {Initialized} event. modifier initializer() virtual { bytes32 s = _initializableSlot(); /// @solidity memory-safe-assembly assembly { let i := sload(s) // Set `initializing` to 1, `initializedVersion` to 1. sstore(s, 3) // If `!(initializing == 0 && initializedVersion == 0)`. if i { // If `!(address(this).code.length == 0 && initializedVersion == 1)`. if iszero(lt(extcodesize(address()), eq(shr(1, i), 1))) { mstore(0x00, 0xf92ee8a9) // `InvalidInitialization()`. revert(0x1c, 0x04) } s := shl(shl(255, i), s) // Skip initializing if `initializing == 1`. } } _; /// @solidity memory-safe-assembly assembly { if s { // Set `initializing` to 0, `initializedVersion` to 1. sstore(s, 2) // Emit the {Initialized} event. mstore(0x20, 1) log1(0x20, 0x20, _INTIALIZED_EVENT_SIGNATURE) } } } /// @dev Guards an reinitialzer function so that it can be invoked at most once. /// /// You can guard a function with `onlyInitializing` such that it can be called /// through a function guarded with `reinitializer`. /// /// Emits an {Initialized} event. modifier reinitializer(uint64 version) virtual { bytes32 s = _initializableSlot(); /// @solidity memory-safe-assembly assembly { version := and(version, 0xffffffffffffffff) // Clean upper bits. let i := sload(s) // If `initializing == 1 || initializedVersion >= version`. if iszero(lt(and(i, 1), lt(shr(1, i), version))) { mstore(0x00, 0xf92ee8a9) // `InvalidInitialization()`. revert(0x1c, 0x04) } // Set `initializing` to 1, `initializedVersion` to `version`. sstore(s, or(1, shl(1, version))) } _; /// @solidity memory-safe-assembly assembly { // Set `initializing` to 0, `initializedVersion` to `version`. sstore(s, shl(1, version)) // Emit the {Initialized} event. mstore(0x20, version) log1(0x20, 0x20, _INTIALIZED_EVENT_SIGNATURE) } } /// @dev Guards a function such that it can only be called in the scope /// of a function guarded with `initializer` or `reinitializer`. modifier onlyInitializing() virtual { _checkInitializing(); _; } /// @dev Reverts if the contract is not initializing. function _checkInitializing() internal view virtual { bytes32 s = _initializableSlot(); /// @solidity memory-safe-assembly assembly { if iszero(and(1, sload(s))) { mstore(0x00, 0xd7e6bcf8) // `NotInitializing()`. revert(0x1c, 0x04) } } } /// @dev Locks any future initializations by setting the initialized version to `2**64 - 1`. /// /// Calling this in the constructor will prevent the contract from being initialized /// or reinitialized. It is recommended to use this to lock implementation contracts /// that are designed to be called through proxies. /// /// Emits an {Initialized} event the first time it is successfully called. function _disableInitializers() internal virtual { bytes32 s = _initializableSlot(); /// @solidity memory-safe-assembly assembly { let i := sload(s) if and(i, 1) { mstore(0x00, 0xf92ee8a9) // `InvalidInitialization()`. revert(0x1c, 0x04) } let uint64max := shr(192, s) // Computed to save bytecode. if iszero(eq(shr(1, i), uint64max)) { // Set `initializing` to 0, `initializedVersion` to `2**64 - 1`. sstore(s, shl(1, uint64max)) // Emit the {Initialized} event. mstore(0x20, uint64max) log1(0x20, 0x20, _INTIALIZED_EVENT_SIGNATURE) } } } /// @dev Returns the highest version that has been initialized. function _getInitializedVersion() internal view virtual returns (uint64 version) { bytes32 s = _initializableSlot(); /// @solidity memory-safe-assembly assembly { version := shr(1, sload(s)) } } /// @dev Returns whether the contract is currently initializing. function _isInitializing() internal view virtual returns (bool result) { bytes32 s = _initializableSlot(); /// @solidity memory-safe-assembly assembly { result := and(1, sload(s)) } } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; /// @notice UUPS proxy mixin. /// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/UUPSUpgradeable.sol) /// @author Modified from OpenZeppelin /// (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/proxy/utils/UUPSUpgradeable.sol) /// /// Note: /// - This implementation is intended to be used with ERC1967 proxies. /// See: `LibClone.deployERC1967` and related functions. /// - This implementation is NOT compatible with legacy OpenZeppelin proxies /// which do not store the implementation at `_ERC1967_IMPLEMENTATION_SLOT`. abstract contract UUPSUpgradeable { /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CUSTOM ERRORS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The upgrade failed. error UpgradeFailed(); /// @dev The call is from an unauthorized call context. error UnauthorizedCallContext(); /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* IMMUTABLES */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev For checking if the context is a delegate call. uint256 private immutable __self = uint256(uint160(address(this))); /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* EVENTS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Emitted when the proxy's implementation is upgraded. event Upgraded(address indexed implementation); /// @dev `keccak256(bytes("Upgraded(address)"))`. uint256 private constant _UPGRADED_EVENT_SIGNATURE = 0xbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* STORAGE */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The ERC-1967 storage slot for the implementation in the proxy. /// `uint256(keccak256("eip1967.proxy.implementation")) - 1`. bytes32 internal constant _ERC1967_IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* UUPS OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Please override this function to check if `msg.sender` is authorized /// to upgrade the proxy to `newImplementation`, reverting if not. /// ``` /// function _authorizeUpgrade(address) internal override onlyOwner {} /// ``` function _authorizeUpgrade(address newImplementation) internal virtual; /// @dev Returns the storage slot used by the implementation, /// as specified in [ERC1822](https://eips.ethereum.org/EIPS/eip-1822). /// /// Note: The `notDelegated` modifier prevents accidental upgrades to /// an implementation that is a proxy contract. function proxiableUUID() public view virtual notDelegated returns (bytes32) { // This function must always return `_ERC1967_IMPLEMENTATION_SLOT` to comply with ERC1967. return _ERC1967_IMPLEMENTATION_SLOT; } /// @dev Upgrades the proxy's implementation to `newImplementation`. /// Emits a {Upgraded} event. /// /// Note: Passing in empty `data` skips the delegatecall to `newImplementation`. function upgradeToAndCall(address newImplementation, bytes calldata data) public payable virtual onlyProxy { _authorizeUpgrade(newImplementation); /// @solidity memory-safe-assembly assembly { newImplementation := shr(96, shl(96, newImplementation)) // Clears upper 96 bits. mstore(0x01, 0x52d1902d) // `proxiableUUID()`. let s := _ERC1967_IMPLEMENTATION_SLOT // Check if `newImplementation` implements `proxiableUUID` correctly. if iszero(eq(mload(staticcall(gas(), newImplementation, 0x1d, 0x04, 0x01, 0x20)), s)) { mstore(0x01, 0x55299b49) // `UpgradeFailed()`. revert(0x1d, 0x04) } // Emit the {Upgraded} event. log2(codesize(), 0x00, _UPGRADED_EVENT_SIGNATURE, newImplementation) sstore(s, newImplementation) // Updates the implementation. // Perform a delegatecall to `newImplementation` if `data` is non-empty. if data.length { // Forwards the `data` to `newImplementation` via delegatecall. let m := mload(0x40) calldatacopy(m, data.offset, data.length) if iszero(delegatecall(gas(), newImplementation, m, data.length, codesize(), 0x00)) { // Bubble up the revert if the call reverts. returndatacopy(m, 0x00, returndatasize()) revert(m, returndatasize()) } } } } /// @dev Requires that the execution is performed through a proxy. modifier onlyProxy() { uint256 s = __self; /// @solidity memory-safe-assembly assembly { // To enable use cases with an immutable default implementation in the bytecode, // (see: ERC6551Proxy), we don't require that the proxy address must match the // value stored in the implementation slot, which may not be initialized. if eq(s, address()) { mstore(0x00, 0x9f03a026) // `UnauthorizedCallContext()`. revert(0x1c, 0x04) } } _; } /// @dev Requires that the execution is NOT performed via delegatecall. /// This is the opposite of `onlyProxy`. modifier notDelegated() { uint256 s = __self; /// @solidity memory-safe-assembly assembly { if iszero(eq(s, address())) { mstore(0x00, 0x9f03a026) // `UnauthorizedCallContext()`. revert(0x1c, 0x04) } } _; } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; /// @notice Safe ETH and ERC20 transfer library that gracefully handles missing return values. /// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/SafeTransferLib.sol) /// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/SafeTransferLib.sol) /// @author Permit2 operations from (https://github.com/Uniswap/permit2/blob/main/src/libraries/Permit2Lib.sol) /// /// @dev Note: /// - For ETH transfers, please use `forceSafeTransferETH` for DoS protection. /// - For ERC20s, this implementation won't check that a token has code, /// responsibility is delegated to the caller. library SafeTransferLib { /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CUSTOM ERRORS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The ETH transfer has failed. error ETHTransferFailed(); /// @dev The ERC20 `transferFrom` has failed. error TransferFromFailed(); /// @dev The ERC20 `transfer` has failed. error TransferFailed(); /// @dev The ERC20 `approve` has failed. error ApproveFailed(); /// @dev The Permit2 operation has failed. error Permit2Failed(); /// @dev The Permit2 amount must be less than `2**160 - 1`. error Permit2AmountOverflow(); /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CONSTANTS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Suggested gas stipend for contract receiving ETH that disallows any storage writes. uint256 internal constant GAS_STIPEND_NO_STORAGE_WRITES = 2300; /// @dev Suggested gas stipend for contract receiving ETH to perform a few /// storage reads and writes, but low enough to prevent griefing. uint256 internal constant GAS_STIPEND_NO_GRIEF = 100000; /// @dev The unique EIP-712 domain domain separator for the DAI token contract. bytes32 internal constant DAI_DOMAIN_SEPARATOR = 0xdbb8cf42e1ecb028be3f3dbc922e1d878b963f411dc388ced501601c60f7c6f7; /// @dev The address for the WETH9 contract on Ethereum mainnet. address internal constant WETH9 = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2; /// @dev The canonical Permit2 address. /// [Github](https://github.com/Uniswap/permit2) /// [Etherscan](https://etherscan.io/address/0x000000000022D473030F116dDEE9F6B43aC78BA3) address internal constant PERMIT2 = 0x000000000022D473030F116dDEE9F6B43aC78BA3; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* ETH OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ // If the ETH transfer MUST succeed with a reasonable gas budget, use the force variants. // // The regular variants: // - Forwards all remaining gas to the target. // - Reverts if the target reverts. // - Reverts if the current contract has insufficient balance. // // The force variants: // - Forwards with an optional gas stipend // (defaults to `GAS_STIPEND_NO_GRIEF`, which is sufficient for most cases). // - If the target reverts, or if the gas stipend is exhausted, // creates a temporary contract to force send the ETH via `SELFDESTRUCT`. // Future compatible with `SENDALL`: https://eips.ethereum.org/EIPS/eip-4758. // - Reverts if the current contract has insufficient balance. // // The try variants: // - Forwards with a mandatory gas stipend. // - Instead of reverting, returns whether the transfer succeeded. /// @dev Sends `amount` (in wei) ETH to `to`. function safeTransferETH(address to, uint256 amount) internal { /// @solidity memory-safe-assembly assembly { if iszero(call(gas(), to, amount, codesize(), 0x00, codesize(), 0x00)) { mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`. revert(0x1c, 0x04) } } } /// @dev Sends all the ETH in the current contract to `to`. function safeTransferAllETH(address to) internal { /// @solidity memory-safe-assembly assembly { // Transfer all the ETH and check if it succeeded or not. if iszero(call(gas(), to, selfbalance(), codesize(), 0x00, codesize(), 0x00)) { mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`. revert(0x1c, 0x04) } } } /// @dev Force sends `amount` (in wei) ETH to `to`, with a `gasStipend`. function forceSafeTransferETH(address to, uint256 amount, uint256 gasStipend) internal { /// @solidity memory-safe-assembly assembly { if lt(selfbalance(), amount) { mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`. revert(0x1c, 0x04) } if iszero(call(gasStipend, to, amount, codesize(), 0x00, codesize(), 0x00)) { mstore(0x00, to) // Store the address in scratch space. mstore8(0x0b, 0x73) // Opcode `PUSH20`. mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`. if iszero(create(amount, 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation. } } } /// @dev Force sends all the ETH in the current contract to `to`, with a `gasStipend`. function forceSafeTransferAllETH(address to, uint256 gasStipend) internal { /// @solidity memory-safe-assembly assembly { if iszero(call(gasStipend, to, selfbalance(), codesize(), 0x00, codesize(), 0x00)) { mstore(0x00, to) // Store the address in scratch space. mstore8(0x0b, 0x73) // Opcode `PUSH20`. mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`. if iszero(create(selfbalance(), 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation. } } } /// @dev Force sends `amount` (in wei) ETH to `to`, with `GAS_STIPEND_NO_GRIEF`. function forceSafeTransferETH(address to, uint256 amount) internal { /// @solidity memory-safe-assembly assembly { if lt(selfbalance(), amount) { mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`. revert(0x1c, 0x04) } if iszero(call(GAS_STIPEND_NO_GRIEF, to, amount, codesize(), 0x00, codesize(), 0x00)) { mstore(0x00, to) // Store the address in scratch space. mstore8(0x0b, 0x73) // Opcode `PUSH20`. mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`. if iszero(create(amount, 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation. } } } /// @dev Force sends all the ETH in the current contract to `to`, with `GAS_STIPEND_NO_GRIEF`. function forceSafeTransferAllETH(address to) internal { /// @solidity memory-safe-assembly assembly { // forgefmt: disable-next-item if iszero(call(GAS_STIPEND_NO_GRIEF, to, selfbalance(), codesize(), 0x00, codesize(), 0x00)) { mstore(0x00, to) // Store the address in scratch space. mstore8(0x0b, 0x73) // Opcode `PUSH20`. mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`. if iszero(create(selfbalance(), 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation. } } } /// @dev Sends `amount` (in wei) ETH to `to`, with a `gasStipend`. function trySafeTransferETH(address to, uint256 amount, uint256 gasStipend) internal returns (bool success) { /// @solidity memory-safe-assembly assembly { success := call(gasStipend, to, amount, codesize(), 0x00, codesize(), 0x00) } } /// @dev Sends all the ETH in the current contract to `to`, with a `gasStipend`. function trySafeTransferAllETH(address to, uint256 gasStipend) internal returns (bool success) { /// @solidity memory-safe-assembly assembly { success := call(gasStipend, to, selfbalance(), codesize(), 0x00, codesize(), 0x00) } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* ERC20 OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Sends `amount` of ERC20 `token` from `from` to `to`. /// Reverts upon failure. /// /// The `from` account must have at least `amount` approved for /// the current contract to manage. function safeTransferFrom(address token, address from, address to, uint256 amount) internal { /// @solidity memory-safe-assembly assembly { let m := mload(0x40) // Cache the free memory pointer. mstore(0x60, amount) // Store the `amount` argument. mstore(0x40, to) // Store the `to` argument. mstore(0x2c, shl(96, from)) // Store the `from` argument. mstore(0x0c, 0x23b872dd000000000000000000000000) // `transferFrom(address,address,uint256)`. // Perform the transfer, reverting upon failure. if iszero( and( // The arguments of `and` are evaluated from right to left. or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing. call(gas(), token, 0, 0x1c, 0x64, 0x00, 0x20) ) ) { mstore(0x00, 0x7939f424) // `TransferFromFailed()`. revert(0x1c, 0x04) } mstore(0x60, 0) // Restore the zero slot to zero. mstore(0x40, m) // Restore the free memory pointer. } } /// @dev Sends `amount` of ERC20 `token` from `from` to `to`. /// /// The `from` account must have at least `amount` approved for the current contract to manage. function trySafeTransferFrom(address token, address from, address to, uint256 amount) internal returns (bool success) { /// @solidity memory-safe-assembly assembly { let m := mload(0x40) // Cache the free memory pointer. mstore(0x60, amount) // Store the `amount` argument. mstore(0x40, to) // Store the `to` argument. mstore(0x2c, shl(96, from)) // Store the `from` argument. mstore(0x0c, 0x23b872dd000000000000000000000000) // `transferFrom(address,address,uint256)`. success := and( // The arguments of `and` are evaluated from right to left. or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing. call(gas(), token, 0, 0x1c, 0x64, 0x00, 0x20) ) mstore(0x60, 0) // Restore the zero slot to zero. mstore(0x40, m) // Restore the free memory pointer. } } /// @dev Sends all of ERC20 `token` from `from` to `to`. /// Reverts upon failure. /// /// The `from` account must have their entire balance approved for the current contract to manage. function safeTransferAllFrom(address token, address from, address to) internal returns (uint256 amount) { /// @solidity memory-safe-assembly assembly { let m := mload(0x40) // Cache the free memory pointer. mstore(0x40, to) // Store the `to` argument. mstore(0x2c, shl(96, from)) // Store the `from` argument. mstore(0x0c, 0x70a08231000000000000000000000000) // `balanceOf(address)`. // Read the balance, reverting upon failure. if iszero( and( // The arguments of `and` are evaluated from right to left. gt(returndatasize(), 0x1f), // At least 32 bytes returned. staticcall(gas(), token, 0x1c, 0x24, 0x60, 0x20) ) ) { mstore(0x00, 0x7939f424) // `TransferFromFailed()`. revert(0x1c, 0x04) } mstore(0x00, 0x23b872dd) // `transferFrom(address,address,uint256)`. amount := mload(0x60) // The `amount` is already at 0x60. We'll need to return it. // Perform the transfer, reverting upon failure. if iszero( and( // The arguments of `and` are evaluated from right to left. or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing. call(gas(), token, 0, 0x1c, 0x64, 0x00, 0x20) ) ) { mstore(0x00, 0x7939f424) // `TransferFromFailed()`. revert(0x1c, 0x04) } mstore(0x60, 0) // Restore the zero slot to zero. mstore(0x40, m) // Restore the free memory pointer. } } /// @dev Sends `amount` of ERC20 `token` from the current contract to `to`. /// Reverts upon failure. function safeTransfer(address token, address to, uint256 amount) internal { /// @solidity memory-safe-assembly assembly { mstore(0x14, to) // Store the `to` argument. mstore(0x34, amount) // Store the `amount` argument. mstore(0x00, 0xa9059cbb000000000000000000000000) // `transfer(address,uint256)`. // Perform the transfer, reverting upon failure. if iszero( and( // The arguments of `and` are evaluated from right to left. or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing. call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20) ) ) { mstore(0x00, 0x90b8ec18) // `TransferFailed()`. revert(0x1c, 0x04) } mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten. } } /// @dev Sends all of ERC20 `token` from the current contract to `to`. /// Reverts upon failure. function safeTransferAll(address token, address to) internal returns (uint256 amount) { /// @solidity memory-safe-assembly assembly { mstore(0x00, 0x70a08231) // Store the function selector of `balanceOf(address)`. mstore(0x20, address()) // Store the address of the current contract. // Read the balance, reverting upon failure. if iszero( and( // The arguments of `and` are evaluated from right to left. gt(returndatasize(), 0x1f), // At least 32 bytes returned. staticcall(gas(), token, 0x1c, 0x24, 0x34, 0x20) ) ) { mstore(0x00, 0x90b8ec18) // `TransferFailed()`. revert(0x1c, 0x04) } mstore(0x14, to) // Store the `to` argument. amount := mload(0x34) // The `amount` is already at 0x34. We'll need to return it. mstore(0x00, 0xa9059cbb000000000000000000000000) // `transfer(address,uint256)`. // Perform the transfer, reverting upon failure. if iszero( and( // The arguments of `and` are evaluated from right to left. or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing. call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20) ) ) { mstore(0x00, 0x90b8ec18) // `TransferFailed()`. revert(0x1c, 0x04) } mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten. } } /// @dev Sets `amount` of ERC20 `token` for `to` to manage on behalf of the current contract. /// Reverts upon failure. function safeApprove(address token, address to, uint256 amount) internal { /// @solidity memory-safe-assembly assembly { mstore(0x14, to) // Store the `to` argument. mstore(0x34, amount) // Store the `amount` argument. mstore(0x00, 0x095ea7b3000000000000000000000000) // `approve(address,uint256)`. // Perform the approval, reverting upon failure. if iszero( and( // The arguments of `and` are evaluated from right to left. or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing. call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20) ) ) { mstore(0x00, 0x3e3f8f73) // `ApproveFailed()`. revert(0x1c, 0x04) } mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten. } } /// @dev Sets `amount` of ERC20 `token` for `to` to manage on behalf of the current contract. /// If the initial attempt to approve fails, attempts to reset the approved amount to zero, /// then retries the approval again (some tokens, e.g. USDT, requires this). /// Reverts upon failure. function safeApproveWithRetry(address token, address to, uint256 amount) internal { /// @solidity memory-safe-assembly assembly { mstore(0x14, to) // Store the `to` argument. mstore(0x34, amount) // Store the `amount` argument. mstore(0x00, 0x095ea7b3000000000000000000000000) // `approve(address,uint256)`. // Perform the approval, retrying upon failure. if iszero( and( // The arguments of `and` are evaluated from right to left. or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing. call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20) ) ) { mstore(0x34, 0) // Store 0 for the `amount`. mstore(0x00, 0x095ea7b3000000000000000000000000) // `approve(address,uint256)`. pop(call(gas(), token, 0, 0x10, 0x44, codesize(), 0x00)) // Reset the approval. mstore(0x34, amount) // Store back the original `amount`. // Retry the approval, reverting upon failure. if iszero( and( or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing. call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20) ) ) { mstore(0x00, 0x3e3f8f73) // `ApproveFailed()`. revert(0x1c, 0x04) } } mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten. } } /// @dev Returns the amount of ERC20 `token` owned by `account`. /// Returns zero if the `token` does not exist. function balanceOf(address token, address account) internal view returns (uint256 amount) { /// @solidity memory-safe-assembly assembly { mstore(0x14, account) // Store the `account` argument. mstore(0x00, 0x70a08231000000000000000000000000) // `balanceOf(address)`. amount := mul( // The arguments of `mul` are evaluated from right to left. mload(0x20), and( // The arguments of `and` are evaluated from right to left. gt(returndatasize(), 0x1f), // At least 32 bytes returned. staticcall(gas(), token, 0x10, 0x24, 0x20, 0x20) ) ) } } /// @dev Sends `amount` of ERC20 `token` from `from` to `to`. /// If the initial attempt fails, try to use Permit2 to transfer the token. /// Reverts upon failure. /// /// The `from` account must have at least `amount` approved for the current contract to manage. function safeTransferFrom2(address token, address from, address to, uint256 amount) internal { if (!trySafeTransferFrom(token, from, to, amount)) { permit2TransferFrom(token, from, to, amount); } } /// @dev Sends `amount` of ERC20 `token` from `from` to `to` via Permit2. /// Reverts upon failure. function permit2TransferFrom(address token, address from, address to, uint256 amount) internal { /// @solidity memory-safe-assembly assembly { let m := mload(0x40) mstore(add(m, 0x74), shr(96, shl(96, token))) mstore(add(m, 0x54), amount) mstore(add(m, 0x34), to) mstore(add(m, 0x20), shl(96, from)) // `transferFrom(address,address,uint160,address)`. mstore(m, 0x36c78516000000000000000000000000) let p := PERMIT2 let exists := eq(chainid(), 1) if iszero(exists) { exists := iszero(iszero(extcodesize(p))) } if iszero(and(call(gas(), p, 0, add(m, 0x10), 0x84, codesize(), 0x00), exists)) { mstore(0x00, 0x7939f4248757f0fd) // `TransferFromFailed()` or `Permit2AmountOverflow()`. revert(add(0x18, shl(2, iszero(iszero(shr(160, amount))))), 0x04) } } } /// @dev Permit a user to spend a given amount of /// another user's tokens via native EIP-2612 permit if possible, falling /// back to Permit2 if native permit fails or is not implemented on the token. function permit2( address token, address owner, address spender, uint256 amount, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) internal { bool success; /// @solidity memory-safe-assembly assembly { for {} shl(96, xor(token, WETH9)) {} { mstore(0x00, 0x3644e515) // `DOMAIN_SEPARATOR()`. if iszero( and( // The arguments of `and` are evaluated from right to left. lt(iszero(mload(0x00)), eq(returndatasize(), 0x20)), // Returns 1 non-zero word. // Gas stipend to limit gas burn for tokens that don't refund gas when // an non-existing function is called. 5K should be enough for a SLOAD. staticcall(5000, token, 0x1c, 0x04, 0x00, 0x20) ) ) { break } // After here, we can be sure that token is a contract. let m := mload(0x40) mstore(add(m, 0x34), spender) mstore(add(m, 0x20), shl(96, owner)) mstore(add(m, 0x74), deadline) if eq(mload(0x00), DAI_DOMAIN_SEPARATOR) { mstore(0x14, owner) mstore(0x00, 0x7ecebe00000000000000000000000000) // `nonces(address)`. mstore(add(m, 0x94), staticcall(gas(), token, 0x10, 0x24, add(m, 0x54), 0x20)) mstore(m, 0x8fcbaf0c000000000000000000000000) // `IDAIPermit.permit`. // `nonces` is already at `add(m, 0x54)`. // `1` is already stored at `add(m, 0x94)`. mstore(add(m, 0xb4), and(0xff, v)) mstore(add(m, 0xd4), r) mstore(add(m, 0xf4), s) success := call(gas(), token, 0, add(m, 0x10), 0x104, codesize(), 0x00) break } mstore(m, 0xd505accf000000000000000000000000) // `IERC20Permit.permit`. mstore(add(m, 0x54), amount) mstore(add(m, 0x94), and(0xff, v)) mstore(add(m, 0xb4), r) mstore(add(m, 0xd4), s) success := call(gas(), token, 0, add(m, 0x10), 0xe4, codesize(), 0x00) break } } if (!success) simplePermit2(token, owner, spender, amount, deadline, v, r, s); } /// @dev Simple permit on the Permit2 contract. function simplePermit2( address token, address owner, address spender, uint256 amount, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) internal { /// @solidity memory-safe-assembly assembly { let m := mload(0x40) mstore(m, 0x927da105) // `allowance(address,address,address)`. { let addressMask := shr(96, not(0)) mstore(add(m, 0x20), and(addressMask, owner)) mstore(add(m, 0x40), and(addressMask, token)) mstore(add(m, 0x60), and(addressMask, spender)) mstore(add(m, 0xc0), and(addressMask, spender)) } let p := mul(PERMIT2, iszero(shr(160, amount))) if iszero( and( // The arguments of `and` are evaluated from right to left. gt(returndatasize(), 0x5f), // Returns 3 words: `amount`, `expiration`, `nonce`. staticcall(gas(), p, add(m, 0x1c), 0x64, add(m, 0x60), 0x60) ) ) { mstore(0x00, 0x6b836e6b8757f0fd) // `Permit2Failed()` or `Permit2AmountOverflow()`. revert(add(0x18, shl(2, iszero(p))), 0x04) } mstore(m, 0x2b67b570) // `Permit2.permit` (PermitSingle variant). // `owner` is already `add(m, 0x20)`. // `token` is already at `add(m, 0x40)`. mstore(add(m, 0x60), amount) mstore(add(m, 0x80), 0xffffffffffff) // `expiration = type(uint48).max`. // `nonce` is already at `add(m, 0xa0)`. // `spender` is already at `add(m, 0xc0)`. mstore(add(m, 0xe0), deadline) mstore(add(m, 0x100), 0x100) // `signature` offset. mstore(add(m, 0x120), 0x41) // `signature` length. mstore(add(m, 0x140), r) mstore(add(m, 0x160), s) mstore(add(m, 0x180), shl(248, v)) if iszero(call(gas(), p, 0, add(m, 0x1c), 0x184, codesize(), 0x00)) { mstore(0x00, 0x6b836e6b) // `Permit2Failed()`. revert(0x1c, 0x04) } } } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; /// @notice Arithmetic library with operations for fixed-point numbers. /// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/FixedPointMathLib.sol) /// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/FixedPointMathLib.sol) library FixedPointMathLib { /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CUSTOM ERRORS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The operation failed, as the output exceeds the maximum value of uint256. error ExpOverflow(); /// @dev The operation failed, as the output exceeds the maximum value of uint256. error FactorialOverflow(); /// @dev The operation failed, due to an overflow. error RPowOverflow(); /// @dev The mantissa is too big to fit. error MantissaOverflow(); /// @dev The operation failed, due to an multiplication overflow. error MulWadFailed(); /// @dev The operation failed, due to an multiplication overflow. error SMulWadFailed(); /// @dev The operation failed, either due to a multiplication overflow, or a division by a zero. error DivWadFailed(); /// @dev The operation failed, either due to a multiplication overflow, or a division by a zero. error SDivWadFailed(); /// @dev The operation failed, either due to a multiplication overflow, or a division by a zero. error MulDivFailed(); /// @dev The division failed, as the denominator is zero. error DivFailed(); /// @dev The full precision multiply-divide operation failed, either due /// to the result being larger than 256 bits, or a division by a zero. error FullMulDivFailed(); /// @dev The output is undefined, as the input is less-than-or-equal to zero. error LnWadUndefined(); /// @dev The input outside the acceptable domain. error OutOfDomain(); /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CONSTANTS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The scalar of ETH and most ERC20s. uint256 internal constant WAD = 1e18; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* SIMPLIFIED FIXED POINT OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Equivalent to `(x * y) / WAD` rounded down. function mulWad(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { // Equivalent to `require(y == 0 || x <= type(uint256).max / y)`. if mul(y, gt(x, div(not(0), y))) { mstore(0x00, 0xbac65e5b) // `MulWadFailed()`. revert(0x1c, 0x04) } z := div(mul(x, y), WAD) } } /// @dev Equivalent to `(x * y) / WAD` rounded down. function sMulWad(int256 x, int256 y) internal pure returns (int256 z) { /// @solidity memory-safe-assembly assembly { z := mul(x, y) // Equivalent to `require((x == 0 || z / x == y) && !(x == -1 && y == type(int256).min))`. if iszero(gt(or(iszero(x), eq(sdiv(z, x), y)), lt(not(x), eq(y, shl(255, 1))))) { mstore(0x00, 0xedcd4dd4) // `SMulWadFailed()`. revert(0x1c, 0x04) } z := sdiv(z, WAD) } } /// @dev Equivalent to `(x * y) / WAD` rounded down, but without overflow checks. function rawMulWad(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := div(mul(x, y), WAD) } } /// @dev Equivalent to `(x * y) / WAD` rounded down, but without overflow checks. function rawSMulWad(int256 x, int256 y) internal pure returns (int256 z) { /// @solidity memory-safe-assembly assembly { z := sdiv(mul(x, y), WAD) } } /// @dev Equivalent to `(x * y) / WAD` rounded up. function mulWadUp(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { // Equivalent to `require(y == 0 || x <= type(uint256).max / y)`. if mul(y, gt(x, div(not(0), y))) { mstore(0x00, 0xbac65e5b) // `MulWadFailed()`. revert(0x1c, 0x04) } z := add(iszero(iszero(mod(mul(x, y), WAD))), div(mul(x, y), WAD)) } } /// @dev Equivalent to `(x * y) / WAD` rounded up, but without overflow checks. function rawMulWadUp(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := add(iszero(iszero(mod(mul(x, y), WAD))), div(mul(x, y), WAD)) } } /// @dev Equivalent to `(x * WAD) / y` rounded down. function divWad(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { // Equivalent to `require(y != 0 && (WAD == 0 || x <= type(uint256).max / WAD))`. if iszero(mul(y, iszero(mul(WAD, gt(x, div(not(0), WAD)))))) { mstore(0x00, 0x7c5f487d) // `DivWadFailed()`. revert(0x1c, 0x04) } z := div(mul(x, WAD), y) } } /// @dev Equivalent to `(x * WAD) / y` rounded down. function sDivWad(int256 x, int256 y) internal pure returns (int256 z) { /// @solidity memory-safe-assembly assembly { z := mul(x, WAD) // Equivalent to `require(y != 0 && ((x * WAD) / WAD == x))`. if iszero(and(iszero(iszero(y)), eq(sdiv(z, WAD), x))) { mstore(0x00, 0x5c43740d) // `SDivWadFailed()`. revert(0x1c, 0x04) } z := sdiv(mul(x, WAD), y) } } /// @dev Equivalent to `(x * WAD) / y` rounded down, but without overflow and divide by zero checks. function rawDivWad(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := div(mul(x, WAD), y) } } /// @dev Equivalent to `(x * WAD) / y` rounded down, but without overflow and divide by zero checks. function rawSDivWad(int256 x, int256 y) internal pure returns (int256 z) { /// @solidity memory-safe-assembly assembly { z := sdiv(mul(x, WAD), y) } } /// @dev Equivalent to `(x * WAD) / y` rounded up. function divWadUp(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { // Equivalent to `require(y != 0 && (WAD == 0 || x <= type(uint256).max / WAD))`. if iszero(mul(y, iszero(mul(WAD, gt(x, div(not(0), WAD)))))) { mstore(0x00, 0x7c5f487d) // `DivWadFailed()`. revert(0x1c, 0x04) } z := add(iszero(iszero(mod(mul(x, WAD), y))), div(mul(x, WAD), y)) } } /// @dev Equivalent to `(x * WAD) / y` rounded up, but without overflow and divide by zero checks. function rawDivWadUp(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := add(iszero(iszero(mod(mul(x, WAD), y))), div(mul(x, WAD), y)) } } /// @dev Equivalent to `x` to the power of `y`. /// because `x ** y = (e ** ln(x)) ** y = e ** (ln(x) * y)`. function powWad(int256 x, int256 y) internal pure returns (int256) { // Using `ln(x)` means `x` must be greater than 0. return expWad((lnWad(x) * y) / int256(WAD)); } /// @dev Returns `exp(x)`, denominated in `WAD`. /// Credit to Remco Bloemen under MIT license: https://2π.com/22/exp-ln function expWad(int256 x) internal pure returns (int256 r) { unchecked { // When the result is less than 0.5 we return zero. // This happens when `x <= (log(1e-18) * 1e18) ~ -4.15e19`. if (x <= -41446531673892822313) return r; /// @solidity memory-safe-assembly assembly { // When the result is greater than `(2**255 - 1) / 1e18` we can not represent it as // an int. This happens when `x >= floor(log((2**255 - 1) / 1e18) * 1e18) ≈ 135`. if iszero(slt(x, 135305999368893231589)) { mstore(0x00, 0xa37bfec9) // `ExpOverflow()`. revert(0x1c, 0x04) } } // `x` is now in the range `(-42, 136) * 1e18`. Convert to `(-42, 136) * 2**96` // for more intermediate precision and a binary basis. This base conversion // is a multiplication by 1e18 / 2**96 = 5**18 / 2**78. x = (x << 78) / 5 ** 18; // Reduce range of x to (-½ ln 2, ½ ln 2) * 2**96 by factoring out powers // of two such that exp(x) = exp(x') * 2**k, where k is an integer. // Solving this gives k = round(x / log(2)) and x' = x - k * log(2). int256 k = ((x << 96) / 54916777467707473351141471128 + 2 ** 95) >> 96; x = x - k * 54916777467707473351141471128; // `k` is in the range `[-61, 195]`. // Evaluate using a (6, 7)-term rational approximation. // `p` is made monic, we'll multiply by a scale factor later. int256 y = x + 1346386616545796478920950773328; y = ((y * x) >> 96) + 57155421227552351082224309758442; int256 p = y + x - 94201549194550492254356042504812; p = ((p * y) >> 96) + 28719021644029726153956944680412240; p = p * x + (4385272521454847904659076985693276 << 96); // We leave `p` in `2**192` basis so we don't need to scale it back up for the division. int256 q = x - 2855989394907223263936484059900; q = ((q * x) >> 96) + 50020603652535783019961831881945; q = ((q * x) >> 96) - 533845033583426703283633433725380; q = ((q * x) >> 96) + 3604857256930695427073651918091429; q = ((q * x) >> 96) - 14423608567350463180887372962807573; q = ((q * x) >> 96) + 26449188498355588339934803723976023; /// @solidity memory-safe-assembly assembly { // Div in assembly because solidity adds a zero check despite the unchecked. // The q polynomial won't have zeros in the domain as all its roots are complex. // No scaling is necessary because p is already `2**96` too large. r := sdiv(p, q) } // r should be in the range `(0.09, 0.25) * 2**96`. // We now need to multiply r by: // - The scale factor `s ≈ 6.031367120`. // - The `2**k` factor from the range reduction. // - The `1e18 / 2**96` factor for base conversion. // We do this all at once, with an intermediate result in `2**213` // basis, so the final right shift is always by a positive amount. r = int256( (uint256(r) * 3822833074963236453042738258902158003155416615667) >> uint256(195 - k) ); } } /// @dev Returns `ln(x)`, denominated in `WAD`. /// Credit to Remco Bloemen under MIT license: https://2π.com/22/exp-ln function lnWad(int256 x) internal pure returns (int256 r) { /// @solidity memory-safe-assembly assembly { // We want to convert `x` from `10**18` fixed point to `2**96` fixed point. // We do this by multiplying by `2**96 / 10**18`. But since // `ln(x * C) = ln(x) + ln(C)`, we can simply do nothing here // and add `ln(2**96 / 10**18)` at the end. // Compute `k = log2(x) - 96`, `r = 159 - k = 255 - log2(x) = 255 ^ log2(x)`. r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x)) r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x)))) r := or(r, shl(5, lt(0xffffffff, shr(r, x)))) r := or(r, shl(4, lt(0xffff, shr(r, x)))) r := or(r, shl(3, lt(0xff, shr(r, x)))) // We place the check here for more optimal stack operations. if iszero(sgt(x, 0)) { mstore(0x00, 0x1615e638) // `LnWadUndefined()`. revert(0x1c, 0x04) } // forgefmt: disable-next-item r := xor(r, byte(and(0x1f, shr(shr(r, x), 0x8421084210842108cc6318c6db6d54be)), 0xf8f9f9faf9fdfafbf9fdfcfdfafbfcfef9fafdfafcfcfbfefafafcfbffffffff)) // Reduce range of x to (1, 2) * 2**96 // ln(2^k * x) = k * ln(2) + ln(x) x := shr(159, shl(r, x)) // Evaluate using a (8, 8)-term rational approximation. // `p` is made monic, we will multiply by a scale factor later. // forgefmt: disable-next-item let p := sub( // This heavily nested expression is to avoid stack-too-deep for via-ir. sar(96, mul(add(43456485725739037958740375743393, sar(96, mul(add(24828157081833163892658089445524, sar(96, mul(add(3273285459638523848632254066296, x), x))), x))), x)), 11111509109440967052023855526967) p := sub(sar(96, mul(p, x)), 45023709667254063763336534515857) p := sub(sar(96, mul(p, x)), 14706773417378608786704636184526) p := sub(mul(p, x), shl(96, 795164235651350426258249787498)) // We leave `p` in `2**192` basis so we don't need to scale it back up for the division. // `q` is monic by convention. let q := add(5573035233440673466300451813936, x) q := add(71694874799317883764090561454958, sar(96, mul(x, q))) q := add(283447036172924575727196451306956, sar(96, mul(x, q))) q := add(401686690394027663651624208769553, sar(96, mul(x, q))) q := add(204048457590392012362485061816622, sar(96, mul(x, q))) q := add(31853899698501571402653359427138, sar(96, mul(x, q))) q := add(909429971244387300277376558375, sar(96, mul(x, q))) // `p / q` is in the range `(0, 0.125) * 2**96`. // Finalization, we need to: // - Multiply by the scale factor `s = 5.549…`. // - Add `ln(2**96 / 10**18)`. // - Add `k * ln(2)`. // - Multiply by `10**18 / 2**96 = 5**18 >> 78`. // The q polynomial is known not to have zeros in the domain. // No scaling required because p is already `2**96` too large. p := sdiv(p, q) // Multiply by the scaling factor: `s * 5**18 * 2**96`, base is now `5**18 * 2**192`. p := mul(1677202110996718588342820967067443963516166, p) // Add `ln(2) * k * 5**18 * 2**192`. // forgefmt: disable-next-item p := add(mul(16597577552685614221487285958193947469193820559219878177908093499208371, sub(159, r)), p) // Add `ln(2**96 / 10**18) * 5**18 * 2**192`. p := add(600920179829731861736702779321621459595472258049074101567377883020018308, p) // Base conversion: mul `2**18 / 2**192`. r := sar(174, p) } } /// @dev Returns `W_0(x)`, denominated in `WAD`. /// See: https://en.wikipedia.org/wiki/Lambert_W_function /// a.k.a. Product log function. This is an approximation of the principal branch. function lambertW0Wad(int256 x) internal pure returns (int256 w) { // forgefmt: disable-next-item unchecked { if ((w = x) <= -367879441171442322) revert OutOfDomain(); // `x` less than `-1/e`. int256 wad = int256(WAD); int256 p = x; uint256 c; // Whether we need to avoid catastrophic cancellation. uint256 i = 4; // Number of iterations. if (w <= 0x1ffffffffffff) { if (-0x4000000000000 <= w) { i = 1; // Inputs near zero only take one step to converge. } else if (w <= -0x3ffffffffffffff) { i = 32; // Inputs near `-1/e` take very long to converge. } } else if (w >> 63 == 0) { /// @solidity memory-safe-assembly assembly { // Inline log2 for more performance, since the range is small. let v := shr(49, w) let l := shl(3, lt(0xff, v)) l := add(or(l, byte(and(0x1f, shr(shr(l, v), 0x8421084210842108cc6318c6db6d54be)), 0x0706060506020504060203020504030106050205030304010505030400000000)), 49) w := sdiv(shl(l, 7), byte(sub(l, 31), 0x0303030303030303040506080c13)) c := gt(l, 60) i := add(2, add(gt(l, 53), c)) } } else { int256 ll = lnWad(w = lnWad(w)); /// @solidity memory-safe-assembly assembly { // `w = ln(x) - ln(ln(x)) + b * ln(ln(x)) / ln(x)`. w := add(sdiv(mul(ll, 1023715080943847266), w), sub(w, ll)) i := add(3, iszero(shr(68, x))) c := iszero(shr(143, x)) } if (c == 0) { do { // If `x` is big, use Newton's so that intermediate values won't overflow. int256 e = expWad(w); /// @solidity memory-safe-assembly assembly { let t := mul(w, div(e, wad)) w := sub(w, sdiv(sub(t, x), div(add(e, t), wad))) } if (p <= w) break; p = w; } while (--i != 0); /// @solidity memory-safe-assembly assembly { w := sub(w, sgt(w, 2)) } return w; } } do { // Otherwise, use Halley's for faster convergence. int256 e = expWad(w); /// @solidity memory-safe-assembly assembly { let t := add(w, wad) let s := sub(mul(w, e), mul(x, wad)) w := sub(w, sdiv(mul(s, wad), sub(mul(e, t), sdiv(mul(add(t, wad), s), add(t, t))))) } if (p <= w) break; p = w; } while (--i != c); /// @solidity memory-safe-assembly assembly { w := sub(w, sgt(w, 2)) } // For certain ranges of `x`, we'll use the quadratic-rate recursive formula of // R. Iacono and J.P. Boyd for the last iteration, to avoid catastrophic cancellation. if (c != 0) { int256 t = w | 1; /// @solidity memory-safe-assembly assembly { x := sdiv(mul(x, wad), t) } x = (t * (wad + lnWad(x))); /// @solidity memory-safe-assembly assembly { w := sdiv(x, add(wad, t)) } } } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* GENERAL NUMBER UTILITIES */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Calculates `floor(x * y / d)` with full precision. /// Throws if result overflows a uint256 or when `d` is zero. /// Credit to Remco Bloemen under MIT license: https://2π.com/21/muldiv function fullMulDiv(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 result) { /// @solidity memory-safe-assembly assembly { for {} 1 {} { // 512-bit multiply `[p1 p0] = x * y`. // Compute the product mod `2**256` and mod `2**256 - 1` // then use the Chinese Remainder Theorem to reconstruct // the 512 bit result. The result is stored in two 256 // variables such that `product = p1 * 2**256 + p0`. // Least significant 256 bits of the product. result := mul(x, y) // Temporarily use `result` as `p0` to save gas. let mm := mulmod(x, y, not(0)) // Most significant 256 bits of the product. let p1 := sub(mm, add(result, lt(mm, result))) // Handle non-overflow cases, 256 by 256 division. if iszero(p1) { if iszero(d) { mstore(0x00, 0xae47f702) // `FullMulDivFailed()`. revert(0x1c, 0x04) } result := div(result, d) break } // Make sure the result is less than `2**256`. Also prevents `d == 0`. if iszero(gt(d, p1)) { mstore(0x00, 0xae47f702) // `FullMulDivFailed()`. revert(0x1c, 0x04) } /*------------------- 512 by 256 division --------------------*/ // Make division exact by subtracting the remainder from `[p1 p0]`. // Compute remainder using mulmod. let r := mulmod(x, y, d) // `t` is the least significant bit of `d`. // Always greater or equal to 1. let t := and(d, sub(0, d)) // Divide `d` by `t`, which is a power of two. d := div(d, t) // Invert `d mod 2**256` // Now that `d` is an odd number, it has an inverse // modulo `2**256` such that `d * inv = 1 mod 2**256`. // Compute the inverse by starting with a seed that is correct // correct for four bits. That is, `d * inv = 1 mod 2**4`. let inv := xor(2, mul(3, d)) // Now use 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. inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**8 inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**16 inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**32 inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**64 inv := mul(inv, sub(2, mul(d, inv))) // inverse mod 2**128 result := mul( // Divide [p1 p0] by the factors of two. // Shift in bits from `p1` into `p0`. For this we need // to flip `t` such that it is `2**256 / t`. or( mul(sub(p1, gt(r, result)), add(div(sub(0, t), t), 1)), div(sub(result, r), t) ), // inverse mod 2**256 mul(inv, sub(2, mul(d, inv))) ) break } } } /// @dev Calculates `floor(x * y / d)` with full precision, rounded up. /// Throws if result overflows a uint256 or when `d` is zero. /// Credit to Uniswap-v3-core under MIT license: /// https://github.com/Uniswap/v3-core/blob/main/contracts/libraries/FullMath.sol function fullMulDivUp(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 result) { result = fullMulDiv(x, y, d); /// @solidity memory-safe-assembly assembly { if mulmod(x, y, d) { result := add(result, 1) if iszero(result) { mstore(0x00, 0xae47f702) // `FullMulDivFailed()`. revert(0x1c, 0x04) } } } } /// @dev Returns `floor(x * y / d)`. /// Reverts if `x * y` overflows, or `d` is zero. function mulDiv(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { // Equivalent to require(d != 0 && (y == 0 || x <= type(uint256).max / y)) if iszero(mul(d, iszero(mul(y, gt(x, div(not(0), y)))))) { mstore(0x00, 0xad251c27) // `MulDivFailed()`. revert(0x1c, 0x04) } z := div(mul(x, y), d) } } /// @dev Returns `ceil(x * y / d)`. /// Reverts if `x * y` overflows, or `d` is zero. function mulDivUp(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { // Equivalent to require(d != 0 && (y == 0 || x <= type(uint256).max / y)) if iszero(mul(d, iszero(mul(y, gt(x, div(not(0), y)))))) { mstore(0x00, 0xad251c27) // `MulDivFailed()`. revert(0x1c, 0x04) } z := add(iszero(iszero(mod(mul(x, y), d))), div(mul(x, y), d)) } } /// @dev Returns `ceil(x / d)`. /// Reverts if `d` is zero. function divUp(uint256 x, uint256 d) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { if iszero(d) { mstore(0x00, 0x65244e4e) // `DivFailed()`. revert(0x1c, 0x04) } z := add(iszero(iszero(mod(x, d))), div(x, d)) } } /// @dev Returns `max(0, x - y)`. function zeroFloorSub(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := mul(gt(x, y), sub(x, y)) } } /// @dev Exponentiate `x` to `y` by squaring, denominated in base `b`. /// Reverts if the computation overflows. function rpow(uint256 x, uint256 y, uint256 b) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := mul(b, iszero(y)) // `0 ** 0 = 1`. Otherwise, `0 ** n = 0`. if x { z := xor(b, mul(xor(b, x), and(y, 1))) // `z = isEven(y) ? scale : x` let half := shr(1, b) // Divide `b` by 2. // Divide `y` by 2 every iteration. for { y := shr(1, y) } y { y := shr(1, y) } { let xx := mul(x, x) // Store x squared. let xxRound := add(xx, half) // Round to the nearest number. // Revert if `xx + half` overflowed, or if `x ** 2` overflows. if or(lt(xxRound, xx), shr(128, x)) { mstore(0x00, 0x49f7642b) // `RPowOverflow()`. revert(0x1c, 0x04) } x := div(xxRound, b) // Set `x` to scaled `xxRound`. // If `y` is odd: if and(y, 1) { let zx := mul(z, x) // Compute `z * x`. let zxRound := add(zx, half) // Round to the nearest number. // If `z * x` overflowed or `zx + half` overflowed: if or(xor(div(zx, x), z), lt(zxRound, zx)) { // Revert if `x` is non-zero. if iszero(iszero(x)) { mstore(0x00, 0x49f7642b) // `RPowOverflow()`. revert(0x1c, 0x04) } } z := div(zxRound, b) // Return properly scaled `zxRound`. } } } } } /// @dev Returns the square root of `x`. function sqrt(uint256 x) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { // `floor(sqrt(2**15)) = 181`. `sqrt(2**15) - 181 = 2.84`. z := 181 // The "correct" value is 1, but this saves a multiplication later. // This segment is to get a reasonable initial estimate for the Babylonian method. With a bad // start, the correct # of bits increases ~linearly each iteration instead of ~quadratically. // Let `y = x / 2**r`. We check `y >= 2**(k + 8)` // but shift right by `k` bits to ensure that if `x >= 256`, then `y >= 256`. let r := shl(7, lt(0xffffffffffffffffffffffffffffffffff, x)) r := or(r, shl(6, lt(0xffffffffffffffffff, shr(r, x)))) r := or(r, shl(5, lt(0xffffffffff, shr(r, x)))) r := or(r, shl(4, lt(0xffffff, shr(r, x)))) z := shl(shr(1, r), z) // Goal was to get `z*z*y` within a small factor of `x`. More iterations could // get y in a tighter range. Currently, we will have y in `[256, 256*(2**16))`. // We ensured `y >= 256` so that the relative difference between `y` and `y+1` is small. // That's not possible if `x < 256` but we can just verify those cases exhaustively. // Now, `z*z*y <= x < z*z*(y+1)`, and `y <= 2**(16+8)`, and either `y >= 256`, or `x < 256`. // Correctness can be checked exhaustively for `x < 256`, so we assume `y >= 256`. // Then `z*sqrt(y)` is within `sqrt(257)/sqrt(256)` of `sqrt(x)`, or about 20bps. // For `s` in the range `[1/256, 256]`, the estimate `f(s) = (181/1024) * (s+1)` // is in the range `(1/2.84 * sqrt(s), 2.84 * sqrt(s))`, // with largest error when `s = 1` and when `s = 256` or `1/256`. // Since `y` is in `[256, 256*(2**16))`, let `a = y/65536`, so that `a` is in `[1/256, 256)`. // Then we can estimate `sqrt(y)` using // `sqrt(65536) * 181/1024 * (a + 1) = 181/4 * (y + 65536)/65536 = 181 * (y + 65536)/2**18`. // There is no overflow risk here since `y < 2**136` after the first branch above. z := shr(18, mul(z, add(shr(r, x), 65536))) // A `mul()` is saved from starting `z` at 181. // Given the worst case multiplicative error of 2.84 above, 7 iterations should be enough. 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))) // If `x+1` is a perfect square, the Babylonian method cycles between // `floor(sqrt(x))` and `ceil(sqrt(x))`. This statement ensures we return floor. // See: https://en.wikipedia.org/wiki/Integer_square_root#Using_only_integer_division z := sub(z, lt(div(x, z), z)) } } /// @dev Returns the cube root of `x`. /// Credit to bout3fiddy and pcaversaccio under AGPLv3 license: /// https://github.com/pcaversaccio/snekmate/blob/main/src/utils/Math.vy function cbrt(uint256 x) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { let r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x)) r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x)))) r := or(r, shl(5, lt(0xffffffff, shr(r, x)))) r := or(r, shl(4, lt(0xffff, shr(r, x)))) r := or(r, shl(3, lt(0xff, shr(r, x)))) z := div(shl(div(r, 3), shl(lt(0xf, shr(r, x)), 0xf)), xor(7, mod(r, 3))) z := div(add(add(div(x, mul(z, z)), z), z), 3) z := div(add(add(div(x, mul(z, z)), z), z), 3) z := div(add(add(div(x, mul(z, z)), z), z), 3) z := div(add(add(div(x, mul(z, z)), z), z), 3) z := div(add(add(div(x, mul(z, z)), z), z), 3) z := div(add(add(div(x, mul(z, z)), z), z), 3) z := div(add(add(div(x, mul(z, z)), z), z), 3) z := sub(z, lt(div(x, mul(z, z)), z)) } } /// @dev Returns the square root of `x`, denominated in `WAD`. function sqrtWad(uint256 x) internal pure returns (uint256 z) { unchecked { z = 10 ** 9; if (x <= type(uint256).max / 10 ** 36 - 1) { x *= 10 ** 18; z = 1; } z *= sqrt(x); } } /// @dev Returns the cube root of `x`, denominated in `WAD`. function cbrtWad(uint256 x) internal pure returns (uint256 z) { unchecked { z = 10 ** 12; if (x <= (type(uint256).max / 10 ** 36) * 10 ** 18 - 1) { if (x >= type(uint256).max / 10 ** 36) { x *= 10 ** 18; z = 10 ** 6; } else { x *= 10 ** 36; z = 1; } } z *= cbrt(x); } } /// @dev Returns the factorial of `x`. function factorial(uint256 x) internal pure returns (uint256 result) { /// @solidity memory-safe-assembly assembly { if iszero(lt(x, 58)) { mstore(0x00, 0xaba0f2a2) // `FactorialOverflow()`. revert(0x1c, 0x04) } for { result := 1 } x { x := sub(x, 1) } { result := mul(result, x) } } } /// @dev Returns the log2 of `x`. /// Equivalent to computing the index of the most significant bit (MSB) of `x`. /// Returns 0 if `x` is zero. function log2(uint256 x) internal pure returns (uint256 r) { /// @solidity memory-safe-assembly assembly { r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x)) r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x)))) r := or(r, shl(5, lt(0xffffffff, shr(r, x)))) r := or(r, shl(4, lt(0xffff, shr(r, x)))) r := or(r, shl(3, lt(0xff, shr(r, x)))) // forgefmt: disable-next-item r := or(r, byte(and(0x1f, shr(shr(r, x), 0x8421084210842108cc6318c6db6d54be)), 0x0706060506020504060203020504030106050205030304010505030400000000)) } } /// @dev Returns the log2 of `x`, rounded up. /// Returns 0 if `x` is zero. function log2Up(uint256 x) internal pure returns (uint256 r) { r = log2(x); /// @solidity memory-safe-assembly assembly { r := add(r, lt(shl(r, 1), x)) } } /// @dev Returns the log10 of `x`. /// Returns 0 if `x` is zero. function log10(uint256 x) internal pure returns (uint256 r) { /// @solidity memory-safe-assembly assembly { if iszero(lt(x, 100000000000000000000000000000000000000)) { x := div(x, 100000000000000000000000000000000000000) r := 38 } if iszero(lt(x, 100000000000000000000)) { x := div(x, 100000000000000000000) r := add(r, 20) } if iszero(lt(x, 10000000000)) { x := div(x, 10000000000) r := add(r, 10) } if iszero(lt(x, 100000)) { x := div(x, 100000) r := add(r, 5) } r := add(r, add(gt(x, 9), add(gt(x, 99), add(gt(x, 999), gt(x, 9999))))) } } /// @dev Returns the log10 of `x`, rounded up. /// Returns 0 if `x` is zero. function log10Up(uint256 x) internal pure returns (uint256 r) { r = log10(x); /// @solidity memory-safe-assembly assembly { r := add(r, lt(exp(10, r), x)) } } /// @dev Returns the log256 of `x`. /// Returns 0 if `x` is zero. function log256(uint256 x) internal pure returns (uint256 r) { /// @solidity memory-safe-assembly assembly { r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x)) r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x)))) r := or(r, shl(5, lt(0xffffffff, shr(r, x)))) r := or(r, shl(4, lt(0xffff, shr(r, x)))) r := or(shr(3, r), lt(0xff, shr(r, x))) } } /// @dev Returns the log256 of `x`, rounded up. /// Returns 0 if `x` is zero. function log256Up(uint256 x) internal pure returns (uint256 r) { r = log256(x); /// @solidity memory-safe-assembly assembly { r := add(r, lt(shl(shl(3, r), 1), x)) } } /// @dev Returns the scientific notation format `mantissa * 10 ** exponent` of `x`. /// Useful for compressing prices (e.g. using 25 bit mantissa and 7 bit exponent). function sci(uint256 x) internal pure returns (uint256 mantissa, uint256 exponent) { /// @solidity memory-safe-assembly assembly { mantissa := x if mantissa { if iszero(mod(mantissa, 1000000000000000000000000000000000)) { mantissa := div(mantissa, 1000000000000000000000000000000000) exponent := 33 } if iszero(mod(mantissa, 10000000000000000000)) { mantissa := div(mantissa, 10000000000000000000) exponent := add(exponent, 19) } if iszero(mod(mantissa, 1000000000000)) { mantissa := div(mantissa, 1000000000000) exponent := add(exponent, 12) } if iszero(mod(mantissa, 1000000)) { mantissa := div(mantissa, 1000000) exponent := add(exponent, 6) } if iszero(mod(mantissa, 10000)) { mantissa := div(mantissa, 10000) exponent := add(exponent, 4) } if iszero(mod(mantissa, 100)) { mantissa := div(mantissa, 100) exponent := add(exponent, 2) } if iszero(mod(mantissa, 10)) { mantissa := div(mantissa, 10) exponent := add(exponent, 1) } } } } /// @dev Convenience function for packing `x` into a smaller number using `sci`. /// The `mantissa` will be in bits [7..255] (the upper 249 bits). /// The `exponent` will be in bits [0..6] (the lower 7 bits). /// Use `SafeCastLib` to safely ensure that the `packed` number is small /// enough to fit in the desired unsigned integer type: /// ``` /// uint32 packed = SafeCastLib.toUint32(FixedPointMathLib.packSci(777 ether)); /// ``` function packSci(uint256 x) internal pure returns (uint256 packed) { (x, packed) = sci(x); // Reuse for `mantissa` and `exponent`. /// @solidity memory-safe-assembly assembly { if shr(249, x) { mstore(0x00, 0xce30380c) // `MantissaOverflow()`. revert(0x1c, 0x04) } packed := or(shl(7, x), packed) } } /// @dev Convenience function for unpacking a packed number from `packSci`. function unpackSci(uint256 packed) internal pure returns (uint256 unpacked) { unchecked { unpacked = (packed >> 7) * 10 ** (packed & 0x7f); } } /// @dev Returns the average of `x` and `y`. function avg(uint256 x, uint256 y) internal pure returns (uint256 z) { unchecked { z = (x & y) + ((x ^ y) >> 1); } } /// @dev Returns the average of `x` and `y`. function avg(int256 x, int256 y) internal pure returns (int256 z) { unchecked { z = (x >> 1) + (y >> 1) + (x & y & 1); } } /// @dev Returns the absolute value of `x`. function abs(int256 x) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := xor(sar(255, x), add(sar(255, x), x)) } } /// @dev Returns the absolute distance between `x` and `y`. function dist(int256 x, int256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := xor(mul(xor(sub(y, x), sub(x, y)), sgt(x, y)), sub(y, x)) } } /// @dev Returns the minimum of `x` and `y`. function min(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := xor(x, mul(xor(x, y), lt(y, x))) } } /// @dev Returns the minimum of `x` and `y`. function min(int256 x, int256 y) internal pure returns (int256 z) { /// @solidity memory-safe-assembly assembly { z := xor(x, mul(xor(x, y), slt(y, x))) } } /// @dev Returns the maximum of `x` and `y`. function max(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := xor(x, mul(xor(x, y), gt(y, x))) } } /// @dev Returns the maximum of `x` and `y`. function max(int256 x, int256 y) internal pure returns (int256 z) { /// @solidity memory-safe-assembly assembly { z := xor(x, mul(xor(x, y), sgt(y, x))) } } /// @dev Returns `x`, bounded to `minValue` and `maxValue`. function clamp(uint256 x, uint256 minValue, uint256 maxValue) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := xor(x, mul(xor(x, minValue), gt(minValue, x))) z := xor(z, mul(xor(z, maxValue), lt(maxValue, z))) } } /// @dev Returns `x`, bounded to `minValue` and `maxValue`. function clamp(int256 x, int256 minValue, int256 maxValue) internal pure returns (int256 z) { /// @solidity memory-safe-assembly assembly { z := xor(x, mul(xor(x, minValue), sgt(minValue, x))) z := xor(z, mul(xor(z, maxValue), slt(maxValue, z))) } } /// @dev Returns greatest common divisor of `x` and `y`. function gcd(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { for { z := x } y {} { let t := y y := mod(z, y) z := t } } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* RAW NUMBER OPERATIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Returns `x + y`, without checking for overflow. function rawAdd(uint256 x, uint256 y) internal pure returns (uint256 z) { unchecked { z = x + y; } } /// @dev Returns `x + y`, without checking for overflow. function rawAdd(int256 x, int256 y) internal pure returns (int256 z) { unchecked { z = x + y; } } /// @dev Returns `x - y`, without checking for underflow. function rawSub(uint256 x, uint256 y) internal pure returns (uint256 z) { unchecked { z = x - y; } } /// @dev Returns `x - y`, without checking for underflow. function rawSub(int256 x, int256 y) internal pure returns (int256 z) { unchecked { z = x - y; } } /// @dev Returns `x * y`, without checking for overflow. function rawMul(uint256 x, uint256 y) internal pure returns (uint256 z) { unchecked { z = x * y; } } /// @dev Returns `x * y`, without checking for overflow. function rawMul(int256 x, int256 y) internal pure returns (int256 z) { unchecked { z = x * y; } } /// @dev Returns `x / y`, returning 0 if `y` is zero. function rawDiv(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := div(x, y) } } /// @dev Returns `x / y`, returning 0 if `y` is zero. function rawSDiv(int256 x, int256 y) internal pure returns (int256 z) { /// @solidity memory-safe-assembly assembly { z := sdiv(x, y) } } /// @dev Returns `x % y`, returning 0 if `y` is zero. function rawMod(uint256 x, uint256 y) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := mod(x, y) } } /// @dev Returns `x % y`, returning 0 if `y` is zero. function rawSMod(int256 x, int256 y) internal pure returns (int256 z) { /// @solidity memory-safe-assembly assembly { z := smod(x, y) } } /// @dev Returns `(x + y) % d`, return 0 if `d` if zero. function rawAddMod(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := addmod(x, y, d) } } /// @dev Returns `(x * y) % d`, return 0 if `d` if zero. function rawMulMod(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) { /// @solidity memory-safe-assembly assembly { z := mulmod(x, y, d) } } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; /// @notice Simple ERC20 + EIP-2612 implementation. /// @author Solady (https://github.com/vectorized/solady/blob/main/src/tokens/ERC20.sol) /// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/tokens/ERC20.sol) /// @author Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol) /// /// @dev Note: /// - The ERC20 standard allows minting and transferring to and from the zero address, /// minting and transferring zero tokens, as well as self-approvals. /// For performance, this implementation WILL NOT revert for such actions. /// Please add any checks with overrides if desired. /// - The `permit` function uses the ecrecover precompile (0x1). /// /// If you are overriding: /// - NEVER violate the ERC20 invariant: /// the total sum of all balances must be equal to `totalSupply()`. /// - Check that the overridden function is actually used in the function you want to /// change the behavior of. Much of the code has been manually inlined for performance. abstract contract ERC20 { /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CUSTOM ERRORS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The total supply has overflowed. error TotalSupplyOverflow(); /// @dev The allowance has overflowed. error AllowanceOverflow(); /// @dev The allowance has underflowed. error AllowanceUnderflow(); /// @dev Insufficient balance. error InsufficientBalance(); /// @dev Insufficient allowance. error InsufficientAllowance(); /// @dev The permit is invalid. error InvalidPermit(); /// @dev The permit has expired. error PermitExpired(); /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* EVENTS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Emitted when `amount` tokens is transferred from `from` to `to`. event Transfer(address indexed from, address indexed to, uint256 amount); /// @dev Emitted when `amount` tokens is approved by `owner` to be used by `spender`. event Approval(address indexed owner, address indexed spender, uint256 amount); /// @dev `keccak256(bytes("Transfer(address,address,uint256)"))`. uint256 private constant _TRANSFER_EVENT_SIGNATURE = 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef; /// @dev `keccak256(bytes("Approval(address,address,uint256)"))`. uint256 private constant _APPROVAL_EVENT_SIGNATURE = 0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* STORAGE */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The storage slot for the total supply. uint256 private constant _TOTAL_SUPPLY_SLOT = 0x05345cdf77eb68f44c; /// @dev The balance slot of `owner` is given by: /// ``` /// mstore(0x0c, _BALANCE_SLOT_SEED) /// mstore(0x00, owner) /// let balanceSlot := keccak256(0x0c, 0x20) /// ``` uint256 private constant _BALANCE_SLOT_SEED = 0x87a211a2; /// @dev The allowance slot of (`owner`, `spender`) is given by: /// ``` /// mstore(0x20, spender) /// mstore(0x0c, _ALLOWANCE_SLOT_SEED) /// mstore(0x00, owner) /// let allowanceSlot := keccak256(0x0c, 0x34) /// ``` uint256 private constant _ALLOWANCE_SLOT_SEED = 0x7f5e9f20; /// @dev The nonce slot of `owner` is given by: /// ``` /// mstore(0x0c, _NONCES_SLOT_SEED) /// mstore(0x00, owner) /// let nonceSlot := keccak256(0x0c, 0x20) /// ``` uint256 private constant _NONCES_SLOT_SEED = 0x38377508; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CONSTANTS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev `(_NONCES_SLOT_SEED << 16) | 0x1901`. uint256 private constant _NONCES_SLOT_SEED_WITH_SIGNATURE_PREFIX = 0x383775081901; /// @dev `keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)")`. bytes32 private constant _DOMAIN_TYPEHASH = 0x8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f; /// @dev `keccak256("1")`. bytes32 private constant _VERSION_HASH = 0xc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6; /// @dev `keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)")`. bytes32 private constant _PERMIT_TYPEHASH = 0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* ERC20 METADATA */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Returns the name of the token. function name() public view virtual returns (string memory); /// @dev Returns the symbol of the token. function symbol() public view virtual returns (string memory); /// @dev Returns the decimals places of the token. function decimals() public view virtual returns (uint8) { return 18; } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* ERC20 */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Returns the amount of tokens in existence. function totalSupply() public view virtual returns (uint256 result) { /// @solidity memory-safe-assembly assembly { result := sload(_TOTAL_SUPPLY_SLOT) } } /// @dev Returns the amount of tokens owned by `owner`. function balanceOf(address owner) public view virtual returns (uint256 result) { /// @solidity memory-safe-assembly assembly { mstore(0x0c, _BALANCE_SLOT_SEED) mstore(0x00, owner) result := sload(keccak256(0x0c, 0x20)) } } /// @dev Returns the amount of tokens that `spender` can spend on behalf of `owner`. function allowance(address owner, address spender) public view virtual returns (uint256 result) { /// @solidity memory-safe-assembly assembly { mstore(0x20, spender) mstore(0x0c, _ALLOWANCE_SLOT_SEED) mstore(0x00, owner) result := sload(keccak256(0x0c, 0x34)) } } /// @dev Sets `amount` as the allowance of `spender` over the caller's tokens. /// /// Emits a {Approval} event. function approve(address spender, uint256 amount) public virtual returns (bool) { /// @solidity memory-safe-assembly assembly { // Compute the allowance slot and store the amount. mstore(0x20, spender) mstore(0x0c, _ALLOWANCE_SLOT_SEED) mstore(0x00, caller()) sstore(keccak256(0x0c, 0x34), amount) // Emit the {Approval} event. mstore(0x00, amount) log3(0x00, 0x20, _APPROVAL_EVENT_SIGNATURE, caller(), shr(96, mload(0x2c))) } return true; } /// @dev Transfer `amount` tokens from the caller to `to`. /// /// Requirements: /// - `from` must at least have `amount`. /// /// Emits a {Transfer} event. function transfer(address to, uint256 amount) public virtual returns (bool) { _beforeTokenTransfer(msg.sender, to, amount); /// @solidity memory-safe-assembly assembly { // Compute the balance slot and load its value. mstore(0x0c, _BALANCE_SLOT_SEED) mstore(0x00, caller()) let fromBalanceSlot := keccak256(0x0c, 0x20) let fromBalance := sload(fromBalanceSlot) // Revert if insufficient balance. if gt(amount, fromBalance) { mstore(0x00, 0xf4d678b8) // `InsufficientBalance()`. revert(0x1c, 0x04) } // Subtract and store the updated balance. sstore(fromBalanceSlot, sub(fromBalance, amount)) // Compute the balance slot of `to`. mstore(0x00, to) let toBalanceSlot := keccak256(0x0c, 0x20) // Add and store the updated balance of `to`. // Will not overflow because the sum of all user balances // cannot exceed the maximum uint256 value. sstore(toBalanceSlot, add(sload(toBalanceSlot), amount)) // Emit the {Transfer} event. mstore(0x20, amount) log3(0x20, 0x20, _TRANSFER_EVENT_SIGNATURE, caller(), shr(96, mload(0x0c))) } _afterTokenTransfer(msg.sender, to, amount); return true; } /// @dev Transfers `amount` tokens from `from` to `to`. /// /// Note: Does not update the allowance if it is the maximum uint256 value. /// /// Requirements: /// - `from` must at least have `amount`. /// - The caller must have at least `amount` of allowance to transfer the tokens of `from`. /// /// Emits a {Transfer} event. function transferFrom(address from, address to, uint256 amount) public virtual returns (bool) { _beforeTokenTransfer(from, to, amount); /// @solidity memory-safe-assembly assembly { let from_ := shl(96, from) // Compute the allowance slot and load its value. mstore(0x20, caller()) mstore(0x0c, or(from_, _ALLOWANCE_SLOT_SEED)) let allowanceSlot := keccak256(0x0c, 0x34) let allowance_ := sload(allowanceSlot) // If the allowance is not the maximum uint256 value. if add(allowance_, 1) { // Revert if the amount to be transferred exceeds the allowance. if gt(amount, allowance_) { mstore(0x00, 0x13be252b) // `InsufficientAllowance()`. revert(0x1c, 0x04) } // Subtract and store the updated allowance. sstore(allowanceSlot, sub(allowance_, amount)) } // Compute the balance slot and load its value. mstore(0x0c, or(from_, _BALANCE_SLOT_SEED)) let fromBalanceSlot := keccak256(0x0c, 0x20) let fromBalance := sload(fromBalanceSlot) // Revert if insufficient balance. if gt(amount, fromBalance) { mstore(0x00, 0xf4d678b8) // `InsufficientBalance()`. revert(0x1c, 0x04) } // Subtract and store the updated balance. sstore(fromBalanceSlot, sub(fromBalance, amount)) // Compute the balance slot of `to`. mstore(0x00, to) let toBalanceSlot := keccak256(0x0c, 0x20) // Add and store the updated balance of `to`. // Will not overflow because the sum of all user balances // cannot exceed the maximum uint256 value. sstore(toBalanceSlot, add(sload(toBalanceSlot), amount)) // Emit the {Transfer} event. mstore(0x20, amount) log3(0x20, 0x20, _TRANSFER_EVENT_SIGNATURE, shr(96, from_), shr(96, mload(0x0c))) } _afterTokenTransfer(from, to, amount); return true; } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* EIP-2612 */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev For more performance, override to return the constant value /// of `keccak256(bytes(name()))` if `name()` will never change. function _constantNameHash() internal view virtual returns (bytes32 result) {} /// @dev Returns the current nonce for `owner`. /// This value is used to compute the signature for EIP-2612 permit. function nonces(address owner) public view virtual returns (uint256 result) { /// @solidity memory-safe-assembly assembly { // Compute the nonce slot and load its value. mstore(0x0c, _NONCES_SLOT_SEED) mstore(0x00, owner) result := sload(keccak256(0x0c, 0x20)) } } /// @dev Sets `value` as the allowance of `spender` over the tokens of `owner`, /// authorized by a signed approval by `owner`. /// /// Emits a {Approval} event. function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) public virtual { bytes32 nameHash = _constantNameHash(); // We simply calculate it on-the-fly to allow for cases where the `name` may change. if (nameHash == bytes32(0)) nameHash = keccak256(bytes(name())); /// @solidity memory-safe-assembly assembly { // Revert if the block timestamp is greater than `deadline`. if gt(timestamp(), deadline) { mstore(0x00, 0x1a15a3cc) // `PermitExpired()`. revert(0x1c, 0x04) } let m := mload(0x40) // Grab the free memory pointer. // Clean the upper 96 bits. owner := shr(96, shl(96, owner)) spender := shr(96, shl(96, spender)) // Compute the nonce slot and load its value. mstore(0x0e, _NONCES_SLOT_SEED_WITH_SIGNATURE_PREFIX) mstore(0x00, owner) let nonceSlot := keccak256(0x0c, 0x20) let nonceValue := sload(nonceSlot) // Prepare the domain separator. mstore(m, _DOMAIN_TYPEHASH) mstore(add(m, 0x20), nameHash) mstore(add(m, 0x40), _VERSION_HASH) mstore(add(m, 0x60), chainid()) mstore(add(m, 0x80), address()) mstore(0x2e, keccak256(m, 0xa0)) // Prepare the struct hash. mstore(m, _PERMIT_TYPEHASH) mstore(add(m, 0x20), owner) mstore(add(m, 0x40), spender) mstore(add(m, 0x60), value) mstore(add(m, 0x80), nonceValue) mstore(add(m, 0xa0), deadline) mstore(0x4e, keccak256(m, 0xc0)) // Prepare the ecrecover calldata. mstore(0x00, keccak256(0x2c, 0x42)) mstore(0x20, and(0xff, v)) mstore(0x40, r) mstore(0x60, s) let t := staticcall(gas(), 1, 0, 0x80, 0x20, 0x20) // If the ecrecover fails, the returndatasize will be 0x00, // `owner` will be checked if it equals the hash at 0x00, // which evaluates to false (i.e. 0), and we will revert. // If the ecrecover succeeds, the returndatasize will be 0x20, // `owner` will be compared against the returned address at 0x20. if iszero(eq(mload(returndatasize()), owner)) { mstore(0x00, 0xddafbaef) // `InvalidPermit()`. revert(0x1c, 0x04) } // Increment and store the updated nonce. sstore(nonceSlot, add(nonceValue, t)) // `t` is 1 if ecrecover succeeds. // Compute the allowance slot and store the value. // The `owner` is already at slot 0x20. mstore(0x40, or(shl(160, _ALLOWANCE_SLOT_SEED), spender)) sstore(keccak256(0x2c, 0x34), value) // Emit the {Approval} event. log3(add(m, 0x60), 0x20, _APPROVAL_EVENT_SIGNATURE, owner, spender) mstore(0x40, m) // Restore the free memory pointer. mstore(0x60, 0) // Restore the zero pointer. } } /// @dev Returns the EIP-712 domain separator for the EIP-2612 permit. function DOMAIN_SEPARATOR() public view virtual returns (bytes32 result) { bytes32 nameHash = _constantNameHash(); // We simply calculate it on-the-fly to allow for cases where the `name` may change. if (nameHash == bytes32(0)) nameHash = keccak256(bytes(name())); /// @solidity memory-safe-assembly assembly { let m := mload(0x40) // Grab the free memory pointer. mstore(m, _DOMAIN_TYPEHASH) mstore(add(m, 0x20), nameHash) mstore(add(m, 0x40), _VERSION_HASH) mstore(add(m, 0x60), chainid()) mstore(add(m, 0x80), address()) result := keccak256(m, 0xa0) } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* INTERNAL MINT FUNCTIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Mints `amount` tokens to `to`, increasing the total supply. /// /// Emits a {Transfer} event. function _mint(address to, uint256 amount) internal virtual { _beforeTokenTransfer(address(0), to, amount); /// @solidity memory-safe-assembly assembly { let totalSupplyBefore := sload(_TOTAL_SUPPLY_SLOT) let totalSupplyAfter := add(totalSupplyBefore, amount) // Revert if the total supply overflows. if lt(totalSupplyAfter, totalSupplyBefore) { mstore(0x00, 0xe5cfe957) // `TotalSupplyOverflow()`. revert(0x1c, 0x04) } // Store the updated total supply. sstore(_TOTAL_SUPPLY_SLOT, totalSupplyAfter) // Compute the balance slot and load its value. mstore(0x0c, _BALANCE_SLOT_SEED) mstore(0x00, to) let toBalanceSlot := keccak256(0x0c, 0x20) // Add and store the updated balance. sstore(toBalanceSlot, add(sload(toBalanceSlot), amount)) // Emit the {Transfer} event. mstore(0x20, amount) log3(0x20, 0x20, _TRANSFER_EVENT_SIGNATURE, 0, shr(96, mload(0x0c))) } _afterTokenTransfer(address(0), to, amount); } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* INTERNAL BURN FUNCTIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Burns `amount` tokens from `from`, reducing the total supply. /// /// Emits a {Transfer} event. function _burn(address from, uint256 amount) internal virtual { _beforeTokenTransfer(from, address(0), amount); /// @solidity memory-safe-assembly assembly { // Compute the balance slot and load its value. mstore(0x0c, _BALANCE_SLOT_SEED) mstore(0x00, from) let fromBalanceSlot := keccak256(0x0c, 0x20) let fromBalance := sload(fromBalanceSlot) // Revert if insufficient balance. if gt(amount, fromBalance) { mstore(0x00, 0xf4d678b8) // `InsufficientBalance()`. revert(0x1c, 0x04) } // Subtract and store the updated balance. sstore(fromBalanceSlot, sub(fromBalance, amount)) // Subtract and store the updated total supply. sstore(_TOTAL_SUPPLY_SLOT, sub(sload(_TOTAL_SUPPLY_SLOT), amount)) // Emit the {Transfer} event. mstore(0x00, amount) log3(0x00, 0x20, _TRANSFER_EVENT_SIGNATURE, shr(96, shl(96, from)), 0) } _afterTokenTransfer(from, address(0), amount); } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* INTERNAL TRANSFER FUNCTIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Moves `amount` of tokens from `from` to `to`. function _transfer(address from, address to, uint256 amount) internal virtual { _beforeTokenTransfer(from, to, amount); /// @solidity memory-safe-assembly assembly { let from_ := shl(96, from) // Compute the balance slot and load its value. mstore(0x0c, or(from_, _BALANCE_SLOT_SEED)) let fromBalanceSlot := keccak256(0x0c, 0x20) let fromBalance := sload(fromBalanceSlot) // Revert if insufficient balance. if gt(amount, fromBalance) { mstore(0x00, 0xf4d678b8) // `InsufficientBalance()`. revert(0x1c, 0x04) } // Subtract and store the updated balance. sstore(fromBalanceSlot, sub(fromBalance, amount)) // Compute the balance slot of `to`. mstore(0x00, to) let toBalanceSlot := keccak256(0x0c, 0x20) // Add and store the updated balance of `to`. // Will not overflow because the sum of all user balances // cannot exceed the maximum uint256 value. sstore(toBalanceSlot, add(sload(toBalanceSlot), amount)) // Emit the {Transfer} event. mstore(0x20, amount) log3(0x20, 0x20, _TRANSFER_EVENT_SIGNATURE, shr(96, from_), shr(96, mload(0x0c))) } _afterTokenTransfer(from, to, amount); } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* INTERNAL ALLOWANCE FUNCTIONS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Updates the allowance of `owner` for `spender` based on spent `amount`. function _spendAllowance(address owner, address spender, uint256 amount) internal virtual { /// @solidity memory-safe-assembly assembly { // Compute the allowance slot and load its value. mstore(0x20, spender) mstore(0x0c, _ALLOWANCE_SLOT_SEED) mstore(0x00, owner) let allowanceSlot := keccak256(0x0c, 0x34) let allowance_ := sload(allowanceSlot) // If the allowance is not the maximum uint256 value. if add(allowance_, 1) { // Revert if the amount to be transferred exceeds the allowance. if gt(amount, allowance_) { mstore(0x00, 0x13be252b) // `InsufficientAllowance()`. revert(0x1c, 0x04) } // Subtract and store the updated allowance. sstore(allowanceSlot, sub(allowance_, amount)) } } } /// @dev Sets `amount` as the allowance of `spender` over the tokens of `owner`. /// /// Emits a {Approval} event. function _approve(address owner, address spender, uint256 amount) internal virtual { /// @solidity memory-safe-assembly assembly { let owner_ := shl(96, owner) // Compute the allowance slot and store the amount. mstore(0x20, spender) mstore(0x0c, or(owner_, _ALLOWANCE_SLOT_SEED)) sstore(keccak256(0x0c, 0x34), amount) // Emit the {Approval} event. mstore(0x00, amount) log3(0x00, 0x20, _APPROVAL_EVENT_SIGNATURE, shr(96, owner_), shr(96, mload(0x2c))) } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* HOOKS TO OVERRIDE */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Hook that is called before any transfer of tokens. /// This includes minting and burning. 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. function _afterTokenTransfer(address from, address to, uint256 amount) internal virtual {} }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.4; import {ERC20} from "./ERC20.sol"; import {FixedPointMathLib} from "../utils/FixedPointMathLib.sol"; import {SafeTransferLib} from "../utils/SafeTransferLib.sol"; /// @notice Simple ERC4626 tokenized Vault implementation. /// @author Solady (https://github.com/vectorized/solady/blob/main/src/tokens/ERC4626.sol) /// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/mixins/ERC4626.sol) /// @author Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/extensions/ERC4626.sol) abstract contract ERC4626 is ERC20 { /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CONSTANTS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev The default underlying decimals. uint8 internal constant _DEFAULT_UNDERLYING_DECIMALS = 18; /// @dev The default decimals offset. uint8 internal constant _DEFAULT_DECIMALS_OFFSET = 0; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* CUSTOM ERRORS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Cannot deposit more than the max limit. error DepositMoreThanMax(); /// @dev Cannot mint more than the max limit. error MintMoreThanMax(); /// @dev Cannot withdraw more than the max limit. error WithdrawMoreThanMax(); /// @dev Cannot redeem more than the max limit. error RedeemMoreThanMax(); /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* EVENTS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Emitted during a mint call or deposit call. event Deposit(address indexed by, address indexed owner, uint256 assets, uint256 shares); /// @dev Emitted during a withdraw call or redeem call. event Withdraw( address indexed by, address indexed to, address indexed owner, uint256 assets, uint256 shares ); /// @dev `keccak256(bytes("Deposit(address,address,uint256,uint256)"))`. uint256 private constant _DEPOSIT_EVENT_SIGNATURE = 0xdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d7; /// @dev `keccak256(bytes("Withdraw(address,address,address,uint256,uint256)"))`. uint256 private constant _WITHDRAW_EVENT_SIGNATURE = 0xfbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db; /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* ERC4626 CONSTANTS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev To be overridden to return the address of the underlying asset. /// /// - MUST be an ERC20 token contract. /// - MUST NOT revert. function asset() public view virtual returns (address); /// @dev To be overridden to return the number of decimals of the underlying asset. /// Default: 18. /// /// - MUST NOT revert. function _underlyingDecimals() internal view virtual returns (uint8) { return _DEFAULT_UNDERLYING_DECIMALS; } /// @dev Override to return a non-zero value to make the inflation attack even more unfeasible. /// Only used when {_useVirtualShares} returns true. /// Default: 0. /// /// - MUST NOT revert. function _decimalsOffset() internal view virtual returns (uint8) { return _DEFAULT_DECIMALS_OFFSET; } /// @dev Returns whether virtual shares will be used to mitigate the inflation attack. /// See: https://github.com/OpenZeppelin/openzeppelin-contracts/issues/3706 /// Override to return true or false. /// Default: true. /// /// - MUST NOT revert. function _useVirtualShares() internal view virtual returns (bool) { return true; } /// @dev Returns the decimals places of the token. /// /// - MUST NOT revert. function decimals() public view virtual override(ERC20) returns (uint8) { if (!_useVirtualShares()) return _underlyingDecimals(); return _underlyingDecimals() + _decimalsOffset(); } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* ASSET DECIMALS GETTER HELPER */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Helper function to get the decimals of the underlying asset. /// Useful for setting the return value of `_underlyingDecimals` during initialization. /// If the retrieval succeeds, `success` will be true, and `result` will hold the result. /// Otherwise, `success` will be false, and `result` will be zero. /// /// Example usage: /// ``` /// (bool success, uint8 result) = _tryGetAssetDecimals(underlying); /// _decimals = success ? result : _DEFAULT_UNDERLYING_DECIMALS; /// ``` function _tryGetAssetDecimals(address underlying) internal view returns (bool success, uint8 result) { /// @solidity memory-safe-assembly assembly { // Store the function selector of `decimals()`. mstore(0x00, 0x313ce567) // Arguments are evaluated last to first. success := and( // Returned value is less than 256, at left-padded to 32 bytes. and(lt(mload(0x00), 0x100), gt(returndatasize(), 0x1f)), // The staticcall succeeds. staticcall(gas(), underlying, 0x1c, 0x04, 0x00, 0x20) ) result := mul(mload(0x00), success) } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* ACCOUNTING LOGIC */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Returns the total amount of the underlying asset managed by the Vault. /// /// - SHOULD include any compounding that occurs from the yield. /// - MUST be inclusive of any fees that are charged against assets in the Vault. /// - MUST NOT revert. function totalAssets() public view virtual returns (uint256 assets) { assets = SafeTransferLib.balanceOf(asset(), address(this)); } /// @dev Returns the amount of shares that the Vault will exchange for the amount of /// assets provided, in an ideal scenario where all 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, during 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, i.e. what the average user should /// expect to see when exchanging to and from. function convertToShares(uint256 assets) public view virtual returns (uint256 shares) { if (!_useVirtualShares()) { uint256 supply = totalSupply(); return _eitherIsZero(assets, supply) ? _initialConvertToShares(assets) : FixedPointMathLib.fullMulDiv(assets, supply, totalAssets()); } uint256 o = _decimalsOffset(); if (o == 0) { return FixedPointMathLib.fullMulDiv(assets, totalSupply() + 1, _inc(totalAssets())); } return FixedPointMathLib.fullMulDiv(assets, totalSupply() + 10 ** o, _inc(totalAssets())); } /// @dev Returns the amount of assets that the Vault will exchange for the amount of /// shares provided, in an ideal scenario where all 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, during 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, i.e. what the average user should /// expect to see when exchanging to and from. function convertToAssets(uint256 shares) public view virtual returns (uint256 assets) { if (!_useVirtualShares()) { uint256 supply = totalSupply(); return supply == 0 ? _initialConvertToAssets(shares) : FixedPointMathLib.fullMulDiv(shares, totalAssets(), supply); } uint256 o = _decimalsOffset(); if (o == 0) { return FixedPointMathLib.fullMulDiv(shares, totalAssets() + 1, _inc(totalSupply())); } return FixedPointMathLib.fullMulDiv(shares, totalAssets() + 1, totalSupply() + 10 ** o); } /// @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 /// will be minted in a deposit call in the same transaction, i.e. deposit should /// return the same or more shares as `previewDeposit` if call in the same transaction. /// - MUST NOT account for deposit limits like those returned from `maxDeposit` and should /// always act as if the deposit will be accepted, regardless of approvals, etc. /// - MUST be inclusive of deposit fees. Integrators should be aware of this. /// - 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) public view virtual returns (uint256 shares) { shares = convertToShares(assets); } /// @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 /// will 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 if the mint will be accepted, regardless of approvals, etc. /// - MUST be inclusive of deposit fees. Integrators should be aware of this. /// - 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) public view virtual returns (uint256 assets) { if (!_useVirtualShares()) { uint256 supply = totalSupply(); return supply == 0 ? _initialConvertToAssets(shares) : FixedPointMathLib.fullMulDivUp(shares, totalAssets(), supply); } uint256 o = _decimalsOffset(); if (o == 0) { return FixedPointMathLib.fullMulDivUp(shares, totalAssets() + 1, _inc(totalSupply())); } return FixedPointMathLib.fullMulDivUp(shares, totalAssets() + 1, totalSupply() + 10 ** o); } /// @dev Allows an on-chain or off-chain user to simulate the effects of their withdrawal /// at the current block, given the current on-chain conditions. /// /// - MUST return as close to and no fewer than the exact amount of Vault shares that /// will be burned in a withdraw call in the same transaction, i.e. withdraw should /// return the same or fewer shares as `previewWithdraw` if call in the same transaction. /// - MUST NOT account for withdrawal limits like those returned from `maxWithdraw` and should /// always act as if the withdrawal will be accepted, regardless of share balance, etc. /// - MUST be inclusive of withdrawal fees. Integrators should be aware of this. /// - 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) public view virtual returns (uint256 shares) { if (!_useVirtualShares()) { uint256 supply = totalSupply(); return _eitherIsZero(assets, supply) ? _initialConvertToShares(assets) : FixedPointMathLib.fullMulDivUp(assets, supply, totalAssets()); } uint256 o = _decimalsOffset(); if (o == 0) { return FixedPointMathLib.fullMulDivUp(assets, totalSupply() + 1, _inc(totalAssets())); } return FixedPointMathLib.fullMulDivUp(assets, totalSupply() + 10 ** o, _inc(totalAssets())); } /// @dev Allows an on-chain or off-chain user to simulate the effects of their redemption /// at the current block, given current on-chain conditions. /// /// - MUST return as close to and no more than the exact amount of assets that /// will 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 if the redemption will be accepted, regardless of approvals, etc. /// - MUST be inclusive of withdrawal fees. Integrators should be aware of this. /// - 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 depositing. function previewRedeem(uint256 shares) public view virtual returns (uint256 assets) { assets = convertToAssets(shares); } /// @dev Private helper to return if either value is zero. function _eitherIsZero(uint256 a, uint256 b) private pure returns (bool result) { /// @solidity memory-safe-assembly assembly { result := or(iszero(a), iszero(b)) } } /// @dev Private helper to return `x + 1` without the overflow check. /// Used for computing the denominator input to `FixedPointMathLib.fullMulDiv(a, b, x + 1)`. /// When `x == type(uint256).max`, we get `x + 1 == 0` (mod 2**256 - 1), /// and `FixedPointMathLib.fullMulDiv` will revert as the denominator is zero. function _inc(uint256 x) private pure returns (uint256) { unchecked { return x + 1; } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* DEPOSIT / WITHDRAWAL LIMIT LOGIC */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Returns the maximum amount of the underlying asset that can be deposited /// into the Vault for `to`, via a deposit call. /// /// - MUST return a limited value if `to` is subject to some deposit limit. /// - MUST return `2**256-1` if there is no maximum limit. /// - MUST NOT revert. function maxDeposit(address to) public view virtual returns (uint256 maxAssets) { to = to; // Silence unused variable warning. maxAssets = type(uint256).max; } /// @dev Returns the maximum amount of the Vault shares that can be minter for `to`, /// via a mint call. /// /// - MUST return a limited value if `to` is subject to some mint limit. /// - MUST return `2**256-1` if there is no maximum limit. /// - MUST NOT revert. function maxMint(address to) public view virtual returns (uint256 maxShares) { to = to; // Silence unused variable warning. maxShares = type(uint256).max; } /// @dev Returns the maximum amount of the underlying asset that can be withdrawn /// from the `owner`'s balance in the Vault, via 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) public view virtual returns (uint256 maxAssets) { maxAssets = convertToAssets(balanceOf(owner)); } /// @dev Returns the maximum amount of Vault shares that can be redeemed /// from the `owner`'s balance in the Vault, via a redeem call. /// /// - MUST return a limited value if `owner` is subject to some withdrawal limit or timelock. /// - MUST return `balanceOf(owner)` otherwise. /// - MUST NOT revert. function maxRedeem(address owner) public view virtual returns (uint256 maxShares) { maxShares = balanceOf(owner); } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* DEPOSIT / WITHDRAWAL LOGIC */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Mints `shares` Vault shares to `to` by depositing exactly `assets` /// 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, such as due to deposit limit, /// slippage, insufficient approval, etc. /// /// Note: Most implementations will require pre-approval of the Vault with the /// Vault's underlying `asset` token. function deposit(uint256 assets, address to) public virtual returns (uint256 shares) { if (assets > maxDeposit(to)) _revert(0xb3c61a83); // `DepositMoreThanMax()`. shares = previewDeposit(assets); _deposit(msg.sender, to, assets, shares); } /// @dev Mints exactly `shares` Vault shares to `to` by depositing `assets` /// 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 deposited, such as due to deposit limit, /// slippage, insufficient approval, etc. /// /// Note: Most implementations will require pre-approval of the Vault with the /// Vault's underlying `asset` token. function mint(uint256 shares, address to) public virtual returns (uint256 assets) { if (shares > maxMint(to)) _revert(0x6a695959); // `MintMoreThanMax()`. assets = previewMint(shares); _deposit(msg.sender, to, assets, shares); } /// @dev Burns `shares` from `owner` and sends exactly `assets` of underlying tokens to `to`. /// /// - 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, such as due to withdrawal limit, /// slippage, insufficient balance, etc. /// /// Note: 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 to, address owner) public virtual returns (uint256 shares) { if (assets > maxWithdraw(owner)) _revert(0x936941fc); // `WithdrawMoreThanMax()`. shares = previewWithdraw(assets); _withdraw(msg.sender, to, owner, assets, shares); } /// @dev Burns exactly `shares` from `owner` and sends `assets` of underlying tokens to `to`. /// /// - 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, such as due to withdrawal limit, /// slippage, insufficient balance, etc. /// /// Note: Some implementations will require pre-requesting to the Vault before a redeem /// may be performed. Those methods should be performed separately. function redeem(uint256 shares, address to, address owner) public virtual returns (uint256 assets) { if (shares > maxRedeem(owner)) _revert(0x4656425a); // `RedeemMoreThanMax()`. assets = previewRedeem(shares); _withdraw(msg.sender, to, owner, assets, shares); } /// @dev Internal helper for reverting efficiently. function _revert(uint256 s) private pure { /// @solidity memory-safe-assembly assembly { mstore(0x00, s) revert(0x1c, 0x04) } } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* INTERNAL HELPERS */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev For deposits and mints. /// /// Emits a {Deposit} event. function _deposit(address by, address to, uint256 assets, uint256 shares) internal virtual { SafeTransferLib.safeTransferFrom(asset(), by, address(this), assets); _mint(to, shares); /// @solidity memory-safe-assembly assembly { // Emit the {Deposit} event. mstore(0x00, assets) mstore(0x20, shares) let m := shr(96, not(0)) log3(0x00, 0x40, _DEPOSIT_EVENT_SIGNATURE, and(m, by), and(m, to)) } _afterDeposit(assets, shares); } /// @dev For withdrawals and redemptions. /// /// Emits a {Withdraw} event. function _withdraw(address by, address to, address owner, uint256 assets, uint256 shares) internal virtual { if (by != owner) _spendAllowance(owner, by, shares); _beforeWithdraw(assets, shares); _burn(owner, shares); SafeTransferLib.safeTransfer(asset(), to, assets); /// @solidity memory-safe-assembly assembly { // Emit the {Withdraw} event. mstore(0x00, assets) mstore(0x20, shares) let m := shr(96, not(0)) log4(0x00, 0x40, _WITHDRAW_EVENT_SIGNATURE, and(m, by), and(m, to), and(m, owner)) } } /// @dev Internal conversion function (from assets to shares) to apply when the Vault is empty. /// Only used when {_useVirtualShares} returns false. /// /// Note: Make sure to keep this function consistent with {_initialConvertToAssets} /// when overriding it. function _initialConvertToShares(uint256 assets) internal view virtual returns (uint256 shares) { shares = assets; } /// @dev Internal conversion function (from shares to assets) to apply when the Vault is empty. /// Only used when {_useVirtualShares} returns false. /// /// Note: Make sure to keep this function consistent with {_initialConvertToShares} /// when overriding it. function _initialConvertToAssets(uint256 shares) internal view virtual returns (uint256 assets) { assets = shares; } /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ /* HOOKS TO OVERRIDE */ /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ /// @dev Hook that is called before any withdrawal or redemption. function _beforeWithdraw(uint256 assets, uint256 shares) internal virtual {} /// @dev Hook that is called after any deposit or mint. function _afterDeposit(uint256 assets, uint256 shares) internal virtual {} }
{ "remappings": [ "solady/src/=lib/solady/src/", "@openzeppelin/contracts-upgradeable/=lib/sbt-contracts/lib/openzeppelin-contracts-upgradeable/contracts/", "@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/", "@prb/test/=lib/sbt-contracts/lib/prb-math/lib/prb-test/src/", "chainlink/=lib/sbt-contracts/lib/chainlink/", "ds-test/=lib/sbt-contracts/lib/forge-std/lib/ds-test/src/", "erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/", "forge-std/=lib/forge-std/src/", "interchain-token-service/=lib/sbt-contracts/lib/interchain-token-service/contracts/", "openzeppelin-contracts-upgradeable/=lib/sbt-contracts/lib/openzeppelin-contracts-upgradeable/", "openzeppelin-contracts/=lib/openzeppelin-contracts/", "prb-math/=lib/sbt-contracts/lib/prb-math/src/", "prb-test/=lib/sbt-contracts/lib/prb-math/lib/prb-test/src/", "pyth-sdk-solidity/=lib/sbt-contracts/lib/pyth-sdk-solidity/", "sbt-contracts/=lib/sbt-contracts/" ], "optimizer": { "enabled": true, "runs": 20000 }, "metadata": { "useLiteralContent": false, "bytecodeHash": "ipfs", "appendCBOR": true }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "evmVersion": "paris", "viaIR": true, "libraries": {} }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AllowanceOverflow","type":"error"},{"inputs":[],"name":"AllowanceUnderflow","type":"error"},{"inputs":[],"name":"AlreadyInitialized","type":"error"},{"inputs":[],"name":"DepositMoreThanMax","type":"error"},{"inputs":[],"name":"DepositTooSmall","type":"error"},{"inputs":[],"name":"InsufficientAllowance","type":"error"},{"inputs":[],"name":"InsufficientBalance","type":"error"},{"inputs":[],"name":"InvalidInitialization","type":"error"},{"inputs":[],"name":"InvalidPermit","type":"error"},{"inputs":[],"name":"MintMoreThanMax","type":"error"},{"inputs":[],"name":"NewOwnerIsZeroAddress","type":"error"},{"inputs":[],"name":"NoHandoverRequest","type":"error"},{"inputs":[],"name":"NotInitializing","type":"error"},{"inputs":[],"name":"PermitExpired","type":"error"},{"inputs":[],"name":"RedeemMoreThanMax","type":"error"},{"inputs":[],"name":"TotalSupplyOverflow","type":"error"},{"inputs":[],"name":"Unauthorized","type":"error"},{"inputs":[],"name":"UnauthorizedCallContext","type":"error"},{"inputs":[],"name":"UpgradeFailed","type":"error"},{"inputs":[],"name":"WithdrawMoreThanMax","type":"error"},{"inputs":[],"name":"WithdrawsLocked","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"by","type":"address"},{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"uint256","name":"assets","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"shares","type":"uint256"}],"name":"Deposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint64","name":"version","type":"uint64"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"pendingOwner","type":"address"}],"name":"OwnershipHandoverCanceled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"pendingOwner","type":"address"}],"name":"OwnershipHandoverRequested","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"oldOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"implementation","type":"address"}],"name":"Upgraded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"by","type":"address"},{"indexed":true,"internalType":"address","name":"to","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":[],"name":"WithdrawalsLocked","type":"event"},{"anonymous":false,"inputs":[],"name":"WithdrawalsUnlocked","type":"event"},{"inputs":[],"name":"DOMAIN_SEPARATOR","outputs":[{"internalType":"bytes32","name":"result","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"result","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":[],"name":"assetVault","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"result","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"cancelOwnershipHandover","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"pendingOwner","type":"address"}],"name":"completeOwnershipHandover","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"contribution","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"address","name":"to","type":"address"}],"name":"deposit","outputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"asset_","type":"address"},{"internalType":"string","name":"name_","type":"string"},{"internalType":"string","name":"symbol_","type":"string"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"lockWithdrawals","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"}],"name":"maxDeposit","outputs":[{"internalType":"uint256","name":"maxAssets","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxEthDeposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"}],"name":"maxMint","outputs":[{"internalType":"uint256","name":"maxShares","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"maxRedeem","outputs":[{"internalType":"uint256","name":"maxShares","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"maxWithdraw","outputs":[{"internalType":"uint256","name":"maxAssets","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"address","name":"to","type":"address"}],"name":"mint","outputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"nonces","outputs":[{"internalType":"uint256","name":"result","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"result","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"pendingOwner","type":"address"}],"name":"ownershipHandoverExpiresAt","outputs":[{"internalType":"uint256","name":"result","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"}],"name":"permit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"proxiableUUID","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"shares","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"internalType":"address","name":"owner","type":"address"}],"name":"redeem","outputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"requestOwnershipHandover","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"stakeEthAndDeposit","outputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalContributions","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"result","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"unlockWithdrawals","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newImplementation","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"upgradeToAndCall","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"assets","type":"uint256"},{"internalType":"address","name":"to","type":"address"},{"internalType":"address","name":"owner","type":"address"}],"name":"withdraw","outputs":[{"internalType":"uint256","name":"shares","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"withdrawContributions","outputs":[],"stateMutability":"nonpayable","type":"function"}]
Contract Creation Code
60a08060405234609a573060805263409feecd1980549060018216608c576001600160401b039160011c6002600160401b0319016053575b6142a583816100a0823960805181818161155701526116020152f35b6002600160411b03905560209081527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29080a138806037565b63f92ee8a96000526004601cfd5b600080fdfe6080604052600436101561001257600080fd5b60003560e01c806306fdde0314611b4a578063095ea7b314611adc57806318160ddd14611ab65780632108af0914611a2d57806323b872dd1461194857806325692962146118fc578063313ce567146118bc5780633644e5151461183357806337c089231461173357806338d52e0f146116e0578063402d267d146108495780634f1ef286146115b357806352d1902d1461154357806354d1f13d146114fb5780636e553f6514610bc557806370a08231146114c8578063715018a6146114675780637ecebe00146114345780638da5cb5b146113e15780639065714714610bee57806394bf804d14610bc557806395d89b4114610a9d578063a0b29ee514610989578063a9059cbb146108fb578063b460af94146108b6578063ba08765214610871578063bc87ec1c1461084e578063c63d75b614610849578063ce96cb771461068e578063d505accf14610693578063d905777e1461068e578063dd62ed3e1461064f578063e2dc4310146104a7578063e36aed281461041d578063f04e283e14610373578063f2fde38b146102de578063f317124c14610257578063f61ebc36146102015763fee81cf4146101c957600080fd5b346101fc5760206003193601126101fc576101e2611be0565b63389a75e1600c52600052602080600c2054604051908152f35b600080fd5b346101fc5760006003193601126101fc57602073ffffffffffffffffffffffffffffffffffffffff7f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e60035460081c16604051908152f35b346101fc5760006003193601126101fc57610270611fb0565b7f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e60077fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0081541690557f15fa93f6df3cbaf0b9ddb555fa798ba412e2bbc86e60aa62d8aade4c3052cd62600080a1005b60206003193601126101fc576102f2611be0565b6102fa611fb0565b8060601b156103655773ffffffffffffffffffffffffffffffffffffffff167fffffffffffffffffffffffffffffffffffffffffffffffffffffffff748739278181547f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0600080a355005b637448fbae6000526004601cfd5b60206003193601126101fc57610387611be0565b61038f611fb0565b63389a75e1600c52806000526020600c20908154421161040f57600073ffffffffffffffffffffffffffffffffffffffff9255167fffffffffffffffffffffffffffffffffffffffffffffffffffffffff748739278181547f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0600080a355005b636f5e88186000526004601cfd5b346101fc5760006003193601126101fc57610436611fb0565b7f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e600760017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff008254161790557f8780a7821711ac08118dc8a77c63f7e98eb11187d8a4566cb46c690f9a6e76bf600080a1005b346101fc576020806003193601126101fc576104c1611be0565b73ffffffffffffffffffffffffffffffffffffffff7f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e60035460081c1690826105478273ffffffffffffffffffffffffffffffffffffffff166000527f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e6004602052604060002090565b546024604051809581937f4cdad50600000000000000000000000000000000000000000000000000000000835260048301525afa91821561064357600092610614575b506387a211a2600c52806000526105e583600c20549173ffffffffffffffffffffffffffffffffffffffff166000527f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e6005602052604060002090565b54918181116105f9575b5050604051908152f35b61060d929161060791611ebe565b90611efa565b82806105ef565b9091508281813d831161063c575b61062c8183611c6a565b810103126101fc5751908361058a565b503d610622565b6040513d6000823e3d90fd5b346101fc5760406003193601126101fc57610668611be0565b610670611c03565b602052637f5e9f20600c5260005260206034600c2054604051908152f35b6114c8565b346101fc5760e06003193601126101fc576106ac611be0565b6106b4611c03565b604435606435906084359360ff851685036101fc576106d1611db5565b9182516020809401209184421161083b576040519073ffffffffffffffffffffffffffffffffffffffff80911696169665383775081901600e528660005260c085600c20928354977f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f82528782019687528860408301977fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc689528c6060850199468b528d608087019330855260a08820602e527f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9885252528789525260a082015220604e526042602c2060005260ff16845260a43560405260c43560605283806080600060015afa863d510361082d577f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259501905585777f5e9f200000000000000000000000000000000000000000176040526034602c2055a3005b63ddafbaef6000526004601cfd5b631a15a3cc6000526004601cfd5b611c26565b346101fc5760006003193601126101fc576020610869611f07565b604051908152f35b346101fc5761087f36611d20565b91906387a211a2600c52826000526020600c205482116108a85781806020946108699333612385565b634656425a6000526004601cfd5b346101fc576108c436611d20565b91906387a211a2600c52826000526020600c205482116108ed5781806020946108699333612385565b63936941fc6000526004601cfd5b346101fc5760406003193601126101fc57610914611be0565b6024356387a211a2600c523360005260209182600c20805480841161097b57839003905560005281600c208181540190558152600c5160601c337fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8380a360405160018152f35b63f4d678b86000526004601cfd5b60006003193601126101fc5761099d611f07565b34118015610a95575b610a6b576024602073ffffffffffffffffffffffffffffffffffffffff7f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e60005416604051928380927fa1903eab0000000000000000000000000000000000000000000000000000000082526000600483015234905af1801561064357600090610a38575b80610869816020933330612031565b506020813d602011610a63575b81610a5260209383611c6a565b810103126101fc5760209051610a29565b3d9150610a45565b60046040517fb3c61a83000000000000000000000000000000000000000000000000000000008152fd5b5060006109a6565b346101fc5760006003193601126101fc576040517f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e60028054826000610ae083611d62565b9283835260209460019186600182169182600014610b84575050600114610b28575b5050610b1092500383611c6a565b610b24604051928284938452830190611b9d565b0390f35b8592506000527f076f787d08cfb4f70f0b3126e729358b131ab3a11cf08c3e097c3179416ab278906000915b858310610b6c575050610b1093508201018580610b02565b80548389018501528794508693909201918101610b54565b91509350610b109592507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0091501682840152151560051b8201018580610b02565b346101fc5760406003193601126101fc5760206004356108698180610be8611c03565b33612031565b346101fc5760606003193601126101fc57610c07611be0565b60243567ffffffffffffffff81116101fc57610c27903690600401611cab565b9060443567ffffffffffffffff81116101fc57610c48903690600401611cab565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffbf60113292835480600386556113b7575b50337fffffffffffffffffffffffffffffffffffffffffffffffffffffffff74873927553360007f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08180a37f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e600073ffffffffffffffffffffffffffffffffffffffff84167fffffffffffffffffffffffff0000000000000000000000000000000000000000825416179055805167ffffffffffffffff811161108f577f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e6001610d5c8154611d62565b91601f92838111611356575b5080602084821160011461129b57600091611290575b507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8260011b9260031b1c19161790555b825167ffffffffffffffff811161108f57610dea7f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e600254611d62565b8281116111d0575b508060208382116001146110d3576000916110c8575b507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8260011b9260031b1c1916177f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e6002555b63313ce567600052602060006004601c875afa903d1190600051916101008310161690816000146110be5702915b60ff7f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e600393167fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00845416178355610f26602c60405184610ef0829651809260208086019101611b7a565b81017f205374616b65205661756c740000000000000000000000000000000000000000602082015203600c810185520183611c6a565b610f79602560405180937f7374766c740000000000000000000000000000000000000000000000000000006020830152610f698151809260208686019101611b7a565b8101036005810184520182611c6a565b60405191611870918284019084821067ffffffffffffffff83111761108f57610fd0610fde938695612a00873973ffffffffffffffffffffffffffffffffffffffff89168452606060208501526060840190611b9d565b916040818403910152611b9d565b03906000f09182156106435761105273ffffffffffffffffffffffffffffffffffffffff85948461105995547fffffffffffffffffffffff0000000000000000000000000000000000000000ff74ffffffffffffffffffffffffffffffffffffffff008460081b169116179055168261231b565b309061231b565b61105f57005b6002905560016020527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d2602080a1005b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b5050601291610e87565b905084015187610e08565b907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016907f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e60026000527f076f787d08cfb4f70f0b3126e729358b131ab3a11cf08c3e097c3179416ab2789160005b8181106111b857509083600194939210611181575b5050811b017f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e600255610e59565b8601517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff60f88460031b161c191690558780611155565b9192602060018192868b015181550194019201611140565b7f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e60026000528280830160051c7f076f787d08cfb4f70f0b3126e729358b131ab3a11cf08c3e097c3179416ab278019160208410611268575b0160051c7f076f787d08cfb4f70f0b3126e729358b131ab3a11cf08c3e097c3179416ab27801905b81811061125c5750610df2565b6000815560010161124f565b7f076f787d08cfb4f70f0b3126e729358b131ab3a11cf08c3e097c3179416ab2789250611227565b905084015188610d7e565b60008481527f1278ec55cbcb4188fb62be70144da3ac242cd8ee486d68f8c531c388d9a420c1927fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016905b81811061133e57509083600194939210611307575b5050811b019055610daf565b8601517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff60f88460031b161c1916905588806112fb565b9192602060018192868b0151815501940192016112e6565b826000527f1278ec55cbcb4188fb62be70144da3ac242cd8ee486d68f8c531c388d9a420c18480840160051c820192602085106113ae575b0160051c01905b8181106113a25750610d68565b60008155600101611395565b9250819261138e565b600181819693961c14303b10156113d35760ff1b1b9284610c76565b63f92ee8a96000526004601cfd5b346101fc5760006003193601126101fc5760207fffffffffffffffffffffffffffffffffffffffffffffffffffffffff748739275473ffffffffffffffffffffffffffffffffffffffff60405191168152f35b346101fc5760206003193601126101fc5761144d611be0565b6338377508600c52600052602080600c2054604051908152f35b60006003193601126101fc5761147b611fb0565b60007fffffffffffffffffffffffffffffffffffffffffffffffffffffffff748739278181547f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a355005b346101fc5760206003193601126101fc576114e1611be0565b6387a211a2600c52600052602080600c2054604051908152f35b60006003193601126101fc5763389a75e1600c523360005260006020600c2055337ffa7b8eab7da67f412cc9575ed43464468f9bfbae89d1675917346ca6d8fe3c92600080a2005b346101fc5760006003193601126101fc57307f0000000000000000000000000000000000000000000000000000000000000000036115a55760206040517f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc8152f35b639f03a0266000526004601cfd5b60406003193601126101fc576115c7611be0565b6024359067ffffffffffffffff908183116101fc57366023840112156101fc5782600401359182116101fc5736602483850101116101fc57307f0000000000000000000000000000000000000000000000000000000000000000146115a55773ffffffffffffffffffffffffffffffffffffffff90611644611fb0565b166352d1902d6001527f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc80602060016004601d865afa51036116d257818391817fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b600080a2556116b057005b816000926024604051950185378338925af4156116c957005b3d6000823e3d90fd5b6355299b496001526004601dfd5b346101fc5760006003193601126101fc57602073ffffffffffffffffffffffffffffffffffffffff7f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e60005416604051908152f35b346101fc5760006003193601126101fc576004602073ffffffffffffffffffffffffffffffffffffffff7f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e60035460081c16604051928380927f01e1d1140000000000000000000000000000000000000000000000000000000082525afa801561064357600090611800575b602091506805345cdf77eb68f44c547f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e600654918181116105f9575050604051908152f35b506020813d60201161182b575b8161181a60209383611c6a565b810103126101fc57602090516117bd565b3d915061180d565b346101fc5760006003193601126101fc57602060a0611850611db5565b828151910120604051907f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f8252838201527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6604082015246606082015230608082015220604051908152f35b346101fc5760006003193601126101fc57602060ff7f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e60035416604051908152f35b60006003193601126101fc5763389a75e1600c52336000526202a30042016020600c2055337fdbf36a107da19e49527a7176a1babf963b4b0ff8cde35ee35d6cd8f1f9ac7e1d600080a2005b346101fc5760606003193601126101fc57611961611be0565b611969611c03565b90604435918160601b602093338552600c91637f5e9f2081178352603483209081549160018301611a08575b506387a211a2178352508482208054939084831161097b578273ffffffffffffffffffffffffffffffffffffffff9503905560005284822081815401905584525160601c91167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8380a360405160018152f35b828411611a1f57836387a211a29303905587611995565b6313be252b6000526004601cfd5b346101fc5760006003193601126101fc57611a46611fb0565b611ab473ffffffffffffffffffffffffffffffffffffffff7f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e60005416306014526f70a0823100000000000000000000000060005260208060246010845afa601f3d111660205102903390611fe8565b005b346101fc5760006003193601126101fc5760206805345cdf77eb68f44c54604051908152f35b346101fc5760406003193601126101fc57611af5611be0565b60243590602052637f5e9f20600c5233600052806034600c2055600052602c5160601c337f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560206000a3602060405160018152f35b346101fc5760006003193601126101fc57610b24611b66611db5565b604051918291602083526020830190611b9d565b60005b838110611b8d5750506000910152565b8181015183820152602001611b7d565b907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f602093611bd981518092818752878088019101611b7a565b0116010190565b6004359073ffffffffffffffffffffffffffffffffffffffff821682036101fc57565b6024359073ffffffffffffffffffffffffffffffffffffffff821682036101fc57565b346101fc5760206003193601126101fc57611c3f611be0565b5060206040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8152f35b90601f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0910116810190811067ffffffffffffffff82111761108f57604052565b81601f820112156101fc5780359067ffffffffffffffff821161108f5760405192611cfe60207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f8601160185611c6a565b828452602083830101116101fc57816000926020809301838601378301015290565b60031960609101126101fc576004359073ffffffffffffffffffffffffffffffffffffffff9060243582811681036101fc579160443590811681036101fc5790565b90600182811c92168015611dab575b6020831014611d7c57565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b91607f1691611d71565b604051906000827f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e600191825492611dea84611d62565b80845293602091600191828116908115611e795750600114611e18575b505050611e1692500383611c6a565b565b60009081527f1278ec55cbcb4188fb62be70144da3ac242cd8ee486d68f8c531c388d9a420c19590935091905b828410611e615750611e16945050508101602001388080611e07565b85548885018301529485019487945092810192611e45565b91505060209350611e169592507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0091501682840152151560051b820101388080611e07565b91908203918211611ecb57565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b91908201809211611ecb57565b6004602073ffffffffffffffffffffffffffffffffffffffff7f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e60005416604051928380927f609c4c6c0000000000000000000000000000000000000000000000000000000082525afa90811561064357600091611f81575090565b90506020813d602011611fa8575b81611f9c60209383611c6a565b810103126101fc575190565b3d9150611f8f565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffff74873927543303611fda57565b6382b429006000526004601cfd5b60109260209260145260345260446000938480936fa9059cbb00000000000000000000000082525af13d15600183511417161561202457603452565b6390b8ec1890526004601cfd5b9291601c919273ffffffffffffffffffffffffffffffffffffffff91827f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e6000541692604096875193836060523089528160601b602c526f23b872dd000000000000000000000000600c526020809660646000998a80935af13d15600189511417161561230e57866060528489526805345cdf77eb68f44c80549082820191821061230157556387a211a2600c5287875285600c208181540190558552600c5160601c867fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8780a38286528682169082167fdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d78988a37f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e60035460081c16917fef8b30f70000000000000000000000000000000000000000000000000000000081528160048201528381602481865afa9081156122f75785916122c6575b501561229d5791809160448594885196879384927f6e553f6500000000000000000000000000000000000000000000000000000000845260048401523060248401525af194851561229257508194612258575b50505061224c6122549173ffffffffffffffffffffffffffffffffffffffff166000527f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e6004602052604060002090565b918254611efa565b9055565b909180939450813d831161228b575b6122718183611c6a565b810103126122885750519061224c612254386121fd565b80fd5b503d612267565b51913d9150823e3d90fd5b600486517f6ba4a1c7000000000000000000000000000000000000000000000000000000008152fd5b90508381813d83116122f0575b6122dd8183611c6a565b810103126122ec5751386121aa565b8480fd5b503d6122d3565b87513d87823e3d90fd5b63e5cfe95789526004601cfd5b637939f42487526004601cfd5b6020906010926014527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff60345260446000938480936f095ea7b300000000000000000000000082525af13d15600183511417161561237857603452565b633e3f8f7390526004601cfd5b91949392909260ff7f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e600754166129d5576123fd8673ffffffffffffffffffffffffffffffffffffffff166000527f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e6004602052604060002090565b54926387a211a296600c92888452600094828652602090818620548082106000146129cd57879080890381168981830460028160030281188083028203028083028203028083028203028083028203028083028203028092029003029260018380829403040191612942575b50505050955b73ffffffffffffffffffffffffffffffffffffffff98897f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e60035460081c1660409889517f4cdad5060000000000000000000000000000000000000000000000000000000081528160048201528681602481865afa90811561293857918688928e9485916128ff575b50101561280057508a517fb460af94000000000000000000000000000000000000000000000000000000008152600481018790523060248201819052604482015292909150829060649082908e905af19081156127f65790859392918b916127bf575b508181101561276d5761256b91611ebe565b6125b48773ffffffffffffffffffffffffffffffffffffffff166000527f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e6004602052604060002090565b555b825b838082116126d9575b50508986169c8d8b89160361268e575b8152858952209a8b54808511612681579088999a9b9c857ffbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db9a930390556805345cdf77eb68f44c8581540390558482527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8483a3612673818b8b7f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e60005416611fe8565b8752528516958516941692a4565b63f4d678b889526004601cfd5b878352637f5e9f208252868a52603482208054600181016126b1575b50506125d1565b80919293945087116126cc57869003905583919038806126aa565b6313be252b8b526004601cfd5b6126e291611ebe565b61272b8773ffffffffffffffffffffffffffffffffffffffff166000527f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e6005602052604060002090565b612736828254611efa565b90556127647f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e6006918254611efa565b905538836125c1565b5050886127b98773ffffffffffffffffffffffffffffffffffffffff166000527f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e6004602052604060002090565b556125b6565b848193949592503d83116127ef575b6127d88183611c6a565b810103126127eb57908492915138612559565b8980fd5b503d6127ce565b89513d8c823e3d90fd5b612811816128a49496959395611ebe565b61285a8b73ffffffffffffffffffffffffffffffffffffffff166000527f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e6004602052604060002090565b558b517fba08765200000000000000000000000000000000000000000000000000000000815260048101919091523060248201819052604482015293849283919082906064820190565b03925af19081156128f557908492918a916128c0575b506125b8565b8381939492503d83116128ee575b6128d88183611c6a565b810103126128ea5790839151386128ba565b8880fd5b503d6128ce565b88513d8b823e3d90fd5b93929450505081813d8311612931575b6129198183611c6a565b8101031261292d578b9186889251386124f6565b8b80fd5b503d61290f565b8b513d8e823e3d90fd5b90919293508b85027fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8d870991818310820180840393146129aa578281111561299d578d870993848203049311900302170238808080612469565b63ae47f7028d526004601cfd5b94509250505081156129c0570438808080612469565b63ae47f70289526004601cfd5b50879561246f565b60046040517f6665c76c000000000000000000000000000000000000000000000000000000008152fdfe608060405234610333576118708038038061001981610338565b9283398101906060818303126103335780516001600160a01b038116908190036103335760208281015190936001600160401b039390918481116103335782610063918301610373565b9160408201518581116103335761007a9201610373565b33638b78c6d8195560009233847f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08180a383546001600160a01b031916178355815192848411610249576001938454938585811c95168015610329575b88861014610315578190601f958681116102c7575b50889086831160011461026857849261025d575b5050600019600383901b1c191690851b1784555b8151948511610249576002548481811c9116801561023f575b8782101461022b578381116101e7575b5085928511600114610183579394508492919083610178575b50501b916000199060031b1c1916176002555b60405161149190816103df8239f35b015192503880610156565b6002815285812093958591601f198316915b888383106101cd57505050106101b4575b505050811b01600255610169565b015160001960f88460031b161c191690553880806101a6565b858701518855909601959485019487935090810190610195565b600282528682208480880160051c820192898910610222575b0160051c019085905b82811061021757505061013d565b838155018590610209565b92508192610200565b634e487b7160e01b82526022600452602482fd5b90607f169061012d565b634e487b7160e01b81526041600452602490fd5b015190503880610100565b8785528985208894509190601f198416865b8c8282106102b15750508411610298575b505050811b018455610114565b015160001960f88460031b161c1916905538808061028b565b8385015186558b9790950194938401930161027a565b9091508684528884208680850160051c8201928b861061030c575b918991869594930160051c01915b8281106102fe5750506100ec565b8681558594508991016102f0565b925081926102e2565b634e487b7160e01b83526022600452602483fd5b94607f16946100d7565b600080fd5b6040519190601f01601f191682016001600160401b0381118382101761035d57604052565b634e487b7160e01b600052604160045260246000fd5b919080601f840112156103335782516001600160401b03811161035d576020906103a5601f8201601f19168301610338565b928184528282870101116103335760005b8181106103cb57508260009394955001015290565b85810183015184820184015282016103b656fe6040608081526004908136101561001557600080fd5b600091823560e01c90816301e1d11414610c9357816306fdde0314610c6a57816307a2d13a14610a52578163095ea7b314610c005781630a28a47714610be057816318160ddd14610bb957816323b872dd14610b945781632569296214610b49578163313ce56714610b2d5781633644e51514610aa557816338d52e0f14610a72578163402d267d146105a15781634cdad50614610a5257816354d1f13d14610a0c5781636e553f65146109cf57816370a0823114610380578163715018a61461096e5781637ecebe001461093a5781638da5cb5b146108e657816394bf804d146108a957816395d89b41146106cd578163a9059cbb1461068b578163b3d7f6b91461066b578163b460af941461060a578163ba087652146105a6578163c63d75b6146105a1578163c6e6f5921461031b578163ce96cb771461056c578163d505accf146103b4578163d905777e14610380578163dd62ed3e14610342578163ef8b30f71461031b578163f04e283e14610270578163f2fde38b146101da575063fee81cf4146101a457600080fd5b346101d65760206003193601126101d6576020916101c0610d16565b9063389a75e1600c525281600c20549051908152f35b5080fd5b839060206003193601126101d6576101f0610d16565b906101f96111bb565b8160601b15610265575073ffffffffffffffffffffffffffffffffffffffff167fffffffffffffffffffffffffffffffffffffffffffffffffffffffff748739278181547f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08580a35580f35b637448fbae8352601cfd5b83602060031936011261031857610285610d16565b61028d6111bb565b63389a75e1600c528082526020600c20928354421161030d57508173ffffffffffffffffffffffffffffffffffffffff929355167fffffffffffffffffffffffffffffffffffffffffffffffffffffffff748739278181547f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08580a35580f35b636f5e88188352601cfd5b80fd5b828434610318576020600319360112610318575061033b602092356110a6565b9051908152f35b5050346101d657806003193601126101d65760209161035f610d16565b90610368610d3e565b8452637f5e9f20600c52526034600c20549051908152f35b5050346101d65760206003193601126101d65760209161039e610d16565b906387a211a2600c525281600c20549051908152f35b8383346101d65760e06003193601126101d6576103cf610d16565b6103d7610d3e565b60443590606435916084359460ff86168603610568576103f5610e2d565b93845160208096012081421161055c5782519760c073ffffffffffffffffffffffffffffffffffffffff809916988997169965383775081901600e52878c5288600c2094855480957f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f84528b84019081528d8985017fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc68152606086019c8d469052608087019330855260a08820602e527f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c988525252898b525260a082015220604e526042602c208a5260ff16865260a435835260c435606052858060808b60015afa90873d5103610550577f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259798999a5001905586777f5e9f2000000000000000000000000000000000000000001790526034602c2055a380f35b8a63ddafbaef8b52601cfd5b89631a15a3cc8a52601cfd5b8680fd5b5050346101d65760206003193601126101d65760209161058a610d16565b906387a211a2600c525261033b82600c2054610ff0565b610d61565b91905034610606576105b736610da5565b939091946105c36111bb565b6387a211a2600c528481526020600c205486116105fb575050836105f5916105ec602096610ff0565b94859133611304565b51908152f35b634656425a9052601cfd5b8280fd5b919050346106065761061b36610da5565b9390946106266111bb565b6387a211a2600c5284815261063f6020600c2054610ff0565b8311610660575050602093816106576105f59361104e565b94859233611304565b63936941fc9052601cfd5b828434610318576020600319360112610318575061033b6020923561107a565b828434610318578160031936011261031857506106a6610d16565b50517f8cd22d19000000000000000000000000000000000000000000000000000000008152fd5b8383346101d657816003193601126101d6578051908260025460018160011c906001831692831561089f575b6020938484108114610873578388528795949392918115610818575060011461079b575b50505003601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01682019267ffffffffffffffff84118385101761076f575082918261076b925282610cb0565b0390f35b806041867f4e487b71000000000000000000000000000000000000000000000000000000006024945252fd5b600288529193925086917f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ace5b82841061080257505050907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe092601f9282010191819361071d565b80548885018701528794509285019281016107c7565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016848701525050151560051b830101905081601f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe061071d565b60248960228c7f4e487b7100000000000000000000000000000000000000000000000000000000835252fd5b91607f16916106f9565b9050346106065781600319360112610606576020925035906105f56108cc610d3e565b926108d56111bb565b6108de8161107a565b8094336111f3565b5050346101d657816003193601126101d65760209073ffffffffffffffffffffffffffffffffffffffff7fffffffffffffffffffffffffffffffffffffffffffffffffffffffff7487392754915191168152f35b5050346101d65760206003193601126101d657602091610958610d16565b906338377508600c525281600c20549051908152f35b8380600319360112610318576109826111bb565b807fffffffffffffffffffffffffffffffffffffffffffffffffffffffff748739278181547f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a35580f35b9050346106065781600319360112610606576020925035906105f56109f2610d3e565b6109fa6111bb565b610a03846110a6565b938491336111f3565b83806003193601126103185763389a75e1600c52338152806020600c2055337ffa7b8eab7da67f412cc9575ed43464468f9bfbae89d1675917346ca6d8fe3c928280a280f35b828434610318576020600319360112610318575061033b60209235610ff0565b5050346101d657816003193601126101d65773ffffffffffffffffffffffffffffffffffffffff60209254169051908152f35b5050346101d657816003193601126101d65760209060a0610ac4610e2d565b8381519101208251907f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f8252848201527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc683820152466060820152306080820152209051908152f35b5050346101d657816003193601126101d6576020905160128152f35b83806003193601126103185763389a75e1600c523381526202a30042016020600c2055337fdbf36a107da19e49527a7176a1babf963b4b0ff8cde35ee35d6cd8f1f9ac7e1d8280a280f35b8284346103185760606003193601126103185750610bb0610d16565b506106a6610d3e565b5050346101d657816003193601126101d6576020906805345cdf77eb68f44c549051908152f35b828434610318576020600319360112610318575061033b6020923561104e565b5050346101d657806003193601126101d657602091610c1d610d16565b602435908452637f5e9f20600c52338252806034600c20558152602c5160601c907f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925843392a35160018152f35b5050346101d657816003193601126101d65761076b90610c88610e2d565b905191829182610cb0565b5050346101d657816003193601126101d65760209061033b610de7565b60208082528251818301819052939260005b858110610d02575050507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f8460006040809697860101520116010190565b818101830151848201604001528201610cc2565b6004359073ffffffffffffffffffffffffffffffffffffffff82168203610d3957565b600080fd5b6024359073ffffffffffffffffffffffffffffffffffffffff82168203610d3957565b34610d39576020600319360112610d3957610d7a610d16565b5060206040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8152f35b6003196060910112610d39576004359073ffffffffffffffffffffffffffffffffffffffff906024358281168103610d3957916044359081168103610d395790565b6020806024601073ffffffffffffffffffffffffffffffffffffffff60005416306014526f70a082310000000000000000000000006000525afa601f3d11166020510290565b6040516000916001926001548060011c60018216958615610fe6575b6020928383108814610fb957869783889798529081600014610f5e5750600114610ee0575b50505003601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016820167ffffffffffffffff811183821017610eb157604052565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b60016000908152929493507fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf65b828410610f4857505050907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe092601f92820101918193610e6e565b8054888501870152879450928501928101610f0d565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016848701525050151560051b830101905081601f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0610e6e565b6024857f4e487b710000000000000000000000000000000000000000000000000000000081526022600452fd5b90607f1690610e49565b610ff8610de7565b906001820180921161101f5761101c9160016805345cdf77eb68f44c5401916110ce565b90565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6805345cdf77eb68f44c54906001820180921161101f5761101c916001611073610de7565b019161118a565b611082610de7565b906001820180921161101f5761101c9160016805345cdf77eb68f44c54019161118a565b6805345cdf77eb68f44c54906001820180921161101f5761101c9160016110cb610de7565b01915b90600091818102917fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff818309918383108401808403931461116e578286111561116157908591099160018585038616809604600281600302811880830282030280830282030280830282030280830282030280830282030280920290030295808086850304960304019211900302170290565b63ae47f70285526004601cfd5b50505090821561117d57500490565b63ae47f70290526004601cfd5b9291906111988282866110ce565b93096111a057565b906001019081156111ad57565b63ae47f7026000526004601cfd5b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffff748739275433036111e557565b6382b429006000526004601cfd5b9092919273ffffffffffffffffffffffffffffffffffffffff93600093858554166020866064601c826040519588606052306040528a60601b602c526f23b872dd000000000000000000000000600c525af13d1560018851141716156112f757856060526040526805345cdf77eb68f44c8054908282019182106112ea57917fdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d795939160409593556387a211a2600c528287526020600c20818154019055602052600c5160601c867fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef602080a385528516941692a3565b63e5cfe95787526004601cfd5b637939f42486526004601cfd5b9093929173ffffffffffffffffffffffffffffffffffffffff93848216938486851603611413575b6387a211a2600c526000948386526020600c2080548085116114065790848893920390556805345cdf77eb68f44c8481540390558382527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef602083a360208560446010828a8154168c601452866034526fa9059cbb00000000000000000000000082525af13d1560018751141716156113f9576034859052845260205283169383169216907ffbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db90604090a4565b6390b8ec1885526004601cfd5b63f4d678b888526004601cfd5b83602052637f5e9f20600c52826000526034600c2080546001810161143a575b505061132c565b80841161144d5783900390553880611433565b6313be252b6000526004601cfdfea26469706673582212206acbac7095e6091c09b8da43ccc62dfe504e5d3e916b7edca95070b573aa260764736f6c63430008190033a26469706673582212202d12600099e9a3f76334b61f2f113c70e767a5aba4c0032694a5e34969d3605a64736f6c63430008190033
Deployed Bytecode
0x6080604052600436101561001257600080fd5b60003560e01c806306fdde0314611b4a578063095ea7b314611adc57806318160ddd14611ab65780632108af0914611a2d57806323b872dd1461194857806325692962146118fc578063313ce567146118bc5780633644e5151461183357806337c089231461173357806338d52e0f146116e0578063402d267d146108495780634f1ef286146115b357806352d1902d1461154357806354d1f13d146114fb5780636e553f6514610bc557806370a08231146114c8578063715018a6146114675780637ecebe00146114345780638da5cb5b146113e15780639065714714610bee57806394bf804d14610bc557806395d89b4114610a9d578063a0b29ee514610989578063a9059cbb146108fb578063b460af94146108b6578063ba08765214610871578063bc87ec1c1461084e578063c63d75b614610849578063ce96cb771461068e578063d505accf14610693578063d905777e1461068e578063dd62ed3e1461064f578063e2dc4310146104a7578063e36aed281461041d578063f04e283e14610373578063f2fde38b146102de578063f317124c14610257578063f61ebc36146102015763fee81cf4146101c957600080fd5b346101fc5760206003193601126101fc576101e2611be0565b63389a75e1600c52600052602080600c2054604051908152f35b600080fd5b346101fc5760006003193601126101fc57602073ffffffffffffffffffffffffffffffffffffffff7f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e60035460081c16604051908152f35b346101fc5760006003193601126101fc57610270611fb0565b7f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e60077fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0081541690557f15fa93f6df3cbaf0b9ddb555fa798ba412e2bbc86e60aa62d8aade4c3052cd62600080a1005b60206003193601126101fc576102f2611be0565b6102fa611fb0565b8060601b156103655773ffffffffffffffffffffffffffffffffffffffff167fffffffffffffffffffffffffffffffffffffffffffffffffffffffff748739278181547f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0600080a355005b637448fbae6000526004601cfd5b60206003193601126101fc57610387611be0565b61038f611fb0565b63389a75e1600c52806000526020600c20908154421161040f57600073ffffffffffffffffffffffffffffffffffffffff9255167fffffffffffffffffffffffffffffffffffffffffffffffffffffffff748739278181547f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0600080a355005b636f5e88186000526004601cfd5b346101fc5760006003193601126101fc57610436611fb0565b7f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e600760017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff008254161790557f8780a7821711ac08118dc8a77c63f7e98eb11187d8a4566cb46c690f9a6e76bf600080a1005b346101fc576020806003193601126101fc576104c1611be0565b73ffffffffffffffffffffffffffffffffffffffff7f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e60035460081c1690826105478273ffffffffffffffffffffffffffffffffffffffff166000527f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e6004602052604060002090565b546024604051809581937f4cdad50600000000000000000000000000000000000000000000000000000000835260048301525afa91821561064357600092610614575b506387a211a2600c52806000526105e583600c20549173ffffffffffffffffffffffffffffffffffffffff166000527f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e6005602052604060002090565b54918181116105f9575b5050604051908152f35b61060d929161060791611ebe565b90611efa565b82806105ef565b9091508281813d831161063c575b61062c8183611c6a565b810103126101fc5751908361058a565b503d610622565b6040513d6000823e3d90fd5b346101fc5760406003193601126101fc57610668611be0565b610670611c03565b602052637f5e9f20600c5260005260206034600c2054604051908152f35b6114c8565b346101fc5760e06003193601126101fc576106ac611be0565b6106b4611c03565b604435606435906084359360ff851685036101fc576106d1611db5565b9182516020809401209184421161083b576040519073ffffffffffffffffffffffffffffffffffffffff80911696169665383775081901600e528660005260c085600c20928354977f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f82528782019687528860408301977fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc689528c6060850199468b528d608087019330855260a08820602e527f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9885252528789525260a082015220604e526042602c2060005260ff16845260a43560405260c43560605283806080600060015afa863d510361082d577f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259501905585777f5e9f200000000000000000000000000000000000000000176040526034602c2055a3005b63ddafbaef6000526004601cfd5b631a15a3cc6000526004601cfd5b611c26565b346101fc5760006003193601126101fc576020610869611f07565b604051908152f35b346101fc5761087f36611d20565b91906387a211a2600c52826000526020600c205482116108a85781806020946108699333612385565b634656425a6000526004601cfd5b346101fc576108c436611d20565b91906387a211a2600c52826000526020600c205482116108ed5781806020946108699333612385565b63936941fc6000526004601cfd5b346101fc5760406003193601126101fc57610914611be0565b6024356387a211a2600c523360005260209182600c20805480841161097b57839003905560005281600c208181540190558152600c5160601c337fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8380a360405160018152f35b63f4d678b86000526004601cfd5b60006003193601126101fc5761099d611f07565b34118015610a95575b610a6b576024602073ffffffffffffffffffffffffffffffffffffffff7f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e60005416604051928380927fa1903eab0000000000000000000000000000000000000000000000000000000082526000600483015234905af1801561064357600090610a38575b80610869816020933330612031565b506020813d602011610a63575b81610a5260209383611c6a565b810103126101fc5760209051610a29565b3d9150610a45565b60046040517fb3c61a83000000000000000000000000000000000000000000000000000000008152fd5b5060006109a6565b346101fc5760006003193601126101fc576040517f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e60028054826000610ae083611d62565b9283835260209460019186600182169182600014610b84575050600114610b28575b5050610b1092500383611c6a565b610b24604051928284938452830190611b9d565b0390f35b8592506000527f076f787d08cfb4f70f0b3126e729358b131ab3a11cf08c3e097c3179416ab278906000915b858310610b6c575050610b1093508201018580610b02565b80548389018501528794508693909201918101610b54565b91509350610b109592507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0091501682840152151560051b8201018580610b02565b346101fc5760406003193601126101fc5760206004356108698180610be8611c03565b33612031565b346101fc5760606003193601126101fc57610c07611be0565b60243567ffffffffffffffff81116101fc57610c27903690600401611cab565b9060443567ffffffffffffffff81116101fc57610c48903690600401611cab565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffbf60113292835480600386556113b7575b50337fffffffffffffffffffffffffffffffffffffffffffffffffffffffff74873927553360007f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08180a37f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e600073ffffffffffffffffffffffffffffffffffffffff84167fffffffffffffffffffffffff0000000000000000000000000000000000000000825416179055805167ffffffffffffffff811161108f577f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e6001610d5c8154611d62565b91601f92838111611356575b5080602084821160011461129b57600091611290575b507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8260011b9260031b1c19161790555b825167ffffffffffffffff811161108f57610dea7f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e600254611d62565b8281116111d0575b508060208382116001146110d3576000916110c8575b507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8260011b9260031b1c1916177f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e6002555b63313ce567600052602060006004601c875afa903d1190600051916101008310161690816000146110be5702915b60ff7f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e600393167fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00845416178355610f26602c60405184610ef0829651809260208086019101611b7a565b81017f205374616b65205661756c740000000000000000000000000000000000000000602082015203600c810185520183611c6a565b610f79602560405180937f7374766c740000000000000000000000000000000000000000000000000000006020830152610f698151809260208686019101611b7a565b8101036005810184520182611c6a565b60405191611870918284019084821067ffffffffffffffff83111761108f57610fd0610fde938695612a00873973ffffffffffffffffffffffffffffffffffffffff89168452606060208501526060840190611b9d565b916040818403910152611b9d565b03906000f09182156106435761105273ffffffffffffffffffffffffffffffffffffffff85948461105995547fffffffffffffffffffffff0000000000000000000000000000000000000000ff74ffffffffffffffffffffffffffffffffffffffff008460081b169116179055168261231b565b309061231b565b61105f57005b6002905560016020527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d2602080a1005b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b5050601291610e87565b905084015187610e08565b907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016907f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e60026000527f076f787d08cfb4f70f0b3126e729358b131ab3a11cf08c3e097c3179416ab2789160005b8181106111b857509083600194939210611181575b5050811b017f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e600255610e59565b8601517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff60f88460031b161c191690558780611155565b9192602060018192868b015181550194019201611140565b7f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e60026000528280830160051c7f076f787d08cfb4f70f0b3126e729358b131ab3a11cf08c3e097c3179416ab278019160208410611268575b0160051c7f076f787d08cfb4f70f0b3126e729358b131ab3a11cf08c3e097c3179416ab27801905b81811061125c5750610df2565b6000815560010161124f565b7f076f787d08cfb4f70f0b3126e729358b131ab3a11cf08c3e097c3179416ab2789250611227565b905084015188610d7e565b60008481527f1278ec55cbcb4188fb62be70144da3ac242cd8ee486d68f8c531c388d9a420c1927fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016905b81811061133e57509083600194939210611307575b5050811b019055610daf565b8601517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff60f88460031b161c1916905588806112fb565b9192602060018192868b0151815501940192016112e6565b826000527f1278ec55cbcb4188fb62be70144da3ac242cd8ee486d68f8c531c388d9a420c18480840160051c820192602085106113ae575b0160051c01905b8181106113a25750610d68565b60008155600101611395565b9250819261138e565b600181819693961c14303b10156113d35760ff1b1b9284610c76565b63f92ee8a96000526004601cfd5b346101fc5760006003193601126101fc5760207fffffffffffffffffffffffffffffffffffffffffffffffffffffffff748739275473ffffffffffffffffffffffffffffffffffffffff60405191168152f35b346101fc5760206003193601126101fc5761144d611be0565b6338377508600c52600052602080600c2054604051908152f35b60006003193601126101fc5761147b611fb0565b60007fffffffffffffffffffffffffffffffffffffffffffffffffffffffff748739278181547f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a355005b346101fc5760206003193601126101fc576114e1611be0565b6387a211a2600c52600052602080600c2054604051908152f35b60006003193601126101fc5763389a75e1600c523360005260006020600c2055337ffa7b8eab7da67f412cc9575ed43464468f9bfbae89d1675917346ca6d8fe3c92600080a2005b346101fc5760006003193601126101fc57307f000000000000000000000000228e26dfa9dd30b8aa8b2d2bc969f1784fbcdd92036115a55760206040517f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc8152f35b639f03a0266000526004601cfd5b60406003193601126101fc576115c7611be0565b6024359067ffffffffffffffff908183116101fc57366023840112156101fc5782600401359182116101fc5736602483850101116101fc57307f000000000000000000000000228e26dfa9dd30b8aa8b2d2bc969f1784fbcdd92146115a55773ffffffffffffffffffffffffffffffffffffffff90611644611fb0565b166352d1902d6001527f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc80602060016004601d865afa51036116d257818391817fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b600080a2556116b057005b816000926024604051950185378338925af4156116c957005b3d6000823e3d90fd5b6355299b496001526004601dfd5b346101fc5760006003193601126101fc57602073ffffffffffffffffffffffffffffffffffffffff7f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e60005416604051908152f35b346101fc5760006003193601126101fc576004602073ffffffffffffffffffffffffffffffffffffffff7f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e60035460081c16604051928380927f01e1d1140000000000000000000000000000000000000000000000000000000082525afa801561064357600090611800575b602091506805345cdf77eb68f44c547f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e600654918181116105f9575050604051908152f35b506020813d60201161182b575b8161181a60209383611c6a565b810103126101fc57602090516117bd565b3d915061180d565b346101fc5760006003193601126101fc57602060a0611850611db5565b828151910120604051907f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f8252838201527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6604082015246606082015230608082015220604051908152f35b346101fc5760006003193601126101fc57602060ff7f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e60035416604051908152f35b60006003193601126101fc5763389a75e1600c52336000526202a30042016020600c2055337fdbf36a107da19e49527a7176a1babf963b4b0ff8cde35ee35d6cd8f1f9ac7e1d600080a2005b346101fc5760606003193601126101fc57611961611be0565b611969611c03565b90604435918160601b602093338552600c91637f5e9f2081178352603483209081549160018301611a08575b506387a211a2178352508482208054939084831161097b578273ffffffffffffffffffffffffffffffffffffffff9503905560005284822081815401905584525160601c91167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8380a360405160018152f35b828411611a1f57836387a211a29303905587611995565b6313be252b6000526004601cfd5b346101fc5760006003193601126101fc57611a46611fb0565b611ab473ffffffffffffffffffffffffffffffffffffffff7f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e60005416306014526f70a0823100000000000000000000000060005260208060246010845afa601f3d111660205102903390611fe8565b005b346101fc5760006003193601126101fc5760206805345cdf77eb68f44c54604051908152f35b346101fc5760406003193601126101fc57611af5611be0565b60243590602052637f5e9f20600c5233600052806034600c2055600052602c5160601c337f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560206000a3602060405160018152f35b346101fc5760006003193601126101fc57610b24611b66611db5565b604051918291602083526020830190611b9d565b60005b838110611b8d5750506000910152565b8181015183820152602001611b7d565b907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f602093611bd981518092818752878088019101611b7a565b0116010190565b6004359073ffffffffffffffffffffffffffffffffffffffff821682036101fc57565b6024359073ffffffffffffffffffffffffffffffffffffffff821682036101fc57565b346101fc5760206003193601126101fc57611c3f611be0565b5060206040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8152f35b90601f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0910116810190811067ffffffffffffffff82111761108f57604052565b81601f820112156101fc5780359067ffffffffffffffff821161108f5760405192611cfe60207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f8601160185611c6a565b828452602083830101116101fc57816000926020809301838601378301015290565b60031960609101126101fc576004359073ffffffffffffffffffffffffffffffffffffffff9060243582811681036101fc579160443590811681036101fc5790565b90600182811c92168015611dab575b6020831014611d7c57565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b91607f1691611d71565b604051906000827f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e600191825492611dea84611d62565b80845293602091600191828116908115611e795750600114611e18575b505050611e1692500383611c6a565b565b60009081527f1278ec55cbcb4188fb62be70144da3ac242cd8ee486d68f8c531c388d9a420c19590935091905b828410611e615750611e16945050508101602001388080611e07565b85548885018301529485019487945092810192611e45565b91505060209350611e169592507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0091501682840152151560051b820101388080611e07565b91908203918211611ecb57565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b91908201809211611ecb57565b6004602073ffffffffffffffffffffffffffffffffffffffff7f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e60005416604051928380927f609c4c6c0000000000000000000000000000000000000000000000000000000082525afa90811561064357600091611f81575090565b90506020813d602011611fa8575b81611f9c60209383611c6a565b810103126101fc575190565b3d9150611f8f565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffff74873927543303611fda57565b6382b429006000526004601cfd5b60109260209260145260345260446000938480936fa9059cbb00000000000000000000000082525af13d15600183511417161561202457603452565b6390b8ec1890526004601cfd5b9291601c919273ffffffffffffffffffffffffffffffffffffffff91827f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e6000541692604096875193836060523089528160601b602c526f23b872dd000000000000000000000000600c526020809660646000998a80935af13d15600189511417161561230e57866060528489526805345cdf77eb68f44c80549082820191821061230157556387a211a2600c5287875285600c208181540190558552600c5160601c867fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8780a38286528682169082167fdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d78988a37f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e60035460081c16917fef8b30f70000000000000000000000000000000000000000000000000000000081528160048201528381602481865afa9081156122f75785916122c6575b501561229d5791809160448594885196879384927f6e553f6500000000000000000000000000000000000000000000000000000000845260048401523060248401525af194851561229257508194612258575b50505061224c6122549173ffffffffffffffffffffffffffffffffffffffff166000527f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e6004602052604060002090565b918254611efa565b9055565b909180939450813d831161228b575b6122718183611c6a565b810103126122885750519061224c612254386121fd565b80fd5b503d612267565b51913d9150823e3d90fd5b600486517f6ba4a1c7000000000000000000000000000000000000000000000000000000008152fd5b90508381813d83116122f0575b6122dd8183611c6a565b810103126122ec5751386121aa565b8480fd5b503d6122d3565b87513d87823e3d90fd5b63e5cfe95789526004601cfd5b637939f42487526004601cfd5b6020906010926014527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff60345260446000938480936f095ea7b300000000000000000000000082525af13d15600183511417161561237857603452565b633e3f8f7390526004601cfd5b91949392909260ff7f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e600754166129d5576123fd8673ffffffffffffffffffffffffffffffffffffffff166000527f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e6004602052604060002090565b54926387a211a296600c92888452600094828652602090818620548082106000146129cd57879080890381168981830460028160030281188083028203028083028203028083028203028083028203028083028203028092029003029260018380829403040191612942575b50505050955b73ffffffffffffffffffffffffffffffffffffffff98897f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e60035460081c1660409889517f4cdad5060000000000000000000000000000000000000000000000000000000081528160048201528681602481865afa90811561293857918688928e9485916128ff575b50101561280057508a517fb460af94000000000000000000000000000000000000000000000000000000008152600481018790523060248201819052604482015292909150829060649082908e905af19081156127f65790859392918b916127bf575b508181101561276d5761256b91611ebe565b6125b48773ffffffffffffffffffffffffffffffffffffffff166000527f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e6004602052604060002090565b555b825b838082116126d9575b50508986169c8d8b89160361268e575b8152858952209a8b54808511612681579088999a9b9c857ffbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db9a930390556805345cdf77eb68f44c8581540390558482527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8483a3612673818b8b7f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e60005416611fe8565b8752528516958516941692a4565b63f4d678b889526004601cfd5b878352637f5e9f208252868a52603482208054600181016126b1575b50506125d1565b80919293945087116126cc57869003905583919038806126aa565b6313be252b8b526004601cfd5b6126e291611ebe565b61272b8773ffffffffffffffffffffffffffffffffffffffff166000527f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e6005602052604060002090565b612736828254611efa565b90556127647f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e6006918254611efa565b905538836125c1565b5050886127b98773ffffffffffffffffffffffffffffffffffffffff166000527f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e6004602052604060002090565b556125b6565b848193949592503d83116127ef575b6127d88183611c6a565b810103126127eb57908492915138612559565b8980fd5b503d6127ce565b89513d8c823e3d90fd5b612811816128a49496959395611ebe565b61285a8b73ffffffffffffffffffffffffffffffffffffffff166000527f58f5323a293346c609e9b9c9396b9bb59f83e4dd4930bed5c3ccc955754e6004602052604060002090565b558b517fba08765200000000000000000000000000000000000000000000000000000000815260048101919091523060248201819052604482015293849283919082906064820190565b03925af19081156128f557908492918a916128c0575b506125b8565b8381939492503d83116128ee575b6128d88183611c6a565b810103126128ea5790839151386128ba565b8880fd5b503d6128ce565b88513d8b823e3d90fd5b93929450505081813d8311612931575b6129198183611c6a565b8101031261292d578b9186889251386124f6565b8b80fd5b503d61290f565b8b513d8e823e3d90fd5b90919293508b85027fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8d870991818310820180840393146129aa578281111561299d578d870993848203049311900302170238808080612469565b63ae47f7028d526004601cfd5b94509250505081156129c0570438808080612469565b63ae47f70289526004601cfd5b50879561246f565b60046040517f6665c76c000000000000000000000000000000000000000000000000000000008152fdfe608060405234610333576118708038038061001981610338565b9283398101906060818303126103335780516001600160a01b038116908190036103335760208281015190936001600160401b039390918481116103335782610063918301610373565b9160408201518581116103335761007a9201610373565b33638b78c6d8195560009233847f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08180a383546001600160a01b031916178355815192848411610249576001938454938585811c95168015610329575b88861014610315578190601f958681116102c7575b50889086831160011461026857849261025d575b5050600019600383901b1c191690851b1784555b8151948511610249576002548481811c9116801561023f575b8782101461022b578381116101e7575b5085928511600114610183579394508492919083610178575b50501b916000199060031b1c1916176002555b60405161149190816103df8239f35b015192503880610156565b6002815285812093958591601f198316915b888383106101cd57505050106101b4575b505050811b01600255610169565b015160001960f88460031b161c191690553880806101a6565b858701518855909601959485019487935090810190610195565b600282528682208480880160051c820192898910610222575b0160051c019085905b82811061021757505061013d565b838155018590610209565b92508192610200565b634e487b7160e01b82526022600452602482fd5b90607f169061012d565b634e487b7160e01b81526041600452602490fd5b015190503880610100565b8785528985208894509190601f198416865b8c8282106102b15750508411610298575b505050811b018455610114565b015160001960f88460031b161c1916905538808061028b565b8385015186558b9790950194938401930161027a565b9091508684528884208680850160051c8201928b861061030c575b918991869594930160051c01915b8281106102fe5750506100ec565b8681558594508991016102f0565b925081926102e2565b634e487b7160e01b83526022600452602483fd5b94607f16946100d7565b600080fd5b6040519190601f01601f191682016001600160401b0381118382101761035d57604052565b634e487b7160e01b600052604160045260246000fd5b919080601f840112156103335782516001600160401b03811161035d576020906103a5601f8201601f19168301610338565b928184528282870101116103335760005b8181106103cb57508260009394955001015290565b85810183015184820184015282016103b656fe6040608081526004908136101561001557600080fd5b600091823560e01c90816301e1d11414610c9357816306fdde0314610c6a57816307a2d13a14610a52578163095ea7b314610c005781630a28a47714610be057816318160ddd14610bb957816323b872dd14610b945781632569296214610b49578163313ce56714610b2d5781633644e51514610aa557816338d52e0f14610a72578163402d267d146105a15781634cdad50614610a5257816354d1f13d14610a0c5781636e553f65146109cf57816370a0823114610380578163715018a61461096e5781637ecebe001461093a5781638da5cb5b146108e657816394bf804d146108a957816395d89b41146106cd578163a9059cbb1461068b578163b3d7f6b91461066b578163b460af941461060a578163ba087652146105a6578163c63d75b6146105a1578163c6e6f5921461031b578163ce96cb771461056c578163d505accf146103b4578163d905777e14610380578163dd62ed3e14610342578163ef8b30f71461031b578163f04e283e14610270578163f2fde38b146101da575063fee81cf4146101a457600080fd5b346101d65760206003193601126101d6576020916101c0610d16565b9063389a75e1600c525281600c20549051908152f35b5080fd5b839060206003193601126101d6576101f0610d16565b906101f96111bb565b8160601b15610265575073ffffffffffffffffffffffffffffffffffffffff167fffffffffffffffffffffffffffffffffffffffffffffffffffffffff748739278181547f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08580a35580f35b637448fbae8352601cfd5b83602060031936011261031857610285610d16565b61028d6111bb565b63389a75e1600c528082526020600c20928354421161030d57508173ffffffffffffffffffffffffffffffffffffffff929355167fffffffffffffffffffffffffffffffffffffffffffffffffffffffff748739278181547f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08580a35580f35b636f5e88188352601cfd5b80fd5b828434610318576020600319360112610318575061033b602092356110a6565b9051908152f35b5050346101d657806003193601126101d65760209161035f610d16565b90610368610d3e565b8452637f5e9f20600c52526034600c20549051908152f35b5050346101d65760206003193601126101d65760209161039e610d16565b906387a211a2600c525281600c20549051908152f35b8383346101d65760e06003193601126101d6576103cf610d16565b6103d7610d3e565b60443590606435916084359460ff86168603610568576103f5610e2d565b93845160208096012081421161055c5782519760c073ffffffffffffffffffffffffffffffffffffffff809916988997169965383775081901600e52878c5288600c2094855480957f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f84528b84019081528d8985017fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc68152606086019c8d469052608087019330855260a08820602e527f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c988525252898b525260a082015220604e526042602c208a5260ff16865260a435835260c435606052858060808b60015afa90873d5103610550577f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259798999a5001905586777f5e9f2000000000000000000000000000000000000000001790526034602c2055a380f35b8a63ddafbaef8b52601cfd5b89631a15a3cc8a52601cfd5b8680fd5b5050346101d65760206003193601126101d65760209161058a610d16565b906387a211a2600c525261033b82600c2054610ff0565b610d61565b91905034610606576105b736610da5565b939091946105c36111bb565b6387a211a2600c528481526020600c205486116105fb575050836105f5916105ec602096610ff0565b94859133611304565b51908152f35b634656425a9052601cfd5b8280fd5b919050346106065761061b36610da5565b9390946106266111bb565b6387a211a2600c5284815261063f6020600c2054610ff0565b8311610660575050602093816106576105f59361104e565b94859233611304565b63936941fc9052601cfd5b828434610318576020600319360112610318575061033b6020923561107a565b828434610318578160031936011261031857506106a6610d16565b50517f8cd22d19000000000000000000000000000000000000000000000000000000008152fd5b8383346101d657816003193601126101d6578051908260025460018160011c906001831692831561089f575b6020938484108114610873578388528795949392918115610818575060011461079b575b50505003601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01682019267ffffffffffffffff84118385101761076f575082918261076b925282610cb0565b0390f35b806041867f4e487b71000000000000000000000000000000000000000000000000000000006024945252fd5b600288529193925086917f405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ace5b82841061080257505050907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe092601f9282010191819361071d565b80548885018701528794509285019281016107c7565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016848701525050151560051b830101905081601f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe061071d565b60248960228c7f4e487b7100000000000000000000000000000000000000000000000000000000835252fd5b91607f16916106f9565b9050346106065781600319360112610606576020925035906105f56108cc610d3e565b926108d56111bb565b6108de8161107a565b8094336111f3565b5050346101d657816003193601126101d65760209073ffffffffffffffffffffffffffffffffffffffff7fffffffffffffffffffffffffffffffffffffffffffffffffffffffff7487392754915191168152f35b5050346101d65760206003193601126101d657602091610958610d16565b906338377508600c525281600c20549051908152f35b8380600319360112610318576109826111bb565b807fffffffffffffffffffffffffffffffffffffffffffffffffffffffff748739278181547f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a35580f35b9050346106065781600319360112610606576020925035906105f56109f2610d3e565b6109fa6111bb565b610a03846110a6565b938491336111f3565b83806003193601126103185763389a75e1600c52338152806020600c2055337ffa7b8eab7da67f412cc9575ed43464468f9bfbae89d1675917346ca6d8fe3c928280a280f35b828434610318576020600319360112610318575061033b60209235610ff0565b5050346101d657816003193601126101d65773ffffffffffffffffffffffffffffffffffffffff60209254169051908152f35b5050346101d657816003193601126101d65760209060a0610ac4610e2d565b8381519101208251907f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f8252848201527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc683820152466060820152306080820152209051908152f35b5050346101d657816003193601126101d6576020905160128152f35b83806003193601126103185763389a75e1600c523381526202a30042016020600c2055337fdbf36a107da19e49527a7176a1babf963b4b0ff8cde35ee35d6cd8f1f9ac7e1d8280a280f35b8284346103185760606003193601126103185750610bb0610d16565b506106a6610d3e565b5050346101d657816003193601126101d6576020906805345cdf77eb68f44c549051908152f35b828434610318576020600319360112610318575061033b6020923561104e565b5050346101d657806003193601126101d657602091610c1d610d16565b602435908452637f5e9f20600c52338252806034600c20558152602c5160601c907f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925843392a35160018152f35b5050346101d657816003193601126101d65761076b90610c88610e2d565b905191829182610cb0565b5050346101d657816003193601126101d65760209061033b610de7565b60208082528251818301819052939260005b858110610d02575050507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f8460006040809697860101520116010190565b818101830151848201604001528201610cc2565b6004359073ffffffffffffffffffffffffffffffffffffffff82168203610d3957565b600080fd5b6024359073ffffffffffffffffffffffffffffffffffffffff82168203610d3957565b34610d39576020600319360112610d3957610d7a610d16565b5060206040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8152f35b6003196060910112610d39576004359073ffffffffffffffffffffffffffffffffffffffff906024358281168103610d3957916044359081168103610d395790565b6020806024601073ffffffffffffffffffffffffffffffffffffffff60005416306014526f70a082310000000000000000000000006000525afa601f3d11166020510290565b6040516000916001926001548060011c60018216958615610fe6575b6020928383108814610fb957869783889798529081600014610f5e5750600114610ee0575b50505003601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016820167ffffffffffffffff811183821017610eb157604052565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b60016000908152929493507fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf65b828410610f4857505050907fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe092601f92820101918193610e6e565b8054888501870152879450928501928101610f0d565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016848701525050151560051b830101905081601f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0610e6e565b6024857f4e487b710000000000000000000000000000000000000000000000000000000081526022600452fd5b90607f1690610e49565b610ff8610de7565b906001820180921161101f5761101c9160016805345cdf77eb68f44c5401916110ce565b90565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6805345cdf77eb68f44c54906001820180921161101f5761101c916001611073610de7565b019161118a565b611082610de7565b906001820180921161101f5761101c9160016805345cdf77eb68f44c54019161118a565b6805345cdf77eb68f44c54906001820180921161101f5761101c9160016110cb610de7565b01915b90600091818102917fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff818309918383108401808403931461116e578286111561116157908591099160018585038616809604600281600302811880830282030280830282030280830282030280830282030280830282030280920290030295808086850304960304019211900302170290565b63ae47f70285526004601cfd5b50505090821561117d57500490565b63ae47f70290526004601cfd5b9291906111988282866110ce565b93096111a057565b906001019081156111ad57565b63ae47f7026000526004601cfd5b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffff748739275433036111e557565b6382b429006000526004601cfd5b9092919273ffffffffffffffffffffffffffffffffffffffff93600093858554166020866064601c826040519588606052306040528a60601b602c526f23b872dd000000000000000000000000600c525af13d1560018851141716156112f757856060526040526805345cdf77eb68f44c8054908282019182106112ea57917fdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d795939160409593556387a211a2600c528287526020600c20818154019055602052600c5160601c867fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef602080a385528516941692a3565b63e5cfe95787526004601cfd5b637939f42486526004601cfd5b9093929173ffffffffffffffffffffffffffffffffffffffff93848216938486851603611413575b6387a211a2600c526000948386526020600c2080548085116114065790848893920390556805345cdf77eb68f44c8481540390558382527fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef602083a360208560446010828a8154168c601452866034526fa9059cbb00000000000000000000000082525af13d1560018751141716156113f9576034859052845260205283169383169216907ffbde797d201c681b91056529119e0b02407c7bb96a4a2c75c01fc9667232c8db90604090a4565b6390b8ec1885526004601cfd5b63f4d678b888526004601cfd5b83602052637f5e9f20600c52826000526034600c2080546001810161143a575b505061132c565b80841161144d5783900390553880611433565b6313be252b6000526004601cfdfea26469706673582212206acbac7095e6091c09b8da43ccc62dfe504e5d3e916b7edca95070b573aa260764736f6c63430008190033a26469706673582212202d12600099e9a3f76334b61f2f113c70e767a5aba4c0032694a5e34969d3605a64736f6c63430008190033
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 26 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
Loading...
Loading
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.