ETH Price: $2,939.41 (-0.47%)

Contract

0xD0a1Ff86C2f1c3522f183400fDE355f6B3d9fCE1

Overview

ETH Balance

0 ETH

ETH Value

$0.00

Token Holdings

More Info

Private Name Tags

TokenTracker

Multichain Info

No addresses found
Transaction Hash
Block
From
To
Deposit379188352026-01-17 16:26:347 days ago1768667194IN
0xD0a1Ff86...6B3d9fCE1
0 ETH0.000000030.00010025
Deposit374563252026-01-12 7:58:0412 days ago1768204684IN
0xD0a1Ff86...6B3d9fCE1
0 ETH0.000000030.0001003
Claim Rewards374213132026-01-11 22:14:3213 days ago1768169672IN
0xD0a1Ff86...6B3d9fCE1
0 ETH0.000000090.00151028
Claim Rewards372465562026-01-09 21:41:5515 days ago1767994915IN
0xD0a1Ff86...6B3d9fCE1
0 ETH00.00000035
Claim Admin Fee364331292025-12-31 11:44:4824 days ago1767181488IN
0xD0a1Ff86...6B3d9fCE1
0 ETH0.000000070.00100028
Deposit354824942025-12-20 11:40:5335 days ago1766230853IN
0xD0a1Ff86...6B3d9fCE1
0 ETH0.000000030.00010031
Deposit340888302025-12-04 8:33:0951 days ago1764837189IN
0xD0a1Ff86...6B3d9fCE1
0 ETH0.000000030.00010025
Claim Rewards339702822025-12-02 23:37:2153 days ago1764718641IN
0xD0a1Ff86...6B3d9fCE1
0 ETH00.00000381
Claim Rewards339315432025-12-02 12:51:4253 days ago1764679902IN
0xD0a1Ff86...6B3d9fCE1
0 ETH00.00010028
Claim Admin Fee337662502025-11-30 14:56:4955 days ago1764514609IN
0xD0a1Ff86...6B3d9fCE1
0 ETH0.000000050.00100028
Deposit323039422025-11-13 16:45:0172 days ago1763052301IN
0xD0a1Ff86...6B3d9fCE1
0 ETH0.000000030.0001003
Withdraw313972692025-11-03 4:53:4883 days ago1762145628IN
0xD0a1Ff86...6B3d9fCE1
0 ETH0.000000010.00005513
Deposit313714082025-11-02 21:42:4783 days ago1762119767IN
0xD0a1Ff86...6B3d9fCE1
0 ETH00.00000386
Deposit313703712025-11-02 21:25:3083 days ago1762118730IN
0xD0a1Ff86...6B3d9fCE1
0 ETH00.00000385
Claim Admin Fee311718622025-10-31 14:17:0185 days ago1761920221IN
0xD0a1Ff86...6B3d9fCE1
0 ETH0.000000050.00100031
Claim Rewards311085142025-10-30 20:41:1386 days ago1761856873IN
0xD0a1Ff86...6B3d9fCE1
0 ETH00.00010032
Deposit304680742025-10-23 10:47:1393 days ago1761216433IN
0xD0a1Ff86...6B3d9fCE1
0 ETH0.000000030.0001003
Deposit300086692025-10-18 3:10:2899 days ago1760757028IN
0xD0a1Ff86...6B3d9fCE1
0 ETH0.000000030.00010027
Withdraw295894592025-10-13 6:43:38104 days ago1760337818IN
0xD0a1Ff86...6B3d9fCE1
0 ETH0.000000030.00010028
Deposit295893942025-10-13 6:42:33104 days ago1760337753IN
0xD0a1Ff86...6B3d9fCE1
0 ETH0.000000030.00010028
Withdraw293703042025-10-10 17:51:03106 days ago1760118663IN
0xD0a1Ff86...6B3d9fCE1
0 ETH0.000000030.0001003
Deposit293701102025-10-10 17:47:49106 days ago1760118469IN
0xD0a1Ff86...6B3d9fCE1
0 ETH0.000000030.00010031
Withdraw291558412025-10-08 6:16:40109 days ago1759904200IN
0xD0a1Ff86...6B3d9fCE1
0 ETH0.000000020.00010028
Deposit291557822025-10-08 6:15:41109 days ago1759904141IN
0xD0a1Ff86...6B3d9fCE1
0 ETH0.000000030.00010028
Withdraw290967822025-10-07 13:52:21109 days ago1759845141IN
0xD0a1Ff86...6B3d9fCE1
0 ETH0.000000030.00010043
View all transactions

View more zero value Internal Transactions in Advanced View mode

Advanced mode:

Cross-Chain Transactions
Loading...
Loading

Similar Match Source Code
This contract matches the deployed Bytecode of the Source Code for Contract 0xBA2FBA24...36ea094D7
The constructor portion of the code might be different and could alter the actual behaviour of the contract

Contract Name:
Pool

Compiler Version
v0.8.20+commit.a1b79de6

Optimization Enabled:
Yes with 1000 runs

Other Settings:
default evmVersion, MIT license

Contract Source Code (Solidity Standard Json-Input format)

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;

import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";
import {RewardManager} from "./RewardManager.sol";

/**
 * 4AD - D = 4A(x + y) - (D³ / 4xy)
 * X - is value of real stable token
 * Y - is value of virtual usd
 */
contract Pool is RewardManager {
    using SafeERC20 for ERC20;
    uint private constant SYSTEM_PRECISION = 3;
    int private constant PP = 1e4; // Price Precision
    uint private constant MAX_TOKEN_BALANCE = 2 ** 40; // Max possible token balance

    /**
     * @dev Gas optimization: both the 'feeShareBP' and 'router' fields are used during the 'swapFromVUsd', 'swapToVUsd'
     * operations and can occupy the same slot.
     */
    uint16 public feeShareBP;
    address public router;
    uint public tokenBalance;
    uint public vUsdBalance;
    uint public balanceRatioMinBP;
    uint public reserves;
    uint public immutable a;
    uint public d;

    uint private immutable tokenAmountReduce;
    uint private immutable tokenAmountIncrease;

    // can restrict deposit or withdraw operations
    address private stopAuthority;
    // is deposit operation allowed
    uint public canDeposit = 1;
    // is withdraw operation allowed
    uint public canWithdraw = 1;

    event SwappedToVUsd(address sender, address token, uint amount, uint vUsdAmount, uint fee);
    event SwappedFromVUsd(address recipient, address token, uint vUsdAmount, uint amount, uint fee);

    constructor(
        address router_,
        uint a_,
        ERC20 token_,
        uint16 feeShareBP_,
        uint balanceRatioMinBP_,
        string memory lpName,
        string memory lpSymbol
    ) RewardManager(token_, lpName, lpSymbol) {
        a = a_;
        router = router_;
        stopAuthority = owner();
        feeShareBP = feeShareBP_;
        balanceRatioMinBP = balanceRatioMinBP_;

        uint decimals = token_.decimals();
        tokenAmountReduce = decimals > SYSTEM_PRECISION ? 10 ** (decimals - SYSTEM_PRECISION) : 0;
        tokenAmountIncrease = decimals < SYSTEM_PRECISION ? 10 ** (SYSTEM_PRECISION - decimals) : 0;
    }

    /**
     * @dev Throws if called by any account other than the router.
     */
    modifier onlyRouter() {
        require(router == msg.sender, "Pool: is not router");
        _;
    }

    /**
     * @dev Throws if called by any account other than the stopAuthority.
     */
    modifier onlyStopAuthority() {
        require(stopAuthority == msg.sender, "Pool: is not stopAuthority");
        _;
    }

    /**
     * @dev Modifier to prevent function from disbalancing the pool over a threshold defined by `balanceRatioMinBP`
     */
    modifier validateBalanceRatio() {
        _;
        if (tokenBalance > vUsdBalance) {
            require((vUsdBalance * BP) / tokenBalance >= balanceRatioMinBP, "Pool: low vUSD balance");
        } else if (tokenBalance < vUsdBalance) {
            require((tokenBalance * BP) / vUsdBalance >= balanceRatioMinBP, "Pool: low token balance");
        }
    }

    /**
     * @dev Modifier to make a function callable only when the deposit is allowed.
     */
    modifier whenCanDeposit() {
        require(canDeposit == 1, "Pool: deposit prohibited");
        _;
    }

    /**
     * @dev Modifier to make a function callable only when the withdraw is allowed.
     */
    modifier whenCanWithdraw() {
        require(canWithdraw == 1, "Pool: withdraw prohibited");
        _;
    }

    /**
     * @dev Calculates the price and deposit token according to the amount and price, then adds the same amount to the X
     * and to the Y
     * @param amount The deposited amount
     */
    function deposit(uint amount) external whenCanDeposit {
        uint oldD = d;

        uint amountSP = _toSystemPrecision(amount);
        require(amountSP > 0, "Pool: too little");

        token.safeTransferFrom(msg.sender, address(this), amount);

        // Add deposited amount to reserves
        reserves += amountSP;

        uint oldBalance = (tokenBalance + vUsdBalance);
        if (oldD == 0 || oldBalance == 0) {
            // Split balance equally on the first deposit
            uint halfAmount = amountSP >> 1;
            tokenBalance += halfAmount;
            vUsdBalance += halfAmount;
        } else {
            // Add amount proportionally to each pool
            tokenBalance += (amountSP * tokenBalance) / oldBalance;
            vUsdBalance += (amountSP * vUsdBalance) / oldBalance;
        }
        _updateD();
        // Deposit as many LP tokens as the D increase
        _depositLp(msg.sender, d - oldD);

        require(tokenBalance < MAX_TOKEN_BALANCE, "Pool: too much");
    }

    /*
     * @dev Subtracts X and Y for that amount, calculates current price and withdraw the token to the user according to
     * the price
     * @param amount The deposited amount
     */
    function withdraw(uint amountLp) external whenCanWithdraw {
        uint oldD = d;
        _withdrawLp(msg.sender, amountLp);

        // Always withdraw tokens in amount equal to amountLp

        // Withdraw proportionally from token and vUsd balance
        uint oldBalance = (tokenBalance + vUsdBalance);
        tokenBalance -= (amountLp * tokenBalance) / oldBalance;
        vUsdBalance -= (amountLp * vUsdBalance) / oldBalance;

        require(tokenBalance + vUsdBalance < oldBalance, "Pool: zero changes");

        // Check if there is enough funds in reserve to withdraw
        require(amountLp <= reserves, "Pool: reserves");

        // Adjust reserves by withdraw amount
        reserves -= amountLp;

        // Update D and transfer tokens to the sender
        _updateD();
        require(d < oldD, "Pool: zero D changes");

        token.safeTransfer(msg.sender, _fromSystemPrecision(amountLp));
    }

    /**
     * @notice Calculates new virtual USD value from the given amount of tokens.
     * @dev Calculates new Y according to new X.
     * NOTICE: Prior to calling this the router must transfer tokens from the user to the pool.
     * @param amount The amount of tokens to swap.
     * @param zeroFee When true it allows to swap without incurring any fees. It is intended for use with service
     * accounts.
     * @return returns the difference between the old and the new value of vUsdBalance
     */
    function swapToVUsd(
        address user,
        uint amount,
        bool zeroFee
    ) external onlyRouter validateBalanceRatio returns (uint) {
        uint result; // 0 by default
        uint fee;
        if (amount > 0) {
            if (!zeroFee) {
                fee = (amount * feeShareBP) / BP;
            }
            uint amountIn = _toSystemPrecision(amount - fee);
            // Incorporate rounding dust into the fee
            fee = amount - _fromSystemPrecision(amountIn);

            // Adjust token and reserve balances after the fee is applied
            tokenBalance += amountIn;
            reserves += amountIn;

            uint vUsdNewAmount = this.getY(tokenBalance);
            if (vUsdBalance > vUsdNewAmount) {
                result = vUsdBalance - vUsdNewAmount;
            }
            vUsdBalance = vUsdNewAmount;
            _addRewards(fee);
        }

        emit SwappedToVUsd(user, address(token), amount, result, fee);
        return result;
    }

    /**
     * @notice Calculates the amount of tokens from the given virtual USD value, and transfers it to the user.
     * @dev Calculates new X according to new Y.
     * @param user The address of the recipient.
     * @param amount The amount of vUSD to swap.
     * @param receiveAmountMin The minimum amount of tokens required to be received during the swap, otherwise the
     * transaction reverts.
     * @param zeroFee When true it allows to swap without incurring any fees. It is intended for use with service
     * accounts.
     * @return returns the difference between the old and the new value of vUsdBalance
     */
    function swapFromVUsd(
        address user,
        uint amount,
        uint receiveAmountMin,
        bool zeroFee
    ) external onlyRouter validateBalanceRatio returns (uint) {
        uint resultSP; // 0 by default
        uint result; // 0 by default
        uint fee;
        if (amount > 0) {
            vUsdBalance += amount;
            uint newAmount = this.getY(vUsdBalance);
            if (tokenBalance > newAmount) {
                resultSP = tokenBalance - newAmount;
                result = _fromSystemPrecision(resultSP);
            } // Otherwise result/resultSP stay 0

            // Check if there is enough funds in reserve to pay
            require(resultSP <= reserves, "Pool: reserves");
            // Remove from reserves including fee, apply fee later
            reserves -= resultSP;
            if (!zeroFee) {
                fee = (result * feeShareBP) / BP;
            }
            // We can use unchecked here because feeShareBP <= BP
            unchecked {
                result -= fee;
            }

            tokenBalance = newAmount;
            require(result >= receiveAmountMin, "Pool: slippage");
            token.safeTransfer(user, result);
            _addRewards(fee);
        }
        emit SwappedFromVUsd(user, address(token), amount, result, fee);
        return result;
    }

    /**
     * @dev Sets admin fee share.
     */
    function setFeeShare(uint16 feeShareBP_) external onlyOwner {
        require(feeShareBP_ <= BP, "Pool: too large");
        feeShareBP = feeShareBP_;
    }

    function adjustTotalLpAmount() external onlyOwner {
        if (d > totalSupply()) {
            _depositLp(owner(), d - totalSupply());
        }
    }

    /**
     * @dev Sets the threshold over which the pool can't be disbalanced.
     */
    function setBalanceRatioMinBP(uint balanceRatioMinBP_) external onlyOwner {
        require(balanceRatioMinBP_ <= BP, "Pool: too large");
        balanceRatioMinBP = balanceRatioMinBP_;
    }

    /**
     * @dev Switches off the possibility to make deposits.
     */
    function stopDeposit() external onlyStopAuthority {
        canDeposit = 0;
    }

    /**
     * @dev Switches on the possibility to make deposits.
     */
    function startDeposit() external onlyOwner {
        canDeposit = 1;
    }

    /**
     * @dev Switches off the possibility to make withdrawals.
     */
    function stopWithdraw() external onlyStopAuthority {
        canWithdraw = 0;
    }

    /**
     * @dev Switches on the possibility to make withdrawals.
     */
    function startWithdraw() external onlyOwner {
        canWithdraw = 1;
    }

    /**
     * @dev Sets the address of the stopAuthority account.
     */
    function setStopAuthority(address stopAuthority_) external onlyOwner {
        stopAuthority = stopAuthority_;
    }

    /**
     * @dev Sets the address of the Router contract.
     */
    function setRouter(address router_) external onlyOwner {
        router = router_;
    }

    /**
     * @dev y = (sqrt(x(4AD³ + x (4A(D - x) - D )²)) + x (4A(D - x) - D ))/8Ax.
     */
    function getY(uint x) external view returns (uint) {
        uint d_ = d; // Gas optimization
        uint a4 = a << 2;
        uint a8 = a4 << 1;
        // 4A(D - x) - D
        int part1 = int(a4) * (int(d_) - int(x)) - int(d_);
        // x * (4AD³ + x(part1²))
        uint part2 = x * (a4 * d_ * d_ * d_ + x * uint(part1 * part1));
        // (sqrt(part2) + x(part1)) / 8Ax)
        return SafeCast.toUint256(int(_sqrt(part2)) + int(x) * part1) / (a8 * x) + 1; // +1 to offset rounding errors
    }

    /**
     * @dev price = (1/2) * ((D³ + 8ADx² - 8Ax³ - 2Dx²) / (4x * sqrt(x(4AD³ + x (4A(D - x) - D )²))))
     */
    function getPrice() external view returns (uint) {
        uint x = tokenBalance;
        uint a8 = a << 3;
        uint dCubed = d * d * d;

        // 4A(D - x) - D
        int p1 = int(a << 2) * (int(d) - int(x)) - int(d);
        // x * 4AD³ + x(p1²)
        uint p2 = x * ((a << 2) * dCubed + x * uint(p1 * p1));
        // D³ + 8ADx² - 8Ax³ - 2Dx²
        int p3 = int(dCubed) + int((a << 3) * d * x * x) - int(a8 * x * x * x) - int((d << 1) * x * x);
        // 1/2 * p3 / (4x * sqrt(p2))
        return SafeCast.toUint256((PP >> 1) + ((PP * p3) / int((x << 2) * _sqrt(p2))));
    }

    function _updateD() internal {
        uint x = tokenBalance;
        uint y = vUsdBalance;
        // a = 8 * Axy(x+y)
        // b = 4 * xy(4A - 1) / 3
        // c = sqrt(a² + b³)
        // D = cbrt(a + c) + cbrt(a - c)
        uint xy = x * y;
        uint a_ = a;
        // Axy(x+y)
        uint p1 = a_ * xy * (x + y);
        // xy(4A - 1) / 3
        uint p2 = (xy * ((a_ << 2) - 1)) / 3;
        // p1² + p2³
        uint p3 = _sqrt((p1 * p1) + (p2 * p2 * p2));
        unchecked {
            uint d_ = _cbrt(p1 + p3);
            if (p3 > p1) {
                d_ -= _cbrt(p3 - p1);
            } else {
                d_ += _cbrt(p1 - p3);
            }
            d = (d_ << 1);
        }
    }

    function _toSystemPrecision(uint amount) internal view returns (uint) {
        if (tokenAmountReduce > 0) {
            return amount / tokenAmountReduce;
        } else if (tokenAmountIncrease > 0) {
            return amount * tokenAmountIncrease;
        }
        return amount;
    }

    function _fromSystemPrecision(uint amount) internal view returns (uint) {
        if (tokenAmountReduce > 0) {
            return amount * tokenAmountReduce;
        } else if (tokenAmountIncrease > 0) {
            return amount / tokenAmountIncrease;
        }
        return amount;
    }

    function _sqrt(uint n) internal pure returns (uint) {
        unchecked {
            if (n > 0) {
                uint x = (n >> 1) + 1;
                uint y = (x + n / x) >> 1;
                while (x > y) {
                    x = y;
                    y = (x + n / x) >> 1;
                }
                return x;
            }
            return 0;
        }
    }

    function _cbrt(uint n) internal pure returns (uint) {
        unchecked {
            uint x = 0;
            for (uint y = 1 << 255; y > 0; y >>= 3) {
                x <<= 1;
                uint z = 3 * x * (x + 1) + 1;
                if (n / y >= z) {
                    n -= y * z;
                    x += 1;
                }
            }
            return x;
        }
    }

    fallback() external payable {
        revert("Unsupported");
    }

    receive() external payable {
        revert("Unsupported");
    }
}

// SPDX-License-Identifier: LZBL-1.2

pragma solidity ^0.8.20;

import "@layerzerolabs/lz-evm-protocol-v2/contracts/libs/CalldataBytesLib.sol";

library ExecutorOptions {
    using CalldataBytesLib for bytes;

    uint8 internal constant WORKER_ID = 1;

    uint8 internal constant OPTION_TYPE_LZRECEIVE = 1;
    uint8 internal constant OPTION_TYPE_NATIVE_DROP = 2;
    uint8 internal constant OPTION_TYPE_LZCOMPOSE = 3;
    uint8 internal constant OPTION_TYPE_ORDERED_EXECUTION = 4;
    uint8 internal constant OPTION_TYPE_LZREAD = 5;

    error Executor_InvalidLzReceiveOption();
    error Executor_InvalidNativeDropOption();
    error Executor_InvalidLzComposeOption();
    error Executor_InvalidLzReadOption();

    /// @dev decode the next executor option from the options starting from the specified cursor
    /// @param _options [executor_id][executor_option][executor_id][executor_option]...
    ///        executor_option = [option_size][option_type][option]
    ///        option_size = len(option_type) + len(option)
    ///        executor_id: uint8, option_size: uint16, option_type: uint8, option: bytes
    /// @param _cursor the cursor to start decoding from
    /// @return optionType the type of the option
    /// @return option the option of the executor
    /// @return cursor the cursor to start decoding the next executor option
    function nextExecutorOption(
        bytes calldata _options,
        uint256 _cursor
    ) internal pure returns (uint8 optionType, bytes calldata option, uint256 cursor) {
        unchecked {
            // skip worker id
            cursor = _cursor + 1;

            // read option size
            uint16 size = _options.toU16(cursor);
            cursor += 2;

            // read option type
            optionType = _options.toU8(cursor);

            // startCursor and endCursor are used to slice the option from _options
            uint256 startCursor = cursor + 1; // skip option type
            uint256 endCursor = cursor + size;
            option = _options[startCursor:endCursor];
            cursor += size;
        }
    }

    function decodeLzReceiveOption(bytes calldata _option) internal pure returns (uint128 gas, uint128 value) {
        if (_option.length != 16 && _option.length != 32) revert Executor_InvalidLzReceiveOption();
        gas = _option.toU128(0);
        value = _option.length == 32 ? _option.toU128(16) : 0;
    }

    function decodeNativeDropOption(bytes calldata _option) internal pure returns (uint128 amount, bytes32 receiver) {
        if (_option.length != 48) revert Executor_InvalidNativeDropOption();
        amount = _option.toU128(0);
        receiver = _option.toB32(16);
    }

    function decodeLzComposeOption(
        bytes calldata _option
    ) internal pure returns (uint16 index, uint128 gas, uint128 value) {
        if (_option.length != 18 && _option.length != 34) revert Executor_InvalidLzComposeOption();
        index = _option.toU16(0);
        gas = _option.toU128(2);
        value = _option.length == 34 ? _option.toU128(18) : 0;
    }

    function decodeLzReadOption(
        bytes calldata _option
    ) internal pure returns (uint128 gas, uint32 calldataSize, uint128 value) {
        if (_option.length != 20 && _option.length != 36) revert Executor_InvalidLzReadOption();
        gas = _option.toU128(0);
        calldataSize = _option.toU32(16);
        value = _option.length == 36 ? _option.toU128(20) : 0;
    }

    function encodeLzReceiveOption(uint128 _gas, uint128 _value) internal pure returns (bytes memory) {
        return _value == 0 ? abi.encodePacked(_gas) : abi.encodePacked(_gas, _value);
    }

    function encodeNativeDropOption(uint128 _amount, bytes32 _receiver) internal pure returns (bytes memory) {
        return abi.encodePacked(_amount, _receiver);
    }

    function encodeLzComposeOption(uint16 _index, uint128 _gas, uint128 _value) internal pure returns (bytes memory) {
        return _value == 0 ? abi.encodePacked(_index, _gas) : abi.encodePacked(_index, _gas, _value);
    }

    function encodeLzReadOption(
        uint128 _gas,
        uint32 _calldataSize,
        uint128 _value
    ) internal pure returns (bytes memory) {
        return _value == 0 ? abi.encodePacked(_gas, _calldataSize) : abi.encodePacked(_gas, _calldataSize, _value);
    }
}

// SPDX-License-Identifier: LZBL-1.2

pragma solidity ^0.8.20;

import { BytesLib } from "solidity-bytes-utils/contracts/BytesLib.sol";

import { BitMap256 } from "@layerzerolabs/lz-evm-protocol-v2/contracts/messagelib/libs/BitMaps.sol";
import { CalldataBytesLib } from "@layerzerolabs/lz-evm-protocol-v2/contracts/libs/CalldataBytesLib.sol";

library DVNOptions {
    using CalldataBytesLib for bytes;
    using BytesLib for bytes;

    uint8 internal constant WORKER_ID = 2;
    uint8 internal constant OPTION_TYPE_PRECRIME = 1;

    error DVN_InvalidDVNIdx();
    error DVN_InvalidDVNOptions(uint256 cursor);

    /// @dev group dvn options by its idx
    /// @param _options [dvn_id][dvn_option][dvn_id][dvn_option]...
    ///        dvn_option = [option_size][dvn_idx][option_type][option]
    ///        option_size = len(dvn_idx) + len(option_type) + len(option)
    ///        dvn_id: uint8, dvn_idx: uint8, option_size: uint16, option_type: uint8, option: bytes
    /// @return dvnOptions the grouped options, still share the same format of _options
    /// @return dvnIndices the dvn indices
    function groupDVNOptionsByIdx(
        bytes memory _options
    ) internal pure returns (bytes[] memory dvnOptions, uint8[] memory dvnIndices) {
        if (_options.length == 0) return (dvnOptions, dvnIndices);

        uint8 numDVNs = getNumDVNs(_options);

        // if there is only 1 dvn, we can just return the whole options
        if (numDVNs == 1) {
            dvnOptions = new bytes[](1);
            dvnOptions[0] = _options;

            dvnIndices = new uint8[](1);
            dvnIndices[0] = _options.toUint8(3); // dvn idx
            return (dvnOptions, dvnIndices);
        }

        // otherwise, we need to group the options by dvn_idx
        dvnIndices = new uint8[](numDVNs);
        dvnOptions = new bytes[](numDVNs);
        unchecked {
            uint256 cursor = 0;
            uint256 start = 0;
            uint8 lastDVNIdx = 255; // 255 is an invalid dvn_idx

            while (cursor < _options.length) {
                ++cursor; // skip worker_id

                // optionLength asserted in getNumDVNs (skip check)
                uint16 optionLength = _options.toUint16(cursor);
                cursor += 2;

                // dvnIdx asserted in getNumDVNs (skip check)
                uint8 dvnIdx = _options.toUint8(cursor);

                // dvnIdx must equal to the lastDVNIdx for the first option
                // so it is always skipped in the first option
                // this operation slices out options whenever the scan finds a different lastDVNIdx
                if (lastDVNIdx == 255) {
                    lastDVNIdx = dvnIdx;
                } else if (dvnIdx != lastDVNIdx) {
                    uint256 len = cursor - start - 3; // 3 is for worker_id and option_length
                    bytes memory opt = _options.slice(start, len);
                    _insertDVNOptions(dvnOptions, dvnIndices, lastDVNIdx, opt);

                    // reset the start and lastDVNIdx
                    start += len;
                    lastDVNIdx = dvnIdx;
                }

                cursor += optionLength;
            }

            // skip check the cursor here because the cursor is asserted in getNumDVNs
            // if we have reached the end of the options, we need to process the last dvn
            uint256 size = cursor - start;
            bytes memory op = _options.slice(start, size);
            _insertDVNOptions(dvnOptions, dvnIndices, lastDVNIdx, op);

            // revert dvnIndices to start from 0
            for (uint8 i = 0; i < numDVNs; ++i) {
                --dvnIndices[i];
            }
        }
    }

    function _insertDVNOptions(
        bytes[] memory _dvnOptions,
        uint8[] memory _dvnIndices,
        uint8 _dvnIdx,
        bytes memory _newOptions
    ) internal pure {
        // dvnIdx starts from 0 but default value of dvnIndices is 0,
        // so we tell if the slot is empty by adding 1 to dvnIdx
        if (_dvnIdx == 255) revert DVN_InvalidDVNIdx();
        uint8 dvnIdxAdj = _dvnIdx + 1;

        for (uint256 j = 0; j < _dvnIndices.length; ++j) {
            uint8 index = _dvnIndices[j];
            if (dvnIdxAdj == index) {
                _dvnOptions[j] = abi.encodePacked(_dvnOptions[j], _newOptions);
                break;
            } else if (index == 0) {
                // empty slot, that means it is the first time we see this dvn
                _dvnIndices[j] = dvnIdxAdj;
                _dvnOptions[j] = _newOptions;
                break;
            }
        }
    }

    /// @dev get the number of unique dvns
    /// @param _options the format is the same as groupDVNOptionsByIdx
    function getNumDVNs(bytes memory _options) internal pure returns (uint8 numDVNs) {
        uint256 cursor = 0;
        BitMap256 bitmap;

        // find number of unique dvn_idx
        unchecked {
            while (cursor < _options.length) {
                ++cursor; // skip worker_id

                uint16 optionLength = _options.toUint16(cursor);
                cursor += 2;
                if (optionLength < 2) revert DVN_InvalidDVNOptions(cursor); // at least 1 byte for dvn_idx and 1 byte for option_type

                uint8 dvnIdx = _options.toUint8(cursor);

                // if dvnIdx is not set, increment numDVNs
                // max num of dvns is 255, 255 is an invalid dvn_idx
                // The order of the dvnIdx is not required to be sequential, as enforcing the order may weaken
                // the composability of the options. e.g. if we refrain from enforcing the order, an OApp that has
                // already enforced certain options can append additional options to the end of the enforced
                // ones without restrictions.
                if (dvnIdx == 255) revert DVN_InvalidDVNIdx();
                if (!bitmap.get(dvnIdx)) {
                    ++numDVNs;
                    bitmap = bitmap.set(dvnIdx);
                }

                cursor += optionLength;
            }
        }
        if (cursor != _options.length) revert DVN_InvalidDVNOptions(cursor);
    }

    /// @dev decode the next dvn option from _options starting from the specified cursor
    /// @param _options the format is the same as groupDVNOptionsByIdx
    /// @param _cursor the cursor to start decoding
    /// @return optionType the type of the option
    /// @return option the option
    /// @return cursor the cursor to start decoding the next option
    function nextDVNOption(
        bytes calldata _options,
        uint256 _cursor
    ) internal pure returns (uint8 optionType, bytes calldata option, uint256 cursor) {
        unchecked {
            // skip worker id
            cursor = _cursor + 1;

            // read option size
            uint16 size = _options.toU16(cursor);
            cursor += 2;

            // read option type
            optionType = _options.toU8(cursor + 1); // skip dvn_idx

            // startCursor and endCursor are used to slice the option from _options
            uint256 startCursor = cursor + 2; // skip option type and dvn_idx
            uint256 endCursor = cursor + size;
            option = _options[startCursor:endCursor];
            cursor += size;
        }
    }
}

// SPDX-License-Identifier: LZBL-1.2

pragma solidity ^0.8.20;

import { SafeCast } from "@openzeppelin/contracts/utils/math/SafeCast.sol";

import { ExecutorOptions } from "@layerzerolabs/lz-evm-protocol-v2/contracts/messagelib/libs/ExecutorOptions.sol";

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

library UlnOptions {
    using SafeCast for uint256;

    uint16 internal constant TYPE_1 = 1; // legacy options type 1
    uint16 internal constant TYPE_2 = 2; // legacy options type 2
    uint16 internal constant TYPE_3 = 3;

    error LZ_ULN_InvalidWorkerOptions(uint256 cursor);
    error LZ_ULN_InvalidWorkerId(uint8 workerId);
    error LZ_ULN_InvalidLegacyType1Option();
    error LZ_ULN_InvalidLegacyType2Option();
    error LZ_ULN_UnsupportedOptionType(uint16 optionType);

    /// @dev decode the options into executorOptions and dvnOptions
    /// @param _options the options can be either legacy options (type 1 or 2) or type 3 options
    /// @return executorOptions the executor options, share the same format of type 3 options
    /// @return dvnOptions the dvn options, share the same format of type 3 options
    function decode(
        bytes calldata _options
    ) internal pure returns (bytes memory executorOptions, bytes memory dvnOptions) {
        // at least 2 bytes for the option type, but can have no options
        if (_options.length < 2) revert LZ_ULN_InvalidWorkerOptions(0);

        uint16 optionsType = uint16(bytes2(_options[0:2]));
        uint256 cursor = 2;

        // type3 options: [worker_option][worker_option]...
        // worker_option: [worker_id][option_size][option]
        // worker_id: uint8, option_size: uint16, option: bytes
        if (optionsType == TYPE_3) {
            unchecked {
                uint256 start = cursor;
                uint8 lastWorkerId; // worker_id starts from 1, so 0 is an invalid worker_id

                // heuristic: we assume that the options are mostly EXECUTOR options only
                // checking the workerID can reduce gas usage for most cases
                while (cursor < _options.length) {
                    uint8 workerId = uint8(bytes1(_options[cursor:cursor + 1]));
                    if (workerId == 0) revert LZ_ULN_InvalidWorkerId(0);

                    // workerId must equal to the lastWorkerId for the first option
                    // so it is always skipped in the first option
                    // this operation slices out options whenever the the scan finds a different workerId
                    if (lastWorkerId == 0) {
                        lastWorkerId = workerId;
                    } else if (workerId != lastWorkerId) {
                        bytes calldata op = _options[start:cursor]; // slice out the last worker's options
                        (executorOptions, dvnOptions) = _insertWorkerOptions(
                            executorOptions,
                            dvnOptions,
                            lastWorkerId,
                            op
                        );

                        // reset the start cursor and lastWorkerId
                        start = cursor;
                        lastWorkerId = workerId;
                    }

                    ++cursor; // for workerId

                    uint16 size = uint16(bytes2(_options[cursor:cursor + 2]));
                    if (size == 0) revert LZ_ULN_InvalidWorkerOptions(cursor);
                    cursor += size + 2;
                }

                // the options length must be the same as the cursor at the end
                if (cursor != _options.length) revert LZ_ULN_InvalidWorkerOptions(cursor);

                // if we have reached the end of the options and the options are not empty
                // we need to process the last worker's options
                if (_options.length > 2) {
                    bytes calldata op = _options[start:cursor];
                    (executorOptions, dvnOptions) = _insertWorkerOptions(executorOptions, dvnOptions, lastWorkerId, op);
                }
            }
        } else {
            executorOptions = decodeLegacyOptions(optionsType, _options);
        }
    }

    function _insertWorkerOptions(
        bytes memory _executorOptions,
        bytes memory _dvnOptions,
        uint8 _workerId,
        bytes calldata _newOptions
    ) private pure returns (bytes memory, bytes memory) {
        if (_workerId == ExecutorOptions.WORKER_ID) {
            _executorOptions = _executorOptions.length == 0
                ? _newOptions
                : abi.encodePacked(_executorOptions, _newOptions);
        } else if (_workerId == DVNOptions.WORKER_ID) {
            _dvnOptions = _dvnOptions.length == 0 ? _newOptions : abi.encodePacked(_dvnOptions, _newOptions);
        } else {
            revert LZ_ULN_InvalidWorkerId(_workerId);
        }
        return (_executorOptions, _dvnOptions);
    }

    /// @dev decode the legacy options (type 1 or 2) into executorOptions
    /// @param _optionType the legacy option type
    /// @param _options the legacy options, which still has the option type in the first 2 bytes
    /// @return executorOptions the executor options, share the same format of type 3 options
    /// Data format:
    /// legacy type 1: [extraGas]
    /// legacy type 2: [extraGas][dstNativeAmt][dstNativeAddress]
    /// extraGas: uint256, dstNativeAmt: uint256, dstNativeAddress: bytes
    function decodeLegacyOptions(
        uint16 _optionType,
        bytes calldata _options
    ) internal pure returns (bytes memory executorOptions) {
        if (_optionType == TYPE_1) {
            if (_options.length != 34) revert LZ_ULN_InvalidLegacyType1Option();

            // execution gas
            uint128 executionGas = uint256(bytes32(_options[2:2 + 32])).toUint128();

            // dont use the encode function in the ExecutorOptions lib for saving gas by calling abi.encodePacked once
            // the result is a lzReceive option: [executor_id][option_size][option_type][execution_gas]
            // option_type: uint8, execution_gas: uint128
            // option_size = len(option_type) + len(execution_gas) = 1 + 16 = 17
            executorOptions = abi.encodePacked(
                ExecutorOptions.WORKER_ID,
                uint16(17), // 16 + 1, 16 for option_length, + 1 for option_type
                ExecutorOptions.OPTION_TYPE_LZRECEIVE,
                executionGas
            );
        } else if (_optionType == TYPE_2) {
            // receiver size <= 32
            if (_options.length <= 66 || _options.length > 98) revert LZ_ULN_InvalidLegacyType2Option();

            // execution gas
            uint128 executionGas = uint256(bytes32(_options[2:2 + 32])).toUint128();

            // nativeDrop (amount + receiver)
            uint128 amount = uint256(bytes32(_options[34:34 + 32])).toUint128(); // offset 2 + 32
            bytes32 receiver;
            unchecked {
                uint256 receiverLen = _options.length - 66; // offset 2 + 32 + 32
                receiver = bytes32(_options[66:]);
                receiver = receiver >> (8 * (32 - receiverLen)); // padding 0 to the left
            }

            // dont use the encode function in the ExecutorOptions lib for saving gas by calling abi.encodePacked once
            // the result has one lzReceive option and one nativeDrop option:
            //      [executor_id][lzReceive_option_size][option_type][execution_gas] +
            //      [executor_id][nativeDrop_option_size][option_type][nativeDrop_amount][receiver]
            // option_type: uint8, execution_gas: uint128, nativeDrop_amount: uint128, receiver: bytes32
            // lzReceive_option_size = len(option_type) + len(execution_gas) = 1 + 16 = 17
            // nativeDrop_option_size = len(option_type) + len(nativeDrop_amount) + len(receiver) = 1 + 16 + 32 = 49
            executorOptions = abi.encodePacked(
                ExecutorOptions.WORKER_ID,
                uint16(17), // 16 + 1, 16 for option_length, + 1 for option_type
                ExecutorOptions.OPTION_TYPE_LZRECEIVE,
                executionGas,
                ExecutorOptions.WORKER_ID,
                uint16(49), // 48 + 1, 32 + 16 for option_length, + 1 for option_type
                ExecutorOptions.OPTION_TYPE_NATIVE_DROP,
                amount,
                receiver
            );
        } else {
            revert LZ_ULN_UnsupportedOptionType(_optionType);
        }
    }
}

// SPDX-License-Identifier: MIT

pragma solidity >=0.8.0;

import { IMessageLibManager } from "./IMessageLibManager.sol";
import { IMessagingComposer } from "./IMessagingComposer.sol";
import { IMessagingChannel } from "./IMessagingChannel.sol";
import { IMessagingContext } from "./IMessagingContext.sol";

struct MessagingParams {
    uint32 dstEid;
    bytes32 receiver;
    bytes message;
    bytes options;
    bool payInLzToken;
}

struct MessagingReceipt {
    bytes32 guid;
    uint64 nonce;
    MessagingFee fee;
}

struct MessagingFee {
    uint256 nativeFee;
    uint256 lzTokenFee;
}

struct Origin {
    uint32 srcEid;
    bytes32 sender;
    uint64 nonce;
}

interface ILayerZeroEndpointV2 is IMessageLibManager, IMessagingComposer, IMessagingChannel, IMessagingContext {
    event PacketSent(bytes encodedPayload, bytes options, address sendLibrary);

    event PacketVerified(Origin origin, address receiver, bytes32 payloadHash);

    event PacketDelivered(Origin origin, address receiver);

    event LzReceiveAlert(
        address indexed receiver,
        address indexed executor,
        Origin origin,
        bytes32 guid,
        uint256 gas,
        uint256 value,
        bytes message,
        bytes extraData,
        bytes reason
    );

    event LzTokenSet(address token);

    event DelegateSet(address sender, address delegate);

    function quote(MessagingParams calldata _params, address _sender) external view returns (MessagingFee memory);

    function send(
        MessagingParams calldata _params,
        address _refundAddress
    ) external payable returns (MessagingReceipt memory);

    function verify(Origin calldata _origin, address _receiver, bytes32 _payloadHash) external;

    function verifiable(Origin calldata _origin, address _receiver) external view returns (bool);

    function initializable(Origin calldata _origin, address _receiver) external view returns (bool);

    function lzReceive(
        Origin calldata _origin,
        address _receiver,
        bytes32 _guid,
        bytes calldata _message,
        bytes calldata _extraData
    ) external payable;

    // oapp can burn messages partially by calling this function with its own business logic if messages are verified in order
    function clear(address _oapp, Origin calldata _origin, bytes32 _guid, bytes calldata _message) external;

    function setLzToken(address _lzToken) external;

    function lzToken() external view returns (address);

    function nativeToken() external view returns (address);

    function setDelegate(address _delegate) external;
}

// SPDX-License-Identifier: MIT

pragma solidity >=0.8.0;

struct SetConfigParam {
    uint32 eid;
    uint32 configType;
    bytes config;
}

interface IMessageLibManager {
    struct Timeout {
        address lib;
        uint256 expiry;
    }

    event LibraryRegistered(address newLib);
    event DefaultSendLibrarySet(uint32 eid, address newLib);
    event DefaultReceiveLibrarySet(uint32 eid, address newLib);
    event DefaultReceiveLibraryTimeoutSet(uint32 eid, address oldLib, uint256 expiry);
    event SendLibrarySet(address sender, uint32 eid, address newLib);
    event ReceiveLibrarySet(address receiver, uint32 eid, address newLib);
    event ReceiveLibraryTimeoutSet(address receiver, uint32 eid, address oldLib, uint256 timeout);

    function registerLibrary(address _lib) external;

    function isRegisteredLibrary(address _lib) external view returns (bool);

    function getRegisteredLibraries() external view returns (address[] memory);

    function setDefaultSendLibrary(uint32 _eid, address _newLib) external;

    function defaultSendLibrary(uint32 _eid) external view returns (address);

    function setDefaultReceiveLibrary(uint32 _eid, address _newLib, uint256 _gracePeriod) external;

    function defaultReceiveLibrary(uint32 _eid) external view returns (address);

    function setDefaultReceiveLibraryTimeout(uint32 _eid, address _lib, uint256 _expiry) external;

    function defaultReceiveLibraryTimeout(uint32 _eid) external view returns (address lib, uint256 expiry);

    function isSupportedEid(uint32 _eid) external view returns (bool);

    function isValidReceiveLibrary(address _receiver, uint32 _eid, address _lib) external view returns (bool);

    /// ------------------- OApp interfaces -------------------
    function setSendLibrary(address _oapp, uint32 _eid, address _newLib) external;

    function getSendLibrary(address _sender, uint32 _eid) external view returns (address lib);

    function isDefaultSendLibrary(address _sender, uint32 _eid) external view returns (bool);

    function setReceiveLibrary(address _oapp, uint32 _eid, address _newLib, uint256 _gracePeriod) external;

    function getReceiveLibrary(address _receiver, uint32 _eid) external view returns (address lib, bool isDefault);

    function setReceiveLibraryTimeout(address _oapp, uint32 _eid, address _lib, uint256 _expiry) external;

    function receiveLibraryTimeout(address _receiver, uint32 _eid) external view returns (address lib, uint256 expiry);

    function setConfig(address _oapp, address _lib, SetConfigParam[] calldata _params) external;

    function getConfig(
        address _oapp,
        address _lib,
        uint32 _eid,
        uint32 _configType
    ) external view returns (bytes memory config);
}

// SPDX-License-Identifier: MIT

pragma solidity >=0.8.0;

interface IMessagingChannel {
    event InboundNonceSkipped(uint32 srcEid, bytes32 sender, address receiver, uint64 nonce);
    event PacketNilified(uint32 srcEid, bytes32 sender, address receiver, uint64 nonce, bytes32 payloadHash);
    event PacketBurnt(uint32 srcEid, bytes32 sender, address receiver, uint64 nonce, bytes32 payloadHash);

    function eid() external view returns (uint32);

    // this is an emergency function if a message cannot be verified for some reasons
    // required to provide _nextNonce to avoid race condition
    function skip(address _oapp, uint32 _srcEid, bytes32 _sender, uint64 _nonce) external;

    function nilify(address _oapp, uint32 _srcEid, bytes32 _sender, uint64 _nonce, bytes32 _payloadHash) external;

    function burn(address _oapp, uint32 _srcEid, bytes32 _sender, uint64 _nonce, bytes32 _payloadHash) external;

    function nextGuid(address _sender, uint32 _dstEid, bytes32 _receiver) external view returns (bytes32);

    function inboundNonce(address _receiver, uint32 _srcEid, bytes32 _sender) external view returns (uint64);

    function outboundNonce(address _sender, uint32 _dstEid, bytes32 _receiver) external view returns (uint64);

    function inboundPayloadHash(
        address _receiver,
        uint32 _srcEid,
        bytes32 _sender,
        uint64 _nonce
    ) external view returns (bytes32);

    function lazyInboundNonce(address _receiver, uint32 _srcEid, bytes32 _sender) external view returns (uint64);
}

// SPDX-License-Identifier: MIT

pragma solidity >=0.8.0;

interface IMessagingComposer {
    event ComposeSent(address from, address to, bytes32 guid, uint16 index, bytes message);
    event ComposeDelivered(address from, address to, bytes32 guid, uint16 index);
    event LzComposeAlert(
        address indexed from,
        address indexed to,
        address indexed executor,
        bytes32 guid,
        uint16 index,
        uint256 gas,
        uint256 value,
        bytes message,
        bytes extraData,
        bytes reason
    );

    function composeQueue(
        address _from,
        address _to,
        bytes32 _guid,
        uint16 _index
    ) external view returns (bytes32 messageHash);

    function sendCompose(address _to, bytes32 _guid, uint16 _index, bytes calldata _message) external;

    function lzCompose(
        address _from,
        address _to,
        bytes32 _guid,
        uint16 _index,
        bytes calldata _message,
        bytes calldata _extraData
    ) external payable;
}

// SPDX-License-Identifier: MIT

pragma solidity >=0.8.0;

interface IMessagingContext {
    function isSendingMessage() external view returns (bool);

    function getSendContext() external view returns (uint32 dstEid, address sender);
}

// SPDX-License-Identifier: LZBL-1.2

pragma solidity ^0.8.20;

library CalldataBytesLib {
    function toU8(bytes calldata _bytes, uint256 _start) internal pure returns (uint8) {
        return uint8(_bytes[_start]);
    }

    function toU16(bytes calldata _bytes, uint256 _start) internal pure returns (uint16) {
        unchecked {
            uint256 end = _start + 2;
            return uint16(bytes2(_bytes[_start:end]));
        }
    }

    function toU32(bytes calldata _bytes, uint256 _start) internal pure returns (uint32) {
        unchecked {
            uint256 end = _start + 4;
            return uint32(bytes4(_bytes[_start:end]));
        }
    }

    function toU64(bytes calldata _bytes, uint256 _start) internal pure returns (uint64) {
        unchecked {
            uint256 end = _start + 8;
            return uint64(bytes8(_bytes[_start:end]));
        }
    }

    function toU128(bytes calldata _bytes, uint256 _start) internal pure returns (uint128) {
        unchecked {
            uint256 end = _start + 16;
            return uint128(bytes16(_bytes[_start:end]));
        }
    }

    function toU256(bytes calldata _bytes, uint256 _start) internal pure returns (uint256) {
        unchecked {
            uint256 end = _start + 32;
            return uint256(bytes32(_bytes[_start:end]));
        }
    }

    function toAddr(bytes calldata _bytes, uint256 _start) internal pure returns (address) {
        unchecked {
            uint256 end = _start + 20;
            return address(bytes20(_bytes[_start:end]));
        }
    }

    function toB32(bytes calldata _bytes, uint256 _start) internal pure returns (bytes32) {
        unchecked {
            uint256 end = _start + 32;
            return bytes32(_bytes[_start:end]);
        }
    }
}

// SPDX-License-Identifier: MIT

// modified from https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/structs/BitMaps.sol
pragma solidity ^0.8.20;

type BitMap256 is uint256;

using BitMaps for BitMap256 global;

library BitMaps {
    /**
     * @dev Returns whether the bit at `index` is set.
     */
    function get(BitMap256 bitmap, uint8 index) internal pure returns (bool) {
        uint256 mask = 1 << index;
        return BitMap256.unwrap(bitmap) & mask != 0;
    }

    /**
     * @dev Sets the bit at `index`.
     */
    function set(BitMap256 bitmap, uint8 index) internal pure returns (BitMap256) {
        uint256 mask = 1 << index;
        return BitMap256.wrap(BitMap256.unwrap(bitmap) | mask);
    }
}

// SPDX-License-Identifier: LZBL-1.2

pragma solidity ^0.8.20;

import { CalldataBytesLib } from "../../libs/CalldataBytesLib.sol";

library ExecutorOptions {
    using CalldataBytesLib for bytes;

    uint8 internal constant WORKER_ID = 1;

    uint8 internal constant OPTION_TYPE_LZRECEIVE = 1;
    uint8 internal constant OPTION_TYPE_NATIVE_DROP = 2;
    uint8 internal constant OPTION_TYPE_LZCOMPOSE = 3;
    uint8 internal constant OPTION_TYPE_ORDERED_EXECUTION = 4;

    error Executor_InvalidLzReceiveOption();
    error Executor_InvalidNativeDropOption();
    error Executor_InvalidLzComposeOption();

    /// @dev decode the next executor option from the options starting from the specified cursor
    /// @param _options [executor_id][executor_option][executor_id][executor_option]...
    ///        executor_option = [option_size][option_type][option]
    ///        option_size = len(option_type) + len(option)
    ///        executor_id: uint8, option_size: uint16, option_type: uint8, option: bytes
    /// @param _cursor the cursor to start decoding from
    /// @return optionType the type of the option
    /// @return option the option of the executor
    /// @return cursor the cursor to start decoding the next executor option
    function nextExecutorOption(
        bytes calldata _options,
        uint256 _cursor
    ) internal pure returns (uint8 optionType, bytes calldata option, uint256 cursor) {
        unchecked {
            // skip worker id
            cursor = _cursor + 1;

            // read option size
            uint16 size = _options.toU16(cursor);
            cursor += 2;

            // read option type
            optionType = _options.toU8(cursor);

            // startCursor and endCursor are used to slice the option from _options
            uint256 startCursor = cursor + 1; // skip option type
            uint256 endCursor = cursor + size;
            option = _options[startCursor:endCursor];
            cursor += size;
        }
    }

    function decodeLzReceiveOption(bytes calldata _option) internal pure returns (uint128 gas, uint128 value) {
        if (_option.length != 16 && _option.length != 32) revert Executor_InvalidLzReceiveOption();
        gas = _option.toU128(0);
        value = _option.length == 32 ? _option.toU128(16) : 0;
    }

    function decodeNativeDropOption(bytes calldata _option) internal pure returns (uint128 amount, bytes32 receiver) {
        if (_option.length != 48) revert Executor_InvalidNativeDropOption();
        amount = _option.toU128(0);
        receiver = _option.toB32(16);
    }

    function decodeLzComposeOption(
        bytes calldata _option
    ) internal pure returns (uint16 index, uint128 gas, uint128 value) {
        if (_option.length != 18 && _option.length != 34) revert Executor_InvalidLzComposeOption();
        index = _option.toU16(0);
        gas = _option.toU128(2);
        value = _option.length == 34 ? _option.toU128(18) : 0;
    }

    function encodeLzReceiveOption(uint128 _gas, uint128 _value) internal pure returns (bytes memory) {
        return _value == 0 ? abi.encodePacked(_gas) : abi.encodePacked(_gas, _value);
    }

    function encodeNativeDropOption(uint128 _amount, bytes32 _receiver) internal pure returns (bytes memory) {
        return abi.encodePacked(_amount, _receiver);
    }

    function encodeLzComposeOption(uint16 _index, uint128 _gas, uint128 _value) internal pure returns (bytes memory) {
        return _value == 0 ? abi.encodePacked(_index, _gas) : abi.encodePacked(_index, _gas, _value);
    }
}

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

import { ILayerZeroEndpointV2 } from "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol";

/**
 * @title IOAppCore
 */
interface IOAppCore {
    // Custom error messages
    error OnlyPeer(uint32 eid, bytes32 sender);
    error NoPeer(uint32 eid);
    error InvalidEndpointCall();
    error InvalidDelegate();

    // Event emitted when a peer (OApp) is set for a corresponding endpoint
    event PeerSet(uint32 eid, bytes32 peer);

    /**
     * @notice Retrieves the OApp version information.
     * @return senderVersion The version of the OAppSender.sol contract.
     * @return receiverVersion The version of the OAppReceiver.sol contract.
     */
    function oAppVersion() external view returns (uint64 senderVersion, uint64 receiverVersion);

    /**
     * @notice Retrieves the LayerZero endpoint associated with the OApp.
     * @return iEndpoint The LayerZero endpoint as an interface.
     */
    function endpoint() external view returns (ILayerZeroEndpointV2 iEndpoint);

    /**
     * @notice Retrieves the peer (OApp) associated with a corresponding endpoint.
     * @param _eid The endpoint ID.
     * @return peer The peer address (OApp instance) associated with the corresponding endpoint.
     */
    function peers(uint32 _eid) external view returns (bytes32 peer);

    /**
     * @notice Sets the peer address (OApp instance) for a corresponding endpoint.
     * @param _eid The endpoint ID.
     * @param _peer The address of the peer to be associated with the corresponding endpoint.
     */
    function setPeer(uint32 _eid, bytes32 _peer) external;

    /**
     * @notice Sets the delegate address for the OApp Core.
     * @param _delegate The address of the delegate to be set.
     */
    function setDelegate(address _delegate) external;
}

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

import { BytesLib } from "solidity-bytes-utils/contracts/BytesLib.sol";
import { SafeCast } from "@openzeppelin/contracts/utils/math/SafeCast.sol";

import { ExecutorOptions } from "@layerzerolabs/lz-evm-messagelib-v2/contracts/libs/ExecutorOptions.sol";
import { DVNOptions } from "@layerzerolabs/lz-evm-messagelib-v2/contracts/uln/libs/DVNOptions.sol";

/**
 * @title OptionsBuilder
 * @dev Library for building and encoding various message options.
 */
library OptionsBuilder {
    using SafeCast for uint256;
    using BytesLib for bytes;

    // Constants for options types
    uint16 internal constant TYPE_1 = 1; // legacy options type 1
    uint16 internal constant TYPE_2 = 2; // legacy options type 2
    uint16 internal constant TYPE_3 = 3;

    // Custom error message
    error InvalidSize(uint256 max, uint256 actual);
    error InvalidOptionType(uint16 optionType);

    // Modifier to ensure only options of type 3 are used
    modifier onlyType3(bytes memory _options) {
        if (_options.toUint16(0) != TYPE_3) revert InvalidOptionType(_options.toUint16(0));
        _;
    }

    /**
     * @dev Creates a new options container with type 3.
     * @return options The newly created options container.
     */
    function newOptions() internal pure returns (bytes memory) {
        return abi.encodePacked(TYPE_3);
    }

    /**
     * @dev Adds an executor LZ receive option to the existing options.
     * @param _options The existing options container.
     * @param _gas The gasLimit used on the lzReceive() function in the OApp.
     * @param _value The msg.value passed to the lzReceive() function in the OApp.
     * @return options The updated options container.
     *
     * @dev When multiples of this option are added, they are summed by the executor
     * eg. if (_gas: 200k, and _value: 1 ether) AND (_gas: 100k, _value: 0.5 ether) are sent in an option to the LayerZeroEndpoint,
     * that becomes (300k, 1.5 ether) when the message is executed on the remote lzReceive() function.
     */
    function addExecutorLzReceiveOption(
        bytes memory _options,
        uint128 _gas,
        uint128 _value
    ) internal pure onlyType3(_options) returns (bytes memory) {
        bytes memory option = ExecutorOptions.encodeLzReceiveOption(_gas, _value);
        return addExecutorOption(_options, ExecutorOptions.OPTION_TYPE_LZRECEIVE, option);
    }

    /**
     * @dev Adds an executor native drop option to the existing options.
     * @param _options The existing options container.
     * @param _amount The amount for the native value that is airdropped to the 'receiver'.
     * @param _receiver The receiver address for the native drop option.
     * @return options The updated options container.
     *
     * @dev When multiples of this option are added, they are summed by the executor on the remote chain.
     */
    function addExecutorNativeDropOption(
        bytes memory _options,
        uint128 _amount,
        bytes32 _receiver
    ) internal pure onlyType3(_options) returns (bytes memory) {
        bytes memory option = ExecutorOptions.encodeNativeDropOption(_amount, _receiver);
        return addExecutorOption(_options, ExecutorOptions.OPTION_TYPE_NATIVE_DROP, option);
    }

    // /**
    //  * @dev Adds an executor native drop option to the existing options.
    //  * @param _options The existing options container.
    //  * @param _amount The amount for the native value that is airdropped to the 'receiver'.
    //  * @param _receiver The receiver address for the native drop option.
    //  * @return options The updated options container.
    //  *
    //  * @dev When multiples of this option are added, they are summed by the executor on the remote chain.
    //  */
    function addExecutorLzReadOption(
        bytes memory _options,
        uint128 _gas,
        uint32 _size,
        uint128 _value
    ) internal pure onlyType3(_options) returns (bytes memory) {
        bytes memory option = ExecutorOptions.encodeLzReadOption(_gas, _size, _value);
        return addExecutorOption(_options, ExecutorOptions.OPTION_TYPE_LZREAD, option);
    }

    /**
     * @dev Adds an executor LZ compose option to the existing options.
     * @param _options The existing options container.
     * @param _index The index for the lzCompose() function call.
     * @param _gas The gasLimit for the lzCompose() function call.
     * @param _value The msg.value for the lzCompose() function call.
     * @return options The updated options container.
     *
     * @dev When multiples of this option are added, they are summed PER index by the executor on the remote chain.
     * @dev If the OApp sends N lzCompose calls on the remote, you must provide N incremented indexes starting with 0.
     * ie. When your remote OApp composes (N = 3) messages, you must set this option for index 0,1,2
     */
    function addExecutorLzComposeOption(
        bytes memory _options,
        uint16 _index,
        uint128 _gas,
        uint128 _value
    ) internal pure onlyType3(_options) returns (bytes memory) {
        bytes memory option = ExecutorOptions.encodeLzComposeOption(_index, _gas, _value);
        return addExecutorOption(_options, ExecutorOptions.OPTION_TYPE_LZCOMPOSE, option);
    }

    /**
     * @dev Adds an executor ordered execution option to the existing options.
     * @param _options The existing options container.
     * @return options The updated options container.
     */
    function addExecutorOrderedExecutionOption(
        bytes memory _options
    ) internal pure onlyType3(_options) returns (bytes memory) {
        return addExecutorOption(_options, ExecutorOptions.OPTION_TYPE_ORDERED_EXECUTION, bytes(""));
    }

    /**
     * @dev Adds a DVN pre-crime option to the existing options.
     * @param _options The existing options container.
     * @param _dvnIdx The DVN index for the pre-crime option.
     * @return options The updated options container.
     */
    function addDVNPreCrimeOption(
        bytes memory _options,
        uint8 _dvnIdx
    ) internal pure onlyType3(_options) returns (bytes memory) {
        return addDVNOption(_options, _dvnIdx, DVNOptions.OPTION_TYPE_PRECRIME, bytes(""));
    }

    /**
     * @dev Adds an executor option to the existing options.
     * @param _options The existing options container.
     * @param _optionType The type of the executor option.
     * @param _option The encoded data for the executor option.
     * @return options The updated options container.
     */
    function addExecutorOption(
        bytes memory _options,
        uint8 _optionType,
        bytes memory _option
    ) internal pure onlyType3(_options) returns (bytes memory) {
        return
            abi.encodePacked(
                _options,
                ExecutorOptions.WORKER_ID,
                _option.length.toUint16() + 1, // +1 for optionType
                _optionType,
                _option
            );
    }

    /**
     * @dev Adds a DVN option to the existing options.
     * @param _options The existing options container.
     * @param _dvnIdx The DVN index for the DVN option.
     * @param _optionType The type of the DVN option.
     * @param _option The encoded data for the DVN option.
     * @return options The updated options container.
     */
    function addDVNOption(
        bytes memory _options,
        uint8 _dvnIdx,
        uint8 _optionType,
        bytes memory _option
    ) internal pure onlyType3(_options) returns (bytes memory) {
        return
            abi.encodePacked(
                _options,
                DVNOptions.WORKER_ID,
                _option.length.toUint16() + 2, // +2 for optionType and dvnIdx
                _dvnIdx,
                _optionType,
                _option
            );
    }

    /**
     * @dev Encodes legacy options of type 1.
     * @param _executionGas The gasLimit value passed to lzReceive().
     * @return legacyOptions The encoded legacy options.
     */
    function encodeLegacyOptionsType1(uint256 _executionGas) internal pure returns (bytes memory) {
        if (_executionGas > type(uint128).max) revert InvalidSize(type(uint128).max, _executionGas);
        return abi.encodePacked(TYPE_1, _executionGas);
    }

    /**
     * @dev Encodes legacy options of type 2.
     * @param _executionGas The gasLimit value passed to lzReceive().
     * @param _nativeForDst The amount of native air dropped to the receiver.
     * @param _receiver The _nativeForDst receiver address.
     * @return legacyOptions The encoded legacy options of type 2.
     */
    function encodeLegacyOptionsType2(
        uint256 _executionGas,
        uint256 _nativeForDst,
        bytes memory _receiver // @dev Use bytes instead of bytes32 in legacy type 2 for _receiver.
    ) internal pure returns (bytes memory) {
        if (_executionGas > type(uint128).max) revert InvalidSize(type(uint128).max, _executionGas);
        if (_nativeForDst > type(uint128).max) revert InvalidSize(type(uint128).max, _nativeForDst);
        if (_receiver.length > 32) revert InvalidSize(32, _receiver.length);
        return abi.encodePacked(TYPE_2, _executionGas, _nativeForDst, _receiver);
    }
}

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { IOAppCore, ILayerZeroEndpointV2 } from "./interfaces/IOAppCore.sol";

/**
 * @title OAppCore
 * @dev Abstract contract implementing the IOAppCore interface with basic OApp configurations.
 */
abstract contract OAppCore is IOAppCore, Ownable {
    // The LayerZero endpoint associated with the given OApp
    ILayerZeroEndpointV2 public immutable endpoint;

    // Mapping to store peers associated with corresponding endpoints
    mapping(uint32 eid => bytes32 peer) public peers;

    /**
     * @dev Constructor to initialize the OAppCore with the provided endpoint and delegate.
     * @param _endpoint The address of the LOCAL Layer Zero endpoint.
     * @param _delegate The delegate capable of making OApp configurations inside of the endpoint.
     *
     * @dev The delegate typically should be set as the owner of the contract.
     */
    constructor(address _endpoint, address _delegate) {
        endpoint = ILayerZeroEndpointV2(_endpoint);

        if (_delegate == address(0)) revert InvalidDelegate();
        endpoint.setDelegate(_delegate);
    }

    /**
     * @notice Sets the peer address (OApp instance) for a corresponding endpoint.
     * @param _eid The endpoint ID.
     * @param _peer The address of the peer to be associated with the corresponding endpoint.
     *
     * @dev Only the owner/admin of the OApp can call this function.
     * @dev Indicates that the peer is trusted to send LayerZero messages to this OApp.
     * @dev Set this to bytes32(0) to remove the peer address.
     * @dev Peer is a bytes32 to accommodate non-evm chains.
     */
    function setPeer(uint32 _eid, bytes32 _peer) public virtual onlyOwner {
        _setPeer(_eid, _peer);
    }

    /**
     * @notice Sets the peer address (OApp instance) for a corresponding endpoint.
     * @param _eid The endpoint ID.
     * @param _peer The address of the peer to be associated with the corresponding endpoint.
     *
     * @dev Indicates that the peer is trusted to send LayerZero messages to this OApp.
     * @dev Set this to bytes32(0) to remove the peer address.
     * @dev Peer is a bytes32 to accommodate non-evm chains.
     */
    function _setPeer(uint32 _eid, bytes32 _peer) internal virtual {
        peers[_eid] = _peer;
        emit PeerSet(_eid, _peer);
    }

    /**
     * @notice Internal function to get the peer address associated with a specific endpoint; reverts if NOT set.
     * ie. the peer is set to bytes32(0).
     * @param _eid The endpoint ID.
     * @return peer The address of the peer associated with the specified endpoint.
     */
    function _getPeerOrRevert(uint32 _eid) internal view virtual returns (bytes32) {
        bytes32 peer = peers[_eid];
        if (peer == bytes32(0)) revert NoPeer(_eid);
        return peer;
    }

    /**
     * @notice Sets the delegate address for the OApp.
     * @param _delegate The address of the delegate to be set.
     *
     * @dev Only the owner/admin of the OApp can call this function.
     * @dev Provides the ability for a delegate to set configs, on behalf of the OApp, directly on the Endpoint contract.
     */
    function setDelegate(address _delegate) public onlyOwner {
        endpoint.setDelegate(_delegate);
    }
}

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

import { SafeERC20, IERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { MessagingParams, MessagingFee, MessagingReceipt } from "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol";
import { OAppCore } from "./OAppCore.sol";

/**
 * @title OAppSender
 * @dev Abstract contract implementing the OAppSender functionality for sending messages to a LayerZero endpoint.
 */
abstract contract OAppSender is OAppCore {
    using SafeERC20 for IERC20;

    // Custom error messages
    error NotEnoughNative(uint256 msgValue);
    error LzTokenUnavailable();

    // @dev The version of the OAppSender implementation.
    // @dev Version is bumped when changes are made to this contract.
    uint64 internal constant SENDER_VERSION = 1;

    /**
     * @notice Retrieves the OApp version information.
     * @return senderVersion The version of the OAppSender.sol contract.
     * @return receiverVersion The version of the OAppReceiver.sol contract.
     *
     * @dev Providing 0 as the default for OAppReceiver version. Indicates that the OAppReceiver is not implemented.
     * ie. this is a SEND only OApp.
     * @dev If the OApp uses both OAppSender and OAppReceiver, then this needs to be override returning the correct versions
     */
    function oAppVersion() public view virtual returns (uint64 senderVersion, uint64 receiverVersion) {
        return (SENDER_VERSION, 0);
    }

    /**
     * @dev Internal function to interact with the LayerZero EndpointV2.quote() for fee calculation.
     * @param _dstEid The destination endpoint ID.
     * @param _message The message payload.
     * @param _options Additional options for the message.
     * @param _payInLzToken Flag indicating whether to pay the fee in LZ tokens.
     * @return fee The calculated MessagingFee for the message.
     *      - nativeFee: The native fee for the message.
     *      - lzTokenFee: The LZ token fee for the message.
     */
    function _quote(
        uint32 _dstEid,
        bytes memory _message,
        bytes memory _options,
        bool _payInLzToken
    ) internal view virtual returns (MessagingFee memory fee) {
        return
            endpoint.quote(
                MessagingParams(_dstEid, _getPeerOrRevert(_dstEid), _message, _options, _payInLzToken),
                address(this)
            );
    }

    /**
     * @dev Internal function to interact with the LayerZero EndpointV2.send() for sending a message.
     * @param _dstEid The destination endpoint ID.
     * @param _message The message payload.
     * @param _options Additional options for the message.
     * @param _fee The calculated LayerZero fee for the message.
     *      - nativeFee: The native fee.
     *      - lzTokenFee: The lzToken fee.
     * @param _refundAddress The address to receive any excess fee values sent to the endpoint.
     * @return receipt The receipt for the sent message.
     *      - guid: The unique identifier for the sent message.
     *      - nonce: The nonce of the sent message.
     *      - fee: The LayerZero fee incurred for the message.
     */
    function _lzSend(
        uint32 _dstEid,
        bytes memory _message,
        bytes memory _options,
        MessagingFee memory _fee,
        address _refundAddress
    ) internal virtual returns (MessagingReceipt memory receipt) {
        // @dev Push corresponding fees to the endpoint, any excess is sent back to the _refundAddress from the endpoint.
        uint256 messageValue = _payNative(_fee.nativeFee);
        if (_fee.lzTokenFee > 0) _payLzToken(_fee.lzTokenFee);

        return
            // solhint-disable-next-line check-send-result
            endpoint.send{ value: messageValue }(
                MessagingParams(_dstEid, _getPeerOrRevert(_dstEid), _message, _options, _fee.lzTokenFee > 0),
                _refundAddress
            );
    }

    /**
     * @dev Internal function to pay the native fee associated with the message.
     * @param _nativeFee The native fee to be paid.
     * @return nativeFee The amount of native currency paid.
     *
     * @dev If the OApp needs to initiate MULTIPLE LayerZero messages in a single transaction,
     * this will need to be overridden because msg.value would contain multiple lzFees.
     * @dev Should be overridden in the event the LayerZero endpoint requires a different native currency.
     * @dev Some EVMs use an ERC20 as a method for paying transactions/gasFees.
     * @dev The endpoint is EITHER/OR, ie. it will NOT support both types of native payment at a time.
     */
    function _payNative(uint256 _nativeFee) internal virtual returns (uint256 nativeFee) {
        if (msg.value != _nativeFee) revert NotEnoughNative(msg.value);
        return _nativeFee;
    }

    /**
     * @dev Internal function to pay the LZ token fee associated with the message.
     * @param _lzTokenFee The LZ token fee to be paid.
     *
     * @dev If the caller is trying to pay in the specified lzToken, then the lzTokenFee is passed to the endpoint.
     * @dev Any excess sent, is passed back to the specified _refundAddress in the _lzSend().
     */
    function _payLzToken(uint256 _lzTokenFee) internal virtual {
        // @dev Cannot cache the token because it is not immutable in the endpoint.
        address lzToken = endpoint.lzToken();
        if (lzToken == address(0)) revert LzTokenUnavailable();

        // Pay LZ token fee by sending tokens to the endpoint.
        IERC20(lzToken).safeTransferFrom(msg.sender, address(endpoint), _lzTokenFee);
    }
}

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

import { MessagingReceipt, MessagingFee } from "@layerzerolabs/oapp-evm/contracts/oapp/OAppSender.sol";

/**
 * @dev Struct representing token parameters for the OFT send() operation.
 */
struct SendParam {
    uint32 dstEid; // Destination endpoint ID.
    bytes32 to; // Recipient address.
    uint256 amountLD; // Amount to send in local decimals.
    uint256 minAmountLD; // Minimum amount to send in local decimals.
    bytes extraOptions; // Additional options supplied by the caller to be used in the LayerZero message.
    bytes composeMsg; // The composed message for the send() operation.
    bytes oftCmd; // The OFT command to be executed, unused in default OFT implementations.
}

/**
 * @dev Struct representing OFT limit information.
 * @dev These amounts can change dynamically and are up the specific oft implementation.
 */
struct OFTLimit {
    uint256 minAmountLD; // Minimum amount in local decimals that can be sent to the recipient.
    uint256 maxAmountLD; // Maximum amount in local decimals that can be sent to the recipient.
}

/**
 * @dev Struct representing OFT receipt information.
 */
struct OFTReceipt {
    uint256 amountSentLD; // Amount of tokens ACTUALLY debited from the sender in local decimals.
    // @dev In non-default implementations, the amountReceivedLD COULD differ from this value.
    uint256 amountReceivedLD; // Amount of tokens to be received on the remote side.
}

/**
 * @dev Struct representing OFT fee details.
 * @dev Future proof mechanism to provide a standardized way to communicate fees to things like a UI.
 */
struct OFTFeeDetail {
    int256 feeAmountLD; // Amount of the fee in local decimals.
    string description; // Description of the fee.
}

/**
 * @title IOFT
 * @dev Interface for the OftChain (OFT) token.
 * @dev Does not inherit ERC20 to accommodate usage by OFTAdapter as well.
 * @dev This specific interface ID is '0x02e49c2c'.
 */
interface IOFT {
    // Custom error messages
    error InvalidLocalDecimals();
    error SlippageExceeded(uint256 amountLD, uint256 minAmountLD);

    // Events
    event OFTSent(
        bytes32 indexed guid, // GUID of the OFT message.
        uint32 dstEid, // Destination Endpoint ID.
        address indexed fromAddress, // Address of the sender on the src chain.
        uint256 amountSentLD, // Amount of tokens sent in local decimals.
        uint256 amountReceivedLD // Amount of tokens received in local decimals.
    );
    event OFTReceived(
        bytes32 indexed guid, // GUID of the OFT message.
        uint32 srcEid, // Source Endpoint ID.
        address indexed toAddress, // Address of the recipient on the dst chain.
        uint256 amountReceivedLD // Amount of tokens received in local decimals.
    );

    /**
     * @notice Retrieves interfaceID and the version of the OFT.
     * @return interfaceId The interface ID.
     * @return version The version.
     *
     * @dev interfaceId: This specific interface ID is '0x02e49c2c'.
     * @dev version: Indicates a cross-chain compatible msg encoding with other OFTs.
     * @dev If a new feature is added to the OFT cross-chain msg encoding, the version will be incremented.
     * ie. localOFT version(x,1) CAN send messages to remoteOFT version(x,1)
     */
    function oftVersion() external view returns (bytes4 interfaceId, uint64 version);

    /**
     * @notice Retrieves the address of the token associated with the OFT.
     * @return token The address of the ERC20 token implementation.
     */
    function token() external view returns (address);

    /**
     * @notice Indicates whether the OFT contract requires approval of the 'token()' to send.
     * @return requiresApproval Needs approval of the underlying token implementation.
     *
     * @dev Allows things like wallet implementers to determine integration requirements,
     * without understanding the underlying token implementation.
     */
    function approvalRequired() external view returns (bool);

    /**
     * @notice Retrieves the shared decimals of the OFT.
     * @return sharedDecimals The shared decimals of the OFT.
     */
    function sharedDecimals() external view returns (uint8);

    /**
     * @notice Provides the fee breakdown and settings data for an OFT. Unused in the default implementation.
     * @param _sendParam The parameters for the send operation.
     * @return limit The OFT limit information.
     * @return oftFeeDetails The details of OFT fees.
     * @return receipt The OFT receipt information.
     */
    function quoteOFT(
        SendParam calldata _sendParam
    ) external view returns (OFTLimit memory, OFTFeeDetail[] memory oftFeeDetails, OFTReceipt memory);

    /**
     * @notice Provides a quote for the send() operation.
     * @param _sendParam The parameters for the send() operation.
     * @param _payInLzToken Flag indicating whether the caller is paying in the LZ token.
     * @return fee The calculated LayerZero messaging fee from the send() operation.
     *
     * @dev MessagingFee: LayerZero msg fee
     *  - nativeFee: The native fee.
     *  - lzTokenFee: The lzToken fee.
     */
    function quoteSend(SendParam calldata _sendParam, bool _payInLzToken) external view returns (MessagingFee memory);

    /**
     * @notice Executes the send() operation.
     * @param _sendParam The parameters for the send operation.
     * @param _fee The fee information supplied by the caller.
     *      - nativeFee: The native fee.
     *      - lzTokenFee: The lzToken fee.
     * @param _refundAddress The address to receive any excess funds from fees etc. on the src.
     * @return receipt The LayerZero messaging receipt from the send() operation.
     * @return oftReceipt The OFT receipt information.
     *
     * @dev MessagingReceipt: LayerZero msg receipt
     *  - guid: The unique identifier for the sent message.
     *  - nonce: The nonce of the sent message.
     *  - fee: The LayerZero fee incurred for the message.
     */
    function send(
        SendParam calldata _sendParam,
        MessagingFee calldata _fee,
        address _refundAddress
    ) external payable returns (MessagingReceipt memory, OFTReceipt memory);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

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

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

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/ERC20.sol)

pragma solidity ^0.8.0;

import "./IERC20.sol";
import "./extensions/IERC20Metadata.sol";
import "../../utils/Context.sol";

/**
 * @dev Implementation of the {IERC20} interface.
 *
 * This implementation is agnostic to the way tokens are created. This means
 * that a supply mechanism has to be added in a derived contract using {_mint}.
 * For a generic mechanism see {ERC20PresetMinterPauser}.
 *
 * TIP: For a detailed writeup see our guide
 * https://forum.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.
 *
 * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
 * functions have been added to mitigate the well-known issues around setting
 * allowances. See {IERC20-approve}.
 */
contract ERC20 is Context, IERC20, IERC20Metadata {
    mapping(address => uint256) private _balances;

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

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;

    /**
     * @dev Sets the values for {name} and {symbol}.
     *
     * 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 override returns (string memory) {
        return _name;
    }

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

    /**
     * @dev Returns the number of decimals used to get its user representation.
     * For example, if `decimals` equals `2`, a balance of `505` tokens should
     * be displayed to a user as `5.05` (`505 / 10 ** 2`).
     *
     * Tokens usually opt for a value of 18, imitating the relationship between
     * Ether and Wei. This is the 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 override returns (uint8) {
        return 18;
    }

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

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

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

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

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

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

    /**
     * @dev Atomically increases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
        address owner = _msgSender();
        _approve(owner, spender, allowance(owner, spender) + addedValue);
        return true;
    }

    /**
     * @dev Atomically decreases the allowance granted to `spender` by the caller.
     *
     * This is an alternative to {approve} that can be used as a mitigation for
     * problems described in {IERC20-approve}.
     *
     * Emits an {Approval} event indicating the updated allowance.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `spender` must have allowance for the caller of at least
     * `subtractedValue`.
     */
    function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
        address owner = _msgSender();
        uint256 currentAllowance = allowance(owner, spender);
        require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
        unchecked {
            _approve(owner, spender, currentAllowance - subtractedValue);
        }

        return true;
    }

    /**
     * @dev Moves `amount` of tokens from `from` to `to`.
     *
     * This internal function is equivalent to {transfer}, and can be used to
     * e.g. implement automatic token fees, slashing mechanisms, etc.
     *
     * Emits a {Transfer} event.
     *
     * Requirements:
     *
     * - `from` cannot be the zero address.
     * - `to` cannot be the zero address.
     * - `from` must have a balance of at least `amount`.
     */
    function _transfer(address from, address to, uint256 amount) internal virtual {
        require(from != address(0), "ERC20: transfer from the zero address");
        require(to != address(0), "ERC20: transfer to the zero address");

        _beforeTokenTransfer(from, to, amount);

        uint256 fromBalance = _balances[from];
        require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
        unchecked {
            _balances[from] = fromBalance - amount;
            // Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by
            // decrementing then incrementing.
            _balances[to] += amount;
        }

        emit Transfer(from, to, amount);

        _afterTokenTransfer(from, to, amount);
    }

    /** @dev Creates `amount` tokens and assigns them to `account`, increasing
     * the total supply.
     *
     * Emits a {Transfer} event with `from` set to the zero address.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     */
    function _mint(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: mint to the zero address");

        _beforeTokenTransfer(address(0), account, amount);

        _totalSupply += amount;
        unchecked {
            // Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above.
            _balances[account] += amount;
        }
        emit Transfer(address(0), account, amount);

        _afterTokenTransfer(address(0), account, amount);
    }

    /**
     * @dev Destroys `amount` tokens from `account`, reducing the
     * total supply.
     *
     * Emits a {Transfer} event with `to` set to the zero address.
     *
     * Requirements:
     *
     * - `account` cannot be the zero address.
     * - `account` must have at least `amount` tokens.
     */
    function _burn(address account, uint256 amount) internal virtual {
        require(account != address(0), "ERC20: burn from the zero address");

        _beforeTokenTransfer(account, address(0), amount);

        uint256 accountBalance = _balances[account];
        require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
        unchecked {
            _balances[account] = accountBalance - amount;
            // Overflow not possible: amount <= accountBalance <= totalSupply.
            _totalSupply -= amount;
        }

        emit Transfer(account, address(0), amount);

        _afterTokenTransfer(account, address(0), amount);
    }

    /**
     * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
     *
     * This internal function is equivalent to `approve`, and can be used to
     * e.g. set automatic allowances for certain subsystems, etc.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `owner` cannot be the zero address.
     * - `spender` cannot be the zero address.
     */
    function _approve(address owner, address spender, uint256 amount) internal virtual {
        require(owner != address(0), "ERC20: approve from the zero address");
        require(spender != address(0), "ERC20: approve to the zero address");

        _allowances[owner][spender] = amount;
        emit Approval(owner, spender, amount);
    }

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

    /**
     * @dev Hook that is called before any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * will be transferred to `to`.
     * - when `from` is zero, `amount` tokens will be minted for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens will be burned.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual {}

    /**
     * @dev Hook that is called after any transfer of tokens. This includes
     * minting and burning.
     *
     * Calling conditions:
     *
     * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
     * has been transferred to `to`.
     * - when `from` is zero, `amount` tokens have been minted for `to`.
     * - when `to` is zero, `amount` of ``from``'s tokens have been burned.
     * - `from` and `to` are never both zero.
     *
     * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
     */
    function _afterTokenTransfer(address from, address to, uint256 amount) internal virtual {}
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";

/**
 * @dev Interface for the optional metadata functions from the ERC20 standard.
 *
 * _Available since v4.1._
 */
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);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.4) (token/ERC20/extensions/IERC20Permit.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 *
 * ==== 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);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @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 amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

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

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

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

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

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

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.3) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";
import "../extensions/IERC20Permit.sol";
import "../../../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 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.encodeWithSelector(token.transfer.selector, 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.encodeWithSelector(token.transferFrom.selector, from, to, value));
    }

    /**
     * @dev Deprecated. This function has issues similar to the ones found in
     * {IERC20-approve}, and its usage is discouraged.
     *
     * Whenever possible, use {safeIncreaseAllowance} and
     * {safeDecreaseAllowance} instead.
     */
    function safeApprove(IERC20 token, address spender, uint256 value) internal {
        // safeApprove should only be called when setting an initial allowance,
        // or when resetting it to zero. To increase and decrease it, use
        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
        require(
            (value == 0) || (token.allowance(address(this), spender) == 0),
            "SafeERC20: approve from non-zero to non-zero allowance"
        );
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
    }

    /**
     * @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);
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));
    }

    /**
     * @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        unchecked {
            uint256 oldAllowance = token.allowance(address(this), spender);
            require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));
        }
    }

    /**
     * @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.encodeWithSelector(token.approve.selector, spender, value);

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

    /**
     * @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.
     * Revert on invalid signature.
     */
    function safePermit(
        IERC20Permit token,
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal {
        uint256 nonceBefore = token.nonces(owner);
        token.permit(owner, spender, value, deadline, v, r, s);
        uint256 nonceAfter = token.nonces(owner);
        require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     */
    function _callOptionalReturn(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, "SafeERC20: low-level call failed");
        require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     *
     * 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.isContract(address(token));
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)

pragma solidity ^0.8.1;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     *
     * Furthermore, `isContract` will also return true if the target contract within
     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
     * which only has an effect at the end of a transaction.
     * ====
     *
     * [IMPORTANT]
     * ====
     * You shouldn't rely on `isContract` to protect against flash loan attacks!
     *
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
     * constructor.
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.

        return account.code.length > 0;
    }

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://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.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

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

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

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

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionDelegateCall(target, data, "Address: low-level delegate call failed");
    }

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

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
     *
     * _Available since v4.8._
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        if (success) {
            if (returndata.length == 0) {
                // only check isContract if the call was successful and the return data is empty
                // otherwise we already know that it was a contract
                require(isContract(target), "Address: call to non-contract");
            }
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason or using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    function _revert(bytes memory returndata, string memory errorMessage) 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(errorMessage);
        }
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.4) (utils/Context.sol)

pragma solidity ^0.8.0;

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

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

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

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/Math.sol)

pragma solidity ^0.8.0;

/**
 * @dev Standard math utilities missing in the Solidity language.
 */
library Math {
    enum Rounding {
        Down, // Toward negative infinity
        Up, // Toward infinity
        Zero // Toward zero
    }

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

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

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

    /**
     * @dev Returns the ceiling of the division of two numbers.
     *
     * This differs from standard division with `/` in that it rounds up instead
     * of rounding down.
     */
    function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
        // (a + b - 1) / b can overflow on addition, so we distribute.
        return a == 0 ? 0 : (a - 1) / b + 1;
    }

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

            // Handle non-overflow cases, 256 by 256 division.
            if (prod1 == 0) {
                // 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.
            require(denominator > prod1, "Math: mulDiv overflow");

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

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

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

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

            // Does not overflow because the denominator cannot be zero at this stage in the function.
            uint256 twos = denominator & (~denominator + 1);
            assembly {
                // Divide denominator by twos.
                denominator := div(denominator, twos)

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

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

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

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

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

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

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

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

        // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
        //
        // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
        // `msb(a) <= a < 2*msb(a)`. 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 + (rounding == Rounding.Up && result * result < a ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 2, rounded down, of a positive value.
     * 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 + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 10, rounded down, of a positive value.
     * 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 + (rounding == Rounding.Up && 10 ** result < value ? 1 : 0);
        }
    }

    /**
     * @dev Return the log in base 256, rounded down, of a positive value.
     * 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 + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0);
        }
    }
}

File 27 of 58 : SafeCast.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.

pragma solidity ^0.8.0;

/**
 * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow
 * checks.
 *
 * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
 * easily result in undesired exploitation or bugs, since developers usually
 * assume that overflows raise errors. `SafeCast` restores this intuition by
 * reverting the transaction when such an operation overflows.
 *
 * Using this library instead of the unchecked operations eliminates an entire
 * class of bugs, so it's recommended to use it always.
 *
 * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing
 * all math on `uint256` and `int256` and then downcasting.
 */
library SafeCast {
    /**
     * @dev Returns the downcasted uint248 from uint256, reverting on
     * overflow (when the input is greater than largest uint248).
     *
     * Counterpart to Solidity's `uint248` operator.
     *
     * Requirements:
     *
     * - input must fit into 248 bits
     *
     * _Available since v4.7._
     */
    function toUint248(uint256 value) internal pure returns (uint248) {
        require(value <= type(uint248).max, "SafeCast: value doesn't fit in 248 bits");
        return uint248(value);
    }

    /**
     * @dev Returns the downcasted uint240 from uint256, reverting on
     * overflow (when the input is greater than largest uint240).
     *
     * Counterpart to Solidity's `uint240` operator.
     *
     * Requirements:
     *
     * - input must fit into 240 bits
     *
     * _Available since v4.7._
     */
    function toUint240(uint256 value) internal pure returns (uint240) {
        require(value <= type(uint240).max, "SafeCast: value doesn't fit in 240 bits");
        return uint240(value);
    }

    /**
     * @dev Returns the downcasted uint232 from uint256, reverting on
     * overflow (when the input is greater than largest uint232).
     *
     * Counterpart to Solidity's `uint232` operator.
     *
     * Requirements:
     *
     * - input must fit into 232 bits
     *
     * _Available since v4.7._
     */
    function toUint232(uint256 value) internal pure returns (uint232) {
        require(value <= type(uint232).max, "SafeCast: value doesn't fit in 232 bits");
        return uint232(value);
    }

    /**
     * @dev Returns the downcasted uint224 from uint256, reverting on
     * overflow (when the input is greater than largest uint224).
     *
     * Counterpart to Solidity's `uint224` operator.
     *
     * Requirements:
     *
     * - input must fit into 224 bits
     *
     * _Available since v4.2._
     */
    function toUint224(uint256 value) internal pure returns (uint224) {
        require(value <= type(uint224).max, "SafeCast: value doesn't fit in 224 bits");
        return uint224(value);
    }

    /**
     * @dev Returns the downcasted uint216 from uint256, reverting on
     * overflow (when the input is greater than largest uint216).
     *
     * Counterpart to Solidity's `uint216` operator.
     *
     * Requirements:
     *
     * - input must fit into 216 bits
     *
     * _Available since v4.7._
     */
    function toUint216(uint256 value) internal pure returns (uint216) {
        require(value <= type(uint216).max, "SafeCast: value doesn't fit in 216 bits");
        return uint216(value);
    }

    /**
     * @dev Returns the downcasted uint208 from uint256, reverting on
     * overflow (when the input is greater than largest uint208).
     *
     * Counterpart to Solidity's `uint208` operator.
     *
     * Requirements:
     *
     * - input must fit into 208 bits
     *
     * _Available since v4.7._
     */
    function toUint208(uint256 value) internal pure returns (uint208) {
        require(value <= type(uint208).max, "SafeCast: value doesn't fit in 208 bits");
        return uint208(value);
    }

    /**
     * @dev Returns the downcasted uint200 from uint256, reverting on
     * overflow (when the input is greater than largest uint200).
     *
     * Counterpart to Solidity's `uint200` operator.
     *
     * Requirements:
     *
     * - input must fit into 200 bits
     *
     * _Available since v4.7._
     */
    function toUint200(uint256 value) internal pure returns (uint200) {
        require(value <= type(uint200).max, "SafeCast: value doesn't fit in 200 bits");
        return uint200(value);
    }

    /**
     * @dev Returns the downcasted uint192 from uint256, reverting on
     * overflow (when the input is greater than largest uint192).
     *
     * Counterpart to Solidity's `uint192` operator.
     *
     * Requirements:
     *
     * - input must fit into 192 bits
     *
     * _Available since v4.7._
     */
    function toUint192(uint256 value) internal pure returns (uint192) {
        require(value <= type(uint192).max, "SafeCast: value doesn't fit in 192 bits");
        return uint192(value);
    }

    /**
     * @dev Returns the downcasted uint184 from uint256, reverting on
     * overflow (when the input is greater than largest uint184).
     *
     * Counterpart to Solidity's `uint184` operator.
     *
     * Requirements:
     *
     * - input must fit into 184 bits
     *
     * _Available since v4.7._
     */
    function toUint184(uint256 value) internal pure returns (uint184) {
        require(value <= type(uint184).max, "SafeCast: value doesn't fit in 184 bits");
        return uint184(value);
    }

    /**
     * @dev Returns the downcasted uint176 from uint256, reverting on
     * overflow (when the input is greater than largest uint176).
     *
     * Counterpart to Solidity's `uint176` operator.
     *
     * Requirements:
     *
     * - input must fit into 176 bits
     *
     * _Available since v4.7._
     */
    function toUint176(uint256 value) internal pure returns (uint176) {
        require(value <= type(uint176).max, "SafeCast: value doesn't fit in 176 bits");
        return uint176(value);
    }

    /**
     * @dev Returns the downcasted uint168 from uint256, reverting on
     * overflow (when the input is greater than largest uint168).
     *
     * Counterpart to Solidity's `uint168` operator.
     *
     * Requirements:
     *
     * - input must fit into 168 bits
     *
     * _Available since v4.7._
     */
    function toUint168(uint256 value) internal pure returns (uint168) {
        require(value <= type(uint168).max, "SafeCast: value doesn't fit in 168 bits");
        return uint168(value);
    }

    /**
     * @dev Returns the downcasted uint160 from uint256, reverting on
     * overflow (when the input is greater than largest uint160).
     *
     * Counterpart to Solidity's `uint160` operator.
     *
     * Requirements:
     *
     * - input must fit into 160 bits
     *
     * _Available since v4.7._
     */
    function toUint160(uint256 value) internal pure returns (uint160) {
        require(value <= type(uint160).max, "SafeCast: value doesn't fit in 160 bits");
        return uint160(value);
    }

    /**
     * @dev Returns the downcasted uint152 from uint256, reverting on
     * overflow (when the input is greater than largest uint152).
     *
     * Counterpart to Solidity's `uint152` operator.
     *
     * Requirements:
     *
     * - input must fit into 152 bits
     *
     * _Available since v4.7._
     */
    function toUint152(uint256 value) internal pure returns (uint152) {
        require(value <= type(uint152).max, "SafeCast: value doesn't fit in 152 bits");
        return uint152(value);
    }

    /**
     * @dev Returns the downcasted uint144 from uint256, reverting on
     * overflow (when the input is greater than largest uint144).
     *
     * Counterpart to Solidity's `uint144` operator.
     *
     * Requirements:
     *
     * - input must fit into 144 bits
     *
     * _Available since v4.7._
     */
    function toUint144(uint256 value) internal pure returns (uint144) {
        require(value <= type(uint144).max, "SafeCast: value doesn't fit in 144 bits");
        return uint144(value);
    }

    /**
     * @dev Returns the downcasted uint136 from uint256, reverting on
     * overflow (when the input is greater than largest uint136).
     *
     * Counterpart to Solidity's `uint136` operator.
     *
     * Requirements:
     *
     * - input must fit into 136 bits
     *
     * _Available since v4.7._
     */
    function toUint136(uint256 value) internal pure returns (uint136) {
        require(value <= type(uint136).max, "SafeCast: value doesn't fit in 136 bits");
        return uint136(value);
    }

    /**
     * @dev Returns the downcasted uint128 from uint256, reverting on
     * overflow (when the input is greater than largest uint128).
     *
     * Counterpart to Solidity's `uint128` operator.
     *
     * Requirements:
     *
     * - input must fit into 128 bits
     *
     * _Available since v2.5._
     */
    function toUint128(uint256 value) internal pure returns (uint128) {
        require(value <= type(uint128).max, "SafeCast: value doesn't fit in 128 bits");
        return uint128(value);
    }

    /**
     * @dev Returns the downcasted uint120 from uint256, reverting on
     * overflow (when the input is greater than largest uint120).
     *
     * Counterpart to Solidity's `uint120` operator.
     *
     * Requirements:
     *
     * - input must fit into 120 bits
     *
     * _Available since v4.7._
     */
    function toUint120(uint256 value) internal pure returns (uint120) {
        require(value <= type(uint120).max, "SafeCast: value doesn't fit in 120 bits");
        return uint120(value);
    }

    /**
     * @dev Returns the downcasted uint112 from uint256, reverting on
     * overflow (when the input is greater than largest uint112).
     *
     * Counterpart to Solidity's `uint112` operator.
     *
     * Requirements:
     *
     * - input must fit into 112 bits
     *
     * _Available since v4.7._
     */
    function toUint112(uint256 value) internal pure returns (uint112) {
        require(value <= type(uint112).max, "SafeCast: value doesn't fit in 112 bits");
        return uint112(value);
    }

    /**
     * @dev Returns the downcasted uint104 from uint256, reverting on
     * overflow (when the input is greater than largest uint104).
     *
     * Counterpart to Solidity's `uint104` operator.
     *
     * Requirements:
     *
     * - input must fit into 104 bits
     *
     * _Available since v4.7._
     */
    function toUint104(uint256 value) internal pure returns (uint104) {
        require(value <= type(uint104).max, "SafeCast: value doesn't fit in 104 bits");
        return uint104(value);
    }

    /**
     * @dev Returns the downcasted uint96 from uint256, reverting on
     * overflow (when the input is greater than largest uint96).
     *
     * Counterpart to Solidity's `uint96` operator.
     *
     * Requirements:
     *
     * - input must fit into 96 bits
     *
     * _Available since v4.2._
     */
    function toUint96(uint256 value) internal pure returns (uint96) {
        require(value <= type(uint96).max, "SafeCast: value doesn't fit in 96 bits");
        return uint96(value);
    }

    /**
     * @dev Returns the downcasted uint88 from uint256, reverting on
     * overflow (when the input is greater than largest uint88).
     *
     * Counterpart to Solidity's `uint88` operator.
     *
     * Requirements:
     *
     * - input must fit into 88 bits
     *
     * _Available since v4.7._
     */
    function toUint88(uint256 value) internal pure returns (uint88) {
        require(value <= type(uint88).max, "SafeCast: value doesn't fit in 88 bits");
        return uint88(value);
    }

    /**
     * @dev Returns the downcasted uint80 from uint256, reverting on
     * overflow (when the input is greater than largest uint80).
     *
     * Counterpart to Solidity's `uint80` operator.
     *
     * Requirements:
     *
     * - input must fit into 80 bits
     *
     * _Available since v4.7._
     */
    function toUint80(uint256 value) internal pure returns (uint80) {
        require(value <= type(uint80).max, "SafeCast: value doesn't fit in 80 bits");
        return uint80(value);
    }

    /**
     * @dev Returns the downcasted uint72 from uint256, reverting on
     * overflow (when the input is greater than largest uint72).
     *
     * Counterpart to Solidity's `uint72` operator.
     *
     * Requirements:
     *
     * - input must fit into 72 bits
     *
     * _Available since v4.7._
     */
    function toUint72(uint256 value) internal pure returns (uint72) {
        require(value <= type(uint72).max, "SafeCast: value doesn't fit in 72 bits");
        return uint72(value);
    }

    /**
     * @dev Returns the downcasted uint64 from uint256, reverting on
     * overflow (when the input is greater than largest uint64).
     *
     * Counterpart to Solidity's `uint64` operator.
     *
     * Requirements:
     *
     * - input must fit into 64 bits
     *
     * _Available since v2.5._
     */
    function toUint64(uint256 value) internal pure returns (uint64) {
        require(value <= type(uint64).max, "SafeCast: value doesn't fit in 64 bits");
        return uint64(value);
    }

    /**
     * @dev Returns the downcasted uint56 from uint256, reverting on
     * overflow (when the input is greater than largest uint56).
     *
     * Counterpart to Solidity's `uint56` operator.
     *
     * Requirements:
     *
     * - input must fit into 56 bits
     *
     * _Available since v4.7._
     */
    function toUint56(uint256 value) internal pure returns (uint56) {
        require(value <= type(uint56).max, "SafeCast: value doesn't fit in 56 bits");
        return uint56(value);
    }

    /**
     * @dev Returns the downcasted uint48 from uint256, reverting on
     * overflow (when the input is greater than largest uint48).
     *
     * Counterpart to Solidity's `uint48` operator.
     *
     * Requirements:
     *
     * - input must fit into 48 bits
     *
     * _Available since v4.7._
     */
    function toUint48(uint256 value) internal pure returns (uint48) {
        require(value <= type(uint48).max, "SafeCast: value doesn't fit in 48 bits");
        return uint48(value);
    }

    /**
     * @dev Returns the downcasted uint40 from uint256, reverting on
     * overflow (when the input is greater than largest uint40).
     *
     * Counterpart to Solidity's `uint40` operator.
     *
     * Requirements:
     *
     * - input must fit into 40 bits
     *
     * _Available since v4.7._
     */
    function toUint40(uint256 value) internal pure returns (uint40) {
        require(value <= type(uint40).max, "SafeCast: value doesn't fit in 40 bits");
        return uint40(value);
    }

    /**
     * @dev Returns the downcasted uint32 from uint256, reverting on
     * overflow (when the input is greater than largest uint32).
     *
     * Counterpart to Solidity's `uint32` operator.
     *
     * Requirements:
     *
     * - input must fit into 32 bits
     *
     * _Available since v2.5._
     */
    function toUint32(uint256 value) internal pure returns (uint32) {
        require(value <= type(uint32).max, "SafeCast: value doesn't fit in 32 bits");
        return uint32(value);
    }

    /**
     * @dev Returns the downcasted uint24 from uint256, reverting on
     * overflow (when the input is greater than largest uint24).
     *
     * Counterpart to Solidity's `uint24` operator.
     *
     * Requirements:
     *
     * - input must fit into 24 bits
     *
     * _Available since v4.7._
     */
    function toUint24(uint256 value) internal pure returns (uint24) {
        require(value <= type(uint24).max, "SafeCast: value doesn't fit in 24 bits");
        return uint24(value);
    }

    /**
     * @dev Returns the downcasted uint16 from uint256, reverting on
     * overflow (when the input is greater than largest uint16).
     *
     * Counterpart to Solidity's `uint16` operator.
     *
     * Requirements:
     *
     * - input must fit into 16 bits
     *
     * _Available since v2.5._
     */
    function toUint16(uint256 value) internal pure returns (uint16) {
        require(value <= type(uint16).max, "SafeCast: value doesn't fit in 16 bits");
        return uint16(value);
    }

    /**
     * @dev Returns the downcasted uint8 from uint256, reverting on
     * overflow (when the input is greater than largest uint8).
     *
     * Counterpart to Solidity's `uint8` operator.
     *
     * Requirements:
     *
     * - input must fit into 8 bits
     *
     * _Available since v2.5._
     */
    function toUint8(uint256 value) internal pure returns (uint8) {
        require(value <= type(uint8).max, "SafeCast: value doesn't fit in 8 bits");
        return uint8(value);
    }

    /**
     * @dev Converts a signed int256 into an unsigned uint256.
     *
     * Requirements:
     *
     * - input must be greater than or equal to 0.
     *
     * _Available since v3.0._
     */
    function toUint256(int256 value) internal pure returns (uint256) {
        require(value >= 0, "SafeCast: value must be positive");
        return uint256(value);
    }

    /**
     * @dev Returns the downcasted int248 from int256, reverting on
     * overflow (when the input is less than smallest int248 or
     * greater than largest int248).
     *
     * Counterpart to Solidity's `int248` operator.
     *
     * Requirements:
     *
     * - input must fit into 248 bits
     *
     * _Available since v4.7._
     */
    function toInt248(int256 value) internal pure returns (int248 downcasted) {
        downcasted = int248(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 248 bits");
    }

    /**
     * @dev Returns the downcasted int240 from int256, reverting on
     * overflow (when the input is less than smallest int240 or
     * greater than largest int240).
     *
     * Counterpart to Solidity's `int240` operator.
     *
     * Requirements:
     *
     * - input must fit into 240 bits
     *
     * _Available since v4.7._
     */
    function toInt240(int256 value) internal pure returns (int240 downcasted) {
        downcasted = int240(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 240 bits");
    }

    /**
     * @dev Returns the downcasted int232 from int256, reverting on
     * overflow (when the input is less than smallest int232 or
     * greater than largest int232).
     *
     * Counterpart to Solidity's `int232` operator.
     *
     * Requirements:
     *
     * - input must fit into 232 bits
     *
     * _Available since v4.7._
     */
    function toInt232(int256 value) internal pure returns (int232 downcasted) {
        downcasted = int232(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 232 bits");
    }

    /**
     * @dev Returns the downcasted int224 from int256, reverting on
     * overflow (when the input is less than smallest int224 or
     * greater than largest int224).
     *
     * Counterpart to Solidity's `int224` operator.
     *
     * Requirements:
     *
     * - input must fit into 224 bits
     *
     * _Available since v4.7._
     */
    function toInt224(int256 value) internal pure returns (int224 downcasted) {
        downcasted = int224(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 224 bits");
    }

    /**
     * @dev Returns the downcasted int216 from int256, reverting on
     * overflow (when the input is less than smallest int216 or
     * greater than largest int216).
     *
     * Counterpart to Solidity's `int216` operator.
     *
     * Requirements:
     *
     * - input must fit into 216 bits
     *
     * _Available since v4.7._
     */
    function toInt216(int256 value) internal pure returns (int216 downcasted) {
        downcasted = int216(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 216 bits");
    }

    /**
     * @dev Returns the downcasted int208 from int256, reverting on
     * overflow (when the input is less than smallest int208 or
     * greater than largest int208).
     *
     * Counterpart to Solidity's `int208` operator.
     *
     * Requirements:
     *
     * - input must fit into 208 bits
     *
     * _Available since v4.7._
     */
    function toInt208(int256 value) internal pure returns (int208 downcasted) {
        downcasted = int208(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 208 bits");
    }

    /**
     * @dev Returns the downcasted int200 from int256, reverting on
     * overflow (when the input is less than smallest int200 or
     * greater than largest int200).
     *
     * Counterpart to Solidity's `int200` operator.
     *
     * Requirements:
     *
     * - input must fit into 200 bits
     *
     * _Available since v4.7._
     */
    function toInt200(int256 value) internal pure returns (int200 downcasted) {
        downcasted = int200(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 200 bits");
    }

    /**
     * @dev Returns the downcasted int192 from int256, reverting on
     * overflow (when the input is less than smallest int192 or
     * greater than largest int192).
     *
     * Counterpart to Solidity's `int192` operator.
     *
     * Requirements:
     *
     * - input must fit into 192 bits
     *
     * _Available since v4.7._
     */
    function toInt192(int256 value) internal pure returns (int192 downcasted) {
        downcasted = int192(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 192 bits");
    }

    /**
     * @dev Returns the downcasted int184 from int256, reverting on
     * overflow (when the input is less than smallest int184 or
     * greater than largest int184).
     *
     * Counterpart to Solidity's `int184` operator.
     *
     * Requirements:
     *
     * - input must fit into 184 bits
     *
     * _Available since v4.7._
     */
    function toInt184(int256 value) internal pure returns (int184 downcasted) {
        downcasted = int184(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 184 bits");
    }

    /**
     * @dev Returns the downcasted int176 from int256, reverting on
     * overflow (when the input is less than smallest int176 or
     * greater than largest int176).
     *
     * Counterpart to Solidity's `int176` operator.
     *
     * Requirements:
     *
     * - input must fit into 176 bits
     *
     * _Available since v4.7._
     */
    function toInt176(int256 value) internal pure returns (int176 downcasted) {
        downcasted = int176(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 176 bits");
    }

    /**
     * @dev Returns the downcasted int168 from int256, reverting on
     * overflow (when the input is less than smallest int168 or
     * greater than largest int168).
     *
     * Counterpart to Solidity's `int168` operator.
     *
     * Requirements:
     *
     * - input must fit into 168 bits
     *
     * _Available since v4.7._
     */
    function toInt168(int256 value) internal pure returns (int168 downcasted) {
        downcasted = int168(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 168 bits");
    }

    /**
     * @dev Returns the downcasted int160 from int256, reverting on
     * overflow (when the input is less than smallest int160 or
     * greater than largest int160).
     *
     * Counterpart to Solidity's `int160` operator.
     *
     * Requirements:
     *
     * - input must fit into 160 bits
     *
     * _Available since v4.7._
     */
    function toInt160(int256 value) internal pure returns (int160 downcasted) {
        downcasted = int160(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 160 bits");
    }

    /**
     * @dev Returns the downcasted int152 from int256, reverting on
     * overflow (when the input is less than smallest int152 or
     * greater than largest int152).
     *
     * Counterpart to Solidity's `int152` operator.
     *
     * Requirements:
     *
     * - input must fit into 152 bits
     *
     * _Available since v4.7._
     */
    function toInt152(int256 value) internal pure returns (int152 downcasted) {
        downcasted = int152(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 152 bits");
    }

    /**
     * @dev Returns the downcasted int144 from int256, reverting on
     * overflow (when the input is less than smallest int144 or
     * greater than largest int144).
     *
     * Counterpart to Solidity's `int144` operator.
     *
     * Requirements:
     *
     * - input must fit into 144 bits
     *
     * _Available since v4.7._
     */
    function toInt144(int256 value) internal pure returns (int144 downcasted) {
        downcasted = int144(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 144 bits");
    }

    /**
     * @dev Returns the downcasted int136 from int256, reverting on
     * overflow (when the input is less than smallest int136 or
     * greater than largest int136).
     *
     * Counterpart to Solidity's `int136` operator.
     *
     * Requirements:
     *
     * - input must fit into 136 bits
     *
     * _Available since v4.7._
     */
    function toInt136(int256 value) internal pure returns (int136 downcasted) {
        downcasted = int136(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 136 bits");
    }

    /**
     * @dev Returns the downcasted int128 from int256, reverting on
     * overflow (when the input is less than smallest int128 or
     * greater than largest int128).
     *
     * Counterpart to Solidity's `int128` operator.
     *
     * Requirements:
     *
     * - input must fit into 128 bits
     *
     * _Available since v3.1._
     */
    function toInt128(int256 value) internal pure returns (int128 downcasted) {
        downcasted = int128(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 128 bits");
    }

    /**
     * @dev Returns the downcasted int120 from int256, reverting on
     * overflow (when the input is less than smallest int120 or
     * greater than largest int120).
     *
     * Counterpart to Solidity's `int120` operator.
     *
     * Requirements:
     *
     * - input must fit into 120 bits
     *
     * _Available since v4.7._
     */
    function toInt120(int256 value) internal pure returns (int120 downcasted) {
        downcasted = int120(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 120 bits");
    }

    /**
     * @dev Returns the downcasted int112 from int256, reverting on
     * overflow (when the input is less than smallest int112 or
     * greater than largest int112).
     *
     * Counterpart to Solidity's `int112` operator.
     *
     * Requirements:
     *
     * - input must fit into 112 bits
     *
     * _Available since v4.7._
     */
    function toInt112(int256 value) internal pure returns (int112 downcasted) {
        downcasted = int112(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 112 bits");
    }

    /**
     * @dev Returns the downcasted int104 from int256, reverting on
     * overflow (when the input is less than smallest int104 or
     * greater than largest int104).
     *
     * Counterpart to Solidity's `int104` operator.
     *
     * Requirements:
     *
     * - input must fit into 104 bits
     *
     * _Available since v4.7._
     */
    function toInt104(int256 value) internal pure returns (int104 downcasted) {
        downcasted = int104(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 104 bits");
    }

    /**
     * @dev Returns the downcasted int96 from int256, reverting on
     * overflow (when the input is less than smallest int96 or
     * greater than largest int96).
     *
     * Counterpart to Solidity's `int96` operator.
     *
     * Requirements:
     *
     * - input must fit into 96 bits
     *
     * _Available since v4.7._
     */
    function toInt96(int256 value) internal pure returns (int96 downcasted) {
        downcasted = int96(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 96 bits");
    }

    /**
     * @dev Returns the downcasted int88 from int256, reverting on
     * overflow (when the input is less than smallest int88 or
     * greater than largest int88).
     *
     * Counterpart to Solidity's `int88` operator.
     *
     * Requirements:
     *
     * - input must fit into 88 bits
     *
     * _Available since v4.7._
     */
    function toInt88(int256 value) internal pure returns (int88 downcasted) {
        downcasted = int88(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 88 bits");
    }

    /**
     * @dev Returns the downcasted int80 from int256, reverting on
     * overflow (when the input is less than smallest int80 or
     * greater than largest int80).
     *
     * Counterpart to Solidity's `int80` operator.
     *
     * Requirements:
     *
     * - input must fit into 80 bits
     *
     * _Available since v4.7._
     */
    function toInt80(int256 value) internal pure returns (int80 downcasted) {
        downcasted = int80(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 80 bits");
    }

    /**
     * @dev Returns the downcasted int72 from int256, reverting on
     * overflow (when the input is less than smallest int72 or
     * greater than largest int72).
     *
     * Counterpart to Solidity's `int72` operator.
     *
     * Requirements:
     *
     * - input must fit into 72 bits
     *
     * _Available since v4.7._
     */
    function toInt72(int256 value) internal pure returns (int72 downcasted) {
        downcasted = int72(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 72 bits");
    }

    /**
     * @dev Returns the downcasted int64 from int256, reverting on
     * overflow (when the input is less than smallest int64 or
     * greater than largest int64).
     *
     * Counterpart to Solidity's `int64` operator.
     *
     * Requirements:
     *
     * - input must fit into 64 bits
     *
     * _Available since v3.1._
     */
    function toInt64(int256 value) internal pure returns (int64 downcasted) {
        downcasted = int64(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 64 bits");
    }

    /**
     * @dev Returns the downcasted int56 from int256, reverting on
     * overflow (when the input is less than smallest int56 or
     * greater than largest int56).
     *
     * Counterpart to Solidity's `int56` operator.
     *
     * Requirements:
     *
     * - input must fit into 56 bits
     *
     * _Available since v4.7._
     */
    function toInt56(int256 value) internal pure returns (int56 downcasted) {
        downcasted = int56(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 56 bits");
    }

    /**
     * @dev Returns the downcasted int48 from int256, reverting on
     * overflow (when the input is less than smallest int48 or
     * greater than largest int48).
     *
     * Counterpart to Solidity's `int48` operator.
     *
     * Requirements:
     *
     * - input must fit into 48 bits
     *
     * _Available since v4.7._
     */
    function toInt48(int256 value) internal pure returns (int48 downcasted) {
        downcasted = int48(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 48 bits");
    }

    /**
     * @dev Returns the downcasted int40 from int256, reverting on
     * overflow (when the input is less than smallest int40 or
     * greater than largest int40).
     *
     * Counterpart to Solidity's `int40` operator.
     *
     * Requirements:
     *
     * - input must fit into 40 bits
     *
     * _Available since v4.7._
     */
    function toInt40(int256 value) internal pure returns (int40 downcasted) {
        downcasted = int40(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 40 bits");
    }

    /**
     * @dev Returns the downcasted int32 from int256, reverting on
     * overflow (when the input is less than smallest int32 or
     * greater than largest int32).
     *
     * Counterpart to Solidity's `int32` operator.
     *
     * Requirements:
     *
     * - input must fit into 32 bits
     *
     * _Available since v3.1._
     */
    function toInt32(int256 value) internal pure returns (int32 downcasted) {
        downcasted = int32(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 32 bits");
    }

    /**
     * @dev Returns the downcasted int24 from int256, reverting on
     * overflow (when the input is less than smallest int24 or
     * greater than largest int24).
     *
     * Counterpart to Solidity's `int24` operator.
     *
     * Requirements:
     *
     * - input must fit into 24 bits
     *
     * _Available since v4.7._
     */
    function toInt24(int256 value) internal pure returns (int24 downcasted) {
        downcasted = int24(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 24 bits");
    }

    /**
     * @dev Returns the downcasted int16 from int256, reverting on
     * overflow (when the input is less than smallest int16 or
     * greater than largest int16).
     *
     * Counterpart to Solidity's `int16` operator.
     *
     * Requirements:
     *
     * - input must fit into 16 bits
     *
     * _Available since v3.1._
     */
    function toInt16(int256 value) internal pure returns (int16 downcasted) {
        downcasted = int16(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 16 bits");
    }

    /**
     * @dev Returns the downcasted int8 from int256, reverting on
     * overflow (when the input is less than smallest int8 or
     * greater than largest int8).
     *
     * Counterpart to Solidity's `int8` operator.
     *
     * Requirements:
     *
     * - input must fit into 8 bits
     *
     * _Available since v3.1._
     */
    function toInt8(int256 value) internal pure returns (int8 downcasted) {
        downcasted = int8(value);
        require(downcasted == value, "SafeCast: value doesn't fit in 8 bits");
    }

    /**
     * @dev Converts an unsigned uint256 into a signed int256.
     *
     * Requirements:
     *
     * - input must be less than or equal to maxInt256.
     *
     * _Available since v3.0._
     */
    function toInt256(uint256 value) internal pure returns (int256) {
        // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
        require(value <= uint256(type(int256).max), "SafeCast: value doesn't fit in an int256");
        return int256(value);
    }
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {IBridge, MessengerProtocol} from "./interfaces/IBridge.sol";
import {Router} from "./Router.sol";
import {Messenger} from "./Messenger.sol";
import {MessengerGateway} from "./MessengerGateway.sol";
import {IGasOracle} from "./interfaces/IGasOracle.sol";
import {GasUsage} from "./GasUsage.sol";
import {WormholeMessenger} from "./WormholeMessenger.sol";
import {HashUtils} from "./libraries/HashUtils.sol";

/**
 * @title Bridge
 * @dev A contract with functions to facilitate bridging tokens across different blockchains.
 */
contract Bridge is GasUsage, Router, MessengerGateway, IBridge {
    using SafeERC20 for IERC20;
    using HashUtils for bytes32;

    uint public immutable override chainId;
    mapping(bytes32 messageHash => uint isProcessed) public override processedMessages;
    mapping(bytes32 messageHash => uint isSent) public override sentMessages;
    // Info about bridges on other chains
    mapping(uint chainId => bytes32 bridgeAddress) public override otherBridges;
    // Info about tokens on other chains
    mapping(uint chainId => mapping(bytes32 tokenAddress => bool isSupported)) public override otherBridgeTokens;

    /**
     * @dev Emitted when tokens are sent on the source blockchain.
     */
    event TokensSent(
        uint amount,
        bytes32 recipient,
        uint destinationChainId,
        bytes32 receiveToken,
        uint nonce,
        MessengerProtocol messenger
    );

    /**
     * @dev Emitted when the tokens are received on the destination blockchain.
     */
    event TokensReceived(uint amount, bytes32 recipient, uint nonce, MessengerProtocol messenger, bytes32 message);

    /**
     * @dev Emitted when this contract receives the bridging fee.
     */
    event ReceiveFee(uint bridgeTransactionCost, uint messageTransactionCost);

    /**
     * @dev Emitted when this contract charged the sender with the tokens for the bridging fee.
     */
    event BridgingFeeFromTokens(uint gas);

    /**
     * @dev Emitted when the contract receives native tokens (e.g. Ether on the Ethereum network) from the admin to
     * supply the gas for bridging.
     */
    event Received(address sender, uint amount);

    constructor(
        uint chainId_,
        uint chainPrecision_,
        Messenger allbridgeMessenger_,
        WormholeMessenger wormholeMessenger_,
        IGasOracle gasOracle_
    ) Router(chainPrecision_) MessengerGateway(allbridgeMessenger_, wormholeMessenger_) GasUsage(gasOracle_) {
        chainId = chainId_;
    }

    /**
     * @notice Initiates a swap and bridge process of a given token for a token on another blockchain.
     * @dev This function is used to initiate a cross-chain transfer. The specified amount of token is first transferred
     * to the pool on the current chain, and then an event `TokensSent` is emitted to signal that tokens have been sent
     * on the source chain. See the function `receiveTokens`.
     * The bridging fee required for the cross-chain transfer can be paid in two ways:
     * - by sending the required amount of native gas token along with the transaction
     *   (See `getTransactionCost` in the `GasUsage` contract and `getMessageCost` in the `MessengerGateway` contract).
     * - by setting the parameter `feeTokenAmount` with the bridging fee amount in the source tokens
     *   (See the function `getBridgingCostInTokens`).
     * @param token The token to be swapped.
     * @param amount The amount of tokens to be swapped (including `feeTokenAmount`).
     * @param destinationChainId The ID of the destination chain.
     * @param receiveToken The token to receive in exchange for the swapped token.
     * @param nonce An identifier that is used to ensure that each transfer is unique and can only be processed once.
     * @param messenger The chosen way of delivering the message across chains.
     * @param feeTokenAmount The amount of tokens to be deducted from the transferred amount as a bridging fee.
     *
     */
    function swapAndBridge(
        bytes32 token,
        uint amount,
        bytes32 recipient,
        uint destinationChainId,
        bytes32 receiveToken,
        uint nonce,
        MessengerProtocol messenger,
        uint feeTokenAmount
    ) external payable override whenCanSwap {
        require(amount > feeTokenAmount, "Bridge: amount too low for fee");
        require(recipient != 0, "Bridge: bridge to the zero address");
        uint bridgingFee = msg.value + _convertBridgingFeeInTokensToNativeToken(msg.sender, token, feeTokenAmount);
        uint amountAfterFee = amount - feeTokenAmount;

        uint vUsdAmount = _sendAndSwapToVUsd(token, msg.sender, amountAfterFee);
        _sendTokens(vUsdAmount, recipient, destinationChainId, receiveToken, nonce, messenger, bridgingFee);
    }

    /**
     * @notice Completes the bridging process by sending the tokens on the destination chain to the recipient.
     * @dev This function is called only after a bridging has been initiated by a user
     *      through the `swapAndBridge` function on the source chain.
     * @param amount The amount of tokens being bridged.
     * @param recipient The recipient address for the bridged tokens.
     * @param sourceChainId The ID of the source chain.
     * @param receiveToken The address of the token being received.
     * @param nonce A unique nonce for the bridging transaction.
     * @param messenger The protocol used to relay the message.
     * @param receiveAmountMin The minimum amount of receiveToken required to be received.
     */
    function receiveTokens(
        uint amount,
        bytes32 recipient,
        uint sourceChainId,
        bytes32 receiveToken,
        uint nonce,
        MessengerProtocol messenger,
        uint receiveAmountMin
    ) external payable override whenCanSwap {
        require(otherBridges[sourceChainId] != bytes32(0), "Bridge: source not registered");
        bytes32 messageWithSender = this
            .hashMessage(amount, recipient, sourceChainId, chainId, receiveToken, nonce, messenger)
            .hashWithSender(otherBridges[sourceChainId]);

        require(processedMessages[messageWithSender] == 0, "Bridge: message processed");
        // mark the transfer as received on the destination chain
        processedMessages[messageWithSender] = 1;

        // check if tokens has been sent on the source chain
        require(this.hasReceivedMessage(messageWithSender, messenger), "Bridge: no message");

        uint receiveAmount = _receiveAndSwapFromVUsd(
            receiveToken,
            address(uint160(uint(recipient))),
            amount,
            receiveAmountMin
        );
        // pass extra gas to the recipient
        if (msg.value > 0) {
            // ignore if passing extra gas failed
            // solc-ignore-next-line unused-call-retval
            payable(address(uint160(uint(recipient)))).call{value: msg.value}("");
        }
        emit TokensReceived(receiveAmount, recipient, nonce, messenger, messageWithSender);
    }

    /**
     * @notice Allows the admin to add new supported chain destination.
     * @dev Registers the address of a bridge deployed on a different chain.
     * @param chainId_ The chain ID of the bridge to register.
     * @param bridgeAddress The address of the bridge contract to register.
     */
    function registerBridge(uint chainId_, bytes32 bridgeAddress) external override onlyOwner {
        otherBridges[chainId_] = bridgeAddress;
    }

    /**
     * @notice Allows the admin to add a new supported destination token.
     * @dev Adds the address of a token on another chain to the list of supported tokens for the specified chain.
     * @param chainId_ The chain ID where the token is deployed.
     * @param tokenAddress The address of the token to add as a supported token.
     */
    function addBridgeToken(uint chainId_, bytes32 tokenAddress) external override onlyOwner {
        otherBridgeTokens[chainId_][tokenAddress] = true;
    }

    /**
     * @notice Allows the admin to remove support for a destination token.
     * @dev Removes the address of a token on another chain from the list of supported tokens for the specified chain.
     * @param chainId_ The chain ID where the token is deployed.
     * @param tokenAddress The address of the token to remove from the list of supported tokens.
     */
    function removeBridgeToken(uint chainId_, bytes32 tokenAddress) external override onlyOwner {
        otherBridgeTokens[chainId_][tokenAddress] = false;
    }

    /**
     * @notice Allows the admin to withdraw the bridging fee collected in native tokens.
     */
    function withdrawGasTokens(uint amount) external override onlyOwner {
        payable(msg.sender).transfer(amount);
    }

    /**
     * @notice Allows the admin to withdraw the bridging fee collected in tokens.
     * @param token The address of the token contract.
     */
    function withdrawBridgingFeeInTokens(IERC20 token) external onlyOwner {
        uint toWithdraw = token.balanceOf(address(this));
        if (toWithdraw > 0) {
            token.safeTransfer(msg.sender, toWithdraw);
        }
    }

    /**
     * @dev Calculates the amount of bridging fee nominated in a given token, which includes:
     * - the gas cost of making the receive transaction on the destination chain,
     * - the gas cost of sending the message to the destination chain using the specified messenger protocol.
     * @param destinationChainId The ID of the destination chain.
     * @param messenger The chosen way of delivering the message across chains.
     * @param tokenAddress The address of the token contract on the source chain.
     * @return The total price of bridging, with the precision according to the token's `decimals()` value.
     */
    function getBridgingCostInTokens(
        uint destinationChainId,
        MessengerProtocol messenger,
        address tokenAddress
    ) external view override returns (uint) {
        return
            gasOracle.getTransactionGasCostInUSD(
                destinationChainId,
                gasUsage[destinationChainId] + getMessageGasUsage(destinationChainId, messenger)
            ) / fromGasOracleScalingFactor[tokenAddress];
    }

    /**
     * @dev Produces a hash of transfer parameters, which is used as a message to the bridge on the destination chain
     *      to notify that the tokens on the source chain has been sent.
     * @param amount The amount of tokens being transferred.
     * @param recipient The address of the recipient on the destination chain.
     * @param sourceChainId The ID of the source chain.
     * @param destinationChainId The ID of the destination chain.
     * @param receiveToken The token being received on the destination chain.
     * @param nonce The unique nonce.
     * @param messenger The chosen way of delivering the message across chains.
     */
    function hashMessage(
        uint amount,
        bytes32 recipient,
        uint sourceChainId,
        uint destinationChainId,
        bytes32 receiveToken,
        uint nonce,
        MessengerProtocol messenger
    ) external pure override returns (bytes32) {
        return
            keccak256(abi.encodePacked(amount, recipient, sourceChainId, receiveToken, nonce, messenger))
                .replaceChainBytes(uint8(sourceChainId), uint8(destinationChainId));
    }

    function _sendTokens(
        uint amount,
        bytes32 recipient,
        uint destinationChainId,
        bytes32 receiveToken,
        uint nonce,
        MessengerProtocol messenger,
        uint bridgingFee
    ) internal {
        require(destinationChainId != chainId, "Bridge: wrong destination chain");
        require(otherBridgeTokens[destinationChainId][receiveToken], "Bridge: unknown chain or token");
        bytes32 message = this.hashMessage(
            amount,
            recipient,
            chainId,
            destinationChainId,
            receiveToken,
            nonce,
            messenger
        );

        require(sentMessages[message] == 0, "Bridge: tokens already sent");
        // mark the transfer as sent on the source chain
        sentMessages[message] = 1;

        uint bridgeTransactionCost = this.getTransactionCost(destinationChainId);
        uint messageTransactionCost = _sendMessage(message, messenger);
        emit ReceiveFee(bridgeTransactionCost, messageTransactionCost);
        unchecked {
            require(bridgingFee >= bridgeTransactionCost + messageTransactionCost, "Bridge: not enough fee");
        }
        emit TokensSent(amount, recipient, destinationChainId, receiveToken, nonce, messenger);
    }

    /**
     * @dev Charges the bridging fee in tokens and calculates the amount of native tokens that correspond
     *      to the charged fee using the current exchange rate.
     * @param user The address of the user who is paying the bridging fee
     * @param tokenAddress The address of the token used to pay the bridging fee
     * @param feeTokenAmount The amount of tokens to pay as the bridging fee
     * @return bridging fee amount in the native tokens (e.g. in wei for Ethereum)
     */
    function _convertBridgingFeeInTokensToNativeToken(
        address user,
        bytes32 tokenAddress,
        uint feeTokenAmount
    ) internal returns (uint) {
        if (feeTokenAmount == 0) return 0;
        address tokenAddress_ = address(uint160(uint(tokenAddress)));

        IERC20 token = IERC20(tokenAddress_);
        token.safeTransferFrom(user, address(this), feeTokenAmount);

        uint fee = (bridgingFeeConversionScalingFactor[tokenAddress_] * feeTokenAmount) / gasOracle.price(chainId);

        emit BridgingFeeFromTokens(fee);
        return fee;
    }

    fallback() external payable {
        revert("Unsupported");
    }

    receive() external payable {
        emit Received(msg.sender, msg.value);
    }
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;

import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {IGasOracle} from "./interfaces/IGasOracle.sol";
import {ITokenMessenger} from "./interfaces/cctp/ITokenMessenger.sol";
import {IMessageTransmitter} from "./interfaces/cctp/IMessageTransmitter.sol";
import {GasUsage} from "./GasUsage.sol";

contract CctpBridge is GasUsage {
    using SafeERC20 for IERC20Metadata;

    uint internal constant ORACLE_PRECISION = 18;
    uint internal constant BP = 1e4;

    uint public immutable chainId;
    // Admin fee share (in basis points)
    uint public adminFeeShareBP;
    IERC20Metadata private immutable token;
    ITokenMessenger private immutable cctpMessenger;
    IMessageTransmitter private immutable cctpTransmitter;
    // precomputed value of the scaling factor required for converting the stable token to gas amount
    uint private immutable stableTokensForGasScalingFactor;
    // precomputed value to divide by to change the precision from the Gas Oracle precision to the stable token precision
    uint private immutable fromGasOracleScalingFactor;

    mapping(uint chainId => uint domainNumber) private chainIdDomainMap;
    mapping(uint nonce => address sender) private senders;

    /**
     * @notice Emitted when the contract receives some gas directly.
     */
    event ReceivedGas(address sender, uint amount);

    /**
     * @notice Emitted when the contract sends some extra gas to the recipient of tokens.
     */
    event ReceivedExtraGas(address recipient, uint amount);

    /**
     * @notice Emitted when tokens are sent on the source blockchain.
     */
    event TokensSent(
        uint amount,
        address sender,
        bytes32 recipient,
        uint destinationChainId,
        uint nonce,
        uint receivedRelayerFeeFromGas,
        uint receivedRelayerFeeFromTokens,
        uint relayerFee,
        uint receivedRelayerFeeTokenAmount,
        uint adminFeeTokenAmount
    );

    event TokensSentExtras(bytes32 recipientWalletAddress);

    event RecipientReplaced(address sender, uint nonce, bytes32 newRecipient);

    constructor(
        uint chainId_,
        uint chainPrecision_,
        address tokenAddress,
        address cctpMessenger_,
        address cctpTransmitter_,
        IGasOracle gasOracle_
    ) GasUsage(gasOracle_) {
        chainId = chainId_;
        token = IERC20Metadata(tokenAddress);
        uint tokenDecimals = token.decimals();
        cctpMessenger = ITokenMessenger(cctpMessenger_);
        cctpTransmitter = IMessageTransmitter(cctpTransmitter_);
        token.approve(cctpMessenger_, type(uint256).max);
        stableTokensForGasScalingFactor = 10 ** (ORACLE_PRECISION - tokenDecimals + chainPrecision_);
        fromGasOracleScalingFactor = 10 ** (ORACLE_PRECISION - tokenDecimals);
    }

    /**
     * @notice Initiates a bridging process of the token to another blockchain.
     * @dev This function is used to initiate a cross-chain transfer.
     * The bridging fee required for the cross-chain transfer can be paid in two ways:
     * - by sending the required amount of native gas token along with the transaction
     *   (See `getTransactionCost` in the `GasUsage` contract).
     * - by setting the parameter `relayerFeeTokenAmount` with the amount of bridging fee in tokens
     *   (See the function `getBridgingCostInTokens`).
     * @param amount The amount of tokens to send (including `relayerFeeTokenAmount`).
     * @param recipient The recipient address.
     * @param destinationChainId The ID of the destination chain.
     * @param relayerFeeTokenAmount The amount of tokens to be deducted from the transferred amount as a bridging fee.
     */
    function bridge(
        uint amount,
        bytes32 recipient,
        uint destinationChainId,
        uint relayerFeeTokenAmount
    ) public payable {
        require(amount > relayerFeeTokenAmount, "CCTP: Amount <= relayer fee");
        require(recipient != 0, "CCTP: Recipient must be nonzero");
        token.safeTransferFrom(msg.sender, address(this), amount);
        uint gasFromStables = _getStableTokensValueInGas(relayerFeeTokenAmount);
        uint relayerFee = this.getTransactionCost(destinationChainId);
        require(msg.value + gasFromStables >= relayerFee, "CCTP: Not enough fee");
        uint amountToSend = amount - relayerFeeTokenAmount;
        uint adminFee;
        if (adminFeeShareBP != 0) {
            adminFee = (amountToSend * adminFeeShareBP) / BP;
            if (adminFee == 0) {
                adminFee = 1;
            }
            amountToSend -= adminFee;
        }
        uint32 destinationDomain = getDomainByChainId(destinationChainId);
        uint64 nonce = cctpMessenger.depositForBurn(amountToSend, destinationDomain, recipient, address(token));
        senders[nonce] = msg.sender;
        emit TokensSent(
            amountToSend,
            msg.sender,
            recipient,
            destinationChainId,
            nonce,
            msg.value,
            gasFromStables,
            relayerFee,
            relayerFeeTokenAmount,
            adminFee
        );
    }

    /**
     * @notice Public method to initiate a bridging process of the token to another blockchain. Used for recipients with different wallet address (Solana)
     * @dev See full description in the bridge method
     * @param recipientWalletAddress The recipient wallet address - used to track user for transfers to Solana.
     **/
    function bridgeWithWalletAddress(
        uint amount,
        bytes32 recipient,
        bytes32 recipientWalletAddress,
        uint destinationChainId,
        uint relayerFeeTokenAmount
    ) external payable {
        bridge(amount, recipient, destinationChainId, relayerFeeTokenAmount);

        emit TokensSentExtras(recipientWalletAddress);
    }

    /**
     * @notice Public method to replace recipient if it was accidentally incorrectly specified
     * @param originalMessage original message bytes (to replace)
     * @param originalAttestation original attestation bytes
     * @param newRecipient the new mint recipient, which may be the same as the
     * original mint recipient, or different.
     **/
    function changeRecipient(
        bytes calldata originalMessage,
        bytes calldata originalAttestation,
        bytes32 newRecipient
    ) external {
        uint64 nonce = uint64(bytes8(originalMessage[12:20]));
        require(senders[nonce] == msg.sender, "CCTP: wrong sender");
        cctpMessenger.replaceDepositForBurn(originalMessage, originalAttestation, bytes32(0), newRecipient);
        emit RecipientReplaced(msg.sender, nonce, newRecipient);
    }

    /**
     * @notice Completes the bridging process by sending the tokens on the destination blockchain to the recipient.
     * @param recipient The recipient address.
     * @param message The message information emitted by the CCTP contract `MessageTransmitter` on the source chain.
     * @param signature Concatenated 65-byte signature(s) of `message`.
     */
    function receiveTokens(address recipient, bytes calldata message, bytes calldata signature) external payable {
        require(cctpTransmitter.receiveMessage(message, signature), "CCTP: Receive message failed");
        // pass extra gas to the recipient
        if (msg.value > 0) {
            (bool sent, ) = payable(recipient).call{value: msg.value}("");
            if (sent) {
                emit ReceivedExtraGas(recipient, msg.value);
            }
        }
    }

    /**
     * @notice Allows the admin to add new supported chain destination.
     * @param chainId_ The chain ID of the destination to register.
     * @param domain The domain of the destination to register.
     */
    function registerBridgeDestination(uint chainId_, uint32 domain) external onlyOwner {
        chainIdDomainMap[chainId_] = domain + 1;
    }

    /**
     * @notice Allows the admin to remove a chain from the map of supported destinations.
     * @param chainId_ The chain ID of the destination to unregister.
     */
    function unregisterBridgeDestination(uint chainId_) external onlyOwner {
        chainIdDomainMap[chainId_] = 0;
    }

    /**
     * @notice Allows the admin to withdraw the relayer fee collected in gas tokens.
     */
    function withdrawGas(uint amount) external onlyOwner {
        payable(msg.sender).transfer(amount);
    }

    /**
     * @notice Allows the admin to withdraw the admin fee and relayer fee collected in tokens.
     */
    function withdrawFeeInTokens() external onlyOwner {
        uint toWithdraw = token.balanceOf(address(this));
        if (toWithdraw > 0) {
            token.safeTransfer(msg.sender, toWithdraw);
        }
    }

    /**
     * @notice Sets the basis points of the admin fee share from each bridge.
     */
    function setAdminFeeShare(uint adminFeeShareBP_) external onlyOwner {
        require(adminFeeShareBP_ <= BP, "CCTP: Too high");
        adminFeeShareBP = adminFeeShareBP_;
    }

    /**
     * @notice Calculates the amount of bridging fee nominated in the stable token.
     * @param destinationChainId The ID of the destination chain.
     * @return The total price of bridging, with the precision according to the token's `decimals()` value.
     */
    function getBridgingCostInTokens(uint destinationChainId) external view returns (uint) {
        return
            gasOracle.getTransactionGasCostInUSD(destinationChainId, gasUsage[destinationChainId]) /
            fromGasOracleScalingFactor;
    }

    function isMessageProcessed(uint sourceChainId, uint64 nonce) external view returns (bool) {
        return cctpTransmitter.usedNonces(_hashSourceAndNonce(getDomainByChainId(sourceChainId), nonce)) != 0;
    }

    function getDomainByChainId(uint chainId_) public view returns (uint32) {
        uint domainNumber = chainIdDomainMap[chainId_];
        require(domainNumber > 0, "CCTP: Unknown chain id");
        return uint32(domainNumber - 1);
    }

    /**
     * @notice Calculates the amount of gas equivalent in value to provided amount of tokens
     * according to the current exchange rate.
     * @param stableTokenAmount The amount of tokens.
     * @return amount of gas tokens.
     */
    function _getStableTokensValueInGas(uint stableTokenAmount) internal view returns (uint) {
        if (stableTokenAmount == 0) return 0;
        return (stableTokensForGasScalingFactor * stableTokenAmount) / gasOracle.price(chainId);
    }

    function _hashSourceAndNonce(uint32 sourceDomain, uint64 nonce) internal pure returns (bytes32) {
        return keccak256(abi.encodePacked(sourceDomain, nonce));
    }

    fallback() external payable {
        revert("Unsupported");
    }

    receive() external payable {
        emit ReceivedGas(msg.sender, msg.value);
    }
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;

import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {IGasOracle} from "./interfaces/IGasOracle.sol";
import {ITokenMessengerV2} from "./interfaces/cctp/ITokenMessengerV2.sol";
import {IMessageTransmitter} from "./interfaces/cctp/IMessageTransmitter.sol";
import {GasUsage} from "./GasUsage.sol";

contract CctpV2Bridge is GasUsage {
    using SafeERC20 for IERC20Metadata;

    uint internal constant ORACLE_PRECISION = 18;
    uint internal constant BP = 1e4;
    uint internal constant MAX_FEE_SHARE_P = 1e9;
    uint32 public minFinalityThreshold = 1000;

    uint public immutable chainId;
    // Admin fee share (in basis points)
    uint public adminFeeShareBP = 10;
    uint public maxFeeShare = 100000;
    IERC20Metadata private immutable token;
    ITokenMessengerV2 private immutable cctpMessenger;
    IMessageTransmitter private immutable cctpTransmitter;
    // precomputed value of the scaling factor required for converting the stable token to gas amount
    uint private immutable stableTokensForGasScalingFactor;
    // precomputed value to divide by to change the precision from the Gas Oracle precision to the stable token precision
    uint private immutable fromGasOracleScalingFactor;

    mapping(uint chainId => uint domainNumber) private chainIdDomainMap;

    /**
     * @notice Emitted when the contract receives some gas directly.
     */
    event ReceivedGas(address sender, uint amount);

    /**
     * @notice Emitted when the contract receives message
     */
    event ReceivedMessageId(bytes32 messageId);

    /**
     * @notice Emitted when the contract sends some extra gas to the recipient of tokens.
     */
    event ReceivedExtraGas(address recipient, uint amount);

    /**
     * @notice Emitted when tokens are sent on the source blockchain.
     */
    event TokensSent(
        address sender,
        bytes32 recipient,
        uint amount,
        uint destinationChainId,
        uint receivedRelayerFeeFromGas,
        uint receivedRelayerFeeFromTokens,
        uint relayerFee,
        uint receivedRelayerFeeTokenAmount,
        uint adminFeeTokenAmount,
        uint maxFee
    );

    event TokensSentExtras(bytes32 recipientWalletAddress);

    constructor(
        uint chainId_,
        uint chainPrecision_,
        address tokenAddress,
        address cctpMessenger_,
        address cctpTransmitter_,
        IGasOracle gasOracle_
    ) GasUsage(gasOracle_) {
        chainId = chainId_;
        token = IERC20Metadata(tokenAddress);
        uint tokenDecimals = token.decimals();
        cctpMessenger = ITokenMessengerV2(cctpMessenger_);
        cctpTransmitter = IMessageTransmitter(cctpTransmitter_);
        token.approve(cctpMessenger_, type(uint256).max);
        stableTokensForGasScalingFactor = 10 ** (ORACLE_PRECISION - tokenDecimals + chainPrecision_);
        fromGasOracleScalingFactor = 10 ** (ORACLE_PRECISION - tokenDecimals);
    }

    /**
     * @notice Initiates a bridging process of the token to another blockchain.
     * @dev This function is used to initiate a cross-chain transfer.
     * The bridging fee required for the cross-chain transfer can be paid in two ways:
     * - by sending the required amount of native gas token along with the transaction
     *   (See `getTransactionCost` in the `GasUsage` contract).
     * - by setting the parameter `relayerFeeTokenAmount` with the amount of bridging fee in tokens
     *   (See the function `getBridgingCostInTokens`).
     * @param amount The amount of tokens to send (including `relayerFeeTokenAmount`).
     * @param recipient The recipient address.
     * @param destinationChainId The ID of the destination chain.
     * @param relayerFeeTokenAmount The amount of tokens to be deducted from the transferred amount as a bridging fee.
     */
    function bridge(
        uint amount,
        bytes32 recipient,
        uint destinationChainId,
        uint relayerFeeTokenAmount
    ) public payable {
        require(amount > relayerFeeTokenAmount, "CCTP: Amount <= relayer fee");
        require(recipient != 0, "CCTP: Recipient must be nonzero");
        token.safeTransferFrom(msg.sender, address(this), amount);
        uint gasFromStables = _getStableTokensValueInGas(relayerFeeTokenAmount);
        uint relayerFee = this.getTransactionCost(destinationChainId);
        require(msg.value + gasFromStables >= relayerFee, "CCTP: Not enough fee");
        uint amountToSend = amount - relayerFeeTokenAmount;
        uint adminFee;
        if (adminFeeShareBP != 0) {
            adminFee = (amountToSend * adminFeeShareBP) / BP;
            if (adminFee == 0) {
                adminFee = 1;
            }
            amountToSend -= adminFee;
        }
        uint maxFee = (amountToSend * maxFeeShare) / MAX_FEE_SHARE_P + 1;
        uint32 destinationDomain = getDomainByChainId(destinationChainId);
        cctpMessenger.depositForBurn(
            amountToSend,
            destinationDomain,
            recipient,
            address(token),
            bytes32(0),
            maxFee,
            minFinalityThreshold
        );
        emit TokensSent(
            msg.sender,
            recipient,
            amountToSend,
            destinationChainId,
            msg.value,
            gasFromStables,
            relayerFee,
            relayerFeeTokenAmount,
            adminFee,
            maxFee
        );
    }

    /**
     * @notice Public method to initiate a bridging process of the token to another blockchain. Used for recipients with different wallet address (Solana)
     * @dev See full description in the bridge method
     * @param recipientWalletAddress The recipient wallet address - used to track user for transfers to Solana.
     **/
    function bridgeWithWalletAddress(
        uint amount,
        bytes32 recipient,
        bytes32 recipientWalletAddress,
        uint destinationChainId,
        uint relayerFeeTokenAmount
    ) external payable {
        bridge(amount, recipient, destinationChainId, relayerFeeTokenAmount);

        emit TokensSentExtras(recipientWalletAddress);
    }

    /**
     * @notice Completes the bridging process by sending the tokens on the destination blockchain to the recipient.
     * @param recipient The recipient address.
     * @param messageId The message id to connect sent and received transaction (Sent tx id)
     * @param message The message information emitted by the CCTP contract `MessageTransmitter` on the source chain.
     * @param signature Concatenated 65-byte signature(s) of `message`.
     */
    function receiveTokens(
        address recipient,
        bytes32 messageId,
        bytes calldata message,
        bytes calldata signature
    ) external payable {
        require(cctpTransmitter.receiveMessage(message, signature), "CCTP: Receive message failed");
        // pass extra gas to the recipient
        if (msg.value > 0) {
            (bool sent, ) = payable(recipient).call{value: msg.value}("");
            if (sent) {
                emit ReceivedExtraGas(recipient, msg.value);
            }
        }

        emit ReceivedMessageId(messageId);
    }

    /**
     * @notice Allows the admin to add new supported chain destination.
     * @param chainId_ The chain ID of the destination to register.
     * @param domain The domain of the destination to register.
     */
    function registerBridgeDestination(uint chainId_, uint32 domain) external onlyOwner {
        chainIdDomainMap[chainId_] = domain + 1;
    }

    /**
     * @notice Allows the admin to remove a chain from the map of supported destinations.
     * @param chainId_ The chain ID of the destination to unregister.
     */
    function unregisterBridgeDestination(uint chainId_) external onlyOwner {
        chainIdDomainMap[chainId_] = 0;
    }

    /**
     * @notice Allows the admin to withdraw the relayer fee collected in gas tokens.
     */
    function withdrawGas(uint amount) external onlyOwner {
        payable(msg.sender).transfer(amount);
    }

    /**
     * @notice Allows the admin to withdraw the admin fee and relayer fee collected in tokens.
     */
    function withdrawFeeInTokens() external onlyOwner {
        uint toWithdraw = token.balanceOf(address(this));
        if (toWithdraw > 0) {
            token.safeTransfer(msg.sender, toWithdraw);
        }
    }

    /**
     * @notice Sets the basis points of the admin fee share from each bridge.
     */
    function setAdminFeeShare(uint adminFeeShareBP_) external onlyOwner {
        require(adminFeeShareBP_ <= BP, "CCTP: Too high");
        adminFeeShareBP = adminFeeShareBP_;
    }

    /**
     * @notice Sets the maximum fee share for the relayer.
     */
    function setMaxFeeShare(uint maxFeeShare_) external onlyOwner {
        require(maxFeeShare_ <= MAX_FEE_SHARE_P, "CCTP: Too high");
        maxFeeShare = maxFeeShare_;
    }

    /**
     * @notice Sets the minimum finality threshold for the relayer.
     */
    function setMinFinalityThreshold(uint32 minFinalityThreshold_) external onlyOwner {
        minFinalityThreshold = minFinalityThreshold_;
    }

    /**
     * @notice Calculates the amount of bridging fee nominated in the stable token.
     * @param destinationChainId The ID of the destination chain.
     * @return The total price of bridging, with the precision according to the token's `decimals()` value.
     */
    function getBridgingCostInTokens(uint destinationChainId) external view returns (uint) {
        return
            gasOracle.getTransactionGasCostInUSD(destinationChainId, gasUsage[destinationChainId]) /
            fromGasOracleScalingFactor;
    }

    function isMessageProcessed(bytes32 nonce) external view returns (bool) {
        return cctpTransmitter.usedNonces(nonce) != 0;
    }

    function getDomainByChainId(uint chainId_) public view returns (uint32) {
        uint domainNumber = chainIdDomainMap[chainId_];
        require(domainNumber > 0, "CCTP: Unknown chain id");
        return uint32(domainNumber - 1);
    }

    /**
     * @notice Calculates the amount of gas equivalent in value to provided amount of tokens
     * according to the current exchange rate.
     * @param stableTokenAmount The amount of tokens.
     * @return amount of gas tokens.
     */
    function _getStableTokensValueInGas(uint stableTokenAmount) internal view returns (uint) {
        if (stableTokenAmount == 0) return 0;
        return (stableTokensForGasScalingFactor * stableTokenAmount) / gasOracle.price(chainId);
    }

    fallback() external payable {
        revert("Unsupported");
    }

    receive() external payable {
        emit ReceivedGas(msg.sender, msg.value);
    }
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;

import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {IGasOracle} from "./interfaces/IGasOracle.sol";

/**
 * @title GasOracle
 * @dev A contract that provides gas price and native token USD price data on other blockchains.
 */
contract GasOracle is Ownable, IGasOracle {
    struct ChainData {
        // price of the chain's native token in USD
        uint128 price;
        // price of a gas unit in the chain's native token with precision according to the const ORACLE_PRECISION
        uint128 gasPrice;
    }
    uint private constant ORACLE_PRECISION = 18;
    uint private constant ORACLE_SCALING_FACTOR = 10 ** ORACLE_PRECISION;
    // number to divide by to change precision from gas oracle price precision to chain precision
    uint private immutable fromOracleToChainScalingFactor;

    mapping(uint chainId => ChainData) public override chainData;
    // current chain ID
    uint public immutable override chainId;

    constructor(uint chainId_, uint chainPrecision) {
        chainId = chainId_;
        fromOracleToChainScalingFactor = 10 ** (ORACLE_PRECISION - chainPrecision);
    }

    /**
     * @notice Sets the chain data for a given chain ID.
     * @param chainId_ The ID of the given chain to set data for.
     * @param price_ The price of the given chain's native token in USD.
     * @param gasPrice The price of a gas unit in the given chain's native token (with precision according to the const
     * `ORACLE_PRECISION`).
     */
    function setChainData(uint chainId_, uint128 price_, uint128 gasPrice) external override onlyOwner {
        chainData[chainId_].price = price_;
        chainData[chainId_].gasPrice = gasPrice;
    }

    /**
     * @notice Sets only the price for a given chain ID.
     * @param chainId_ The ID of the given chain to set the price for.
     * @param price_ The price of the given chain's native token in USD.
     */
    function setPrice(uint chainId_, uint128 price_) external override onlyOwner {
        chainData[chainId_].price = price_;
    }

    /**
     * @notice Sets only the gas price for a given chain ID.
     * @param chainId_ The ID of the given chain to set the gas price for.
     * @param gasPrice The price of a gas unit in the given chain's native token (with precision according to the const
     * `ORACLE_PRECISION`).
     */
    function setGasPrice(uint chainId_, uint128 gasPrice) external override onlyOwner {
        chainData[chainId_].gasPrice = gasPrice;
    }

    /**
     * @notice Calculates the gas cost of a transaction on another chain in the current chain's native token.
     * @param otherChainId The ID of the chain for which to get the gas cost.
     * @param gasAmount The amount of gas used in a transaction.
     * @return The gas cost of a transaction in the current chain's native token
     */
    function getTransactionGasCostInNativeToken(
        uint otherChainId,
        uint gasAmount
    ) external view override returns (uint) {
        return
            (chainData[otherChainId].gasPrice * gasAmount * chainData[otherChainId].price) /
            chainData[chainId].price /
            fromOracleToChainScalingFactor;
    }

    /**
     * @notice Calculates the gas cost of a transaction on another chain in USD.
     * @param otherChainId The ID of the chain for which to get the gas cost.
     * @param gasAmount The amount of gas used in a transaction.
     * @return The gas cost of a transaction in USD with precision of `ORACLE_PRECISION`
     */
    function getTransactionGasCostInUSD(uint otherChainId, uint gasAmount) external view override returns (uint) {
        return (chainData[otherChainId].gasPrice * gasAmount * chainData[otherChainId].price) / ORACLE_SCALING_FACTOR;
    }

    /**
     * @notice Get the cross-rate between the two chains' native tokens.
     * @param otherChainId The ID of the other chain to get the cross-rate for.
     */
    function crossRate(uint otherChainId) external view override returns (uint) {
        return (chainData[otherChainId].price * ORACLE_SCALING_FACTOR) / chainData[chainId].price;
    }

    /**
     * @notice Get the price of a given chain's native token in USD.
     * @param chainId_ The ID of the given chain to get the price.
     * @return the price of the given chain's native token in USD with precision of const ORACLE_PRECISION
     */
    function price(uint chainId_) external view override returns (uint) {
        return chainData[chainId_].price;
    }

    fallback() external payable {
        revert("Unsupported");
    }

    receive() external payable {
        revert("Unsupported");
    }
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;

import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {IGasOracle} from "./interfaces/IGasOracle.sol";

/**
 * @dev Contract module which allows children to store typical gas usage of a certain transaction on another chain.
 */
abstract contract GasUsage is Ownable {
    IGasOracle internal gasOracle;
    mapping(uint chainId => uint amount) public gasUsage;

    constructor(IGasOracle gasOracle_) {
        gasOracle = gasOracle_;
    }

    /**
     * @dev Sets the amount of gas used for a transaction on a given chain.
     * @param chainId The ID of the chain.
     * @param gasAmount The amount of gas used on the chain.
     */
    function setGasUsage(uint chainId, uint gasAmount) external onlyOwner {
        gasUsage[chainId] = gasAmount;
    }

    /**
     * @dev Sets the Gas Oracle contract address.
     * @param gasOracle_ The address of the Gas Oracle contract.
     */
    function setGasOracle(IGasOracle gasOracle_) external onlyOwner {
        gasOracle = gasOracle_;
    }

    /**
     * @notice Get the gas cost of a transaction on another chain in the current chain's native token.
     * @param chainId The ID of the chain for which to get the gas cost.
     * @return The calculated gas cost of the transaction in the current chain's native token
     */
    function getTransactionCost(uint chainId) external view returns (uint) {
        unchecked {
            return gasOracle.getTransactionGasCostInNativeToken(chainId, gasUsage[chainId]);
        }
    }
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;

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

interface IMessageTransmitter is IReceiver {
    function usedNonces(bytes32 _sourceAndNonce) external view returns (uint256);
}

// SPDX-License-Identifier: Apache-2.0
/*
 * Copyright (c) 2022, Circle Internet Financial Limited.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
pragma solidity ^0.8.18;

/**
 * @title IReceiver
 * @notice Receives messages on destination chain and forwards them to IMessageDestinationHandler
 */
interface IReceiver {
    /**
     * @notice Receives an incoming message, validating the header and passing
     * the body to application-specific handler.
     * @param message The message raw bytes
     * @param signature The message signature
     * @return success bool, true if successful
     */
    function receiveMessage(bytes calldata message, bytes calldata signature) external returns (bool success);
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;

interface ITokenMessenger {
    /**
     * @notice Deposits and burns tokens from sender to be minted on destination domain.
     * Emits a `DepositForBurn` event.
     * @dev reverts if:
     * - given burnToken is not supported
     * - given destinationDomain has no TokenMessenger registered
     * - transferFrom() reverts. For example, if sender's burnToken balance or approved allowance
     * to this contract is less than `amount`.
     * - burn() reverts. For example, if `amount` is 0.
     * - MessageTransmitter returns false or reverts.
     * @param amount amount of tokens to burn
     * @param destinationDomain destination domain
     * @param mintRecipient address of mint recipient on destination domain
     * @param burnToken address of contract to burn deposited tokens, on local domain
     * @return _nonce unique nonce reserved by message
     */
    function depositForBurn(
        uint amount,
        uint32 destinationDomain,
        bytes32 mintRecipient,
        address burnToken
    ) external returns (uint64 _nonce);

    /**
     * @notice Replace a BurnMessage to change the mint recipient and/or
     * destination caller. Allows the sender of a previous BurnMessage
     * (created by depositForBurn or depositForBurnWithCaller)
     * to send a new BurnMessage to replace the original.
     * The new BurnMessage will reuse the amount and burn token of the original,
     * without requiring a new deposit.
     * @dev The new message will reuse the original message's nonce. For a
     * given nonce, all replacement message(s) and the original message are
     * valid to broadcast on the destination domain, until the first message
     * at the nonce confirms, at which point all others are invalidated.
     * Note: The msg.sender of the replaced message must be the same as the
     * msg.sender of the original message.
     * @param originalMessage original message bytes (to replace)
     * @param originalAttestation original attestation bytes
     * @param newDestinationCaller the new destination caller, which may be the
     * same as the original destination caller, a new destination caller, or an empty
     * destination caller (bytes32(0), indicating that any destination caller is valid.)
     * @param newMintRecipient the new mint recipient, which may be the same as the
     * original mint recipient, or different.
     */
    function replaceDepositForBurn(
        bytes calldata originalMessage,
        bytes calldata originalAttestation,
        bytes32 newDestinationCaller,
        bytes32 newMintRecipient
    ) external;
}

File 36 of 58 : ITokenMessengerV2.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;

interface ITokenMessengerV2 {
    /**
     * @notice Deposits and burns tokens from sender to be minted on destination domain.
     * Emits a `DepositForBurn` event.
     * @dev reverts if:
     * - given burnToken is not supported
     * - given destinationDomain has no TokenMessenger registered
     * - transferFrom() reverts. For example, if sender's burnToken balance or approved allowance
     * to this contract is less than `amount`.
     * - burn() reverts. For example, if `amount` is 0.
     * - maxFee is greater than or equal to `amount`.
     * - MessageTransmitterV2#sendMessage reverts.
     * @param amount amount of tokens to burn
     * @param destinationDomain destination domain to receive message on
     * @param mintRecipient address of mint recipient on destination domain
     * @param burnToken token to burn `amount` of, on local domain
     * @param destinationCaller authorized caller on the destination domain, as bytes32. If equal to bytes32(0),
     * any address can broadcast the message.
     * @param maxFee maximum fee to pay on the destination domain, specified in units of burnToken
     * @param minFinalityThreshold the minimum finality at which a burn message will be attested to.
     */
    function depositForBurn(
        uint256 amount,
        uint32 destinationDomain,
        bytes32 mintRecipient,
        address burnToken,
        bytes32 destinationCaller,
        uint256 maxFee,
        uint32 minFinalityThreshold
    ) external;
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;

enum MessengerProtocol {
    None,
    Allbridge,
    Wormhole,
    LayerZero
}

interface IBridge {
    function chainId() external view returns (uint);

    function processedMessages(bytes32) external view returns (uint);

    function sentMessages(bytes32) external view returns (uint);

    function otherBridges(uint) external view returns (bytes32);

    function otherBridgeTokens(uint, bytes32) external view returns (bool);

    function getBridgingCostInTokens(
        uint destinationChainId,
        MessengerProtocol messenger,
        address tokenAddress
    ) external view returns (uint);

    function hashMessage(
        uint amount,
        bytes32 recipient,
        uint sourceChainId,
        uint destinationChainId,
        bytes32 receiveToken,
        uint nonce,
        MessengerProtocol messenger
    ) external pure returns (bytes32);

    function receiveTokens(
        uint amount,
        bytes32 recipient,
        uint sourceChainId,
        bytes32 receiveToken,
        uint nonce,
        MessengerProtocol messenger,
        uint receiveAmountMin
    ) external payable;

    function withdrawGasTokens(uint amount) external;

    function registerBridge(uint chainId, bytes32 bridgeAddress) external;

    function addBridgeToken(uint chainId, bytes32 tokenAddress) external;

    function removeBridgeToken(uint chainId, bytes32 tokenAddress) external;

    function swapAndBridge(
        bytes32 token,
        uint amount,
        bytes32 recipient,
        uint destinationChainId,
        bytes32 receiveToken,
        uint nonce,
        MessengerProtocol messenger,
        uint feeTokenAmount
    ) external payable;
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;

interface IGasOracle {
    function chainData(uint chainId) external view returns (uint128 price, uint128 gasPrice);

    function chainId() external view returns (uint);

    function crossRate(uint otherChainId) external view returns (uint);

    function getTransactionGasCostInNativeToken(uint otherChainId, uint256 gasAmount) external view returns (uint);

    function getTransactionGasCostInUSD(uint otherChainId, uint256 gasAmount) external view returns (uint);

    function price(uint chainId) external view returns (uint);

    function setChainData(uint chainId, uint128 price, uint128 gasPrice) external;

    function setGasPrice(uint chainId, uint128 gasPrice) external;

    function setPrice(uint chainId, uint128 price) external;
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;

interface IMessenger {
    function sentMessagesBlock(bytes32 message) external view returns (uint);

    function receivedMessages(bytes32 message) external view returns (uint);

    function sendMessage(bytes32 message) external payable;

    function receiveMessage(bytes32 message, uint v1v2, bytes32 r1, bytes32 s1, bytes32 r2, bytes32 s2) external;
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;

import {MessengerProtocol} from "./IBridge.sol";

interface IRouter {
    function canSwap() external view returns (uint8);

    function swap(uint amount, bytes32 token, bytes32 receiveToken, address recipient, uint receiveAmountMin) external;
}

// contracts/Messages.sol
// SPDX-License-Identifier: Apache 2
pragma solidity ^0.8.18;

interface Structs {
    struct Provider {
        uint16 chainId;
        uint16 governanceChainId;
        bytes32 governanceContract;
    }

    struct GuardianSet {
        address[] keys;
        uint32 expirationTime;
    }

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

    struct VM {
        uint8 version;
        uint32 timestamp;
        uint32 nonce;
        uint16 emitterChainId;
        bytes32 emitterAddress;
        uint64 sequence;
        uint8 consistencyLevel;
        bytes payload;
        uint32 guardianSetIndex;
        Signature[] signatures;
        bytes32 hash;
    }
}

interface IWormhole is Structs {
    event LogMessagePublished(
        address indexed sender,
        uint64 sequence,
        uint32 nonce,
        bytes payload,
        uint8 consistencyLevel
    );

    function publishMessage(
        uint32 nonce,
        bytes memory payload,
        uint8 consistencyLevel
    ) external payable returns (uint64 sequence);

    function parseAndVerifyVM(
        bytes calldata encodedVM
    ) external view returns (Structs.VM memory vm, bool valid, string memory reason);

    function verifyVM(Structs.VM memory vm) external view returns (bool valid, string memory reason);

    function verifySignatures(
        bytes32 hash,
        Structs.Signature[] memory signatures,
        Structs.GuardianSet memory guardianSet
    ) external pure returns (bool valid, string memory reason);

    function parseVM(bytes memory encodedVM) external pure returns (Structs.VM memory vm);

    function getGuardianSet(uint32 index) external view returns (Structs.GuardianSet memory);

    function getCurrentGuardianSetIndex() external view returns (uint32);

    function getGuardianSetExpiry() external view returns (uint32);

    function governanceActionIsConsumed(bytes32 hash) external view returns (bool);

    function isInitialized(address impl) external view returns (bool);

    function chainId() external view returns (uint16);

    function governanceChainId() external view returns (uint16);

    function governanceContract() external view returns (bytes32);

    function messageFee() external view returns (uint);
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;

library HashUtils {
    function replaceChainBytes(
        bytes32 data,
        uint8 sourceChainId,
        uint8 destinationChainId
    ) internal pure returns (bytes32 result) {
        assembly {
            mstore(0x00, data)
            mstore8(0x00, sourceChainId)
            mstore8(0x01, destinationChainId)
            result := mload(0x0)
        }
    }

    function hashWithSender(bytes32 message, bytes32 sender) internal pure returns (bytes32 result) {
        assembly {
            mstore(0x00, message)
            mstore(0x20, sender)
            result := or(
                and(
                    message,
                    0xffff000000000000000000000000000000000000000000000000000000000000 // First 2 bytes
                ),
                and(
                    keccak256(0x00, 0x40),
                    0x0000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff // Last 30 bytes
                )
            )
        }
    }

    function hashWithSenderAddress(bytes32 message, address sender) internal pure returns (bytes32 result) {
        assembly {
            mstore(0x00, message)
            mstore(0x20, sender)
            result := or(
                and(
                    message,
                    0xffff000000000000000000000000000000000000000000000000000000000000 // First 2 bytes
                ),
                and(
                    keccak256(0x00, 0x40),
                    0x0000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff // Last 30 bytes
                )
            )
        }
    }

    function hashed(bytes32 message) internal pure returns (bytes32 result) {
        assembly {
            mstore(0x00, message)
            result := keccak256(0x00, 0x20)
        }
    }
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;

import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {IGasOracle} from "./interfaces/IGasOracle.sol";
import {IMessenger} from "./interfaces/IMessenger.sol";
import {GasUsage} from "./GasUsage.sol";
import {HashUtils} from "./libraries/HashUtils.sol";

/**
 * @dev This contract implements the Allbridge messenger cross-chain communication protocol.
 */
contract Messenger is Ownable, GasUsage, IMessenger {
    using HashUtils for bytes32;
    // current chain ID
    uint public immutable chainId;
    // supported destination chain IDs
    bytes32 public otherChainIds;

    // the primary account that is responsible for validation that a message has been sent on the source chain
    address private primaryValidator;
    // the secondary accounts that are responsible for validation that a message has been sent on the source chain
    mapping(address => bool) private secondaryValidators;
    mapping(bytes32 messageHash => uint blockNumber) public override sentMessagesBlock;
    mapping(bytes32 messageHash => uint isReceived) public override receivedMessages;

    event MessageSent(bytes32 indexed message);
    event MessageReceived(bytes32 indexed message);

    /**
     * @dev Emitted when the contract receives native gas tokens (e.g. Ether on the Ethereum network).
     */
    event Received(address, uint);

    /**
     * @dev Emitted when the mapping of secondary validators is updated.
     */
    event SecondaryValidatorsSet(address[] oldValidators, address[] newValidators);

    constructor(
        uint chainId_,
        bytes32 otherChainIds_,
        IGasOracle gasOracle_,
        address primaryValidator_,
        address[] memory validators
    ) GasUsage(gasOracle_) {
        chainId = chainId_;
        otherChainIds = otherChainIds_;
        primaryValidator = primaryValidator_;

        uint length = validators.length;
        for (uint index; index < length; ) {
            secondaryValidators[validators[index]] = true;
            unchecked {
                index++;
            }
        }
    }

    /**
     * @notice Sends a message to another chain.
     * @dev Emits a {MessageSent} event, which signals to the off-chain messaging service to invoke the `receiveMessage`
     * function on the destination chain to deliver the message.
     *
     * Requirements:
     *
     * - the first byte of the message must be the current chain ID.
     * - the second byte of the message must be the destination chain ID.
     * - the same message cannot be sent second time.
     * - messaging fee must be payed. (See `getTransactionCost` of the `GasUsage` contract).
     * @param message The message to be sent to the destination chain.
     */
    function sendMessage(bytes32 message) external payable override {
        require(uint8(message[0]) == chainId, "Messenger: wrong chainId");
        require(otherChainIds[uint8(message[1])] != 0, "Messenger: wrong destination");

        bytes32 messageWithSender = message.hashWithSenderAddress(msg.sender);

        require(sentMessagesBlock[messageWithSender] == 0, "Messenger: has message");
        sentMessagesBlock[messageWithSender] = block.number;

        require(msg.value >= this.getTransactionCost(uint8(message[1])), "Messenger: not enough fee");

        emit MessageSent(messageWithSender);
    }

    /**
     * @notice Delivers a message to the destination chain.
     * @dev Emits an {MessageReceived} event indicating the message has been delivered.
     *
     * Requirements:
     *
     * - a valid signature of the primary validator.
     * - a valid signature of one of the secondary validators.
     * - the second byte of the message must be the current chain ID.
     */
    function receiveMessage(
        bytes32 message,
        uint v1v2,
        bytes32 r1,
        bytes32 s1,
        bytes32 r2,
        bytes32 s2
    ) external override {
        bytes32 hashedMessage = message.hashed();
        require(ecrecover(hashedMessage, uint8(v1v2 >> 8), r1, s1) == primaryValidator, "Messenger: invalid primary");
        require(secondaryValidators[ecrecover(hashedMessage, uint8(v1v2), r2, s2)], "Messenger: invalid secondary");

        require(uint8(message[1]) == chainId, "Messenger: wrong chainId");

        receivedMessages[message] = 1;

        emit MessageReceived(message);
    }

    /**
     * @dev Allows the admin to withdraw the messaging fee collected in native gas tokens.
     */
    function withdrawGasTokens(uint amount) external onlyOwner {
        payable(msg.sender).transfer(amount);
    }

    /**
     * @dev Allows the admin to set the primary validator address.
     */
    function setPrimaryValidator(address value) external onlyOwner {
        primaryValidator = value;
    }

    /**
     * @dev Allows the admin to set the addresses of secondary validators.
     */
    function setSecondaryValidators(address[] memory oldValidators, address[] memory newValidators) external onlyOwner {
        uint length = oldValidators.length;
        uint index;
        for (; index < length; ) {
            secondaryValidators[oldValidators[index]] = false;
            unchecked {
                index++;
            }
        }
        length = newValidators.length;
        index = 0;
        for (; index < length; ) {
            secondaryValidators[newValidators[index]] = true;
            unchecked {
                index++;
            }
        }
        emit SecondaryValidatorsSet(oldValidators, newValidators);
    }

    /**
     * @dev Allows the admin to update a list of supported destination chain IDs
     * @param value Each byte of the `value` parameter represents whether a chain ID with such index is supported
     *              as a valid message destination.
     */
    function setOtherChainIds(bytes32 value) external onlyOwner {
        otherChainIds = value;
    }

    fallback() external payable {
        revert("Unsupported");
    }

    receive() external payable {
        emit Received(msg.sender, msg.value);
    }
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;

import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {IGasOracle} from "./interfaces/IGasOracle.sol";
import {Messenger} from "./Messenger.sol";
import {MessengerProtocol} from "./interfaces/IBridge.sol";
import {WormholeMessenger} from "./WormholeMessenger.sol";

/**
 * @dev This abstract contract provides functions for cross-chain communication and supports different messaging
 *      protocols.
 */
abstract contract MessengerGateway is Ownable {
    Messenger private allbridgeMessenger;
    WormholeMessenger private wormholeMessenger;

    constructor(Messenger allbridgeMessenger_, WormholeMessenger wormholeMessenger_) {
        allbridgeMessenger = allbridgeMessenger_;
        wormholeMessenger = wormholeMessenger_;
    }

    /**
     * @dev Sets the Allbridge Messenger contract address.
     * @param allbridgeMessenger_ The address of the Messenger contract.
     */
    function setAllbridgeMessenger(Messenger allbridgeMessenger_) external onlyOwner {
        allbridgeMessenger = allbridgeMessenger_;
    }

    /**
     * @dev Sets the Wormhole Messenger contract address.
     * @param wormholeMessenger_ The address of the WormholeMessenger contract.
     */
    function setWormholeMessenger(WormholeMessenger wormholeMessenger_) external onlyOwner {
        wormholeMessenger = wormholeMessenger_;
    }

    /**
     * @notice Get the gas cost of a messaging transaction on another chain in the current chain's native token.
     * @param chainId The ID of the chain where to send the message.
     * @param protocol The messenger used to send the message.
     * @return The calculated gas cost of the messaging transaction in the current chain's native token.
     */
    function getMessageCost(uint chainId, MessengerProtocol protocol) external view returns (uint) {
        if (protocol == MessengerProtocol.Allbridge) {
            return allbridgeMessenger.getTransactionCost(chainId);
        } else if (protocol == MessengerProtocol.Wormhole) {
            return wormholeMessenger.getTransactionCost(chainId);
        }
        return 0;
    }

    /**
     * @notice Get the amount of gas a messaging transaction uses on a given chain.
     * @param chainId The ID of the chain where to send the message.
     * @param protocol The messenger used to send the message.
     * @return The amount of gas a messaging transaction uses.
     */
    function getMessageGasUsage(uint chainId, MessengerProtocol protocol) public view returns (uint) {
        if (protocol == MessengerProtocol.Allbridge) {
            return allbridgeMessenger.gasUsage(chainId);
        } else if (protocol == MessengerProtocol.Wormhole) {
            return wormholeMessenger.gasUsage(chainId);
        }
        return 0;
    }

    /**
     * @notice Checks whether a given message has been received via the specified messenger protocol.
     * @param message The message to check.
     * @param protocol The messenger used to send the message.
     * @return A boolean indicating whether the message has been received.
     */
    function hasReceivedMessage(bytes32 message, MessengerProtocol protocol) external view returns (bool) {
        if (protocol == MessengerProtocol.Allbridge) {
            return allbridgeMessenger.receivedMessages(message) != 0;
        } else if (protocol == MessengerProtocol.Wormhole) {
            return wormholeMessenger.receivedMessages(message) != 0;
        } else {
            revert("Not implemented");
        }
    }

    /**
     * @notice Checks whether a given message has been sent.
     * @param message The message to check.
     * @return A boolean indicating whether the message has been sent.
     */
    function hasSentMessage(bytes32 message) external view returns (bool) {
        return allbridgeMessenger.sentMessagesBlock(message) != 0 || wormholeMessenger.sentMessages(message) != 0;
    }

    function _sendMessage(bytes32 message, MessengerProtocol protocol) internal returns (uint messageCost) {
        if (protocol == MessengerProtocol.Allbridge) {
            messageCost = allbridgeMessenger.getTransactionCost(uint8(message[1]));
            allbridgeMessenger.sendMessage{value: messageCost}(message);
        } else if (protocol == MessengerProtocol.Wormhole) {
            messageCost = wormholeMessenger.getTransactionCost(uint8(message[1]));
            wormholeMessenger.sendMessage{value: messageCost}(message);
        } else {
            revert("Not implemented");
        }
    }
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;

import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IGasOracle} from "./interfaces/IGasOracle.sol";
import {OptionsBuilder} from "@layerzerolabs/oapp-evm/contracts/oapp/libs/OptionsBuilder.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {SendParam, IOFT, MessagingFee} from "@layerzerolabs/oft-evm/contracts/interfaces/IOFT.sol";

/**
 * @title OftBridge
 * @notice A proxy contract for handling cross-chain token transfers using LayerZero's Omnichain Fungible Token (OFT) standard.
 * @dev Incorporates OpenZeppelin and LayerZero libraries for safe token handling and cross-chain messaging.
 */
contract OftBridge is Ownable {
    using SafeERC20 for IERC20;
    using OptionsBuilder for bytes;

    // Constants
    uint internal constant ORACLE_PRECISION = 18; // Decimals for gas cost calculations
    uint internal constant BP = 1e4;             // Basis points denominator (1 basis point = 0.01%)
    uint private immutable chainPrecision;       // Current chain precision

    // State variables
    IGasOracle internal gasOracle;               // Gas price oracle for pricing gas in token terms
    uint public immutable chainId;               // Chain ID of the current blockchain
    mapping(address tokenAddress => uint feeShare) public adminFeeShareBP;    // Admin's fee share per token (bps)

    // Mappings for managing token addresses and chain configurations
    mapping(address tokenAddress => uint scalingFactor) internal stableTokensForGasScalingFactor;               // Scaling factor for token-to-gas conversion
    mapping(uint chainId => uint32 eid) private chainIdEidMap;                                                  // Map from chain ID to LayerZero Endpoint ID
    mapping(uint chainId => uint maxExtraGas) internal maxExtraGas;                                             // Maximum allowed extra gas for each chain
    mapping(uint chainId => uint128 gasLimit) internal lzGasLimit;                                              // LayerZero-specific gas limit for cross-chain transactions
    mapping(address tokenAddress => mapping(uint destinationChainId => address oftAddress)) public oftAddress;  // Map from token to its OFT contract address depending on destination ChainId

    /**
     * @dev Event emitted when the contract receives some gas directly.
     * @param sender The address of the sender.
     * @param amount The amount of gas received.
     */
    event ReceivedGas(address sender, uint amount);

    /**
     * @dev Event emitted when tokens are sent to a destination chain.
     */
    event OftTokensSent(
        address sender,
        bytes32 recipient,
        address tokenAddress,
        uint amount,
        uint destinationChainId,
        uint receivedRelayerFeeFromGas,
        uint receivedRelayerFeeFromTokens,
        uint relayerFeeWithExtraGas,
        uint receivedRelayerFeeTokenAmount,
        uint adminFeeTokenAmount,
        uint extraGasDestinationToken
    );

    /**
     * @notice Constructor to initialize the OftBridge.
     * @param chainId_ The chain ID of the current blockchain.
     * @param gasOracle_ The address of the gas oracle contract.
     */
    constructor(
        uint chainId_,
        uint chainPrecision_,
        IGasOracle gasOracle_
    ) {
        chainId = chainId_;
        gasOracle = gasOracle_;
        chainPrecision = chainPrecision_;
    }

    /**
     * @notice Bridges tokens to a destination chain.
     * @param tokenAddress The token address to send.
     * @param amount The amount of tokens to bridge.
     * @param recipient The recipient address on the destination chain (as bytes32).
     * @param destinationChainId The ID of the destination chain.
     * @param relayerFeeTokenAmount The portion of the fee in tokens.
     * @param extraGasInDestinationToken Additional gas for execution on the destination chain.
     * @param slippageBP The acceptable slippage in basis points.
     */
    function bridge(
        address tokenAddress,
        uint amount,
        bytes32 recipient,
        uint destinationChainId,
        uint relayerFeeTokenAmount,
        uint extraGasInDestinationToken,
        uint slippageBP
    ) public payable {
        // Validate input parameters
        require(amount > relayerFeeTokenAmount, "Amount <= relayer fee");
        require(recipient != 0, "Recipient must be nonzero");
        require(slippageBP <= BP, "Too high slippage");
        // Retrieve the oft address associated with the token
        address oft = oftAddress[tokenAddress][destinationChainId];
        require(oft != address(0), "Token is not registered for the destination");

        IERC20(tokenAddress).safeTransferFrom(msg.sender, address(this), amount);

        // Ensure extra gas is within the allowed limit
        require(maxExtraGas[destinationChainId] == 0 || extraGasInDestinationToken <= maxExtraGas[destinationChainId], "Extra gas too high");

        // Initialize LayerZero options for the transaction
        bytes memory options = OptionsBuilder.newOptions();
        if (lzGasLimit[destinationChainId] > 0) {
            options = options.addExecutorLzReceiveOption(lzGasLimit[destinationChainId], 0);
        }
        if (extraGasInDestinationToken > 0) {
            options = options.addExecutorNativeDropOption(uint128(extraGasInDestinationToken), recipient);
        }

        // Calculate the amount to send after deducting fees
        uint amountToSend = amount - relayerFeeTokenAmount;
        uint adminFee;
        if (adminFeeShareBP[tokenAddress] != 0) {
            adminFee = (amountToSend * adminFeeShareBP[tokenAddress]) / BP;
            if (adminFee == 0) {
                adminFee = 1;
            }
            amountToSend -= adminFee;
        }

        // Prepare the LayerZero `SendParam` with messaging options and slippage
        SendParam memory sendParam = SendParam(
            getEidByChainId(destinationChainId),
            recipient,
            amountToSend,
            amountToSend - (amountToSend * slippageBP / BP), // Minimum amount (after slippage)
            options,
            "",
            ""
        );

        // Retrieve the messaging fee from the LayerZero protocol
        MessagingFee memory messagingFee = IOFT(oft).quoteSend(sendParam, false);

        // Calculate the gas equivalent of stable tokens for the relayer fee
        uint gasFromStables = _getStableTokensValueInGas(tokenAddress, relayerFeeTokenAmount);
        require(msg.value + gasFromStables >= messagingFee.nativeFee, "Not enough fee");

        // Send the transaction through the OFT protocol
        require(address(this).balance >= messagingFee.nativeFee, "Insufficient contract balance");
        IOFT(oft).send{value: messagingFee.nativeFee}(sendParam, messagingFee, msg.sender);

        // Emit an event for tracking the token bridge
        emit OftTokensSent(
            msg.sender,
            recipient,
            tokenAddress,
            amountToSend,
            destinationChainId,
            msg.value,
            gasFromStables,
            messagingFee.nativeFee,
            relayerFeeTokenAmount,
            adminFee,
            extraGasInDestinationToken
        );
    }

    /**
    * @notice Registers a new destination chain for bridging operations.
     * @param chainId_ The chain ID of the destination chain.
     * @param eid_ The LayerZero endpoint ID for the destination chain.
     * @param lzGasLimit_ The gas limit for LayerZero operations on the destination chain.
     */
    function registerBridgeDestination(uint chainId_, uint32 eid_, uint128 lzGasLimit_) external onlyOwner {
        chainIdEidMap[chainId_] = eid_;
        lzGasLimit[chainId_] = lzGasLimit_;
    }

    /**
     * @notice Allows the admin to remove a chain from the map of supported destinations.
     * @param chainId_ The chain ID of the destination to unregister.
     */
    function unregisterBridgeDestination(uint chainId_) external onlyOwner {
        chainIdEidMap[chainId_] = 0;
        lzGasLimit[chainId_] = 0;
    }

    /**
     * @notice Adds a new token to the bridge with its corresponding OFT contract for specific destination
     * @param oft_ The address of the OFT contract for the token.
     * @param destinationChainId_ The ID of the destination chain.
     */
    function addToken(address oft_, uint destinationChainId_) external onlyOwner {
        address tokenAddress = IOFT(oft_).token();
        uint tokenDecimals = IERC20Metadata(tokenAddress).decimals();
        IERC20(tokenAddress).forceApprove(oft_, type(uint256).max);
        stableTokensForGasScalingFactor[tokenAddress] = 10 ** (ORACLE_PRECISION - tokenDecimals + chainPrecision);
        oftAddress[tokenAddress][destinationChainId_] = oft_;
    }

    /**
     * @notice Removes a token from the bridge for specific destination.
     * @param oft_ The address of the OFT contract to remove.
     * @param destinationChainId_ The ID of the destination chain.
     */
    function removeToken(address oft_, uint destinationChainId_) external onlyOwner {
        address tokenAddress = IOFT(oft_).token();
        oftAddress[tokenAddress][destinationChainId_] = address(0);
    }

    /**
     * @notice Removes a token allowance from oft contract and scaling factor
     * @param oft_ The address of the OFT contract to remove.
     */
    function removeTokenAllowanceAndScalingFactor(address oft_) external onlyOwner {
        address tokenAddress = IOFT(oft_).token();
        stableTokensForGasScalingFactor[tokenAddress] = 0;
        IERC20(tokenAddress).forceApprove(oft_, 0);
    }

    /**
     * @notice Retrieves the relayer fee required for a specific chain.
     * @param tokenAddress_ The address of the token.
     * @param destinationChainId_ The ID of the destination chain.
     * @return The required fee in native gas tokens.
     */
    function relayerFee(address tokenAddress_, uint destinationChainId_) external view returns (uint) {
        address oft = oftAddress[tokenAddress_][destinationChainId_];
        require(oft != address(0), "Token is not registered for the destination");
        MessagingFee memory messagingFee = IOFT(oft).quoteSend(_createEmptySendParam(destinationChainId_, 0), false);
        return messagingFee.nativeFee;
    }

    /**
     * @notice Calculates the price of additional gas on the destination chain.
     * @param tokenAddress_ The address of the token.
     * @param destinationChainId_ The ID of the destination chain.
     * @param extraGasAmount_ The extra gas amount for the destination chain.
     * @return The price of the additional gas in native tokens.
     */
    function extraGasPrice(address tokenAddress_, uint destinationChainId_, uint128 extraGasAmount_) external view returns (uint) {
        address oft = oftAddress[tokenAddress_][destinationChainId_];
        require(oft != address(0), "Token is not registered for the destination");
        MessagingFee memory messagingFee1 = IOFT(oft).quoteSend(_createEmptySendParam(destinationChainId_, extraGasAmount_), false);
        MessagingFee memory messagingFee2 = IOFT(oft).quoteSend(_createEmptySendParam(destinationChainId_, extraGasAmount_ * 2), false);
        return messagingFee2.nativeFee - messagingFee1.nativeFee;
    }

    /**
     * @notice Allows the admin to withdraw the relayer fee collected in gas tokens.
     * @param amount_ The amount of gas tokens to withdraw.
     * @dev Only callable by the contract owner. Transfers the specified amount of native tokens
     * from the contract to the owner's address.
     */
    function withdrawGas(uint amount_) external onlyOwner {
        payable(msg.sender).transfer(amount_);
    }

    /**
     * @notice Allows the admin to withdraw the admin fee and relayer fee collected in tokens.
     * @param token_ The ERC20 token contract address from which to withdraw fees.
     * @dev Only callable by the contract owner. Transfers all available tokens
     * of the specified type from the contract to the owner's address.
     */
    function withdrawFeeInTokens(IERC20 token_) external onlyOwner {
        uint toWithdraw = token_.balanceOf(address(this));
        if (toWithdraw > 0) {
            token_.safeTransfer(msg.sender, toWithdraw);
        }
    }

    /**
     * @notice Sets the basis points of the admin fee share from each bridge.
     * @param tokenAddress_ The address of the token for which to set the admin fee share.
     * @param adminFeeShareBP_ The percentage of the fee in basis points (1 BP = 0.01%) to be allocated to admin.
     * @dev Only callable by the contract owner.
     * The value must be less than or equal to the BP constant (10000).
     * This fee is deducted from the token amount before bridging.
     */
    function setAdminFeeShare(address tokenAddress_, uint adminFeeShareBP_) external onlyOwner {
        require(adminFeeShareBP_ <= BP, "Too high");
        adminFeeShareBP[tokenAddress_] = adminFeeShareBP_;
    }

    /**
     * @notice Sets the maximum extra gas allowed for a specific chain.
     * @param chainId_ The chain ID to set the limit for.
     * @param maxExtraGas_ The maximum amount of extra gas allowed.
     */
    function setMaxExtraGas(uint chainId_, uint maxExtraGas_) external onlyOwner {
        maxExtraGas[chainId_] = maxExtraGas_;
    }

    /**
     * @notice Sets the LayerZero gas limit for a specific chain.
     * @param chainId_ The chain ID to set the limit for.
     * @param lzGasLimit_ The gas limit for LayerZero operations.
     */
    function setLzGasLimit(uint chainId_, uint128 lzGasLimit_) external onlyOwner {
        lzGasLimit[chainId_] = lzGasLimit_;
    }

    /**
     * @notice Gets the LayerZero endpoint ID for a given chain ID.
     * @param chainId_ The chain ID to lookup.
     * @return The corresponding LayerZero endpoint ID.
     */
    function getEidByChainId(uint chainId_) public view returns (uint32) {
        uint32 domainNumber = chainIdEidMap[chainId_];
        require(domainNumber > 0, "Unknown chain id");
        return domainNumber;
    }

    /**
     * @notice Creates an empty SendParam structure for fee estimation.
     * @dev Used internally to create a basic SendParam with minimal values for gas calculations.
     * @param destinationChainId_ The ID of the destination chain.
     * @param extraGasDestinationToken_ Additional gas amount for the destination chain execution.
     * @return SendParam A LayerZero SendParam structure with basic configuration.
     */
    function _createEmptySendParam(
        uint destinationChainId_, uint128 extraGasDestinationToken_
    ) private view returns (SendParam memory) {
        bytes memory options = OptionsBuilder.newOptions();
        if (lzGasLimit[destinationChainId_] > 0) {
            options = options.addExecutorLzReceiveOption(lzGasLimit[destinationChainId_], 0);
        }
        if (extraGasDestinationToken_ > 0) {
            options = options.addExecutorNativeDropOption(extraGasDestinationToken_, bytes32(0));
        }
        return SendParam(
            getEidByChainId(destinationChainId_),
            bytes32(0),
            0,
            0,
            options,
            "",
            ""
        );
    }

    /**
     * @notice Calculates the amount of gas equivalent in value to provided amount of tokens
     * according to the current exchange rate.
     * @param tokenAddress_ The address of the token.
     * @param stableTokenAmount_ The amount of tokens.
     * @return amount of gas tokens.
     */
    function _getStableTokensValueInGas(address tokenAddress_, uint stableTokenAmount_) internal view returns (uint) {
        require(stableTokensForGasScalingFactor[tokenAddress_] > 0, "Token is not set");
        if (stableTokenAmount_ == 0) return 0;
        return (stableTokensForGasScalingFactor[tokenAddress_] * stableTokenAmount_) / gasOracle.price(chainId);
    }

    fallback() external payable {
        revert("Unsupported");
    }

    receive() external payable {
        emit ReceivedGas(msg.sender, msg.value);
    }
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;

import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";

contract RewardManager is Ownable, ERC20 {
    using SafeERC20 for ERC20;
    uint private constant P = 52;
    uint internal constant BP = 1e4;

    // Accumulated rewards per share, shifted left by P bits
    uint public accRewardPerShareP;

    // Reward token
    ERC20 public immutable token;
    // Info of each user reward debt
    mapping(address user => uint amount) public userRewardDebt;

    // Admin fee share (in basis points)
    uint public adminFeeShareBP;
    // Unclaimed admin fee amount
    uint public adminFeeAmount;

    event Deposit(address indexed user, uint amount);
    event Withdraw(address indexed user, uint amount);
    event RewardsClaimed(address indexed user, uint amount);

    constructor(ERC20 token_, string memory lpName, string memory lpSymbol) ERC20(lpName, lpSymbol) {
        token = token_;
        // Default admin fee is 20%
        adminFeeShareBP = BP / 5;
    }

    /**
     * @notice Claims pending rewards for the current staker without updating the stake balance.
     */
    function claimRewards() external {
        uint userLpAmount = balanceOf(msg.sender);
        if (userLpAmount > 0) {
            uint rewards = (userLpAmount * accRewardPerShareP) >> P;
            uint pending = rewards - userRewardDebt[msg.sender];
            if (pending > 0) {
                userRewardDebt[msg.sender] = rewards;
                token.safeTransfer(msg.sender, pending);
                emit RewardsClaimed(msg.sender, pending);
            }
        }
    }

    /**
     * @notice Sets the basis points of the admin fee share from rewards.
     */
    function setAdminFeeShare(uint adminFeeShareBP_) external onlyOwner {
        require(adminFeeShareBP_ <= BP, "RewardManager: too high");
        adminFeeShareBP = adminFeeShareBP_;
    }

    /**
     * @notice Allows the admin to claim the collected admin fee.
     */
    function claimAdminFee() external onlyOwner {
        if (adminFeeAmount > 0) {
            token.safeTransfer(msg.sender, adminFeeAmount);
            adminFeeAmount = 0;
        }
    }

    /**
     * @notice Returns pending rewards for the staker.
     * @param user The address of the staker.
     */
    function pendingReward(address user) external view returns (uint) {
        return ((balanceOf(user) * accRewardPerShareP) >> P) - userRewardDebt[user];
    }

    /**
     * @dev Returns the number of decimals used to get user representation of LP tokens.
     */
    function decimals() public pure override returns (uint8) {
        return 3;
    }

    /**
     * @dev Adds reward to the pool, splits admin fee share and updates the accumulated rewards per share.
     */
    function _addRewards(uint rewardAmount) internal {
        if (totalSupply() > 0) {
            uint adminFeeRewards = (rewardAmount * adminFeeShareBP) / BP;
            unchecked {
                rewardAmount -= adminFeeRewards;
            }
            accRewardPerShareP += (rewardAmount << P) / totalSupply();
            adminFeeAmount += adminFeeRewards;
        }
    }

    /**
     * @dev Deposits LP amount for the user, updates user reward debt and pays pending rewards.
     */
    function _depositLp(address to, uint lpAmount) internal {
        uint pending;
        uint userLpAmount = balanceOf(to); // Gas optimization
        if (userLpAmount > 0) {
            pending = ((userLpAmount * accRewardPerShareP) >> P) - userRewardDebt[to];
        }
        userLpAmount += lpAmount;
        _mint(to, lpAmount);
        userRewardDebt[to] = (userLpAmount * accRewardPerShareP) >> P;
        if (pending > 0) {
            token.safeTransfer(to, pending);
            emit RewardsClaimed(to, pending);
        }
        emit Deposit(to, lpAmount);
    }

    /**
     * @dev Withdraws LP amount for the user, updates user reward debt and pays out pending rewards.
     */
    function _withdrawLp(address from, uint lpAmount) internal {
        uint userLpAmount = balanceOf(from); // Gas optimization
        require(userLpAmount >= lpAmount, "RewardManager: not enough amount");
        uint pending;
        if (userLpAmount > 0) {
            pending = ((userLpAmount * accRewardPerShareP) >> P) - userRewardDebt[from];
        }
        userLpAmount -= lpAmount;
        _burn(from, lpAmount);
        userRewardDebt[from] = (userLpAmount * accRewardPerShareP) >> P;
        if (pending > 0) {
            token.safeTransfer(from, pending);
            emit RewardsClaimed(from, pending);
        }
        emit Withdraw(from, lpAmount);
    }

    function _transfer(address, address, uint) internal pure override {
        revert("Unsupported");
    }

    function _approve(address, address, uint) internal pure override {
        revert("Unsupported");
    }
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;

import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {IRouter} from "./interfaces/IRouter.sol";
import {MessengerProtocol} from "./interfaces/IBridge.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {Pool} from "./Pool.sol";

abstract contract Router is Ownable, IRouter {
    using SafeERC20 for ERC20;
    uint private immutable chainPrecision;
    uint internal constant ORACLE_PRECISION = 18;

    mapping(bytes32 tokenId => Pool) public pools;
    // precomputed values to divide by to change the precision from the Gas Oracle precision to the token precision
    mapping(address tokenAddress => uint scalingFactor) internal fromGasOracleScalingFactor;
    // precomputed values of the scaling factor required for paying the bridging fee with stable tokens
    mapping(address tokenAddress => uint scalingFactor) internal bridgingFeeConversionScalingFactor;

    // can restrict swap operations
    address private stopAuthority;

    /**
     * @dev The rebalancer is an account responsible for balancing the liquidity pools. It ensures that the pool is
     * balanced by executing zero-fee swaps when the pool is imbalanced.
     *
     * Gas optimization: both the 'rebalancer' and 'canSwap' fields are used in the 'swap' and 'swapAndBridge'
     * functions and can occupy the same slot.
     */
    address private rebalancer;
    uint8 public override canSwap = 1;

    /**
     * @dev Emitted during the on-chain swap of tokens.
     */
    event Swapped(
        address sender,
        address recipient,
        bytes32 sendToken,
        bytes32 receiveToken,
        uint sendAmount,
        uint receiveAmount
    );

    constructor(uint chainPrecision_) {
        chainPrecision = chainPrecision_;
        stopAuthority = owner();
    }

    /**
     * @dev Modifier to make a function callable only when the swap is allowed.
     */
    modifier whenCanSwap() {
        require(canSwap == 1, "Router: swap prohibited");
        _;
    }

    /**
     * @dev Throws if called by any account other than the stopAuthority.
     */
    modifier onlyStopAuthority() {
        require(stopAuthority == msg.sender, "Router: is not stopAuthority");
        _;
    }

    /**
     * @notice Swaps a given pair of tokens on the same blockchain.
     * @param amount The amount of tokens to be swapped.
     * @param token The token to be swapped.
     * @param receiveToken The token to receive in exchange for the swapped token.
     * @param recipient The address to receive the tokens.
     * @param receiveAmountMin The minimum amount of tokens required to receive during the swap.
     */
    function swap(
        uint amount,
        bytes32 token,
        bytes32 receiveToken,
        address recipient,
        uint receiveAmountMin
    ) external override whenCanSwap {
        uint vUsdAmount = _sendAndSwapToVUsd(token, msg.sender, amount);
        uint receivedAmount = _receiveAndSwapFromVUsd(receiveToken, recipient, vUsdAmount, receiveAmountMin);
        emit Swapped(msg.sender, recipient, token, receiveToken, amount, receivedAmount);
    }

    /**
     * @notice Allows the admin to add new supported liquidity pools.
     * @dev Adds the address of the `Pool` contract to the list of supported liquidity pools.
     * @param pool The address of the `Pool` contract.
     * @param token The address of the token in the liquidity pool.
     */
    function addPool(Pool pool, bytes32 token) external onlyOwner {
        pools[token] = pool;
        address tokenAddress = address(uint160(uint(token)));
        uint tokenDecimals = ERC20(tokenAddress).decimals();
        bridgingFeeConversionScalingFactor[tokenAddress] = 10 ** (ORACLE_PRECISION - tokenDecimals + chainPrecision);
        fromGasOracleScalingFactor[tokenAddress] = 10 ** (ORACLE_PRECISION - tokenDecimals);
    }

    /**
     * @dev Switches off the possibility to make swaps.
     */
    function stopSwap() external onlyStopAuthority {
        canSwap = 0;
    }

    /**
     * @dev Switches on the possibility to make swaps.
     */
    function startSwap() external onlyOwner {
        canSwap = 1;
    }

    /**
     * @dev Allows the admin to set the address of the stopAuthority.
     */
    function setStopAuthority(address stopAuthority_) external onlyOwner {
        stopAuthority = stopAuthority_;
    }

    /**
     * @dev Allows the admin to set the address of the rebalancer.
     */
    function setRebalancer(address rebalancer_) external onlyOwner {
        rebalancer = rebalancer_;
    }

    function _receiveAndSwapFromVUsd(
        bytes32 token,
        address recipient,
        uint vUsdAmount,
        uint receiveAmountMin
    ) internal returns (uint) {
        Pool tokenPool = pools[token];
        require(address(tokenPool) != address(0), "Router: no receive pool");
        return tokenPool.swapFromVUsd(recipient, vUsdAmount, receiveAmountMin, recipient == rebalancer);
    }

    function _sendAndSwapToVUsd(bytes32 token, address user, uint amount) internal virtual returns (uint) {
        Pool pool = pools[token];
        require(address(pool) != address(0), "Router: no pool");
        ERC20(address(uint160(uint(token)))).safeTransferFrom(user, address(pool), amount);
        return pool.swapToVUsd(user, amount, user == rebalancer);
    }
}

File 48 of 58 : Console.sol
// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;

library console {
    address constant CONSOLE_ADDRESS = address(0x000000000000000000636F6e736F6c652e6c6f67);

    function _sendLogPayload(bytes memory payload) private view {
        uint payloadLength = payload.length;
        address consoleAddress = CONSOLE_ADDRESS;
        assembly {
            let payloadStart := add(payload, 32)
            let r := staticcall(gas(), consoleAddress, payloadStart, payloadLength, 0, 0)
        }
    }

    function log() internal view {
        _sendLogPayload(abi.encodeWithSignature("log()"));
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    function log(uint p0) internal view {
        _sendLogPayload(abi.encodeWithSignature("log(uint)", p0));
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    function log(uint p0, uint p1, uint p2, uint p3) internal view {
        _sendLogPayload(abi.encodeWithSignature("log(uint,uint,uint,uint)", p0, p1, p2, p3));
    }

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

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

    function log(uint p0, uint p1, uint p2, address p3) internal view {
        _sendLogPayload(abi.encodeWithSignature("log(uint,uint,uint,address)", p0, p1, p2, p3));
    }

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

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

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

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

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

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

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

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

    function log(uint p0, uint p1, address p2, uint p3) internal view {
        _sendLogPayload(abi.encodeWithSignature("log(uint,uint,address,uint)", p0, p1, p2, p3));
    }

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

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

    function log(uint p0, uint p1, address p2, address p3) internal view {
        _sendLogPayload(abi.encodeWithSignature("log(uint,uint,address,address)", p0, p1, p2, p3));
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    function log(uint p0, address p1, uint p2, uint p3) internal view {
        _sendLogPayload(abi.encodeWithSignature("log(uint,address,uint,uint)", p0, p1, p2, p3));
    }

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

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

    function log(uint p0, address p1, uint p2, address p3) internal view {
        _sendLogPayload(abi.encodeWithSignature("log(uint,address,uint,address)", p0, p1, p2, p3));
    }

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

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

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

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

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

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

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

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

    function log(uint p0, address p1, address p2, uint p3) internal view {
        _sendLogPayload(abi.encodeWithSignature("log(uint,address,address,uint)", p0, p1, p2, p3));
    }

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

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

    function log(uint p0, address p1, address p2, address p3) internal view {
        _sendLogPayload(abi.encodeWithSignature("log(uint,address,address,address)", p0, p1, p2, p3));
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    function log(string memory p0, string memory p1, string memory p2, string memory p3) internal view {
        _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 view {
        _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 view {
        _sendLogPayload(abi.encodeWithSignature("log(string,string,string,address)", p0, p1, p2, p3));
    }

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

    function log(string memory p0, string memory p1, bool p2, string memory p3) internal view {
        _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 view {
        _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 view {
        _sendLogPayload(abi.encodeWithSignature("log(string,string,bool,address)", p0, p1, p2, p3));
    }

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

    function log(string memory p0, string memory p1, address p2, string memory p3) internal view {
        _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 view {
        _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 view {
        _sendLogPayload(abi.encodeWithSignature("log(string,string,address,address)", p0, p1, p2, p3));
    }

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

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

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

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

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

    function log(string memory p0, bool p1, string memory p2, string memory p3) internal view {
        _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 view {
        _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 view {
        _sendLogPayload(abi.encodeWithSignature("log(string,bool,string,address)", p0, p1, p2, p3));
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

    function log(string memory p0, address p1, string memory p2, string memory p3) internal view {
        _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 view {
        _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 view {
        _sendLogPayload(abi.encodeWithSignature("log(string,address,string,address)", p0, p1, p2, p3));
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    function log(bool p0, string memory p1, string memory p2, string memory p3) internal view {
        _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 view {
        _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 view {
        _sendLogPayload(abi.encodeWithSignature("log(bool,string,string,address)", p0, p1, p2, p3));
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    function log(address p0, uint p1, uint p2, uint p3) internal view {
        _sendLogPayload(abi.encodeWithSignature("log(address,uint,uint,uint)", p0, p1, p2, p3));
    }

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

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

    function log(address p0, uint p1, uint p2, address p3) internal view {
        _sendLogPayload(abi.encodeWithSignature("log(address,uint,uint,address)", p0, p1, p2, p3));
    }

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

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

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

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

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

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

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

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

    function log(address p0, uint p1, address p2, uint p3) internal view {
        _sendLogPayload(abi.encodeWithSignature("log(address,uint,address,uint)", p0, p1, p2, p3));
    }

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

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

    function log(address p0, uint p1, address p2, address p3) internal view {
        _sendLogPayload(abi.encodeWithSignature("log(address,uint,address,address)", p0, p1, p2, p3));
    }

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

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

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

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

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

    function log(address p0, string memory p1, string memory p2, string memory p3) internal view {
        _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 view {
        _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 view {
        _sendLogPayload(abi.encodeWithSignature("log(address,string,string,address)", p0, p1, p2, p3));
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    function log(address p0, address p1, uint p2, uint p3) internal view {
        _sendLogPayload(abi.encodeWithSignature("log(address,address,uint,uint)", p0, p1, p2, p3));
    }

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

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

    function log(address p0, address p1, uint p2, address p3) internal view {
        _sendLogPayload(abi.encodeWithSignature("log(address,address,uint,address)", p0, p1, p2, p3));
    }

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

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

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

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

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

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

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

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

    function log(address p0, address p1, address p2, uint p3) internal view {
        _sendLogPayload(abi.encodeWithSignature("log(address,address,address,uint)", p0, p1, p2, p3));
    }

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

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

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

// SPDX-License-Identifier: MIT
contract MockERC20 {
    string public name;
    string public symbol;
    uint8 public decimals;
    uint public totalSupply;
    mapping(address => uint) public balanceOf;
    mapping(address => mapping(address => uint)) public allowance;

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

    function mint(address to, uint amount) external {
        balanceOf[to] += amount;
        totalSupply += amount;
    }

    function approve(address spender, uint amount) external returns (bool) {
        allowance[msg.sender][spender] = amount;
        return true;
    }

    function transfer(address to, uint amount) external returns (bool) {
        require(balanceOf[msg.sender] >= amount, "Insufficient balance");
        balanceOf[msg.sender] -= amount;
        balanceOf[to] += amount;
        return true;
    }

    function transferFrom(address from, address to, uint amount) external returns (bool) {
        require(balanceOf[from] >= amount, "Insufficient balance");
        require(allowance[from][msg.sender] >= amount, "Insufficient allowance");
        balanceOf[from] -= amount;
        balanceOf[to] += amount;
        allowance[from][msg.sender] -= amount;
        return true;
    }
}

// SPDX-License-Identifier: MIT
contract MockGasOracle {
    mapping(uint => uint) public prices;

    function price(uint chainId) external view returns (uint) {
        return prices[chainId];
    }

    function setPrice(uint chainId, uint _price) external {
        prices[chainId] = _price;
    }
}

import {UlnOptions} from "@layerzerolabs/lz-evm-messagelib-v2/contracts/uln/libs/UlnOptions.sol";
import {ExecutorOptions} from "@layerzerolabs/lz-evm-messagelib-v2/contracts/libs/ExecutorOptions.sol";
import {MockERC20} from "./MockERC20.sol";
import {SendParam, MessagingFee, MessagingReceipt, OFTReceipt} from "@layerzerolabs/oft-evm/contracts/interfaces/IOFT.sol";

// SPDX-License-Identifier: MIT
contract MockOFT {
    using ExecutorOptions for bytes;
    address public token;
    uint public defaultNativeFee = 10000000000000000;

    constructor(address _token) {
        token = _token;
    }

    function setDefaultNativeFee(uint fee) external {
        defaultNativeFee = fee;
    }

    function quoteSend(SendParam calldata sendParam, bool payInLzToken) external view returns (MessagingFee memory) {
        // Calculate fee based on options - in real implementation this would parse the options 
        uint fee = defaultNativeFee;
        bytes calldata _options = sendParam.extraOptions[2:];

        uint256 cursor = 0;
        while (cursor < _options.length) {
            (uint8 optionType, bytes calldata option, uint256 newCursor) = _options.nextExecutorOption(cursor);
            cursor = newCursor;
            if (optionType == ExecutorOptions.OPTION_TYPE_NATIVE_DROP) {
                (uint128 nativeDropAmount, ) = ExecutorOptions.decodeNativeDropOption(option);
                fee += nativeDropAmount;
            }
        }

        return MessagingFee({
            nativeFee: fee,
            lzTokenFee: 0
        });
    }

    function send(
        SendParam calldata sendParam,
        MessagingFee calldata fee,
        address refundAddress
    ) external payable returns (MessagingReceipt memory, OFTReceipt memory) {
        require(msg.value >= fee.nativeFee, "Not enough native token for fee");

        // Simulate the token transfer
        MockERC20(token).transferFrom(msg.sender, address(this), sendParam.amountLD);
        return (MessagingReceipt(bytes32(0), 0, MessagingFee(0, 0)), OFTReceipt(0, 0));
    }
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;

import {IBridge, MessengerProtocol} from "../interfaces/IBridge.sol";
import {Router} from "../Router.sol";

contract TestBridgeForSwap is IBridge, Router {
    uint public chainId;
    mapping(bytes32 messageHash => uint isProcessed) public override processedMessages;
    mapping(bytes32 messageHash => uint isSent) public override sentMessages;
    // Info about bridges on other chains
    mapping(uint chainId => bytes32 bridgeAddress) public override otherBridges;
    // Info about tokens on other chains
    mapping(uint chainId => mapping(bytes32 tokenAddress => bool isSupported)) public override otherBridgeTokens;

    event vUsdSent(uint amount);

    constructor() Router(18) {}

    function swapAndBridge(
        bytes32 token,
        uint amount,
        bytes32 recipient,
        uint destinationChainId,
        bytes32 receiveToken,
        uint nonce,
        MessengerProtocol messenger,
        uint feeTokenAmount
    ) external payable override {}

    function receiveTokens(
        uint amount,
        bytes32,
        uint,
        bytes32 receiveToken,
        uint,
        MessengerProtocol,
        uint receiveAmountMin
    ) external payable override {}

    function withdrawGasTokens(uint amount) external override onlyOwner {}

    function registerBridge(uint chainId_, bytes32 bridgeAddress_) external override onlyOwner {}

    function addBridgeToken(uint chainId_, bytes32 tokenAddress_) external override onlyOwner {}

    function removeBridgeToken(uint chainId_, bytes32 tokenAddress_) external override onlyOwner {}

    function getBridgingCostInTokens(uint, MessengerProtocol, address) external pure override returns (uint) {
        return 0;
    }

    function hashMessage(
        uint,
        bytes32,
        uint,
        uint,
        bytes32,
        uint,
        MessengerProtocol
    ) external pure override returns (bytes32) {
        return 0;
    }

    function _sendAndSwapToVUsd(bytes32 token, address user, uint amount) internal override returns (uint) {
        uint vUsdAmount = super._sendAndSwapToVUsd(token, user, amount);
        emit vUsdSent(vUsdAmount);
        return vUsdAmount;
    }
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;

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

contract TestMessenger is IMessenger {
    bool public isHasMessage = false;

    event Sent();

    function sentMessagesBlock(bytes32) external view override returns (uint) {
        return isHasMessage ? 1 : 0;
    }

    function receivedMessages(bytes32) external view override returns (uint) {
        return isHasMessage ? 1 : 0;
    }

    function sendMessage(bytes32) external payable override {
        emit Sent();
    }

    function receiveMessage(
        bytes32 message,
        uint v1v2,
        bytes32 r1,
        bytes32 s1,
        bytes32 r2,
        bytes32 s2
    ) external override {
        // Do nothing
    }

    function getTransactionCost(uint) external pure returns (uint) {
        return 1000;
    }

    function setIsHasMessage(bool isHasMessage_) external {
        isHasMessage = isHasMessage_;
    }
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;

import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {Pool} from "../Pool.sol";
import {RewardManager} from "../RewardManager.sol";

contract TestPool is Pool {
    constructor(
        address router_,
        uint a_,
        ERC20 token_,
        uint16 feeShareBP_,
        uint balanceRatioMinBP_
    ) Pool(router_, a_, token_, feeShareBP_, balanceRatioMinBP_, "LP", "LP") {}

    function setVUsdBalance(uint vUsdBalance_) public {
        vUsdBalance = vUsdBalance_;
    }

    function setTokenBalance(uint tokenBalance_) public {
        tokenBalance = tokenBalance_;
    }
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;

import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {RewardManager} from "../RewardManager.sol";

contract TestPoolForRewards is RewardManager {
    // solhint-disable-next-line no-empty-blocks
    constructor(ERC20 token) RewardManager(token, "LP", "LP") {}

    function deposit(uint amount) external {
        _depositLp(msg.sender, amount);
    }

    function withdraw(uint amount) external {
        _withdrawLp(msg.sender, amount);
    }

    function addRewards(uint amount) external {
        _addRewards(amount);
    }
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;

import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract Token is ERC20 {
    uint8 internal _decimals;

    constructor(string memory _name, string memory _symbol, uint _amount, uint8 __decimals) ERC20(_name, _symbol) {
        _mint(msg.sender, _amount);
        _decimals = __decimals;
    }

    function decimals() public view virtual override returns (uint8) {
        return _decimals;
    }
}

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;

import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {IGasOracle} from "./interfaces/IGasOracle.sol";
import {IMessenger} from "./interfaces/IMessenger.sol";
import {IWormhole} from "./interfaces/IWormhole.sol";
import {GasUsage} from "./GasUsage.sol";
import {GasOracle} from "./GasOracle.sol";
import {HashUtils} from "./libraries/HashUtils.sol";

contract WormholeMessenger is Ownable, GasUsage {
    using HashUtils for bytes32;

    IWormhole private immutable wormhole;
    uint public immutable chainId;
    bytes32 public otherChainIds;

    uint32 private nonce;
    uint8 private commitmentLevel;

    mapping(uint16 chainId => bytes32 wormholeMessengerAddress) private otherWormholeMessengers;

    mapping(bytes32 messageHash => uint isReceived) public receivedMessages;
    mapping(bytes32 messageHash => uint isSent) public sentMessages;

    event MessageSent(bytes32 indexed message, uint64 sequence);
    event MessageReceived(bytes32 indexed message, uint64 sequence);
    event Received(address, uint);

    constructor(
        uint chainId_,
        bytes32 otherChainIds_,
        IWormhole wormhole_,
        uint8 commitmentLevel_,
        IGasOracle gasOracle_
    ) GasUsage(gasOracle_) {
        chainId = chainId_;
        otherChainIds = otherChainIds_;
        wormhole = wormhole_;
        commitmentLevel = commitmentLevel_;
    }

    function sendMessage(bytes32 message) external payable {
        require(uint8(message[0]) == chainId, "WormholeMessenger: wrong chainId");
        require(otherChainIds[uint8(message[1])] != 0, "Messenger: wrong destination");
        bytes32 messageWithSender = message.hashWithSenderAddress(msg.sender);

        uint32 nonce_ = nonce;

        uint256 wormholeFee = wormhole.messageFee();
        uint64 sequence = wormhole.publishMessage{value: wormholeFee}(
            nonce_,
            abi.encodePacked(messageWithSender),
            commitmentLevel
        );

        unchecked {
            nonce = nonce_ + 1;
        }

        require(sentMessages[messageWithSender] == 0, "WormholeMessenger: has message");
        sentMessages[messageWithSender] = 1;

        emit MessageSent(messageWithSender, sequence);
    }

    function receiveMessage(bytes memory encodedMsg) external {
        (IWormhole.VM memory vm, bool valid, string memory reason) = wormhole.parseAndVerifyVM(encodedMsg);

        require(valid, reason);
        require(vm.payload.length == 32, "WormholeMessenger: wrong length");

        bytes32 messageWithSender = bytes32(vm.payload);
        require(uint8(messageWithSender[1]) == chainId, "WormholeMessenger: wrong chainId");

        require(otherWormholeMessengers[vm.emitterChainId] == vm.emitterAddress, "WormholeMessenger: wrong emitter");

        receivedMessages[messageWithSender] = 1;

        emit MessageReceived(messageWithSender, vm.sequence);
    }

    function setCommitmentLevel(uint8 value) external onlyOwner {
        commitmentLevel = value;
    }

    function setOtherChainIds(bytes32 value) external onlyOwner {
        otherChainIds = value;
    }

    function registerWormholeMessenger(uint16 chainId_, bytes32 address_) external onlyOwner {
        otherWormholeMessengers[chainId_] = address_;
    }

    function withdrawGasTokens(uint amount) external onlyOwner {
        payable(msg.sender).transfer(amount);
    }

    fallback() external payable {
        revert("Unsupported");
    }

    receive() external payable {
        emit Received(msg.sender, msg.value);
    }
}

// SPDX-License-Identifier: Unlicense
/*
 * @title Solidity Bytes Arrays Utils
 * @author Gonçalo Sá <[email protected]>
 *
 * @dev Bytes tightly packed arrays utility library for ethereum contracts written in Solidity.
 *      The library lets you concatenate, slice and type cast bytes arrays both in memory and storage.
 */
pragma solidity >=0.8.0 <0.9.0;


library BytesLib {
    function concat(
        bytes memory _preBytes,
        bytes memory _postBytes
    )
        internal
        pure
        returns (bytes memory)
    {
        bytes memory tempBytes;

        assembly {
            // Get a location of some free memory and store it in tempBytes as
            // Solidity does for memory variables.
            tempBytes := mload(0x40)

            // Store the length of the first bytes array at the beginning of
            // the memory for tempBytes.
            let length := mload(_preBytes)
            mstore(tempBytes, length)

            // Maintain a memory counter for the current write location in the
            // temp bytes array by adding the 32 bytes for the array length to
            // the starting location.
            let mc := add(tempBytes, 0x20)
            // Stop copying when the memory counter reaches the length of the
            // first bytes array.
            let end := add(mc, length)

            for {
                // Initialize a copy counter to the start of the _preBytes data,
                // 32 bytes into its memory.
                let cc := add(_preBytes, 0x20)
            } lt(mc, end) {
                // Increase both counters by 32 bytes each iteration.
                mc := add(mc, 0x20)
                cc := add(cc, 0x20)
            } {
                // Write the _preBytes data into the tempBytes memory 32 bytes
                // at a time.
                mstore(mc, mload(cc))
            }

            // Add the length of _postBytes to the current length of tempBytes
            // and store it as the new length in the first 32 bytes of the
            // tempBytes memory.
            length := mload(_postBytes)
            mstore(tempBytes, add(length, mload(tempBytes)))

            // Move the memory counter back from a multiple of 0x20 to the
            // actual end of the _preBytes data.
            mc := end
            // Stop copying when the memory counter reaches the new combined
            // length of the arrays.
            end := add(mc, length)

            for {
                let cc := add(_postBytes, 0x20)
            } lt(mc, end) {
                mc := add(mc, 0x20)
                cc := add(cc, 0x20)
            } {
                mstore(mc, mload(cc))
            }

            // Update the free-memory pointer by padding our last write location
            // to 32 bytes: add 31 bytes to the end of tempBytes to move to the
            // next 32 byte block, then round down to the nearest multiple of
            // 32. If the sum of the length of the two arrays is zero then add
            // one before rounding down to leave a blank 32 bytes (the length block with 0).
            mstore(0x40, and(
              add(add(end, iszero(add(length, mload(_preBytes)))), 31),
              not(31) // Round down to the nearest 32 bytes.
            ))
        }

        return tempBytes;
    }

    function concatStorage(bytes storage _preBytes, bytes memory _postBytes) internal {
        assembly {
            // Read the first 32 bytes of _preBytes storage, which is the length
            // of the array. (We don't need to use the offset into the slot
            // because arrays use the entire slot.)
            let fslot := sload(_preBytes.slot)
            // Arrays of 31 bytes or less have an even value in their slot,
            // while longer arrays have an odd value. The actual length is
            // the slot divided by two for odd values, and the lowest order
            // byte divided by two for even values.
            // If the slot is even, bitwise and the slot with 255 and divide by
            // two to get the length. If the slot is odd, bitwise and the slot
            // with -1 and divide by two.
            let slength := div(and(fslot, sub(mul(0x100, iszero(and(fslot, 1))), 1)), 2)
            let mlength := mload(_postBytes)
            let newlength := add(slength, mlength)
            // slength can contain both the length and contents of the array
            // if length < 32 bytes so let's prepare for that
            // v. http://solidity.readthedocs.io/en/latest/miscellaneous.html#layout-of-state-variables-in-storage
            switch add(lt(slength, 32), lt(newlength, 32))
            case 2 {
                // Since the new array still fits in the slot, we just need to
                // update the contents of the slot.
                // uint256(bytes_storage) = uint256(bytes_storage) + uint256(bytes_memory) + new_length
                sstore(
                    _preBytes.slot,
                    // all the modifications to the slot are inside this
                    // next block
                    add(
                        // we can just add to the slot contents because the
                        // bytes we want to change are the LSBs
                        fslot,
                        add(
                            mul(
                                div(
                                    // load the bytes from memory
                                    mload(add(_postBytes, 0x20)),
                                    // zero all bytes to the right
                                    exp(0x100, sub(32, mlength))
                                ),
                                // and now shift left the number of bytes to
                                // leave space for the length in the slot
                                exp(0x100, sub(32, newlength))
                            ),
                            // increase length by the double of the memory
                            // bytes length
                            mul(mlength, 2)
                        )
                    )
                )
            }
            case 1 {
                // The stored value fits in the slot, but the combined value
                // will exceed it.
                // get the keccak hash to get the contents of the array
                mstore(0x0, _preBytes.slot)
                let sc := add(keccak256(0x0, 0x20), div(slength, 32))

                // save new length
                sstore(_preBytes.slot, add(mul(newlength, 2), 1))

                // The contents of the _postBytes array start 32 bytes into
                // the structure. Our first read should obtain the `submod`
                // bytes that can fit into the unused space in the last word
                // of the stored array. To get this, we read 32 bytes starting
                // from `submod`, so the data we read overlaps with the array
                // contents by `submod` bytes. Masking the lowest-order
                // `submod` bytes allows us to add that value directly to the
                // stored value.

                let submod := sub(32, slength)
                let mc := add(_postBytes, submod)
                let end := add(_postBytes, mlength)
                let mask := sub(exp(0x100, submod), 1)

                sstore(
                    sc,
                    add(
                        and(
                            fslot,
                            0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00
                        ),
                        and(mload(mc), mask)
                    )
                )

                for {
                    mc := add(mc, 0x20)
                    sc := add(sc, 1)
                } lt(mc, end) {
                    sc := add(sc, 1)
                    mc := add(mc, 0x20)
                } {
                    sstore(sc, mload(mc))
                }

                mask := exp(0x100, sub(mc, end))

                sstore(sc, mul(div(mload(mc), mask), mask))
            }
            default {
                // get the keccak hash to get the contents of the array
                mstore(0x0, _preBytes.slot)
                // Start copying to the last used word of the stored array.
                let sc := add(keccak256(0x0, 0x20), div(slength, 32))

                // save new length
                sstore(_preBytes.slot, add(mul(newlength, 2), 1))

                // Copy over the first `submod` bytes of the new data as in
                // case 1 above.
                let slengthmod := mod(slength, 32)
                let mlengthmod := mod(mlength, 32)
                let submod := sub(32, slengthmod)
                let mc := add(_postBytes, submod)
                let end := add(_postBytes, mlength)
                let mask := sub(exp(0x100, submod), 1)

                sstore(sc, add(sload(sc), and(mload(mc), mask)))

                for {
                    sc := add(sc, 1)
                    mc := add(mc, 0x20)
                } lt(mc, end) {
                    sc := add(sc, 1)
                    mc := add(mc, 0x20)
                } {
                    sstore(sc, mload(mc))
                }

                mask := exp(0x100, sub(mc, end))

                sstore(sc, mul(div(mload(mc), mask), mask))
            }
        }
    }

    function slice(
        bytes memory _bytes,
        uint256 _start,
        uint256 _length
    )
        internal
        pure
        returns (bytes memory)
    {
        require(_length + 31 >= _length, "slice_overflow");
        require(_bytes.length >= _start + _length, "slice_outOfBounds");

        bytes memory tempBytes;

        assembly {
            switch iszero(_length)
            case 0 {
                // Get a location of some free memory and store it in tempBytes as
                // Solidity does for memory variables.
                tempBytes := mload(0x40)

                // The first word of the slice result is potentially a partial
                // word read from the original array. To read it, we calculate
                // the length of that partial word and start copying that many
                // bytes into the array. The first word we copy will start with
                // data we don't care about, but the last `lengthmod` bytes will
                // land at the beginning of the contents of the new array. When
                // we're done copying, we overwrite the full first word with
                // the actual length of the slice.
                let lengthmod := and(_length, 31)

                // The multiplication in the next line is necessary
                // because when slicing multiples of 32 bytes (lengthmod == 0)
                // the following copy loop was copying the origin's length
                // and then ending prematurely not copying everything it should.
                let mc := add(add(tempBytes, lengthmod), mul(0x20, iszero(lengthmod)))
                let end := add(mc, _length)

                for {
                    // The multiplication in the next line has the same exact purpose
                    // as the one above.
                    let cc := add(add(add(_bytes, lengthmod), mul(0x20, iszero(lengthmod))), _start)
                } lt(mc, end) {
                    mc := add(mc, 0x20)
                    cc := add(cc, 0x20)
                } {
                    mstore(mc, mload(cc))
                }

                mstore(tempBytes, _length)

                //update free-memory pointer
                //allocating the array padded to 32 bytes like the compiler does now
                mstore(0x40, and(add(mc, 31), not(31)))
            }
            //if we want a zero-length slice let's just return a zero-length array
            default {
                tempBytes := mload(0x40)
                //zero out the 32 bytes slice we are about to return
                //we need to do it because Solidity does not garbage collect
                mstore(tempBytes, 0)

                mstore(0x40, add(tempBytes, 0x20))
            }
        }

        return tempBytes;
    }

    function toAddress(bytes memory _bytes, uint256 _start) internal pure returns (address) {
        require(_bytes.length >= _start + 20, "toAddress_outOfBounds");
        address tempAddress;

        assembly {
            tempAddress := div(mload(add(add(_bytes, 0x20), _start)), 0x1000000000000000000000000)
        }

        return tempAddress;
    }

    function toUint8(bytes memory _bytes, uint256 _start) internal pure returns (uint8) {
        require(_bytes.length >= _start + 1 , "toUint8_outOfBounds");
        uint8 tempUint;

        assembly {
            tempUint := mload(add(add(_bytes, 0x1), _start))
        }

        return tempUint;
    }

    function toUint16(bytes memory _bytes, uint256 _start) internal pure returns (uint16) {
        require(_bytes.length >= _start + 2, "toUint16_outOfBounds");
        uint16 tempUint;

        assembly {
            tempUint := mload(add(add(_bytes, 0x2), _start))
        }

        return tempUint;
    }

    function toUint32(bytes memory _bytes, uint256 _start) internal pure returns (uint32) {
        require(_bytes.length >= _start + 4, "toUint32_outOfBounds");
        uint32 tempUint;

        assembly {
            tempUint := mload(add(add(_bytes, 0x4), _start))
        }

        return tempUint;
    }

    function toUint64(bytes memory _bytes, uint256 _start) internal pure returns (uint64) {
        require(_bytes.length >= _start + 8, "toUint64_outOfBounds");
        uint64 tempUint;

        assembly {
            tempUint := mload(add(add(_bytes, 0x8), _start))
        }

        return tempUint;
    }

    function toUint96(bytes memory _bytes, uint256 _start) internal pure returns (uint96) {
        require(_bytes.length >= _start + 12, "toUint96_outOfBounds");
        uint96 tempUint;

        assembly {
            tempUint := mload(add(add(_bytes, 0xc), _start))
        }

        return tempUint;
    }

    function toUint128(bytes memory _bytes, uint256 _start) internal pure returns (uint128) {
        require(_bytes.length >= _start + 16, "toUint128_outOfBounds");
        uint128 tempUint;

        assembly {
            tempUint := mload(add(add(_bytes, 0x10), _start))
        }

        return tempUint;
    }

    function toUint256(bytes memory _bytes, uint256 _start) internal pure returns (uint256) {
        require(_bytes.length >= _start + 32, "toUint256_outOfBounds");
        uint256 tempUint;

        assembly {
            tempUint := mload(add(add(_bytes, 0x20), _start))
        }

        return tempUint;
    }

    function toBytes32(bytes memory _bytes, uint256 _start) internal pure returns (bytes32) {
        require(_bytes.length >= _start + 32, "toBytes32_outOfBounds");
        bytes32 tempBytes32;

        assembly {
            tempBytes32 := mload(add(add(_bytes, 0x20), _start))
        }

        return tempBytes32;
    }

    function equal(bytes memory _preBytes, bytes memory _postBytes) internal pure returns (bool) {
        bool success = true;

        assembly {
            let length := mload(_preBytes)

            // if lengths don't match the arrays are not equal
            switch eq(length, mload(_postBytes))
            case 1 {
                // cb is a circuit breaker in the for loop since there's
                //  no said feature for inline assembly loops
                // cb = 1 - don't breaker
                // cb = 0 - break
                let cb := 1

                let mc := add(_preBytes, 0x20)
                let end := add(mc, length)

                for {
                    let cc := add(_postBytes, 0x20)
                // the next line is the loop condition:
                // while(uint256(mc < end) + cb == 2)
                } eq(add(lt(mc, end), cb), 2) {
                    mc := add(mc, 0x20)
                    cc := add(cc, 0x20)
                } {
                    // if any of these checks fails then arrays are not equal
                    if iszero(eq(mload(mc), mload(cc))) {
                        // unsuccess:
                        success := 0
                        cb := 0
                    }
                }
            }
            default {
                // unsuccess:
                success := 0
            }
        }

        return success;
    }

    function equalStorage(
        bytes storage _preBytes,
        bytes memory _postBytes
    )
        internal
        view
        returns (bool)
    {
        bool success = true;

        assembly {
            // we know _preBytes_offset is 0
            let fslot := sload(_preBytes.slot)
            // Decode the length of the stored array like in concatStorage().
            let slength := div(and(fslot, sub(mul(0x100, iszero(and(fslot, 1))), 1)), 2)
            let mlength := mload(_postBytes)

            // if lengths don't match the arrays are not equal
            switch eq(slength, mlength)
            case 1 {
                // slength can contain both the length and contents of the array
                // if length < 32 bytes so let's prepare for that
                // v. http://solidity.readthedocs.io/en/latest/miscellaneous.html#layout-of-state-variables-in-storage
                if iszero(iszero(slength)) {
                    switch lt(slength, 32)
                    case 1 {
                        // blank the last byte which is the length
                        fslot := mul(div(fslot, 0x100), 0x100)

                        if iszero(eq(fslot, mload(add(_postBytes, 0x20)))) {
                            // unsuccess:
                            success := 0
                        }
                    }
                    default {
                        // cb is a circuit breaker in the for loop since there's
                        //  no said feature for inline assembly loops
                        // cb = 1 - don't breaker
                        // cb = 0 - break
                        let cb := 1

                        // get the keccak hash to get the contents of the array
                        mstore(0x0, _preBytes.slot)
                        let sc := keccak256(0x0, 0x20)

                        let mc := add(_postBytes, 0x20)
                        let end := add(mc, mlength)

                        // the next line is the loop condition:
                        // while(uint256(mc < end) + cb == 2)
                        for {} eq(add(lt(mc, end), cb), 2) {
                            sc := add(sc, 1)
                            mc := add(mc, 0x20)
                        } {
                            if iszero(eq(sload(sc), mload(mc))) {
                                // unsuccess:
                                success := 0
                                cb := 0
                            }
                        }
                    }
                }
            }
            default {
                // unsuccess:
                success := 0
            }
        }

        return success;
    }
}

Settings
{
  "viaIR": true,
  "optimizer": {
    "enabled": true,
    "runs": 1000,
    "details": {
      "yulDetails": {
        "optimizerSteps": "u"
      }
    }
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "abi"
      ]
    }
  }
}

Contract Security Audit

Contract ABI

API
[{"inputs":[{"internalType":"address","name":"router_","type":"address"},{"internalType":"uint256","name":"a_","type":"uint256"},{"internalType":"contract ERC20","name":"token_","type":"address"},{"internalType":"uint16","name":"feeShareBP_","type":"uint16"},{"internalType":"uint256","name":"balanceRatioMinBP_","type":"uint256"},{"internalType":"string","name":"lpName","type":"string"},{"internalType":"string","name":"lpSymbol","type":"string"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Deposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"RewardsClaimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"recipient","type":"address"},{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"vUsdAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"fee","type":"uint256"}],"name":"SwappedFromVUsd","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"vUsdAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"fee","type":"uint256"}],"name":"SwappedToVUsd","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Withdraw","type":"event"},{"stateMutability":"payable","type":"fallback"},{"inputs":[],"name":"a","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"accRewardPerShareP","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"adjustTotalLpAmount","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"adminFeeAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"adminFeeShareBP","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"spender","type":"address"}],"name":"allowance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"balanceRatioMinBP","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"canDeposit","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"canWithdraw","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"claimAdminFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"claimRewards","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"d","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"subtractedValue","type":"uint256"}],"name":"decreaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"deposit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"feeShareBP","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getPrice","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"x","type":"uint256"}],"name":"getY","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"spender","type":"address"},{"internalType":"uint256","name":"addedValue","type":"uint256"}],"name":"increaseAllowance","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"pendingReward","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"reserves","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"router","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"adminFeeShareBP_","type":"uint256"}],"name":"setAdminFeeShare","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"balanceRatioMinBP_","type":"uint256"}],"name":"setBalanceRatioMinBP","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint16","name":"feeShareBP_","type":"uint16"}],"name":"setFeeShare","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"router_","type":"address"}],"name":"setRouter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"stopAuthority_","type":"address"}],"name":"setStopAuthority","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"startDeposit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"startWithdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"stopDeposit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"stopWithdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"receiveAmountMin","type":"uint256"},{"internalType":"bool","name":"zeroFee","type":"bool"}],"name":"swapFromVUsd","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bool","name":"zeroFee","type":"bool"}],"name":"swapToVUsd","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"token","outputs":[{"internalType":"contract ERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tokenBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"userRewardDebt","outputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"vUsdBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amountLp","type":"uint256"}],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]

0x61010060405234620000be576200002662000019620002c3565b959490949391936200048a565b604051613449620008c58239608051818181610b94015281816112b401528181611a3d01528181611d7301528181611fc6015281816120e901528181612d2a01528181612e5201528181612fe2015261323f015260a051818181610450015281816124eb015281816126be0152612926015260c0518181816129f10152612a6c015260e051818181612a320152612aad015261344990f35b5f80fd5b634e487b7160e01b5f52604160045260245ffd5b90601f01601f191681019081106001600160401b03821117620000f857604052565b620000c2565b90620001156200010d60405190565b9283620000d6565b565b6001600160a01b031690565b90565b6001600160a01b0381165b03620000be57565b90505190620001158262000126565b8062000131565b90505190620001158262000148565b6001600160a01b03811662000131565b9050519062000115826200015e565b61ffff811662000131565b9050519062000115826200017d565b6001600160401b038111620000f857602090601f01601f19160190565b5f5b838110620001c65750505f910152565b8181015183820152602001620001b6565b90929192620001f0620001ea8262000197565b620000fe565b93818552602085019082840111620000be576200011592620001b4565b9080601f83011215620000be5781516200012392602001620001d7565b9160e083830312620000be5762000242828462000139565b926200025283602083016200014f565b92604062000263828285016200016e565b9362000273836060860162000188565b936200028384608083016200014f565b9360a0820151600180861b038111620000be5781620002a49184016200020d565b9360018060c0850151921b038111620000be576200012392016200020d565b620002e662003d0e80380380620002da81620000fe565b9283398101906200022a565b90919293949596565b905f19905b9181191691161790565b6200012362000123620001239290565b9062000322620001236200032a92620002fe565b8254620002ef565b9055565b9062010000600160b01b039060101b620002f4565b620001239062000117906001600160a01b031682565b620001239062000343565b620001239062000359565b9062000383620001236200032a9262000364565b82546200032e565b906001600160a01b0390620002f4565b90620003af620001236200032a9262000364565b82546200038b565b9061ffff90620002f4565b620003d662000123620001239261ffff1690565b61ffff1690565b90620003f1620001236200032a92620003c2565b8254620003b7565b60ff811662000131565b905051906200011582620003f9565b90602082820312620000be57620001239162000403565b6040513d5f823e3d90fd5b6200012362000123620001239260ff1690565b620001236003620002fe565b634e487b7160e01b5f52601160045260245ffd5b919082039182116200047557565b62000453565b604d81116200047557600a0a90565b620005069293620004d8620004fe926200050c9794620004b2620005259b60209b8a62000623565b620004cd6001620004c58160116200030e565b60126200030e565b60a052600a6200036f565b620004f6620004ee5f546001600160a01b031690565b60106200039b565b600a620003dd565b600d6200030e565b62000364565b63313ce567906200051c60405190565b93849260e01b90565b825260049082905afa8015620005eb5762000549915f91620005b6575b5062000434565b6200055362000447565b5f81831115620005a55750620005746200056e828462000467565b6200047b565b60c0525f8183101562000597575062000592916200056e9162000467565b60e052565b9050620005929150620002fe565b620005b090620002fe565b62000574565b620005dc915060203d8111620005e3575b620005d38183620000d6565b81019062000412565b5f62000542565b503d620005c7565b62000429565b62000123612710620002fe565b634e487b7160e01b5f52601260045260245ffd5b81156200061d570490565b620005fe565b916200062f916200083a565b608052620001156200065762000644620005f1565b620006506005620002fe565b9062000612565b60086200030e565b634e487b7160e01b5f52602260045260245ffd5b906001600283049216801562000696575b60208310146200069057565b6200065f565b91607f169162000684565b915f1960089290920291821b911b620002f4565b9190620006ca620001236200032a93620002fe565b908354620006a1565b62000115915f91620006b5565b818110620006ec575050565b80620006fb5f600193620006d3565b01620006e0565b9190601f81116200071257505050565b6200072462000115935f5260205f2090565b906020601f84018190048301931062000748575b6020601f909101040190620006e0565b909150819062000738565b906200075d815190565b906001600160401b038211620000f85762000785826200077e855462000673565b8562000702565b602090601f8311600114620007c2576200032a92915f9183620007b6575b50505f19600883021c1916906002021790565b015190505f80620007a3565b601f19831691620007d6855f5260205f2090565b925f5b8181106200081557509160029391856001969410620007fc575b50505002019055565b01515f196008601f8516021c191690555f8080620007f3565b91936020600181928787015181550195019201620007d9565b90620001159162000753565b906200085662000115926200084e6200085e565b60046200082e565b60056200082e565b620001158080335f546001600160a01b0316906200087d815f6200039b565b620008b4620008ad7f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09362000364565b9162000364565b91620008bf60405190565b5f90a356fe60806040526004361015610019575b36612c3f575b612c3f565b5f3560e01c806306fdde0314610313578063095ea7b3146102645780630dbe671f1461030e5780630ec330221461030957806318160ddd1461030457806323b872dd146102ff57806328fdb481146102fa5780632d46f63e146102f55780632d8fe99a146102f05780632e1a7d4d146102eb578063313ce567146102e65780633536a1dc146102e157806335c24a88146102dc578063372500ab146102d757806339509351146102d2578063488cb841146102cd5780634927b44c146102c85780634bf6f9e7146102c357806352fb8b03146102be5780635860638d146102b957806358ba94d7146102b457806370a08231146102af578063715018a6146102aa57806375172a8b146102a557806379df4fa2146102a05780637a23032c1461029b5780637f6a92ed146102965780638427a58114610291578063845a46971461028c5780638a054ac2146102875780638da5cb5b1461028257806390ed6bf41461027d57806395d89b411461027857806398d5fdca146102735780639e1a4d191461026e578063a457c2d714610269578063a9059cbb14610264578063b51459fe1461025f578063b6b55f251461025a578063c0d7865514610255578063c1c46dbe14610250578063dd62ed3e1461024b578063e78a587514610246578063e99fee3e14610241578063f2fde38b1461023c578063f40f0f5214610237578063f887ea40146102325763fc0c546a0361000e57610b7b565b610b47565b610b08565b610af0565b610ad8565b610abd565b610a96565b610a5b565b610a43565b610a2b565b610a10565b610421565b6109ef565b6109d4565b6109ae565b610993565b61097b565b610946565b61092b565b610905565b6108ed565b6108bd565b61087c565b610859565b61083e565b61081b565b610800565b6107e8565b6107d0565b6107b5565b61078f565b610723565b6106f4565b6106d3565b6106bb565b6106a0565b61067d565b610623565b61060b565b6105ee565b6105bb565b610563565b610508565b6104bd565b6104a2565b61043b565b610393565b5f91031261032257565b5f80fd5b5f5b8381106103375750505f910152565b8181015183820152602001610328565b61036861037160209361037b9361035c815190565b80835293849260200190565b95869101610326565b601f01601f191690565b0190565b602080825261039092910190610347565b90565b34610322576103a3366004610318565b6103ba6103ae610ef8565b6040519182918261037f565b0390f35b6001600160a01b031690565b6001600160a01b0381165b0361032257565b905035906103e9826103ca565b565b806103d5565b905035906103e9826103eb565b9190604083820312610322576103909061041881856103dc565b936020016103f1565b34610322576104313660046103fe565b90610f42565b9052565b346103225761044b366004610318565b6103ba7f00000000000000000000000000000000000000000000000000000000000000005b6040515b9182918290815260200190565b610390916008021c81565b906103909154610481565b6103905f600c61048c565b34610322576104b2366004610318565b6103ba610470610497565b34610322576104cd366004610318565b6103ba610470610f1d565b9091606082840312610322576103906104f184846103dc565b936104ff81602086016103dc565b936040016103f1565b34610322576105183660046104d8565b91610f67565b8015156103d5565b905035906103e98261051e565b90916060828403126103225761039061054c84846103dc565b9361055a81602086016103f1565b93604001610526565b34610322576103ba610470610579366004610533565b91611f29565b6080818303126103225761059382826103dc565b926103906105a484602085016103f1565b936105b281604086016103f1565b93606001610526565b34610322576103ba6104706105d136600461057f565b929190916121a6565b9060208282031261032257610390916103f1565b34610322576106066106013660046105da565b612e0f565b604051005b346103225761060661061e3660046105da565b611a6d565b3461032257610633366004610318565b6103ba61063e612ebb565b6040519182918260ff909116815260200190565b61ffff81166103d5565b905035906103e982610652565b90602082820312610322576103909161065c565b3461032257610606610690366004610669565b61226b565b6103905f600d61048c565b34610322576106b0366004610318565b6103ba610470610695565b34610322576106cb366004610318565b610606612c9f565b34610322576106e33660046103fe565b90610fa1565b6103905f600861048c565b3461032257610704366004610318565b6103ba6104706106e9565b9060208282031261032257610390916103dc565b346103225761060661073636600461070f565b612408565b6103be610390610390926001600160a01b031690565b6103909061073b565b61039090610751565b9061076d9061075a565b5f5260205260405f2090565b6103909061078a6007915f92610763565b61048c565b34610322576103ba6104706107a536600461070f565b610779565b6103905f600661048c565b34610322576107c5366004610318565b6103ba6104706107aa565b34610322576107e0366004610318565b6106066123c9565b34610322576107f8366004610318565b61060661237e565b34610322576103ba61047061081636600461070f565b610f27565b346103225761082b366004610318565b610606610c0c565b6103905f600e61048c565b346103225761084e366004610318565b6103ba610470610833565b3461032257610869366004610318565b61060661239e565b6103905f600961048c565b346103225761088c366004610318565b6103ba610470610871565b610390916008021c5b61ffff1690565b906103909154610897565b6103905f600a6108a7565b34610322576108cd366004610318565b6103ba6108d86108b2565b6040519182918261ffff909116815260200190565b34610322576108fd366004610318565b6106066122c4565b34610322576103ba61047061091b3660046105da565b6124de565b6103905f600f61048c565b346103225761093b366004610318565b6103ba610470610920565b3461032257610956366004610318565b6103ba610961610bcc565b604051918291826001600160a01b03909116815260200190565b346103225761098b366004610318565b6106066123e9565b34610322576109a3366004610318565b6103ba6103ae610f02565b34610322576109be366004610318565b6103ba6104706126b2565b6103905f600b61048c565b34610322576109e4366004610318565b6103ba6104706109c9565b34610322576109ff3660046103fe565b9061102d565b6103905f601261048c565b3461032257610a20366004610318565b6103ba610470610a05565b3461032257610606610a3e3660046105da565b61141d565b3461032257610606610a5636600461070f565b612465565b3461032257610606610a6e3660046105da565b6122f7565b91906040838203126103225761039090610a8d81856103dc565b936020016103dc565b34610322576103ba610470610aac366004610a73565b90610f48565b6103905f601161048c565b3461032257610acd366004610318565b6103ba610470610ab2565b3461032257610ae8366004610318565b610606612e88565b3461032257610606610b0336600461070f565b610d39565b34610322576103ba610470610b1e36600461070f565b612e90565b610390916008021c6103be565b906103909154610b23565b6103906002600a610b30565b3461032257610b57366004610318565b6103ba610961610b3b565b6104379061075a565b6020810192916103e99190610b62565b3461032257610b8b366004610318565b604051806103ba7f000000000000000000000000000000000000000000000000000000000000000082610b6b565b610390906103be565b6103909054610bb9565b6103905f610bc2565b610bdd610c68565b6103e9610bfb565b6103be6103906103909290565b61039090610be5565b6103e9610c075f610bf2565b610d72565b6103e9610bd5565b15610c1b57565b60405162461bcd60e51b815280610c64600482016020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b0390fd5b6103e9610c73610bcc565b610c8c610c7f336103be565b916001600160a01b031690565b14610c14565b6103e990610c9e610c68565b610d15565b15610caa57565b60405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201527f64647265737300000000000000000000000000000000000000000000000000006064820152608490fd5b6103e990610c07610d286103be5f610bf2565b6001600160a01b0383161415610ca3565b6103e990610c92565b906001600160a01b03905b9181191691161790565b90610d67610390610d6e9261075a565b8254610d42565b9055565b610d7b5f610bc2565b90610d86815f610d57565b610db9610db37f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09361075a565b9161075a565b91610dc360405190565b80805b0390a3565b634e487b7160e01b5f52602260045260245ffd5b9060016002830492168015610dff575b6020831014610dfa57565b610dcb565b91607f1691610def565b80545f939291610e25610e1b83610ddf565b8085529360200190565b9160018116908115610e745750600114610e3e57505050565b610e4f91929394505f5260205f2090565b915f925b818410610e605750500190565b805484840152602090930192600101610e53565b92949550505060ff1916825215156020020190565b9061039091610e09565b634e487b7160e01b5f52604160045260245ffd5b90601f01601f1916810190811067ffffffffffffffff821117610ec957604052565b610e93565b906103e9610ee892610edf60405190565b93848092610e89565b0383610ea7565b61039090610ece565b6103906004610eef565b6103906005610eef565b6103909081565b6103909054610f0c565b6103906003610f13565b610f3d61039091610f355f90565b506001610763565b610f13565b33612c3f565b61039091610f62610f3d92610f5a5f90565b506002610763565b610763565b610014833383611098565b634e487b7160e01b5f52601160045260245ffd5b9190610f91565b9290565b8201809211610f9c57565b610f72565b610fb53392610fb08385610f48565b610f86565b91612c3f565b15610fc257565b60405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f7760448201527f207a65726f0000000000000000000000000000000000000000000000000000006064820152608490fd5b610fb5339261103c8385610f48565b61104882821015610fbb565b0390565b1561105357565b60405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e63650000006044820152606490fd5b916110a38284610f48565b5f1981036110b15750505050565b610fb591906110488282101561104c565b6103906103906103909290565b156110d657565b60405162461bcd60e51b815260206004820152601860248201527f506f6f6c3a206465706f7369742070726f6869626974656400000000000000006044820152606490fd5b6103e99061114361112c6011610f13565b61113d61113960016110c2565b9190565b146110cf565b61127e565b1561114f57565b60405162461bcd60e51b815260206004820152601060248201527f506f6f6c3a20746f6f206c6974746c65000000000000000000000000000000006044820152606490fd5b905f1990610d4d565b906111ad610390610d6e926110c2565b8254611194565b81810292918115918404141715610f9c57565b634e487b7160e01b5f52601260045260245ffd5b81156111e5570490565b6111c7565b6111f76103906103909290565b60ff1690565b610390906112116111396103909460ff1690565b901c90565b91908203918211610f9c57565b610390650100000000006110c2565b1561123957565b60405162461bcd60e51b815260206004820152600e60248201527f506f6f6c3a20746f6f206d7563680000000000000000000000000000000000006044820152606490fd5b61139b9061139561128f600f610f13565b611298836129ef565b5f6112ac6112a5826110c2565b8311611148565b6112eb6112d87f000000000000000000000000000000000000000000000000000000000000000061075a565b953396876112e53061075a565b9161148c565b6113036112fc83610fb0600e610f13565b600e61119d565b611320611310600b610f13565b61131a600c610f13565b90610f86565b9061132a816110c2565b841490811561140b575b50156113bc575061137761135561137e9261134f60016111ea565b906111fd565b61136d61136682610fb0600b610f13565b600b61119d565b610fb0600c610f13565b600c61119d565b6113866128e7565b611390600f610f13565b611216565b90612f55565b6103e96113a8600b610f13565b6113b6611139610390611223565b10611232565b61136d816113e7611406946113f66113666113ec611377976113e76113e1600b610f13565b866111b4565b6111db565b610fb0600b610f13565b611400600c610f13565b906111b4565b61137e565b61141591506110c2565b81145f611334565b6103e99061111b565b61143f6114396103909263ffffffff1690565b60e01b90565b7fffffffff000000000000000000000000000000000000000000000000000000001690565b6001600160a01b039182168152911660208201526060810192916103e99160400152565b0152565b906114d1906114c26103e9956004956114a86323b872dd611426565b936114b260405190565b9788956020870190815201611464565b60208201810382520383610ea7565b6115ec565b906103e96114e360405190565b9283610ea7565b67ffffffffffffffff8111610ec957602090601f01601f19160190565b90611519611514836114ea565b6114d6565b918252565b6115286020611507565b7f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564602082015290565b61039061151e565b905051906103e98261051e565b906020828203126103225761039091611559565b1561158157565b60405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f742073756363656564000000000000000000000000000000000000000000006064820152608490fd5b6103e9916115fc61160b9261075a565b90611605611551565b91611648565b80516116196111395f6110c2565b14908115611628575b5061157a565b61164291506020611637825190565b818301019101611566565b5f611622565b61039092916116565f6110c2565b916116ec565b1561166357565b60405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f60448201527f722063616c6c00000000000000000000000000000000000000000000000000006064820152608490fd5b3d156116e7576116dd3d611507565b903d5f602084013e565b606090565b905f610390949381926116fd606090565b5061171461170a3061075a565b839031101561165c565b60208101905191855af16117266116ce565b91611778565b1561173357565b60405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606490fd5b919290156117a95750815161178f6111395f6110c2565b14611798575090565b6117a4610390916117af565b61172c565b826117c0565b3b6117bc6111395f6110c2565b1190565b906117c9825190565b6117d56111395f6110c2565b11156117e45750805190602001fd5b610c64906117f160405190565b91829162461bcd60e51b83526004830161037f565b1561180d57565b60405162461bcd60e51b815260206004820152601960248201527f506f6f6c3a2077697468647261772070726f68696269746564000000000000006044820152606490fd5b6103e9906118766118636012610f13565b61187061113960016110c2565b14611806565b61195f565b1561188257565b60405162461bcd60e51b815260206004820152601260248201527f506f6f6c3a207a65726f206368616e67657300000000000000000000000000006044820152606490fd5b156118ce57565b60405162461bcd60e51b815260206004820152600e60248201527f506f6f6c3a2072657365727665730000000000000000000000000000000000006044820152606490fd5b1561191a57565b60405162461bcd60e51b815260206004820152601460248201527f506f6f6c3a207a65726f2044206368616e6765730000000000000000000000006044820152606490fd5b6103e99061196d600f610f13565b611a35339161197c84846131b7565b6119ed61198c611310600b610f13565b6119b36113666119a9836113e76119a3600b610f13565b8b6111b4565b611390600b610f13565b6119d46113776119ca836113e76119a3600c610f13565b611390600c610f13565b6119e7611139610f8d611310600b610f13565b1061187b565b611a066119fd610390600e610f13565b855b11156118c7565b611a176112fc85611390600e610f13565b611a1f6128e7565b611a2f611139610f8d600f610f13565b10611913565b611a67611a617f000000000000000000000000000000000000000000000000000000000000000061075a565b92612a6a565b91611a93565b6103e990611852565b6001600160a01b0390911681526040810192916103e99160200152565b6114d16004926114c26103e995611aad63a9059cbb611426565b92611ab760405190565b9687946020860190815201611a76565b6103909060101c6103be565b6103909054611ac7565b15611ae457565b60405162461bcd60e51b815260206004820152601360248201527f506f6f6c3a206973206e6f7420726f75746572000000000000000000000000006044820152606490fd5b90610390939291611b4c611b3d600a611ad3565b611b4633610c7f565b14611add565b611bf4565b6103906127106110c2565b15611b6357565b60405162461bcd60e51b815260206004820152601760248201527f506f6f6c3a206c6f7720746f6b656e2062616c616e63650000000000000000006044820152606490fd5b15611baf57565b60405162461bcd60e51b815260206004820152601660248201527f506f6f6c3a206c6f7720765553442062616c616e6365000000000000000000006044820152606490fd5b90611c00939291611d54565b90611c0b600b610f13565b611c1b611139610390600c610f13565b1115611c63576103e9611c4c611c3c611c34600c610f13565b611400611b51565b611c46600b610f13565b906111db565b611c5c611139610390600d610f13565b1015611ba8565b611c6d600b610f13565b611c7d611139610390600c610f13565b10611c8457565b6103e9611ca1611c97611c34600b610f13565b611c46600c610f13565b611cb1611139610390600d610f13565b1015611b5c565b610390906108a0565b6103909054611cb8565b6103906103906103909261ffff1690565b905051906103e9826103eb565b906020828203126103225761039091611cdc565b6040513d5f823e3d90fd5b909594926103e994611d4d61148892611d46608096611d3660a088019c5f8901906001600160a01b03169052565b6001600160a01b03166020870152565b6040850152565b6060830152565b505f928390611d625f6110c2565b8411611dd3575b5090611dcd611d977f000000000000000000000000000000000000000000000000000000000000000061075a565b92857fa930da1d3f27a25892307dd59cec52dd9b881661a0f20364757f83a0da2f687395611dc460405190565b95869586611d08565b0390a190565b15611efa575b611de6611deb9184611216565b6129ef565b90611dfe611df883612a6a565b84611216565b611e216112fc8294611e1761136682610fb0600b610f13565b610fb0600e610f13565b611e676020611e2f3061075a565b63845a469790611e59611e42600b610f13565b92611e4c60405190565b9586948593849360e01b90565b835260048301526024820190565b03915afa908115611ef5575f91611ec7575b50611e84600c610f13565b8110611ea6575b90611e9a611e9f92600c61119d565b612ed6565b905f611d69565b9450611e9f90611e9a611ebd87611390600c610f13565b9691925050611e8b565b611ee8915060203d8111611eee575b611ee08183610ea7565b810190611ce9565b5f611e79565b503d611ed6565b611cfd565b50611deb611de6611f21611f196113e1611f14600a611cc1565b611ccb565b611c46611b51565b915050611dd9565b6103909291905f611b29565b9061039094939291611f4a611b3d600a611ad3565b90611c0094939291611fa3565b15611f5e57565b60405162461bcd60e51b815260206004820152600e60248201527f506f6f6c3a20736c6970706167650000000000000000000000000000000000006044820152606490fd5b505f939192849283611fb4816110c2565b8611612017575b505050611dcd611fea7f000000000000000000000000000000000000000000000000000000000000000061075a565b92857ffc1df7b9ba72a13350b8a4e0f094e232eebded9edd179950e74a852a0f40511295611dc460405190565b90612063969161202e61137788610fb0600c610f13565b60206120393061075a565b63845a469790611e5961204c600c610f13565b9261205660405190565b9c8d948593849360e01b90565b03915afa978815611ef5575f98612186575b50612080600b610f13565b8810612157575b906120b26112fc6120b6936120a86120a2610390600e610f13565b826119ff565b611390600e610f13565b1590565b612123575b906120e36120db6120ce86612112950390565b926103908499600b61119d565b821015611f57565b8261210d7f000000000000000000000000000000000000000000000000000000000000000061075a565b611a93565b61211b82612ed6565b5f8080611fbb565b9250612112906120e36120db6120ce61214b611f19612145611f14600a611cc1565b896111b4565b969394505050506120bb565b5090506120b661216b87611390600b610f13565b916120b26112fc61217b85612a6a565b949293505050612087565b61219f91985060203d8111611eee57611ee08183610ea7565b965f612075565b610390939291905f611f35565b6103e9906121bf610c68565b612242565b156121cb57565b60405162461bcd60e51b815260206004820152600f60248201527f506f6f6c3a20746f6f206c6172676500000000000000000000000000000000006044820152606490fd5b9061ffff90610d4d565b6108a06103906103909261ffff1690565b9061223b610390610d6e9261221a565b8254612210565b6103e990612264612254610390611b51565b61225d83611ccb565b11156121c4565b600a61222b565b6103e9906121b3565b61227c610c68565b6103e9612289600f610f13565b612297611139610390610f1d565b1161229e57565b6103e96122a9610bcc565b6113956122b6600f610f13565b6122be610f1d565b90611216565b6103e9612274565b6103e9906122d8610c68565b6103e9906122f06122ea610390611b51565b8261225d565b600d61119d565b6103e9906122cc565b1561230757565b60405162461bcd60e51b815260206004820152601a60248201527f506f6f6c3a206973206e6f742073746f70417574686f726974790000000000006044820152606490fd5b6123686123596010610bc2565b61236233610c7f565b14612300565b6103e96103e96123775f6110c2565b601161119d565b6103e961234c565b61238e610c68565b6103e96103e961237760016110c2565b6103e9612386565b6123b36123596010610bc2565b6103e96103e96123c25f6110c2565b601261119d565b6103e96123a6565b6123d9610c68565b6103e96103e96123c260016110c2565b6103e96123d1565b6103e9906123fd610c68565b6103e9906010610d57565b6103e9906123f1565b6103e99061241d610c68565b61245a565b9075ffffffffffffffffffffffffffffffffffffffff00009060101b610d4d565b90612453610390610d6e9261075a565b8254612422565b6103e990600a612443565b6103e990612411565b610390906124826111396103909460ff1690565b901b90565b9190808303925f9091128015828513169184121617610f9c57565b81810292915f8212600160ff1b821416610f9c578184051490151715610f9c57565b9190828101925f13801591841291821691151617610f9c57565b6124e8600f610f13565b907f000000000000000000000000000000000000000000000000000000000000000061251460026111ea565b61251d9161246e565b600192612529846111ea565b612533908361246e565b91818061253f836110c2565b92612549826110c2565b612552886110c2565b9461255d8683612487565b612566916124a2565b9061257091612487565b9461257a916111b4565b90612584916111b4565b9061258e916111b4565b61259883806124a2565b6125a1906110c2565b6125ab90866111b4565b6125b491610f86565b6125be90856111b4565b6125c790612ae5565b6125d0906110c2565b916125da916124a2565b6125e3916124c4565b6125ec90612662565b916125f6916111b4565b6125ff916111db565b90612609906110c2565b61039091610f86565b1561261957565b60405162461bcd60e51b815280610c64600482016020808252818101527f53616665436173743a2076616c7565206d75737420626520706f736974697665604082015260600190565b6103909061267a6126725f6110c2565b821215612612565b6110c2565b610390906126936111396103909460ff1690565b901d90565b81156111e557600160ff1b81145f19831416610f9c570590565b6126bc600b610f13565b7f00000000000000000000000000000000000000000000000000000000000000006126e760036111ea565b6126f1908261246e565b8280806126fe600f610f13565b612708600f610f13565b612711916111b4565b61271b600f610f13565b612724916111b4565b938461273060026111ea565b968761273b9161246e565b612744816110c2565b61274e600f610f13565b612757906110c2565b612760866110c2565b61276991612487565b612772916124a2565b61277c600f610f13565b612785906110c2565b61278e91612487565b91612798916111b4565b90806127a3916124a2565b6127ac906110c2565b6127b690846111b4565b6127bf91610f86565b6127c990836111b4565b946127d3906110c2565b82806127df600f610f13565b6127e990856111b4565b906127f3916111b4565b906127fd916111b4565b612806906110c2565b61280f916124c4565b93612819916111b4565b90612823916111b4565b9061282d916111b4565b612836906110c2565b61283f91612487565b9261284a600f610f13565b93818061285760016111ea565b96876128629161246e565b9061286c916111b4565b90612876916111b4565b61287f906110c2565b61288891612487565b93612891611b51565b9061289c908261267f565b946128a6916124a2565b926128b09161246e565b906128ba90612ae5565b6128c3916111b4565b6128cc906110c2565b6128d591612698565b6128de916124c4565b61039090612662565b6103e96129d76128f7600b610f13565b612961612904600c610f13565b6129a361299e612981612977612967612956612920878a6111b4565b986114007f0000000000000000000000000000000000000000000000000000000000000000986129508c8b6111b4565b92610f86565b9561296160026111ea565b9061246e565b966114006001986122be8a6110c2565b611c4660036110c2565b61131a61298e85806111b4565b9161299981806111b4565b6111b4565b612ae5565b6129b3828201612b7c565b612b7c565b9081838211156129de57506129d1926129cc9103612b7c565b900390565b916111ea565b600f61119d565b91506129ae61037b916129d1940390565b7f00000000000000000000000000000000000000000000000000000000000000005f612a1a816110c2565b821115612a2b5750610390916111db565b9050612a577f0000000000000000000000000000000000000000000000000000000000000000916110c2565b8111612a61575090565b610390916111b4565b7f00000000000000000000000000000000000000000000000000000000000000005f612a95816110c2565b821115612aa65750610390916111b4565b9050612ad27f0000000000000000000000000000000000000000000000000000000000000000916110c2565b8111612adc575090565b610390916111db565b5f612aef816110c2565b8211612aff5761039091506110c2565b50600180612b0c816111ea565b612b22612b1982866111fd565b61037b846110c2565b93612b3a82612b358761037b81866111db565b6111fd565b935b612b48575b5050505090565b90919293612b538590565b811115612b765750612b6d82612b358661037b81866111db565b92919082612b3c565b93612b41565b5f90612b87826110c2565b90612b95600160ff1b6110c2565b612b9e846110c2565b811115612c3857612bb4600193612961856111ea565b9283612bdf612b19612bce83612bca60036110c2565b0290565b612bca612bda866110c2565b850190565b612be984866111db565b811115612c0c575b505050612c05612b9e9161134f60036111ea565b9050612b95565b8395509061037b612c2a612c0594966129cc612c3095612b9e980290565b956110c2565b93915f612bf1565b5050905090565b60405162461bcd60e51b815260206004820152600b60248201527f556e737570706f727465640000000000000000000000000000000000000000006044820152606490fd5b61039060346110c2565b610390906112116111396103909490565b33612ca981610f27565b905f91612cb5836110c2565b8111612cc057505050565b612cd1612cdf916114006006610f13565b612cd9612c84565b90612c8e565b600790612d01612cfb612cf5610f3d8686610763565b83611216565b946110c2565b8411612d0e575b50505050565b612d1b83612d2093610763565b61119d565b612d4e828261210d7f000000000000000000000000000000000000000000000000000000000000000061075a565b612d85612d7b7ffc30cddea38e2bf4d6ea7d3f9ed3b6ad7f176419f4963bd81318067a4aee73fe9261075a565b9261047460405190565b0390a25f808080612d08565b6103e990612d9d610c68565b612dee565b15612da957565b60405162461bcd60e51b815260206004820152601760248201527f5265776172644d616e616765723a20746f6f20686967680000000000000000006044820152606490fd5b6103e990612e08612e00610390611b51565b821115612da2565b600861119d565b6103e990612d91565b612e20610c68565b6103e9612e2d6009610f13565b5f90612e3b611139836110c2565b11612e435750565b612e816103e99161267a612e767f000000000000000000000000000000000000000000000000000000000000000061075a565b33611a676009610f13565b600961119d565b6103e9612e18565b610390906122be610f3d612eb3612cd1612ea985610f27565b6114006006610f13565b926007610763565b61039060036111ea565b610390906124826111396103909490565b612ede610f1d565b612eea6111395f6110c2565b11612ef25750565b612e816103e991612f4b612f44612f3a612f32612f24612f1e611f19612f186008610f13565b886111b4565b80960390565b612f2c612c84565b90612ec5565b611c46610f1d565b610fb06006610f13565b600661119d565b610fb06009610f13565b5f612f5f82610f27565b905f84612f6b826110c2565b841161303c575b612f93612cd1612f8961267a93612f9e9697610f86565b612ea989896130c7565b612d1b866007610763565b8111612fd8575b50612fd3612d7b7fe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c9261075a565b0390a2565b613006818361210d7f000000000000000000000000000000000000000000000000000000000000000061075a565b7ffc30cddea38e2bf4d6ea7d3f9ed3b6ad7f176419f4963bd81318067a4aee73fe613033612d7b8461075a565b0390a25f612fa5565b612f9e9250612f93612cd1612f8961267a9361306f613061612cd16119a36006610f13565b6122be610f3d8c6007610763565b96509350505050612f72565b1561308257565b60405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152606490fd5b6130d05f610bf2565b6130ee6001600160a01b0382166001600160a01b038416141561307b565b6131066130ff84610fb06003610f13565b600361119d565b613127613114836001610763565b6131218561037b83610f13565b9061119d565b610dc661315d6131577fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9361075a565b9361075a565b9361047460405190565b1561316e57565b60405162461bcd60e51b815280610c64600482016020808252818101527f5265776172644d616e616765723a206e6f7420656e6f75676820616d6f756e74604082015260600190565b6131c081610f27565b6131cc83821015613167565b5f80846131d8826110c2565b8411613299575b612f93612cd16131f661267a936132009697611216565b612ea989896133ae565b8111613235575b50612fd3612d7b7f884edad9ce6fa2440d8a54cc123490eb96d2768479d49ff9c7366125a94243649261075a565b613263818361210d7f000000000000000000000000000000000000000000000000000000000000000061075a565b7ffc30cddea38e2bf4d6ea7d3f9ed3b6ad7f176419f4963bd81318067a4aee73fe613290612d7b8461075a565b0390a25f613207565b6132009250612f93612cd16131f661267a936132be613061612cd16119a36006610f13565b965093505050506131df565b156132d157565b60405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f2061646472657360448201527f73000000000000000000000000000000000000000000000000000000000000006064820152608490fd5b1561334357565b60405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e60448201527f63650000000000000000000000000000000000000000000000000000000000006064820152608490fd5b6133b75f610bf2565b906133d66001600160a01b0383166001600160a01b03831614156132ca565b6134026001612d1b836133fc876133f0610f3d8487610763565b6110488282101561333c565b92610763565b6131276130ff846110486003610f1356fea2646970667358221220aa604a89c59e3e752c604c51c6ecb59367fcba4e584af94b4b1e3a2736f26d8e64736f6c63430008140033000000000000000000000000782e918ed2b3d161e90c5e154fed3e93d705c59800000000000000000000000000000000000000000000000000000000000000140000000000000000000000009151434b16b9763660705744891fa906f660ecc5000000000000000000000000000000000000000000000000000000000000001e00000000000000000000000000000000000000000000000000000000000001f400000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000000c416c6c627269646765204c50000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000074c502d5553445400000000000000000000000000000000000000000000000000

Deployed Bytecode

0x60806040526004361015610019575b36612c3f575b612c3f565b5f3560e01c806306fdde0314610313578063095ea7b3146102645780630dbe671f1461030e5780630ec330221461030957806318160ddd1461030457806323b872dd146102ff57806328fdb481146102fa5780632d46f63e146102f55780632d8fe99a146102f05780632e1a7d4d146102eb578063313ce567146102e65780633536a1dc146102e157806335c24a88146102dc578063372500ab146102d757806339509351146102d2578063488cb841146102cd5780634927b44c146102c85780634bf6f9e7146102c357806352fb8b03146102be5780635860638d146102b957806358ba94d7146102b457806370a08231146102af578063715018a6146102aa57806375172a8b146102a557806379df4fa2146102a05780637a23032c1461029b5780637f6a92ed146102965780638427a58114610291578063845a46971461028c5780638a054ac2146102875780638da5cb5b1461028257806390ed6bf41461027d57806395d89b411461027857806398d5fdca146102735780639e1a4d191461026e578063a457c2d714610269578063a9059cbb14610264578063b51459fe1461025f578063b6b55f251461025a578063c0d7865514610255578063c1c46dbe14610250578063dd62ed3e1461024b578063e78a587514610246578063e99fee3e14610241578063f2fde38b1461023c578063f40f0f5214610237578063f887ea40146102325763fc0c546a0361000e57610b7b565b610b47565b610b08565b610af0565b610ad8565b610abd565b610a96565b610a5b565b610a43565b610a2b565b610a10565b610421565b6109ef565b6109d4565b6109ae565b610993565b61097b565b610946565b61092b565b610905565b6108ed565b6108bd565b61087c565b610859565b61083e565b61081b565b610800565b6107e8565b6107d0565b6107b5565b61078f565b610723565b6106f4565b6106d3565b6106bb565b6106a0565b61067d565b610623565b61060b565b6105ee565b6105bb565b610563565b610508565b6104bd565b6104a2565b61043b565b610393565b5f91031261032257565b5f80fd5b5f5b8381106103375750505f910152565b8181015183820152602001610328565b61036861037160209361037b9361035c815190565b80835293849260200190565b95869101610326565b601f01601f191690565b0190565b602080825261039092910190610347565b90565b34610322576103a3366004610318565b6103ba6103ae610ef8565b6040519182918261037f565b0390f35b6001600160a01b031690565b6001600160a01b0381165b0361032257565b905035906103e9826103ca565b565b806103d5565b905035906103e9826103eb565b9190604083820312610322576103909061041881856103dc565b936020016103f1565b34610322576104313660046103fe565b90610f42565b9052565b346103225761044b366004610318565b6103ba7f00000000000000000000000000000000000000000000000000000000000000145b6040515b9182918290815260200190565b610390916008021c81565b906103909154610481565b6103905f600c61048c565b34610322576104b2366004610318565b6103ba610470610497565b34610322576104cd366004610318565b6103ba610470610f1d565b9091606082840312610322576103906104f184846103dc565b936104ff81602086016103dc565b936040016103f1565b34610322576105183660046104d8565b91610f67565b8015156103d5565b905035906103e98261051e565b90916060828403126103225761039061054c84846103dc565b9361055a81602086016103f1565b93604001610526565b34610322576103ba610470610579366004610533565b91611f29565b6080818303126103225761059382826103dc565b926103906105a484602085016103f1565b936105b281604086016103f1565b93606001610526565b34610322576103ba6104706105d136600461057f565b929190916121a6565b9060208282031261032257610390916103f1565b34610322576106066106013660046105da565b612e0f565b604051005b346103225761060661061e3660046105da565b611a6d565b3461032257610633366004610318565b6103ba61063e612ebb565b6040519182918260ff909116815260200190565b61ffff81166103d5565b905035906103e982610652565b90602082820312610322576103909161065c565b3461032257610606610690366004610669565b61226b565b6103905f600d61048c565b34610322576106b0366004610318565b6103ba610470610695565b34610322576106cb366004610318565b610606612c9f565b34610322576106e33660046103fe565b90610fa1565b6103905f600861048c565b3461032257610704366004610318565b6103ba6104706106e9565b9060208282031261032257610390916103dc565b346103225761060661073636600461070f565b612408565b6103be610390610390926001600160a01b031690565b6103909061073b565b61039090610751565b9061076d9061075a565b5f5260205260405f2090565b6103909061078a6007915f92610763565b61048c565b34610322576103ba6104706107a536600461070f565b610779565b6103905f600661048c565b34610322576107c5366004610318565b6103ba6104706107aa565b34610322576107e0366004610318565b6106066123c9565b34610322576107f8366004610318565b61060661237e565b34610322576103ba61047061081636600461070f565b610f27565b346103225761082b366004610318565b610606610c0c565b6103905f600e61048c565b346103225761084e366004610318565b6103ba610470610833565b3461032257610869366004610318565b61060661239e565b6103905f600961048c565b346103225761088c366004610318565b6103ba610470610871565b610390916008021c5b61ffff1690565b906103909154610897565b6103905f600a6108a7565b34610322576108cd366004610318565b6103ba6108d86108b2565b6040519182918261ffff909116815260200190565b34610322576108fd366004610318565b6106066122c4565b34610322576103ba61047061091b3660046105da565b6124de565b6103905f600f61048c565b346103225761093b366004610318565b6103ba610470610920565b3461032257610956366004610318565b6103ba610961610bcc565b604051918291826001600160a01b03909116815260200190565b346103225761098b366004610318565b6106066123e9565b34610322576109a3366004610318565b6103ba6103ae610f02565b34610322576109be366004610318565b6103ba6104706126b2565b6103905f600b61048c565b34610322576109e4366004610318565b6103ba6104706109c9565b34610322576109ff3660046103fe565b9061102d565b6103905f601261048c565b3461032257610a20366004610318565b6103ba610470610a05565b3461032257610606610a3e3660046105da565b61141d565b3461032257610606610a5636600461070f565b612465565b3461032257610606610a6e3660046105da565b6122f7565b91906040838203126103225761039090610a8d81856103dc565b936020016103dc565b34610322576103ba610470610aac366004610a73565b90610f48565b6103905f601161048c565b3461032257610acd366004610318565b6103ba610470610ab2565b3461032257610ae8366004610318565b610606612e88565b3461032257610606610b0336600461070f565b610d39565b34610322576103ba610470610b1e36600461070f565b612e90565b610390916008021c6103be565b906103909154610b23565b6103906002600a610b30565b3461032257610b57366004610318565b6103ba610961610b3b565b6104379061075a565b6020810192916103e99190610b62565b3461032257610b8b366004610318565b604051806103ba7f0000000000000000000000009151434b16b9763660705744891fa906f660ecc582610b6b565b610390906103be565b6103909054610bb9565b6103905f610bc2565b610bdd610c68565b6103e9610bfb565b6103be6103906103909290565b61039090610be5565b6103e9610c075f610bf2565b610d72565b6103e9610bd5565b15610c1b57565b60405162461bcd60e51b815280610c64600482016020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b0390fd5b6103e9610c73610bcc565b610c8c610c7f336103be565b916001600160a01b031690565b14610c14565b6103e990610c9e610c68565b610d15565b15610caa57565b60405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201527f64647265737300000000000000000000000000000000000000000000000000006064820152608490fd5b6103e990610c07610d286103be5f610bf2565b6001600160a01b0383161415610ca3565b6103e990610c92565b906001600160a01b03905b9181191691161790565b90610d67610390610d6e9261075a565b8254610d42565b9055565b610d7b5f610bc2565b90610d86815f610d57565b610db9610db37f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09361075a565b9161075a565b91610dc360405190565b80805b0390a3565b634e487b7160e01b5f52602260045260245ffd5b9060016002830492168015610dff575b6020831014610dfa57565b610dcb565b91607f1691610def565b80545f939291610e25610e1b83610ddf565b8085529360200190565b9160018116908115610e745750600114610e3e57505050565b610e4f91929394505f5260205f2090565b915f925b818410610e605750500190565b805484840152602090930192600101610e53565b92949550505060ff1916825215156020020190565b9061039091610e09565b634e487b7160e01b5f52604160045260245ffd5b90601f01601f1916810190811067ffffffffffffffff821117610ec957604052565b610e93565b906103e9610ee892610edf60405190565b93848092610e89565b0383610ea7565b61039090610ece565b6103906004610eef565b6103906005610eef565b6103909081565b6103909054610f0c565b6103906003610f13565b610f3d61039091610f355f90565b506001610763565b610f13565b33612c3f565b61039091610f62610f3d92610f5a5f90565b506002610763565b610763565b610014833383611098565b634e487b7160e01b5f52601160045260245ffd5b9190610f91565b9290565b8201809211610f9c57565b610f72565b610fb53392610fb08385610f48565b610f86565b91612c3f565b15610fc257565b60405162461bcd60e51b815260206004820152602560248201527f45524332303a2064656372656173656420616c6c6f77616e63652062656c6f7760448201527f207a65726f0000000000000000000000000000000000000000000000000000006064820152608490fd5b610fb5339261103c8385610f48565b61104882821015610fbb565b0390565b1561105357565b60405162461bcd60e51b815260206004820152601d60248201527f45524332303a20696e73756666696369656e7420616c6c6f77616e63650000006044820152606490fd5b916110a38284610f48565b5f1981036110b15750505050565b610fb591906110488282101561104c565b6103906103906103909290565b156110d657565b60405162461bcd60e51b815260206004820152601860248201527f506f6f6c3a206465706f7369742070726f6869626974656400000000000000006044820152606490fd5b6103e99061114361112c6011610f13565b61113d61113960016110c2565b9190565b146110cf565b61127e565b1561114f57565b60405162461bcd60e51b815260206004820152601060248201527f506f6f6c3a20746f6f206c6974746c65000000000000000000000000000000006044820152606490fd5b905f1990610d4d565b906111ad610390610d6e926110c2565b8254611194565b81810292918115918404141715610f9c57565b634e487b7160e01b5f52601260045260245ffd5b81156111e5570490565b6111c7565b6111f76103906103909290565b60ff1690565b610390906112116111396103909460ff1690565b901c90565b91908203918211610f9c57565b610390650100000000006110c2565b1561123957565b60405162461bcd60e51b815260206004820152600e60248201527f506f6f6c3a20746f6f206d7563680000000000000000000000000000000000006044820152606490fd5b61139b9061139561128f600f610f13565b611298836129ef565b5f6112ac6112a5826110c2565b8311611148565b6112eb6112d87f0000000000000000000000009151434b16b9763660705744891fa906f660ecc561075a565b953396876112e53061075a565b9161148c565b6113036112fc83610fb0600e610f13565b600e61119d565b611320611310600b610f13565b61131a600c610f13565b90610f86565b9061132a816110c2565b841490811561140b575b50156113bc575061137761135561137e9261134f60016111ea565b906111fd565b61136d61136682610fb0600b610f13565b600b61119d565b610fb0600c610f13565b600c61119d565b6113866128e7565b611390600f610f13565b611216565b90612f55565b6103e96113a8600b610f13565b6113b6611139610390611223565b10611232565b61136d816113e7611406946113f66113666113ec611377976113e76113e1600b610f13565b866111b4565b6111db565b610fb0600b610f13565b611400600c610f13565b906111b4565b61137e565b61141591506110c2565b81145f611334565b6103e99061111b565b61143f6114396103909263ffffffff1690565b60e01b90565b7fffffffff000000000000000000000000000000000000000000000000000000001690565b6001600160a01b039182168152911660208201526060810192916103e99160400152565b0152565b906114d1906114c26103e9956004956114a86323b872dd611426565b936114b260405190565b9788956020870190815201611464565b60208201810382520383610ea7565b6115ec565b906103e96114e360405190565b9283610ea7565b67ffffffffffffffff8111610ec957602090601f01601f19160190565b90611519611514836114ea565b6114d6565b918252565b6115286020611507565b7f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564602082015290565b61039061151e565b905051906103e98261051e565b906020828203126103225761039091611559565b1561158157565b60405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f742073756363656564000000000000000000000000000000000000000000006064820152608490fd5b6103e9916115fc61160b9261075a565b90611605611551565b91611648565b80516116196111395f6110c2565b14908115611628575b5061157a565b61164291506020611637825190565b818301019101611566565b5f611622565b61039092916116565f6110c2565b916116ec565b1561166357565b60405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f60448201527f722063616c6c00000000000000000000000000000000000000000000000000006064820152608490fd5b3d156116e7576116dd3d611507565b903d5f602084013e565b606090565b905f610390949381926116fd606090565b5061171461170a3061075a565b839031101561165c565b60208101905191855af16117266116ce565b91611778565b1561173357565b60405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606490fd5b919290156117a95750815161178f6111395f6110c2565b14611798575090565b6117a4610390916117af565b61172c565b826117c0565b3b6117bc6111395f6110c2565b1190565b906117c9825190565b6117d56111395f6110c2565b11156117e45750805190602001fd5b610c64906117f160405190565b91829162461bcd60e51b83526004830161037f565b1561180d57565b60405162461bcd60e51b815260206004820152601960248201527f506f6f6c3a2077697468647261772070726f68696269746564000000000000006044820152606490fd5b6103e9906118766118636012610f13565b61187061113960016110c2565b14611806565b61195f565b1561188257565b60405162461bcd60e51b815260206004820152601260248201527f506f6f6c3a207a65726f206368616e67657300000000000000000000000000006044820152606490fd5b156118ce57565b60405162461bcd60e51b815260206004820152600e60248201527f506f6f6c3a2072657365727665730000000000000000000000000000000000006044820152606490fd5b1561191a57565b60405162461bcd60e51b815260206004820152601460248201527f506f6f6c3a207a65726f2044206368616e6765730000000000000000000000006044820152606490fd5b6103e99061196d600f610f13565b611a35339161197c84846131b7565b6119ed61198c611310600b610f13565b6119b36113666119a9836113e76119a3600b610f13565b8b6111b4565b611390600b610f13565b6119d46113776119ca836113e76119a3600c610f13565b611390600c610f13565b6119e7611139610f8d611310600b610f13565b1061187b565b611a066119fd610390600e610f13565b855b11156118c7565b611a176112fc85611390600e610f13565b611a1f6128e7565b611a2f611139610f8d600f610f13565b10611913565b611a67611a617f0000000000000000000000009151434b16b9763660705744891fa906f660ecc561075a565b92612a6a565b91611a93565b6103e990611852565b6001600160a01b0390911681526040810192916103e99160200152565b6114d16004926114c26103e995611aad63a9059cbb611426565b92611ab760405190565b9687946020860190815201611a76565b6103909060101c6103be565b6103909054611ac7565b15611ae457565b60405162461bcd60e51b815260206004820152601360248201527f506f6f6c3a206973206e6f7420726f75746572000000000000000000000000006044820152606490fd5b90610390939291611b4c611b3d600a611ad3565b611b4633610c7f565b14611add565b611bf4565b6103906127106110c2565b15611b6357565b60405162461bcd60e51b815260206004820152601760248201527f506f6f6c3a206c6f7720746f6b656e2062616c616e63650000000000000000006044820152606490fd5b15611baf57565b60405162461bcd60e51b815260206004820152601660248201527f506f6f6c3a206c6f7720765553442062616c616e6365000000000000000000006044820152606490fd5b90611c00939291611d54565b90611c0b600b610f13565b611c1b611139610390600c610f13565b1115611c63576103e9611c4c611c3c611c34600c610f13565b611400611b51565b611c46600b610f13565b906111db565b611c5c611139610390600d610f13565b1015611ba8565b611c6d600b610f13565b611c7d611139610390600c610f13565b10611c8457565b6103e9611ca1611c97611c34600b610f13565b611c46600c610f13565b611cb1611139610390600d610f13565b1015611b5c565b610390906108a0565b6103909054611cb8565b6103906103906103909261ffff1690565b905051906103e9826103eb565b906020828203126103225761039091611cdc565b6040513d5f823e3d90fd5b909594926103e994611d4d61148892611d46608096611d3660a088019c5f8901906001600160a01b03169052565b6001600160a01b03166020870152565b6040850152565b6060830152565b505f928390611d625f6110c2565b8411611dd3575b5090611dcd611d977f0000000000000000000000009151434b16b9763660705744891fa906f660ecc561075a565b92857fa930da1d3f27a25892307dd59cec52dd9b881661a0f20364757f83a0da2f687395611dc460405190565b95869586611d08565b0390a190565b15611efa575b611de6611deb9184611216565b6129ef565b90611dfe611df883612a6a565b84611216565b611e216112fc8294611e1761136682610fb0600b610f13565b610fb0600e610f13565b611e676020611e2f3061075a565b63845a469790611e59611e42600b610f13565b92611e4c60405190565b9586948593849360e01b90565b835260048301526024820190565b03915afa908115611ef5575f91611ec7575b50611e84600c610f13565b8110611ea6575b90611e9a611e9f92600c61119d565b612ed6565b905f611d69565b9450611e9f90611e9a611ebd87611390600c610f13565b9691925050611e8b565b611ee8915060203d8111611eee575b611ee08183610ea7565b810190611ce9565b5f611e79565b503d611ed6565b611cfd565b50611deb611de6611f21611f196113e1611f14600a611cc1565b611ccb565b611c46611b51565b915050611dd9565b6103909291905f611b29565b9061039094939291611f4a611b3d600a611ad3565b90611c0094939291611fa3565b15611f5e57565b60405162461bcd60e51b815260206004820152600e60248201527f506f6f6c3a20736c6970706167650000000000000000000000000000000000006044820152606490fd5b505f939192849283611fb4816110c2565b8611612017575b505050611dcd611fea7f0000000000000000000000009151434b16b9763660705744891fa906f660ecc561075a565b92857ffc1df7b9ba72a13350b8a4e0f094e232eebded9edd179950e74a852a0f40511295611dc460405190565b90612063969161202e61137788610fb0600c610f13565b60206120393061075a565b63845a469790611e5961204c600c610f13565b9261205660405190565b9c8d948593849360e01b90565b03915afa978815611ef5575f98612186575b50612080600b610f13565b8810612157575b906120b26112fc6120b6936120a86120a2610390600e610f13565b826119ff565b611390600e610f13565b1590565b612123575b906120e36120db6120ce86612112950390565b926103908499600b61119d565b821015611f57565b8261210d7f0000000000000000000000009151434b16b9763660705744891fa906f660ecc561075a565b611a93565b61211b82612ed6565b5f8080611fbb565b9250612112906120e36120db6120ce61214b611f19612145611f14600a611cc1565b896111b4565b969394505050506120bb565b5090506120b661216b87611390600b610f13565b916120b26112fc61217b85612a6a565b949293505050612087565b61219f91985060203d8111611eee57611ee08183610ea7565b965f612075565b610390939291905f611f35565b6103e9906121bf610c68565b612242565b156121cb57565b60405162461bcd60e51b815260206004820152600f60248201527f506f6f6c3a20746f6f206c6172676500000000000000000000000000000000006044820152606490fd5b9061ffff90610d4d565b6108a06103906103909261ffff1690565b9061223b610390610d6e9261221a565b8254612210565b6103e990612264612254610390611b51565b61225d83611ccb565b11156121c4565b600a61222b565b6103e9906121b3565b61227c610c68565b6103e9612289600f610f13565b612297611139610390610f1d565b1161229e57565b6103e96122a9610bcc565b6113956122b6600f610f13565b6122be610f1d565b90611216565b6103e9612274565b6103e9906122d8610c68565b6103e9906122f06122ea610390611b51565b8261225d565b600d61119d565b6103e9906122cc565b1561230757565b60405162461bcd60e51b815260206004820152601a60248201527f506f6f6c3a206973206e6f742073746f70417574686f726974790000000000006044820152606490fd5b6123686123596010610bc2565b61236233610c7f565b14612300565b6103e96103e96123775f6110c2565b601161119d565b6103e961234c565b61238e610c68565b6103e96103e961237760016110c2565b6103e9612386565b6123b36123596010610bc2565b6103e96103e96123c25f6110c2565b601261119d565b6103e96123a6565b6123d9610c68565b6103e96103e96123c260016110c2565b6103e96123d1565b6103e9906123fd610c68565b6103e9906010610d57565b6103e9906123f1565b6103e99061241d610c68565b61245a565b9075ffffffffffffffffffffffffffffffffffffffff00009060101b610d4d565b90612453610390610d6e9261075a565b8254612422565b6103e990600a612443565b6103e990612411565b610390906124826111396103909460ff1690565b901b90565b9190808303925f9091128015828513169184121617610f9c57565b81810292915f8212600160ff1b821416610f9c578184051490151715610f9c57565b9190828101925f13801591841291821691151617610f9c57565b6124e8600f610f13565b907f000000000000000000000000000000000000000000000000000000000000001461251460026111ea565b61251d9161246e565b600192612529846111ea565b612533908361246e565b91818061253f836110c2565b92612549826110c2565b612552886110c2565b9461255d8683612487565b612566916124a2565b9061257091612487565b9461257a916111b4565b90612584916111b4565b9061258e916111b4565b61259883806124a2565b6125a1906110c2565b6125ab90866111b4565b6125b491610f86565b6125be90856111b4565b6125c790612ae5565b6125d0906110c2565b916125da916124a2565b6125e3916124c4565b6125ec90612662565b916125f6916111b4565b6125ff916111db565b90612609906110c2565b61039091610f86565b1561261957565b60405162461bcd60e51b815280610c64600482016020808252818101527f53616665436173743a2076616c7565206d75737420626520706f736974697665604082015260600190565b6103909061267a6126725f6110c2565b821215612612565b6110c2565b610390906126936111396103909460ff1690565b901d90565b81156111e557600160ff1b81145f19831416610f9c570590565b6126bc600b610f13565b7f00000000000000000000000000000000000000000000000000000000000000146126e760036111ea565b6126f1908261246e565b8280806126fe600f610f13565b612708600f610f13565b612711916111b4565b61271b600f610f13565b612724916111b4565b938461273060026111ea565b968761273b9161246e565b612744816110c2565b61274e600f610f13565b612757906110c2565b612760866110c2565b61276991612487565b612772916124a2565b61277c600f610f13565b612785906110c2565b61278e91612487565b91612798916111b4565b90806127a3916124a2565b6127ac906110c2565b6127b690846111b4565b6127bf91610f86565b6127c990836111b4565b946127d3906110c2565b82806127df600f610f13565b6127e990856111b4565b906127f3916111b4565b906127fd916111b4565b612806906110c2565b61280f916124c4565b93612819916111b4565b90612823916111b4565b9061282d916111b4565b612836906110c2565b61283f91612487565b9261284a600f610f13565b93818061285760016111ea565b96876128629161246e565b9061286c916111b4565b90612876916111b4565b61287f906110c2565b61288891612487565b93612891611b51565b9061289c908261267f565b946128a6916124a2565b926128b09161246e565b906128ba90612ae5565b6128c3916111b4565b6128cc906110c2565b6128d591612698565b6128de916124c4565b61039090612662565b6103e96129d76128f7600b610f13565b612961612904600c610f13565b6129a361299e612981612977612967612956612920878a6111b4565b986114007f0000000000000000000000000000000000000000000000000000000000000014986129508c8b6111b4565b92610f86565b9561296160026111ea565b9061246e565b966114006001986122be8a6110c2565b611c4660036110c2565b61131a61298e85806111b4565b9161299981806111b4565b6111b4565b612ae5565b6129b3828201612b7c565b612b7c565b9081838211156129de57506129d1926129cc9103612b7c565b900390565b916111ea565b600f61119d565b91506129ae61037b916129d1940390565b7f00000000000000000000000000000000000000000000000000000000000003e85f612a1a816110c2565b821115612a2b5750610390916111db565b9050612a577f0000000000000000000000000000000000000000000000000000000000000000916110c2565b8111612a61575090565b610390916111b4565b7f00000000000000000000000000000000000000000000000000000000000003e85f612a95816110c2565b821115612aa65750610390916111b4565b9050612ad27f0000000000000000000000000000000000000000000000000000000000000000916110c2565b8111612adc575090565b610390916111db565b5f612aef816110c2565b8211612aff5761039091506110c2565b50600180612b0c816111ea565b612b22612b1982866111fd565b61037b846110c2565b93612b3a82612b358761037b81866111db565b6111fd565b935b612b48575b5050505090565b90919293612b538590565b811115612b765750612b6d82612b358661037b81866111db565b92919082612b3c565b93612b41565b5f90612b87826110c2565b90612b95600160ff1b6110c2565b612b9e846110c2565b811115612c3857612bb4600193612961856111ea565b9283612bdf612b19612bce83612bca60036110c2565b0290565b612bca612bda866110c2565b850190565b612be984866111db565b811115612c0c575b505050612c05612b9e9161134f60036111ea565b9050612b95565b8395509061037b612c2a612c0594966129cc612c3095612b9e980290565b956110c2565b93915f612bf1565b5050905090565b60405162461bcd60e51b815260206004820152600b60248201527f556e737570706f727465640000000000000000000000000000000000000000006044820152606490fd5b61039060346110c2565b610390906112116111396103909490565b33612ca981610f27565b905f91612cb5836110c2565b8111612cc057505050565b612cd1612cdf916114006006610f13565b612cd9612c84565b90612c8e565b600790612d01612cfb612cf5610f3d8686610763565b83611216565b946110c2565b8411612d0e575b50505050565b612d1b83612d2093610763565b61119d565b612d4e828261210d7f0000000000000000000000009151434b16b9763660705744891fa906f660ecc561075a565b612d85612d7b7ffc30cddea38e2bf4d6ea7d3f9ed3b6ad7f176419f4963bd81318067a4aee73fe9261075a565b9261047460405190565b0390a25f808080612d08565b6103e990612d9d610c68565b612dee565b15612da957565b60405162461bcd60e51b815260206004820152601760248201527f5265776172644d616e616765723a20746f6f20686967680000000000000000006044820152606490fd5b6103e990612e08612e00610390611b51565b821115612da2565b600861119d565b6103e990612d91565b612e20610c68565b6103e9612e2d6009610f13565b5f90612e3b611139836110c2565b11612e435750565b612e816103e99161267a612e767f0000000000000000000000009151434b16b9763660705744891fa906f660ecc561075a565b33611a676009610f13565b600961119d565b6103e9612e18565b610390906122be610f3d612eb3612cd1612ea985610f27565b6114006006610f13565b926007610763565b61039060036111ea565b610390906124826111396103909490565b612ede610f1d565b612eea6111395f6110c2565b11612ef25750565b612e816103e991612f4b612f44612f3a612f32612f24612f1e611f19612f186008610f13565b886111b4565b80960390565b612f2c612c84565b90612ec5565b611c46610f1d565b610fb06006610f13565b600661119d565b610fb06009610f13565b5f612f5f82610f27565b905f84612f6b826110c2565b841161303c575b612f93612cd1612f8961267a93612f9e9697610f86565b612ea989896130c7565b612d1b866007610763565b8111612fd8575b50612fd3612d7b7fe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c9261075a565b0390a2565b613006818361210d7f0000000000000000000000009151434b16b9763660705744891fa906f660ecc561075a565b7ffc30cddea38e2bf4d6ea7d3f9ed3b6ad7f176419f4963bd81318067a4aee73fe613033612d7b8461075a565b0390a25f612fa5565b612f9e9250612f93612cd1612f8961267a9361306f613061612cd16119a36006610f13565b6122be610f3d8c6007610763565b96509350505050612f72565b1561308257565b60405162461bcd60e51b815260206004820152601f60248201527f45524332303a206d696e7420746f20746865207a65726f2061646472657373006044820152606490fd5b6130d05f610bf2565b6130ee6001600160a01b0382166001600160a01b038416141561307b565b6131066130ff84610fb06003610f13565b600361119d565b613127613114836001610763565b6131218561037b83610f13565b9061119d565b610dc661315d6131577fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9361075a565b9361075a565b9361047460405190565b1561316e57565b60405162461bcd60e51b815280610c64600482016020808252818101527f5265776172644d616e616765723a206e6f7420656e6f75676820616d6f756e74604082015260600190565b6131c081610f27565b6131cc83821015613167565b5f80846131d8826110c2565b8411613299575b612f93612cd16131f661267a936132009697611216565b612ea989896133ae565b8111613235575b50612fd3612d7b7f884edad9ce6fa2440d8a54cc123490eb96d2768479d49ff9c7366125a94243649261075a565b613263818361210d7f0000000000000000000000009151434b16b9763660705744891fa906f660ecc561075a565b7ffc30cddea38e2bf4d6ea7d3f9ed3b6ad7f176419f4963bd81318067a4aee73fe613290612d7b8461075a565b0390a25f613207565b6132009250612f93612cd16131f661267a936132be613061612cd16119a36006610f13565b965093505050506131df565b156132d157565b60405162461bcd60e51b815260206004820152602160248201527f45524332303a206275726e2066726f6d20746865207a65726f2061646472657360448201527f73000000000000000000000000000000000000000000000000000000000000006064820152608490fd5b1561334357565b60405162461bcd60e51b815260206004820152602260248201527f45524332303a206275726e20616d6f756e7420657863656564732062616c616e60448201527f63650000000000000000000000000000000000000000000000000000000000006064820152608490fd5b6133b75f610bf2565b906133d66001600160a01b0383166001600160a01b03831614156132ca565b6134026001612d1b836133fc876133f0610f3d8487610763565b6110488282101561333c565b92610763565b6131276130ff846110486003610f1356fea2646970667358221220aa604a89c59e3e752c604c51c6ecb59367fcba4e584af94b4b1e3a2736f26d8e64736f6c63430008140033

Deployed Bytecode Sourcemap

515:14235:34:-:0;;;;;;;;;-1:-1:-1;515:14235:34;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;:::i;:::-;;:::i;:::-;;:::i;:::-;;:::i;:::-;;:::i;:::-;;:::i;:::-;;:::i;:::-;;:::i;:::-;;:::i;:::-;;:::i;:::-;;:::i;:::-;;:::i;:::-;;:::i;:::-;;:::i;:::-;;:::i;:::-;;:::i;:::-;;:::i;:::-;;:::i;:::-;;:::i;:::-;;:::i;:::-;;:::i;:::-;;:::i;:::-;;:::i;:::-;;:::i;:::-;;:::i;:::-;;:::i;:::-;;:::i;:::-;;:::i;:::-;;:::i;:::-;;:::i;:::-;;:::i;:::-;;:::i;:::-;;:::i;:::-;;:::i;:::-;;:::i;:::-;;:::i;:::-;;:::i;:::-;;:::i;:::-;;:::i;:::-;;:::i;:::-;;:::i;:::-;;:::i;:::-;;:::i;:::-;;:::i;:::-;;:::i;:::-;;:::i;:::-;;;;;;;:::o;:::-;;;;;;;;;;;;-1:-1:-1;;515:14235:34;;;;:::o;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;-1:-1:-1;;515:14235:34;;;;;;:::o;:::-;;;;;;;;;;;:::i;:::-;;:::o;:::-;;;;;;;;:::i;:::-;;;;:::i;:::-;;;;;;;;:::i;:::-;;;;;-1:-1:-1;;;;;515:14235:34;;:::o;:::-;-1:-1:-1;;;;;515:14235:34;;;;;;:::o;:::-;;;;;;;;:::i;:::-;:::o;:::-;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;:::i;:::-;;;;;:::i;:::-;;;;;;;;:::i;:::-;;;:::i;:::-;;;:::o;:::-;;;;;;;;:::i;:::-;;1133:23;515:14235;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;1043:23::-;;;;;:::i;515:14235::-;;;;;;;;:::i;:::-;;;;:::i;:::-;;;;;;;;:::i;:::-;;;;:::i;:::-;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;:::i;:::-;;;;;:::i;:::-;;;;;;;;:::i;:::-;;;:::i;:::-;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;:::i;:::-;;;;;:::i;:::-;;;;;;;;;;:::i;:::-;;;:::i;:::-;;;;;;;;;;;;:::i;:::-;;;;;;;;;:::i;:::-;;;;;;;;:::i;:::-;;;;;:::i;:::-;;;;;;;;;;:::i;:::-;;;;;;:::i;:::-;;;;;;;;;;;;:::i;:::-;;;;;;;;;:::i;:::-;;:::i;:::-;;;-1:-1:-1;515:14235:34;;;;;;;;;:::i;:::-;;:::i;:::-;;;;;;;;:::i;:::-;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;:::i;:::-;;;;;;;;;:::i;:::-;;:::i;1072:29::-;;;;;:::i;515:14235::-;;;;;;;;:::i;:::-;;;;:::i;:::-;;;;;;;;:::i;:::-;;;:::i;:::-;;;;;;;;:::i;:::-;;;:::i;724:27:35:-;;;;;:::i;515:14235:34:-;;;;;;;;:::i;:::-;;;;:::i;:::-;;;;;;;;;;;;:::i;:::-;;;;;;;;;:::i;:::-;;:::i;:::-;;;;;-1:-1:-1;;;;;515:14235:34;;;;;;;:::i;:::-;;;;:::i;:::-;;;;;:::i;:::-;;;;;;;;;:::o;618:58:35:-;;;;;;;;;:::i;:::-;;:::i;515:14235:34:-;;;;;;;;;;:::i;:::-;;:::i;490:30:35:-;;;;;:::i;515:14235:34:-;;;;;;;;:::i;:::-;;;;:::i;:::-;;;;;;;;:::i;:::-;;;:::i;:::-;;;;;;;;:::i;:::-;;;:::i;:::-;;;;;;;;;;:::i;:::-;;:::i;:::-;;;;;;;;:::i;:::-;;;:::i;1107:20::-;;;;;:::i;515:14235::-;;;;;;;;:::i;:::-;;;;:::i;:::-;;;;;;;;:::i;:::-;;;:::i;791:26:35:-;;;;;:::i;515:14235:34:-;;;;;;;;:::i;:::-;;;;:::i;:::-;;;;;;;;;;;;;;;;;:::i;956:24::-;;;;;:::i;515:14235::-;;;;;;;;:::i;:::-;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;:::i;:::-;;;;;;;;;;:::i;:::-;;:::i;1162:13::-;;;;;:::i;515:14235::-;;;;;;;;:::i;:::-;;;;:::i;:::-;;;;;;;;:::i;:::-;;;;:::i;:::-;;;;;;;-1:-1:-1;;;;;515:14235:34;;;;;;;;;;;;;;;;;:::i;:::-;;;:::i;:::-;;;;;;;;:::i;:::-;;;;:::i;:::-;;;;;;;;:::i;:::-;;;;:::i;1013:24::-;;;;;:::i;515:14235::-;;;;;;;;:::i;:::-;;;;:::i;:::-;;;;;;;;:::i;:::-;;;:::i;1468:27::-;;;;;:::i;515:14235::-;;;;;;;;:::i;:::-;;;;:::i;:::-;;;;;;;;;:::i;:::-;;:::i;:::-;;;;;;;;;:::i;:::-;;:::i;:::-;;;;;;;;;:::i;:::-;;:::i;:::-;;;;;;;;;;;;;;;;:::i;:::-;;;;;:::i;:::-;;;;;;;;;;:::i;:::-;;;:::i;1399:26::-;;;;;:::i;515:14235::-;;;;;;;;:::i;:::-;;;;:::i;:::-;;;;;;;;:::i;:::-;;;:::i;:::-;;;;;;;;;:::i;:::-;;:::i;:::-;;;;;;;;;;:::i;:::-;;:::i;:::-;;;;;;;;;;;;;;:::i;986:21::-;;;;;:::i;515:14235::-;;;;;;;;:::i;:::-;;;;:::i;:::-;;;;:::i;:::-;;;;;;;;;;:::i;:::-;;;;;;;;:::i;:::-;;;;;547:28:35;515:14235:34;;:::i;:::-;;;;;;;;;;:::i;1201:85:16:-;1273:6;;;:::i;1063:62::-;;;:::i;:::-;1117:1;;:::i;515:14235:34:-;;;;;;;;;;;:::i;1824:101:16:-;1907:10;;1915:1;1907:10;:::i;:::-;;:::i;1824:101::-;;;:::i;515:14235:34:-;;;;:::o;:::-;;;-1:-1:-1;;;515:14235:34;;;;;;;;;;;;;;;;;;;;;;;;;;;;1359:130:16;1414:68;1422:7;;:::i;:::-;:23;;734:10:23;1433:12:16;655:96:23;1422:23:16;;-1:-1:-1;;;;;515:14235:34;;;1422:23:16;;1414:68;:::i;1063:62::-;1117:1;1063:62;;;:::i;:::-;1117:1;:::i;515:14235:34:-;;;;:::o;:::-;;;-1:-1:-1;;;515:14235:34;;;;;;;;;;;;;;;;;;;;;;;;;2074:198:16;2256:8;2074:198;2154:73;2162:22;2174:10;2182:1;2174:10;:::i;2162:22::-;-1:-1:-1;;;;;515:14235:34;;2162:22:16;;2154:73;:::i;2074:198::-;;;;:::i;515:14235:34:-;;-1:-1:-1;;;;;515:14235:34;;;;;;;;;;:::o;:::-;;;;;;;:::i;:::-;;;;:::i;:::-;;;:::o;2426:187:16:-;2518:6;;;:::i;:::-;2534:17;;;;;:::i;:::-;2566:40;;;;;:::i;:::-;;;:::i;:::-;;;515:14235:34;;;;2566:40:16;;;;;;;2426:187::o;515:14235:34:-;-1:-1:-1;;;515:14235:34;;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;;:::i;:::-;;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;;;;;:::i;:::-;-1:-1:-1;;;515:14235:34;;;;;;;;;;;;-1:-1:-1;;515:14235:34;;;;;;;;;;;;;;:::o;:::-;;:::i;:::-;;;;;;;;;;;;;;;;:::i;:::-;;;;:::i;:::-;;;;:::i;2158:98:17:-;2237:12;2244:5;2237:12;:::i;2369:102::-;2450:14;2457:7;2450:14;:::i;515:14235:34:-;;;;;;;;;;:::i;3255:106:17:-;3342:12;;;:::i;3419:125::-;3519:18;;3419:125;3493:7;515:14235:34;;;3493:7:17;3519:9;;:18;:::i;:::-;;:::i;3740:189::-;734:10:23;515:14235:34;:::i;3987:149:17:-;4102:27;3987:149;4102:18;:27;3987:149;4076:7;515:14235:34;;;4076:7:17;4102:11;;:18;:::i;:::-;:27;:::i;5203:256::-;5387:6;5334:12;734:10:23;5387:6:17;;:::i;515:14235:34:-;-1:-1:-1;;;515:14235:34;;;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;;:::i;5854:234:17:-;6021:38;734:10:23;6021:25:17;;;;;:::i;:::-;:38;:::i;:::-;;;:::i;515:14235:34:-;;;;:::o;:::-;;;-1:-1:-1;;;515:14235:34;;;;;;;;;;;;;;;;;;;;;;;;;6575:427:17;6928:34;734:10:23;6749:25:17;;;;;:::i;:::-;6784:85;6792:35;;;;6784:85;:::i;:::-;515:14235:34;;;;;;;:::o;:::-;;;-1:-1:-1;;;515:14235:34;;;;;;;;;;;;;;;;;;;;11078:411:17;;11205:25;;;;:::i;:::-;-1:-1:-1;;11244:37:17;;11240:243;;11078:411;;;;:::o;11240:243::-;11432:25;;11305:26;11297:68;11305:26;;;;11297:68;:::i;515:14235:34:-;;;;;;;;;;;:::o;:::-;;;-1:-1:-1;;;515:14235:34;;;;;;;;;;;;;;;;;;;;3364:106;3462:1;3364:106;3400:52;3408:10;;;:::i;:::-;:15;;3422:1;3408:15;:::i;:::-;;515:14235;;3408:15;;3400:52;:::i;:::-;3462:1;:::i;515:14235::-;;;;:::o;:::-;;;-1:-1:-1;;;515:14235:34;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;11264:17:17;515:14235:34;;;;;;;;;:::i;:::-;;;;:::i;:::-;;;;;;;;;;;;;;;;:::o;:::-;-1:-1:-1;;;515:14235:34;;;;;;;;;;;;;;;:::o;:::-;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;685:49::-;727:7;;;:::i;:::-;;;;:::o;:::-;515:14235;;-1:-1:-1;;;727:7:34;;;;;;;;;;;515:14235;727:7;515:14235;;;727:7;515:14235;;;3890:1016;4820:8;3890:1016;4820:8;3966:1;;;:::i;:::-;3994:26;;;:::i;:::-;4049:1;4030:41;4038:12;;;:::i;:::-;;;4030:41;:::i;:::-;4132:6;4082:22;:5;:22;:::i;:::-;4105:10;;4125:4;;4117:13;4125:4;4117:13;:::i;:::-;4132:6;;:::i;:::-;4194:20;;;;;;:::i;:::-;;;:::i;:::-;4244:26;:12;;;:::i;:::-;4259:11;;;:::i;:::-;4244:26;;:::i;:::-;4285:9;;;;:::i;:::-;;;:28;;;;;3890:1016;-1:-1:-1;4281:432:34;;;4417:1;4472:25;4405:13;4472:25;4417:1;4405:13;4417:1;4405:13;:::i;:::-;;;:::i;:::-;4432:26;;;;;;:::i;:::-;;;:::i;:::-;4472:25;;;:::i;:::-;;;:::i;:::-;4281:432;;:::i;:::-;4820:1;;;:::i;:::-;:8;:::i;:::-;;;:::i;:::-;4840:59;4848:12;;;:::i;:::-;:32;;4863:17;;:::i;4848:32::-;;4840:59;:::i;4281:432::-;4665:37;4610:12;4666:22;4650:52;4610:12;4582:54;;4598:38;4650:52;4610:12;4599:23;4610:12;;;:::i;:::-;4599:23;;:::i;:::-;4598:38;:::i;:::-;4582:54;;;:::i;:::-;4677:11;;;:::i;:::-;4666:22;;:::i;4650:52::-;4281:432;;4285:28;4298:15;;;;:::i;:::-;;;4285:28;;;3890:1016;;;;:::i;515:14235::-;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;;;;515:14235:34;;;;;;;;;;;;;;;;;;;;;;;;;;1355:203:21;;1482:68;1355:203;1482:68;;1355:203;1482:68;1355:203;1505:27;:18;:27;:::i;:::-;1482:68;;515:14235:34;;;;1482:68:21;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;:::i;:::-;;:::i;515:14235:34:-;;;;;;;;;;;;:::i;:::-;;;;;;;;;;-1:-1:-1;;515:14235:34;;;:::o;:::-;;;;;;:::i;:::-;;:::i;:::-;;;;:::o;:::-;;;;:::i;:::-;;;;;;;:::o;:::-;;;:::i;:::-;;;;;;;;:::i;:::-;;;;;;;;;;;;:::i;:::-;;;;:::o;:::-;;;-1:-1:-1;;;515:14235:34;;;;;;;;;;;;;;;;;;;;;;;;;5196:642:21;5720:111;5196:642;5641:14;:69;5196:642;5641:14;:::i;:::-;:69;;;:::i;:::-;;;:::i;:::-;515:14235:34;;5728:22:21;;5749:1;5728:22;:::i;:::-;;:56;;;;;5196:642;5720:111;;:::i;5728:56::-;5754:30;;;;;;515:14235:34;;;5754:30:21;;;;;;;;:::i;:::-;5728:56;;;4108:223:22;4272:52;;4108:223;4272:52;4308:1;4272:52;:::i;:::-;;;:::i;515:14235:34:-;;;;:::o;:::-;;;-1:-1:-1;;;515:14235:34;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;:::o;:::-;;;:::o;5165:446:22:-;;5487:31;5535:69;5165:446;;;;5330:12;515:14235:34;;;5330:12:22;5370:4;5354:81;5362:13;5370:4;5362:13;:::i;:::-;:30;;:21;:30;;5354:81;:::i;:::-;5487:31;;;;;;;;;;;:::i;:::-;5535:69;;:::i;515:14235:34:-;;;;:::o;:::-;;;-1:-1:-1;;;515:14235:34;;;;;;;;;;;;;;;;;;;;7671:628:22;;;;7875:418;;;-1:-1:-1;515:14235:34;;7906:22:22;;7927:1;7906:22;:::i;:::-;;7902:286;;8201:17;;:::o;7902:286::-;8121:18;8113:60;8121:18;;:::i;:::-;8113:60;:::i;7875:418::-;8269:12;;:::i;1412:320::-;1702:19;:23;;1724:1;1702:23;:::i;:::-;;1412:320;:::o;8821:540::-;;8980:17;;515:14235:34;;;8980:17:22;:21;;9000:1;8980:21;:::i;:::-;;8976:379;;;9152:142;;;;;;;8976:379;9324:20;;;515:14235:34;;;;9324:20:22;;;;-1:-1:-1;;;9324:20:22;;;;;;:::i;515:14235:34:-;;;;:::o;:::-;;;-1:-1:-1;;;515:14235:34;;;;;;;;;;;;;;;;;;;;3576:109;3677:1;3576:109;3613:54;3621:11;;;:::i;:::-;:16;;3636:1;3621:16;:::i;:::-;;3613:54;:::i;:::-;3677:1;:::i;515:14235::-;;;;:::o;:::-;;;-1:-1:-1;;;515:14235:34;;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;;;-1:-1:-1;;;515:14235:34;;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;;;-1:-1:-1;;;515:14235:34;;;;;;;;;;;;;;;;;;;;5106:920;5988:30;5106:920;5186:1;;;:::i;:::-;5905:41;5209:10;5221:8;;;;;:::i;:::-;5550:70;5386:26;:12;;;:::i;:26::-;5423:54;;5439:38;5451:12;5440:23;5451:12;;;:::i;:::-;5440:23;;:::i;5439:38::-;5423:54;;;:::i;:::-;5487:52;;5502:37;5514:11;5503:22;5514:11;;;:::i;5502:37::-;5487:52;;;:::i;:::-;5558:39;;:26;:12;;;:::i;:39::-;;5550:70;:::i;:::-;5696:47;5704:20;5716:8;;;:::i;5704:20::-;;;;;5696:47;:::i;:::-;5800:20;;;;;;:::i;:::-;;;:::i;:::-;5913:8;;:1;;;:::i;:8::-;;5905:41;:::i;:::-;5988:30;5957:18;:5;:18;:::i;:::-;5988:30;;:::i;:::-;;;:::i;5106:920::-;;;;:::i;515:14235::-;-1:-1:-1;;;;;515:14235:34;;;;;;;;;;;;;;;;941:175:21;1050:58;;941:175;1050:58;;941:175;1073:23;:14;:23;:::i;:::-;1050:58;;515:14235:34;;;;1050:58:21;;;;;;;;;;;;:::i;515:14235:34:-;;;;;;;;;;;;:::i;:::-;;;;:::o;:::-;;;-1:-1:-1;;;515:14235:34;;;;;;;;;;;;;;;;;;;;2442:102;;2536:1;2442:102;;;2474:52;2482:6;;;:::i;:::-;:20;2492:10;2482:20;515:14235;2482:20;;2474:52;:::i;:::-;2536:1;:::i;391:31:35:-;419:3;;;:::i;:::-;;;;:::o;:::-;515:14235:34;;-1:-1:-1;;;419:3:35;;;;;;;;;;;515:14235:34;419:3:35;515:14235:34;;;419:3:35;515:14235:34;;;419:3:35;;;;:::o;:::-;515:14235:34;;-1:-1:-1;;;419:3:35;;;;;;;;;;;515:14235:34;419:3:35;515:14235:34;;;419:3:35;515:14235:34;;;2901:358;;2943:1;2901:358;;;2943:1;:::i;:::-;2958:12;;;;:::i;:::-;:26;;2973:11;;;:::i;2958:26::-;;2954:299;;;3000:89;3008:33;3009:16;:11;;;:::i;:::-;3023:2;;:::i;3009:16::-;3029:12;;;:::i;:::-;3008:33;;:::i;:::-;:54;;3045:17;;;:::i;3008:54::-;;;3000:89;:::i;2954:299::-;3110:12;;;:::i;:::-;:26;;3125:11;;;:::i;3110:26::-;;3106:147;;2901:358::o;3106:147::-;3152:90;3160:33;3161:17;:12;;;:::i;:17::-;3182:11;;;:::i;3160:33::-;:54;;3197:17;;;:::i;3160:54::-;;;3152:90;:::i;515:14235::-;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;;;;515:14235:34;;;;;-1:-1:-1;;;;;515:14235:34;;;;;;;;;;;;;;;;;;6543:999;-1:-1:-1;515:14235:34;6700:11;;6768:1;6759:10;6768:1;6759:10;:::i;:::-;;;6755:686;;6543:999;7484:5;;7456:56;7476:14;7484:5;7476:14;:::i;:::-;7456:56;;;;;515:14235;;;;7456:56;;;;;;:::i;:::-;;;;6543:999;:::o;6755:686::-;6789:8;6785:79;;6755:686;6912:12;6893:32;6912:12;;;:::i;:::-;6893:32;:::i;:::-;7008:30;6999:39;7008:30;;;:::i;:::-;6999:39;;:::i;:::-;7165:20;;6993:45;7127:24;;;;;;;:::i;:::-;7165:20;;;:::i;:::-;7221:23;;:9;:4;:9;:::i;:::-;;7231:12;7221:23;7231:12;;;:::i;:::-;7221:23;;515:14235;;;;7221:23;;;;;;;;515:14235;;;;7221:23;;;;;;515:14235;;;;;;7221:23;;;;;;;;;;;;;;6755:686;7262:11;;;;:::i;:::-;:27;-1:-1:-1;7258:102:34;;6755:686;7373:27;;7426:3;7373:27;;;:::i;:::-;7426:3;:::i;:::-;6755:686;;;;7258:102;7318:11;;7426:3;7318:11;7373:27;7318;:11;;;;:::i;:27::-;7258:102;;;;;;;7221:23;;;;;;;;;;;;;;;:::i;:::-;;;;;:::i;:::-;;;;;;;;;;;:::i;6785:79::-;6833:10;6893:32;6912:12;6823:26;6824:19;;6833:10;;;:::i;:::-;6824:19;:::i;:::-;6847:2;;:::i;6823:26::-;6785:79;;;;;6543:999;6684:4;;6543:999;;515:14235;6684:4;:::i;2442:102::-;;2536:1;2442:102;;;;2474:52;2482:6;;;:::i;2474:52::-;2901:358;2943:1;2901:358;;;;2943:1;:::i;515:14235::-;;;;:::o;:::-;;;-1:-1:-1;;;515:14235:34;;;;;;;;;;;;;;;;;;;;8183:1341;-1:-1:-1;515:14235:34;;8183:1341;;515:14235;;;8471:10;515:14235;8471:10;:::i;:::-;;;8467:955;;8183:1341;9466:5;;;9436:58;9458:14;9466:5;9458:14;:::i;:::-;9436:58;;;;;515:14235;;;;8467:955;8497:21;8549:22;8497:21;;;;;;;;:::i;:::-;8549:22;:9;:4;:9;:::i;:::-;;8559:11;8549:22;8559:11;;;:::i;:::-;8549:22;;515:14235;;;;8549:22;;;;;;;;515:14235;;;;8549:22;;;;;;;;;;;;;;8467:955;8589:12;;;;:::i;:::-;:24;-1:-1:-1;8585:155:34;;8467:955;8874:8;8982:20;;9020:8;8874;8854:47;8862:20;8874:8;;;:::i;8862:20::-;;;515:14235;8854:47;8982:20;;;:::i;:::-;9020:8;;515:14235;9020:8;9016:79;;8467:955;9202:13;9282:53;9290:26;9202:13;;9374:6;9202:13;515:14235;;;9202:13;;9244:24;9202:13;9244:24;;;:::i;9290:26::-;;;;9282:53;:::i;:::-;9349:5;:18;:5;:18;:::i;:::-;9374:6;:::i;:::-;9407:3;;;:::i;:::-;8467:955;;;;;9016:79;9064:10;;9374:6;9064:10;9282:53;9290:26;9202:13;9054:26;9055:19;;9064:10;;;:::i;9055:19::-;;;:::i;9054:26::-;9016:79;;;;;;;;;8585:155;8644:12;;;9020:8;8644:24;:12;;;;:::i;:24::-;8633:35;8982:20;;8695:30;8633:35;8695:30;:::i;:::-;8585:155;;;;;;;;8549:22;;;;;;;;;;;;;;;:::i;:::-;;;;;8183:1341;8357:4;;8183:1341;;;515:14235;8357:4;:::i;1063:62:16:-;1117:1;1063:62;;;:::i;:::-;1117:1;:::i;515:14235:34:-;;;;:::o;:::-;;;-1:-1:-1;;;515:14235:34;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;;:::i;9580:156::-;9705:24;9580:156;9650:45;9658:17;9673:2;;:::i;9658:17::-;;;;:::i;:::-;;;9650:45;:::i;:::-;9705:24;;:::i;9580:156::-;;;;:::i;1063:62:16:-;;;:::i;:::-;1117:1;9806::34;;;:::i;:::-;:17;;9810:13;;:::i;9806:17::-;;9802:86;;9742:152::o;9802:86::-;9859:17;9850:7;;:::i;:::-;9859:17;:1;;;:::i;:::-;9863:13;;:::i;:::-;9859:17;;:::i;9742:152::-;;;:::i;1063:62:16:-;1117:1;1063:62;;;:::i;:::-;10135:38:34;9989:191;10073:52;10081:24;10103:2;;:::i;10081:24::-;;;515:14235;10073:52;10135:38;;:::i;9989:191::-;;;;:::i;515:14235::-;;;;:::o;:::-;;;-1:-1:-1;;;515:14235:34;;;;;;;;;;;;;;;;;;;;2640:123;2679:66;2687:13;;;:::i;:::-;:27;2704:10;2687:27;515:14235;2687:27;;2679:66;:::i;:::-;2755:1;10321:14;;10334:1;10321:14;:::i;:::-;;;:::i;10261:81::-;;;:::i;1063:62:16:-;;;:::i;:::-;1117:1;10475:14:34;;10488:1;10475:14;:::i;10422:74::-;;;:::i;2640:123::-;2679:66;2687:13;;;:::i;2679:66::-;2755:1;10641:15;;10655:1;10641:15;:::i;:::-;;;:::i;10580:83::-;;;:::i;1063:62:16:-;;;:::i;:::-;1117:1;10800:15:34;;10814:1;10800:15;:::i;10746:76::-;;;:::i;1063:62:16:-;1117:1;1063:62;;;:::i;:::-;10982:30:34;10903:116;10982:30;;:::i;10903:116::-;;;;:::i;1063:62:16:-;1117:1;1063:62;;;:::i;:::-;1117:1;:::i;515:14235:34:-;;;;;;;;;;;;;;;:::i;:::-;;;;:::i;11094:88::-;11159:16;11094:88;11159:16;;:::i;11094:88::-;;;;:::i;515:14235::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;-1:-1:-1;;;515:14235:34;;;;;;;;;;;;;;;:::o;:::-;;;;;;;;-1:-1:-1;515:14235:34;;;;;;;;;;;;;;:::o;11286:506::-;11357:1;;;:::i;:::-;11398;;:6;11403:1;11398:6;:::i;:::-;;;;:::i;:::-;11430:1;11424:7;;;;:::i;:::-;;;;;:::i;:::-;11478;;;;;;:::i;:::-;11489;;;;:::i;:::-;11499:6;;;:::i;:::-;11489:16;;;;;:::i;:::-;11478:28;;;:::i;:::-;:38;;;;:::i;:::-;11580:7;;;;:::i;:::-;:12;;;;:::i;:::-;:17;;;;:::i;:::-;11609:13;;;;:::i;:::-;11604:19;;;:::i;:::-;11600:23;;;;:::i;:::-;11580:43;;;:::i;:::-;11575:49;;;;:::i;:::-;11707:12;;;:::i;:::-;11703:17;;;:::i;:::-;11723:14;;;;:::i;:::-;11703:34;;;:::i;:::-;11684:54;;;:::i;:::-;11742:6;;;;:::i;:::-;11684:65;;;:::i;:::-;:69;;;;:::i;:::-;;;;:::i;515:14235::-;;;;:::o;:::-;;;-1:-1:-1;;;515:14235:34;;;;;;;;;;;;;;;;;;;;;;;;17187:168:25;17334:14;;17262:55;17270:10;17279:1;17270:10;:::i;:::-;;;;17262:55;:::i;:::-;17334:14;:::i;657:3:34:-;;;;;;;515:14235;;;;657:3;;;;;;;;;;-1:-1:-1;;;657:3:34;;-1:-1:-1;;657:3:34;;;;;;;:::o;11922:595::-;11990:12;;;:::i;:::-;12022:1;:6;12027:1;12022:6;:::i;:::-;;;;;:::i;:::-;12052:1;;;;;;:::i;:::-;12056;;;:::i;:::-;12052:5;;;:::i;:::-;12060:1;;;:::i;:::-;12052:9;;;:::i;:::-;12115:1;;12110:6;12115:1;12110:6;:::i;:::-;;;;;;:::i;:::-;12106:11;;;:::i;:::-;12125:1;;;:::i;:::-;12121:6;;;:::i;:::-;12130;;;:::i;:::-;12121:15;;;:::i;:::-;12106:31;;;:::i;:::-;12144:1;;;:::i;:::-;12140:6;;;:::i;:::-;12106:40;;;:::i;:::-;12202:17;;;;:::i;:::-;12231:7;;;;;:::i;:::-;12226:13;;;:::i;:::-;12222:17;;;;:::i;:::-;12202:37;;;:::i;:::-;12197:43;;;;:::i;:::-;12299:11;;;;:::i;:::-;12328:1;;;;;:::i;:::-;12317:12;;;;:::i;:::-;:16;;;;:::i;:::-;:20;;;;:::i;:::-;12313:25;;;:::i;:::-;12299:39;;;:::i;:::-;12345:6;;;;:::i;:::-;:10;;;;:::i;:::-;:14;;;;:::i;:::-;12341:19;;;:::i;:::-;12299:61;;;:::i;:::-;12368:1;;;;:::i;:::-;12373;;;12368:6;12373:1;12368:6;:::i;:::-;;;;;;:::i;:::-;12367:12;;;;:::i;:::-;:16;;;;:::i;:::-;12363:21;;;:::i;:::-;12299:85;;;:::i;:::-;12459:2;;;:::i;:::-;:7;;;;;:::i;:::-;12472;;;;:::i;:::-;12488:6;;;;:::i;:::-;12498:9;;;;:::i;:::-;12487:20;;;:::i;:::-;12483:25;;;:::i;:::-;12471:37;;;:::i;:::-;12458:51;;;:::i;:::-;12439:71;;;:::i;12523:715::-;13208:13;13213:7;12571:12;;;:::i;:::-;13213:7;12602:11;;;:::i;:::-;12965:33;12971:26;12896;12897:20;12904:7;12833:17;12767:5;;;;:::i;:::-;12792:1;12844:5;12792:1;12833:7;;;;;:::i;:::-;12844:5;;:::i;12833:17::-;12910:1;12904:7;12910:1;12904:7;:::i;:::-;;;:::i;:::-;12915:1;12903:13;12915:1;12903:13;;;;:::i;12897:20::-;12896:26;12921:1;12896:26;:::i;:::-;12984:12;12972:7;;;;:::i;:::-;12984;;;;;:::i;:::-;:12;:::i;12971:26::-;12965:33;:::i;:::-;13042:14;515:14235;;;13042:14;:::i;13048:7::-;13042:14;:::i;:::-;13032:24;;13074:7;;;13070:125;;;-1:-1:-1;13101:20:34;;13107:14;;515:14235;13042:14;:::i;13107:::-;13101:20;515:14235;;;13101:20;13070:125;13213:7;:::i;:::-;13208:13;;:::i;13070:125::-;13172:7;;;13166:14;13172:7;13160:20;13172:7;515:14235;;;13244:289;13328:17;13348:1;13328:21;;;:::i;:::-;;;13324:180;;;13372:26;;;;:::i;13324:180::-;13419:19;;:23;:19;:23;;:::i;:::-;;;13415:89;;13324:180;13244:289;:::o;13415:89::-;13465:28;;;:::i;13539:291::-;13625:17;13645:1;13625:21;;;:::i;:::-;;;13621:180;;;13669:26;;;;:::i;13621:180::-;13716:19;;:23;:19;:23;;:::i;:::-;;;13712:89;;13621:180;13539:291;:::o;13712:89::-;13762:28;;;:::i;13836:377::-;13930:1;13926:5;;;:::i;:::-;;;13922:253;;14188:8;;;;:::i;13922:253::-;13966:1;;13961:6;;;;:::i;:::-;13960:12;13961:6;;;;:::i;:::-;13960:12;;;:::i;:::-;13951:21;13999:16;13951:21;14000:9;13951:21;14004:5;;;;:::i;14000:9::-;13999:16;:::i;:::-;14033:102;13966:1;;;14033:102;14152:8;;;;;:::o;14033:102::-;14040:5;;;;;;515:14235;;14040:5;;;;;;14069;14100:16;14069:5;14101:9;14069:5;14105;;;;:::i;14100:16::-;14033:102;;;;;;14040:5;;;;14219:386;14314:1;14305:10;;;;:::i;:::-;14343:8;14334:17;-1:-1:-1;;;14334:17:34;:::i;:::-;14353:5;;;:::i;:::-;;;;;;14387:7;14393:1;14387:7;;;;:::i;:::-;;;14421:19;:15;:5;:1;:5;:1;:5;:::i;:::-;515:14235;;;14421:5;14430;;;;:::i;:::-;;515:14235;;;14421:19;14462:5;;;;:::i;:::-;:10;-1:-1:-1;14462:10:34;14458:95;;14360:7;;;;;14353:5;14360:7;;14366:1;14360:7;:::i;:::-;14334:17;;;;14458:95;14501:5;;;;14528:6;14496:10;14360:7;14501:5;;;14528:6;14501:5;14353;14501;515:14235;;;14496:10;14528:6;;:::i;:::-;14458:95;;;;;14353:5;;;;;14219:386;:::o;14611:66::-;515:14235;;-1:-1:-1;;;14649:21:34;;515:14235;14649:21;;;515:14235;;;;;;;;;;;;;;357:28:35;383:2;;;:::i;:::-;;;;;;;515:14235:34;;1311:481:35;1384:10;1374:21;;;:::i;:::-;1424:1;;1409:16;;;;:::i;:::-;;;1405:381;;1311:481;;;:::o;1405:381::-;1457:33;1456:40;1472:18;;;;:::i;1457:33::-;1495:1;;:::i;:::-;1456:40;;:::i;:::-;1535:14;:26;1579:11;1525:36;1535:26;;;;;:::i;:::-;1525:36;;:::i;:::-;1579:11;;:::i;:::-;;;1575:201;;1405:381;;1311:481;;;:::o;1575:201::-;1610:26;;:36;:26;;:::i;:::-;:36;:::i;:::-;1695:7;1664:5;;:18;:5;:18;:::i;1695:7::-;1726:35;;;;;:::i;:::-;;;515:14235:34;;;;1726:35:35;;;;1575:201;;;;;;1063:62:16;1117:1;1063:62;;;:::i;:::-;1117:1;:::i;515:14235:34:-;;;;:::o;:::-;;;-1:-1:-1;;;515:14235:34;;;;;;;;;;;;;;;;;;;;1888:187:35;2034:34;1888:187;1966:58;1974:22;1994:2;;:::i;1974:22::-;;;;1966:58;:::i;:::-;2034:34;;:::i;1888:187::-;;;;:::i;1063:62:16:-;;;:::i;:::-;1117:1;2221:14:35;;;:::i;:::-;2238:1;2221:18;;;;;:::i;:::-;;2217:127;;2163:187;:::o;2217:127::-;2315:18;;2255:5;2286:14;2255:18;:5;:18;:::i;:::-;2274:10;2286:14;;;:::i;2315:18::-;;;:::i;2163:187::-;;;:::i;2473:158::-;2556:68;;2604:20;;2557:43;2558:36;:15;;;:::i;:::-;2576:18;;;:::i;2557:43::-;2604:14;;:20;:::i;2742:82::-;2809:8;2816:1;2809:8;:::i;515:14235:34:-;;;;;;;;;2953:378:35;3016:13;;:::i;:::-;:17;;3032:1;3016:17;:::i;:::-;;3012:313;;2953:378;:::o;3012:313::-;3281:33;;3088:15;3210:57;;3232:35;3233:17;3151:31;3072:37;3073:30;3088:15;;;:::i;:::-;3073:30;;:::i;3072:37::-;3049:60;3151:31;515:14235:34;;;3151:31:35;3249:1;;:::i;:::-;3233:17;;:::i;:::-;3254:13;;:::i;3232:35::-;3210:57;;;:::i;:::-;;;:::i;:::-;3281:33;;;:::i;3449:575::-;515:14235:34;3557:13:35;;;:::i;:::-;3537:33;3619:1;3604:16;;;;:::i;:::-;;;3600:120;;3449:575;3813:40;3814:33;3729:24;3792:61;3729:24;3867:11;3729:24;;;:::i;:::-;3773:8;;;;:::i;3813:40::-;3792:18;:14;;:18;:::i;3867:11::-;;;3863:119;;3449:575;3996:21;;;;;;:::i;:::-;;;;3449:575::o;3863:119::-;3917:7;3894:5;;:18;:5;:18;:::i;3917:7::-;3944:27;;;;;:::i;:::-;;;;3863:119;;;3600:120;3867:11;3663:18;;3813:40;3814:33;3729:24;3792:61;3663:18;3646:63;3647:40;3648:33;3663:18;;;:::i;3647:40::-;3691:18;;:14;;:18;:::i;3646:63::-;3600:120;;;;;;;;;515:14235:34;;;;:::o;:::-;;;-1:-1:-1;;;515:14235:34;;;;;;;;;;;;;;;;;;;;8520:535:17;8614:10;8622:1;8614:10;:::i;:::-;8595:65;-1:-1:-1;;;;;515:14235:34;;-1:-1:-1;;;;;515:14235:34;;8603:21:17;;8595:65;:::i;:::-;8731:22;;;;;;:::i;:::-;;;:::i;:::-;8899:28;:18;:9;;:18;:::i;:::-;:28;;;;;:::i;:::-;;;:::i;:::-;8952:37;;;;;;:::i;:::-;;;:::i;:::-;;;515:14235:34;;;;;;;;:::o;:::-;;;-1:-1:-1;;;515:14235:34;;;;;;;;;;;;;;;;;;;;;;;;4147:672:35;4236:15;;;:::i;:::-;4281:69;4289:24;;;;4281:69;:::i;:::-;515:14235:34;4401:1:35;4386:16;;;;:::i;:::-;;;4382:122;;4147:672;4601:40;4602:33;4513:24;4578:63;4513:24;4655:11;4513:24;;;:::i;:::-;4559:8;;;;:::i;4655:11::-;;;4651:123;;4147:672;4788:24;;;;;;:::i;4651:123::-;4707:7;4682:5;;:18;:5;:18;:::i;4707:7::-;4734:29;;;;;:::i;:::-;;;;4651:123;;;4382:122;4655:11;4445:18;;4601:40;4602:33;4513:24;4578:63;4445:18;4428:65;4429:40;4430:33;4445:18;;;:::i;4428:65::-;4382:122;;;;;;;;;515:14235:34;;;;:::o;:::-;;;-1:-1:-1;;;515:14235:34;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;;;-1:-1:-1;;;515:14235:34;;;;;;;;;;;;;;;;;;;;;;;;;9375:659:17;9469:10;9477:1;9469:10;:::i;:::-;9458:21;9450:67;-1:-1:-1;;;;;515:14235:34;;-1:-1:-1;;;;;515:14235:34;;9458:21:17;;9450:67;:::i;:::-;9746:44;9613:9;9746:18;9613;9767:23;9613:18;;;;;;:::i;:::-;9641:71;9649:24;;;;9641:71;:::i;9767:23::-;9746:18;;:::i;:44::-;9883:22;;;;;;:::i

Swarm Source

ipfs://aa604a89c59e3e752c604c51c6ecb59367fcba4e584af94b4b1e3a2736f26d8e

Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

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

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
Loading...
Loading
[ Download: CSV Export  ]

A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.