Sepolia Testnet

Contract

0xC27AbAFf28978dF844d95acDE4F57C29F66878f8
Transaction Hash
Method
Block
From
To
Redeem With CT62885482024-07-11 8:18:129 days ago1720685892IN
0xC27AbAFf...9F66878f8
0 ETH0.0066931953.1906734
Redeem With CT62885362024-07-11 8:15:369 days ago1720685736IN
0xC27AbAFf...9F66878f8
0 ETH0.0109061461.56588337
Redeem With CT62883032024-07-11 7:25:009 days ago1720682700IN
0xC27AbAFf...9F66878f8
0 ETH0.0036156918.7659759
Redeem Expired L...62879682024-07-11 6:11:489 days ago1720678308IN
0xC27AbAFf...9F66878f8
0 ETH0.0031142626.57383443
Request Redempti...62879652024-07-11 6:11:129 days ago1720678272IN
0xC27AbAFf...9F66878f8
0 ETH0.0019026826.87555152
Deposit Lv62879612024-07-11 6:10:249 days ago1720678224IN
0xC27AbAFf...9F66878f8
0 ETH0.004819725.37848469
Deposit Psm62879602024-07-11 6:10:129 days ago1720678212IN
0xC27AbAFf...9F66878f8
0 ETH0.0048056225.88988577
Issue New Ds62879512024-07-11 6:08:129 days ago1720678092IN
0xC27AbAFf...9F66878f8
0 ETH0.0686943225.16399197
Redeem Expired L...62879302024-07-11 6:03:129 days ago1720677792IN
0xC27AbAFf...9F66878f8
0 ETH0.0047859520.78753714
Redeem Expired L...62878752024-07-11 5:51:489 days ago1720677108IN
0xC27AbAFf...9F66878f8
0 ETH0.0014405713.24140101
Request Redempti...62878612024-07-11 5:49:009 days ago1720676940IN
0xC27AbAFf...9F66878f8
0 ETH0.0021494915.44219994
Deposit Lv62878522024-07-11 5:46:489 days ago1720676808IN
0xC27AbAFf...9F66878f8
0 ETH0.0036264415.03419729
Deposit Psm62878512024-07-11 5:46:369 days ago1720676796IN
0xC27AbAFf...9F66878f8
0 ETH0.0032041214.57625414
Issue New Ds62878412024-07-11 5:44:249 days ago1720676664IN
0xC27AbAFf...9F66878f8
0 ETH0.0354057813.10502185
Initialize62878092024-07-11 5:37:129 days ago1720676232IN
0xC27AbAFf...9F66878f8
0 ETH0.0219484514.77210349
0x6080604062877842024-07-11 5:32:009 days ago1720675920IN
 Create: ModuleCore
0 ETH0.0816143318.63976734

Advanced mode:
Parent Transaction Hash Block From To
View All Internal Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
ModuleCore

Compiler Version
v0.8.24+commit.e11b9ed9

Optimization Enabled:
Yes with 200 runs

Other Settings:
paris EvmVersion
File 1 of 59 : ModuleCore.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
import "./libraries/PsmLib.sol";
import "./libraries/VaultLib.sol";
import "./libraries/Pair.sol";
import "./libraries/MathHelper.sol";
import "./interfaces/IPSMcore.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import "./interfaces/IAssetFactory.sol";
import "./libraries/State.sol";
import "./ModuleState.sol";
import "./interfaces/ICommon.sol";
import "./Psm.sol";
import "./Vault.sol";
import "./interfaces/Init.sol";
import "./dev/LvDev.sol";
import "./dev/PsmDev.sol";

// TODO : make entrypoint that do not rely on permit with function overloading or different function altogether
// TODO : make sync function to sync each pair of DS and CT balance
contract ModuleCore is PsmCore, Initialize, VaultCore, LvDev, PsmDev {
    using PsmLibrary for State;
    using PairLibrary for Pair;

    constructor(address factory) ModuleState(factory) {}

    function getId(address pa, address ra) external pure returns (Id) {
        return PairLibrary.initalize(pa, ra).toId();
    }

    // TODO : only allow to call this from config contract later or router
    // TODO : make a pair id associated with it's interval.
    // TODO : auto issue.
    function initialize(
        address pa,
        address ra,
        uint256 lvFee,
        uint256 lvAmmWaDepositThreshold,
        uint256 lvAmmCtDepositThreshold
    ) external override {
        Pair memory key = PairLibrary.initalize(pa, ra);
        Id id = key.toId();

        State storage state = states[id];

        if (state.isInitialized()) {
            revert AlreadyInitialized();
        }

        IAssetFactory factory = IAssetFactory(_factory);

        address lv = factory.deployLv(ra, pa, address(this));

        PsmLibrary.initialize(state, key);
        VaultLibrary.initialize(
            state.vault,
            lv,
            lvFee,
            lvAmmWaDepositThreshold,
            lvAmmCtDepositThreshold,
            ra
        );

        emit Initialized(id, pa, ra, lv);
    }

    // TODO : only allow to call this from config contract later or router
    function issueNewDs(
        Id id,
        uint256 expiry,
        uint256 exchangeRates
    ) external override onlyInitialized(id) {
        State storage state = states[id];

        address pa = state.info.pair0;
        address ra = state.info.pair1;

        (address _ct, address _ds) = IAssetFactory(_factory).deploySwapAssets(
            ra,
            pa,
            address(this),
            expiry,
            exchangeRates
        );

        uint256 prevIdx = state.globalAssetIdx++;
        uint256 idx = state.globalAssetIdx;

        PsmLibrary.issueNewPair(state, _ct, _ds, idx, prevIdx);
        VaultLibrary.onNewIssuanceAndExpiry(state, prevIdx);

        emit Issued(id, idx, expiry, _ds, _ct);
    }

    function lastDsId(Id id) external view override returns (uint256 dsId) {
        return states[id].globalAssetIdx;
    }
}

File 2 of 59 : Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)

pragma solidity ^0.8.20;

import {Context} from "../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.
 *
 * The initial owner is set to the address provided by the deployer. 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;

    /**
     * @dev The caller account is not authorized to perform an operation.
     */
    error OwnableUnauthorizedAccount(address account);

    /**
     * @dev The owner is not a valid owner account. (eg. `address(0)`)
     */
    error OwnableInvalidOwner(address owner);

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

    /**
     * @dev Initializes the contract setting the address provided by the deployer as the initial owner.
     */
    constructor(address initialOwner) {
        if (initialOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(initialOwner);
    }

    /**
     * @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 {
        if (owner() != _msgSender()) {
            revert OwnableUnauthorizedAccount(_msgSender());
        }
    }

    /**
     * @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 {
        if (newOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _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 3 of 59 : draft-IERC6093.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/draft-IERC6093.sol)
pragma solidity ^0.8.20;

/**
 * @dev Standard ERC20 Errors
 * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC20 tokens.
 */
interface IERC20Errors {
    /**
     * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     * @param balance Current balance for the interacting account.
     * @param needed Minimum amount required to perform a transfer.
     */
    error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);

    /**
     * @dev Indicates a failure with the token `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     */
    error ERC20InvalidSender(address sender);

    /**
     * @dev Indicates a failure with the token `receiver`. Used in transfers.
     * @param receiver Address to which tokens are being transferred.
     */
    error ERC20InvalidReceiver(address receiver);

    /**
     * @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.
     * @param spender Address that may be allowed to operate on tokens without being their owner.
     * @param allowance Amount of tokens a `spender` is allowed to operate with.
     * @param needed Minimum amount required to perform a transfer.
     */
    error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);

    /**
     * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
     * @param approver Address initiating an approval operation.
     */
    error ERC20InvalidApprover(address approver);

    /**
     * @dev Indicates a failure with the `spender` to be approved. Used in approvals.
     * @param spender Address that may be allowed to operate on tokens without being their owner.
     */
    error ERC20InvalidSpender(address spender);
}

/**
 * @dev Standard ERC721 Errors
 * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC721 tokens.
 */
interface IERC721Errors {
    /**
     * @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in EIP-20.
     * Used in balance queries.
     * @param owner Address of the current owner of a token.
     */
    error ERC721InvalidOwner(address owner);

    /**
     * @dev Indicates a `tokenId` whose `owner` is the zero address.
     * @param tokenId Identifier number of a token.
     */
    error ERC721NonexistentToken(uint256 tokenId);

    /**
     * @dev Indicates an error related to the ownership over a particular token. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     * @param tokenId Identifier number of a token.
     * @param owner Address of the current owner of a token.
     */
    error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner);

    /**
     * @dev Indicates a failure with the token `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     */
    error ERC721InvalidSender(address sender);

    /**
     * @dev Indicates a failure with the token `receiver`. Used in transfers.
     * @param receiver Address to which tokens are being transferred.
     */
    error ERC721InvalidReceiver(address receiver);

    /**
     * @dev Indicates a failure with the `operator`’s approval. Used in transfers.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     * @param tokenId Identifier number of a token.
     */
    error ERC721InsufficientApproval(address operator, uint256 tokenId);

    /**
     * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
     * @param approver Address initiating an approval operation.
     */
    error ERC721InvalidApprover(address approver);

    /**
     * @dev Indicates a failure with the `operator` to be approved. Used in approvals.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     */
    error ERC721InvalidOperator(address operator);
}

/**
 * @dev Standard ERC1155 Errors
 * Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC1155 tokens.
 */
interface IERC1155Errors {
    /**
     * @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     * @param balance Current balance for the interacting account.
     * @param needed Minimum amount required to perform a transfer.
     * @param tokenId Identifier number of a token.
     */
    error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId);

    /**
     * @dev Indicates a failure with the token `sender`. Used in transfers.
     * @param sender Address whose tokens are being transferred.
     */
    error ERC1155InvalidSender(address sender);

    /**
     * @dev Indicates a failure with the token `receiver`. Used in transfers.
     * @param receiver Address to which tokens are being transferred.
     */
    error ERC1155InvalidReceiver(address receiver);

    /**
     * @dev Indicates a failure with the `operator`’s approval. Used in transfers.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     * @param owner Address of the current owner of a token.
     */
    error ERC1155MissingApprovalForAll(address operator, address owner);

    /**
     * @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
     * @param approver Address initiating an approval operation.
     */
    error ERC1155InvalidApprover(address approver);

    /**
     * @dev Indicates a failure with the `operator` to be approved. Used in approvals.
     * @param operator Address that may be allowed to operate on tokens without being their owner.
     */
    error ERC1155InvalidOperator(address operator);

    /**
     * @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation.
     * Used in batch transfers.
     * @param idsLength Length of the array of token identifiers
     * @param valuesLength Length of the array of token amounts
     */
    error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength);
}

File 4 of 59 : IERC3156FlashBorrower.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC3156FlashBorrower.sol)

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC3156 FlashBorrower, as defined in
 * https://eips.ethereum.org/EIPS/eip-3156[ERC-3156].
 */
interface IERC3156FlashBorrower {
    /**
     * @dev Receive a flash loan.
     * @param initiator The initiator of the loan.
     * @param token The loan currency.
     * @param amount The amount of tokens lent.
     * @param fee The additional amount of tokens to repay.
     * @param data Arbitrary data structure, intended to contain user-defined parameters.
     * @return The keccak256 hash of "ERC3156FlashBorrower.onFlashLoan"
     */
    function onFlashLoan(
        address initiator,
        address token,
        uint256 amount,
        uint256 fee,
        bytes calldata data
    ) external returns (bytes32);
}

File 5 of 59 : IERC3156FlashLender.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC3156FlashLender.sol)

pragma solidity ^0.8.20;

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

/**
 * @dev Interface of the ERC3156 FlashLender, as defined in
 * https://eips.ethereum.org/EIPS/eip-3156[ERC-3156].
 */
interface IERC3156FlashLender {
    /**
     * @dev The amount of currency available to be lended.
     * @param token The loan currency.
     * @return The amount of `token` that can be borrowed.
     */
    function maxFlashLoan(address token) external view returns (uint256);

    /**
     * @dev The fee to be charged for a given loan.
     * @param token The loan currency.
     * @param amount The amount of tokens lent.
     * @return The amount of `token` to be charged for the loan, on top of the returned principal.
     */
    function flashFee(address token, uint256 amount) external view returns (uint256);

    /**
     * @dev Initiate a flash loan.
     * @param receiver The receiver of the tokens in the loan, and the receiver of the callback.
     * @param token The loan currency.
     * @param amount The amount of tokens lent.
     * @param data Arbitrary data structure, intended to contain user-defined parameters.
     */
    function flashLoan(
        IERC3156FlashBorrower receiver,
        address token,
        uint256 amount,
        bytes calldata data
    ) external returns (bool);
}

File 6 of 59 : IERC5267.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC5267.sol)

pragma solidity ^0.8.20;

interface IERC5267 {
    /**
     * @dev MAY be emitted to signal that the domain could have changed.
     */
    event EIP712DomainChanged();

    /**
     * @dev returns the fields and values that describe the domain separator used by this contract for EIP-712
     * signature.
     */
    function eip712Domain()
        external
        view
        returns (
            bytes1 fields,
            string memory name,
            string memory version,
            uint256 chainId,
            address verifyingContract,
            bytes32 salt,
            uint256[] memory extensions
        );
}

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

pragma solidity ^0.8.20;

import {IERC20} from "./IERC20.sol";
import {IERC20Metadata} from "./extensions/IERC20Metadata.sol";
import {Context} from "../../utils/Context.sol";
import {IERC20Errors} from "../../interfaces/draft-IERC6093.sol";

/**
 * @dev Implementation of the {IERC20} interface.
 *
 * This implementation is agnostic to the way tokens are created. This means
 * that a supply mechanism has to be added in a derived contract using {_mint}.
 *
 * TIP: For a detailed writeup see our guide
 * https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
 * to implement supply mechanisms].
 *
 * The default value of {decimals} is 18. To change this, you should override
 * this function so it returns a different value.
 *
 * We have followed general OpenZeppelin Contracts guidelines: functions revert
 * instead returning `false` on failure. This behavior is nonetheless
 * conventional and does not conflict with the expectations of ERC20
 * applications.
 *
 * Additionally, an {Approval} event is emitted on calls to {transferFrom}.
 * This allows applications to reconstruct the allowance for all accounts just
 * by listening to said events. Other implementations of the EIP may not emit
 * these events, as it isn't required by the specification.
 */
abstract contract ERC20 is Context, IERC20, IERC20Metadata, IERC20Errors {
    mapping(address account => uint256) private _balances;

    mapping(address account => mapping(address spender => uint256)) private _allowances;

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;

    /**
     * @dev Sets the values for {name} and {symbol}.
     *
     * All two of these values are immutable: they can only be set once during
     * construction.
     */
    constructor(string memory name_, string memory symbol_) {
        _name = name_;
        _symbol = symbol_;
    }

    /**
     * @dev Returns the name of the token.
     */
    function name() public view virtual returns (string memory) {
        return _name;
    }

    /**
     * @dev Returns the symbol of the token, usually a shorter version of the
     * name.
     */
    function symbol() public view virtual returns (string memory) {
        return _symbol;
    }

    /**
     * @dev Returns the number of decimals used to get its user representation.
     * For example, if `decimals` equals `2`, a balance of `505` tokens should
     * be displayed to a user as `5.05` (`505 / 10 ** 2`).
     *
     * Tokens usually opt for a value of 18, imitating the relationship between
     * Ether and Wei. This is the default value returned by this function, unless
     * it's overridden.
     *
     * NOTE: This information is only used for _display_ purposes: it in
     * no way affects any of the arithmetic of the contract, including
     * {IERC20-balanceOf} and {IERC20-transfer}.
     */
    function decimals() public view virtual returns (uint8) {
        return 18;
    }

    /**
     * @dev See {IERC20-totalSupply}.
     */
    function totalSupply() public view virtual returns (uint256) {
        return _totalSupply;
    }

    /**
     * @dev See {IERC20-balanceOf}.
     */
    function balanceOf(address account) public view virtual returns (uint256) {
        return _balances[account];
    }

    /**
     * @dev See {IERC20-transfer}.
     *
     * Requirements:
     *
     * - `to` cannot be the zero address.
     * - the caller must have a balance of at least `value`.
     */
    function transfer(address to, uint256 value) public virtual returns (bool) {
        address owner = _msgSender();
        _transfer(owner, to, value);
        return true;
    }

    /**
     * @dev See {IERC20-allowance}.
     */
    function allowance(address owner, address spender) public view virtual returns (uint256) {
        return _allowances[owner][spender];
    }

    /**
     * @dev See {IERC20-approve}.
     *
     * NOTE: If `value` is the maximum `uint256`, the allowance is not updated on
     * `transferFrom`. This is semantically equivalent to an infinite approval.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function approve(address spender, uint256 value) public virtual returns (bool) {
        address owner = _msgSender();
        _approve(owner, spender, value);
        return true;
    }

    /**
     * @dev See {IERC20-transferFrom}.
     *
     * Emits an {Approval} event indicating the updated allowance. This is not
     * required by the EIP. See the note at the beginning of {ERC20}.
     *
     * NOTE: Does not update the allowance if the current allowance
     * is the maximum `uint256`.
     *
     * Requirements:
     *
     * - `from` and `to` cannot be the zero address.
     * - `from` must have a balance of at least `value`.
     * - the caller must have allowance for ``from``'s tokens of at least
     * `value`.
     */
    function transferFrom(address from, address to, uint256 value) public virtual returns (bool) {
        address spender = _msgSender();
        _spendAllowance(from, spender, value);
        _transfer(from, to, value);
        return true;
    }

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to`.
     *
     * This internal function is equivalent to {transfer}, and can be used to
     * e.g. implement automatic token fees, slashing mechanisms, etc.
     *
     * Emits a {Transfer} event.
     *
     * NOTE: This function is not virtual, {_update} should be overridden instead.
     */
    function _transfer(address from, address to, uint256 value) internal {
        if (from == address(0)) {
            revert ERC20InvalidSender(address(0));
        }
        if (to == address(0)) {
            revert ERC20InvalidReceiver(address(0));
        }
        _update(from, to, value);
    }

    /**
     * @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from`
     * (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding
     * this function.
     *
     * Emits a {Transfer} event.
     */
    function _update(address from, address to, uint256 value) internal virtual {
        if (from == address(0)) {
            // Overflow check required: The rest of the code assumes that totalSupply never overflows
            _totalSupply += value;
        } else {
            uint256 fromBalance = _balances[from];
            if (fromBalance < value) {
                revert ERC20InsufficientBalance(from, fromBalance, value);
            }
            unchecked {
                // Overflow not possible: value <= fromBalance <= totalSupply.
                _balances[from] = fromBalance - value;
            }
        }

        if (to == address(0)) {
            unchecked {
                // Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply.
                _totalSupply -= value;
            }
        } else {
            unchecked {
                // Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256.
                _balances[to] += value;
            }
        }

        emit Transfer(from, to, value);
    }

    /**
     * @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0).
     * Relies on the `_update` mechanism
     *
     * Emits a {Transfer} event with `from` set to the zero address.
     *
     * NOTE: This function is not virtual, {_update} should be overridden instead.
     */
    function _mint(address account, uint256 value) internal {
        if (account == address(0)) {
            revert ERC20InvalidReceiver(address(0));
        }
        _update(address(0), account, value);
    }

    /**
     * @dev Destroys a `value` amount of tokens from `account`, lowering the total supply.
     * Relies on the `_update` mechanism.
     *
     * Emits a {Transfer} event with `to` set to the zero address.
     *
     * NOTE: This function is not virtual, {_update} should be overridden instead
     */
    function _burn(address account, uint256 value) internal {
        if (account == address(0)) {
            revert ERC20InvalidSender(address(0));
        }
        _update(account, address(0), value);
    }

    /**
     * @dev Sets `value` as the allowance of `spender` over the `owner` s tokens.
     *
     * This internal function is equivalent to `approve`, and can be used to
     * e.g. set automatic allowances for certain subsystems, etc.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `owner` cannot be the zero address.
     * - `spender` cannot be the zero address.
     *
     * Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.
     */
    function _approve(address owner, address spender, uint256 value) internal {
        _approve(owner, spender, value, true);
    }

    /**
     * @dev Variant of {_approve} with an optional flag to enable or disable the {Approval} event.
     *
     * By default (when calling {_approve}) the flag is set to true. On the other hand, approval changes made by
     * `_spendAllowance` during the `transferFrom` operation set the flag to false. This saves gas by not emitting any
     * `Approval` event during `transferFrom` operations.
     *
     * Anyone who wishes to continue emitting `Approval` events on the`transferFrom` operation can force the flag to
     * true using the following override:
     * ```
     * function _approve(address owner, address spender, uint256 value, bool) internal virtual override {
     *     super._approve(owner, spender, value, true);
     * }
     * ```
     *
     * Requirements are the same as {_approve}.
     */
    function _approve(address owner, address spender, uint256 value, bool emitEvent) internal virtual {
        if (owner == address(0)) {
            revert ERC20InvalidApprover(address(0));
        }
        if (spender == address(0)) {
            revert ERC20InvalidSpender(address(0));
        }
        _allowances[owner][spender] = value;
        if (emitEvent) {
            emit Approval(owner, spender, value);
        }
    }

    /**
     * @dev Updates `owner` s allowance for `spender` based on spent `value`.
     *
     * Does not update the allowance value in case of infinite allowance.
     * Revert if not enough allowance is available.
     *
     * Does not emit an {Approval} event.
     */
    function _spendAllowance(address owner, address spender, uint256 value) internal virtual {
        uint256 currentAllowance = allowance(owner, spender);
        if (currentAllowance != type(uint256).max) {
            if (currentAllowance < value) {
                revert ERC20InsufficientAllowance(spender, currentAllowance, value);
            }
            unchecked {
                _approve(owner, spender, currentAllowance - value, false);
            }
        }
    }
}

File 8 of 59 : ERC20Burnable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/ERC20Burnable.sol)

pragma solidity ^0.8.20;

import {ERC20} from "../ERC20.sol";
import {Context} from "../../../utils/Context.sol";

/**
 * @dev Extension of {ERC20} that allows token holders to destroy both their own
 * tokens and those that they have an allowance for, in a way that can be
 * recognized off-chain (via event analysis).
 */
abstract contract ERC20Burnable is Context, ERC20 {
    /**
     * @dev Destroys a `value` amount of tokens from the caller.
     *
     * See {ERC20-_burn}.
     */
    function burn(uint256 value) public virtual {
        _burn(_msgSender(), value);
    }

    /**
     * @dev Destroys a `value` amount of tokens from `account`, deducting from
     * the caller's allowance.
     *
     * See {ERC20-_burn} and {ERC20-allowance}.
     *
     * Requirements:
     *
     * - the caller must have allowance for ``accounts``'s tokens of at least
     * `value`.
     */
    function burnFrom(address account, uint256 value) public virtual {
        _spendAllowance(account, _msgSender(), value);
        _burn(account, value);
    }
}

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

pragma solidity ^0.8.20;

import {IERC3156FlashBorrower} from "../../../interfaces/IERC3156FlashBorrower.sol";
import {IERC3156FlashLender} from "../../../interfaces/IERC3156FlashLender.sol";
import {ERC20} from "../ERC20.sol";

/**
 * @dev Implementation of the ERC3156 Flash loans extension, as defined in
 * https://eips.ethereum.org/EIPS/eip-3156[ERC-3156].
 *
 * Adds the {flashLoan} method, which provides flash loan support at the token
 * level. By default there is no fee, but this can be changed by overriding {flashFee}.
 *
 * NOTE: When this extension is used along with the {ERC20Capped} or {ERC20Votes} extensions,
 * {maxFlashLoan} will not correctly reflect the maximum that can be flash minted. We recommend
 * overriding {maxFlashLoan} so that it correctly reflects the supply cap.
 */
abstract contract ERC20FlashMint is ERC20, IERC3156FlashLender {
    bytes32 private constant RETURN_VALUE = keccak256("ERC3156FlashBorrower.onFlashLoan");

    /**
     * @dev The loan token is not valid.
     */
    error ERC3156UnsupportedToken(address token);

    /**
     * @dev The requested loan exceeds the max loan value for `token`.
     */
    error ERC3156ExceededMaxLoan(uint256 maxLoan);

    /**
     * @dev The receiver of a flashloan is not a valid {onFlashLoan} implementer.
     */
    error ERC3156InvalidReceiver(address receiver);

    /**
     * @dev Returns the maximum amount of tokens available for loan.
     * @param token The address of the token that is requested.
     * @return The amount of token that can be loaned.
     *
     * NOTE: This function does not consider any form of supply cap, so in case
     * it's used in a token with a cap like {ERC20Capped}, make sure to override this
     * function to integrate the cap instead of `type(uint256).max`.
     */
    function maxFlashLoan(address token) public view virtual returns (uint256) {
        return token == address(this) ? type(uint256).max - totalSupply() : 0;
    }

    /**
     * @dev Returns the fee applied when doing flash loans. This function calls
     * the {_flashFee} function which returns the fee applied when doing flash
     * loans.
     * @param token The token to be flash loaned.
     * @param value The amount of tokens to be loaned.
     * @return The fees applied to the corresponding flash loan.
     */
    function flashFee(address token, uint256 value) public view virtual returns (uint256) {
        if (token != address(this)) {
            revert ERC3156UnsupportedToken(token);
        }
        return _flashFee(token, value);
    }

    /**
     * @dev Returns the fee applied when doing flash loans. By default this
     * implementation has 0 fees. This function can be overloaded to make
     * the flash loan mechanism deflationary.
     * @param token The token to be flash loaned.
     * @param value The amount of tokens to be loaned.
     * @return The fees applied to the corresponding flash loan.
     */
    function _flashFee(address token, uint256 value) internal view virtual returns (uint256) {
        // silence warning about unused variable without the addition of bytecode.
        token;
        value;
        return 0;
    }

    /**
     * @dev Returns the receiver address of the flash fee. By default this
     * implementation returns the address(0) which means the fee amount will be burnt.
     * This function can be overloaded to change the fee receiver.
     * @return The address for which the flash fee will be sent to.
     */
    function _flashFeeReceiver() internal view virtual returns (address) {
        return address(0);
    }

    /**
     * @dev Performs a flash loan. New tokens are minted and sent to the
     * `receiver`, who is required to implement the {IERC3156FlashBorrower}
     * interface. By the end of the flash loan, the receiver is expected to own
     * value + fee tokens and have them approved back to the token contract itself so
     * they can be burned.
     * @param receiver The receiver of the flash loan. Should implement the
     * {IERC3156FlashBorrower-onFlashLoan} interface.
     * @param token The token to be flash loaned. Only `address(this)` is
     * supported.
     * @param value The amount of tokens to be loaned.
     * @param data An arbitrary datafield that is passed to the receiver.
     * @return `true` if the flash loan was successful.
     */
    // This function can reenter, but it doesn't pose a risk because it always preserves the property that the amount
    // minted at the beginning is always recovered and burned at the end, or else the entire function will revert.
    // slither-disable-next-line reentrancy-no-eth
    function flashLoan(
        IERC3156FlashBorrower receiver,
        address token,
        uint256 value,
        bytes calldata data
    ) public virtual returns (bool) {
        uint256 maxLoan = maxFlashLoan(token);
        if (value > maxLoan) {
            revert ERC3156ExceededMaxLoan(maxLoan);
        }
        uint256 fee = flashFee(token, value);
        _mint(address(receiver), value);
        if (receiver.onFlashLoan(_msgSender(), token, value, fee, data) != RETURN_VALUE) {
            revert ERC3156InvalidReceiver(address(receiver));
        }
        address flashFeeReceiver = _flashFeeReceiver();
        _spendAllowance(address(receiver), address(this), value + fee);
        if (fee == 0 || flashFeeReceiver == address(0)) {
            _burn(address(receiver), value + fee);
        } else {
            _burn(address(receiver), value);
            _transfer(address(receiver), flashFeeReceiver, fee);
        }
        return true;
    }
}

File 10 of 59 : ERC20Permit.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/ERC20Permit.sol)

pragma solidity ^0.8.20;

import {IERC20Permit} from "./IERC20Permit.sol";
import {ERC20} from "../ERC20.sol";
import {ECDSA} from "../../../utils/cryptography/ECDSA.sol";
import {EIP712} from "../../../utils/cryptography/EIP712.sol";
import {Nonces} from "../../../utils/Nonces.sol";

/**
 * @dev Implementation of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on `{IERC20-approve}`, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 */
abstract contract ERC20Permit is ERC20, IERC20Permit, EIP712, Nonces {
    bytes32 private constant PERMIT_TYPEHASH =
        keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");

    /**
     * @dev Permit deadline has expired.
     */
    error ERC2612ExpiredSignature(uint256 deadline);

    /**
     * @dev Mismatched signature.
     */
    error ERC2612InvalidSigner(address signer, address owner);

    /**
     * @dev Initializes the {EIP712} domain separator using the `name` parameter, and setting `version` to `"1"`.
     *
     * It's a good idea to use the same `name` that is defined as the ERC20 token name.
     */
    constructor(string memory name) EIP712(name, "1") {}

    /**
     * @inheritdoc IERC20Permit
     */
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) public virtual {
        if (block.timestamp > deadline) {
            revert ERC2612ExpiredSignature(deadline);
        }

        bytes32 structHash = keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, value, _useNonce(owner), deadline));

        bytes32 hash = _hashTypedDataV4(structHash);

        address signer = ECDSA.recover(hash, v, r, s);
        if (signer != owner) {
            revert ERC2612InvalidSigner(signer, owner);
        }

        _approve(owner, spender, value);
    }

    /**
     * @inheritdoc IERC20Permit
     */
    function nonces(address owner) public view virtual override(IERC20Permit, Nonces) returns (uint256) {
        return super.nonces(owner);
    }

    /**
     * @inheritdoc IERC20Permit
     */
    // solhint-disable-next-line func-name-mixedcase
    function DOMAIN_SEPARATOR() external view virtual returns (bytes32) {
        return _domainSeparatorV4();
    }
}

File 11 of 59 : ERC20Wrapper.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/ERC20Wrapper.sol)

pragma solidity ^0.8.20;

import {IERC20, IERC20Metadata, ERC20} from "../ERC20.sol";
import {SafeERC20} from "../utils/SafeERC20.sol";

/**
 * @dev Extension of the ERC20 token contract to support token wrapping.
 *
 * Users can deposit and withdraw "underlying tokens" and receive a matching number of "wrapped tokens". This is useful
 * in conjunction with other modules. For example, combining this wrapping mechanism with {ERC20Votes} will allow the
 * wrapping of an existing "basic" ERC20 into a governance token.
 */
abstract contract ERC20Wrapper is ERC20 {
    IERC20 private immutable _underlying;

    /**
     * @dev The underlying token couldn't be wrapped.
     */
    error ERC20InvalidUnderlying(address token);

    constructor(IERC20 underlyingToken) {
        if (underlyingToken == this) {
            revert ERC20InvalidUnderlying(address(this));
        }
        _underlying = underlyingToken;
    }

    /**
     * @dev See {ERC20-decimals}.
     */
    function decimals() public view virtual override returns (uint8) {
        try IERC20Metadata(address(_underlying)).decimals() returns (uint8 value) {
            return value;
        } catch {
            return super.decimals();
        }
    }

    /**
     * @dev Returns the address of the underlying ERC-20 token that is being wrapped.
     */
    function underlying() public view returns (IERC20) {
        return _underlying;
    }

    /**
     * @dev Allow a user to deposit underlying tokens and mint the corresponding number of wrapped tokens.
     */
    function depositFor(address account, uint256 value) public virtual returns (bool) {
        address sender = _msgSender();
        if (sender == address(this)) {
            revert ERC20InvalidSender(address(this));
        }
        if (account == address(this)) {
            revert ERC20InvalidReceiver(account);
        }
        SafeERC20.safeTransferFrom(_underlying, sender, address(this), value);
        _mint(account, value);
        return true;
    }

    /**
     * @dev Allow a user to burn a number of wrapped tokens and withdraw the corresponding number of underlying tokens.
     */
    function withdrawTo(address account, uint256 value) public virtual returns (bool) {
        if (account == address(this)) {
            revert ERC20InvalidReceiver(account);
        }
        _burn(_msgSender(), value);
        SafeERC20.safeTransfer(_underlying, account, value);
        return true;
    }

    /**
     * @dev Mint wrapped token to cover any underlyingTokens that would have been transferred by mistake. Internal
     * function that can be exposed with access control if desired.
     */
    function _recover(address account) internal virtual returns (uint256) {
        uint256 value = _underlying.balanceOf(address(this)) - totalSupply();
        _mint(account, value);
        return value;
    }
}

File 12 of 59 : IERC20Metadata.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity ^0.8.20;

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

/**
 * @dev Interface for the optional metadata functions from the ERC20 standard.
 */
interface IERC20Metadata is IERC20 {
    /**
     * @dev Returns the name of the token.
     */
    function name() external view returns (string memory);

    /**
     * @dev Returns the symbol of the token.
     */
    function symbol() external view returns (string memory);

    /**
     * @dev Returns the decimals places of the token.
     */
    function decimals() external view returns (uint8);
}

File 13 of 59 : IERC20Permit.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Permit.sol)

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 *
 * ==== Security Considerations
 *
 * There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
 * expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
 * considered as an intention to spend the allowance in any specific way. The second is that because permits have
 * built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
 * take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
 * generally recommended is:
 *
 * ```solidity
 * function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
 *     try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
 *     doThing(..., value);
 * }
 *
 * function doThing(..., uint256 value) public {
 *     token.safeTransferFrom(msg.sender, address(this), value);
 *     ...
 * }
 * ```
 *
 * Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
 * `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
 * {SafeERC20-safeTransferFrom}).
 *
 * Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
 * contracts should have entry points that don't rely on permit.
 */
interface IERC20Permit {
    /**
     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
     * given ``owner``'s signed approval.
     *
     * IMPORTANT: The same issues {IERC20-approve} has related to transaction
     * ordering also apply here.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `deadline` must be a timestamp in the future.
     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
     * over the EIP712-formatted function arguments.
     * - the signature must use ``owner``'s current nonce (see {nonces}).
     *
     * For more information on the signature format, see the
     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
     * section].
     *
     * CAUTION: See Security Considerations above.
     */
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;

    /**
     * @dev Returns the current nonce for `owner`. This value must be
     * included whenever a signature is generated for {permit}.
     *
     * Every successful call to {permit} increases ``owner``'s nonce by one. This
     * prevents a signature from being used multiple times.
     */
    function nonces(address owner) external view returns (uint256);

    /**
     * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
     */
    // solhint-disable-next-line func-name-mixedcase
    function DOMAIN_SEPARATOR() external view returns (bytes32);
}

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

pragma solidity ^0.8.20;

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

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

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

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

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

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

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

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

File 15 of 59 : SafeERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.20;

import {IERC20} from "../IERC20.sol";
import {IERC20Permit} from "../extensions/IERC20Permit.sol";
import {Address} from "../../../utils/Address.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC20 operations that throw on failure (when the token
 * contract returns false). Tokens that return no value (and instead revert or
 * throw on failure) are also supported, non-reverting calls are assumed to be
 * successful.
 * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
library SafeERC20 {
    using Address for address;

    /**
     * @dev An operation with an ERC20 token failed.
     */
    error SafeERC20FailedOperation(address token);

    /**
     * @dev Indicates a failed `decreaseAllowance` request.
     */
    error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);

    /**
     * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeTransfer(IERC20 token, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
    }

    /**
     * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
     * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
     */
    function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
    }

    /**
     * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 oldAllowance = token.allowance(address(this), spender);
        forceApprove(token, spender, oldAllowance + value);
    }

    /**
     * @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
     * value, non-reverting calls are assumed to be successful.
     */
    function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
        unchecked {
            uint256 currentAllowance = token.allowance(address(this), spender);
            if (currentAllowance < requestedDecrease) {
                revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
            }
            forceApprove(token, spender, currentAllowance - requestedDecrease);
        }
    }

    /**
     * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
     * to be set to zero before setting it to a non-zero value, such as USDT.
     */
    function forceApprove(IERC20 token, address spender, uint256 value) internal {
        bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));

        if (!_callOptionalReturnBool(token, approvalCall)) {
            _callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
            _callOptionalReturn(token, approvalCall);
        }
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
        // the target address contains contract code and also asserts for success in the low-level call.

        bytes memory returndata = address(token).functionCall(data);
        if (returndata.length != 0 && !abi.decode(returndata, (bool))) {
            revert SafeERC20FailedOperation(address(token));
        }
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     *
     * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
     */
    function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
        // and not revert is the subcall reverts.

        (bool success, bytes memory returndata) = address(token).call(data);
        return success && (returndata.length == 0 || abi.decode(returndata, (bool))) && address(token).code.length > 0;
    }
}

File 16 of 59 : Address.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Address.sol)

pragma solidity ^0.8.20;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev The ETH balance of the account is not enough to perform the operation.
     */
    error AddressInsufficientBalance(address account);

    /**
     * @dev There's no code at `target` (it is not a contract).
     */
    error AddressEmptyCode(address target);

    /**
     * @dev A call to an address target failed. The target may have reverted.
     */
    error FailedInnerCall();

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        if (address(this).balance < amount) {
            revert AddressInsufficientBalance(address(this));
        }

        (bool success, ) = recipient.call{value: amount}("");
        if (!success) {
            revert FailedInnerCall();
        }
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason or custom error, it is bubbled
     * up by this function (like regular Solidity function calls). However, if
     * the call reverted with no returned reason, this function reverts with a
     * {FailedInnerCall} error.
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
        if (address(this).balance < value) {
            revert AddressInsufficientBalance(address(this));
        }
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResultFromTarget(target, success, returndata);
    }

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
     * was not a contract or bubbling up the revert reason (falling back to {FailedInnerCall}) in case of an
     * unsuccessful call.
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata
    ) internal view returns (bytes memory) {
        if (!success) {
            _revert(returndata);
        } else {
            // only check if target is a contract if the call was successful and the return data is empty
            // otherwise we already know that it was a contract
            if (returndata.length == 0 && target.code.length == 0) {
                revert AddressEmptyCode(target);
            }
            return returndata;
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
     * revert reason or with a default {FailedInnerCall} error.
     */
    function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
        if (!success) {
            _revert(returndata);
        } else {
            return returndata;
        }
    }

    /**
     * @dev Reverts with returndata if present. Otherwise reverts with {FailedInnerCall}.
     */
    function _revert(bytes memory returndata) private pure {
        // Look for revert reason and bubble it up if present
        if (returndata.length > 0) {
            // The easiest way to bubble the revert reason is using memory via assembly
            /// @solidity memory-safe-assembly
            assembly {
                let returndata_size := mload(returndata)
                revert(add(32, returndata), returndata_size)
            }
        } else {
            revert FailedInnerCall();
        }
    }
}

File 17 of 59 : Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)

pragma solidity ^0.8.20;

/**
 * @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;
    }

    function _contextSuffixLength() internal view virtual returns (uint256) {
        return 0;
    }
}

File 18 of 59 : ECDSA.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/ECDSA.sol)

pragma solidity ^0.8.20;

/**
 * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
 *
 * These functions can be used to verify that a message was signed by the holder
 * of the private keys of a given address.
 */
library ECDSA {
    enum RecoverError {
        NoError,
        InvalidSignature,
        InvalidSignatureLength,
        InvalidSignatureS
    }

    /**
     * @dev The signature derives the `address(0)`.
     */
    error ECDSAInvalidSignature();

    /**
     * @dev The signature has an invalid length.
     */
    error ECDSAInvalidSignatureLength(uint256 length);

    /**
     * @dev The signature has an S value that is in the upper half order.
     */
    error ECDSAInvalidSignatureS(bytes32 s);

    /**
     * @dev Returns the address that signed a hashed message (`hash`) with `signature` or an error. This will not
     * return address(0) without also returning an error description. Errors are documented using an enum (error type)
     * and a bytes32 providing additional information about the error.
     *
     * If no error is returned, then the address can be used for verification purposes.
     *
     * The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:
     * this function rejects them by requiring the `s` value to be in the lower
     * half order, and the `v` value to be either 27 or 28.
     *
     * IMPORTANT: `hash` _must_ be the result of a hash operation for the
     * verification to be secure: it is possible to craft signatures that
     * recover to arbitrary addresses for non-hashed data. A safe way to ensure
     * this is by receiving a hash of the original message (which may otherwise
     * be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it.
     *
     * Documentation for signature generation:
     * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
     * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
     */
    function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError, bytes32) {
        if (signature.length == 65) {
            bytes32 r;
            bytes32 s;
            uint8 v;
            // ecrecover takes the signature parameters, and the only way to get them
            // currently is to use assembly.
            /// @solidity memory-safe-assembly
            assembly {
                r := mload(add(signature, 0x20))
                s := mload(add(signature, 0x40))
                v := byte(0, mload(add(signature, 0x60)))
            }
            return tryRecover(hash, v, r, s);
        } else {
            return (address(0), RecoverError.InvalidSignatureLength, bytes32(signature.length));
        }
    }

    /**
     * @dev Returns the address that signed a hashed message (`hash`) with
     * `signature`. This address can then be used for verification purposes.
     *
     * The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:
     * this function rejects them by requiring the `s` value to be in the lower
     * half order, and the `v` value to be either 27 or 28.
     *
     * IMPORTANT: `hash` _must_ be the result of a hash operation for the
     * verification to be secure: it is possible to craft signatures that
     * recover to arbitrary addresses for non-hashed data. A safe way to ensure
     * this is by receiving a hash of the original message (which may otherwise
     * be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it.
     */
    function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
        (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, signature);
        _throwError(error, errorArg);
        return recovered;
    }

    /**
     * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.
     *
     * See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]
     */
    function tryRecover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address, RecoverError, bytes32) {
        unchecked {
            bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
            // We do not check for an overflow here since the shift operation results in 0 or 1.
            uint8 v = uint8((uint256(vs) >> 255) + 27);
            return tryRecover(hash, v, r, s);
        }
    }

    /**
     * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.
     */
    function recover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address) {
        (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, r, vs);
        _throwError(error, errorArg);
        return recovered;
    }

    /**
     * @dev Overload of {ECDSA-tryRecover} that receives the `v`,
     * `r` and `s` signature fields separately.
     */
    function tryRecover(
        bytes32 hash,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal pure returns (address, RecoverError, bytes32) {
        // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
        // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
        // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most
        // signatures from current libraries generate a unique signature with an s-value in the lower half order.
        //
        // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
        // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
        // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
        // these malleable signatures as well.
        if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
            return (address(0), RecoverError.InvalidSignatureS, s);
        }

        // If the signature is valid (and not malleable), return the signer address
        address signer = ecrecover(hash, v, r, s);
        if (signer == address(0)) {
            return (address(0), RecoverError.InvalidSignature, bytes32(0));
        }

        return (signer, RecoverError.NoError, bytes32(0));
    }

    /**
     * @dev Overload of {ECDSA-recover} that receives the `v`,
     * `r` and `s` signature fields separately.
     */
    function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) {
        (address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, v, r, s);
        _throwError(error, errorArg);
        return recovered;
    }

    /**
     * @dev Optionally reverts with the corresponding custom error according to the `error` argument provided.
     */
    function _throwError(RecoverError error, bytes32 errorArg) private pure {
        if (error == RecoverError.NoError) {
            return; // no error: do nothing
        } else if (error == RecoverError.InvalidSignature) {
            revert ECDSAInvalidSignature();
        } else if (error == RecoverError.InvalidSignatureLength) {
            revert ECDSAInvalidSignatureLength(uint256(errorArg));
        } else if (error == RecoverError.InvalidSignatureS) {
            revert ECDSAInvalidSignatureS(errorArg);
        }
    }
}

File 19 of 59 : EIP712.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/EIP712.sol)

pragma solidity ^0.8.20;

import {MessageHashUtils} from "./MessageHashUtils.sol";
import {ShortStrings, ShortString} from "../ShortStrings.sol";
import {IERC5267} from "../../interfaces/IERC5267.sol";

/**
 * @dev https://eips.ethereum.org/EIPS/eip-712[EIP 712] is a standard for hashing and signing of typed structured data.
 *
 * The encoding scheme specified in the EIP requires a domain separator and a hash of the typed structured data, whose
 * encoding is very generic and therefore its implementation in Solidity is not feasible, thus this contract
 * does not implement the encoding itself. Protocols need to implement the type-specific encoding they need in order to
 * produce the hash of their typed data using a combination of `abi.encode` and `keccak256`.
 *
 * This contract implements the EIP 712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding
 * scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA
 * ({_hashTypedDataV4}).
 *
 * The implementation of the domain separator was designed to be as efficient as possible while still properly updating
 * the chain id to protect against replay attacks on an eventual fork of the chain.
 *
 * NOTE: This contract implements the version of the encoding known as "v4", as implemented by the JSON RPC method
 * https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask].
 *
 * NOTE: In the upgradeable version of this contract, the cached values will correspond to the address, and the domain
 * separator of the implementation contract. This will cause the {_domainSeparatorV4} function to always rebuild the
 * separator from the immutable values, which is cheaper than accessing a cached version in cold storage.
 *
 * @custom:oz-upgrades-unsafe-allow state-variable-immutable
 */
abstract contract EIP712 is IERC5267 {
    using ShortStrings for *;

    bytes32 private constant TYPE_HASH =
        keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");

    // Cache the domain separator as an immutable value, but also store the chain id that it corresponds to, in order to
    // invalidate the cached domain separator if the chain id changes.
    bytes32 private immutable _cachedDomainSeparator;
    uint256 private immutable _cachedChainId;
    address private immutable _cachedThis;

    bytes32 private immutable _hashedName;
    bytes32 private immutable _hashedVersion;

    ShortString private immutable _name;
    ShortString private immutable _version;
    string private _nameFallback;
    string private _versionFallback;

    /**
     * @dev Initializes the domain separator and parameter caches.
     *
     * The meaning of `name` and `version` is specified in
     * https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP 712]:
     *
     * - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol.
     * - `version`: the current major version of the signing domain.
     *
     * NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart
     * contract upgrade].
     */
    constructor(string memory name, string memory version) {
        _name = name.toShortStringWithFallback(_nameFallback);
        _version = version.toShortStringWithFallback(_versionFallback);
        _hashedName = keccak256(bytes(name));
        _hashedVersion = keccak256(bytes(version));

        _cachedChainId = block.chainid;
        _cachedDomainSeparator = _buildDomainSeparator();
        _cachedThis = address(this);
    }

    /**
     * @dev Returns the domain separator for the current chain.
     */
    function _domainSeparatorV4() internal view returns (bytes32) {
        if (address(this) == _cachedThis && block.chainid == _cachedChainId) {
            return _cachedDomainSeparator;
        } else {
            return _buildDomainSeparator();
        }
    }

    function _buildDomainSeparator() private view returns (bytes32) {
        return keccak256(abi.encode(TYPE_HASH, _hashedName, _hashedVersion, block.chainid, address(this)));
    }

    /**
     * @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this
     * function returns the hash of the fully encoded EIP712 message for this domain.
     *
     * This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example:
     *
     * ```solidity
     * bytes32 digest = _hashTypedDataV4(keccak256(abi.encode(
     *     keccak256("Mail(address to,string contents)"),
     *     mailTo,
     *     keccak256(bytes(mailContents))
     * )));
     * address signer = ECDSA.recover(digest, signature);
     * ```
     */
    function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) {
        return MessageHashUtils.toTypedDataHash(_domainSeparatorV4(), structHash);
    }

    /**
     * @dev See {IERC-5267}.
     */
    function eip712Domain()
        public
        view
        virtual
        returns (
            bytes1 fields,
            string memory name,
            string memory version,
            uint256 chainId,
            address verifyingContract,
            bytes32 salt,
            uint256[] memory extensions
        )
    {
        return (
            hex"0f", // 01111
            _EIP712Name(),
            _EIP712Version(),
            block.chainid,
            address(this),
            bytes32(0),
            new uint256[](0)
        );
    }

    /**
     * @dev The name parameter for the EIP712 domain.
     *
     * NOTE: By default this function reads _name which is an immutable value.
     * It only reads from storage if necessary (in case the value is too large to fit in a ShortString).
     */
    // solhint-disable-next-line func-name-mixedcase
    function _EIP712Name() internal view returns (string memory) {
        return _name.toStringWithFallback(_nameFallback);
    }

    /**
     * @dev The version parameter for the EIP712 domain.
     *
     * NOTE: By default this function reads _version which is an immutable value.
     * It only reads from storage if necessary (in case the value is too large to fit in a ShortString).
     */
    // solhint-disable-next-line func-name-mixedcase
    function _EIP712Version() internal view returns (string memory) {
        return _version.toStringWithFallback(_versionFallback);
    }
}

File 20 of 59 : MessageHashUtils.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/MessageHashUtils.sol)

pragma solidity ^0.8.20;

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

/**
 * @dev Signature message hash utilities for producing digests to be consumed by {ECDSA} recovery or signing.
 *
 * The library provides methods for generating a hash of a message that conforms to the
 * https://eips.ethereum.org/EIPS/eip-191[EIP 191] and https://eips.ethereum.org/EIPS/eip-712[EIP 712]
 * specifications.
 */
library MessageHashUtils {
    /**
     * @dev Returns the keccak256 digest of an EIP-191 signed data with version
     * `0x45` (`personal_sign` messages).
     *
     * The digest is calculated by prefixing a bytes32 `messageHash` with
     * `"\x19Ethereum Signed Message:\n32"` and hashing the result. It corresponds with the
     * hash signed when using the https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] JSON-RPC method.
     *
     * NOTE: The `messageHash` parameter is intended to be the result of hashing a raw message with
     * keccak256, although any bytes32 value can be safely used because the final digest will
     * be re-hashed.
     *
     * See {ECDSA-recover}.
     */
    function toEthSignedMessageHash(bytes32 messageHash) internal pure returns (bytes32 digest) {
        /// @solidity memory-safe-assembly
        assembly {
            mstore(0x00, "\x19Ethereum Signed Message:\n32") // 32 is the bytes-length of messageHash
            mstore(0x1c, messageHash) // 0x1c (28) is the length of the prefix
            digest := keccak256(0x00, 0x3c) // 0x3c is the length of the prefix (0x1c) + messageHash (0x20)
        }
    }

    /**
     * @dev Returns the keccak256 digest of an EIP-191 signed data with version
     * `0x45` (`personal_sign` messages).
     *
     * The digest is calculated by prefixing an arbitrary `message` with
     * `"\x19Ethereum Signed Message:\n" + len(message)` and hashing the result. It corresponds with the
     * hash signed when using the https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] JSON-RPC method.
     *
     * See {ECDSA-recover}.
     */
    function toEthSignedMessageHash(bytes memory message) internal pure returns (bytes32) {
        return
            keccak256(bytes.concat("\x19Ethereum Signed Message:\n", bytes(Strings.toString(message.length)), message));
    }

    /**
     * @dev Returns the keccak256 digest of an EIP-191 signed data with version
     * `0x00` (data with intended validator).
     *
     * The digest is calculated by prefixing an arbitrary `data` with `"\x19\x00"` and the intended
     * `validator` address. Then hashing the result.
     *
     * See {ECDSA-recover}.
     */
    function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) {
        return keccak256(abi.encodePacked(hex"19_00", validator, data));
    }

    /**
     * @dev Returns the keccak256 digest of an EIP-712 typed data (EIP-191 version `0x01`).
     *
     * The digest is calculated from a `domainSeparator` and a `structHash`, by prefixing them with
     * `\x19\x01` and hashing the result. It corresponds to the hash signed by the
     * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`] JSON-RPC method as part of EIP-712.
     *
     * See {ECDSA-recover}.
     */
    function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 digest) {
        /// @solidity memory-safe-assembly
        assembly {
            let ptr := mload(0x40)
            mstore(ptr, hex"19_01")
            mstore(add(ptr, 0x02), domainSeparator)
            mstore(add(ptr, 0x22), structHash)
            digest := keccak256(ptr, 0x42)
        }
    }
}

File 21 of 59 : Math.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/Math.sol)

pragma solidity ^0.8.20;

/**
 * @dev Standard math utilities missing in the Solidity language.
 */
library Math {
    /**
     * @dev Muldiv operation overflow.
     */
    error MathOverflowedMulDiv();

    enum Rounding {
        Floor, // Toward negative infinity
        Ceil, // Toward positive infinity
        Trunc, // Toward zero
        Expand // Away from zero
    }

    /**
     * @dev Returns the addition of two unsigned integers, with an overflow flag.
     */
    function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            uint256 c = a + b;
            if (c < a) return (false, 0);
            return (true, c);
        }
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, with an overflow flag.
     */
    function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b > a) return (false, 0);
            return (true, a - b);
        }
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, with an overflow flag.
     */
    function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            // Gas optimization: this is cheaper than requiring 'a' not being zero, but the
            // benefit is lost if 'b' is also tested.
            // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
            if (a == 0) return (true, 0);
            uint256 c = a * b;
            if (c / a != b) return (false, 0);
            return (true, c);
        }
    }

    /**
     * @dev Returns the division of two unsigned integers, with a division by zero flag.
     */
    function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a / b);
        }
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
     */
    function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
        unchecked {
            if (b == 0) return (false, 0);
            return (true, a % b);
        }
    }

    /**
     * @dev Returns the largest of two numbers.
     */
    function max(uint256 a, uint256 b) internal pure returns (uint256) {
        return a > b ? a : b;
    }

    /**
     * @dev Returns the smallest of two numbers.
     */
    function min(uint256 a, uint256 b) internal pure returns (uint256) {
        return a < b ? a : b;
    }

    /**
     * @dev Returns the average of two numbers. The result is rounded towards
     * zero.
     */
    function average(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b) / 2 can overflow.
        return (a & b) + (a ^ b) / 2;
    }

    /**
     * @dev Returns the ceiling of the division of two numbers.
     *
     * This differs from standard division with `/` in that it rounds towards infinity instead
     * of rounding towards zero.
     */
    function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
        if (b == 0) {
            // Guarantee the same behavior as in a regular Solidity division.
            return a / b;
        }

        // (a + b - 1) / b can overflow on addition, so we distribute.
        return a == 0 ? 0 : (a - 1) / b + 1;
    }

    /**
     * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or
     * denominator == 0.
     * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by
     * Uniswap Labs also under MIT license.
     */
    function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
        unchecked {
            // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
            // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
            // variables such that product = prod1 * 2^256 + prod0.
            uint256 prod0 = x * y; // Least significant 256 bits of the product
            uint256 prod1; // Most significant 256 bits of the product
            assembly {
                let mm := mulmod(x, y, not(0))
                prod1 := sub(sub(mm, prod0), lt(mm, prod0))
            }

            // Handle non-overflow cases, 256 by 256 division.
            if (prod1 == 0) {
                // Solidity will revert if denominator == 0, unlike the div opcode on its own.
                // The surrounding unchecked block does not change this fact.
                // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
                return prod0 / denominator;
            }

            // Make sure the result is less than 2^256. Also prevents denominator == 0.
            if (denominator <= prod1) {
                revert MathOverflowedMulDiv();
            }

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

            // Make division exact by subtracting the remainder from [prod1 prod0].
            uint256 remainder;
            assembly {
                // Compute remainder using mulmod.
                remainder := mulmod(x, y, denominator)

                // Subtract 256 bit number from 512 bit number.
                prod1 := sub(prod1, gt(remainder, prod0))
                prod0 := sub(prod0, remainder)
            }

            // Factor powers of two out of denominator and compute largest power of two divisor of denominator.
            // Always >= 1. See https://cs.stackexchange.com/q/138556/92363.

            uint256 twos = denominator & (0 - denominator);
            assembly {
                // Divide denominator by twos.
                denominator := div(denominator, twos)

                // Divide [prod1 prod0] by twos.
                prod0 := div(prod0, twos)

                // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
                twos := add(div(sub(0, twos), twos), 1)
            }

            // Shift in bits from prod1 into prod0.
            prod0 |= prod1 * twos;

            // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
            // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
            // four bits. That is, denominator * inv = 1 mod 2^4.
            uint256 inverse = (3 * denominator) ^ 2;

            // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also
            // works in modular arithmetic, doubling the correct bits in each step.
            inverse *= 2 - denominator * inverse; // inverse mod 2^8
            inverse *= 2 - denominator * inverse; // inverse mod 2^16
            inverse *= 2 - denominator * inverse; // inverse mod 2^32
            inverse *= 2 - denominator * inverse; // inverse mod 2^64
            inverse *= 2 - denominator * inverse; // inverse mod 2^128
            inverse *= 2 - denominator * inverse; // inverse mod 2^256

            // Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
            // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
            // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
            // is no longer required.
            result = prod0 * inverse;
            return result;
        }
    }

    /**
     * @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
     */
    function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
        uint256 result = mulDiv(x, y, denominator);
        if (unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0) {
            result += 1;
        }
        return result;
    }

    /**
     * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded
     * towards zero.
     *
     * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
     */
    function sqrt(uint256 a) internal pure returns (uint256) {
        if (a == 0) {
            return 0;
        }

        // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
        //
        // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
        // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
        //
        // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
        // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
        // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
        //
        // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
        uint256 result = 1 << (log2(a) >> 1);

        // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
        // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
        // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
        // into the expected uint128 result.
        unchecked {
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            result = (result + a / result) >> 1;
            return min(result, a / result);
        }
    }

    /**
     * @notice Calculates sqrt(a), following the selected rounding direction.
     */
    function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = sqrt(a);
            return result + (unsignedRoundsUp(rounding) && result * result < a ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 2 of a positive value rounded towards zero.
     * Returns 0 if given 0.
     */
    function log2(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 128;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 64;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 32;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 16;
            }
            if (value >> 8 > 0) {
                value >>= 8;
                result += 8;
            }
            if (value >> 4 > 0) {
                value >>= 4;
                result += 4;
            }
            if (value >> 2 > 0) {
                value >>= 2;
                result += 2;
            }
            if (value >> 1 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 2, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log2(value);
            return result + (unsignedRoundsUp(rounding) && 1 << result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 10 of a positive value rounded towards zero.
     * Returns 0 if given 0.
     */
    function log10(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >= 10 ** 64) {
                value /= 10 ** 64;
                result += 64;
            }
            if (value >= 10 ** 32) {
                value /= 10 ** 32;
                result += 32;
            }
            if (value >= 10 ** 16) {
                value /= 10 ** 16;
                result += 16;
            }
            if (value >= 10 ** 8) {
                value /= 10 ** 8;
                result += 8;
            }
            if (value >= 10 ** 4) {
                value /= 10 ** 4;
                result += 4;
            }
            if (value >= 10 ** 2) {
                value /= 10 ** 2;
                result += 2;
            }
            if (value >= 10 ** 1) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 10, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log10(value);
            return result + (unsignedRoundsUp(rounding) && 10 ** result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 256 of a positive value rounded towards zero.
     * Returns 0 if given 0.
     *
     * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
     */
    function log256(uint256 value) internal pure returns (uint256) {
        uint256 result = 0;
        unchecked {
            if (value >> 128 > 0) {
                value >>= 128;
                result += 16;
            }
            if (value >> 64 > 0) {
                value >>= 64;
                result += 8;
            }
            if (value >> 32 > 0) {
                value >>= 32;
                result += 4;
            }
            if (value >> 16 > 0) {
                value >>= 16;
                result += 2;
            }
            if (value >> 8 > 0) {
                result += 1;
            }
        }
        return result;
    }

    /**
     * @dev Return the log in base 256, following the selected rounding direction, of a positive value.
     * Returns 0 if given 0.
     */
    function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
        unchecked {
            uint256 result = log256(value);
            return result + (unsignedRoundsUp(rounding) && 1 << (result << 3) < value ? 1 : 0);
        }
    }

    /**
     * @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.
     */
    function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {
        return uint8(rounding) % 2 == 1;
    }
}

File 22 of 59 : SignedMath.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/SignedMath.sol)

pragma solidity ^0.8.20;

/**
 * @dev Standard signed math utilities missing in the Solidity language.
 */
library SignedMath {
    /**
     * @dev Returns the largest of two signed numbers.
     */
    function max(int256 a, int256 b) internal pure returns (int256) {
        return a > b ? a : b;
    }

    /**
     * @dev Returns the smallest of two signed numbers.
     */
    function min(int256 a, int256 b) internal pure returns (int256) {
        return a < b ? a : b;
    }

    /**
     * @dev Returns the average of two signed numbers without overflow.
     * The result is rounded towards zero.
     */
    function average(int256 a, int256 b) internal pure returns (int256) {
        // Formula from the book "Hacker's Delight"
        int256 x = (a & b) + ((a ^ b) >> 1);
        return x + (int256(uint256(x) >> 255) & (a ^ b));
    }

    /**
     * @dev Returns the absolute unsigned value of a signed value.
     */
    function abs(int256 n) internal pure returns (uint256) {
        unchecked {
            // must be unchecked in order to support `n = type(int256).min`
            return uint256(n >= 0 ? n : -n);
        }
    }
}

File 23 of 59 : Nonces.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Nonces.sol)
pragma solidity ^0.8.20;

/**
 * @dev Provides tracking nonces for addresses. Nonces will only increment.
 */
abstract contract Nonces {
    /**
     * @dev The nonce used for an `account` is not the expected current nonce.
     */
    error InvalidAccountNonce(address account, uint256 currentNonce);

    mapping(address account => uint256) private _nonces;

    /**
     * @dev Returns the next unused nonce for an address.
     */
    function nonces(address owner) public view virtual returns (uint256) {
        return _nonces[owner];
    }

    /**
     * @dev Consumes a nonce.
     *
     * Returns the current value and increments nonce.
     */
    function _useNonce(address owner) internal virtual returns (uint256) {
        // For each account, the nonce has an initial value of 0, can only be incremented by one, and cannot be
        // decremented or reset. This guarantees that the nonce never overflows.
        unchecked {
            // It is important to do x++ and not ++x here.
            return _nonces[owner]++;
        }
    }

    /**
     * @dev Same as {_useNonce} but checking that `nonce` is the next valid for `owner`.
     */
    function _useCheckedNonce(address owner, uint256 nonce) internal virtual {
        uint256 current = _useNonce(owner);
        if (nonce != current) {
            revert InvalidAccountNonce(owner, current);
        }
    }
}

File 24 of 59 : ShortStrings.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/ShortStrings.sol)

pragma solidity ^0.8.20;

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

// | string  | 0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA   |
// | length  | 0x                                                              BB |
type ShortString is bytes32;

/**
 * @dev This library provides functions to convert short memory strings
 * into a `ShortString` type that can be used as an immutable variable.
 *
 * Strings of arbitrary length can be optimized using this library if
 * they are short enough (up to 31 bytes) by packing them with their
 * length (1 byte) in a single EVM word (32 bytes). Additionally, a
 * fallback mechanism can be used for every other case.
 *
 * Usage example:
 *
 * ```solidity
 * contract Named {
 *     using ShortStrings for *;
 *
 *     ShortString private immutable _name;
 *     string private _nameFallback;
 *
 *     constructor(string memory contractName) {
 *         _name = contractName.toShortStringWithFallback(_nameFallback);
 *     }
 *
 *     function name() external view returns (string memory) {
 *         return _name.toStringWithFallback(_nameFallback);
 *     }
 * }
 * ```
 */
library ShortStrings {
    // Used as an identifier for strings longer than 31 bytes.
    bytes32 private constant FALLBACK_SENTINEL = 0x00000000000000000000000000000000000000000000000000000000000000FF;

    error StringTooLong(string str);
    error InvalidShortString();

    /**
     * @dev Encode a string of at most 31 chars into a `ShortString`.
     *
     * This will trigger a `StringTooLong` error is the input string is too long.
     */
    function toShortString(string memory str) internal pure returns (ShortString) {
        bytes memory bstr = bytes(str);
        if (bstr.length > 31) {
            revert StringTooLong(str);
        }
        return ShortString.wrap(bytes32(uint256(bytes32(bstr)) | bstr.length));
    }

    /**
     * @dev Decode a `ShortString` back to a "normal" string.
     */
    function toString(ShortString sstr) internal pure returns (string memory) {
        uint256 len = byteLength(sstr);
        // using `new string(len)` would work locally but is not memory safe.
        string memory str = new string(32);
        /// @solidity memory-safe-assembly
        assembly {
            mstore(str, len)
            mstore(add(str, 0x20), sstr)
        }
        return str;
    }

    /**
     * @dev Return the length of a `ShortString`.
     */
    function byteLength(ShortString sstr) internal pure returns (uint256) {
        uint256 result = uint256(ShortString.unwrap(sstr)) & 0xFF;
        if (result > 31) {
            revert InvalidShortString();
        }
        return result;
    }

    /**
     * @dev Encode a string into a `ShortString`, or write it to storage if it is too long.
     */
    function toShortStringWithFallback(string memory value, string storage store) internal returns (ShortString) {
        if (bytes(value).length < 32) {
            return toShortString(value);
        } else {
            StorageSlot.getStringSlot(store).value = value;
            return ShortString.wrap(FALLBACK_SENTINEL);
        }
    }

    /**
     * @dev Decode a string that was encoded to `ShortString` or written to storage using {setWithFallback}.
     */
    function toStringWithFallback(ShortString value, string storage store) internal pure returns (string memory) {
        if (ShortString.unwrap(value) != FALLBACK_SENTINEL) {
            return toString(value);
        } else {
            return store;
        }
    }

    /**
     * @dev Return the length of a string that was encoded to `ShortString` or written to storage using
     * {setWithFallback}.
     *
     * WARNING: This will return the "byte length" of the string. This may not reflect the actual length in terms of
     * actual characters as the UTF-8 encoding of a single character can span over multiple bytes.
     */
    function byteLengthWithFallback(ShortString value, string storage store) internal view returns (uint256) {
        if (ShortString.unwrap(value) != FALLBACK_SENTINEL) {
            return byteLength(value);
        } else {
            return bytes(store).length;
        }
    }
}

File 25 of 59 : StorageSlot.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/StorageSlot.sol)
// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.

pragma solidity ^0.8.20;

/**
 * @dev Library for reading and writing primitive types to specific storage slots.
 *
 * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
 * This library helps with reading and writing to such slots without the need for inline assembly.
 *
 * The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
 *
 * Example usage to set ERC1967 implementation slot:
 * ```solidity
 * contract ERC1967 {
 *     bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
 *
 *     function _getImplementation() internal view returns (address) {
 *         return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
 *     }
 *
 *     function _setImplementation(address newImplementation) internal {
 *         require(newImplementation.code.length > 0);
 *         StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
 *     }
 * }
 * ```
 */
library StorageSlot {
    struct AddressSlot {
        address value;
    }

    struct BooleanSlot {
        bool value;
    }

    struct Bytes32Slot {
        bytes32 value;
    }

    struct Uint256Slot {
        uint256 value;
    }

    struct StringSlot {
        string value;
    }

    struct BytesSlot {
        bytes value;
    }

    /**
     * @dev Returns an `AddressSlot` with member `value` located at `slot`.
     */
    function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `BooleanSlot` with member `value` located at `slot`.
     */
    function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
     */
    function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `Uint256Slot` with member `value` located at `slot`.
     */
    function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `StringSlot` with member `value` located at `slot`.
     */
    function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `StringSlot` representation of the string storage pointer `store`.
     */
    function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := store.slot
        }
    }

    /**
     * @dev Returns an `BytesSlot` with member `value` located at `slot`.
     */
    function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := slot
        }
    }

    /**
     * @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.
     */
    function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
        /// @solidity memory-safe-assembly
        assembly {
            r.slot := store.slot
        }
    }
}

File 26 of 59 : Strings.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Strings.sol)

pragma solidity ^0.8.20;

import {Math} from "./math/Math.sol";
import {SignedMath} from "./math/SignedMath.sol";

/**
 * @dev String operations.
 */
library Strings {
    bytes16 private constant HEX_DIGITS = "0123456789abcdef";
    uint8 private constant ADDRESS_LENGTH = 20;

    /**
     * @dev The `value` string doesn't fit in the specified `length`.
     */
    error StringsInsufficientHexLength(uint256 value, uint256 length);

    /**
     * @dev Converts a `uint256` to its ASCII `string` decimal representation.
     */
    function toString(uint256 value) internal pure returns (string memory) {
        unchecked {
            uint256 length = Math.log10(value) + 1;
            string memory buffer = new string(length);
            uint256 ptr;
            /// @solidity memory-safe-assembly
            assembly {
                ptr := add(buffer, add(32, length))
            }
            while (true) {
                ptr--;
                /// @solidity memory-safe-assembly
                assembly {
                    mstore8(ptr, byte(mod(value, 10), HEX_DIGITS))
                }
                value /= 10;
                if (value == 0) break;
            }
            return buffer;
        }
    }

    /**
     * @dev Converts a `int256` to its ASCII `string` decimal representation.
     */
    function toStringSigned(int256 value) internal pure returns (string memory) {
        return string.concat(value < 0 ? "-" : "", toString(SignedMath.abs(value)));
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
     */
    function toHexString(uint256 value) internal pure returns (string memory) {
        unchecked {
            return toHexString(value, Math.log256(value) + 1);
        }
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
     */
    function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
        uint256 localValue = value;
        bytes memory buffer = new bytes(2 * length + 2);
        buffer[0] = "0";
        buffer[1] = "x";
        for (uint256 i = 2 * length + 1; i > 1; --i) {
            buffer[i] = HEX_DIGITS[localValue & 0xf];
            localValue >>= 4;
        }
        if (localValue != 0) {
            revert StringsInsufficientHexLength(value, length);
        }
        return string(buffer);
    }

    /**
     * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal
     * representation.
     */
    function toHexString(address addr) internal pure returns (string memory) {
        return toHexString(uint256(uint160(addr)), ADDRESS_LENGTH);
    }

    /**
     * @dev Returns true if the two strings are equal.
     */
    function equal(string memory a, string memory b) internal pure returns (bool) {
        return bytes(a).length == bytes(b).length && keccak256(bytes(a)) == keccak256(bytes(b));
    }
}

File 27 of 59 : BitMaps.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/structs/BitMaps.sol)
pragma solidity ^0.8.20;

/**
 * @dev Library for managing uint256 to bool mapping in a compact and efficient way, provided the keys are sequential.
 * Largely inspired by Uniswap's https://github.com/Uniswap/merkle-distributor/blob/master/contracts/MerkleDistributor.sol[merkle-distributor].
 *
 * BitMaps pack 256 booleans across each bit of a single 256-bit slot of `uint256` type.
 * Hence booleans corresponding to 256 _sequential_ indices would only consume a single slot,
 * unlike the regular `bool` which would consume an entire slot for a single value.
 *
 * This results in gas savings in two ways:
 *
 * - Setting a zero value to non-zero only once every 256 times
 * - Accessing the same warm slot for every 256 _sequential_ indices
 */
library BitMaps {
    struct BitMap {
        mapping(uint256 bucket => uint256) _data;
    }

    /**
     * @dev Returns whether the bit at `index` is set.
     */
    function get(BitMap storage bitmap, uint256 index) internal view returns (bool) {
        uint256 bucket = index >> 8;
        uint256 mask = 1 << (index & 0xff);
        return bitmap._data[bucket] & mask != 0;
    }

    /**
     * @dev Sets the bit at `index` to the boolean `value`.
     */
    function setTo(BitMap storage bitmap, uint256 index, bool value) internal {
        if (value) {
            set(bitmap, index);
        } else {
            unset(bitmap, index);
        }
    }

    /**
     * @dev Sets the bit at `index`.
     */
    function set(BitMap storage bitmap, uint256 index) internal {
        uint256 bucket = index >> 8;
        uint256 mask = 1 << (index & 0xff);
        bitmap._data[bucket] |= mask;
    }

    /**
     * @dev Unsets the bit at `index`.
     */
    function unset(BitMap storage bitmap, uint256 index) internal {
        uint256 bucket = index >> 8;
        uint256 mask = 1 << (index & 0xff);
        bitmap._data[bucket] &= ~mask;
    }
}

File 28 of 59 : Asset.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20FlashMint.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
import "./interfaces/IExpiry.sol";
import "./interfaces/IRates.sol";

contract ExchangeRate is IRates {
    uint256 internal rate;

    constructor(uint256 _rate) {
        rate = _rate;
    }

    function exchangeRate() external view override returns (uint256) {
        return rate;
    }
}

contract Expiry is IExpiry {
    uint256 internal timestamp;

    constructor(uint256 _expiry) {
        if (_expiry != 0 && _expiry < block.timestamp) {
            revert Expired();
        }

        timestamp = _expiry;
    }

    function isExpired() external view virtual returns (bool) {
        if (timestamp == 0) {
            return false;
        }

        return block.timestamp >= timestamp;
    }

    function expiry() external view virtual returns (uint256) {
        return timestamp;
    }
}

contract Asset is
    ERC20Burnable,
    ERC20Permit,
    ERC20FlashMint,
    Ownable,
    Expiry,
    ExchangeRate
{
    constructor(
        string memory prefix,
        string memory pairName,
        address _owner,
        uint256 _expiry,
        uint256 _rate
    )
        ExchangeRate(_rate)
        ERC20(
            string(abi.encodePacked(prefix, "-", pairName)),
            string(abi.encodePacked(prefix, "-", pairName))
        )
        ERC20Permit(string(abi.encodePacked(prefix, "-", pairName)))
        Ownable(_owner)
        Expiry(_expiry)
    {}

    function mint(address to, uint256 amount) public onlyOwner {
        _mint(to, amount);
    }
}

File 29 of 59 : Dev.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

import "../interfaces/dev/IDevToken.sol";

abstract contract Dev {
    function increase(address _contract, uint256 amount) external {
        IDevToken(_contract).mint(msg.sender, amount);
    }

    function decrease(address _contract, uint256 amount) external {
        IDevToken(_contract).burnSelf(amount);
    }
}

File 30 of 59 : LvDev.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

import "../interfaces/dev/ILvDev.sol";
import "./Dev.sol";
import "../ModuleState.sol";
import "../libraries/VaultLib.sol";
import "../libraries/State.sol";
import "../libraries/VaultLib.sol";

abstract contract LvDev is ModuleState, ILvDev {
    using VaultLibrary for *;
    using VaultLibrary for VaultState;

    function lvIncreaseCtBalance(
        address ct,
        uint256 amount,
        Id id
    ) external override {
        IDevToken(ct).mint(address(this), amount);
        states[id].vault.balances.ctBalance += amount;
    }

    function lvDecreaseCtBalance(
        address ct,
        uint256 amount,
        Id id
    ) external override {
        IDevToken(ct).burnSelf(amount);
        states[id].vault.balances.ctBalance -= amount;
    }

    function lvIncreaseDsBalance(
        address ds,
        uint256 amount,
        Id id
    ) external override {
        IDevToken(ds).mint(address(this), amount);
        states[id].vault.balances.dsBalance += amount;
    }

    function lvDecreaseDsBalance(
        address ds,
        uint256 amount,
        Id id
    ) external override {
        IDevToken(ds).burnSelf(amount);
        states[id].vault.balances.dsBalance -= amount;
    }

    function lvIncreasePaBalance(uint256 amount, Id id) external override {
        address pa = states[id].info.pair1;
        IDevToken(pa).mint(address(this), amount);
        states[id].vault.balances.paBalance += amount;
    }

    function lvDecreasePaBalance(uint256 amount, Id id) external override {
        address pa = states[id].info.pair1;
        IDevToken(pa).burnSelf(amount);
        states[id].vault.balances.paBalance -= amount;
    }

    function lvIncreaseRaBalance(uint256 amount, Id id) external override {
        address ra = states[id].info.pair0;

        IDevToken(ra).mint(address(this), amount);
        states[id].vault.balances.ra.free += amount;
    }

    function lvDecreaseRaBalance(uint256 amount, Id id) external override {
        address ra = states[id].info.pair0;
        IDevToken(ra).burnSelf(amount);
        states[id].vault.balances.ra.free -= amount;
    }
}

File 31 of 59 : PsmDev.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

import "../interfaces/dev/IPsmDev.sol";
import "./Dev.sol";
import "../ModuleState.sol";
import "../libraries/VaultLib.sol";
import "../libraries/State.sol";

abstract contract PsmDev is ModuleState, IPsmDev {
    using VaultLibrary for *;

    function psmIncreaseCtBalance(
        address ct,
        uint256 amount,
        Id id
    ) external override {
        IDevToken(ct).mint(address(this), amount);
        states[id].psmBalances.ctBalance += amount;
    }

    function psmDecreaseCtBalance(
        address ct,
        uint256 amount,
        Id id
    ) external override {
        IDevToken(ct).burnSelf(amount);
        states[id].psmBalances.ctBalance -= amount;
    }

    function psmIncreaseDsBalance(
        address ds,
        uint256 amount,
        Id id
    ) external override {
        IDevToken(ds).mint(address(this), amount);
        states[id].psmBalances.dsBalance += amount;
    }

    function psmDecreaseDsBalance(
        address ds,
        uint256 amount,
        Id id
    ) external override {
        IDevToken(ds).burnSelf(amount);
        states[id].psmBalances.dsBalance -= amount;
    }

    function psmIncreasePaBalance(uint256 amount, Id id) external override {
        address pa = states[id].info.pair1;

        IDevToken(pa).mint(address(this), amount);
        states[id].psmBalances.paBalance += amount;
    }

    function psmDecreasePaBalance(uint256 amount, Id id) external override {
        address pa = states[id].info.pair1;
        IDevToken(pa).burnSelf(amount);
        states[id].psmBalances.paBalance -= amount;
    }

    function psmIncreaseRaBalance(uint256 amount, Id id) external override {
        address ra = states[id].info.pair0;

        IDevToken(ra).mint(address(this), amount);
        states[id].psmBalances.ra.free += amount;
    }

    function psmDecreaseRaBalance(uint256 amount, Id id) external override {
        address ra = states[id].info.pair0;

        IDevToken(ra).burnSelf(amount);
        states[id].psmBalances.ra.free -= amount;
    }
}

File 32 of 59 : IDevToken.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

interface IDevToken {
    function mint(address to, uint256 amount) external;

    function burnSelf(uint256 amount) external;
}

File 33 of 59 : ILvDev.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
import "../../libraries/Pair.sol";

// - increases & decrease CT balance
// - increases & decrease DS balance
// - make deposit(the user who execute this will be minted RA and automatically deposit it into the LV, similar to PSM, it acts kinda like a router)
// - increase & decrease PA balance
// - increase & decrease RA balance
// - increase & decrease free WA balance (will automatically mint RA, wrap it to WA and deposit to LV, will NOT mint CT + DS to user)
interface ILvDev {
    function lvIncreaseCtBalance(address ct, uint256 amount, Id id) external;

    function lvDecreaseCtBalance(address ct, uint256 amount, Id id) external;

    function lvIncreaseDsBalance(address ds, uint256 amount, Id id) external;

    function lvDecreaseDsBalance(address ds, uint256 amount, Id id) external;

    function lvIncreasePaBalance(uint256 amount, Id id) external;

    function lvDecreasePaBalance(uint256 amount, Id id) external;

    function lvIncreaseRaBalance(uint256 amount, Id id) external;

    function lvDecreaseRaBalance(uint256 amount, Id id) external;
}

File 34 of 59 : IPsmDev.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
import "../../libraries/Pair.sol";

// - increases & decrease CT balance
// - increases & decrease DS balance
// - make deposit(the user who execute this will be minted RA and automatically deposit it into the psm, similar to PSM, it acts kinda like a router)
// - increase & decrease PA balance
// - increase & decrease RA balance
// - increase & decrease locked WA balance (will automatically mint RA, wrap it to WA and deposit to psm, will NOT mint CT + DS to user)
interface IPsmDev {
    function psmIncreaseCtBalance(address ct, uint256 amount, Id id) external;

    function psmDecreaseCtBalance(address ct, uint256 amount, Id id) external;

    function psmIncreaseDsBalance(address ds, uint256 amount, Id id) external;

    function psmDecreaseDsBalance(address ds, uint256 amount, Id id) external;

    function psmIncreasePaBalance(uint256 amount, Id id) external;

    function psmDecreasePaBalance(uint256 amount, Id id) external;

    function psmIncreaseRaBalance(uint256 amount, Id id) external;

    function psmDecreaseRaBalance(uint256 amount, Id id) external;
}

File 35 of 59 : IAssetFactory.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

interface IAssetFactory {
    /// @notice limit too long when getting deployed assets
    error LimitTooLong(uint256 max, uint256 received);

    /// @notice error when trying to deploying a swap asset of a non existent pair
    error NotExist(address ra, address pa);

    /// @notice emitted when a new CT + DS assets is deployed
    event AssetDeployed(
        address indexed ra,
        address indexed ct,
        address indexed ds
    );

    /// @notice emitted when a new LvAsset is deployed
    event LvAssetDeployed(
        address indexed ra,
        address indexed pa,
        address indexed lv
    );

    function getDeployedAssets(
        uint8 page,
        uint8 limit
    ) external view returns (address[] memory ra, address[] memory lv);

    function isDeployed(address asset) external view returns (bool);

    function getDeployedSwapAssets(
        address ra,
        uint8 page,
        uint8 limit
    ) external view returns (address[] memory ct, address[] memory ds);

    function deploySwapAssets(
        address ra,
        address pa,
        address owner,
        uint256 expiry,
        uint256 psmExchangeRate
    ) external returns (address ct, address ds);

    function deployLv(
        address ra,
        address pa,
        address owner
    ) external returns (address lv);
}

File 36 of 59 : ICommon.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
import "../libraries/Pair.sol";

interface ICommon {
    /// @notice module is not initialized, i.e thrown when interacting with uninitialized module
    error Uinitialized();

    /// @notice module is already initialized, i.e thrown when trying to reinitialize a module
    error AlreadyInitialized();

    /// @notice invalid asset, thrown when trying to do something with an asset not deployed with asset factory
    error InvalidAsset(address asset);

    /// @notice Emitted when a new LV and PSM is initialized with a given pair
    /// @param id The PSM id
    /// @param pa The address of the pegged asset
    /// @param ra The address of the redemption asset
    /// @param lv The address of the LV
    event Initialized(
        Id indexed id,
        address indexed pa,
        address indexed ra,
        address lv
    );

    /// @notice Emitted when a new DS is issued for a given PSM
    /// @param Id The PSM id
    /// @param dsId The DS id
    /// @param expiry The expiry of the DS
    event Issued(
        Id indexed Id,
        uint256 indexed dsId,
        uint256 indexed expiry,
        address ds,
        address ct
    );

    /**
     * @notice Get the last DS id issued for a given module, the returned DS doesn't guarantee to be active
     * @param id The current module id
     * @return dsId The current effective DS id
     *
     */
    function lastDsId(Id id) external view returns (uint256 dsId);
}

File 37 of 59 : IExpiry.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

interface IExpiry  {

    /// @notice Trying to issue an expired asset
    error Expired();

    function isExpired() external view returns (bool);

    ///@notice returns the expiry timestamp if 0 then it means it never expires
    function expiry() external view returns (uint256);
}

File 38 of 59 : Init.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
import "../libraries/Pair.sol";

interface Initialize {
    function initialize(
        address pa,
        address ra,
        uint256 lvFee,
        uint256 lvAmmWaDepositThreshold,
        uint256 lvAmmCtDepositThreshold
    ) external;

    function issueNewDs(Id id, uint256 expiry, uint256 exchangeRates) external;
}

File 39 of 59 : IPSMcore.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
import "../libraries/Pair.sol";

interface IPSMcore {
    /// @notice Emitted when a user deposits assets into a given PSM
    /// @param Id The PSM id
    /// @param dsId The DS id
    /// @param depositor The address of the depositor
    /// @param amount The amount of the asset deposited
    event PsmDeposited(
        Id indexed Id,
        uint256 indexed dsId,
        address indexed depositor,
        uint256 amount
    );

    /// @notice Emitted when a user redeems a DS for a given PSM
    /// @param Id The PSM id
    /// @param dsId The DS id
    /// @param redeemer The address of the redeemer
    /// @param amount The amount of the DS redeemed
    event DsRedeemed(
        Id indexed Id,
        uint256 indexed dsId,
        address indexed redeemer,
        uint256 amount
    );

    /// @notice Emitted when a user redeems a CT for a given PSM
    /// @param Id The PSM id
    /// @param dsId The DS id
    /// @param redeemer The address of the redeemer
    /// @param amount The amount of the CT redeemed
    /// @param paReceived The amount of the pegged asset received
    /// @param raReceived The amount of the redemption asset received
    event CtRedeemed(
        Id indexed Id,
        uint256 indexed dsId,
        address indexed redeemer,
        uint256 amount,
        uint256 paReceived,
        uint256 raReceived
    );

    /// @notice Emitted when a user cancels their DS position by depositing the CT + DS back into the PSM
    /// @param Id The PSM id
    /// @param dsId The DS id
    /// @param redeemer The address of the redeemer
    /// @param raAmount The amount of RA received
    /// @param swapAmount The amount of CT + DS swapped
    /// @param exchangeRates The exchange rate between RA:(CT+DS) at the time of the swap
    event Cancelled(
        Id indexed Id,
        uint256 indexed dsId,
        address indexed redeemer,
        uint256 raAmount,
        uint256 swapAmount,
        uint256 exchangeRates
    );

    function depositPsm(Id id, uint256 amount) external;

    /**
     * This determines the rate of how much the user will receive for the amount of asset they want to deposit.
     * for example, if the rate is 1.5, then the user will need to deposit 1.5 token to get 1 CT and DS.
     * @param id the id of the PSM
     */
    function exchangeRate(Id id) external view returns (uint256 rates);

    function previewDepositPsm(
        Id id,
        uint256 amount
    )
        external
        view
        returns (uint256 ctReceived, uint256 dsReceived, uint256 dsId);

    function redeemRaWithDs(
        Id id,
        uint256 dsId,
        uint256 amount,
        bytes memory rawDsPermitSig,
        uint256 deadline
    ) external;

    function previewRedeemRaWithDs(
        Id id,
        uint256 dsId,
        uint256 amount
    ) external view returns (uint256 assets);

    function redeemWithCT(
        Id id,
        uint256 dsId,
        uint256 amount,
        bytes memory rawCtPermitSig,
        uint256 deadline
    ) external;

    function previewRedeemWithCt(
        Id id,
        uint256 dsId,
        uint256 amount
    ) external view returns (uint256 paReceived, uint256 raReceived);

    function redeemRaWithCtDs(Id id, uint256 amount) external;

    function previewRedeemRaWithCtDs(
        Id id,
        uint256 amount
    ) external view returns (uint256 ra, uint256 rates);

    function valueLocked(Id id) external view returns (uint256);
}

File 40 of 59 : IRates.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

interface IRates {
    /// @notice returns the exchange rate, if 0 then it means that there's no rate associated with it, like the case of LV token
    function exchangeRate() external view returns (uint256 rates);
}

File 41 of 59 : IVault.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
import "../libraries/Pair.sol";

interface IVault {
    /// @notice Emitted when a user deposits assets into a given Vault
    /// @param id The Module id that is used to reference both psm and lv of a given pair
    /// @param depositor The address of the depositor
    /// @param amount  The amount of the asset deposited
    event LvDeposited(Id indexed id, address indexed depositor, uint256 amount);

    /// @notice Emitted when a user requests redemption of a given Vault
    /// @param Id The Module id that is used to reference both psm and lv of a given pair
    /// @param redeemer The address of the redeemer
    /// @param amount The amount of the asset to be redeemed
    event RedemptionRequested(
        Id indexed Id,
        address indexed redeemer,
        uint256 amount
    );

    /// @notice Emitted when a user transfers redemption rights of a given Vault
    /// @param Id The Module id that is used to reference both psm and lv of a given pair
    /// @param from The address of the previous owner of the redemption rights
    /// @param to The address of the new owner of the redemption rights
    event RedemptionRightTransferred(
        Id indexed Id,
        address indexed from,
        address indexed to,
        uint256 amount
    );

    /// @notice Emitted when a user redeems expired Lv
    /// @param Id The Module id that is used to reference both psm and lv of a given pair
    /// @param receiver The address of the receiver
    /// @param ra The amount of ra redeemed
    /// @param pa The amount of pa redeemed
    event LvRedeemExpired(
        Id indexed Id,
        address indexed receiver,
        uint256 ra,
        uint256 pa
    );

    /// @notice Emitted when a user redeems Lv before expiry
    /// @param Id The Module id that is used to reference both psm and lv of a given pair
    /// @param receiver The address of the receiver
    /// @param amount The amount of the asset redeemed
    /// @param fee The total fee charged for early redemption
    /// @param feePrecentage The fee precentage for early redemption, denominated in 1e18 (e.g 100e18 = 100%)
    event LvRedeemEarly(
        Id indexed Id,
        address indexed redeemer,
        address indexed receiver,
        uint256 amount,
        uint256 fee,
        uint256 feePrecentage
    );

    /// @notice Emitted when a user cancels a redemption request
    /// @param Id The Module id that is used to reference both psm and lv of a given pair
    /// @param redeemer The address of the redeemer
    /// @param amount The amount of the asset to be redeemed
    event RedemptionRequestCancelled(
        Id indexed Id,
        address indexed redeemer,
        uint256 amount
    );

    /**
     * @notice Deposit a wrapped asset into a given vault
     * @param id The Module id that is used to reference both psm and lv of a given pair
     * @param amount The amount of the redemption asset(ra) deposited
     */
    function depositLv(Id id, uint256 amount) external;

    /**
     * @notice Preview the amount of lv that will be deposited
     * @param amount The amount of the redemption asset(ra) to be deposited
     */
    function previewLvDeposit(
        uint256 amount
    ) external pure returns (uint256 lv);

    /**
     * @notice Request redemption of a given vault at expiry
     * @param id The Module id that is used to reference both psm and lv of a given pair
     */
    function requestRedemption(Id id, uint256 amount) external;

    /**
     * @notice Transfer redemption rights of a given vault at expiry
     * @param id The Module id that is used to reference both psm and lv of a given pair
     * @param to The address of the new owner of the redemption rights
     * @param amount The amount of the user locked LV token to be transferred
     */
    function transferRedemptionRights(
        Id id,
        address to,
        uint256 amount
    ) external;

    /**
     * @notice Redeem expired lv, when there's no active DS issuance, there's no cap on the amount of lv that can be redeemed.
     * @param id The Module id that is used to reference both psm and lv of a given pair
     * @param receiver  The address of the receiver
     * @param amount The amount of the asset to be redeemed
     */
    function redeemExpiredLv(Id id, address receiver, uint256 amount) external;

    /**
     * @notice preview redeem expired lv
     * @param id The Module id that is used to reference both psm and lv of a given pair
     * @param amount The amount of the asset to be redeemed
     * @return attributedRa The amount of ra that will be redeemed
     * @return attributedPa The amount of pa that will be redeemed
     * @return approvedAmount The amount of lv needed to be approved before redeeming,
     * this is necessary when the user doesn't have enough locked LV token to redeem the full amount
     */
    function previewRedeemExpiredLv(
        Id id,
        uint256 amount
    )
        external
        view
        returns (
            uint256 attributedRa,
            uint256 attributedPa,
            uint256 approvedAmount
        );

    /**
     * @notice Redeem lv before expiry
     * @param id The Module id that is used to reference both psm and lv of a given pair
     * @param receiver The address of the receiver
     * @param amount The amount of the asset to be redeemed
     */
    function redeemEarlyLv(Id id, address receiver, uint256 amount) external;

    /**
     * @notice Get the amount of locked lv for a given user
     * @param id The Module id that is used to reference both psm and lv of a given pair
     * @param user The address of the user
     */
    function lockedLvfor(
        Id id,
        address user
    ) external view returns (uint256 locked);

    /**
     * @notice preview redeem lv before expiry
     * @param id The Module id that is used to reference both psm and lv of a given pair
     * @param amount The amount of the asset to be redeemed
     */
    function previewRedeemEarlyLv(
        Id id,
        uint256 amount
    )
        external
        view
        returns (uint256 received, uint256 fee, uint256 feePrecentage);

    /**
     * Returns the amount of RA and PA reserved for user withdrawal
     * @param id The Module id that is used to reference both psm and lv of a given pair
     */
    function reservedUserWithdrawal(
        Id id
    ) external view returns (uint256 reservedRa, uint256 reservedPa);
}

File 42 of 59 : DepegSwapLib.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;
import "./../Asset.sol";
import "./SignatureHelperLib.sol";

struct DepegSwap {
    bool expiredEventEmitted;
    address ds;
    address ct;
    uint256 dsRedeemed;
    uint256 ctRedeemed;
}

library DepegSwapLibrary {
    using MinimalSignatureHelper for Signature;

    function isExpired(DepegSwap storage self) internal view returns (bool) {
        return Asset(self.ds).isExpired();
    }

    function isInitialized(
        DepegSwap storage self
    ) internal view returns (bool) {
        return self.ds != address(0) && self.ct != address(0);
    }

    function exchangeRate(
        DepegSwap storage self
    ) internal view returns (uint256) {
        return Asset(self.ds).exchangeRate();
    }

    function initialize(
        address ds,
        address ct
    ) internal pure returns (DepegSwap memory) {
        return
            DepegSwap({
                expiredEventEmitted: false,
                ds: ds,
                ct: ct,
                dsRedeemed: 0,
                ctRedeemed: 0
            });
    }

    function permit(
        address contract_,
        bytes memory rawSig,
        address owner,
        address spender,
        uint256 value,
        uint256 deadline
    ) internal {
        Signature memory sig = MinimalSignatureHelper.split(rawSig);

        Asset(contract_).permit(
            owner,
            spender,
            value,
            deadline,
            sig.v,
            sig.r,
            sig.s
        );
    }

    function issue(DepegSwap memory self, address to, uint256 amount) internal {
        Asset(self.ds).mint(to, amount);
        Asset(self.ct).mint(to, amount);
    }

    function burnBothforSelf(DepegSwap storage self, uint256 amount) internal {
        Asset(self.ds).burn(amount);
        Asset(self.ct).burn(amount);
    }
}

File 43 of 59 : Guard.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
import "./DepegSwapLib.sol";
import "./LvAssetLib.sol";

library Guard {
    using DepegSwapLibrary for DepegSwap;
    using LvAssetLibrary for LvAsset;

    /// @notice asset is expired
    error Expired();

    /// @notice asset is not expired. e.g trying to redeem before expiry
    error NotExpired();

    /// @notice asset is not initialized
    error Uinitialized();

    function _onlyNotExpired(DepegSwap storage ds) internal view {
        if (ds.isExpired()) {
            revert Expired();
        }
    }

    function _onlyExpired(DepegSwap storage ds) internal view {
        if (!ds.isExpired()) {
            revert NotExpired();
        }
    }

    function _onlyInitialized(DepegSwap storage ds) internal view {
        if (!ds.isInitialized()) {
            revert Uinitialized();
        }
    }

    function safeBeforeExpired(DepegSwap storage ds) internal view {
        _onlyInitialized(ds);
        _onlyNotExpired(ds);
    }

    function safeAfterExpired(DepegSwap storage ds) internal view {
        _onlyInitialized(ds);
        _onlyExpired(ds);
    }
}

File 44 of 59 : LvAssetLib.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "../Asset.sol";

struct LvAsset {
    address _address;
    uint256 locked;
}

library LvAssetLibrary {
    using LvAssetLibrary for LvAsset;

    function initialize(
        address _address
    ) internal pure returns (LvAsset memory) {
        return LvAsset(_address, 0);
    }

    function asErc20(LvAsset memory self) internal pure returns (IERC20) {
        return IERC20(self._address);
    }

    function isInitialized(LvAsset memory self) internal pure returns (bool) {
        return self._address != address(0);
    }

    function depositUnchecked(
        LvAsset memory self,
        address from,
        uint256 amount
    ) internal {
        self.asErc20().transferFrom(from, address(this), amount);
    }

    function totalIssued(
        LvAsset memory self
    ) internal view returns (uint256 total) {
        total = IERC20(self._address).totalSupply();
    }

    function issue(LvAsset memory self, address to, uint256 amount) internal {
        Asset(self._address).mint(to, amount);
    }

    function incLocked(LvAsset storage self, uint256 amount) internal {
        self.locked = self.locked + amount;
    }

    function decLocked(LvAsset storage self, uint256 amount) internal {
        self.locked = self.locked - amount;
    }

    function lockFrom(
        LvAsset storage self,
        uint256 amount,
        address from
    ) internal {
        incLocked(self, amount);
        lockUnchecked(self, amount, from);
    }

    function unlockTo(
        LvAsset storage self,
        uint256 amount,
        address to
    ) internal {
        decLocked(self, amount);
        self.asErc20().transfer(to, amount);
    }

    function lockUnchecked(
        LvAsset storage self,
        uint256 amount,
        address from
    ) internal {
        ERC20(self._address).transferFrom(from, address(this), amount);
    }

    function burnSelf(LvAsset storage self, uint256 amount) internal {
        decLocked(self, amount);
        ERC20Burnable(self._address).burn(amount);
    }
}

File 45 of 59 : MathHelper.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

library MathHelper {
    /// @dev default decimals for now to calculate price ratio
    uint8 internal constant DEFAULT_DECIMAL = 18;

    /**
     * @dev calculate the amount of ra and ct needed to provide AMM with liquidity in respect to the price ratio
     *
     * @param amountra the total amount of liquidity user provide(e.g 2 ra)
     * @param priceRatio the price ratio of the pair, should be retrieved from the AMM as sqrtx96 and be converted to ratio
     * @return ra the amount of ra needed to provide AMM with liquidity
     * @return ct the amount of ct needed to provide AMM with liquidity, also the amount of how much ra should be converted to ct
     */
    function calculateAmounts(
        uint256 amountra,
        uint256 priceRatio
    ) external pure returns (uint256 ra, uint256 ct) {
        ct = (amountra * 1e18) / (priceRatio + 1e18);
        ra = (amountra - ct);

        assert((ct + ra) == amountra);
    }

    // TODO: add support for 2 different decimals token? but since we're
    // using ra and ct, which both has 18 decimals so will default into that one for now
    /// @dev should only pass ERC20.decimals() onto the decimal field
    /// @dev will output price ratio in 18 decimal precision.
    function calculatePriceRatio(
        uint160 sqrtPriceX96,
        uint8 decimal
    ) external pure returns (uint256) {
        uint256 numerator1 = uint256(sqrtPriceX96) * uint256(sqrtPriceX96);
        uint256 numerator2 = 10 ** decimal;
        uint256 denominator = 1 << 192;

        return (numerator1 * numerator2) / denominator;
    }

    /**
     *  @dev calculate the base withdrawal amount of ra and pa in respect of given amount
     * @param totalLv the total amount of lv in the pool
     * @param accruedRa the total amount of ra accrued in the pool
     * @param accruedPa the total amount of pa accrued in the pool
     * @param amount the amount of lv user want to withdraw
     * @return ra the amount of ra user will receive
     * @return pa the amount of pa user will receive
     */
    function calculateBaseWithdrawal(
        uint256 totalLv,
        uint256 accruedRa,
        uint256 accruedPa,
        uint256 amount
    ) external pure returns (uint256 ra, uint256 pa) {
        ra = (amount * ((accruedRa * 1e18) / totalLv)) / 1e18;
        pa = (amount * ((accruedPa * 1e18) / totalLv)) / 1e18;
    }

    /**
     * calculate the early lv rate in respect to the amount given
     * @param lvRaBalance the total amount of ra in the lv
     * @param totalLv the total amount of lv in the pool
     * @param amount the amount of lv user want to withdraw
     */
    function calculateEarlyLvRate(
        uint256 lvRaBalance,
        uint256 totalLv,
        uint256 amount
    ) external pure returns (uint256 received) {
        received = (amount * ((lvRaBalance * 1e18) / totalLv)) / 1e18;
    }

    /**
     * @dev calculate the fee in respect to the amount given
     * @param fee1e8 the fee in 1e8
     * @param amount the amount of lv user want to withdraw
     */
    function calculatePrecentageFee(
        uint256 fee1e8,
        uint256 amount
    ) external pure returns (uint256 precentage) {
        precentage = (((amount * 1e18) * fee1e8) / (100 * 1e18)) / 1e18;
    }

    /**
     * @dev calcualte how much ct + ds user will receive based on the amount of the current exchange rate
     * @param amount  the amount of user  deposit
     * @param exchangeRate the current exchange rate between RA:(CT+DS)
     */
    function calculateDepositAmountWithExchangeRate(
        uint256 amount,
        uint256 exchangeRate
    ) external pure returns (uint256 _amount) {
        _amount = (amount * 1e18) / exchangeRate;
    }

    /**
     * @dev caclulcate how much ra user will receive based on an exchange rate
     * @param amount the amount of ds user want to redeem
     * @param exchangeRate the current exchange rate between RA:(CT+DS)
     */
    function calculateRedeemAmountWithExchangeRate(
        uint256 amount,
        uint256 exchangeRate
    ) external pure returns (uint256 _amount) {
        _amount = (amount * exchangeRate) / 1e18;
    }

    // TODO : unit test this, just move here from psm
    /// @notice calculate the accrued PA & RA
    /// @dev this function follow below equation :
    /// '#' refers to the total circulation supply of that token.
    /// '&' refers to the total amount of token in the PSM.
    ///
    /// amount * (&PA or &RA/#CT)
    function calculateAccrued(
        uint256 amount,
        uint256 available,
        uint256 totalCtIssued
    ) internal pure returns (uint256 accrued) {
        accrued = (amount * ((available * 1e18) / totalCtIssued)) / 1e18;
    }

    function separateLiquidity(
        uint256 totalAmount,
        uint256 totalLvIssued,
        uint256 totalLvWithdrawn
    )
        external
        pure
        returns (
            uint256 attributedWithdrawal,
            uint256 attributedAmm,
            uint256 ratePerLv
        )
    {
        // with 1e18 precision
        ratePerLv = ((totalAmount * 1e18) / totalLvIssued);
        attributedWithdrawal = (ratePerLv * totalLvWithdrawn) / 1e18;
        attributedAmm = totalAmount - attributedWithdrawal;

        assert((attributedWithdrawal + attributedAmm) == totalAmount);
    }
}

File 46 of 59 : Pair.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;

import "./PeggedAssetLib.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";

type Id is bytes32;

/// @dev represent a token pair that does not assumes relationship between the two
/// it may be a pegged asset and a redemption asset, or ct and ds or any other pair
struct Pair {
    // pa/ct
    address pair0;
    // ra/ds
    address pair1;
}

library PairLibrary {
    using PeggedAssetLibrary for PeggedAsset;

    function toId(Pair memory key) internal pure returns (Id id) {
        bytes32 k = keccak256(abi.encode(key));

        assembly {
            id := k
        }
    }

    function toPairname(
        Pair memory key
    ) internal view returns (string memory pairname) {
        (string memory _pa, string memory _ra) = (
            IERC20Metadata(key.pair0).symbol(),
            IERC20Metadata(key.pair1).symbol()
        );

        pairname = string(abi.encodePacked(_pa, "-", _ra));
    }

    function initalize(
        address pa,
        address ra
    ) internal pure returns (Pair memory key) {
        key = Pair({pair0: pa, pair1: ra});
    }

    function peggedAsset(
        Pair memory key
    ) internal pure returns (PeggedAsset memory pa) {
        pa = PeggedAsset({_address: key.pair0});
    }

    function redemptionAsset(
        Pair memory key
    ) internal pure returns (address ra) {
        ra = key.pair1;
    }

    function isInitialized(
        Pair memory key
    ) internal pure returns (bool status) {
        status = key.pair0 != address(0) && key.pair1 != address(0);
    }
}

File 47 of 59 : PeggedAssetLib.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

struct PeggedAsset {
    address _address;
}

library PeggedAssetLibrary {
    using PeggedAssetLibrary for PeggedAsset;

    function asErc20(PeggedAsset memory self) internal pure returns (IERC20) {
        return IERC20(self._address);
    }

    function redeemUnchecked(PeggedAsset memory self, address from, uint256 amount) internal {
        self.asErc20().transferFrom(from, address(this), amount);
    }
}

File 48 of 59 : PsmLib.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;

import "./../Asset.sol";
import "./Pair.sol";
import "./DepegSwapLib.sol";
import "./RedemptionAssetManagerLib.sol";
import "./SignatureHelperLib.sol";
import "./PeggedAssetLib.sol";
import "./State.sol";
import "./Guard.sol";
import "./MathHelper.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";

// TODO : support native token
// TODO : make an entrypoint that does not depend on permit
// TODO : make every redeem have receiver address
library PsmLibrary {
    using MinimalSignatureHelper for Signature;
    using PairLibrary for Pair;
    using DepegSwapLibrary for DepegSwap;
    using RedemptionAssetManagerLibrary for PsmRedemptionAssetManager;
    using PeggedAssetLibrary for PeggedAsset;

    function isInitialized(
        State storage self
    ) internal view returns (bool status) {
        status = self.info.isInitialized();
    }

    function initialize(State storage self, Pair memory key) internal {
        self.info = key;
        self.psmBalances.ra = RedemptionAssetManagerLibrary.initialize(
            key.redemptionAsset()
        );
    }

    /// @notice issue a new pair of DS, will fail if the previous DS isn't yet expired
    function issueNewPair(
        State storage self,
        address ct,
        address ds,
        uint256 idx,
        uint256 prevIdx
    ) internal {
        if (prevIdx != 0) {
            DepegSwap storage _prevDs = self.ds[prevIdx];
            Guard.safeAfterExpired(_prevDs);
        }

        self.ds[idx] = DepegSwapLibrary.initialize(ds, ct);
    }

    /// @notice deposit RA to the PSM
    /// @dev the user must approve the PSM to spend their RA
    function deposit(
        State storage self,
        address depositor,
        uint256 amount
    ) internal returns (uint256 dsId) {
        dsId = self.globalAssetIdx;

        DepegSwap storage ds = self.ds[dsId];

        Guard.safeBeforeExpired(ds);

        uint256 normalizedRateAmount = MathHelper
            .calculateDepositAmountWithExchangeRate(amount, ds.exchangeRate());

        self.psmBalances.ra.lockFrom(amount, depositor);

        ds.issue(depositor, normalizedRateAmount);
    }

    // This is here just for semantics, since in the whitepaper, all the CT DS issuance
    // happens in the PSM, although they essentially lives in the same contract, we leave it here just for consistency sake
    function lvIssue(State storage self, uint256 amount) internal {
        uint256 dsId = self.globalAssetIdx;

        DepegSwap storage ds = self.ds[dsId];

        ds.issue(address(this), amount);
    }

    function lvRedeemRaWithCtDs(
        State storage self,
        uint256 amount,
        uint256 dsId
    ) internal {
        DepegSwap storage ds = self.ds[dsId];

        ds.burnBothforSelf(amount);
    }

    function lvRedeemRaPaWithCt(
        State storage self,
        uint256 amount
    ) internal returns (uint256 pa) {
        // just for semantics for now.
    }

    /// @notice preview deposit
    /// @dev since we mint 1:1, we return the same amount,
    /// since rate only effective when redeeming with CT
    // TODO: test this
    function previewDeposit(
        State storage self,
        uint256 amount
    )
        internal
        view
        returns (uint256 ctReceived, uint256 dsReceived, uint256 dsId)
    {
        dsId = self.globalAssetIdx;
        DepegSwap storage ds = self.ds[dsId];

        Guard.safeBeforeExpired(ds);
        uint256 normalizedRateAmount = MathHelper
            .calculateDepositAmountWithExchangeRate(amount, ds.exchangeRate());

        ctReceived = normalizedRateAmount;
        dsReceived = normalizedRateAmount;
    }

    function previewRedeemRaWithCtDs(
        State storage self,
        uint256 amount
    ) internal view returns (uint256 ra, uint256 dsId, uint256 rates) {
        dsId = self.globalAssetIdx;
        DepegSwap storage ds = self.ds[dsId];
        Guard.safeBeforeExpired(ds);

        rates = ds.exchangeRate();
        ra = MathHelper.calculateRedeemAmountWithExchangeRate(amount, rates);
    }

    function redeemRaWithCtDs(
        State storage self,
        address owner,
        uint256 amount
    ) internal returns (uint256 ra, uint256 dsId, uint256 rates) {
        dsId = self.globalAssetIdx;
        DepegSwap storage ds = self.ds[dsId];
        Guard.safeBeforeExpired(ds);

        rates = ds.exchangeRate();

        ra = MathHelper.calculateRedeemAmountWithExchangeRate(amount, rates);

        self.psmBalances.ra.unlockTo(owner, ra);

        ERC20Burnable(ds.ct).burnFrom(owner, amount);
        ERC20Burnable(ds.ds).burnFrom(owner, amount);
    }

    function _redeemDs(
        Balances storage self,
        DepegSwap storage ds,
        uint256 amount
    ) internal {
        self.dsBalance += amount;
        self.paBalance += amount;
        ds.dsRedeemed += amount;
    }

    function _afterRedeemWithDs(
        State storage self,
        DepegSwap storage ds,
        bytes memory rawDsPermitSig,
        address owner,
        uint256 amount,
        uint256 deadline
    ) internal {
        DepegSwapLibrary.permit(
            ds.ds,
            rawDsPermitSig,
            owner,
            address(this),
            amount,
            deadline
        );

        IERC20(ds.ds).transferFrom(owner, address(this), amount);
        self.info.peggedAsset().asErc20().transferFrom(
            owner,
            address(this),
            amount
        );

        uint256 normalizedRateAmount = MathHelper
            .calculateRedeemAmountWithExchangeRate(amount, ds.exchangeRate());

        self.psmBalances.ra.unlockTo(owner, normalizedRateAmount);
    }

    function valueLocked(State storage self) internal view returns (uint256) {
        return self.psmBalances.ra.locked;
    }

    function exchangeRate(
        State storage self
    ) internal view returns (uint256 rates) {
        uint256 dsId = self.globalAssetIdx;
        DepegSwap storage ds = self.ds[dsId];
        rates = ds.exchangeRate();
    }

    /// @notice redeem an RA with DS + PA
    /// @dev since we currently have no way of knowing if the PA contract implements permit,
    /// we depends on the frontend to make approval to the PA contract before calling this function.
    /// for the DS, we use the permit function to approve the transfer. the parameter passed here MUST be the same
    /// as the one used to generate the ds permit signature
    function redeemWithDs(
        State storage self,
        address owner,
        uint256 amount,
        uint256 dsId,
        bytes memory rawDsPermitSig,
        uint256 deadline
    ) internal {
        DepegSwap storage ds = self.ds[dsId];
        Guard.safeBeforeExpired(ds);
        _redeemDs(self.psmBalances, ds, amount);
        _afterRedeemWithDs(self, ds, rawDsPermitSig, owner, amount, deadline);
    }

    /// @notice simulate a ds redeem.
    /// @return assets how much RA the user would receive
    /// @dev since the rate is constant at 1:1, we return the same amount,
    // TODO: test this
    function previewRedeemWithDs(
        State storage self,
        uint256 dsId,
        uint256 amount
    ) internal view returns (uint256 assets) {
        DepegSwap storage ds = self.ds[dsId];
        Guard.safeBeforeExpired(ds);

        uint256 normalizedRateAmount = MathHelper
            .calculateRedeemAmountWithExchangeRate(amount, ds.exchangeRate());

        assets = normalizedRateAmount;
    }

    /// @notice return the number of redeemed RA for a particular DS
    /// @param dsId the id of the DS
    /// @return amount the number of redeemed RA
    function redeemed(
        State storage self,
        uint256 dsId
    ) external view returns (uint256 amount) {
        amount = self.ds[dsId].dsRedeemed;
    }

    /// @notice return the next depeg swap expiry
    function nextExpiry(
        State storage self
    ) internal view returns (uint256 expiry) {
        uint256 idx = self.globalAssetIdx;

        DepegSwap storage ds = self.ds[idx];

        expiry = Asset(ds.ds).expiry();
    }

    function _calcRedeemAmount(
        State storage self,
        uint256 amount,
        uint256 totalCtIssued,
        uint256 availableRa
    ) internal view returns (uint256 accruedPa, uint256 accruedRa) {
        uint256 availablePa = self.psmBalances.paBalance;
        accruedPa = MathHelper.calculateAccrued(
            amount,
            availablePa,
            totalCtIssued
        );

        accruedRa = MathHelper.calculateAccrued(
            amount,
            availableRa,
            totalCtIssued
        );
    }

    function _beforeCtRedeem(
        Balances storage self,
        DepegSwap storage ds,
        uint256 amount,
        uint256 accruedPa,
        uint256 accruedRa
    ) internal {
        ds.ctRedeemed += amount;
        self.ctBalance += amount;
        self.paBalance -= accruedPa;
        self.ra.decFree(accruedRa);
    }

    function _afterCtRedeem(
        State storage self,
        DepegSwap storage ds,
        address owner,
        uint256 ctRedeemedAmount,
        uint256 accruedPa,
        uint256 accruedRa,
        bytes memory rawCtPermitSig,
        uint256 deadline
    ) internal {
        DepegSwapLibrary.permit(
            ds.ct,
            rawCtPermitSig,
            owner,
            address(this),
            ctRedeemedAmount,
            deadline
        );

        IERC20(ds.ct).transferFrom(owner, address(this), ctRedeemedAmount);
        self.info.peggedAsset().asErc20().transfer(owner, accruedPa);
        IERC20(self.info.redemptionAsset()).transfer(owner, accruedRa);
    }

    /// @notice redeem accrued RA + PA with CT on expiry
    /// @dev since we currently have no way of knowing if the PA contract implements permit,
    /// we depends on the frontend to make approval to the PA contract before calling this function.
    /// for the CT, we use the permit function to approve the transfer.
    /// the parameter passed here MUST be the same as the one used to generate the ct permit signature.
    function redeemWithCt(
        State storage self,
        address owner,
        uint256 amount,
        uint256 dsId,
        bytes memory rawCtPermitSig,
        uint256 deadline
    ) internal returns (uint256 accruedPa, uint256 accruedRa) {
        DepegSwap storage ds = self.ds[dsId];
        Guard.safeAfterExpired(ds);

        uint256 totalCtIssued = IERC20(ds.ct).totalSupply();
        uint256 availableRa = self.psmBalances.ra.convertAllToFree();

        (accruedPa, accruedRa) = _calcRedeemAmount(
            self,
            amount,
            totalCtIssued,
            availableRa
        );

        _beforeCtRedeem(self.psmBalances, ds, amount, accruedPa, accruedRa);
        _afterCtRedeem(
            self,
            ds,
            owner,
            amount,
            accruedPa,
            accruedRa,
            rawCtPermitSig,
            deadline
        );
    }

    /// @notice simulate a ct redeem. will fail if not expired.
    /// @return accruedPa the amount of PA the user would receive
    /// @return accruedRa the amount of RA the user would receive
    function previewRedeemWithCt(
        State storage self,
        uint256 dsId,
        uint256 amount
    ) internal view returns (uint256 accruedPa, uint256 accruedRa) {
        DepegSwap storage ds = self.ds[dsId];
        Guard.safeAfterExpired(ds);

        uint256 totalCtIssued = IERC20(ds.ct).totalSupply();

        uint256 availableRa = self.psmBalances.ra.tryConvertAllToFree();

        (accruedPa, accruedRa) = _calcRedeemAmount(
            self,
            amount,
            totalCtIssued,
            availableRa
        );
    }
}

File 49 of 59 : RedemptionAssetManagerLib.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

import "./../Asset.sol";
import "./SignatureHelperLib.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Permit.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "./../WrappedAsset.sol";
import "./DepegSwapLib.sol";

struct PsmRedemptionAssetManager {
    address _address;
    uint256 locked;
    uint256 free;
}

library RedemptionAssetManagerLibrary {
    using MinimalSignatureHelper for Signature;

    function initialize(
        address ra
    ) internal pure returns (PsmRedemptionAssetManager memory) {
        return PsmRedemptionAssetManager(ra, 0, 0);
    }

    function incLocked(
        PsmRedemptionAssetManager storage self,
        uint256 amount
    ) internal {
        self.locked = self.locked + amount;
    }

    function incFree(
        PsmRedemptionAssetManager storage self,
        uint256 amount
    ) internal {
        self.free = self.free + amount;
    }

    function decFree(
        PsmRedemptionAssetManager storage self,
        uint256 amount
    ) internal {
        self.free = self.free - amount;
    }

    function convertAllToFree(
        PsmRedemptionAssetManager storage self
    ) internal returns (uint256) {
        if (self.locked == 0) {
            return self.free;
        }

        self.free = self.free + self.locked;
        self.locked = 0;

        return self.free;
    }

    function tryConvertAllToFree(
        PsmRedemptionAssetManager storage self
    ) internal view returns (uint256) {
        if (self.locked == 0) {
            return self.free;
        }

        return self.free + self.locked;
    }

    function decLocked(
        PsmRedemptionAssetManager storage self,
        uint256 amount
    ) internal {
        self.locked = self.locked - amount;
    }

    function circulatingSupply(
        PsmRedemptionAssetManager memory self
    ) internal view returns (uint256) {
        return IERC20(self._address).totalSupply() - self.locked;
    }

    function lockFrom(
        PsmRedemptionAssetManager storage self,
        uint256 amount,
        address from
    ) internal {
        incLocked(self, amount);
        lockUnchecked(self, amount, from);
    }

    function lockUnchecked(
        PsmRedemptionAssetManager storage self,
        uint256 amount,
        address from
    ) internal {
        IERC20(self._address).transferFrom(from, address(this), amount);
    }

    function unlockTo(
        PsmRedemptionAssetManager storage self,
        address to,
        uint256 amount
    ) internal {
        decLocked(self, amount);
        unlockToUnchecked(self, amount, to);
    }

    function unlockToUnchecked(
        PsmRedemptionAssetManager storage self,
        uint256 amount,
        address to
    ) internal {
        IERC20(self._address).transfer(to, amount);
    }
}

File 50 of 59 : SignatureHelperLib.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;

struct Signature {
    uint8 v;
    bytes32 r;
    bytes32 s;
}

library MinimalSignatureHelper {
    error InvalidSignatureLength(uint256 length);

    function split(
        bytes memory raw
    ) internal pure returns (Signature memory sig) {
        if (raw.length != 65) {
            revert InvalidSignatureLength(raw.length);
        }

        (uint8 v, bytes32 r, bytes32 s) = splitUnchecked(raw);

        sig = Signature({v: v, r: r, s: s});
    }

    function splitUnchecked(
        bytes memory sig
    ) private pure returns (uint8 v, bytes32 r, bytes32 s) {
        assembly {
            r := mload(add(sig, 32))
            s := mload(add(sig, 64))
            v := byte(0, mload(add(sig, 96)))
        }
    }
}

File 51 of 59 : State.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;

import "./Pair.sol";
import "./RedemptionAssetManagerLib.sol";
import "./VaultConfig.sol";
import "./LvAssetLib.sol";
import "@openzeppelin/contracts/utils/structs/BitMaps.sol";

// TODO : should refactor this into distinct structs for psm and lv states, especially the balances
// as there are some fields that are used in PSM but not in LV
struct State {
    /// @dev used to track current ds and ct for both lv and psm
    uint256 globalAssetIdx;
    Pair info;
    mapping(uint256 => DepegSwap) ds;
    Balances psmBalances;
    VaultState vault;
}

// TODO : to PSM balance
struct Balances {
    PsmRedemptionAssetManager ra;
    uint256 dsBalance;
    uint256 ctBalance;
    uint256 paBalance;
}

struct VaultPool {
    VaultWithdrawalPool withdrawalPool;
    VaultAmmLiquidityPool ammLiquidityPool;
    /// @dev user => (dsId => amount)
    mapping(address => uint256) withdrawEligible;
}
struct VaultWithdrawalPool {
    uint256 atrributedLv;
    uint256 raExchangeRate;
    uint256 paExchangeRate;
    uint256 raBalance;
    uint256 paBalance;
    // FIXME : this is only temporary, for now
    // we trate PA the same as RA, thus we also separate PA
    // the difference is the PA here isn't being used as anything
    // and for now will just sit there until rationed again at next expiry.
    uint256 stagnatedPaBalance;
}
struct VaultAmmLiquidityPool {
    uint256 balance;
}

struct VaultState {
    Balances balances;
    VaultConfig config;
    LvAsset lv;
    BitMaps.BitMap lpLiquidated;
    VaultPool pool;
}

File 52 of 59 : VaultConfig.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

// TODO : remove all threshold

struct VaultConfig {
    // 1 % = 1e18
    uint256 fee;
    //
    uint256 lpRaBalance;
    uint256 ammRaDepositThreshold;
    //
    uint256 ammCtDepositThreshold;
    uint256 lpCtBalance;

    uint256 accmulatedFee;
}

library VaultConfigLibrary {
    function initialize(
        uint256 fee,
        uint256 ammWaDepositThreshold,
        uint256 ammCtDepositThreshold
    ) internal pure returns (VaultConfig memory) {
        return
            VaultConfig({
                fee: fee,
                ammRaDepositThreshold: ammWaDepositThreshold,
                lpRaBalance: 0,
                lpCtBalance: 0,
                ammCtDepositThreshold: ammCtDepositThreshold,
                accmulatedFee: 0
            });
    }

    function mustProvideLiquidity(
        VaultConfig memory self
    ) internal pure returns (bool) {
        return
            (self.lpRaBalance > self.ammRaDepositThreshold) &&
            (self.lpCtBalance > self.ammCtDepositThreshold);
    }

    function updateFee(VaultConfig memory self, uint256 fee) internal pure {
        self.fee = fee;
    }

    function updateAmmDepositThreshold(
        VaultConfig memory self,
        uint256 ammDepositThreshold
    ) internal pure {
        self.ammRaDepositThreshold = ammDepositThreshold;
    }

}

File 53 of 59 : VaultLib.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

import "./VaultConfig.sol";
import "./Pair.sol";
import "./LvAssetLib.sol";
import "./PsmLib.sol";
import "./RedemptionAssetManagerLib.sol";
import "./MathHelper.sol";
import "./Guard.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
import "@openzeppelin/contracts/utils/structs/BitMaps.sol";
import "./VaultPoolLib.sol";

import "hardhat/console.sol";

library VaultLibrary {
    using VaultConfigLibrary for VaultConfig;
    using PairLibrary for Pair;
    using LvAssetLibrary for LvAsset;
    using VaultLibrary for VaultState;
    using PsmLibrary for State;
    using RedemptionAssetManagerLibrary for WrappedAsset;
    using RedemptionAssetManagerLibrary for PsmRedemptionAssetManager;
    using BitMaps for BitMaps.BitMap;
    using VaultLibrary for VaultState;
    using DepegSwapLibrary for DepegSwap;
    using VaultPoolLibrary for VaultPool;

    /// @notice caller is not authorized to perform the action, e.g transfering
    /// redemption rights to another address while not having the rights
    error Unauthorized(address caller);

    /// @notice inssuficient balance to perform expiry redeem(e.g requesting 5 LV to redeem but trying to redeem 10)
    error InsufficientBalance(
        address caller,
        uint256 requested,
        uint256 balance
    );

    function initialize(
        VaultState storage self,
        address lv,
        uint256 fee,
        uint256 ammWaDepositThreshold,
        uint256 ammCtDepositThreshold,
        address ra
    ) internal {
        self.config = VaultConfigLibrary.initialize(
            fee,
            ammWaDepositThreshold,
            ammCtDepositThreshold
        );

        self.lv = LvAssetLibrary.initialize(lv);
        self.balances.ra = RedemptionAssetManagerLibrary.initialize(ra);
    }

    function provideAmmLiquidityFromPool(State storage self) internal {
        uint256 ratio = MathHelper.calculatePriceRatio(
            self.vault.getSqrtPriceX96(),
            MathHelper.DEFAULT_DECIMAL
        );

        (uint256 ra, uint256 ct) = self.vault.pool.rationedToAmm(ratio);

        self.vault.config.lpRaBalance += ra;
        self.vault.config.lpCtBalance += ct;

        self.vault.pool.resetAmmPool();
    }

    function _limitOrderDs(uint256 amount) internal {
        // TODO : placeholder
    }

    function getSqrtPriceX96(
        VaultState storage self
    ) internal view returns (uint160) {
        // TODO : placeholder
        // 1 for now, so that every 1 ra there must be 1 ct
        return 79228162514264337593543950336;
    }

    // MUST be called on every new DS issuance
    function onNewIssuanceAndExpiry(State storage self, uint256 dsId) internal {
        // do nothing at first issuance
        if (dsId == 0) {
            return;
        }

        if (!self.vault.lpLiquidated.get(dsId)) {
            _liquidatedLp(self, dsId);
        }

        provideAmmLiquidityFromPool(self);
    }

    function safeBeforeExpired(State storage self) internal view {
        uint256 dsId = self.globalAssetIdx;
        DepegSwap storage ds = self.ds[dsId];

        Guard.safeBeforeExpired(ds);
    }

    function safeAfterExpired(State storage self) internal view {
        uint256 dsId = self.globalAssetIdx;
        DepegSwap storage ds = self.ds[dsId];
        Guard.safeAfterExpired(ds);
    }

    function deposit(
        State storage self,
        address from,
        uint256 amount
    ) internal {
        safeBeforeExpired(self);
        self.vault.balances.ra.lockUnchecked(amount, from);

        uint256 ratio = MathHelper.calculatePriceRatio(
            self.vault.getSqrtPriceX96(),
            MathHelper.DEFAULT_DECIMAL
        );

        (uint256 ra, uint256 ct) = MathHelper.calculateAmounts(amount, ratio);
        self.vault.config.lpRaBalance += ra;
        self.vault.config.lpCtBalance += ct;

        PsmLibrary.lvIssue(self, ct);

        _limitOrderDs(amount);
        self.vault.lv.issue(from, amount);
    }

    // preview a deposit action with current exchange rate,
    // returns the amount of shares(share pool token) that user will receive
    function previewDeposit(
        uint256 amount
    ) internal pure returns (uint256 lvReceived) {
        lvReceived = amount;
    }

    function requestRedemption(
        State storage self,
        address owner,
        uint256 amount
    ) internal {
        safeBeforeExpired(self);
        self.vault.pool.withdrawEligible[owner] += amount;
        self.vault.pool.withdrawalPool.atrributedLv += amount;
        self.vault.lv.lockFrom(amount, owner);
    }

    function lvLockedFor(
        State storage self,
        address owner
    ) internal view returns (uint256) {
        return self.vault.pool.withdrawEligible[owner];
    }

    function cancelRedemptionRequest(
        State storage self,
        address owner,
        uint256 amount
    ) internal {
        safeBeforeExpired(self);
        uint256 userEligible = self.vault.pool.withdrawEligible[owner];

        if (userEligible == 0) {
            revert Unauthorized(msg.sender);
        }

        if (userEligible < amount) {
            revert InsufficientBalance(owner, amount, userEligible);
        }

        self.vault.pool.withdrawEligible[owner] -= amount;
        self.vault.pool.withdrawalPool.atrributedLv -= amount;
        self.vault.lv.unlockTo(amount, owner);
    }

    function transferRedemptionRights(
        State storage self,
        address from,
        address to,
        uint256 amount
    ) internal {
        uint256 initialOwneramount = self.vault.pool.withdrawEligible[from];

        if (initialOwneramount == 0) {
            revert Unauthorized(msg.sender);
        }

        if (initialOwneramount < amount) {
            revert InsufficientBalance(from, amount, initialOwneramount);
        }

        self.vault.pool.withdrawEligible[to] += amount;
        self.vault.pool.withdrawEligible[from] -= amount;
    }

    function _liquidatedLp(State storage self, uint256 dsId) internal {
        // TODO : placeholder
        // the following things should happen here(taken directly from the whitepaper) :
        // 1. The AMM LP is redeemed to receive CT + RA
        // 2. Any excess DS in the LV is paired with CT to redeem RA
        // 3. The excess CT is used to claim RA + PA in the PSM
        // 4. End state: Only RA + redeemed PA remains

        self.vault.lpLiquidated.set(dsId);
        // IMPORTANT : for now, we only unlock the wa to ourself
        // since we don't have the AMM LP yet
        // since the ds isn't sold right now so it's safe to do this
        // but that means we won't receive any pegged asset from the PSM yet
        // since the number of CT and DS in LV will always be the same
        // due to not having an actual AMM.
        uint256 ammCtBalance = self.vault.config.lpCtBalance;
        uint256 totalRa = self.vault.config.lpRaBalance + ammCtBalance;
        PsmLibrary.lvRedeemRaWithCtDs(self, ammCtBalance, dsId);

        // static values for PA for now.
        uint256 ctAttributedToPa = 0;
        uint256 pa = PsmLibrary.lvRedeemRaPaWithCt(self, ctAttributedToPa);

        self.vault.pool.reserve(self.vault.lv.totalIssued(), totalRa, pa);

        self.vault.config.lpRaBalance = 0;
        self.vault.config.lpCtBalance = 0;
    }

    function reservedForWithdrawal(
        State storage self
    ) internal view returns (uint256 ra, uint256 pa) {
        ra = self.vault.pool.withdrawalPool.raBalance;
        pa = self.vault.pool.withdrawalPool.paBalance;
    }

    // FIXME : maybe remove this when the off-chain aggregator is finalized
    function _tryLiquidateLp(
        State storage self
    )
        internal
        view
        returns (
            VaultWithdrawalPool memory withdrawalPool,
            VaultAmmLiquidityPool memory ammLiquidityPool
        )
    {
        // due to not having an actual AMM.
        uint256 ammCtBalance = self.vault.config.lpCtBalance;
        uint256 totalRa = self.vault.config.lpRaBalance + ammCtBalance;

        withdrawalPool = self.vault.pool.withdrawalPool;
        ammLiquidityPool = self.vault.pool.ammLiquidityPool;

        // static values for PA for now.
        uint256 ctAttributedToPa = 0;
        VaultPoolLibrary.tryReserve(
            withdrawalPool,
            ammLiquidityPool,
            self.vault.lv.totalIssued(),
            totalRa,
            ctAttributedToPa
        );
    }

    function redeemExpired(
        State storage self,
        address owner,
        address receiver,
        uint256 amount
    ) internal returns (uint256 attributedRa, uint256 attributedPa) {
        uint256 dsId = self.globalAssetIdx;
        DepegSwap storage ds = self.ds[dsId];

        uint256 userEligible = self.vault.pool.withdrawEligible[owner];

        if (userEligible == 0 && !ds.isExpired()) {
            revert Unauthorized(owner);
        }

        // user can only redeem up to the amount they requested, when there's a DS active
        // if there's no DS active, then there's no cap on the amount of LV that can be redeemed
        if (!ds.isExpired() && userEligible < amount) {
            revert InsufficientBalance(owner, amount, userEligible);
        }

        if (ds.isExpired() && !self.vault.lpLiquidated.get(dsId)) {
            _liquidatedLp(self, dsId);
            assert(self.vault.balances.ra.locked == 0);
        }

        ERC20Burnable lv = ERC20Burnable(self.vault.lv._address);

        uint256 burnUserAmount;
        uint256 burnSelfAmount;
        (attributedRa, attributedPa, burnUserAmount, burnSelfAmount) = self
            .vault
            .pool
            .redeem(amount, owner);

        //ra
        IERC20(self.info.pair1).transfer(receiver, attributedRa);
        //pa
        IERC20(self.info.pair0).transfer(receiver, attributedPa);

        assert(burnSelfAmount + burnUserAmount == amount);

        self.vault.lv.burnSelf(burnSelfAmount);

        if (burnUserAmount != 0) {
            lv.burnFrom(owner, burnUserAmount);
        }
    }

    function previewRedeemExpired(
        State storage self,
        uint256 amount,
        address owner
    )
        internal
        view
        returns (
            uint256 attributedRa,
            uint256 attributedPa,
            uint256 approvedAmount
        )
    {
        uint256 dsId = self.globalAssetIdx;
        DepegSwap storage ds = self.ds[dsId];

        uint256 userEligible = self.vault.pool.withdrawEligible[owner];

        if (userEligible == 0 && !ds.isExpired()) {
            revert Unauthorized(owner);
        }

        // user can only redeem up to the amount they requested, when there's a DS active
        // if there's no DS active, then there's no cap on the amount of LV that can be redeemed
        if (!ds.isExpired() && userEligible < amount) {
            revert InsufficientBalance(owner, amount, userEligible);
        }

        VaultWithdrawalPool memory withdrawalPool = self
            .vault
            .pool
            .withdrawalPool;

        VaultAmmLiquidityPool memory ammLiquidityPool = self
            .vault
            .pool
            .ammLiquidityPool;

        if (ds.isExpired() && !self.vault.lpLiquidated.get(dsId)) {
            (withdrawalPool, ammLiquidityPool) = _tryLiquidateLp(self);
            assert(self.vault.balances.ra.locked == 0);
        }

        (attributedRa, attributedPa, approvedAmount) = VaultPoolLibrary
            .tryRedeem(
                self.vault.pool.withdrawEligible,
                withdrawalPool,
                ammLiquidityPool,
                amount,
                owner
            );
    }

    // taken directly from spec document, technically below is what should happen in this function
    //
    // '#' refers to the total circulation supply of that token.
    // '&' refers to the total amount of token in the LV.
    //
    // say our percent fee is 3%
    // fee(amount)
    //
    // say the amount of user LV token is 'N'
    //
    // AMM LP liquidation (#LP/#LV) provide more CT($CT) + WA($WA) :
    // &CT = &CT + $CT
    // &WA = &WA + $WA
    //
    // Create WA pairing CT with DS inside the vault :
    // &WA = &WA + &(CT + DS)
    //
    // Excess and unpaired CT is sold to AMM to provide WA($WA) :
    // &WA = $WA
    //
    // the LV token rate is :
    // eLV = &WA/#LV
    //
    // redemption amount(rA) :
    // rA = N x eLV
    //
    // final amount(Fa) :
    // Fa = rA - fee(rA)
    function redeemEarly(
        State storage self,
        address owner,
        address receiver,
        uint256 amount
    ) internal returns (uint256 received, uint256 fee, uint256 feePrecentage) {
        safeBeforeExpired(self);
        uint256 dsId = self.globalAssetIdx;

        feePrecentage = self.vault.config.fee;

        // again, it's safe to do this because there's the same amount of CT + DS in the LV so we treat CT the same as RA
        uint256 totalRa = self.vault.config.lpRaBalance +
            self.vault.config.lpCtBalance;

        console.log("totalRa", totalRa);

        received = MathHelper.calculateEarlyLvRate(
            totalRa,
            IERC20(self.vault.lv._address).totalSupply(),
            amount
        );

        uint256 ratio = MathHelper.calculatePriceRatio(
            self.vault.getSqrtPriceX96(),
            MathHelper.DEFAULT_DECIMAL
        );

        // calculate substracted LP liquidity in respect to the price ratio
        // this is done to minimize price impact
        (uint256 ra, uint256 ct) = MathHelper.calculateAmounts(received, ratio);

        // TODO : change this into pool function
        self.vault.config.lpRaBalance -= ra;
        self.vault.config.lpCtBalance -= ct;

        fee = MathHelper.calculatePrecentageFee(
            received,
            self.vault.config.fee
        );
        self.vault.config.accmulatedFee += fee;
        received = received - fee;

        // IMPORTANT: ideally, the source of the WA that's used to fulfill
        // early redemption should be calculated in a way that respect the
        // current price ratio of the asset in the AMM and then an algorithm should
        // decide how much LP WA is used, how much CT is paired with existing DS in the LV
        // to turned into WA for user redemption, it should look like this :
        //
        // if the price ratio is 2:1, then for every 2 WA, there should be 1 CT
        // assuming the DS is not sold yet, then it should use ~66% of WA and ~33% of CT to be paired with DS
        // for user withdrawal
        //
        // but for now, as we don't currently have a good general grip on AMM mechanics,
        // we calculate the rate in as if all the CT can be readyily paired with DS and turned into WA, but we
        // but we source everything from the LP WA which will most likely has a worse side effect on price than the ideal one.
        // you could say we currently use the "dumb" algorithm for now.
        //

        ERC20Burnable(self.vault.lv._address).burnFrom(owner, amount);
        self.vault.balances.ra.unlockToUnchecked(received, receiver);
    }

    function previewRedeemEarly(
        State storage self,
        uint256 amount
    )
        internal
        view
        returns (uint256 received, uint256 fee, uint256 feePrecentage)
    {
        safeBeforeExpired(self);

        feePrecentage = self.vault.config.fee;

        uint256 totalRa = self.vault.config.lpRaBalance +
            self.vault.config.lpCtBalance;

        received = MathHelper.calculateEarlyLvRate(
            totalRa,
            IERC20(self.vault.lv._address).totalSupply(),
            amount
        );

        fee = MathHelper.calculatePrecentageFee(
            received,
            self.vault.config.fee
        );

        received = received - fee;
    }

    function sellExcessCt(State storage self) internal {
        // TODO : placeholder
    }

    function createWaPairings(State storage self) internal {
        // TODO : placeholder
    }
}

File 54 of 59 : VaultPoolLib.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;
import "./State.sol";
import "./MathHelper.sol";

library VaultPoolLibrary {
    function reserve(
        VaultPool storage self,
        uint256 totalLvIssued,
        uint256 addedRa,
        uint256 addedPa
    ) internal {
        uint256 totalLvWithdrawn = self.withdrawalPool.atrributedLv;
        self.withdrawalPool.atrributedLv = totalLvWithdrawn;

        // RA
        uint256 totalRa = self.withdrawalPool.raBalance + addedRa;
        (
            uint256 attributedToWithdraw,
            uint256 attributedToAmm,
            uint256 ratePerLv
        ) = MathHelper.separateLiquidity(
                totalRa,
                totalLvIssued,
                totalLvWithdrawn
            );

        self.withdrawalPool.raBalance = attributedToWithdraw;
        self.ammLiquidityPool.balance = attributedToAmm;
        self.withdrawalPool.raExchangeRate = ratePerLv;

        // PA
        uint256 totalPa = self.withdrawalPool.paBalance + addedPa;
        (attributedToWithdraw, attributedToAmm, ratePerLv) = MathHelper
            .separateLiquidity(totalPa, totalLvIssued, totalLvWithdrawn);

        self.withdrawalPool.paBalance = attributedToWithdraw;
        self.withdrawalPool.stagnatedPaBalance = attributedToWithdraw;
        self.withdrawalPool.paExchangeRate = ratePerLv;

        assert(
            totalRa ==
                self.withdrawalPool.raBalance + self.ammLiquidityPool.balance
        );
    }

    function tryReserve(
        VaultWithdrawalPool memory withdrawalPool,
        VaultAmmLiquidityPool memory ammLiquidityPool,
        uint256 totalLvIssued,
        uint256 addedRa,
        uint256 addedPa
    ) internal pure {
        uint256 totalLvWithdrawn = withdrawalPool.atrributedLv;
        withdrawalPool.atrributedLv = totalLvWithdrawn;

        // RA
        uint256 totalRa = withdrawalPool.raBalance + addedRa;
        (
            uint256 attributedToWithdraw,
            uint256 attributedToAmm,
            uint256 ratePerLv
        ) = MathHelper.separateLiquidity(
                totalRa,
                totalLvIssued,
                totalLvWithdrawn
            );

        withdrawalPool.raBalance = attributedToWithdraw;
        ammLiquidityPool.balance = attributedToAmm;
        withdrawalPool.raExchangeRate = ratePerLv;

        // PA
        uint256 totalPa = withdrawalPool.paBalance + addedPa;
        (attributedToWithdraw, attributedToAmm, ratePerLv) = MathHelper
            .separateLiquidity(totalPa, totalLvIssued, totalLvWithdrawn);

        withdrawalPool.paBalance = attributedToWithdraw;
        withdrawalPool.stagnatedPaBalance = attributedToWithdraw;
        withdrawalPool.paExchangeRate = ratePerLv;

        assert(totalRa == withdrawalPool.raBalance + ammLiquidityPool.balance);
    }

    function __decreaseUserAttributed(
        VaultPool storage self,
        uint256 amount,
        address owner
    ) internal {
        self.withdrawEligible[owner] -= amount;
    }

    function redeem(
        VaultPool storage self,
        uint256 amount,
        address owner
    )
        internal
        returns (uint256 ra, uint256 pa, uint256 excess, uint256 attributed)
    {
        uint256 userEligible = self.withdrawEligible[owner];

        if (userEligible >= amount) {
            attributed = amount;

            (ra, pa) = __redeemfromWithdrawalPool(self, amount);
            __decreaseUserAttributed(self, amount, owner);
        } else {
            attributed = userEligible;
            excess = amount - userEligible;

            assert(excess + attributed == amount);

            (ra, pa) = __redeemExcessFromAmmPool(self, userEligible, excess);
            __decreaseUserAttributed(self, userEligible, owner);
        }
    }

    function tryRedeem(
        mapping(address => uint256) storage withdrawEligible,
        VaultWithdrawalPool memory withdrawalPool,
        VaultAmmLiquidityPool memory ammLiquidityPool,
        uint256 amount,
        address owner
    ) internal view returns (uint256 ra, uint256 pa, uint256 excess) {
        uint256 userEligible = withdrawEligible[owner];

        if (userEligible >= amount) {
            ra = MathHelper.calculateRedeemAmountWithExchangeRate(
                amount,
                withdrawalPool.raExchangeRate
            );

            pa = MathHelper.calculateRedeemAmountWithExchangeRate(
                amount,
                withdrawalPool.paExchangeRate
            );
        } else {
            uint256 attributed = userEligible;
            excess = amount - userEligible;

            assert(excess + attributed == amount);

            ra = MathHelper.calculateRedeemAmountWithExchangeRate(
                attributed,
                withdrawalPool.raExchangeRate
            );

            pa = MathHelper.calculateRedeemAmountWithExchangeRate(
                attributed,
                withdrawalPool.paExchangeRate
            );

            uint256 withdrawnFromAmm = MathHelper
                .calculateRedeemAmountWithExchangeRate(
                    excess,
                    withdrawalPool.raExchangeRate
                );

            ra += withdrawnFromAmm;

            ammLiquidityPool.balance -= withdrawnFromAmm;
        }
    }

    function __redeemfromWithdrawalPool(
        VaultPool storage self,
        uint256 amount
    ) internal returns (uint256 ra, uint256 pa) {
        self.withdrawalPool.atrributedLv -= amount;
        (ra, pa) = __tryRedeemfromWithdrawalPool(self, amount);

        self.withdrawalPool.raBalance -= ra;
        self.withdrawalPool.paBalance -= pa;
    }

    function __tryRedeemfromWithdrawalPool(
        VaultPool storage self,
        uint256 amount
    ) internal view returns (uint256 ra, uint256 pa) {
        ra = MathHelper.calculateRedeemAmountWithExchangeRate(
            amount,
            self.withdrawalPool.raExchangeRate
        );

        pa = MathHelper.calculateRedeemAmountWithExchangeRate(
            amount,
            self.withdrawalPool.paExchangeRate
        );
    }

    function __tryRedeemExcessFromAmmPool(
        VaultPool storage self,
        uint256 amountAttributed,
        uint256 excessAmount
    ) internal view returns (uint256 ra, uint256 pa, uint256 withdrawnFromAmm) {
        (ra, pa) = __tryRedeemfromWithdrawalPool(self, amountAttributed);

        withdrawnFromAmm = MathHelper.calculateRedeemAmountWithExchangeRate(
            excessAmount,
            self.withdrawalPool.raExchangeRate
        );

        ra += withdrawnFromAmm;
    }

    function __redeemExcessFromAmmPool(
        VaultPool storage self,
        uint256 amountAttributed,
        uint256 excessAmount
    ) internal returns (uint256 ra, uint256 pa) {
        uint256 withdrawnFromAmm;
        (ra, pa, withdrawnFromAmm) = __tryRedeemExcessFromAmmPool(
            self,
            amountAttributed,
            excessAmount
        );

        self.ammLiquidityPool.balance -= withdrawnFromAmm;
    }

    function rationedToAmm(
        VaultPool storage self,
        uint256 ratio
    ) internal view returns (uint256 ra, uint256 ct) {
        uint256 amount = self.ammLiquidityPool.balance;

        (ra, ct) = MathHelper.calculateAmounts(amount, ratio);
    }

    function resetAmmPool(VaultPool storage self) internal {
        self.ammLiquidityPool.balance = 0;
    }
}

File 55 of 59 : ModuleState.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

import "./libraries/Pair.sol";
import "./libraries/State.sol";
import "./interfaces/IAssetFactory.sol";
import "./interfaces/ICommon.sol";
import "./libraries/PsmLib.sol";

abstract contract ModuleState is ICommon {
    using PsmLibrary for State;

    mapping(Id => State) internal states;
    address _factory;

    function factory() external view returns (address) {
        return _factory;
    }

    constructor(address factoryAddress) {
        _factory = factoryAddress;
    }

    function getFactory() internal view returns (IAssetFactory) {
        return IAssetFactory(_factory);
    }

    modifier onlyInitialized(Id id) {
        if (!states[id].isInitialized()) {
            revert Uinitialized();
        }
        _;
    }

    function _onlyValidAsset(address asset) internal view {
        if (getFactory().isDeployed(asset) == false) {
            revert InvalidAsset(asset);
        }
    }
}

File 56 of 59 : Psm.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
import "./libraries/PsmLib.sol";
import "./libraries/Pair.sol";
import "./interfaces/IPSMcore.sol";
import "./libraries/State.sol";
import "./ModuleState.sol";
import "./interfaces/IRates.sol";
import "@openzeppelin/contracts/utils/Context.sol";

abstract contract PsmCore is IPSMcore, ModuleState, Context {
    using PsmLibrary for State;
    using PairLibrary for Pair;

    function depositPsm(
        Id id,
        uint256 amount
    ) external override onlyInitialized(id) {
        State storage state = states[id];
        uint256 dsId = state.deposit(_msgSender(), amount);
        emit PsmDeposited(id, dsId, _msgSender(), amount);
    }

    function previewDepositPsm(
        Id id,
        uint256 amount
    )
        external
        view
        override
        onlyInitialized(id)
        returns (uint256 ctReceived, uint256 dsReceived, uint256 dsId)
    {
        State storage state = states[id];
        (ctReceived, dsReceived, dsId) = state.previewDeposit(amount);
    }

    function redeemRaWithDs(
        Id id,
        uint256 dsId,
        uint256 amount,
        bytes memory rawDsPermitSig,
        uint256 deadline
    ) external override onlyInitialized(id) {
        State storage state = states[id];

        emit DsRedeemed(id, dsId, _msgSender(), amount);

        state.redeemWithDs(
            _msgSender(),
            amount,
            dsId,
            rawDsPermitSig,
            deadline
        );
    }

    function exchangeRate(
        Id id
    ) external view override returns (uint256 rates) {
        State storage state = states[id];
        rates = state.exchangeRate();
    }

    function previewRedeemRaWithDs(
        Id id,
        uint256 dsId,
        uint256 amount
    ) external view override onlyInitialized(id) returns (uint256 assets) {
        State storage state = states[id];
        assets = state.previewRedeemWithDs(amount, dsId);
    }

    function redeemWithCT(
        Id id,
        uint256 dsId,
        uint256 amount,
        bytes memory rawCtPermitSig,
        uint256 deadline
    ) external override onlyInitialized(id) {
        State storage state = states[id];

        (uint256 accruedPa, uint256 accruedRa) = state.redeemWithCt(
            _msgSender(),
            amount,
            dsId,
            rawCtPermitSig,
            deadline
        );

        emit CtRedeemed(id, dsId, _msgSender(), amount, accruedPa, accruedRa);
    }

    function previewRedeemWithCt(
        Id id,
        uint256 dsId,
        uint256 amount
    )
        external
        view
        override
        onlyInitialized(id)
        returns (uint256 paReceived, uint256 raReceived)
    {
        State storage state = states[id];
        (paReceived, raReceived) = state.previewRedeemWithCt(dsId, amount);
    }

    function valueLocked(Id id) external view override returns (uint256) {
        State storage state = states[id];
        return state.valueLocked();
    }

    function redeemRaWithCtDs(Id id, uint256 amount) external override {
        State storage state = states[id];
        (uint256 ra, uint256 dsId, uint256 rates) = state.redeemRaWithCtDs(
            _msgSender(),
            amount
        );

        emit Cancelled(id, dsId, _msgSender(), ra, amount, rates);
    }

    function previewRedeemRaWithCtDs(
        Id id,
        uint256 amount
    ) external view override returns (uint256 ra, uint256 rates) {
        State storage state = states[id];
        (ra, , rates) = state.previewRedeemRaWithCtDs(amount);
    }
}

File 57 of 59 : Vault.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
import "./libraries/VaultLib.sol";
import "./libraries/Pair.sol";
import "./libraries/State.sol";
import "./ModuleState.sol";
import "@openzeppelin/contracts/utils/Context.sol";
import "./interfaces/IVault.sol";

abstract contract VaultCore is ModuleState, Context, IVault {
    using PairLibrary for Pair;
    using VaultLibrary for State;

    function reservedUserWithdrawal(
        Id id
    ) external view override returns (uint256 reservedRa, uint256 reservedPa) {
        State storage state = states[id];
        (reservedRa, reservedPa) = state.reservedForWithdrawal();
    }

    function depositLv(Id id, uint256 amount) external override {
        State storage state = states[id];
        state.deposit(_msgSender(), amount);
        emit LvDeposited(id, _msgSender(), amount);
    }

    function lockedLvfor(
        Id id,
        address user
    ) external view returns (uint256 locked) {
        State storage state = states[id];
        locked = state.lvLockedFor(user);
    }

    function previewLvDeposit(
        uint256 amount
    ) external pure override returns (uint256 lv) {
        lv = VaultLibrary.previewDeposit(amount);
    }

    function requestRedemption(Id id, uint256 amount) external override {
        State storage state = states[id];
        state.requestRedemption(_msgSender(), amount);
        emit RedemptionRequested(id, _msgSender(), amount);
    }

    function transferRedemptionRights(
        Id id,
        address to,
        uint256 amount
    ) external override {
        State storage state = states[id];
        state.transferRedemptionRights(_msgSender(), to, amount);
        emit RedemptionRightTransferred(id, _msgSender(), to, amount);
    }

    function redeemExpiredLv(
        Id id,
        address receiver,
        uint256 amount
    ) external override {
        State storage state = states[id];
        (uint256 attributedRa, uint256 attributedPa) = state.redeemExpired(
            _msgSender(),
            receiver,
            amount
        );
        emit LvRedeemExpired(id, receiver, attributedRa, attributedPa);
    }

    function previewRedeemExpiredLv(
        Id id,
        uint256 amount
    )
        external
        view
        override
        returns (
            uint256 attributedRa,
            uint256 attributedPa,
            uint256 approvedAmount
        )
    {
        State storage state = states[id];
        (attributedRa, attributedPa, approvedAmount) = state
            .previewRedeemExpired(amount, _msgSender());
    }

    function redeemEarlyLv(
        Id id,
        address receiver,
        uint256 amount
    ) external override {
        State storage state = states[id];
        (uint256 received, uint256 fee, uint256 feePrecentage) = state
            .redeemEarly(_msgSender(), receiver, amount);

        emit LvRedeemEarly(
            id,
            _msgSender(),
            receiver,
            received,
            fee,
            feePrecentage
        );
    }

    function previewRedeemEarlyLv(
        Id id,
        uint256 amount
    )
        external
        view
        override
        returns (uint256 received, uint256 fee, uint256 feePrecentage)
    {
        State storage state = states[id];
        (received, fee, feePrecentage) = state.previewRedeemEarly(amount);
    }
}

File 58 of 59 : WrappedAsset.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Wrapper.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract WrappedAsset is ERC20Permit, ERC20Wrapper {
    event Wrapped(address indexed owner, uint256 amount);

    event UnWrapped(address indexed owner, uint256 amount);

    string private PREFIX = "WA-";

    constructor(
        address _underlying
    )
        ERC20(
            string(
                abi.encodePacked(PREFIX, IERC20Metadata(_underlying).name())
            ),
            string(
                abi.encodePacked(PREFIX, IERC20Metadata(_underlying).symbol())
            )
        )
        ERC20Wrapper(IERC20(_underlying))
        ERC20Permit(
            string(abi.encodePacked(PREFIX, IERC20Metadata(_underlying).name()))
        )
    {}

    function decimals()
        public
        view
        virtual
        override(ERC20, ERC20Wrapper)
        returns (uint8)
    {
        return ERC20Wrapper.decimals();
    }

    function wrap(uint256 amount) external {
        depositFor(msg.sender, amount);
        emit Wrapped(msg.sender, amount);
    }

    function unwrap(uint256 amount) external {
        withdrawTo(msg.sender, amount);
        emit UnWrapped(msg.sender, amount);
    }

    function unwrapTo(address to, uint256 amount) external {
        withdrawTo(to, amount);
        emit UnWrapped(msg.sender, amount);
    }
}

File 59 of 59 : console.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;

library console {
    address constant CONSOLE_ADDRESS =
        0x000000000000000000636F6e736F6c652e6c6f67;

    function _sendLogPayloadImplementation(bytes memory payload) internal view {
        address consoleAddress = CONSOLE_ADDRESS;
        /// @solidity memory-safe-assembly
        assembly {
            pop(
                staticcall(
                    gas(),
                    consoleAddress,
                    add(payload, 32),
                    mload(payload),
                    0,
                    0
                )
            )
        }
    }

    function _castToPure(
      function(bytes memory) internal view fnIn
    ) internal pure returns (function(bytes memory) pure fnOut) {
        assembly {
            fnOut := fnIn
        }
    }

    function _sendLogPayload(bytes memory payload) internal pure {
        _castToPure(_sendLogPayloadImplementation)(payload);
    }

    function log() internal pure {
        _sendLogPayload(abi.encodeWithSignature("log()"));
    }
    function logInt(int256 p0) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(int256)", p0));
    }

    function logUint(uint256 p0) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256)", p0));
    }

    function logString(string memory p0) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string)", p0));
    }

    function logBool(bool p0) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool)", p0));
    }

    function logAddress(address p0) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address)", p0));
    }

    function logBytes(bytes memory p0) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bytes)", p0));
    }

    function logBytes1(bytes1 p0) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bytes1)", p0));
    }

    function logBytes2(bytes2 p0) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bytes2)", p0));
    }

    function logBytes3(bytes3 p0) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bytes3)", p0));
    }

    function logBytes4(bytes4 p0) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bytes4)", p0));
    }

    function logBytes5(bytes5 p0) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bytes5)", p0));
    }

    function logBytes6(bytes6 p0) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bytes6)", p0));
    }

    function logBytes7(bytes7 p0) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bytes7)", p0));
    }

    function logBytes8(bytes8 p0) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bytes8)", p0));
    }

    function logBytes9(bytes9 p0) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bytes9)", p0));
    }

    function logBytes10(bytes10 p0) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bytes10)", p0));
    }

    function logBytes11(bytes11 p0) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bytes11)", p0));
    }

    function logBytes12(bytes12 p0) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bytes12)", p0));
    }

    function logBytes13(bytes13 p0) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bytes13)", p0));
    }

    function logBytes14(bytes14 p0) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bytes14)", p0));
    }

    function logBytes15(bytes15 p0) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bytes15)", p0));
    }

    function logBytes16(bytes16 p0) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bytes16)", p0));
    }

    function logBytes17(bytes17 p0) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bytes17)", p0));
    }

    function logBytes18(bytes18 p0) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bytes18)", p0));
    }

    function logBytes19(bytes19 p0) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bytes19)", p0));
    }

    function logBytes20(bytes20 p0) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bytes20)", p0));
    }

    function logBytes21(bytes21 p0) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bytes21)", p0));
    }

    function logBytes22(bytes22 p0) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bytes22)", p0));
    }

    function logBytes23(bytes23 p0) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bytes23)", p0));
    }

    function logBytes24(bytes24 p0) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bytes24)", p0));
    }

    function logBytes25(bytes25 p0) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bytes25)", p0));
    }

    function logBytes26(bytes26 p0) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bytes26)", p0));
    }

    function logBytes27(bytes27 p0) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bytes27)", p0));
    }

    function logBytes28(bytes28 p0) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bytes28)", p0));
    }

    function logBytes29(bytes29 p0) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bytes29)", p0));
    }

    function logBytes30(bytes30 p0) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bytes30)", p0));
    }

    function logBytes31(bytes31 p0) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bytes31)", p0));
    }

    function logBytes32(bytes32 p0) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bytes32)", p0));
    }

    function log(uint256 p0) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256)", p0));
    }

    function log(string memory p0) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string)", p0));
    }

    function log(bool p0) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool)", p0));
    }

    function log(address p0) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address)", p0));
    }

    function log(uint256 p0, uint256 p1) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,uint256)", p0, p1));
    }

    function log(uint256 p0, string memory p1) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,string)", p0, p1));
    }

    function log(uint256 p0, bool p1) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,bool)", p0, p1));
    }

    function log(uint256 p0, address p1) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,address)", p0, p1));
    }

    function log(string memory p0, uint256 p1) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,uint256)", p0, p1));
    }

    function log(string memory p0, string memory p1) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,string)", p0, p1));
    }

    function log(string memory p0, bool p1) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,bool)", p0, p1));
    }

    function log(string memory p0, address p1) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,address)", p0, p1));
    }

    function log(bool p0, uint256 p1) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,uint256)", p0, p1));
    }

    function log(bool p0, string memory p1) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,string)", p0, p1));
    }

    function log(bool p0, bool p1) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,bool)", p0, p1));
    }

    function log(bool p0, address p1) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,address)", p0, p1));
    }

    function log(address p0, uint256 p1) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,uint256)", p0, p1));
    }

    function log(address p0, string memory p1) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,string)", p0, p1));
    }

    function log(address p0, bool p1) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,bool)", p0, p1));
    }

    function log(address p0, address p1) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,address)", p0, p1));
    }

    function log(uint256 p0, uint256 p1, uint256 p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,uint256)", p0, p1, p2));
    }

    function log(uint256 p0, uint256 p1, string memory p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,string)", p0, p1, p2));
    }

    function log(uint256 p0, uint256 p1, bool p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,bool)", p0, p1, p2));
    }

    function log(uint256 p0, uint256 p1, address p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,address)", p0, p1, p2));
    }

    function log(uint256 p0, string memory p1, uint256 p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,string,uint256)", p0, p1, p2));
    }

    function log(uint256 p0, string memory p1, string memory p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,string,string)", p0, p1, p2));
    }

    function log(uint256 p0, string memory p1, bool p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,string,bool)", p0, p1, p2));
    }

    function log(uint256 p0, string memory p1, address p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,string,address)", p0, p1, p2));
    }

    function log(uint256 p0, bool p1, uint256 p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,bool,uint256)", p0, p1, p2));
    }

    function log(uint256 p0, bool p1, string memory p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,bool,string)", p0, p1, p2));
    }

    function log(uint256 p0, bool p1, bool p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,bool,bool)", p0, p1, p2));
    }

    function log(uint256 p0, bool p1, address p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,bool,address)", p0, p1, p2));
    }

    function log(uint256 p0, address p1, uint256 p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,address,uint256)", p0, p1, p2));
    }

    function log(uint256 p0, address p1, string memory p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,address,string)", p0, p1, p2));
    }

    function log(uint256 p0, address p1, bool p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,address,bool)", p0, p1, p2));
    }

    function log(uint256 p0, address p1, address p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,address,address)", p0, p1, p2));
    }

    function log(string memory p0, uint256 p1, uint256 p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,uint256,uint256)", p0, p1, p2));
    }

    function log(string memory p0, uint256 p1, string memory p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,uint256,string)", p0, p1, p2));
    }

    function log(string memory p0, uint256 p1, bool p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,uint256,bool)", p0, p1, p2));
    }

    function log(string memory p0, uint256 p1, address p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,uint256,address)", p0, p1, p2));
    }

    function log(string memory p0, string memory p1, uint256 p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,string,uint256)", p0, p1, p2));
    }

    function log(string memory p0, string memory p1, string memory p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,string,string)", p0, p1, p2));
    }

    function log(string memory p0, string memory p1, bool p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,string,bool)", p0, p1, p2));
    }

    function log(string memory p0, string memory p1, address p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,string,address)", p0, p1, p2));
    }

    function log(string memory p0, bool p1, uint256 p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,bool,uint256)", p0, p1, p2));
    }

    function log(string memory p0, bool p1, string memory p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,bool,string)", p0, p1, p2));
    }

    function log(string memory p0, bool p1, bool p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,bool,bool)", p0, p1, p2));
    }

    function log(string memory p0, bool p1, address p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,bool,address)", p0, p1, p2));
    }

    function log(string memory p0, address p1, uint256 p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,address,uint256)", p0, p1, p2));
    }

    function log(string memory p0, address p1, string memory p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,address,string)", p0, p1, p2));
    }

    function log(string memory p0, address p1, bool p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,address,bool)", p0, p1, p2));
    }

    function log(string memory p0, address p1, address p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,address,address)", p0, p1, p2));
    }

    function log(bool p0, uint256 p1, uint256 p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,uint256,uint256)", p0, p1, p2));
    }

    function log(bool p0, uint256 p1, string memory p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,uint256,string)", p0, p1, p2));
    }

    function log(bool p0, uint256 p1, bool p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,uint256,bool)", p0, p1, p2));
    }

    function log(bool p0, uint256 p1, address p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,uint256,address)", p0, p1, p2));
    }

    function log(bool p0, string memory p1, uint256 p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,string,uint256)", p0, p1, p2));
    }

    function log(bool p0, string memory p1, string memory p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,string,string)", p0, p1, p2));
    }

    function log(bool p0, string memory p1, bool p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,string,bool)", p0, p1, p2));
    }

    function log(bool p0, string memory p1, address p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,string,address)", p0, p1, p2));
    }

    function log(bool p0, bool p1, uint256 p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint256)", p0, p1, p2));
    }

    function log(bool p0, bool p1, string memory p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,bool,string)", p0, p1, p2));
    }

    function log(bool p0, bool p1, bool p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool)", p0, p1, p2));
    }

    function log(bool p0, bool p1, address p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,bool,address)", p0, p1, p2));
    }

    function log(bool p0, address p1, uint256 p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,address,uint256)", p0, p1, p2));
    }

    function log(bool p0, address p1, string memory p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,address,string)", p0, p1, p2));
    }

    function log(bool p0, address p1, bool p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,address,bool)", p0, p1, p2));
    }

    function log(bool p0, address p1, address p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,address,address)", p0, p1, p2));
    }

    function log(address p0, uint256 p1, uint256 p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,uint256,uint256)", p0, p1, p2));
    }

    function log(address p0, uint256 p1, string memory p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,uint256,string)", p0, p1, p2));
    }

    function log(address p0, uint256 p1, bool p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,uint256,bool)", p0, p1, p2));
    }

    function log(address p0, uint256 p1, address p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,uint256,address)", p0, p1, p2));
    }

    function log(address p0, string memory p1, uint256 p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,string,uint256)", p0, p1, p2));
    }

    function log(address p0, string memory p1, string memory p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,string,string)", p0, p1, p2));
    }

    function log(address p0, string memory p1, bool p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,string,bool)", p0, p1, p2));
    }

    function log(address p0, string memory p1, address p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,string,address)", p0, p1, p2));
    }

    function log(address p0, bool p1, uint256 p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,bool,uint256)", p0, p1, p2));
    }

    function log(address p0, bool p1, string memory p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,bool,string)", p0, p1, p2));
    }

    function log(address p0, bool p1, bool p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,bool,bool)", p0, p1, p2));
    }

    function log(address p0, bool p1, address p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,bool,address)", p0, p1, p2));
    }

    function log(address p0, address p1, uint256 p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,address,uint256)", p0, p1, p2));
    }

    function log(address p0, address p1, string memory p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,address,string)", p0, p1, p2));
    }

    function log(address p0, address p1, bool p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,address,bool)", p0, p1, p2));
    }

    function log(address p0, address p1, address p2) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,address,address)", p0, p1, p2));
    }

    function log(uint256 p0, uint256 p1, uint256 p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,uint256,uint256)", p0, p1, p2, p3));
    }

    function log(uint256 p0, uint256 p1, uint256 p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,uint256,string)", p0, p1, p2, p3));
    }

    function log(uint256 p0, uint256 p1, uint256 p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,uint256,bool)", p0, p1, p2, p3));
    }

    function log(uint256 p0, uint256 p1, uint256 p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,uint256,address)", p0, p1, p2, p3));
    }

    function log(uint256 p0, uint256 p1, string memory p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,string,uint256)", p0, p1, p2, p3));
    }

    function log(uint256 p0, uint256 p1, string memory p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,string,string)", p0, p1, p2, p3));
    }

    function log(uint256 p0, uint256 p1, string memory p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,string,bool)", p0, p1, p2, p3));
    }

    function log(uint256 p0, uint256 p1, string memory p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,string,address)", p0, p1, p2, p3));
    }

    function log(uint256 p0, uint256 p1, bool p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,bool,uint256)", p0, p1, p2, p3));
    }

    function log(uint256 p0, uint256 p1, bool p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,bool,string)", p0, p1, p2, p3));
    }

    function log(uint256 p0, uint256 p1, bool p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,bool,bool)", p0, p1, p2, p3));
    }

    function log(uint256 p0, uint256 p1, bool p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,bool,address)", p0, p1, p2, p3));
    }

    function log(uint256 p0, uint256 p1, address p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,address,uint256)", p0, p1, p2, p3));
    }

    function log(uint256 p0, uint256 p1, address p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,address,string)", p0, p1, p2, p3));
    }

    function log(uint256 p0, uint256 p1, address p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,address,bool)", p0, p1, p2, p3));
    }

    function log(uint256 p0, uint256 p1, address p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,address,address)", p0, p1, p2, p3));
    }

    function log(uint256 p0, string memory p1, uint256 p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,string,uint256,uint256)", p0, p1, p2, p3));
    }

    function log(uint256 p0, string memory p1, uint256 p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,string,uint256,string)", p0, p1, p2, p3));
    }

    function log(uint256 p0, string memory p1, uint256 p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,string,uint256,bool)", p0, p1, p2, p3));
    }

    function log(uint256 p0, string memory p1, uint256 p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,string,uint256,address)", p0, p1, p2, p3));
    }

    function log(uint256 p0, string memory p1, string memory p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,string,string,uint256)", p0, p1, p2, p3));
    }

    function log(uint256 p0, string memory p1, string memory p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,string,string,string)", p0, p1, p2, p3));
    }

    function log(uint256 p0, string memory p1, string memory p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,string,string,bool)", p0, p1, p2, p3));
    }

    function log(uint256 p0, string memory p1, string memory p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,string,string,address)", p0, p1, p2, p3));
    }

    function log(uint256 p0, string memory p1, bool p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,string,bool,uint256)", p0, p1, p2, p3));
    }

    function log(uint256 p0, string memory p1, bool p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,string,bool,string)", p0, p1, p2, p3));
    }

    function log(uint256 p0, string memory p1, bool p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,string,bool,bool)", p0, p1, p2, p3));
    }

    function log(uint256 p0, string memory p1, bool p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,string,bool,address)", p0, p1, p2, p3));
    }

    function log(uint256 p0, string memory p1, address p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,string,address,uint256)", p0, p1, p2, p3));
    }

    function log(uint256 p0, string memory p1, address p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,string,address,string)", p0, p1, p2, p3));
    }

    function log(uint256 p0, string memory p1, address p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,string,address,bool)", p0, p1, p2, p3));
    }

    function log(uint256 p0, string memory p1, address p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,string,address,address)", p0, p1, p2, p3));
    }

    function log(uint256 p0, bool p1, uint256 p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,bool,uint256,uint256)", p0, p1, p2, p3));
    }

    function log(uint256 p0, bool p1, uint256 p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,bool,uint256,string)", p0, p1, p2, p3));
    }

    function log(uint256 p0, bool p1, uint256 p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,bool,uint256,bool)", p0, p1, p2, p3));
    }

    function log(uint256 p0, bool p1, uint256 p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,bool,uint256,address)", p0, p1, p2, p3));
    }

    function log(uint256 p0, bool p1, string memory p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,bool,string,uint256)", p0, p1, p2, p3));
    }

    function log(uint256 p0, bool p1, string memory p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,bool,string,string)", p0, p1, p2, p3));
    }

    function log(uint256 p0, bool p1, string memory p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,bool,string,bool)", p0, p1, p2, p3));
    }

    function log(uint256 p0, bool p1, string memory p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,bool,string,address)", p0, p1, p2, p3));
    }

    function log(uint256 p0, bool p1, bool p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,bool,bool,uint256)", p0, p1, p2, p3));
    }

    function log(uint256 p0, bool p1, bool p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,bool,bool,string)", p0, p1, p2, p3));
    }

    function log(uint256 p0, bool p1, bool p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,bool,bool,bool)", p0, p1, p2, p3));
    }

    function log(uint256 p0, bool p1, bool p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,bool,bool,address)", p0, p1, p2, p3));
    }

    function log(uint256 p0, bool p1, address p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,bool,address,uint256)", p0, p1, p2, p3));
    }

    function log(uint256 p0, bool p1, address p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,bool,address,string)", p0, p1, p2, p3));
    }

    function log(uint256 p0, bool p1, address p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,bool,address,bool)", p0, p1, p2, p3));
    }

    function log(uint256 p0, bool p1, address p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,bool,address,address)", p0, p1, p2, p3));
    }

    function log(uint256 p0, address p1, uint256 p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,address,uint256,uint256)", p0, p1, p2, p3));
    }

    function log(uint256 p0, address p1, uint256 p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,address,uint256,string)", p0, p1, p2, p3));
    }

    function log(uint256 p0, address p1, uint256 p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,address,uint256,bool)", p0, p1, p2, p3));
    }

    function log(uint256 p0, address p1, uint256 p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,address,uint256,address)", p0, p1, p2, p3));
    }

    function log(uint256 p0, address p1, string memory p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,address,string,uint256)", p0, p1, p2, p3));
    }

    function log(uint256 p0, address p1, string memory p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,address,string,string)", p0, p1, p2, p3));
    }

    function log(uint256 p0, address p1, string memory p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,address,string,bool)", p0, p1, p2, p3));
    }

    function log(uint256 p0, address p1, string memory p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,address,string,address)", p0, p1, p2, p3));
    }

    function log(uint256 p0, address p1, bool p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,address,bool,uint256)", p0, p1, p2, p3));
    }

    function log(uint256 p0, address p1, bool p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,address,bool,string)", p0, p1, p2, p3));
    }

    function log(uint256 p0, address p1, bool p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,address,bool,bool)", p0, p1, p2, p3));
    }

    function log(uint256 p0, address p1, bool p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,address,bool,address)", p0, p1, p2, p3));
    }

    function log(uint256 p0, address p1, address p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,address,address,uint256)", p0, p1, p2, p3));
    }

    function log(uint256 p0, address p1, address p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,address,address,string)", p0, p1, p2, p3));
    }

    function log(uint256 p0, address p1, address p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,address,address,bool)", p0, p1, p2, p3));
    }

    function log(uint256 p0, address p1, address p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(uint256,address,address,address)", p0, p1, p2, p3));
    }

    function log(string memory p0, uint256 p1, uint256 p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,uint256,uint256,uint256)", p0, p1, p2, p3));
    }

    function log(string memory p0, uint256 p1, uint256 p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,uint256,uint256,string)", p0, p1, p2, p3));
    }

    function log(string memory p0, uint256 p1, uint256 p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,uint256,uint256,bool)", p0, p1, p2, p3));
    }

    function log(string memory p0, uint256 p1, uint256 p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,uint256,uint256,address)", p0, p1, p2, p3));
    }

    function log(string memory p0, uint256 p1, string memory p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,uint256,string,uint256)", p0, p1, p2, p3));
    }

    function log(string memory p0, uint256 p1, string memory p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,uint256,string,string)", p0, p1, p2, p3));
    }

    function log(string memory p0, uint256 p1, string memory p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,uint256,string,bool)", p0, p1, p2, p3));
    }

    function log(string memory p0, uint256 p1, string memory p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,uint256,string,address)", p0, p1, p2, p3));
    }

    function log(string memory p0, uint256 p1, bool p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,uint256,bool,uint256)", p0, p1, p2, p3));
    }

    function log(string memory p0, uint256 p1, bool p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,uint256,bool,string)", p0, p1, p2, p3));
    }

    function log(string memory p0, uint256 p1, bool p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,uint256,bool,bool)", p0, p1, p2, p3));
    }

    function log(string memory p0, uint256 p1, bool p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,uint256,bool,address)", p0, p1, p2, p3));
    }

    function log(string memory p0, uint256 p1, address p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,uint256,address,uint256)", p0, p1, p2, p3));
    }

    function log(string memory p0, uint256 p1, address p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,uint256,address,string)", p0, p1, p2, p3));
    }

    function log(string memory p0, uint256 p1, address p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,uint256,address,bool)", p0, p1, p2, p3));
    }

    function log(string memory p0, uint256 p1, address p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,uint256,address,address)", p0, p1, p2, p3));
    }

    function log(string memory p0, string memory p1, uint256 p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,string,uint256,uint256)", p0, p1, p2, p3));
    }

    function log(string memory p0, string memory p1, uint256 p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,string,uint256,string)", p0, p1, p2, p3));
    }

    function log(string memory p0, string memory p1, uint256 p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,string,uint256,bool)", p0, p1, p2, p3));
    }

    function log(string memory p0, string memory p1, uint256 p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,string,uint256,address)", p0, p1, p2, p3));
    }

    function log(string memory p0, string memory p1, string memory p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,string,string,uint256)", p0, p1, p2, p3));
    }

    function log(string memory p0, string memory p1, string memory p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,string,string,string)", p0, p1, p2, p3));
    }

    function log(string memory p0, string memory p1, string memory p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,string,string,bool)", p0, p1, p2, p3));
    }

    function log(string memory p0, string memory p1, string memory p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,string,string,address)", p0, p1, p2, p3));
    }

    function log(string memory p0, string memory p1, bool p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,string,bool,uint256)", p0, p1, p2, p3));
    }

    function log(string memory p0, string memory p1, bool p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,string,bool,string)", p0, p1, p2, p3));
    }

    function log(string memory p0, string memory p1, bool p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,string,bool,bool)", p0, p1, p2, p3));
    }

    function log(string memory p0, string memory p1, bool p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,string,bool,address)", p0, p1, p2, p3));
    }

    function log(string memory p0, string memory p1, address p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,string,address,uint256)", p0, p1, p2, p3));
    }

    function log(string memory p0, string memory p1, address p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,string,address,string)", p0, p1, p2, p3));
    }

    function log(string memory p0, string memory p1, address p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,string,address,bool)", p0, p1, p2, p3));
    }

    function log(string memory p0, string memory p1, address p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,string,address,address)", p0, p1, p2, p3));
    }

    function log(string memory p0, bool p1, uint256 p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,bool,uint256,uint256)", p0, p1, p2, p3));
    }

    function log(string memory p0, bool p1, uint256 p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,bool,uint256,string)", p0, p1, p2, p3));
    }

    function log(string memory p0, bool p1, uint256 p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,bool,uint256,bool)", p0, p1, p2, p3));
    }

    function log(string memory p0, bool p1, uint256 p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,bool,uint256,address)", p0, p1, p2, p3));
    }

    function log(string memory p0, bool p1, string memory p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,bool,string,uint256)", p0, p1, p2, p3));
    }

    function log(string memory p0, bool p1, string memory p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,bool,string,string)", p0, p1, p2, p3));
    }

    function log(string memory p0, bool p1, string memory p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,bool,string,bool)", p0, p1, p2, p3));
    }

    function log(string memory p0, bool p1, string memory p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,bool,string,address)", p0, p1, p2, p3));
    }

    function log(string memory p0, bool p1, bool p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,uint256)", p0, p1, p2, p3));
    }

    function log(string memory p0, bool p1, bool p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,string)", p0, p1, p2, p3));
    }

    function log(string memory p0, bool p1, bool p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,bool)", p0, p1, p2, p3));
    }

    function log(string memory p0, bool p1, bool p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,address)", p0, p1, p2, p3));
    }

    function log(string memory p0, bool p1, address p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,bool,address,uint256)", p0, p1, p2, p3));
    }

    function log(string memory p0, bool p1, address p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,bool,address,string)", p0, p1, p2, p3));
    }

    function log(string memory p0, bool p1, address p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,bool,address,bool)", p0, p1, p2, p3));
    }

    function log(string memory p0, bool p1, address p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,bool,address,address)", p0, p1, p2, p3));
    }

    function log(string memory p0, address p1, uint256 p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,address,uint256,uint256)", p0, p1, p2, p3));
    }

    function log(string memory p0, address p1, uint256 p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,address,uint256,string)", p0, p1, p2, p3));
    }

    function log(string memory p0, address p1, uint256 p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,address,uint256,bool)", p0, p1, p2, p3));
    }

    function log(string memory p0, address p1, uint256 p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,address,uint256,address)", p0, p1, p2, p3));
    }

    function log(string memory p0, address p1, string memory p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,address,string,uint256)", p0, p1, p2, p3));
    }

    function log(string memory p0, address p1, string memory p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,address,string,string)", p0, p1, p2, p3));
    }

    function log(string memory p0, address p1, string memory p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,address,string,bool)", p0, p1, p2, p3));
    }

    function log(string memory p0, address p1, string memory p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,address,string,address)", p0, p1, p2, p3));
    }

    function log(string memory p0, address p1, bool p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,address,bool,uint256)", p0, p1, p2, p3));
    }

    function log(string memory p0, address p1, bool p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,address,bool,string)", p0, p1, p2, p3));
    }

    function log(string memory p0, address p1, bool p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,address,bool,bool)", p0, p1, p2, p3));
    }

    function log(string memory p0, address p1, bool p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,address,bool,address)", p0, p1, p2, p3));
    }

    function log(string memory p0, address p1, address p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,address,address,uint256)", p0, p1, p2, p3));
    }

    function log(string memory p0, address p1, address p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,address,address,string)", p0, p1, p2, p3));
    }

    function log(string memory p0, address p1, address p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,address,address,bool)", p0, p1, p2, p3));
    }

    function log(string memory p0, address p1, address p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(string,address,address,address)", p0, p1, p2, p3));
    }

    function log(bool p0, uint256 p1, uint256 p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,uint256,uint256,uint256)", p0, p1, p2, p3));
    }

    function log(bool p0, uint256 p1, uint256 p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,uint256,uint256,string)", p0, p1, p2, p3));
    }

    function log(bool p0, uint256 p1, uint256 p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,uint256,uint256,bool)", p0, p1, p2, p3));
    }

    function log(bool p0, uint256 p1, uint256 p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,uint256,uint256,address)", p0, p1, p2, p3));
    }

    function log(bool p0, uint256 p1, string memory p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,uint256,string,uint256)", p0, p1, p2, p3));
    }

    function log(bool p0, uint256 p1, string memory p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,uint256,string,string)", p0, p1, p2, p3));
    }

    function log(bool p0, uint256 p1, string memory p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,uint256,string,bool)", p0, p1, p2, p3));
    }

    function log(bool p0, uint256 p1, string memory p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,uint256,string,address)", p0, p1, p2, p3));
    }

    function log(bool p0, uint256 p1, bool p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,uint256,bool,uint256)", p0, p1, p2, p3));
    }

    function log(bool p0, uint256 p1, bool p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,uint256,bool,string)", p0, p1, p2, p3));
    }

    function log(bool p0, uint256 p1, bool p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,uint256,bool,bool)", p0, p1, p2, p3));
    }

    function log(bool p0, uint256 p1, bool p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,uint256,bool,address)", p0, p1, p2, p3));
    }

    function log(bool p0, uint256 p1, address p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,uint256,address,uint256)", p0, p1, p2, p3));
    }

    function log(bool p0, uint256 p1, address p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,uint256,address,string)", p0, p1, p2, p3));
    }

    function log(bool p0, uint256 p1, address p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,uint256,address,bool)", p0, p1, p2, p3));
    }

    function log(bool p0, uint256 p1, address p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,uint256,address,address)", p0, p1, p2, p3));
    }

    function log(bool p0, string memory p1, uint256 p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,string,uint256,uint256)", p0, p1, p2, p3));
    }

    function log(bool p0, string memory p1, uint256 p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,string,uint256,string)", p0, p1, p2, p3));
    }

    function log(bool p0, string memory p1, uint256 p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,string,uint256,bool)", p0, p1, p2, p3));
    }

    function log(bool p0, string memory p1, uint256 p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,string,uint256,address)", p0, p1, p2, p3));
    }

    function log(bool p0, string memory p1, string memory p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,string,string,uint256)", p0, p1, p2, p3));
    }

    function log(bool p0, string memory p1, string memory p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,string,string,string)", p0, p1, p2, p3));
    }

    function log(bool p0, string memory p1, string memory p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,string,string,bool)", p0, p1, p2, p3));
    }

    function log(bool p0, string memory p1, string memory p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,string,string,address)", p0, p1, p2, p3));
    }

    function log(bool p0, string memory p1, bool p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,uint256)", p0, p1, p2, p3));
    }

    function log(bool p0, string memory p1, bool p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,string)", p0, p1, p2, p3));
    }

    function log(bool p0, string memory p1, bool p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,bool)", p0, p1, p2, p3));
    }

    function log(bool p0, string memory p1, bool p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,address)", p0, p1, p2, p3));
    }

    function log(bool p0, string memory p1, address p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,string,address,uint256)", p0, p1, p2, p3));
    }

    function log(bool p0, string memory p1, address p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,string,address,string)", p0, p1, p2, p3));
    }

    function log(bool p0, string memory p1, address p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,string,address,bool)", p0, p1, p2, p3));
    }

    function log(bool p0, string memory p1, address p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,string,address,address)", p0, p1, p2, p3));
    }

    function log(bool p0, bool p1, uint256 p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint256,uint256)", p0, p1, p2, p3));
    }

    function log(bool p0, bool p1, uint256 p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint256,string)", p0, p1, p2, p3));
    }

    function log(bool p0, bool p1, uint256 p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint256,bool)", p0, p1, p2, p3));
    }

    function log(bool p0, bool p1, uint256 p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint256,address)", p0, p1, p2, p3));
    }

    function log(bool p0, bool p1, string memory p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,bool,string,uint256)", p0, p1, p2, p3));
    }

    function log(bool p0, bool p1, string memory p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,bool,string,string)", p0, p1, p2, p3));
    }

    function log(bool p0, bool p1, string memory p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,bool,string,bool)", p0, p1, p2, p3));
    }

    function log(bool p0, bool p1, string memory p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,bool,string,address)", p0, p1, p2, p3));
    }

    function log(bool p0, bool p1, bool p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool,uint256)", p0, p1, p2, p3));
    }

    function log(bool p0, bool p1, bool p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool,string)", p0, p1, p2, p3));
    }

    function log(bool p0, bool p1, bool p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool,bool)", p0, p1, p2, p3));
    }

    function log(bool p0, bool p1, bool p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool,address)", p0, p1, p2, p3));
    }

    function log(bool p0, bool p1, address p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,bool,address,uint256)", p0, p1, p2, p3));
    }

    function log(bool p0, bool p1, address p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,bool,address,string)", p0, p1, p2, p3));
    }

    function log(bool p0, bool p1, address p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,bool,address,bool)", p0, p1, p2, p3));
    }

    function log(bool p0, bool p1, address p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,bool,address,address)", p0, p1, p2, p3));
    }

    function log(bool p0, address p1, uint256 p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,address,uint256,uint256)", p0, p1, p2, p3));
    }

    function log(bool p0, address p1, uint256 p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,address,uint256,string)", p0, p1, p2, p3));
    }

    function log(bool p0, address p1, uint256 p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,address,uint256,bool)", p0, p1, p2, p3));
    }

    function log(bool p0, address p1, uint256 p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,address,uint256,address)", p0, p1, p2, p3));
    }

    function log(bool p0, address p1, string memory p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,address,string,uint256)", p0, p1, p2, p3));
    }

    function log(bool p0, address p1, string memory p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,address,string,string)", p0, p1, p2, p3));
    }

    function log(bool p0, address p1, string memory p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,address,string,bool)", p0, p1, p2, p3));
    }

    function log(bool p0, address p1, string memory p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,address,string,address)", p0, p1, p2, p3));
    }

    function log(bool p0, address p1, bool p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,address,bool,uint256)", p0, p1, p2, p3));
    }

    function log(bool p0, address p1, bool p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,address,bool,string)", p0, p1, p2, p3));
    }

    function log(bool p0, address p1, bool p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,address,bool,bool)", p0, p1, p2, p3));
    }

    function log(bool p0, address p1, bool p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,address,bool,address)", p0, p1, p2, p3));
    }

    function log(bool p0, address p1, address p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,address,address,uint256)", p0, p1, p2, p3));
    }

    function log(bool p0, address p1, address p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,address,address,string)", p0, p1, p2, p3));
    }

    function log(bool p0, address p1, address p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,address,address,bool)", p0, p1, p2, p3));
    }

    function log(bool p0, address p1, address p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(bool,address,address,address)", p0, p1, p2, p3));
    }

    function log(address p0, uint256 p1, uint256 p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,uint256,uint256,uint256)", p0, p1, p2, p3));
    }

    function log(address p0, uint256 p1, uint256 p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,uint256,uint256,string)", p0, p1, p2, p3));
    }

    function log(address p0, uint256 p1, uint256 p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,uint256,uint256,bool)", p0, p1, p2, p3));
    }

    function log(address p0, uint256 p1, uint256 p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,uint256,uint256,address)", p0, p1, p2, p3));
    }

    function log(address p0, uint256 p1, string memory p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,uint256,string,uint256)", p0, p1, p2, p3));
    }

    function log(address p0, uint256 p1, string memory p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,uint256,string,string)", p0, p1, p2, p3));
    }

    function log(address p0, uint256 p1, string memory p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,uint256,string,bool)", p0, p1, p2, p3));
    }

    function log(address p0, uint256 p1, string memory p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,uint256,string,address)", p0, p1, p2, p3));
    }

    function log(address p0, uint256 p1, bool p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,uint256,bool,uint256)", p0, p1, p2, p3));
    }

    function log(address p0, uint256 p1, bool p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,uint256,bool,string)", p0, p1, p2, p3));
    }

    function log(address p0, uint256 p1, bool p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,uint256,bool,bool)", p0, p1, p2, p3));
    }

    function log(address p0, uint256 p1, bool p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,uint256,bool,address)", p0, p1, p2, p3));
    }

    function log(address p0, uint256 p1, address p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,uint256,address,uint256)", p0, p1, p2, p3));
    }

    function log(address p0, uint256 p1, address p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,uint256,address,string)", p0, p1, p2, p3));
    }

    function log(address p0, uint256 p1, address p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,uint256,address,bool)", p0, p1, p2, p3));
    }

    function log(address p0, uint256 p1, address p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,uint256,address,address)", p0, p1, p2, p3));
    }

    function log(address p0, string memory p1, uint256 p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,string,uint256,uint256)", p0, p1, p2, p3));
    }

    function log(address p0, string memory p1, uint256 p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,string,uint256,string)", p0, p1, p2, p3));
    }

    function log(address p0, string memory p1, uint256 p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,string,uint256,bool)", p0, p1, p2, p3));
    }

    function log(address p0, string memory p1, uint256 p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,string,uint256,address)", p0, p1, p2, p3));
    }

    function log(address p0, string memory p1, string memory p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,string,string,uint256)", p0, p1, p2, p3));
    }

    function log(address p0, string memory p1, string memory p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,string,string,string)", p0, p1, p2, p3));
    }

    function log(address p0, string memory p1, string memory p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,string,string,bool)", p0, p1, p2, p3));
    }

    function log(address p0, string memory p1, string memory p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,string,string,address)", p0, p1, p2, p3));
    }

    function log(address p0, string memory p1, bool p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,string,bool,uint256)", p0, p1, p2, p3));
    }

    function log(address p0, string memory p1, bool p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,string,bool,string)", p0, p1, p2, p3));
    }

    function log(address p0, string memory p1, bool p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,string,bool,bool)", p0, p1, p2, p3));
    }

    function log(address p0, string memory p1, bool p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,string,bool,address)", p0, p1, p2, p3));
    }

    function log(address p0, string memory p1, address p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,string,address,uint256)", p0, p1, p2, p3));
    }

    function log(address p0, string memory p1, address p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,string,address,string)", p0, p1, p2, p3));
    }

    function log(address p0, string memory p1, address p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,string,address,bool)", p0, p1, p2, p3));
    }

    function log(address p0, string memory p1, address p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,string,address,address)", p0, p1, p2, p3));
    }

    function log(address p0, bool p1, uint256 p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,bool,uint256,uint256)", p0, p1, p2, p3));
    }

    function log(address p0, bool p1, uint256 p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,bool,uint256,string)", p0, p1, p2, p3));
    }

    function log(address p0, bool p1, uint256 p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,bool,uint256,bool)", p0, p1, p2, p3));
    }

    function log(address p0, bool p1, uint256 p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,bool,uint256,address)", p0, p1, p2, p3));
    }

    function log(address p0, bool p1, string memory p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,bool,string,uint256)", p0, p1, p2, p3));
    }

    function log(address p0, bool p1, string memory p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,bool,string,string)", p0, p1, p2, p3));
    }

    function log(address p0, bool p1, string memory p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,bool,string,bool)", p0, p1, p2, p3));
    }

    function log(address p0, bool p1, string memory p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,bool,string,address)", p0, p1, p2, p3));
    }

    function log(address p0, bool p1, bool p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,bool,bool,uint256)", p0, p1, p2, p3));
    }

    function log(address p0, bool p1, bool p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,bool,bool,string)", p0, p1, p2, p3));
    }

    function log(address p0, bool p1, bool p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,bool,bool,bool)", p0, p1, p2, p3));
    }

    function log(address p0, bool p1, bool p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,bool,bool,address)", p0, p1, p2, p3));
    }

    function log(address p0, bool p1, address p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,bool,address,uint256)", p0, p1, p2, p3));
    }

    function log(address p0, bool p1, address p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,bool,address,string)", p0, p1, p2, p3));
    }

    function log(address p0, bool p1, address p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,bool,address,bool)", p0, p1, p2, p3));
    }

    function log(address p0, bool p1, address p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,bool,address,address)", p0, p1, p2, p3));
    }

    function log(address p0, address p1, uint256 p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,address,uint256,uint256)", p0, p1, p2, p3));
    }

    function log(address p0, address p1, uint256 p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,address,uint256,string)", p0, p1, p2, p3));
    }

    function log(address p0, address p1, uint256 p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,address,uint256,bool)", p0, p1, p2, p3));
    }

    function log(address p0, address p1, uint256 p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,address,uint256,address)", p0, p1, p2, p3));
    }

    function log(address p0, address p1, string memory p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,address,string,uint256)", p0, p1, p2, p3));
    }

    function log(address p0, address p1, string memory p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,address,string,string)", p0, p1, p2, p3));
    }

    function log(address p0, address p1, string memory p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,address,string,bool)", p0, p1, p2, p3));
    }

    function log(address p0, address p1, string memory p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,address,string,address)", p0, p1, p2, p3));
    }

    function log(address p0, address p1, bool p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,address,bool,uint256)", p0, p1, p2, p3));
    }

    function log(address p0, address p1, bool p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,address,bool,string)", p0, p1, p2, p3));
    }

    function log(address p0, address p1, bool p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,address,bool,bool)", p0, p1, p2, p3));
    }

    function log(address p0, address p1, bool p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,address,bool,address)", p0, p1, p2, p3));
    }

    function log(address p0, address p1, address p2, uint256 p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,address,address,uint256)", p0, p1, p2, p3));
    }

    function log(address p0, address p1, address p2, string memory p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,address,address,string)", p0, p1, p2, p3));
    }

    function log(address p0, address p1, address p2, bool p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,address,address,bool)", p0, p1, p2, p3));
    }

    function log(address p0, address p1, address p2, address p3) internal pure {
        _sendLogPayload(abi.encodeWithSignature("log(address,address,address,address)", p0, p1, p2, p3));
    }

}

Settings
{
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "evmVersion": "paris",
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "libraries": {
    "contracts/libraries/MathHelper.sol": {
      "MathHelper": "0x1F64078E323c37B3Aca709FB9146A73c3f3c4617"
    }
  }
}

Contract ABI

[{"inputs":[{"internalType":"address","name":"factory","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AlreadyInitialized","type":"error"},{"inputs":[],"name":"Expired","type":"error"},{"inputs":[{"internalType":"address","name":"caller","type":"address"},{"internalType":"uint256","name":"requested","type":"uint256"},{"internalType":"uint256","name":"balance","type":"uint256"}],"name":"InsufficientBalance","type":"error"},{"inputs":[{"internalType":"address","name":"asset","type":"address"}],"name":"InvalidAsset","type":"error"},{"inputs":[{"internalType":"uint256","name":"length","type":"uint256"}],"name":"InvalidSignatureLength","type":"error"},{"inputs":[],"name":"NotExpired","type":"error"},{"inputs":[],"name":"Uinitialized","type":"error"},{"inputs":[],"name":"Uinitialized","type":"error"},{"inputs":[{"internalType":"address","name":"caller","type":"address"}],"name":"Unauthorized","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"Id","name":"Id","type":"bytes32"},{"indexed":true,"internalType":"uint256","name":"dsId","type":"uint256"},{"indexed":true,"internalType":"address","name":"redeemer","type":"address"},{"indexed":false,"internalType":"uint256","name":"raAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"swapAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"exchangeRates","type":"uint256"}],"name":"Cancelled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"Id","name":"Id","type":"bytes32"},{"indexed":true,"internalType":"uint256","name":"dsId","type":"uint256"},{"indexed":true,"internalType":"address","name":"redeemer","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"paReceived","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"raReceived","type":"uint256"}],"name":"CtRedeemed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"Id","name":"Id","type":"bytes32"},{"indexed":true,"internalType":"uint256","name":"dsId","type":"uint256"},{"indexed":true,"internalType":"address","name":"redeemer","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"DsRedeemed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"Id","name":"id","type":"bytes32"},{"indexed":true,"internalType":"address","name":"pa","type":"address"},{"indexed":true,"internalType":"address","name":"ra","type":"address"},{"indexed":false,"internalType":"address","name":"lv","type":"address"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"Id","name":"Id","type":"bytes32"},{"indexed":true,"internalType":"uint256","name":"dsId","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"expiry","type":"uint256"},{"indexed":false,"internalType":"address","name":"ds","type":"address"},{"indexed":false,"internalType":"address","name":"ct","type":"address"}],"name":"Issued","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"Id","name":"id","type":"bytes32"},{"indexed":true,"internalType":"address","name":"depositor","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"LvDeposited","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"Id","name":"Id","type":"bytes32"},{"indexed":true,"internalType":"address","name":"redeemer","type":"address"},{"indexed":true,"internalType":"address","name":"receiver","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"fee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"feePrecentage","type":"uint256"}],"name":"LvRedeemEarly","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"Id","name":"Id","type":"bytes32"},{"indexed":true,"internalType":"address","name":"receiver","type":"address"},{"indexed":false,"internalType":"uint256","name":"ra","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"pa","type":"uint256"}],"name":"LvRedeemExpired","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"Id","name":"Id","type":"bytes32"},{"indexed":true,"internalType":"uint256","name":"dsId","type":"uint256"},{"indexed":true,"internalType":"address","name":"depositor","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"PsmDeposited","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"Id","name":"Id","type":"bytes32"},{"indexed":true,"internalType":"address","name":"redeemer","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"RedemptionRequestCancelled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"Id","name":"Id","type":"bytes32"},{"indexed":true,"internalType":"address","name":"redeemer","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"RedemptionRequested","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"Id","name":"Id","type":"bytes32"},{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"RedemptionRightTransferred","type":"event"},{"inputs":[{"internalType":"Id","name":"id","type":"bytes32"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"depositLv","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"Id","name":"id","type":"bytes32"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"depositPsm","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"Id","name":"id","type":"bytes32"}],"name":"exchangeRate","outputs":[{"internalType":"uint256","name":"rates","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"factory","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"pa","type":"address"},{"internalType":"address","name":"ra","type":"address"}],"name":"getId","outputs":[{"internalType":"Id","name":"","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"pa","type":"address"},{"internalType":"address","name":"ra","type":"address"},{"internalType":"uint256","name":"lvFee","type":"uint256"},{"internalType":"uint256","name":"lvAmmWaDepositThreshold","type":"uint256"},{"internalType":"uint256","name":"lvAmmCtDepositThreshold","type":"uint256"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"Id","name":"id","type":"bytes32"},{"internalType":"uint256","name":"expiry","type":"uint256"},{"internalType":"uint256","name":"exchangeRates","type":"uint256"}],"name":"issueNewDs","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"Id","name":"id","type":"bytes32"}],"name":"lastDsId","outputs":[{"internalType":"uint256","name":"dsId","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"Id","name":"id","type":"bytes32"},{"internalType":"address","name":"user","type":"address"}],"name":"lockedLvfor","outputs":[{"internalType":"uint256","name":"locked","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"ct","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"Id","name":"id","type":"bytes32"}],"name":"lvDecreaseCtBalance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"ds","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"Id","name":"id","type":"bytes32"}],"name":"lvDecreaseDsBalance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"Id","name":"id","type":"bytes32"}],"name":"lvDecreasePaBalance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"Id","name":"id","type":"bytes32"}],"name":"lvDecreaseRaBalance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"ct","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"Id","name":"id","type":"bytes32"}],"name":"lvIncreaseCtBalance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"ds","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"Id","name":"id","type":"bytes32"}],"name":"lvIncreaseDsBalance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"Id","name":"id","type":"bytes32"}],"name":"lvIncreasePaBalance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"Id","name":"id","type":"bytes32"}],"name":"lvIncreaseRaBalance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"Id","name":"id","type":"bytes32"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"previewDepositPsm","outputs":[{"internalType":"uint256","name":"ctReceived","type":"uint256"},{"internalType":"uint256","name":"dsReceived","type":"uint256"},{"internalType":"uint256","name":"dsId","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"previewLvDeposit","outputs":[{"internalType":"uint256","name":"lv","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"Id","name":"id","type":"bytes32"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"previewRedeemEarlyLv","outputs":[{"internalType":"uint256","name":"received","type":"uint256"},{"internalType":"uint256","name":"fee","type":"uint256"},{"internalType":"uint256","name":"feePrecentage","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"Id","name":"id","type":"bytes32"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"previewRedeemExpiredLv","outputs":[{"internalType":"uint256","name":"attributedRa","type":"uint256"},{"internalType":"uint256","name":"attributedPa","type":"uint256"},{"internalType":"uint256","name":"approvedAmount","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"Id","name":"id","type":"bytes32"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"previewRedeemRaWithCtDs","outputs":[{"internalType":"uint256","name":"ra","type":"uint256"},{"internalType":"uint256","name":"rates","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"Id","name":"id","type":"bytes32"},{"internalType":"uint256","name":"dsId","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"previewRedeemRaWithDs","outputs":[{"internalType":"uint256","name":"assets","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"Id","name":"id","type":"bytes32"},{"internalType":"uint256","name":"dsId","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"previewRedeemWithCt","outputs":[{"internalType":"uint256","name":"paReceived","type":"uint256"},{"internalType":"uint256","name":"raReceived","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"ct","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"Id","name":"id","type":"bytes32"}],"name":"psmDecreaseCtBalance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"ds","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"Id","name":"id","type":"bytes32"}],"name":"psmDecreaseDsBalance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"Id","name":"id","type":"bytes32"}],"name":"psmDecreasePaBalance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"Id","name":"id","type":"bytes32"}],"name":"psmDecreaseRaBalance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"ct","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"Id","name":"id","type":"bytes32"}],"name":"psmIncreaseCtBalance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"ds","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"Id","name":"id","type":"bytes32"}],"name":"psmIncreaseDsBalance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"Id","name":"id","type":"bytes32"}],"name":"psmIncreasePaBalance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"Id","name":"id","type":"bytes32"}],"name":"psmIncreaseRaBalance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"Id","name":"id","type":"bytes32"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"redeemEarlyLv","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"Id","name":"id","type":"bytes32"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"redeemExpiredLv","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"Id","name":"id","type":"bytes32"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"redeemRaWithCtDs","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"Id","name":"id","type":"bytes32"},{"internalType":"uint256","name":"dsId","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes","name":"rawDsPermitSig","type":"bytes"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"redeemRaWithDs","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"Id","name":"id","type":"bytes32"},{"internalType":"uint256","name":"dsId","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes","name":"rawCtPermitSig","type":"bytes"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"redeemWithCT","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"Id","name":"id","type":"bytes32"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"requestRedemption","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"Id","name":"id","type":"bytes32"}],"name":"reservedUserWithdrawal","outputs":[{"internalType":"uint256","name":"reservedRa","type":"uint256"},{"internalType":"uint256","name":"reservedPa","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"Id","name":"id","type":"bytes32"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferRedemptionRights","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"Id","name":"id","type":"bytes32"}],"name":"valueLocked","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]

60806040523480156200001157600080fd5b5060405162004e6438038062004e6483398101604081905262000034916200005a565b600180546001600160a01b0319166001600160a01b03929092169190911790556200008c565b6000602082840312156200006d57600080fd5b81516001600160a01b03811681146200008557600080fd5b9392505050565b614dc8806200009c6000396000f3fe608060405234801561001057600080fd5b50600436106102535760003560e01c80636910a77d11610146578063ab50b4c1116100c3578063cd3c0a5011610087578063cd3c0a5014610563578063d13f90b414610576578063e93036a614610589578063ea8b6eb71461059c578063f18eb1da146105af578063f7268185146105c257600080fd5b8063ab50b4c1146104fc578063b2418a811461050f578063b2810ef514610522578063b431169f14610535578063c45a01551461054857600080fd5b806393dafb741161010a57806393dafb741461049d578063964a85b9146104b0578063a1d5dae1146104c3578063a208bc0a146104d6578063a5af6d9a146104e957600080fd5b80636910a77d1461043e5780636c1167c0146104515780636c82b692146104645780638a4b7a52146104775780638ffe8ee41461048a57600080fd5b806335cfbbf6116101d45780634281cef0116101985780634281cef0146103c45780635363bc3d146103d75780635b239c2c146103ea5780635d5ca2d9146103fd57806360fc15e71461042b57600080fd5b806335cfbbf61461036557806336ef80db146103785780633af8d4e41461038b5780633bd9cf8d1461039e5780633dccb39b146103b157600080fd5b80630f57e8481161021b5780630f57e848146102b95780630fcf2edf146102df5780632103912b1461031f5780632347fd60146103325780633407b0a31461034557600080fd5b806302fe2c2714610258578063035399031461026d578063061c52211461028057806308b9c146146102935780630a33f24d146102a6575b600080fd5b61026b6102663660046148ff565b6105d5565b005b61026b61027b366004614936565b610673565b61026b61028e36600461496b565b6106fa565b61026b6102a13660046148ff565b610768565b61026b6102b43660046148ff565b6107f0565b6102cc6102c73660046149a3565b610883565b6040519081526020015b60405180910390f35b61030a6102ed3660046149a3565b6000908152602081905260409020601c810154601d909101549091565b604080519283526020830191909152016102d6565b61026b61032d366004614936565b6108a1565b61026b6103403660046148ff565b61091e565b6102cc6103533660046149a3565b60009081526020819052604090205490565b61026b6103733660046148ff565b6109b7565b6102cc6103863660046149bc565b610a50565b61030a6103993660046149f5565b610a9e565b61026b6103ac366004614936565b610afd565b61026b6103bf366004614936565b610b80565b61026b6103d236600461496b565b610c03565b6102cc6103e53660046149a3565b610c78565b61026b6103f8366004614a37565b610c80565b61041061040b3660046148ff565b610d20565b604080519384526020840192909252908201526060016102d6565b61026b610439366004614936565b610d4b565b61041061044c3660046148ff565b610dce565b61026b61045f366004614a37565b610deb565b61026b6104723660046148ff565b610eac565b61026b6104853660046148ff565b610f45565b61026b6104983660046148ff565b610fd8565b61026b6104ab3660046148ff565b611071565b61026b6104be3660046149f5565b6110c7565b61026b6104d1366004614936565b611236565b6102cc6104e43660046149a3565b6112b3565b61026b6104f73660046148ff565b6112cb565b6102cc61050a3660046149f5565b61135e565b61026b61051d36600461496b565b6113b7565b61026b6105303660046148ff565b61144a565b6104106105433660046148ff565b611497565b6001546040516001600160a01b0390911681526020016102d6565b61026b610571366004614936565b6114fc565b61026b610584366004614b0d565b61157f565b6102cc610597366004614b5e565b6116f3565b61026b6105aa366004614936565b611720565b61026b6105bd3660046148ff565b61179d565b61030a6105d03660046148ff565b611830565b600082815260208190526040902082906105ee90611858565b61060b576040516305bb301f60e51b815260040160405180910390fd5b60008381526020819052604081209061062582338661188b565b9050336001600160a01b031681867f2be78f44ec51653e82a47117fec352f06123e1378c7b304fbe431681a87679d58760405161066491815260200190565b60405180910390a45050505050565b604051635c58950f60e11b8152600481018390526001600160a01b0384169063b8b12a1e90602401600060405180830381600087803b1580156106b557600080fd5b505af11580156106c9573d6000803e3d6000fd5b5050506000828152602081905260408120600e0180548593509091906106f0908490614b99565b9091555050505050565b60008381526020819052604090206107148133858561199f565b6001600160a01b038316336001600160a01b0316857fd87cfe86ee1e5fdc646d6804cb83d3a064572208e1e6da7e92bdd16d9420daf98560405161075a91815260200190565b60405180910390a450505050565b6000828152602081905260408120908080610784843387611a81565b9250925092506107913390565b6001600160a01b031682877f5e639cd9080405443c0a7a5e722321527207147b4f189c36d757700d59c716378689866040516107e0939291909283526020830191909152604082015260600190565b60405180910390a4505050505050565b60008181526020819052604090819020600201549051635c58950f60e11b8152600481018490526001600160a01b0390911690819063b8b12a1e90602401600060405180830381600087803b15801561084857600080fd5b505af115801561085c573d6000803e3d6000fd5b5050506000838152602081905260408120600f0180548693509091906106f0908490614b99565b600081815260208190526040812061089a81611c0f565b9392505050565b604051635c58950f60e11b8152600481018390526001600160a01b0384169063b8b12a1e90602401600060405180830381600087803b1580156108e357600080fd5b505af11580156108f7573d6000803e3d6000fd5b505050600082815260208190526040812060080180548593509091906106f0908490614b99565b600081815260208190526040908190206002015490516340c10f1960e01b81526001600160a01b039091169081906340c10f19906109629030908790600401614bac565b600060405180830381600087803b15801561097c57600080fd5b505af1158015610990573d6000803e3d6000fd5b5050506000838152602081905260408120600f0180548693509091906106f0908490614bc5565b600081815260208190526040908190206001015490516340c10f1960e01b81526001600160a01b039091169081906340c10f19906109fb9030908790600401614bac565b600060405180830381600087803b158015610a1557600080fd5b505af1158015610a29573d6000803e3d6000fd5b505050600083815260208190526040812060060180548693509091906106f0908490614bc5565b6000610a95610a908484604080518082019091526000808252602082015250604080518082019091526001600160a01b0392831681529116602082015290565b611c2d565b90505b92915050565b600083815260208190526040812081908590610ab990611858565b610ad6576040516305bb301f60e51b815260040160405180910390fd5b6000868152602081905260409020610aef818787611c7e565b909890975095505050505050565b6040516340c10f1960e01b81526001600160a01b038416906340c10f1990610b2b9030908690600401614bac565b600060405180830381600087803b158015610b4557600080fd5b505af1158015610b59573d6000803e3d6000fd5b505050600082815260208190526040812060070180548593509091906106f0908490614bc5565b6040516340c10f1960e01b81526001600160a01b038416906340c10f1990610bae9030908690600401614bac565b600060405180830381600087803b158015610bc857600080fd5b505af1158015610bdc573d6000803e3d6000fd5b5050506000828152602081905260408120600d0180548593509091906106f0908490614bc5565b60008381526020819052604081209080610c1f83338787611d36565b91509150846001600160a01b0316867f6886cf6a5c29c986e34ca4d560ea1c4bbb880221c387915f2a1ca2a3c5dd066a8484604051610c68929190918252602082015260400190565b60405180910390a3505050505050565b600081610a98565b60008581526020819052604090208590610c9990611858565b610cb6576040516305bb301f60e51b815260040160405180910390fd5b6000868152602081905260409020336001600160a01b031686887f15eb4c60bee595ca5f7c62c20f2f7f7e52f43fa459fba81b39271523a0e85f3d88604051610d0191815260200190565b60405180910390a4610d1781338789888861200f565b50505050505050565b600082815260208190526040812081908190610d3c8186612044565b91989097509095509350505050565b6040516340c10f1960e01b81526001600160a01b038416906340c10f1990610d799030908690600401614bac565b600060405180830381600087803b158015610d9357600080fd5b505af1158015610da7573d6000803e3d6000fd5b505050600082815260208190526040812060080180548593509091906106f0908490614bc5565b600082815260208190526040812081908190610d3c818633612210565b60008581526020819052604090208590610e0490611858565b610e21576040516305bb301f60e51b815260040160405180910390fd5b60008681526020819052604081209080610e3f8333898b8a8a612399565b91509150610e4a3390565b6001600160a01b0316888a7fc901c80d52ba5274697ecdce2dca541020aa66e35eef49e801708ae75bd36e2a8a8686604051610e99939291909283526020830191909152604082015260600190565b60405180910390a4505050505050505050565b600081815260208190526040908190206001015490516340c10f1960e01b81526001600160a01b039091169081906340c10f1990610ef09030908790600401614bac565b600060405180830381600087803b158015610f0a57600080fd5b505af1158015610f1e573d6000803e3d6000fd5b5050506000838152602081905260408120600c0180548693509091906106f0908490614bc5565b60008181526020819052604090819020600101549051635c58950f60e11b8152600481018490526001600160a01b0390911690819063b8b12a1e90602401600060405180830381600087803b158015610f9d57600080fd5b505af1158015610fb1573d6000803e3d6000fd5b505050600083815260208190526040812060060180548693509091906106f0908490614b99565b600081815260208190526040908190206002015490516340c10f1960e01b81526001600160a01b039091169081906340c10f199061101c9030908790600401614bac565b600060405180830381600087803b15801561103657600080fd5b505af115801561104a573d6000803e3d6000fd5b505050600083815260208190526040812060090180548693509091906106f0908490614bc5565b600082815260208190526040902061108a813384612475565b604051828152339084907f9c089cc0fdbab29c0e65f3512c8fc12103af382382dabe473b3daffcd1b5487e906020015b60405180910390a3505050565b600083815260208190526040902083906110e090611858565b6110fd576040516305bb301f60e51b815260040160405180910390fd5b600084815260208190526040808220600180820154600283015491549351630b4edfaf60e11b81526001600160a01b039283166004820181905291831660248201819052306044830152606482018a905260848201899052939593949193928392169063169dbf5e9060a40160408051808303816000875af1158015611187573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111ab9190614bd8565b8654919350915060009086826111c083614c07565b9091555086549091506111d687858584866124dd565b6111e087836125e2565b604080516001600160a01b038086168252861660208201528b9183918e917f5184c4193f766fd6977e52a68321d6f109de1a0745b553059c984373e83e9db0910160405180910390a45050505050505050505050565b604051635c58950f60e11b8152600481018390526001600160a01b0384169063b8b12a1e90602401600060405180830381600087803b15801561127857600080fd5b505af115801561128c573d6000803e3d6000fd5b5050506000828152602081905260408120600d0180548593509091906106f0908490614b99565b6000818152602081905260408120600581015461089a565b60008181526020819052604090819020600101549051635c58950f60e11b8152600481018490526001600160a01b0390911690819063b8b12a1e90602401600060405180830381600087803b15801561132357600080fd5b505af1158015611337573d6000803e3d6000fd5b5050506000838152602081905260408120600c0180548693509091906106f0908490614b99565b6000838152602081905260408120849061137790611858565b611394576040516305bb301f60e51b815260040160405180910390fd5b60008581526020819052604090206113ad818587612627565b9695505050505050565b60008381526020819052604081209080806113d4843388886126cb565b925092509250856001600160a01b03166113eb3390565b6001600160a01b0316887fb52292f46324c668438c13eae0859c783b8516639ed3b8c8c2ab842e63e9dea8868686604051611439939291909283526020830191909152604082015260600190565b60405180910390a450505050505050565b6000828152602081905260409020611463813384612aa9565b604051828152339084907f7f6aa3e2623e42a2bd437a912b332ba383b4004a593c06ae69511f55d04ef8ae906020016110ba565b6000806000846114b7600080838152602001908152602001600020611858565b6114d4576040516305bb301f60e51b815260040160405180910390fd5b60008681526020819052604090206114ec8187612c56565b9199909850909650945050505050565b6040516340c10f1960e01b81526001600160a01b038416906340c10f199061152a9030908690600401614bac565b600060405180830381600087803b15801561154457600080fd5b505af1158015611558573d6000803e3d6000fd5b5050506000828152602081905260408120600e0180548593509091906106f0908490614bc5565b60006115bc8686604080518082019091526000808252602082015250604080518082019091526001600160a01b0392831681529116602082015290565b905060006115c982611c2d565b60008181526020819052604090209091506115e381611858565b156116005760405162dc149f60e41b815260040160405180910390fd5b600154604051637d39041b60e11b81526001600160a01b0389811660048301528a8116602483015230604483015290911690600090829063fa720836906064016020604051808303816000875af115801561165f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116839190614c20565b905061168f8386612d0f565b6116a083600a01828a8a8a8e612d8f565b6040516001600160a01b038281168252808b1691908c169086907fad7174cdf644277b474d89119511e4a5ba3aa0af1ee78e0a74fd2979aace6c159060200160405180910390a450505050505050505050565b6000828152602081815260408083206001600160a01b03851684528083019092528220545b949350505050565b604051635c58950f60e11b8152600481018390526001600160a01b0384169063b8b12a1e90602401600060405180830381600087803b15801561176257600080fd5b505af1158015611776573d6000803e3d6000fd5b505050600082815260208190526040812060070180548593509091906106f0908490614b99565b60008181526020819052604090819020600201549051635c58950f60e11b8152600481018490526001600160a01b0390911690819063b8b12a1e90602401600060405180830381600087803b1580156117f557600080fd5b505af1158015611809573d6000803e3d6000fd5b505050600083815260208190526040812060090180548693509091906106f0908490614b99565b6000828152602081905260408120819061184a8185612e62565b919791965090945050505050565b6040805180820190915260018201546001600160a01b0390811682526002830154166020820152600090610a9890612f09565b8254600081815260038501602052604090206118a681612f33565b6000731f64078e323c37b3aca709fb9146a73c3f3c4617630e042cec856118cc85612f48565b6040516001600160e01b031960e085901b16815260048101929092526024820152604401602060405180830381865af415801561190d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119319190614c3d565b9050611941600487018587612fc3565b6040805160a081018252835460ff8116151582526001600160a01b0361010090910481166020830152600185015416918101919091526002830154606082015260038301546080820152611996908683612fd8565b50509392505050565b6001600160a01b0383166000908152602080860190526040812054908190036119e25760405163472511eb60e11b81523360048201526024015b60405180910390fd5b81811015611a1c5760405163db42144d60e01b81526001600160a01b038516600482015260248101839052604481018290526064016119d9565b6001600160a01b038316600090815260208087019052604081208054849290611a46908490614bc5565b90915550506001600160a01b038416600090815260208087019052604081208054849290611a75908490614b99565b90915550505050505050565b8254600081815260038501602052604081209091908290611aa181612f33565b611aaa81612f48565b604051638d3d803d60e01b81526004810187905260248101829052909250731f64078e323c37b3aca709fb9146a73c3f3c461790638d3d803d90604401602060405180830381865af4158015611b04573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b289190614c3d565b9350611b3860048801878661309c565b600181015460405163079cc67960e41b81526001600160a01b03909116906379cc679090611b6c9089908990600401614bac565b600060405180830381600087803b158015611b8657600080fd5b505af1158015611b9a573d6000803e3d6000fd5b5050825460405163079cc67960e41b81526101009091046001600160a01b031692506379cc67909150611bd39089908990600401614bac565b600060405180830381600087803b158015611bed57600080fd5b505af1158015611c01573d6000803e3d6000fd5b505050505093509350939050565b80546000818152600383016020526040812090919061171881612f48565b60008082604051602001611c5f919081516001600160a01b039081168252602092830151169181019190915260400190565b60408051601f1981840301815291905280516020909101209392505050565b600082815260038401602052604081208190611c99816130b1565b6001810154604080516318160ddd60e01b815290516000926001600160a01b0316916318160ddd9160048083019260209291908290030181865afa158015611ce5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d099190614c3d565b90506000611d19600489016130c3565b9050611d27888784846130ed565b90999098509650505050505050565b8354600081815260038601602090815260408083206001600160a01b03881684528289019092528220549192839290919080158015611d7b5750611d798261311b565b155b15611da45760405163472511eb60e11b81526001600160a01b03891660048201526024016119d9565b611dad8261311b565b158015611db957508581105b15611df05760405163db42144d60e01b81526001600160a01b038916600482015260248101879052604481018290526064016119d9565b611df98261311b565b8015611e205750600883901c600090815260188a016020526040902054600160ff85161b16155b15611e4157611e2f8984613196565b600b89015415611e4157611e41614c56565b60168901546001600160a01b0316600080611e6060198d018a8d613237565b809450819550829a50839b50505050508b60010160010160009054906101000a90046001600160a01b03166001600160a01b031663a9059cbb8b8a6040518363ffffffff1660e01b8152600401611eb8929190614bac565b6020604051808303816000875af1158015611ed7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611efb9190614c6c565b5060018c015460405163a9059cbb60e01b81526001600160a01b039091169063a9059cbb90611f30908d908b90600401614bac565b6020604051808303816000875af1158015611f4f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f739190614c6c565b5088611f7f8383614bc5565b14611f8c57611f8c614c56565b611f9960168d01826132cd565b81156120005760405163079cc67960e41b81526001600160a01b038416906379cc679090611fcd908e908690600401614bac565b600060405180830381600087803b158015611fe757600080fd5b505af1158015611ffb573d6000803e3d6000fd5b505050505b50505050505094509492505050565b6000838152600387016020526040902061202881612f33565b612036876004018287613331565b610d1787828589898761337b565b60008060006120528561355b565b5060108401546014850154601186015460009161206e91614bc5565b9050731f64078e323c37b3aca709fb9146a73c3f3c4617637b7ddb3b8288600a01600c0160000160009054906101000a90046001600160a01b03166001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156120e6573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061210a9190614c3d565b6040516001600160e01b031960e085901b1681526004810192909252602482015260448101889052606401602060405180830381865af4158015612152573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121769190614c3d565b601087015460405163b5b4115f60e01b8152600481018390526024810191909152909450731f64078e323c37b3aca709fb9146a73c3f3c46179063b5b4115f90604401602060405180830381865af41580156121d6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121fa9190614c3d565b92506122068385614b99565b9350509250925092565b8254600081815260038501602090815260408083206001600160a01b0386168452828801909252822054919283928392908015801561225557506122538261311b565b155b1561227e5760405163472511eb60e11b81526001600160a01b03881660048201526024016119d9565b6122878261311b565b15801561229357508781105b156122ca5760405163db42144d60e01b81526001600160a01b038816600482015260248101899052604481018290526064016119d9565b6040805160c08101825260198b01548152601a8b0154602080830191909152601b8c015482840152601c8c01546060830152601d8c01546080830152601e8c015460a08301528251908101909252601f8b01548252906123298461311b565b80156123505750600885901c600090815260188c016020526040902054600160ff87161b16155b156123755761235e8b613576565b600b8d015491935091501561237557612375614c56565b61238560208c0183838d8d613679565b919d909c50909a5098505050505050505050565b6000838152600387016020526040812081906123b4816130b1565b6001810154604080516318160ddd60e01b815290516000926001600160a01b0316916318160ddd9160048083019260209291908290030181865afa158015612400573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124249190614c3d565b9050600061243460048c0161399b565b90506124428b8a84846130ed565b909550935061245760048c01848b88886139db565b6124678b848c8c89898d8d613a3c565b505050965096945050505050565b61247e8361355b565b6001600160a01b0382166000908152602080850190526040812080548392906124a8908490614bc5565b90915550506019830180548291906000906124c4908490614bc5565b909155506124d89050601684018284612fc3565b505050565b80156124fe57600081815260038601602052604090206124fc816130b1565b505b61256583856040805160a081018252600080825260208201819052918101829052606081018290526080810191909152506040805160a08101825260008082526001600160a01b039485166020830152929093169083015260608201819052608082015290565b60009283526003958601602090815260409384902082518154928401516001600160a81b0319909316901515610100600160a81b031916176101006001600160a01b0393841602178155938201516001850180546001600160a01b0319169190921617905560608101516002840155608001519190940155505050565b806000036125ee575050565b600881901c6000908152601883016020526040902054600160ff83161b1661261a5761261a8282613196565b61262382613c15565b5050565b6000828152600384016020526040812061264081612f33565b6000731f64078e323c37b3aca709fb9146a73c3f3c4617638d3d803d8561266685612f48565b6040516001600160e01b031960e085901b16815260048101929092526024820152604401602060405180830381865af41580156126a7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113ad9190614c3d565b60008060006126d98761355b565b5085546010870154601488015460118901549192916000916126fa91614bc5565b905061272560405180604001604052806007815260200166746f74616c526160c81b81525082613d04565b6016890154604080516318160ddd60e01b81529051731f64078e323c37b3aca709fb9146a73c3f3c461792637b7ddb3b9285926001600160a01b03909216916318160ddd916004808201926020929091908290030181865afa15801561278f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127b39190614c3d565b6040516001600160e01b031960e085901b1681526004810192909252602482015260448101899052606401602060405180830381865af41580156127fb573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061281f9190614c3d565b94506000731f64078e323c37b3aca709fb9146a73c3f3c461763f2a5e970600160601b6040516001600160e01b031960e084901b1681526001600160a01b03909116600482015260126024820152604401602060405180830381865af415801561288d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906128b19190614c3d565b6040516001629a5d1f60e01b0319815260048101889052602481018290529091506000908190731f64078e323c37b3aca709fb9146a73c3f3c46179063ff65a2e1906044016040805180830381865af4158015612912573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129369190614c8e565b91509150818c600a0160060160010160008282546129549190614b99565b909155505060148c018054829190600090612970908490614b99565b909155505060108c015460405163b5b4115f60e01b8152731f64078e323c37b3aca709fb9146a73c3f3c46179163b5b4115f916129ba918c91600401918252602082015260400190565b602060405180830381865af41580156129d7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129fb9190614c3d565b60158d0180549198508891600090612a14908490614bc5565b90915550612a2490508789614b99565b60168d015460405163079cc67960e41b81529199506001600160a01b0316906379cc679090612a59908e908d90600401614bac565b600060405180830381600087803b158015612a7357600080fd5b505af1158015612a87573d6000803e3d6000fd5b50612a9a92505050600a8d01898c613d49565b50505050509450945094915050565b612ab28361355b565b612ac0600a84018284613dbd565b6000731f64078e323c37b3aca709fb9146a73c3f3c461763f2a5e970600160601b6040516001600160e01b031960e084901b1681526001600160a01b03909116600482015260126024820152604401602060405180830381865af4158015612b2c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b509190614c3d565b6040516001629a5d1f60e01b0319815260048101849052602481018290529091506000908190731f64078e323c37b3aca709fb9146a73c3f3c46179063ff65a2e1906044016040805180830381865af4158015612bb1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612bd59190614c8e565b915091508186600a016006016001016000828254612bf39190614bc5565b9091555050601486018054829190600090612c0f908490614bc5565b90915550612c1f90508682613df0565b6040805180820190915260168701546001600160a01b0316815260178701546020820152612c4e908686613e5d565b505050505050565b81546000818152600384016020526040812090918291612c7581612f33565b6000731f64078e323c37b3aca709fb9146a73c3f3c4617630e042cec87612c9b85612f48565b6040516001600160e01b031960e085901b16815260048101929092526024820152604401602060405180830381865af4158015612cdc573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d009190614c3d565b97889750929550919350505050565b80516001830180546001600160a01b03199081166001600160a01b03938416179091556020830151600285018054909216928116929092179055612d5290613e8e565b80516004840180546001600160a01b0319166001600160a01b03909216919091179055602081015160058401556040015160069092019190915550565b612d9a848484613ee3565b80516006880155602080820151600789015560408083015160088a0155606083015160098a01556080830151600a8a015560a090920151600b89015581518083018352600080825290820181905282518084019093526001600160a01b03881680845292909101819052600c880180546001600160a01b031916909217909155600d870155612e2881613e8e565b805187546001600160a01b0319166001600160a01b0390911617875560208101516001880155604001516002909601959095555050505050565b8154600081815260038401602052604081209091908290612e8281612f33565b612e8b81612f48565b604051638d3d803d60e01b81526004810187905260248101829052909250731f64078e323c37b3aca709fb9146a73c3f3c461790638d3d803d90604401602060405180830381865af4158015612ee5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122069190614c3d565b80516000906001600160a01b031615801590610a98575050602001516001600160a01b0316151590565b612f3c81613f4e565b612f4581613f74565b50565b60008160000160019054906101000a90046001600160a01b03166001600160a01b0316633ba0b9a96040518163ffffffff1660e01b8152600401602060405180830381865afa158015612f9f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a989190614c3d565b612fcd8383613f9b565b6124d8838383613dbd565b82602001516001600160a01b03166340c10f1983836040518363ffffffff1660e01b815260040161300a929190614bac565b600060405180830381600087803b15801561302457600080fd5b505af1158015613038573d6000803e3d6000fd5b5050505082604001516001600160a01b03166340c10f1983836040518363ffffffff1660e01b815260040161306e929190614bac565b600060405180830381600087803b15801561308857600080fd5b505af1158015610d17573d6000803e3d6000fd5b6130a68382613fb7565b6124d8838284613d49565b6130ba81613f4e565b612f4581613fc7565b600081600101546000036130d957506002015490565b81600101548260020154610a989190614bc5565b60098401546000908190613102868287613fed565b925061310f868587613fed565b91505094509492505050565b60008160000160019054906101000a90046001600160a01b03166001600160a01b0316632f13b60c6040518163ffffffff1660e01b8152600401602060405180830381865afa158015613172573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a989190614c6c565b600881901c600090815260188301602052604090208054600160ff84161b179055601482015460118301546000906131cf908390614bc5565b90506131dc848385614021565b6040805180820190915260168501546001600160a01b0316815260178501546020820152600090819061321e906132129061403b565b6019880190858461407f565b5050600060118501819055601490940193909355505050565b6001600160a01b03811660009081526007840160205260408120548190819081908681106132815786915061326c888861421f565b909550935061327c88888861428f565b6132c3565b90508061328e8188614b99565b92508661329b8385614bc5565b146132a8576132a8614c56565b6132b38882856142b9565b90955093506132c388828861428f565b5093509350935093565b6132d78282613fb7565b8154604051630852cd8d60e31b8152600481018390526001600160a01b03909116906342966c68906024015b600060405180830381600087803b15801561331d57600080fd5b505af1158015612c4e573d6000803e3d6000fd5b808360030160008282546133459190614bc5565b92505081905550808360050160008282546133609190614bc5565b92505081905550808260020160008282546106f09190614bc5565b84546133999061010090046001600160a01b031685853086866142f7565b84546040516323b872dd60e01b81526101009091046001600160a01b0316906323b872dd906133d090869030908790600401614cb2565b6020604051808303816000875af11580156133ef573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906134139190614c6c565b5060408051808201825260018801546001600160a01b039081168252600289015481166020808401919091528351808201855260009052835190810184529151169081905290516323b872dd60e01b81526323b872dd9061347c90869030908790600401614cb2565b6020604051808303816000875af115801561349b573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906134bf9190614c6c565b506000731f64078e323c37b3aca709fb9146a73c3f3c4617638d3d803d846134e689612f48565b6040516001600160e01b031960e085901b16815260048101929092526024820152604401602060405180830381865af4158015613527573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061354b9190614c3d565b9050610d1760048801858361309c565b8054600081815260038301602052604090206124d881612f33565b6135af6040518060c001604052806000815260200160008152602001600081526020016000815260200160008152602001600081525090565b604080516020810190915260008152601483015460118401546000906135d6908390614bc5565b6040805160c08101825260198801548152601a880154602080830191909152601b89015482840152601c8901546060830152601d8901546080830152601e89015460a083015282518082018452601f8a01548152835180850190945260168a01546001600160a01b0316845260178a0154918401919091529096509450909150600090613671908690869061366a9061403b565b85856143a2565b505050915091565b6001600160a01b038116600090815260208690526040812054819081908581106137ae576020880151604051638d3d803d60e01b8152731f64078e323c37b3aca709fb9146a73c3f3c461791638d3d803d916136e2918a91600401918252602082015260400190565b602060405180830381865af41580156136ff573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906137239190614c3d565b6040808a01519051638d3d803d60e01b8152600481018990526024810191909152909450731f64078e323c37b3aca709fb9146a73c3f3c461790638d3d803d90604401602060405180830381865af4158015613783573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906137a79190614c3d565b925061398f565b806137b98188614b99565b9250866137c68285614bc5565b146137d3576137d3614c56565b6020890151604051638d3d803d60e01b8152731f64078e323c37b3aca709fb9146a73c3f3c461791638d3d803d91613818918591600401918252602082015260400190565b602060405180830381865af4158015613835573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906138599190614c3d565b6040808b01519051638d3d803d60e01b8152600481018490526024810191909152909550731f64078e323c37b3aca709fb9146a73c3f3c461790638d3d803d90604401602060405180830381865af41580156138b9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906138dd9190614c3d565b60208a0151604051638d3d803d60e01b8152919550600091731f64078e323c37b3aca709fb9146a73c3f3c461791638d3d803d91613928918891600401918252602082015260400190565b602060405180830381865af4158015613945573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906139699190614c3d565b90506139758187614bc5565b955080896000018181516139899190614b99565b90525050505b50955095509592505050565b600081600101546000036139b157506002015490565b816001015482600201546139c59190614bc5565b6002830181905560006001909301929092555090565b828460030160008282546139ef9190614bc5565b9250508190555082856004016000828254613a0a9190614bc5565b9250508190555081856005016000828254613a259190614b99565b90915550613a359050858261452f565b5050505050565b6001870154613a58906001600160a01b031683883089866142f7565b60018701546040516323b872dd60e01b81526001600160a01b03909116906323b872dd90613a8e90899030908a90600401614cb2565b6020604051808303816000875af1158015613aad573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613ad19190614c6c565b5060408051808201825260018a01546001600160a01b03908116825260028b0154811660208084019190915283518082018552600090528351908101845291511690819052905163a9059cbb60e01b815263a9059cbb90613b389089908890600401614bac565b6020604051808303816000875af1158015613b57573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613b7b9190614c6c565b5060408051808201825260018a01546001600160a01b03908116825260028b0154166020909101819052905163a9059cbb60e01b815263a9059cbb90613bc79089908790600401614bac565b6020604051808303816000875af1158015613be6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613c0a9190614c6c565b505050505050505050565b6000731f64078e323c37b3aca709fb9146a73c3f3c461763f2a5e970600160601b6040516001600160e01b031960e084901b1681526001600160a01b03909116600482015260126024820152604401602060405180830381865af4158015613c81573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613ca59190614c3d565b9050600080613cb7601985018461454b565b915091508184600a016006016001016000828254613cd59190614bc5565b9091555050601484018054829190600090613cf1908490614bc5565b90915550506000601f8501555b50505050565b6126238282604051602401613d1a929190614cd6565b60408051601f198184030181529190526020810180516001600160e01b0316632d839cb360e21b1790526145de565b825460405163a9059cbb60e01b81526001600160a01b039091169063a9059cbb90613d7a9084908690600401614bac565b6020604051808303816000875af1158015613d99573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613cfe9190614c6c565b82546040516323b872dd60e01b81526001600160a01b03909116906323b872dd90613d7a90849030908790600401614cb2565b8154600081815260038085016020908152604092839020835160a081018552815460ff8116151582526001600160a01b0361010090910481169382019390935260018201549092169382019390935260028301546060820152908201546080820152613cfe903085612fd8565b82516040516340c10f1960e01b81526001600160a01b03909116906340c10f199061306e9085908590600401614bac565b613ebb604051806060016040528060006001600160a01b0316815260200160008152602001600081525090565b50604080516060810182526001600160a01b0390921682526000602083018190529082015290565b613f1c6040518060c001604052806000815260200160008152602001600081526020016000815260200160008152602001600081525090565b506040805160c0810182529384526000602085018190529084019290925260608301526080820181905260a082015290565b613f57816145e7565b612f45576040516305bb301f60e51b815260040160405180910390fd5b613f7d8161311b565b15612f4557604051630407b05b60e31b815260040160405180910390fd5b808260010154613fab9190614bc5565b82600101819055505050565b808260010154613fab9190614b99565b613fd08161311b565b612f455760405163d0404f8560e01b815260040160405180910390fd5b6000670de0b6b3a7640000826140038583614d2b565b61400d9190614d42565b6140179086614d2b565b6117189190614d42565b60008181526003840160205260409020613cfe8184614616565b600081600001516001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612f9f573d6000803e3d6000fd5b83546003850154600090614094908590614bc5565b604051633d6690db60e01b815260048101829052602481018790526044810184905290915060009081908190731f64078e323c37b3aca709fb9146a73c3f3c461790633d6690db90606401606060405180830381865af41580156140fc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906141209190614d64565b60038c0183905560068c0182905560018c0181905560048c01549295509093509150600090614150908890614bc5565b604051633d6690db60e01b815260048101829052602481018b905260448101889052909150731f64078e323c37b3aca709fb9146a73c3f3c461790633d6690db90606401606060405180830381865af41580156141b1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906141d59190614d64565b60048d0183905560058d0183905560028d0181905560068d015460038e0154939750919550935061420591614bc5565b851461421357614213614c56565b50505050505050505050565b600080828460000160000160008282546142399190614b99565b90915550614249905084846146aa565b6003860180549294509092508391600090614265908490614b99565b9091555050600484018054829190600090614281908490614b99565b925050819055509250929050565b6001600160a01b0381166000908152600784016020526040812080548492906106f0908490614b99565b60008060006142c98686866147c2565b600689018054939650919450925082916000906142e7908490614b99565b9250508190555050935093915050565b60006143028661486e565b80516020820151604080840151905163d505accf60e01b81526001600160a01b038a811660048301528981166024830152604482018990526064820188905260ff909416608482015260a481019290925260c482015291925088169063d505accf9060e401600060405180830381600087803b15801561438157600080fd5b505af1158015614395573d6000803e3d6000fd5b5050505050505050505050565b845160608601516000906143b7908590614bc5565b604051633d6690db60e01b815260048101829052602481018790526044810184905290915060009081908190731f64078e323c37b3aca709fb9146a73c3f3c461790633d6690db90606401606060405180830381865af415801561441f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906144439190614d64565b60608d01839052818c5260208d0181905260808d0151929550909350915060009061446f908890614bc5565b604051633d6690db60e01b815260048101829052602481018b905260448101889052909150731f64078e323c37b3aca709fb9146a73c3f3c461790633d6690db90606401606060405180830381865af41580156144d0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906144f49190614d64565b60808e0183905260a08e0183905260408e018190528c5160608f0151939750919550935061452191614bc5565b851461439557614395614c56565b80826002015461453f9190614b99565b82600201819055505050565b60068201546040516001629a5d1f60e01b0319815260048101829052602481018390526000918291731f64078e323c37b3aca709fb9146a73c3f3c46179063ff65a2e1906044016040805180830381865af41580156145ae573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906145d29190614c8e565b90969095509350505050565b612f45816148de565b805460009061010090046001600160a01b031615801590610a98575050600101546001600160a01b0316151590565b8154604051630852cd8d60e31b8152600481018390526101009091046001600160a01b0316906342966c6890602401600060405180830381600087803b15801561465f57600080fd5b505af1158015614673573d6000803e3d6000fd5b505050506001820154604051630852cd8d60e31b8152600481018390526001600160a01b03909116906342966c6890602401613303565b6001820154604051638d3d803d60e01b81526000918291731f64078e323c37b3aca709fb9146a73c3f3c461791638d3d803d916146f4918791600401918252602082015260400190565b602060405180830381865af4158015614711573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906147359190614c3d565b6002850154604051638d3d803d60e01b8152600481018690526024810191909152909250731f64078e323c37b3aca709fb9146a73c3f3c461790638d3d803d90604401602060405180830381865af4158015614795573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906147b99190614c3d565b90509250929050565b60008060006147d186866146aa565b6001880154604051638d3d803d60e01b81526004810188905260248101919091529194509250731f64078e323c37b3aca709fb9146a73c3f3c461790638d3d803d90604401602060405180830381865af4158015614833573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906148579190614c3d565b90506148638184614bc5565b925093509350939050565b604080516060810182526000808252602082018190529181019190915281516041146148b257815160405163058676ad60e31b81526004016119d991815260200190565b506020818101516040808401516060948501518251958601835260001a85529284019190915282015290565b60006a636f6e736f6c652e6c6f679050600080835160208501845afa505050565b6000806040838503121561491257600080fd5b50508035926020909101359150565b6001600160a01b0381168114612f4557600080fd5b60008060006060848603121561494b57600080fd5b833561495681614921565b95602085013595506040909401359392505050565b60008060006060848603121561498057600080fd5b83359250602084013561499281614921565b929592945050506040919091013590565b6000602082840312156149b557600080fd5b5035919050565b600080604083850312156149cf57600080fd5b82356149da81614921565b915060208301356149ea81614921565b809150509250929050565b600080600060608486031215614a0a57600080fd5b505081359360208301359350604090920135919050565b634e487b7160e01b600052604160045260246000fd5b600080600080600060a08688031215614a4f57600080fd5b853594506020860135935060408601359250606086013567ffffffffffffffff80821115614a7c57600080fd5b818801915088601f830112614a9057600080fd5b813581811115614aa257614aa2614a21565b604051601f8201601f19908116603f01168101908382118183101715614aca57614aca614a21565b816040528281528b6020848701011115614ae357600080fd5b82602086016020830137600092810160200192909252509699959850939660800135949350505050565b600080600080600060a08688031215614b2557600080fd5b8535614b3081614921565b94506020860135614b4081614921565b94979496505050506040830135926060810135926080909101359150565b60008060408385031215614b7157600080fd5b8235915060208301356149ea81614921565b634e487b7160e01b600052601160045260246000fd5b81810381811115610a9857610a98614b83565b6001600160a01b03929092168252602082015260400190565b80820180821115610a9857610a98614b83565b60008060408385031215614beb57600080fd5b8251614bf681614921565b60208401519092506149ea81614921565b600060018201614c1957614c19614b83565b5060010190565b600060208284031215614c3257600080fd5b815161089a81614921565b600060208284031215614c4f57600080fd5b5051919050565b634e487b7160e01b600052600160045260246000fd5b600060208284031215614c7e57600080fd5b8151801515811461089a57600080fd5b60008060408385031215614ca157600080fd5b505080516020909101519092909150565b6001600160a01b039384168152919092166020820152604081019190915260600190565b604081526000835180604084015260005b81811015614d045760208187018101516060868401015201614ce7565b506000606082850101526060601f19601f8301168401019150508260208301529392505050565b8082028115828204841417610a9857610a98614b83565b600082614d5f57634e487b7160e01b600052601260045260246000fd5b500490565b600080600060608486031215614d7957600080fd5b835192506020840151915060408401519050925092509256fea26469706673582212204f8cd681b87c27a2bc7b9f7c13d311132cd021627cde3ebd18adbd472651373f64736f6c63430008180033000000000000000000000000e6771c4a288cd74a46af81ebe8be8cc66edc6cfe

Deployed Bytecode

0x608060405234801561001057600080fd5b50600436106102535760003560e01c80636910a77d11610146578063ab50b4c1116100c3578063cd3c0a5011610087578063cd3c0a5014610563578063d13f90b414610576578063e93036a614610589578063ea8b6eb71461059c578063f18eb1da146105af578063f7268185146105c257600080fd5b8063ab50b4c1146104fc578063b2418a811461050f578063b2810ef514610522578063b431169f14610535578063c45a01551461054857600080fd5b806393dafb741161010a57806393dafb741461049d578063964a85b9146104b0578063a1d5dae1146104c3578063a208bc0a146104d6578063a5af6d9a146104e957600080fd5b80636910a77d1461043e5780636c1167c0146104515780636c82b692146104645780638a4b7a52146104775780638ffe8ee41461048a57600080fd5b806335cfbbf6116101d45780634281cef0116101985780634281cef0146103c45780635363bc3d146103d75780635b239c2c146103ea5780635d5ca2d9146103fd57806360fc15e71461042b57600080fd5b806335cfbbf61461036557806336ef80db146103785780633af8d4e41461038b5780633bd9cf8d1461039e5780633dccb39b146103b157600080fd5b80630f57e8481161021b5780630f57e848146102b95780630fcf2edf146102df5780632103912b1461031f5780632347fd60146103325780633407b0a31461034557600080fd5b806302fe2c2714610258578063035399031461026d578063061c52211461028057806308b9c146146102935780630a33f24d146102a6575b600080fd5b61026b6102663660046148ff565b6105d5565b005b61026b61027b366004614936565b610673565b61026b61028e36600461496b565b6106fa565b61026b6102a13660046148ff565b610768565b61026b6102b43660046148ff565b6107f0565b6102cc6102c73660046149a3565b610883565b6040519081526020015b60405180910390f35b61030a6102ed3660046149a3565b6000908152602081905260409020601c810154601d909101549091565b604080519283526020830191909152016102d6565b61026b61032d366004614936565b6108a1565b61026b6103403660046148ff565b61091e565b6102cc6103533660046149a3565b60009081526020819052604090205490565b61026b6103733660046148ff565b6109b7565b6102cc6103863660046149bc565b610a50565b61030a6103993660046149f5565b610a9e565b61026b6103ac366004614936565b610afd565b61026b6103bf366004614936565b610b80565b61026b6103d236600461496b565b610c03565b6102cc6103e53660046149a3565b610c78565b61026b6103f8366004614a37565b610c80565b61041061040b3660046148ff565b610d20565b604080519384526020840192909252908201526060016102d6565b61026b610439366004614936565b610d4b565b61041061044c3660046148ff565b610dce565b61026b61045f366004614a37565b610deb565b61026b6104723660046148ff565b610eac565b61026b6104853660046148ff565b610f45565b61026b6104983660046148ff565b610fd8565b61026b6104ab3660046148ff565b611071565b61026b6104be3660046149f5565b6110c7565b61026b6104d1366004614936565b611236565b6102cc6104e43660046149a3565b6112b3565b61026b6104f73660046148ff565b6112cb565b6102cc61050a3660046149f5565b61135e565b61026b61051d36600461496b565b6113b7565b61026b6105303660046148ff565b61144a565b6104106105433660046148ff565b611497565b6001546040516001600160a01b0390911681526020016102d6565b61026b610571366004614936565b6114fc565b61026b610584366004614b0d565b61157f565b6102cc610597366004614b5e565b6116f3565b61026b6105aa366004614936565b611720565b61026b6105bd3660046148ff565b61179d565b61030a6105d03660046148ff565b611830565b600082815260208190526040902082906105ee90611858565b61060b576040516305bb301f60e51b815260040160405180910390fd5b60008381526020819052604081209061062582338661188b565b9050336001600160a01b031681867f2be78f44ec51653e82a47117fec352f06123e1378c7b304fbe431681a87679d58760405161066491815260200190565b60405180910390a45050505050565b604051635c58950f60e11b8152600481018390526001600160a01b0384169063b8b12a1e90602401600060405180830381600087803b1580156106b557600080fd5b505af11580156106c9573d6000803e3d6000fd5b5050506000828152602081905260408120600e0180548593509091906106f0908490614b99565b9091555050505050565b60008381526020819052604090206107148133858561199f565b6001600160a01b038316336001600160a01b0316857fd87cfe86ee1e5fdc646d6804cb83d3a064572208e1e6da7e92bdd16d9420daf98560405161075a91815260200190565b60405180910390a450505050565b6000828152602081905260408120908080610784843387611a81565b9250925092506107913390565b6001600160a01b031682877f5e639cd9080405443c0a7a5e722321527207147b4f189c36d757700d59c716378689866040516107e0939291909283526020830191909152604082015260600190565b60405180910390a4505050505050565b60008181526020819052604090819020600201549051635c58950f60e11b8152600481018490526001600160a01b0390911690819063b8b12a1e90602401600060405180830381600087803b15801561084857600080fd5b505af115801561085c573d6000803e3d6000fd5b5050506000838152602081905260408120600f0180548693509091906106f0908490614b99565b600081815260208190526040812061089a81611c0f565b9392505050565b604051635c58950f60e11b8152600481018390526001600160a01b0384169063b8b12a1e90602401600060405180830381600087803b1580156108e357600080fd5b505af11580156108f7573d6000803e3d6000fd5b505050600082815260208190526040812060080180548593509091906106f0908490614b99565b600081815260208190526040908190206002015490516340c10f1960e01b81526001600160a01b039091169081906340c10f19906109629030908790600401614bac565b600060405180830381600087803b15801561097c57600080fd5b505af1158015610990573d6000803e3d6000fd5b5050506000838152602081905260408120600f0180548693509091906106f0908490614bc5565b600081815260208190526040908190206001015490516340c10f1960e01b81526001600160a01b039091169081906340c10f19906109fb9030908790600401614bac565b600060405180830381600087803b158015610a1557600080fd5b505af1158015610a29573d6000803e3d6000fd5b505050600083815260208190526040812060060180548693509091906106f0908490614bc5565b6000610a95610a908484604080518082019091526000808252602082015250604080518082019091526001600160a01b0392831681529116602082015290565b611c2d565b90505b92915050565b600083815260208190526040812081908590610ab990611858565b610ad6576040516305bb301f60e51b815260040160405180910390fd5b6000868152602081905260409020610aef818787611c7e565b909890975095505050505050565b6040516340c10f1960e01b81526001600160a01b038416906340c10f1990610b2b9030908690600401614bac565b600060405180830381600087803b158015610b4557600080fd5b505af1158015610b59573d6000803e3d6000fd5b505050600082815260208190526040812060070180548593509091906106f0908490614bc5565b6040516340c10f1960e01b81526001600160a01b038416906340c10f1990610bae9030908690600401614bac565b600060405180830381600087803b158015610bc857600080fd5b505af1158015610bdc573d6000803e3d6000fd5b5050506000828152602081905260408120600d0180548593509091906106f0908490614bc5565b60008381526020819052604081209080610c1f83338787611d36565b91509150846001600160a01b0316867f6886cf6a5c29c986e34ca4d560ea1c4bbb880221c387915f2a1ca2a3c5dd066a8484604051610c68929190918252602082015260400190565b60405180910390a3505050505050565b600081610a98565b60008581526020819052604090208590610c9990611858565b610cb6576040516305bb301f60e51b815260040160405180910390fd5b6000868152602081905260409020336001600160a01b031686887f15eb4c60bee595ca5f7c62c20f2f7f7e52f43fa459fba81b39271523a0e85f3d88604051610d0191815260200190565b60405180910390a4610d1781338789888861200f565b50505050505050565b600082815260208190526040812081908190610d3c8186612044565b91989097509095509350505050565b6040516340c10f1960e01b81526001600160a01b038416906340c10f1990610d799030908690600401614bac565b600060405180830381600087803b158015610d9357600080fd5b505af1158015610da7573d6000803e3d6000fd5b505050600082815260208190526040812060080180548593509091906106f0908490614bc5565b600082815260208190526040812081908190610d3c818633612210565b60008581526020819052604090208590610e0490611858565b610e21576040516305bb301f60e51b815260040160405180910390fd5b60008681526020819052604081209080610e3f8333898b8a8a612399565b91509150610e4a3390565b6001600160a01b0316888a7fc901c80d52ba5274697ecdce2dca541020aa66e35eef49e801708ae75bd36e2a8a8686604051610e99939291909283526020830191909152604082015260600190565b60405180910390a4505050505050505050565b600081815260208190526040908190206001015490516340c10f1960e01b81526001600160a01b039091169081906340c10f1990610ef09030908790600401614bac565b600060405180830381600087803b158015610f0a57600080fd5b505af1158015610f1e573d6000803e3d6000fd5b5050506000838152602081905260408120600c0180548693509091906106f0908490614bc5565b60008181526020819052604090819020600101549051635c58950f60e11b8152600481018490526001600160a01b0390911690819063b8b12a1e90602401600060405180830381600087803b158015610f9d57600080fd5b505af1158015610fb1573d6000803e3d6000fd5b505050600083815260208190526040812060060180548693509091906106f0908490614b99565b600081815260208190526040908190206002015490516340c10f1960e01b81526001600160a01b039091169081906340c10f199061101c9030908790600401614bac565b600060405180830381600087803b15801561103657600080fd5b505af115801561104a573d6000803e3d6000fd5b505050600083815260208190526040812060090180548693509091906106f0908490614bc5565b600082815260208190526040902061108a813384612475565b604051828152339084907f9c089cc0fdbab29c0e65f3512c8fc12103af382382dabe473b3daffcd1b5487e906020015b60405180910390a3505050565b600083815260208190526040902083906110e090611858565b6110fd576040516305bb301f60e51b815260040160405180910390fd5b600084815260208190526040808220600180820154600283015491549351630b4edfaf60e11b81526001600160a01b039283166004820181905291831660248201819052306044830152606482018a905260848201899052939593949193928392169063169dbf5e9060a40160408051808303816000875af1158015611187573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111ab9190614bd8565b8654919350915060009086826111c083614c07565b9091555086549091506111d687858584866124dd565b6111e087836125e2565b604080516001600160a01b038086168252861660208201528b9183918e917f5184c4193f766fd6977e52a68321d6f109de1a0745b553059c984373e83e9db0910160405180910390a45050505050505050505050565b604051635c58950f60e11b8152600481018390526001600160a01b0384169063b8b12a1e90602401600060405180830381600087803b15801561127857600080fd5b505af115801561128c573d6000803e3d6000fd5b5050506000828152602081905260408120600d0180548593509091906106f0908490614b99565b6000818152602081905260408120600581015461089a565b60008181526020819052604090819020600101549051635c58950f60e11b8152600481018490526001600160a01b0390911690819063b8b12a1e90602401600060405180830381600087803b15801561132357600080fd5b505af1158015611337573d6000803e3d6000fd5b5050506000838152602081905260408120600c0180548693509091906106f0908490614b99565b6000838152602081905260408120849061137790611858565b611394576040516305bb301f60e51b815260040160405180910390fd5b60008581526020819052604090206113ad818587612627565b9695505050505050565b60008381526020819052604081209080806113d4843388886126cb565b925092509250856001600160a01b03166113eb3390565b6001600160a01b0316887fb52292f46324c668438c13eae0859c783b8516639ed3b8c8c2ab842e63e9dea8868686604051611439939291909283526020830191909152604082015260600190565b60405180910390a450505050505050565b6000828152602081905260409020611463813384612aa9565b604051828152339084907f7f6aa3e2623e42a2bd437a912b332ba383b4004a593c06ae69511f55d04ef8ae906020016110ba565b6000806000846114b7600080838152602001908152602001600020611858565b6114d4576040516305bb301f60e51b815260040160405180910390fd5b60008681526020819052604090206114ec8187612c56565b9199909850909650945050505050565b6040516340c10f1960e01b81526001600160a01b038416906340c10f199061152a9030908690600401614bac565b600060405180830381600087803b15801561154457600080fd5b505af1158015611558573d6000803e3d6000fd5b5050506000828152602081905260408120600e0180548593509091906106f0908490614bc5565b60006115bc8686604080518082019091526000808252602082015250604080518082019091526001600160a01b0392831681529116602082015290565b905060006115c982611c2d565b60008181526020819052604090209091506115e381611858565b156116005760405162dc149f60e41b815260040160405180910390fd5b600154604051637d39041b60e11b81526001600160a01b0389811660048301528a8116602483015230604483015290911690600090829063fa720836906064016020604051808303816000875af115801561165f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116839190614c20565b905061168f8386612d0f565b6116a083600a01828a8a8a8e612d8f565b6040516001600160a01b038281168252808b1691908c169086907fad7174cdf644277b474d89119511e4a5ba3aa0af1ee78e0a74fd2979aace6c159060200160405180910390a450505050505050505050565b6000828152602081815260408083206001600160a01b03851684528083019092528220545b949350505050565b604051635c58950f60e11b8152600481018390526001600160a01b0384169063b8b12a1e90602401600060405180830381600087803b15801561176257600080fd5b505af1158015611776573d6000803e3d6000fd5b505050600082815260208190526040812060070180548593509091906106f0908490614b99565b60008181526020819052604090819020600201549051635c58950f60e11b8152600481018490526001600160a01b0390911690819063b8b12a1e90602401600060405180830381600087803b1580156117f557600080fd5b505af1158015611809573d6000803e3d6000fd5b505050600083815260208190526040812060090180548693509091906106f0908490614b99565b6000828152602081905260408120819061184a8185612e62565b919791965090945050505050565b6040805180820190915260018201546001600160a01b0390811682526002830154166020820152600090610a9890612f09565b8254600081815260038501602052604090206118a681612f33565b6000731f64078e323c37b3aca709fb9146a73c3f3c4617630e042cec856118cc85612f48565b6040516001600160e01b031960e085901b16815260048101929092526024820152604401602060405180830381865af415801561190d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119319190614c3d565b9050611941600487018587612fc3565b6040805160a081018252835460ff8116151582526001600160a01b0361010090910481166020830152600185015416918101919091526002830154606082015260038301546080820152611996908683612fd8565b50509392505050565b6001600160a01b0383166000908152602080860190526040812054908190036119e25760405163472511eb60e11b81523360048201526024015b60405180910390fd5b81811015611a1c5760405163db42144d60e01b81526001600160a01b038516600482015260248101839052604481018290526064016119d9565b6001600160a01b038316600090815260208087019052604081208054849290611a46908490614bc5565b90915550506001600160a01b038416600090815260208087019052604081208054849290611a75908490614b99565b90915550505050505050565b8254600081815260038501602052604081209091908290611aa181612f33565b611aaa81612f48565b604051638d3d803d60e01b81526004810187905260248101829052909250731f64078e323c37b3aca709fb9146a73c3f3c461790638d3d803d90604401602060405180830381865af4158015611b04573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611b289190614c3d565b9350611b3860048801878661309c565b600181015460405163079cc67960e41b81526001600160a01b03909116906379cc679090611b6c9089908990600401614bac565b600060405180830381600087803b158015611b8657600080fd5b505af1158015611b9a573d6000803e3d6000fd5b5050825460405163079cc67960e41b81526101009091046001600160a01b031692506379cc67909150611bd39089908990600401614bac565b600060405180830381600087803b158015611bed57600080fd5b505af1158015611c01573d6000803e3d6000fd5b505050505093509350939050565b80546000818152600383016020526040812090919061171881612f48565b60008082604051602001611c5f919081516001600160a01b039081168252602092830151169181019190915260400190565b60408051601f1981840301815291905280516020909101209392505050565b600082815260038401602052604081208190611c99816130b1565b6001810154604080516318160ddd60e01b815290516000926001600160a01b0316916318160ddd9160048083019260209291908290030181865afa158015611ce5573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d099190614c3d565b90506000611d19600489016130c3565b9050611d27888784846130ed565b90999098509650505050505050565b8354600081815260038601602090815260408083206001600160a01b03881684528289019092528220549192839290919080158015611d7b5750611d798261311b565b155b15611da45760405163472511eb60e11b81526001600160a01b03891660048201526024016119d9565b611dad8261311b565b158015611db957508581105b15611df05760405163db42144d60e01b81526001600160a01b038916600482015260248101879052604481018290526064016119d9565b611df98261311b565b8015611e205750600883901c600090815260188a016020526040902054600160ff85161b16155b15611e4157611e2f8984613196565b600b89015415611e4157611e41614c56565b60168901546001600160a01b0316600080611e6060198d018a8d613237565b809450819550829a50839b50505050508b60010160010160009054906101000a90046001600160a01b03166001600160a01b031663a9059cbb8b8a6040518363ffffffff1660e01b8152600401611eb8929190614bac565b6020604051808303816000875af1158015611ed7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611efb9190614c6c565b5060018c015460405163a9059cbb60e01b81526001600160a01b039091169063a9059cbb90611f30908d908b90600401614bac565b6020604051808303816000875af1158015611f4f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f739190614c6c565b5088611f7f8383614bc5565b14611f8c57611f8c614c56565b611f9960168d01826132cd565b81156120005760405163079cc67960e41b81526001600160a01b038416906379cc679090611fcd908e908690600401614bac565b600060405180830381600087803b158015611fe757600080fd5b505af1158015611ffb573d6000803e3d6000fd5b505050505b50505050505094509492505050565b6000838152600387016020526040902061202881612f33565b612036876004018287613331565b610d1787828589898761337b565b60008060006120528561355b565b5060108401546014850154601186015460009161206e91614bc5565b9050731f64078e323c37b3aca709fb9146a73c3f3c4617637b7ddb3b8288600a01600c0160000160009054906101000a90046001600160a01b03166001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156120e6573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061210a9190614c3d565b6040516001600160e01b031960e085901b1681526004810192909252602482015260448101889052606401602060405180830381865af4158015612152573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121769190614c3d565b601087015460405163b5b4115f60e01b8152600481018390526024810191909152909450731f64078e323c37b3aca709fb9146a73c3f3c46179063b5b4115f90604401602060405180830381865af41580156121d6573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906121fa9190614c3d565b92506122068385614b99565b9350509250925092565b8254600081815260038501602090815260408083206001600160a01b0386168452828801909252822054919283928392908015801561225557506122538261311b565b155b1561227e5760405163472511eb60e11b81526001600160a01b03881660048201526024016119d9565b6122878261311b565b15801561229357508781105b156122ca5760405163db42144d60e01b81526001600160a01b038816600482015260248101899052604481018290526064016119d9565b6040805160c08101825260198b01548152601a8b0154602080830191909152601b8c015482840152601c8c01546060830152601d8c01546080830152601e8c015460a08301528251908101909252601f8b01548252906123298461311b565b80156123505750600885901c600090815260188c016020526040902054600160ff87161b16155b156123755761235e8b613576565b600b8d015491935091501561237557612375614c56565b61238560208c0183838d8d613679565b919d909c50909a5098505050505050505050565b6000838152600387016020526040812081906123b4816130b1565b6001810154604080516318160ddd60e01b815290516000926001600160a01b0316916318160ddd9160048083019260209291908290030181865afa158015612400573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124249190614c3d565b9050600061243460048c0161399b565b90506124428b8a84846130ed565b909550935061245760048c01848b88886139db565b6124678b848c8c89898d8d613a3c565b505050965096945050505050565b61247e8361355b565b6001600160a01b0382166000908152602080850190526040812080548392906124a8908490614bc5565b90915550506019830180548291906000906124c4908490614bc5565b909155506124d89050601684018284612fc3565b505050565b80156124fe57600081815260038601602052604090206124fc816130b1565b505b61256583856040805160a081018252600080825260208201819052918101829052606081018290526080810191909152506040805160a08101825260008082526001600160a01b039485166020830152929093169083015260608201819052608082015290565b60009283526003958601602090815260409384902082518154928401516001600160a81b0319909316901515610100600160a81b031916176101006001600160a01b0393841602178155938201516001850180546001600160a01b0319169190921617905560608101516002840155608001519190940155505050565b806000036125ee575050565b600881901c6000908152601883016020526040902054600160ff83161b1661261a5761261a8282613196565b61262382613c15565b5050565b6000828152600384016020526040812061264081612f33565b6000731f64078e323c37b3aca709fb9146a73c3f3c4617638d3d803d8561266685612f48565b6040516001600160e01b031960e085901b16815260048101929092526024820152604401602060405180830381865af41580156126a7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113ad9190614c3d565b60008060006126d98761355b565b5085546010870154601488015460118901549192916000916126fa91614bc5565b905061272560405180604001604052806007815260200166746f74616c526160c81b81525082613d04565b6016890154604080516318160ddd60e01b81529051731f64078e323c37b3aca709fb9146a73c3f3c461792637b7ddb3b9285926001600160a01b03909216916318160ddd916004808201926020929091908290030181865afa15801561278f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127b39190614c3d565b6040516001600160e01b031960e085901b1681526004810192909252602482015260448101899052606401602060405180830381865af41580156127fb573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061281f9190614c3d565b94506000731f64078e323c37b3aca709fb9146a73c3f3c461763f2a5e970600160601b6040516001600160e01b031960e084901b1681526001600160a01b03909116600482015260126024820152604401602060405180830381865af415801561288d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906128b19190614c3d565b6040516001629a5d1f60e01b0319815260048101889052602481018290529091506000908190731f64078e323c37b3aca709fb9146a73c3f3c46179063ff65a2e1906044016040805180830381865af4158015612912573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129369190614c8e565b91509150818c600a0160060160010160008282546129549190614b99565b909155505060148c018054829190600090612970908490614b99565b909155505060108c015460405163b5b4115f60e01b8152731f64078e323c37b3aca709fb9146a73c3f3c46179163b5b4115f916129ba918c91600401918252602082015260400190565b602060405180830381865af41580156129d7573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906129fb9190614c3d565b60158d0180549198508891600090612a14908490614bc5565b90915550612a2490508789614b99565b60168d015460405163079cc67960e41b81529199506001600160a01b0316906379cc679090612a59908e908d90600401614bac565b600060405180830381600087803b158015612a7357600080fd5b505af1158015612a87573d6000803e3d6000fd5b50612a9a92505050600a8d01898c613d49565b50505050509450945094915050565b612ab28361355b565b612ac0600a84018284613dbd565b6000731f64078e323c37b3aca709fb9146a73c3f3c461763f2a5e970600160601b6040516001600160e01b031960e084901b1681526001600160a01b03909116600482015260126024820152604401602060405180830381865af4158015612b2c573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612b509190614c3d565b6040516001629a5d1f60e01b0319815260048101849052602481018290529091506000908190731f64078e323c37b3aca709fb9146a73c3f3c46179063ff65a2e1906044016040805180830381865af4158015612bb1573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612bd59190614c8e565b915091508186600a016006016001016000828254612bf39190614bc5565b9091555050601486018054829190600090612c0f908490614bc5565b90915550612c1f90508682613df0565b6040805180820190915260168701546001600160a01b0316815260178701546020820152612c4e908686613e5d565b505050505050565b81546000818152600384016020526040812090918291612c7581612f33565b6000731f64078e323c37b3aca709fb9146a73c3f3c4617630e042cec87612c9b85612f48565b6040516001600160e01b031960e085901b16815260048101929092526024820152604401602060405180830381865af4158015612cdc573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612d009190614c3d565b97889750929550919350505050565b80516001830180546001600160a01b03199081166001600160a01b03938416179091556020830151600285018054909216928116929092179055612d5290613e8e565b80516004840180546001600160a01b0319166001600160a01b03909216919091179055602081015160058401556040015160069092019190915550565b612d9a848484613ee3565b80516006880155602080820151600789015560408083015160088a0155606083015160098a01556080830151600a8a015560a090920151600b89015581518083018352600080825290820181905282518084019093526001600160a01b03881680845292909101819052600c880180546001600160a01b031916909217909155600d870155612e2881613e8e565b805187546001600160a01b0319166001600160a01b0390911617875560208101516001880155604001516002909601959095555050505050565b8154600081815260038401602052604081209091908290612e8281612f33565b612e8b81612f48565b604051638d3d803d60e01b81526004810187905260248101829052909250731f64078e323c37b3aca709fb9146a73c3f3c461790638d3d803d90604401602060405180830381865af4158015612ee5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906122069190614c3d565b80516000906001600160a01b031615801590610a98575050602001516001600160a01b0316151590565b612f3c81613f4e565b612f4581613f74565b50565b60008160000160019054906101000a90046001600160a01b03166001600160a01b0316633ba0b9a96040518163ffffffff1660e01b8152600401602060405180830381865afa158015612f9f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a989190614c3d565b612fcd8383613f9b565b6124d8838383613dbd565b82602001516001600160a01b03166340c10f1983836040518363ffffffff1660e01b815260040161300a929190614bac565b600060405180830381600087803b15801561302457600080fd5b505af1158015613038573d6000803e3d6000fd5b5050505082604001516001600160a01b03166340c10f1983836040518363ffffffff1660e01b815260040161306e929190614bac565b600060405180830381600087803b15801561308857600080fd5b505af1158015610d17573d6000803e3d6000fd5b6130a68382613fb7565b6124d8838284613d49565b6130ba81613f4e565b612f4581613fc7565b600081600101546000036130d957506002015490565b81600101548260020154610a989190614bc5565b60098401546000908190613102868287613fed565b925061310f868587613fed565b91505094509492505050565b60008160000160019054906101000a90046001600160a01b03166001600160a01b0316632f13b60c6040518163ffffffff1660e01b8152600401602060405180830381865afa158015613172573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a989190614c6c565b600881901c600090815260188301602052604090208054600160ff84161b179055601482015460118301546000906131cf908390614bc5565b90506131dc848385614021565b6040805180820190915260168501546001600160a01b0316815260178501546020820152600090819061321e906132129061403b565b6019880190858461407f565b5050600060118501819055601490940193909355505050565b6001600160a01b03811660009081526007840160205260408120548190819081908681106132815786915061326c888861421f565b909550935061327c88888861428f565b6132c3565b90508061328e8188614b99565b92508661329b8385614bc5565b146132a8576132a8614c56565b6132b38882856142b9565b90955093506132c388828861428f565b5093509350935093565b6132d78282613fb7565b8154604051630852cd8d60e31b8152600481018390526001600160a01b03909116906342966c68906024015b600060405180830381600087803b15801561331d57600080fd5b505af1158015612c4e573d6000803e3d6000fd5b808360030160008282546133459190614bc5565b92505081905550808360050160008282546133609190614bc5565b92505081905550808260020160008282546106f09190614bc5565b84546133999061010090046001600160a01b031685853086866142f7565b84546040516323b872dd60e01b81526101009091046001600160a01b0316906323b872dd906133d090869030908790600401614cb2565b6020604051808303816000875af11580156133ef573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906134139190614c6c565b5060408051808201825260018801546001600160a01b039081168252600289015481166020808401919091528351808201855260009052835190810184529151169081905290516323b872dd60e01b81526323b872dd9061347c90869030908790600401614cb2565b6020604051808303816000875af115801561349b573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906134bf9190614c6c565b506000731f64078e323c37b3aca709fb9146a73c3f3c4617638d3d803d846134e689612f48565b6040516001600160e01b031960e085901b16815260048101929092526024820152604401602060405180830381865af4158015613527573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061354b9190614c3d565b9050610d1760048801858361309c565b8054600081815260038301602052604090206124d881612f33565b6135af6040518060c001604052806000815260200160008152602001600081526020016000815260200160008152602001600081525090565b604080516020810190915260008152601483015460118401546000906135d6908390614bc5565b6040805160c08101825260198801548152601a880154602080830191909152601b89015482840152601c8901546060830152601d8901546080830152601e89015460a083015282518082018452601f8a01548152835180850190945260168a01546001600160a01b0316845260178a0154918401919091529096509450909150600090613671908690869061366a9061403b565b85856143a2565b505050915091565b6001600160a01b038116600090815260208690526040812054819081908581106137ae576020880151604051638d3d803d60e01b8152731f64078e323c37b3aca709fb9146a73c3f3c461791638d3d803d916136e2918a91600401918252602082015260400190565b602060405180830381865af41580156136ff573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906137239190614c3d565b6040808a01519051638d3d803d60e01b8152600481018990526024810191909152909450731f64078e323c37b3aca709fb9146a73c3f3c461790638d3d803d90604401602060405180830381865af4158015613783573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906137a79190614c3d565b925061398f565b806137b98188614b99565b9250866137c68285614bc5565b146137d3576137d3614c56565b6020890151604051638d3d803d60e01b8152731f64078e323c37b3aca709fb9146a73c3f3c461791638d3d803d91613818918591600401918252602082015260400190565b602060405180830381865af4158015613835573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906138599190614c3d565b6040808b01519051638d3d803d60e01b8152600481018490526024810191909152909550731f64078e323c37b3aca709fb9146a73c3f3c461790638d3d803d90604401602060405180830381865af41580156138b9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906138dd9190614c3d565b60208a0151604051638d3d803d60e01b8152919550600091731f64078e323c37b3aca709fb9146a73c3f3c461791638d3d803d91613928918891600401918252602082015260400190565b602060405180830381865af4158015613945573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906139699190614c3d565b90506139758187614bc5565b955080896000018181516139899190614b99565b90525050505b50955095509592505050565b600081600101546000036139b157506002015490565b816001015482600201546139c59190614bc5565b6002830181905560006001909301929092555090565b828460030160008282546139ef9190614bc5565b9250508190555082856004016000828254613a0a9190614bc5565b9250508190555081856005016000828254613a259190614b99565b90915550613a359050858261452f565b5050505050565b6001870154613a58906001600160a01b031683883089866142f7565b60018701546040516323b872dd60e01b81526001600160a01b03909116906323b872dd90613a8e90899030908a90600401614cb2565b6020604051808303816000875af1158015613aad573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613ad19190614c6c565b5060408051808201825260018a01546001600160a01b03908116825260028b0154811660208084019190915283518082018552600090528351908101845291511690819052905163a9059cbb60e01b815263a9059cbb90613b389089908890600401614bac565b6020604051808303816000875af1158015613b57573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613b7b9190614c6c565b5060408051808201825260018a01546001600160a01b03908116825260028b0154166020909101819052905163a9059cbb60e01b815263a9059cbb90613bc79089908790600401614bac565b6020604051808303816000875af1158015613be6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613c0a9190614c6c565b505050505050505050565b6000731f64078e323c37b3aca709fb9146a73c3f3c461763f2a5e970600160601b6040516001600160e01b031960e084901b1681526001600160a01b03909116600482015260126024820152604401602060405180830381865af4158015613c81573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613ca59190614c3d565b9050600080613cb7601985018461454b565b915091508184600a016006016001016000828254613cd59190614bc5565b9091555050601484018054829190600090613cf1908490614bc5565b90915550506000601f8501555b50505050565b6126238282604051602401613d1a929190614cd6565b60408051601f198184030181529190526020810180516001600160e01b0316632d839cb360e21b1790526145de565b825460405163a9059cbb60e01b81526001600160a01b039091169063a9059cbb90613d7a9084908690600401614bac565b6020604051808303816000875af1158015613d99573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613cfe9190614c6c565b82546040516323b872dd60e01b81526001600160a01b03909116906323b872dd90613d7a90849030908790600401614cb2565b8154600081815260038085016020908152604092839020835160a081018552815460ff8116151582526001600160a01b0361010090910481169382019390935260018201549092169382019390935260028301546060820152908201546080820152613cfe903085612fd8565b82516040516340c10f1960e01b81526001600160a01b03909116906340c10f199061306e9085908590600401614bac565b613ebb604051806060016040528060006001600160a01b0316815260200160008152602001600081525090565b50604080516060810182526001600160a01b0390921682526000602083018190529082015290565b613f1c6040518060c001604052806000815260200160008152602001600081526020016000815260200160008152602001600081525090565b506040805160c0810182529384526000602085018190529084019290925260608301526080820181905260a082015290565b613f57816145e7565b612f45576040516305bb301f60e51b815260040160405180910390fd5b613f7d8161311b565b15612f4557604051630407b05b60e31b815260040160405180910390fd5b808260010154613fab9190614bc5565b82600101819055505050565b808260010154613fab9190614b99565b613fd08161311b565b612f455760405163d0404f8560e01b815260040160405180910390fd5b6000670de0b6b3a7640000826140038583614d2b565b61400d9190614d42565b6140179086614d2b565b6117189190614d42565b60008181526003840160205260409020613cfe8184614616565b600081600001516001600160a01b03166318160ddd6040518163ffffffff1660e01b8152600401602060405180830381865afa158015612f9f573d6000803e3d6000fd5b83546003850154600090614094908590614bc5565b604051633d6690db60e01b815260048101829052602481018790526044810184905290915060009081908190731f64078e323c37b3aca709fb9146a73c3f3c461790633d6690db90606401606060405180830381865af41580156140fc573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906141209190614d64565b60038c0183905560068c0182905560018c0181905560048c01549295509093509150600090614150908890614bc5565b604051633d6690db60e01b815260048101829052602481018b905260448101889052909150731f64078e323c37b3aca709fb9146a73c3f3c461790633d6690db90606401606060405180830381865af41580156141b1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906141d59190614d64565b60048d0183905560058d0183905560028d0181905560068d015460038e0154939750919550935061420591614bc5565b851461421357614213614c56565b50505050505050505050565b600080828460000160000160008282546142399190614b99565b90915550614249905084846146aa565b6003860180549294509092508391600090614265908490614b99565b9091555050600484018054829190600090614281908490614b99565b925050819055509250929050565b6001600160a01b0381166000908152600784016020526040812080548492906106f0908490614b99565b60008060006142c98686866147c2565b600689018054939650919450925082916000906142e7908490614b99565b9250508190555050935093915050565b60006143028661486e565b80516020820151604080840151905163d505accf60e01b81526001600160a01b038a811660048301528981166024830152604482018990526064820188905260ff909416608482015260a481019290925260c482015291925088169063d505accf9060e401600060405180830381600087803b15801561438157600080fd5b505af1158015614395573d6000803e3d6000fd5b5050505050505050505050565b845160608601516000906143b7908590614bc5565b604051633d6690db60e01b815260048101829052602481018790526044810184905290915060009081908190731f64078e323c37b3aca709fb9146a73c3f3c461790633d6690db90606401606060405180830381865af415801561441f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906144439190614d64565b60608d01839052818c5260208d0181905260808d0151929550909350915060009061446f908890614bc5565b604051633d6690db60e01b815260048101829052602481018b905260448101889052909150731f64078e323c37b3aca709fb9146a73c3f3c461790633d6690db90606401606060405180830381865af41580156144d0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906144f49190614d64565b60808e0183905260a08e0183905260408e018190528c5160608f0151939750919550935061452191614bc5565b851461439557614395614c56565b80826002015461453f9190614b99565b82600201819055505050565b60068201546040516001629a5d1f60e01b0319815260048101829052602481018390526000918291731f64078e323c37b3aca709fb9146a73c3f3c46179063ff65a2e1906044016040805180830381865af41580156145ae573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906145d29190614c8e565b90969095509350505050565b612f45816148de565b805460009061010090046001600160a01b031615801590610a98575050600101546001600160a01b0316151590565b8154604051630852cd8d60e31b8152600481018390526101009091046001600160a01b0316906342966c6890602401600060405180830381600087803b15801561465f57600080fd5b505af1158015614673573d6000803e3d6000fd5b505050506001820154604051630852cd8d60e31b8152600481018390526001600160a01b03909116906342966c6890602401613303565b6001820154604051638d3d803d60e01b81526000918291731f64078e323c37b3aca709fb9146a73c3f3c461791638d3d803d916146f4918791600401918252602082015260400190565b602060405180830381865af4158015614711573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906147359190614c3d565b6002850154604051638d3d803d60e01b8152600481018690526024810191909152909250731f64078e323c37b3aca709fb9146a73c3f3c461790638d3d803d90604401602060405180830381865af4158015614795573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906147b99190614c3d565b90509250929050565b60008060006147d186866146aa565b6001880154604051638d3d803d60e01b81526004810188905260248101919091529194509250731f64078e323c37b3aca709fb9146a73c3f3c461790638d3d803d90604401602060405180830381865af4158015614833573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906148579190614c3d565b90506148638184614bc5565b925093509350939050565b604080516060810182526000808252602082018190529181019190915281516041146148b257815160405163058676ad60e31b81526004016119d991815260200190565b506020818101516040808401516060948501518251958601835260001a85529284019190915282015290565b60006a636f6e736f6c652e6c6f679050600080835160208501845afa505050565b6000806040838503121561491257600080fd5b50508035926020909101359150565b6001600160a01b0381168114612f4557600080fd5b60008060006060848603121561494b57600080fd5b833561495681614921565b95602085013595506040909401359392505050565b60008060006060848603121561498057600080fd5b83359250602084013561499281614921565b929592945050506040919091013590565b6000602082840312156149b557600080fd5b5035919050565b600080604083850312156149cf57600080fd5b82356149da81614921565b915060208301356149ea81614921565b809150509250929050565b600080600060608486031215614a0a57600080fd5b505081359360208301359350604090920135919050565b634e487b7160e01b600052604160045260246000fd5b600080600080600060a08688031215614a4f57600080fd5b853594506020860135935060408601359250606086013567ffffffffffffffff80821115614a7c57600080fd5b818801915088601f830112614a9057600080fd5b813581811115614aa257614aa2614a21565b604051601f8201601f19908116603f01168101908382118183101715614aca57614aca614a21565b816040528281528b6020848701011115614ae357600080fd5b82602086016020830137600092810160200192909252509699959850939660800135949350505050565b600080600080600060a08688031215614b2557600080fd5b8535614b3081614921565b94506020860135614b4081614921565b94979496505050506040830135926060810135926080909101359150565b60008060408385031215614b7157600080fd5b8235915060208301356149ea81614921565b634e487b7160e01b600052601160045260246000fd5b81810381811115610a9857610a98614b83565b6001600160a01b03929092168252602082015260400190565b80820180821115610a9857610a98614b83565b60008060408385031215614beb57600080fd5b8251614bf681614921565b60208401519092506149ea81614921565b600060018201614c1957614c19614b83565b5060010190565b600060208284031215614c3257600080fd5b815161089a81614921565b600060208284031215614c4f57600080fd5b5051919050565b634e487b7160e01b600052600160045260246000fd5b600060208284031215614c7e57600080fd5b8151801515811461089a57600080fd5b60008060408385031215614ca157600080fd5b505080516020909101519092909150565b6001600160a01b039384168152919092166020820152604081019190915260600190565b604081526000835180604084015260005b81811015614d045760208187018101516060868401015201614ce7565b506000606082850101526060601f19601f8301168401019150508260208301529392505050565b8082028115828204841417610a9857610a98614b83565b600082614d5f57634e487b7160e01b600052601260045260246000fd5b500490565b600080600060608486031215614d7957600080fd5b835192506020840151915060408401519050925092509256fea26469706673582212204f8cd681b87c27a2bc7b9f7c13d311132cd021627cde3ebd18adbd472651373f64736f6c63430008180033

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

000000000000000000000000e6771c4a288cd74a46af81ebe8be8cc66edc6cfe

-----Decoded View---------------
Arg [0] : factory (address): 0xe6771C4A288CD74a46aF81eBe8Be8CC66edC6CFE

-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 000000000000000000000000e6771c4a288cd74a46af81ebe8be8cc66edc6cfe


Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

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

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
[ Download: CSV Export  ]

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.