Sepolia Testnet

Contract

0x43FE6e5A17B38b2944c0Ed0605c8cF15b9Ddf3bF

Overview

ETH Balance

0 ETH

Multichain Info

N/A
Transaction Hash
Method
Block
From
To
Create Fixed ERC...63621002024-07-23 13:18:24139 days ago1721740704IN
0x43FE6e5A...5b9Ddf3bF
0 ETH0.0268505715.21835317
Create Fixed Nat...63583842024-07-22 21:55:24140 days ago1721685324IN
0x43FE6e5A...5b9Ddf3bF
0 ETH0.002549841.50000001
Create Fixed ERC...63541112024-07-22 3:59:24141 days ago1721620764IN
0x43FE6e5A...5b9Ddf3bF
0 ETH0.002669691.50568843
Create Fixed ERC...63515922024-07-21 17:34:48141 days ago1721583288IN
0x43FE6e5A...5b9Ddf3bF
0 ETH0.003072551.74135405
Create Fixed ERC...63418542024-07-20 0:18:12143 days ago1721434692IN
0x43FE6e5A...5b9Ddf3bF
0 ETH0.002641471.50073257
Create Fixed Nat...63403802024-07-19 18:13:00143 days ago1721412780IN
0x43FE6e5A...5b9Ddf3bF
0 ETH0.011420656.67948502
Create Fixed Nat...63402922024-07-19 17:49:24143 days ago1721411364IN
0x43FE6e5A...5b9Ddf3bF
0 ETH0.0225389113.30998292
Create Fixed Nat...63402352024-07-19 17:34:36143 days ago1721410476IN
0x43FE6e5A...5b9Ddf3bF
0 ETH0.0319065918.66089989
Create Fixed ERC...63399762024-07-19 16:29:00143 days ago1721406540IN
0x43FE6e5A...5b9Ddf3bF
0 ETH0.0366571720.77473866
Create Fixed ERC...63359932024-07-19 0:04:00144 days ago1721347440IN
0x43FE6e5A...5b9Ddf3bF
0 ETH0.002660821.50071257
Create Fixed ERC...63359342024-07-18 23:47:24144 days ago1721346444IN
0x43FE6e5A...5b9Ddf3bF
0 ETH0.002648441.50090052
Create Fixed ERC...63301472024-07-17 23:47:48145 days ago1721260068IN
0x43FE6e5A...5b9Ddf3bF
0 ETH0.002641721.50089099
Create Fixed Nat...63301212024-07-17 23:40:48145 days ago1721259648IN
0x43FE6e5A...5b9Ddf3bF
0 ETH0.001418440.83446872
Create Fixed ERC...63301152024-07-17 23:38:36145 days ago1721259516IN
0x43FE6e5A...5b9Ddf3bF
0 ETH0.000003250.00184423
Create Fixed ERC...63296782024-07-17 21:49:00145 days ago1721252940IN
0x43FE6e5A...5b9Ddf3bF
0 ETH0.002648221.50082227
Create Fixed Nat...63290522024-07-17 19:16:36145 days ago1721243796IN
0x43FE6e5A...5b9Ddf3bF
0 ETH0.006564943.86182786
Create Fixed ERC...63249942024-07-17 3:25:00146 days ago1721186700IN
0x43FE6e5A...5b9Ddf3bF
0 ETH0.0030371.71284589

Latest 17 internal transactions

Advanced mode:
Parent Transaction Hash Block From To
63621002024-07-23 13:18:24139 days ago1721740704
0x43FE6e5A...5b9Ddf3bF
 Contract Creation0 ETH
63583842024-07-22 21:55:24140 days ago1721685324
0x43FE6e5A...5b9Ddf3bF
 Contract Creation0 ETH
63541112024-07-22 3:59:24141 days ago1721620764
0x43FE6e5A...5b9Ddf3bF
 Contract Creation0 ETH
63515922024-07-21 17:34:48141 days ago1721583288
0x43FE6e5A...5b9Ddf3bF
 Contract Creation0 ETH
63418542024-07-20 0:18:12143 days ago1721434692
0x43FE6e5A...5b9Ddf3bF
 Contract Creation0 ETH
63403802024-07-19 18:13:00143 days ago1721412780
0x43FE6e5A...5b9Ddf3bF
 Contract Creation0 ETH
63402922024-07-19 17:49:24143 days ago1721411364
0x43FE6e5A...5b9Ddf3bF
 Contract Creation0 ETH
63402352024-07-19 17:34:36143 days ago1721410476
0x43FE6e5A...5b9Ddf3bF
 Contract Creation0 ETH
63399762024-07-19 16:29:00143 days ago1721406540
0x43FE6e5A...5b9Ddf3bF
 Contract Creation0 ETH
63359932024-07-19 0:04:00144 days ago1721347440
0x43FE6e5A...5b9Ddf3bF
 Contract Creation0 ETH
63359342024-07-18 23:47:24144 days ago1721346444
0x43FE6e5A...5b9Ddf3bF
 Contract Creation0 ETH
63301472024-07-17 23:47:48145 days ago1721260068
0x43FE6e5A...5b9Ddf3bF
 Contract Creation0 ETH
63301212024-07-17 23:40:48145 days ago1721259648
0x43FE6e5A...5b9Ddf3bF
 Contract Creation0 ETH
63301152024-07-17 23:38:36145 days ago1721259516
0x43FE6e5A...5b9Ddf3bF
 Contract Creation0 ETH
63296782024-07-17 21:49:00145 days ago1721252940
0x43FE6e5A...5b9Ddf3bF
 Contract Creation0 ETH
63290522024-07-17 19:16:36145 days ago1721243796
0x43FE6e5A...5b9Ddf3bF
 Contract Creation0 ETH
63249942024-07-17 3:25:00146 days ago1721186700
0x43FE6e5A...5b9Ddf3bF
 Contract Creation0 ETH
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
FixedPriceFactory

Compiler Version
v0.8.25+commit.b61c2a91

Optimization Enabled:
Yes with 200 runs

Other Settings:
paris EvmVersion

Contract Source Code (Solidity Standard Json-Input format)

File 1 of 9 : FixedPriceFactory.sol
//SPDX-License-Identifier: MIT

pragma solidity =0.8.25;

import { CREATE3 } from "solady/utils/CREATE3.sol";

import { FixedERC20Pool } from "./FixedERC20Pool.sol";
import { FixedNativePool } from "./FixedNativePool.sol";
import { FixedERC20Params, FixedNativeParams } from "./interfaces/IBasePool.sol";

/// @title FixedPriceFactory
/// @notice Factory contract to deploy Fixed Price Pools with native and ERC20 token as the asset token
/// @notice and any arbitrary ERC20 token as the share token. The pools are deployed using the create3 method.
/// @dev The asset token decimals must be >=2 and <=18 and the share token decimals must be >=0 and <=18
/// @dev Any transfer-hooks applied during swaps will be ignored during the sale but will be applied during redemption and closure
/// @dev if the pool is not whitelisted/exempted from these features.
contract FixedPriceFactory {
    using CREATE3 for *;

    ///@notice Emitted when a new pool is created
    event PoolCreated(address indexed poolAddress, PoolType poolType);

    ///@notice Emitted when a pool creation fails.
    error PoolCreationFailed();

    ///@notice Enum to differentiate between created Native and ERC20 pools
    enum PoolType {
        Native,
        ERC20
    }

    /// -----------------------------------------------------------------------
    /// Public Write Functions
    /// -----------------------------------------------------------------------

    /// @notice Deploys a Fixed Price Pool with native token as the asset token via create3
    /// @dev No two pools can be deployed with the exact same params due to create3 collision.
    /// @param params FixedNativeParams struct
    function createFixedNative(FixedNativeParams memory params) public returns (address pool) {
        bytes32 salt = keccak256(abi.encode(msg.sender, params));

        pool = salt.deploy(getCreationBytecode(msg.sender, params), 0);
        if (pool == address(0)) revert PoolCreationFailed();
        emit PoolCreated(pool, PoolType.Native);
    }

    /// @notice Deploys a Fixed Price Pool with ERC20s token as the asset token via create3
    /// @dev No two pools can be deployed with the exact same params due to create3 collision.
    /// @param params FixedNativeParams struct
    /// @return pool The address of the deployed pool
    function createFixedERC20(FixedERC20Params memory params) public returns (address pool) {
        bytes32 salt = keccak256(abi.encode(msg.sender, params));

        pool = salt.deploy(getCreationBytecode(msg.sender, params), 0);

        if (pool == address(0)) {
            revert PoolCreationFailed();
        }
        emit PoolCreated(pool, PoolType.ERC20);
    }

    /// -----------------------------------------------------------------------
    /// Public Read Functions
    /// -----------------------------------------------------------------------

    ///@notice Returns the address of the Fixed Price Pool with native token as the asset via create3
    ///@param _sender The address of the pool creator
    ///@param params FixedNativeParams struct
    ///@return pool The address of the pool that will be deployed with the given params
    function getFixedNativeAddress(
        address _sender,
        FixedNativeParams memory params
    )
        public
        view
        returns (address)
    {
        bytes32 salt = keccak256(abi.encode(_sender, params));
        return CREATE3.getDeployed(salt);
    }

    ///@notice Returns the address of the Fixed Price Pool with native token as the asset via create3
    ///@param _sender The address of the pool creator
    ///@param params FixedNativeParams struct
    ///@return pool The address of the pool that will be deployed with the given params
    function getFixedERC20Address(
        address _sender,
        FixedERC20Params memory params
    )
        public
        view
        returns (address)
    {
        bytes32 salt = keccak256(abi.encode(_sender, params));
        return CREATE3.getDeployed(salt);
    }

    /// -----------------------------------------------------------------------
    /// Internal Helper Functions
    /// -----------------------------------------------------------------------

    ///@notice Returns the bytecode of the Native Fixed Price Pool used during the create3 call.
    ///@param _owner The address of the pool creator
    ///@param params FixedNativeParams struct
    ///@return The bytecode of the pool that will be deployed with the given params
    function getCreationBytecode(
        address _owner,
        FixedNativeParams memory params
    )
        internal
        pure
        returns (bytes memory)
    {
        bytes memory bytecode = type(FixedNativePool).creationCode;

        return abi.encodePacked(bytecode, abi.encode(_owner, params));
    }

    ///@notice Returns the bytecode of the ERC20 Fixed Price Pool used during the create3 call.
    ///@param _owner The address of the pool creator
    ///@param params FixedNativeParams struct
    ///@return The bytecode of the pool that will be deployed with the given params
    function getCreationBytecode(
        address _owner,
        FixedERC20Params memory params
    )
        internal
        pure
        returns (bytes memory)
    {
        bytes memory bytecode = type(FixedERC20Pool).creationCode;

        return abi.encodePacked(bytecode, abi.encode(_owner, params));
    }
}

File 2 of 9 : CREATE3.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

/// @notice Deploy to deterministic addresses without an initcode factor.
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/CREATE3.sol)
/// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/CREATE3.sol)
/// @author Modified from 0xSequence (https://github.com/0xSequence/create3/blob/master/contracts/Create3.sol)
library CREATE3 {
    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                        CUSTOM ERRORS                       */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Unable to deploy the contract.
    error DeploymentFailed();

    /// @dev Unable to initialize the contract.
    error InitializationFailed();

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                      BYTECODE CONSTANTS                    */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /**
     * -------------------------------------------------------------------+
     * Opcode      | Mnemonic         | Stack        | Memory             |
     * -------------------------------------------------------------------|
     * 36          | CALLDATASIZE     | cds          |                    |
     * 3d          | RETURNDATASIZE   | 0 cds        |                    |
     * 3d          | RETURNDATASIZE   | 0 0 cds      |                    |
     * 37          | CALLDATACOPY     |              | [0..cds): calldata |
     * 36          | CALLDATASIZE     | cds          | [0..cds): calldata |
     * 3d          | RETURNDATASIZE   | 0 cds        | [0..cds): calldata |
     * 34          | CALLVALUE        | value 0 cds  | [0..cds): calldata |
     * f0          | CREATE           | newContract  | [0..cds): calldata |
     * -------------------------------------------------------------------|
     * Opcode      | Mnemonic         | Stack        | Memory             |
     * -------------------------------------------------------------------|
     * 67 bytecode | PUSH8 bytecode   | bytecode     |                    |
     * 3d          | RETURNDATASIZE   | 0 bytecode   |                    |
     * 52          | MSTORE           |              | [0..8): bytecode   |
     * 60 0x08     | PUSH1 0x08       | 0x08         | [0..8): bytecode   |
     * 60 0x18     | PUSH1 0x18       | 0x18 0x08    | [0..8): bytecode   |
     * f3          | RETURN           |              | [0..8): bytecode   |
     * -------------------------------------------------------------------+
     */

    /// @dev The proxy bytecode.
    uint256 private constant _PROXY_BYTECODE = 0x67363d3d37363d34f03d5260086018f3;

    /// @dev Hash of the `_PROXY_BYTECODE`.
    /// Equivalent to `keccak256(abi.encodePacked(hex"67363d3d37363d34f03d5260086018f3"))`.
    bytes32 private constant _PROXY_BYTECODE_HASH =
        0x21c35dbe1b344a2488cf3321d6ce542f8e9f305544ff09e4993a62319a497c1f;

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                      CREATE3 OPERATIONS                    */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Deploys `creationCode` deterministically with a `salt`.
    /// The deployed contract is funded with `value` (in wei) ETH.
    /// Returns the deterministic address of the deployed contract,
    /// which solely depends on `salt`.
    function deploy(bytes32 salt, bytes memory creationCode, uint256 value)
        internal
        returns (address deployed)
    {
        /// @solidity memory-safe-assembly
        assembly {
            // Store the `_PROXY_BYTECODE` into scratch space.
            mstore(0x00, _PROXY_BYTECODE)
            // Deploy a new contract with our pre-made bytecode via CREATE2.
            let proxy := create2(0, 0x10, 0x10, salt)

            // If the result of `create2` is the zero address, revert.
            if iszero(proxy) {
                // Store the function selector of `DeploymentFailed()`.
                mstore(0x00, 0x30116425)
                // Revert with (offset, size).
                revert(0x1c, 0x04)
            }

            // Store the proxy's address.
            mstore(0x14, proxy)
            // 0xd6 = 0xc0 (short RLP prefix) + 0x16 (length of: 0x94 ++ proxy ++ 0x01).
            // 0x94 = 0x80 + 0x14 (0x14 = the length of an address, 20 bytes, in hex).
            mstore(0x00, 0xd694)
            // Nonce of the proxy contract (1).
            mstore8(0x34, 0x01)

            deployed := keccak256(0x1e, 0x17)

            // If the `call` fails, revert.
            if iszero(
                call(
                    gas(), // Gas remaining.
                    proxy, // Proxy's address.
                    value, // Ether value.
                    add(creationCode, 0x20), // Start of `creationCode`.
                    mload(creationCode), // Length of `creationCode`.
                    0x00, // Offset of output.
                    0x00 // Length of output.
                )
            ) {
                // Store the function selector of `InitializationFailed()`.
                mstore(0x00, 0x19b991a8)
                // Revert with (offset, size).
                revert(0x1c, 0x04)
            }

            // If the code size of `deployed` is zero, revert.
            if iszero(extcodesize(deployed)) {
                // Store the function selector of `InitializationFailed()`.
                mstore(0x00, 0x19b991a8)
                // Revert with (offset, size).
                revert(0x1c, 0x04)
            }
        }
    }

    /// @dev Returns the deterministic address for `salt` with `deployer`.
    function getDeployed(bytes32 salt, address deployer) internal pure returns (address deployed) {
        /// @solidity memory-safe-assembly
        assembly {
            // Cache the free memory pointer.
            let m := mload(0x40)
            // Store `deployer`.
            mstore(0x00, deployer)
            // Store the prefix.
            mstore8(0x0b, 0xff)
            // Store the salt.
            mstore(0x20, salt)
            // Store the bytecode hash.
            mstore(0x40, _PROXY_BYTECODE_HASH)

            // Store the proxy's address.
            mstore(0x14, keccak256(0x0b, 0x55))
            // Restore the free memory pointer.
            mstore(0x40, m)
            // 0xd6 = 0xc0 (short RLP prefix) + 0x16 (length of: 0x94 ++ proxy ++ 0x01).
            // 0x94 = 0x80 + 0x14 (0x14 = the length of an address, 20 bytes, in hex).
            mstore(0x00, 0xd694)
            // Nonce of the proxy contract (1).
            mstore8(0x34, 0x01)

            deployed := keccak256(0x1e, 0x17)
        }
    }

    /// @dev Returns the deterministic address for `salt`.
    function getDeployed(bytes32 salt) internal view returns (address deployed) {
        deployed = getDeployed(salt, address(this));
    }
}

File 3 of 9 : FixedERC20Pool.sol
//SPDX-License-Identifier: MIT

pragma solidity =0.8.25;

import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol";
import { FixedPointMathLib } from "solady/utils/FixedPointMathLib.sol";
import { ReentrancyGuard } from "solady/utils/ReentrancyGuard.sol";

import "./interfaces/IERC20.sol";
import { IBasePool, FixedERC20Params } from "./interfaces/IBasePool.sol";

/// @title FixedERC2Pool
/// @notice A fixed price pool that allows users to purchase shares with a predefined standard ERC20 token.
/// @notice The pool creator can set the number of shares available for purchase, the price of each share,
/// @notice the sale start and end dates, the redemption date, and the maximum number of shares a user can purchase.
/// @notice The pool creator can also set a minimum number of shares that must be sold for the sale to be considered successful.
/// @notice The pool creator can also set a platform fee and a swap fee that will be taken from the raised funds.
/// @dev Creation will fail if the asset token has less than 2 or more than 18 decimals, or if the share token has more than 18 decimals.
/// @dev The pool will fail if the sale start date is after the sale end date, or if the redemption date is before the sale end date.
/// @dev The pool will fail if the platform fee or swap fee is greater than or equal to 1e18.
/// @dev The pool will fail if the price of each share is 0, or if the minimum number of shares that must be sold is greater than the number of shares available for purchase.
contract FixedERC20Pool is ReentrancyGuard, IBasePool {
    /// -----------------------------------------------------------------------
    /// Dependencies
    /// -----------------------------------------------------------------------
    using SafeTransferLib for address;
    using FixedPointMathLib for uint256;

    /// -----------------------------------------------------------------------
    /// Immutable State
    /// -----------------------------------------------------------------------
    /// @notice The number of assets (with decimals) required to purchase 1 share.
    uint256 public immutable assetsPerToken;
    /// @notice The number of shares available for purchase (with decimals.)
    uint256 public immutable sharesForSale;
    /// @notice The minimum number of shares that must be sold for the sale to be considered successful, else refunds are issuable.
    uint256 public immutable minimumSharesSold;
    /// @notice The fee percentage in WAD (1e18) that will be taken from the raised funds.
    uint256 public immutable platformFeeWAD;
    /// @notice The fee percentage in WAD (1e18) that will be taken from each swap.
    uint256 public immutable swapFeeWAD;
    /// @notice The maximum number of shares (with decimals) a user can purchase per sale.
    uint256 public immutable userMaximumShares;
    /// @notice The address of the pool creator that retains administrative control.
    address public immutable owner;
    /// @notice The address that will receive the fees generated from the raised funds.
    address public immutable feeRecipient;
    /// @notice The address of the ERC20 token that represents the shares.
    address public immutable shareToken;
    /// @notice The address of the ERC20 token that will be used to purchase shares.
    address public immutable assetToken;
    /// @notice The timestamp when the sale will begin.
    uint40 public immutable saleStart;
    /// @notice The timestamp when the sale will end.
    uint40 public immutable saleEnd;
    /// @notice The timestamp when the shares can be redeemed.
    uint40 public immutable redemptionTimestamp;
    /// @notice Cached ERC20 asset token decimals.
    uint8 private immutable assetDecimals;
    /// @notice Cached ERC20 share token decimals.
    uint8 private immutable shareDecimals;
    /// -----------------------------------------------------------------------
    /// Mutable State
    /// -----------------------------------------------------------------------
    /// @notice The total number of shares sold during the sale so far.
    uint256 public totalSharesSold;
    /// @notice The total amount of swap fees generated during the sale.
    uint256 public swapFees;
    /// @notice Returns true if `close` has been called.
    bool public closed;
    /// @notice Returns true if `pause` has been called.
    bool public paused;
    /// @notice Returns true if `cancelSale` has been called.
    bool public canceled;
    /// @notice The number of shares purchased by each user.
    mapping(address => uint256) public purchasedShares;

    /// -----------------------------------------------------------------------
    /// Modifiers
    /// -----------------------------------------------------------------------
    modifier whenSaleActive() {
        if (
            uint40(block.timestamp) < saleStart || uint40(block.timestamp) >= saleEnd || closed
                || canceled || paused
        ) {
            revert SaleInactive();
        }
        _;
    }

    modifier onlyOwner() {
        if (msg.sender != owner) {
            revert NotOwner();
        }
        _;
    }

    constructor(address _owner, FixedERC20Params memory params) {
        if (
            params.shareToken == address(0) || params.assetToken == address(0)
                || params.feeRecipient == address(0)
        ) {
            revert ZeroAddress();
        }
        if (params.saleStart >= params.saleEnd || params.saleEnd > params.redemptionTimestamp) {
            revert InvalidDates();
        }
        if (params.platformFeeWAD >= 1e18 || params.swapFeeWAD >= 1e18) revert InvalidFee();
        if (params.assetsPerToken == 0) revert InvalidPrice();
        if (params.minimumSharesSold > params.sharesForSale) revert MinSharesTooHigh();

        shareToken = params.shareToken;
        assetToken = params.assetToken;
        shareDecimals = IERC20(shareToken).decimals();
        assetDecimals = IERC20(assetToken).decimals();

        if (assetDecimals < 2 || assetDecimals > 18 || shareDecimals > 18) {
            revert InvalidDecimals();
        }

        assetsPerToken = params.assetsPerToken;
        owner = _owner;
        platformFeeWAD = params.platformFeeWAD;
        swapFeeWAD = params.swapFeeWAD;
        feeRecipient = params.feeRecipient;
        saleStart = params.saleStart;
        saleEnd = params.saleEnd;
        redemptionTimestamp = params.redemptionTimestamp;
        sharesForSale = params.sharesForSale;
        userMaximumShares =
            params.userMaximumShares > 0 ? params.userMaximumShares : type(uint256).max;
        minimumSharesSold = params.minimumSharesSold;

        shareToken.safeTransferFrom(owner, address(this), sharesForSale);

        emit SharesDeposited(sharesForSale);
    }

    /// -----------------------------------------------------------------------
    /// Public Write Functions
    /// -----------------------------------------------------------------------

    /// @notice Allows a user to buy shares in the pool with ERC20 assets.
    /// @param shares The number of shares to purchase.
    /// @param recipient The address that will receive the shares once redeemed.
    function buyExactShares(
        uint256 shares,
        address recipient
    )
        external
        nonReentrant
        whenSaleActive
        returns (uint256 assetsIn)
    {
        if (shares == 0) {
            revert TransferZero();
        }
        if (shares + totalSharesSold > sharesForSale) {
            revert SharesOutExceeded();
        }
        if (shares + purchasedShares[recipient] > userMaximumShares) {
            revert UserMaxSharesExceeded();
        }
        if (recipient == address(0)) {
            revert ZeroAddress();
        }

        if (!_isAboveMandatoryMinimum(shares)) {
            revert PurchaseTooLow();
        }

        if (sharesRemaining() - shares < getMandatoryMinimum()) {
            revert InvalidAmount();
        }

        uint256 sharesScaled = scaleTokenBefore(shareDecimals, shares);

        uint256 priceScaled = scaleTokenBefore(assetDecimals, assetsPerToken);

        uint256 assetsInScaled = sharesScaled.mulWad(priceScaled);

        assetsIn = scaleTokenAfter(assetDecimals, assetsInScaled);

        if (assetsIn == 0) {
            revert TransferZero();
        }

        uint256 _swapFees = assetsIn.mulWad(swapFeeWAD);

        totalSharesSold += shares;
        purchasedShares[recipient] += shares;
        swapFees += _swapFees;

        assetsIn = assetsIn.rawAdd(_swapFees);

        assetToken.safeTransferFrom(msg.sender, address(this), assetsIn);

        if (totalSharesSold == sharesForSale) {
            emit PoolCompleted();
        }

        emit BuyFixedShares(recipient, shares, assetsIn);
    }

    /// @notice Allows any user to close the pool and distribute the fees.
    /// @dev The pool can only be closed after the sale end date has passed, OR the max shares sold have been reached.
    function close()
        external
        nonReentrant
        returns (uint256 feesGenerated, uint256 fundsRaised, uint256 sharesNotSold)
    {
        if (!canClose()) {
            revert SaleActive();
        }

        closed = true;

        if (!_minReserveMet()) {
            _handleManagerRefund();
            emit RaiseGoalNotMet(swapFees);
            return (0, 0, 0);
        }
        feesGenerated = IERC20(assetToken).balanceOf(address(this)).rawSub(swapFees).mulWad(
            platformFeeWAD
        ).rawAdd(swapFees);

        if (feesGenerated > 0) {
            assetToken.safeTransfer(feeRecipient, feesGenerated);
        }

        fundsRaised = IERC20(assetToken).balanceOf(address(this));

        if (fundsRaised > 0) {
            assetToken.safeTransfer(owner, fundsRaised);
        }

        sharesNotSold = sharesForSale - totalSharesSold;

        if (sharesNotSold > 0) {
            shareToken.safeTransfer(owner, sharesNotSold);
        }

        emit Closed(fundsRaised, totalSharesSold, feesGenerated.rawSub(swapFees), swapFees);
    }

    /// @notice Allows a user to redeem purchased shares after the redemption date has passed.
    /// @return shares The number of shares redeemed.
    /// @dev If the minReserve has not been met, the user will receive a refund of their assets minus swap fees.
    function redeem() external nonReentrant returns (uint256 shares) {
        if (canceled) {
            revert SaleCancelled();
        }
        if (!closed) {
            revert SaleActive();
        }

        if (uint40(block.timestamp) < _getCorrectRedemptionTimestamp()) {
            revert RedeemedTooEarly();
        }

        if (!_minReserveMet()) {
            uint256 assetsOwed = _handleUserRefund(msg.sender);

            emit Refunded(msg.sender, assetsOwed);
            return 0;
        }

        shares = purchasedShares[msg.sender];
        delete purchasedShares[msg.sender];

        if (shares > 0) {
            shareToken.safeTransfer(msg.sender, shares);
        }
        emit Redeemed(msg.sender, shares);
    }

    /// -----------------------------------------------------------------------
    /// Owner-Only Write Functions
    /// -----------------------------------------------------------------------

    /// @notice Allows the pool creator to pause/unpause the sale, halting/enabling any trading activity.
    function togglePause() external nonReentrant onlyOwner {
        paused = !paused;
        emit PauseToggled(paused);
    }

    /// @notice Allows the pool creator to cancel the sale and withdraw all funds and shares before a sale begins.
    function cancelSale() external nonReentrant onlyOwner {
        if (closed) {
            revert AlreadyClosed();
        }
        if (canceled) {
            revert SaleCancelled();
        }
        if (uint40(block.timestamp) >= saleStart) {
            revert SaleActive();
        }

        canceled = true;
        shareToken.safeTransfer(owner, sharesForSale);
        emit PoolCanceled();
    }

    /// -----------------------------------------------------------------------
    /// Public Read Functions
    /// -----------------------------------------------------------------------

    /// @notice Checks if the pool can be closed.
    /// @return True if the pool can be closed, false otherwise.
    /// @dev The pool can be closed if all shares have been sold, or the sale end date has passed.
    function canClose() public view returns (bool) {
        if (canceled || closed) {
            return false;
        }
        if (totalSharesSold == sharesForSale || uint40(block.timestamp) >= saleEnd) {
            return true;
        }

        return false;
    }

    /// @notice Returns the number of shares remaining for purchase.
    /// @return The number of shares remaining for purchase.
    function sharesRemaining() public view returns (uint256) {
        return sharesForSale - totalSharesSold;
    }

    /// @notice Returns the number of shares remaining for purchase for a specific user.
    /// @param user The address of the user to check.
    /// @return The number of shares remaining for purchase.
    function userSharesRemaining(address user) external view returns (uint256) {
        return userMaximumShares - purchasedShares[user];
    }

    /// @notice Returns all relevant pool data.
    function args() public view returns (PoolArgs memory) {
        return (
            PoolArgs(
                shareToken,
                assetToken,
                owner,
                feeRecipient,
                assetsPerToken,
                sharesForSale,
                minimumSharesSold,
                platformFeeWAD,
                swapFeeWAD,
                saleStart,
                saleEnd,
                _getCorrectRedemptionTimestamp(),
                totalSharesSold,
                closed,
                paused,
                canceled,
                canClose(),
                userMaximumShares,
                getMandatoryMinimum()
            )
        );
    }

    ///@notice Returns the minimum number of shares that must be purchased to ensure the pool is not left with a fractional shares.
    function getMandatoryMinimum() public view returns (uint256) {
        if (shareDecimals > assetDecimals) {
            return 10 ** (shareDecimals - assetDecimals);
        } else {
            return 0;
        }
    }

    /// -----------------------------------------------------------------------
    /// Internal Helper Functions
    /// -----------------------------------------------------------------------

    ///@dev Checks if the amount of shares purchased is above the mandatory minimum.
    function _isAboveMandatoryMinimum(uint256 amount) internal view returns (bool) {
        return amount >= getMandatoryMinimum();
    }

    ///@dev Checks if the minimum reserve is set and whether or not the shares sold surpasses this value.
    function _minReserveMet() internal view returns (bool) {
        if (minimumSharesSold > 0 && totalSharesSold < minimumSharesSold) {
            return false;
        }
        return true;
    }

    ///@dev Returns the correct redemption timestamp based on the sale. adding a limitation of 24 hours if the sale doesn't reach the the goal.
    function _getCorrectRedemptionTimestamp() internal view returns (uint40) {
        if (redemptionTimestamp - saleEnd < 24 hours || _minReserveMet()) {
            return redemptionTimestamp;
        }
        return saleEnd + 24 hours;
    }

    /// @notice Helper function to handle refunding in the case of a minReserve not being met.
    /// @dev Refunds all shares to the owner, and distro's asset swap fees to the platform.
    function _handleManagerRefund() internal {
        uint256 sharesOwed = shareToken.balanceOf(address(this));
        if (sharesOwed > 0) {
            shareToken.safeTransfer(owner, sharesOwed);
        }
        if (swapFees > 0) {
            assetToken.safeTransfer(feeRecipient, swapFees);
        }
    }

    /// @notice Helper function to handle refunding in the case of a minReserve not being met.
    /// @dev Refunds all assets to the purchaser sans swap fees.
    function _handleUserRefund(address sender) internal returns (uint256 assetsOwed) {
        uint256 userShares = purchasedShares[sender];
        purchasedShares[sender] = 0;

        assetsOwed = scaleTokenBefore(shareDecimals, userShares).mulWad(
            scaleTokenBefore(assetDecimals, assetsPerToken)
        );
        assetsOwed = scaleTokenAfter(assetDecimals, assetsOwed);

        if (userShares > 0 && assetsOwed > 0) {
            assetToken.safeTransfer(sender, assetsOwed);
        }
    }

    ///@notice Scales the token amount to 18 decimals based on the token's cached decimal value.
    /// @param decimals The number of decimals the token has.
    /// @param value The value to scale.
    /// @return scaledAmount The token amount scaled to 18 decimals.
    function scaleTokenBefore(
        uint8 decimals,
        uint256 value
    )
        internal
        pure
        returns (uint256 scaledAmount)
    {
        scaledAmount = value;
        if (decimals < 18) {
            uint8 decimalDiff = 18 - decimals;
            scaledAmount *= 10 ** decimalDiff;
        } else if (decimals > 18) {
            uint8 decimalDiff = decimals - 18;
            scaledAmount /= 10 ** decimalDiff;
        }
    }

    ///@notice Scales the token amount from 18 decimals based to the token's cached decimal value.
    /// @param decimals The number of decimals the token has.
    /// @param value The value to scale.
    /// @return scaledAmount The token amount scaled to its native decimals.
    function scaleTokenAfter(
        uint8 decimals,
        uint256 value
    )
        internal
        pure
        returns (uint256 scaledAmount)
    {
        scaledAmount = value;
        if (decimals < 18) {
            uint8 decimalDiff = 18 - decimals;
            scaledAmount /= 10 ** decimalDiff;
        } else if (decimals > 18) {
            uint8 decimalDiff = decimals - 18;
            scaledAmount *= 10 ** decimalDiff;
        }
    }
}

File 4 of 9 : FixedNativePool.sol
//SPDX-License-Identifier: MIT

pragma solidity =0.8.25;

import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol";
import { FixedPointMathLib } from "solady/utils/FixedPointMathLib.sol";
import { ReentrancyGuard } from "solady/utils/ReentrancyGuard.sol";

import "./interfaces/IERC20.sol";
import { IBasePool, FixedNativeParams } from "./interfaces/IBasePool.sol";

/// @title FixedERC2Pool
/// @notice A fixed price pool that allows users to purchase shares with a predefined standard ERC20 token.
/// @notice The pool creator can set the number of shares available for purchase, the price of each share,
/// @notice the sale start and end dates, the redemption date, and the maximum number of shares a user can purchase.
/// @notice The pool creator can also set a minimum number of shares that must be sold for the sale to be considered successful.
/// @notice The pool creator can also set a platform fee and a swap fee that will be taken from the raised funds.
/// @dev Creation will fail if the asset token has less than 2 or more than 18 decimals, or if the share token has more than 18 decimals.
/// @dev The pool will fail if the sale start date is after the sale end date, or if the redemption date is before the sale end date.
/// @dev The pool will fail if the platform fee or swap fee is greater than or equal to 1e18.
/// @dev The pool will fail if the price of each share is 0, or if the minimum number of shares that must be sold is greater than the number of shares available for purchase.
contract FixedNativePool is ReentrancyGuard, IBasePool {
    /// -----------------------------------------------------------------------
    /// Dependencies
    /// -----------------------------------------------------------------------
    using SafeTransferLib for address;
    using FixedPointMathLib for uint256;

    /// -----------------------------------------------------------------------
    /// Immutable State
    /// -----------------------------------------------------------------------
    /// @notice The number of wei required to purchase 1 share.
    uint256 public immutable weiPerToken;
    /// @notice The number of shares available for purchase (with decimals.)
    uint256 public immutable sharesForSale;
    /// @notice The minimum number of shares that must be sold for the sale to be considered successful, else refunds are issuable.
    uint256 public immutable minimumSharesSold;
    /// @notice The fee percentage in WAD (1e18) that will be taken from the raised funds.
    uint256 public immutable platformFeeWAD;
    /// @notice The fee percentage in WAD (1e18) that will be taken from each swap.
    uint256 public immutable swapFeeWAD;
    /// @notice The maximum number of shares (with decimals) a user can purchase per sale.
    uint256 public immutable userMaximumShares;
    /// @notice The address of the pool creator that retains administrative control.
    address public immutable owner;
    /// @notice The address that will receive the fees generated from the raised funds.
    address public immutable feeRecipient;
    /// @notice The address of the ERC20 token that represents the shares.
    address public immutable shareToken;
    /// @notice The timestamp when the sale will begin.
    uint40 public immutable saleStart;
    /// @notice The timestamp when the sale will end.
    uint40 public immutable saleEnd;
    /// @notice The timestamp when the shares can be redeemed.
    uint40 public immutable redemptionTimestamp;
    /// @notice Cached ERC20 asset decimals (always 18 for native tokens)
    uint8 private constant assetDecimals = 18;
    /// @notice Cached ERC20 share decimals
    uint8 private immutable shareDecimals;
    //
    /// -----------------------------------------------------------------------
    /// Mutable Read Functions
    /// -----------------------------------------------------------------------
    /// @notice The total number of shares sold during the sale so far.
    uint256 public totalSharesSold;
    /// @notice The total amount of swap fees generated during the sale.
    uint256 public swapFees;
    /// @notice Returns true if `close` has been called.
    bool public closed;
    /// @notice Returns true if `pause` has been called.
    bool public paused;
    /// @notice Returns true if `cancelSale` has been called.
    bool public canceled;
    /// @notice The number of shares purchased by each user.
    mapping(address => uint256) public purchasedShares;
    /// -----------------------------------------------------------------------
    /// Modifiers
    /// -----------------------------------------------------------------------

    modifier whenSaleActive() {
        if (
            uint40(block.timestamp) < saleStart || uint40(block.timestamp) >= saleEnd || closed
                || paused || canceled
        ) {
            revert SaleInactive();
        }
        _;
    }

    modifier onlyOwner() {
        if (msg.sender != owner) {
            revert NotOwner();
        }
        _;
    }

    constructor(address _owner, FixedNativeParams memory params) {
        if (
            params.shareToken == address(0) || params.feeRecipient == address(0)
                || _owner == address(0)
        ) {
            revert ZeroAddress();
        }
        if (params.saleStart >= params.saleEnd || params.saleEnd > params.redemptionTimestamp) {
            revert InvalidDates();
        }
        if (params.platformFeeWAD >= 1e18 || params.swapFeeWAD >= 1e18) {
            revert InvalidFee();
        }
        if (params.weiPerToken == 0) {
            revert InvalidPrice();
        }
        if (params.minimumSharesSold > params.sharesForSale) {
            revert MinSharesTooHigh();
        }

        shareToken = params.shareToken;

        shareDecimals = IERC20(shareToken).decimals();
        if (shareDecimals > 18) {
            revert InvalidDecimals();
        }

        weiPerToken = params.weiPerToken;
        owner = _owner;
        platformFeeWAD = params.platformFeeWAD;
        swapFeeWAD = params.swapFeeWAD;
        feeRecipient = params.feeRecipient;
        saleStart = params.saleStart;
        saleEnd = params.saleEnd;
        redemptionTimestamp = params.redemptionTimestamp;
        sharesForSale = params.sharesForSale;
        userMaximumShares =
            params.userMaximumShares > 0 ? params.userMaximumShares : type(uint256).max;
        minimumSharesSold = params.minimumSharesSold;

        shareToken.safeTransferFrom(owner, address(this), params.sharesForSale);
        emit SharesDeposited(params.sharesForSale);
    }

    /// -----------------------------------------------------------------------
    /// Public Write Functions
    /// -----------------------------------------------------------------------

    /// @notice Allows a user to buy shares in the pool with native assets.
    /// @param shares The number of shares to purchase.
    /// @param recipient The address that will receive the shares once redeemed.
    function buyExactShares(
        uint256 shares,
        address recipient
    ) external payable nonReentrant whenSaleActive returns (uint256 assetsIn) {
        if (shares == 0 || msg.value == 0) {
            revert TransferZero();
        }

        if (recipient == address(0)) {
            revert ZeroAddress();
        }

        if (shares + totalSharesSold > sharesForSale) {
            revert SharesOutExceeded();
        }
        if (shares + purchasedShares[recipient] > userMaximumShares) {
            revert UserMaxSharesExceeded();
        }

        if (!_isAboveMandatoryMinimum(shares)) {
            revert PurchaseTooLow();
        }

        if (sharesRemaining() - shares < getMandatoryMinimum()) {
            revert InvalidAmount();
        }

        uint256 sharesScaled = scaleTokenBefore(shareDecimals, shares);
        uint256 priceScaled = scaleTokenBefore(18, weiPerToken);

        uint256 assetsInScaled = sharesScaled.mulWad(priceScaled);

        assetsIn = scaleTokenAfter(18, assetsInScaled);

        if (assetsIn == 0) {
            revert TransferZero();
        }

        uint256 _swapFees = assetsIn.mulWad(swapFeeWAD);
        assetsIn = assetsIn.rawAdd(_swapFees);

        if (msg.value < assetsIn) {
            revert InsufficientFunds();
        }

        totalSharesSold += shares;
        purchasedShares[recipient] += shares;
        swapFees += _swapFees;

        if (totalSharesSold == sharesForSale) {
            emit PoolCompleted();
        }

        emit BuyFixedShares(recipient, shares, assetsIn);
    }

    /// @notice Allows any user to close the pool and distribute the fees.
    /// @dev The pool can only be closed after the sale end date has passed, OR the max shares sold have been reached.
    function close()
        external
        nonReentrant
        returns (uint256 feesGenerated, uint256 fundsRaised, uint256 sharesNotSold)
    {
        if (!canClose()) {
            revert SaleActive();
        }

        closed = true;

        if (!_minReserveMet()) {
            _handleManagerRefund();
            emit RaiseGoalNotMet(swapFees);
            return (swapFees, 0, sharesForSale);
        }

        feesGenerated = address(this).balance.rawSub(swapFees).mulWad(platformFeeWAD) + swapFees;

        if (feesGenerated > 0) {
            feeRecipient.safeTransferETH(feesGenerated);
        }

        fundsRaised = address(this).balance;

        if (fundsRaised > 0) {
            owner.forceSafeTransferETH(fundsRaised);
        }

        sharesNotSold = sharesForSale - totalSharesSold;

        if (sharesNotSold > 0) {
            shareToken.safeTransfer(owner, sharesNotSold);
        }

        emit Closed(fundsRaised, totalSharesSold, feesGenerated.rawSub(swapFees), swapFees);
    }

    /// @notice Allows a user to redeem purchased shares after the redemption date has passed.
    /// @return shares The number of shares redeemed.
    /// @dev If the minReserve has not been met, the user will receive a refund of their assets minus swap fees.
    function redeem() external nonReentrant returns (uint256 shares) {
        if (canceled) {
            revert SaleCancelled();
        }
        if (!closed) {
            revert SaleActive();
        }

        if (uint40(block.timestamp) < _getCorrectRedemptionTimestamp()) {
            revert RedeemedTooEarly();
        }

        if (!_minReserveMet()) {
            uint256 assetsOwed = _handleUserRefund(msg.sender);
            emit Refunded(msg.sender, assetsOwed);
            return 0;
        }

        shares = purchasedShares[msg.sender];
        delete purchasedShares[msg.sender];

        if (shares > 0) {
            shareToken.safeTransfer(msg.sender, shares);
        }
        emit Redeemed(msg.sender, shares);
    }

    /// -----------------------------------------------------------------------
    /// Owner-Only Write Functions
    /// -----------------------------------------------------------------------

    /// @notice Allows the pool creator to pause/unpause the sale, halting/enabling any trading activity.
    function togglePause() external nonReentrant onlyOwner {
        paused = !paused;
        emit PauseToggled(paused);
    }

    /// @notice Allows the pool creator to cancel the sale and withdraw all funds and shares before a sale begins.
    function cancelSale() external nonReentrant onlyOwner {
        if (closed) {
            revert AlreadyClosed();
        }
        if (canceled) {
            revert SaleCancelled();
        }
        if (uint40(block.timestamp) >= saleStart) {
            revert SaleActive();
        }

        canceled = true;
        shareToken.safeTransfer(owner, sharesForSale);
        emit PoolCanceled();
    }

    /// -----------------------------------------------------------------------
    /// Public Read Functions
    /// -----------------------------------------------------------------------

    /// @notice Checks if the pool can be closed.
    /// @return True if the pool can be closed, false otherwise.
    /// @dev The pool can be closed if all shares have been sold, or the sale end date has passed.
    function canClose() public view returns (bool) {
        if (canceled || closed) {
            return false;
        }
        if (totalSharesSold == sharesForSale || uint40(block.timestamp) >= saleEnd) {
            return true;
        }

        return false;
    }

    /// @notice Returns the number of shares remaining for purchase.
    /// @return The number of shares remaining for purchase.
    function sharesRemaining() public view returns (uint256) {
        return sharesForSale - totalSharesSold;
    }

    /// @notice Returns the number of shares remaining for purchase for a specific user.
    /// @param user The address of the user to check.
    /// @return The number of shares remaining for purchase.
    function userSharesRemaining(address user) external view returns (uint256) {
        return userMaximumShares - purchasedShares[user];
    }

    /// @notice Returns all relevant pool data.
    function args() public view returns (PoolArgs memory) {
        return
            PoolArgs(
                shareToken,
                address(0),
                owner,
                feeRecipient,
                weiPerToken,
                sharesForSale,
                minimumSharesSold,
                platformFeeWAD,
                swapFeeWAD,
                saleStart,
                saleEnd,
                _getCorrectRedemptionTimestamp(),
                totalSharesSold,
                closed,
                paused,
                canceled,
                canClose(),
                userMaximumShares,
                getMandatoryMinimum()
            );
    }

    ///@notice Returns the minimum number of shares that must be purchased to ensure the pool is not left with a fractional shares.
    function getMandatoryMinimum() public view returns (uint256) {
        if (shareDecimals > assetDecimals) {
            return 10 ** (shareDecimals - assetDecimals);
        } else {
            return 0;
        }
    }

    /// -----------------------------------------------------------------------
    /// Internal Helper Functions
    /// -----------------------------------------------------------------------

    ///@dev Checks if the amount of shares purchased is above the mandatory minimum.
    function _isAboveMandatoryMinimum(uint256 amount) internal view returns (bool) {
        return amount >= getMandatoryMinimum();
    }

    ///@dev Checks if the minimum reserve is set and whether or not the shares sold surpasses this value.
    function _minReserveMet() internal view returns (bool) {
        if (minimumSharesSold > 0 && totalSharesSold < minimumSharesSold) {
            return false;
        }
        return true;
    }

    ///@dev Returns the correct redemption timestamp based on the sale. adding a limitation of 24 hours if the sale doesn't reach the the goal.
    function _getCorrectRedemptionTimestamp() internal view returns (uint40) {
        if (redemptionTimestamp - saleEnd < 24 hours || _minReserveMet()) {
            return redemptionTimestamp;
        }
        return saleEnd + 24 hours;
    }

    /// @notice Helper function to handle refunding in the case of a minReserve not being met.
    /// @dev Refunds all shares to the owner, and distro's asset swap fees to the platform.
    function _handleManagerRefund() internal {
        uint256 sharesOwed = shareToken.balanceOf(address(this));
        if (sharesOwed > 0) {
            shareToken.safeTransfer(owner, sharesOwed);
        }
        if (swapFees > 0) {
            feeRecipient.safeTransferETH(swapFees);
        }
    }

    /// @notice Helper function to handle refunding in the case of a minReserve not being met.
    /// @dev Refunds all assets to the purchaser sans swap fees.
    function _handleUserRefund(address sender) internal returns (uint256 assetsOwed) {
        uint256 userShares =
            scaleTokenBefore(shareDecimals, purchasedShares[sender]).mulWad(weiPerToken);

        purchasedShares[sender] = 0;
        assetsOwed = userShares.mulWad(weiPerToken);

        if (userShares > 0 && assetsOwed > 0) {
            sender.safeTransferETH(assetsOwed);
        }
    }

    ///@notice Scales the token amount to 18 decimals based on the token's cached decimal value.
    /// @param decimals The number of decimals the token has.
    /// @param value The value to scale.
    /// @return scaledAmount The token amount scaled to 18 decimals.
    function scaleTokenBefore(
        uint8 decimals,
        uint256 value
    )
        internal
        pure
        returns (uint256 scaledAmount)
    {
        scaledAmount = value;
        if (decimals < 18) {
            uint8 decimalDiff = 18 - decimals;
            scaledAmount *= 10 ** decimalDiff;
        } else if (decimals > 18) {
            uint8 decimalDiff = decimals - 18;
            scaledAmount /= 10 ** decimalDiff;
        }
    }

    ///@notice Scales the token amount from 18 decimals based to the token's cached decimal value.
    /// @param decimals The number of decimals the token has.
    /// @param value The value to scale.
    /// @return scaledAmount The token amount scaled to its native decimals.
    function scaleTokenAfter(
        uint8 decimals,
        uint256 value
    )
        internal
        pure
        returns (uint256 scaledAmount)
    {
        scaledAmount = value;
        if (decimals < 18) {
            uint8 decimalDiff = 18 - decimals;
            scaledAmount /= 10 ** decimalDiff;
        } else if (decimals > 18) {
            uint8 decimalDiff = decimals - 18;
            scaledAmount *= 10 ** decimalDiff;
        }
    }
}

File 5 of 9 : IBasePool.sol
//SPDX-License-Identifier: MIT

pragma solidity =0.8.25;

struct FixedNativeParams {
    address shareToken;
    uint256 weiPerToken;
    uint256 sharesForSale;
    uint256 minimumSharesSold;
    uint256 userMaximumShares;
    address feeRecipient;
    uint256 platformFeeWAD;
    uint256 swapFeeWAD;
    uint40 saleStart;
    uint40 saleEnd;
    uint40 redemptionTimestamp;
}

struct FixedERC20Params {
    address shareToken;
    address assetToken;
    uint256 assetsPerToken;
    uint256 sharesForSale;
    uint256 minimumSharesSold;
    uint256 userMaximumShares;
    address feeRecipient;
    uint256 platformFeeWAD;
    uint256 swapFeeWAD;
    uint40 saleStart;
    uint40 saleEnd;
    uint40 redemptionTimestamp;
}

interface IBasePool {
    struct PoolArgs {
        address shareToken;
        address assetToken;
        address owner;
        address feeRecipient;
        uint256 assetsPerToken;
        uint256 sharesForSale;
        uint256 minimumSharesSold;
        uint256 platformFeeWAD;
        uint256 swapFeeWAD;
        uint40 saleStart;
        uint40 saleEnd;
        uint40 redemptionTimestamp;
        uint256 totalSharesSold;
        bool closed;
        bool paused;
        bool canceled;
        bool canClose;
        uint256 userMaximumShares;
        uint256 minimumPurchaseAmount;
    }

    error InsufficientFunds();
    error SaleInactive();
    error AlreadyClosed();
    error InvalidDates();
    error SaleActive();
    error InvalidFee();
    error ZeroAddress();
    error SharesOutExceeded();
    error NotOwner();
    error RedeemedTooEarly();
    error AlreadyDeposited();
    error TransferZero();
    error UserMaxSharesExceeded();
    error SaleCancelled();
    error PurchaseTooLow();
    error InvalidAmount();
    error MinSharesTooHigh();
    error InvalidDecimals();
    error InvalidPrice();

    event BuyFixedShares(address indexed recipient, uint256 sharesOut, uint256 assetsIn);
    event SharesDeposited(uint256 amount);
    event PauseToggled(bool paused);
    event Closed(
        uint256 totalFundsRaised, uint256 totalSharesSold, uint256 platformFee, uint256 swapFee
    );
    event RaiseGoalNotMet(uint256 swapFees);
    event Redeemed(address indexed recipient, uint256 shares);
    event PoolCanceled();
    event PoolCompleted();
    event Refunded(address indexed recipient, uint256 amount);
}

File 6 of 9 : SafeTransferLib.sol
// 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)
            }
        }
    }
}

File 7 of 9 : FixedPointMathLib.sol
// 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)`.
    /// Note: This function is an approximation.
    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
    /// Note: This function is an approximation. Monotonically increasing.
    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
    /// Note: This function is an approximation. Monotonically increasing.
    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.
    /// Note: This function is an approximation. Monotonically increasing.
    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 (uint256(w >> 63) == uint256(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 == uint256(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 != uint256(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 == uint256(0)) return w;
            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 {
            // 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`.

            // Temporarily use `result` as `p0` to save gas.
            result := mul(x, y) // Lower 256 bits of `x * y`.
            for {} 1 {} {
                // If overflows.
                if iszero(mul(or(iszero(x), eq(div(result, x), y)), d)) {
                    let mm := mulmod(x, y, not(0))
                    let p1 := sub(mm, add(result, lt(mm, result))) // Upper 256 bits of `x * y`.

                    /*------------------- 512 by 256 division --------------------*/

                    // Make division exact by subtracting the remainder from `[p1 p0]`.
                    let r := mulmod(x, y, d) // Compute remainder using mulmod.
                    let t := and(d, sub(0, d)) // The least significant bit of `d`. `t >= 1`.
                    // Make sure the result is less than `2**256`. Also prevents `d == 0`.
                    // Placing the check here seems to give more optimal stack operations.
                    if iszero(gt(d, p1)) {
                        mstore(0x00, 0xae47f702) // `FullMulDivFailed()`.
                        revert(0x1c, 0x04)
                    }
                    d := div(d, t) // Divide `d` by `t`, which is a power of two.
                    // 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)
                            ),
                            mul(sub(2, mul(d, inv)), inv) // inverse mod 2**256
                        )
                    break
                }
                result := div(result, d)
                break
            }
        }
    }

    /// @dev Calculates `floor(x * y / d)` with full precision.
    /// Behavior is undefined if `d` is zero or the final result cannot fit in 256 bits.
    /// Performs the full 512 bit calculation regardless.
    function fullMulDivUnchecked(uint256 x, uint256 y, uint256 d)
        internal
        pure
        returns (uint256 result)
    {
        /// @solidity memory-safe-assembly
        assembly {
            result := mul(x, y)
            let mm := mulmod(x, y, not(0))
            let p1 := sub(mm, add(result, lt(mm, result)))
            let t := and(d, sub(0, d))
            let r := mulmod(x, y, d)
            d := div(d, t)
            let inv := xor(2, mul(3, d))
            inv := mul(inv, sub(2, mul(d, inv)))
            inv := mul(inv, sub(2, mul(d, inv)))
            inv := mul(inv, sub(2, mul(d, inv)))
            inv := mul(inv, sub(2, mul(d, inv)))
            inv := mul(inv, sub(2, mul(d, inv)))
            result :=
                mul(
                    or(mul(sub(p1, gt(r, result)), add(div(sub(0, t), t), 1)), div(sub(result, r), t)),
                    mul(sub(2, mul(d, inv)), inv)
                )
        }
    }

    /// @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 {
            z := mul(x, y)
            // Equivalent to `require(d != 0 && (y == 0 || x <= type(uint256).max / y))`.
            if iszero(mul(or(iszero(x), eq(div(z, x), y)), d)) {
                mstore(0x00, 0xad251c27) // `MulDivFailed()`.
                revert(0x1c, 0x04)
            }
            z := div(z, 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 {
            z := mul(x, y)
            // Equivalent to `require(d != 0 && (y == 0 || x <= type(uint256).max / y))`.
            if iszero(mul(or(iszero(x), eq(div(z, x), y)), d)) {
                mstore(0x00, 0xad251c27) // `MulDivFailed()`.
                revert(0x1c, 0x04)
            }
            z := add(iszero(iszero(mod(z, d))), div(z, 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 Returns `condition ? x : y`, without branching.
    function ternary(bool condition, uint256 x, uint256 y) internal pure returns (uint256 result) {
        /// @solidity memory-safe-assembly
        assembly {
            result := xor(x, mul(xor(x, y), iszero(condition)))
        }
    }

    /// @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 x {
                                mstore(0x00, 0x49f7642b) // `RPowOverflow()`.
                                revert(0x1c, 0x04)
                            }
                        }
                        z := div(zxRound, b) // Return properly scaled `zxRound`.
                    }
                }
            }
        }
    }

    /// @dev Returns the square root of `x`, rounded down.
    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`, rounded down.
    /// 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`, rounded down.
    function sqrtWad(uint256 x) internal pure returns (uint256 z) {
        unchecked {
            if (x <= type(uint256).max / 10 ** 18) return sqrt(x * 10 ** 18);
            z = (1 + sqrt(x)) * 10 ** 9;
            z = (fullMulDivUnchecked(x, 10 ** 18, z) + z) >> 1;
        }
        /// @solidity memory-safe-assembly
        assembly {
            z := sub(z, gt(999999999999999999, sub(mulmod(z, z, x), 1)))
        }
    }

    /// @dev Returns the cube root of `x`, denominated in `WAD`, rounded down.
    function cbrtWad(uint256 x) internal pure returns (uint256 z) {
        unchecked {
            if (x <= type(uint256).max / 10 ** 36) return cbrt(x * 10 ** 36);
            z = (1 + cbrt(x)) * 10 ** 12;
            z = (fullMulDivUnchecked(x, 10 ** 36, z * z) + z + z) / 3;
            uint256 t = fullMulDivUnchecked(x, 10 ** 36, z * z);
            /// @solidity memory-safe-assembly
            assembly {
                z := sub(z, lt(t, z))
            }
        }
    }

    /// @dev Returns the factorial of `x`.
    function factorial(uint256 x) internal pure returns (uint256 result) {
        /// @solidity memory-safe-assembly
        assembly {
            result := 1
            if iszero(lt(x, 58)) {
                mstore(0x00, 0xaba0f2a2) // `FactorialOverflow()`.
                revert(0x1c, 0x04)
            }
            for {} 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`. Rounds towards zero.
    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`. Rounds towards negative infinity.
    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(uint256 x, uint256 y) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := xor(mul(xor(sub(y, x), sub(x, y)), gt(x, y)), sub(y, 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
            }
        }
    }

    /// @dev Returns `a + (b - a) * (t - begin) / (end - begin)`,
    /// with `t` clamped between `begin` and `end` (inclusive).
    /// Agnostic to the order of (`a`, `b`) and (`end`, `begin`).
    /// Reverts if `begin` equals `end` (due to division by zero).
    function lerp(uint256 a, uint256 b, uint256 t, uint256 begin, uint256 end)
        internal
        pure
        returns (uint256)
    {
        if (begin >= end) {
            t = ~t;
            begin = ~begin;
            end = ~end;
        }
        if (t <= begin) return a;
        if (t >= end) return b;
        unchecked {
            if (b >= a) return a + fullMulDiv(b - a, t - begin, end - begin);
            return a - fullMulDiv(a - b, t - begin, end - begin);
        }
    }

    /// @dev Returns `a + (b - a) * (t - begin) / (end - begin)`.
    /// with `t` clamped between `begin` and `end` (inclusive).
    /// Agnostic to the order of (`a`, `b`) and (`end`, `begin`).
    /// Reverts if `begin` equals `end` (due to division by zero).
    function lerp(int256 a, int256 b, int256 t, int256 begin, int256 end)
        internal
        pure
        returns (int256)
    {
        if (begin >= end) {
            t = int256(~uint256(t));
            begin = int256(~uint256(begin));
            end = int256(~uint256(end));
        }
        if (t <= begin) return a;
        if (t >= end) return b;
        // forgefmt: disable-next-item
        unchecked {
            if (b >= a) return int256(uint256(a) + fullMulDiv(uint256(b) - uint256(a),
                uint256(t) - uint256(begin), uint256(end) - uint256(begin)));
            return int256(uint256(a) - fullMulDiv(uint256(a) - uint256(b),
                uint256(t) - uint256(begin), uint256(end) - uint256(begin)));
        }
    }

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                   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)
        }
    }
}

File 8 of 9 : ReentrancyGuard.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

/// @notice Reentrancy guard mixin.
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/ReentrancyGuard.sol)
abstract contract ReentrancyGuard {
    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                       CUSTOM ERRORS                        */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Unauthorized reentrant call.
    error Reentrancy();

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                          STORAGE                           */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Equivalent to: `uint72(bytes9(keccak256("_REENTRANCY_GUARD_SLOT")))`.
    /// 9 bytes is large enough to avoid collisions with lower slots,
    /// but not too large to result in excessive bytecode bloat.
    uint256 private constant _REENTRANCY_GUARD_SLOT = 0x929eee149b4bd21268;

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                      REENTRANCY GUARD                      */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Guards a function from reentrancy.
    modifier nonReentrant() virtual {
        /// @solidity memory-safe-assembly
        assembly {
            if eq(sload(_REENTRANCY_GUARD_SLOT), address()) {
                mstore(0x00, 0xab143c06) // `Reentrancy()`.
                revert(0x1c, 0x04)
            }
            sstore(_REENTRANCY_GUARD_SLOT, address())
        }
        _;
        /// @solidity memory-safe-assembly
        assembly {
            sstore(_REENTRANCY_GUARD_SLOT, codesize())
        }
    }

    /// @dev Guards a view function from read-only reentrancy.
    modifier nonReadReentrant() virtual {
        /// @solidity memory-safe-assembly
        assembly {
            if eq(sload(_REENTRANCY_GUARD_SLOT), address()) {
                mstore(0x00, 0xab143c06) // `Reentrancy()`.
                revert(0x1c, 0x04)
            }
        }
        _;
    }
}

File 9 of 9 : IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)

pragma solidity =0.8.25;

/**
 * @dev Interface of the ERC-20 standard as defined in the ERC.
 */
interface IERC20 {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);

    /**
     * @dev Returns the value of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the value of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves a `value` amount of tokens from the caller's account to `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, uint256 value) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
     * caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the
     * allowance mechanism. `value` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address from, address to, uint256 value) external returns (bool);

    function decimals() external view returns (uint8);
}

Settings
{
  "remappings": [
    "forge-std/=lib/forge-std/src/",
    "solady/=lib/solady/src/"
  ],
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "metadata": {
    "useLiteralContent": false,
    "bytecodeHash": "ipfs",
    "appendCBOR": true
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "evmVersion": "paris",
  "viaIR": false,
  "libraries": {}
}

Contract ABI

[{"inputs":[],"name":"PoolCreationFailed","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"poolAddress","type":"address"},{"indexed":false,"internalType":"enum FixedPriceFactory.PoolType","name":"poolType","type":"uint8"}],"name":"PoolCreated","type":"event"},{"inputs":[{"components":[{"internalType":"address","name":"shareToken","type":"address"},{"internalType":"address","name":"assetToken","type":"address"},{"internalType":"uint256","name":"assetsPerToken","type":"uint256"},{"internalType":"uint256","name":"sharesForSale","type":"uint256"},{"internalType":"uint256","name":"minimumSharesSold","type":"uint256"},{"internalType":"uint256","name":"userMaximumShares","type":"uint256"},{"internalType":"address","name":"feeRecipient","type":"address"},{"internalType":"uint256","name":"platformFeeWAD","type":"uint256"},{"internalType":"uint256","name":"swapFeeWAD","type":"uint256"},{"internalType":"uint40","name":"saleStart","type":"uint40"},{"internalType":"uint40","name":"saleEnd","type":"uint40"},{"internalType":"uint40","name":"redemptionTimestamp","type":"uint40"}],"internalType":"struct FixedERC20Params","name":"params","type":"tuple"}],"name":"createFixedERC20","outputs":[{"internalType":"address","name":"pool","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"shareToken","type":"address"},{"internalType":"uint256","name":"weiPerToken","type":"uint256"},{"internalType":"uint256","name":"sharesForSale","type":"uint256"},{"internalType":"uint256","name":"minimumSharesSold","type":"uint256"},{"internalType":"uint256","name":"userMaximumShares","type":"uint256"},{"internalType":"address","name":"feeRecipient","type":"address"},{"internalType":"uint256","name":"platformFeeWAD","type":"uint256"},{"internalType":"uint256","name":"swapFeeWAD","type":"uint256"},{"internalType":"uint40","name":"saleStart","type":"uint40"},{"internalType":"uint40","name":"saleEnd","type":"uint40"},{"internalType":"uint40","name":"redemptionTimestamp","type":"uint40"}],"internalType":"struct FixedNativeParams","name":"params","type":"tuple"}],"name":"createFixedNative","outputs":[{"internalType":"address","name":"pool","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_sender","type":"address"},{"components":[{"internalType":"address","name":"shareToken","type":"address"},{"internalType":"address","name":"assetToken","type":"address"},{"internalType":"uint256","name":"assetsPerToken","type":"uint256"},{"internalType":"uint256","name":"sharesForSale","type":"uint256"},{"internalType":"uint256","name":"minimumSharesSold","type":"uint256"},{"internalType":"uint256","name":"userMaximumShares","type":"uint256"},{"internalType":"address","name":"feeRecipient","type":"address"},{"internalType":"uint256","name":"platformFeeWAD","type":"uint256"},{"internalType":"uint256","name":"swapFeeWAD","type":"uint256"},{"internalType":"uint40","name":"saleStart","type":"uint40"},{"internalType":"uint40","name":"saleEnd","type":"uint40"},{"internalType":"uint40","name":"redemptionTimestamp","type":"uint40"}],"internalType":"struct FixedERC20Params","name":"params","type":"tuple"}],"name":"getFixedERC20Address","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_sender","type":"address"},{"components":[{"internalType":"address","name":"shareToken","type":"address"},{"internalType":"uint256","name":"weiPerToken","type":"uint256"},{"internalType":"uint256","name":"sharesForSale","type":"uint256"},{"internalType":"uint256","name":"minimumSharesSold","type":"uint256"},{"internalType":"uint256","name":"userMaximumShares","type":"uint256"},{"internalType":"address","name":"feeRecipient","type":"address"},{"internalType":"uint256","name":"platformFeeWAD","type":"uint256"},{"internalType":"uint256","name":"swapFeeWAD","type":"uint256"},{"internalType":"uint40","name":"saleStart","type":"uint40"},{"internalType":"uint40","name":"saleEnd","type":"uint40"},{"internalType":"uint40","name":"redemptionTimestamp","type":"uint40"}],"internalType":"struct FixedNativeParams","name":"params","type":"tuple"}],"name":"getFixedNativeAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"}]

6080604052348015600f57600080fd5b506154bb8061001f6000396000f3fe608060405234801561001057600080fd5b506004361061004c5760003560e01c8063178cb7b0146100515780633cad498a146100805780636c5817a6146100935780639c19ed02146100a6575b600080fd5b61006461005f366004610579565b6100b9565b6040516001600160a01b03909116815260200160405180910390f35b61006461008e36600461063d565b61016e565b6100646100a1366004610672565b6101ad565b6100646100b436600461068f565b61024b565b60008033836040516020016100cf9291906106bb565b6040516020818303038152906040528051906020012090506100fd6100f43385610261565b829060006102d5565b91506001600160a01b038216610126576040516337200b1d60e21b815260040160405180910390fd5b816001600160a01b03167f7c3072652d5407e4dcbe90ac1760509311e2511e531f5caf91859f3bc741670860016040516101609190610797565b60405180910390a250919050565b60008083836040516020016101849291906107bf565b6040516020818303038152906040528051906020012090506101a581610356565b949350505050565b60008033836040516020016101c39291906107bf565b6040516020818303038152906040528051906020012090506101e86100f43385610368565b91506001600160a01b038216610211576040516337200b1d60e21b815260040160405180910390fd5b816001600160a01b03167f7c3072652d5407e4dcbe90ac1760509311e2511e531f5caf91859f3bc741670860006040516101609190610797565b60008083836040516020016101849291906106bb565b606060006040518060200161027590610400565b6020820181038252601f19601f82011660405250905080848460405160200161029f9291906106bb565b60408051601f19818403018152908290526102bd92916020016108b1565b60405160208183030381529060405291505092915050565b60006f67363d3d37363d34f03d5260086018f3600052836010806000f5806103055763301164256000526004601cfd5b8060145261d69460005260016034536017601e20915060008085516020870186855af161033a576319b991a86000526004601cfd5b50803b61034f576319b991a86000526004601cfd5b9392505050565b600061036282306103a6565b92915050565b606060006040518060200161037c9061040d565b6020820181038252601f19601f82011660405250905080848460405160200161029f9291906107bf565b60006040518260005260ff600b53836020527f21c35dbe1b344a2488cf3321d6ce542f8e9f305544ff09e4993a62319a497c1f6040526055600b20601452806040525061d694600052600160345350506017601e20919050565b6126f8806108c783390190565b6124c780612fbf83390190565b604051610180810167ffffffffffffffff8111828210171561044c57634e487b7160e01b600052604160045260246000fd5b60405290565b604051610160810167ffffffffffffffff8111828210171561044c57634e487b7160e01b600052604160045260246000fd5b80356001600160a01b038116811461049b57600080fd5b919050565b803564ffffffffff8116811461049b57600080fd5b600061018082840312156104c857600080fd5b6104d061041a565b90506104db82610484565b81526104e960208301610484565b602082015260408201356040820152606082013560608201526080820135608082015260a082013560a082015261052260c08301610484565b60c082015260e082013560e082015261010080830135818301525061012061054b8184016104a0565b9082015261014061055d8382016104a0565b9082015261016061056f8382016104a0565b9082015292915050565b6000610180828403121561058c57600080fd5b61034f83836104b5565b600061016082840312156105a957600080fd5b6105b1610452565b90506105bc82610484565b8152602082013560208201526040820135604082015260608201356060820152608082013560808201526105f260a08301610484565b60a082015260c082013560c082015260e082013560e08201526101006106198184016104a0565b9082015261012061062b8382016104a0565b9082015261014061056f8382016104a0565b600080610180838503121561065157600080fd5b61065a83610484565b91506106698460208501610596565b90509250929050565b6000610160828403121561068557600080fd5b61034f8383610596565b6000806101a083850312156106a357600080fd5b6106ac83610484565b915061066984602085016104b5565b6001600160a01b03838116825282511660208201526101a0810160208301516001600160a01b0381166040840152506040830151606083015260608301516080830152608083015160a083015260a083015160c083015260c083015161072c60e08401826001600160a01b03169052565b5060e083015161010083810191909152830151610120808401919091528301516101406107618185018364ffffffffff169052565b840151905061016061077b8482018364ffffffffff169052565b84015164ffffffffff811661018085015290505b509392505050565b60208101600283106107b957634e487b7160e01b600052602160045260246000fd5b91905290565b6001600160a01b03838116825282511660208201526101808101602083015160408301526040830151606083015260608301516080830152608083015160a083015260a083015161081b60c08401826001600160a01b03169052565b5060c083015160e083015260e083015161010081818501528085015191505061012061084f8185018364ffffffffff169052565b84015190506101406108698482018364ffffffffff169052565b84015164ffffffffff8116610160850152905061078f565b6000815160005b818110156108a25760208185018101518683015201610888565b50600093019283525090919050565b60006101a56108c08386610881565b8461088156fe61026060405234801561001157600080fd5b506040516126f83803806126f883398101604081905261003091610460565b80516001600160a01b03161580610052575060208101516001600160a01b0316155b80610068575060c08101516001600160a01b0316155b156100865760405163d92e233d60e01b815260040160405180910390fd5b80610140015164ffffffffff1681610120015164ffffffffff161015806100c4575080610160015164ffffffffff1681610140015164ffffffffff16115b156100e25760405163364dd21b60e21b815260040160405180910390fd5b670de0b6b3a76400008160e0015110158061010a5750670de0b6b3a764000081610100015110155b15610128576040516358d620b360e01b815260040160405180910390fd5b806040015160000361014c5760405162bfc92160e01b815260040160405180910390fd5b80606001518160800151111561017557604051639c7de60360e01b815260040160405180910390fd5b80516001600160a01b039081166101808190526020808401519092166101a0526040805163313ce56760e01b81529051919263313ce567926004808401938290030181865afa1580156101cc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101f0919061054e565b60ff166102408160ff16815250506101a0516001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa15801561023f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610263919061054e565b60ff1661022081905260021180610280575060126102205160ff16115b80610291575060126102405160ff16115b156102af57604051630692acc560e51b815260040160405180910390fd5b60408101516080526001600160a01b0380831661014090815260e080840151905261010080840151905260c083015190911661016090815261012083015164ffffffffff9081166101c0529183015182166101e0528201511661020052606081015160a09081528101516103255760001961032b565b8060a001515b61012052608081015160c0526101405160a05161018051610359926001600160a01b0390911691309061039b565b7f6b9e4c2de0a9dd9c71d8102a31b5460936ff4259a4119802a01823a727b95c7260a05160405161038c91815260200190565b60405180910390a15050610578565b60405181606052826040528360601b602c526f23b872dd000000000000000000000000600c52602060006064601c6000895af13d1560016000511417166103ea57637939f4246000526004601cfd5b600060605260405250505050565b80516001600160a01b038116811461040f57600080fd5b919050565b60405161018081016001600160401b038111828210171561044557634e487b7160e01b600052604160045260246000fd5b60405290565b805164ffffffffff8116811461040f57600080fd5b6000808284036101a081121561047557600080fd5b61047e846103f8565b925061018080601f198301121561049457600080fd5b61049c610414565b91506104aa602086016103f8565b82526104b8604086016103f8565b6020830152606085015160408301526080850151606083015260a0850151608083015260c085015160a08301526104f160e086016103f8565b60c08301526101008086015160e08401526101208087015182850152610140915061051d82880161044b565b9084015261016061052f87820161044b565b8285015261053e83880161044b565b9084015250929590945092505050565b60006020828403121561056057600080fd5b815160ff8116811461057157600080fd5b9392505050565b60805160a05160c05160e05161010051610120516101405161016051610180516101a0516101c0516101e051610200516102205161024051611f1c6107dc60003960008181610e1e01528181610e6c015281816111cb0152611965015260008181610dfa01528181610e4b015281816111f9015281816112530152818161191b01526119910152600081816102520152818161186401526118a601526000818161049d01528181610b2601528181610fe90152818161162b0152818161184301526118cd01526000818161046501528181610af901528181610fb201526114cf0152600081816101d901528181610624015281816106b20152818161070e01528181610796015281816109ae0152818161132e0152818161177401526119da0152600081816104060152818161081f0152818161097f01528181610d8a01528181611539015281816116d90152611714015260008181610371015281816106d401528181610a0c0152611797015260008181610436015281816107b801528181610841015281816109dd01528181610ed7015281816114410152818161155b015261173601526000818161021d01528181610baa01528181610bfc01526110f401526000818161028f01528181610ad301526112a30152600081816102b6015281816105f40152610aad01526000818161034a01528181610a870152818161166c0152611695015260008181610300015281816107e601528181610a6101528181610c300152818161108d015281816113600152818161157c01526116000152600081816103df01528181610a3b0152818161121a015261193c0152611f1c6000f3fe608060405234801561001057600080fd5b50600436106101cf5760003560e01c80636b71809a11610104578063be040fb0116100a2578063c669c07811610071578063c669c078146104d1578063e7e10490146104e4578063f12723e6146104ec578063f7049d781461050c57600080fd5b8063be040fb014610490578063c10b935814610498578063c20ed671146104bf578063c4ae3168146104c757600080fd5b80638da5cb5b116100de5780638da5cb5b14610431578063aaa30c9714610458578063ab0bcc4114610460578063b9ccf21d1461048757600080fd5b80636b71809a146103da5780636c9fa59e1461040157806373aff5af1461042857600080fd5b806343d726d6116101715780634e9b75b61161014b5780634e9b75b6146103935780635249cc52146103a8578063597e1fb5146103bb5780635c975abb146103c857600080fd5b806343d726d6146103225780634415c60e14610345578063469048401461036c57600080fd5b80631f2f2e1b116101ad5780631f2f2e1b1461028a5780631f7d8c4a146102b15780633f9942ff146102d857806342c22ff1146102fb57600080fd5b80631083f761146101d457806319f76c18146102185780631b2354371461024d575b600080fd5b6101fb7f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b0390911681526020015b60405180910390f35b61023f7f000000000000000000000000000000000000000000000000000000000000000081565b60405190815260200161020f565b6102747f000000000000000000000000000000000000000000000000000000000000000081565b60405164ffffffffff909116815260200161020f565b61023f7f000000000000000000000000000000000000000000000000000000000000000081565b61023f7f000000000000000000000000000000000000000000000000000000000000000081565b6002546102eb9062010000900460ff1681565b604051901515815260200161020f565b61023f7f000000000000000000000000000000000000000000000000000000000000000081565b61032a610514565b6040805193845260208401929092529082015260600161020f565b61023f7f000000000000000000000000000000000000000000000000000000000000000081565b6101fb7f000000000000000000000000000000000000000000000000000000000000000081565b61039b6108d8565b60405161020f9190611b6c565b61023f6103b6366004611cbb565b610bdd565b6002546102eb9060ff1681565b6002546102eb90610100900460ff1681565b61023f7f000000000000000000000000000000000000000000000000000000000000000081565b6101fb7f000000000000000000000000000000000000000000000000000000000000000081565b61023f60005481565b6101fb7f000000000000000000000000000000000000000000000000000000000000000081565b61023f610c26565b6102747f000000000000000000000000000000000000000000000000000000000000000081565b61023f60015481565b61023f610c59565b6102747f000000000000000000000000000000000000000000000000000000000000000081565b61023f610df6565b6104cf610ea1565b005b61023f6104df366004611cdd565b610f83565b6104cf61140b565b61023f6104fa366004611cbb565b60036020526000908152604090205481565b6102eb6115d7565b60008060003068929eee149b4bd2126854036105385763ab143c066000526004601cfd5b3068929eee149b4bd212685561054c6115d7565b6105695760405163f1d2165f60e01b815260040160405180910390fd5b6002805460ff1916600117905561057e611667565b6105d35761058a6116ca565b7f80bc0863d90c6c8fac9104e99d78f2aa8d867a4474dbb8bdbc32ba9d84c1c4e36001546040516105bd91815260200190565b60405180910390a15060009150819050806108c7565b6001546040516370a0823160e01b815230600482015261069d9190610699907f0000000000000000000000000000000000000000000000000000000000000000906106939084906001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016906370a0823190602401602060405180830381865afa15801561066b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061068f9190611d09565b0390565b906117c4565b0190565b925082156106f9576106f96001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000167f0000000000000000000000000000000000000000000000000000000000000000856117f2565b6040516370a0823160e01b81523060048201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906370a0823190602401602060405180830381865afa15801561075d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107819190611d09565b915081156107dd576107dd6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000167f0000000000000000000000000000000000000000000000000000000000000000846117f2565b60005461080a907f0000000000000000000000000000000000000000000000000000000000000000611d38565b90508015610866576108666001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000167f0000000000000000000000000000000000000000000000000000000000000000836117f2565b7ff24c64885f2398a320c41d4eb1531c9b2440ba4e78edfc733536609a4a2a1b1b826000546108a0600154876117bf90919063ffffffff16565b60015460408051948552602085019390935291830152606082015260800160405180910390a15b3868929eee149b4bd2126855909192565b6040805161026081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e08101829052610100810182905261012081018290526101408101829052610160810182905261018081018290526101a081018290526101c081018290526101e08101829052610200810182905261022081018290526102408101919091526040518061026001604052807f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031681526020017f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031681526020017f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031681526020017f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031681526020017f000000000000000000000000000000000000000000000000000000000000000081526020017f000000000000000000000000000000000000000000000000000000000000000081526020017f000000000000000000000000000000000000000000000000000000000000000081526020017f000000000000000000000000000000000000000000000000000000000000000081526020017f000000000000000000000000000000000000000000000000000000000000000081526020017f000000000000000000000000000000000000000000000000000000000000000064ffffffffff1681526020017f000000000000000000000000000000000000000000000000000000000000000064ffffffffff168152602001610b59611838565b64ffffffffff168152600054602082015260025460ff80821615156040840152610100820481161515606084015262010000909104161515608082015260a001610ba16115d7565b151581526020017f00000000000000000000000000000000000000000000000000000000000000008152602001610bd6610df6565b9052919050565b6001600160a01b038116600090815260036020526040812054610c20907f0000000000000000000000000000000000000000000000000000000000000000611d38565b92915050565b60008054610c54907f0000000000000000000000000000000000000000000000000000000000000000611d38565b905090565b60003068929eee149b4bd212685403610c7a5763ab143c066000526004601cfd5b3068929eee149b4bd212685560025462010000900460ff1615610cb0576040516338384cc160e21b815260040160405180910390fd5b60025460ff16610cd35760405163f1d2165f60e01b815260040160405180910390fd5b610cdb611838565b64ffffffffff164264ffffffffff161015610d09576040516312dbbce560e01b815260040160405180910390fd5b610d11611667565b610d62576000610d20336118f5565b60405181815290915033907fd7dee2702d63ad89917b6a4da9981c90c4d24f8c2bdfd64c604ecae57d8d06519060200160405180910390a26000915050610de7565b5033600090815260036020526040812080549190558015610db157610db16001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001633836117f2565b60405181815233907f4896181ff8f4543cc00db9fe9b6fb7e6f032b7eb772c72ab1ec1b4d2e03b93699060200160405180910390a25b3868929eee149b4bd212685590565b60007f000000000000000000000000000000000000000000000000000000000000000060ff167f000000000000000000000000000000000000000000000000000000000000000060ff161115610e9b57610e907f00000000000000000000000000000000000000000000000000000000000000007f0000000000000000000000000000000000000000000000000000000000000000611d4b565b610c5490600a611e48565b50600090565b3068929eee149b4bd212685403610ec05763ab143c066000526004601cfd5b3068929eee149b4bd2126855336001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001614610f15576040516330cd747160e01b815260040160405180910390fd5b6002805460ff610100808304821615810261ff001990931692909217928390556040517f9077d36bc00859b5c3f320310707208543dd35092cb0a0fe117d0c6a558b148b93610f6d9390049091161515815260200190565b60405180910390a13868929eee149b4bd2126855565b60003068929eee149b4bd212685403610fa45763ab143c066000526004601cfd5b3068929eee149b4bd21268557f000000000000000000000000000000000000000000000000000000000000000064ffffffffff164264ffffffffff16108061101a57507f000000000000000000000000000000000000000000000000000000000000000064ffffffffff164264ffffffffff1610155b80611027575060025460ff165b8061103a575060025462010000900460ff165b8061104c5750600254610100900460ff165b1561106a57604051630fe219dd60e21b815260040160405180910390fd5b8260000361108b57604051635b0b4c9160e01b815260040160405180910390fd5b7f0000000000000000000000000000000000000000000000000000000000000000600054846110ba9190611e57565b11156110d957604051637858758f60e11b815260040160405180910390fd5b6001600160a01b0382166000908152600360205260409020547f00000000000000000000000000000000000000000000000000000000000000009061111e9085611e57565b111561113d57604051631dc374f160e11b815260040160405180910390fd5b6001600160a01b0382166111645760405163d92e233d60e01b815260040160405180910390fd5b61116d83611a07565b61118a5760405163c13a806160e01b815260040160405180910390fd5b611192610df6565b8361119b610c26565b6111a59190611d38565b10156111c45760405163162908e360e11b815260040160405180910390fd5b60006111f07f000000000000000000000000000000000000000000000000000000000000000085611a1a565b9050600061123e7f00000000000000000000000000000000000000000000000000000000000000007f0000000000000000000000000000000000000000000000000000000000000000611a1a565b9050600061124c83836117c4565b90506112787f000000000000000000000000000000000000000000000000000000000000000082611a8b565b93508360000361129b57604051635b0b4c9160e01b815260040160405180910390fd5b60006112c7857f00000000000000000000000000000000000000000000000000000000000000006117c4565b9050866000808282546112da9190611e57565b90915550506001600160a01b03861660009081526003602052604081208054899290611307908490611e57565b9250508190555080600160008282546113209190611e57565b90915550509384019361135e7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316333088611aec565b7f0000000000000000000000000000000000000000000000000000000000000000600054036113b1576040517fcd69fa9896c4546b6ceac642f9fc45bf9603651c212d512911d735dc97f99f7290600090a15b60408051888152602081018790526001600160a01b038816917f16481c457cfa97f1508c848b8ce22b67b27711f139806040aeb662abdfc4996b910160405180910390a2505050503868929eee149b4bd212685592915050565b3068929eee149b4bd21268540361142a5763ab143c066000526004601cfd5b3068929eee149b4bd2126855336001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000161461147f576040516330cd747160e01b815260040160405180910390fd5b60025460ff16156114a357604051634d65bf2960e11b815260040160405180910390fd5b60025462010000900460ff16156114cd576040516338384cc160e21b815260040160405180910390fd5b7f000000000000000000000000000000000000000000000000000000000000000064ffffffffff164264ffffffffff161061151b5760405163f1d2165f60e01b815260040160405180910390fd5b6002805462ff00001916620100001790556115a06001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000167f00000000000000000000000000000000000000000000000000000000000000007f00000000000000000000000000000000000000000000000000000000000000006117f2565b6040517f4717c1fcb8954ad4f0da8b5d368d4064a1c750f8639c89dc534ad6070697078290600090a13868929eee149b4bd2126855565b60025460009062010000900460ff16806115f3575060025460ff165b156115fe5750600090565b7f0000000000000000000000000000000000000000000000000000000000000000600054148061165c57507f000000000000000000000000000000000000000000000000000000000000000064ffffffffff164264ffffffffff1610155b15610e9b5750600190565b6000807f00000000000000000000000000000000000000000000000000000000000000001180156116b957507f0000000000000000000000000000000000000000000000000000000000000000600054105b156116c45750600090565b50600190565b60006116ff6001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001630611b40565b9050801561175b5761175b6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000167f0000000000000000000000000000000000000000000000000000000000000000836117f2565b600154156117bc576001546117bc906001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016907f0000000000000000000000000000000000000000000000000000000000000000906117f2565b50565b900390565b6000816000190483118202156117e25763bac65e5b6000526004601cfd5b50670de0b6b3a764000091020490565b816014528060345263a9059cbb60601b60005260206000604460106000875af13d15600160005114171661182e576390b8ec186000526004601cfd5b6000603452505050565b6000620151806118887f00000000000000000000000000000000000000000000000000000000000000007f0000000000000000000000000000000000000000000000000000000000000000611e6a565b64ffffffffff16108061189e575061189e611667565b156118c857507f000000000000000000000000000000000000000000000000000000000000000090565b610c547f000000000000000000000000000000000000000000000000000000000000000062015180611e8f565b6001600160a01b038116600090815260036020526040812080549082905561198a6119607f00000000000000000000000000000000000000000000000000000000000000007f0000000000000000000000000000000000000000000000000000000000000000611a1a565b6106937f000000000000000000000000000000000000000000000000000000000000000084611a1a565b91506119b67f000000000000000000000000000000000000000000000000000000000000000083611a8b565b91506000811180156119c85750600082115b15611a0157611a016001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001684846117f2565b50919050565b6000611a11610df6565b90911015919050565b80601260ff84161015611a53576000611a34846012611d4b565b9050611a4181600a611e48565b611a4b9083611ead565b915050610c20565b60128360ff161115610c20576000611a6c601285611d4b565b9050611a7981600a611e48565b611a839083611ec4565b949350505050565b80601260ff84161015611abc576000611aa5846012611d4b565b9050611ab281600a611e48565b611a4b9083611ec4565b60128360ff161115610c20576000611ad5601285611d4b565b9050611ae281600a611e48565b611a839083611ead565b60405181606052826040528360601b602c526323b872dd60601b600c52602060006064601c6000895af13d156001600051141716611b3257637939f4246000526004601cfd5b600060605260405250505050565b6000816014526370a0823160601b60005260208060246010865afa601f3d111660205102905092915050565b81516001600160a01b0316815261026081016020830151611b9860208401826001600160a01b03169052565b506040830151611bb360408401826001600160a01b03169052565b506060830151611bce60608401826001600160a01b03169052565b506080830151608083015260a083015160a083015260c083015160c083015260e083015160e083015261010080840151818401525061012080840151611c1c8285018264ffffffffff169052565b50506101408381015164ffffffffff90811691840191909152610160808501519091169083015261018080840151908301526101a0808401511515908301526101c0808401511515908301526101e08084015115159083015261020080840151151590830152610220808401519083015261024092830151929091019190915290565b80356001600160a01b0381168114611cb657600080fd5b919050565b600060208284031215611ccd57600080fd5b611cd682611c9f565b9392505050565b60008060408385031215611cf057600080fd5b82359150611d0060208401611c9f565b90509250929050565b600060208284031215611d1b57600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b81810381811115610c2057610c20611d22565b60ff8281168282160390811115610c2057610c20611d22565b600181815b80851115611d9f578160001904821115611d8557611d85611d22565b80851615611d9257918102915b93841c9390800290611d69565b509250929050565b600082611db657506001610c20565b81611dc357506000610c20565b8160018114611dd95760028114611de357611dff565b6001915050610c20565b60ff841115611df457611df4611d22565b50506001821b610c20565b5060208310610133831016604e8410600b8410161715611e22575081810a610c20565b611e2c8383611d64565b8060001904821115611e4057611e40611d22565b029392505050565b6000611cd660ff841683611da7565b80820180821115610c2057610c20611d22565b64ffffffffff828116828216039080821115611e8857611e88611d22565b5092915050565b64ffffffffff818116838216019080821115611e8857611e88611d22565b8082028115828204841417610c2057610c20611d22565b600082611ee157634e487b7160e01b600052601260045260246000fd5b50049056fea2646970667358221220d80ff467a698acde908eb45576f6021368b1bb6b7a8612ed131758998a3c825064736f6c6343000819003361022060405234801561001157600080fd5b506040516124c73803806124c7833981016040819052610030916103bf565b80516001600160a01b03161580610052575060a08101516001600160a01b0316155b8061006457506001600160a01b038216155b156100825760405163d92e233d60e01b815260040160405180910390fd5b80610120015164ffffffffff1681610100015164ffffffffff161015806100c0575080610140015164ffffffffff1681610120015164ffffffffff16115b156100de5760405163364dd21b60e21b815260040160405180910390fd5b670de0b6b3a76400008160c001511015806101055750670de0b6b3a76400008160e0015110155b15610123576040516358d620b360e01b815260040160405180910390fd5b80602001516000036101475760405162bfc92160e01b815260040160405180910390fd5b80604001518160600151111561017057604051639c7de60360e01b815260040160405180910390fd5b80516001600160a01b03166101808190526040805163313ce56760e01b8152905163313ce567916004808201926020929091908290030181865afa1580156101bc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101e0919061049b565b60ff166102008190526012101561020a57604051630692acc560e51b815260040160405180910390fd5b602081015160809081526001600160a01b0380841661014090815260c084015160e090815284015161010090815260a0808601519093166101605284015164ffffffffff9081166101a05261012085015181166101c05290840151166101e0526040830151905281015161028057600019610286565b80608001515b61012052606081015160c052610140516040820151610180516102b6926001600160a01b039091169130906102fa565b7f6b9e4c2de0a9dd9c71d8102a31b5460936ff4259a4119802a01823a727b95c7281604001516040516102eb91815260200190565b60405180910390a150506104c5565b60405181606052826040528360601b602c526f23b872dd000000000000000000000000600c52602060006064601c6000895af13d15600160005114171661034957637939f4246000526004601cfd5b600060605260405250505050565b80516001600160a01b038116811461036e57600080fd5b919050565b60405161016081016001600160401b03811182821017156103a457634e487b7160e01b600052604160045260246000fd5b60405290565b805164ffffffffff8116811461036e57600080fd5b6000808284036101808112156103d457600080fd5b6103dd84610357565b925061016080601f19830112156103f357600080fd5b6103fb610373565b915061040960208601610357565b825260408501516020830152606085015160408301526080850151606083015260a0850151608083015261043f60c08601610357565b60a083015260e085015160c08301526101008086015160e08401526101206104688188016103aa565b82850152610140915061047c8288016103aa565b9084015261048b8683016103aa565b9083015250919491935090915050565b6000602082840312156104ad57600080fd5b815160ff811681146104be57600080fd5b9392505050565b60805160a05160c05160e05161010051610120516101405161016051610180516101a0516101c0516101e05161020051611e016106c660003960008181610dc701528181610df60152818161115d01526118bf015260008181610215015281816117e7015261182901526000818161054801528181610af101528181610f730152818161156d015281816117c601526118500152600081816104e901528181610ac401528181610f3c0152611411015260008181610456015281816108090152818161096901528181610d550152818161147b0152818161161b015261165601526000818161038f01528181610765015281816109d701526116b60152600081816104a0015281816107a10152818161082b015281816109a801528181610e61015281816113830152818161149d01526116780152600081816101ce01528181610b7501528181610bc701526110ad01526000818161025f01528181610a9e01526111f70152600081816102930152818161071c0152610a7801526000818161035b01528181610a52015281816115ae01526115d70152600081816102f7015281816106f0015281816107d001528181610a2c01528181610bfb01528181611046015281816112a4015281816114be01526115420152600081816105bb01528181610a060152818161118d0152818161189901526119050152611e016000f3fe6080604052600436106101b75760003560e01c806373aff5af116100ec578063c20ed6711161008a578063dab8263a11610064578063dab8263a146105a9578063e7e10490146105dd578063f12723e6146105f2578063f7049d781461061f57600080fd5b8063c20ed6711461056a578063c4ae31681461057f578063c669c0781461059657600080fd5b8063ab0bcc41116100c6578063ab0bcc41146104d7578063b9ccf21d1461050b578063be040fb014610521578063c10b93581461053657600080fd5b806373aff5af146104785780638da5cb5b1461048e578063aaa30c97146104c257600080fd5b80634415c60e116101595780635249cc52116101335780635249cc52146103eb578063597e1fb51461040b5780635c975abb146104255780636c9fa59e1461044457600080fd5b80634415c60e14610349578063469048401461037d5780634e9b75b6146103c957600080fd5b80631f7d8c4a116101955780631f7d8c4a146102815780633f9942ff146102b557806342c22ff1146102e557806343d726d61461031957600080fd5b806319f76c18146101bc5780631b235437146102035780631f2f2e1b1461024d575b600080fd5b3480156101c857600080fd5b506101f07f000000000000000000000000000000000000000000000000000000000000000081565b6040519081526020015b60405180910390f35b34801561020f57600080fd5b506102377f000000000000000000000000000000000000000000000000000000000000000081565b60405164ffffffffff90911681526020016101fa565b34801561025957600080fd5b506101f07f000000000000000000000000000000000000000000000000000000000000000081565b34801561028d57600080fd5b506101f07f000000000000000000000000000000000000000000000000000000000000000081565b3480156102c157600080fd5b506002546102d59062010000900460ff1681565b60405190151581526020016101fa565b3480156102f157600080fd5b506101f07f000000000000000000000000000000000000000000000000000000000000000081565b34801561032557600080fd5b5061032e610634565b604080519384526020840192909252908201526060016101fa565b34801561035557600080fd5b506101f07f000000000000000000000000000000000000000000000000000000000000000081565b34801561038957600080fd5b506103b17f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b0390911681526020016101fa565b3480156103d557600080fd5b506103de6108c2565b6040516101fa9190611a6a565b3480156103f757600080fd5b506101f0610406366004611bb9565b610ba8565b34801561041757600080fd5b506002546102d59060ff1681565b34801561043157600080fd5b506002546102d590610100900460ff1681565b34801561045057600080fd5b506103b17f000000000000000000000000000000000000000000000000000000000000000081565b34801561048457600080fd5b506101f060005481565b34801561049a57600080fd5b506103b17f000000000000000000000000000000000000000000000000000000000000000081565b3480156104ce57600080fd5b506101f0610bf1565b3480156104e357600080fd5b506102377f000000000000000000000000000000000000000000000000000000000000000081565b34801561051757600080fd5b506101f060015481565b34801561052d57600080fd5b506101f0610c24565b34801561054257600080fd5b506102377f000000000000000000000000000000000000000000000000000000000000000081565b34801561057657600080fd5b506101f0610dc1565b34801561058b57600080fd5b50610594610e2b565b005b6101f06105a4366004611bdb565b610f0d565b3480156105b557600080fd5b506101f07f000000000000000000000000000000000000000000000000000000000000000081565b3480156105e957600080fd5b5061059461134d565b3480156105fe57600080fd5b506101f061060d366004611bb9565b60036020526000908152604090205481565b34801561062b57600080fd5b506102d5611519565b60008060003068929eee149b4bd2126854036106585763ab143c066000526004601cfd5b3068929eee149b4bd212685561066c611519565b6106895760405163f1d2165f60e01b815260040160405180910390fd5b6002805460ff1916600117905561069e6115a9565b610714576106aa61160c565b7f80bc0863d90c6c8fac9104e99d78f2aa8d867a4474dbb8bdbc32ba9d84c1c4e36001546040516106dd91815260200190565b60405180910390a15050600154905060007f00000000000000000000000000000000000000000000000000000000000000006108b1565b6001546107467f0000000000000000000000000000000000000000000000000000000000000000478390035b906116e4565b6107509190611c1d565b9250821561078b5761078b6001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001684611712565b47915081156107c7576107c76001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001683611732565b6000546107f4907f0000000000000000000000000000000000000000000000000000000000000000611c30565b90508015610850576108506001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000167f000000000000000000000000000000000000000000000000000000000000000083611775565b7ff24c64885f2398a320c41d4eb1531c9b2440ba4e78edfc733536609a4a2a1b1b8260005461088a600154876116df90919063ffffffff16565b60015460408051948552602085019390935291830152606082015260800160405180910390a15b3868929eee149b4bd2126855909192565b6040805161026081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e08101829052610100810182905261012081018290526101408101829052610160810182905261018081018290526101a081018290526101c081018290526101e08101829052610200810182905261022081018290526102408101919091526040518061026001604052807f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316815260200160006001600160a01b031681526020017f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031681526020017f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031681526020017f000000000000000000000000000000000000000000000000000000000000000081526020017f000000000000000000000000000000000000000000000000000000000000000081526020017f000000000000000000000000000000000000000000000000000000000000000081526020017f000000000000000000000000000000000000000000000000000000000000000081526020017f000000000000000000000000000000000000000000000000000000000000000081526020017f000000000000000000000000000000000000000000000000000000000000000064ffffffffff1681526020017f000000000000000000000000000000000000000000000000000000000000000064ffffffffff168152602001610b246117bb565b64ffffffffff168152600054602082015260025460ff80821615156040840152610100820481161515606084015262010000909104161515608082015260a001610b6c611519565b151581526020017f00000000000000000000000000000000000000000000000000000000000000008152602001610ba1610dc1565b9052919050565b6001600160a01b038116600090815260036020526040812054610beb907f0000000000000000000000000000000000000000000000000000000000000000611c30565b92915050565b60008054610c1f907f0000000000000000000000000000000000000000000000000000000000000000611c30565b905090565b60003068929eee149b4bd212685403610c455763ab143c066000526004601cfd5b3068929eee149b4bd212685560025462010000900460ff1615610c7b576040516338384cc160e21b815260040160405180910390fd5b60025460ff16610c9e5760405163f1d2165f60e01b815260040160405180910390fd5b610ca66117bb565b64ffffffffff164264ffffffffff161015610cd4576040516312dbbce560e01b815260040160405180910390fd5b610cdc6115a9565b610d2d576000610ceb33611878565b60405181815290915033907fd7dee2702d63ad89917b6a4da9981c90c4d24f8c2bdfd64c604ecae57d8d06519060200160405180910390a26000915050610db2565b5033600090815260036020526040812080549190558015610d7c57610d7c6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000163383611775565b60405181815233907f4896181ff8f4543cc00db9fe9b6fb7e6f032b7eb772c72ab1ec1b4d2e03b93699060200160405180910390a25b3868929eee149b4bd212685590565b600060127f000000000000000000000000000000000000000000000000000000000000000060ff161115610e2557610e1a60127f0000000000000000000000000000000000000000000000000000000000000000611c43565b610c1f90600a611d40565b50600090565b3068929eee149b4bd212685403610e4a5763ab143c066000526004601cfd5b3068929eee149b4bd2126855336001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001614610e9f576040516330cd747160e01b815260040160405180910390fd5b6002805460ff610100808304821615810261ff001990931692909217928390556040517f9077d36bc00859b5c3f320310707208543dd35092cb0a0fe117d0c6a558b148b93610ef79390049091161515815260200190565b60405180910390a13868929eee149b4bd2126855565b60003068929eee149b4bd212685403610f2e5763ab143c066000526004601cfd5b3068929eee149b4bd21268557f000000000000000000000000000000000000000000000000000000000000000064ffffffffff164264ffffffffff161080610fa457507f000000000000000000000000000000000000000000000000000000000000000064ffffffffff164264ffffffffff1610155b80610fb1575060025460ff165b80610fc35750600254610100900460ff165b80610fd6575060025462010000900460ff165b15610ff457604051630fe219dd60e21b815260040160405180910390fd5b821580610fff575034155b1561101d57604051635b0b4c9160e01b815260040160405180910390fd5b6001600160a01b0382166110445760405163d92e233d60e01b815260040160405180910390fd5b7f0000000000000000000000000000000000000000000000000000000000000000600054846110739190611c1d565b111561109257604051637858758f60e11b815260040160405180910390fd5b6001600160a01b0382166000908152600360205260409020547f0000000000000000000000000000000000000000000000000000000000000000906110d79085611c1d565b11156110f657604051631dc374f160e11b815260040160405180910390fd5b6110ff83611959565b61111c5760405163c13a806160e01b815260040160405180910390fd5b611124610dc1565b8361112d610bf1565b6111379190611c30565b10156111565760405163162908e360e11b815260040160405180910390fd5b60006111827f00000000000000000000000000000000000000000000000000000000000000008561196c565b905060006111b160127f000000000000000000000000000000000000000000000000000000000000000061196c565b905060006111bf83836116e4565b90506111cc6012826119dd565b9350836000036111ef57604051635b0b4c9160e01b815260040160405180910390fd5b600061121b857f00000000000000000000000000000000000000000000000000000000000000006116e4565b90508481019450843410156112435760405163356680b760e01b815260040160405180910390fd5b866000808282546112549190611c1d565b90915550506001600160a01b03861660009081526003602052604081208054899290611281908490611c1d565b92505081905550806001600082825461129a9190611c1d565b90915550506000547f000000000000000000000000000000000000000000000000000000000000000090036112f3576040517fcd69fa9896c4546b6ceac642f9fc45bf9603651c212d512911d735dc97f99f7290600090a15b60408051888152602081018790526001600160a01b038816917f16481c457cfa97f1508c848b8ce22b67b27711f139806040aeb662abdfc4996b910160405180910390a2505050503868929eee149b4bd212685592915050565b3068929eee149b4bd21268540361136c5763ab143c066000526004601cfd5b3068929eee149b4bd2126855336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146113c1576040516330cd747160e01b815260040160405180910390fd5b60025460ff16156113e557604051634d65bf2960e11b815260040160405180910390fd5b60025462010000900460ff161561140f576040516338384cc160e21b815260040160405180910390fd5b7f000000000000000000000000000000000000000000000000000000000000000064ffffffffff164264ffffffffff161061145d5760405163f1d2165f60e01b815260040160405180910390fd5b6002805462ff00001916620100001790556114e26001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000167f00000000000000000000000000000000000000000000000000000000000000007f0000000000000000000000000000000000000000000000000000000000000000611775565b6040517f4717c1fcb8954ad4f0da8b5d368d4064a1c750f8639c89dc534ad6070697078290600090a13868929eee149b4bd2126855565b60025460009062010000900460ff1680611535575060025460ff165b156115405750600090565b7f0000000000000000000000000000000000000000000000000000000000000000600054148061159e57507f000000000000000000000000000000000000000000000000000000000000000064ffffffffff164264ffffffffff1610155b15610e255750600190565b6000807f00000000000000000000000000000000000000000000000000000000000000001180156115fb57507f0000000000000000000000000000000000000000000000000000000000000000600054105b156116065750600090565b50600190565b60006116416001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001630611a3e565b9050801561169d5761169d6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000167f000000000000000000000000000000000000000000000000000000000000000083611775565b600154156116dc576001546116dc906001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690611712565b50565b900390565b6000816000190483118202156117025763bac65e5b6000526004601cfd5b50670de0b6b3a764000091020490565b60003860003884865af161172e5763b12d13eb6000526004601cfd5b5050565b804710156117485763b12d13eb6000526004601cfd5b6000386000388486620186a0f161172e57816000526073600b5360ff6020536016600b82f061172e573838fd5b816014528060345263a9059cbb60601b60005260206000604460106000875af13d1560016000511417166117b1576390b8ec186000526004601cfd5b6000603452505050565b60006201518061180b7f00000000000000000000000000000000000000000000000000000000000000007f0000000000000000000000000000000000000000000000000000000000000000611d4f565b64ffffffffff16108061182157506118216115a9565b1561184b57507f000000000000000000000000000000000000000000000000000000000000000090565b610c1f7f000000000000000000000000000000000000000000000000000000000000000062015180611d74565b6001600160a01b03811660009081526003602052604081205481906118e4907f000000000000000000000000000000000000000000000000000000000000000090610740907f00000000000000000000000000000000000000000000000000000000000000009061196c565b6001600160a01b0384166000908152600360205260408120559050611929817f00000000000000000000000000000000000000000000000000000000000000006116e4565b915060008111801561193b5750600082115b15611953576119536001600160a01b03841683611712565b50919050565b6000611963610dc1565b90911015919050565b80601260ff841610156119a5576000611986846012611c43565b905061199381600a611d40565b61199d9083611d92565b915050610beb565b60128360ff161115610beb5760006119be601285611c43565b90506119cb81600a611d40565b6119d59083611da9565b949350505050565b80601260ff84161015611a0e5760006119f7846012611c43565b9050611a0481600a611d40565b61199d9083611da9565b60128360ff161115610beb576000611a27601285611c43565b9050611a3481600a611d40565b6119d59083611d92565b6000816014526370a0823160601b60005260208060246010865afa601f3d111660205102905092915050565b81516001600160a01b0316815261026081016020830151611a9660208401826001600160a01b03169052565b506040830151611ab160408401826001600160a01b03169052565b506060830151611acc60608401826001600160a01b03169052565b506080830151608083015260a083015160a083015260c083015160c083015260e083015160e083015261010080840151818401525061012080840151611b1a8285018264ffffffffff169052565b50506101408381015164ffffffffff90811691840191909152610160808501519091169083015261018080840151908301526101a0808401511515908301526101c0808401511515908301526101e08084015115159083015261020080840151151590830152610220808401519083015261024092830151929091019190915290565b80356001600160a01b0381168114611bb457600080fd5b919050565b600060208284031215611bcb57600080fd5b611bd482611b9d565b9392505050565b60008060408385031215611bee57600080fd5b82359150611bfe60208401611b9d565b90509250929050565b634e487b7160e01b600052601160045260246000fd5b80820180821115610beb57610beb611c07565b81810381811115610beb57610beb611c07565b60ff8281168282160390811115610beb57610beb611c07565b600181815b80851115611c97578160001904821115611c7d57611c7d611c07565b80851615611c8a57918102915b93841c9390800290611c61565b509250929050565b600082611cae57506001610beb565b81611cbb57506000610beb565b8160018114611cd15760028114611cdb57611cf7565b6001915050610beb565b60ff841115611cec57611cec611c07565b50506001821b610beb565b5060208310610133831016604e8410600b8410161715611d1a575081810a610beb565b611d248383611c5c565b8060001904821115611d3857611d38611c07565b029392505050565b6000611bd460ff841683611c9f565b64ffffffffff828116828216039080821115611d6d57611d6d611c07565b5092915050565b64ffffffffff818116838216019080821115611d6d57611d6d611c07565b8082028115828204841417610beb57610beb611c07565b600082611dc657634e487b7160e01b600052601260045260246000fd5b50049056fea26469706673582212202e387a7eebb4817f76067e16639d58a0af3fb68bbc23f72c07a996a89b8f0ae264736f6c63430008190033a26469706673582212207e4664e15fd552095b995fefaa9c1f21229bf66fd278cf39e89e40a9ec58f30764736f6c63430008190033

Deployed Bytecode

0x608060405234801561001057600080fd5b506004361061004c5760003560e01c8063178cb7b0146100515780633cad498a146100805780636c5817a6146100935780639c19ed02146100a6575b600080fd5b61006461005f366004610579565b6100b9565b6040516001600160a01b03909116815260200160405180910390f35b61006461008e36600461063d565b61016e565b6100646100a1366004610672565b6101ad565b6100646100b436600461068f565b61024b565b60008033836040516020016100cf9291906106bb565b6040516020818303038152906040528051906020012090506100fd6100f43385610261565b829060006102d5565b91506001600160a01b038216610126576040516337200b1d60e21b815260040160405180910390fd5b816001600160a01b03167f7c3072652d5407e4dcbe90ac1760509311e2511e531f5caf91859f3bc741670860016040516101609190610797565b60405180910390a250919050565b60008083836040516020016101849291906107bf565b6040516020818303038152906040528051906020012090506101a581610356565b949350505050565b60008033836040516020016101c39291906107bf565b6040516020818303038152906040528051906020012090506101e86100f43385610368565b91506001600160a01b038216610211576040516337200b1d60e21b815260040160405180910390fd5b816001600160a01b03167f7c3072652d5407e4dcbe90ac1760509311e2511e531f5caf91859f3bc741670860006040516101609190610797565b60008083836040516020016101849291906106bb565b606060006040518060200161027590610400565b6020820181038252601f19601f82011660405250905080848460405160200161029f9291906106bb565b60408051601f19818403018152908290526102bd92916020016108b1565b60405160208183030381529060405291505092915050565b60006f67363d3d37363d34f03d5260086018f3600052836010806000f5806103055763301164256000526004601cfd5b8060145261d69460005260016034536017601e20915060008085516020870186855af161033a576319b991a86000526004601cfd5b50803b61034f576319b991a86000526004601cfd5b9392505050565b600061036282306103a6565b92915050565b606060006040518060200161037c9061040d565b6020820181038252601f19601f82011660405250905080848460405160200161029f9291906107bf565b60006040518260005260ff600b53836020527f21c35dbe1b344a2488cf3321d6ce542f8e9f305544ff09e4993a62319a497c1f6040526055600b20601452806040525061d694600052600160345350506017601e20919050565b6126f8806108c783390190565b6124c780612fbf83390190565b604051610180810167ffffffffffffffff8111828210171561044c57634e487b7160e01b600052604160045260246000fd5b60405290565b604051610160810167ffffffffffffffff8111828210171561044c57634e487b7160e01b600052604160045260246000fd5b80356001600160a01b038116811461049b57600080fd5b919050565b803564ffffffffff8116811461049b57600080fd5b600061018082840312156104c857600080fd5b6104d061041a565b90506104db82610484565b81526104e960208301610484565b602082015260408201356040820152606082013560608201526080820135608082015260a082013560a082015261052260c08301610484565b60c082015260e082013560e082015261010080830135818301525061012061054b8184016104a0565b9082015261014061055d8382016104a0565b9082015261016061056f8382016104a0565b9082015292915050565b6000610180828403121561058c57600080fd5b61034f83836104b5565b600061016082840312156105a957600080fd5b6105b1610452565b90506105bc82610484565b8152602082013560208201526040820135604082015260608201356060820152608082013560808201526105f260a08301610484565b60a082015260c082013560c082015260e082013560e08201526101006106198184016104a0565b9082015261012061062b8382016104a0565b9082015261014061056f8382016104a0565b600080610180838503121561065157600080fd5b61065a83610484565b91506106698460208501610596565b90509250929050565b6000610160828403121561068557600080fd5b61034f8383610596565b6000806101a083850312156106a357600080fd5b6106ac83610484565b915061066984602085016104b5565b6001600160a01b03838116825282511660208201526101a0810160208301516001600160a01b0381166040840152506040830151606083015260608301516080830152608083015160a083015260a083015160c083015260c083015161072c60e08401826001600160a01b03169052565b5060e083015161010083810191909152830151610120808401919091528301516101406107618185018364ffffffffff169052565b840151905061016061077b8482018364ffffffffff169052565b84015164ffffffffff811661018085015290505b509392505050565b60208101600283106107b957634e487b7160e01b600052602160045260246000fd5b91905290565b6001600160a01b03838116825282511660208201526101808101602083015160408301526040830151606083015260608301516080830152608083015160a083015260a083015161081b60c08401826001600160a01b03169052565b5060c083015160e083015260e083015161010081818501528085015191505061012061084f8185018364ffffffffff169052565b84015190506101406108698482018364ffffffffff169052565b84015164ffffffffff8116610160850152905061078f565b6000815160005b818110156108a25760208185018101518683015201610888565b50600093019283525090919050565b60006101a56108c08386610881565b8461088156fe61026060405234801561001157600080fd5b506040516126f83803806126f883398101604081905261003091610460565b80516001600160a01b03161580610052575060208101516001600160a01b0316155b80610068575060c08101516001600160a01b0316155b156100865760405163d92e233d60e01b815260040160405180910390fd5b80610140015164ffffffffff1681610120015164ffffffffff161015806100c4575080610160015164ffffffffff1681610140015164ffffffffff16115b156100e25760405163364dd21b60e21b815260040160405180910390fd5b670de0b6b3a76400008160e0015110158061010a5750670de0b6b3a764000081610100015110155b15610128576040516358d620b360e01b815260040160405180910390fd5b806040015160000361014c5760405162bfc92160e01b815260040160405180910390fd5b80606001518160800151111561017557604051639c7de60360e01b815260040160405180910390fd5b80516001600160a01b039081166101808190526020808401519092166101a0526040805163313ce56760e01b81529051919263313ce567926004808401938290030181865afa1580156101cc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101f0919061054e565b60ff166102408160ff16815250506101a0516001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa15801561023f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610263919061054e565b60ff1661022081905260021180610280575060126102205160ff16115b80610291575060126102405160ff16115b156102af57604051630692acc560e51b815260040160405180910390fd5b60408101516080526001600160a01b0380831661014090815260e080840151905261010080840151905260c083015190911661016090815261012083015164ffffffffff9081166101c0529183015182166101e0528201511661020052606081015160a09081528101516103255760001961032b565b8060a001515b61012052608081015160c0526101405160a05161018051610359926001600160a01b0390911691309061039b565b7f6b9e4c2de0a9dd9c71d8102a31b5460936ff4259a4119802a01823a727b95c7260a05160405161038c91815260200190565b60405180910390a15050610578565b60405181606052826040528360601b602c526f23b872dd000000000000000000000000600c52602060006064601c6000895af13d1560016000511417166103ea57637939f4246000526004601cfd5b600060605260405250505050565b80516001600160a01b038116811461040f57600080fd5b919050565b60405161018081016001600160401b038111828210171561044557634e487b7160e01b600052604160045260246000fd5b60405290565b805164ffffffffff8116811461040f57600080fd5b6000808284036101a081121561047557600080fd5b61047e846103f8565b925061018080601f198301121561049457600080fd5b61049c610414565b91506104aa602086016103f8565b82526104b8604086016103f8565b6020830152606085015160408301526080850151606083015260a0850151608083015260c085015160a08301526104f160e086016103f8565b60c08301526101008086015160e08401526101208087015182850152610140915061051d82880161044b565b9084015261016061052f87820161044b565b8285015261053e83880161044b565b9084015250929590945092505050565b60006020828403121561056057600080fd5b815160ff8116811461057157600080fd5b9392505050565b60805160a05160c05160e05161010051610120516101405161016051610180516101a0516101c0516101e051610200516102205161024051611f1c6107dc60003960008181610e1e01528181610e6c015281816111cb0152611965015260008181610dfa01528181610e4b015281816111f9015281816112530152818161191b01526119910152600081816102520152818161186401526118a601526000818161049d01528181610b2601528181610fe90152818161162b0152818161184301526118cd01526000818161046501528181610af901528181610fb201526114cf0152600081816101d901528181610624015281816106b20152818161070e01528181610796015281816109ae0152818161132e0152818161177401526119da0152600081816104060152818161081f0152818161097f01528181610d8a01528181611539015281816116d90152611714015260008181610371015281816106d401528181610a0c0152611797015260008181610436015281816107b801528181610841015281816109dd01528181610ed7015281816114410152818161155b015261173601526000818161021d01528181610baa01528181610bfc01526110f401526000818161028f01528181610ad301526112a30152600081816102b6015281816105f40152610aad01526000818161034a01528181610a870152818161166c0152611695015260008181610300015281816107e601528181610a6101528181610c300152818161108d015281816113600152818161157c01526116000152600081816103df01528181610a3b0152818161121a015261193c0152611f1c6000f3fe608060405234801561001057600080fd5b50600436106101cf5760003560e01c80636b71809a11610104578063be040fb0116100a2578063c669c07811610071578063c669c078146104d1578063e7e10490146104e4578063f12723e6146104ec578063f7049d781461050c57600080fd5b8063be040fb014610490578063c10b935814610498578063c20ed671146104bf578063c4ae3168146104c757600080fd5b80638da5cb5b116100de5780638da5cb5b14610431578063aaa30c9714610458578063ab0bcc4114610460578063b9ccf21d1461048757600080fd5b80636b71809a146103da5780636c9fa59e1461040157806373aff5af1461042857600080fd5b806343d726d6116101715780634e9b75b61161014b5780634e9b75b6146103935780635249cc52146103a8578063597e1fb5146103bb5780635c975abb146103c857600080fd5b806343d726d6146103225780634415c60e14610345578063469048401461036c57600080fd5b80631f2f2e1b116101ad5780631f2f2e1b1461028a5780631f7d8c4a146102b15780633f9942ff146102d857806342c22ff1146102fb57600080fd5b80631083f761146101d457806319f76c18146102185780631b2354371461024d575b600080fd5b6101fb7f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b0390911681526020015b60405180910390f35b61023f7f000000000000000000000000000000000000000000000000000000000000000081565b60405190815260200161020f565b6102747f000000000000000000000000000000000000000000000000000000000000000081565b60405164ffffffffff909116815260200161020f565b61023f7f000000000000000000000000000000000000000000000000000000000000000081565b61023f7f000000000000000000000000000000000000000000000000000000000000000081565b6002546102eb9062010000900460ff1681565b604051901515815260200161020f565b61023f7f000000000000000000000000000000000000000000000000000000000000000081565b61032a610514565b6040805193845260208401929092529082015260600161020f565b61023f7f000000000000000000000000000000000000000000000000000000000000000081565b6101fb7f000000000000000000000000000000000000000000000000000000000000000081565b61039b6108d8565b60405161020f9190611b6c565b61023f6103b6366004611cbb565b610bdd565b6002546102eb9060ff1681565b6002546102eb90610100900460ff1681565b61023f7f000000000000000000000000000000000000000000000000000000000000000081565b6101fb7f000000000000000000000000000000000000000000000000000000000000000081565b61023f60005481565b6101fb7f000000000000000000000000000000000000000000000000000000000000000081565b61023f610c26565b6102747f000000000000000000000000000000000000000000000000000000000000000081565b61023f60015481565b61023f610c59565b6102747f000000000000000000000000000000000000000000000000000000000000000081565b61023f610df6565b6104cf610ea1565b005b61023f6104df366004611cdd565b610f83565b6104cf61140b565b61023f6104fa366004611cbb565b60036020526000908152604090205481565b6102eb6115d7565b60008060003068929eee149b4bd2126854036105385763ab143c066000526004601cfd5b3068929eee149b4bd212685561054c6115d7565b6105695760405163f1d2165f60e01b815260040160405180910390fd5b6002805460ff1916600117905561057e611667565b6105d35761058a6116ca565b7f80bc0863d90c6c8fac9104e99d78f2aa8d867a4474dbb8bdbc32ba9d84c1c4e36001546040516105bd91815260200190565b60405180910390a15060009150819050806108c7565b6001546040516370a0823160e01b815230600482015261069d9190610699907f0000000000000000000000000000000000000000000000000000000000000000906106939084906001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016906370a0823190602401602060405180830381865afa15801561066b573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061068f9190611d09565b0390565b906117c4565b0190565b925082156106f9576106f96001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000167f0000000000000000000000000000000000000000000000000000000000000000856117f2565b6040516370a0823160e01b81523060048201527f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316906370a0823190602401602060405180830381865afa15801561075d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107819190611d09565b915081156107dd576107dd6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000167f0000000000000000000000000000000000000000000000000000000000000000846117f2565b60005461080a907f0000000000000000000000000000000000000000000000000000000000000000611d38565b90508015610866576108666001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000167f0000000000000000000000000000000000000000000000000000000000000000836117f2565b7ff24c64885f2398a320c41d4eb1531c9b2440ba4e78edfc733536609a4a2a1b1b826000546108a0600154876117bf90919063ffffffff16565b60015460408051948552602085019390935291830152606082015260800160405180910390a15b3868929eee149b4bd2126855909192565b6040805161026081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e08101829052610100810182905261012081018290526101408101829052610160810182905261018081018290526101a081018290526101c081018290526101e08101829052610200810182905261022081018290526102408101919091526040518061026001604052807f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031681526020017f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031681526020017f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031681526020017f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031681526020017f000000000000000000000000000000000000000000000000000000000000000081526020017f000000000000000000000000000000000000000000000000000000000000000081526020017f000000000000000000000000000000000000000000000000000000000000000081526020017f000000000000000000000000000000000000000000000000000000000000000081526020017f000000000000000000000000000000000000000000000000000000000000000081526020017f000000000000000000000000000000000000000000000000000000000000000064ffffffffff1681526020017f000000000000000000000000000000000000000000000000000000000000000064ffffffffff168152602001610b59611838565b64ffffffffff168152600054602082015260025460ff80821615156040840152610100820481161515606084015262010000909104161515608082015260a001610ba16115d7565b151581526020017f00000000000000000000000000000000000000000000000000000000000000008152602001610bd6610df6565b9052919050565b6001600160a01b038116600090815260036020526040812054610c20907f0000000000000000000000000000000000000000000000000000000000000000611d38565b92915050565b60008054610c54907f0000000000000000000000000000000000000000000000000000000000000000611d38565b905090565b60003068929eee149b4bd212685403610c7a5763ab143c066000526004601cfd5b3068929eee149b4bd212685560025462010000900460ff1615610cb0576040516338384cc160e21b815260040160405180910390fd5b60025460ff16610cd35760405163f1d2165f60e01b815260040160405180910390fd5b610cdb611838565b64ffffffffff164264ffffffffff161015610d09576040516312dbbce560e01b815260040160405180910390fd5b610d11611667565b610d62576000610d20336118f5565b60405181815290915033907fd7dee2702d63ad89917b6a4da9981c90c4d24f8c2bdfd64c604ecae57d8d06519060200160405180910390a26000915050610de7565b5033600090815260036020526040812080549190558015610db157610db16001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001633836117f2565b60405181815233907f4896181ff8f4543cc00db9fe9b6fb7e6f032b7eb772c72ab1ec1b4d2e03b93699060200160405180910390a25b3868929eee149b4bd212685590565b60007f000000000000000000000000000000000000000000000000000000000000000060ff167f000000000000000000000000000000000000000000000000000000000000000060ff161115610e9b57610e907f00000000000000000000000000000000000000000000000000000000000000007f0000000000000000000000000000000000000000000000000000000000000000611d4b565b610c5490600a611e48565b50600090565b3068929eee149b4bd212685403610ec05763ab143c066000526004601cfd5b3068929eee149b4bd2126855336001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001614610f15576040516330cd747160e01b815260040160405180910390fd5b6002805460ff610100808304821615810261ff001990931692909217928390556040517f9077d36bc00859b5c3f320310707208543dd35092cb0a0fe117d0c6a558b148b93610f6d9390049091161515815260200190565b60405180910390a13868929eee149b4bd2126855565b60003068929eee149b4bd212685403610fa45763ab143c066000526004601cfd5b3068929eee149b4bd21268557f000000000000000000000000000000000000000000000000000000000000000064ffffffffff164264ffffffffff16108061101a57507f000000000000000000000000000000000000000000000000000000000000000064ffffffffff164264ffffffffff1610155b80611027575060025460ff165b8061103a575060025462010000900460ff165b8061104c5750600254610100900460ff165b1561106a57604051630fe219dd60e21b815260040160405180910390fd5b8260000361108b57604051635b0b4c9160e01b815260040160405180910390fd5b7f0000000000000000000000000000000000000000000000000000000000000000600054846110ba9190611e57565b11156110d957604051637858758f60e11b815260040160405180910390fd5b6001600160a01b0382166000908152600360205260409020547f00000000000000000000000000000000000000000000000000000000000000009061111e9085611e57565b111561113d57604051631dc374f160e11b815260040160405180910390fd5b6001600160a01b0382166111645760405163d92e233d60e01b815260040160405180910390fd5b61116d83611a07565b61118a5760405163c13a806160e01b815260040160405180910390fd5b611192610df6565b8361119b610c26565b6111a59190611d38565b10156111c45760405163162908e360e11b815260040160405180910390fd5b60006111f07f000000000000000000000000000000000000000000000000000000000000000085611a1a565b9050600061123e7f00000000000000000000000000000000000000000000000000000000000000007f0000000000000000000000000000000000000000000000000000000000000000611a1a565b9050600061124c83836117c4565b90506112787f000000000000000000000000000000000000000000000000000000000000000082611a8b565b93508360000361129b57604051635b0b4c9160e01b815260040160405180910390fd5b60006112c7857f00000000000000000000000000000000000000000000000000000000000000006117c4565b9050866000808282546112da9190611e57565b90915550506001600160a01b03861660009081526003602052604081208054899290611307908490611e57565b9250508190555080600160008282546113209190611e57565b90915550509384019361135e7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316333088611aec565b7f0000000000000000000000000000000000000000000000000000000000000000600054036113b1576040517fcd69fa9896c4546b6ceac642f9fc45bf9603651c212d512911d735dc97f99f7290600090a15b60408051888152602081018790526001600160a01b038816917f16481c457cfa97f1508c848b8ce22b67b27711f139806040aeb662abdfc4996b910160405180910390a2505050503868929eee149b4bd212685592915050565b3068929eee149b4bd21268540361142a5763ab143c066000526004601cfd5b3068929eee149b4bd2126855336001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000161461147f576040516330cd747160e01b815260040160405180910390fd5b60025460ff16156114a357604051634d65bf2960e11b815260040160405180910390fd5b60025462010000900460ff16156114cd576040516338384cc160e21b815260040160405180910390fd5b7f000000000000000000000000000000000000000000000000000000000000000064ffffffffff164264ffffffffff161061151b5760405163f1d2165f60e01b815260040160405180910390fd5b6002805462ff00001916620100001790556115a06001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000167f00000000000000000000000000000000000000000000000000000000000000007f00000000000000000000000000000000000000000000000000000000000000006117f2565b6040517f4717c1fcb8954ad4f0da8b5d368d4064a1c750f8639c89dc534ad6070697078290600090a13868929eee149b4bd2126855565b60025460009062010000900460ff16806115f3575060025460ff165b156115fe5750600090565b7f0000000000000000000000000000000000000000000000000000000000000000600054148061165c57507f000000000000000000000000000000000000000000000000000000000000000064ffffffffff164264ffffffffff1610155b15610e9b5750600190565b6000807f00000000000000000000000000000000000000000000000000000000000000001180156116b957507f0000000000000000000000000000000000000000000000000000000000000000600054105b156116c45750600090565b50600190565b60006116ff6001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001630611b40565b9050801561175b5761175b6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000167f0000000000000000000000000000000000000000000000000000000000000000836117f2565b600154156117bc576001546117bc906001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016907f0000000000000000000000000000000000000000000000000000000000000000906117f2565b50565b900390565b6000816000190483118202156117e25763bac65e5b6000526004601cfd5b50670de0b6b3a764000091020490565b816014528060345263a9059cbb60601b60005260206000604460106000875af13d15600160005114171661182e576390b8ec186000526004601cfd5b6000603452505050565b6000620151806118887f00000000000000000000000000000000000000000000000000000000000000007f0000000000000000000000000000000000000000000000000000000000000000611e6a565b64ffffffffff16108061189e575061189e611667565b156118c857507f000000000000000000000000000000000000000000000000000000000000000090565b610c547f000000000000000000000000000000000000000000000000000000000000000062015180611e8f565b6001600160a01b038116600090815260036020526040812080549082905561198a6119607f00000000000000000000000000000000000000000000000000000000000000007f0000000000000000000000000000000000000000000000000000000000000000611a1a565b6106937f000000000000000000000000000000000000000000000000000000000000000084611a1a565b91506119b67f000000000000000000000000000000000000000000000000000000000000000083611a8b565b91506000811180156119c85750600082115b15611a0157611a016001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001684846117f2565b50919050565b6000611a11610df6565b90911015919050565b80601260ff84161015611a53576000611a34846012611d4b565b9050611a4181600a611e48565b611a4b9083611ead565b915050610c20565b60128360ff161115610c20576000611a6c601285611d4b565b9050611a7981600a611e48565b611a839083611ec4565b949350505050565b80601260ff84161015611abc576000611aa5846012611d4b565b9050611ab281600a611e48565b611a4b9083611ec4565b60128360ff161115610c20576000611ad5601285611d4b565b9050611ae281600a611e48565b611a839083611ead565b60405181606052826040528360601b602c526323b872dd60601b600c52602060006064601c6000895af13d156001600051141716611b3257637939f4246000526004601cfd5b600060605260405250505050565b6000816014526370a0823160601b60005260208060246010865afa601f3d111660205102905092915050565b81516001600160a01b0316815261026081016020830151611b9860208401826001600160a01b03169052565b506040830151611bb360408401826001600160a01b03169052565b506060830151611bce60608401826001600160a01b03169052565b506080830151608083015260a083015160a083015260c083015160c083015260e083015160e083015261010080840151818401525061012080840151611c1c8285018264ffffffffff169052565b50506101408381015164ffffffffff90811691840191909152610160808501519091169083015261018080840151908301526101a0808401511515908301526101c0808401511515908301526101e08084015115159083015261020080840151151590830152610220808401519083015261024092830151929091019190915290565b80356001600160a01b0381168114611cb657600080fd5b919050565b600060208284031215611ccd57600080fd5b611cd682611c9f565b9392505050565b60008060408385031215611cf057600080fd5b82359150611d0060208401611c9f565b90509250929050565b600060208284031215611d1b57600080fd5b5051919050565b634e487b7160e01b600052601160045260246000fd5b81810381811115610c2057610c20611d22565b60ff8281168282160390811115610c2057610c20611d22565b600181815b80851115611d9f578160001904821115611d8557611d85611d22565b80851615611d9257918102915b93841c9390800290611d69565b509250929050565b600082611db657506001610c20565b81611dc357506000610c20565b8160018114611dd95760028114611de357611dff565b6001915050610c20565b60ff841115611df457611df4611d22565b50506001821b610c20565b5060208310610133831016604e8410600b8410161715611e22575081810a610c20565b611e2c8383611d64565b8060001904821115611e4057611e40611d22565b029392505050565b6000611cd660ff841683611da7565b80820180821115610c2057610c20611d22565b64ffffffffff828116828216039080821115611e8857611e88611d22565b5092915050565b64ffffffffff818116838216019080821115611e8857611e88611d22565b8082028115828204841417610c2057610c20611d22565b600082611ee157634e487b7160e01b600052601260045260246000fd5b50049056fea2646970667358221220d80ff467a698acde908eb45576f6021368b1bb6b7a8612ed131758998a3c825064736f6c6343000819003361022060405234801561001157600080fd5b506040516124c73803806124c7833981016040819052610030916103bf565b80516001600160a01b03161580610052575060a08101516001600160a01b0316155b8061006457506001600160a01b038216155b156100825760405163d92e233d60e01b815260040160405180910390fd5b80610120015164ffffffffff1681610100015164ffffffffff161015806100c0575080610140015164ffffffffff1681610120015164ffffffffff16115b156100de5760405163364dd21b60e21b815260040160405180910390fd5b670de0b6b3a76400008160c001511015806101055750670de0b6b3a76400008160e0015110155b15610123576040516358d620b360e01b815260040160405180910390fd5b80602001516000036101475760405162bfc92160e01b815260040160405180910390fd5b80604001518160600151111561017057604051639c7de60360e01b815260040160405180910390fd5b80516001600160a01b03166101808190526040805163313ce56760e01b8152905163313ce567916004808201926020929091908290030181865afa1580156101bc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101e0919061049b565b60ff166102008190526012101561020a57604051630692acc560e51b815260040160405180910390fd5b602081015160809081526001600160a01b0380841661014090815260c084015160e090815284015161010090815260a0808601519093166101605284015164ffffffffff9081166101a05261012085015181166101c05290840151166101e0526040830151905281015161028057600019610286565b80608001515b61012052606081015160c052610140516040820151610180516102b6926001600160a01b039091169130906102fa565b7f6b9e4c2de0a9dd9c71d8102a31b5460936ff4259a4119802a01823a727b95c7281604001516040516102eb91815260200190565b60405180910390a150506104c5565b60405181606052826040528360601b602c526f23b872dd000000000000000000000000600c52602060006064601c6000895af13d15600160005114171661034957637939f4246000526004601cfd5b600060605260405250505050565b80516001600160a01b038116811461036e57600080fd5b919050565b60405161016081016001600160401b03811182821017156103a457634e487b7160e01b600052604160045260246000fd5b60405290565b805164ffffffffff8116811461036e57600080fd5b6000808284036101808112156103d457600080fd5b6103dd84610357565b925061016080601f19830112156103f357600080fd5b6103fb610373565b915061040960208601610357565b825260408501516020830152606085015160408301526080850151606083015260a0850151608083015261043f60c08601610357565b60a083015260e085015160c08301526101008086015160e08401526101206104688188016103aa565b82850152610140915061047c8288016103aa565b9084015261048b8683016103aa565b9083015250919491935090915050565b6000602082840312156104ad57600080fd5b815160ff811681146104be57600080fd5b9392505050565b60805160a05160c05160e05161010051610120516101405161016051610180516101a0516101c0516101e05161020051611e016106c660003960008181610dc701528181610df60152818161115d01526118bf015260008181610215015281816117e7015261182901526000818161054801528181610af101528181610f730152818161156d015281816117c601526118500152600081816104e901528181610ac401528181610f3c0152611411015260008181610456015281816108090152818161096901528181610d550152818161147b0152818161161b015261165601526000818161038f01528181610765015281816109d701526116b60152600081816104a0015281816107a10152818161082b015281816109a801528181610e61015281816113830152818161149d01526116780152600081816101ce01528181610b7501528181610bc701526110ad01526000818161025f01528181610a9e01526111f70152600081816102930152818161071c0152610a7801526000818161035b01528181610a52015281816115ae01526115d70152600081816102f7015281816106f0015281816107d001528181610a2c01528181610bfb01528181611046015281816112a4015281816114be01526115420152600081816105bb01528181610a060152818161118d0152818161189901526119050152611e016000f3fe6080604052600436106101b75760003560e01c806373aff5af116100ec578063c20ed6711161008a578063dab8263a11610064578063dab8263a146105a9578063e7e10490146105dd578063f12723e6146105f2578063f7049d781461061f57600080fd5b8063c20ed6711461056a578063c4ae31681461057f578063c669c0781461059657600080fd5b8063ab0bcc41116100c6578063ab0bcc41146104d7578063b9ccf21d1461050b578063be040fb014610521578063c10b93581461053657600080fd5b806373aff5af146104785780638da5cb5b1461048e578063aaa30c97146104c257600080fd5b80634415c60e116101595780635249cc52116101335780635249cc52146103eb578063597e1fb51461040b5780635c975abb146104255780636c9fa59e1461044457600080fd5b80634415c60e14610349578063469048401461037d5780634e9b75b6146103c957600080fd5b80631f7d8c4a116101955780631f7d8c4a146102815780633f9942ff146102b557806342c22ff1146102e557806343d726d61461031957600080fd5b806319f76c18146101bc5780631b235437146102035780631f2f2e1b1461024d575b600080fd5b3480156101c857600080fd5b506101f07f000000000000000000000000000000000000000000000000000000000000000081565b6040519081526020015b60405180910390f35b34801561020f57600080fd5b506102377f000000000000000000000000000000000000000000000000000000000000000081565b60405164ffffffffff90911681526020016101fa565b34801561025957600080fd5b506101f07f000000000000000000000000000000000000000000000000000000000000000081565b34801561028d57600080fd5b506101f07f000000000000000000000000000000000000000000000000000000000000000081565b3480156102c157600080fd5b506002546102d59062010000900460ff1681565b60405190151581526020016101fa565b3480156102f157600080fd5b506101f07f000000000000000000000000000000000000000000000000000000000000000081565b34801561032557600080fd5b5061032e610634565b604080519384526020840192909252908201526060016101fa565b34801561035557600080fd5b506101f07f000000000000000000000000000000000000000000000000000000000000000081565b34801561038957600080fd5b506103b17f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b0390911681526020016101fa565b3480156103d557600080fd5b506103de6108c2565b6040516101fa9190611a6a565b3480156103f757600080fd5b506101f0610406366004611bb9565b610ba8565b34801561041757600080fd5b506002546102d59060ff1681565b34801561043157600080fd5b506002546102d590610100900460ff1681565b34801561045057600080fd5b506103b17f000000000000000000000000000000000000000000000000000000000000000081565b34801561048457600080fd5b506101f060005481565b34801561049a57600080fd5b506103b17f000000000000000000000000000000000000000000000000000000000000000081565b3480156104ce57600080fd5b506101f0610bf1565b3480156104e357600080fd5b506102377f000000000000000000000000000000000000000000000000000000000000000081565b34801561051757600080fd5b506101f060015481565b34801561052d57600080fd5b506101f0610c24565b34801561054257600080fd5b506102377f000000000000000000000000000000000000000000000000000000000000000081565b34801561057657600080fd5b506101f0610dc1565b34801561058b57600080fd5b50610594610e2b565b005b6101f06105a4366004611bdb565b610f0d565b3480156105b557600080fd5b506101f07f000000000000000000000000000000000000000000000000000000000000000081565b3480156105e957600080fd5b5061059461134d565b3480156105fe57600080fd5b506101f061060d366004611bb9565b60036020526000908152604090205481565b34801561062b57600080fd5b506102d5611519565b60008060003068929eee149b4bd2126854036106585763ab143c066000526004601cfd5b3068929eee149b4bd212685561066c611519565b6106895760405163f1d2165f60e01b815260040160405180910390fd5b6002805460ff1916600117905561069e6115a9565b610714576106aa61160c565b7f80bc0863d90c6c8fac9104e99d78f2aa8d867a4474dbb8bdbc32ba9d84c1c4e36001546040516106dd91815260200190565b60405180910390a15050600154905060007f00000000000000000000000000000000000000000000000000000000000000006108b1565b6001546107467f0000000000000000000000000000000000000000000000000000000000000000478390035b906116e4565b6107509190611c1d565b9250821561078b5761078b6001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001684611712565b47915081156107c7576107c76001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001683611732565b6000546107f4907f0000000000000000000000000000000000000000000000000000000000000000611c30565b90508015610850576108506001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000167f000000000000000000000000000000000000000000000000000000000000000083611775565b7ff24c64885f2398a320c41d4eb1531c9b2440ba4e78edfc733536609a4a2a1b1b8260005461088a600154876116df90919063ffffffff16565b60015460408051948552602085019390935291830152606082015260800160405180910390a15b3868929eee149b4bd2126855909192565b6040805161026081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e08101829052610100810182905261012081018290526101408101829052610160810182905261018081018290526101a081018290526101c081018290526101e08101829052610200810182905261022081018290526102408101919091526040518061026001604052807f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316815260200160006001600160a01b031681526020017f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031681526020017f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031681526020017f000000000000000000000000000000000000000000000000000000000000000081526020017f000000000000000000000000000000000000000000000000000000000000000081526020017f000000000000000000000000000000000000000000000000000000000000000081526020017f000000000000000000000000000000000000000000000000000000000000000081526020017f000000000000000000000000000000000000000000000000000000000000000081526020017f000000000000000000000000000000000000000000000000000000000000000064ffffffffff1681526020017f000000000000000000000000000000000000000000000000000000000000000064ffffffffff168152602001610b246117bb565b64ffffffffff168152600054602082015260025460ff80821615156040840152610100820481161515606084015262010000909104161515608082015260a001610b6c611519565b151581526020017f00000000000000000000000000000000000000000000000000000000000000008152602001610ba1610dc1565b9052919050565b6001600160a01b038116600090815260036020526040812054610beb907f0000000000000000000000000000000000000000000000000000000000000000611c30565b92915050565b60008054610c1f907f0000000000000000000000000000000000000000000000000000000000000000611c30565b905090565b60003068929eee149b4bd212685403610c455763ab143c066000526004601cfd5b3068929eee149b4bd212685560025462010000900460ff1615610c7b576040516338384cc160e21b815260040160405180910390fd5b60025460ff16610c9e5760405163f1d2165f60e01b815260040160405180910390fd5b610ca66117bb565b64ffffffffff164264ffffffffff161015610cd4576040516312dbbce560e01b815260040160405180910390fd5b610cdc6115a9565b610d2d576000610ceb33611878565b60405181815290915033907fd7dee2702d63ad89917b6a4da9981c90c4d24f8c2bdfd64c604ecae57d8d06519060200160405180910390a26000915050610db2565b5033600090815260036020526040812080549190558015610d7c57610d7c6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000163383611775565b60405181815233907f4896181ff8f4543cc00db9fe9b6fb7e6f032b7eb772c72ab1ec1b4d2e03b93699060200160405180910390a25b3868929eee149b4bd212685590565b600060127f000000000000000000000000000000000000000000000000000000000000000060ff161115610e2557610e1a60127f0000000000000000000000000000000000000000000000000000000000000000611c43565b610c1f90600a611d40565b50600090565b3068929eee149b4bd212685403610e4a5763ab143c066000526004601cfd5b3068929eee149b4bd2126855336001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001614610e9f576040516330cd747160e01b815260040160405180910390fd5b6002805460ff610100808304821615810261ff001990931692909217928390556040517f9077d36bc00859b5c3f320310707208543dd35092cb0a0fe117d0c6a558b148b93610ef79390049091161515815260200190565b60405180910390a13868929eee149b4bd2126855565b60003068929eee149b4bd212685403610f2e5763ab143c066000526004601cfd5b3068929eee149b4bd21268557f000000000000000000000000000000000000000000000000000000000000000064ffffffffff164264ffffffffff161080610fa457507f000000000000000000000000000000000000000000000000000000000000000064ffffffffff164264ffffffffff1610155b80610fb1575060025460ff165b80610fc35750600254610100900460ff165b80610fd6575060025462010000900460ff165b15610ff457604051630fe219dd60e21b815260040160405180910390fd5b821580610fff575034155b1561101d57604051635b0b4c9160e01b815260040160405180910390fd5b6001600160a01b0382166110445760405163d92e233d60e01b815260040160405180910390fd5b7f0000000000000000000000000000000000000000000000000000000000000000600054846110739190611c1d565b111561109257604051637858758f60e11b815260040160405180910390fd5b6001600160a01b0382166000908152600360205260409020547f0000000000000000000000000000000000000000000000000000000000000000906110d79085611c1d565b11156110f657604051631dc374f160e11b815260040160405180910390fd5b6110ff83611959565b61111c5760405163c13a806160e01b815260040160405180910390fd5b611124610dc1565b8361112d610bf1565b6111379190611c30565b10156111565760405163162908e360e11b815260040160405180910390fd5b60006111827f00000000000000000000000000000000000000000000000000000000000000008561196c565b905060006111b160127f000000000000000000000000000000000000000000000000000000000000000061196c565b905060006111bf83836116e4565b90506111cc6012826119dd565b9350836000036111ef57604051635b0b4c9160e01b815260040160405180910390fd5b600061121b857f00000000000000000000000000000000000000000000000000000000000000006116e4565b90508481019450843410156112435760405163356680b760e01b815260040160405180910390fd5b866000808282546112549190611c1d565b90915550506001600160a01b03861660009081526003602052604081208054899290611281908490611c1d565b92505081905550806001600082825461129a9190611c1d565b90915550506000547f000000000000000000000000000000000000000000000000000000000000000090036112f3576040517fcd69fa9896c4546b6ceac642f9fc45bf9603651c212d512911d735dc97f99f7290600090a15b60408051888152602081018790526001600160a01b038816917f16481c457cfa97f1508c848b8ce22b67b27711f139806040aeb662abdfc4996b910160405180910390a2505050503868929eee149b4bd212685592915050565b3068929eee149b4bd21268540361136c5763ab143c066000526004601cfd5b3068929eee149b4bd2126855336001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016146113c1576040516330cd747160e01b815260040160405180910390fd5b60025460ff16156113e557604051634d65bf2960e11b815260040160405180910390fd5b60025462010000900460ff161561140f576040516338384cc160e21b815260040160405180910390fd5b7f000000000000000000000000000000000000000000000000000000000000000064ffffffffff164264ffffffffff161061145d5760405163f1d2165f60e01b815260040160405180910390fd5b6002805462ff00001916620100001790556114e26001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000167f00000000000000000000000000000000000000000000000000000000000000007f0000000000000000000000000000000000000000000000000000000000000000611775565b6040517f4717c1fcb8954ad4f0da8b5d368d4064a1c750f8639c89dc534ad6070697078290600090a13868929eee149b4bd2126855565b60025460009062010000900460ff1680611535575060025460ff165b156115405750600090565b7f0000000000000000000000000000000000000000000000000000000000000000600054148061159e57507f000000000000000000000000000000000000000000000000000000000000000064ffffffffff164264ffffffffff1610155b15610e255750600190565b6000807f00000000000000000000000000000000000000000000000000000000000000001180156115fb57507f0000000000000000000000000000000000000000000000000000000000000000600054105b156116065750600090565b50600190565b60006116416001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001630611a3e565b9050801561169d5761169d6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000167f000000000000000000000000000000000000000000000000000000000000000083611775565b600154156116dc576001546116dc906001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001690611712565b50565b900390565b6000816000190483118202156117025763bac65e5b6000526004601cfd5b50670de0b6b3a764000091020490565b60003860003884865af161172e5763b12d13eb6000526004601cfd5b5050565b804710156117485763b12d13eb6000526004601cfd5b6000386000388486620186a0f161172e57816000526073600b5360ff6020536016600b82f061172e573838fd5b816014528060345263a9059cbb60601b60005260206000604460106000875af13d1560016000511417166117b1576390b8ec186000526004601cfd5b6000603452505050565b60006201518061180b7f00000000000000000000000000000000000000000000000000000000000000007f0000000000000000000000000000000000000000000000000000000000000000611d4f565b64ffffffffff16108061182157506118216115a9565b1561184b57507f000000000000000000000000000000000000000000000000000000000000000090565b610c1f7f000000000000000000000000000000000000000000000000000000000000000062015180611d74565b6001600160a01b03811660009081526003602052604081205481906118e4907f000000000000000000000000000000000000000000000000000000000000000090610740907f00000000000000000000000000000000000000000000000000000000000000009061196c565b6001600160a01b0384166000908152600360205260408120559050611929817f00000000000000000000000000000000000000000000000000000000000000006116e4565b915060008111801561193b5750600082115b15611953576119536001600160a01b03841683611712565b50919050565b6000611963610dc1565b90911015919050565b80601260ff841610156119a5576000611986846012611c43565b905061199381600a611d40565b61199d9083611d92565b915050610beb565b60128360ff161115610beb5760006119be601285611c43565b90506119cb81600a611d40565b6119d59083611da9565b949350505050565b80601260ff84161015611a0e5760006119f7846012611c43565b9050611a0481600a611d40565b61199d9083611da9565b60128360ff161115610beb576000611a27601285611c43565b9050611a3481600a611d40565b6119d59083611d92565b6000816014526370a0823160601b60005260208060246010865afa601f3d111660205102905092915050565b81516001600160a01b0316815261026081016020830151611a9660208401826001600160a01b03169052565b506040830151611ab160408401826001600160a01b03169052565b506060830151611acc60608401826001600160a01b03169052565b506080830151608083015260a083015160a083015260c083015160c083015260e083015160e083015261010080840151818401525061012080840151611b1a8285018264ffffffffff169052565b50506101408381015164ffffffffff90811691840191909152610160808501519091169083015261018080840151908301526101a0808401511515908301526101c0808401511515908301526101e08084015115159083015261020080840151151590830152610220808401519083015261024092830151929091019190915290565b80356001600160a01b0381168114611bb457600080fd5b919050565b600060208284031215611bcb57600080fd5b611bd482611b9d565b9392505050565b60008060408385031215611bee57600080fd5b82359150611bfe60208401611b9d565b90509250929050565b634e487b7160e01b600052601160045260246000fd5b80820180821115610beb57610beb611c07565b81810381811115610beb57610beb611c07565b60ff8281168282160390811115610beb57610beb611c07565b600181815b80851115611c97578160001904821115611c7d57611c7d611c07565b80851615611c8a57918102915b93841c9390800290611c61565b509250929050565b600082611cae57506001610beb565b81611cbb57506000610beb565b8160018114611cd15760028114611cdb57611cf7565b6001915050610beb565b60ff841115611cec57611cec611c07565b50506001821b610beb565b5060208310610133831016604e8410600b8410161715611d1a575081810a610beb565b611d248383611c5c565b8060001904821115611d3857611d38611c07565b029392505050565b6000611bd460ff841683611c9f565b64ffffffffff828116828216039080821115611d6d57611d6d611c07565b5092915050565b64ffffffffff818116838216019080821115611d6d57611d6d611c07565b8082028115828204841417610beb57610beb611c07565b600082611dc657634e487b7160e01b600052601260045260246000fd5b50049056fea26469706673582212202e387a7eebb4817f76067e16639d58a0af3fb68bbc23f72c07a996a89b8f0ae264736f6c63430008190033a26469706673582212207e4664e15fd552095b995fefaa9c1f21229bf66fd278cf39e89e40a9ec58f30764736f6c63430008190033

Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
[ Download: CSV Export  ]
[ 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.