Sepolia Testnet

Contract

0xa9B38466A776dD9Ec25e5Fe3Ca472eaDcae034b1

Overview

ETH Balance

0 ETH

Multichain Info

N/A
Transaction Hash
Method
Block
From
To
0x60a0806062877652024-07-11 5:28:129 days ago1720675692IN
 Create: Borrowing
0 ETH0.1022226522.0519508

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

Contract Source Code Verified (Exact Match)

Contract Name:
Borrowing

Compiler Version
v0.8.20+commit.a1b79de6

Optimization Enabled:
Yes with 200 runs

Other Settings:
paris EvmVersion
File 1 of 48 : borrowing.sol
// SPDX-License-Identifier: unlicensed
pragma solidity 0.8.20;

import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/ReentrancyGuardUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import "../interface/CDSInterface.sol";
import "../interface/IBorrowing.sol";
import "../interface/IUSDa.sol";
import "../interface/IBorrowLiquidation.sol";
import { IABONDToken } from "../interface/IAbond.sol";
import { BorrowLib } from "../lib/BorrowLib.sol";
import "../interface/ITreasury.sol";
import "../interface/IOptions.sol";
import "../interface/IMultiSign.sol";
import "../interface/IGlobalVariables.sol";
import "../interface/PreviousDeployment/IBorrowing.sol";
import "../interface/PreviousDeployment/ITreasury.sol";
import "hardhat/console.sol";
import {AggregatorV3Interface} from "@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol";
import { MessagingFee} from "@layerzerolabs/lz-evm-oapp-v2/contracts/oapp/OApp.sol";
import { OptionsBuilder } from "@layerzerolabs/lz-evm-oapp-v2/contracts/oapp/libs/OptionsBuilder.sol";

contract Borrowing is IBorrowing,Initializable,UUPSUpgradeable,ReentrancyGuardUpgradeable,OwnableUpgradeable{

    IUSDa  public usda; // our stablecoin
    CDSInterface    private cds;
    IABONDToken private abond; // abond stablecoin
    ITreasury   private treasury;
    IOptions    private options; // options contract interface
    IMultiSign  private multiSign;
    IBorrowLiquidation private borrowLiquiation;

    uint256 private _downSideProtectionLimit;
    address private treasuryAddress; // treasury contract address
    address public admin; // admin address
    uint8   private LTV; // LTV is a percentage eg LTV = 60 is 60%, must be divided by 100 in calculations
    uint8   private APR; 
    uint256 private totalNormalizedAmount; // total normalized amount in protocol
    address private priceFeedAddress; // ETH USD pricefeed address
    uint128 private lastEthprice; // previous eth price
    uint256 private lastEthVaultValue; // previous eth vault value
    uint256 private lastCDSPoolValue; // previous CDS pool value
    uint256 private lastTotalCDSPool;
    uint256 public  lastCumulativeRate; // previous cumulative rate
    uint128 private lastEventTime;
    uint128 private noOfLiquidations; // total number of liquidation happened till now
    uint128 private ratePerSec;
    uint64  private bondRatio;
    bytes32 private DOMAIN_SEPARATOR;
    uint256 private ethRemainingInWithdraw;
    uint256 private ethValueRemainingInWithdraw;
    // uint32  private dstEid; //! dst id
    using OptionsBuilder for bytes;
    // OmniChainBorrowingData private omniChainBorrowing; //! omniChainBorrowing contains global borrowing data(all chains)
    IGlobalVariables private globalVariables;
    
    IOldBorrowing private oldBorrowing;
    IOldTreasury private oldTreasury;

    function initialize( 
        address _tokenAddress,
        address _cds,
        address _abondToken,
        address _multiSign,
        address _priceFeedAddress,
        uint64 chainId,
        address _globalVariables
    ) initializer public{
        __Ownable_init(msg.sender);
        __UUPSUpgradeable_init();
        usda = IUSDa(_tokenAddress);
        cds = CDSInterface(_cds);
        abond = IABONDToken(_abondToken);
        multiSign = IMultiSign(_multiSign);
        globalVariables = IGlobalVariables(_globalVariables);
        priceFeedAddress = _priceFeedAddress;                       //0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419
        DOMAIN_SEPARATOR = keccak256(abi.encode(
            keccak256("EIP712Domain(string name,string version,uint64 chainId,address verifyingContract)"),
            keccak256(bytes(BorrowLib.name)),
            keccak256(bytes(BorrowLib.version)),
            chainId,
            address(this)
        ));
        lastEthprice = uint128(getUSDValue());
        lastEventTime = uint128(block.timestamp);
    }

    function _authorizeUpgrade(address newImplementation) internal onlyOwner override{}

    modifier onlyAdmin(){
        require(msg.sender == admin,"Caller is not an admin");
        _;
    }
    modifier onlyTreasury(){
        require(msg.sender == treasuryAddress,"Function should only be called by treasury");
        _;
    }

    modifier whenNotPaused(IMultiSign.Functions _function) {
        require(!multiSign.functionState(_function),"Paused");
        _;
    }

    // Function to check if an address is a contract
    function isContract(address addr) internal view returns (bool) {
        uint size;
        assembly {
            size := extcodesize(addr)
        }
    return size > 0;
    }

    /**
     * @dev set Treasury contract
     * @param _treasury treasury contract address
     */

    function setTreasury(address _treasury) external onlyAdmin{
        require(_treasury != address(0) && isContract(_treasury) != false, "Treasury must be contract address & can't be zero address");
        require(multiSign.executeSetterFunction(IMultiSign.SetterFunctions(5)));
        treasury = ITreasury(_treasury);
        treasuryAddress = _treasury;
    }

    /**
     * @dev set Options contract
     * @param _options option contract address
     */
    function setOptions(address _options) external onlyAdmin{
        require(_options != address(0) && isContract(_options) != false, "Options must be contract address & can't be zero address");
        options = IOptions(_options);
    }

    function setBorrowLiquidation(address _borrowLiquidation) external onlyAdmin{
        require(_borrowLiquidation != address(0) && isContract(_borrowLiquidation) != false, "Borrow Liquidation must be contract address & can't be zero address");
        borrowLiquiation = IBorrowLiquidation(_borrowLiquidation);
    }

    function setOldBorrow(address _oldBorrow) external onlyAdmin{
        require(_oldBorrow != address(0) && isContract(_oldBorrow) != false, "Old Borrow must be contract address & can't be zero address");
        oldBorrowing = IOldBorrowing(_oldBorrow);
    }

    function setOldTreasury(address _oldTreasury) external onlyAdmin{
        require(_oldTreasury != address(0) && isContract(_oldTreasury) != false, "Old Treasury must be contract address & can't be zero address");
        oldTreasury = IOldTreasury(_oldTreasury);
    }

    /**
     * @dev set admin address
     * @param _admin  admin address
     */
    function setAdmin(address _admin) external onlyOwner{
        require(_admin != address(0) && isContract(_admin) != true, "Admin can't be contract address & zero address");
        require(multiSign.executeSetterFunction(IMultiSign.SetterFunctions(3)));
        admin = _admin;    
    }

    /**
     * @dev Transfer USDa token to the borrower
     * @param _borrower Address of the borrower to transfer
     * @param amount deposited amount of the borrower
     * @param _ethPrice current eth price
     */
    function _transferToken(address _borrower,uint256 amount,uint128 _ethPrice,uint256 optionFees) internal {
        require(_borrower != address(0), "Borrower cannot be zero address");
        require(LTV != 0, "LTV must be set to non-zero value before providing loans");
        
        // tokenValueConversion is in USD, and our stablecoin is pegged to USD in 1:1 ratio
        // Hence if tokenValueConversion = 1, then equivalent stablecoin tokens = tokenValueConversion

        uint256 tokensToLend = BorrowLib.tokensToLend(amount, _ethPrice, LTV);

        //Call the mint function in USDa
        //Mint 80% - options fees to borrower
        bool minted = usda.mint(_borrower, (tokensToLend - optionFees));

        if(!minted){
            revert Borrowing_usdaMintFailed();
        }

        //Mint options fees to treasury
        bool treasuryMint = usda.mint(treasuryAddress,optionFees);

        if(!treasuryMint){
            revert Borrowing_usdaMintFailed();
        }
    }

    /**
     * @dev Transfer Abond token to the borrower
     * @param _toAddress Address of the borrower to transfer
     * @param _amount adond amount to transfer
     */

    function _mintAbondToken(address _toAddress, uint64 _index, uint256 _amount) internal returns(uint128){
        require(_toAddress != address(0), "Borrower cannot be zero address");
        require(_amount != 0,"Amount can't be zero");

        // ABOND:USDa = 4:1
        uint128 amount = BorrowLib.abondToMint(_amount,bondRatio);

        //Call the mint function in ABONDToken
        bool minted = abond.mint(_toAddress, _index, amount);

        if(!minted){
            revert Borrowing_abondMintFailed();
        }
        return amount;
    }

    /**
    * @dev This function takes ethPrice, depositTime, percentageOfEth and receivedType parameters to deposit eth into the contract and mint them back the AMINT tokens.
    * @param _strikePercent percentage increase of eth price
    * @param _strikePrice strike price which the user opted
    * @param _volatility eth volatility
    **/

    function depositTokens (
        IOptions.StrikePrice _strikePercent,
        uint64 _strikePrice,
        uint256 _volatility,
        uint256 _depositingAmount
    ) external payable nonReentrant whenNotPaused(IMultiSign.Functions(0)) {
        require(_depositingAmount > 0, "Cannot deposit zero tokens");
        require(msg.value > _depositingAmount,"Borrowing: Don't have enough LZ fee");
        uint128 _ethPrice = uint128(getUSDValue());
        bytes memory _options = OptionsBuilder.newOptions().addExecutorLzReceiveOption(250000, 0);
        //! calculting fee 
        MessagingFee memory fee = globalVariables.quote(IGlobalVariables.FunctionToDo(1), _options, false);

        //Call calculateInverseOfRatio function to find ratio
        uint64 ratio = calculateRatio(_depositingAmount,uint128(_ethPrice));
        require(ratio >= (2 * BorrowLib.RATIO_PRECISION),"Not enough fund in CDS");

        // Call calculateOptionPrice in options contract to get options fees
        uint256 optionFees = options.calculateOptionPrice(_ethPrice,_volatility,_depositingAmount,_strikePercent);
        uint256 tokensToLend = BorrowLib.tokensToLend(_depositingAmount, _ethPrice, LTV);
        
        //Call the deposit function in Treasury contract
        ITreasury.DepositResult memory depositResult = treasury.deposit{value: _depositingAmount}(
                msg.sender,_ethPrice,uint64(block.timestamp));
        uint64 index = depositResult.borrowerIndex;
        //Check whether the deposit is successfull
        if(!depositResult.hasDeposited){
            revert Borrowing_DepositFailed();
        }
        uint256 aBondCr = treasury.getExternalProtocolCumulativeRate(true);
        abond.setAbondData(msg.sender, index, BorrowLib.calculateHalfValue(_depositingAmount), treasury.getExternalProtocolCumulativeRate(true));
        // Call the transfer function to mint USDa
        _transferToken(msg.sender,_depositingAmount,_ethPrice,optionFees);
        IGlobalVariables.OmniChainData memory omniChainData = globalVariables.getOmniChainData();

        // Call calculateCumulativeRate in cds to split fees to cds users
        omniChainData.lastCumulativeRate = cds.calculateCumulativeRate(uint128(optionFees));
        omniChainData.totalCdsDepositedAmountWithOptionFees += optionFees;

        //Get the deposit details from treasury
        ITreasury.GetBorrowingResult memory getBorrowingResult = treasury.getBorrowing(msg.sender,index);
        ITreasury.DepositDetails memory depositDetail = getBorrowingResult.depositDetails;
        depositDetail.borrowedAmount = uint128(tokensToLend);
        depositDetail.optionFees = uint128(optionFees);
        depositDetail.APR = APR;

        //Update variables in treasury
        treasury.updateHasBorrowed(msg.sender,true);
        treasury.updateTotalBorrowedAmount(msg.sender,tokensToLend);

        //Call calculateCumulativeRate() to get currentCumulativeRate
        calculateCumulativeRate();
        lastEventTime = uint128(block.timestamp);

        // Calculate normalizedAmount
        uint256 normalizedAmount = BorrowLib.calculateNormAmount(tokensToLend,lastCumulativeRate);

        depositDetail.normalizedAmount = uint128(normalizedAmount);
        depositDetail.strikePrice = _strikePrice * uint128(_depositingAmount);

        //Update the deposit details
        treasury.updateDepositDetails(msg.sender,index,depositDetail);

        // Calculate normalizedAmount of Protocol
        totalNormalizedAmount += normalizedAmount;
        lastEthprice = uint128(_ethPrice);
        
        //! updating global data 
        omniChainData.normalizedAmount += normalizedAmount;
        if(index == 1){
            ++omniChainData.noOfBorrowers;
        }
        ++omniChainData.totalNoOfDepositIndices;
        omniChainData.totalVolumeOfBorrowersAmountinWei += _depositingAmount;
        omniChainData.totalVolumeOfBorrowersAmountinUSD += (_ethPrice * _depositingAmount);

        globalVariables.setOmniChainData(omniChainData);
        //! Calling Omnichain send function
        globalVariables.send{value:fee.nativeFee}(IGlobalVariables.FunctionToDo(1), fee, _options,msg.sender);

        emit Deposit(msg.sender,index,_depositingAmount,normalizedAmount,block.timestamp,_ethPrice,tokensToLend,_strikePrice,optionFees,_strikePercent,APR,aBondCr);
    }

    /**
    @dev This function withdraw ETH.
    @param _toAddress The address to whom to transfer ETH.
    @param _index Index of the borrow
    **/

    function withDraw(
        address _toAddress,
        uint64 _index
    ) external payable nonReentrant whenNotPaused(IMultiSign.Functions(1)){
        // check is _toAddress in not a zero address and isContract address
        require(_toAddress != address(0) && isContract(_toAddress) != true, "To address cannot be a zero and contract address");
        uint64 oldIndex = oldTreasury.getTotalIndex(msg.sender);

        if(_index <= oldIndex){
            oldBorrowing.withDraw{value: msg.value}(_toAddress,_index);
        }else{
            uint64 _ethPrice = uint64(getUSDValue());
            calculateRatio(0,_ethPrice);
            lastEthprice = uint128(_ethPrice);

            ITreasury.GetBorrowingResult memory getBorrowingResult = treasury.getBorrowing(msg.sender,_index);
            ITreasury.DepositDetails memory depositDetail = getBorrowingResult.depositDetails;
            IGlobalVariables.OmniChainData memory omniChainData = globalVariables.getOmniChainData();

            // check if borrowerIndex in BorrowerDetails of the msg.sender is greater than or equal to Index
            if(getBorrowingResult.totalIndex >= _index ) {
                // Check if user amount in the Index is been liquidated or not
                require(!depositDetail.liquidated,"User amount has been liquidated");
                // check if withdrawed in depositDetail in borrowing of msg.seader is false or not
                if(depositDetail.withdrawed == false) {                                  
                    // Calculate the borrowingHealth
                    uint128 borrowingHealth = BorrowLib.calculateEthPriceRatio(depositDetail.ethPriceAtDeposit,_ethPrice);
                    require(borrowingHealth > 8000,"BorrowingHealth is Low");
                    // Calculate th borrower's debt
                    uint256 borrowerDebt = BorrowLib.calculateDebtAmount(depositDetail.normalizedAmount, lastCumulativeRate);
                    calculateCumulativeRate();
                    lastEventTime = uint128(block.timestamp);
                    // Check whether the Borrower have enough Trinty
                    require(usda.balanceOf(msg.sender) >= borrowerDebt, "User balance is less than required");
                                
                    // Update the borrower's data
                    {depositDetail.ethPriceAtWithdraw = _ethPrice;
                    depositDetail.withdrawed = true;
                    depositDetail.withdrawTime = uint64(block.timestamp);
                    // Calculate interest for the borrower's debt
                    //uint256 interest = borrowerDebt - depositDetail.borrowedAmount;

                    uint256 discountedETH = BorrowLib.calculateDiscountedETH(depositDetail.depositedAmount,_ethPrice); // 0.4
                    omniChainData.abondUSDaPool += discountedETH;
                    treasury.updateAbondUSDaPool(discountedETH,true);
                    // Calculate the amount of USDa to burn and sent to the treasury
                    // uint256 halfValue = (50 *(depositDetail.borrowedAmount))/100;
                    //!console.log("BORROWED AMOUNT",depositDetail.borrowedAmount);
                    //!console.log("DISCOUNTED ETH",discountedETH);
                    uint256 burnValue = depositDetail.borrowedAmount - discountedETH;
                    //!console.log("BURN VALUE",burnValue);
                    // Burn the USDa from the Borrower
                    bool success = usda.burnFromUser(msg.sender, burnValue);
                    if(!success){
                        revert Borrowing_WithdrawBurnFailed();
                    }

                    //Transfer the remaining USDa to the treasury
                    bool transfer = usda.transferFrom(msg.sender,treasuryAddress,borrowerDebt - burnValue);
                    if(!transfer){
                        revert Borrowing_WithdrawUSDaTransferFailed();
                    }
                    //Update totalNormalizedAmount
                    totalNormalizedAmount -= depositDetail.normalizedAmount;
                    omniChainData.normalizedAmount -= depositDetail.normalizedAmount;
                    //!console.log("borrowerDebt",borrowerDebt);
                    omniChainData.totalInterest += borrowerDebt - depositDetail.borrowedAmount;
                    treasury.updateTotalInterest(borrowerDebt - depositDetail.borrowedAmount);

                    // Mint the ABondTokens
                    uint128 noOfAbondTokensminted = _mintAbondToken(msg.sender, _index, discountedETH);
                    // Update ABONDToken data
                    depositDetail.aBondTokensAmount = noOfAbondTokensminted;

                    // Update deposit details    
                    treasury.updateDepositDetails(msg.sender,_index,depositDetail);}             
                    uint128 ethToReturn;
                    //Calculate current depositedAmount value
                    uint128 depositedAmountvalue = (depositDetail.depositedAmount * depositDetail.ethPriceAtDeposit)/_ethPrice;

                    if(borrowingHealth > 10000){
                        // If the ethPrice is higher than deposit ethPrice,call withdrawOption in options contract
                        ethToReturn = (depositedAmountvalue + (options.calculateStrikePriceGains(depositDetail.depositedAmount,depositDetail.strikePrice,_ethPrice)));
                        if(ethToReturn > depositDetail.depositedAmount){
                            ethRemainingInWithdraw += (ethToReturn - depositDetail.depositedAmount);
                            omniChainData.ethRemainingInWithdraw += (ethToReturn - depositDetail.depositedAmount);
                        }else{
                            ethRemainingInWithdraw += (depositDetail.depositedAmount - ethToReturn);
                            omniChainData.ethRemainingInWithdraw += (depositDetail.depositedAmount - ethToReturn);
                        }
                        ethValueRemainingInWithdraw += (ethRemainingInWithdraw * _ethPrice);
                        omniChainData.ethValueRemainingInWithdraw += (ethRemainingInWithdraw * _ethPrice);
                    }else if(borrowingHealth == 10000){
                        ethToReturn = depositedAmountvalue;
                    }else if(8000 < borrowingHealth && borrowingHealth < 10000) {
                        ethToReturn = depositDetail.depositedAmount;
                    }else{
                        revert("BorrowingHealth is Low");
                    }
                    ethToReturn = BorrowLib.calculateHalfValue(ethToReturn);

                    bytes memory _options = OptionsBuilder.newOptions().addExecutorLzReceiveOption(200000, 0);
                    //! calculting fee 
                    MessagingFee memory fee = globalVariables.quote(IGlobalVariables.FunctionToDo(1), _options, false);
                    if(treasury.getTotalDeposited(msg.sender) == depositDetail.depositedAmount){
                        --omniChainData.noOfBorrowers;
                    }
                    --omniChainData.totalNoOfDepositIndices;
                    omniChainData.totalVolumeOfBorrowersAmountinWei += depositDetail.depositedAmount;
                    omniChainData.totalVolumeOfBorrowersAmountinUSD += depositDetail.depositedAmountUsdValue;

                    globalVariables.setOmniChainData(omniChainData);

                    // Call withdraw in treasury
                    bool sent = treasury.withdraw(msg.sender,_toAddress,ethToReturn,_index);
                    if(!sent){
                        revert Borrowing_WithdrawEthTransferFailed();
                    }

                    //! Calling Omnichain send function
                    globalVariables.send{value:fee.nativeFee}(IGlobalVariables.FunctionToDo(1), fee, _options,msg.sender);
                    emit Withdraw(msg.sender,_index,block.timestamp,ethToReturn,depositDetail.aBondTokensAmount,borrowerDebt);
                }else{
                    // update withdrawed to true
                    revert("User already withdraw entire amount");
                }
            }else {
                // revert if user doens't have the perticular index
                revert("User doens't have the perticular index");
            }
        }
    }

    function redeemYields(address user,uint128 aBondAmount) public returns(uint256){
        return (BorrowLib.redeemYields(user, aBondAmount, address(usda), address(abond), address(treasury)));
    }

    function getAbondYields(address user,uint128 aBondAmount) public view returns(uint128,uint256,uint256){
        return (BorrowLib.getAbondYields(user, aBondAmount, address(abond), address(treasury)));
    }

    /**
     * @dev This function liquidate ETH which are below downside protection.
     * @param user The address to whom to liquidate ETH.
     * @param index Index of the borrow
     */

    function liquidate(
        address user,
        uint64 index
    ) external payable whenNotPaused(IMultiSign.Functions(2)) onlyAdmin{

        // Check whether the liquidator 
        require(user != address(0), "To address cannot be a zero address");
        require(msg.sender != user,"You cannot liquidate your own assets!");

        calculateCumulativeRate();
        bytes memory _options = OptionsBuilder.newOptions().addExecutorLzReceiveOption(250000, 0);

        MessagingFee memory fee = globalVariables.quote(IGlobalVariables.FunctionToDo(2), _options, false);
        
        ++noOfLiquidations;

        (CDSInterface.LiquidationInfo memory liquidationInfo ) = borrowLiquiation.liquidateBorrowPosition{value: msg.value - fee.nativeFee}(
            user,
            index,
            uint64(getUSDValue()),
            lastCumulativeRate
        );

        //! Calling Omnichain send function
        globalVariables.sendForLiquidation{value:fee.nativeFee}(
            IGlobalVariables.FunctionToDo(2), 
            noOfLiquidations,
            liquidationInfo, 
            fee, 
            _options,
            msg.sender);

    }

    /**
     * @dev get the usd value of ETH
     */
    function getUSDValue() public view returns(uint256){
        AggregatorV3Interface priceFeed = AggregatorV3Interface(priceFeedAddress);
        (,int256 price,,,) = priceFeed.latestRoundData();
        return (uint256(price) / BorrowLib.PRECISION);
    }

    function setLTV(uint8 _LTV) external onlyAdmin {
        require(_LTV != 0, "LTV can't be zero");
        require(multiSign.executeSetterFunction(IMultiSign.SetterFunctions(0)));
        LTV = _LTV;
    }

    function setBondRatio(uint64 _bondRatio) external onlyAdmin {
        require(_bondRatio != 0, "Bond Ratio can't be zero");
        require(multiSign.executeSetterFunction(IMultiSign.SetterFunctions(7)));
        bondRatio = _bondRatio;
    }

    function getLTV() public view returns(uint8){
        return LTV;
    }

    // function getLastEthVaultValue() public view returns(uint256){
    //     return (lastEthVaultValue/100);
    // }

    /**
     * @dev update the last eth vault value
     * @param _amount eth vault value
     */
    function updateLastEthVaultValue(uint256 _amount) external onlyTreasury{
        require(_amount != 0,"Last ETH vault value can't be zero");
        IGlobalVariables.OmniChainData memory omniChainData = globalVariables.getOmniChainData();
        omniChainData.ethVaultValue += _amount;
        globalVariables.setOmniChainData(omniChainData);
    }

    /**
     * @dev calculate the ratio of CDS Pool/Eth Vault
     * @param _amount amount to be depositing
     * @param currentEthPrice current eth price in usd
     */
    function calculateRatio(uint256 _amount,uint currentEthPrice) public returns(uint64){

        if(currentEthPrice == 0){
            revert Borrowing_GettingETHPriceFailed();
        }

        IGlobalVariables.OmniChainData memory omniChainData = globalVariables.getOmniChainData();

        (uint64 ratio, IGlobalVariables.OmniChainData memory omniChainDataFromLib) = BorrowLib.calculateRatio(
            _amount,
            currentEthPrice,
            lastEthprice,
            omniChainData.totalNoOfDepositIndices,
            omniChainData.totalCdsDepositedAmount,
            omniChainData  //! using global data instead of individual chain data
            );

        //! updating global data 
        globalVariables.setOmniChainData(omniChainDataFromLib);

        return ratio;
    }

    function setAPR(uint8 _APR, uint128 _ratePerSec) external whenNotPaused(IMultiSign.Functions(3)) onlyAdmin{
        require(_ratePerSec != 0 && _APR != 0,"Rate should not be zero");
        require(multiSign.executeSetterFunction(IMultiSign.SetterFunctions(1)));
        APR = _APR;
        ratePerSec = _ratePerSec;
    }

    /**
     * @dev calculate cumulative rate 
     */
    function calculateCumulativeRate() public returns(uint256){
        // Get the noOfBorrowers
        uint128 noOfBorrowers = treasury.noOfBorrowers();

        uint256 currentCumulativeRate = BorrowLib.calculateCumulativeRate(noOfBorrowers, ratePerSec, lastEventTime, lastCumulativeRate);
        lastCumulativeRate = currentCumulativeRate;
        return currentCumulativeRate;
    }

    function updateRatePerSecByUSDaPrice(uint32 usdaPrice) public onlyAdmin{
        if(usdaPrice <= 0) revert("Invalid USDa price");
        (ratePerSec, APR) = BorrowLib.calculateNewAPRToUpdate(usdaPrice);
    }
}

File 2 of 48 : AggregatorV3Interface.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface AggregatorV3Interface {
  function decimals() external view returns (uint8);

  function description() external view returns (string memory);

  function version() external view returns (uint256);

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

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

File 3 of 48 : DVNOptions.sol
// 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;
        }
    }
}

File 4 of 48 : IOAppCore.sol
// 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();
    error EndPointUnavailable();

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

File 5 of 48 : IOAppReceiver.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

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

interface IOAppReceiver is ILayerZeroReceiver {
    /**
     * @notice Indicates whether an address is an approved composeMsg sender to the Endpoint.
     * @param _origin The origin information containing the source endpoint and sender address.
     *  - srcEid: The source chain endpoint ID.
     *  - sender: The sender address on the src chain.
     *  - nonce: The nonce of the message.
     * @param _message The lzReceive payload.
     * @param _sender The sender address.
     * @return isSender Is a valid sender.
     *
     * @dev Applications can optionally choose to implement a separate composeMsg sender that is NOT the bridging layer.
     * @dev The default sender IS the OAppReceiver implementer.
     */
    function isComposeMsgSender(
        Origin calldata _origin,
        bytes calldata _message,
        address _sender
    ) external view returns (bool isSender);
}

File 6 of 48 : OptionsBuilder.sol
// 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-protocol-v2/contracts/messagelib/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 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);
    }
}

File 7 of 48 : OApp.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

// @dev Import the 'MessagingFee' and 'MessagingReceipt' so it's exposed to OApp implementers
// solhint-disable-next-line no-unused-import
import { OAppSender, MessagingFee, MessagingReceipt } from "./OAppSender.sol";
// @dev Import the 'Origin' so it's exposed to OApp implementers
// solhint-disable-next-line no-unused-import
import { OAppReceiver, Origin } from "./OAppReceiver.sol";
import { OAppCore } from "./OAppCore.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";

/**
 * @title OApp
 * @dev Abstract contract serving as the base for OApp implementation, combining OAppSender and OAppReceiver functionality.
 */
abstract contract OApp is Initializable, OAppSender, OAppReceiver {
    /**
     * @dev Constructor to initialize the OApp with the provided endpoint and owner.
     * @param _endpoint The address of the LOCAL LayerZero endpoint.
     * @param _delegate The delegate capable of making OApp configurations inside of the endpoint.
     */
    // constructor(address _endpoint, address _delegate) OAppCore(_endpoint, _delegate) {}

    function __oAppinit(address _endpoint, address _delegate) internal {
        __oAppCoreinit(_endpoint, _delegate);
    }

    /**
     * @notice Retrieves the OApp version information.
     * @return senderVersion The version of the OAppSender.sol implementation.
     * @return receiverVersion The version of the OAppReceiver.sol implementation.
     */
    function oAppVersion()
        public
        pure
        virtual
        override(OAppSender, OAppReceiver)
        returns (uint64 senderVersion, uint64 receiverVersion)
    {
        return (SENDER_VERSION, RECEIVER_VERSION);
    }
}

File 8 of 48 : OAppCore.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.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 Initializable, IOAppCore, OwnableUpgradeable {
    // The LayerZero endpoint associated with the given OApp
    ILayerZeroEndpointV2 public 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);
    // }

    function __oAppCoreinit(address _endpoint, address _delegate) internal {
        if (_endpoint == address(0)) revert EndPointUnavailable();
        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);
    }
}

File 9 of 48 : OAppReceiver.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

import { IOAppReceiver, Origin } from "./interfaces/IOAppReceiver.sol";
import { OAppCore } from "./OAppCore.sol";

/**
 * @title OAppReceiver
 * @dev Abstract contract implementing the ILayerZeroReceiver interface and extending OAppCore for OApp receivers.
 */
abstract contract OAppReceiver is IOAppReceiver, OAppCore {
    // Custom error message for when the caller is not the registered endpoint/
    error OnlyEndpoint(address addr);

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

    /**
     * @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 OAppSender version. Indicates that the OAppSender is not implemented.
     * ie. this is a RECEIVE 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 (0, RECEIVER_VERSION);
    }

    /**
     * @notice Indicates whether an address is an approved composeMsg sender to the Endpoint.
     * @dev _origin The origin information containing the source endpoint and sender address.
     *  - srcEid: The source chain endpoint ID.
     *  - sender: The sender address on the src chain.
     *  - nonce: The nonce of the message.
     * @dev _message The lzReceive payload.
     * @param _sender The sender address.
     * @return isSender Is a valid sender.
     *
     * @dev Applications can optionally choose to implement separate composeMsg senders that are NOT the bridging layer.
     * @dev The default sender IS the OAppReceiver implementer.
     */
    function isComposeMsgSender(
        Origin calldata /*_origin*/,
        bytes calldata /*_message*/,
        address _sender
    ) public view virtual returns (bool) {
        return _sender == address(this);
    }

    /**
     * @notice Checks if the path initialization is allowed based on the provided origin.
     * @param origin The origin information containing the source endpoint and sender address.
     * @return Whether the path has been initialized.
     *
     * @dev This indicates to the endpoint that the OApp has enabled msgs for this particular path to be received.
     * @dev This defaults to assuming if a peer has been set, its initialized.
     * Can be overridden by the OApp if there is other logic to determine this.
     */
    function allowInitializePath(Origin calldata origin) public view virtual returns (bool) {
        return peers[origin.srcEid] == origin.sender;
    }

    /**
     * @notice Retrieves the next nonce for a given source endpoint and sender address.
     * @dev _srcEid The source endpoint ID.
     * @dev _sender The sender address.
     * @return nonce The next nonce.
     *
     * @dev The path nonce starts from 1. If 0 is returned it means that there is NO nonce ordered enforcement.
     * @dev Is required by the off-chain executor to determine the OApp expects msg execution is ordered.
     * @dev This is also enforced by the OApp.
     * @dev By default this is NOT enabled. ie. nextNonce is hardcoded to return 0.
     */
    function nextNonce(uint32 /*_srcEid*/, bytes32 /*_sender*/) public view virtual returns (uint64 nonce) {
        return 0;
    }

    /**
     * @dev Entry point for receiving messages or packets from the endpoint.
     * @param _origin The origin information containing the source endpoint and sender address.
     *  - srcEid: The source chain endpoint ID.
     *  - sender: The sender address on the src chain.
     *  - nonce: The nonce of the message.
     * @param _guid The unique identifier for the received LayerZero message.
     * @param _message The payload of the received message.
     * @param _executor The address of the executor for the received message.
     * @param _extraData Additional arbitrary data provided by the corresponding executor.
     *
     * @dev Entry point for receiving msg/packet from the LayerZero endpoint.
     */
    function lzReceive(
        Origin calldata _origin,
        bytes32 _guid,
        bytes calldata _message,
        address _executor,
        bytes calldata _extraData
    ) public payable virtual {
        // Ensures that only the endpoint can attempt to lzReceive() messages to this OApp.
        if (address(endpoint) != msg.sender) revert OnlyEndpoint(msg.sender);

        // Ensure that the sender matches the expected peer for the source endpoint.
        if (_getPeerOrRevert(_origin.srcEid) != _origin.sender) revert OnlyPeer(_origin.srcEid, _origin.sender);

        // Call the internal OApp implementation of lzReceive.
        _lzReceive(_origin, _guid, _message, _executor, _extraData);
    }

    /**
     * @dev Internal function to implement lzReceive logic without needing to copy the basic parameter validation.
     */
    function _lzReceive(
        Origin calldata _origin,
        bytes32 _guid,
        bytes calldata _message,
        address _executor,
        bytes calldata _extraData
    ) internal virtual;
}

File 10 of 48 : OAppSender.sol
// 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";
import "hardhat/console.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);
        
          //  solhint-disable-next-line check-send-result
        receipt = 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);
    }
}

File 11 of 48 : IOFT.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

import { MessagingReceipt, MessagingFee } from "../../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 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 a quote for OFT-related operations.
     * @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);
}

File 12 of 48 : ILayerZeroEndpointV2.sol
// 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;
}

File 13 of 48 : ILayerZeroReceiver.sol
// SPDX-License-Identifier: MIT

pragma solidity >=0.8.0;

import { Origin } from "./ILayerZeroEndpointV2.sol";

interface ILayerZeroReceiver {
    function allowInitializePath(Origin calldata _origin) external view returns (bool);

    function nextNonce(uint32 _eid, bytes32 _sender) external view returns (uint64);

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

File 14 of 48 : IMessageLibManager.sol
// 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 _timeout) 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 _gracePeriod) 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);
}

File 15 of 48 : IMessagingChannel.sol
// 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);
}

File 16 of 48 : IMessagingComposer.sol
// 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;
}

File 17 of 48 : IMessagingContext.sol
// 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);
}

File 18 of 48 : CalldataBytesLib.sol
// 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]);
        }
    }
}

File 19 of 48 : BitMaps.sol
// 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);
    }
}

File 20 of 48 : ExecutorOptions.sol
// 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);
    }
}

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

pragma solidity ^0.8.20;

import {ContextUpgradeable} from "../utils/ContextUpgradeable.sol";
import {Initializable} from "../proxy/utils/Initializable.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * The initial owner is set to the address provided by the deployer. This can
 * later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {
    /// @custom:storage-location erc7201:openzeppelin.storage.Ownable
    struct OwnableStorage {
        address _owner;
    }

    // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Ownable")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 private constant OwnableStorageLocation = 0x9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c199300;

    function _getOwnableStorage() private pure returns (OwnableStorage storage $) {
        assembly {
            $.slot := OwnableStorageLocation
        }
    }

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

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

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

    /**
     * @dev Initializes the contract setting the address provided by the deployer as the initial owner.
     */
    function __Ownable_init(address initialOwner) internal {
        __Ownable_init_unchained(initialOwner);
    }

    function __Ownable_init_unchained(address initialOwner) internal {
        if (initialOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(initialOwner);
    }

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

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

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        if (owner() != _msgSender()) {
            revert OwnableUnauthorizedAccount(_msgSender());
        }
    }

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

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        if (newOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(newOwner);
    }

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

File 22 of 48 : Initializable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/utils/Initializable.sol)

pragma solidity ^0.8.20;

/**
 * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
 * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
 * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
 * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
 *
 * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
 * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
 * case an upgrade adds a module that needs to be initialized.
 *
 * For example:
 *
 * [.hljs-theme-light.nopadding]
 * ```solidity
 * contract MyToken is ERC20Upgradeable {
 *     function initialize() initializer public {
 *         __ERC20_init("MyToken", "MTK");
 *     }
 * }
 *
 * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
 *     function initializeV2() reinitializer(2) public {
 *         __ERC20Permit_init("MyToken");
 *     }
 * }
 * ```
 *
 * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
 * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
 *
 * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
 * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
 *
 * [CAUTION]
 * ====
 * Avoid leaving a contract uninitialized.
 *
 * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
 * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
 * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
 *
 * [.hljs-theme-light.nopadding]
 * ```
 * /// @custom:oz-upgrades-unsafe-allow constructor
 * constructor() {
 *     _disableInitializers();
 * }
 * ```
 * ====
 */
abstract contract Initializable {
    /**
     * @dev Storage of the initializable contract.
     *
     * It's implemented on a custom ERC-7201 namespace to reduce the risk of storage collisions
     * when using with upgradeable contracts.
     *
     * @custom:storage-location erc7201:openzeppelin.storage.Initializable
     */
    struct InitializableStorage {
        /**
         * @dev Indicates that the contract has been initialized.
         */
        uint64 _initialized;
        /**
         * @dev Indicates that the contract is in the process of being initialized.
         */
        bool _initializing;
    }

    // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Initializable")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 private constant INITIALIZABLE_STORAGE = 0xf0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00;

    /**
     * @dev The contract is already initialized.
     */
    error InvalidInitialization();

    /**
     * @dev The contract is not initializing.
     */
    error NotInitializing();

    /**
     * @dev Triggered when the contract has been initialized or reinitialized.
     */
    event Initialized(uint64 version);

    /**
     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
     * `onlyInitializing` functions can be used to initialize parent contracts.
     *
     * Similar to `reinitializer(1)`, except that in the context of a constructor an `initializer` may be invoked any
     * number of times. This behavior in the constructor can be useful during testing and is not expected to be used in
     * production.
     *
     * Emits an {Initialized} event.
     */
    modifier initializer() {
        // solhint-disable-next-line var-name-mixedcase
        InitializableStorage storage $ = _getInitializableStorage();

        // Cache values to avoid duplicated sloads
        bool isTopLevelCall = !$._initializing;
        uint64 initialized = $._initialized;

        // Allowed calls:
        // - initialSetup: the contract is not in the initializing state and no previous version was
        //                 initialized
        // - construction: the contract is initialized at version 1 (no reininitialization) and the
        //                 current contract is just being deployed
        bool initialSetup = initialized == 0 && isTopLevelCall;
        bool construction = initialized == 1 && address(this).code.length == 0;

        if (!initialSetup && !construction) {
            revert InvalidInitialization();
        }
        $._initialized = 1;
        if (isTopLevelCall) {
            $._initializing = true;
        }
        _;
        if (isTopLevelCall) {
            $._initializing = false;
            emit Initialized(1);
        }
    }

    /**
     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
     * used to initialize parent contracts.
     *
     * A reinitializer may be used after the original initialization step. This is essential to configure modules that
     * are added through upgrades and that require initialization.
     *
     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
     * cannot be nested. If one is invoked in the context of another, execution will revert.
     *
     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
     * a contract, executing them in the right order is up to the developer or operator.
     *
     * WARNING: Setting the version to 2**64 - 1 will prevent any future reinitialization.
     *
     * Emits an {Initialized} event.
     */
    modifier reinitializer(uint64 version) {
        // solhint-disable-next-line var-name-mixedcase
        InitializableStorage storage $ = _getInitializableStorage();

        if ($._initializing || $._initialized >= version) {
            revert InvalidInitialization();
        }
        $._initialized = version;
        $._initializing = true;
        _;
        $._initializing = false;
        emit Initialized(version);
    }

    /**
     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
     * {initializer} and {reinitializer} modifiers, directly or indirectly.
     */
    modifier onlyInitializing() {
        _checkInitializing();
        _;
    }

    /**
     * @dev Reverts if the contract is not in an initializing state. See {onlyInitializing}.
     */
    function _checkInitializing() internal view virtual {
        if (!_isInitializing()) {
            revert NotInitializing();
        }
    }

    /**
     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called
     * through proxies.
     *
     * Emits an {Initialized} event the first time it is successfully executed.
     */
    function _disableInitializers() internal virtual {
        // solhint-disable-next-line var-name-mixedcase
        InitializableStorage storage $ = _getInitializableStorage();

        if ($._initializing) {
            revert InvalidInitialization();
        }
        if ($._initialized != type(uint64).max) {
            $._initialized = type(uint64).max;
            emit Initialized(type(uint64).max);
        }
    }

    /**
     * @dev Returns the highest version that has been initialized. See {reinitializer}.
     */
    function _getInitializedVersion() internal view returns (uint64) {
        return _getInitializableStorage()._initialized;
    }

    /**
     * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
     */
    function _isInitializing() internal view returns (bool) {
        return _getInitializableStorage()._initializing;
    }

    /**
     * @dev Returns a pointer to the storage namespace.
     */
    // solhint-disable-next-line var-name-mixedcase
    function _getInitializableStorage() private pure returns (InitializableStorage storage $) {
        assembly {
            $.slot := INITIALIZABLE_STORAGE
        }
    }
}

File 23 of 48 : UUPSUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/utils/UUPSUpgradeable.sol)

pragma solidity ^0.8.20;

import {IERC1822Proxiable} from "@openzeppelin/contracts/interfaces/draft-IERC1822.sol";
import {ERC1967Utils} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol";
import {Initializable} from "./Initializable.sol";

/**
 * @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an
 * {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy.
 *
 * A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is
 * reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing
 * `UUPSUpgradeable` with a custom implementation of upgrades.
 *
 * The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism.
 */
abstract contract UUPSUpgradeable is Initializable, IERC1822Proxiable {
    /// @custom:oz-upgrades-unsafe-allow state-variable-immutable
    address private immutable __self = address(this);

    /**
     * @dev The version of the upgrade interface of the contract. If this getter is missing, both `upgradeTo(address)`
     * and `upgradeToAndCall(address,bytes)` are present, and `upgradeTo` must be used if no function should be called,
     * while `upgradeToAndCall` will invoke the `receive` function if the second argument is the empty byte string.
     * If the getter returns `"5.0.0"`, only `upgradeToAndCall(address,bytes)` is present, and the second argument must
     * be the empty byte string if no function should be called, making it impossible to invoke the `receive` function
     * during an upgrade.
     */
    string public constant UPGRADE_INTERFACE_VERSION = "5.0.0";

    /**
     * @dev The call is from an unauthorized context.
     */
    error UUPSUnauthorizedCallContext();

    /**
     * @dev The storage `slot` is unsupported as a UUID.
     */
    error UUPSUnsupportedProxiableUUID(bytes32 slot);

    /**
     * @dev Check that the execution is being performed through a delegatecall call and that the execution context is
     * a proxy contract with an implementation (as defined in ERC1967) pointing to self. This should only be the case
     * for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a
     * function through ERC1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to
     * fail.
     */
    modifier onlyProxy() {
        _checkProxy();
        _;
    }

    /**
     * @dev Check that the execution is not being performed through a delegate call. This allows a function to be
     * callable on the implementing contract but not through proxies.
     */
    modifier notDelegated() {
        _checkNotDelegated();
        _;
    }

    function __UUPSUpgradeable_init() internal onlyInitializing {
    }

    function __UUPSUpgradeable_init_unchained() internal onlyInitializing {
    }
    /**
     * @dev Implementation of the ERC1822 {proxiableUUID} function. This returns the storage slot used by the
     * implementation. It is used to validate the implementation's compatibility when performing an upgrade.
     *
     * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
     * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
     * function revert if invoked through a proxy. This is guaranteed by the `notDelegated` modifier.
     */
    function proxiableUUID() external view virtual notDelegated returns (bytes32) {
        return ERC1967Utils.IMPLEMENTATION_SLOT;
    }

    /**
     * @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call
     * encoded in `data`.
     *
     * Calls {_authorizeUpgrade}.
     *
     * Emits an {Upgraded} event.
     *
     * @custom:oz-upgrades-unsafe-allow-reachable delegatecall
     */
    function upgradeToAndCall(address newImplementation, bytes memory data) public payable virtual onlyProxy {
        _authorizeUpgrade(newImplementation);
        _upgradeToAndCallUUPS(newImplementation, data);
    }

    /**
     * @dev Reverts if the execution is not performed via delegatecall or the execution
     * context is not of a proxy with an ERC1967-compliant implementation pointing to self.
     * See {_onlyProxy}.
     */
    function _checkProxy() internal view virtual {
        if (
            address(this) == __self || // Must be called through delegatecall
            ERC1967Utils.getImplementation() != __self // Must be called through an active proxy
        ) {
            revert UUPSUnauthorizedCallContext();
        }
    }

    /**
     * @dev Reverts if the execution is performed via delegatecall.
     * See {notDelegated}.
     */
    function _checkNotDelegated() internal view virtual {
        if (address(this) != __self) {
            // Must not be called through delegatecall
            revert UUPSUnauthorizedCallContext();
        }
    }

    /**
     * @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by
     * {upgradeToAndCall}.
     *
     * Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}.
     *
     * ```solidity
     * function _authorizeUpgrade(address) internal onlyOwner {}
     * ```
     */
    function _authorizeUpgrade(address newImplementation) internal virtual;

    /**
     * @dev Performs an implementation upgrade with a security check for UUPS proxies, and additional setup call.
     *
     * As a security check, {proxiableUUID} is invoked in the new implementation, and the return value
     * is expected to be the implementation slot in ERC1967.
     *
     * Emits an {IERC1967-Upgraded} event.
     */
    function _upgradeToAndCallUUPS(address newImplementation, bytes memory data) private {
        try IERC1822Proxiable(newImplementation).proxiableUUID() returns (bytes32 slot) {
            if (slot != ERC1967Utils.IMPLEMENTATION_SLOT) {
                revert UUPSUnsupportedProxiableUUID(slot);
            }
            ERC1967Utils.upgradeToAndCall(newImplementation, data);
        } catch {
            // The implementation is not UUPS
            revert ERC1967Utils.ERC1967InvalidImplementation(newImplementation);
        }
    }
}

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

pragma solidity ^0.8.20;
import {Initializable} from "../proxy/utils/Initializable.sol";

/**
 * @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 ContextUpgradeable is Initializable {
    function __Context_init() internal onlyInitializing {
    }

    function __Context_init_unchained() internal onlyInitializing {
    }
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

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

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

File 25 of 48 : ReentrancyGuardUpgradeable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/ReentrancyGuard.sol)

pragma solidity ^0.8.20;
import {Initializable} from "../proxy/utils/Initializable.sol";

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
abstract contract ReentrancyGuardUpgradeable is Initializable {
    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

    // The values being non-zero value makes deployment a bit more expensive,
    // but in exchange the refund on every call to nonReentrant will be lower in
    // amount. Since refunds are capped to a percentage of the total
    // transaction's gas, it is best to keep them low in cases like this one, to
    // increase the likelihood of the full refund coming into effect.
    uint256 private constant NOT_ENTERED = 1;
    uint256 private constant ENTERED = 2;

    /// @custom:storage-location erc7201:openzeppelin.storage.ReentrancyGuard
    struct ReentrancyGuardStorage {
        uint256 _status;
    }

    // keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.ReentrancyGuard")) - 1)) & ~bytes32(uint256(0xff))
    bytes32 private constant ReentrancyGuardStorageLocation = 0x9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00;

    function _getReentrancyGuardStorage() private pure returns (ReentrancyGuardStorage storage $) {
        assembly {
            $.slot := ReentrancyGuardStorageLocation
        }
    }

    /**
     * @dev Unauthorized reentrant call.
     */
    error ReentrancyGuardReentrantCall();

    function __ReentrancyGuard_init() internal onlyInitializing {
        __ReentrancyGuard_init_unchained();
    }

    function __ReentrancyGuard_init_unchained() internal onlyInitializing {
        ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
        $._status = NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        _nonReentrantBefore();
        _;
        _nonReentrantAfter();
    }

    function _nonReentrantBefore() private {
        ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
        // On the first call to nonReentrant, _status will be NOT_ENTERED
        if ($._status == ENTERED) {
            revert ReentrancyGuardReentrantCall();
        }

        // Any calls to nonReentrant after this point will fail
        $._status = ENTERED;
    }

    function _nonReentrantAfter() private {
        ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        $._status = NOT_ENTERED;
    }

    /**
     * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
     * `nonReentrant` function in the call stack.
     */
    function _reentrancyGuardEntered() internal view returns (bool) {
        ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
        return $._status == ENTERED;
    }
}

File 26 of 48 : draft-IERC1822.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/draft-IERC1822.sol)

pragma solidity ^0.8.20;

/**
 * @dev ERC1822: Universal Upgradeable Proxy Standard (UUPS) documents a method for upgradeability through a simplified
 * proxy whose upgrades are fully controlled by the current implementation.
 */
interface IERC1822Proxiable {
    /**
     * @dev Returns the storage slot that the proxiable contract assumes is being used to store the implementation
     * address.
     *
     * IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
     * bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
     * function revert if invoked through a proxy.
     */
    function proxiableUUID() external view returns (bytes32);
}

File 27 of 48 : IBeacon.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/beacon/IBeacon.sol)

pragma solidity ^0.8.20;

/**
 * @dev This is the interface that {BeaconProxy} expects of its beacon.
 */
interface IBeacon {
    /**
     * @dev Must return an address that can be used as a delegate call target.
     *
     * {UpgradeableBeacon} will check that this address is a contract.
     */
    function implementation() external view returns (address);
}

File 28 of 48 : ERC1967Utils.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/ERC1967/ERC1967Utils.sol)

pragma solidity ^0.8.20;

import {IBeacon} from "../beacon/IBeacon.sol";
import {Address} from "../../utils/Address.sol";
import {StorageSlot} from "../../utils/StorageSlot.sol";

/**
 * @dev This abstract contract provides getters and event emitting update functions for
 * https://eips.ethereum.org/EIPS/eip-1967[EIP1967] slots.
 */
library ERC1967Utils {
    // We re-declare ERC-1967 events here because they can't be used directly from IERC1967.
    // This will be fixed in Solidity 0.8.21. At that point we should remove these events.
    /**
     * @dev Emitted when the implementation is upgraded.
     */
    event Upgraded(address indexed implementation);

    /**
     * @dev Emitted when the admin account has changed.
     */
    event AdminChanged(address previousAdmin, address newAdmin);

    /**
     * @dev Emitted when the beacon is changed.
     */
    event BeaconUpgraded(address indexed beacon);

    /**
     * @dev Storage slot with the address of the current implementation.
     * This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1.
     */
    // solhint-disable-next-line private-vars-leading-underscore
    bytes32 internal constant IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;

    /**
     * @dev The `implementation` of the proxy is invalid.
     */
    error ERC1967InvalidImplementation(address implementation);

    /**
     * @dev The `admin` of the proxy is invalid.
     */
    error ERC1967InvalidAdmin(address admin);

    /**
     * @dev The `beacon` of the proxy is invalid.
     */
    error ERC1967InvalidBeacon(address beacon);

    /**
     * @dev An upgrade function sees `msg.value > 0` that may be lost.
     */
    error ERC1967NonPayable();

    /**
     * @dev Returns the current implementation address.
     */
    function getImplementation() internal view returns (address) {
        return StorageSlot.getAddressSlot(IMPLEMENTATION_SLOT).value;
    }

    /**
     * @dev Stores a new address in the EIP1967 implementation slot.
     */
    function _setImplementation(address newImplementation) private {
        if (newImplementation.code.length == 0) {
            revert ERC1967InvalidImplementation(newImplementation);
        }
        StorageSlot.getAddressSlot(IMPLEMENTATION_SLOT).value = newImplementation;
    }

    /**
     * @dev Performs implementation upgrade with additional setup call if data is nonempty.
     * This function is payable only if the setup call is performed, otherwise `msg.value` is rejected
     * to avoid stuck value in the contract.
     *
     * Emits an {IERC1967-Upgraded} event.
     */
    function upgradeToAndCall(address newImplementation, bytes memory data) internal {
        _setImplementation(newImplementation);
        emit Upgraded(newImplementation);

        if (data.length > 0) {
            Address.functionDelegateCall(newImplementation, data);
        } else {
            _checkNonPayable();
        }
    }

    /**
     * @dev Storage slot with the admin of the contract.
     * This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1.
     */
    // solhint-disable-next-line private-vars-leading-underscore
    bytes32 internal constant ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;

    /**
     * @dev Returns the current admin.
     *
     * TIP: To get this value clients can read directly from the storage slot shown below (specified by EIP1967) using
     * the https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call.
     * `0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103`
     */
    function getAdmin() internal view returns (address) {
        return StorageSlot.getAddressSlot(ADMIN_SLOT).value;
    }

    /**
     * @dev Stores a new address in the EIP1967 admin slot.
     */
    function _setAdmin(address newAdmin) private {
        if (newAdmin == address(0)) {
            revert ERC1967InvalidAdmin(address(0));
        }
        StorageSlot.getAddressSlot(ADMIN_SLOT).value = newAdmin;
    }

    /**
     * @dev Changes the admin of the proxy.
     *
     * Emits an {IERC1967-AdminChanged} event.
     */
    function changeAdmin(address newAdmin) internal {
        emit AdminChanged(getAdmin(), newAdmin);
        _setAdmin(newAdmin);
    }

    /**
     * @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy.
     * This is the keccak-256 hash of "eip1967.proxy.beacon" subtracted by 1.
     */
    // solhint-disable-next-line private-vars-leading-underscore
    bytes32 internal constant BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;

    /**
     * @dev Returns the current beacon.
     */
    function getBeacon() internal view returns (address) {
        return StorageSlot.getAddressSlot(BEACON_SLOT).value;
    }

    /**
     * @dev Stores a new beacon in the EIP1967 beacon slot.
     */
    function _setBeacon(address newBeacon) private {
        if (newBeacon.code.length == 0) {
            revert ERC1967InvalidBeacon(newBeacon);
        }

        StorageSlot.getAddressSlot(BEACON_SLOT).value = newBeacon;

        address beaconImplementation = IBeacon(newBeacon).implementation();
        if (beaconImplementation.code.length == 0) {
            revert ERC1967InvalidImplementation(beaconImplementation);
        }
    }

    /**
     * @dev Change the beacon and trigger a setup call if data is nonempty.
     * This function is payable only if the setup call is performed, otherwise `msg.value` is rejected
     * to avoid stuck value in the contract.
     *
     * Emits an {IERC1967-BeaconUpgraded} event.
     *
     * CAUTION: Invoking this function has no effect on an instance of {BeaconProxy} since v5, since
     * it uses an immutable beacon without looking at the value of the ERC-1967 beacon slot for
     * efficiency.
     */
    function upgradeBeaconToAndCall(address newBeacon, bytes memory data) internal {
        _setBeacon(newBeacon);
        emit BeaconUpgraded(newBeacon);

        if (data.length > 0) {
            Address.functionDelegateCall(IBeacon(newBeacon).implementation(), data);
        } else {
            _checkNonPayable();
        }
    }

    /**
     * @dev Reverts if `msg.value` is not zero. It can be used to avoid `msg.value` stuck in the contract
     * if an upgrade doesn't perform an initialization call.
     */
    function _checkNonPayable() private {
        if (msg.value > 0) {
            revert ERC1967NonPayable();
        }
    }
}

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

pragma solidity ^0.8.20;

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

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

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

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

pragma solidity ^0.8.20;

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

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

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

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

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

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

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

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

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

pragma solidity ^0.8.20;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

pragma solidity ^0.8.20;

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

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

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

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

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

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

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

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

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

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

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

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

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

pragma solidity ^0.8.20;

/**
 * @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.
 */
library SafeCast {
    /**
     * @dev Value doesn't fit in an uint of `bits` size.
     */
    error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);

    /**
     * @dev An int value doesn't fit in an uint of `bits` size.
     */
    error SafeCastOverflowedIntToUint(int256 value);

    /**
     * @dev Value doesn't fit in an int of `bits` size.
     */
    error SafeCastOverflowedIntDowncast(uint8 bits, int256 value);

    /**
     * @dev An uint value doesn't fit in an int of `bits` size.
     */
    error SafeCastOverflowedUintToInt(uint256 value);

    /**
     * @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
     */
    function toUint248(uint256 value) internal pure returns (uint248) {
        if (value > type(uint248).max) {
            revert SafeCastOverflowedUintDowncast(248, value);
        }
        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
     */
    function toUint240(uint256 value) internal pure returns (uint240) {
        if (value > type(uint240).max) {
            revert SafeCastOverflowedUintDowncast(240, value);
        }
        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
     */
    function toUint232(uint256 value) internal pure returns (uint232) {
        if (value > type(uint232).max) {
            revert SafeCastOverflowedUintDowncast(232, value);
        }
        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
     */
    function toUint224(uint256 value) internal pure returns (uint224) {
        if (value > type(uint224).max) {
            revert SafeCastOverflowedUintDowncast(224, value);
        }
        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
     */
    function toUint216(uint256 value) internal pure returns (uint216) {
        if (value > type(uint216).max) {
            revert SafeCastOverflowedUintDowncast(216, value);
        }
        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
     */
    function toUint208(uint256 value) internal pure returns (uint208) {
        if (value > type(uint208).max) {
            revert SafeCastOverflowedUintDowncast(208, value);
        }
        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
     */
    function toUint200(uint256 value) internal pure returns (uint200) {
        if (value > type(uint200).max) {
            revert SafeCastOverflowedUintDowncast(200, value);
        }
        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
     */
    function toUint192(uint256 value) internal pure returns (uint192) {
        if (value > type(uint192).max) {
            revert SafeCastOverflowedUintDowncast(192, value);
        }
        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
     */
    function toUint184(uint256 value) internal pure returns (uint184) {
        if (value > type(uint184).max) {
            revert SafeCastOverflowedUintDowncast(184, value);
        }
        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
     */
    function toUint176(uint256 value) internal pure returns (uint176) {
        if (value > type(uint176).max) {
            revert SafeCastOverflowedUintDowncast(176, value);
        }
        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
     */
    function toUint168(uint256 value) internal pure returns (uint168) {
        if (value > type(uint168).max) {
            revert SafeCastOverflowedUintDowncast(168, value);
        }
        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
     */
    function toUint160(uint256 value) internal pure returns (uint160) {
        if (value > type(uint160).max) {
            revert SafeCastOverflowedUintDowncast(160, value);
        }
        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
     */
    function toUint152(uint256 value) internal pure returns (uint152) {
        if (value > type(uint152).max) {
            revert SafeCastOverflowedUintDowncast(152, value);
        }
        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
     */
    function toUint144(uint256 value) internal pure returns (uint144) {
        if (value > type(uint144).max) {
            revert SafeCastOverflowedUintDowncast(144, value);
        }
        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
     */
    function toUint136(uint256 value) internal pure returns (uint136) {
        if (value > type(uint136).max) {
            revert SafeCastOverflowedUintDowncast(136, value);
        }
        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
     */
    function toUint128(uint256 value) internal pure returns (uint128) {
        if (value > type(uint128).max) {
            revert SafeCastOverflowedUintDowncast(128, value);
        }
        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
     */
    function toUint120(uint256 value) internal pure returns (uint120) {
        if (value > type(uint120).max) {
            revert SafeCastOverflowedUintDowncast(120, value);
        }
        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
     */
    function toUint112(uint256 value) internal pure returns (uint112) {
        if (value > type(uint112).max) {
            revert SafeCastOverflowedUintDowncast(112, value);
        }
        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
     */
    function toUint104(uint256 value) internal pure returns (uint104) {
        if (value > type(uint104).max) {
            revert SafeCastOverflowedUintDowncast(104, value);
        }
        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
     */
    function toUint96(uint256 value) internal pure returns (uint96) {
        if (value > type(uint96).max) {
            revert SafeCastOverflowedUintDowncast(96, value);
        }
        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
     */
    function toUint88(uint256 value) internal pure returns (uint88) {
        if (value > type(uint88).max) {
            revert SafeCastOverflowedUintDowncast(88, value);
        }
        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
     */
    function toUint80(uint256 value) internal pure returns (uint80) {
        if (value > type(uint80).max) {
            revert SafeCastOverflowedUintDowncast(80, value);
        }
        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
     */
    function toUint72(uint256 value) internal pure returns (uint72) {
        if (value > type(uint72).max) {
            revert SafeCastOverflowedUintDowncast(72, value);
        }
        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
     */
    function toUint64(uint256 value) internal pure returns (uint64) {
        if (value > type(uint64).max) {
            revert SafeCastOverflowedUintDowncast(64, value);
        }
        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
     */
    function toUint56(uint256 value) internal pure returns (uint56) {
        if (value > type(uint56).max) {
            revert SafeCastOverflowedUintDowncast(56, value);
        }
        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
     */
    function toUint48(uint256 value) internal pure returns (uint48) {
        if (value > type(uint48).max) {
            revert SafeCastOverflowedUintDowncast(48, value);
        }
        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
     */
    function toUint40(uint256 value) internal pure returns (uint40) {
        if (value > type(uint40).max) {
            revert SafeCastOverflowedUintDowncast(40, value);
        }
        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
     */
    function toUint32(uint256 value) internal pure returns (uint32) {
        if (value > type(uint32).max) {
            revert SafeCastOverflowedUintDowncast(32, value);
        }
        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
     */
    function toUint24(uint256 value) internal pure returns (uint24) {
        if (value > type(uint24).max) {
            revert SafeCastOverflowedUintDowncast(24, value);
        }
        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
     */
    function toUint16(uint256 value) internal pure returns (uint16) {
        if (value > type(uint16).max) {
            revert SafeCastOverflowedUintDowncast(16, value);
        }
        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
     */
    function toUint8(uint256 value) internal pure returns (uint8) {
        if (value > type(uint8).max) {
            revert SafeCastOverflowedUintDowncast(8, value);
        }
        return uint8(value);
    }

    /**
     * @dev Converts a signed int256 into an unsigned uint256.
     *
     * Requirements:
     *
     * - input must be greater than or equal to 0.
     */
    function toUint256(int256 value) internal pure returns (uint256) {
        if (value < 0) {
            revert SafeCastOverflowedIntToUint(value);
        }
        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
     */
    function toInt248(int256 value) internal pure returns (int248 downcasted) {
        downcasted = int248(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(248, value);
        }
    }

    /**
     * @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
     */
    function toInt240(int256 value) internal pure returns (int240 downcasted) {
        downcasted = int240(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(240, value);
        }
    }

    /**
     * @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
     */
    function toInt232(int256 value) internal pure returns (int232 downcasted) {
        downcasted = int232(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(232, value);
        }
    }

    /**
     * @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
     */
    function toInt224(int256 value) internal pure returns (int224 downcasted) {
        downcasted = int224(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(224, value);
        }
    }

    /**
     * @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
     */
    function toInt216(int256 value) internal pure returns (int216 downcasted) {
        downcasted = int216(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(216, value);
        }
    }

    /**
     * @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
     */
    function toInt208(int256 value) internal pure returns (int208 downcasted) {
        downcasted = int208(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(208, value);
        }
    }

    /**
     * @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
     */
    function toInt200(int256 value) internal pure returns (int200 downcasted) {
        downcasted = int200(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(200, value);
        }
    }

    /**
     * @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
     */
    function toInt192(int256 value) internal pure returns (int192 downcasted) {
        downcasted = int192(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(192, value);
        }
    }

    /**
     * @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
     */
    function toInt184(int256 value) internal pure returns (int184 downcasted) {
        downcasted = int184(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(184, value);
        }
    }

    /**
     * @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
     */
    function toInt176(int256 value) internal pure returns (int176 downcasted) {
        downcasted = int176(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(176, value);
        }
    }

    /**
     * @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
     */
    function toInt168(int256 value) internal pure returns (int168 downcasted) {
        downcasted = int168(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(168, value);
        }
    }

    /**
     * @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
     */
    function toInt160(int256 value) internal pure returns (int160 downcasted) {
        downcasted = int160(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(160, value);
        }
    }

    /**
     * @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
     */
    function toInt152(int256 value) internal pure returns (int152 downcasted) {
        downcasted = int152(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(152, value);
        }
    }

    /**
     * @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
     */
    function toInt144(int256 value) internal pure returns (int144 downcasted) {
        downcasted = int144(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(144, value);
        }
    }

    /**
     * @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
     */
    function toInt136(int256 value) internal pure returns (int136 downcasted) {
        downcasted = int136(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(136, value);
        }
    }

    /**
     * @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
     */
    function toInt128(int256 value) internal pure returns (int128 downcasted) {
        downcasted = int128(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(128, value);
        }
    }

    /**
     * @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
     */
    function toInt120(int256 value) internal pure returns (int120 downcasted) {
        downcasted = int120(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(120, value);
        }
    }

    /**
     * @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
     */
    function toInt112(int256 value) internal pure returns (int112 downcasted) {
        downcasted = int112(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(112, value);
        }
    }

    /**
     * @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
     */
    function toInt104(int256 value) internal pure returns (int104 downcasted) {
        downcasted = int104(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(104, value);
        }
    }

    /**
     * @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
     */
    function toInt96(int256 value) internal pure returns (int96 downcasted) {
        downcasted = int96(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(96, value);
        }
    }

    /**
     * @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
     */
    function toInt88(int256 value) internal pure returns (int88 downcasted) {
        downcasted = int88(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(88, value);
        }
    }

    /**
     * @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
     */
    function toInt80(int256 value) internal pure returns (int80 downcasted) {
        downcasted = int80(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(80, value);
        }
    }

    /**
     * @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
     */
    function toInt72(int256 value) internal pure returns (int72 downcasted) {
        downcasted = int72(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(72, value);
        }
    }

    /**
     * @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
     */
    function toInt64(int256 value) internal pure returns (int64 downcasted) {
        downcasted = int64(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(64, value);
        }
    }

    /**
     * @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
     */
    function toInt56(int256 value) internal pure returns (int56 downcasted) {
        downcasted = int56(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(56, value);
        }
    }

    /**
     * @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
     */
    function toInt48(int256 value) internal pure returns (int48 downcasted) {
        downcasted = int48(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(48, value);
        }
    }

    /**
     * @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
     */
    function toInt40(int256 value) internal pure returns (int40 downcasted) {
        downcasted = int40(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(40, value);
        }
    }

    /**
     * @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
     */
    function toInt32(int256 value) internal pure returns (int32 downcasted) {
        downcasted = int32(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(32, value);
        }
    }

    /**
     * @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
     */
    function toInt24(int256 value) internal pure returns (int24 downcasted) {
        downcasted = int24(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(24, value);
        }
    }

    /**
     * @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
     */
    function toInt16(int256 value) internal pure returns (int16 downcasted) {
        downcasted = int16(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(16, value);
        }
    }

    /**
     * @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
     */
    function toInt8(int256 value) internal pure returns (int8 downcasted) {
        downcasted = int8(value);
        if (downcasted != value) {
            revert SafeCastOverflowedIntDowncast(8, value);
        }
    }

    /**
     * @dev Converts an unsigned uint256 into a signed int256.
     *
     * Requirements:
     *
     * - input must be less than or equal to maxInt256.
     */
    function toInt256(uint256 value) internal pure returns (int256) {
        // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
        if (value > uint256(type(int256).max)) {
            revert SafeCastOverflowedUintToInt(value);
        }
        return int256(value);
    }
}

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

pragma solidity ^0.8.20;

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

    struct BooleanSlot {
        bool value;
    }

    struct Bytes32Slot {
        bytes32 value;
    }

    struct Uint256Slot {
        uint256 value;
    }

    struct StringSlot {
        string value;
    }

    struct BytesSlot {
        bytes value;
    }

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

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

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

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

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

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

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

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

File 35 of 48 : CDSInterface.sol
// SPDX-License-Identifier: unlicensed
pragma solidity 0.8.20;

import { MessagingReceipt, MessagingFee } from "@layerzerolabs/lz-evm-oapp-v2/contracts/oft/interfaces/IOFT.sol";

interface CDSInterface {


    struct CdsAccountDetails {
        uint64 depositedTime;
        uint256 depositedAmount;
        uint64 withdrawedTime;
        uint256 withdrawedAmount;
        bool withdrawed;
        uint128 depositPrice;
        uint128 depositValue;
        bool depositValueSign;
        bool optedLiquidation;
        uint128 InitialLiquidationAmount;
        uint128 liquidationAmount;
        uint128 liquidationindex;
        uint256 normalizedAmount;
        uint128 lockingPeriod;
        uint128 depositedUSDa;
        uint128 depositedUSDT;
        uint128 withdrawETHAmount;
        uint128 ethPriceAtWithdraw;
        uint256 optionFees;
        uint256 optionFeesWithdrawn;
    }

    struct CdsDetails {
        uint64 index;
        bool hasDeposited;
        mapping ( uint64 => CdsAccountDetails) cdsAccountDetails;
    }
    
    struct CalculateValueResult{
        uint128 currentValue;
        bool gains;
    }

    struct LiquidationInfo{
        uint128 liquidationAmount;
        uint128 profits;
        uint128 ethAmount;
        uint256 availableLiquidationAmount;
    }

    struct OmniChainCDSData {
        uint64  cdsCount;
        uint256 totalCdsDepositedAmount;
        uint256 totalCdsDepositedAmountWithOptionFees;
        uint256 totalAvailableLiquidationAmount;
        uint256 usdtAmountDepositedTillNow;
        uint256 burnedUSDaInRedeem;
        uint128 lastCumulativeRate;
    }

    enum FunctionToDo { DUMMY, UPDATE_GLOBAL, UPDATE_INDIVIDUAL }

    function totalCdsDepositedAmount() external view returns(uint256);
    function totalAvailableLiquidationAmount() external returns(uint256);

    function calculateCumulativeRate(uint128 fees) external returns(uint128);

    function getCDSDepositDetails(address depositor,uint64 index) external view returns(CdsAccountDetails memory,uint64);
    function updateTotalAvailableLiquidationAmount(uint256 amount) external;
    function updateLiquidationInfo(uint128 index,LiquidationInfo memory liquidationData) external;
    function updateTotalCdsDepositedAmount(uint128 _amount) external;
    function updateTotalCdsDepositedAmountWithOptionFees(uint128 _amount) external;

    
    event Deposit(
        address user,
        uint64 index,
        uint128 depositedUSDa,
        uint128 depositedUSDT,
        uint256 depositedTime,
        uint128 ethPriceAtDeposit,
        uint128 lockingPeriod,
        uint128 liquidationAmount,
        bool optedForLiquidation
    );
    event Withdraw(
        address user,
        uint64 index,
        uint256 withdrawUSDa,
        uint256 withdrawTime,
        uint128 withdrawETH,
        uint128 ethPriceAtWithdraw,
        uint256 optionsFees,
        uint256 optionsFeesWithdrawn
    );
}

File 36 of 48 : IAbond.sol
// SPDX-License-Identifier: unlicensed
pragma solidity 0.8.20;

struct State {
    uint256 cumulativeRate;
    uint128 ethBacked;
    uint128 aBondBalance;
}

interface IABONDToken {
    function balanceOf(address account) external view returns (uint256);
    function mint(address to, uint64 index, uint256 amount) external returns(bool);
    function burnFromUser(address to, uint256 amount) external returns(bool);
    function burnFrom(address account, uint256 amount) external;
    function transferFrom(address from, address to, uint256 amount) external returns (bool);
    function transfer(address to,uint256 value) external returns(bool);
    function approve(address spender, uint256 amount) external returns (bool);
    function allowance(address owner, address spender) external view returns (uint256);

    function totalSupply() external view returns (uint256);

    function setAbondData(address user, uint64 index, uint128 ethBacked, uint128 cumulativeRate) external;
    function userStates(address user) external view returns(State memory);


    event Transfer(address indexed from, address indexed to, uint256 value);
    event Approval(address indexed owner, address indexed spender, uint256 value);
}

File 37 of 48 : IBorrowing.sol
// SPDX-License-Identifier: unlicensed

import "../interface/IOptions.sol";

pragma solidity 0.8.20;

interface IBorrowing{

    error Borrowing_DepositFailed();
    error Borrowing_GettingETHPriceFailed();
    error Borrowing_usdaMintFailed();
    error Borrowing_abondMintFailed();
    error Borrowing_WithdrawUSDaTransferFailed();
    error Borrowing_WithdrawEthTransferFailed();
    error Borrowing_WithdrawBurnFailed();
    error Borrowing_LiquidateBurnFailed();
    error Borrowing_LiquidateEthTransferToCdsFailed();
    
    enum DownsideProtectionLimitValue {
        // 0: deside Downside Protection limit by percentage of eth price in past 3 months
        ETH_PRICE_VOLUME,
        // 1: deside Downside Protection limit by CDS volume divided by borrower volume.
        CDS_VOLUME_BY_BORROWER_VOLUME
    }

    struct OmniChainBorrowingData {
        uint256  normalizedAmount;
        uint256  ethVaultValue;
        uint256  cdsPoolValue;
        uint256  totalCDSPool;
        uint256  ethRemainingInWithdraw;
        uint256  ethValueRemainingInWithdraw;
        uint128  noOfLiquidations;
        uint64 nonce;
    }

    function getUSDValue() external view returns(uint256);
    // function lastEthVaultValue() external view returns(uint256);
    // function lastCDSPoolValue() external view returns(uint256);

    function updateLastEthVaultValue(uint256 _amount) external;
    function calculateRatio(uint256 _amount,uint currentEthPrice) external returns(uint64);

    event Deposit(
        address user,
        uint64 index,
        uint256 depositedAmount,
        uint256 normalizedAmount,
        uint256 depositedTime,
        uint128 ethPrice,
        uint256 borrowAmount,
        uint64 strikePrice,
        uint256 optionsFees,
        IOptions.StrikePrice strikePricePercent,
        uint8 APR,
        uint256 aBondCr
        );
    event Withdraw(
        address user,
        uint64 index,
        uint256 withdrawTime,
        uint128 withdrawAmount,
        uint128 noOfAbond,
        uint256 borrowDebt
    );
    event Liquidate(uint64 index,uint128 liquidationAmount,uint128 profits,uint128 ethAmount,uint256 availableLiquidationAmount);
}

File 38 of 48 : IBorrowLiquidation.sol
// SPDX-License-Identifier: unlicensed

pragma solidity 0.8.20;

import "./CDSInterface.sol";

interface IBorrowLiquidation{

    error BorrowLiquidation_LiquidateBurnFailed();

    function liquidateBorrowPosition(
        address _user,
        uint64 _index,
        uint64 _currentEthPrice,
        uint256 _lastCumulativeRate
    ) external payable returns(CDSInterface.LiquidationInfo memory);

    event Liquidate(uint64 index,uint128 liquidationAmount,uint128 profits,uint128 ethAmount,uint256 availableLiquidationAmount);

}

File 39 of 48 : IGlobalVariables.sol
// SPDX-License-Identifier: unlicensed

pragma solidity 0.8.20;

import { MessagingReceipt, MessagingFee } from "@layerzerolabs/lz-evm-oapp-v2/contracts/oft/interfaces/IOFT.sol";
import "../interface/CDSInterface.sol";
interface IGlobalVariables{

    struct OmniChainData {
        uint256  normalizedAmount;
        uint256  ethVaultValue;
        uint256  cdsPoolValue;
        uint256  totalCDSPool;
        uint256  ethRemainingInWithdraw;
        uint256  ethValueRemainingInWithdraw;
        uint128  noOfLiquidations;
        uint64   nonce;

        uint64  cdsCount;
        uint256 totalCdsDepositedAmount;
        uint256 totalCdsDepositedAmountWithOptionFees;
        uint256 totalAvailableLiquidationAmount;
        uint256 usdtAmountDepositedTillNow;
        uint256 burnedUSDaInRedeem;
        uint128 lastCumulativeRate;

        uint256  totalVolumeOfBorrowersAmountinWei;
        uint256  totalVolumeOfBorrowersAmountinUSD;
        uint128  noOfBorrowers;
        uint256  totalInterest;
        uint256  abondUSDaPool;
        uint256  ethProfitsOfLiquidators;
        uint256  usdaGainedFromLiquidation;
        uint256  totalInterestFromLiquidation;
        uint256  interestFromExternalProtocolDuringLiquidation;
        uint256  totalNoOfDepositIndices;
    }

    struct USDaOftTransferData {
        address recipient;
        uint256 tokensToSend;
    }

    struct NativeTokenTransferData{
        address recipient;
        uint256 nativeTokensToSend;
    }

    enum FunctionToDo { DUMMY, UPDATE_GLOBAL, UPDATE_INDIVIDUAL , TOKEN_TRANSFER, NATIVE_TRANSFER, BOTH_TRANSFER}
    
    function getOmniChainData() external view returns(OmniChainData memory);

    function setOmniChainData(OmniChainData memory _omniChainData) external;
    function oftOrNativeReceiveFromOtherChains(
        FunctionToDo _functionToDo,
        USDaOftTransferData memory _oftTransferData,
        NativeTokenTransferData memory _nativeTokenTransferData,
        address _refundAddress
    ) external payable returns (MessagingReceipt memory receipt);


    function quote(
        FunctionToDo _functionToDo,
        bytes memory _options,
        bool _payInLzToken
    ) external view returns(MessagingFee memory fee);

    function send(        
        FunctionToDo _functionToDo,
        MessagingFee memory _fee,
        bytes memory _options,
        address refundAddress
    ) external payable returns (MessagingReceipt memory receipt);

    function sendForLiquidation(        
        FunctionToDo _functionToDo,
        uint128 _liqIndex,
        CDSInterface.LiquidationInfo memory _liquidationInfo,
        MessagingFee memory _fee,
        bytes memory _options,
        address _refundAddress
    ) external payable returns (MessagingReceipt memory receipt);
}

File 40 of 48 : IMultiSign.sol
// SPDX-License-Identifier: unlicensed

pragma solidity 0.8.20;

interface IMultiSign{

    enum SetterFunctions{
        SetLTV,
        SetAPR,
        SetWithdrawTimeLimitCDS,
        SetAdminBorrow,
        SetAdminCDS,
        SetTreasuryBorrow,
        SetTreasuryCDS,
        SetBondRatio,
        SetUSDaLimit,
        SetUsdtLimit
    }
    enum Functions{
        BorrowingDeposit,
        BorrowingWithdraw,
        Liquidation,
        SetAPR,
        CDSDeposit,
        CDSWithdraw,
        RedeemUSDT
    }
    
    function functionState(Functions) external returns(bool);
    function executeSetterFunction(SetterFunctions _function) external returns (bool);
}

File 41 of 48 : IOptions.sol
// SPDX-License-Identifier: unlicensed

pragma solidity 0.8.20;

interface IOptions{
    enum StrikePrice{FIVE,TEN,FIFTEEN,TWENTY,TWENTY_FIVE}
    function calculateStrikePriceGains(uint128 depositedAmount,uint128 strikePrice,uint64 ethPrice) external pure returns(uint128);
    function calculateOptionPrice(uint128 _ethPrice,uint256 _ethVolatility,uint256 _amount,StrikePrice _strikePrice) external returns (uint256);

}

File 42 of 48 : ITreasury.sol
// SPDX-License-Identifier: unlicensed

pragma solidity 0.8.20;

import { MessagingReceipt, MessagingFee } from "@layerzerolabs/lz-evm-oapp-v2/contracts/oft/interfaces/IOFT.sol";
interface ITreasury{

    error Treasury_ZeroDeposit();
    error Treasury_ZeroWithdraw();
    error Treasury_AavePoolAddressZero();
    error Treasury_AaveDepositAndMintFailed();
    error Treasury_AaveWithdrawFailed();
    error Treasury_CompoundDepositAndMintFailed();
    error Treasury_CompoundWithdrawFailed();
    error Treasury_EthTransferToCdsLiquidatorFailed();
    error Treasury_WithdrawExternalProtocolInterestFailed();

    //Depositor's Details for each depsoit.
    struct DepositDetails{
        uint64  depositedTime;
        uint128 depositedAmount;
        uint128 depositedAmountUsdValue;
        uint64  downsidePercentage;
        uint128 ethPriceAtDeposit;
        uint128 borrowedAmount;
        uint128 normalizedAmount;
        bool    withdrawed;
        uint128 withdrawAmount;
        bool    liquidated;
        uint64  ethPriceAtWithdraw;
        uint64  withdrawTime;
        uint128 aBondTokensAmount;
        uint128 strikePrice;
        uint128 optionFees;
        uint8 APR;
        uint256 totalDebtAmountPaid;
        uint256 aBondCr;
    }

    //Borrower Details
    struct BorrowerDetails {
        uint256 depositedAmount;
        mapping(uint64 => DepositDetails) depositDetails;
        uint256 totalBorrowedAmount;
        bool    hasBorrowed;
        bool    hasDeposited;
        uint64  borrowerIndex;
    }

    //Each Deposit to Aave/Compound
    struct EachDepositToProtocol{
        uint64  depositedTime;
        uint128 depositedAmount;
        uint128 ethPriceAtDeposit;
        uint256 depositedUsdValue;
        uint128 tokensCredited;

        bool    withdrawed;
        uint128 ethPriceAtWithdraw;
        uint64  withdrawTime;
        uint256 withdrawedUsdValue;
        uint128 interestGained;
        uint256 discountedPrice;
    }

    //Total Deposit to Aave/Compound
    struct ProtocolDeposit{
        mapping (uint64 => EachDepositToProtocol) eachDepositToProtocol;
        uint64  depositIndex;
        uint256 depositedAmount;
        uint256 totalCreditedTokens;
        uint256 depositedUsdValue;
        uint256 cumulativeRate;       
    }

    struct DepositResult{
        bool hasDeposited;
        uint64 borrowerIndex;
    }

    struct GetBorrowingResult{
        uint64 totalIndex;
        DepositDetails depositDetails;
    }

    struct OmniChainTreasuryData {
        uint256  totalVolumeOfBorrowersAmountinWei;
        uint256  totalVolumeOfBorrowersAmountinUSD;
        uint128  noOfBorrowers;
        uint256  totalInterest;
        uint256  abondUSDaPool;
        uint256  ethProfitsOfLiquidators;
        uint256  usdaGainedFromLiquidation;
        uint256  totalInterestFromLiquidation;
        uint256  interestFromExternalProtocolDuringLiquidation;
    }

    struct USDaOftTransferData {
        address recipient;
        uint256 tokensToSend;
    }

    struct NativeTokenTransferData{
        address recipient;
        uint256 nativeTokensToSend;
    }

    enum Protocol{Aave,Compound}
    enum FunctionToDo { DUMMY, UPDATE, TOKEN_TRANSFER, NATIVE_TRANSFER, BOTH_TRANSFER}

        function deposit(
            address user,
            uint128 _ethPrice,
            uint64 _depositTime
        ) external payable returns(DepositResult memory);
        function withdraw(address borrower,address toAddress,uint256 _amount,uint64 index) external payable returns(bool);
        function withdrawFromExternalProtocol(address user, uint128 aBondAmount) external returns(uint256);

        // function depositToAave() external;
        // function withdrawFromAave(uint64 index) external;
        // function depositToCompound() external;
        // function withdrawFromCompound(uint64 index) external;
        // function withdrawFromCompoundByUser(address depositor,uint64 index) external returns(uint256);
        function calculateYieldsForExternalProtocol(address user,uint128 aBondAmount) external view returns (uint256);
        function getBalanceInTreasury() external view returns(uint256);
        function approveUSDa(address _address, uint _amount) external;
        function approveUsdt(address _address, uint _amount) external;
        function transferEthToCdsLiquidators(address borrower,uint128 amount) external;


        function noOfBorrowers() external view returns(uint128);
        function abondUSDaPool() external view returns(uint256);
        function usdaGainedFromLiquidation() external view returns(uint256);
        function totalVolumeOfBorrowersAmountinWei() external view returns(uint256);
        function totalVolumeOfBorrowersAmountinUSD() external view returns(uint256);

        function updateHasBorrowed(address borrower,bool _bool) external;
        function updateTotalDepositedAmount(address borrower,uint128 amount) external;
        function updateTotalBorrowedAmount(address borrower,uint256 amount) external;
        function getTotalDeposited(address borrower) external view returns(uint256);

        function getBorrowing(address depositor,uint64 index) external view returns(GetBorrowingResult memory);
        function getExternalProtocolCumulativeRate(bool maximum) external view  returns(uint128);
        function updateDepositDetails(address depositor,uint64 index,DepositDetails memory depositDetail) external;
        function updateTotalInterest(uint256 _amount) external;
        function updateTotalInterestFromLiquidation(uint256 _amount) external;
        function updateAbondUSDaPool(uint256 amount,bool operation) external;
        function updateUSDaGainedFromLiquidation(uint256 amount,bool operation) external;
        function updateInterestFromExternalProtocol(uint256 amount) external;
        function updateUsdaCollectedFromCdsWithdraw(uint256 amount) external;
        function updateLiquidatedETHCollectedFromCdsWithdraw(uint256 amount) external;
        function transferFundsToGlobal(uint256 usdaAmount, uint256 ethAmount) external;

    event Deposit(address indexed user,uint256 amount);
    event Withdraw(address indexed user,uint256 amount);
    event DepositToAave(uint64 count,uint256 amount);
    event WithdrawFromAave(uint64 count,uint256 amount);
    event DepositToCompound(uint64 count,uint256 amount);
    event WithdrawFromCompound(uint64 count,uint256 amount);
}

File 43 of 48 : IUSDa.sol
// SPDX-License-Identifier: unlicensed
pragma solidity 0.8.20;

import {
    SendParam, 
    OFTReceipt, 
    MessagingReceipt, 
    MessagingFee  
    } from "@layerzerolabs/lz-evm-oapp-v2/contracts/oft/interfaces/IOFT.sol";

interface IUSDa {
    function balanceOf(address account) external view returns (uint256);
    function mint(address to, uint256 amount) external returns(bool);
    function burnFromUser(address to, uint256 amount) external returns(bool);
    function burnFrom(address account, uint256 amount) external;
    function transferFrom(address from, address to, uint256 amount) external returns (bool);
    function transfer(address to,uint256 value) external returns(bool);
    function approve(address spender, uint256 amount) external returns (bool);
    function allowance(address owner, address spender) external view returns (uint256);

    function totalSupply() external view returns (uint256);
    function send(
        SendParam calldata _sendParam,
        MessagingFee calldata _fee,
        address _refundAddress
    ) external payable returns (MessagingReceipt memory msgReceipt, OFTReceipt memory oftReceipt);

    function quoteSend(
        SendParam calldata _sendParam,
        bool _payInLzToken
    ) external view returns (MessagingFee memory msgFee);

    event Transfer(address indexed from, address indexed to, uint256 value);
    event Approval(address indexed owner, address indexed spender, uint256 value);
}

File 44 of 48 : IBorrowing.sol
// SPDX-License-Identifier: unlicensed

pragma solidity 0.8.20;

interface IOldBorrowing{

    function withDraw(
        address _toAddress,
        uint64 _index
    ) external payable;

}

File 45 of 48 : ITreasury.sol
// SPDX-License-Identifier: unlicensed

pragma solidity 0.8.20;

interface IOldTreasury{

    struct DepositDetails{
        uint64  depositedTime;
        uint128 depositedAmount;
        uint128 depositedAmountUsdValue;
        uint64  downsidePercentage;
        uint128 ethPriceAtDeposit;
        uint128 borrowedAmount;
        uint128 normalizedAmount;
        bool    withdrawed;
        uint128 withdrawAmount;
        bool    liquidated;
        uint64  ethPriceAtWithdraw;
        uint64  withdrawTime;
        uint128 aBondTokensAmount;
        uint128 strikePrice;
        uint128 optionFees;
        uint8 APR;
        uint256 totalDebtAmountPaid;
        uint256 aBondCr;
    }

    struct GetBorrowingResult{
        uint64 totalIndex;
        DepositDetails depositDetails;
    }
    function getBorrowing(address depositor,uint64 index) external view returns(GetBorrowingResult memory);
    function getTotalIndex(address borrower) external view returns(uint64);

}

File 46 of 48 : BorrowLib.sol
// SPDX-License-Identifier: LZBL-1.1
// Copyright 2023 LayerZero Labs Ltd.
// You may obtain a copy of the License at
// https://github.com/LayerZero-Labs/license/blob/main/LICENSE-LZBL-1.1

pragma solidity 0.8.20;

import { State, IABONDToken } from "../interface/IAbond.sol";
import "../interface/ITreasury.sol";
import "../interface/IUSDa.sol";
import "../interface/IBorrowing.sol";
import "../interface/IGlobalVariables.sol";
import "hardhat/console.sol";


library BorrowLib {

    uint128 constant PRECISION = 1e6;
    uint128 constant CUMULATIVE_PRECISION = 1e7;
    uint128 constant RATIO_PRECISION = 1e4;
    uint128 constant RATE_PRECISION = 1e27;
    uint128 constant USDA_PRECISION = 1e12;
    uint128 constant LIQ_AMOUNT_PRECISION = 1e10;

    string  public constant name = "Autonomint USD";
    string  public constant version = "1";
    bytes32 public constant PERMIT_TYPEHASH = keccak256("Permit(address holder,address spender,uint256 allowedAmount,bool allowed,uint256 expiry)");

    function calculateHalfValue(uint256 amount) public pure returns(uint128){
        return uint128((amount * 50)/100);
    }

    function calculateNormAmount(
        uint256 amount,
        uint256 cumulativeRate
    ) public pure returns(uint256){
        return (amount * RATE_PRECISION)/cumulativeRate;
    }

    function calculateDebtAmount(
        uint256 amount,
        uint256 cumulativeRate
    ) public pure returns(uint256){
        return (amount * cumulativeRate)/RATE_PRECISION;
    }

    function calculateEthPriceRatio(
        uint128 depositEthPrice, 
        uint128 currentEthPrice
    ) public pure returns(uint128){
        return (currentEthPrice * 10000)/depositEthPrice;
    }

    function calculateDiscountedETH(
        uint256 amount,
        uint128 ethPrice
    ) public pure returns(uint256){
        return ((((80*calculateHalfValue(amount))/100)*ethPrice)/100)/USDA_PRECISION;
    }

    function calculateReturnToAbond(
        uint128 depositedAmount,
        uint128 depositEthPrice,
        uint128 returnToTreasury
    ) public pure returns(uint128){
        return (((((depositedAmount * depositEthPrice)/USDA_PRECISION)/100) - returnToTreasury) * 10)/100;
    }
    
    function calculateRatio(
        uint256 _amount,
        uint currentEthPrice,
        uint128 lastEthprice,
        uint256 noOfBorrowers,
        uint256 latestTotalCDSPool,
        IGlobalVariables.OmniChainData memory previousData
    ) public pure returns(uint64, IGlobalVariables.OmniChainData memory){

        uint256 netPLCdsPool;

        // Calculate net P/L of CDS Pool
        if(currentEthPrice > lastEthprice){
            netPLCdsPool = (currentEthPrice - lastEthprice) * noOfBorrowers;
        }else{
            netPLCdsPool = (lastEthprice - currentEthPrice) * noOfBorrowers;
        }

        uint256 currentEthVaultValue;
        uint256 currentCDSPoolValue;
        
        // OmniChainBorrowingData memory previousData = omniChainBorrowing;
 
        // Check it is the first deposit
        if(noOfBorrowers == 0){

            // Calculate the ethVault value
            // lastEthVaultValue = _amount * currentEthPrice;
            previousData.ethVaultValue = _amount * currentEthPrice;
            // Set the currentEthVaultValue to lastEthVaultValue for next deposit
            currentEthVaultValue = previousData.ethVaultValue;

            // Get the total amount in CDS
            // lastTotalCDSPool = cds.totalCdsDepositedAmount();
            previousData.totalCDSPool = latestTotalCDSPool;

            if (currentEthPrice >= lastEthprice){
                currentCDSPoolValue = previousData.totalCDSPool + netPLCdsPool;
            }else{
                currentCDSPoolValue = previousData.totalCDSPool - netPLCdsPool;
            }

            // Set the currentCDSPoolValue to lastCDSPoolValue for next deposit
            previousData.cdsPoolValue = currentCDSPoolValue;
            currentCDSPoolValue = currentCDSPoolValue * USDA_PRECISION;

        }else{

            currentEthVaultValue = previousData.ethVaultValue + (_amount * currentEthPrice);
            previousData.ethVaultValue = currentEthVaultValue;


            if(currentEthPrice >= lastEthprice){
                // if(latestTotalCDSPool > previousData.totalCDSPool){
                //     previousData.cdsPoolValue = previousData.cdsPoolValue + (
                //         latestTotalCDSPool - previousData.totalCDSPool) + netPLCdsPool;  
                // }else{
                //     previousData.cdsPoolValue = previousData.cdsPoolValue - (
                //         previousData.totalCDSPool - latestTotalCDSPool) + netPLCdsPool;
                // }
                previousData.cdsPoolValue += netPLCdsPool;
            }else{
                // if(latestTotalCDSPool > previousData.totalCDSPool){
                //     previousData.cdsPoolValue = previousData.cdsPoolValue + (
                //         latestTotalCDSPool - previousData.totalCDSPool) - netPLCdsPool;  
                // }else{
                //     previousData.cdsPoolValue = previousData.cdsPoolValue - (
                //         previousData.totalCDSPool - latestTotalCDSPool) - netPLCdsPool;
                // }
                previousData.cdsPoolValue -= netPLCdsPool;
            }

            previousData.totalCDSPool = latestTotalCDSPool;
            currentCDSPoolValue = previousData.cdsPoolValue * USDA_PRECISION;
        }

        // Calculate ratio by dividing currentEthVaultValue by currentCDSPoolValue,
        // since it may return in decimals we multiply it by 1e6
        uint64 ratio = uint64((currentCDSPoolValue * CUMULATIVE_PRECISION)/currentEthVaultValue);
        return (ratio, previousData);
    }

    function calculateCumulativeRate(
        uint128 noOfBorrowers,
        uint256 ratePerSec,
        uint128 lastEventTime,
        uint256 lastCumulativeRate
    ) public view returns (uint256) {
        uint256 currentCumulativeRate;

        if (noOfBorrowers == 0) {
            currentCumulativeRate = ratePerSec;
        } else {
            uint256 timeInterval = uint128(block.timestamp) - lastEventTime;
            currentCumulativeRate = lastCumulativeRate * _rpow(ratePerSec, timeInterval, RATE_PRECISION);
            currentCumulativeRate = currentCumulativeRate / RATE_PRECISION;
        }
        return currentCumulativeRate;
    }

    function tokensToLend(
        uint256 depositedAmont, 
        uint128 ethPrice, 
        uint8 LTV
    ) public pure returns(uint256){
        uint256 tokens = (depositedAmont * ethPrice * LTV) / (USDA_PRECISION * RATIO_PRECISION);
        return tokens;
    }

    function abondToMint(
        uint256 _amount, 
        uint64 _bondRatio
    ) public pure returns(uint128 amount){
        amount = (uint128(_amount) * USDA_PRECISION)/_bondRatio;
    }

    function calculateBaseToMultiply(uint32 usdaPrice) public pure returns (uint8 baseToMultiply){
        if(usdaPrice < 9500){
            baseToMultiply = 50;
        }else if(usdaPrice < 9700 && usdaPrice >= 9500){
            baseToMultiply = 30;
        }else if(usdaPrice < 9800 && usdaPrice >= 9700){
            baseToMultiply = 20;
        }else if(usdaPrice < 9900 && usdaPrice >= 9800){
            baseToMultiply = 15;
        }else if(usdaPrice < 10100 && usdaPrice >= 9900){
            baseToMultiply = 10;
        }else if(usdaPrice < 10200 && usdaPrice >= 10100){
            baseToMultiply = 8;
        }else if(usdaPrice < 10500 && usdaPrice >= 10200){
            baseToMultiply = 5;
        }else{
            baseToMultiply = 1;
        }
    }

    function calculateNewAPRToUpdate(uint32 usdaPrice) public pure returns(uint128 ratePerSec,uint8 newAPR){
        require(usdaPrice != 0, "Invalid USDa price");
        newAPR = 5 * calculateBaseToMultiply(usdaPrice);
        if(newAPR == 250){
            ratePerSec = 1000000007075835619725814915;
        }else if (newAPR == 150){
            ratePerSec = 1000000004431822129783699001;
        }else if(newAPR == 100){
            ratePerSec = 1000000003022265980097387650;
        }else if(newAPR == 75){
            ratePerSec = 1000000002293273137447730714;
        }else if(newAPR == 50){
            ratePerSec = 1000000001547125957863212448;
        }else if(newAPR == 40){
            ratePerSec = 1000000001243680656318820312;
        }else if(newAPR == 25){
            ratePerSec = 1000000000782997609082909351;
        }else if(newAPR == 5){
            ratePerSec = 1000000000158153903837946257;
        }
    }

    function getAbondYields(
        address user,
        uint128 aBondAmount,
        address abondAddress,
        address treasuryAddress
    ) public view returns(uint128,uint256,uint256){
        require(aBondAmount > 0,"Abond amount should not be zero");
        
        IABONDToken abond = IABONDToken(abondAddress);
        State memory userState = abond.userStates(user);
        require(aBondAmount <= userState.aBondBalance,"You don't have enough aBonds");

        ITreasury treasury = ITreasury(treasuryAddress);

        uint256 redeemableAmount = treasury.calculateYieldsForExternalProtocol(user,aBondAmount);
        uint128 depositedAmount = (aBondAmount * userState.ethBacked)/1e18;

        uint128 usdaToAbondRatioLiq = uint64(treasury.usdaGainedFromLiquidation() * RATE_PRECISION/ abond.totalSupply());
        uint256 usdaToTransfer = (usdaToAbondRatioLiq * aBondAmount) / RATE_PRECISION;

        return (depositedAmount,redeemableAmount,usdaToTransfer);
    }

    function getLiquidationAmountProportions(
        uint256 _liqAmount,
        uint256 _totalCdsDepositedAmount,
        uint256 _totalGlobalCdsDepositedAmount,
        uint256 _totalAvailableLiqAmount,
        uint256 _totalGlobalAvailableLiqAmountAmount
    ) public pure returns (uint256){

        uint256 otherChainCDSAmount = _totalGlobalCdsDepositedAmount - _totalCdsDepositedAmount;

        uint256 totalAvailableLiqAmountInOtherChain = _totalGlobalAvailableLiqAmountAmount - _totalAvailableLiqAmount;

        uint256 share = (otherChainCDSAmount * LIQ_AMOUNT_PRECISION)/_totalGlobalCdsDepositedAmount;
        uint256 liqAmountToGet = (_liqAmount * share)/LIQ_AMOUNT_PRECISION;
        uint256 liqAmountRemaining = _liqAmount - liqAmountToGet;

        if(totalAvailableLiqAmountInOtherChain == 0){
            liqAmountToGet = 0;
        }else{
            if(totalAvailableLiqAmountInOtherChain < liqAmountToGet) {
                liqAmountToGet = totalAvailableLiqAmountInOtherChain;
            }else{
                if(totalAvailableLiqAmountInOtherChain > liqAmountToGet && _totalAvailableLiqAmount < liqAmountRemaining){
                    liqAmountToGet += liqAmountRemaining - _totalAvailableLiqAmount;
                }else{
                    liqAmountToGet = liqAmountToGet;
                }
            }
        }
        return liqAmountToGet;
    }

    function getCdsProfitsProportions(
        uint128 _liqAmount,
        uint128 _liqAmountToGetFromOtherChain,
        uint128 _cdsProfits
    ) public pure returns (uint128){

        uint128 share = (_liqAmountToGetFromOtherChain * LIQ_AMOUNT_PRECISION)/_liqAmount;
        uint128 cdsProfitsForOtherChain = (_cdsProfits * share)/LIQ_AMOUNT_PRECISION;

        return cdsProfitsForOtherChain;
    }

    function redeemYields(
        address user,
        uint128 aBondAmount,
        address usdaAddress,
        address abondAddress,
        address treasuryAddress
    ) public returns(uint256){

        require(aBondAmount > 0,"Abond amount should not be zero");
        IABONDToken abond = IABONDToken(abondAddress);

        State memory userState = abond.userStates(user);
        require(aBondAmount <= userState.aBondBalance,"You don't have enough aBonds");

        ITreasury treasury = ITreasury(treasuryAddress);
        uint128 usdaToAbondRatio = uint128(treasury.abondUSDaPool() * RATE_PRECISION/ abond.totalSupply());
        uint256 usdaToBurn = (usdaToAbondRatio * aBondAmount) / RATE_PRECISION;
        treasury.updateAbondUSDaPool(usdaToBurn,false);

        uint128 usdaToAbondRatioLiq = uint128(treasury.usdaGainedFromLiquidation() * RATE_PRECISION/ abond.totalSupply());
        uint256 usdaToTransfer = (usdaToAbondRatioLiq * aBondAmount) / RATE_PRECISION;
        treasury.updateUSDaGainedFromLiquidation(usdaToTransfer,false);

        //Burn the usda from treasury
        treasury.approveUSDa(address(this),(usdaToBurn + usdaToTransfer));

        IUSDa usda = IUSDa(usdaAddress);
        bool burned = usda.burnFromUser(address(treasury),usdaToBurn);
        if(!burned){
            revert ('Borrowing_RedeemBurnFailed');
        }
        
        if(usdaToTransfer > 0){
            bool transferred = usda.transferFrom(address(treasury),user,usdaToTransfer);
            if(!transferred){
                revert ('Borrowing_RedeemTransferFailed');
            }
        }
        
        uint256 withdrawAmount = treasury.withdrawFromExternalProtocol(user,aBondAmount);

        //Burn the abond from user
        bool success = abond.burnFromUser(msg.sender,aBondAmount);
        if(!success){
            revert ('Borrowing_RedeemBurnFailed');
        }
        return withdrawAmount;
    }

    function _rpow(uint x, uint n, uint b) public pure returns (uint z) {
      assembly {
        switch x case 0 {switch n case 0 {z := b} default {z := 0}}
        default {
          switch mod(n, 2) case 0 { z := b } default { z := x }
          let half := div(b, 2)  // for rounding.
          for { n := div(n, 2) } n { n := div(n,2) } {
            let xx := mul(x, x)
            if iszero(eq(div(xx, x), x)) { revert(0,0) }
            let xxRound := add(xx, half)
            if lt(xxRound, xx) { revert(0,0) }
            x := div(xxRound, b)
            if mod(n,2) {
              let zx := mul(z, x)
              if and(iszero(iszero(x)), iszero(eq(div(zx, x), z))) { revert(0,0) }
              let zxRound := add(zx, half)
              if lt(zxRound, zx) { revert(0,0) }
              z := div(zxRound, b)
            }
          }
        }
      }
    }
}

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

library console {
    address constant CONSOLE_ADDRESS =
        0x000000000000000000636F6e736F6c652e6c6f67;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

}

File 48 of 48 : BytesLib.sol
// 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 equal_nonAligned(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 endMinusWord := add(_preBytes, length)
                let mc := add(_preBytes, 0x20)
                let cc := add(_postBytes, 0x20)

                for {
                // the next line is the loop condition:
                // while(uint256(mc < endWord) + cb == 2)
                } eq(add(lt(mc, endMinusWord), 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
                    }
                }

                // Only if still successful
                // For <1 word tail bytes
                if gt(success, 0) {
                    // Get the remainder of length/32
                    // length % 32 = AND(length, 32 - 1)
                    let numTailBytes := and(length, 0x1f)
                    let mcRem := mload(mc)
                    let ccRem := mload(cc)
                    for {
                        let i := 0
                    // the next line is the loop condition:
                    // while(uint256(i < numTailBytes) + cb == 2)
                    } eq(add(lt(i, numTailBytes), cb), 2) {
                        i := add(i, 1)
                    } {
                        if iszero(eq(byte(i, mcRem), byte(i, ccRem))) {
                            // 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
{
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "viaIR": true,
  "evmVersion": "paris",
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "metadata": {
    "useLiteralContent": true
  },
  "libraries": {
    "contracts/lib/BorrowLib.sol": {
      "BorrowLib": "0x980ab9ca184fafd7bf0e1fa8403298b2bcc12cf9"
    }
  }
}

Contract ABI

[{"inputs":[{"internalType":"address","name":"target","type":"address"}],"name":"AddressEmptyCode","type":"error"},{"inputs":[],"name":"Borrowing_DepositFailed","type":"error"},{"inputs":[],"name":"Borrowing_GettingETHPriceFailed","type":"error"},{"inputs":[],"name":"Borrowing_LiquidateBurnFailed","type":"error"},{"inputs":[],"name":"Borrowing_LiquidateEthTransferToCdsFailed","type":"error"},{"inputs":[],"name":"Borrowing_WithdrawBurnFailed","type":"error"},{"inputs":[],"name":"Borrowing_WithdrawEthTransferFailed","type":"error"},{"inputs":[],"name":"Borrowing_WithdrawUSDaTransferFailed","type":"error"},{"inputs":[],"name":"Borrowing_abondMintFailed","type":"error"},{"inputs":[],"name":"Borrowing_usdaMintFailed","type":"error"},{"inputs":[{"internalType":"address","name":"implementation","type":"address"}],"name":"ERC1967InvalidImplementation","type":"error"},{"inputs":[],"name":"ERC1967NonPayable","type":"error"},{"inputs":[],"name":"FailedInnerCall","type":"error"},{"inputs":[],"name":"InvalidInitialization","type":"error"},{"inputs":[{"internalType":"uint16","name":"optionType","type":"uint16"}],"name":"InvalidOptionType","type":"error"},{"inputs":[],"name":"NotInitializing","type":"error"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"OwnableInvalidOwner","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"OwnableUnauthorizedAccount","type":"error"},{"inputs":[],"name":"ReentrancyGuardReentrantCall","type":"error"},{"inputs":[{"internalType":"uint8","name":"bits","type":"uint8"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"SafeCastOverflowedUintDowncast","type":"error"},{"inputs":[],"name":"UUPSUnauthorizedCallContext","type":"error"},{"inputs":[{"internalType":"bytes32","name":"slot","type":"bytes32"}],"name":"UUPSUnsupportedProxiableUUID","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint64","name":"index","type":"uint64"},{"indexed":false,"internalType":"uint256","name":"depositedAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"normalizedAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"depositedTime","type":"uint256"},{"indexed":false,"internalType":"uint128","name":"ethPrice","type":"uint128"},{"indexed":false,"internalType":"uint256","name":"borrowAmount","type":"uint256"},{"indexed":false,"internalType":"uint64","name":"strikePrice","type":"uint64"},{"indexed":false,"internalType":"uint256","name":"optionsFees","type":"uint256"},{"indexed":false,"internalType":"enum IOptions.StrikePrice","name":"strikePricePercent","type":"uint8"},{"indexed":false,"internalType":"uint8","name":"APR","type":"uint8"},{"indexed":false,"internalType":"uint256","name":"aBondCr","type":"uint256"}],"name":"Deposit","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint64","name":"version","type":"uint64"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint64","name":"index","type":"uint64"},{"indexed":false,"internalType":"uint128","name":"liquidationAmount","type":"uint128"},{"indexed":false,"internalType":"uint128","name":"profits","type":"uint128"},{"indexed":false,"internalType":"uint128","name":"ethAmount","type":"uint128"},{"indexed":false,"internalType":"uint256","name":"availableLiquidationAmount","type":"uint256"}],"name":"Liquidate","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":"implementation","type":"address"}],"name":"Upgraded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint64","name":"index","type":"uint64"},{"indexed":false,"internalType":"uint256","name":"withdrawTime","type":"uint256"},{"indexed":false,"internalType":"uint128","name":"withdrawAmount","type":"uint128"},{"indexed":false,"internalType":"uint128","name":"noOfAbond","type":"uint128"},{"indexed":false,"internalType":"uint256","name":"borrowDebt","type":"uint256"}],"name":"Withdraw","type":"event"},{"inputs":[],"name":"UPGRADE_INTERFACE_VERSION","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"admin","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"calculateCumulativeRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"uint256","name":"currentEthPrice","type":"uint256"}],"name":"calculateRatio","outputs":[{"internalType":"uint64","name":"","type":"uint64"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"enum IOptions.StrikePrice","name":"_strikePercent","type":"uint8"},{"internalType":"uint64","name":"_strikePrice","type":"uint64"},{"internalType":"uint256","name":"_volatility","type":"uint256"},{"internalType":"uint256","name":"_depositingAmount","type":"uint256"}],"name":"depositTokens","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"uint128","name":"aBondAmount","type":"uint128"}],"name":"getAbondYields","outputs":[{"internalType":"uint128","name":"","type":"uint128"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getLTV","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getUSDValue","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_tokenAddress","type":"address"},{"internalType":"address","name":"_cds","type":"address"},{"internalType":"address","name":"_abondToken","type":"address"},{"internalType":"address","name":"_multiSign","type":"address"},{"internalType":"address","name":"_priceFeedAddress","type":"address"},{"internalType":"uint64","name":"chainId","type":"uint64"},{"internalType":"address","name":"_globalVariables","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"lastCumulativeRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"uint64","name":"index","type":"uint64"}],"name":"liquidate","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"proxiableUUID","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"uint128","name":"aBondAmount","type":"uint128"}],"name":"redeemYields","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint8","name":"_APR","type":"uint8"},{"internalType":"uint128","name":"_ratePerSec","type":"uint128"}],"name":"setAPR","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_admin","type":"address"}],"name":"setAdmin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint64","name":"_bondRatio","type":"uint64"}],"name":"setBondRatio","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_borrowLiquidation","type":"address"}],"name":"setBorrowLiquidation","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint8","name":"_LTV","type":"uint8"}],"name":"setLTV","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_oldBorrow","type":"address"}],"name":"setOldBorrow","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_oldTreasury","type":"address"}],"name":"setOldTreasury","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_options","type":"address"}],"name":"setOptions","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_treasury","type":"address"}],"name":"setTreasury","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"updateLastEthVaultValue","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"usdaPrice","type":"uint32"}],"name":"updateRatePerSecByUSDaPrice","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newImplementation","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"upgradeToAndCall","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"usda","outputs":[{"internalType":"contract IUSDa","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_toAddress","type":"address"},{"internalType":"uint64","name":"_index","type":"uint64"}],"name":"withDraw","outputs":[],"stateMutability":"payable","type":"function"}]

60a0806040523461002a57306080526152d0908161003082396080518181816106fe01526108450152f35b600080fdfe6080604052600436101561001257600080fd5b60003560e01c8063181ab6db146101f75780632541eb0c146101f2578063276eb3ac146101ed5780632e4b3676146101e85780634ed2b8ac146101e35780634f1ef286146101de57806350593af7146101d957806352d1902d146101d457806355fe82a2146101cf578063661b7d3e146101ca5780636aa2ca3a146101c5578063704b6c02146101c057806370a88251146101bb578063715018a6146101b65780637d6dff7d146101b157806380ddebcb146101ac5780638da5cb5b146101a75780638e4db39a146101a25780639281b9851461019d578063a4cdc59714610198578063aad2476d14610193578063ab2f40ee1461018e578063ad3cb1cc14610189578063ada0b0ed14610184578063e2b19ff01461017f578063f0f442601461017a578063f2fde38b14610175578063f30707e114610170578063f851a4401461016b5763fd65d03f1461016657600080fd5b611861565b611838565b6117bd565b611794565b6116b0565b611687565b611655565b61160f565b6114cd565b6113dd565b6112f5565b611044565b611026565b610ff0565b610eef565b610e13565b610da5565b610c3d565b610b80565b610ad0565b610979565b61089d565b610832565b610817565b610687565b61059e565b6104c2565b61030e565b61024b565b61020c565b600091031261020757565b600080fd5b346102075760003660031901126102075760206102276150cf565b604051908152f35b60ff81160361020757565b6001600160801b0381160361020757565b34610207576040366003190112610207576004356102688161022f565b6024356102748161023a565b6005546040516326d2a55160e21b8152600360048201529290602090849060249082906000906001600160a01b03165af19283156102f8576102c8936102c3916000916102ca575b5015611f1d565b614fce565b005b6102eb915060203d81116102f1575b6102e3818361060b565b810190611e9f565b386102bc565b503d6102d9565b611a4e565b6001600160401b0381160361020757565b346102075760203660031901126102075760043561032b816102fd565b61034060018060a01b03600954163314611ddb565b6001600160401b038116156103f95760055461036c906001600160a01b03165b6001600160a01b031690565b604051631f71924f60e31b8152600760048201529190602090839060249082906000905af19182156102f8576102c8926103ae916000916103db575b50611eb3565b6012805467ffffffffffffffff60801b191660809290921b67ffffffffffffffff60801b16919091179055565b6103f3915060203d81116102f1576102e3818361060b565b386103a8565b60405162461bcd60e51b815260206004820152601860248201527f426f6e6420526174696f2063616e2774206265207a65726f00000000000000006044820152606490fd5b600435906001600160a01b038216820361020757565b602435906001600160a01b038216820361020757565b604435906001600160a01b038216820361020757565b606435906001600160a01b038216820361020757565b608435906001600160a01b038216820361020757565b60c435906001600160a01b038216820361020757565b34610207576020366003190112610207576104db61043e565b6009546001600160a01b03906104f49082163314611ddb565b8116908115159081610593575b501561052857601780546001600160a01b0319166001600160a01b03909216919091179055005b60405162461bcd60e51b815260206004820152603b60248201527f4f6c6420426f72726f77206d75737420626520636f6e7472616374206164647260448201527f65737320262063616e2774206265207a65726f206164647265737300000000006064820152608490fd5b90503b151538610501565b3461020757600036600319011261020757602060ff60095460a01c16604051908152f35b634e487b7160e01b600052604160045260246000fd5b6001600160401b0381116105eb57604052565b6105c2565b604081019081106001600160401b038211176105eb57604052565b90601f801991011681019081106001600160401b038211176105eb57604052565b6040519061032082018281106001600160401b038211176105eb57604052565b6040519061024082018281106001600160401b038211176105eb57604052565b6001600160401b0381116105eb57601f01601f191660200190565b6040806003193601126102075761069c61043e565b6024356001600160401b03811161020757366023820112156102075780600401356106c68161066c565b916106d38551938461060b565b8183523660248383010111610207578160009260246020930183860137830101526001600160a01b037f000000000000000000000000000000000000000000000000000000000000000081163081149081156107fb575b506107ea57602060049161073c611992565b85516352d1902d60e01b8152928391829087165afa600091816107ba575b5061077f578351634c9c8ce360e01b81526001600160a01b0384166004820152602490fd5b60008051602061525b83398151915281939293036107a1576102c88383611a5a565b8351632a87526960e21b81526004810191909152602490fd5b6107dc91925060203d81116107e3575b6107d4818361060b565b810190611a3f565b903861075a565b503d6107ca565b835163703e46dd60e11b8152600490fd5b90508160008051602061525b833981519152541614153861072a565b34610207576000366003190112610207576020610227614c3d565b34610207576000366003190112610207577f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316300361088b57602060405160008051602061525b8339815191528152f35b60405163703e46dd60e11b8152600490fd5b34610207576020366003190112610207576108b661043e565b6009546001600160a01b03906108cf9082163314611ddb565b811690811515908161096e575b501561090357601880546001600160a01b0319166001600160a01b03909216919091179055005b60405162461bcd60e51b815260206004820152603d60248201527f4f6c64205472656173757279206d75737420626520636f6e747261637420616460448201527f647265737320262063616e2774206265207a65726f20616464726573730000006064820152608490fd5b90503b1515386108dc565b3461020757602036600319011261020757600854600435906001600160a01b03163303610a78576109ab811515614cca565b6016546109c0906001600160a01b0316610360565b6040516336483edd60e01b815261032092908381600481865afa9384156102f857600094610a49575b50506109fa602084019182516122f9565b9052803b15610207576040516339ef448360e01b8152906000908290818381610a2688600483016127a5565b03925af180156102f857610a3657005b80610a436102c8926105d8565b806101fc565b610a69929450803d10610a71575b610a61818361060b565b8101906122e4565b9138806109e9565b503d610a57565b60405162461bcd60e51b815260206004820152602a60248201527f46756e6374696f6e2073686f756c64206f6e6c792062652063616c6c656420626044820152697920747265617375727960b01b6064820152608490fd5b608036600319011261020757600435600581101561020757602435610af4816102fd565b610afc613448565b6005546040516326d2a55160e21b8152600060048201819052909391602091859160249183916001600160a01b03165af19283156102f857610b5793610b4a916000916102ca575015611f1d565b60643591604435916128cb565b6102c860017f9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f0055565b3461020757602036600319011261020757610b9961043e565b610ba1611992565b6001600160a01b038116151580610c2f575b610bbc90611eba565b600554610bd1906001600160a01b0316610360565b604051631f71924f60e31b8152600360048201529190602090839060249082906000905af19182156102f8576102c892610c12916000916103db5750611eb3565b60018060a01b03166001600160601b0360a01b6009541617600955565b50803b151560011415610bb3565b346102075760e036600319011261020757610c5661043e565b610c5e610454565b90610c6761046a565b610c6f610480565b610c77610496565b60a43591610c84836102fd565b610c8c6104ac565b9360008051602061527b83398151915254966001600160401b0360ff8960401c1615981680159081610d9d575b6001149081610d93575b159081610d8a575b50610d785760008051602061527b833981519152805467ffffffffffffffff19166001179055610cff9688610d4e57611bf0565b610d0557005b60008051602061527b833981519152805460ff60401b19169055604051600181527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d290602090a1005b60008051602061527b833981519152805460ff60401b191668010000000000000000179055611bf0565b60405163f92ee8a960e01b8152600490fd5b90501538610ccb565b303b159150610cc3565b899150610cb9565b3461020757600080600319360112610e1057610dbf611992565b60008051602061523b83398151915280546001600160a01b0319811690915581906001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a380f35b80fd5b3461020757602036600319011261020757610e2c61043e565b6009546001600160a01b0390610e459082163314611ddb565b8116908115159081610ee4575b5015610e7957600480546001600160a01b0319166001600160a01b03909216919091179055005b60405162461bcd60e51b815260206004820152603860248201527f4f7074696f6e73206d75737420626520636f6e7472616374206164647265737360448201527f20262063616e2774206265207a65726f206164647265737300000000000000006064820152608490fd5b90503b151538610e52565b3461020757604036600319011261020757610f0861043e565b6020602435610f168161023a565b6000546002546001600160a01b039182169491610f929116600354610f43906001600160a01b0316610360565b60405163d4222e2b60e01b81526001600160a01b0394851660048201526001600160801b03909516602486015295831660448501528216606484015293166084820152918290819060a4820190565b038173980ab9ca184fafd7bf0e1fa8403298b2bcc12cf95af480156102f857610fce91600091610fd2575b506040519081529081906020820190565b0390f35b610fea915060203d81116107e3576107d4818361060b565b38610fbd565b346102075760003660031901126102075760008051602061523b833981519152546040516001600160a01b039091168152602090f35b34610207576000366003190112610207576020601054604051908152f35b6040806003193601126102075761105961043e565b9060243590611067826102fd565b60055481516326d2a55160e21b815260026004820152600094916001600160a01b0390602090839060249082908a9086165af19182156102f8576110da926110b69188916102ca575015611f1d565b6110c581600954163314611ddb565b82166110d2811515614a98565b331415614af0565b6110e26150cf565b506110f36110ee6132dc565b6132f6565b601654611108906001600160a01b0316610360565b91838051809463206153af60e01b825281806111278760048301612056565b03915afa9081156102f8576111fd9387926112c6575b5061117061115561115060115460801c90565b612631565b6001600160801b036011549181199060801b16911617601155565b600654611185906001600160a01b0316610360565b611190835134613548565b906111a861119c614c3d565b6001600160401b031690565b6010548851635fa578ff60e11b81526001600160a01b0390951660048601526001600160401b03998a166024860152981660448401526064830197909752608096919487928692909183919082906084820190565b03925af19081156102f85785938792611297575b50601654611227906001600160a01b0316610360565b9181519061125861123a60115460801c90565b975163382d5af960e11b815297889687958694339360048701614bb3565b03925af180156102f85761126a578280f35b8161128992903d10611290575b611281818361060b565b8101906127b6565b5038808280f35b503d611277565b6112b8919250843d86116112bf575b6112b0818361060b565b810190614b4a565b9038611211565b503d6112a6565b6112e7919250853d87116112ee575b6112df818361060b565b81019061201e565b903861113d565b503d6112d5565b346102075760203660031901126102075761130e61043e565b6009546001600160a01b03906113279082163314611ddb565b81169081151590816113d2575b501561135b57600680546001600160a01b0319166001600160a01b03909216919091179055005b60405162461bcd60e51b815260206004820152604360248201527f426f72726f77204c69717569646174696f6e206d75737420626520636f6e747260448201527f616374206164647265737320262063616e2774206265207a65726f206164647260648201526265737360e81b608482015260a490fd5b90503b151538611334565b34610207576020366003190112610207576004356113fa8161022f565b61140f60018060a01b03600954163314611ddb565b60ff8116156114945760055461142d906001600160a01b0316610360565b9060206040518093631f71924f60e31b82528160008161145560048201906000602083019252565b03925af19182156102f8576102c892611475916000916103db5750611eb3565b6009805460ff60a01b191660a09290921b60ff60a01b16919091179055565b60405162461bcd60e51b81526020600482015260116024820152704c54562063616e2774206265207a65726f60781b6044820152606490fd5b34610207576040366003190112610207576114e661043e565b60606024356114f48161023a565b600254600354604051630d22c2ff60e31b81526001600160a01b0395861660048201526001600160801b0393909316602484015290841660448301529290921660648301528160848173980ab9ca184fafd7bf0e1fa8403298b2bcc12cf95af480156102f85760009081928291611591575b50610fce90604051938493846040919493926001600160801b03606083019616825260208201520152565b9050610fce92506115b9915060603d81116115c0575b6115b1818361060b565b810190614a74565b9092611566565b503d6115a7565b60005b8381106115da5750506000910152565b81810151838201526020016115ca565b90602091611603815180928185528580860191016115c7565b601f01601f1916010190565b3461020757600036600319011261020757610fce60405161162f816105f0565b60058152640352e302e360dc1b60208201526040519182916020835260208301906115ea565b34610207576040366003190112610207576020611676602435600435614f2a565b6001600160401b0360405191168152f35b34610207576000366003190112610207576000546040516001600160a01b039091168152602090f35b34610207576020366003190112610207576116c961043e565b6009546001600160a01b03906116e29082163314611ddb565b8116908115158061178a575b6116f790611e20565b60055461170c906001600160a01b0316610360565b604051631f71924f60e31b8152600560048201529290602090849060249082906000905af19081156102f85761175061176d926102c8956000916103db5750611eb3565b60018060a01b03166001600160601b0360a01b6003541617600355565b60018060a01b03166001600160601b0360a01b6008541617600855565b50803b15156116ee565b34610207576020366003190112610207576102c86117b061043e565b6117b8611992565b6119cb565b6040366003190112610207576117d161043e565b6024356117dd816102fd565b6117e5613448565b6005546040516326d2a55160e21b8152600160048201529290602090849060249082906000906001600160a01b03165af19283156102f857610b5793611833916000916102ca575015611f1d565b61391d565b34610207576000366003190112610207576009546040516001600160a01b039091168152602090f35b346102075760203660031901126102075760043563ffffffff81168082036102075761189860018060a01b03600954163314611ddb565b15611958576040805163f5c11c3f60e01b815263ffffffff9290921660048301528160248173980ab9ca184fafd7bf0e1fa8403298b2bcc12cf95af49081156102f8576102c8916000918291611924575b506009805460ff60a81b191660a89290921b60ff60a81b169190911790555b6001600160801b03166001600160801b03196012541617601255565b611908925061194a915060403d8111611951575b611942818361060b565b8101906151c9565b90916118e9565b503d611938565b60405162461bcd60e51b8152602060048201526012602482015271496e76616c6964205553446120707269636560701b6044820152606490fd5b60008051602061523b833981519152546001600160a01b031633036119b357565b60405163118cdaa760e01b8152336004820152602490fd5b6001600160a01b03908116908115611a265760008051602061523b83398151915280546001600160a01b031981168417909155167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0600080a3565b604051631e4fbdf760e01b815260006004820152602490fd5b90816020910312610207575190565b6040513d6000823e3d90fd5b90813b15611ae05760008051602061525b83398151915280546001600160a01b0319166001600160a01b0384169081179091557fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b600080a2805115611ac557611ac291611b01565b50565b505034611ace57565b60405163b398979f60e01b8152600490fd5b604051634c9c8ce360e01b81526001600160a01b0383166004820152602490fd5b600080611b3f93602081519101845af43d15611b42573d91611b228361066c565b92611b30604051948561060b565b83523d6000602085013e611b46565b90565b6060915b90611b6d5750805115611b5b57805190602001fd5b604051630a12f52160e11b8152600490fd5b81511580611ba0575b611b7e575090565b604051639996b31560e01b81526001600160a01b039091166004820152602490fd5b50803b15611b76565b60405190611bb6826105f0565b600e82526d105d5d1bdb9bdb5a5b9d081554d160921b6020830152565b60405190611be0826105f0565b60018252603160f81b6020830152565b93929195611bfd336119cb565b60ff60008051602061527b8339815191525460401c1615611dc957600080546001600160a01b0319166001600160a01b03968716179055611d7496611ce995611ccc949093611cae92859291611c90918491611c7290831660018060a01b03166001600160601b0360a01b6001541617600155565b1660018060a01b03166001600160601b0360a01b6002541617600255565b1660018060a01b03166001600160601b0360a01b6005541617600555565b1660018060a01b03166001600160601b0360a01b6016541617601655565b60018060a01b03166001600160601b0360a01b600b541617600b55565b611cf1611ba9565b60208151910120611d6c611d03611bd3565b8051602091820120604080517f2010028ec63295361a00945794d4fce5b1046c419f60af448db7aaeb91e918f89381019384529081019490945260608401526001600160401b0390931660808301523060a08301528160c081015b03601f19810183528261060b565b519020601355565b611daa611d8e611d82614c3d565b6001600160801b031690565b6001600160801b03166001600160801b0319600c541617600c55565b601180546001600160801b031916426001600160801b0316179055565b565b604051631afcd79f60e31b8152600490fd5b15611de257565b60405162461bcd60e51b815260206004820152601660248201527521b0b63632b91034b9903737ba1030b71030b236b4b760511b6044820152606490fd5b15611e2757565b60405162461bcd60e51b815260206004820152603960248201527f5472656173757279206d75737420626520636f6e74726163742061646472657360448201527f7320262063616e2774206265207a65726f2061646472657373000000000000006064820152608490fd5b5190811515820361020757565b9081602091031261020757611b3f90611e92565b1561020757565b15611ec157565b60405162461bcd60e51b815260206004820152602e60248201527f41646d696e2063616e277420626520636f6e747261637420616464726573732060448201526d26207a65726f206164647265737360901b6064820152608490fd5b15611f2457565b60405162461bcd60e51b815260206004820152600660248201526514185d5cd95960d21b6044820152606490fd5b15611f5957565b60405162461bcd60e51b815260206004820152601a60248201527f43616e6e6f74206465706f736974207a65726f20746f6b656e730000000000006044820152606490fd5b15611fa557565b60405162461bcd60e51b815260206004820152602360248201527f426f72726f77696e673a20446f6e2774206861766520656e6f756768204c5a2060448201526266656560e81b6064820152608490fd5b91908260409103126102075760405161200e816105f0565b6020808294805184520151910152565b9060408282031261020757611b3f91611ff6565b91906040612051600092600186526060602087015260608601906115ea565b930152565b91906040612051600092600286526060602087015260608601906115ea565b634e487b7160e01b600052601160045260246000fd5b9190916001600160801b03808094169116029182169182036120a957565b612075565b156120b557565b60405162461bcd60e51b81526020600482015260166024820152754e6f7420656e6f7567682066756e6420696e2043445360501b6044820152606490fd5b9060058210156121005752565b634e487b7160e01b600052602160045260246000fd5b611dc7936060929695936001600160801b0360808401981683526020830152604082015201906120f3565b5190611dc7826102fd565b9081604091031261020757602060405191612166836105f0565b61216f81611e92565b8352015161217c816102fd565b602082015290565b5190611dc78261023a565b908160209103126102075751611b3f8161023a565b919082610320910312610207576121b961062c565b91805183526020810151602084015260408101516040840152606081015160608401526080810151608084015260a081015160a08401526121fc60c08201612184565b60c084015261220d60e08201612141565b60e0840152610100612220818301612141565b9084015261012080820151908401526101408082015190840152610160808201519084015261018080820151908401526101a080820151908401526101c0612269818301612184565b908401526101e080820151908401526102008082015190840152610220612291818301612184565b908401526102408082015190840152610260808201519084015261028080820151908401526102a080820151908401526102c080820151908401526102e080820151908401526103008091015190830152565b906103208282031261020757611b3f916121a4565b919082018092116120a957565b5190611dc78261022f565b8091036102608112610207576040519161232a836105f0565b8051612335816102fd565b83526102408092601f1901126102075761234d61064c565b9161235a60208301612141565b835261236860408301612184565b602084015261237960608301612184565b604084015261238a60808301612141565b606084015261239b60a08301612184565b60808401526123ac60c08301612184565b60a08401526123bd60e08301612184565b60c0840152610100916123d1838201611e92565b60e0850152610120926123e5848301612184565b90850152610140926123f8848301611e92565b908501526101609261240b848301612141565b908501526101809261241e848301612141565b908501526101a092612431848301612184565b908501526101c092612444848301612184565b908501526101e092612457848301612184565b908501526102009261246a848301612306565b90850152610220928382015190850152015190820152602082015290565b6001600160a01b0390911681526001600160401b03918216602082015282519091166040820152610280810192916102609060208101516001600160801b0316606084015260408101516001600160801b0316608084015260608101516001600160401b031660a084015260808101516001600160801b031660c084015260a08101516001600160801b031660e084015260c08101519061253761010092838601906001600160801b03169052565b60e08101519161254e610120938487019015159052565b8101519161256a61014093848701906001600160801b03169052565b8101519161257f610160938487019015159052565b8101519161259b61018093848701906001600160401b03169052565b810151916125b76101a093848701906001600160401b03169052565b810151916125d36101c093848701906001600160801b03169052565b810151916125ef6101e093848701906001600160801b03169052565b8101519161260b61020093848701906001600160801b03169052565b81015191612621610220938487019060ff169052565b8101516102408501520151910152565b6001600160801b038091169081146120a95760010190565b60001981146120a95760010190565b818102929181159184041417156120a957565b805182526020810151602083015260408101516040830152606081015160608301526080810151608083015260a081015160a08301526126bb60c082015160c08401906001600160801b03169052565b60e0818101516001600160401b031690830152610100818101516001600160401b03169083015261012081810151908301526101408082015190830152610160808201519083015261018080820151908301526101a080820151908301526101c0808201516001600160801b0316908301526101e081810151908301526102008082015190830152610220808201516001600160801b0316908301526102408082015190830152610260808201519083015261028080820151908301526102a080820151908301526102c080820151908301526102e0808201519083015261030080910151910152565b61032081019291611dc7919061266b565b6080818303126102075760405191606083018381106001600160401b038211176105eb576128009260409182528051855260208101516127f5816102fd565b602086015201611ff6565b604082015290565b9161283f9061282e60809396959660018652602086019060208091805184520151910152565b60a0606085015260a08401906115ea565b6001600160a01b03909416910152565b9997949195929c9b9a989693909c6101808b019d600160a01b60019003168b526001600160401b0380971660208c015260408b015260608a015260808901526001600160801b031660a088015260c08701521660e085015261010084015261012083016128bb916120f3565b60ff166101408201526101600152565b90926128d8811515611f52565b6128e3813411611f9e565b6128ee611d82614c3d565b906128fa6110ee6132dc565b601654909490612912906001600160a01b0316610360565b6040805163206153af60e01b81529591869081806129338b60048301612032565b03915afa9182156102f8576129b1956000936132b6575b5081602091612978614e206001600160401b036129706001600160801b038b168a614f2a565b1610156120ae565b6004548690600090612992906001600160a01b0316610360565b926040519a8b9586948593636916a18160e11b85528d60048601612116565b03925af180156102f857612a0d95600091613297575b5060095460209060a01c60ff16604051636812dc0360e01b8152600481018790526001600160801b038816602482015260ff909116604482015296879081906064820190565b038173980ab9ca184fafd7bf0e1fa8403298b2bcc12cf95af49586156102f857600096613276575b50600354612a4b906001600160a01b0316610360565b6040805163dcb71f3f60e01b81523360048201526001600160801b03881660248201526001600160401b034216604482015299918a90606490829089905af19889156102f857600099613245575b50612abf612abb612ab460208c01516001600160401b031690565b9a51151590565b1590565b61323357600354612ad8906001600160a01b0316610360565b604051637b85b73960e01b8152600160048201529790602090899060249082905afa9788156102f857600098613212575b50600254612b1f906001600160a01b0316610360565b604051632af2698d60e11b815260048101889052999060208b60248173980ab9ca184fafd7bf0e1fa8403298b2bcc12cf95af49a8b156102f85760009b6131f1575b50600354612b77906001600160a01b0316610360565b604051637b85b73960e01b81526001600482015290602090829060249082905afa9081156102f8576000916131d2575b50813b1561020757604051639992f4b760e01b81523360048201526001600160401b038e1660248201526001600160801b039c8d1660448201529b1660648c01528a6084815a6000948591f1998a156102f85760049a6131bf575b50612c0f84898933613555565b60165461032090612c28906001600160a01b0316610360565b6040516336483edd60e01b81529b8c9182905afa998a156102f85760009a61319c575b50600154612c61906001600160a01b0316610360565b60405163b87c3dc360e01b81526001600160801b03861660048201529690602090889060249082906000905af19687156102f85760009761316b575b50612cb66101c097888d01906001600160801b03169052565b6101408b01612cc68682516122f9565b9052600354612cdd906001600160a01b0316610360565b604051634d5c56a560e01b81523360048201526001600160401b038e1660248201526102608082604481865afa80156102f857612d439260209260009261313e575b505001516001600160801b03861660a0820152986001600160801b038816908a0152565b600954612d5b9060a81c60ff1660ff166101e08a0152565b803b1561020757604051632e449f1760e21b815233600482015260016024820152906000908290604490829084905af180156102f85761312b575b50600354612dac906001600160a01b0316610360565b96873b1561020757604051630e6840d960e11b815233600482015260248101859052976000908990604490829084905af19788156102f857612e4098613118575b50612df66150cf565b50601180546001600160801b031916426001600160801b0316179055601054604051633460dd8b60e11b815260048101869052602481019190915297602090899081906044820190565b038173980ab9ca184fafd7bf0e1fa8403298b2bcc12cf95af49788156102f8576000986130f7575b506001600160801b03881660c0820152612ea8612e976001600160801b038b166001600160401b03881661208b565b6001600160801b03166101a0830152565b600354612ebd906001600160a01b0316610360565b803b1561020757612eea916000918f836040518096819582946307fcd77f60e51b84523360048501612488565b03925af180156102f8576130e4575b50612f0e612f0988600a546122f9565b600a55565b612f2e896001600160801b03166001600160801b0319600c541617600c55565b612f39878c516122f9565b8b5260016001600160401b038d16146130b6575b6103008b01612f5c8151612649565b90526101e08b01612f6e8982516122f9565b9052612f83886001600160801b038b16612658565b612f936102008d019182516122f9565b9052601654612faa906001600160a01b0316610360565b803b15610207576040516339ef448360e01b81529b6000918d91829084908290612fd790600483016127a5565b03925af19182156102f8576130259b6080936130a3575b50601654613004906001600160a01b0316610360565b908251604051809e81958294632dec448f60e11b8452339160048501612808565b03925af19687156102f8577f047e772632ce862987044160c43583036943c98cdb74492e0438b017de03fd7b9a6001600160801b039a61308099613085575b5060095460a81c60ff16966040519b8c9b16984292338d61284f565b0390a1565b61309c9060803d811161129057611281818361060b565b5038613064565b80610a436130b0926105d8565b38612fee565b6130df6102208c016130d261115082516001600160801b031690565b6001600160801b03169052565b612f4d565b80610a436130f1926105d8565b38612ef9565b61311191985060203d6020116107e3576107d4818361060b565b9638612e68565b80610a43613125926105d8565b38612ded565b80610a43613138926105d8565b38612d96565b61315d9250803d10613164575b613155818361060b565b810190612311565b3880612d1f565b503d61314b565b61318e91975060203d602011613195575b613186818361060b565b81019061218f565b9538612c9d565b503d61317c565b6131b8919a506103203d61032011610a7157610a61818361060b565b9838612c4b565b80610a436131cc926105d8565b38612c02565b6131eb915060203d60201161319557613186818361060b565b38612ba7565b61320b919b5060203d60201161319557613186818361060b565b9938612b61565b61322c91985060203d60201161319557613186818361060b565b9638612b09565b604051634fad3b0960e01b8152600490fd5b61326891995060403d60401161326f575b613260818361060b565b81019061214c565b9738612a99565b503d613256565b61329091965060203d6020116107e3576107d4818361060b565b9438612a35565b6132b0915060203d6020116107e3576107d4818361060b565b386129c7565b60209193506132d4839160403d6040116112ee576112df818361060b565b93915061294a565b604051600360f01b602082015260028152611b3f816105f0565b61ffff600381613305846151ee565b16036133305750604051613d0960841b602082015260108152611b3f9161332b826105f0565b6133db565b61333b6024926151ee565b604051633a51740d60e01b815291166004820152fd5b61ffff600381613360846151ee565b16036133305750604051610c3560861b602082015260108152611b3f9161332b826105f0565b60209061339d6004959493828151948592016115c7565b600160f81b910181815260f09290921b6001600160f01b031916600183015260038201528151916133d6908390858401906020016115c7565b010190565b9061ffff916003836133ec836151ee565b160361343c57815183811161341d5783166001019283116120a957611d5e611b3f9260405194859360208501613386565b604490604051906306dfcc6560e41b8252601060048301526024820152fd5b8261333b6024926151ee565b7f9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f0060028154146134785760029055565b604051633ee5aeb560e01b8152600490fd5b1561349157565b60405162461bcd60e51b815260206004820152601f60248201527f426f72726f7765722063616e6e6f74206265207a65726f2061646472657373006044820152606490fd5b156134dd57565b60405162461bcd60e51b815260206004820152603860248201527f4c5456206d7573742062652073657420746f206e6f6e2d7a65726f2076616c7560448201527f65206265666f72652070726f766964696e67206c6f616e7300000000000000006064820152608490fd5b919082039182116120a957565b919291906135c6906135716001600160a01b038416151561348a565b60095460a01c60ff1661358860ff821615156134d6565b60405180938192636812dc0360e01b83526020988995600485019160409194936001600160801b0360ff926060860197865216602085015216910152565b038173980ab9ca184fafd7bf0e1fa8403298b2bcc12cf95af480156102f85761364a85916000938491613719575b50835461361590879061360f906001600160a01b0316610360565b92613548565b6040516340c10f1960e01b8082526001600160a01b039097166004820152602481019190915293849283919082906044820190565b03925af19081156102f8576000916136fc575b50156136cd576000546136b19284929091613680906001600160a01b0316610360565b6008546040519283526001600160a01b03166004830152602482019290925292839190829060009082906044820190565b03925af19182156102f8576000926136df575b5050156136cd57565b60405163035f563160e31b8152600490fd5b6136f59250803d106102f1576102e3818361060b565b38806136c4565b6137139150843d86116102f1576102e3818361060b565b3861365d565b6137309150833d85116107e3576107d4818361060b565b386135f4565b1561373d57565b60405162461bcd60e51b815260206004820152603060248201527f546f20616464726573732063616e6e6f742062652061207a65726f20616e642060448201526f636f6e7472616374206164647265737360801b6064820152608490fd5b908160209103126102075751611b3f816102fd565b156137b757565b60405162461bcd60e51b815260206004820152601f60248201527f5573657220616d6f756e7420686173206265656e206c697175696461746564006044820152606490fd5b1561380357565b60405162461bcd60e51b8152602060048201526016602482015275426f72726f77696e674865616c7468206973204c6f7760501b6044820152606490fd5b1561384857565b60405162461bcd60e51b815260206004820152602260248201527f557365722062616c616e6365206973206c657373207468616e20726571756972604482015261195960f21b6064820152608490fd5b906001600160801b038091169182156138b057160490565b634e487b7160e01b600052601260045260246000fd5b9190916001600160801b03808094169116019182116120a957565b6001600160801b0391821690821603919082116120a957565b6001600160801b031680156120a9576000190190565b80156120a9576000190190565b6001600160a01b0381161515806148cd575b61393890613736565b60185461394d906001600160a01b0316610360565b6040516339e9a67360e21b815233600482015290602090829060249082905afa9081156102f85760009161489e575b506001600160401b0383811691168111613a0357506017546139a6906001600160a01b0316610360565b91823b156102075760405163f30707e160e01b81526001600160a01b039290921660048301526001600160401b03166024820152906000908290604490829034905af180156102f8576139f65750565b80610a43611dc7926105d8565b9091613a1061119c614c3d565b91613a236001600160401b038416614db9565b50600c80546001600160801b0319166001600160401b038516179055600354613a54906001600160a01b0316610360565b604051634d5c56a560e01b81523360048201526001600160401b0384166024820152949061026090869060449082905afa9485156102f85760009561487b575b506020850151601654909290613ab2906001600160a01b0316610360565b9560405180976336483edd60e01b82528160046103209a8b935afa9788156102f857600098614854575b505051613af1906001600160401b031661119c565b1061480057613b0f613b0a612abb610120850151151590565b6137b0565b60e08201516147af57836020613b6c95613b3360808601516001600160801b031690565b604051636614cc0560e01b81526001600160801b0390911660048201526001600160401b03909116602482015295869081906044820190565b038173980ab9ca184fafd7bf0e1fa8403298b2bcc12cf95af49485156102f857600095614788575b5090613bf791613bb0611f406001600160801b038816116137fc565b6020613bc660c08601516001600160801b031690565b6010546040516350ad67e160e11b81526001600160801b039092166004830152602482015293849081906044820190565b038173980ab9ca184fafd7bf0e1fa8403298b2bcc12cf95af49283156102f857600093614767575b50613c286150cf565b50601180546001600160801b031916426001600160801b0316179055600054613c59906001600160a01b0316610360565b6040516370a0823160e01b815233600482015290602090829060249082905afa9081156102f857613c96918591600091614748575b501015613841565b6001600160401b038116610140850152600160e0850152426001600160401b0316610160850152613d0f602082613cd6828801516001600160801b031690565b60405163684d536d60e11b81526001600160801b0390911660048201526001600160401b03909116602482015291829081906044820190565b038173980ab9ca184fafd7bf0e1fa8403298b2bcc12cf95af49081156102f857600091614729575b506102608801613d488282516122f9565b9052600354613d5f906001600160a01b0316610360565b803b15610207576040516302c235d160e31b81526004810183905260016024820152906000908290604490829084905af180156102f857614716575b50613dbc81613db7611d8260a08901516001600160801b031690565b613548565b600054613dd1906001600160a01b0316610360565b6040516363a9f09360e11b81523360048201526024810183905290602090829060449082906000905af19081156102f8576000916146f7575b50156146e557600054613e7e91602091613e2c906001600160a01b0316610360565b600854613e43906001600160a01b03169289613548565b6040516323b872dd60e01b81523360048201526001600160a01b03909316602484015260448301529092839190829060009082906064820190565b03925af19081156102f8576000916146c6575b50156146b457613ebc612f09613eb4611d8260c08901516001600160801b031690565b600a54613548565b613edd613ed6611d8260c08801516001600160801b031690565b8951613548565b8852613eff613ef9611d8260a08801516001600160801b031690565b85613548565b613f0f6102408a019182516122f9565b9052600354613f26906001600160a01b0316610360565b90613f47613f41611d8260a08901516001600160801b031690565b86613548565b91803b156102075760405163b9a221eb60e01b815260048101939093526000908390602490829084905af19081156102f857613f9f92613f8e926146a1575b50873361491e565b6001600160801b0316610180860152565b600354613fb4906001600160a01b0316610360565b803b1561020757600060405180926307fcd77f60e51b8252818381613fde8b8d3360048501612488565b03925af180156102f85761468e575b5061403261400560208601516001600160801b031690565b61402d6001600160401b0384169161402760808901516001600160801b031690565b9061208b565b613898565b95612710806001600160801b0383161160001461461b5750506004546140b99190602090829061406a906001600160a01b0316610360565b828801516101a0890151604051630e1fab4360e01b81526001600160801b039283166004820152911660248201526001600160401b039290921660448301529093849190829081906064820190565b03915afa80156102f8576001600160401b036140e76141a7926141e29a6020966000926145fc575b506138c6565b92836140fc868a01516001600160801b031690565b6001600160801b0381166001600160801b038316116000146145b457505061414c61414761413f611d82614139898d01516001600160801b031690565b886138e1565b6014546122f9565b601455565b61416b611d82614165878b01516001600160801b031690565b866138e1565b61417a60808d019182516122f9565b90525b61419e614199614191848416601454612658565b6015546122f9565b601555565b16601454612658565b6141b660a08a019182516122f9565b90525b604051632af2698d60e11b81526001600160801b03909116600482015295869081906024820190565b038173980ab9ca184fafd7bf0e1fa8403298b2bcc12cf95af49485156102f857600095614593575b5061421b6142166132dc565b613351565b601654909190614233906001600160a01b0316610360565b6040805163206153af60e01b815298919089806142538760048301612032565b0381845afa9889156102f857600099614572575b5060035461427d906001600160a01b0316610360565b604051630c9c31bd60e01b815233600482015290602090829060249082905afa9081156102f857600091614553575b506142c4611d8260208901516001600160801b031690565b1461452d575b61030082016142d98151613910565b90526142f2611d8260208801516001600160801b031690565b6143026101e084019182516122f9565b905261431b611d8260408801516001600160801b031690565b61432b61020084019182516122f9565b9052803b15610207576040516339ef448360e01b815291600091839182908490829061435a90600483016127a5565b03925af180156102f8576143df92602092889261451a575b50600354899060009061438d906001600160a01b0316610360565b6040516315ee073360e11b81523360048201526001600160a01b0390941660248501526001600160801b0390921660448401526001600160401b03909316606483015290938492839182906084820190565b03925af19081156102f8576000916144fb575b50156144e957601654614437966080929091614416906001600160a01b0316610360565b908251604051809a81958294632dec448f60e11b8452339160048501612808565b03925af19485156102f85761018061308093614483927f59c54db06277209213236b5f864552e9ee789e1ca98ed9988d78cdea7bd4d9d4986144ca575b5001516001600160801b031690565b604080513381526001600160401b03909516602086015242908501526001600160801b03948516606085015293909316608083015260a082019290925290819060c0820190565b6144e29060803d60801161129057611281818361060b565b5038614474565b604051635e5e86d560e01b8152600490fd5b614514915060203d6020116102f1576102e3818361060b565b386143f2565b80610a43614527926105d8565b38614372565b61454e61022083016130d261454982516001600160801b031690565b6138fa565b6142ca565b61456c915060203d6020116107e3576107d4818361060b565b386142ac565b61458c91995060403d6040116112ee576112df818361060b565b9738614267565b6145ad91955060203d60201161319557613186818361060b565b933861420a565b61413f611d826145c793614147936138e1565b6145e6611d82856145e1888c01516001600160801b031690565b6138e1565b6145f560808d019182516122f9565b905261417d565b614614919250873d891161319557613186818361060b565b90386140e1565b9296929091506001600160801b038216810361463f5750509360206141e2956141b9565b6001600160801b038216611f40109250908261467b575b505015613803576141e2936020614676818501516001600160801b031690565b6141b9565b6001600160801b03161090503880614656565b80610a4361469b926105d8565b38613fed565b80610a436146ae926105d8565b38613f86565b60405163a07c821960e01b8152600490fd5b6146df915060203d6020116102f1576102e3818361060b565b38613e91565b6040516303f7009160e51b8152600490fd5b614710915060203d6020116102f1576102e3818361060b565b38613e0a565b80610a43614723926105d8565b38613d9b565b614742915060203d6020116107e3576107d4818361060b565b38613d37565b614761915060203d6020116107e3576107d4818361060b565b38613c8e565b61478191935060203d6020116107e3576107d4818361060b565b9138613c1f565b613bf7929195506147a79060203d60201161319557613186818361060b565b949091613b94565b60405162461bcd60e51b815260206004820152602360248201527f5573657220616c726561647920776974686472617720656e7469726520616d6f6044820152621d5b9d60ea1b6064820152608490fd5b60405162461bcd60e51b815260206004820152602660248201527f5573657220646f656e73277420686176652074686520706572746963756c6172604482015265040d2dcc8caf60d31b6064820152608490fd5b613af192985061119c918161487492903d10610a7157610a61818361060b565b9791613adc565b6148979195506102603d6102601161316457613155818361060b565b9338613a94565b6148c0915060203d6020116148c6575b6148b8818361060b565b81019061379b565b3861397c565b503d6148ae565b50803b15156001141561392f565b156148e257565b60405162461bcd60e51b8152602060048201526014602482015273416d6f756e742063616e2774206265207a65726f60601b6044820152606490fd5b6149326001600160a01b038216151561348a565b61493d8315156148db565b601254604051631f79572960e11b8152600481019490945260801c6001600160401b03166024840152602091828460448173980ab9ca184fafd7bf0e1fa8403298b2bcc12cf95af49384156102f857600094614a4d575b50600254614a0192849286926000906149b5906001600160a01b0316610360565b604051631ff9eb7f60e21b81526001600160a01b0390941660048501526001600160401b0390921660248401526001600160801b03909316604483015290938492839182906064820190565b03925af19182156102f857600092614a30575b505015614a1e5790565b6040516328eca99f60e21b8152600490fd5b614a469250803d106102f1576102e3818361060b565b3880614a14565b614a0192945090614a6b8492833d851161319557613186818361060b565b94925090614994565b90816060910312610207578051614a8a8161023a565b916040602083015192015190565b15614a9f57565b60405162461bcd60e51b815260206004820152602360248201527f546f20616464726573732063616e6e6f742062652061207a65726f206164647260448201526265737360e81b6064820152608490fd5b15614af757565b60405162461bcd60e51b815260206004820152602560248201527f596f752063616e6e6f74206c697175696461746520796f7572206f776e206173604482015264736574732160d81b6064820152608490fd5b90816080910312610207576040519060808201908282106001600160401b038311176105eb576060916040528051614b818161023a565b83526020810151614b918161023a565b60208401526040810151614ba48161023a565b60408401520151606082015290565b939061012093606061283f94614c1493999899600289526001600160801b0380911660208a01528082511660408a015280602083015116838a01526040820151166080890152015160a087015260c086019060208091805184520151910152565b610140806101008601528401906115ea565b519069ffffffffffffffffffff8216820361020757565b600b54604051633fabe5a360e21b81529060a090829060049082906001600160a01b03165afa80156102f857600090614c7b575b620f424091500490565b60a0823d8211614cc2575b81614c9360a0938361060b565b81010312610e10575080614caa620f424092614c26565b50614cbc608060208301519201614c26565b50614c71565b3d9150614c86565b15614cd157565b60405162461bcd60e51b815260206004820152602260248201527f4c61737420455448207661756c742076616c75652063616e2774206265207a65604482015261726f60f01b6064820152608490fd5b91906103408382031261020757611b3f9060208451614d3f816102fd565b94016121a4565b9095949293611dc7946001600160801b0360a0946103c085019960008652602086015216604084015260608301526080820152019061266b565b91936001600160801b0360a094611dc797939998966103c086019a8652602086015216604084015260608301526080820152019061266b565b8015614f1857601654614dd4906001600160a01b0316610360565b60405180916336483edd60e01b82528160046103209485935afa9182156102f857600092614efb575b5050600c546001600160801b03169161030082015161012083015190614e3d6040519485938493632c5ed22d60e01b855261034098899760048701614d46565b038173980ab9ca184fafd7bf0e1fa8403298b2bcc12cf95af49081156102f8576000928392614eca575b5050601654614e7e906001600160a01b0316610360565b803b15610207576040516339ef448360e01b8152916000918391829084908290614eab90600483016127a5565b03925af180156102f857614ebd575090565b80610a43611b3f926105d8565b614eed935080919250903d10614ef4575b614ee5818361060b565b810190614d21565b3880614e67565b503d614edb565b614f119250803d10610a7157610a61818361060b565b3880614dfd565b6040516315e73e9f60e01b8152600490fd5b8115614f1857601654614f45906001600160a01b0316610360565b9060405180926336483edd60e01b82528160046103209586935afa9283156102f857600093614faf575b5050600c546001600160801b031661030083015190614e3d610120850151946040519586948594632c5ed22d60e01b8652610340998a9860048801614d80565b614fc6929350803d10610a7157610a61818361060b565b903880614f6f565b90614fe460018060a01b03600954163314611ddb565b6001600160801b038116151580615077575b614fff90615083565b600554615014906001600160a01b0316610360565b604051631f71924f60e31b8152600160048201529290602090849060249082906000905af19081156102f85761505861190892611dc7956000916103db5750611eb3565b6009805460ff60a81b191660a89290921b60ff60a81b16919091179055565b5060ff82161515614ff6565b1561508a57565b60405162461bcd60e51b815260206004820152601760248201527f526174652073686f756c64206e6f74206265207a65726f0000000000000000006044820152606490fd5b6003546150e4906001600160a01b0316610360565b60405180916322d7586760e11b825281600460209485935afa9081156102f8576000916151ac575b50816151206012546001600160801b031690565b601154601054604051635529dfd560e01b81526001600160801b03958616600482015292851660248401529316604482015260648101929092528160848173980ab9ca184fafd7bf0e1fa8403298b2bcc12cf95af49182156102f85760009261518f575b5050611b3f81601055565b6151a59250803d106107e3576107d4818361060b565b3880615184565b6151c39150823d841161319557613186818361060b565b3861510c565b919082604091031261020757602082516151e28161023a565b920151611b3f8161022f565b60028151106151fe576002015190565b60405162461bcd60e51b8152602060048201526014602482015273746f55696e7431365f6f75744f66426f756e647360601b6044820152606490fdfe9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c199300360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbcf0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00a26469706673582212209af00f48a7fd6f158604c072b0aad6a52d7cfde19bd70ebdce65d3921f87455a64736f6c63430008140033

Deployed Bytecode

0x6080604052600436101561001257600080fd5b60003560e01c8063181ab6db146101f75780632541eb0c146101f2578063276eb3ac146101ed5780632e4b3676146101e85780634ed2b8ac146101e35780634f1ef286146101de57806350593af7146101d957806352d1902d146101d457806355fe82a2146101cf578063661b7d3e146101ca5780636aa2ca3a146101c5578063704b6c02146101c057806370a88251146101bb578063715018a6146101b65780637d6dff7d146101b157806380ddebcb146101ac5780638da5cb5b146101a75780638e4db39a146101a25780639281b9851461019d578063a4cdc59714610198578063aad2476d14610193578063ab2f40ee1461018e578063ad3cb1cc14610189578063ada0b0ed14610184578063e2b19ff01461017f578063f0f442601461017a578063f2fde38b14610175578063f30707e114610170578063f851a4401461016b5763fd65d03f1461016657600080fd5b611861565b611838565b6117bd565b611794565b6116b0565b611687565b611655565b61160f565b6114cd565b6113dd565b6112f5565b611044565b611026565b610ff0565b610eef565b610e13565b610da5565b610c3d565b610b80565b610ad0565b610979565b61089d565b610832565b610817565b610687565b61059e565b6104c2565b61030e565b61024b565b61020c565b600091031261020757565b600080fd5b346102075760003660031901126102075760206102276150cf565b604051908152f35b60ff81160361020757565b6001600160801b0381160361020757565b34610207576040366003190112610207576004356102688161022f565b6024356102748161023a565b6005546040516326d2a55160e21b8152600360048201529290602090849060249082906000906001600160a01b03165af19283156102f8576102c8936102c3916000916102ca575b5015611f1d565b614fce565b005b6102eb915060203d81116102f1575b6102e3818361060b565b810190611e9f565b386102bc565b503d6102d9565b611a4e565b6001600160401b0381160361020757565b346102075760203660031901126102075760043561032b816102fd565b61034060018060a01b03600954163314611ddb565b6001600160401b038116156103f95760055461036c906001600160a01b03165b6001600160a01b031690565b604051631f71924f60e31b8152600760048201529190602090839060249082906000905af19182156102f8576102c8926103ae916000916103db575b50611eb3565b6012805467ffffffffffffffff60801b191660809290921b67ffffffffffffffff60801b16919091179055565b6103f3915060203d81116102f1576102e3818361060b565b386103a8565b60405162461bcd60e51b815260206004820152601860248201527f426f6e6420526174696f2063616e2774206265207a65726f00000000000000006044820152606490fd5b600435906001600160a01b038216820361020757565b602435906001600160a01b038216820361020757565b604435906001600160a01b038216820361020757565b606435906001600160a01b038216820361020757565b608435906001600160a01b038216820361020757565b60c435906001600160a01b038216820361020757565b34610207576020366003190112610207576104db61043e565b6009546001600160a01b03906104f49082163314611ddb565b8116908115159081610593575b501561052857601780546001600160a01b0319166001600160a01b03909216919091179055005b60405162461bcd60e51b815260206004820152603b60248201527f4f6c6420426f72726f77206d75737420626520636f6e7472616374206164647260448201527f65737320262063616e2774206265207a65726f206164647265737300000000006064820152608490fd5b90503b151538610501565b3461020757600036600319011261020757602060ff60095460a01c16604051908152f35b634e487b7160e01b600052604160045260246000fd5b6001600160401b0381116105eb57604052565b6105c2565b604081019081106001600160401b038211176105eb57604052565b90601f801991011681019081106001600160401b038211176105eb57604052565b6040519061032082018281106001600160401b038211176105eb57604052565b6040519061024082018281106001600160401b038211176105eb57604052565b6001600160401b0381116105eb57601f01601f191660200190565b6040806003193601126102075761069c61043e565b6024356001600160401b03811161020757366023820112156102075780600401356106c68161066c565b916106d38551938461060b565b8183523660248383010111610207578160009260246020930183860137830101526001600160a01b037f000000000000000000000000a9b38466a776dd9ec25e5fe3ca472eadcae034b181163081149081156107fb575b506107ea57602060049161073c611992565b85516352d1902d60e01b8152928391829087165afa600091816107ba575b5061077f578351634c9c8ce360e01b81526001600160a01b0384166004820152602490fd5b60008051602061525b83398151915281939293036107a1576102c88383611a5a565b8351632a87526960e21b81526004810191909152602490fd5b6107dc91925060203d81116107e3575b6107d4818361060b565b810190611a3f565b903861075a565b503d6107ca565b835163703e46dd60e11b8152600490fd5b90508160008051602061525b833981519152541614153861072a565b34610207576000366003190112610207576020610227614c3d565b34610207576000366003190112610207577f000000000000000000000000a9b38466a776dd9ec25e5fe3ca472eadcae034b16001600160a01b0316300361088b57602060405160008051602061525b8339815191528152f35b60405163703e46dd60e11b8152600490fd5b34610207576020366003190112610207576108b661043e565b6009546001600160a01b03906108cf9082163314611ddb565b811690811515908161096e575b501561090357601880546001600160a01b0319166001600160a01b03909216919091179055005b60405162461bcd60e51b815260206004820152603d60248201527f4f6c64205472656173757279206d75737420626520636f6e747261637420616460448201527f647265737320262063616e2774206265207a65726f20616464726573730000006064820152608490fd5b90503b1515386108dc565b3461020757602036600319011261020757600854600435906001600160a01b03163303610a78576109ab811515614cca565b6016546109c0906001600160a01b0316610360565b6040516336483edd60e01b815261032092908381600481865afa9384156102f857600094610a49575b50506109fa602084019182516122f9565b9052803b15610207576040516339ef448360e01b8152906000908290818381610a2688600483016127a5565b03925af180156102f857610a3657005b80610a436102c8926105d8565b806101fc565b610a69929450803d10610a71575b610a61818361060b565b8101906122e4565b9138806109e9565b503d610a57565b60405162461bcd60e51b815260206004820152602a60248201527f46756e6374696f6e2073686f756c64206f6e6c792062652063616c6c656420626044820152697920747265617375727960b01b6064820152608490fd5b608036600319011261020757600435600581101561020757602435610af4816102fd565b610afc613448565b6005546040516326d2a55160e21b8152600060048201819052909391602091859160249183916001600160a01b03165af19283156102f857610b5793610b4a916000916102ca575015611f1d565b60643591604435916128cb565b6102c860017f9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f0055565b3461020757602036600319011261020757610b9961043e565b610ba1611992565b6001600160a01b038116151580610c2f575b610bbc90611eba565b600554610bd1906001600160a01b0316610360565b604051631f71924f60e31b8152600360048201529190602090839060249082906000905af19182156102f8576102c892610c12916000916103db5750611eb3565b60018060a01b03166001600160601b0360a01b6009541617600955565b50803b151560011415610bb3565b346102075760e036600319011261020757610c5661043e565b610c5e610454565b90610c6761046a565b610c6f610480565b610c77610496565b60a43591610c84836102fd565b610c8c6104ac565b9360008051602061527b83398151915254966001600160401b0360ff8960401c1615981680159081610d9d575b6001149081610d93575b159081610d8a575b50610d785760008051602061527b833981519152805467ffffffffffffffff19166001179055610cff9688610d4e57611bf0565b610d0557005b60008051602061527b833981519152805460ff60401b19169055604051600181527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d290602090a1005b60008051602061527b833981519152805460ff60401b191668010000000000000000179055611bf0565b60405163f92ee8a960e01b8152600490fd5b90501538610ccb565b303b159150610cc3565b899150610cb9565b3461020757600080600319360112610e1057610dbf611992565b60008051602061523b83398151915280546001600160a01b0319811690915581906001600160a01b03167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a380f35b80fd5b3461020757602036600319011261020757610e2c61043e565b6009546001600160a01b0390610e459082163314611ddb565b8116908115159081610ee4575b5015610e7957600480546001600160a01b0319166001600160a01b03909216919091179055005b60405162461bcd60e51b815260206004820152603860248201527f4f7074696f6e73206d75737420626520636f6e7472616374206164647265737360448201527f20262063616e2774206265207a65726f206164647265737300000000000000006064820152608490fd5b90503b151538610e52565b3461020757604036600319011261020757610f0861043e565b6020602435610f168161023a565b6000546002546001600160a01b039182169491610f929116600354610f43906001600160a01b0316610360565b60405163d4222e2b60e01b81526001600160a01b0394851660048201526001600160801b03909516602486015295831660448501528216606484015293166084820152918290819060a4820190565b038173980ab9ca184fafd7bf0e1fa8403298b2bcc12cf95af480156102f857610fce91600091610fd2575b506040519081529081906020820190565b0390f35b610fea915060203d81116107e3576107d4818361060b565b38610fbd565b346102075760003660031901126102075760008051602061523b833981519152546040516001600160a01b039091168152602090f35b34610207576000366003190112610207576020601054604051908152f35b6040806003193601126102075761105961043e565b9060243590611067826102fd565b60055481516326d2a55160e21b815260026004820152600094916001600160a01b0390602090839060249082908a9086165af19182156102f8576110da926110b69188916102ca575015611f1d565b6110c581600954163314611ddb565b82166110d2811515614a98565b331415614af0565b6110e26150cf565b506110f36110ee6132dc565b6132f6565b601654611108906001600160a01b0316610360565b91838051809463206153af60e01b825281806111278760048301612056565b03915afa9081156102f8576111fd9387926112c6575b5061117061115561115060115460801c90565b612631565b6001600160801b036011549181199060801b16911617601155565b600654611185906001600160a01b0316610360565b611190835134613548565b906111a861119c614c3d565b6001600160401b031690565b6010548851635fa578ff60e11b81526001600160a01b0390951660048601526001600160401b03998a166024860152981660448401526064830197909752608096919487928692909183919082906084820190565b03925af19081156102f85785938792611297575b50601654611227906001600160a01b0316610360565b9181519061125861123a60115460801c90565b975163382d5af960e11b815297889687958694339360048701614bb3565b03925af180156102f85761126a578280f35b8161128992903d10611290575b611281818361060b565b8101906127b6565b5038808280f35b503d611277565b6112b8919250843d86116112bf575b6112b0818361060b565b810190614b4a565b9038611211565b503d6112a6565b6112e7919250853d87116112ee575b6112df818361060b565b81019061201e565b903861113d565b503d6112d5565b346102075760203660031901126102075761130e61043e565b6009546001600160a01b03906113279082163314611ddb565b81169081151590816113d2575b501561135b57600680546001600160a01b0319166001600160a01b03909216919091179055005b60405162461bcd60e51b815260206004820152604360248201527f426f72726f77204c69717569646174696f6e206d75737420626520636f6e747260448201527f616374206164647265737320262063616e2774206265207a65726f206164647260648201526265737360e81b608482015260a490fd5b90503b151538611334565b34610207576020366003190112610207576004356113fa8161022f565b61140f60018060a01b03600954163314611ddb565b60ff8116156114945760055461142d906001600160a01b0316610360565b9060206040518093631f71924f60e31b82528160008161145560048201906000602083019252565b03925af19182156102f8576102c892611475916000916103db5750611eb3565b6009805460ff60a01b191660a09290921b60ff60a01b16919091179055565b60405162461bcd60e51b81526020600482015260116024820152704c54562063616e2774206265207a65726f60781b6044820152606490fd5b34610207576040366003190112610207576114e661043e565b60606024356114f48161023a565b600254600354604051630d22c2ff60e31b81526001600160a01b0395861660048201526001600160801b0393909316602484015290841660448301529290921660648301528160848173980ab9ca184fafd7bf0e1fa8403298b2bcc12cf95af480156102f85760009081928291611591575b50610fce90604051938493846040919493926001600160801b03606083019616825260208201520152565b9050610fce92506115b9915060603d81116115c0575b6115b1818361060b565b810190614a74565b9092611566565b503d6115a7565b60005b8381106115da5750506000910152565b81810151838201526020016115ca565b90602091611603815180928185528580860191016115c7565b601f01601f1916010190565b3461020757600036600319011261020757610fce60405161162f816105f0565b60058152640352e302e360dc1b60208201526040519182916020835260208301906115ea565b34610207576040366003190112610207576020611676602435600435614f2a565b6001600160401b0360405191168152f35b34610207576000366003190112610207576000546040516001600160a01b039091168152602090f35b34610207576020366003190112610207576116c961043e565b6009546001600160a01b03906116e29082163314611ddb565b8116908115158061178a575b6116f790611e20565b60055461170c906001600160a01b0316610360565b604051631f71924f60e31b8152600560048201529290602090849060249082906000905af19081156102f85761175061176d926102c8956000916103db5750611eb3565b60018060a01b03166001600160601b0360a01b6003541617600355565b60018060a01b03166001600160601b0360a01b6008541617600855565b50803b15156116ee565b34610207576020366003190112610207576102c86117b061043e565b6117b8611992565b6119cb565b6040366003190112610207576117d161043e565b6024356117dd816102fd565b6117e5613448565b6005546040516326d2a55160e21b8152600160048201529290602090849060249082906000906001600160a01b03165af19283156102f857610b5793611833916000916102ca575015611f1d565b61391d565b34610207576000366003190112610207576009546040516001600160a01b039091168152602090f35b346102075760203660031901126102075760043563ffffffff81168082036102075761189860018060a01b03600954163314611ddb565b15611958576040805163f5c11c3f60e01b815263ffffffff9290921660048301528160248173980ab9ca184fafd7bf0e1fa8403298b2bcc12cf95af49081156102f8576102c8916000918291611924575b506009805460ff60a81b191660a89290921b60ff60a81b169190911790555b6001600160801b03166001600160801b03196012541617601255565b611908925061194a915060403d8111611951575b611942818361060b565b8101906151c9565b90916118e9565b503d611938565b60405162461bcd60e51b8152602060048201526012602482015271496e76616c6964205553446120707269636560701b6044820152606490fd5b60008051602061523b833981519152546001600160a01b031633036119b357565b60405163118cdaa760e01b8152336004820152602490fd5b6001600160a01b03908116908115611a265760008051602061523b83398151915280546001600160a01b031981168417909155167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0600080a3565b604051631e4fbdf760e01b815260006004820152602490fd5b90816020910312610207575190565b6040513d6000823e3d90fd5b90813b15611ae05760008051602061525b83398151915280546001600160a01b0319166001600160a01b0384169081179091557fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b600080a2805115611ac557611ac291611b01565b50565b505034611ace57565b60405163b398979f60e01b8152600490fd5b604051634c9c8ce360e01b81526001600160a01b0383166004820152602490fd5b600080611b3f93602081519101845af43d15611b42573d91611b228361066c565b92611b30604051948561060b565b83523d6000602085013e611b46565b90565b6060915b90611b6d5750805115611b5b57805190602001fd5b604051630a12f52160e11b8152600490fd5b81511580611ba0575b611b7e575090565b604051639996b31560e01b81526001600160a01b039091166004820152602490fd5b50803b15611b76565b60405190611bb6826105f0565b600e82526d105d5d1bdb9bdb5a5b9d081554d160921b6020830152565b60405190611be0826105f0565b60018252603160f81b6020830152565b93929195611bfd336119cb565b60ff60008051602061527b8339815191525460401c1615611dc957600080546001600160a01b0319166001600160a01b03968716179055611d7496611ce995611ccc949093611cae92859291611c90918491611c7290831660018060a01b03166001600160601b0360a01b6001541617600155565b1660018060a01b03166001600160601b0360a01b6002541617600255565b1660018060a01b03166001600160601b0360a01b6005541617600555565b1660018060a01b03166001600160601b0360a01b6016541617601655565b60018060a01b03166001600160601b0360a01b600b541617600b55565b611cf1611ba9565b60208151910120611d6c611d03611bd3565b8051602091820120604080517f2010028ec63295361a00945794d4fce5b1046c419f60af448db7aaeb91e918f89381019384529081019490945260608401526001600160401b0390931660808301523060a08301528160c081015b03601f19810183528261060b565b519020601355565b611daa611d8e611d82614c3d565b6001600160801b031690565b6001600160801b03166001600160801b0319600c541617600c55565b601180546001600160801b031916426001600160801b0316179055565b565b604051631afcd79f60e31b8152600490fd5b15611de257565b60405162461bcd60e51b815260206004820152601660248201527521b0b63632b91034b9903737ba1030b71030b236b4b760511b6044820152606490fd5b15611e2757565b60405162461bcd60e51b815260206004820152603960248201527f5472656173757279206d75737420626520636f6e74726163742061646472657360448201527f7320262063616e2774206265207a65726f2061646472657373000000000000006064820152608490fd5b5190811515820361020757565b9081602091031261020757611b3f90611e92565b1561020757565b15611ec157565b60405162461bcd60e51b815260206004820152602e60248201527f41646d696e2063616e277420626520636f6e747261637420616464726573732060448201526d26207a65726f206164647265737360901b6064820152608490fd5b15611f2457565b60405162461bcd60e51b815260206004820152600660248201526514185d5cd95960d21b6044820152606490fd5b15611f5957565b60405162461bcd60e51b815260206004820152601a60248201527f43616e6e6f74206465706f736974207a65726f20746f6b656e730000000000006044820152606490fd5b15611fa557565b60405162461bcd60e51b815260206004820152602360248201527f426f72726f77696e673a20446f6e2774206861766520656e6f756768204c5a2060448201526266656560e81b6064820152608490fd5b91908260409103126102075760405161200e816105f0565b6020808294805184520151910152565b9060408282031261020757611b3f91611ff6565b91906040612051600092600186526060602087015260608601906115ea565b930152565b91906040612051600092600286526060602087015260608601906115ea565b634e487b7160e01b600052601160045260246000fd5b9190916001600160801b03808094169116029182169182036120a957565b612075565b156120b557565b60405162461bcd60e51b81526020600482015260166024820152754e6f7420656e6f7567682066756e6420696e2043445360501b6044820152606490fd5b9060058210156121005752565b634e487b7160e01b600052602160045260246000fd5b611dc7936060929695936001600160801b0360808401981683526020830152604082015201906120f3565b5190611dc7826102fd565b9081604091031261020757602060405191612166836105f0565b61216f81611e92565b8352015161217c816102fd565b602082015290565b5190611dc78261023a565b908160209103126102075751611b3f8161023a565b919082610320910312610207576121b961062c565b91805183526020810151602084015260408101516040840152606081015160608401526080810151608084015260a081015160a08401526121fc60c08201612184565b60c084015261220d60e08201612141565b60e0840152610100612220818301612141565b9084015261012080820151908401526101408082015190840152610160808201519084015261018080820151908401526101a080820151908401526101c0612269818301612184565b908401526101e080820151908401526102008082015190840152610220612291818301612184565b908401526102408082015190840152610260808201519084015261028080820151908401526102a080820151908401526102c080820151908401526102e080820151908401526103008091015190830152565b906103208282031261020757611b3f916121a4565b919082018092116120a957565b5190611dc78261022f565b8091036102608112610207576040519161232a836105f0565b8051612335816102fd565b83526102408092601f1901126102075761234d61064c565b9161235a60208301612141565b835261236860408301612184565b602084015261237960608301612184565b604084015261238a60808301612141565b606084015261239b60a08301612184565b60808401526123ac60c08301612184565b60a08401526123bd60e08301612184565b60c0840152610100916123d1838201611e92565b60e0850152610120926123e5848301612184565b90850152610140926123f8848301611e92565b908501526101609261240b848301612141565b908501526101809261241e848301612141565b908501526101a092612431848301612184565b908501526101c092612444848301612184565b908501526101e092612457848301612184565b908501526102009261246a848301612306565b90850152610220928382015190850152015190820152602082015290565b6001600160a01b0390911681526001600160401b03918216602082015282519091166040820152610280810192916102609060208101516001600160801b0316606084015260408101516001600160801b0316608084015260608101516001600160401b031660a084015260808101516001600160801b031660c084015260a08101516001600160801b031660e084015260c08101519061253761010092838601906001600160801b03169052565b60e08101519161254e610120938487019015159052565b8101519161256a61014093848701906001600160801b03169052565b8101519161257f610160938487019015159052565b8101519161259b61018093848701906001600160401b03169052565b810151916125b76101a093848701906001600160401b03169052565b810151916125d36101c093848701906001600160801b03169052565b810151916125ef6101e093848701906001600160801b03169052565b8101519161260b61020093848701906001600160801b03169052565b81015191612621610220938487019060ff169052565b8101516102408501520151910152565b6001600160801b038091169081146120a95760010190565b60001981146120a95760010190565b818102929181159184041417156120a957565b805182526020810151602083015260408101516040830152606081015160608301526080810151608083015260a081015160a08301526126bb60c082015160c08401906001600160801b03169052565b60e0818101516001600160401b031690830152610100818101516001600160401b03169083015261012081810151908301526101408082015190830152610160808201519083015261018080820151908301526101a080820151908301526101c0808201516001600160801b0316908301526101e081810151908301526102008082015190830152610220808201516001600160801b0316908301526102408082015190830152610260808201519083015261028080820151908301526102a080820151908301526102c080820151908301526102e0808201519083015261030080910151910152565b61032081019291611dc7919061266b565b6080818303126102075760405191606083018381106001600160401b038211176105eb576128009260409182528051855260208101516127f5816102fd565b602086015201611ff6565b604082015290565b9161283f9061282e60809396959660018652602086019060208091805184520151910152565b60a0606085015260a08401906115ea565b6001600160a01b03909416910152565b9997949195929c9b9a989693909c6101808b019d600160a01b60019003168b526001600160401b0380971660208c015260408b015260608a015260808901526001600160801b031660a088015260c08701521660e085015261010084015261012083016128bb916120f3565b60ff166101408201526101600152565b90926128d8811515611f52565b6128e3813411611f9e565b6128ee611d82614c3d565b906128fa6110ee6132dc565b601654909490612912906001600160a01b0316610360565b6040805163206153af60e01b81529591869081806129338b60048301612032565b03915afa9182156102f8576129b1956000936132b6575b5081602091612978614e206001600160401b036129706001600160801b038b168a614f2a565b1610156120ae565b6004548690600090612992906001600160a01b0316610360565b926040519a8b9586948593636916a18160e11b85528d60048601612116565b03925af180156102f857612a0d95600091613297575b5060095460209060a01c60ff16604051636812dc0360e01b8152600481018790526001600160801b038816602482015260ff909116604482015296879081906064820190565b038173980ab9ca184fafd7bf0e1fa8403298b2bcc12cf95af49586156102f857600096613276575b50600354612a4b906001600160a01b0316610360565b6040805163dcb71f3f60e01b81523360048201526001600160801b03881660248201526001600160401b034216604482015299918a90606490829089905af19889156102f857600099613245575b50612abf612abb612ab460208c01516001600160401b031690565b9a51151590565b1590565b61323357600354612ad8906001600160a01b0316610360565b604051637b85b73960e01b8152600160048201529790602090899060249082905afa9788156102f857600098613212575b50600254612b1f906001600160a01b0316610360565b604051632af2698d60e11b815260048101889052999060208b60248173980ab9ca184fafd7bf0e1fa8403298b2bcc12cf95af49a8b156102f85760009b6131f1575b50600354612b77906001600160a01b0316610360565b604051637b85b73960e01b81526001600482015290602090829060249082905afa9081156102f8576000916131d2575b50813b1561020757604051639992f4b760e01b81523360048201526001600160401b038e1660248201526001600160801b039c8d1660448201529b1660648c01528a6084815a6000948591f1998a156102f85760049a6131bf575b50612c0f84898933613555565b60165461032090612c28906001600160a01b0316610360565b6040516336483edd60e01b81529b8c9182905afa998a156102f85760009a61319c575b50600154612c61906001600160a01b0316610360565b60405163b87c3dc360e01b81526001600160801b03861660048201529690602090889060249082906000905af19687156102f85760009761316b575b50612cb66101c097888d01906001600160801b03169052565b6101408b01612cc68682516122f9565b9052600354612cdd906001600160a01b0316610360565b604051634d5c56a560e01b81523360048201526001600160401b038e1660248201526102608082604481865afa80156102f857612d439260209260009261313e575b505001516001600160801b03861660a0820152986001600160801b038816908a0152565b600954612d5b9060a81c60ff1660ff166101e08a0152565b803b1561020757604051632e449f1760e21b815233600482015260016024820152906000908290604490829084905af180156102f85761312b575b50600354612dac906001600160a01b0316610360565b96873b1561020757604051630e6840d960e11b815233600482015260248101859052976000908990604490829084905af19788156102f857612e4098613118575b50612df66150cf565b50601180546001600160801b031916426001600160801b0316179055601054604051633460dd8b60e11b815260048101869052602481019190915297602090899081906044820190565b038173980ab9ca184fafd7bf0e1fa8403298b2bcc12cf95af49788156102f8576000986130f7575b506001600160801b03881660c0820152612ea8612e976001600160801b038b166001600160401b03881661208b565b6001600160801b03166101a0830152565b600354612ebd906001600160a01b0316610360565b803b1561020757612eea916000918f836040518096819582946307fcd77f60e51b84523360048501612488565b03925af180156102f8576130e4575b50612f0e612f0988600a546122f9565b600a55565b612f2e896001600160801b03166001600160801b0319600c541617600c55565b612f39878c516122f9565b8b5260016001600160401b038d16146130b6575b6103008b01612f5c8151612649565b90526101e08b01612f6e8982516122f9565b9052612f83886001600160801b038b16612658565b612f936102008d019182516122f9565b9052601654612faa906001600160a01b0316610360565b803b15610207576040516339ef448360e01b81529b6000918d91829084908290612fd790600483016127a5565b03925af19182156102f8576130259b6080936130a3575b50601654613004906001600160a01b0316610360565b908251604051809e81958294632dec448f60e11b8452339160048501612808565b03925af19687156102f8577f047e772632ce862987044160c43583036943c98cdb74492e0438b017de03fd7b9a6001600160801b039a61308099613085575b5060095460a81c60ff16966040519b8c9b16984292338d61284f565b0390a1565b61309c9060803d811161129057611281818361060b565b5038613064565b80610a436130b0926105d8565b38612fee565b6130df6102208c016130d261115082516001600160801b031690565b6001600160801b03169052565b612f4d565b80610a436130f1926105d8565b38612ef9565b61311191985060203d6020116107e3576107d4818361060b565b9638612e68565b80610a43613125926105d8565b38612ded565b80610a43613138926105d8565b38612d96565b61315d9250803d10613164575b613155818361060b565b810190612311565b3880612d1f565b503d61314b565b61318e91975060203d602011613195575b613186818361060b565b81019061218f565b9538612c9d565b503d61317c565b6131b8919a506103203d61032011610a7157610a61818361060b565b9838612c4b565b80610a436131cc926105d8565b38612c02565b6131eb915060203d60201161319557613186818361060b565b38612ba7565b61320b919b5060203d60201161319557613186818361060b565b9938612b61565b61322c91985060203d60201161319557613186818361060b565b9638612b09565b604051634fad3b0960e01b8152600490fd5b61326891995060403d60401161326f575b613260818361060b565b81019061214c565b9738612a99565b503d613256565b61329091965060203d6020116107e3576107d4818361060b565b9438612a35565b6132b0915060203d6020116107e3576107d4818361060b565b386129c7565b60209193506132d4839160403d6040116112ee576112df818361060b565b93915061294a565b604051600360f01b602082015260028152611b3f816105f0565b61ffff600381613305846151ee565b16036133305750604051613d0960841b602082015260108152611b3f9161332b826105f0565b6133db565b61333b6024926151ee565b604051633a51740d60e01b815291166004820152fd5b61ffff600381613360846151ee565b16036133305750604051610c3560861b602082015260108152611b3f9161332b826105f0565b60209061339d6004959493828151948592016115c7565b600160f81b910181815260f09290921b6001600160f01b031916600183015260038201528151916133d6908390858401906020016115c7565b010190565b9061ffff916003836133ec836151ee565b160361343c57815183811161341d5783166001019283116120a957611d5e611b3f9260405194859360208501613386565b604490604051906306dfcc6560e41b8252601060048301526024820152fd5b8261333b6024926151ee565b7f9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f0060028154146134785760029055565b604051633ee5aeb560e01b8152600490fd5b1561349157565b60405162461bcd60e51b815260206004820152601f60248201527f426f72726f7765722063616e6e6f74206265207a65726f2061646472657373006044820152606490fd5b156134dd57565b60405162461bcd60e51b815260206004820152603860248201527f4c5456206d7573742062652073657420746f206e6f6e2d7a65726f2076616c7560448201527f65206265666f72652070726f766964696e67206c6f616e7300000000000000006064820152608490fd5b919082039182116120a957565b919291906135c6906135716001600160a01b038416151561348a565b60095460a01c60ff1661358860ff821615156134d6565b60405180938192636812dc0360e01b83526020988995600485019160409194936001600160801b0360ff926060860197865216602085015216910152565b038173980ab9ca184fafd7bf0e1fa8403298b2bcc12cf95af480156102f85761364a85916000938491613719575b50835461361590879061360f906001600160a01b0316610360565b92613548565b6040516340c10f1960e01b8082526001600160a01b039097166004820152602481019190915293849283919082906044820190565b03925af19081156102f8576000916136fc575b50156136cd576000546136b19284929091613680906001600160a01b0316610360565b6008546040519283526001600160a01b03166004830152602482019290925292839190829060009082906044820190565b03925af19182156102f8576000926136df575b5050156136cd57565b60405163035f563160e31b8152600490fd5b6136f59250803d106102f1576102e3818361060b565b38806136c4565b6137139150843d86116102f1576102e3818361060b565b3861365d565b6137309150833d85116107e3576107d4818361060b565b386135f4565b1561373d57565b60405162461bcd60e51b815260206004820152603060248201527f546f20616464726573732063616e6e6f742062652061207a65726f20616e642060448201526f636f6e7472616374206164647265737360801b6064820152608490fd5b908160209103126102075751611b3f816102fd565b156137b757565b60405162461bcd60e51b815260206004820152601f60248201527f5573657220616d6f756e7420686173206265656e206c697175696461746564006044820152606490fd5b1561380357565b60405162461bcd60e51b8152602060048201526016602482015275426f72726f77696e674865616c7468206973204c6f7760501b6044820152606490fd5b1561384857565b60405162461bcd60e51b815260206004820152602260248201527f557365722062616c616e6365206973206c657373207468616e20726571756972604482015261195960f21b6064820152608490fd5b906001600160801b038091169182156138b057160490565b634e487b7160e01b600052601260045260246000fd5b9190916001600160801b03808094169116019182116120a957565b6001600160801b0391821690821603919082116120a957565b6001600160801b031680156120a9576000190190565b80156120a9576000190190565b6001600160a01b0381161515806148cd575b61393890613736565b60185461394d906001600160a01b0316610360565b6040516339e9a67360e21b815233600482015290602090829060249082905afa9081156102f85760009161489e575b506001600160401b0383811691168111613a0357506017546139a6906001600160a01b0316610360565b91823b156102075760405163f30707e160e01b81526001600160a01b039290921660048301526001600160401b03166024820152906000908290604490829034905af180156102f8576139f65750565b80610a43611dc7926105d8565b9091613a1061119c614c3d565b91613a236001600160401b038416614db9565b50600c80546001600160801b0319166001600160401b038516179055600354613a54906001600160a01b0316610360565b604051634d5c56a560e01b81523360048201526001600160401b0384166024820152949061026090869060449082905afa9485156102f85760009561487b575b506020850151601654909290613ab2906001600160a01b0316610360565b9560405180976336483edd60e01b82528160046103209a8b935afa9788156102f857600098614854575b505051613af1906001600160401b031661119c565b1061480057613b0f613b0a612abb610120850151151590565b6137b0565b60e08201516147af57836020613b6c95613b3360808601516001600160801b031690565b604051636614cc0560e01b81526001600160801b0390911660048201526001600160401b03909116602482015295869081906044820190565b038173980ab9ca184fafd7bf0e1fa8403298b2bcc12cf95af49485156102f857600095614788575b5090613bf791613bb0611f406001600160801b038816116137fc565b6020613bc660c08601516001600160801b031690565b6010546040516350ad67e160e11b81526001600160801b039092166004830152602482015293849081906044820190565b038173980ab9ca184fafd7bf0e1fa8403298b2bcc12cf95af49283156102f857600093614767575b50613c286150cf565b50601180546001600160801b031916426001600160801b0316179055600054613c59906001600160a01b0316610360565b6040516370a0823160e01b815233600482015290602090829060249082905afa9081156102f857613c96918591600091614748575b501015613841565b6001600160401b038116610140850152600160e0850152426001600160401b0316610160850152613d0f602082613cd6828801516001600160801b031690565b60405163684d536d60e11b81526001600160801b0390911660048201526001600160401b03909116602482015291829081906044820190565b038173980ab9ca184fafd7bf0e1fa8403298b2bcc12cf95af49081156102f857600091614729575b506102608801613d488282516122f9565b9052600354613d5f906001600160a01b0316610360565b803b15610207576040516302c235d160e31b81526004810183905260016024820152906000908290604490829084905af180156102f857614716575b50613dbc81613db7611d8260a08901516001600160801b031690565b613548565b600054613dd1906001600160a01b0316610360565b6040516363a9f09360e11b81523360048201526024810183905290602090829060449082906000905af19081156102f8576000916146f7575b50156146e557600054613e7e91602091613e2c906001600160a01b0316610360565b600854613e43906001600160a01b03169289613548565b6040516323b872dd60e01b81523360048201526001600160a01b03909316602484015260448301529092839190829060009082906064820190565b03925af19081156102f8576000916146c6575b50156146b457613ebc612f09613eb4611d8260c08901516001600160801b031690565b600a54613548565b613edd613ed6611d8260c08801516001600160801b031690565b8951613548565b8852613eff613ef9611d8260a08801516001600160801b031690565b85613548565b613f0f6102408a019182516122f9565b9052600354613f26906001600160a01b0316610360565b90613f47613f41611d8260a08901516001600160801b031690565b86613548565b91803b156102075760405163b9a221eb60e01b815260048101939093526000908390602490829084905af19081156102f857613f9f92613f8e926146a1575b50873361491e565b6001600160801b0316610180860152565b600354613fb4906001600160a01b0316610360565b803b1561020757600060405180926307fcd77f60e51b8252818381613fde8b8d3360048501612488565b03925af180156102f85761468e575b5061403261400560208601516001600160801b031690565b61402d6001600160401b0384169161402760808901516001600160801b031690565b9061208b565b613898565b95612710806001600160801b0383161160001461461b5750506004546140b99190602090829061406a906001600160a01b0316610360565b828801516101a0890151604051630e1fab4360e01b81526001600160801b039283166004820152911660248201526001600160401b039290921660448301529093849190829081906064820190565b03915afa80156102f8576001600160401b036140e76141a7926141e29a6020966000926145fc575b506138c6565b92836140fc868a01516001600160801b031690565b6001600160801b0381166001600160801b038316116000146145b457505061414c61414761413f611d82614139898d01516001600160801b031690565b886138e1565b6014546122f9565b601455565b61416b611d82614165878b01516001600160801b031690565b866138e1565b61417a60808d019182516122f9565b90525b61419e614199614191848416601454612658565b6015546122f9565b601555565b16601454612658565b6141b660a08a019182516122f9565b90525b604051632af2698d60e11b81526001600160801b03909116600482015295869081906024820190565b038173980ab9ca184fafd7bf0e1fa8403298b2bcc12cf95af49485156102f857600095614593575b5061421b6142166132dc565b613351565b601654909190614233906001600160a01b0316610360565b6040805163206153af60e01b815298919089806142538760048301612032565b0381845afa9889156102f857600099614572575b5060035461427d906001600160a01b0316610360565b604051630c9c31bd60e01b815233600482015290602090829060249082905afa9081156102f857600091614553575b506142c4611d8260208901516001600160801b031690565b1461452d575b61030082016142d98151613910565b90526142f2611d8260208801516001600160801b031690565b6143026101e084019182516122f9565b905261431b611d8260408801516001600160801b031690565b61432b61020084019182516122f9565b9052803b15610207576040516339ef448360e01b815291600091839182908490829061435a90600483016127a5565b03925af180156102f8576143df92602092889261451a575b50600354899060009061438d906001600160a01b0316610360565b6040516315ee073360e11b81523360048201526001600160a01b0390941660248501526001600160801b0390921660448401526001600160401b03909316606483015290938492839182906084820190565b03925af19081156102f8576000916144fb575b50156144e957601654614437966080929091614416906001600160a01b0316610360565b908251604051809a81958294632dec448f60e11b8452339160048501612808565b03925af19485156102f85761018061308093614483927f59c54db06277209213236b5f864552e9ee789e1ca98ed9988d78cdea7bd4d9d4986144ca575b5001516001600160801b031690565b604080513381526001600160401b03909516602086015242908501526001600160801b03948516606085015293909316608083015260a082019290925290819060c0820190565b6144e29060803d60801161129057611281818361060b565b5038614474565b604051635e5e86d560e01b8152600490fd5b614514915060203d6020116102f1576102e3818361060b565b386143f2565b80610a43614527926105d8565b38614372565b61454e61022083016130d261454982516001600160801b031690565b6138fa565b6142ca565b61456c915060203d6020116107e3576107d4818361060b565b386142ac565b61458c91995060403d6040116112ee576112df818361060b565b9738614267565b6145ad91955060203d60201161319557613186818361060b565b933861420a565b61413f611d826145c793614147936138e1565b6145e6611d82856145e1888c01516001600160801b031690565b6138e1565b6145f560808d019182516122f9565b905261417d565b614614919250873d891161319557613186818361060b565b90386140e1565b9296929091506001600160801b038216810361463f5750509360206141e2956141b9565b6001600160801b038216611f40109250908261467b575b505015613803576141e2936020614676818501516001600160801b031690565b6141b9565b6001600160801b03161090503880614656565b80610a4361469b926105d8565b38613fed565b80610a436146ae926105d8565b38613f86565b60405163a07c821960e01b8152600490fd5b6146df915060203d6020116102f1576102e3818361060b565b38613e91565b6040516303f7009160e51b8152600490fd5b614710915060203d6020116102f1576102e3818361060b565b38613e0a565b80610a43614723926105d8565b38613d9b565b614742915060203d6020116107e3576107d4818361060b565b38613d37565b614761915060203d6020116107e3576107d4818361060b565b38613c8e565b61478191935060203d6020116107e3576107d4818361060b565b9138613c1f565b613bf7929195506147a79060203d60201161319557613186818361060b565b949091613b94565b60405162461bcd60e51b815260206004820152602360248201527f5573657220616c726561647920776974686472617720656e7469726520616d6f6044820152621d5b9d60ea1b6064820152608490fd5b60405162461bcd60e51b815260206004820152602660248201527f5573657220646f656e73277420686176652074686520706572746963756c6172604482015265040d2dcc8caf60d31b6064820152608490fd5b613af192985061119c918161487492903d10610a7157610a61818361060b565b9791613adc565b6148979195506102603d6102601161316457613155818361060b565b9338613a94565b6148c0915060203d6020116148c6575b6148b8818361060b565b81019061379b565b3861397c565b503d6148ae565b50803b15156001141561392f565b156148e257565b60405162461bcd60e51b8152602060048201526014602482015273416d6f756e742063616e2774206265207a65726f60601b6044820152606490fd5b6149326001600160a01b038216151561348a565b61493d8315156148db565b601254604051631f79572960e11b8152600481019490945260801c6001600160401b03166024840152602091828460448173980ab9ca184fafd7bf0e1fa8403298b2bcc12cf95af49384156102f857600094614a4d575b50600254614a0192849286926000906149b5906001600160a01b0316610360565b604051631ff9eb7f60e21b81526001600160a01b0390941660048501526001600160401b0390921660248401526001600160801b03909316604483015290938492839182906064820190565b03925af19182156102f857600092614a30575b505015614a1e5790565b6040516328eca99f60e21b8152600490fd5b614a469250803d106102f1576102e3818361060b565b3880614a14565b614a0192945090614a6b8492833d851161319557613186818361060b565b94925090614994565b90816060910312610207578051614a8a8161023a565b916040602083015192015190565b15614a9f57565b60405162461bcd60e51b815260206004820152602360248201527f546f20616464726573732063616e6e6f742062652061207a65726f206164647260448201526265737360e81b6064820152608490fd5b15614af757565b60405162461bcd60e51b815260206004820152602560248201527f596f752063616e6e6f74206c697175696461746520796f7572206f776e206173604482015264736574732160d81b6064820152608490fd5b90816080910312610207576040519060808201908282106001600160401b038311176105eb576060916040528051614b818161023a565b83526020810151614b918161023a565b60208401526040810151614ba48161023a565b60408401520151606082015290565b939061012093606061283f94614c1493999899600289526001600160801b0380911660208a01528082511660408a015280602083015116838a01526040820151166080890152015160a087015260c086019060208091805184520151910152565b610140806101008601528401906115ea565b519069ffffffffffffffffffff8216820361020757565b600b54604051633fabe5a360e21b81529060a090829060049082906001600160a01b03165afa80156102f857600090614c7b575b620f424091500490565b60a0823d8211614cc2575b81614c9360a0938361060b565b81010312610e10575080614caa620f424092614c26565b50614cbc608060208301519201614c26565b50614c71565b3d9150614c86565b15614cd157565b60405162461bcd60e51b815260206004820152602260248201527f4c61737420455448207661756c742076616c75652063616e2774206265207a65604482015261726f60f01b6064820152608490fd5b91906103408382031261020757611b3f9060208451614d3f816102fd565b94016121a4565b9095949293611dc7946001600160801b0360a0946103c085019960008652602086015216604084015260608301526080820152019061266b565b91936001600160801b0360a094611dc797939998966103c086019a8652602086015216604084015260608301526080820152019061266b565b8015614f1857601654614dd4906001600160a01b0316610360565b60405180916336483edd60e01b82528160046103209485935afa9182156102f857600092614efb575b5050600c546001600160801b03169161030082015161012083015190614e3d6040519485938493632c5ed22d60e01b855261034098899760048701614d46565b038173980ab9ca184fafd7bf0e1fa8403298b2bcc12cf95af49081156102f8576000928392614eca575b5050601654614e7e906001600160a01b0316610360565b803b15610207576040516339ef448360e01b8152916000918391829084908290614eab90600483016127a5565b03925af180156102f857614ebd575090565b80610a43611b3f926105d8565b614eed935080919250903d10614ef4575b614ee5818361060b565b810190614d21565b3880614e67565b503d614edb565b614f119250803d10610a7157610a61818361060b565b3880614dfd565b6040516315e73e9f60e01b8152600490fd5b8115614f1857601654614f45906001600160a01b0316610360565b9060405180926336483edd60e01b82528160046103209586935afa9283156102f857600093614faf575b5050600c546001600160801b031661030083015190614e3d610120850151946040519586948594632c5ed22d60e01b8652610340998a9860048801614d80565b614fc6929350803d10610a7157610a61818361060b565b903880614f6f565b90614fe460018060a01b03600954163314611ddb565b6001600160801b038116151580615077575b614fff90615083565b600554615014906001600160a01b0316610360565b604051631f71924f60e31b8152600160048201529290602090849060249082906000905af19081156102f85761505861190892611dc7956000916103db5750611eb3565b6009805460ff60a81b191660a89290921b60ff60a81b16919091179055565b5060ff82161515614ff6565b1561508a57565b60405162461bcd60e51b815260206004820152601760248201527f526174652073686f756c64206e6f74206265207a65726f0000000000000000006044820152606490fd5b6003546150e4906001600160a01b0316610360565b60405180916322d7586760e11b825281600460209485935afa9081156102f8576000916151ac575b50816151206012546001600160801b031690565b601154601054604051635529dfd560e01b81526001600160801b03958616600482015292851660248401529316604482015260648101929092528160848173980ab9ca184fafd7bf0e1fa8403298b2bcc12cf95af49182156102f85760009261518f575b5050611b3f81601055565b6151a59250803d106107e3576107d4818361060b565b3880615184565b6151c39150823d841161319557613186818361060b565b3861510c565b919082604091031261020757602082516151e28161023a565b920151611b3f8161022f565b60028151106151fe576002015190565b60405162461bcd60e51b8152602060048201526014602482015273746f55696e7431365f6f75744f66426f756e647360601b6044820152606490fdfe9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c199300360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbcf0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00a26469706673582212209af00f48a7fd6f158604c072b0aad6a52d7cfde19bd70ebdce65d3921f87455a64736f6c63430008140033

Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

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

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
[ Download: CSV Export  ]

A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.