ETH Price: $3,432.07 (+0.36%)
Gas: 54 Gwei

Contract

0xb8d050D6413257f1CbaFFC82e9D6a583509D29df
 

Overview

ETH Balance

0 ETH

Eth Value

$0.00

Multichain Info

No addresses found
Transaction Hash
Method
Block
From
To
Value
Create184220172023-10-24 18:51:23129 days ago1698173483IN
0xb8d050D6...3509D29df
0 ETH0.0844325123.14218098

Latest 3 internal transactions

Advanced mode:
Parent Txn Hash Block From To Value
184220172023-10-24 18:51:23129 days ago1698173483
0xb8d050D6...3509D29df
 Contract Creation0 ETH
184220172023-10-24 18:51:23129 days ago1698173483
0xb8d050D6...3509D29df
 Contract Creation0 ETH
184220132023-10-24 18:50:35129 days ago1698173435  Contract Creation0 ETH
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
BloomFactory

Compiler Version
v0.8.19+commit.7dd6d404

Optimization Enabled:
Yes with 100 runs

Other Settings:
paris EvmVersion
File 1 of 24 : BloomFactory.sol
// SPDX-License-Identifier: BUSL-1.1
/*
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ•—β–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ–ˆβ•—β–‘β–‘β–‘β–ˆβ–ˆβ–ˆβ•—
β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ–ˆβ–ˆβ•‘
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•¦β•β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β–ˆβ–ˆβ–ˆβ–ˆβ•”β–ˆβ–ˆβ•‘
β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•¦β•β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘β–‘β•šβ•β•β–‘β–ˆβ–ˆβ•‘
β•šβ•β•β•β•β•β•β–‘β•šβ•β•β•β•β•β•β•β–‘β•šβ•β•β•β•β•β–‘β–‘β•šβ•β•β•β•β•β–‘β•šβ•β•β–‘β–‘β–‘β–‘β–‘β•šβ•β•
*/

pragma solidity 0.8.19;

import {EnumerableSet} from "openzeppelin/utils/structs/EnumerableSet.sol";
import {Ownable2Step} from "openzeppelin/access/Ownable2Step.sol";
import {LibRLP} from "solady/utils/LibRLP.sol";

import {BloomPool} from "./BloomPool.sol";
import {SwapFacility} from "./SwapFacility.sol";

import {IBloomFactory} from "./interfaces/IBloomFactory.sol";
import {IWhitelist} from "./interfaces/IWhitelist.sol";
import {IRegistry} from "./interfaces/IRegistry.sol";

contract BloomFactory is IBloomFactory, Ownable2Step {
    // =================== Storage ===================   
    address private _lastCreatedPool;
    mapping(address => bool) private _isPoolFromFactory;

    constructor(address owner) Ownable2Step() {
        _transferOwnership(owner);
    }

    function getLastCreatedPool() external view override returns (address) {
        return _lastCreatedPool;
    }

    function isPoolFromFactory(address pool)
        external
        view
        override
        returns (bool) 
    {
        return _isPoolFromFactory[pool];
    }

    function create(
        string memory name,
        string memory symbol,
        address underlyingToken,
        address billToken,
        IRegistry exchangeRateRegistry,
        PoolParams calldata poolParams,
        SwapFacilityParams calldata swapFacilityParams,
        uint256 factoryNonce
    ) external override onlyOwner returns (BloomPool) {
        // Precompute the address of the BloomPool
        address expectedPoolAddress = LibRLP.computeAddress(address(this), factoryNonce + 1);
        
        // Deploys SwapFacility
        SwapFacility swapFacility = new SwapFacility(
            underlyingToken,
            billToken,
            swapFacilityParams.underlyingTokenOracle,
            swapFacilityParams.billyTokenOracle,
            IWhitelist(swapFacilityParams.swapWhitelist),
            swapFacilityParams.spread,
            expectedPoolAddress,
            swapFacilityParams.minStableValue,
            swapFacilityParams.maxBillyValue
        );

        // Deploys BloomPool
        BloomPool bloomPool = new BloomPool(
            underlyingToken,
            billToken,
            IWhitelist(poolParams.borrowerWhiteList),
            address(swapFacility),
            poolParams.treasury,
            poolParams.lenderReturnBpsFeed,
            poolParams.emergencyHandler,
            poolParams.leverageBps,
            poolParams.minBorrowDeposit,
            poolParams.commitPhaseDuration,
            poolParams.swapTimeout,
            poolParams.poolPhaseDuration,
            poolParams.lenderReturnFee,
            poolParams.borrowerReturnFee,
            name,
            symbol
        );

        // Verify that the deployed BloomPool address matches the expected address
        // If this isn't the case we should revert because the swap facility is associated 
        //     with the wrong address
        if (address(bloomPool) != expectedPoolAddress) {
            revert InvalidPoolAddress();
        }

        // Add the pool to the set of pools & store the last created pool
        _isPoolFromFactory[address(bloomPool)] = true;
        _lastCreatedPool = address(bloomPool);

        // Register the pool in the exchange rate registry & activate the token
        exchangeRateRegistry.registerToken(bloomPool);

        emit NewBloomPoolCreated(address(bloomPool), address(swapFacility));

        return bloomPool;
    }
}

File 2 of 24 : EnumerableSet.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/structs/EnumerableSet.sol)
// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.

pragma solidity ^0.8.0;

/**
 * @dev Library for managing
 * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
 * types.
 *
 * Sets have the following properties:
 *
 * - Elements are added, removed, and checked for existence in constant time
 * (O(1)).
 * - Elements are enumerated in O(n). No guarantees are made on the ordering.
 *
 * ```solidity
 * contract Example {
 *     // Add the library methods
 *     using EnumerableSet for EnumerableSet.AddressSet;
 *
 *     // Declare a set state variable
 *     EnumerableSet.AddressSet private mySet;
 * }
 * ```
 *
 * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
 * and `uint256` (`UintSet`) are supported.
 *
 * [WARNING]
 * ====
 * Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
 * unusable.
 * See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
 *
 * In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an
 * array of EnumerableSet.
 * ====
 */
library EnumerableSet {
    // To implement this library for multiple types with as little code
    // repetition as possible, we write it in terms of a generic Set type with
    // bytes32 values.
    // The Set implementation uses private functions, and user-facing
    // implementations (such as AddressSet) are just wrappers around the
    // underlying Set.
    // This means that we can only create new EnumerableSets for types that fit
    // in bytes32.

    struct Set {
        // Storage of set values
        bytes32[] _values;
        // Position of the value in the `values` array, plus 1 because index 0
        // means a value is not in the set.
        mapping(bytes32 => uint256) _indexes;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function _add(Set storage set, bytes32 value) private returns (bool) {
        if (!_contains(set, value)) {
            set._values.push(value);
            // The value is stored at length-1, but we add 1 to all indexes
            // and use 0 as a sentinel value
            set._indexes[value] = set._values.length;
            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function _remove(Set storage set, bytes32 value) private returns (bool) {
        // We read and store the value's index to prevent multiple reads from the same storage slot
        uint256 valueIndex = set._indexes[value];

        if (valueIndex != 0) {
            // Equivalent to contains(set, value)
            // To delete an element from the _values array in O(1), we swap the element to delete with the last one in
            // the array, and then remove the last element (sometimes called as 'swap and pop').
            // This modifies the order of the array, as noted in {at}.

            uint256 toDeleteIndex = valueIndex - 1;
            uint256 lastIndex = set._values.length - 1;

            if (lastIndex != toDeleteIndex) {
                bytes32 lastValue = set._values[lastIndex];

                // Move the last value to the index where the value to delete is
                set._values[toDeleteIndex] = lastValue;
                // Update the index for the moved value
                set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex
            }

            // Delete the slot where the moved value was stored
            set._values.pop();

            // Delete the index for the deleted slot
            delete set._indexes[value];

            return true;
        } else {
            return false;
        }
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function _contains(Set storage set, bytes32 value) private view returns (bool) {
        return set._indexes[value] != 0;
    }

    /**
     * @dev Returns the number of values on the set. O(1).
     */
    function _length(Set storage set) private view returns (uint256) {
        return set._values.length;
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function _at(Set storage set, uint256 index) private view returns (bytes32) {
        return set._values[index];
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function _values(Set storage set) private view returns (bytes32[] memory) {
        return set._values;
    }

    // Bytes32Set

    struct Bytes32Set {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _add(set._inner, value);
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
        return _remove(set._inner, value);
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
        return _contains(set._inner, value);
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(Bytes32Set storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
        return _at(set._inner, index);
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
        bytes32[] memory store = _values(set._inner);
        bytes32[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }

    // AddressSet

    struct AddressSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(AddressSet storage set, address value) internal returns (bool) {
        return _add(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(AddressSet storage set, address value) internal returns (bool) {
        return _remove(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(AddressSet storage set, address value) internal view returns (bool) {
        return _contains(set._inner, bytes32(uint256(uint160(value))));
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(AddressSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(AddressSet storage set, uint256 index) internal view returns (address) {
        return address(uint160(uint256(_at(set._inner, index))));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(AddressSet storage set) internal view returns (address[] memory) {
        bytes32[] memory store = _values(set._inner);
        address[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }

    // UintSet

    struct UintSet {
        Set _inner;
    }

    /**
     * @dev Add a value to a set. O(1).
     *
     * Returns true if the value was added to the set, that is if it was not
     * already present.
     */
    function add(UintSet storage set, uint256 value) internal returns (bool) {
        return _add(set._inner, bytes32(value));
    }

    /**
     * @dev Removes a value from a set. O(1).
     *
     * Returns true if the value was removed from the set, that is if it was
     * present.
     */
    function remove(UintSet storage set, uint256 value) internal returns (bool) {
        return _remove(set._inner, bytes32(value));
    }

    /**
     * @dev Returns true if the value is in the set. O(1).
     */
    function contains(UintSet storage set, uint256 value) internal view returns (bool) {
        return _contains(set._inner, bytes32(value));
    }

    /**
     * @dev Returns the number of values in the set. O(1).
     */
    function length(UintSet storage set) internal view returns (uint256) {
        return _length(set._inner);
    }

    /**
     * @dev Returns the value stored at position `index` in the set. O(1).
     *
     * Note that there are no guarantees on the ordering of values inside the
     * array, and it may change when more values are added or removed.
     *
     * Requirements:
     *
     * - `index` must be strictly less than {length}.
     */
    function at(UintSet storage set, uint256 index) internal view returns (uint256) {
        return uint256(_at(set._inner, index));
    }

    /**
     * @dev Return the entire set in an array
     *
     * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
     * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
     * this function has an unbounded cost, and using it as part of a state-changing function may render the function
     * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
     */
    function values(UintSet storage set) internal view returns (uint256[] memory) {
        bytes32[] memory store = _values(set._inner);
        uint256[] memory result;

        /// @solidity memory-safe-assembly
        assembly {
            result := store
        }

        return result;
    }
}

File 3 of 24 : Ownable2Step.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (access/Ownable2Step.sol)

pragma solidity ^0.8.0;

import "./Ownable.sol";

/**
 * @dev Contract module which provides access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * By default, the owner account will be the one that deploys the contract. This
 * can later be changed with {transferOwnership} and {acceptOwnership}.
 *
 * This module is used through inheritance. It will make available all functions
 * from parent (Ownable).
 */
abstract contract Ownable2Step is Ownable {
    address private _pendingOwner;

    event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Returns the address of the pending owner.
     */
    function pendingOwner() public view virtual returns (address) {
        return _pendingOwner;
    }

    /**
     * @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual override onlyOwner {
        _pendingOwner = newOwner;
        emit OwnershipTransferStarted(owner(), newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual override {
        delete _pendingOwner;
        super._transferOwnership(newOwner);
    }

    /**
     * @dev The new owner accepts the ownership transfer.
     */
    function acceptOwnership() public virtual {
        address sender = _msgSender();
        require(pendingOwner() == sender, "Ownable2Step: caller is not the new owner");
        _transferOwnership(sender);
    }
}

File 4 of 24 : LibRLP.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

/// @notice Library for computing contract addresses from their deployer and nonce.
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/LibRLP.sol)
/// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/LibRLP.sol)
library LibRLP {
    /// @dev Returns the address where a contract will be stored if deployed via
    /// `deployer` with `nonce` using the `CREATE` opcode.
    /// For the specification of the Recursive Length Prefix (RLP)
    /// encoding scheme, please refer to p. 19 of the Ethereum Yellow Paper
    /// (https://ethereum.github.io/yellowpaper/paper.pdf)
    /// and the Ethereum Wiki (https://eth.wiki/fundamentals/rlp).
    ///
    /// Based on the EIP-161 (https://github.com/ethereum/EIPs/blob/master/EIPS/eip-161.md)
    /// specification, all contract accounts on the Ethereum mainnet are initiated with
    /// `nonce = 1`. Thus, the first contract address created by another contract
    /// is calculated with a non-zero nonce.
    ///
    /// The theoretical allowed limit, based on EIP-2681
    /// (https://eips.ethereum.org/EIPS/eip-2681), for an account nonce is 2**64-2.
    ///
    /// Caution! This function will NOT check that the nonce is within the theoretical range.
    /// This is for performance, as exceeding the range is extremely impractical.
    /// It is the user's responsibility to ensure that the nonce is valid
    /// (e.g. no dirty bits after packing / unpacking).
    function computeAddress(address deployer, uint256 nonce)
        internal
        pure
        returns (address deployed)
    {
        /// @solidity memory-safe-assembly
        assembly {
            for {} 1 {} {
                // The integer zero is treated as an empty byte string,
                // and as a result it only has a length prefix, 0x80,
                // computed via `0x80 + 0`.

                // A one-byte integer in the [0x00, 0x7f] range uses its
                // own value as a length prefix,
                // there is no additional `0x80 + length` prefix that precedes it.
                if iszero(gt(nonce, 0x7f)) {
                    mstore(0x00, deployer)
                    // Using `mstore8` instead of `or` naturally cleans
                    // any dirty upper bits of `deployer`.
                    mstore8(0x0b, 0x94)
                    mstore8(0x0a, 0xd6)
                    // `shl` 7 is equivalent to multiplying by 0x80.
                    mstore8(0x20, or(shl(7, iszero(nonce)), nonce))
                    deployed := keccak256(0x0a, 0x17)
                    break
                }
                let i := 8
                // Just use a loop to generalize all the way with minimal bytecode size.
                for {} shr(i, nonce) { i := add(i, 8) } {}
                // `shr` 3 is equivalent to dividing by 8.
                i := shr(3, i)
                // Store in descending slot sequence to overlap the values correctly.
                mstore(i, nonce)
                mstore(0x00, shl(8, deployer))
                mstore8(0x1f, add(0x80, i))
                mstore8(0x0a, 0x94)
                mstore8(0x09, add(0xd6, i))
                deployed := keccak256(0x09, add(0x17, i))
                break
            }
        }
    }
}

File 5 of 24 : BloomPool.sol
// SPDX-License-Identifier: BUSL-1.1
/*
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ•—β–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ–ˆβ•—β–‘β–‘β–‘β–ˆβ–ˆβ–ˆβ•—
β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ–ˆβ–ˆβ•‘
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•¦β•β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β–ˆβ–ˆβ–ˆβ–ˆβ•”β–ˆβ–ˆβ•‘
β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•¦β•β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘β–‘β•šβ•β•β–‘β–ˆβ–ˆβ•‘
β•šβ•β•β•β•β•β•β–‘β•šβ•β•β•β•β•β•β•β–‘β•šβ•β•β•β•β•β–‘β–‘β•šβ•β•β•β•β•β–‘β•šβ•β•β–‘β–‘β–‘β–‘β–‘β•šβ•β•
*/

pragma solidity 0.8.19;

import {ERC20} from "solmate/tokens/ERC20.sol";
import {IBloomPool, State} from "./interfaces/IBloomPool.sol";
import {IEmergencyHandler} from "./interfaces/IEmergencyHandler.sol";
import {ISwapRecipient} from "./interfaces/ISwapRecipient.sol";

import {SafeTransferLib} from "solady/utils/SafeTransferLib.sol";
import {SafeCastLib} from "solady/utils/SafeCastLib.sol";
import {FixedPointMathLib as Math} from "solady/utils/FixedPointMathLib.sol";
import {CommitmentsLib, Commitments, AssetCommitment} from "./lib/CommitmentsLib.sol";

import {IWhitelist} from "./interfaces/IWhitelist.sol";
import {ISwapFacility} from "./interfaces/ISwapFacility.sol";
import {IBPSFeed} from "./interfaces/IBPSFeed.sol";
import {IOracle} from "./interfaces/IOracle.sol";

contract BloomPool is IBloomPool, ISwapRecipient, ERC20 {
    using CommitmentsLib for Commitments;
    using CommitmentsLib for AssetCommitment;
    using SafeTransferLib for address;
    using SafeCastLib for uint256;

    uint256 internal constant BPS = 1e4; // Represents Scaling & Initial BPS Feed Rate
    uint256 internal constant ONE_YEAR = 360 days;

    // =============== Core Parameters ===============

    address public immutable UNDERLYING_TOKEN;
    address public immutable BILL_TOKEN;
    IWhitelist public immutable WHITELIST;
    address public immutable SWAP_FACILITY;
    address public immutable TREASURY;
    address public immutable EMERGENCY_HANDLER;
    address public immutable LENDER_RETURN_BPS_FEED;
    uint256 public immutable LEVERAGE_BPS;
    uint256 public immutable MIN_BORROW_DEPOSIT;
    uint256 public immutable COMMIT_PHASE_END;
    uint256 public immutable PRE_HOLD_SWAP_TIMEOUT_END;
    uint256 public immutable POST_HOLD_SWAP_TIMEOUT_END;
    uint256 public immutable POOL_PHASE_END;
    uint256 public immutable POOL_PHASE_DURATION;
    uint256 public immutable LENDER_RETURN_FEE;
    uint256 public immutable BORROWER_RETURN_FEE;

    // =================== Storage ===================

    Commitments internal borrowers;
    Commitments internal lenders;
    State internal setState = State.Commit;
    State internal stateBeforeEmergency;
    uint128 internal borrowerDistribution;
    uint128 internal totalBorrowerShares;
    uint128 internal lenderDistribution;
    uint128 internal totalLenderShares;

    // ================== Modifiers ==================

    modifier onlyState(State expectedState) {
        State currentState = state();
        if (currentState != expectedState) revert InvalidState(currentState);
        _;
    }

    modifier onlyAfterState(State lastInvalidState) {
        State currentState = state();
        if (currentState <= lastInvalidState) revert InvalidState(currentState);
        _;
    }

    modifier onlyEmergencyHandler() {
        if (msg.sender != EMERGENCY_HANDLER) revert NotEmergencyHandler();
        _;
    }

    constructor(
        address underlyingToken,
        address billToken,
        IWhitelist whitelist,
        address swapFacility,
        address treasury,
        address lenderReturnBpsFeed,
        address emergencyHandler,
        uint256 leverageBps,
        uint256 minBorrowDeposit,
        uint256 commitPhaseDuration,
        uint256 swapTimeout,
        uint256 poolPhaseDuration,
        uint256 lenderReturnFee,
        uint256 borrowerReturnFee,
        string memory name,
        string memory symbol
    ) ERC20(name, symbol, ERC20(underlyingToken).decimals()) {
        UNDERLYING_TOKEN = underlyingToken;
        BILL_TOKEN = billToken;
        WHITELIST = whitelist;
        SWAP_FACILITY = swapFacility;
        TREASURY = treasury;
        LENDER_RETURN_BPS_FEED = lenderReturnBpsFeed;
        EMERGENCY_HANDLER = emergencyHandler;
        LEVERAGE_BPS = leverageBps;
        MIN_BORROW_DEPOSIT = minBorrowDeposit;
        COMMIT_PHASE_END = block.timestamp + commitPhaseDuration;
        PRE_HOLD_SWAP_TIMEOUT_END = block.timestamp + commitPhaseDuration + swapTimeout;
        POOL_PHASE_END = block.timestamp + commitPhaseDuration + poolPhaseDuration;
        POOL_PHASE_DURATION = poolPhaseDuration;
        POST_HOLD_SWAP_TIMEOUT_END = block.timestamp + commitPhaseDuration + poolPhaseDuration + (swapTimeout * 2 );
        LENDER_RETURN_FEE = lenderReturnFee;
        BORROWER_RETURN_FEE = borrowerReturnFee;
    }

    // =============== Deposit Methods ===============

    /**
     * @inheritdoc IBloomPool
     */
    function depositBorrower(uint256 amount, bytes32[] calldata proof)
        external
        onlyState(State.Commit)
        returns (uint256 newId)
    {
        if (amount < MIN_BORROW_DEPOSIT) revert CommitTooSmall();
        if (!IWhitelist(WHITELIST).isWhitelisted(msg.sender, proof)) revert NotWhitelisted();
        UNDERLYING_TOKEN.safeTransferFrom(msg.sender, address(this), amount);
        uint256 cumulativeAmountEnd;
        (newId, cumulativeAmountEnd) = borrowers.add(msg.sender, amount);
        emit BorrowerCommit(msg.sender, newId, amount, cumulativeAmountEnd);
    }

    /**
     * @inheritdoc IBloomPool
     */
    function depositLender(uint256 amount) external onlyState(State.Commit) returns (uint256 newId) {
        if (amount == 0) revert CommitTooSmall();
        UNDERLYING_TOKEN.safeTransferFrom(msg.sender, address(this), amount);
        uint256 cumulativeAmountEnd;
        (newId, cumulativeAmountEnd) = lenders.add(msg.sender, amount);
        emit LenderCommit(msg.sender, newId, amount, cumulativeAmountEnd);
    }

    // =========== Further Deposit Methods ===========

    /**
     * @inheritdoc IBloomPool
     */
    function processBorrowerCommit(uint256 id) external onlyAfterState(State.Commit) {
        AssetCommitment storage commitment = borrowers.commitments[id];
        if (commitment.cumulativeAmountEnd == 0) revert NoCommitToProcess();
        uint256 committedBorrowValue = lenders.totalAssetsCommitted * BPS / LEVERAGE_BPS;
        (uint256 includedAmount, uint256 excludedAmount) = commitment.getAmountSplit(committedBorrowValue);
        commitment.committedAmount = includedAmount.toUint128();
        commitment.cumulativeAmountEnd = 0;
        address owner = commitment.owner;
        emit BorrowerCommitmentProcessed(owner, id, includedAmount, excludedAmount);
        if (excludedAmount > 0) UNDERLYING_TOKEN.safeTransfer(owner, excludedAmount);
    }

    /**
     * @inheritdoc IBloomPool
     */
    function processLenderCommit(uint256 id) external onlyAfterState(State.Commit) {
        AssetCommitment storage commitment = lenders.commitments[id];
        if (commitment.cumulativeAmountEnd == 0) revert NoCommitToProcess();
        uint256 committedBorrowValue = borrowers.totalAssetsCommitted * LEVERAGE_BPS / BPS;
        (uint256 includedAmount, uint256 excludedAmount) = commitment.getAmountSplit(committedBorrowValue);
        address owner = commitment.owner;
        delete lenders.commitments[id];
        _mint(owner, includedAmount);
        emit LenderCommitmentProcessed(owner, id, includedAmount, excludedAmount);
        if (excludedAmount > 0) UNDERLYING_TOKEN.safeTransfer(owner, excludedAmount);
    }

    // ======== Swap State Management Methods ========

    /**
     * @inheritdoc IBloomPool
     */
    function initiatePreHoldSwap(bytes32[] calldata proof) external onlyState(State.ReadyPreHoldSwap) {
        uint256 amountToSwap = totalMatchAmount() * (LEVERAGE_BPS + BPS) / LEVERAGE_BPS;
        // Reset allowance to zero before to ensure can always set for weird tokens like USDT.
        UNDERLYING_TOKEN.safeApprove(SWAP_FACILITY, 0);
        UNDERLYING_TOKEN.safeApprove(SWAP_FACILITY, amountToSwap);
        emit ExplictStateTransition(State.ReadyPreHoldSwap, setState = State.PendingPreHoldSwap);
        ISwapFacility(SWAP_FACILITY).swap(UNDERLYING_TOKEN, BILL_TOKEN, amountToSwap, proof);
    }

    /**
     * @inheritdoc IBloomPool
     */
    function initiatePostHoldSwap(bytes32[] calldata proof) external onlyState(State.ReadyPostHoldSwap) {
        uint256 amountToSwap = ERC20(BILL_TOKEN).balanceOf(address(this));
        // Reset allowance to zero before to ensure can always set for weird tokens like USDT.
        BILL_TOKEN.safeApprove(SWAP_FACILITY, 0);
        BILL_TOKEN.safeApprove(SWAP_FACILITY, amountToSwap);
        emit ExplictStateTransition(State.ReadyPostHoldSwap, setState = State.PendingPostHoldSwap);
        ISwapFacility(SWAP_FACILITY).swap(BILL_TOKEN, UNDERLYING_TOKEN, amountToSwap, proof);
    }

    /**
     * @inheritdoc ISwapRecipient
     */
    function completeSwap(address outToken, uint256 outAmount) external {
        if (msg.sender != SWAP_FACILITY) revert NotSwapFacility();
        State currentState = state();
        if (currentState == State.PendingPreHoldSwap) {
            if (outToken != BILL_TOKEN) revert InvalidOutToken(outToken);
            emit ExplictStateTransition(State.PendingPreHoldSwap, setState = State.Holding);
            return;
        }
        if (currentState == State.PendingPostHoldSwap) {
            if (outToken != UNDERLYING_TOKEN) revert InvalidOutToken(outToken);
            uint256 totalMatched = totalMatchAmount();

            // Lenders get paid first, borrowers carry any shortfalls/excesses due to slippage.
            uint256 lenderReturn = _calculateLenderReturn(totalMatched, outAmount);

            uint256 borrowerReturn = outAmount - lenderReturn;
            uint256 lenderReturnFee = (lenderReturn - totalMatched) * LENDER_RETURN_FEE / BPS;
            uint256 borrowerReturnFee = borrowerReturn * BORROWER_RETURN_FEE / BPS;

            borrowerDistribution = (borrowerReturn - borrowerReturnFee).toUint128();
            totalBorrowerShares = uint256(totalMatched * BPS / LEVERAGE_BPS).toUint128();

            lenderDistribution = (lenderReturn - lenderReturnFee).toUint128();
            totalLenderShares = uint256(totalMatched).toUint128();

            UNDERLYING_TOKEN.safeTransfer(TREASURY, lenderReturnFee + borrowerReturnFee);

            emit ExplictStateTransition(State.PendingPostHoldSwap, setState = State.FinalWithdraw);
            return;
        }
        revert InvalidState(currentState);
    }

    // =========== Final Withdraw Methods ============

    /**
     * @inheritdoc IBloomPool
     */
    function withdrawBorrower(uint256 id) external onlyState(State.FinalWithdraw) {
        AssetCommitment storage commitment = borrowers.commitments[id];
        if (commitment.cumulativeAmountEnd != 0) revert CanOnlyWithdrawProcessedCommit(id);
        address owner = commitment.owner;
        if (owner == address(0)) revert NoCommitToWithdraw();
        uint256 shares = commitment.committedAmount;
        uint256 currentBorrowerDist = borrowerDistribution;
        uint256 sharesLeft = totalBorrowerShares;
        uint256 claimAmount = shares * currentBorrowerDist / sharesLeft;
        borrowerDistribution = (currentBorrowerDist - claimAmount).toUint128();
        totalBorrowerShares = (sharesLeft - shares).toUint128();
        delete borrowers.commitments[id];
        emit BorrowerWithdraw(owner, id, claimAmount);
        UNDERLYING_TOKEN.safeTransfer(owner, claimAmount);
    }

    /**
     * @inheritdoc IBloomPool
     */
    function withdrawLender(uint256 shares) external onlyState(State.FinalWithdraw) {
        _burn(msg.sender, shares);
        uint256 currentLenderDist = lenderDistribution;
        uint256 sharesLeft = totalLenderShares;
        uint256 claimAmount = shares * currentLenderDist / sharesLeft;
        lenderDistribution = (currentLenderDist - claimAmount).toUint128();
        totalLenderShares = (sharesLeft - shares).toUint128();
        emit LenderWithdraw(msg.sender, shares, claimAmount);
        UNDERLYING_TOKEN.safeTransfer(msg.sender, claimAmount);
    }

    // ========= Emergency Withdraw Methods ==========

    function emergencyWithdraw() external onlyState(State.EmergencyExit) {
        uint256 underlyingBalance = UNDERLYING_TOKEN.balanceOf(address(this));
        uint256 billBalance = BILL_TOKEN.balanceOf(address(this));
        uint256 underlyingPrice = 1e8;

        IOracle billOracle = IOracle(ISwapFacility(SWAP_FACILITY).billyTokenOracle());
        uint256 currentBillPrice = uint256(billOracle.latestAnswer());
        if (currentBillPrice <= 0) revert OracleAnswerNegative();

        uint256 underlyingDecimals = ERC20(UNDERLYING_TOKEN).decimals();
        uint256 billDecimals = ERC20(BILL_TOKEN).decimals();
        uint256 scalingFactor = 10 ** (billDecimals - underlyingDecimals);
        
        uint256 additionalValue = BILL_TOKEN.balanceOf(address(this)) * currentBillPrice / underlyingPrice / scalingFactor;
        uint256 expectedTotalBalance = underlyingBalance + additionalValue;
       
        uint256 lenderDistro;
        uint256 borrowerDistro;
        uint256 totalMatched;
        bool yieldGenerating;
        // If we are in the emergency exit state before the end of the pool phase then we
        //    know this exit occured during the pre-hold swap phase, so users should be able
        //    to redeem USDC 1 for 1.
        if (block.timestamp >= POOL_PHASE_END) {
            totalMatched = totalMatchAmount();
            lenderDistro = _calculateLenderReturn(totalMatched, expectedTotalBalance);
            borrowerDistro = expectedTotalBalance - lenderDistro;
            yieldGenerating = true;
        } else {
            lenderDistro = lenders.totalAssetsCommitted;
            borrowerDistro = expectedTotalBalance - lenderDistro;
            yieldGenerating = false;
        }

        if (underlyingBalance > 0) {
            UNDERLYING_TOKEN.safeTransferAll(EMERGENCY_HANDLER);
            emit EmergencyWithdrawExecuted(address(this), EMERGENCY_HANDLER, underlyingBalance);
        }
        
        if (billBalance > 0) {
            BILL_TOKEN.safeTransferAll(EMERGENCY_HANDLER);
            emit EmergencyWithdrawExecuted(address(this), EMERGENCY_HANDLER, billBalance);
        }

        IEmergencyHandler.RedemptionInfo memory redemptionInfo = IEmergencyHandler.RedemptionInfo(
            IEmergencyHandler.Token(UNDERLYING_TOKEN, underlyingPrice, underlyingDecimals),
            IEmergencyHandler.Token(BILL_TOKEN, currentBillPrice, billDecimals),
            IEmergencyHandler.PoolAccounting(
                lenderDistro,
                borrowerDistro,
                totalMatched,
                totalMatched * BPS / LEVERAGE_BPS,
                underlyingBalance,
                billBalance
            ),
            yieldGenerating
        );

        IEmergencyHandler(EMERGENCY_HANDLER).registerPool(redemptionInfo);
    }

    function executeEmergencyBurn(
        address from,
        uint256 amount
    ) external onlyState(State.EmergencyExit) onlyEmergencyHandler {
        emit EmergencyBurn(from, amount);
        _burn(from, amount);
    }

    // ================ View Methods =================

    /// @notice Returns amount of lender-to-borrower demand that was matched.
    function totalMatchAmount() public view returns (uint256) {
        uint256 borrowDemand = borrowers.totalAssetsCommitted * LEVERAGE_BPS / BPS;
        uint256 lendDemand = lenders.totalAssetsCommitted;
        return Math.min(borrowDemand, lendDemand);
    }

    function state() public view returns (State) {
        if (block.timestamp < COMMIT_PHASE_END) {
            return State.Commit;
        }
        State lastState = setState;
        if (lastState == State.Commit && block.timestamp >= COMMIT_PHASE_END) {
            return State.ReadyPreHoldSwap;
        }
        if (lastState == State.PendingPreHoldSwap && block.timestamp >= PRE_HOLD_SWAP_TIMEOUT_END) {
            return State.EmergencyExit;
        }
        if (lastState == State.Holding && block.timestamp >= POOL_PHASE_END) {
            return State.ReadyPostHoldSwap;
        }
        if (lastState == State.PendingPostHoldSwap && block.timestamp >= POST_HOLD_SWAP_TIMEOUT_END) {
            return State.EmergencyExit;
        }
        return lastState;
    }

    function getBorrowCommitment(uint256 id) external view returns (AssetCommitment memory) {
        return borrowers.get(id);
    }

    function getLenderCommitment(uint256 id) external view returns (AssetCommitment memory) {
        return lenders.get(id);
    }

    function getTotalBorrowCommitment()
        external
        view
        returns (uint256 totalAssetsCommitted, uint256 totalCommitmentCount)
    {
        totalAssetsCommitted = borrowers.totalAssetsCommitted;
        totalCommitmentCount = borrowers.commitmentCount;
    }

    function getTotalLendCommitment()
        external
        view
        returns (uint256 totalAssetsCommitted, uint256 totalCommitmentCount)
    {
        totalAssetsCommitted = lenders.totalAssetsCommitted;
        totalCommitmentCount = lenders.commitmentCount;
    }

    function getDistributionInfo() external view returns (uint128, uint128, uint128, uint128) {
        return (borrowerDistribution, totalBorrowerShares, lenderDistribution, totalLenderShares);
    }

    function _calculateLenderReturn(uint256 totalMatched, uint256 outAmount) internal view returns (uint256) {
        uint256 rateAppreciation = IBPSFeed(LENDER_RETURN_BPS_FEED).getWeightedRate() - BPS;
        uint256 yieldEarned = totalMatched * rateAppreciation * POOL_PHASE_DURATION / ONE_YEAR / BPS;
        return Math.min(totalMatched + yieldEarned, outAmount);
    }
}

File 6 of 24 : SwapFacility.sol
// SPDX-License-Identifier: BUSL-1.1
/*
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ•—β–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ–ˆβ•—β–‘β–‘β–‘β–ˆβ–ˆβ–ˆβ•—
β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ–ˆβ–ˆβ•‘
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•¦β•β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β–ˆβ–ˆβ–ˆβ–ˆβ•”β–ˆβ–ˆβ•‘
β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•¦β•β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘β–‘β•šβ•β•β–‘β–ˆβ–ˆβ•‘
β•šβ•β•β•β•β•β•β–‘β•šβ•β•β•β•β•β•β•β–‘β•šβ•β•β•β•β•β–‘β–‘β•šβ•β•β•β•β•β–‘β•šβ•β•β–‘β–‘β–‘β–‘β–‘β•šβ•β•
*/

pragma solidity 0.8.19;

import {ERC20} from "solmate/tokens/ERC20.sol";
import {SafeTransferLib} from "solmate/utils/SafeTransferLib.sol";
import {Owned} from "solmate/auth/Owned.sol";
import {IWhitelist} from "./interfaces/IWhitelist.sol";
import {ISwapFacility} from "./interfaces/ISwapFacility.sol";
import {ISwapRecipient} from "./interfaces/ISwapRecipient.sol";
import {IBloomPool, State} from "./interfaces/IBloomPool.sol";
import {IOracle} from "./interfaces/IOracle.sol";

contract SwapFacility is ISwapFacility, Owned {
    using SafeTransferLib for ERC20;
    // =================== Storage ===================

    /// @notice Underlying token
    address public immutable underlyingToken;

    /// @notice Billy token
    address public immutable billyToken;

    /// @notice Price oracle for underlying token
    address public immutable underlyingTokenOracle;
    uint256 public immutable underlyingScale;

    /// @notice Price oracle for billy token
    address public immutable billyTokenOracle;
    uint256 public immutable billyScale;

    /// @dev Minimum value of the stable asset (denominated in the oracle's decimals).
    uint256 internal immutable MIN_STABLE_VALUE;

    /// @dev Maximum fair value of the t-bill asset (denominated in the oracle's decimals).
    uint256 internal immutable MAX_BILLY_VALUE;

    /// @notice Whitelist contract
    IWhitelist public immutable whitelist;

    /// @notice Spread in basis points
    uint256 public immutable spread;

    /// @dev Pool address
    address public immutable pool;

    uint256 internal constant ORACLE_STALE_THRESHOLD = 36 hours;
    uint256 internal constant BPS = 1e4;
    uint256 internal constant MAX_SPREAD = 0.1e4; // 10%
    uint256 internal constant STABLE_VALUE = 1e8;

    /// @dev Current swap stage
    /// 0: Not started
    /// 1: Underlying -> Billy swap initiated
    /// 2: Underlying -> Billy swap completed
    /// 3: Billy -> Underlying swap initiated
    /// 4: Billy -> Underlying swap completed
    uint8 internal _stage;

    /// @dev Total swap amount
    uint256 internal _swapAmount;

    /// @dev Total out amount
    uint256 internal _totalAmount;

    // =================== Errors ===================

    /// @notice Invalid Token
    error InvalidToken();

    /// @notice Not Pool
    error NotPool();

    /// @notice Not Whitelisted
    error NotWhitelisted();

    /// @dev Oracle reported negative `answer`.
    error OracleAnswerNegative();

    /// @dev Oracle response is more than `ORACLE_STALE_THRESHOLD` old.
    error OracleStale();

    /// @dev Given `spread` parameter is >=100%
    error InvalidSpread();

    error ExtremePrice();

    // =================== Events ===================

    /// @notice Swap Event
    /// @param inToken In token address
    /// @param outToken Out token address
    /// @param inAmount In token amount
    /// @param user To address
    event Swap(address inToken, address outToken, uint256 inAmount, uint256 outAmount, address indexed user);

    // =================== Modifiers ===================

    modifier onlyWhitelisted(bytes32[] calldata proof) {
        if (msg.sender != pool && !IWhitelist(whitelist).isWhitelisted(msg.sender, proof)) {
            revert NotWhitelisted();
        }
        _;
    }

    // =================== Functions ===================

    /// @notice SwapFacility Constructor
    /// @param _underlyingToken Underlying token address
    /// @param _billyToken Billy token address
    /// @param _underlyingTokenOracle Price oracle for underlying token
    /// @param _billyTokenOracle Price oracle for billy token
    /// @param _whitelist Whitelist contract
    /// @param _spread Spread price
    /// @param _minStableValue Minimum value of the stable asset (denominated in the oracle's decimals)
    /// @param _maxBillyValue Maximum fair value of the t-bill asset (denominated in the oracle's decimals)
    constructor(
        address _underlyingToken,
        address _billyToken,
        address _underlyingTokenOracle,
        address _billyTokenOracle,
        IWhitelist _whitelist,
        uint256 _spread,
        address _pool,
        uint256 _minStableValue,
        uint256 _maxBillyValue
    ) Owned(msg.sender) {
        if (_spread > MAX_SPREAD) revert InvalidSpread();
        underlyingToken = _underlyingToken;
        billyToken = _billyToken;
        underlyingTokenOracle = _underlyingTokenOracle;

        // Get token and oracle decimals to see the scale required to balance out.
        uint256 underlyingExp = IOracle(_underlyingTokenOracle).decimals() + ERC20(_underlyingToken).decimals();
        uint256 billyExp = IOracle(_billyTokenOracle).decimals() + ERC20(_billyToken).decimals();
        // The two `{...}Exp` variables represent the zeros in the scale values, can cancel out
        // early to minimize overflows:
        (underlyingExp, billyExp) =
            underlyingExp > billyExp ? (underlyingExp - billyExp, uint256(0)) : (uint256(0), billyExp - underlyingExp);

        underlyingScale = 10 ** underlyingExp;
        billyTokenOracle = _billyTokenOracle;
        billyScale = 10 ** billyExp;
        whitelist = _whitelist;
        spread = _spread;
        pool = _pool;
        MIN_STABLE_VALUE = _minStableValue;
        MAX_BILLY_VALUE = _maxBillyValue;
    }

    /// @notice Swap tokens UNDERLYING <-> BILLY
    /// @param _inToken In token address
    /// @param _outToken Out token address
    /// @param _inAmount In token amount
    /// @param _proof Whitelist proof
    function swap(address _inToken, address _outToken, uint256 _inAmount, bytes32[] calldata _proof)
        external
        onlyWhitelisted(_proof)
    {
        if (_stage == 0) {
            if (_inToken != underlyingToken || _outToken != billyToken) {
                revert InvalidToken();
            }
            if (pool != msg.sender) revert NotPool();
            _stage = 1;
            _swapAmount = _inAmount;
        } else if (_stage == 1) {
            if (_inToken != billyToken || _outToken != underlyingToken) {
                revert InvalidToken();
            }
            _swap(_inToken, _outToken, _inAmount, msg.sender, true);
        } else if (_stage == 2) {
            if (_inToken != billyToken || _outToken != underlyingToken) {
                revert InvalidToken();
            }
            if (pool != msg.sender) revert NotPool();
            _stage = 3;
            _swapAmount = _inAmount;
        } else if (_stage == 3) {
            if (_inToken != underlyingToken || _outToken != billyToken) {
                revert InvalidToken();
            }
            _swap(_inToken, _outToken, _inAmount, msg.sender, false);
        }
    }

    /// @dev Perform swap between pool and user
    ///     Transfer `outToken` from `to` to Pool and `inToken` from Pool to `to`
    ///     outAmount is calculated based on the prices of both tokens
    ///     No swap fee is applied
    ///     Once entire swap is done, notify Pool contract by calling `completeSwap` function
    /// @param _inToken In token address
    /// @param _outToken Out token address
    /// @param _inAmount In token amount
    /// @param _to To address
    function _swap(address _inToken, address _outToken, uint256 _inAmount, address _to, bool _boundPrices)
        internal
        returns (uint256 outAmount)
    {
        (uint256 underlyingTokenPrice, uint256 billyTokenPrice) = _getTokenPrices(_boundPrices);
        (uint256 inTokenPrice, uint256 outTokenPrice) = _inToken == underlyingToken
            ? (underlyingTokenPrice, billyTokenPrice)
            : (billyTokenPrice, underlyingTokenPrice);
        outAmount = (_inAmount * inTokenPrice * (BPS + spread)) / outTokenPrice / BPS;
        if (_swapAmount < outAmount) {
            outAmount = _swapAmount;
            _inAmount = (outAmount * outTokenPrice * BPS) / inTokenPrice / (BPS + spread);
        }
        unchecked {
            _swapAmount -= outAmount;
        }
        _totalAmount += _inAmount;
        ERC20(_inToken).safeTransferFrom(_to, pool, _inAmount);
        ERC20(_outToken).safeTransferFrom(pool, _to, outAmount);
        if (_swapAmount == 0) {
            ++_stage;
            ISwapRecipient(pool).completeSwap(_inToken, _totalAmount);
            _totalAmount = 0;
        }

        emit Swap(_inToken, _outToken, _inAmount, outAmount, _to);
    }

    /// @dev Get prices of underlying and billy tokens
    /// @return underlyingTokenPrice Underlying token price
    /// @return billyTokenPrice Billy token price
    function _getTokenPrices(bool _boundPrices)
        internal
        view
        returns (uint256 underlyingTokenPrice, uint256 billyTokenPrice)
    {
        uint256 stablePrice = _readOracle(underlyingTokenOracle); 
        uint256 billyPrice = _readOracle(billyTokenOracle);
        if (_boundPrices) {
            if (stablePrice < MIN_STABLE_VALUE) revert ExtremePrice();
            if (billyPrice > MAX_BILLY_VALUE) revert ExtremePrice();
        }
        underlyingTokenPrice = STABLE_VALUE * billyScale;
        billyTokenPrice = billyPrice * underlyingScale;
    }

    function _readOracle(address _oracle) internal view returns (uint256) {
        (, int256 answer,, uint256 updatedAt,) = IOracle(_oracle).latestRoundData();
        if (answer <= 0) revert OracleAnswerNegative();
        if (block.timestamp - updatedAt >= ORACLE_STALE_THRESHOLD) revert OracleStale();
        return uint256(answer);
    }
}

File 7 of 24 : IBloomFactory.sol
// SPDX-License-Identifier: BUSL-1.1
/*
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ•—β–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ–ˆβ•—β–‘β–‘β–‘β–ˆβ–ˆβ–ˆβ•—
β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ–ˆβ–ˆβ•‘
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•¦β•β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β–ˆβ–ˆβ–ˆβ–ˆβ•”β–ˆβ–ˆβ•‘
β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•¦β•β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘β–‘β•šβ•β•β–‘β–ˆβ–ˆβ•‘
β•šβ•β•β•β•β•β•β–‘β•šβ•β•β•β•β•β•β•β–‘β•šβ•β•β•β•β•β–‘β–‘β•šβ•β•β•β•β•β–‘β•šβ•β•β–‘β–‘β–‘β–‘β–‘β•šβ•β•
*/

pragma solidity ^0.8.0;

import {BloomPool} from "../BloomPool.sol";

import {IWhitelist} from "./IWhitelist.sol";
import {IRegistry} from "./IRegistry.sol";

interface IBloomFactory {
    error InvalidPoolAddress();

    struct PoolParams {
        address treasury;
        address borrowerWhiteList;
        address lenderReturnBpsFeed;
        address emergencyHandler;
        uint256 leverageBps;
        uint256 minBorrowDeposit;
        uint256 commitPhaseDuration;
        uint256 swapTimeout;
        uint256 poolPhaseDuration;
        uint256 lenderReturnFee;
        uint256 borrowerReturnFee;
    }

    struct SwapFacilityParams {
        address underlyingTokenOracle;
        address billyTokenOracle;
        address swapWhitelist;
        uint256 spread;
        uint256 minStableValue;
        uint256 maxBillyValue;
    }

    event NewBloomPoolCreated(address indexed pool, address swapFacility);

    /**
     * @notice Returns the last created pool that was created from the factory
     */
    function getLastCreatedPool() external view returns (address);

    /**
     * @notice Returns true if the pool was created from the factory
     * @param pool Address of a BloomPool
     * @return True if the pool was created from the factory
     */
    function isPoolFromFactory(address pool) external view returns (bool);

    /**
     * @notice Create and initializes a new BloomPool and SwapFacility
     * @param name Name of the pool
     * @param symbol Symbol of the pool
     * @param underlyingToken Address of the underlying token
     * @param billToken Address of the bill token
     * @param poolParams Parameters that are used for the pool
     * @param swapFacilityParams Parameters that are used for the swap facility
     * @param factoryNonce Nonce of the factory
     * @return Address of the new pool
     */
    function create(
        string memory name,
        string memory symbol,
        address underlyingToken,
        address billToken,
        IRegistry exchangeRateRegistry,
        PoolParams calldata poolParams,
        SwapFacilityParams calldata swapFacilityParams,
        uint256 factoryNonce
    ) external returns (BloomPool);

}

File 8 of 24 : IWhitelist.sol
// SPDX-License-Identifier: BUSL-1.1
/*
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ•—β–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ–ˆβ•—β–‘β–‘β–‘β–ˆβ–ˆβ–ˆβ•—
β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ–ˆβ–ˆβ•‘
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•¦β•β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β–ˆβ–ˆβ–ˆβ–ˆβ•”β–ˆβ–ˆβ•‘
β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•¦β•β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘β–‘β•šβ•β•β–‘β–ˆβ–ˆβ•‘
β•šβ•β•β•β•β•β•β–‘β•šβ•β•β•β•β•β•β•β–‘β•šβ•β•β•β•β•β–‘β–‘β•šβ•β•β•β•β•β–‘β•šβ•β•β–‘β–‘β–‘β–‘β–‘β•šβ•β•
*/

pragma solidity 0.8.19;

interface IWhitelist {
    event NewWhitelistRoot(bytes32 newRoot);

    function setRoot(bytes32 newRoot) external;

    function isWhitelisted(address member, bytes32[] calldata proof) external returns (bool);
}

File 9 of 24 : IRegistry.sol
// SPDX-License-Identifier: BUSL-1.1
/*
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ•—β–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ–ˆβ•—β–‘β–‘β–‘β–ˆβ–ˆβ–ˆβ•—
β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ–ˆβ–ˆβ•‘
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•¦β•β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β–ˆβ–ˆβ–ˆβ–ˆβ•”β–ˆβ–ˆβ•‘
β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•¦β•β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘β–‘β•šβ•β•β–‘β–ˆβ–ˆβ•‘
β•šβ•β•β•β•β•β•β–‘β•šβ•β•β•β•β•β•β•β–‘β•šβ•β•β•β•β•β–‘β–‘β•šβ•β•β•β•β•β–‘β•šβ•β•β–‘β–‘β–‘β–‘β–‘β•šβ•β•
*/

pragma solidity ^0.8.0;

import {IBloomPool} from "./IBloomPool.sol";

/**
 * @title Bloom Registry interface to return exchangeRate
 */
interface IRegistry {
    /**
     * @notice Returns the current exchange rate of the given token
     * @param token The token address
     * @return The current exchange rate of the given token
     */
    function getExchangeRate(address token) external view returns (uint256);

    /**
     * @notice Register new token to the registry
     * @dev This is a permissioned function. Only the BloomFactory or the registry owner can call this function
     * @param token The TBY token that will be registered (aka the BloomPool)
     */
    function registerToken(IBloomPool token) external; 

}

File 10 of 24 : Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (access/Ownable.sol)

pragma solidity ^0.8.0;

import "../utils/Context.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * By default, the owner account will be the one that deploys the contract. This
 * can later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor() {
        _transferOwnership(_msgSender());
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby disabling any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}

File 11 of 24 : ERC20.sol
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;

/// @notice Modern and gas efficient ERC20 + EIP-2612 implementation.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/tokens/ERC20.sol)
/// @author Modified from Uniswap (https://github.com/Uniswap/uniswap-v2-core/blob/master/contracts/UniswapV2ERC20.sol)
/// @dev Do not manually set balances without updating totalSupply, as the sum of all user balances must not exceed it.
abstract contract ERC20 {
    /*//////////////////////////////////////////////////////////////
                                 EVENTS
    //////////////////////////////////////////////////////////////*/

    event Transfer(address indexed from, address indexed to, uint256 amount);

    event Approval(address indexed owner, address indexed spender, uint256 amount);

    /*//////////////////////////////////////////////////////////////
                            METADATA STORAGE
    //////////////////////////////////////////////////////////////*/

    string public name;

    string public symbol;

    uint8 public immutable decimals;

    /*//////////////////////////////////////////////////////////////
                              ERC20 STORAGE
    //////////////////////////////////////////////////////////////*/

    uint256 public totalSupply;

    mapping(address => uint256) public balanceOf;

    mapping(address => mapping(address => uint256)) public allowance;

    /*//////////////////////////////////////////////////////////////
                            EIP-2612 STORAGE
    //////////////////////////////////////////////////////////////*/

    uint256 internal immutable INITIAL_CHAIN_ID;

    bytes32 internal immutable INITIAL_DOMAIN_SEPARATOR;

    mapping(address => uint256) public nonces;

    /*//////////////////////////////////////////////////////////////
                               CONSTRUCTOR
    //////////////////////////////////////////////////////////////*/

    constructor(
        string memory _name,
        string memory _symbol,
        uint8 _decimals
    ) {
        name = _name;
        symbol = _symbol;
        decimals = _decimals;

        INITIAL_CHAIN_ID = block.chainid;
        INITIAL_DOMAIN_SEPARATOR = computeDomainSeparator();
    }

    /*//////////////////////////////////////////////////////////////
                               ERC20 LOGIC
    //////////////////////////////////////////////////////////////*/

    function approve(address spender, uint256 amount) public virtual returns (bool) {
        allowance[msg.sender][spender] = amount;

        emit Approval(msg.sender, spender, amount);

        return true;
    }

    function transfer(address to, uint256 amount) public virtual returns (bool) {
        balanceOf[msg.sender] -= amount;

        // Cannot overflow because the sum of all user
        // balances can't exceed the max uint256 value.
        unchecked {
            balanceOf[to] += amount;
        }

        emit Transfer(msg.sender, to, amount);

        return true;
    }

    function transferFrom(
        address from,
        address to,
        uint256 amount
    ) public virtual returns (bool) {
        uint256 allowed = allowance[from][msg.sender]; // Saves gas for limited approvals.

        if (allowed != type(uint256).max) allowance[from][msg.sender] = allowed - amount;

        balanceOf[from] -= amount;

        // Cannot overflow because the sum of all user
        // balances can't exceed the max uint256 value.
        unchecked {
            balanceOf[to] += amount;
        }

        emit Transfer(from, to, amount);

        return true;
    }

    /*//////////////////////////////////////////////////////////////
                             EIP-2612 LOGIC
    //////////////////////////////////////////////////////////////*/

    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) public virtual {
        require(deadline >= block.timestamp, "PERMIT_DEADLINE_EXPIRED");

        // Unchecked because the only math done is incrementing
        // the owner's nonce which cannot realistically overflow.
        unchecked {
            address recoveredAddress = ecrecover(
                keccak256(
                    abi.encodePacked(
                        "\x19\x01",
                        DOMAIN_SEPARATOR(),
                        keccak256(
                            abi.encode(
                                keccak256(
                                    "Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"
                                ),
                                owner,
                                spender,
                                value,
                                nonces[owner]++,
                                deadline
                            )
                        )
                    )
                ),
                v,
                r,
                s
            );

            require(recoveredAddress != address(0) && recoveredAddress == owner, "INVALID_SIGNER");

            allowance[recoveredAddress][spender] = value;
        }

        emit Approval(owner, spender, value);
    }

    function DOMAIN_SEPARATOR() public view virtual returns (bytes32) {
        return block.chainid == INITIAL_CHAIN_ID ? INITIAL_DOMAIN_SEPARATOR : computeDomainSeparator();
    }

    function computeDomainSeparator() internal view virtual returns (bytes32) {
        return
            keccak256(
                abi.encode(
                    keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
                    keccak256(bytes(name)),
                    keccak256("1"),
                    block.chainid,
                    address(this)
                )
            );
    }

    /*//////////////////////////////////////////////////////////////
                        INTERNAL MINT/BURN LOGIC
    //////////////////////////////////////////////////////////////*/

    function _mint(address to, uint256 amount) internal virtual {
        totalSupply += amount;

        // Cannot overflow because the sum of all user
        // balances can't exceed the max uint256 value.
        unchecked {
            balanceOf[to] += amount;
        }

        emit Transfer(address(0), to, amount);
    }

    function _burn(address from, uint256 amount) internal virtual {
        balanceOf[from] -= amount;

        // Cannot underflow because a user's balance
        // will never be larger than the total supply.
        unchecked {
            totalSupply -= amount;
        }

        emit Transfer(from, address(0), amount);
    }
}

File 12 of 24 : IBloomPool.sol
// SPDX-License-Identifier: BUSL-1.1
/*
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ•—β–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ–ˆβ•—β–‘β–‘β–‘β–ˆβ–ˆβ–ˆβ•—
β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ–ˆβ–ˆβ•‘
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•¦β•β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β–ˆβ–ˆβ–ˆβ–ˆβ•”β–ˆβ–ˆβ•‘
β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•¦β•β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘β–‘β•šβ•β•β–‘β–ˆβ–ˆβ•‘
β•šβ•β•β•β•β•β•β–‘β•šβ•β•β•β•β•β•β•β–‘β•šβ•β•β•β•β•β–‘β–‘β•šβ•β•β•β•β•β–‘β•šβ•β•β–‘β–‘β–‘β–‘β–‘β•šβ•β•
*/

pragma solidity 0.8.19;

import {AssetCommitment} from "../lib/CommitmentsLib.sol";
import {IWhitelist} from "../interfaces/IWhitelist.sol";

enum State {
    Other,
    Commit,
    ReadyPreHoldSwap,
    PendingPreHoldSwap,
    Holding,
    ReadyPostHoldSwap,
    PendingPostHoldSwap,
    EmergencyExit,
    FinalWithdraw
}

interface IBloomPool {
    // Initialization errors
    error ZeroAddress();

    error NotSwapFacility();
    error InvalidOutToken(address outToken);

    error NotWhitelisted();
    error NoCommitToProcess();
    error CommitTooSmall();
    error OracleAnswerNegative();
    error CanOnlyWithdrawProcessedCommit(uint256 id);
    error NoCommitToWithdraw();

    error InvalidState(State current);

    error NotEmergencyHandler();

    event BorrowerCommit(address indexed owner, uint256 indexed id, uint256 amount, uint256 cumulativeAmountEnd);
    event LenderCommit(address indexed owner, uint256 indexed id, uint256 amount, uint256 cumulativeAmountEnd);
    event BorrowerCommitmentProcessed(
        address indexed owner, uint256 indexed id, uint256 includedAmount, uint256 excludedAmount
    );
    event LenderCommitmentProcessed(
        address indexed owner, uint256 indexed id, uint256 includedAmount, uint256 excludedAmount
    );
    event ExplictStateTransition(State prevState, State newState);
    event BorrowerWithdraw(address indexed owner, uint256 indexed id, uint256 amount);
    event LenderWithdraw(address indexed owner, uint256 sharesRedeemed, uint256 amount);

    event EmergencyWithdrawExecuted(address indexed from, address indexed to, uint256 amount);
    event EmergencyBurn(address indexed user, uint256 amount);

    /// @notice Initiates the pre-hold swap.
    function initiatePreHoldSwap(bytes32[] calldata proof) external;

    /// @notice Initiates the post-hold swap.
    function initiatePostHoldSwap(bytes32[] calldata proof) external;

    /**
     * @notice Deposits funds from the borrower committing them for the duration of the commit
     * phase.
     * @param amount The amount of tokens to deposit.
     * @param proof The whitelist proof data, format dependent on implementation.
     * @return newCommitmentId The commitment ID for the borrower's new deposit.
     */
    function depositBorrower(uint256 amount, bytes32[] calldata proof) external returns (uint256 newCommitmentId);
    /**
     * @notice Deposits funds from the lender committing them for the duration of the commit phase.
     * @param amount The amount of stablecoins to deposit.
     * @return newCommitmentId The commitment ID for the lender deposit.
     */
    function depositLender(uint256 amount) external returns (uint256 newCommitmentId);

    /**
     * @notice Sends all funds to the EmergencyHandler contract
     * @dev This is a permissioned function that can only be executed by the owner of the BloomPool
     *     It can only be executed when the pool is in Emergency mode.
     */
    function emergencyWithdraw() external;

    /**
     * @notice Burns TBY shares when users redeem from the EmergencyHandler
     * @dev This is a permissioned function that can only be called by the EmergencyHandler contract
     * @param from The account from which the TBY tokens will be burned from
     * @param amount The amount of tokens to burn
     */
    function executeEmergencyBurn(address from, uint256 amount) external;

    /**
     * @notice Processes a borrower's commit, calculates the included and excluded amounts, and refunds any unmatched amounts.
     * @param commitId The borrower's commitment ID.
     */
    function processBorrowerCommit(uint256 commitId) external;

    /**
     * @notice Processes a lender's commit, calculates the included and excluded amounts, mints shares, and refunds any unmatched amounts.
     * @param commitId The lender's commitment ID.
     */
    function processLenderCommit(uint256 commitId) external;

    /**
     * @notice Allows borrowers to withdraw their share of the returned stablecoins after the pool phase has ended and swaps have been completed.
     * @param id The borrower's commitment ID.
     */
    function withdrawBorrower(uint256 id) external;

    /**
     * @notice Allows lenders to withdraw their share of the returned stablecoins and earned interest after the pool phase has ended and swaps have been completed.
     * @param shares The number of lender shares to withdraw.
     */
    function withdrawLender(uint256 shares) external;

    function UNDERLYING_TOKEN() external view returns (address);
    function BILL_TOKEN() external view returns (address);
    function WHITELIST() external view returns (IWhitelist);
    function SWAP_FACILITY() external view returns (address);
    function TREASURY() external view returns (address);
    function LENDER_RETURN_BPS_FEED() external view returns (address);
    function LEVERAGE_BPS() external view returns (uint256);
    function MIN_BORROW_DEPOSIT() external view returns (uint256);
    function COMMIT_PHASE_END() external view returns (uint256);
    function PRE_HOLD_SWAP_TIMEOUT_END() external view returns (uint256);
    function POST_HOLD_SWAP_TIMEOUT_END() external view returns (uint256);
    function POOL_PHASE_END() external view returns (uint256);
    function POOL_PHASE_DURATION() external view returns (uint256);
    function LENDER_RETURN_FEE() external view returns (uint256);
    function BORROWER_RETURN_FEE() external view returns (uint256);

    function state() external view returns (State currentState);
    function totalMatchAmount() external view returns (uint256);

    function getBorrowCommitment(uint256 id) external view returns (AssetCommitment memory);
    function getLenderCommitment(uint256 id) external view returns (AssetCommitment memory);

    function getTotalBorrowCommitment()
        external
        view
        returns (uint256 totalAssetsCommited, uint256 totalCommitmentCount);
    function getTotalLendCommitment()
        external
        view
        returns (uint256 totalAssetsCommited, uint256 totalCommitmentCount);

    function getDistributionInfo()
        external
        view
        returns (
            uint128 borrowerDistribution,
            uint128 totalBorrowerShares,
            uint128 lenderDistribution,
            uint128 totalLenderShares
        );
}

File 13 of 24 : IEmergencyHandler.sol
// SPDX-License-Identifier: BUSL-1.1
/*
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ•—β–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ–ˆβ•—β–‘β–‘β–‘β–ˆβ–ˆβ–ˆβ•—
β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ–ˆβ–ˆβ•‘
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•¦β•β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β–ˆβ–ˆβ–ˆβ–ˆβ•”β–ˆβ–ˆβ•‘
β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•¦β•β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘β–‘β•šβ•β•β–‘β–ˆβ–ˆβ•‘
β•šβ•β•β•β•β•β•β–‘β•šβ•β•β•β•β•β•β•β–‘β•šβ•β•β•β•β•β–‘β–‘β•šβ•β•β•β•β•β–‘β•šβ•β•β–‘β–‘β–‘β–‘β–‘β•šβ•β•
*/

pragma solidity ^0.8.0;

import {IBloomPool} from "./IBloomPool.sol";
import {IOracle} from "./IOracle.sol";

interface IEmergencyHandler {

    error BorrowerAlreadyClaimed();
    error CallerNotBloomPool();
    error NoTokensToRedeem();
    error NotWhitelisted();
    error PoolNotRegistered();
    error PoolAlreadyRegistered();
    error InvalidOwner();

    struct Token {
        address token;
        uint256 rate;
        uint256 rateDecimals;
    }

    struct PoolAccounting {
        uint256 lenderDistro; // Underlying assets available for lenders
        uint256 borrowerDistro; // Underlying assets available for borrowers
        uint256 lenderShares; // Total shares available for lenders
        uint256 borrowerShares; // Total shares available for borrowers
        uint256 totalUnderlying; // Total underlying assets from the pool
        uint256 totalBill; // Total bill assets from the pool
    }

    struct RedemptionInfo {
        Token underlyingToken;
        Token billToken;
        PoolAccounting accounting;
        bool yieldGenerated;
    }

    struct ClaimStatus {
        bool claimed;
        uint256 amountRemaining;
    }

    /**
     * @notice Redeem underlying assets for lenders of a BloomPool in Emergency Exit mode
     * @param _pool BloomPool that the funds in the emergency handler contract orginated from
     * @return amount of underlying assets redeemed
     */
    function redeem(IBloomPool _pool) external returns (uint256);

    /**
     * @notice  Redeem underlying assets for borrowers of a BloomPool in Emergency Exit mode
     * @param pool BloomPool that the funds in the emergency handler contract orginated from
     * @param id Id of the borrowers commit in the corresponding BloomPool
     * @return amount of underlying assets redeemed
     */
    function redeem(IBloomPool pool, uint256 id) external returns (uint256);

    /**
     * @notice Allows Market Makers to swap underlying assets for bill tokens
     * @param pool BloomPool that the funds in the emergency handler contract orginated from
     * @param underlyingIn Amount of underlying assets to swap
     * @param proof Whitelist proof data, prevents non-approved maket makers from swapping
     * @return amount of bill tokens received
     */
    function swap(IBloomPool pool, uint256 underlyingIn, bytes32[] calldata proof) external returns (uint256);
    
    /**
     * @notice Registers a Bloom Pool in the Emergency Handler
     * @param redemptionInfo RedemptionInfo struct containing the pool's accounting and oracle information
    */
    function registerPool(RedemptionInfo memory redemptionInfo) external;
}

File 14 of 24 : ISwapRecipient.sol
// SPDX-License-Identifier: BUSL-1.1
/*
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ•—β–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ–ˆβ•—β–‘β–‘β–‘β–ˆβ–ˆβ–ˆβ•—
β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ–ˆβ–ˆβ•‘
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•¦β•β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β–ˆβ–ˆβ–ˆβ–ˆβ•”β–ˆβ–ˆβ•‘
β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•¦β•β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘β–‘β•šβ•β•β–‘β–ˆβ–ˆβ•‘
β•šβ•β•β•β•β•β•β–‘β•šβ•β•β•β•β•β•β•β–‘β•šβ•β•β•β•β•β–‘β–‘β•šβ•β•β•β•β•β–‘β•šβ•β•β–‘β–‘β–‘β–‘β–‘β•šβ•β•
*/

pragma solidity ^0.8.0;

interface ISwapRecipient {
    /**
     * @notice Callback that is invoked by a swap facility when a trade is completed.
     * @param outToken The address of the token that's coming from the swap.
     * @param outAmount The amount of tokens that was transferred separately.
     */
    function completeSwap(address outToken, uint256 outAmount) external;
}

File 15 of 24 : 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)
/// @dev Caution! This library 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();

    /*´:°β€’.°+.*β€’´.*:˚.°*.Λšβ€’´.°:°β€’.°β€’.*β€’´.*:˚.°*.Λšβ€’´.°:°β€’.°+.*β€’´.*:*/
    /*                         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.
    /// Multiply by a small constant (e.g. 2), if needed.
    uint256 internal constant _GAS_STIPEND_NO_GRIEF = 100000;

    /*´:°β€’.°+.*β€’´.*:˚.°*.Λšβ€’´.°:°β€’.°β€’.*β€’´.*:˚.°*.Λšβ€’´.°:°β€’.°+.*β€’´.*:*/
    /*                       ETH OPERATIONS                       */
    /*.β€’°:°.´+˚.*°.˚:*.´β€’*.+°.β€’°:´*.´β€’*.β€’°.β€’°:°.´:β€’Λš°.*°.˚:*.´+°.β€’*/

    /// @dev Sends `amount` (in wei) ETH to `to`.
    /// Reverts upon failure.
    function safeTransferETH(address to, uint256 amount) internal {
        /// @solidity memory-safe-assembly
        assembly {
            // Transfer the ETH and check if it succeeded or not.
            if iszero(call(gas(), to, amount, 0, 0, 0, 0)) {
                // Store the function selector of `ETHTransferFailed()`.
                mstore(0x00, 0xb12d13eb)
                // Revert with (offset, size).
                revert(0x1c, 0x04)
            }
        }
    }

    /// @dev Force sends `amount` (in wei) ETH to `to`, with a `gasStipend`.
    /// The `gasStipend` can be set to a low enough value to prevent
    /// storage writes or gas griefing.
    ///
    /// If sending via the normal procedure fails, force sends the ETH by
    /// creating a temporary contract which uses `SELFDESTRUCT` to force send the ETH.
    ///
    /// Reverts if the current contract has insufficient balance.
    function forceSafeTransferETH(address to, uint256 amount, uint256 gasStipend) internal {
        /// @solidity memory-safe-assembly
        assembly {
            // If insufficient balance, revert.
            if lt(selfbalance(), amount) {
                // Store the function selector of `ETHTransferFailed()`.
                mstore(0x00, 0xb12d13eb)
                // Revert with (offset, size).
                revert(0x1c, 0x04)
            }
            // Transfer the ETH and check if it succeeded or not.
            if iszero(call(gasStipend, to, amount, 0, 0, 0, 0)) {
                mstore(0x00, to) // Store the address in scratch space.
                mstore8(0x0b, 0x73) // Opcode `PUSH20`.
                mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`.
                // We can directly use `SELFDESTRUCT` in the contract creation.
                // Compatible with `SENDALL`: https://eips.ethereum.org/EIPS/eip-4758
                if iszero(create(amount, 0x0b, 0x16)) {
                    // For better gas estimation.
                    if iszero(gt(gas(), 1000000)) { revert(0, 0) }
                }
            }
        }
    }

    /// @dev Force sends `amount` (in wei) ETH to `to`, with a gas stipend
    /// equal to `_GAS_STIPEND_NO_GRIEF`. This gas stipend is a reasonable default
    /// for 99% of cases and can be overriden with the three-argument version of this
    /// function if necessary.
    ///
    /// If sending via the normal procedure fails, force sends the ETH by
    /// creating a temporary contract which uses `SELFDESTRUCT` to force send the ETH.
    ///
    /// Reverts if the current contract has insufficient balance.
    function forceSafeTransferETH(address to, uint256 amount) internal {
        // Manually inlined because the compiler doesn't inline functions with branches.
        /// @solidity memory-safe-assembly
        assembly {
            // If insufficient balance, revert.
            if lt(selfbalance(), amount) {
                // Store the function selector of `ETHTransferFailed()`.
                mstore(0x00, 0xb12d13eb)
                // Revert with (offset, size).
                revert(0x1c, 0x04)
            }
            // Transfer the ETH and check if it succeeded or not.
            if iszero(call(_GAS_STIPEND_NO_GRIEF, to, amount, 0, 0, 0, 0)) {
                mstore(0x00, to) // Store the address in scratch space.
                mstore8(0x0b, 0x73) // Opcode `PUSH20`.
                mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`.
                // We can directly use `SELFDESTRUCT` in the contract creation.
                // Compatible with `SENDALL`: https://eips.ethereum.org/EIPS/eip-4758
                if iszero(create(amount, 0x0b, 0x16)) {
                    // For better gas estimation.
                    if iszero(gt(gas(), 1000000)) { revert(0, 0) }
                }
            }
        }
    }

    /// @dev Sends `amount` (in wei) ETH to `to`, with a `gasStipend`.
    /// The `gasStipend` can be set to a low enough value to prevent
    /// storage writes or gas griefing.
    ///
    /// Simply use `gasleft()` for `gasStipend` if you don't need a gas stipend.
    ///
    /// Note: Does NOT revert upon failure.
    /// Returns whether the transfer of ETH is successful instead.
    function trySafeTransferETH(address to, uint256 amount, uint256 gasStipend)
        internal
        returns (bool success)
    {
        /// @solidity memory-safe-assembly
        assembly {
            // Transfer the ETH and check if it succeeded or not.
            success := call(gasStipend, to, amount, 0, 0, 0, 0)
        }
    }

    /*´:°β€’.°+.*β€’´.*:˚.°*.Λšβ€’´.°:°β€’.°β€’.*β€’´.*:˚.°*.Λšβ€’´.°:°β€’.°+.*β€’´.*:*/
    /*                      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.
            // Store the function selector of `transferFrom(address,address,uint256)`.
            mstore(0x0c, 0x23b872dd000000000000000000000000)

            if iszero(
                and( // The arguments of `and` are evaluated from right to left.
                    // Set success to whether the call reverted, if not we check it either
                    // returned exactly 1 (can't just be non-zero data), or had no return data.
                    or(eq(mload(0x00), 1), iszero(returndatasize())),
                    call(gas(), token, 0, 0x1c, 0x64, 0x00, 0x20)
                )
            ) {
                // Store the function selector of `TransferFromFailed()`.
                mstore(0x00, 0x7939f424)
                // Revert with (offset, size).
                revert(0x1c, 0x04)
            }

            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 at least `amount` 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.
            // Store the function selector of `balanceOf(address)`.
            mstore(0x0c, 0x70a08231000000000000000000000000)
            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)
                )
            ) {
                // Store the function selector of `TransferFromFailed()`.
                mstore(0x00, 0x7939f424)
                // Revert with (offset, size).
                revert(0x1c, 0x04)
            }

            // Store the function selector of `transferFrom(address,address,uint256)`.
            mstore(0x00, 0x23b872dd)
            // The `amount` argument is already written to the memory word at 0x6c.
            amount := mload(0x60)

            if iszero(
                and( // The arguments of `and` are evaluated from right to left.
                    // Set success to whether the call reverted, if not we check it either
                    // returned exactly 1 (can't just be non-zero data), or had no return data.
                    or(eq(mload(0x00), 1), iszero(returndatasize())),
                    call(gas(), token, 0, 0x1c, 0x64, 0x00, 0x20)
                )
            ) {
                // Store the function selector of `TransferFromFailed()`.
                mstore(0x00, 0x7939f424)
                // Revert with (offset, size).
                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.
            // Store the function selector of `transfer(address,uint256)`.
            mstore(0x00, 0xa9059cbb000000000000000000000000)

            if iszero(
                and( // The arguments of `and` are evaluated from right to left.
                    // Set success to whether the call reverted, if not we check it either
                    // returned exactly 1 (can't just be non-zero data), or had no return data.
                    or(eq(mload(0x00), 1), iszero(returndatasize())),
                    call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)
                )
            ) {
                // Store the function selector of `TransferFailed()`.
                mstore(0x00, 0x90b8ec18)
                // Revert with (offset, size).
                revert(0x1c, 0x04)
            }
            // Restore the part of the free memory pointer that was overwritten.
            mstore(0x34, 0)
        }
    }

    /// @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.
            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)
                )
            ) {
                // Store the function selector of `TransferFailed()`.
                mstore(0x00, 0x90b8ec18)
                // Revert with (offset, size).
                revert(0x1c, 0x04)
            }

            mstore(0x14, to) // Store the `to` argument.
            // The `amount` argument is already written to the memory word at 0x34.
            amount := mload(0x34)
            // Store the function selector of `transfer(address,uint256)`.
            mstore(0x00, 0xa9059cbb000000000000000000000000)

            if iszero(
                and( // The arguments of `and` are evaluated from right to left.
                    // Set success to whether the call reverted, if not we check it either
                    // returned exactly 1 (can't just be non-zero data), or had no return data.
                    or(eq(mload(0x00), 1), iszero(returndatasize())),
                    call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)
                )
            ) {
                // Store the function selector of `TransferFailed()`.
                mstore(0x00, 0x90b8ec18)
                // Revert with (offset, size).
                revert(0x1c, 0x04)
            }
            // Restore the part of the free memory pointer that was overwritten.
            mstore(0x34, 0)
        }
    }

    /// @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.
            // Store the function selector of `approve(address,uint256)`.
            mstore(0x00, 0x095ea7b3000000000000000000000000)

            if iszero(
                and( // The arguments of `and` are evaluated from right to left.
                    // Set success to whether the call reverted, if not we check it either
                    // returned exactly 1 (can't just be non-zero data), or had no return data.
                    or(eq(mload(0x00), 1), iszero(returndatasize())),
                    call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)
                )
            ) {
                // Store the function selector of `ApproveFailed()`.
                mstore(0x00, 0x3e3f8f73)
                // Revert with (offset, size).
                revert(0x1c, 0x04)
            }
            // Restore the part of the free memory pointer that was overwritten.
            mstore(0x34, 0)
        }
    }

    /// @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.
            // Store the function selector of `balanceOf(address)`.
            mstore(0x00, 0x70a08231000000000000000000000000)
            amount :=
                mul(
                    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)
                    )
                )
        }
    }
}

File 16 of 24 : SafeCastLib.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

/// @notice Safe integer casting library that reverts on overflow.
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/SafeCastLib.sol)
/// @author Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/math/SafeCast.sol)
library SafeCastLib {
    /*´:°β€’.°+.*β€’´.*:˚.°*.Λšβ€’´.°:°β€’.°β€’.*β€’´.*:˚.°*.Λšβ€’´.°:°β€’.°+.*β€’´.*:*/
    /*                       CUSTOM ERRORS                        */
    /*.β€’°:°.´+˚.*°.˚:*.´β€’*.+°.β€’°:´*.´β€’*.β€’°.β€’°:°.´:β€’Λš°.*°.˚:*.´+°.β€’*/

    error Overflow();

    /*´:°β€’.°+.*β€’´.*:˚.°*.Λšβ€’´.°:°β€’.°β€’.*β€’´.*:˚.°*.Λšβ€’´.°:°β€’.°+.*β€’´.*:*/
    /*          UNSIGNED INTEGER SAFE CASTING OPERATIONS          */
    /*.β€’°:°.´+˚.*°.˚:*.´β€’*.+°.β€’°:´*.´β€’*.β€’°.β€’°:°.´:β€’Λš°.*°.˚:*.´+°.β€’*/

    function toUint8(uint256 x) internal pure returns (uint8) {
        if (x >= 1 << 8) _revertOverflow();
        return uint8(x);
    }

    function toUint16(uint256 x) internal pure returns (uint16) {
        if (x >= 1 << 16) _revertOverflow();
        return uint16(x);
    }

    function toUint24(uint256 x) internal pure returns (uint24) {
        if (x >= 1 << 24) _revertOverflow();
        return uint24(x);
    }

    function toUint32(uint256 x) internal pure returns (uint32) {
        if (x >= 1 << 32) _revertOverflow();
        return uint32(x);
    }

    function toUint40(uint256 x) internal pure returns (uint40) {
        if (x >= 1 << 40) _revertOverflow();
        return uint40(x);
    }

    function toUint48(uint256 x) internal pure returns (uint48) {
        if (x >= 1 << 48) _revertOverflow();
        return uint48(x);
    }

    function toUint56(uint256 x) internal pure returns (uint56) {
        if (x >= 1 << 56) _revertOverflow();
        return uint56(x);
    }

    function toUint64(uint256 x) internal pure returns (uint64) {
        if (x >= 1 << 64) _revertOverflow();
        return uint64(x);
    }

    function toUint72(uint256 x) internal pure returns (uint72) {
        if (x >= 1 << 72) _revertOverflow();
        return uint72(x);
    }

    function toUint80(uint256 x) internal pure returns (uint80) {
        if (x >= 1 << 80) _revertOverflow();
        return uint80(x);
    }

    function toUint88(uint256 x) internal pure returns (uint88) {
        if (x >= 1 << 88) _revertOverflow();
        return uint88(x);
    }

    function toUint96(uint256 x) internal pure returns (uint96) {
        if (x >= 1 << 96) _revertOverflow();
        return uint96(x);
    }

    function toUint104(uint256 x) internal pure returns (uint104) {
        if (x >= 1 << 104) _revertOverflow();
        return uint104(x);
    }

    function toUint112(uint256 x) internal pure returns (uint112) {
        if (x >= 1 << 112) _revertOverflow();
        return uint112(x);
    }

    function toUint120(uint256 x) internal pure returns (uint120) {
        if (x >= 1 << 120) _revertOverflow();
        return uint120(x);
    }

    function toUint128(uint256 x) internal pure returns (uint128) {
        if (x >= 1 << 128) _revertOverflow();
        return uint128(x);
    }

    function toUint136(uint256 x) internal pure returns (uint136) {
        if (x >= 1 << 136) _revertOverflow();
        return uint136(x);
    }

    function toUint144(uint256 x) internal pure returns (uint144) {
        if (x >= 1 << 144) _revertOverflow();
        return uint144(x);
    }

    function toUint152(uint256 x) internal pure returns (uint152) {
        if (x >= 1 << 152) _revertOverflow();
        return uint152(x);
    }

    function toUint160(uint256 x) internal pure returns (uint160) {
        if (x >= 1 << 160) _revertOverflow();
        return uint160(x);
    }

    function toUint168(uint256 x) internal pure returns (uint168) {
        if (x >= 1 << 168) _revertOverflow();
        return uint168(x);
    }

    function toUint176(uint256 x) internal pure returns (uint176) {
        if (x >= 1 << 176) _revertOverflow();
        return uint176(x);
    }

    function toUint184(uint256 x) internal pure returns (uint184) {
        if (x >= 1 << 184) _revertOverflow();
        return uint184(x);
    }

    function toUint192(uint256 x) internal pure returns (uint192) {
        if (x >= 1 << 192) _revertOverflow();
        return uint192(x);
    }

    function toUint200(uint256 x) internal pure returns (uint200) {
        if (x >= 1 << 200) _revertOverflow();
        return uint200(x);
    }

    function toUint208(uint256 x) internal pure returns (uint208) {
        if (x >= 1 << 208) _revertOverflow();
        return uint208(x);
    }

    function toUint216(uint256 x) internal pure returns (uint216) {
        if (x >= 1 << 216) _revertOverflow();
        return uint216(x);
    }

    function toUint224(uint256 x) internal pure returns (uint224) {
        if (x >= 1 << 224) _revertOverflow();
        return uint224(x);
    }

    function toUint232(uint256 x) internal pure returns (uint232) {
        if (x >= 1 << 232) _revertOverflow();
        return uint232(x);
    }

    function toUint240(uint256 x) internal pure returns (uint240) {
        if (x >= 1 << 240) _revertOverflow();
        return uint240(x);
    }

    function toUint248(uint256 x) internal pure returns (uint248) {
        if (x >= 1 << 248) _revertOverflow();
        return uint248(x);
    }

    /*´:°β€’.°+.*β€’´.*:˚.°*.Λšβ€’´.°:°β€’.°β€’.*β€’´.*:˚.°*.Λšβ€’´.°:°β€’.°+.*β€’´.*:*/
    /*           SIGNED INTEGER SAFE CASTING OPERATIONS           */
    /*.β€’°:°.´+˚.*°.˚:*.´β€’*.+°.β€’°:´*.´β€’*.β€’°.β€’°:°.´:β€’Λš°.*°.˚:*.´+°.β€’*/

    function toInt8(int256 x) internal pure returns (int8) {
        int8 y = int8(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt16(int256 x) internal pure returns (int16) {
        int16 y = int16(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt24(int256 x) internal pure returns (int24) {
        int24 y = int24(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt32(int256 x) internal pure returns (int32) {
        int32 y = int32(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt40(int256 x) internal pure returns (int40) {
        int40 y = int40(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt48(int256 x) internal pure returns (int48) {
        int48 y = int48(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt56(int256 x) internal pure returns (int56) {
        int56 y = int56(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt64(int256 x) internal pure returns (int64) {
        int64 y = int64(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt72(int256 x) internal pure returns (int72) {
        int72 y = int72(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt80(int256 x) internal pure returns (int80) {
        int80 y = int80(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt88(int256 x) internal pure returns (int88) {
        int88 y = int88(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt96(int256 x) internal pure returns (int96) {
        int96 y = int96(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt104(int256 x) internal pure returns (int104) {
        int104 y = int104(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt112(int256 x) internal pure returns (int112) {
        int112 y = int112(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt120(int256 x) internal pure returns (int120) {
        int120 y = int120(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt128(int256 x) internal pure returns (int128) {
        int128 y = int128(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt136(int256 x) internal pure returns (int136) {
        int136 y = int136(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt144(int256 x) internal pure returns (int144) {
        int144 y = int144(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt152(int256 x) internal pure returns (int152) {
        int152 y = int152(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt160(int256 x) internal pure returns (int160) {
        int160 y = int160(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt168(int256 x) internal pure returns (int168) {
        int168 y = int168(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt176(int256 x) internal pure returns (int176) {
        int176 y = int176(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt184(int256 x) internal pure returns (int184) {
        int184 y = int184(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt192(int256 x) internal pure returns (int192) {
        int192 y = int192(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt200(int256 x) internal pure returns (int200) {
        int200 y = int200(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt208(int256 x) internal pure returns (int208) {
        int208 y = int208(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt216(int256 x) internal pure returns (int216) {
        int216 y = int216(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt224(int256 x) internal pure returns (int224) {
        int224 y = int224(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt232(int256 x) internal pure returns (int232) {
        int232 y = int232(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt240(int256 x) internal pure returns (int240) {
        int240 y = int240(x);
        if (x != y) _revertOverflow();
        return y;
    }

    function toInt248(int256 x) internal pure returns (int248) {
        int248 y = int248(x);
        if (x != y) _revertOverflow();
        return y;
    }

    /*´:°β€’.°+.*β€’´.*:˚.°*.Λšβ€’´.°:°β€’.°β€’.*β€’´.*:˚.°*.Λšβ€’´.°:°β€’.°+.*β€’´.*:*/
    /*                      PRIVATE HELPERS                       */
    /*.β€’°:°.´+˚.*°.˚:*.´β€’*.+°.β€’°:´*.´β€’*.β€’°.β€’°:°.´:β€’Λš°.*°.˚:*.´+°.β€’*/

    function _revertOverflow() private pure {
        /// @solidity memory-safe-assembly
        assembly {
            // Store the function selector of `Overflow()`.
            mstore(0x00, 0x35278d12)
            // Revert with (offset, size).
            revert(0x1c, 0x04)
        }
    }
}

File 17 of 24 : 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 multiplication overflow.
    error MulWadFailed();

    /// @dev The operation failed, either due to a
    /// multiplication overflow, or a division by a zero.
    error DivWadFailed();

    /// @dev The multiply-divide 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 output is undefined, as the input is zero.
    error Log2Undefined();

    /*´:°β€’.°+.*β€’´.*:˚.°*.Λšβ€’´.°:°β€’.°β€’.*β€’´.*:˚.°*.Λšβ€’´.°:°β€’.°+.*β€’´.*:*/
    /*                         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))) {
                // Store the function selector of `MulWadFailed()`.
                mstore(0x00, 0xbac65e5b)
                // Revert with (offset, size).
                revert(0x1c, 0x04)
            }
            z := div(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))) {
                // Store the function selector of `MulWadFailed()`.
                mstore(0x00, 0xbac65e5b)
                // Revert with (offset, size).
                revert(0x1c, 0x04)
            }
            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)))))) {
                // Store the function selector of `DivWadFailed()`.
                mstore(0x00, 0x7c5f487d)
                // Revert with (offset, size).
                revert(0x1c, 0x04)
            }
            z := div(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)))))) {
                // Store the function selector of `DivWadFailed()`.
                mstore(0x00, 0x7c5f487d)
                // Revert with (offset, size).
                revert(0x1c, 0x04)
            }
            z := add(iszero(iszero(mod(mul(x, WAD), y))), div(mul(x, WAD), y))
        }
    }

    /// @dev Equivalent to `x` to the power of `y`.
    /// because `x ** y = (e ** ln(x)) ** y = e ** (ln(x) * y)`.
    function powWad(int256 x, int256 y) internal pure returns (int256) {
        // Using `ln(x)` means `x` must be greater than 0.
        return expWad((lnWad(x) * y) / int256(WAD));
    }

    /// @dev Returns `exp(x)`, denominated in `WAD`.
    function expWad(int256 x) internal pure returns (int256 r) {
        unchecked {
            // When the result is < 0.5 we return zero. This happens when
            // x <= floor(log(0.5e18) * 1e18) ~ -42e18
            if (x <= -42139678854452767551) return r;

            /// @solidity memory-safe-assembly
            assembly {
                // When the result is > (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)) {
                    // Store the function selector of `ExpOverflow()`.
                    mstore(0x00, 0xa37bfec9)
                    // Revert with (offset, size).
                    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`.
    function lnWad(int256 x) internal pure returns (int256 r) {
        unchecked {
            /// @solidity memory-safe-assembly
            assembly {
                if iszero(sgt(x, 0)) {
                    // Store the function selector of `LnWadUndefined()`.
                    mstore(0x00, 0x1615e638)
                    // Revert with (offset, size).
                    revert(0x1c, 0x04)
                }
            }

            // 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.
            int256 k;
            /// @solidity memory-safe-assembly
            assembly {
                let v := x
                k := shl(7, lt(0xffffffffffffffffffffffffffffffff, v))
                k := or(k, shl(6, lt(0xffffffffffffffff, shr(k, v))))
                k := or(k, shl(5, lt(0xffffffff, shr(k, v))))

                // For the remaining 32 bits, use a De Bruijn lookup.
                // See: https://graphics.stanford.edu/~seander/bithacks.html
                v := shr(k, v)
                v := or(v, shr(1, v))
                v := or(v, shr(2, v))
                v := or(v, shr(4, v))
                v := or(v, shr(8, v))
                v := or(v, shr(16, v))

                // forgefmt: disable-next-item
                k := sub(or(k, byte(shr(251, mul(v, shl(224, 0x07c4acdd))),
                    0x0009010a0d15021d0b0e10121619031e080c141c0f111807131b17061a05041f)), 96)
            }

            // Reduce range of x to (1, 2) * 2**96
            // ln(2^k * x) = k * ln(2) + ln(x)
            x <<= uint256(159 - k);
            x = int256(uint256(x) >> 159);

            // Evaluate using a (8, 8)-term rational approximation.
            // p is made monic, we will multiply by a scale factor later.
            int256 p = x + 3273285459638523848632254066296;
            p = ((p * x) >> 96) + 24828157081833163892658089445524;
            p = ((p * x) >> 96) + 43456485725739037958740375743393;
            p = ((p * x) >> 96) - 11111509109440967052023855526967;
            p = ((p * x) >> 96) - 45023709667254063763336534515857;
            p = ((p * x) >> 96) - 14706773417378608786704636184526;
            p = p * x - (795164235651350426258249787498 << 96);

            // 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.
            int256 q = x + 5573035233440673466300451813936;
            q = ((q * x) >> 96) + 71694874799317883764090561454958;
            q = ((q * x) >> 96) + 283447036172924575727196451306956;
            q = ((q * x) >> 96) + 401686690394027663651624208769553;
            q = ((q * x) >> 96) + 204048457590392012362485061816622;
            q = ((q * x) >> 96) + 31853899698501571402653359427138;
            q = ((q * x) >> 96) + 909429971244387300277376558375;
            /// @solidity memory-safe-assembly
            assembly {
                // Div in assembly because solidity adds a zero check despite the unchecked.
                // The q polynomial is known not to have zeros in the domain.
                // No scaling required because p is already 2**96 too large.
                r := sdiv(p, q)
            }

            // r 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

            // mul s * 5e18 * 2**96, base is now 5**18 * 2**192
            r *= 1677202110996718588342820967067443963516166;
            // add ln(2) * k * 5e18 * 2**192
            r += 16597577552685614221487285958193947469193820559219878177908093499208371 * k;
            // add ln(2**96 / 10**18) * 5e18 * 2**192
            r += 600920179829731861736702779321621459595472258049074101567377883020018308;
            // base conversion: mul 2**18 / 2**192
            r >>= 174;
        }
    }

    /*´:°β€’.°+.*β€’´.*:˚.°*.Λšβ€’´.°:°β€’.°β€’.*β€’´.*:˚.°*.Λšβ€’´.°:°β€’.°+.*β€’´.*:*/
    /*                  GENERAL NUMBER UTILITIES                  */
    /*.β€’°:°.´+˚.*°.˚:*.´β€’*.+°.β€’°:´*.´β€’*.β€’°.β€’°:°.´:β€’Λš°.*°.˚:*.´+°.β€’*/

    /// @dev Calculates `floor(a * b / 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 {
            // forgefmt: disable-next-item
            for {} 1 {} {
                // 512-bit multiply `[prod1 prod0] = 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 = prod1 * 2**256 + prod0`.

                // Least significant 256 bits of the product.
                let prod0 := mul(x, y)
                let mm := mulmod(x, y, not(0))
                // Most significant 256 bits of the product.
                let prod1 := sub(mm, add(prod0, lt(mm, prod0)))

                // Handle non-overflow cases, 256 by 256 division.
                if iszero(prod1) {
                    if iszero(d) {
                        // Store the function selector of `FullMulDivFailed()`.
                        mstore(0x00, 0xae47f702)
                        // Revert with (offset, size).
                        revert(0x1c, 0x04)
                    }
                    result := div(prod0, d)
                    break       
                }

                // Make sure the result is less than `2**256`.
                // Also prevents `d == 0`.
                if iszero(gt(d, prod1)) {
                    // Store the function selector of `FullMulDivFailed()`.
                    mstore(0x00, 0xae47f702)
                    // Revert with (offset, size).
                    revert(0x1c, 0x04)
                }

                ///////////////////////////////////////////////
                // 512 by 256 division.
                ///////////////////////////////////////////////

                // Make division exact by subtracting the remainder from `[prod1 prod0]`.
                // Compute remainder using mulmod.
                let remainder := mulmod(x, y, d)
                // Subtract 256 bit number from 512 bit number.
                prod1 := sub(prod1, gt(remainder, prod0))
                prod0 := sub(prod0, remainder)
                // Factor powers of two out of `d`.
                // Compute largest power of two divisor of `d`.
                // Always greater or equal to 1.
                let twos := and(d, sub(0, d))
                // Divide d by power of two.
                d := div(d, twos)
                // Divide [prod1 prod0] by the factors of two.
                prod0 := div(prod0, twos)
                // Shift in bits from `prod1` into `prod0`. For this we need
                // to flip `twos` such that it is `2**256 / twos`.
                // If `twos` is zero, then it becomes one.
                prod0 := or(prod0, mul(prod1, add(div(sub(0, twos), twos), 1)))
                // 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(mul(3, d), 2)
                // 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(prod0, mul(inv, sub(2, mul(d, inv)))) // inverse mod 2**256
                break
            }
        }
    }

    /// @dev Calculates `floor(x * y / d)` with full precision, rounded up.
    /// Throws if result overflows a uint256 or when `d` is zero.
    /// Credit to Uniswap-v3-core under MIT license:
    /// https://github.com/Uniswap/v3-core/blob/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) {
                if iszero(add(result, 1)) {
                    // Store the function selector of `FullMulDivFailed()`.
                    mstore(0x00, 0xae47f702)
                    // Revert with (offset, size).
                    revert(0x1c, 0x04)
                }
                result := add(result, 1)
            }
        }
    }

    /// @dev Returns `floor(x * y / d)`.
    /// Reverts if `x * y` overflows, or `d` is zero.
    function mulDiv(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            // Equivalent to require(d != 0 && (y == 0 || x <= type(uint256).max / y))
            if iszero(mul(d, iszero(mul(y, gt(x, div(not(0), y)))))) {
                // Store the function selector of `MulDivFailed()`.
                mstore(0x00, 0xad251c27)
                // Revert with (offset, size).
                revert(0x1c, 0x04)
            }
            z := div(mul(x, y), d)
        }
    }

    /// @dev Returns `ceil(x * y / d)`.
    /// Reverts if `x * y` overflows, or `d` is zero.
    function mulDivUp(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            // Equivalent to require(d != 0 && (y == 0 || x <= type(uint256).max / y))
            if iszero(mul(d, iszero(mul(y, gt(x, div(not(0), y)))))) {
                // Store the function selector of `MulDivFailed()`.
                mstore(0x00, 0xad251c27)
                // Revert with (offset, size).
                revert(0x1c, 0x04)
            }
            z := add(iszero(iszero(mod(mul(x, y), d))), div(mul(x, y), d))
        }
    }

    /// @dev Returns `ceil(x / d)`.
    /// Reverts if `d` is zero.
    function divUp(uint256 x, uint256 d) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            if iszero(d) {
                // Store the function selector of `DivFailed()`.
                mstore(0x00, 0x65244e4e)
                // Revert with (offset, size).
                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 the square root of `x`.
    function sqrt(uint256 x) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            // `floor(sqrt(2**15)) = 181`. `sqrt(2**15) - 181 = 2.84`.
            z := 181 // The "correct" value is 1, but this saves a multiplication later.

            // This segment is to get a reasonable initial estimate for the Babylonian method. With a bad
            // start, the correct # of bits increases ~linearly each iteration instead of ~quadratically.

            // Let `y = x / 2**r`.
            // We check `y >= 2**(k + 8)` but shift right by `k` bits
            // each branch 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
            // Since the ceil is rare, we save gas on the assignment and repeat division in the rare case.
            // If you don't care whether the floor or ceil square root is returned, you can remove this statement.
            z := sub(z, lt(div(x, z), z))
        }
    }

    /// @dev Returns the cube root of `x`.
    /// Credit to bout3fiddy and pcaversaccio under AGPLv3 license:
    /// https://github.com/pcaversaccio/snekmate/blob/main/src/utils/Math.vy
    function cbrt(uint256 x) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            let r := shl(7, lt(0xffffffffffffffffffffffffffffffff, x))
            r := or(r, shl(6, lt(0xffffffffffffffff, shr(r, x))))
            r := or(r, shl(5, lt(0xffffffff, shr(r, x))))
            r := or(r, shl(4, lt(0xffff, shr(r, x))))
            r := or(r, shl(3, lt(0xff, shr(r, x))))

            z := shl(add(div(r, 3), lt(0xf, shr(r, x))), 0xff)
            z := div(z, byte(mod(r, 3), shl(232, 0x7f624b)))

            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 factorial of `x`.
    function factorial(uint256 x) internal pure returns (uint256 result) {
        /// @solidity memory-safe-assembly
        assembly {
            for {} 1 {} {
                if iszero(lt(10, x)) {
                    // forgefmt: disable-next-item
                    result := and(
                        shr(mul(22, x), 0x375f0016260009d80004ec0002d00001e0000180000180000200000400001),
                        0x3fffff
                    )
                    break
                }
                if iszero(lt(57, x)) {
                    let end := 31
                    result := 8222838654177922817725562880000000
                    if iszero(lt(end, x)) {
                        end := 10
                        result := 3628800
                    }
                    for { let w := not(0) } 1 {} {
                        result := mul(result, x)
                        x := add(x, w)
                        if eq(x, end) { break }
                    }
                    break
                }
                // Store the function selector of `FactorialOverflow()`.
                mstore(0x00, 0xaba0f2a2)
                // Revert with (offset, size).
                revert(0x1c, 0x04)
            }
        }
    }

    /// @dev Returns the log2 of `x`.
    /// Equivalent to computing the index of the most significant bit (MSB) of `x`.
    function log2(uint256 x) internal pure returns (uint256 r) {
        /// @solidity memory-safe-assembly
        assembly {
            if iszero(x) {
                // Store the function selector of `Log2Undefined()`.
                mstore(0x00, 0x5be3aa5c)
                // Revert with (offset, size).
                revert(0x1c, 0x04)
            }

            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))))

            // For the remaining 32 bits, use a De Bruijn lookup.
            // See: https://graphics.stanford.edu/~seander/bithacks.html
            x := shr(r, x)
            x := or(x, shr(1, x))
            x := or(x, shr(2, x))
            x := or(x, shr(4, x))
            x := or(x, shr(8, x))
            x := or(x, shr(16, x))

            // forgefmt: disable-next-item
            r := or(r, byte(shr(251, mul(x, shl(224, 0x07c4acdd))),
                0x0009010a0d15021d0b0e10121619031e080c141c0f111807131b17061a05041f))
        }
    }

    /// @dev Returns the log2 of `x`, rounded up.
    function log2Up(uint256 x) internal pure returns (uint256 r) {
        unchecked {
            uint256 isNotPo2;
            assembly {
                isNotPo2 := iszero(iszero(and(x, sub(x, 1))))
            }
            return log2(x) + isNotPo2;
        }
    }

    /// @dev Returns the average of `x` and `y`.
    function avg(uint256 x, uint256 y) internal pure returns (uint256 z) {
        unchecked {
            z = (x & y) + ((x ^ y) >> 1);
        }
    }

    /// @dev Returns the average of `x` and `y`.
    function avg(int256 x, int256 y) internal pure returns (int256 z) {
        unchecked {
            z = (x >> 1) + (y >> 1) + (((x & 1) + (y & 1)) >> 1);
        }
    }

    /// @dev Returns the absolute value of `x`.
    function abs(int256 x) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            let mask := sub(0, shr(255, x))
            z := xor(mask, add(mask, 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 {
            let a := sub(y, x)
            z := xor(a, mul(xor(a, sub(x, y)), sgt(x, y)))
        }
    }

    /// @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)
    {
        z = min(max(x, minValue), maxValue);
    }

    /// @dev Returns `x`, bounded to `minValue` and `maxValue`.
    function clamp(int256 x, int256 minValue, int256 maxValue) internal pure returns (int256 z) {
        z = min(max(x, minValue), maxValue);
    }

    /// @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 {
            // forgefmt: disable-next-item
            for { z := x } y {} {
                let t := y
                y := mod(z, y)
                z := t
            }
        }
    }

    /*´:°β€’.°+.*β€’´.*:˚.°*.Λšβ€’´.°:°β€’.°β€’.*β€’´.*:˚.°*.Λšβ€’´.°:°β€’.°+.*β€’´.*:*/
    /*                   RAW NUMBER OPERATIONS                    */
    /*.β€’°:°.´+˚.*°.˚:*.´β€’*.+°.β€’°:´*.´β€’*.β€’°.β€’°:°.´:β€’Λš°.*°.˚:*.´+°.β€’*/

    /// @dev Returns `x + y`, without checking for overflow.
    function rawAdd(uint256 x, uint256 y) internal pure returns (uint256 z) {
        unchecked {
            z = x + y;
        }
    }

    /// @dev Returns `x + y`, without checking for overflow.
    function rawAdd(int256 x, int256 y) internal pure returns (int256 z) {
        unchecked {
            z = x + y;
        }
    }

    /// @dev Returns `x - y`, without checking for underflow.
    function rawSub(uint256 x, uint256 y) internal pure returns (uint256 z) {
        unchecked {
            z = x - y;
        }
    }

    /// @dev Returns `x - y`, without checking for underflow.
    function rawSub(int256 x, int256 y) internal pure returns (int256 z) {
        unchecked {
            z = x - y;
        }
    }

    /// @dev Returns `x * y`, without checking for overflow.
    function rawMul(uint256 x, uint256 y) internal pure returns (uint256 z) {
        unchecked {
            z = x * y;
        }
    }

    /// @dev Returns `x * y`, without checking for overflow.
    function rawMul(int256 x, int256 y) internal pure returns (int256 z) {
        unchecked {
            z = x * y;
        }
    }

    /// @dev Returns `x / y`, returning 0 if `y` is zero.
    function rawDiv(uint256 x, uint256 y) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := div(x, y)
        }
    }

    /// @dev Returns `x / y`, returning 0 if `y` is zero.
    function rawSDiv(int256 x, int256 y) internal pure returns (int256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := sdiv(x, y)
        }
    }

    /// @dev Returns `x % y`, returning 0 if `y` is zero.
    function rawMod(uint256 x, uint256 y) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := mod(x, y)
        }
    }

    /// @dev Returns `x % y`, returning 0 if `y` is zero.
    function rawSMod(int256 x, int256 y) internal pure returns (int256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := smod(x, y)
        }
    }

    /// @dev Returns `(x + y) % d`, return 0 if `d` if zero.
    function rawAddMod(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := addmod(x, y, d)
        }
    }

    /// @dev Returns `(x * y) % d`, return 0 if `d` if zero.
    function rawMulMod(uint256 x, uint256 y, uint256 d) internal pure returns (uint256 z) {
        /// @solidity memory-safe-assembly
        assembly {
            z := mulmod(x, y, d)
        }
    }
}

File 18 of 24 : CommitmentsLib.sol
// SPDX-License-Identifier: BUSL-1.1
/*
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ•—β–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ–ˆβ•—β–‘β–‘β–‘β–ˆβ–ˆβ–ˆβ•—
β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ–ˆβ–ˆβ•‘
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•¦β•β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β–ˆβ–ˆβ–ˆβ–ˆβ•”β–ˆβ–ˆβ•‘
β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•¦β•β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘β–‘β•šβ•β•β–‘β–ˆβ–ˆβ•‘
β•šβ•β•β•β•β•β•β–‘β•šβ•β•β•β•β•β•β•β–‘β•šβ•β•β•β•β•β–‘β–‘β•šβ•β•β•β•β•β–‘β•šβ•β•β–‘β–‘β–‘β–‘β–‘β•šβ•β•
*/

pragma solidity 0.8.19;

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

struct AssetCommitment {
    address owner;
    uint128 committedAmount;
    uint128 cumulativeAmountEnd;
}

struct Commitments {
    mapping(uint256 => AssetCommitment) commitments;
    uint64 commitmentCount;
    uint192 totalAssetsCommitted;
}

library CommitmentsLib {
    using SafeCastLib for uint256;

    error NonexistentCommit();

    function add(Commitments storage commitments, address owner, uint256 amount)
        internal
        returns (uint256 newCommitmendId, uint256 cumulativeAmountEnd)
    {
        uint256 commitmentCount = commitments.commitmentCount;
        unchecked {
            newCommitmendId = commitmentCount++;
        }
        cumulativeAmountEnd = commitments.totalAssetsCommitted + amount;
        commitments.commitments[newCommitmendId] = AssetCommitment({
            owner: owner,
            committedAmount: uint128(amount),
            cumulativeAmountEnd: cumulativeAmountEnd.toUint128()
        });
        commitments.commitmentCount = commitmentCount.toUint64();
        // If safe cast to uint128 did not fail cast to uint192 cannot truncate.
        commitments.totalAssetsCommitted = uint192(cumulativeAmountEnd);
    }

    function getAmountSplit(AssetCommitment storage commitment, uint256 totalIncludedAmount)
        internal
        view
        returns (uint256 includedAmount, uint256 excludedAmount)
    {
        uint256 committedAmount = commitment.committedAmount;
        uint256 cumulativeAmountEnd = commitment.cumulativeAmountEnd;
        if (totalIncludedAmount >= cumulativeAmountEnd) {
            includedAmount = committedAmount;
            excludedAmount = 0;
        } else {
            uint256 cumulativeAmountStart = cumulativeAmountEnd - committedAmount;
            if (cumulativeAmountStart > totalIncludedAmount) {
                includedAmount = 0;
                excludedAmount = committedAmount;
            } else {
                unchecked {
                    includedAmount = totalIncludedAmount - cumulativeAmountStart;
                    excludedAmount = committedAmount - includedAmount;
                }
            }
        }
    }

    function get(Commitments storage commitments, uint256 id) internal view returns (AssetCommitment storage) {
        if (id >= commitments.commitmentCount) {
            revert NonexistentCommit();
        }
        return commitments.commitments[id];
    }
}

File 19 of 24 : ISwapFacility.sol
// SPDX-License-Identifier: BUSL-1.1
/*
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ•—β–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ–ˆβ•—β–‘β–‘β–‘β–ˆβ–ˆβ–ˆβ•—
β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ–ˆβ–ˆβ•‘
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•¦β•β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β–ˆβ–ˆβ–ˆβ–ˆβ•”β–ˆβ–ˆβ•‘
β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•¦β•β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘β–‘β•šβ•β•β–‘β–ˆβ–ˆβ•‘
β•šβ•β•β•β•β•β•β–‘β•šβ•β•β•β•β•β•β•β–‘β•šβ•β•β•β•β•β–‘β–‘β•šβ•β•β•β•β•β–‘β•šβ•β•β–‘β–‘β–‘β–‘β–‘β•šβ•β•
*/

pragma solidity 0.8.19;

import {IWhitelist} from "../interfaces/IWhitelist.sol";

interface ISwapFacility {
    // =================== Functions ===================

    /// @notice Get Underlying token
    function underlyingToken() external view returns (address);

    /// @notice Get Billy token
    function billyToken() external view returns (address);

    /// @notice Get Price oracle for underlying token
    function underlyingTokenOracle() external view returns (address);

    /// @notice Get Price oracle for billy token
    function billyTokenOracle() external view returns (address);

    /// @notice Get Whitelist contract
    function whitelist() external view returns (IWhitelist);

    /// @notice Get Spread price
    function spread() external view returns (uint256);

    /// @notice Get Pool address
    function pool() external view returns (address);

    /// @notice swap tokens Underlying <-> Billy
    function swap(address inToken, address outToken, uint256 inAmount, bytes32[] calldata proof) external;
}

File 20 of 24 : IBPSFeed.sol
// SPDX-License-Identifier: BUSL-1.1
/*
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ•—β–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ–ˆβ•—β–‘β–‘β–‘β–ˆβ–ˆβ–ˆβ•—
β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ–ˆβ–ˆβ•‘
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•¦β•β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β–ˆβ–ˆβ–ˆβ–ˆβ•”β–ˆβ–ˆβ•‘
β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•¦β•β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘β–‘β•šβ•β•β–‘β–ˆβ–ˆβ•‘
β•šβ•β•β•β•β•β•β–‘β•šβ•β•β•β•β•β•β•β–‘β•šβ•β•β•β•β•β–‘β–‘β•šβ•β•β•β•β•β–‘β•šβ•β•β–‘β–‘β–‘β–‘β–‘β•šβ•β•
*/

pragma solidity 0.8.19;

interface IBPSFeed {
    error InvalidRate();

    event UpdateRate(uint256 currentRate);

    /// @notice Returns weighted rate
    function getWeightedRate() external view returns (uint256);

    /// @notice Returns current rate
    function currentRate() external view returns (uint256);

    /// @notice Returns last timestamp the rate was set
    function lastTimestamp() external view returns (uint256);

    /// @notice Sets new rate
    /// @param rate New rate
    function updateRate(uint256 rate) external;
}

File 21 of 24 : IOracle.sol
// SPDX-License-Identifier: BUSL-1.1
/*
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ•—β–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ–ˆβ•—β–‘β–‘β–‘β–ˆβ–ˆβ–ˆβ•—
β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ•—β–‘β–ˆβ–ˆβ–ˆβ–ˆβ•‘
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•¦β•β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β–ˆβ–ˆβ–ˆβ–ˆβ•”β–ˆβ–ˆβ•‘
β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β–‘β–‘β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘
β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•¦β•β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘β–‘β•šβ•β•β–‘β–ˆβ–ˆβ•‘
β•šβ•β•β•β•β•β•β–‘β•šβ•β•β•β•β•β•β•β–‘β•šβ•β•β•β•β•β–‘β–‘β•šβ•β•β•β•β•β–‘β•šβ•β•β–‘β–‘β–‘β–‘β–‘β•šβ•β•
*/

pragma solidity ^0.8.0;

interface IOracle {
    function latestAnswer() external view returns (int256);

    function decimals() external view returns (uint8);

    function latestRoundData()
        external
        view
        returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound);
}

File 22 of 24 : SafeTransferLib.sol
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;

import {ERC20} from "../tokens/ERC20.sol";

/// @notice Safe ETH and ERC20 transfer library that gracefully handles missing return values.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/SafeTransferLib.sol)
/// @dev Use with caution! Some functions in this library knowingly create dirty bits at the destination of the free memory pointer.
/// @dev Note that none of the functions in this library check that a token has code at all! That responsibility is delegated to the caller.
library SafeTransferLib {
    /*//////////////////////////////////////////////////////////////
                             ETH OPERATIONS
    //////////////////////////////////////////////////////////////*/

    function safeTransferETH(address to, uint256 amount) internal {
        bool success;

        /// @solidity memory-safe-assembly
        assembly {
            // Transfer the ETH and store if it succeeded or not.
            success := call(gas(), to, amount, 0, 0, 0, 0)
        }

        require(success, "ETH_TRANSFER_FAILED");
    }

    /*//////////////////////////////////////////////////////////////
                            ERC20 OPERATIONS
    //////////////////////////////////////////////////////////////*/

    function safeTransferFrom(
        ERC20 token,
        address from,
        address to,
        uint256 amount
    ) internal {
        bool success;

        /// @solidity memory-safe-assembly
        assembly {
            // Get a pointer to some free memory.
            let freeMemoryPointer := mload(0x40)

            // Write the abi-encoded calldata into memory, beginning with the function selector.
            mstore(freeMemoryPointer, 0x23b872dd00000000000000000000000000000000000000000000000000000000)
            mstore(add(freeMemoryPointer, 4), from) // Append the "from" argument.
            mstore(add(freeMemoryPointer, 36), to) // Append the "to" argument.
            mstore(add(freeMemoryPointer, 68), amount) // Append the "amount" argument.

            success := and(
                // Set success to whether the call reverted, if not we check it either
                // returned exactly 1 (can't just be non-zero data), or had no return data.
                or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())),
                // We use 100 because the length of our calldata totals up like so: 4 + 32 * 3.
                // We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
                // Counterintuitively, this call must be positioned second to the or() call in the
                // surrounding and() call or else returndatasize() will be zero during the computation.
                call(gas(), token, 0, freeMemoryPointer, 100, 0, 32)
            )
        }

        require(success, "TRANSFER_FROM_FAILED");
    }

    function safeTransfer(
        ERC20 token,
        address to,
        uint256 amount
    ) internal {
        bool success;

        /// @solidity memory-safe-assembly
        assembly {
            // Get a pointer to some free memory.
            let freeMemoryPointer := mload(0x40)

            // Write the abi-encoded calldata into memory, beginning with the function selector.
            mstore(freeMemoryPointer, 0xa9059cbb00000000000000000000000000000000000000000000000000000000)
            mstore(add(freeMemoryPointer, 4), to) // Append the "to" argument.
            mstore(add(freeMemoryPointer, 36), amount) // Append the "amount" argument.

            success := and(
                // Set success to whether the call reverted, if not we check it either
                // returned exactly 1 (can't just be non-zero data), or had no return data.
                or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())),
                // We use 68 because the length of our calldata totals up like so: 4 + 32 * 2.
                // We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
                // Counterintuitively, this call must be positioned second to the or() call in the
                // surrounding and() call or else returndatasize() will be zero during the computation.
                call(gas(), token, 0, freeMemoryPointer, 68, 0, 32)
            )
        }

        require(success, "TRANSFER_FAILED");
    }

    function safeApprove(
        ERC20 token,
        address to,
        uint256 amount
    ) internal {
        bool success;

        /// @solidity memory-safe-assembly
        assembly {
            // Get a pointer to some free memory.
            let freeMemoryPointer := mload(0x40)

            // Write the abi-encoded calldata into memory, beginning with the function selector.
            mstore(freeMemoryPointer, 0x095ea7b300000000000000000000000000000000000000000000000000000000)
            mstore(add(freeMemoryPointer, 4), to) // Append the "to" argument.
            mstore(add(freeMemoryPointer, 36), amount) // Append the "amount" argument.

            success := and(
                // Set success to whether the call reverted, if not we check it either
                // returned exactly 1 (can't just be non-zero data), or had no return data.
                or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())),
                // We use 68 because the length of our calldata totals up like so: 4 + 32 * 2.
                // We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
                // Counterintuitively, this call must be positioned second to the or() call in the
                // surrounding and() call or else returndatasize() will be zero during the computation.
                call(gas(), token, 0, freeMemoryPointer, 68, 0, 32)
            )
        }

        require(success, "APPROVE_FAILED");
    }
}

File 23 of 24 : Owned.sol
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;

/// @notice Simple single owner authorization mixin.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/auth/Owned.sol)
abstract contract Owned {
    /*//////////////////////////////////////////////////////////////
                                 EVENTS
    //////////////////////////////////////////////////////////////*/

    event OwnershipTransferred(address indexed user, address indexed newOwner);

    /*//////////////////////////////////////////////////////////////
                            OWNERSHIP STORAGE
    //////////////////////////////////////////////////////////////*/

    address public owner;

    modifier onlyOwner() virtual {
        require(msg.sender == owner, "UNAUTHORIZED");

        _;
    }

    /*//////////////////////////////////////////////////////////////
                               CONSTRUCTOR
    //////////////////////////////////////////////////////////////*/

    constructor(address _owner) {
        owner = _owner;

        emit OwnershipTransferred(address(0), _owner);
    }

    /*//////////////////////////////////////////////////////////////
                             OWNERSHIP LOGIC
    //////////////////////////////////////////////////////////////*/

    function transferOwnership(address newOwner) public virtual onlyOwner {
        owner = newOwner;

        emit OwnershipTransferred(msg.sender, newOwner);
    }
}

File 24 of 24 : Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }
}

Settings
{
  "remappings": [
    "ds-test/=lib/forge-safe/lib/ds-test/src/",
    "erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
    "forge-safe/=lib/forge-safe/",
    "forge-std/=lib/forge-std/src/",
    "openzeppelin-contracts/=lib/openzeppelin-contracts/",
    "openzeppelin/=lib/openzeppelin-contracts/contracts/",
    "solady/=lib/solady/src/",
    "solidity-stringutils/=lib/forge-safe/lib/surl/lib/solidity-stringutils/",
    "solmate/=lib/solmate/src/",
    "surl/=lib/forge-safe/lib/surl/"
  ],
  "optimizer": {
    "enabled": true,
    "runs": 100
  },
  "metadata": {
    "bytecodeHash": "ipfs",
    "appendCBOR": true
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "evmVersion": "paris",
  "viaIR": true,
  "libraries": {}
}

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"InvalidPoolAddress","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"pool","type":"address"},{"indexed":false,"internalType":"address","name":"swapFacility","type":"address"}],"name":"NewBloomPoolCreated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferStarted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[],"name":"acceptOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"name","type":"string"},{"internalType":"string","name":"symbol","type":"string"},{"internalType":"address","name":"underlyingToken","type":"address"},{"internalType":"address","name":"billToken","type":"address"},{"internalType":"contract IRegistry","name":"exchangeRateRegistry","type":"address"},{"components":[{"internalType":"address","name":"treasury","type":"address"},{"internalType":"address","name":"borrowerWhiteList","type":"address"},{"internalType":"address","name":"lenderReturnBpsFeed","type":"address"},{"internalType":"address","name":"emergencyHandler","type":"address"},{"internalType":"uint256","name":"leverageBps","type":"uint256"},{"internalType":"uint256","name":"minBorrowDeposit","type":"uint256"},{"internalType":"uint256","name":"commitPhaseDuration","type":"uint256"},{"internalType":"uint256","name":"swapTimeout","type":"uint256"},{"internalType":"uint256","name":"poolPhaseDuration","type":"uint256"},{"internalType":"uint256","name":"lenderReturnFee","type":"uint256"},{"internalType":"uint256","name":"borrowerReturnFee","type":"uint256"}],"internalType":"struct IBloomFactory.PoolParams","name":"poolParams","type":"tuple"},{"components":[{"internalType":"address","name":"underlyingTokenOracle","type":"address"},{"internalType":"address","name":"billyTokenOracle","type":"address"},{"internalType":"address","name":"swapWhitelist","type":"address"},{"internalType":"uint256","name":"spread","type":"uint256"},{"internalType":"uint256","name":"minStableValue","type":"uint256"},{"internalType":"uint256","name":"maxBillyValue","type":"uint256"}],"internalType":"struct IBloomFactory.SwapFacilityParams","name":"swapFacilityParams","type":"tuple"},{"internalType":"uint256","name":"factoryNonce","type":"uint256"}],"name":"create","outputs":[{"internalType":"contract BloomPool","name":"","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getLastCreatedPool","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"pool","type":"address"}],"name":"isPoolFromFactory","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pendingOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"}]

60803461007057601f61566d38819003918201601f19168301916001600160401b038311848410176100755780849260209460405283398101031261007057516001600160a01b0381168103610070576100619061005c3361008b565b61008b565b60405161559390816100da8239f35b600080fd5b634e487b7160e01b600052604160045260246000fd5b60018060a01b031990816001541660015560005460018060a01b038092168093821617600055167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0600080a356fe608060405260043610156200001357600080fd5b60003560e01c80631a9cb48c14620002e05780635ed3128214620002b55780636634b7531462000272578063715018a6146200020957806379ba509714620001465780638da5cb5b146200011b578063e30c397814620000f05763f2fde38b146200007d57600080fd5b34620000eb576020366003190112620000eb576200009a620007d3565b620000a4620007ea565b60018060a01b03809116908160018060a01b03196001541617600155600054167f38d16b8cac22d99fc7c124b9cd0de2d3fa1faef420bfe791d8c362d765e22700600080a3005b600080fd5b34620000eb576000366003190112620000eb576001546040516001600160a01b039091168152602090f35b34620000eb576000366003190112620000eb576000546040516001600160a01b039091168152602090f35b34620000eb576000366003190112620000eb576001546001600160a01b033381831603620001b25760018060a01b03198092166001556000549133908316176000553391167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0600080a3005b60405162461bcd60e51b815260206004820152602960248201527f4f776e61626c6532537465703a2063616c6c6572206973206e6f7420746865206044820152683732bb9037bbb732b960b91b6064820152608490fd5b34620000eb576000366003190112620000eb5762000226620007ea565b600180546001600160a01b0319908116909155600080549182168155906001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a3005b34620000eb576020366003190112620000eb576001600160a01b0362000297620007d3565b166000526003602052602060ff604060002054166040519015158152f35b34620000eb576000366003190112620000eb576002546040516001600160a01b039091168152602090f35b34620000eb576102e0366003190112620000eb5760043567ffffffffffffffff8111620000eb57620003179036906004016200076c565b60243567ffffffffffffffff8111620000eb576200033a9036906004016200076c565b906044356001600160a01b0381168103620000eb57606435916001600160a01b0383168303620000eb57608435916001600160a01b0383168303620000eb576101603660a3190112620000eb5760c036610203190112620000eb576102c435620003a3620007ea565b6001810181116200075657607f6001820111156200072f5760085b60018201811c620007265760019060031c910181523060081b60005280608001601f536094600a536009908060d60182536017019020935b610204356001600160a01b0381168103620000eb57610224356001600160a01b0381168103620000eb5761024435906001600160a01b0382168203620000eb57604051928361142881011067ffffffffffffffff61142886011117620006f2576114286200413685396001600160a01b03868116611428860190815286821660208201529181166040830152918216606082015291811660808301526102643560a0830152871660c08201526102843560e08201526102a43561010082015281900361012001906000f0958615620007085760c435926001600160a01b0384168403620000eb5760a4356001600160a01b0381169003620000eb5760e435946001600160a01b0386168603620000eb57610104356001600160a01b0381168103620000eb5760405196876138b081011067ffffffffffffffff6138b08a011117620006f25787966200060696620005ee956138b0620008868b396001600160a01b039081166138b08b01908152918116602083015291821660408201528c8216606082015260a4358216608082015291811660a08301529190911660c08201526101243560e08201526101443561010082015261016435610120820152610184356101408201526101a4356101608201526101c4356101808201526101e4356101a08201526102006101c08201819052019062000843565b906138b0840182036101e06138b08601015262000843565b03906000f0801562000708576001600160a01b039081169216820362000714576000828152600360205260409020805460ff19166001179055600280546001600160a01b031916831790556001600160a01b0381163b15620000eb576040516213049560e71b815260048101839052906000908290602490829084906001600160a01b03165af180156200070857620006d8575b50807f54a17a2091ac643cd96590b7dacb5a435d9cdd58d5d0f6306bcff71dd1fb7170602080946040519060018060a01b03168152a2604051908152f35b67ffffffffffffffff8111620006f257604052806200069a565b634e487b7160e01b600052604160045260246000fd5b6040513d6000823e3d90fd5b60405163da6a56c360e01b8152600490fd5b600801620003be565b601790306000526094600b53600a9060d68253600101801560071b176020532093620003f6565b634e487b7160e01b600052601160045260246000fd5b81601f82011215620000eb5780359067ffffffffffffffff92838311620006f25760405193601f8401601f19908116603f0116850190811185821017620006f25760405282845260208383010111620000eb57816000926020809301838601378301015290565b600435906001600160a01b0382168203620000eb57565b6000546001600160a01b03163303620007ff57565b606460405162461bcd60e51b815260206004820152602060248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152fd5b919082519283825260005b84811062000870575050826000602080949584010152601f8019910116010190565b6020818301810151848301820152016200084e56fe61038060405234620008b757620038b080380380916200002282610380620008bc565b610380396102008112620008b7576200003d610380620008e0565b906200004b6103a0620008e0565b6103c051909290916001600160a01b0383168303620008b757620000716103e0620008e0565b6200007e610400620008e0565b6200008b610420620008e0565b62000098610440620008e0565b61046051610480516104a0516104c0516104e0516105005161034052610520516103605261054051919c909992989397949694939290916001600160401b038111620008b757620000f39082610380019061038001620008f5565b61056051916001600160401b038311620008b7576004926200011e91610380019061038001620008f5565b9060208d6040519485809263313ce56760e01b825260018060a01b03165afa928315620008ab576000936200085d575b508051906001600160401b038211620005cb578190620001706000546200097a565b601f8111620007fd575b50602090601f8311600114620007815760009262000775575b50508160011b916000199060031b1c1916176000555b8051906001600160401b038211620005cb578190620001ca6001546200097a565b601f811162000714575b50602090601f831160011462000696576000926200068a575b50508160011b916000199060031b1c1916176001555b6080524660a0526040516102e0526000805462000220816200097a565b80610320526102e05152600181169081600014620006615750600114620005e1575b906200027a7f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f9a9b9c926102e05180910390620008bc565b6102e0518051602091820120604080519283019c8d528201527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc660608201524660808201523060a08083019190915281529b60c08d019a6001600160401b038c118e8d1017620005cb57620003739d620003489c60405251902060c052600160ff19600a541617600a5560e052610100526101205261014052610160526101a052610180526101c0526101e0526200033381426200096c565b610200526200034e856200034883426200096c565b6200096c565b6102205262000363836200034883426200096c565b610260528261028052426200096c565b908060011b9080820460021490151715620005b55762000393916200096c565b61024052610340516102a052610360516102c052604051612eb8620009b8823960805181611f50015260a051816124b2015260c051816124d9015260e05181818161031301528181610403015281816105520152818161087201528181610e8a015281816111a80152818161137b0152818161161f015281816119f401528181611b3b01528181611d1701528181611fcf015261286201526101005181818161033d0152818161044a015281816104b4015281816105a5015281816107e7015281816112b201528181611be901528181611eec0152612a500152610120518181816115df01526121560152610140518181816103790152818161130701528181611b5d01528181611e8401526127f5015261016051818181611f8a01526129dc015261018051818181610691015281816107c20152818161084d015281816117f6015261201401526101a051818181610c9d0152612d2501526101c0518181816105eb0152818161195601528181611a8301528181611afc01528181611dcf0152818161297b0152612ba801526101e05181818161122601526115780152610200518181816102320152612be4015261022051818181611a480152612cb60152610240518181816102700152612c5c0152610260518181816104ed01528181610c640152612c8c0152610280518181816115010152612d8601526102a051818181610dd701526128bf01526102c05181818161211d01526128f20152612eb890f35b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052604160045260246000fd5b50600080805261030052989796959493929190600080516020620038708339815191525b6103205161030051908110156200063a579060019160208254916102e051010152019a60206103005101610300529a62000605565b5050610300516102e051999a98999798969795969495939492939192910160200162000242565b6102e0805160ff1990921660209283015261032051905190151560051b01019150620002429050565b015190503880620001ed565b6001600090815293506000805160206200389083398151915291905b601f1984168510620006f8576001945083601f19811610620006de575b505050811b0160015562000203565b015160001960f88460031b161c19169055388080620006cf565b81810151835560209485019460019093019290910190620006b2565b600160005290915060008051602062003890833981519152601f840160051c8101602085106200076d575b90849392915b601f830160051c820181106200075d575050620001d4565b6000815585945060010162000745565b50806200073f565b01519050388062000193565b600080805293506000805160206200387083398151915291905b601f1984168510620007e1576001945083601f19811610620007c7575b505050811b01600055620001a9565b015160001960f88460031b161c19169055388080620007b8565b818101518355602094850194600190930192909101906200079b565b6000805290915060008051602062003870833981519152601f840160051c81016020851062000855575b90849392915b601f830160051c82018110620008455750506200017a565b600081558594506001016200082d565b508062000827565b6020939193813d602011620008a2575b816200087c60209383620008bc565b810103126200089e57519060ff821682036200089b575091386200014e565b80fd5b5080fd5b3d91506200086d565b6040513d6000823e3d90fd5b600080fd5b601f909101601f19168101906001600160401b03821190821017620005cb57604052565b51906001600160a01b0382168203620008b757565b919080601f84011215620008b7578251906001600160401b038211620005cb576040519160209162000931601f8301601f1916840185620008bc565b818452828287010111620008b75760005b8181106200095857508260009394955001015290565b858101830151848201840152820162000942565b91908201809211620005b557565b90600182811c92168015620009ac575b60208310146200099657565b634e487b7160e01b600052602260045260246000fd5b91607f16916200098a56fe608080604052600436101561001357600080fd5b600090813560e01c90816306fdde031461228e5750806307ea4c0114612248578063095ea7b3146121d15780630c1f70a1146121a357806318160ddd146121855780631bb7cc9914612140578063208c6b861461210557806323b872dd14612043578063267b626e14611ffe57806329db1be614611fb95780632d2c556514611f74578063313ce56714611f365780633456878014611f1b5780633639a82f14611ed65780633644e51514611eb3578063380bfc9914611e6e578063466ad01c14611e485780634c62a8f014611d3b5780635594012014611c455780635a196ae814611aa65780635eace5f214611a6b5780635f4d1eae14611a3057806364eb1c0b146118d857806370a082311461189f5780637ecebe001461186657806380ebc282146117b45780638538a498146115245780638ac732a6146114e957806395d89b411461142c578063970a558314611249578063a109fa561461120e578063a1f5d4da14611088578063a9059cbb14611013578063ab7ac1ed14610fe5578063ae4c12bb14610e4a578063af256edf14610dfa578063b9bd4e5a14610dbf578063c19d93fb14610d95578063c7f463f914610ccc578063cbc9bdda14610c87578063cf91e6bf14610c4c578063d505accf14610a2f578063db2e21bc146102e2578063dd62ed3e14610293578063e28035d7146102585763e6d0c4891461021b57600080fd5b3461025557806003193601126102555760206040517f00000000000000000000000000000000000000000000000000000000000000008152f35b80fd5b503461025557806003193601126102555760206040517f00000000000000000000000000000000000000000000000000000000000000008152f35b5034610255576040366003190112610255576102ad61240b565b60406102b7612421565b9260018060a01b03809316815260046020522091166000526020526020604060002054604051908152f35b50346102555780600319360112610255576102fb612be2565b6009811015610a1b57600781036109fb5750610337307f0000000000000000000000000000000000000000000000000000000000000000612b77565b610361307f0000000000000000000000000000000000000000000000000000000000000000612b77565b604051631698272560e31b81529091906020816004817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa9081156109ab5784916109b6575b506040516350d25bcd60e01b81529190602090839060049082906001600160a01b03165afa9182156109ab578492610973575b5081156109615760405163313ce56760e01b80825290936020856004817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa948515610935578695610940575b506040519182526020826004817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa918215610935578692610904575b5061049360ff861660ff841661248a565b604d81116108f0576104e36104e991600a0a6305f5e1006104dd886104d8307f0000000000000000000000000000000000000000000000000000000000000000612b77565b6126a9565b046126bc565b84612734565b92867f000000000000000000000000000000000000000000000000000000000000000042106108d6575061051b612b9d565b61052f6105288683612d0f565b809661248a565b9060ff6001955b8461084b575b856107c0575b816040519a6105508c612386565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168c526305f5e10060208d0152166040808c0191909152519861059b8a612386565b6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000168a5260208a01521660408801526127108181029082820414821517156107ac57610610907f0000000000000000000000000000000000000000000000000000000000000000906126bc565b91604051968760c08101106001600160401b0360c08a0111176107965760c088016040528752602087015260408601526060850152608084015260a08301526040519060808201948286106001600160401b038711176107965786956040528252602082019384526040820192835260608201901515815260018060a01b037f00000000000000000000000000000000000000000000000000000000000000001691823b156107925760408051637dccb2c560e11b8152915180516001600160a01b03166004840152602081015160248401520151604482015293859385936101a4938593879360a091610724905180516001600160a01b03166064890152602081015160848901526040015160a4880152565b51805160c4870152602081015160e487015260408101516101048701526060810151610124870152608081015161014487015201516101648501525115156101848401525af18015610787576107775750f35b61078090612373565b6102555780f35b6040513d84823e3d90fd5b8580fd5b634e487b7160e01b600052604160045260246000fd5b634e487b7160e01b8a52601160045260248afd5b7f000000000000000000000000000000000000000000000000000000000000000061080b817f0000000000000000000000000000000000000000000000000000000000000000612b17565b506040518781526001600160a01b039091169030907f0fce68bd37d0ff2cb1977193c60fc476d985a8047f711cbcd23e5f38ec546aa090602090a3610542565b7f0000000000000000000000000000000000000000000000000000000000000000610896817f0000000000000000000000000000000000000000000000000000000000000000612b17565b506040518681526001600160a01b039091169030907f0fce68bd37d0ff2cb1977193c60fc476d985a8047f711cbcd23e5f38ec546aa090602090a361053c565b6108e660095460401c809661248a565b9060ff8995610536565b634e487b7160e01b87526011600452602487fd5b61092791925060203d60201161092e575b61091f81836123a1565b810190612afe565b9038610482565b503d610915565b6040513d88823e3d90fd5b61095a91955060203d60201161092e5761091f81836123a1565b933861043b565b60405163956d448360e01b8152600490fd5b9091506020813d6020116109a3575b8161098f602093836123a1565b8101031261099f575190386103e4565b8380fd5b3d9150610982565b6040513d86823e3d90fd5b90506020813d6020116109f3575b816109d1602093836123a1565b8101031261099f5751906001600160a01b038216820361099f579060206103b1565b3d91506109c4565b60405163683f44bb60e11b8152602491610a19906004830190612467565bfd5b634e487b7160e01b82526021600452602482fd5b50346102555760e036600319011261025557610a4961240b565b610a51612421565b90604435606435906084359260ff841680940361079257428310610c0d57610a776124ad565b9360018060a01b038092169485885260209460058652604089209788549860018a0190556040519185888401927f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c984528a604086015216998a606085015287608085015260a084015260c083015260c0825260e08201916001600160401b03918184108385111761079657836040528151902061010082019461190160f01b865261010283015261012282015260428352610160810191838310908311176107965787948b9460809484604052519020835261018082015260a4356101a08201526101c060c43591015282805260015afa15610c025785511680151580610bf9575b15610bc357907f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92592918652600482526040862085600052825280604060002055604051908152a380f35b60405162461bcd60e51b815260048101849052600e60248201526d24a72b20a624a22fa9a4a3a722a960911b6044820152606490fd5b50838114610b79565b6040513d87823e3d90fd5b60405162461bcd60e51b815260206004820152601760248201527614115493525517d11150511312539157d1561412549151604a1b6044820152606490fd5b503461025557806003193601126102555760206040517f00000000000000000000000000000000000000000000000000000000000000008152f35b50346102555780600319360112610255576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b503461025557602036600319011261025557600435610ce9612cf0565b506001600160401b0360095416811015610d83576000526008602052610d7f6040600020600160405191610d1c83612386565b818060a01b038154168352015460018060801b038116602083015260801c60408201526040519182918281516001600160a01b031681526020808301516001600160801b0390811691830191909152604092830151169181019190915260600190565b0390f35b6040516332a6366160e11b8152600490fd5b50346102555780600319360112610255576020610db0612be2565b610dbd6040518092612467565bf35b503461025557806003193601126102555760206040517f00000000000000000000000000000000000000000000000000000000000000008152f35b503461025557602036600319011261025557600435610e17612cf0565b506001600160401b0360075416811015610d83576000526006602052610d7f6040600020600160405191610d1c83612386565b50346102555760203660031901126102555760043590610e68612be2565b906009821015610fd15750600181036109fb57508015610fbf57610eae8130337f0000000000000000000000000000000000000000000000000000000000000000612659565b600954906001600160401b0380831691610ecf81600185019560401c612734565b610f54610edb826126dc565b600160405191610eea83612386565b338352608082811b8390038781166020808701918252938216604080880191825260008d815260089096529094209551865460a087901b8790039182169119161786555192516001600160801b031990821690921b9190911691166001600160801b031617910155565b600160401b851015610fb15760209484936001600160401b03198360401b16911617600955604051918252848201527fc4e37f25cec4977d3d50c92f66c08c232f7eac78356d970e0cdd65225ffa149d60403392a3604051908152f35b6335278d126000526004601cfd5b604051638d52450360e01b8152600490fd5b634e487b7160e01b81526021600452602490fd5b503461025557806003193601126102555760406009546001600160401b0382519180841c8352166020820152f35b50346102555760403660031901126102555761102d61240b565b604060243591338452600360205281842061104984825461248a565b905560018060a01b031692838152600360205220818154019055604051908152600080516020612e6383398151915260203392a3602060405160018152f35b5034610255576020366003190112610255576004356110a5612be2565b60098110156111fa57600881036109fb57508082526006602052604082206001810154908160801c6111e157546001600160a01b031680156111cf576111cc9260018060801b0380931692600a5490611158611137828460101c1696600b54948486169061111c826111178c866126a9565b6126bc565b9962010000600160901b039061113c90611137908d9061248a565b6126dc565b60101b1662010000600160901b03199190911617600a5561248a565b169060018060801b03191617600b558085526006602052846001604082208281550155817fc8f7724a19d1dc1ff217cfef1bb2edb3414520f46dd42ffdea1ec98a59cedf056020604051868152a37f00000000000000000000000000000000000000000000000000000000000000006126f4565b80f35b6040516373f9ebb560e11b8152600490fd5b604051632037236f60e21b815260048101849052602490fd5b634e487b7160e01b83526021600452602483fd5b503461025557806003193601126102555760206040517f00000000000000000000000000000000000000000000000000000000000000008152f35b50346102555760209081600319360112610255576004356001600160401b0381116114285761127c903690600401612437565b9092611286612be2565b93600985101561141457600585036113f7576040516370a0823160e01b815230600482015293945084937f0000000000000000000000000000000000000000000000000000000000000000926001600160a01b039080836024818589165afa9283156113ec5787936113b5575b50600080516020612e4383398151915260407f0000000000000000000000000000000000000000000000000000000000000000926113318489612775565b61133c86858a6127b6565b600660ff19600a541617600a55600682519160058352820152a11690813b15610792578580946113a46040519788968795869463dd9caf6160e01b86527f00000000000000000000000000000000000000000000000000000000000000009060048701612741565b03925af18015610787576107775750f35b809750818094503d83116113e5575b6113ce81836123a1565b810103126113e05786955191386112f3565b600080fd5b503d6113c4565b6040513d89823e3d90fd5b60405163683f44bb60e11b8152602490610a196004820188612467565b634e487b7160e01b84526021600452602484fd5b5080fd5b50346102555780600319360112610255576040516000906001805461145081612339565b808452908281169081156114c15750600114611483575b610d7f83611477818703826123a1565b604051918291826123c2565b92508060005260209283600020916000925b8284106114ae5750505081019091019061147781611467565b8054858501870152928501928101611495565b610d7f955061147793506020915091849260ff191682840152151560051b8201019350611467565b503461025557806003193601126102555760206040517f00000000000000000000000000000000000000000000000000000000000000008152f35b503461025557604036600319011261025557600435906001600160401b036024358181116117b05761155a903690600401612437565b9390611564612be2565b600981101561179c57600181036109fb57507f00000000000000000000000000000000000000000000000000000000000000008210610fbf576115cb90604051918291635a23dd9960e01b8352336004840152604060248401526020976044840191612635565b6001600160a01b03959187918491900381847f00000000000000000000000000000000000000000000000000000000000000008a165af191821561178f578192611755575b505015611743576116438130337f0000000000000000000000000000000000000000000000000000000000000000612659565b60075492828416936116e9868661166186600183019560401c612734565b9486600161166e886126dc565b926040519061167c82612386565b338252608083811b849003948516888401908152958516604080850191825260009889526006909952979096209151825460a085901b85900319169116178155925194516001600160801b03958316959095169490911690921b6001600160801b03191692909217910155565b600160401b811015610fb15784936001600160401b03198360401b16911617600755604051918252848201527fdc35d0d1210063339550b8fa9939bc402fb0bf71d978c48b98ba166b261a1e8460403392a3604051908152f35b604051630b094f2760e31b8152600490fd5b9091508581813d8311611788575b61176d81836123a1565b81010312611428575190811515820361025557503880611610565b503d611763565b50604051903d90823e3d90fd5b634e487b7160e01b85526021600452602485fd5b8280fd5b5034610255576040366003190112610255576117ce61240b565b6024356117d9612be2565b600981101561141457600781036109fb57506001600160a01b03917f000000000000000000000000000000000000000000000000000000000000000083163303611854576111cc927fea6196d807445d7a5ef97b4f06996a3d075e5be717e30cd482794c5da0b95517602060405192858452841692a2612ab7565b604051633d9c7ca360e21b8152600490fd5b5034610255576020366003190112610255576020906040906001600160a01b0361188e61240b565b168152600583522054604051908152f35b5034610255576020366003190112610255576020906040906001600160a01b036118c761240b565b168152600383522054604051908152f35b503461025557602080600319360112611428576004356118f6612be2565b60098110156114145760018111156109fb5750808352600882526040832090600182015460801c15611a1e576040927f53ead95e361ca1924d3168f8130c12e4847fa6352e02cdf01a55d952aa51ff9561198261271061197b600754881c7f0000000000000000000000000000000000000000000000000000000000000000906126a9565b0485612dfe565b9590869560018060a01b03905416968794868a526008815289600185822082815501556119b183600254612734565b600255858a5260038152838a20838154019055858a600080516020612e63833981519152838751878152a38351928352820152a3806119ee578280f35b611a18917f00000000000000000000000000000000000000000000000000000000000000006126f4565b38808280f35b604051633e51778f60e11b8152600490fd5b503461025557806003193601126102555760206040517f00000000000000000000000000000000000000000000000000000000000000008152f35b503461025557806003193601126102555760206040517f00000000000000000000000000000000000000000000000000000000000000008152f35b5034610255576020366003190112610255576004356001600160401b03811161142857611ad7903690600401612437565b90611ae0612be2565b600981101561141457600281036109fb5750611afa612b9d565b7f000000000000000000000000000000000000000000000000000000000000000090612710820190818311611c315791611117611b39928795946126a9565b7f0000000000000000000000000000000000000000000000000000000000000000907f0000000000000000000000000000000000000000000000000000000000000000611b868184612775565b611b918282856127b6565b600360ff19600a541617600a55600080516020612e43833981519152604080516002815260036020820152a16001600160a01b031691823b15611c2d578490611c126040519788968795869463dd9caf6160e01b86527f00000000000000000000000000000000000000000000000000000000000000009060048701612741565b03925af1801561078757611c24575080f35b6111cc90612373565b8480fd5b634e487b7160e01b86526011600452602486fd5b503461025557602036600319011261025557600435611c62612be2565b60098110156111fa57600881036109fb575080611c826111cc9233612ab7565b80600b548060801c600c5491611cdb61113760018060801b0396879384871690611cb08261111789866126a9565b996001600160801b0319978890611ccc90611137908e9061248a565b60801b16911617600b5561248a565b16911617600c556040519081528160208201527f362effd2b777f1d13bcc9a1b841a2985dc4bdaa711824edf76401cd92e3a80a960403392a2337f00000000000000000000000000000000000000000000000000000000000000006126f4565b50346102555760203660031901126102555760043590611d59612be2565b6009811015610a1b5760018111156109fb57508181526006602052604081206001810192835460801c15611a1e5760095460401c9361271094858102958187041490151715611e34577f6226d20d15e9f5667f91ee807d592e22d6db2238f333ac8fb8e36883be0363f9611dfa611df4604096977f0000000000000000000000000000000000000000000000000000000000000000906126bc565b85612dfe565b9490926001600160801b03611e0e856126dc565b169055548551928352602083018590526001600160a01b0316948592a3806119ee578280f35b634e487b7160e01b84526011600452602484fd5b5034610255576040366003190112610255576111cc611e6561240b565b602435906127e9565b50346102555780600319360112610255576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b50346102555780600319360112610255576020611ece6124ad565b604051908152f35b50346102555780600319360112610255576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b50346102555780600319360112610255576020611ece612b9d565b5034610255578060031936011261025557602060405160ff7f0000000000000000000000000000000000000000000000000000000000000000168152f35b50346102555780600319360112610255576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b50346102555780600319360112610255576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b50346102555780600319360112610255576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b50346102555760603660031901126102555761205d61240b565b90612066612421565b600080516020612e638339815191526044359160018060a01b038095169283855260406020968793600485528288203389528552828820548460001982036120e2575b5050868852600385528288206120c085825461248a565b905516958681526003845220818154019055604051908152a360405160018152f35b6120eb9161248a565b87895260048652838920338a5286528389205538846120a9565b503461025557806003193601126102555760206040517f00000000000000000000000000000000000000000000000000000000000000008152f35b50346102555780600319360112610255576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b50346102555780600319360112610255576020600254604051908152f35b503461025557806003193601126102555760406007546001600160401b0382519180841c8352166020820152f35b50346102555760403660031901126102555760406121ed61240b565b9160243591829133815260046020528181209460018060a01b03169485825260205220556040519081527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560203392a3602060405160018152f35b50346102555780600319360112610255576080600180821b0380600a5460101c1690600b5481600c54169160405193845281166020840152831c60408301526060820152f35b9050346114285781600319360112611428578180546122ac81612339565b8084529060019081811690811561231157506001146122d6575b610d7f84611477818803826123a1565b93508180526020938483205b8284106122fe5750505081610d7f9361147792820101936122c6565b80548585018701529285019281016122e2565b610d7f96506114779450602092508593915060ff191682840152151560051b820101936122c6565b90600182811c92168015612369575b602083101461235357565b634e487b7160e01b600052602260045260246000fd5b91607f1691612348565b6001600160401b03811161079657604052565b606081019081106001600160401b0382111761079657604052565b90601f801991011681019081106001600160401b0382111761079657604052565b6020808252825181830181905290939260005b8281106123f757505060409293506000838284010152601f8019910116010190565b8181018601518482016040015285016123d5565b600435906001600160a01b03821682036113e057565b602435906001600160a01b03821682036113e057565b9181601f840112156113e0578235916001600160401b0383116113e0576020808501948460051b0101116113e057565b9060098210156124745752565b634e487b7160e01b600052602160045260246000fd5b9190820391821161249757565b634e487b7160e01b600052601160045260246000fd5b6000467f0000000000000000000000000000000000000000000000000000000000000000036124fb57507f000000000000000000000000000000000000000000000000000000000000000090565b6040518154829161250b82612339565b80825281602094858201946001908782821691826000146126175750506001146125db575b5061253d925003826123a1565b51902091604051918201927f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f845260408301527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc660608301524660808301523060a083015260a0825260c08201908282106001600160401b038311176125c7575060405251902090565b634e487b7160e01b81526041600452602490fd5b8691508780528188209088915b8583106125ff57505061253d935082010138612530565b805483880185015286945088939092019181016125e8565b60ff1916885261253d95151560051b85010192503891506125309050565b81835290916001600160fb1b0383116113e05760209260051b809284830137010190565b601c600060649281946020966040519860605260405260601b602c526323b872dd60601b600c525af13d1560016000511417161561269b576000606052604052565b637939f4246000526004601cfd5b8181029291811591840414171561249757565b81156126c6570490565b634e487b7160e01b600052601260045260246000fd5b600160801b811015610fb1576001600160801b031690565b601092602092601452603452604460009384809363a9059cbb60601b82525af13d15600183511417161561272757603452565b6390b8ec1890526004601cfd5b9190820180921161249757565b6001600160a01b03918216815291166020820152604081019190915260806060820181905261277293910191612635565b90565b60209060109260145260446000938480938160345263095ea7b360601b82525af13d1560018351141716156127a957603452565b633e3f8f7390526004601cfd5b601092602092601452603452604460009384809363095ea7b360601b82525af13d1560018351141716156127a957603452565b6001600160a01b0391907f000000000000000000000000000000000000000000000000000000000000000083163303612aa557612824612be2565b9260098410156124745760038414612a47576006841461285b5760405163683f44bb60e11b8152602490610a196004820187612467565b80919293507f000000000000000000000000000000000000000000000000000000000000000092169082168103612a2f57506128e4612898612b9d565b6128ac6128a58583612d0f565b809561248a565b906128b7818661248a565b6127109384917f0000000000000000000000000000000000000000000000000000000000000000906126a9565b049061291f611137856129177f0000000000000000000000000000000000000000000000000000000000000000876126a9565b04809561248a565b600a805462010000600160901b03191660109290921b62010000600160901b0316919091179055808402938115828604909114171561249757612a01956129d99483926001600160801b03926129ca9284906129a090611137907f0000000000000000000000000000000000000000000000000000000000000000906126bc565b6001600160801b03199691169186916129bd91611137919061248a565b60801b1617600b556126dc565b1690600c541617600c55612734565b907f0000000000000000000000000000000000000000000000000000000000000000906126f4565b600860ff19600a541617600a55600080516020612e43833981519152604080516006815260086020820152a1565b60249060405190639e5f788160e01b82526004820152fd5b925082915016907f0000000000000000000000000000000000000000000000000000000000000000168103612a2f5750600460ff19600a541617600a55600080516020612e43833981519152604080516003815260046020820152a1565b604051630aff86d760e21b8152600490fd5b90600080516020612e63833981519152602060009360018060a01b0316928385526003825260408520612aeb82825461248a565b90558060025403600255604051908152a3565b908160209103126113e0575160ff811681036113e05790565b91906000906370a08231825230602052602060346024601c875afa601f3d111615612b6a5760145260208160446010826034519763a9059cbb60601b82525af13d15600183511417161561272757603452565b6390b8ec1882526004601cfd5b602460106020939284936014526370a0823160601b6000525afa601f3d11166020510290565b612710612bd06007547f00000000000000000000000000000000000000000000000000000000000000009060401c6126a9565b0460095460401c818110908218021890565b7f00000000000000000000000000000000000000000000000000000000000000004210612ceb5760ff600a54166009811015612474576001811480612ce3575b612cdd576003811480612cb3575b612c53576004811480612c89575b612c83576006811480612c59575b612c535790565b50600790565b507f0000000000000000000000000000000000000000000000000000000000000000421015612c4c565b50600590565b507f0000000000000000000000000000000000000000000000000000000000000000421015612c3e565b507f0000000000000000000000000000000000000000000000000000000000000000421015612c30565b50600290565b506001612c22565b600190565b60405190612cfd82612386565b60006040838281528260208201520152565b6040516301e66bcf60e01b8152906020826004817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa918215612df257600092612dbf575b5061270f198201918211612497576127106301da9c00612dab612d84612db395856126a9565b7f0000000000000000000000000000000000000000000000000000000000000000906126a9565b040490612734565b90818110908218021890565b90916020823d8211612dea575b81612dd9602093836123a1565b810103126102555750519038612d5e565b3d9150612dcc565b6040513d6000823e3d90fd5b600101546001600160801b03811692919060801c808210612e20575050600090565b83612e2a9161248a565b9080821115612e3b57505060009190565b038092039056fea4bda53ae0fd969a8a76873655c70563e1c49a76a63384848681457a8b8e52ebddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efa26469706673582212205c0c6896b5dc54898a3fe165d9d30f6be279682d3bdeefe376bf94148ba1ce8a64736f6c63430008130033290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563b10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf66101e0604081815234620003d3578190620014288038038091620000248286620003d8565b843961012092839181010312620003d357620000408362000412565b906020916200005183860162000412565b916200005f81870162000412565b6200006d6060880162000412565b6080880151936001600160a01b0393918486168603620003d35760a08a0151966200009b60c08c0162000412565b9860e08c015195610100809d0151976000953360018060a01b0319885416178755875133887f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08180a36103e88d11620003c45750806080528460a0528260c05287519084826004818663313ce56760e01b98898352165afa918215620003725783929186918a93620003a0575b5060048b5180958193898352165afa918215620003725791620001579160ff938a926200037c575b5062000442565b16938751928084528484600481868b165afa93841562000372579085929189956200034b575b506004908a5194859384928352165afa9283156200034157620001d7938796959360ff93620001ba93620001e29a936200030b575b505062000442565b169081811115620002f95790620001d1916200046d565b6200047b565b60e0528a526200047b565b87526101809384526101a09485526101c09586526101409182526101609283525195610f9d97886200048b893960805188818161024401528181610435015281816106790152818161070b0152818161075e0152610ccf015260a0518881816102b1015281816102fd015281816106bb015281816109fd0152610c15015260c051888181610334015281816107980152610b65015260e0518881816101600152818161040c015261082301525187818161035e015281816107c20152610b210152518681816103d7015281816107ee0152610c5c01525185610385015251846103ac015251838181610a7f0152610ba901525182818161046e015281816108620152610c970152518181816101f90152610d120152f35b62000304916200046d565b926200047b565b62000330929350803d1062000339575b620003278183620003d8565b81019062000427565b903880620001b2565b503d6200031b565b87513d88823e3d90fd5b60049195506200036a90843d86116200033957620003278183620003d8565b94906200017d565b89513d8a823e3d90fd5b62000398919250873d89116200033957620003278183620003d8565b903862000150565b620003bc919350823d84116200033957620003278183620003d8565b913862000128565b633cd146b160e01b8152600490fd5b600080fd5b601f909101601f19168101906001600160401b03821190821017620003fc57604052565b634e487b7160e01b600052604160045260246000fd5b51906001600160a01b0382168203620003d357565b90816020910312620003d3575160ff81168103620003d35790565b9060ff8091169116019060ff82116200045757565b634e487b7160e01b600052601160045260246000fd5b919082039182116200045757565b604d81116200045757600a0a9056fe608060408181526004908136101561001657600080fd5b600092833560e01c90816316f0115b14610cfe575080632495a59914610cba5780635c25c76c14610c7f578063628e040e14610c4457806387db4c4614610c005780638da5cb5b14610bd857806393e59dc114610b94578063afb70dc014610b50578063b4c1392814610b0c578063dd9caf6114610187578063e77fec26146101485763f2fde38b146100a857600080fd5b34610144576020366003190112610144576100c1610d41565b8354926001600160a01b03928385163303610112575050166001600160a01b03199190911681178255337f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08380a380f35b906020606492519162461bcd60e51b8352820152600c60248201526b15539055551213d49256915160a21b6044820152fd5b8280fd5b838234610183578160031936011261018357602090517f00000000000000000000000000000000000000000000000000000000000000008152f35b5080fd5b509034610144576080366003190112610144576101a2610d41565b9160246001600160a01b03813581811690819003610b0857604435956064359367ffffffffffffffff808611610b045736602387011215610b045785880135908111610b04578060051b36838289010111610aeb577f00000000000000000000000000000000000000000000000000000000000000009186831697883314159283610a36575b505050610a2657895460a01c60ff1691826102dc5750505082167f0000000000000000000000000000000000000000000000000000000000000000831614801592906102af575b50506102a1573303610294575050815460ff60a01b1916600160a01b17825560015580f35b51636f61f64160e01b8152fd5b505163c1ab6dc160e01b8152fd5b7f00000000000000000000000000000000000000000000000000000000000000001614159050388061026f565b9260019a9994959a98929897969197988981146000146106a157508a16978a7f0000000000000000000000000000000000000000000000000000000000000000168914801590610675575b6106655784978a956103587f0000000000000000000000000000000000000000000000000000000000000000610e91565b9c6103827f0000000000000000000000000000000000000000000000000000000000000000610e91565b9d7f000000000000000000000000000000000000000000000000000000000000000011610655578d7f000000000000000000000000000000000000000000000000000000000000000010610655576305f5e1007f00000000000000000000000000000000000000000000000000000000000000008181029291830403610624576104318e9f9e9d9e7f000000000000000000000000000000000000000000000000000000000000000090610da8565b9c507f0000000000000000000000000000000000000000000000000000000000000000168d036106495761046790809c92610da8565b90612710917f0000000000000000000000000000000000000000000000000000000000000000830190818411610636576104ab836104a6848794610da8565b610dde565b049c8d9386549485106105d5575b50505050816104e38b6104eb948f8f80960388556104d983600254610dd1565b6002553390610dfe565b339089610dfe565b805415610533575b50505050508151948552602085015283015260608201527fb39c9bc43f811e1a7ce159c5f147458fdb80266bf23c17322013316e27e086d060803392a280f35b8a549060ff8260a01c169060ff82146105c35760ff60a01b19909216910160a01b60ff60a01b16178a556002548a92909190813b156105bf57836044928c948a51978896879563119ab40760e21b87528601528401525af180156105b5576105a4575b5060025538808080806104f3565b6105ae9150610d5c565b8538610596565b84513d8a823e3d90fd5b8380fd5b634e487b7160e01b8d5260118552858dfd5b949f9e9d50929b508b939092916105ec9085610da8565b818102918183041490151715610624576104eb938d9e9f8d9e6106188f966104a684976104e397610dde565b9e5050948194506104b9565b634e487b7160e01b8e5260118752878efd5b50634e487b7160e01b8f5260118752878ffd5b90610467908c90610da8565b8951632f6c3e6f60e11b81528690fd5b865163c1ab6dc160e01b81528390fd5b508a7f000000000000000000000000000000000000000000000000000000000000000016861415610327565b999a949992979195939092600281036107365750505082167f000000000000000000000000000000000000000000000000000000000000000083161480159290610709575b50506102a1573303610294575050825460ff60a01b1916600360a01b1783555580f35b7f0000000000000000000000000000000000000000000000000000000000000000161415905038806106e6565b6003909b9a959b9893919496929814610758575b505050505050505050905080f35b8a16978a7f0000000000000000000000000000000000000000000000000000000000000000168914809b8115916109f9575b506106655784978a956107bc7f0000000000000000000000000000000000000000000000000000000000000000610e91565b506107e67f0000000000000000000000000000000000000000000000000000000000000000610e91565b9c6305f5e1007f00000000000000000000000000000000000000000000000000000000000000008181029291830403610624576108488e9f9e9d9e7f000000000000000000000000000000000000000000000000000000000000000090610da8565b9c50156109ed5761085b90809c92610da8565b90612710917f00000000000000000000000000000000000000000000000000000000000000008301908184116106365761089a836104a6848794610da8565b049c8d93865494851061099e575b50505050816104e38b6108c8948f8f80960388556104d983600254610dd1565b80541561091c575b50505050508151948552602085015283015260608201527fb39c9bc43f811e1a7ce159c5f147458fdb80266bf23c17322013316e27e086d060803392a28038808080808080808061074a565b8a549060ff8260a01c169060ff82146105c35760ff60a01b19909216910160a01b60ff60a01b16178a556002548a92909190813b156105bf57836044928c948a51978896879563119ab40760e21b87528601528401525af180156105b55761098d575b5060025538808080806108d0565b6109979150610d5c565b853861097f565b949f9e9d50929b508b939092916109b59085610da8565b818102918183041490151715610624576108c8938d9e9f8d9e6109e18f966104a684976104e397610dde565b9e5050948194506108a8565b9061085b908c90610da8565b90507f0000000000000000000000000000000000000000000000000000000000000000168614153861078a565b8651630b094f2760e31b81528890fd5b8a51635a23dd9960e01b8152338d8201528681018c905260448101849052935090918d906001600160fb1b0310610b0157836064818481958a602098018484013781010301918a7f0000000000000000000000000000000000000000000000000000000000000000165af1908115610af7578b91610ab9575b5015388080610228565b90506020813d8211610aef575b81610ad360209383610d86565b81010312610aeb57518015158103610aeb5738610aaf565b8a80fd5b3d9150610ac6565b88513d8d823e3d90fd5b80fd5b8980fd5b8680fd5b838234610183578160031936011261018357517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b838234610183578160031936011261018357517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b838234610183578160031936011261018357517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b838234610183578160031936011261018357905490516001600160a01b039091168152602090f35b838234610183578160031936011261018357517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b838234610183578160031936011261018357602090517f00000000000000000000000000000000000000000000000000000000000000008152f35b838234610183578160031936011261018357602090517f00000000000000000000000000000000000000000000000000000000000000008152f35b838234610183578160031936011261018357517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b8490346101835781600319360112610183577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b600435906001600160a01b0382168203610d5757565b600080fd5b67ffffffffffffffff8111610d7057604052565b634e487b7160e01b600052604160045260246000fd5b90601f8019910116810190811067ffffffffffffffff821117610d7057604052565b81810292918115918404141715610dbb57565b634e487b7160e01b600052601160045260246000fd5b91908201809211610dbb57565b8115610de8570490565b634e487b7160e01b600052601260045260246000fd5b9060006064926020958295604051946323b872dd60e01b86526004860152602485015260448401525af13d15601f3d1160016000511416171615610e3e57565b60405162461bcd60e51b81526020600482015260146024820152731514905394d1915497d19493d357d1905253115160621b6044820152606490fd5b519069ffffffffffffffffffff82168203610d5757565b604051633fabe5a360e21b81529060a090829060049082906001600160a01b03165afa8015610f5b576000918291610f07575b506000821315610ef5574203428111610dbb576201fa401115610ee45790565b604051628af0d360e31b8152600490fd5b60405163956d448360e01b8152600490fd5b91905060a0823d8211610f53575b81610f2260a09383610d86565b81010312610b015750610f3481610e7a565b506020810151610f4b608060608401519301610e7a565b509038610ec4565b3d9150610f15565b6040513d6000823e3d90fdfea2646970667358221220f32c1d4f2a332a3beeb4e2440d43aabc8efbf504086db601e38d5ba7729367ac64736f6c63430008130033a2646970667358221220d9cbde723f4234cbe68ca456c4846a077573f32db3e20c57df3f6d23da836d5c64736f6c6343000813003300000000000000000000000021c2bd51f230d69787daf230672f70baa1826f67

Deployed Bytecode

0x608060405260043610156200001357600080fd5b60003560e01c80631a9cb48c14620002e05780635ed3128214620002b55780636634b7531462000272578063715018a6146200020957806379ba509714620001465780638da5cb5b146200011b578063e30c397814620000f05763f2fde38b146200007d57600080fd5b34620000eb576020366003190112620000eb576200009a620007d3565b620000a4620007ea565b60018060a01b03809116908160018060a01b03196001541617600155600054167f38d16b8cac22d99fc7c124b9cd0de2d3fa1faef420bfe791d8c362d765e22700600080a3005b600080fd5b34620000eb576000366003190112620000eb576001546040516001600160a01b039091168152602090f35b34620000eb576000366003190112620000eb576000546040516001600160a01b039091168152602090f35b34620000eb576000366003190112620000eb576001546001600160a01b033381831603620001b25760018060a01b03198092166001556000549133908316176000553391167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0600080a3005b60405162461bcd60e51b815260206004820152602960248201527f4f776e61626c6532537465703a2063616c6c6572206973206e6f7420746865206044820152683732bb9037bbb732b960b91b6064820152608490fd5b34620000eb576000366003190112620000eb5762000226620007ea565b600180546001600160a01b0319908116909155600080549182168155906001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a3005b34620000eb576020366003190112620000eb576001600160a01b0362000297620007d3565b166000526003602052602060ff604060002054166040519015158152f35b34620000eb576000366003190112620000eb576002546040516001600160a01b039091168152602090f35b34620000eb576102e0366003190112620000eb5760043567ffffffffffffffff8111620000eb57620003179036906004016200076c565b60243567ffffffffffffffff8111620000eb576200033a9036906004016200076c565b906044356001600160a01b0381168103620000eb57606435916001600160a01b0383168303620000eb57608435916001600160a01b0383168303620000eb576101603660a3190112620000eb5760c036610203190112620000eb576102c435620003a3620007ea565b6001810181116200075657607f6001820111156200072f5760085b60018201811c620007265760019060031c910181523060081b60005280608001601f536094600a536009908060d60182536017019020935b610204356001600160a01b0381168103620000eb57610224356001600160a01b0381168103620000eb5761024435906001600160a01b0382168203620000eb57604051928361142881011067ffffffffffffffff61142886011117620006f2576114286200413685396001600160a01b03868116611428860190815286821660208201529181166040830152918216606082015291811660808301526102643560a0830152871660c08201526102843560e08201526102a43561010082015281900361012001906000f0958615620007085760c435926001600160a01b0384168403620000eb5760a4356001600160a01b0381169003620000eb5760e435946001600160a01b0386168603620000eb57610104356001600160a01b0381168103620000eb5760405196876138b081011067ffffffffffffffff6138b08a011117620006f25787966200060696620005ee956138b0620008868b396001600160a01b039081166138b08b01908152918116602083015291821660408201528c8216606082015260a4358216608082015291811660a08301529190911660c08201526101243560e08201526101443561010082015261016435610120820152610184356101408201526101a4356101608201526101c4356101808201526101e4356101a08201526102006101c08201819052019062000843565b906138b0840182036101e06138b08601015262000843565b03906000f0801562000708576001600160a01b039081169216820362000714576000828152600360205260409020805460ff19166001179055600280546001600160a01b031916831790556001600160a01b0381163b15620000eb576040516213049560e71b815260048101839052906000908290602490829084906001600160a01b03165af180156200070857620006d8575b50807f54a17a2091ac643cd96590b7dacb5a435d9cdd58d5d0f6306bcff71dd1fb7170602080946040519060018060a01b03168152a2604051908152f35b67ffffffffffffffff8111620006f257604052806200069a565b634e487b7160e01b600052604160045260246000fd5b6040513d6000823e3d90fd5b60405163da6a56c360e01b8152600490fd5b600801620003be565b601790306000526094600b53600a9060d68253600101801560071b176020532093620003f6565b634e487b7160e01b600052601160045260246000fd5b81601f82011215620000eb5780359067ffffffffffffffff92838311620006f25760405193601f8401601f19908116603f0116850190811185821017620006f25760405282845260208383010111620000eb57816000926020809301838601378301015290565b600435906001600160a01b0382168203620000eb57565b6000546001600160a01b03163303620007ff57565b606460405162461bcd60e51b815260206004820152602060248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65726044820152fd5b919082519283825260005b84811062000870575050826000602080949584010152601f8019910116010190565b6020818301810151848301820152016200084e56fe61038060405234620008b757620038b080380380916200002282610380620008bc565b610380396102008112620008b7576200003d610380620008e0565b906200004b6103a0620008e0565b6103c051909290916001600160a01b0383168303620008b757620000716103e0620008e0565b6200007e610400620008e0565b6200008b610420620008e0565b62000098610440620008e0565b61046051610480516104a0516104c0516104e0516105005161034052610520516103605261054051919c909992989397949694939290916001600160401b038111620008b757620000f39082610380019061038001620008f5565b61056051916001600160401b038311620008b7576004926200011e91610380019061038001620008f5565b9060208d6040519485809263313ce56760e01b825260018060a01b03165afa928315620008ab576000936200085d575b508051906001600160401b038211620005cb578190620001706000546200097a565b601f8111620007fd575b50602090601f8311600114620007815760009262000775575b50508160011b916000199060031b1c1916176000555b8051906001600160401b038211620005cb578190620001ca6001546200097a565b601f811162000714575b50602090601f831160011462000696576000926200068a575b50508160011b916000199060031b1c1916176001555b6080524660a0526040516102e0526000805462000220816200097a565b80610320526102e05152600181169081600014620006615750600114620005e1575b906200027a7f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f9a9b9c926102e05180910390620008bc565b6102e0518051602091820120604080519283019c8d528201527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc660608201524660808201523060a08083019190915281529b60c08d019a6001600160401b038c118e8d1017620005cb57620003739d620003489c60405251902060c052600160ff19600a541617600a5560e052610100526101205261014052610160526101a052610180526101c0526101e0526200033381426200096c565b610200526200034e856200034883426200096c565b6200096c565b6102205262000363836200034883426200096c565b610260528261028052426200096c565b908060011b9080820460021490151715620005b55762000393916200096c565b61024052610340516102a052610360516102c052604051612eb8620009b8823960805181611f50015260a051816124b2015260c051816124d9015260e05181818161031301528181610403015281816105520152818161087201528181610e8a015281816111a80152818161137b0152818161161f015281816119f401528181611b3b01528181611d1701528181611fcf015261286201526101005181818161033d0152818161044a015281816104b4015281816105a5015281816107e7015281816112b201528181611be901528181611eec0152612a500152610120518181816115df01526121560152610140518181816103790152818161130701528181611b5d01528181611e8401526127f5015261016051818181611f8a01526129dc015261018051818181610691015281816107c20152818161084d015281816117f6015261201401526101a051818181610c9d0152612d2501526101c0518181816105eb0152818161195601528181611a8301528181611afc01528181611dcf0152818161297b0152612ba801526101e05181818161122601526115780152610200518181816102320152612be4015261022051818181611a480152612cb60152610240518181816102700152612c5c0152610260518181816104ed01528181610c640152612c8c0152610280518181816115010152612d8601526102a051818181610dd701526128bf01526102c05181818161211d01526128f20152612eb890f35b634e487b7160e01b600052601160045260246000fd5b634e487b7160e01b600052604160045260246000fd5b50600080805261030052989796959493929190600080516020620038708339815191525b6103205161030051908110156200063a579060019160208254916102e051010152019a60206103005101610300529a62000605565b5050610300516102e051999a98999798969795969495939492939192910160200162000242565b6102e0805160ff1990921660209283015261032051905190151560051b01019150620002429050565b015190503880620001ed565b6001600090815293506000805160206200389083398151915291905b601f1984168510620006f8576001945083601f19811610620006de575b505050811b0160015562000203565b015160001960f88460031b161c19169055388080620006cf565b81810151835560209485019460019093019290910190620006b2565b600160005290915060008051602062003890833981519152601f840160051c8101602085106200076d575b90849392915b601f830160051c820181106200075d575050620001d4565b6000815585945060010162000745565b50806200073f565b01519050388062000193565b600080805293506000805160206200387083398151915291905b601f1984168510620007e1576001945083601f19811610620007c7575b505050811b01600055620001a9565b015160001960f88460031b161c19169055388080620007b8565b818101518355602094850194600190930192909101906200079b565b6000805290915060008051602062003870833981519152601f840160051c81016020851062000855575b90849392915b601f830160051c82018110620008455750506200017a565b600081558594506001016200082d565b508062000827565b6020939193813d602011620008a2575b816200087c60209383620008bc565b810103126200089e57519060ff821682036200089b575091386200014e565b80fd5b5080fd5b3d91506200086d565b6040513d6000823e3d90fd5b600080fd5b601f909101601f19168101906001600160401b03821190821017620005cb57604052565b51906001600160a01b0382168203620008b757565b919080601f84011215620008b7578251906001600160401b038211620005cb576040519160209162000931601f8301601f1916840185620008bc565b818452828287010111620008b75760005b8181106200095857508260009394955001015290565b858101830151848201840152820162000942565b91908201809211620005b557565b90600182811c92168015620009ac575b60208310146200099657565b634e487b7160e01b600052602260045260246000fd5b91607f16916200098a56fe608080604052600436101561001357600080fd5b600090813560e01c90816306fdde031461228e5750806307ea4c0114612248578063095ea7b3146121d15780630c1f70a1146121a357806318160ddd146121855780631bb7cc9914612140578063208c6b861461210557806323b872dd14612043578063267b626e14611ffe57806329db1be614611fb95780632d2c556514611f74578063313ce56714611f365780633456878014611f1b5780633639a82f14611ed65780633644e51514611eb3578063380bfc9914611e6e578063466ad01c14611e485780634c62a8f014611d3b5780635594012014611c455780635a196ae814611aa65780635eace5f214611a6b5780635f4d1eae14611a3057806364eb1c0b146118d857806370a082311461189f5780637ecebe001461186657806380ebc282146117b45780638538a498146115245780638ac732a6146114e957806395d89b411461142c578063970a558314611249578063a109fa561461120e578063a1f5d4da14611088578063a9059cbb14611013578063ab7ac1ed14610fe5578063ae4c12bb14610e4a578063af256edf14610dfa578063b9bd4e5a14610dbf578063c19d93fb14610d95578063c7f463f914610ccc578063cbc9bdda14610c87578063cf91e6bf14610c4c578063d505accf14610a2f578063db2e21bc146102e2578063dd62ed3e14610293578063e28035d7146102585763e6d0c4891461021b57600080fd5b3461025557806003193601126102555760206040517f00000000000000000000000000000000000000000000000000000000000000008152f35b80fd5b503461025557806003193601126102555760206040517f00000000000000000000000000000000000000000000000000000000000000008152f35b5034610255576040366003190112610255576102ad61240b565b60406102b7612421565b9260018060a01b03809316815260046020522091166000526020526020604060002054604051908152f35b50346102555780600319360112610255576102fb612be2565b6009811015610a1b57600781036109fb5750610337307f0000000000000000000000000000000000000000000000000000000000000000612b77565b610361307f0000000000000000000000000000000000000000000000000000000000000000612b77565b604051631698272560e31b81529091906020816004817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa9081156109ab5784916109b6575b506040516350d25bcd60e01b81529190602090839060049082906001600160a01b03165afa9182156109ab578492610973575b5081156109615760405163313ce56760e01b80825290936020856004817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa948515610935578695610940575b506040519182526020826004817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa918215610935578692610904575b5061049360ff861660ff841661248a565b604d81116108f0576104e36104e991600a0a6305f5e1006104dd886104d8307f0000000000000000000000000000000000000000000000000000000000000000612b77565b6126a9565b046126bc565b84612734565b92867f000000000000000000000000000000000000000000000000000000000000000042106108d6575061051b612b9d565b61052f6105288683612d0f565b809661248a565b9060ff6001955b8461084b575b856107c0575b816040519a6105508c612386565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168c526305f5e10060208d0152166040808c0191909152519861059b8a612386565b6001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000168a5260208a01521660408801526127108181029082820414821517156107ac57610610907f0000000000000000000000000000000000000000000000000000000000000000906126bc565b91604051968760c08101106001600160401b0360c08a0111176107965760c088016040528752602087015260408601526060850152608084015260a08301526040519060808201948286106001600160401b038711176107965786956040528252602082019384526040820192835260608201901515815260018060a01b037f00000000000000000000000000000000000000000000000000000000000000001691823b156107925760408051637dccb2c560e11b8152915180516001600160a01b03166004840152602081015160248401520151604482015293859385936101a4938593879360a091610724905180516001600160a01b03166064890152602081015160848901526040015160a4880152565b51805160c4870152602081015160e487015260408101516101048701526060810151610124870152608081015161014487015201516101648501525115156101848401525af18015610787576107775750f35b61078090612373565b6102555780f35b6040513d84823e3d90fd5b8580fd5b634e487b7160e01b600052604160045260246000fd5b634e487b7160e01b8a52601160045260248afd5b7f000000000000000000000000000000000000000000000000000000000000000061080b817f0000000000000000000000000000000000000000000000000000000000000000612b17565b506040518781526001600160a01b039091169030907f0fce68bd37d0ff2cb1977193c60fc476d985a8047f711cbcd23e5f38ec546aa090602090a3610542565b7f0000000000000000000000000000000000000000000000000000000000000000610896817f0000000000000000000000000000000000000000000000000000000000000000612b17565b506040518681526001600160a01b039091169030907f0fce68bd37d0ff2cb1977193c60fc476d985a8047f711cbcd23e5f38ec546aa090602090a361053c565b6108e660095460401c809661248a565b9060ff8995610536565b634e487b7160e01b87526011600452602487fd5b61092791925060203d60201161092e575b61091f81836123a1565b810190612afe565b9038610482565b503d610915565b6040513d88823e3d90fd5b61095a91955060203d60201161092e5761091f81836123a1565b933861043b565b60405163956d448360e01b8152600490fd5b9091506020813d6020116109a3575b8161098f602093836123a1565b8101031261099f575190386103e4565b8380fd5b3d9150610982565b6040513d86823e3d90fd5b90506020813d6020116109f3575b816109d1602093836123a1565b8101031261099f5751906001600160a01b038216820361099f579060206103b1565b3d91506109c4565b60405163683f44bb60e11b8152602491610a19906004830190612467565bfd5b634e487b7160e01b82526021600452602482fd5b50346102555760e036600319011261025557610a4961240b565b610a51612421565b90604435606435906084359260ff841680940361079257428310610c0d57610a776124ad565b9360018060a01b038092169485885260209460058652604089209788549860018a0190556040519185888401927f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c984528a604086015216998a606085015287608085015260a084015260c083015260c0825260e08201916001600160401b03918184108385111761079657836040528151902061010082019461190160f01b865261010283015261012282015260428352610160810191838310908311176107965787948b9460809484604052519020835261018082015260a4356101a08201526101c060c43591015282805260015afa15610c025785511680151580610bf9575b15610bc357907f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92592918652600482526040862085600052825280604060002055604051908152a380f35b60405162461bcd60e51b815260048101849052600e60248201526d24a72b20a624a22fa9a4a3a722a960911b6044820152606490fd5b50838114610b79565b6040513d87823e3d90fd5b60405162461bcd60e51b815260206004820152601760248201527614115493525517d11150511312539157d1561412549151604a1b6044820152606490fd5b503461025557806003193601126102555760206040517f00000000000000000000000000000000000000000000000000000000000000008152f35b50346102555780600319360112610255576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b503461025557602036600319011261025557600435610ce9612cf0565b506001600160401b0360095416811015610d83576000526008602052610d7f6040600020600160405191610d1c83612386565b818060a01b038154168352015460018060801b038116602083015260801c60408201526040519182918281516001600160a01b031681526020808301516001600160801b0390811691830191909152604092830151169181019190915260600190565b0390f35b6040516332a6366160e11b8152600490fd5b50346102555780600319360112610255576020610db0612be2565b610dbd6040518092612467565bf35b503461025557806003193601126102555760206040517f00000000000000000000000000000000000000000000000000000000000000008152f35b503461025557602036600319011261025557600435610e17612cf0565b506001600160401b0360075416811015610d83576000526006602052610d7f6040600020600160405191610d1c83612386565b50346102555760203660031901126102555760043590610e68612be2565b906009821015610fd15750600181036109fb57508015610fbf57610eae8130337f0000000000000000000000000000000000000000000000000000000000000000612659565b600954906001600160401b0380831691610ecf81600185019560401c612734565b610f54610edb826126dc565b600160405191610eea83612386565b338352608082811b8390038781166020808701918252938216604080880191825260008d815260089096529094209551865460a087901b8790039182169119161786555192516001600160801b031990821690921b9190911691166001600160801b031617910155565b600160401b851015610fb15760209484936001600160401b03198360401b16911617600955604051918252848201527fc4e37f25cec4977d3d50c92f66c08c232f7eac78356d970e0cdd65225ffa149d60403392a3604051908152f35b6335278d126000526004601cfd5b604051638d52450360e01b8152600490fd5b634e487b7160e01b81526021600452602490fd5b503461025557806003193601126102555760406009546001600160401b0382519180841c8352166020820152f35b50346102555760403660031901126102555761102d61240b565b604060243591338452600360205281842061104984825461248a565b905560018060a01b031692838152600360205220818154019055604051908152600080516020612e6383398151915260203392a3602060405160018152f35b5034610255576020366003190112610255576004356110a5612be2565b60098110156111fa57600881036109fb57508082526006602052604082206001810154908160801c6111e157546001600160a01b031680156111cf576111cc9260018060801b0380931692600a5490611158611137828460101c1696600b54948486169061111c826111178c866126a9565b6126bc565b9962010000600160901b039061113c90611137908d9061248a565b6126dc565b60101b1662010000600160901b03199190911617600a5561248a565b169060018060801b03191617600b558085526006602052846001604082208281550155817fc8f7724a19d1dc1ff217cfef1bb2edb3414520f46dd42ffdea1ec98a59cedf056020604051868152a37f00000000000000000000000000000000000000000000000000000000000000006126f4565b80f35b6040516373f9ebb560e11b8152600490fd5b604051632037236f60e21b815260048101849052602490fd5b634e487b7160e01b83526021600452602483fd5b503461025557806003193601126102555760206040517f00000000000000000000000000000000000000000000000000000000000000008152f35b50346102555760209081600319360112610255576004356001600160401b0381116114285761127c903690600401612437565b9092611286612be2565b93600985101561141457600585036113f7576040516370a0823160e01b815230600482015293945084937f0000000000000000000000000000000000000000000000000000000000000000926001600160a01b039080836024818589165afa9283156113ec5787936113b5575b50600080516020612e4383398151915260407f0000000000000000000000000000000000000000000000000000000000000000926113318489612775565b61133c86858a6127b6565b600660ff19600a541617600a55600682519160058352820152a11690813b15610792578580946113a46040519788968795869463dd9caf6160e01b86527f00000000000000000000000000000000000000000000000000000000000000009060048701612741565b03925af18015610787576107775750f35b809750818094503d83116113e5575b6113ce81836123a1565b810103126113e05786955191386112f3565b600080fd5b503d6113c4565b6040513d89823e3d90fd5b60405163683f44bb60e11b8152602490610a196004820188612467565b634e487b7160e01b84526021600452602484fd5b5080fd5b50346102555780600319360112610255576040516000906001805461145081612339565b808452908281169081156114c15750600114611483575b610d7f83611477818703826123a1565b604051918291826123c2565b92508060005260209283600020916000925b8284106114ae5750505081019091019061147781611467565b8054858501870152928501928101611495565b610d7f955061147793506020915091849260ff191682840152151560051b8201019350611467565b503461025557806003193601126102555760206040517f00000000000000000000000000000000000000000000000000000000000000008152f35b503461025557604036600319011261025557600435906001600160401b036024358181116117b05761155a903690600401612437565b9390611564612be2565b600981101561179c57600181036109fb57507f00000000000000000000000000000000000000000000000000000000000000008210610fbf576115cb90604051918291635a23dd9960e01b8352336004840152604060248401526020976044840191612635565b6001600160a01b03959187918491900381847f00000000000000000000000000000000000000000000000000000000000000008a165af191821561178f578192611755575b505015611743576116438130337f0000000000000000000000000000000000000000000000000000000000000000612659565b60075492828416936116e9868661166186600183019560401c612734565b9486600161166e886126dc565b926040519061167c82612386565b338252608083811b849003948516888401908152958516604080850191825260009889526006909952979096209151825460a085901b85900319169116178155925194516001600160801b03958316959095169490911690921b6001600160801b03191692909217910155565b600160401b811015610fb15784936001600160401b03198360401b16911617600755604051918252848201527fdc35d0d1210063339550b8fa9939bc402fb0bf71d978c48b98ba166b261a1e8460403392a3604051908152f35b604051630b094f2760e31b8152600490fd5b9091508581813d8311611788575b61176d81836123a1565b81010312611428575190811515820361025557503880611610565b503d611763565b50604051903d90823e3d90fd5b634e487b7160e01b85526021600452602485fd5b8280fd5b5034610255576040366003190112610255576117ce61240b565b6024356117d9612be2565b600981101561141457600781036109fb57506001600160a01b03917f000000000000000000000000000000000000000000000000000000000000000083163303611854576111cc927fea6196d807445d7a5ef97b4f06996a3d075e5be717e30cd482794c5da0b95517602060405192858452841692a2612ab7565b604051633d9c7ca360e21b8152600490fd5b5034610255576020366003190112610255576020906040906001600160a01b0361188e61240b565b168152600583522054604051908152f35b5034610255576020366003190112610255576020906040906001600160a01b036118c761240b565b168152600383522054604051908152f35b503461025557602080600319360112611428576004356118f6612be2565b60098110156114145760018111156109fb5750808352600882526040832090600182015460801c15611a1e576040927f53ead95e361ca1924d3168f8130c12e4847fa6352e02cdf01a55d952aa51ff9561198261271061197b600754881c7f0000000000000000000000000000000000000000000000000000000000000000906126a9565b0485612dfe565b9590869560018060a01b03905416968794868a526008815289600185822082815501556119b183600254612734565b600255858a5260038152838a20838154019055858a600080516020612e63833981519152838751878152a38351928352820152a3806119ee578280f35b611a18917f00000000000000000000000000000000000000000000000000000000000000006126f4565b38808280f35b604051633e51778f60e11b8152600490fd5b503461025557806003193601126102555760206040517f00000000000000000000000000000000000000000000000000000000000000008152f35b503461025557806003193601126102555760206040517f00000000000000000000000000000000000000000000000000000000000000008152f35b5034610255576020366003190112610255576004356001600160401b03811161142857611ad7903690600401612437565b90611ae0612be2565b600981101561141457600281036109fb5750611afa612b9d565b7f000000000000000000000000000000000000000000000000000000000000000090612710820190818311611c315791611117611b39928795946126a9565b7f0000000000000000000000000000000000000000000000000000000000000000907f0000000000000000000000000000000000000000000000000000000000000000611b868184612775565b611b918282856127b6565b600360ff19600a541617600a55600080516020612e43833981519152604080516002815260036020820152a16001600160a01b031691823b15611c2d578490611c126040519788968795869463dd9caf6160e01b86527f00000000000000000000000000000000000000000000000000000000000000009060048701612741565b03925af1801561078757611c24575080f35b6111cc90612373565b8480fd5b634e487b7160e01b86526011600452602486fd5b503461025557602036600319011261025557600435611c62612be2565b60098110156111fa57600881036109fb575080611c826111cc9233612ab7565b80600b548060801c600c5491611cdb61113760018060801b0396879384871690611cb08261111789866126a9565b996001600160801b0319978890611ccc90611137908e9061248a565b60801b16911617600b5561248a565b16911617600c556040519081528160208201527f362effd2b777f1d13bcc9a1b841a2985dc4bdaa711824edf76401cd92e3a80a960403392a2337f00000000000000000000000000000000000000000000000000000000000000006126f4565b50346102555760203660031901126102555760043590611d59612be2565b6009811015610a1b5760018111156109fb57508181526006602052604081206001810192835460801c15611a1e5760095460401c9361271094858102958187041490151715611e34577f6226d20d15e9f5667f91ee807d592e22d6db2238f333ac8fb8e36883be0363f9611dfa611df4604096977f0000000000000000000000000000000000000000000000000000000000000000906126bc565b85612dfe565b9490926001600160801b03611e0e856126dc565b169055548551928352602083018590526001600160a01b0316948592a3806119ee578280f35b634e487b7160e01b84526011600452602484fd5b5034610255576040366003190112610255576111cc611e6561240b565b602435906127e9565b50346102555780600319360112610255576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b50346102555780600319360112610255576020611ece6124ad565b604051908152f35b50346102555780600319360112610255576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b50346102555780600319360112610255576020611ece612b9d565b5034610255578060031936011261025557602060405160ff7f0000000000000000000000000000000000000000000000000000000000000000168152f35b50346102555780600319360112610255576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b50346102555780600319360112610255576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b50346102555780600319360112610255576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b50346102555760603660031901126102555761205d61240b565b90612066612421565b600080516020612e638339815191526044359160018060a01b038095169283855260406020968793600485528288203389528552828820548460001982036120e2575b5050868852600385528288206120c085825461248a565b905516958681526003845220818154019055604051908152a360405160018152f35b6120eb9161248a565b87895260048652838920338a5286528389205538846120a9565b503461025557806003193601126102555760206040517f00000000000000000000000000000000000000000000000000000000000000008152f35b50346102555780600319360112610255576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b50346102555780600319360112610255576020600254604051908152f35b503461025557806003193601126102555760406007546001600160401b0382519180841c8352166020820152f35b50346102555760403660031901126102555760406121ed61240b565b9160243591829133815260046020528181209460018060a01b03169485825260205220556040519081527f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b92560203392a3602060405160018152f35b50346102555780600319360112610255576080600180821b0380600a5460101c1690600b5481600c54169160405193845281166020840152831c60408301526060820152f35b9050346114285781600319360112611428578180546122ac81612339565b8084529060019081811690811561231157506001146122d6575b610d7f84611477818803826123a1565b93508180526020938483205b8284106122fe5750505081610d7f9361147792820101936122c6565b80548585018701529285019281016122e2565b610d7f96506114779450602092508593915060ff191682840152151560051b820101936122c6565b90600182811c92168015612369575b602083101461235357565b634e487b7160e01b600052602260045260246000fd5b91607f1691612348565b6001600160401b03811161079657604052565b606081019081106001600160401b0382111761079657604052565b90601f801991011681019081106001600160401b0382111761079657604052565b6020808252825181830181905290939260005b8281106123f757505060409293506000838284010152601f8019910116010190565b8181018601518482016040015285016123d5565b600435906001600160a01b03821682036113e057565b602435906001600160a01b03821682036113e057565b9181601f840112156113e0578235916001600160401b0383116113e0576020808501948460051b0101116113e057565b9060098210156124745752565b634e487b7160e01b600052602160045260246000fd5b9190820391821161249757565b634e487b7160e01b600052601160045260246000fd5b6000467f0000000000000000000000000000000000000000000000000000000000000000036124fb57507f000000000000000000000000000000000000000000000000000000000000000090565b6040518154829161250b82612339565b80825281602094858201946001908782821691826000146126175750506001146125db575b5061253d925003826123a1565b51902091604051918201927f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f845260408301527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc660608301524660808301523060a083015260a0825260c08201908282106001600160401b038311176125c7575060405251902090565b634e487b7160e01b81526041600452602490fd5b8691508780528188209088915b8583106125ff57505061253d935082010138612530565b805483880185015286945088939092019181016125e8565b60ff1916885261253d95151560051b85010192503891506125309050565b81835290916001600160fb1b0383116113e05760209260051b809284830137010190565b601c600060649281946020966040519860605260405260601b602c526323b872dd60601b600c525af13d1560016000511417161561269b576000606052604052565b637939f4246000526004601cfd5b8181029291811591840414171561249757565b81156126c6570490565b634e487b7160e01b600052601260045260246000fd5b600160801b811015610fb1576001600160801b031690565b601092602092601452603452604460009384809363a9059cbb60601b82525af13d15600183511417161561272757603452565b6390b8ec1890526004601cfd5b9190820180921161249757565b6001600160a01b03918216815291166020820152604081019190915260806060820181905261277293910191612635565b90565b60209060109260145260446000938480938160345263095ea7b360601b82525af13d1560018351141716156127a957603452565b633e3f8f7390526004601cfd5b601092602092601452603452604460009384809363095ea7b360601b82525af13d1560018351141716156127a957603452565b6001600160a01b0391907f000000000000000000000000000000000000000000000000000000000000000083163303612aa557612824612be2565b9260098410156124745760038414612a47576006841461285b5760405163683f44bb60e11b8152602490610a196004820187612467565b80919293507f000000000000000000000000000000000000000000000000000000000000000092169082168103612a2f57506128e4612898612b9d565b6128ac6128a58583612d0f565b809561248a565b906128b7818661248a565b6127109384917f0000000000000000000000000000000000000000000000000000000000000000906126a9565b049061291f611137856129177f0000000000000000000000000000000000000000000000000000000000000000876126a9565b04809561248a565b600a805462010000600160901b03191660109290921b62010000600160901b0316919091179055808402938115828604909114171561249757612a01956129d99483926001600160801b03926129ca9284906129a090611137907f0000000000000000000000000000000000000000000000000000000000000000906126bc565b6001600160801b03199691169186916129bd91611137919061248a565b60801b1617600b556126dc565b1690600c541617600c55612734565b907f0000000000000000000000000000000000000000000000000000000000000000906126f4565b600860ff19600a541617600a55600080516020612e43833981519152604080516006815260086020820152a1565b60249060405190639e5f788160e01b82526004820152fd5b925082915016907f0000000000000000000000000000000000000000000000000000000000000000168103612a2f5750600460ff19600a541617600a55600080516020612e43833981519152604080516003815260046020820152a1565b604051630aff86d760e21b8152600490fd5b90600080516020612e63833981519152602060009360018060a01b0316928385526003825260408520612aeb82825461248a565b90558060025403600255604051908152a3565b908160209103126113e0575160ff811681036113e05790565b91906000906370a08231825230602052602060346024601c875afa601f3d111615612b6a5760145260208160446010826034519763a9059cbb60601b82525af13d15600183511417161561272757603452565b6390b8ec1882526004601cfd5b602460106020939284936014526370a0823160601b6000525afa601f3d11166020510290565b612710612bd06007547f00000000000000000000000000000000000000000000000000000000000000009060401c6126a9565b0460095460401c818110908218021890565b7f00000000000000000000000000000000000000000000000000000000000000004210612ceb5760ff600a54166009811015612474576001811480612ce3575b612cdd576003811480612cb3575b612c53576004811480612c89575b612c83576006811480612c59575b612c535790565b50600790565b507f0000000000000000000000000000000000000000000000000000000000000000421015612c4c565b50600590565b507f0000000000000000000000000000000000000000000000000000000000000000421015612c3e565b507f0000000000000000000000000000000000000000000000000000000000000000421015612c30565b50600290565b506001612c22565b600190565b60405190612cfd82612386565b60006040838281528260208201520152565b6040516301e66bcf60e01b8152906020826004817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa918215612df257600092612dbf575b5061270f198201918211612497576127106301da9c00612dab612d84612db395856126a9565b7f0000000000000000000000000000000000000000000000000000000000000000906126a9565b040490612734565b90818110908218021890565b90916020823d8211612dea575b81612dd9602093836123a1565b810103126102555750519038612d5e565b3d9150612dcc565b6040513d6000823e3d90fd5b600101546001600160801b03811692919060801c808210612e20575050600090565b83612e2a9161248a565b9080821115612e3b57505060009190565b038092039056fea4bda53ae0fd969a8a76873655c70563e1c49a76a63384848681457a8b8e52ebddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efa26469706673582212205c0c6896b5dc54898a3fe165d9d30f6be279682d3bdeefe376bf94148ba1ce8a64736f6c63430008130033290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563b10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf66101e0604081815234620003d3578190620014288038038091620000248286620003d8565b843961012092839181010312620003d357620000408362000412565b906020916200005183860162000412565b916200005f81870162000412565b6200006d6060880162000412565b6080880151936001600160a01b0393918486168603620003d35760a08a0151966200009b60c08c0162000412565b9860e08c015195610100809d0151976000953360018060a01b0319885416178755875133887f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08180a36103e88d11620003c45750806080528460a0528260c05287519084826004818663313ce56760e01b98898352165afa918215620003725783929186918a93620003a0575b5060048b5180958193898352165afa918215620003725791620001579160ff938a926200037c575b5062000442565b16938751928084528484600481868b165afa93841562000372579085929189956200034b575b506004908a5194859384928352165afa9283156200034157620001d7938796959360ff93620001ba93620001e29a936200030b575b505062000442565b169081811115620002f95790620001d1916200046d565b6200047b565b60e0528a526200047b565b87526101809384526101a09485526101c09586526101409182526101609283525195610f9d97886200048b893960805188818161024401528181610435015281816106790152818161070b0152818161075e0152610ccf015260a0518881816102b1015281816102fd015281816106bb015281816109fd0152610c15015260c051888181610334015281816107980152610b65015260e0518881816101600152818161040c015261082301525187818161035e015281816107c20152610b210152518681816103d7015281816107ee0152610c5c01525185610385015251846103ac015251838181610a7f0152610ba901525182818161046e015281816108620152610c970152518181816101f90152610d120152f35b62000304916200046d565b926200047b565b62000330929350803d1062000339575b620003278183620003d8565b81019062000427565b903880620001b2565b503d6200031b565b87513d88823e3d90fd5b60049195506200036a90843d86116200033957620003278183620003d8565b94906200017d565b89513d8a823e3d90fd5b62000398919250873d89116200033957620003278183620003d8565b903862000150565b620003bc919350823d84116200033957620003278183620003d8565b913862000128565b633cd146b160e01b8152600490fd5b600080fd5b601f909101601f19168101906001600160401b03821190821017620003fc57604052565b634e487b7160e01b600052604160045260246000fd5b51906001600160a01b0382168203620003d357565b90816020910312620003d3575160ff81168103620003d35790565b9060ff8091169116019060ff82116200045757565b634e487b7160e01b600052601160045260246000fd5b919082039182116200045757565b604d81116200045757600a0a9056fe608060408181526004908136101561001657600080fd5b600092833560e01c90816316f0115b14610cfe575080632495a59914610cba5780635c25c76c14610c7f578063628e040e14610c4457806387db4c4614610c005780638da5cb5b14610bd857806393e59dc114610b94578063afb70dc014610b50578063b4c1392814610b0c578063dd9caf6114610187578063e77fec26146101485763f2fde38b146100a857600080fd5b34610144576020366003190112610144576100c1610d41565b8354926001600160a01b03928385163303610112575050166001600160a01b03199190911681178255337f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08380a380f35b906020606492519162461bcd60e51b8352820152600c60248201526b15539055551213d49256915160a21b6044820152fd5b8280fd5b838234610183578160031936011261018357602090517f00000000000000000000000000000000000000000000000000000000000000008152f35b5080fd5b509034610144576080366003190112610144576101a2610d41565b9160246001600160a01b03813581811690819003610b0857604435956064359367ffffffffffffffff808611610b045736602387011215610b045785880135908111610b04578060051b36838289010111610aeb577f00000000000000000000000000000000000000000000000000000000000000009186831697883314159283610a36575b505050610a2657895460a01c60ff1691826102dc5750505082167f0000000000000000000000000000000000000000000000000000000000000000831614801592906102af575b50506102a1573303610294575050815460ff60a01b1916600160a01b17825560015580f35b51636f61f64160e01b8152fd5b505163c1ab6dc160e01b8152fd5b7f00000000000000000000000000000000000000000000000000000000000000001614159050388061026f565b9260019a9994959a98929897969197988981146000146106a157508a16978a7f0000000000000000000000000000000000000000000000000000000000000000168914801590610675575b6106655784978a956103587f0000000000000000000000000000000000000000000000000000000000000000610e91565b9c6103827f0000000000000000000000000000000000000000000000000000000000000000610e91565b9d7f000000000000000000000000000000000000000000000000000000000000000011610655578d7f000000000000000000000000000000000000000000000000000000000000000010610655576305f5e1007f00000000000000000000000000000000000000000000000000000000000000008181029291830403610624576104318e9f9e9d9e7f000000000000000000000000000000000000000000000000000000000000000090610da8565b9c507f0000000000000000000000000000000000000000000000000000000000000000168d036106495761046790809c92610da8565b90612710917f0000000000000000000000000000000000000000000000000000000000000000830190818411610636576104ab836104a6848794610da8565b610dde565b049c8d9386549485106105d5575b50505050816104e38b6104eb948f8f80960388556104d983600254610dd1565b6002553390610dfe565b339089610dfe565b805415610533575b50505050508151948552602085015283015260608201527fb39c9bc43f811e1a7ce159c5f147458fdb80266bf23c17322013316e27e086d060803392a280f35b8a549060ff8260a01c169060ff82146105c35760ff60a01b19909216910160a01b60ff60a01b16178a556002548a92909190813b156105bf57836044928c948a51978896879563119ab40760e21b87528601528401525af180156105b5576105a4575b5060025538808080806104f3565b6105ae9150610d5c565b8538610596565b84513d8a823e3d90fd5b8380fd5b634e487b7160e01b8d5260118552858dfd5b949f9e9d50929b508b939092916105ec9085610da8565b818102918183041490151715610624576104eb938d9e9f8d9e6106188f966104a684976104e397610dde565b9e5050948194506104b9565b634e487b7160e01b8e5260118752878efd5b50634e487b7160e01b8f5260118752878ffd5b90610467908c90610da8565b8951632f6c3e6f60e11b81528690fd5b865163c1ab6dc160e01b81528390fd5b508a7f000000000000000000000000000000000000000000000000000000000000000016861415610327565b999a949992979195939092600281036107365750505082167f000000000000000000000000000000000000000000000000000000000000000083161480159290610709575b50506102a1573303610294575050825460ff60a01b1916600360a01b1783555580f35b7f0000000000000000000000000000000000000000000000000000000000000000161415905038806106e6565b6003909b9a959b9893919496929814610758575b505050505050505050905080f35b8a16978a7f0000000000000000000000000000000000000000000000000000000000000000168914809b8115916109f9575b506106655784978a956107bc7f0000000000000000000000000000000000000000000000000000000000000000610e91565b506107e67f0000000000000000000000000000000000000000000000000000000000000000610e91565b9c6305f5e1007f00000000000000000000000000000000000000000000000000000000000000008181029291830403610624576108488e9f9e9d9e7f000000000000000000000000000000000000000000000000000000000000000090610da8565b9c50156109ed5761085b90809c92610da8565b90612710917f00000000000000000000000000000000000000000000000000000000000000008301908184116106365761089a836104a6848794610da8565b049c8d93865494851061099e575b50505050816104e38b6108c8948f8f80960388556104d983600254610dd1565b80541561091c575b50505050508151948552602085015283015260608201527fb39c9bc43f811e1a7ce159c5f147458fdb80266bf23c17322013316e27e086d060803392a28038808080808080808061074a565b8a549060ff8260a01c169060ff82146105c35760ff60a01b19909216910160a01b60ff60a01b16178a556002548a92909190813b156105bf57836044928c948a51978896879563119ab40760e21b87528601528401525af180156105b55761098d575b5060025538808080806108d0565b6109979150610d5c565b853861097f565b949f9e9d50929b508b939092916109b59085610da8565b818102918183041490151715610624576108c8938d9e9f8d9e6109e18f966104a684976104e397610dde565b9e5050948194506108a8565b9061085b908c90610da8565b90507f0000000000000000000000000000000000000000000000000000000000000000168614153861078a565b8651630b094f2760e31b81528890fd5b8a51635a23dd9960e01b8152338d8201528681018c905260448101849052935090918d906001600160fb1b0310610b0157836064818481958a602098018484013781010301918a7f0000000000000000000000000000000000000000000000000000000000000000165af1908115610af7578b91610ab9575b5015388080610228565b90506020813d8211610aef575b81610ad360209383610d86565b81010312610aeb57518015158103610aeb5738610aaf565b8a80fd5b3d9150610ac6565b88513d8d823e3d90fd5b80fd5b8980fd5b8680fd5b838234610183578160031936011261018357517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b838234610183578160031936011261018357517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b838234610183578160031936011261018357517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b838234610183578160031936011261018357905490516001600160a01b039091168152602090f35b838234610183578160031936011261018357517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b838234610183578160031936011261018357602090517f00000000000000000000000000000000000000000000000000000000000000008152f35b838234610183578160031936011261018357602090517f00000000000000000000000000000000000000000000000000000000000000008152f35b838234610183578160031936011261018357517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b8490346101835781600319360112610183577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b600435906001600160a01b0382168203610d5757565b600080fd5b67ffffffffffffffff8111610d7057604052565b634e487b7160e01b600052604160045260246000fd5b90601f8019910116810190811067ffffffffffffffff821117610d7057604052565b81810292918115918404141715610dbb57565b634e487b7160e01b600052601160045260246000fd5b91908201809211610dbb57565b8115610de8570490565b634e487b7160e01b600052601260045260246000fd5b9060006064926020958295604051946323b872dd60e01b86526004860152602485015260448401525af13d15601f3d1160016000511416171615610e3e57565b60405162461bcd60e51b81526020600482015260146024820152731514905394d1915497d19493d357d1905253115160621b6044820152606490fd5b519069ffffffffffffffffffff82168203610d5757565b604051633fabe5a360e21b81529060a090829060049082906001600160a01b03165afa8015610f5b576000918291610f07575b506000821315610ef5574203428111610dbb576201fa401115610ee45790565b604051628af0d360e31b8152600490fd5b60405163956d448360e01b8152600490fd5b91905060a0823d8211610f53575b81610f2260a09383610d86565b81010312610b015750610f3481610e7a565b506020810151610f4b608060608401519301610e7a565b509038610ec4565b3d9150610f15565b6040513d6000823e3d90fdfea2646970667358221220f32c1d4f2a332a3beeb4e2440d43aabc8efbf504086db601e38d5ba7729367ac64736f6c63430008130033a2646970667358221220d9cbde723f4234cbe68ca456c4846a077573f32db3e20c57df3f6d23da836d5c64736f6c63430008130033

Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)

00000000000000000000000021c2bd51f230d69787daf230672f70baa1826f67

-----Decoded View---------------
Arg [0] : owner (address): 0x21c2bd51f230D69787DAf230672F70bAA1826F67

-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 00000000000000000000000021c2bd51f230d69787daf230672f70baa1826f67


Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

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

Validator Index Block Amount
View All Withdrawals

Txn 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.