FTM Price: $0.99 (-4.45%)
Gas: 33 GWei

Contract

0xd7F1Dd5D49206349CaE8b585fcB0Ce3D96f1696F
 

Multichain Info

Transaction Hash
Method
Block
From
To
Value
Execute784234582024-03-29 10:33:021 hr ago1711708382IN
0xd7F1Dd5D...D96f1696F
0 FTM0.0133989838.03937194
Execute784233792024-03-29 10:30:481 hr ago1711708248IN
0xd7F1Dd5D...D96f1696F
0 FTM0.0167440738.05055516
Execute784167022024-03-29 7:03:495 hrs ago1711695829IN
0xd7F1Dd5D...D96f1696F
4 FTM0.1268477567.95640193
Execute784140072024-03-29 6:00:416 hrs ago1711692041IN
0xd7F1Dd5D...D96f1696F
0 FTM0.0573449388.40672194
Execute784139462024-03-29 5:59:156 hrs ago1711691955IN
0xd7F1Dd5D...D96f1696F
2 FTM0.0664868688.41408464
Execute784121802024-03-29 5:15:547 hrs ago1711689354IN
0xd7F1Dd5D...D96f1696F
111 FTM0.0495393898.12188974
Execute783720682024-03-28 15:17:5521 hrs ago1711639075IN
0xd7F1Dd5D...D96f1696F
0 FTM0.05171314114.92652606
Execute783695942024-03-28 14:34:1021 hrs ago1711636450IN
0xd7F1Dd5D...D96f1696F
0 FTM0.02600829119.80972076
Execute783667992024-03-28 13:44:4722 hrs ago1711633487IN
0xd7F1Dd5D...D96f1696F
0 FTM0.03219185113.21726289
Execute783632512024-03-28 12:42:4423 hrs ago1711629764IN
0xd7F1Dd5D...D96f1696F
3,417 FTM0.09531735114.35328659
Execute783628212024-03-28 12:35:4323 hrs ago1711629343IN
0xd7F1Dd5D...D96f1696F
0 FTM0.0546149114.42780321
Execute783430882024-03-28 6:00:0130 hrs ago1711605601IN
0xd7F1Dd5D...D96f1696F
0 FTM0.10096385138.75866659
Execute783317892024-03-28 2:01:1134 hrs ago1711591271IN
0xd7F1Dd5D...D96f1696F
633 FTM0.05107209113.90817215
Execute783311202024-03-28 1:48:4734 hrs ago1711590527IN
0xd7F1Dd5D...D96f1696F
0 FTM0.08120672108.77119815
Execute783299182024-03-28 1:24:0434 hrs ago1711589044IN
0xd7F1Dd5D...D96f1696F
255 FTM0.02948127113.376432
Execute783110252024-03-27 19:18:1241 hrs ago1711567092IN
0xd7F1Dd5D...D96f1696F
14 FTM0.08529839116
Execute783098772024-03-27 18:57:0441 hrs ago1711565824IN
0xd7F1Dd5D...D96f1696F
0 FTM0.08106108108.73968945
Execute783098292024-03-27 18:56:1641 hrs ago1711565776IN
0xd7F1Dd5D...D96f1696F
0 FTM0.15737294108.07208079
Execute783034642024-03-27 16:53:4543 hrs ago1711558425IN
0xd7F1Dd5D...D96f1696F
0.00000329 FTM0.02923409145.95809647
Execute783034272024-03-27 16:53:0343 hrs ago1711558383IN
0xd7F1Dd5D...D96f1696F
0.00000432 FTM0.03775559145.94356274
Execute783033802024-03-27 16:52:0143 hrs ago1711558321IN
0xd7F1Dd5D...D96f1696F
0.00000315 FTM0.03763379145.95795399
Execute783033282024-03-27 16:50:5243 hrs ago1711558252IN
0xd7F1Dd5D...D96f1696F
0.00000182 FTM0.02941613145.93943061
Execute783033002024-03-27 16:50:1443 hrs ago1711558214IN
0xd7F1Dd5D...D96f1696F
0.00000588 FTM0.05464489145.95909389
Execute783032632024-03-27 16:49:2943 hrs ago1711558169IN
0xd7F1Dd5D...D96f1696F
0.00000317 FTM0.03759123145.94854981
Execute783032132024-03-27 16:48:4043 hrs ago1711558120IN
0xd7F1Dd5D...D96f1696F
0.00549208 FTM0.02919062145.94655498
View all transactions

Latest 25 internal transactions (View All)

Parent Txn Hash Block From To Value
784167022024-03-29 7:03:495 hrs ago1711695829
0xd7F1Dd5D...D96f1696F
4 FTM
784140072024-03-29 6:00:416 hrs ago1711692041
0xd7F1Dd5D...D96f1696F
0.01583061 FTM
784140072024-03-29 6:00:416 hrs ago1711692041
0xd7F1Dd5D...D96f1696F
1.97882642 FTM
784140072024-03-29 6:00:416 hrs ago1711692041
0xd7F1Dd5D...D96f1696F
1.99465703 FTM
784139462024-03-29 5:59:156 hrs ago1711691955
0xd7F1Dd5D...D96f1696F
2 FTM
784121802024-03-29 5:15:547 hrs ago1711689354
0xd7F1Dd5D...D96f1696F
111 FTM
783720682024-03-28 15:17:5521 hrs ago1711639075
0xd7F1Dd5D...D96f1696F
0.92663749 FTM
783720682024-03-28 15:17:5521 hrs ago1711639075
0xd7F1Dd5D...D96f1696F
115.82968735 FTM
783720682024-03-28 15:17:5521 hrs ago1711639075
0xd7F1Dd5D...D96f1696F
116.75632484 FTM
783632512024-03-28 12:42:4423 hrs ago1711629764
0xd7F1Dd5D...D96f1696F
3,417 FTM
783628212024-03-28 12:35:4323 hrs ago1711629343
0xd7F1Dd5D...D96f1696F
21.5894331 FTM
783628212024-03-28 12:35:4323 hrs ago1711629343
0xd7F1Dd5D...D96f1696F
2,698.67913822 FTM
783628212024-03-28 12:35:4323 hrs ago1711629343
0xd7F1Dd5D...D96f1696F
2,720.26857133 FTM
783430882024-03-28 6:00:0130 hrs ago1711605601
0xd7F1Dd5D...D96f1696F
0.05305535 FTM
783430882024-03-28 6:00:0130 hrs ago1711605601
0xd7F1Dd5D...D96f1696F
6.63191988 FTM
783430882024-03-28 6:00:0130 hrs ago1711605601
0xd7F1Dd5D...D96f1696F
6.68497524 FTM
783317892024-03-28 2:01:1134 hrs ago1711591271
0xd7F1Dd5D...D96f1696F
633 FTM
783299182024-03-28 1:24:0434 hrs ago1711589044
0xd7F1Dd5D...D96f1696F
255 FTM
783110252024-03-27 19:18:1241 hrs ago1711567092
0xd7F1Dd5D...D96f1696F
14 FTM
783034642024-03-27 16:53:4543 hrs ago1711558425
0xd7F1Dd5D...D96f1696F
0.00000329 FTM
783034272024-03-27 16:53:0343 hrs ago1711558383
0xd7F1Dd5D...D96f1696F
0.00000432 FTM
783033802024-03-27 16:52:0143 hrs ago1711558321
0xd7F1Dd5D...D96f1696F
0.00000315 FTM
783033282024-03-27 16:50:5243 hrs ago1711558252
0xd7F1Dd5D...D96f1696F
0.00000182 FTM
783033002024-03-27 16:50:1443 hrs ago1711558214
0xd7F1Dd5D...D96f1696F
0.00000588 FTM
783032632024-03-27 16:49:2943 hrs ago1711558169
0xd7F1Dd5D...D96f1696F
0.00000317 FTM
View All Internal Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
Router

Compiler Version
v0.8.12+commit.f00d7308

Optimization Enabled:
Yes with 1000000 runs

Other Settings:
default evmVersion

Contract Source Code (Solidity Standard Json-Input format)

File 1 of 26 : Router.sol
// Copyright (C) 2020 Zerion Inc. <https://zerion.io>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//
// SPDX-License-Identifier: LGPL-3.0-only

pragma solidity 0.8.12;

import { ReentrancyGuard } from "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { Address } from "@openzeppelin/contracts/utils/Address.sol";
import { SignatureChecker } from "@openzeppelin/contracts/utils/cryptography/SignatureChecker.sol";

import { ICaller } from "../interfaces/ICaller.sol";
import { IDAIPermit } from "../interfaces/IDAIPermit.sol";
import { IEIP2612 } from "../interfaces/IEIP2612.sol";
import { IRouter } from "../interfaces/IRouter.sol";
import { IYearnPermit } from "../interfaces/IYearnPermit.sol";
import { Base } from "../shared/Base.sol";
import { AmountType, PermitType, SwapType } from "../shared/Enums.sol";
import {
    BadAmount,
    BadAccount,
    BadAccountSignature,
    BadAmountType,
    BadFeeAmount,
    BadFeeBeneficiary,
    BadFeeShare,
    BadFeeSignature,
    ExceedingDelimiterAmount,
    ExceedingLimitFee,
    HighInputBalanceChange,
    InsufficientAllowance,
    InsufficientMsgValue,
    LowActualOutputAmount,
    NoneAmountType,
    NonePermitType,
    NoneSwapType,
    PassedDeadline
} from "../shared/Errors.sol";
import { Ownable } from "../shared/Ownable.sol";
import {
    AbsoluteTokenAmount,
    AccountSignature,
    Fee,
    ProtocolFeeSignature,
    Input,
    Permit,
    SwapDescription,
    TokenAmount
} from "../shared/Structs.sol";
import { TokensHandler } from "../shared/TokensHandler.sol";

import { ProtocolFee } from "./ProtocolFee.sol";
import { SignatureVerifier } from "./SignatureVerifier.sol";

// solhint-disable code-complexity
contract Router is
    IRouter,
    Ownable,
    TokensHandler,
    SignatureVerifier("Zerion Router", "4"),
    ProtocolFee,
    ReentrancyGuard
{
    address internal constant ETH = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;

    /**
     * @inheritdoc IRouter
     */
    function cancelAccountSignature(
        Input calldata input,
        AbsoluteTokenAmount calldata output,
        SwapDescription calldata swapDescription,
        AccountSignature calldata accountSignature
    ) external override nonReentrant {
        if (msg.sender != swapDescription.account)
            revert BadAccount(msg.sender, swapDescription.account);

        validateAndExpireAccountSignature(input, output, swapDescription, accountSignature);
    }

    /**
     * @inheritdoc IRouter
     */
    function execute(
        Input calldata input,
        AbsoluteTokenAmount calldata output,
        SwapDescription calldata swapDescription,
        AccountSignature calldata accountSignature,
        ProtocolFeeSignature calldata protocolFeeSignature
    )
        external payable override nonReentrant
        returns (
            uint256 inputBalanceChange,
            uint256 actualOutputAmount,
            uint256 protocolFeeAmount,
            uint256 marketplaceFeeAmount
        )
    {
        validateProtocolFeeSignature(input, output, swapDescription, protocolFeeSignature);
        validateAndExpireAccountSignature(input, output, swapDescription, accountSignature);

        return execute(input, output, swapDescription);
    }

    /**
     * @dev Take tokens from the user, executes the swap,
     *     do the security checks, and all the required transfers
     * @dev All the parameters are described in `execute()` function
     */
    function execute(
        Input calldata input,
        AbsoluteTokenAmount calldata output,
        SwapDescription calldata swapDescription
    )
        internal
        returns (
            uint256 inputBalanceChange,
            uint256 actualOutputAmount,
            uint256 protocolFeeAmount,
            uint256 marketplaceFeeAmount
        )
    {
        // Calculate absolute amount in case it was relative
        uint256 absoluteInputAmount = getAbsoluteInputAmount(
            input.tokenAmount,
            swapDescription.account
        );

        // Transfer input token (`msg.value` check for Ether) to this contract address,
        // do nothing in case of zero input token address
        address inputToken = input.tokenAmount.token;
        handleInput(inputToken, absoluteInputAmount, input.permit, swapDescription.account);

        // Calculate the initial balances for input and output tokens
        uint256 initialInputBalance = Base.getBalance(inputToken);
        uint256 initialOutputBalance = Base.getBalance(output.token);

        // Transfer tokens to the caller
        Base.transfer(inputToken, swapDescription.caller, absoluteInputAmount);

        // Call caller's `callBytes()` function with the provided calldata
        Address.functionCall(
            swapDescription.caller,
            abi.encodeCall(ICaller.callBytes, swapDescription.callerCallData),
            "R: callBytes failed w/ no reason"
        );

        // Calculate the balance changes for input and output tokens
        inputBalanceChange = initialInputBalance - Base.getBalance(inputToken);
        uint256 outputBalanceChange = Base.getBalance(output.token) - initialOutputBalance;

        // Check input requirements, prevent the underflow
        if (inputBalanceChange > absoluteInputAmount)
            revert HighInputBalanceChange(inputBalanceChange, absoluteInputAmount);

        // Calculate the refund amount
        uint256 refundAmount = absoluteInputAmount - inputBalanceChange;

        // Calculate returned output token amount and fees amounts
        (actualOutputAmount, protocolFeeAmount, marketplaceFeeAmount) = getReturnedAmounts(
            swapDescription.swapType,
            swapDescription.protocolFee,
            swapDescription.marketplaceFee,
            output,
            outputBalanceChange
        );

        // Check output requirements, prevent revert on transfers
        if (actualOutputAmount < output.absoluteAmount)
            revert LowActualOutputAmount(actualOutputAmount, output.absoluteAmount);

        // Transfer the refund back to the user,
        // do nothing in zero input token case as `refundAmount` is zero
        Base.transfer(inputToken, swapDescription.account, refundAmount);

        // Transfer the output tokens to the user,
        // do nothing in zero output token case as `actualOutputAmount` is zero
        Base.transfer(output.token, swapDescription.account, actualOutputAmount);

        // Transfer protocol fee,
        // do nothing in zero output token case as `protocolFeeAmount` is zero
        Base.transfer(output.token, swapDescription.protocolFee.beneficiary, protocolFeeAmount);

        // Transfer marketplace fee,
        // do nothing in zero output token case as `marketplaceFeeAmount` is zero
        Base.transfer(
            output.token,
            swapDescription.marketplaceFee.beneficiary,
            marketplaceFeeAmount
        );

        // Emit event so one could track the swap
        emitExecuted(
            input,
            output,
            swapDescription,
            absoluteInputAmount,
            inputBalanceChange,
            actualOutputAmount,
            protocolFeeAmount,
            marketplaceFeeAmount
        );

        // Return this contract's balance changes,
        // output token balance change is split into 3 values
        return (inputBalanceChange, actualOutputAmount, protocolFeeAmount, marketplaceFeeAmount);
    }

    /**
     * @dev In ERC20 token case, transfers input token from the accound address to this contract,
     *     calls `permit()` function if allowance is not enough and permit call data is provided
     * @dev Checks `msg.value` in Ether case
     * @dev Does nothing in zero input token address case
     * @param token Input token address (may be Ether or zero)
     * @param amount Input token amount
     * @param permit Permit type and call data, which is used if allowance is not enough
     * @param account Address of the account to take tokens from
     */
    function handleInput(
        address token,
        uint256 amount,
        Permit calldata permit,
        address account
    ) internal {
        if (token == address(0)) return;

        if (token == ETH) return handleETHInput(amount);

        handleTokenInput(token, amount, permit, account);
    }

    /**
     * @dev Checks `msg.value` to be greater or equal to the Ether absolute amount to be used
     * @param amount Ether absolute amount to be used
     */
    function handleETHInput(uint256 amount) internal {
        if (msg.value < amount) revert InsufficientMsgValue(msg.value, amount);
    }

    /**
     * @dev Transfers input token from the accound address to this contract,
     *     calls `permit()` function if allowance is not enough and permit call data is provided
     * @param token Token to be taken from the account address
     * @param amount Input token absolute amount to be taken from the account
     * @param permit Permit type and call data, which is used if allowance is not enough
     * @param account Address of the account to take tokens from
     */
    function handleTokenInput(
        address token,
        uint256 amount,
        Permit calldata permit,
        address account
    ) internal {
        uint256 allowance = IERC20(token).allowance(account, address(this));
        if (allowance < amount) {
            if (permit.permitCallData.length == uint256(0))
                revert InsufficientAllowance(allowance, amount);

            Address.functionCall(
                token,
                abi.encodePacked(getPermitSelector(permit.permitType), permit.permitCallData),
                "R: permit"
            );
        }

        SafeERC20.safeTransferFrom(IERC20(token), account, address(this), amount);
    }

    /**
     * @notice Emits Executed event
     * @param input Input described in `execute()` function
     * @param output Output described in `execute()` function
     * @param swapDescription Swap parameters described in `execute()` function
     * @param absoluteInputAmount Max amount of input token to be taken from the account address
     * @param inputBalanceChange Actual amount of input token taken from the account address
     * @param returnedAmount Actual amount of tokens returned to the account address
     * @param protocolFeeAmount Protocol fee amount
     * @param marketplaceFeeAmount Marketplace fee amount
     */
    function emitExecuted(
        Input calldata input,
        AbsoluteTokenAmount calldata output,
        SwapDescription calldata swapDescription,
        uint256 absoluteInputAmount,
        uint256 inputBalanceChange,
        uint256 returnedAmount,
        uint256 protocolFeeAmount,
        uint256 marketplaceFeeAmount
    ) internal {
        emit Executed(
            input.tokenAmount.token,
            absoluteInputAmount,
            inputBalanceChange,
            output.token,
            output.absoluteAmount,
            returnedAmount,
            protocolFeeAmount,
            marketplaceFeeAmount,
            swapDescription,
            msg.sender
        );
    }

    /**
     * @dev Validates signature for the account (reverts on used signatures) and marks it as used
     * @dev All the parameters are described in `execute()` function
     * @dev In case of empty signature, account address must be equal to the sender address
     */
    function validateAndExpireAccountSignature(
        Input calldata input,
        AbsoluteTokenAmount calldata output,
        SwapDescription calldata swapDescription,
        AccountSignature calldata accountSignature
    ) internal {
        if (accountSignature.signature.length == uint256(0)) {
            if (msg.sender != swapDescription.account)
                revert BadAccount(msg.sender, swapDescription.account);
            return;
        }
        bytes32 hashedAccountSignatureData = hashAccountSignatureData(
            input,
            output,
            swapDescription,
            accountSignature.salt
        );

        if (
            !SignatureChecker.isValidSignatureNow(
                swapDescription.account,
                hashedAccountSignatureData,
                accountSignature.signature
            )
        ) revert BadAccountSignature();

        markHashUsed(hashedAccountSignatureData);
    }

    /**
     * @dev Validates protocol fee signature (reverts on expired signatures)
     * @dev All the parameters are described in `execute()` function
     * @dev In case of empty signature, protocol fee must be equal to the default one
     * @dev Signature is valid only until the deadline
     * @dev Custom protocol fee can be lower or equal to the default one
     */
    function validateProtocolFeeSignature(
        Input calldata input,
        AbsoluteTokenAmount calldata output,
        SwapDescription calldata swapDescription,
        ProtocolFeeSignature calldata protocolFeeSignature
    ) internal view {
        Fee memory baseProtocolFee = getProtocolFeeDefault();
        Fee memory protocolFee = swapDescription.protocolFee;

        if (protocolFeeSignature.signature.length == uint256(0)) {
            if (protocolFee.share != baseProtocolFee.share)
                revert BadFeeShare(protocolFee.share, baseProtocolFee.share);
            if (protocolFee.beneficiary != baseProtocolFee.beneficiary)
                revert BadFeeBeneficiary(protocolFee.beneficiary, baseProtocolFee.beneficiary);
            return;
        }

        if (protocolFee.share > baseProtocolFee.share)
            revert ExceedingLimitFee(protocolFee.share, baseProtocolFee.share);

        bytes32 hashedProtocolFeeSignatureData = hashProtocolFeeSignatureData(
            input,
            output,
            swapDescription,
            protocolFeeSignature.deadline
        );

        if (
            !SignatureChecker.isValidSignatureNow(
                getProtocolFeeSigner(),
                hashedProtocolFeeSignatureData,
                protocolFeeSignature.signature
            )
        ) revert BadFeeSignature();

        // solhint-disable not-rely-on-time
        if (block.timestamp > protocolFeeSignature.deadline)
            revert PassedDeadline(block.timestamp, protocolFeeSignature.deadline);
        // solhint-enable not-rely-on-time
    }

    /**
     * @dev Calculate absolute input amount given token amount from `execute()` function inputs
     * @dev Relative amount type cannot be used with Ether or zero token address
     * @dev Only zero amount can be used with zero token address
     * @param tokenAmount Token address, its amount, and amount type
     * @param account Address of the account to transfer token from
     * @return absoluteTokenAmount Absolute token amount
     */
    function getAbsoluteInputAmount(TokenAmount calldata tokenAmount, address account)
        internal
        view
        returns (uint256 absoluteTokenAmount)
    {
        AmountType amountType = tokenAmount.amountType;
        address token = tokenAmount.token;
        uint256 amount = tokenAmount.amount;

        if (amountType == AmountType.None) revert NoneAmountType();

        if (token == address(0) && amount > uint256(0)) revert BadAmount(amount, uint256(0));

        if (amountType == AmountType.Absolute) return amount;

        if (token == ETH || token == address(0))
            revert BadAmountType(amountType, AmountType.Absolute);

        if (amount > DELIMITER) revert ExceedingDelimiterAmount(amount);

        if (amount == DELIMITER) return IERC20(token).balanceOf(account);

        return (IERC20(token).balanceOf(account) * amount) / DELIMITER;
    }

    /**
     * @dev Calculates returned amount, protocol fee amount, and marketplace fee amount
     *     - In case of fixed inputs, returned amount is
     *         `outputBalanceChange` multiplied by (1 - total fee share)
     *         This shows that actual fee is a share of output
     *     - In case of fixed outputs, returned amount is `outputAmount`
     *         This proves that outputs are fixed
     * @param swapType Whether the inputs or outputs are fixed
     * @param protocolFee Protocol fee share and beneficiary address
     * @param marketplaceFee Marketplace fee share and beneficiary address
     * @param output Output token and absolute amount required to be returned
     * @param outputBalanceChange Output token absolute amount actually returned
     * @return returnedAmount Amount of output token returned to the account
     * @return protocolFeeAmount Amount of output token sent to the protocol fee beneficiary
     * @return marketplaceFeeAmount Amount of output token sent to the marketplace fee beneficiary
     * @dev Returns all zeroes in case of zero output token
     */
    function getReturnedAmounts(
        SwapType swapType,
        Fee calldata protocolFee,
        Fee calldata marketplaceFee,
        AbsoluteTokenAmount calldata output,
        uint256 outputBalanceChange
    )
        internal
        pure
        returns (
            uint256 returnedAmount,
            uint256 protocolFeeAmount,
            uint256 marketplaceFeeAmount
        )
    {
        if (swapType == SwapType.None) revert NoneSwapType();

        uint256 outputAbsoluteAmount = output.absoluteAmount;
        if (output.token == address(0)) {
            if (outputAbsoluteAmount > uint256(0))
                revert BadAmount(outputAbsoluteAmount, uint256(0));
            return (uint256(0), uint256(0), uint256(0));
        }

        if (outputBalanceChange == uint256(0)) return (uint256(0), uint256(0), uint256(0));

        uint256 totalFeeShare = protocolFee.share + marketplaceFee.share;

        if (totalFeeShare == uint256(0)) return (outputBalanceChange, uint256(0), uint256(0));

        if (totalFeeShare > DELIMITER) revert BadFeeShare(totalFeeShare, DELIMITER);

        // The most tricky and gentle place connected with fees
        // We return either the amount the user requested
        // or the output balance change divided by (1 + fee percentage)
        // Plus one in the fixed inputs case is used to eliminate precision issues
        returnedAmount = (swapType == SwapType.FixedOutputs)
            ? output.absoluteAmount
            : ((outputBalanceChange * DELIMITER) / (DELIMITER + totalFeeShare)) + uint256(1);

        uint256 totalFeeAmount = outputBalanceChange - returnedAmount;
        // This check is important in fixed outputs case as we never actually check that
        // total fee amount is not too large and should always just pass in fixed inputs case
        if (totalFeeAmount * DELIMITER > totalFeeShare * returnedAmount)
            revert BadFeeAmount(totalFeeAmount, (returnedAmount * totalFeeShare) / DELIMITER);

        protocolFeeAmount = (totalFeeAmount * protocolFee.share) / totalFeeShare;
        marketplaceFeeAmount = totalFeeAmount - protocolFeeAmount;
    }

    /**
     * @dev Maps permit type to permit selector
     * @param permitType PermitType enum variable with permit type
     * @return selector permit() function signature corresponding to the given permit type
     */
    function getPermitSelector(PermitType permitType) internal pure returns (bytes4 selector) {
        if (permitType == PermitType.None) revert NonePermitType();

        /*
         * Constants of non-value type not yet implemented, so we have to use else-if's
         *    bytes4[3] internal constant PERMIT_SELECTORS = [
         *        // PermitType.EIP2612
         *        // keccak256(abi.encodePacked(
         *        //     'permit(address,address,uint256,uint256,uint8,bytes32,bytes32)'
         *        // ))
         *        0xd505accf,
         *        // PermitType.DAI
         *        // keccak256(abi.encodePacked(
         *        //     'permit(address,address,uint256,uint256,bool,uint8,bytes32,bytes32)'
         *        // ))
         *        0x8fcbaf0c,
         *        // PermitType.Yearn
         *        // keccak256(abi.encodePacked('permit(address,address,uint256,uint256,bytes)'))
         *        0x9fd5a6cf
         *    ];
         */
        if (permitType == PermitType.EIP2612) return IEIP2612.permit.selector;
        if (permitType == PermitType.DAI) return IDAIPermit.permit.selector;
        if (permitType == PermitType.Yearn) return IYearnPermit.permit.selector;
        // There is no else case here, however, is marked as uncovered by tests
    }
}

File 2 of 26 : IERC1271.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.0 (interfaces/IERC1271.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC1271 standard signature validation method for
 * contracts as defined in https://eips.ethereum.org/EIPS/eip-1271[ERC-1271].
 *
 * _Available since v4.1._
 */
interface IERC1271 {
    /**
     * @dev Should return whether the signature provided is valid for the provided data
     * @param hash      Hash of the data to be signed
     * @param signature Signature byte array associated with _data
     */
    function isValidSignature(bytes32 hash, bytes memory signature) external view returns (bytes4 magicValue);
}

File 3 of 26 : ReentrancyGuard.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.0 (security/ReentrancyGuard.sol)

pragma solidity ^0.8.0;

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

    uint256 private _status;

    constructor() {
        _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() {
        // On the first call to nonReentrant, _notEntered will be true
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

        // Any calls to nonReentrant after this point will fail
        _status = _ENTERED;

        _;

        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _status = _NOT_ENTERED;
    }
}

File 4 of 26 : IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.0 (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

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

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

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

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

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

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

File 5 of 26 : SafeERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.0 (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";
import "../../../utils/Address.sol";

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

    function safeTransfer(
        IERC20 token,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }

    function safeTransferFrom(
        IERC20 token,
        address from,
        address to,
        uint256 value
    ) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
    }

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

    function safeIncreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        uint256 newAllowance = token.allowance(address(this), spender) + value;
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
    }

    function safeDecreaseAllowance(
        IERC20 token,
        address spender,
        uint256 value
    ) internal {
        unchecked {
            uint256 oldAllowance = token.allowance(address(this), spender);
            require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
            uint256 newAllowance = oldAllowance - value;
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
        }
    }

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

        bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
        if (returndata.length > 0) {
            // Return data is optional
            require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
        }
    }
}

File 6 of 26 : Address.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.0 (utils/Address.sol)

pragma solidity ^0.8.0;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize, which returns 0 for contracts in
        // construction, since the code is only stored at the end of the
        // constructor execution.

        uint256 size;
        assembly {
            size := extcodesize(account)
        }
        return size > 0;
    }

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

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

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

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

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

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

        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

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

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        require(isContract(target), "Address: static call to non-contract");

        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

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

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(isContract(target), "Address: delegate call to non-contract");

        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResult(success, returndata, errorMessage);
    }

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

                assembly {
                    let returndata_size := mload(returndata)
                    revert(add(32, returndata), returndata_size)
                }
            } else {
                revert(errorMessage);
            }
        }
    }
}

File 7 of 26 : draft-EIP712.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.0 (utils/cryptography/draft-EIP712.sol)

pragma solidity ^0.8.0;

import "./ECDSA.sol";

/**
 * @dev https://eips.ethereum.org/EIPS/eip-712[EIP 712] is a standard for hashing and signing of typed structured data.
 *
 * The encoding specified in the EIP is very generic, and such a generic implementation in Solidity is not feasible,
 * thus this contract does not implement the encoding itself. Protocols need to implement the type-specific encoding
 * they need in their contracts using a combination of `abi.encode` and `keccak256`.
 *
 * This contract implements the EIP 712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding
 * scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA
 * ({_hashTypedDataV4}).
 *
 * The implementation of the domain separator was designed to be as efficient as possible while still properly updating
 * the chain id to protect against replay attacks on an eventual fork of the chain.
 *
 * NOTE: This contract implements the version of the encoding known as "v4", as implemented by the JSON RPC method
 * https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask].
 *
 * _Available since v3.4._
 */
abstract contract EIP712 {
    /* solhint-disable var-name-mixedcase */
    // Cache the domain separator as an immutable value, but also store the chain id that it corresponds to, in order to
    // invalidate the cached domain separator if the chain id changes.
    bytes32 private immutable _CACHED_DOMAIN_SEPARATOR;
    uint256 private immutable _CACHED_CHAIN_ID;
    address private immutable _CACHED_THIS;

    bytes32 private immutable _HASHED_NAME;
    bytes32 private immutable _HASHED_VERSION;
    bytes32 private immutable _TYPE_HASH;

    /* solhint-enable var-name-mixedcase */

    /**
     * @dev Initializes the domain separator and parameter caches.
     *
     * The meaning of `name` and `version` is specified in
     * https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP 712]:
     *
     * - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol.
     * - `version`: the current major version of the signing domain.
     *
     * NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart
     * contract upgrade].
     */
    constructor(string memory name, string memory version) {
        bytes32 hashedName = keccak256(bytes(name));
        bytes32 hashedVersion = keccak256(bytes(version));
        bytes32 typeHash = keccak256(
            "EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"
        );
        _HASHED_NAME = hashedName;
        _HASHED_VERSION = hashedVersion;
        _CACHED_CHAIN_ID = block.chainid;
        _CACHED_DOMAIN_SEPARATOR = _buildDomainSeparator(typeHash, hashedName, hashedVersion);
        _CACHED_THIS = address(this);
        _TYPE_HASH = typeHash;
    }

    /**
     * @dev Returns the domain separator for the current chain.
     */
    function _domainSeparatorV4() internal view returns (bytes32) {
        if (address(this) == _CACHED_THIS && block.chainid == _CACHED_CHAIN_ID) {
            return _CACHED_DOMAIN_SEPARATOR;
        } else {
            return _buildDomainSeparator(_TYPE_HASH, _HASHED_NAME, _HASHED_VERSION);
        }
    }

    function _buildDomainSeparator(
        bytes32 typeHash,
        bytes32 nameHash,
        bytes32 versionHash
    ) private view returns (bytes32) {
        return keccak256(abi.encode(typeHash, nameHash, versionHash, block.chainid, address(this)));
    }

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

File 8 of 26 : ECDSA.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.0 (utils/cryptography/ECDSA.sol)

pragma solidity ^0.8.0;

import "../Strings.sol";

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

    function _throwError(RecoverError error) private pure {
        if (error == RecoverError.NoError) {
            return; // no error: do nothing
        } else if (error == RecoverError.InvalidSignature) {
            revert("ECDSA: invalid signature");
        } else if (error == RecoverError.InvalidSignatureLength) {
            revert("ECDSA: invalid signature length");
        } else if (error == RecoverError.InvalidSignatureS) {
            revert("ECDSA: invalid signature 's' value");
        } else if (error == RecoverError.InvalidSignatureV) {
            revert("ECDSA: invalid signature 'v' value");
        }
    }

    /**
     * @dev Returns the address that signed a hashed message (`hash`) with
     * `signature` or error string. This address can then be used for verification purposes.
     *
     * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
     * this function rejects them by requiring the `s` value to be in the lower
     * half order, and the `v` value to be either 27 or 28.
     *
     * IMPORTANT: `hash` _must_ be the result of a hash operation for the
     * verification to be secure: it is possible to craft signatures that
     * recover to arbitrary addresses for non-hashed data. A safe way to ensure
     * this is by receiving a hash of the original message (which may otherwise
     * be too long), and then calling {toEthSignedMessageHash} on it.
     *
     * Documentation for signature generation:
     * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
     * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
     *
     * _Available since v4.3._
     */
    function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) {
        // Check the signature length
        // - case 65: r,s,v signature (standard)
        // - case 64: r,vs signature (cf https://eips.ethereum.org/EIPS/eip-2098) _Available since v4.1._
        if (signature.length == 65) {
            bytes32 r;
            bytes32 s;
            uint8 v;
            // ecrecover takes the signature parameters, and the only way to get them
            // currently is to use assembly.
            assembly {
                r := mload(add(signature, 0x20))
                s := mload(add(signature, 0x40))
                v := byte(0, mload(add(signature, 0x60)))
            }
            return tryRecover(hash, v, r, s);
        } else if (signature.length == 64) {
            bytes32 r;
            bytes32 vs;
            // ecrecover takes the signature parameters, and the only way to get them
            // currently is to use assembly.
            assembly {
                r := mload(add(signature, 0x20))
                vs := mload(add(signature, 0x40))
            }
            return tryRecover(hash, r, vs);
        } else {
            return (address(0), RecoverError.InvalidSignatureLength);
        }
    }

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

    /**
     * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.
     *
     * See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]
     *
     * _Available since v4.3._
     */
    function tryRecover(
        bytes32 hash,
        bytes32 r,
        bytes32 vs
    ) internal pure returns (address, RecoverError) {
        bytes32 s;
        uint8 v;
        assembly {
            s := and(vs, 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)
            v := add(shr(255, vs), 27)
        }
        return tryRecover(hash, v, r, s);
    }

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

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

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

        return (signer, RecoverError.NoError);
    }

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

    /**
     * @dev Returns an Ethereum Signed Message, created from a `hash`. This
     * produces hash corresponding to the one signed with the
     * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
     * JSON-RPC method as part of EIP-191.
     *
     * See {recover}.
     */
    function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32) {
        // 32 is the length in bytes of hash,
        // enforced by the type signature above
        return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", hash));
    }

    /**
     * @dev Returns an Ethereum Signed Message, created from `s`. This
     * produces hash corresponding to the one signed with the
     * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
     * JSON-RPC method as part of EIP-191.
     *
     * See {recover}.
     */
    function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) {
        return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n", Strings.toString(s.length), s));
    }

    /**
     * @dev Returns an Ethereum Signed Typed Data, created from a
     * `domainSeparator` and a `structHash`. This produces hash corresponding
     * to the one signed with the
     * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`]
     * JSON-RPC method as part of EIP-712.
     *
     * See {recover}.
     */
    function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32) {
        return keccak256(abi.encodePacked("\x19\x01", domainSeparator, structHash));
    }
}

File 9 of 26 : SignatureChecker.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.0 (utils/cryptography/SignatureChecker.sol)

pragma solidity ^0.8.0;

import "./ECDSA.sol";
import "../Address.sol";
import "../../interfaces/IERC1271.sol";

/**
 * @dev Signature verification helper: Provide a single mechanism to verify both private-key (EOA) ECDSA signature and
 * ERC1271 contract signatures. Using this instead of ECDSA.recover in your contract will make them compatible with
 * smart contract wallets such as Argent and Gnosis.
 *
 * Note: unlike ECDSA signatures, contract signature's are revocable, and the outcome of this function can thus change
 * through time. It could return true at block N and false at block N+1 (or the opposite).
 *
 * _Available since v4.1._
 */
library SignatureChecker {
    function isValidSignatureNow(
        address signer,
        bytes32 hash,
        bytes memory signature
    ) internal view returns (bool) {
        (address recovered, ECDSA.RecoverError error) = ECDSA.tryRecover(hash, signature);
        if (error == ECDSA.RecoverError.NoError && recovered == signer) {
            return true;
        }

        (bool success, bytes memory result) = signer.staticcall(
            abi.encodeWithSelector(IERC1271.isValidSignature.selector, hash, signature)
        );
        return (success && result.length == 32 && abi.decode(result, (bytes4)) == IERC1271.isValidSignature.selector);
    }
}

File 10 of 26 : Strings.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.0 (utils/Strings.sol)

pragma solidity ^0.8.0;

/**
 * @dev String operations.
 */
library Strings {
    bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";

    /**
     * @dev Converts a `uint256` to its ASCII `string` decimal representation.
     */
    function toString(uint256 value) internal pure returns (string memory) {
        // Inspired by OraclizeAPI's implementation - MIT licence
        // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol

        if (value == 0) {
            return "0";
        }
        uint256 temp = value;
        uint256 digits;
        while (temp != 0) {
            digits++;
            temp /= 10;
        }
        bytes memory buffer = new bytes(digits);
        while (value != 0) {
            digits -= 1;
            buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
            value /= 10;
        }
        return string(buffer);
    }

    /**
     * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
     */
    function toHexString(uint256 value) internal pure returns (string memory) {
        if (value == 0) {
            return "0x00";
        }
        uint256 temp = value;
        uint256 length = 0;
        while (temp != 0) {
            length++;
            temp >>= 8;
        }
        return toHexString(value, length);
    }

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

File 11 of 26 : ICaller.sol
// Copyright (C) 2020 Zerion Inc. <https://zerion.io>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//
// SPDX-License-Identifier: LGPL-3.0-only

pragma solidity 0.8.12;

import { AbsoluteTokenAmount } from "../shared/Structs.sol";

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

interface ICaller is ITokensHandler {
    /**
     * @notice Main external function: implements all the caller specific logic
     * @param callerCallData ABI-encoded parameters depending on the caller logic
     */
    function callBytes(bytes calldata callerCallData) external;
}

File 12 of 26 : IDAIPermit.sol
// Copyright (C) 2020 Zerion Inc. <https://zerion.io>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//
// SPDX-License-Identifier: LGPL-3.0-only

pragma solidity 0.8.12;

import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

interface IDAIPermit is IERC20 {
    function permit(
        address holder,
        address spender,
        uint256 nonce,
        uint256 expiry,
        bool allowed,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;

    function nonces(address holder) external view returns (uint256);
}

File 13 of 26 : IEIP2612.sol
// Copyright (C) 2020 Zerion Inc. <https://zerion.io>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//
// SPDX-License-Identifier: LGPL-3.0-only

pragma solidity 0.8.12;

import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

interface IEIP2612 is IERC20 {
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;

    function nonces(address holder) external view returns (uint256);
}

File 14 of 26 : IProtocolFee.sol
// Copyright (C) 2020 Zerion Inc. <https://zerion.io>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//
// SPDX-License-Identifier: LGPL-3.0-only

pragma solidity 0.8.12;

import { Fee } from "../shared/Structs.sol";

interface IProtocolFee {
    /**
     * @notice Sets protocol fee default value
     * @param protocolFeeDefault New base fee defaul value
     * @dev Can be called only by the owner
     */
    function setProtocolFeeDefault(Fee calldata protocolFeeDefault) external;

    /**
     * @notice Sets protocol fee signature signer
     * @param signer New signer
     * @dev Can be called only by the owner
     */
    function setProtocolFeeSigner(address signer) external;

    /**
     * @notice Returns current protocol fee default value
     * @return protocolFeeDefault Protocol fee consisting of its share and beneficiary
     */
    function getProtocolFeeDefault() external view returns (Fee memory protocolFeeDefault);

    /**
     * @notice Returns current protocol fee signature signer
     * @return signer Current signer address
     */
    function getProtocolFeeSigner() external view returns (address signer);
}

File 15 of 26 : IRouter.sol
// Copyright (C) 2020 Zerion Inc. <https://zerion.io>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//
// SPDX-License-Identifier: LGPL-3.0-only

pragma solidity 0.8.12;

import {
    AbsoluteTokenAmount,
    Input,
    SwapDescription,
    AccountSignature,
    ProtocolFeeSignature,
    Fee
} from "../shared/Structs.sol";

import { ITokensHandler } from "./ITokensHandler.sol";
import { ISignatureVerifier } from "./ISignatureVerifier.sol";

interface IRouter is ITokensHandler, ISignatureVerifier {
    /**
     * @notice Emits swap info
     * @param inputToken Input token address
     * @param absoluteInputAmount Max amount of input token to be taken from the account address
     * @param inputBalanceChange Actual amount of input token taken from the account address
     * @param outputToken Output token address
     * @param absoluteOutputAmount Min amount of output token to be returned to the account address
     * @param returnedAmount Actual amount of tokens returned to the account address
     * @param protocolFeeAmount Protocol fee amount
     * @param marketplaceFeeAmount Marketplace fee amount
     * @param swapDescription Swap parameters
     * @param sender Address that called the Router contract
     */
    event Executed(
        address indexed inputToken,
        uint256 absoluteInputAmount,
        uint256 inputBalanceChange,
        address indexed outputToken,
        uint256 absoluteOutputAmount,
        uint256 returnedAmount,
        uint256 protocolFeeAmount,
        uint256 marketplaceFeeAmount,
        SwapDescription swapDescription,
        address sender
    );

    /**
     * @notice Main function executing the swaps
     * @param input Token and amount (relative or absolute) to be taken from the account address,
     *     also, permit type and call data may provided if required
     * @dev `address(0)` may be used as input token address,
     *     in this case no tokens will be taken from the user
     * @param absoluteOutput Token and absolute amount requirement
     *     to be returned to the account address
     * @dev `address(0)` may be used as output token address,
     *     in this case no tokens will be returned to the user, no fees are applied
     * @param swapDescription Swap description with the following elements:
     *     - Whether the inputs or outputs are fixed
     *     - Protocol fee share and beneficiary address
     *     - Marketplace fee share and beneficiary address
     *     - Address of the account executing the swap
     *     - Address of the Caller contract to be called
     *     - Calldata for the call to the Caller contract
     * @param accountSignature Signature for the relayed transaction
     *     (checks that account address is the one who actually did a signature)
     * @param protocolFeeSignature Signature for the discounted protocol fee
     *     (checks that current protocol fee signer is the one who actually did a signature),
     *     this signature may be reused multiple times until the deadline
     * @return inputBalanceChange Actual amount of input tokens spent
     * @return actualOutputAmount Actual amount of output tokens returned to the user
     * @return protocolFeeAmount Actual amount of output tokens charged as protocol fee
     * @return marketplaceFeeAmount Actual amount of output tokens charged as marketplace fee
     */
    function execute(
        Input calldata input,
        AbsoluteTokenAmount calldata absoluteOutput,
        SwapDescription calldata swapDescription,
        AccountSignature calldata accountSignature,
        ProtocolFeeSignature calldata protocolFeeSignature
    ) external payable
        returns (
            uint256 inputBalanceChange,
            uint256 actualOutputAmount,
            uint256 protocolFeeAmount,
            uint256 marketplaceFeeAmount
        );

    /**
     * @notice Function for the account signature cancellation
     * @param input Token and amount (relative or absolute) to be taken from the account address,
     *     also, permit type and call data may provided if required
     * @dev `address(0)` may be used as input token address,
     *     in this case no tokens will be taken from the user
     * @param absoluteOutput Token and absolute amount requirement
     *     to be returned to the account address
     * @dev `address(0)` may be used as output token address,
     *     in this case no tokens will be returned to the user, no fees are applied
     * @param swapDescription Swap description with the following elements:
     *     - Whether the inputs or outputs are fixed
     *     - Protocol fee share and beneficiary address
     *     - Marketplace fee share and beneficiary address
     *     - Address of the account executing the swap
     *     - Address of the Caller contract to be called
     *     - Calldata for the call to the Caller contract
     * @param accountSignature Signature for the relayed transaction
     *     (checks that account address is the one who actually did a signature)
     */
    function cancelAccountSignature(
        Input calldata input,
        AbsoluteTokenAmount calldata absoluteOutput,
        SwapDescription calldata swapDescription,
        AccountSignature calldata accountSignature
    ) external;
}

File 16 of 26 : ISignatureVerifier.sol
// Copyright (C) 2020 Zerion Inc. <https://zerion.io>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//
// SPDX-License-Identifier: LGPL-3.0-only

pragma solidity 0.8.12;

import { EIP712 } from "@openzeppelin/contracts/utils/cryptography/draft-EIP712.sol";
import { ECDSA } from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";

import { AbsoluteTokenAmount, Input, SwapDescription } from "../shared/Structs.sol";

interface ISignatureVerifier {
    /**
     * @param hashToCheck Hash to be checked
     * @return hashUsed True if hash has already been used by this account address
     */
    function isHashUsed(bytes32 hashToCheck) external view returns (bool hashUsed);

    /**
     * @param input Input struct to be hashed
     * @param requiredOutput AbsoluteTokenAmount struct to be hashed
     * @param swapDescription SwapDescription struct to be hashed
     * @param salt Salt parameter preventing double-spending to be hashed
     * @return hashedData Execute data hashed with domainSeparator
     */
    function hashAccountSignatureData(
        Input memory input,
        AbsoluteTokenAmount memory requiredOutput,
        SwapDescription memory swapDescription,
        uint256 salt
    ) external view returns (bytes32 hashedData);

    /**
     * @param input Input struct to be hashed
     * @param requiredOutput AbsoluteTokenAmount struct to be hashed
     * @param swapDescription SwapDescription struct to be hashed
     * @param deadline Deadline showing the timestamp signature is valid up to
     * @return hashedData Execute data hashed with domainSeparator
     */
    function hashProtocolFeeSignatureData(
        Input memory input,
        AbsoluteTokenAmount memory requiredOutput,
        SwapDescription memory swapDescription,
        uint256 deadline
    ) external view returns (bytes32 hashedData);
}

File 17 of 26 : ITokensHandler.sol
// Copyright (C) 2020 Zerion Inc. <https://zerion.io>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//
// SPDX-License-Identifier: LGPL-3.0-only

pragma solidity 0.8.12;

interface ITokensHandler {
    /**
     * @notice Returns tokens mistakenly sent to this contract
     * @param token Address of token
     * @param beneficiary Address that will receive tokens
     * @dev Can be called only by the owner
     */
    function returnLostTokens(address token, address payable beneficiary) external;
}

File 18 of 26 : IYearnPermit.sol
// Copyright (C) 2020 Zerion Inc. <https://zerion.io>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//
// SPDX-License-Identifier: LGPL-3.0-only

pragma solidity 0.8.12;

import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

interface IYearnPermit is IERC20 {
    function permit(
        address,
        address,
        uint256,
        uint256,
        bytes calldata
    ) external;
}

File 19 of 26 : ProtocolFee.sol
// Copyright (C) 2020 Zerion Inc. <https://zerion.io>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//
// SPDX-License-Identifier: LGPL-3.0-only

pragma solidity 0.8.12;

import { IProtocolFee } from "../interfaces/IProtocolFee.sol";
import { BadFeeShare, ZeroFeeBeneficiary, ZeroSigner } from "../shared/Errors.sol";
import { Ownable } from "../shared/Ownable.sol";
import { Fee } from "../shared/Structs.sol";

// solhint-disable code-complexity
contract ProtocolFee is IProtocolFee, Ownable {
    uint256 internal constant DELIMITER = 1e18; // 100%

    Fee private protocolFeeDefault_;
    address private protocolFeeSigner_;

    /**
     * @notice Emits old and new protocol fee signature signer
     * @param oldProtocolFeeSigner Old protocol fee signature signer
     * @param newProtocolFeeSigner New protocol fee signature signer
     */
    event ProtocolFeeSignerSet(
        address indexed oldProtocolFeeSigner,
        address indexed newProtocolFeeSigner
    );

    /**
     * @notice Emits old and new protocol fee defaults
     * @param oldProtocolFeeDefaultShare Old protocol fee default share
     * @param oldProtocolFeeDefaultBeneficiary Old protocol fee default beneficiary
     * @param newProtocolFeeDefaultShare New protocol fee default share
     * @param newProtocolFeeDefaultBeneficiary New protocol fee default beneficiary
     */
    event ProtocolFeeDefaultSet(
        uint256 oldProtocolFeeDefaultShare,
        address indexed oldProtocolFeeDefaultBeneficiary,
        uint256 newProtocolFeeDefaultShare,
        address indexed newProtocolFeeDefaultBeneficiary
    );

    /**
     * @inheritdoc IProtocolFee
     */
    function setProtocolFeeDefault(Fee calldata protocolFeeDefault) external override onlyOwner {
        if (protocolFeeDefault.share > uint256(0) && protocolFeeDefault.beneficiary == address(0))
            revert ZeroFeeBeneficiary();
        if (protocolFeeDefault.share > DELIMITER)
            revert BadFeeShare(protocolFeeDefault.share, DELIMITER);

        protocolFeeDefault_ = protocolFeeDefault;
    }

    /**
     * @inheritdoc IProtocolFee
     */
    function setProtocolFeeSigner(address signer) external override onlyOwner {
        if (signer == address(0)) revert ZeroSigner();

        protocolFeeSigner_ = signer;
    }

    /**
     * @inheritdoc IProtocolFee
     */
    function getProtocolFeeDefault() public view override returns (Fee memory protocolFeeDefault) {
        return protocolFeeDefault_;
    }

    /**
     * @inheritdoc IProtocolFee
     */
    function getProtocolFeeSigner() public view override returns (address protocolFeeSigner) {
        return protocolFeeSigner_;
    }
}

File 20 of 26 : SignatureVerifier.sol
// Copyright (C) 2020 Zerion Inc. <https://zerion.io>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//
// SPDX-License-Identifier: LGPL-3.0-only

pragma solidity 0.8.12;

import { EIP712 } from "@openzeppelin/contracts/utils/cryptography/draft-EIP712.sol";

import { ISignatureVerifier } from "../interfaces/ISignatureVerifier.sol";
import { UsedHash } from "../shared/Errors.sol";
import {
    AbsoluteTokenAmount,
    AccountSignature,
    ProtocolFeeSignature,
    Fee,
    Input,
    Permit,
    SwapDescription,
    TokenAmount
} from "../shared/Structs.sol";

contract SignatureVerifier is ISignatureVerifier, EIP712 {
    mapping(bytes32 => bool) private isHashUsed_;

    bytes32 internal constant ACCOUNT_SIGNATURE_TYPEHASH =
        keccak256(
            abi.encodePacked(
                "AccountSignature(",
                "Input input,",
                "AbsoluteTokenAmount output,",
                "SwapDescription swapDescription,",
                "uint256 salt",
                ")",
                "AbsoluteTokenAmount(address token,uint256 absoluteAmount)",
                "Fee(uint256 share,address beneficiary)",
                "Input(TokenAmount tokenAmount,Permit permit)",
                "Permit(uint8 permitType,bytes permitCallData)",
                "SwapDescription(",
                "uint8 swapType,",
                "Fee protocolFee,",
                "Fee marketplaceFee,",
                "address account,",
                "address caller,",
                "bytes callerCallData",
                ")",
                "TokenAmount(address token,uint256 amount,uint8 amountType)"
            )
        );
    bytes32 internal constant PROTOCOL_FEE_SIGNATURE_TYPEHASH =
        keccak256(
            abi.encodePacked(
                "ProtocolFeeSignature(",
                "Input input,",
                "AbsoluteTokenAmount output,",
                "SwapDescription swapDescription,",
                "uint256 deadline",
                ")",
                "AbsoluteTokenAmount(address token,uint256 absoluteAmount)",
                "Fee(uint256 share,address beneficiary)",
                "Input(TokenAmount tokenAmount,Permit permit)",
                "Permit(uint8 permitType,bytes permitCallData)",
                "SwapDescription(",
                "uint8 swapType,",
                "Fee protocolFee,",
                "Fee marketplaceFee,",
                "address account,",
                "address caller,",
                "bytes callerCallData",
                ")",
                "TokenAmount(address token,uint256 amount,uint8 amountType)"
            )
        );
    bytes32 internal constant ABSOLUTE_TOKEN_AMOUNT_TYPEHASH =
        keccak256(abi.encodePacked("AbsoluteTokenAmount(address token,uint256 absoluteAmount)"));
    bytes32 internal constant SWAP_DESCRIPTION_TYPEHASH =
        keccak256(
            abi.encodePacked(
                "SwapDescription(",
                "uint8 swapType,",
                "Fee protocolFee,",
                "Fee marketplaceFee,",
                "address account,",
                "address caller,",
                "bytes callerCallData",
                ")",
                "Fee(uint256 share,address beneficiary)"
            )
        );
    bytes32 internal constant FEE_TYPEHASH =
        keccak256(abi.encodePacked("Fee(uint256 share,address beneficiary)"));
    bytes32 internal constant INPUT_TYPEHASH =
        keccak256(
            abi.encodePacked(
                "Input(TokenAmount tokenAmount,Permit permit)",
                "Permit(uint8 permitType,bytes permitCallData)",
                "TokenAmount(address token,uint256 amount,uint8 amountType)"
            )
        );
    bytes32 internal constant PERMIT_TYPEHASH =
        keccak256(abi.encodePacked("Permit(uint8 permitType,bytes permitCallData)"));
    bytes32 internal constant TOKEN_AMOUNT_TYPEHASH =
        keccak256(abi.encodePacked("TokenAmount(address token,uint256 amount,uint8 amountType)"));

    /**
     * @param name String with EIP712 name.
     * @param version String with EIP712 version.
     */
    constructor(string memory name, string memory version) EIP712(name, version) {
        // solhint-disable-previous-line no-empty-blocks
    }

    /**
     * @inheritdoc ISignatureVerifier
     */
    function isHashUsed(bytes32 hashToCheck) external view override returns (bool hashUsed) {
        return isHashUsed_[hashToCheck];
    }

    /**
     * @inheritdoc ISignatureVerifier
     */
    function hashAccountSignatureData(
        Input memory input,
        AbsoluteTokenAmount memory output,
        SwapDescription memory swapDescription,
        uint256 salt
    ) public view override returns (bytes32 hashedData) {
        return
            _hashTypedDataV4(
                hash(ACCOUNT_SIGNATURE_TYPEHASH, input, output, swapDescription, salt)
            );
    }

    /**
     * @inheritdoc ISignatureVerifier
     */
    function hashProtocolFeeSignatureData(
        Input memory input,
        AbsoluteTokenAmount memory output,
        SwapDescription memory swapDescription,
        uint256 deadline
    ) public view override returns (bytes32 hashedData) {
        return
            _hashTypedDataV4(
                hash(PROTOCOL_FEE_SIGNATURE_TYPEHASH, input, output, swapDescription, deadline)
            );
    }

    /**
     * @dev Marks hash as used by the given account.
     * @param hashToMark Hash to be marked as used one.
     */
    function markHashUsed(bytes32 hashToMark) internal {
        if (isHashUsed_[hashToMark]) revert UsedHash(hashToMark);

        isHashUsed_[hashToMark] = true;
    }

    /**
     * @param typehash The required signature typehash
     * @param input Input described in `hashDada()` function
     * @param output Outut described in `hashDada()` function
     * @param swapDescription Swap parameters described in `hashDada()` function
     * @param saltOrDeadline Salt/deadline parameter preventing double-spending
     * @return `execute()` function data hashed
     */
    function hash(
        bytes32 typehash,
        Input memory input,
        AbsoluteTokenAmount memory output,
        SwapDescription memory swapDescription,
        uint256 saltOrDeadline
    ) internal pure returns (bytes32) {
        return
            keccak256(
                abi.encode(
                    typehash,
                    hash(input),
                    hash(output),
                    hash(swapDescription),
                    saltOrDeadline
                )
            );
    }

    /**
     * @param input Input struct to be hashed
     * @return Hashed Input structs array
     */
    function hash(Input memory input) internal pure returns (bytes32) {
        return keccak256(abi.encode(INPUT_TYPEHASH, hash(input.tokenAmount), hash(input.permit)));
    }

    /**
     * @param tokenAmount TokenAmount struct to be hashed
     * @return Hashed TokenAmount struct
     */
    function hash(TokenAmount memory tokenAmount) internal pure returns (bytes32) {
        return
            keccak256(
                abi.encode(
                    TOKEN_AMOUNT_TYPEHASH,
                    tokenAmount.token,
                    tokenAmount.amount,
                    tokenAmount.amountType
                )
            );
    }

    /**
     * @param permit Permit struct to be hashed
     * @return Hashed Permit struct
     */
    function hash(Permit memory permit) internal pure returns (bytes32) {
        return
            keccak256(
                abi.encode(
                    PERMIT_TYPEHASH,
                    permit.permitType,
                    keccak256(abi.encodePacked(permit.permitCallData))
                )
            );
    }

    /**
     * @param absoluteTokenAmount AbsoluteTokenAmount struct to be hashed
     * @return Hashed AbsoluteTokenAmount struct
     */
    function hash(AbsoluteTokenAmount memory absoluteTokenAmount) internal pure returns (bytes32) {
        return
            keccak256(
                abi.encode(
                    ABSOLUTE_TOKEN_AMOUNT_TYPEHASH,
                    absoluteTokenAmount.token,
                    absoluteTokenAmount.absoluteAmount
                )
            );
    }

    /**
     * @param swapDescription SwapDescription struct to be hashed
     * @return Hashed SwapDescription struct
     */
    function hash(SwapDescription memory swapDescription) internal pure returns (bytes32) {
        return
            keccak256(
                abi.encode(
                    SWAP_DESCRIPTION_TYPEHASH,
                    swapDescription.swapType,
                    hash(swapDescription.protocolFee),
                    hash(swapDescription.marketplaceFee),
                    swapDescription.account,
                    swapDescription.caller,
                    keccak256(abi.encodePacked(swapDescription.callerCallData))
                )
            );
    }

    /**
     * @param fee Fee struct to be hashed
     * @return Hashed Fee struct
     */
    function hash(Fee memory fee) internal pure returns (bytes32) {
        return keccak256(abi.encode(FEE_TYPEHASH, fee.share, fee.beneficiary));
    }
}

File 21 of 26 : Base.sol
// Copyright (C) 2020 Zerion Inc. <https://zerion.io>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//
// SPDX-License-Identifier: LGPL-3.0-only

pragma solidity 0.8.12;

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

import { FailedEtherTransfer, ZeroReceiver } from "./Errors.sol";

/**
 * @title Library unifying transfer, approval, and getting balance for ERC20 tokens and Ether
 */
library Base {
    address internal constant ETH = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;

    /**
     * @notice Transfers tokens or Ether
     * @param token Address of the token or `ETH` in case of Ether transfer
     * @param receiver Address of the account that will receive funds
     * @param amount Amount to be transferred
     * @dev This function is compatible only with ERC20 tokens and Ether, not ERC721/ERC1155 tokens
     * @dev Reverts on zero `receiver`, does nothing for zero amount
     * @dev Should not be used with zero token address
     */
    function transfer(
        address token,
        address receiver,
        uint256 amount
    ) internal {
        if (amount == uint256(0)) return;
        if (receiver == address(0)) revert ZeroReceiver();

        if (token == ETH) {
            Address.sendValue(payable(receiver), amount);
        } else {
            SafeERC20.safeTransfer(IERC20(token), receiver, amount);
        }
    }

    /**
     * @notice Safely approves type(uint256).max tokens
     * @param token Address of the token
     * @param spender Address to approve tokens to
     * @param amount Tokens amount to be approved
     * @dev Should not be used with zero or `ETH` token address
     */
    function safeApproveMax(
        address token,
        address spender,
        uint256 amount
    ) internal {
        uint256 allowance = IERC20(token).allowance(address(this), spender);
        if (allowance < amount) {
            if (allowance > uint256(0)) {
                SafeERC20.safeApprove(IERC20(token), spender, uint256(0));
            }
            SafeERC20.safeApprove(IERC20(token), spender, type(uint256).max);
        }
    }

    /**
     * @notice Calculates the token balance for the given account
     * @param token Address of the token
     * @param account Address of the account
     * @dev Should not be used with zero token address
     */
    function getBalance(address token, address account) internal view returns (uint256) {
        if (token == ETH) return account.balance;

        return IERC20(token).balanceOf(account);
    }

    /**
     * @notice Calculates the token balance for `this` contract address
     * @param token Address of the token
     * @dev Returns `0` for zero token address in order to handle empty token case
     */
    function getBalance(address token) internal view returns (uint256) {
        if (token == address(0)) return uint256(0);

        return Base.getBalance(token, address(this));
    }
}

File 22 of 26 : Enums.sol
// Copyright (C) 2020 Zerion Inc. <https://zerion.io>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//
// SPDX-License-Identifier: LGPL-3.0-only

pragma solidity 0.8.12;

enum ActionType {
    None,
    Deposit,
    Withdraw
}

enum AmountType {
    None,
    Relative,
    Absolute
}

enum SwapType {
    None,
    FixedInputs,
    FixedOutputs
}

enum PermitType {
    None,
    EIP2612,
    DAI,
    Yearn
}

File 23 of 26 : Errors.sol
// Copyright (C) 2020 Zerion Inc. <https://zerion.io>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//
// SPDX-License-Identifier: LGPL-3.0-only

pragma solidity 0.8.12;

import { ActionType, AmountType, PermitType, SwapType } from "./Enums.sol";
import { Fee } from "./Structs.sol";

error BadAccount(address account, address expectedAccount);
error BadAccountSignature();
error BadAmount(uint256 amount, uint256 requiredAmount);
error BadAmountType(AmountType amountType, AmountType requiredAmountType);
error BadFee(Fee fee, Fee baseProtocolFee);
error BadFeeAmount(uint256 actualFeeAmount, uint256 expectedFeeAmount);
error BadFeeSignature();
error BadFeeShare(uint256 protocolFeeShare, uint256 baseProtocolFeeShare);
error BadFeeBeneficiary(address protocolFeeBanaficiary, address baseProtocolFeeBeneficiary);
error BadLength(uint256 length, uint256 requiredLength);
error BadMsgSender(address msgSender, address requiredMsgSender);
error BadProtocolAdapterName(bytes32 protocolAdapterName);
error BadToken(address token);
error ExceedingDelimiterAmount(uint256 amount);
error ExceedingLimitFee(uint256 feeShare, uint256 feeLimit);
error FailedEtherTransfer(address to);
error HighInputBalanceChange(uint256 inputBalanceChange, uint256 requiredInputBalanceChange);
error InconsistentPairsAndDirectionsLengths(uint256 pairsLength, uint256 directionsLength);
error InputSlippage(uint256 amount, uint256 requiredAmount);
error InsufficientAllowance(uint256 allowance, uint256 requiredAllowance);
error InsufficientMsgValue(uint256 msgValue, uint256 requiredMsgValue);
error LowActualOutputAmount(uint256 actualOutputAmount, uint256 requiredActualOutputAmount);
error LowReserve(uint256 reserve, uint256 requiredReserve);
error NoneActionType();
error NoneAmountType();
error NonePermitType();
error NoneSwapType();
error PassedDeadline(uint256 timestamp, uint256 deadline);
error TooLowBaseFeeShare(uint256 baseProtocolFeeShare, uint256 baseProtocolFeeShareLimit);
error UsedHash(bytes32 hash);
error ZeroReceiver();
error ZeroAmountIn();
error ZeroAmountOut();
error ZeroFeeBeneficiary();
error ZeroLength();
error ZeroProtocolAdapterRegistry();
error ZeroSigner();
error ZeroSwapPath();
error ZeroTarget();

File 24 of 26 : Ownable.sol
// Copyright (C) 2020 Zerion Inc. <https://zerion.io>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//
// SPDX-License-Identifier: LGPL-3.0-only

pragma solidity 0.8.12;

/**
 * @title Abstract contract with basic Ownable functionality and two-step ownership transfer
 */
abstract contract Ownable {
    address private pendingOwner_;
    address private owner_;

    /**
     * @notice Emits old and new pending owners
     * @param oldPendingOwner Old pending owner
     * @param newPendingOwner New pending owner
     */
    event PendingOwnerSet(address indexed oldPendingOwner, address indexed newPendingOwner);

    /**
     * @notice Emits old and new owners
     * @param oldOwner Old contract's owner
     * @param newOwner New contract's owner
     */
    event OwnerSet(address indexed oldOwner, address indexed newOwner);

    modifier onlyPendingOwner() {
        require(msg.sender == pendingOwner_, "O: only pending owner");
        _;
    }

    modifier onlyOwner() {
        require(msg.sender == owner_, "O: only owner");
        _;
    }

    /**
     * @notice Initializes owner variable with msg.sender address
     */
    constructor() {
        emit OwnerSet(address(0), msg.sender);

        owner_ = msg.sender;
    }

    /**
     * @notice Sets pending owner to the `newPendingOwner` address
     * @param newPendingOwner Address of new pending owner
     * @dev The function is callable only by the owner
     */
    function setPendingOwner(address newPendingOwner) external onlyOwner {
        emit PendingOwnerSet(pendingOwner_, newPendingOwner);

        pendingOwner_ = newPendingOwner;
    }

    /**
     * @notice Sets owner to the pending owner
     * @dev The function is callable only by the pending owner
     */
    function setOwner() external onlyPendingOwner {
        emit OwnerSet(owner_, msg.sender);

        owner_ = msg.sender;
        delete pendingOwner_;
    }

    /**
     * @return owner Owner of the contract
     */
    function getOwner() external view returns (address owner) {
        return owner_;
    }

    /**
     * @return pendingOwner Pending owner of the contract
     */
    function getPendingOwner() external view returns (address pendingOwner) {
        return pendingOwner_;
    }
}

File 25 of 26 : Structs.sol
// Copyright (C) 2020 Zerion Inc. <https://zerion.io>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//
// SPDX-License-Identifier: LGPL-3.0-only

pragma solidity 0.8.12;

import { ActionType, AmountType, PermitType, SwapType } from "./Enums.sol";

//=============================== Adapters Managers Structs ====================================

// The struct consists of adapter name and address
struct AdapterNameAndAddress {
    bytes32 name;
    address adapter;
}

// The struct consists of token and its adapter name
struct TokenAndAdapterName {
    address token;
    bytes32 name;
}

// The struct consists of hash (hash of token's bytecode or address) and its adapter name
struct HashAndAdapterName {
    bytes32 hash;
    bytes32 name;
}

// The struct consists of TokenBalanceMeta structs for
// (base) token and its underlying tokens (if any)
struct FullTokenBalance {
    TokenBalanceMeta base;
    TokenBalanceMeta[] underlying;
}

// The struct consists of TokenBalance struct with token address and absolute amount
// and ERC20Metadata struct with ERC20-style metadata
// 0xEeee...EEeE address is used for Ether
struct TokenBalanceMeta {
    TokenBalance tokenBalance;
    ERC20Metadata erc20metadata;
}

// The struct consists of ERC20-style token metadata
struct ERC20Metadata {
    string name;
    string symbol;
    uint8 decimals;
}

// The struct consists of protocol adapter's name and array of TokenBalance structs
// with token addresses and absolute amounts
struct AdapterBalance {
    bytes32 name;
    TokenBalance[] tokenBalances;
}

// The struct consists of protocol adapter's name and array of supported tokens' addresses
struct AdapterTokens {
    bytes32 name;
    address[] tokens;
}

// The struct consists of token address and its absolute amount (may be negative)
// 0xEeee...EEeE is used for Ether
struct TokenBalance {
    address token;
    int256 amount;
}

//=============================== Interactive Adapters Structs ====================================

// The struct consists of swap type, fee descriptions (share & beneficiary), account address,
// and Caller contract address with call data used for the call
struct SwapDescription {
    SwapType swapType;
    Fee protocolFee;
    Fee marketplaceFee;
    address account;
    address caller;
    bytes callerCallData;
}

// The struct consists of name of the protocol adapter, action type,
// array of token amounts, and some additional data (depends on the protocol)
struct Action {
    bytes32 protocolAdapterName;
    ActionType actionType;
    TokenAmount[] tokenAmounts;
    bytes data;
}

// The struct consists of token address, its amount, and amount type,
// as well as permit type and calldata.
struct Input {
    TokenAmount tokenAmount;
    Permit permit;
}

// The struct consists of permit type and call data
struct Permit {
    PermitType permitType;
    bytes permitCallData;
}

// The struct consists of token address, its amount, and amount type
// 0xEeee...EEeE is used for Ether
struct TokenAmount {
    address token;
    uint256 amount;
    AmountType amountType;
}

// The struct consists of fee share and beneficiary address
struct Fee {
    uint256 share;
    address beneficiary;
}

// The struct consists of deadline and signature
struct ProtocolFeeSignature {
    uint256 deadline;
    bytes signature;
}

// The struct consists of salt and signature
struct AccountSignature {
    uint256 salt;
    bytes signature;
}

// The struct consists of token address and its absolute amount
// 0xEeee...EEeE is used for Ether
struct AbsoluteTokenAmount {
    address token;
    uint256 absoluteAmount;
}

File 26 of 26 : TokensHandler.sol
// Copyright (C) 2020 Zerion Inc. <https://zerion.io>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//
// SPDX-License-Identifier: LGPL-3.0-only

pragma solidity 0.8.12;

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

import { Base } from "./Base.sol";
import { Ownable } from "./Ownable.sol";

/**
 * @title Abstract contract returning tokens lost on the contract
 */
abstract contract TokensHandler is ITokensHandler, Ownable {
    receive() external payable {
        // solhint-disable-previous-line no-empty-blocks
    }

    /**
     * @inheritdoc ITokensHandler
     */
    function returnLostTokens(address token, address payable beneficiary) external onlyOwner {
        Base.transfer(token, beneficiary, Base.getBalance(token));
    }
}

Settings
{
  "optimizer": {
    "enabled": true,
    "runs": 1000000
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "libraries": {}
}

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"address","name":"expectedAccount","type":"address"}],"name":"BadAccount","type":"error"},{"inputs":[],"name":"BadAccountSignature","type":"error"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"requiredAmount","type":"uint256"}],"name":"BadAmount","type":"error"},{"inputs":[{"internalType":"enum AmountType","name":"amountType","type":"uint8"},{"internalType":"enum AmountType","name":"requiredAmountType","type":"uint8"}],"name":"BadAmountType","type":"error"},{"inputs":[{"internalType":"uint256","name":"actualFeeAmount","type":"uint256"},{"internalType":"uint256","name":"expectedFeeAmount","type":"uint256"}],"name":"BadFeeAmount","type":"error"},{"inputs":[{"internalType":"address","name":"protocolFeeBanaficiary","type":"address"},{"internalType":"address","name":"baseProtocolFeeBeneficiary","type":"address"}],"name":"BadFeeBeneficiary","type":"error"},{"inputs":[{"internalType":"uint256","name":"protocolFeeShare","type":"uint256"},{"internalType":"uint256","name":"baseProtocolFeeShare","type":"uint256"}],"name":"BadFeeShare","type":"error"},{"inputs":[],"name":"BadFeeSignature","type":"error"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"ExceedingDelimiterAmount","type":"error"},{"inputs":[{"internalType":"uint256","name":"feeShare","type":"uint256"},{"internalType":"uint256","name":"feeLimit","type":"uint256"}],"name":"ExceedingLimitFee","type":"error"},{"inputs":[{"internalType":"uint256","name":"inputBalanceChange","type":"uint256"},{"internalType":"uint256","name":"requiredInputBalanceChange","type":"uint256"}],"name":"HighInputBalanceChange","type":"error"},{"inputs":[{"internalType":"uint256","name":"allowance","type":"uint256"},{"internalType":"uint256","name":"requiredAllowance","type":"uint256"}],"name":"InsufficientAllowance","type":"error"},{"inputs":[{"internalType":"uint256","name":"msgValue","type":"uint256"},{"internalType":"uint256","name":"requiredMsgValue","type":"uint256"}],"name":"InsufficientMsgValue","type":"error"},{"inputs":[{"internalType":"uint256","name":"actualOutputAmount","type":"uint256"},{"internalType":"uint256","name":"requiredActualOutputAmount","type":"uint256"}],"name":"LowActualOutputAmount","type":"error"},{"inputs":[],"name":"NoneAmountType","type":"error"},{"inputs":[],"name":"NonePermitType","type":"error"},{"inputs":[],"name":"NoneSwapType","type":"error"},{"inputs":[{"internalType":"uint256","name":"timestamp","type":"uint256"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"PassedDeadline","type":"error"},{"inputs":[{"internalType":"bytes32","name":"hash","type":"bytes32"}],"name":"UsedHash","type":"error"},{"inputs":[],"name":"ZeroFeeBeneficiary","type":"error"},{"inputs":[],"name":"ZeroReceiver","type":"error"},{"inputs":[],"name":"ZeroSigner","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"inputToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"absoluteInputAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"inputBalanceChange","type":"uint256"},{"indexed":true,"internalType":"address","name":"outputToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"absoluteOutputAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"returnedAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"protocolFeeAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"marketplaceFeeAmount","type":"uint256"},{"components":[{"internalType":"enum SwapType","name":"swapType","type":"uint8"},{"components":[{"internalType":"uint256","name":"share","type":"uint256"},{"internalType":"address","name":"beneficiary","type":"address"}],"internalType":"struct Fee","name":"protocolFee","type":"tuple"},{"components":[{"internalType":"uint256","name":"share","type":"uint256"},{"internalType":"address","name":"beneficiary","type":"address"}],"internalType":"struct Fee","name":"marketplaceFee","type":"tuple"},{"internalType":"address","name":"account","type":"address"},{"internalType":"address","name":"caller","type":"address"},{"internalType":"bytes","name":"callerCallData","type":"bytes"}],"indexed":false,"internalType":"struct SwapDescription","name":"swapDescription","type":"tuple"},{"indexed":false,"internalType":"address","name":"sender","type":"address"}],"name":"Executed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"oldOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnerSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"oldPendingOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newPendingOwner","type":"address"}],"name":"PendingOwnerSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"oldProtocolFeeDefaultShare","type":"uint256"},{"indexed":true,"internalType":"address","name":"oldProtocolFeeDefaultBeneficiary","type":"address"},{"indexed":false,"internalType":"uint256","name":"newProtocolFeeDefaultShare","type":"uint256"},{"indexed":true,"internalType":"address","name":"newProtocolFeeDefaultBeneficiary","type":"address"}],"name":"ProtocolFeeDefaultSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"oldProtocolFeeSigner","type":"address"},{"indexed":true,"internalType":"address","name":"newProtocolFeeSigner","type":"address"}],"name":"ProtocolFeeSignerSet","type":"event"},{"inputs":[{"components":[{"components":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"enum AmountType","name":"amountType","type":"uint8"}],"internalType":"struct TokenAmount","name":"tokenAmount","type":"tuple"},{"components":[{"internalType":"enum PermitType","name":"permitType","type":"uint8"},{"internalType":"bytes","name":"permitCallData","type":"bytes"}],"internalType":"struct Permit","name":"permit","type":"tuple"}],"internalType":"struct Input","name":"input","type":"tuple"},{"components":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"absoluteAmount","type":"uint256"}],"internalType":"struct AbsoluteTokenAmount","name":"output","type":"tuple"},{"components":[{"internalType":"enum SwapType","name":"swapType","type":"uint8"},{"components":[{"internalType":"uint256","name":"share","type":"uint256"},{"internalType":"address","name":"beneficiary","type":"address"}],"internalType":"struct Fee","name":"protocolFee","type":"tuple"},{"components":[{"internalType":"uint256","name":"share","type":"uint256"},{"internalType":"address","name":"beneficiary","type":"address"}],"internalType":"struct Fee","name":"marketplaceFee","type":"tuple"},{"internalType":"address","name":"account","type":"address"},{"internalType":"address","name":"caller","type":"address"},{"internalType":"bytes","name":"callerCallData","type":"bytes"}],"internalType":"struct SwapDescription","name":"swapDescription","type":"tuple"},{"components":[{"internalType":"uint256","name":"salt","type":"uint256"},{"internalType":"bytes","name":"signature","type":"bytes"}],"internalType":"struct AccountSignature","name":"accountSignature","type":"tuple"}],"name":"cancelAccountSignature","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"components":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"enum AmountType","name":"amountType","type":"uint8"}],"internalType":"struct TokenAmount","name":"tokenAmount","type":"tuple"},{"components":[{"internalType":"enum PermitType","name":"permitType","type":"uint8"},{"internalType":"bytes","name":"permitCallData","type":"bytes"}],"internalType":"struct Permit","name":"permit","type":"tuple"}],"internalType":"struct Input","name":"input","type":"tuple"},{"components":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"absoluteAmount","type":"uint256"}],"internalType":"struct AbsoluteTokenAmount","name":"output","type":"tuple"},{"components":[{"internalType":"enum SwapType","name":"swapType","type":"uint8"},{"components":[{"internalType":"uint256","name":"share","type":"uint256"},{"internalType":"address","name":"beneficiary","type":"address"}],"internalType":"struct Fee","name":"protocolFee","type":"tuple"},{"components":[{"internalType":"uint256","name":"share","type":"uint256"},{"internalType":"address","name":"beneficiary","type":"address"}],"internalType":"struct Fee","name":"marketplaceFee","type":"tuple"},{"internalType":"address","name":"account","type":"address"},{"internalType":"address","name":"caller","type":"address"},{"internalType":"bytes","name":"callerCallData","type":"bytes"}],"internalType":"struct SwapDescription","name":"swapDescription","type":"tuple"},{"components":[{"internalType":"uint256","name":"salt","type":"uint256"},{"internalType":"bytes","name":"signature","type":"bytes"}],"internalType":"struct AccountSignature","name":"accountSignature","type":"tuple"},{"components":[{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"bytes","name":"signature","type":"bytes"}],"internalType":"struct ProtocolFeeSignature","name":"protocolFeeSignature","type":"tuple"}],"name":"execute","outputs":[{"internalType":"uint256","name":"inputBalanceChange","type":"uint256"},{"internalType":"uint256","name":"actualOutputAmount","type":"uint256"},{"internalType":"uint256","name":"protocolFeeAmount","type":"uint256"},{"internalType":"uint256","name":"marketplaceFeeAmount","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"getOwner","outputs":[{"internalType":"address","name":"owner","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getPendingOwner","outputs":[{"internalType":"address","name":"pendingOwner","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getProtocolFeeDefault","outputs":[{"components":[{"internalType":"uint256","name":"share","type":"uint256"},{"internalType":"address","name":"beneficiary","type":"address"}],"internalType":"struct Fee","name":"protocolFeeDefault","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getProtocolFeeSigner","outputs":[{"internalType":"address","name":"protocolFeeSigner","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"components":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"enum AmountType","name":"amountType","type":"uint8"}],"internalType":"struct TokenAmount","name":"tokenAmount","type":"tuple"},{"components":[{"internalType":"enum PermitType","name":"permitType","type":"uint8"},{"internalType":"bytes","name":"permitCallData","type":"bytes"}],"internalType":"struct Permit","name":"permit","type":"tuple"}],"internalType":"struct Input","name":"input","type":"tuple"},{"components":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"absoluteAmount","type":"uint256"}],"internalType":"struct AbsoluteTokenAmount","name":"output","type":"tuple"},{"components":[{"internalType":"enum SwapType","name":"swapType","type":"uint8"},{"components":[{"internalType":"uint256","name":"share","type":"uint256"},{"internalType":"address","name":"beneficiary","type":"address"}],"internalType":"struct Fee","name":"protocolFee","type":"tuple"},{"components":[{"internalType":"uint256","name":"share","type":"uint256"},{"internalType":"address","name":"beneficiary","type":"address"}],"internalType":"struct Fee","name":"marketplaceFee","type":"tuple"},{"internalType":"address","name":"account","type":"address"},{"internalType":"address","name":"caller","type":"address"},{"internalType":"bytes","name":"callerCallData","type":"bytes"}],"internalType":"struct SwapDescription","name":"swapDescription","type":"tuple"},{"internalType":"uint256","name":"salt","type":"uint256"}],"name":"hashAccountSignatureData","outputs":[{"internalType":"bytes32","name":"hashedData","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"components":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"enum AmountType","name":"amountType","type":"uint8"}],"internalType":"struct TokenAmount","name":"tokenAmount","type":"tuple"},{"components":[{"internalType":"enum PermitType","name":"permitType","type":"uint8"},{"internalType":"bytes","name":"permitCallData","type":"bytes"}],"internalType":"struct Permit","name":"permit","type":"tuple"}],"internalType":"struct Input","name":"input","type":"tuple"},{"components":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"absoluteAmount","type":"uint256"}],"internalType":"struct AbsoluteTokenAmount","name":"output","type":"tuple"},{"components":[{"internalType":"enum SwapType","name":"swapType","type":"uint8"},{"components":[{"internalType":"uint256","name":"share","type":"uint256"},{"internalType":"address","name":"beneficiary","type":"address"}],"internalType":"struct Fee","name":"protocolFee","type":"tuple"},{"components":[{"internalType":"uint256","name":"share","type":"uint256"},{"internalType":"address","name":"beneficiary","type":"address"}],"internalType":"struct Fee","name":"marketplaceFee","type":"tuple"},{"internalType":"address","name":"account","type":"address"},{"internalType":"address","name":"caller","type":"address"},{"internalType":"bytes","name":"callerCallData","type":"bytes"}],"internalType":"struct SwapDescription","name":"swapDescription","type":"tuple"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"name":"hashProtocolFeeSignatureData","outputs":[{"internalType":"bytes32","name":"hashedData","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"hashToCheck","type":"bytes32"}],"name":"isHashUsed","outputs":[{"internalType":"bool","name":"hashUsed","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"address payable","name":"beneficiary","type":"address"}],"name":"returnLostTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"setOwner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newPendingOwner","type":"address"}],"name":"setPendingOwner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"share","type":"uint256"},{"internalType":"address","name":"beneficiary","type":"address"}],"internalType":"struct Fee","name":"protocolFeeDefault","type":"tuple"}],"name":"setProtocolFeeDefault","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"signer","type":"address"}],"name":"setProtocolFeeSigner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]

61014060405234801561001157600080fd5b506040518060400160405280600d81526020016c2d32b934b7b7102937baba32b960991b815250604051806040016040528060018152602001600d60fa1b8152508181336001600160a01b031660006001600160a01b03167f342827c97908e5e2f71151c08502a66d44b6f758e3ac2f1de95f02eb95f0a73560405160405180910390a3600180546001600160a01b03191633179055815160208084019190912082518383012060e08290526101008190524660a0818152604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f81880181905281830187905260608201869052608082019490945230818401528151808203909301835260c00190528051940193909320919290916080523060c05261012052505060016006555061014592505050565b60805160a05160c05160e05161010051610120516140d2620001956000396000611eaf01526000611efe01526000611ed901526000611e3201526000611e5c01526000611e8601526140d26000f3fe6080604052600436106100e15760003560e01c8063b297ccfd1161007f578063e1b92a9c11610059578063e1b92a9c146102ef578063e89db6711461031d578063ebfa1a611461033d578063ec5afea71461035d57600080fd5b8063b297ccfd1461028f578063bba185de146102af578063c42069ec146102cf57600080fd5b8063893d20e8116100bb578063893d20e81461017c57806392ff2806146101c857806393596c7b14610244578063b0998bf71461026f57600080fd5b806320021d8b146100ed57806340caae061461013257806383d13e011461014957600080fd5b366100e857005b600080fd5b3480156100f957600080fd5b5061011d610108366004612b92565b60009081526002602052604090205460ff1690565b60405190151581526020015b60405180910390f35b34801561013e57600080fd5b50610147610388565b005b61015c610157366004612be8565b61048b565b604080519485526020850193909352918301526060820152608001610129565b34801561018857600080fd5b5060015473ffffffffffffffffffffffffffffffffffffffff165b60405173ffffffffffffffffffffffffffffffffffffffff9091168152602001610129565b3480156101d457600080fd5b5060408051808201825260008082526020918201528151808301909252600354825260045473ffffffffffffffffffffffffffffffffffffffff1690820152604080518251815260209283015173ffffffffffffffffffffffffffffffffffffffff169281019290925201610129565b34801561025057600080fd5b5060005473ffffffffffffffffffffffffffffffffffffffff166101a3565b34801561027b57600080fd5b5061014761028a366004612ca7565b61053e565b34801561029b57600080fd5b506101476102aa366004612cf0565b610691565b3480156102bb57600080fd5b506101476102ca366004612d0d565b6107a6565b3480156102db57600080fd5b506101476102ea366004612cf0565b6108d4565b3480156102fb57600080fd5b5061030f61030a3660046130f9565b6109e2565b604051908152602001610129565b34801561032957600080fd5b50610147610338366004613176565b610a26565b34801561034957600080fd5b5061030f6103583660046130f9565b610abe565b34801561036957600080fd5b5060055473ffffffffffffffffffffffffffffffffffffffff166101a3565b60005473ffffffffffffffffffffffffffffffffffffffff16331461040e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601560248201527f4f3a206f6e6c792070656e64696e67206f776e6572000000000000000000000060448201526064015b60405180910390fd5b600154604051339173ffffffffffffffffffffffffffffffffffffffff16907f342827c97908e5e2f71151c08502a66d44b6f758e3ac2f1de95f02eb95f0a73590600090a3600180547fffffffffffffffffffffffff00000000000000000000000000000000000000009081163317909155600080549091169055565b600080600080600260065414156104fe576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610405565b600260065561050f89898988610ad5565b61051b89898989610d96565b610526898989610e9b565b6001600655929c919b50995090975095505050505050565b60015473ffffffffffffffffffffffffffffffffffffffff1633146105bf576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600d60248201527f4f3a206f6e6c79206f776e6572000000000000000000000000000000000000006044820152606401610405565b8035158015906105f4575060006105dc6040830160208401612cf0565b73ffffffffffffffffffffffffffffffffffffffff16145b1561062b576040517f6081460800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b670de0b6b3a76400008135111561067f576040517fa47ecae600000000000000000000000000000000000000000000000000000000815281356004820152670de0b6b3a76400006024820152604401610405565b80600361068c82826131af565b505050565b60015473ffffffffffffffffffffffffffffffffffffffff163314610712576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600d60248201527f4f3a206f6e6c79206f776e6572000000000000000000000000000000000000006044820152606401610405565b73ffffffffffffffffffffffffffffffffffffffff811661075f576040517fe5c48ac500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600580547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b60026006541415610813576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610405565b600260065561082860c0830160a08401612cf0565b73ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146108bd573361086b60c0840160a08501612cf0565b6040517f57dfaa7900000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff928316600482015291166024820152604401610405565b6108c984848484610d96565b505060016006555050565b60015473ffffffffffffffffffffffffffffffffffffffff163314610955576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600d60248201527f4f3a206f6e6c79206f776e6572000000000000000000000000000000000000006044820152606401610405565b6000805460405173ffffffffffffffffffffffffffffffffffffffff808516939216917fa86864fa6b65f969d5ac8391ddaac6a0eba3f41386cbf6e78c3e4d6c59eb115f91a3600080547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b6000610a1d610a186040516020016109f990613209565b60405160208183030381529060405280519060200120878787876111b4565b611219565b95945050505050565b60015473ffffffffffffffffffffffffffffffffffffffff163314610aa7576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600d60248201527f4f3a206f6e6c79206f776e6572000000000000000000000000000000000000006044820152606401610405565b610aba8282610ab585611288565b6112b7565b5050565b6000610a1d610a186040516020016109f9906135b7565b6000610b1b60408051808201825260008082526020918201528151808301909252600354825260045473ffffffffffffffffffffffffffffffffffffffff169082015290565b90506000610b31368590038501602086016136f8565b90506000610b426020850185613714565b90501415610c30578151815114610b9257805182516040517fa47ecae600000000000000000000000000000000000000000000000000000000815260048101929092526024820152604401610405565b816020015173ffffffffffffffffffffffffffffffffffffffff16816020015173ffffffffffffffffffffffffffffffffffffffff1614610c2957602080820151908301516040517ff04b92fe00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff928316600482015291166024820152604401610405565b5050610d90565b815181511115610c7957805182516040517f5f83594500000000000000000000000000000000000000000000000000000000815260048101929092526024820152604401610405565b6000610ca6610c8788613779565b610c9636899003890189613785565b610c9f886137a1565b8735610abe565b9050610d12610cca60055473ffffffffffffffffffffffffffffffffffffffff1690565b82610cd86020880188613714565b8080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525061135592505050565b610d48576040517f299600b400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8335421115610d8c576040517fb3c7ab9600000000000000000000000000000000000000000000000000000000815242600482015284356024820152604401610405565b5050505b50505050565b6000610da56020830183613714565b90501415610e0557610dbd60c0830160a08401612cf0565b73ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610e00573361086b60c0840160a08501612cf0565b610d90565b6000610e32610e1386613779565b610e2236879003870187613785565b610e2b866137a1565b85356109e2565b9050610e55610e4760c0850160a08601612cf0565b82610cd86020860186613714565b610e8b576040517f2e40c06e00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610e9481611546565b5050505050565b600080808080610eba88610eb560c0890160a08a01612cf0565b6115cb565b90506000610ecb60208a018a612cf0565b9050610ef48183610edf60608d018d6137ad565b610eef60c08c0160a08d01612cf0565b6118fc565b6000610eff82611288565b90506000610f18610f1360208c018c612cf0565b611288565b9050610f3483610f2e60e08c0160c08d01612cf0565b866112b7565b611011610f4760e08b0160c08c01612cf0565b610f5460e08c018c613714565b604051602401610f65929190613834565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0818403018152918152602080830180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fd9c453570000000000000000000000000000000000000000000000000000000017905281518083019092528082527f523a2063616c6c4279746573206661696c656420772f206e6f20726561736f6e90820152611963565b5061101b83611288565b6110259083613877565b975060008161103a610f1360208e018e612cf0565b6110449190613877565b90508489111561108a576040517f84adf742000000000000000000000000000000000000000000000000000000008152600481018a905260248101869052604401610405565b60006110968a87613877565b90506110b76110a860208d018d61388e565b8c6020018d6060018f8661197a565b919a509850965060208c0135891015611109576040517fc7312ae9000000000000000000000000000000000000000000000000000000008152600481018a905260208d01356024820152604401610405565b6111238561111d60c08e0160a08f01612cf0565b836112b7565b61114961113360208e018e612cf0565b61114360c08e0160a08f01612cf0565b8b6112b7565b61116f61115960208e018e612cf0565b61116960608e0160408f01612cf0565b8a6112b7565b61119561117f60208e018e612cf0565b61118f60a08e0160808f01612cf0565b896112b7565b6111a58d8d8d898e8e8e8e611bf7565b50505050505093509350935093565b6000856111c086611c90565b6111c986611d09565b6111d286611d87565b6040805160208101959095528401929092526060830152608082015260a0810183905260c00160405160208183030381529060405280519060200120905095945050505050565b6000611282611226611e18565b836040517f19010000000000000000000000000000000000000000000000000000000000006020820152602281018390526042810182905260009060620160405160208183030381529060405280519060200120905092915050565b92915050565b600073ffffffffffffffffffffffffffffffffffffffff82166112ad57506000919050565b6112828230611f4c565b806112c157505050565b73ffffffffffffffffffffffffffffffffffffffff821661130e576040517f6ba9ecd800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff831673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee141561134a5761068c828261202e565b61068c838383612188565b6000806000611364858561225c565b9092509050600081600481111561137d5761137d6138ab565b1480156113b557508573ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16145b156113c55760019250505061153f565b6000808773ffffffffffffffffffffffffffffffffffffffff16631626ba7e60e01b88886040516024016113fa929190613950565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529181526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff000000000000000000000000000000000000000000000000000000009094169390931790925290516114839190613969565b600060405180830381855afa9150503d80600081146114be576040519150601f19603f3d011682016040523d82523d6000602084013e6114c3565b606091505b50915091508180156114d6575080516020145b8015611538575080517f1626ba7e0000000000000000000000000000000000000000000000000000000090611514908301602090810190840161397b565b7fffffffff0000000000000000000000000000000000000000000000000000000016145b9450505050505b9392505050565b60008181526002602052604090205460ff1615611592576040517f2371a2c500000000000000000000000000000000000000000000000000000000815260048101829052602401610405565b600090815260026020526040902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00166001179055565b6000806115de606085016040860161388e565b905060006115ef6020860186612cf0565b90506020850135600083600281111561160a5761160a6138ab565b1415611642576040517f9d91e86400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff82161580156116665750600081115b156116a7576040517f50da5b780000000000000000000000000000000000000000000000000000000081526004810182905260006024820152604401610405565b60028360028111156116bb576116bb6138ab565b14156116cb579250611282915050565b73ffffffffffffffffffffffffffffffffffffffff821673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee1480611717575073ffffffffffffffffffffffffffffffffffffffff8216155b15611753578260026040517ffa01e5e20000000000000000000000000000000000000000000000000000000081526004016104059291906139cd565b670de0b6b3a7640000811115611798576040517fab03530300000000000000000000000000000000000000000000000000000000815260048101829052602401610405565b670de0b6b3a7640000811415611842576040517f70a0823100000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff86811660048301528316906370a0823190602401602060405180830381865afa158015611814573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061183891906139f3565b9350505050611282565b6040517f70a0823100000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8681166004830152670de0b6b3a76400009183918516906370a0823190602401602060405180830381865afa1580156118ba573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118de91906139f3565b6118e89190613a0c565b6118f29190613a49565b9695505050505050565b73ffffffffffffffffffffffffffffffffffffffff841661191c57610d90565b73ffffffffffffffffffffffffffffffffffffffff841673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee141561195757610e00836122cc565b610d9084848484612312565b606061197284846000856124b0565b949350505050565b6000808080886002811115611991576119916138ab565b14156119c9576040517f90315abe00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b602085018035906000906119dd9088612cf0565b73ffffffffffffffffffffffffffffffffffffffff161415611a4c578015611a3b576040517f50da5b780000000000000000000000000000000000000000000000000000000081526004810182905260006024820152604401610405565b600080600093509350935050611bec565b84611a6257600080600093509350935050611bec565b6000611a7088358a35613a84565b905080611a8857856000809450945094505050611bec565b670de0b6b3a7640000811115611adb576040517fa47ecae600000000000000000000000000000000000000000000000000000000815260048101829052670de0b6b3a76400006024820152604401610405565b60028a6002811115611aef57611aef6138ab565b14611b33576001611b0882670de0b6b3a7640000613a84565b611b1a670de0b6b3a764000089613a0c565b611b249190613a49565b611b2e9190613a84565b611b39565b86602001355b94506000611b478688613877565b9050611b538683613a0c565b611b65670de0b6b3a764000083613a0c565b1115611bc45780670de0b6b3a7640000611b7f8489613a0c565b611b899190613a49565b6040517f16c7c00700000000000000000000000000000000000000000000000000000000815260048101929092526024820152604401610405565b81611bd08b3583613a0c565b611bda9190613a49565b9450611be68582613877565b93505050505b955095509592505050565b611c046020880188612cf0565b73ffffffffffffffffffffffffffffffffffffffff16611c2760208a018a612cf0565b73ffffffffffffffffffffffffffffffffffffffff167f5b99554095b82fa9d0725a9ff1f1db8bc3e4d461e7d61911c752c349a47b987f87878b602001358888888e33604051611c7e989796959493929190613acf565b60405180910390a35050505050505050565b6000604051602001611ca190613c22565b60405160208183030381529060405280519060200120611cc48360000151612630565b611cd18460200151612679565b60408051602081019490945283019190915260608201526080015b604051602081830303815290604052805190602001209050919050565b6000604051602001611d1a90613c7c565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe081840301815282825280516020918201208551868301519285019190915273ffffffffffffffffffffffffffffffffffffffff16918301919091526060820152608001611cec565b6000604051602001611d9890613cd0565b604051602081830303815290604052805190602001208260000151611dc084602001516126e2565b611dcd85604001516126e2565b856060015186608001518760a00151604051602001611dec9190613969565b60405160208183030381529060405280519060200120604051602001611cec9796959493929190613e54565b60003073ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000000000000000000000000000000000000000000016148015611e7e57507f000000000000000000000000000000000000000000000000000000000000000046145b15611ea857507f000000000000000000000000000000000000000000000000000000000000000090565b50604080517f00000000000000000000000000000000000000000000000000000000000000006020808301919091527f0000000000000000000000000000000000000000000000000000000000000000828401527f000000000000000000000000000000000000000000000000000000000000000060608301524660808301523060a0808401919091528351808403909101815260c0909201909252805191012090565b600073ffffffffffffffffffffffffffffffffffffffff831673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee1415611f9e575073ffffffffffffffffffffffffffffffffffffffff811631611282565b6040517f70a0823100000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff83811660048301528416906370a0823190602401602060405180830381865afa15801561200a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061153f91906139f3565b80471015612098576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f416464726573733a20696e73756666696369656e742062616c616e63650000006044820152606401610405565b60008273ffffffffffffffffffffffffffffffffffffffff168260405160006040518083038185875af1925050503d80600081146120f2576040519150601f19603f3d011682016040523d82523d6000602084013e6120f7565b606091505b505090508061068c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603a60248201527f416464726573733a20756e61626c6520746f2073656e642076616c75652c207260448201527f6563697069656e74206d617920686176652072657665727465640000000000006064820152608401610405565b60405173ffffffffffffffffffffffffffffffffffffffff831660248201526044810182905261068c9084907fa9059cbb00000000000000000000000000000000000000000000000000000000906064015b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff0000000000000000000000000000000000000000000000000000000090931692909217909152612760565b6000808251604114156122935760208301516040840151606085015160001a6122878782858561286c565b945094505050506122c5565b8251604014156122bd57602083015160408401516122b2868383612984565b9350935050506122c5565b506000905060025b9250929050565b8034101561230f576040517f7cb769dc00000000000000000000000000000000000000000000000000000000815234600482015260248101829052604401610405565b50565b6040517fdd62ed3e00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff82811660048301523060248301526000919086169063dd62ed3e90604401602060405180830381865afa158015612388573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123ac91906139f3565b9050838110156124a45760006123c56020850185613714565b90501415612409576040517f2a1b2dd80000000000000000000000000000000000000000000000000000000081526004810182905260248101859052604401610405565b6124a28561242261241d6020870187613eaa565b6129cc565b61242f6020870187613714565b60405160200161244193929190613ec5565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0818403018152828201909152600982527f523a207065726d69740000000000000000000000000000000000000000000000602083015290611963565b505b610e9485833087612ae1565b606082471015612542576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f60448201527f722063616c6c00000000000000000000000000000000000000000000000000006064820152608401610405565b843b6125aa576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610405565b6000808673ffffffffffffffffffffffffffffffffffffffff1685876040516125d39190613969565b60006040518083038185875af1925050503d8060008114612610576040519150601f19603f3d011682016040523d82523d6000602084013e612615565b606091505b5091509150612625828286612b3f565b979650505050505050565b600060405160200161264190613f01565b60405160208183030381529060405280519060200120826000015183602001518460400151604051602001611cec9493929190613f55565b600060405160200161268a90613f97565b60405160208183030381529060405280519060200120826000015183602001516040516020016126ba9190613969565b60405160208183030381529060405280519060200120604051602001611cec93929190613feb565b60006040516020016126f390614013565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181528282528051602091820120855186830151928501919091529183019190915273ffffffffffffffffffffffffffffffffffffffff166060820152608001611cec565b60006127c2826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c65648152508573ffffffffffffffffffffffffffffffffffffffff166119639092919063ffffffff16565b80519091501561068c57808060200190518101906127e09190614067565b61068c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f742073756363656564000000000000000000000000000000000000000000006064820152608401610405565b6000807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a08311156128a3575060009050600361297b565b8460ff16601b141580156128bb57508460ff16601c14155b156128cc575060009050600461297b565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa158015612920573d6000803e3d6000fd5b50506040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0015191505073ffffffffffffffffffffffffffffffffffffffff81166129745760006001925092505061297b565b9150600090505b94509492505050565b6000807f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff831660ff84901c601b016129be8782888561286c565b935093505050935093915050565b6000808260038111156129e1576129e16138ab565b1415612a19576040517f82e9999200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001826003811115612a2d57612a2d6138ab565b1415612a5a57507fd505accf00000000000000000000000000000000000000000000000000000000919050565b6002826003811115612a6e57612a6e6138ab565b1415612a9b57507f8fcbaf0c00000000000000000000000000000000000000000000000000000000919050565b6003826003811115612aaf57612aaf6138ab565b1415612adc57507f9fd5a6cf00000000000000000000000000000000000000000000000000000000919050565b919050565b60405173ffffffffffffffffffffffffffffffffffffffff80851660248301528316604482015260648101829052610d909085907f23b872dd00000000000000000000000000000000000000000000000000000000906084016121da565b60608315612b4e57508161153f565b825115612b5e5782518084602001fd5b816040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016104059190614089565b600060208284031215612ba457600080fd5b5035919050565b600060808284031215612bbd57600080fd5b50919050565b600060408284031215612bbd57600080fd5b60006101008284031215612bbd57600080fd5b600080600080600060c08688031215612c0057600080fd5b853567ffffffffffffffff80821115612c1857600080fd5b612c2489838a01612bab565b9650612c338960208a01612bc3565b95506060880135915080821115612c4957600080fd5b612c5589838a01612bd5565b94506080880135915080821115612c6b57600080fd5b612c7789838a01612bc3565b935060a0880135915080821115612c8d57600080fd5b50612c9a88828901612bc3565b9150509295509295909350565b600060408284031215612cb957600080fd5b61153f8383612bc3565b73ffffffffffffffffffffffffffffffffffffffff8116811461230f57600080fd5b8035612adc81612cc3565b600060208284031215612d0257600080fd5b813561153f81612cc3565b60008060008060a08587031215612d2357600080fd5b843567ffffffffffffffff80821115612d3b57600080fd5b612d4788838901612bab565b9550612d568860208901612bc3565b94506060870135915080821115612d6c57600080fd5b612d7888838901612bd5565b93506080870135915080821115612d8e57600080fd5b50612d9b87828801612bc3565b91505092959194509250565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6040805190810167ffffffffffffffff81118282101715612df957612df9612da7565b60405290565b6040516060810167ffffffffffffffff81118282101715612df957612df9612da7565b6003811061230f57600080fd5b803560048110612adc57600080fd5b600082601f830112612e4f57600080fd5b813567ffffffffffffffff80821115612e6a57612e6a612da7565b604051601f83017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0908116603f01168101908282118183101715612eb057612eb0612da7565b81604052838152866020858801011115612ec957600080fd5b836020870160208301376000602085830101528094505050505092915050565b60008183036080811215612efc57600080fd5b612f04612dd6565b91506060811215612f1457600080fd5b50612f1d612dff565b8235612f2881612cc3565b8152602083810135908201526040830135612f4281612e22565b60408201528152606082013567ffffffffffffffff80821115612f6457600080fd5b9083019060408286031215612f7857600080fd5b612f80612dd6565b612f8983612e2f565b8152602083013582811115612f9d57600080fd5b612fa987828601612e3e565b60208301525080602085015250505092915050565b600060408284031215612fd057600080fd5b612fd8612dd6565b90508135612fe581612cc3565b808252506020820135602082015292915050565b60006040828403121561300b57600080fd5b613013612dd6565b905081358152602082013561302781612cc3565b602082015292915050565b6000610100828403121561304557600080fd5b60405160c0810167ffffffffffffffff828210818311171561306957613069612da7565b816040528293508435915061307d82612e22565b81835261308d8660208701612ff9565b602084015261309f8660608701612ff9565b604084015260a085013591506130b482612cc3565b8160608401526130c660c08601612ce5565b608084015260e08501359150808211156130df57600080fd5b506130ec85828601612e3e565b60a0830152505092915050565b60008060008060a0858703121561310f57600080fd5b843567ffffffffffffffff8082111561312757600080fd5b61313388838901612ee9565b95506131428860208901612fbe565b9450606087013591508082111561315857600080fd5b5061316587828801613032565b949793965093946080013593505050565b6000806040838503121561318957600080fd5b823561319481612cc3565b915060208301356131a481612cc3565b809150509250929050565b813581556001810160208301356131c581612cc3565b73ffffffffffffffffffffffffffffffffffffffff81167fffffffffffffffffffffffff000000000000000000000000000000000000000083541617825550505050565b7f4163636f756e745369676e61747572652800000000000000000000000000000081527f496e70757420696e7075742c000000000000000000000000000000000000000060118201527f4162736f6c757465546f6b656e416d6f756e74206f75747075742c0000000000601d8201527f537761704465736372697074696f6e20737761704465736372697074696f6e2c60388201527f75696e743235362073616c74000000000000000000000000000000000000000060588201527f290000000000000000000000000000000000000000000000000000000000000060648201527f4162736f6c757465546f6b656e416d6f756e74286164647265737320746f6b6560658201527f6e2c75696e74323536206162736f6c757465416d6f756e742900000000000000608582015260006134336133e4613395609e85015b7f4665652875696e743235362073686172652c616464726573732062656e65666981527f6369617279290000000000000000000000000000000000000000000000000000602082015260260190565b7f496e70757428546f6b656e416d6f756e7420746f6b656e416d6f756e742c506581527f726d6974207065726d69742900000000000000000000000000000000000000006020820152602c0190565b7f5065726d69742875696e7438207065726d6974547970652c627974657320706581527f726d697443616c6c4461746129000000000000000000000000000000000000006020820152602d0190565b7f537761704465736372697074696f6e280000000000000000000000000000000081527f75696e74382073776170547970652c000000000000000000000000000000000060108201527f4665652070726f746f636f6c4665652c00000000000000000000000000000000601f8201527f466565206d61726b6574706c6163654665652c00000000000000000000000000602f8201527f61646472657373206163636f756e742c0000000000000000000000000000000060428201527f616464726573732063616c6c65722c000000000000000000000000000000000060528201527f62797465732063616c6c657243616c6c4461746100000000000000000000000060618201527f2900000000000000000000000000000000000000000000000000000000000000607582015261153f607682015b7f546f6b656e416d6f756e74286164647265737320746f6b656e2c75696e74323581527f3620616d6f756e742c75696e743820616d6f756e7454797065290000000000006020820152603a0190565b7f50726f746f636f6c4665655369676e617475726528000000000000000000000081527f496e70757420696e7075742c000000000000000000000000000000000000000060158201527f4162736f6c757465546f6b656e416d6f756e74206f75747075742c000000000060218201527f537761704465736372697074696f6e20737761704465736372697074696f6e2c603c8201527f75696e7432353620646561646c696e6500000000000000000000000000000000605c8201527f2900000000000000000000000000000000000000000000000000000000000000606c8201527f4162736f6c757465546f6b656e416d6f756e74286164647265737320746f6b65606d8201527f6e2c75696e74323536206162736f6c757465416d6f756e742900000000000000608d82015260006134336133e461339560a68501613346565b60006040828403121561370a57600080fd5b61153f8383612ff9565b60008083357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe184360301811261374957600080fd5b83018035915067ffffffffffffffff82111561376457600080fd5b6020019150368190038213156122c557600080fd5b60006112823683612ee9565b60006040828403121561379757600080fd5b61153f8383612fbe565b60006112823683613032565b600082357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc18336030181126137e157600080fd5b9190910192915050565b8183528181602085013750600060208284010152600060207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f840116840101905092915050565b6020815260006119726020830184866137eb565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b60008282101561388957613889613848565b500390565b6000602082840312156138a057600080fd5b813561153f81612e22565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b60005b838110156138f55781810151838201526020016138dd565b83811115610d905750506000910152565b6000815180845261391e8160208601602086016138da565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169290920160200192915050565b8281526040602082015260006119726040830184613906565b600082516137e18184602087016138da565b60006020828403121561398d57600080fd5b81517fffffffff000000000000000000000000000000000000000000000000000000008116811461153f57600080fd5b6003811061230f5761230f6138ab565b604081016139da846139bd565b8382526139e6836139bd565b8260208301529392505050565b600060208284031215613a0557600080fd5b5051919050565b6000817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0483118215151615613a4457613a44613848565b500290565b600082613a7f577f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b500490565b60008219821115613a9757613a97613848565b500190565b803582526020810135613aae81612cc3565b73ffffffffffffffffffffffffffffffffffffffff81166020840152505050565b60006101008a83528960208401528860408401528760608401528660808401528560a08401528060c08401528435613b0681612e22565b613b0f816139bd565b83820152613b24610120840160208701613a9c565b613b35610160840160608701613a9c565b60a0850135613b4381612cc3565b73ffffffffffffffffffffffffffffffffffffffff9081166101a085015260c086013590613b7082612cc3565b166101c084015260e0850135368690037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe1018112613bad57600080fd5b8501803567ffffffffffffffff811115613bc657600080fd5b803603871315613bd557600080fd5b826101e0860152613bee610200860182602085016137eb565b9350505050613c1560e083018473ffffffffffffffffffffffffffffffffffffffff169052565b9998505050505050505050565b7f496e70757428546f6b656e416d6f756e7420746f6b656e416d6f756e742c506581527f726d6974207065726d697429000000000000000000000000000000000000000060208201526000611282613568602c84016133e4565b7f4162736f6c757465546f6b656e416d6f756e74286164647265737320746f6b6581527f6e2c75696e74323536206162736f6c757465416d6f756e7429000000000000006020820152600060398201611282565b7f537761704465736372697074696f6e280000000000000000000000000000000081527f75696e74382073776170547970652c000000000000000000000000000000000060108201527f4665652070726f746f636f6c4665652c00000000000000000000000000000000601f8201527f466565206d61726b6574706c6163654665652c00000000000000000000000000602f8201527f61646472657373206163636f756e742c0000000000000000000000000000000060428201527f616464726573732063616c6c65722c000000000000000000000000000000000060528201527f62797465732063616c6c657243616c6c4461746100000000000000000000000060618201527f290000000000000000000000000000000000000000000000000000000000000060758201527f4665652875696e743235362073686172652c616464726573732062656e65666960768201527f636961727929000000000000000000000000000000000000000000000000000060968201526000609c8201611282565b87815260e08101613e64886139bd565b60208201979097526040810195909552606085019390935273ffffffffffffffffffffffffffffffffffffffff91821660808501521660a083015260c090910152919050565b600060208284031215613ebc57600080fd5b61153f82612e2f565b7fffffffff0000000000000000000000000000000000000000000000000000000084168152818360048301376000910160040190815292915050565b7f546f6b656e416d6f756e74286164647265737320746f6b656e2c75696e74323581527f3620616d6f756e742c75696e743820616d6f756e74547970652900000000000060208201526000603a8201611282565b84815273ffffffffffffffffffffffffffffffffffffffff841660208201526040810183905260808101613f88836139bd565b82606083015295945050505050565b7f5065726d69742875696e7438207065726d6974547970652c627974657320706581527f726d697443616c6c44617461290000000000000000000000000000000000000060208201526000602d8201611282565b8381526060810160048410614002576140026138ab565b602082019390935260400152919050565b7f4665652875696e743235362073686172652c616464726573732062656e65666981527f63696172792900000000000000000000000000000000000000000000000000006020820152600060268201611282565b60006020828403121561407957600080fd5b8151801515811461153f57600080fd5b60208152600061153f602083018461390656fea2646970667358221220b74cb04769364aee7c859b8208b8f05afd3fb55d66c99fd13ffa97eb86d7034f64736f6c634300080c0033

Deployed Bytecode

0x6080604052600436106100e15760003560e01c8063b297ccfd1161007f578063e1b92a9c11610059578063e1b92a9c146102ef578063e89db6711461031d578063ebfa1a611461033d578063ec5afea71461035d57600080fd5b8063b297ccfd1461028f578063bba185de146102af578063c42069ec146102cf57600080fd5b8063893d20e8116100bb578063893d20e81461017c57806392ff2806146101c857806393596c7b14610244578063b0998bf71461026f57600080fd5b806320021d8b146100ed57806340caae061461013257806383d13e011461014957600080fd5b366100e857005b600080fd5b3480156100f957600080fd5b5061011d610108366004612b92565b60009081526002602052604090205460ff1690565b60405190151581526020015b60405180910390f35b34801561013e57600080fd5b50610147610388565b005b61015c610157366004612be8565b61048b565b604080519485526020850193909352918301526060820152608001610129565b34801561018857600080fd5b5060015473ffffffffffffffffffffffffffffffffffffffff165b60405173ffffffffffffffffffffffffffffffffffffffff9091168152602001610129565b3480156101d457600080fd5b5060408051808201825260008082526020918201528151808301909252600354825260045473ffffffffffffffffffffffffffffffffffffffff1690820152604080518251815260209283015173ffffffffffffffffffffffffffffffffffffffff169281019290925201610129565b34801561025057600080fd5b5060005473ffffffffffffffffffffffffffffffffffffffff166101a3565b34801561027b57600080fd5b5061014761028a366004612ca7565b61053e565b34801561029b57600080fd5b506101476102aa366004612cf0565b610691565b3480156102bb57600080fd5b506101476102ca366004612d0d565b6107a6565b3480156102db57600080fd5b506101476102ea366004612cf0565b6108d4565b3480156102fb57600080fd5b5061030f61030a3660046130f9565b6109e2565b604051908152602001610129565b34801561032957600080fd5b50610147610338366004613176565b610a26565b34801561034957600080fd5b5061030f6103583660046130f9565b610abe565b34801561036957600080fd5b5060055473ffffffffffffffffffffffffffffffffffffffff166101a3565b60005473ffffffffffffffffffffffffffffffffffffffff16331461040e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601560248201527f4f3a206f6e6c792070656e64696e67206f776e6572000000000000000000000060448201526064015b60405180910390fd5b600154604051339173ffffffffffffffffffffffffffffffffffffffff16907f342827c97908e5e2f71151c08502a66d44b6f758e3ac2f1de95f02eb95f0a73590600090a3600180547fffffffffffffffffffffffff00000000000000000000000000000000000000009081163317909155600080549091169055565b600080600080600260065414156104fe576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610405565b600260065561050f89898988610ad5565b61051b89898989610d96565b610526898989610e9b565b6001600655929c919b50995090975095505050505050565b60015473ffffffffffffffffffffffffffffffffffffffff1633146105bf576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600d60248201527f4f3a206f6e6c79206f776e6572000000000000000000000000000000000000006044820152606401610405565b8035158015906105f4575060006105dc6040830160208401612cf0565b73ffffffffffffffffffffffffffffffffffffffff16145b1561062b576040517f6081460800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b670de0b6b3a76400008135111561067f576040517fa47ecae600000000000000000000000000000000000000000000000000000000815281356004820152670de0b6b3a76400006024820152604401610405565b80600361068c82826131af565b505050565b60015473ffffffffffffffffffffffffffffffffffffffff163314610712576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600d60248201527f4f3a206f6e6c79206f776e6572000000000000000000000000000000000000006044820152606401610405565b73ffffffffffffffffffffffffffffffffffffffff811661075f576040517fe5c48ac500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600580547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b60026006541415610813576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610405565b600260065561082860c0830160a08401612cf0565b73ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146108bd573361086b60c0840160a08501612cf0565b6040517f57dfaa7900000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff928316600482015291166024820152604401610405565b6108c984848484610d96565b505060016006555050565b60015473ffffffffffffffffffffffffffffffffffffffff163314610955576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600d60248201527f4f3a206f6e6c79206f776e6572000000000000000000000000000000000000006044820152606401610405565b6000805460405173ffffffffffffffffffffffffffffffffffffffff808516939216917fa86864fa6b65f969d5ac8391ddaac6a0eba3f41386cbf6e78c3e4d6c59eb115f91a3600080547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b6000610a1d610a186040516020016109f990613209565b60405160208183030381529060405280519060200120878787876111b4565b611219565b95945050505050565b60015473ffffffffffffffffffffffffffffffffffffffff163314610aa7576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152600d60248201527f4f3a206f6e6c79206f776e6572000000000000000000000000000000000000006044820152606401610405565b610aba8282610ab585611288565b6112b7565b5050565b6000610a1d610a186040516020016109f9906135b7565b6000610b1b60408051808201825260008082526020918201528151808301909252600354825260045473ffffffffffffffffffffffffffffffffffffffff169082015290565b90506000610b31368590038501602086016136f8565b90506000610b426020850185613714565b90501415610c30578151815114610b9257805182516040517fa47ecae600000000000000000000000000000000000000000000000000000000815260048101929092526024820152604401610405565b816020015173ffffffffffffffffffffffffffffffffffffffff16816020015173ffffffffffffffffffffffffffffffffffffffff1614610c2957602080820151908301516040517ff04b92fe00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff928316600482015291166024820152604401610405565b5050610d90565b815181511115610c7957805182516040517f5f83594500000000000000000000000000000000000000000000000000000000815260048101929092526024820152604401610405565b6000610ca6610c8788613779565b610c9636899003890189613785565b610c9f886137a1565b8735610abe565b9050610d12610cca60055473ffffffffffffffffffffffffffffffffffffffff1690565b82610cd86020880188613714565b8080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525061135592505050565b610d48576040517f299600b400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8335421115610d8c576040517fb3c7ab9600000000000000000000000000000000000000000000000000000000815242600482015284356024820152604401610405565b5050505b50505050565b6000610da56020830183613714565b90501415610e0557610dbd60c0830160a08401612cf0565b73ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610e00573361086b60c0840160a08501612cf0565b610d90565b6000610e32610e1386613779565b610e2236879003870187613785565b610e2b866137a1565b85356109e2565b9050610e55610e4760c0850160a08601612cf0565b82610cd86020860186613714565b610e8b576040517f2e40c06e00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610e9481611546565b5050505050565b600080808080610eba88610eb560c0890160a08a01612cf0565b6115cb565b90506000610ecb60208a018a612cf0565b9050610ef48183610edf60608d018d6137ad565b610eef60c08c0160a08d01612cf0565b6118fc565b6000610eff82611288565b90506000610f18610f1360208c018c612cf0565b611288565b9050610f3483610f2e60e08c0160c08d01612cf0565b866112b7565b611011610f4760e08b0160c08c01612cf0565b610f5460e08c018c613714565b604051602401610f65929190613834565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0818403018152918152602080830180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fd9c453570000000000000000000000000000000000000000000000000000000017905281518083019092528082527f523a2063616c6c4279746573206661696c656420772f206e6f20726561736f6e90820152611963565b5061101b83611288565b6110259083613877565b975060008161103a610f1360208e018e612cf0565b6110449190613877565b90508489111561108a576040517f84adf742000000000000000000000000000000000000000000000000000000008152600481018a905260248101869052604401610405565b60006110968a87613877565b90506110b76110a860208d018d61388e565b8c6020018d6060018f8661197a565b919a509850965060208c0135891015611109576040517fc7312ae9000000000000000000000000000000000000000000000000000000008152600481018a905260208d01356024820152604401610405565b6111238561111d60c08e0160a08f01612cf0565b836112b7565b61114961113360208e018e612cf0565b61114360c08e0160a08f01612cf0565b8b6112b7565b61116f61115960208e018e612cf0565b61116960608e0160408f01612cf0565b8a6112b7565b61119561117f60208e018e612cf0565b61118f60a08e0160808f01612cf0565b896112b7565b6111a58d8d8d898e8e8e8e611bf7565b50505050505093509350935093565b6000856111c086611c90565b6111c986611d09565b6111d286611d87565b6040805160208101959095528401929092526060830152608082015260a0810183905260c00160405160208183030381529060405280519060200120905095945050505050565b6000611282611226611e18565b836040517f19010000000000000000000000000000000000000000000000000000000000006020820152602281018390526042810182905260009060620160405160208183030381529060405280519060200120905092915050565b92915050565b600073ffffffffffffffffffffffffffffffffffffffff82166112ad57506000919050565b6112828230611f4c565b806112c157505050565b73ffffffffffffffffffffffffffffffffffffffff821661130e576040517f6ba9ecd800000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff831673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee141561134a5761068c828261202e565b61068c838383612188565b6000806000611364858561225c565b9092509050600081600481111561137d5761137d6138ab565b1480156113b557508573ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16145b156113c55760019250505061153f565b6000808773ffffffffffffffffffffffffffffffffffffffff16631626ba7e60e01b88886040516024016113fa929190613950565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529181526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff000000000000000000000000000000000000000000000000000000009094169390931790925290516114839190613969565b600060405180830381855afa9150503d80600081146114be576040519150601f19603f3d011682016040523d82523d6000602084013e6114c3565b606091505b50915091508180156114d6575080516020145b8015611538575080517f1626ba7e0000000000000000000000000000000000000000000000000000000090611514908301602090810190840161397b565b7fffffffff0000000000000000000000000000000000000000000000000000000016145b9450505050505b9392505050565b60008181526002602052604090205460ff1615611592576040517f2371a2c500000000000000000000000000000000000000000000000000000000815260048101829052602401610405565b600090815260026020526040902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00166001179055565b6000806115de606085016040860161388e565b905060006115ef6020860186612cf0565b90506020850135600083600281111561160a5761160a6138ab565b1415611642576040517f9d91e86400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff82161580156116665750600081115b156116a7576040517f50da5b780000000000000000000000000000000000000000000000000000000081526004810182905260006024820152604401610405565b60028360028111156116bb576116bb6138ab565b14156116cb579250611282915050565b73ffffffffffffffffffffffffffffffffffffffff821673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee1480611717575073ffffffffffffffffffffffffffffffffffffffff8216155b15611753578260026040517ffa01e5e20000000000000000000000000000000000000000000000000000000081526004016104059291906139cd565b670de0b6b3a7640000811115611798576040517fab03530300000000000000000000000000000000000000000000000000000000815260048101829052602401610405565b670de0b6b3a7640000811415611842576040517f70a0823100000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff86811660048301528316906370a0823190602401602060405180830381865afa158015611814573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061183891906139f3565b9350505050611282565b6040517f70a0823100000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8681166004830152670de0b6b3a76400009183918516906370a0823190602401602060405180830381865afa1580156118ba573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118de91906139f3565b6118e89190613a0c565b6118f29190613a49565b9695505050505050565b73ffffffffffffffffffffffffffffffffffffffff841661191c57610d90565b73ffffffffffffffffffffffffffffffffffffffff841673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee141561195757610e00836122cc565b610d9084848484612312565b606061197284846000856124b0565b949350505050565b6000808080886002811115611991576119916138ab565b14156119c9576040517f90315abe00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b602085018035906000906119dd9088612cf0565b73ffffffffffffffffffffffffffffffffffffffff161415611a4c578015611a3b576040517f50da5b780000000000000000000000000000000000000000000000000000000081526004810182905260006024820152604401610405565b600080600093509350935050611bec565b84611a6257600080600093509350935050611bec565b6000611a7088358a35613a84565b905080611a8857856000809450945094505050611bec565b670de0b6b3a7640000811115611adb576040517fa47ecae600000000000000000000000000000000000000000000000000000000815260048101829052670de0b6b3a76400006024820152604401610405565b60028a6002811115611aef57611aef6138ab565b14611b33576001611b0882670de0b6b3a7640000613a84565b611b1a670de0b6b3a764000089613a0c565b611b249190613a49565b611b2e9190613a84565b611b39565b86602001355b94506000611b478688613877565b9050611b538683613a0c565b611b65670de0b6b3a764000083613a0c565b1115611bc45780670de0b6b3a7640000611b7f8489613a0c565b611b899190613a49565b6040517f16c7c00700000000000000000000000000000000000000000000000000000000815260048101929092526024820152604401610405565b81611bd08b3583613a0c565b611bda9190613a49565b9450611be68582613877565b93505050505b955095509592505050565b611c046020880188612cf0565b73ffffffffffffffffffffffffffffffffffffffff16611c2760208a018a612cf0565b73ffffffffffffffffffffffffffffffffffffffff167f5b99554095b82fa9d0725a9ff1f1db8bc3e4d461e7d61911c752c349a47b987f87878b602001358888888e33604051611c7e989796959493929190613acf565b60405180910390a35050505050505050565b6000604051602001611ca190613c22565b60405160208183030381529060405280519060200120611cc48360000151612630565b611cd18460200151612679565b60408051602081019490945283019190915260608201526080015b604051602081830303815290604052805190602001209050919050565b6000604051602001611d1a90613c7c565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe081840301815282825280516020918201208551868301519285019190915273ffffffffffffffffffffffffffffffffffffffff16918301919091526060820152608001611cec565b6000604051602001611d9890613cd0565b604051602081830303815290604052805190602001208260000151611dc084602001516126e2565b611dcd85604001516126e2565b856060015186608001518760a00151604051602001611dec9190613969565b60405160208183030381529060405280519060200120604051602001611cec9796959493929190613e54565b60003073ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000d7f1dd5d49206349cae8b585fcb0ce3d96f1696f16148015611e7e57507f00000000000000000000000000000000000000000000000000000000000000fa46145b15611ea857507f334a9fe9e9d10c35c24878e4eb30ccbf361ebb8d12c0708cd0ad3b9ff5b83b1690565b50604080517f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f6020808301919091527fcfd5f08c473f5b1869b29dde054cbf75e7e9d36bc094ab6161ba031b900d93be828401527f13600b294191fc92924bb3ce4b969c1e7e2bab8f4c93c3fc6d0a51733df3c06060608301524660808301523060a0808401919091528351808403909101815260c0909201909252805191012090565b600073ffffffffffffffffffffffffffffffffffffffff831673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee1415611f9e575073ffffffffffffffffffffffffffffffffffffffff811631611282565b6040517f70a0823100000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff83811660048301528416906370a0823190602401602060405180830381865afa15801561200a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061153f91906139f3565b80471015612098576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f416464726573733a20696e73756666696369656e742062616c616e63650000006044820152606401610405565b60008273ffffffffffffffffffffffffffffffffffffffff168260405160006040518083038185875af1925050503d80600081146120f2576040519150601f19603f3d011682016040523d82523d6000602084013e6120f7565b606091505b505090508061068c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603a60248201527f416464726573733a20756e61626c6520746f2073656e642076616c75652c207260448201527f6563697069656e74206d617920686176652072657665727465640000000000006064820152608401610405565b60405173ffffffffffffffffffffffffffffffffffffffff831660248201526044810182905261068c9084907fa9059cbb00000000000000000000000000000000000000000000000000000000906064015b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff0000000000000000000000000000000000000000000000000000000090931692909217909152612760565b6000808251604114156122935760208301516040840151606085015160001a6122878782858561286c565b945094505050506122c5565b8251604014156122bd57602083015160408401516122b2868383612984565b9350935050506122c5565b506000905060025b9250929050565b8034101561230f576040517f7cb769dc00000000000000000000000000000000000000000000000000000000815234600482015260248101829052604401610405565b50565b6040517fdd62ed3e00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff82811660048301523060248301526000919086169063dd62ed3e90604401602060405180830381865afa158015612388573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906123ac91906139f3565b9050838110156124a45760006123c56020850185613714565b90501415612409576040517f2a1b2dd80000000000000000000000000000000000000000000000000000000081526004810182905260248101859052604401610405565b6124a28561242261241d6020870187613eaa565b6129cc565b61242f6020870187613714565b60405160200161244193929190613ec5565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0818403018152828201909152600982527f523a207065726d69740000000000000000000000000000000000000000000000602083015290611963565b505b610e9485833087612ae1565b606082471015612542576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f60448201527f722063616c6c00000000000000000000000000000000000000000000000000006064820152608401610405565b843b6125aa576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610405565b6000808673ffffffffffffffffffffffffffffffffffffffff1685876040516125d39190613969565b60006040518083038185875af1925050503d8060008114612610576040519150601f19603f3d011682016040523d82523d6000602084013e612615565b606091505b5091509150612625828286612b3f565b979650505050505050565b600060405160200161264190613f01565b60405160208183030381529060405280519060200120826000015183602001518460400151604051602001611cec9493929190613f55565b600060405160200161268a90613f97565b60405160208183030381529060405280519060200120826000015183602001516040516020016126ba9190613969565b60405160208183030381529060405280519060200120604051602001611cec93929190613feb565b60006040516020016126f390614013565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181528282528051602091820120855186830151928501919091529183019190915273ffffffffffffffffffffffffffffffffffffffff166060820152608001611cec565b60006127c2826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c65648152508573ffffffffffffffffffffffffffffffffffffffff166119639092919063ffffffff16565b80519091501561068c57808060200190518101906127e09190614067565b61068c576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f742073756363656564000000000000000000000000000000000000000000006064820152608401610405565b6000807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a08311156128a3575060009050600361297b565b8460ff16601b141580156128bb57508460ff16601c14155b156128cc575060009050600461297b565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa158015612920573d6000803e3d6000fd5b50506040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0015191505073ffffffffffffffffffffffffffffffffffffffff81166129745760006001925092505061297b565b9150600090505b94509492505050565b6000807f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff831660ff84901c601b016129be8782888561286c565b935093505050935093915050565b6000808260038111156129e1576129e16138ab565b1415612a19576040517f82e9999200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001826003811115612a2d57612a2d6138ab565b1415612a5a57507fd505accf00000000000000000000000000000000000000000000000000000000919050565b6002826003811115612a6e57612a6e6138ab565b1415612a9b57507f8fcbaf0c00000000000000000000000000000000000000000000000000000000919050565b6003826003811115612aaf57612aaf6138ab565b1415612adc57507f9fd5a6cf00000000000000000000000000000000000000000000000000000000919050565b919050565b60405173ffffffffffffffffffffffffffffffffffffffff80851660248301528316604482015260648101829052610d909085907f23b872dd00000000000000000000000000000000000000000000000000000000906084016121da565b60608315612b4e57508161153f565b825115612b5e5782518084602001fd5b816040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016104059190614089565b600060208284031215612ba457600080fd5b5035919050565b600060808284031215612bbd57600080fd5b50919050565b600060408284031215612bbd57600080fd5b60006101008284031215612bbd57600080fd5b600080600080600060c08688031215612c0057600080fd5b853567ffffffffffffffff80821115612c1857600080fd5b612c2489838a01612bab565b9650612c338960208a01612bc3565b95506060880135915080821115612c4957600080fd5b612c5589838a01612bd5565b94506080880135915080821115612c6b57600080fd5b612c7789838a01612bc3565b935060a0880135915080821115612c8d57600080fd5b50612c9a88828901612bc3565b9150509295509295909350565b600060408284031215612cb957600080fd5b61153f8383612bc3565b73ffffffffffffffffffffffffffffffffffffffff8116811461230f57600080fd5b8035612adc81612cc3565b600060208284031215612d0257600080fd5b813561153f81612cc3565b60008060008060a08587031215612d2357600080fd5b843567ffffffffffffffff80821115612d3b57600080fd5b612d4788838901612bab565b9550612d568860208901612bc3565b94506060870135915080821115612d6c57600080fd5b612d7888838901612bd5565b93506080870135915080821115612d8e57600080fd5b50612d9b87828801612bc3565b91505092959194509250565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6040805190810167ffffffffffffffff81118282101715612df957612df9612da7565b60405290565b6040516060810167ffffffffffffffff81118282101715612df957612df9612da7565b6003811061230f57600080fd5b803560048110612adc57600080fd5b600082601f830112612e4f57600080fd5b813567ffffffffffffffff80821115612e6a57612e6a612da7565b604051601f83017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0908116603f01168101908282118183101715612eb057612eb0612da7565b81604052838152866020858801011115612ec957600080fd5b836020870160208301376000602085830101528094505050505092915050565b60008183036080811215612efc57600080fd5b612f04612dd6565b91506060811215612f1457600080fd5b50612f1d612dff565b8235612f2881612cc3565b8152602083810135908201526040830135612f4281612e22565b60408201528152606082013567ffffffffffffffff80821115612f6457600080fd5b9083019060408286031215612f7857600080fd5b612f80612dd6565b612f8983612e2f565b8152602083013582811115612f9d57600080fd5b612fa987828601612e3e565b60208301525080602085015250505092915050565b600060408284031215612fd057600080fd5b612fd8612dd6565b90508135612fe581612cc3565b808252506020820135602082015292915050565b60006040828403121561300b57600080fd5b613013612dd6565b905081358152602082013561302781612cc3565b602082015292915050565b6000610100828403121561304557600080fd5b60405160c0810167ffffffffffffffff828210818311171561306957613069612da7565b816040528293508435915061307d82612e22565b81835261308d8660208701612ff9565b602084015261309f8660608701612ff9565b604084015260a085013591506130b482612cc3565b8160608401526130c660c08601612ce5565b608084015260e08501359150808211156130df57600080fd5b506130ec85828601612e3e565b60a0830152505092915050565b60008060008060a0858703121561310f57600080fd5b843567ffffffffffffffff8082111561312757600080fd5b61313388838901612ee9565b95506131428860208901612fbe565b9450606087013591508082111561315857600080fd5b5061316587828801613032565b949793965093946080013593505050565b6000806040838503121561318957600080fd5b823561319481612cc3565b915060208301356131a481612cc3565b809150509250929050565b813581556001810160208301356131c581612cc3565b73ffffffffffffffffffffffffffffffffffffffff81167fffffffffffffffffffffffff000000000000000000000000000000000000000083541617825550505050565b7f4163636f756e745369676e61747572652800000000000000000000000000000081527f496e70757420696e7075742c000000000000000000000000000000000000000060118201527f4162736f6c757465546f6b656e416d6f756e74206f75747075742c0000000000601d8201527f537761704465736372697074696f6e20737761704465736372697074696f6e2c60388201527f75696e743235362073616c74000000000000000000000000000000000000000060588201527f290000000000000000000000000000000000000000000000000000000000000060648201527f4162736f6c757465546f6b656e416d6f756e74286164647265737320746f6b6560658201527f6e2c75696e74323536206162736f6c757465416d6f756e742900000000000000608582015260006134336133e4613395609e85015b7f4665652875696e743235362073686172652c616464726573732062656e65666981527f6369617279290000000000000000000000000000000000000000000000000000602082015260260190565b7f496e70757428546f6b656e416d6f756e7420746f6b656e416d6f756e742c506581527f726d6974207065726d69742900000000000000000000000000000000000000006020820152602c0190565b7f5065726d69742875696e7438207065726d6974547970652c627974657320706581527f726d697443616c6c4461746129000000000000000000000000000000000000006020820152602d0190565b7f537761704465736372697074696f6e280000000000000000000000000000000081527f75696e74382073776170547970652c000000000000000000000000000000000060108201527f4665652070726f746f636f6c4665652c00000000000000000000000000000000601f8201527f466565206d61726b6574706c6163654665652c00000000000000000000000000602f8201527f61646472657373206163636f756e742c0000000000000000000000000000000060428201527f616464726573732063616c6c65722c000000000000000000000000000000000060528201527f62797465732063616c6c657243616c6c4461746100000000000000000000000060618201527f2900000000000000000000000000000000000000000000000000000000000000607582015261153f607682015b7f546f6b656e416d6f756e74286164647265737320746f6b656e2c75696e74323581527f3620616d6f756e742c75696e743820616d6f756e7454797065290000000000006020820152603a0190565b7f50726f746f636f6c4665655369676e617475726528000000000000000000000081527f496e70757420696e7075742c000000000000000000000000000000000000000060158201527f4162736f6c757465546f6b656e416d6f756e74206f75747075742c000000000060218201527f537761704465736372697074696f6e20737761704465736372697074696f6e2c603c8201527f75696e7432353620646561646c696e6500000000000000000000000000000000605c8201527f2900000000000000000000000000000000000000000000000000000000000000606c8201527f4162736f6c757465546f6b656e416d6f756e74286164647265737320746f6b65606d8201527f6e2c75696e74323536206162736f6c757465416d6f756e742900000000000000608d82015260006134336133e461339560a68501613346565b60006040828403121561370a57600080fd5b61153f8383612ff9565b60008083357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe184360301811261374957600080fd5b83018035915067ffffffffffffffff82111561376457600080fd5b6020019150368190038213156122c557600080fd5b60006112823683612ee9565b60006040828403121561379757600080fd5b61153f8383612fbe565b60006112823683613032565b600082357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc18336030181126137e157600080fd5b9190910192915050565b8183528181602085013750600060208284010152600060207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f840116840101905092915050565b6020815260006119726020830184866137eb565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b60008282101561388957613889613848565b500390565b6000602082840312156138a057600080fd5b813561153f81612e22565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b60005b838110156138f55781810151838201526020016138dd565b83811115610d905750506000910152565b6000815180845261391e8160208601602086016138da565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169290920160200192915050565b8281526040602082015260006119726040830184613906565b600082516137e18184602087016138da565b60006020828403121561398d57600080fd5b81517fffffffff000000000000000000000000000000000000000000000000000000008116811461153f57600080fd5b6003811061230f5761230f6138ab565b604081016139da846139bd565b8382526139e6836139bd565b8260208301529392505050565b600060208284031215613a0557600080fd5b5051919050565b6000817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0483118215151615613a4457613a44613848565b500290565b600082613a7f577f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b500490565b60008219821115613a9757613a97613848565b500190565b803582526020810135613aae81612cc3565b73ffffffffffffffffffffffffffffffffffffffff81166020840152505050565b60006101008a83528960208401528860408401528760608401528660808401528560a08401528060c08401528435613b0681612e22565b613b0f816139bd565b83820152613b24610120840160208701613a9c565b613b35610160840160608701613a9c565b60a0850135613b4381612cc3565b73ffffffffffffffffffffffffffffffffffffffff9081166101a085015260c086013590613b7082612cc3565b166101c084015260e0850135368690037fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe1018112613bad57600080fd5b8501803567ffffffffffffffff811115613bc657600080fd5b803603871315613bd557600080fd5b826101e0860152613bee610200860182602085016137eb565b9350505050613c1560e083018473ffffffffffffffffffffffffffffffffffffffff169052565b9998505050505050505050565b7f496e70757428546f6b656e416d6f756e7420746f6b656e416d6f756e742c506581527f726d6974207065726d697429000000000000000000000000000000000000000060208201526000611282613568602c84016133e4565b7f4162736f6c757465546f6b656e416d6f756e74286164647265737320746f6b6581527f6e2c75696e74323536206162736f6c757465416d6f756e7429000000000000006020820152600060398201611282565b7f537761704465736372697074696f6e280000000000000000000000000000000081527f75696e74382073776170547970652c000000000000000000000000000000000060108201527f4665652070726f746f636f6c4665652c00000000000000000000000000000000601f8201527f466565206d61726b6574706c6163654665652c00000000000000000000000000602f8201527f61646472657373206163636f756e742c0000000000000000000000000000000060428201527f616464726573732063616c6c65722c000000000000000000000000000000000060528201527f62797465732063616c6c657243616c6c4461746100000000000000000000000060618201527f290000000000000000000000000000000000000000000000000000000000000060758201527f4665652875696e743235362073686172652c616464726573732062656e65666960768201527f636961727929000000000000000000000000000000000000000000000000000060968201526000609c8201611282565b87815260e08101613e64886139bd565b60208201979097526040810195909552606085019390935273ffffffffffffffffffffffffffffffffffffffff91821660808501521660a083015260c090910152919050565b600060208284031215613ebc57600080fd5b61153f82612e2f565b7fffffffff0000000000000000000000000000000000000000000000000000000084168152818360048301376000910160040190815292915050565b7f546f6b656e416d6f756e74286164647265737320746f6b656e2c75696e74323581527f3620616d6f756e742c75696e743820616d6f756e74547970652900000000000060208201526000603a8201611282565b84815273ffffffffffffffffffffffffffffffffffffffff841660208201526040810183905260808101613f88836139bd565b82606083015295945050505050565b7f5065726d69742875696e7438207065726d6974547970652c627974657320706581527f726d697443616c6c44617461290000000000000000000000000000000000000060208201526000602d8201611282565b8381526060810160048410614002576140026138ab565b602082019390935260400152919050565b7f4665652875696e743235362073686172652c616464726573732062656e65666981527f63696172792900000000000000000000000000000000000000000000000000006020820152600060268201611282565b60006020828403121561407957600080fd5b8151801515811461153f57600080fd5b60208152600061153f602083018461390656fea2646970667358221220b74cb04769364aee7c859b8208b8f05afd3fb55d66c99fd13ffa97eb86d7034f64736f6c634300080c0033

Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

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

Validator Index Block Amount
View All Withdrawals

Txn Hash Block Value Eth2 PubKey Valid
View All Deposits
Chain Token Portfolio % Price Amount Value
ETH50.60%$3,546.720.1705$604.54
ZKSYNC29.65%$3,542.660.1$354.27
ARB14.87%$3,547.210.0501$177.64
ARB0.12%$0.9985681.4427$1.44
ARB0.08%$0.9979321.0029$1
ARB0.05%$1.650.3862$0.6371
BSC3.27%$608.040.0643$39.07
BSC0.06%<$0.00000120,934,043.3415$0.6675
BSC0.03%$0.3595421$0.3595
BSC0.03%$0.0001322,613.2802$0.3443
BSC0.02%$0.2154120.9474$0.204
BASE1.03%$0.99758712.3472$12.32
MATIC0.10%$0.9966081.2564$1.25
MATIC0.09%$0.9941481.0555$1.05
GNO<0.01%$10.00315695$0.003158
FTM
Fantom (FTM)
<0.01%$0.9886480.0001$0.000099
[ Download: CSV Export  ]
[ Download: CSV Export  ]

A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.