ETH Price: $1,885.26 (-0.44%)

Transaction Decoder

Block:
21652247 at Jan-18-2025 03:23:47 PM +UTC
Transaction Fee:
0.00552190695062731 ETH $10.41
Gas Used:
188,662 Gas / 29.268782005 Gwei

Emitted Events:

211 WETH9.Deposit( dst=MainnetSettler, wad=2283900000000000000 )
212 WETH9.Transfer( src=MainnetSettler, dst=UniswapV2Pair, wad=2283900000000000000 )
213 HPOP8I.Transfer( from=UniswapV2Pair, to=HPOP8I, value=1123910182458 )
214 HPOP8I.Transfer( from=UniswapV2Pair, to=[Sender] 0xe9e59f3f4105a722fff9a3a8aedecf730704db17, value=55071598940464 )
215 UniswapV2Pair.Sync( reserve0=921630813500950, reserve1=39628483399350926778 )
216 UniswapV2Pair.Swap( sender=MainnetSettler, amount0In=0, amount1In=2283900000000000000, amount0Out=56195509122922, amount1Out=0, to=[Sender] 0xe9e59f3f4105a722fff9a3a8aedecf730704db17 )

Account State Difference:

  Address   Before After State Difference Code
0x07E0EDf8...D67F298ae
(beaverbuild)
6.901432004715580483 Eth6.901620666715580483 Eth0.000188662
0xaD01C20d...824c8fCe5 30.850618666553873752 Eth30.866718666553873752 Eth0.0161
0xB49159aF...28B8c20bb
0xC02aaA39...83C756Cc2 3,071,695.108096265421101492 Eth3,071,697.391996265421101492 Eth2.2839
0xE9E59f3F...30704Db17
2.326777038009025494 Eth
Nonce: 5
0.021255131058398184 Eth
Nonce: 6
2.30552190695062731

Execution Trace

ETH 2.3 AllowanceHolder.2213bc0b( )
  • MainnetSettler.balanceOf( 0x000000000000000000000000000000000000dEaD )
  • ETH 2.3 MainnetSettler.execute( slippage=[{name:recipient, type:address, order:1, indexed:false, value:0x0000000000000000000000000000000000000000, valueString:0x0000000000000000000000000000000000000000}, {name:buyToken, type:address, order:2, indexed:false, value:0x0000000000000000000000000000000000000000, valueString:0x0000000000000000000000000000000000000000}, {name:minAmountOut, type:uint256, order:3, indexed:false, value:0, valueString:0}], actions=[OMnBRwAAAAAAAAAAAAAAAO7u7u7u7u7u7u7u7u7u7u7u7u7uAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEYAAAAAAAAAAAAAAACtAcINWIYTfgVnda9WkV3oJMj85QAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAKAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==, OMnBRwAAAAAAAAAAAAAAAO7u7u7u7u7u7u7u7u7u7u7u7u7uAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJxAAAAAAAAAAAAAAAADAKqo5siP+jQoOXE8n6tkIPHVswgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAKAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJNDjDbAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=, EDtIvgAAAAAAAAAAAAAAAOnlnz9BBaci//mjqK7ez3MHBNsXAAAAAAAAAAAAAAAAwCqqObIj/o0KDlxPJ+rZCDx1bMIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAnEAAAAAAAAAAAAAAAALSRWa/rVPiSKwqCpdWL1HKLjCC7AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAC6UynnAOA==], 65BF9C4218BE1B44FBF83E680F15B10000000000000000000000000000000000 ) => ( True )
    • ETH 0.0161 0xad01c20d5886137e056775af56915de824c8fce5.CALL( )
    • ETH 2.2839 WETH9.deposit( )
    • WETH9.balanceOf( 0x70bf6634eE8Cb27D04478f184b9b8BB13E5f4710 ) => ( 2283900000000000000 )
    • WETH9.transfer( dst=0xB49159aFEB54f8922b0A82a5d58bd4728B8c20bb, wad=2283900000000000000 ) => ( True )
    • UniswapV2Pair.STATICCALL( )
    • UniswapV2Pair.swap( amount0Out=56195509122922, amount1Out=0, to=0xE9E59f3F4105a722fFf9a3a8aEDECF730704Db17, data=0x )
      • HPOP8I.transfer( recipient=0xE9E59f3F4105a722fFf9a3a8aEDECF730704Db17, amount=56195509122922 ) => ( True )
      • HPOP8I.balanceOf( account=0xB49159aFEB54f8922b0A82a5d58bd4728B8c20bb ) => ( 921630813500950 )
      • WETH9.balanceOf( 0xB49159aFEB54f8922b0A82a5d58bd4728B8c20bb ) => ( 39628483399350926778 )
        File 1 of 5: AllowanceHolder
        // SPDX-License-Identifier: MIT
        pragma solidity ^0.8.25;
        import {AllowanceHolderBase} from "./AllowanceHolderBase.sol";
        import {TransientStorage} from "./TransientStorage.sol";
        /// @custom:security-contact [email protected]
        contract AllowanceHolder is TransientStorage, AllowanceHolderBase {
            constructor() {
                require(address(this) == 0x0000000000001fF3684f28c67538d4D072C22734 || block.chainid == 31337);
            }
            /// @inheritdoc AllowanceHolderBase
            function exec(address operator, address token, uint256 amount, address payable target, bytes calldata data)
                internal
                override
                returns (bytes memory)
            {
                (bytes memory result, address sender, TSlot allowance) = _exec(operator, token, amount, target, data);
                // EIP-3074 seems unlikely
                if (sender != tx.origin) {
                    _set(allowance, 0);
                }
                return result;
            }
        }
        // SPDX-License-Identifier: MIT
        pragma solidity ^0.8.25;
        import {IAllowanceHolder} from "./IAllowanceHolder.sol";
        import {IERC20} from "../IERC20.sol";
        import {SafeTransferLib} from "../vendor/SafeTransferLib.sol";
        import {CheckCall} from "../utils/CheckCall.sol";
        import {FreeMemory} from "../utils/FreeMemory.sol";
        import {TransientStorageLayout} from "./TransientStorageLayout.sol";
        /// @notice Thrown when validating the target, avoiding executing against an ERC20 directly
        error ConfusedDeputy();
        abstract contract AllowanceHolderBase is TransientStorageLayout, FreeMemory {
            using SafeTransferLib for IERC20;
            using CheckCall for address payable;
            function _rejectIfERC20(address payable maybeERC20, bytes calldata data) private view DANGEROUS_freeMemory {
                // We could just choose a random address for this check, but to make
                // confused deputy attacks harder for tokens that might be badly behaved
                // (e.g. tokens with blacklists), we choose to copy the first argument
                // out of `data` and mask it as an address. If there isn't enough
                // `data`, we use 0xdead instead.
                address target;
                if (data.length > 0x10) {
                    target = address(uint160(bytes20(data[0x10:])));
                }
                // EIP-1352 (not adopted) specifies 0xffff as the maximum precompile
                if (target <= address(0xffff)) {
                    // 0xdead is a conventional burn address; we assume that it is not treated specially
                    target = address(0xdead);
                }
                bytes memory testData = abi.encodeCall(IERC20.balanceOf, target);
                if (maybeERC20.checkCall(testData, 0x20)) revert ConfusedDeputy();
            }
            function _msgSender() private view returns (address sender) {
                if ((sender = msg.sender) == address(this)) {
                    assembly ("memory-safe") {
                        sender := shr(0x60, calldataload(sub(calldatasize(), 0x14)))
                    }
                }
            }
            /// @dev This virtual function provides the implementation for the function
            ///      of the same name in `IAllowanceHolder`. It is unimplemented in this
            ///      base contract to accommodate the customization required to support
            ///      both chains that have EIP-1153 (transient storage) and those that
            ///      don't.
            function exec(address operator, address token, uint256 amount, address payable target, bytes calldata data)
                internal
                virtual
                returns (bytes memory result);
            /// @dev This is the majority of the implementation of IAllowanceHolder.exec
            ///      . The arguments have the same meaning as documented there.
            /// @return result
            /// @return sender The (possibly forwarded) message sender that is
            ///                requesting the allowance be set. Provided to avoid
            ///                duplicated computation in customized `exec`
            /// @return allowance The slot where the ephemeral allowance is
            ///                   stored. Provided to avoid duplicated computation in
            ///                   customized `exec`
            function _exec(address operator, address token, uint256 amount, address payable target, bytes calldata data)
                internal
                returns (bytes memory result, address sender, TSlot allowance)
            {
                // This contract has no special privileges, except for the allowances it
                // holds. In order to prevent abusing those allowances, we prohibit
                // sending arbitrary calldata (doing `target.call(data)`) to any
                // contract that might be an ERC20.
                _rejectIfERC20(target, data);
                sender = _msgSender();
                allowance = _ephemeralAllowance(operator, sender, token);
                _set(allowance, amount);
                // For gas efficiency we're omitting a bunch of checks here. Notably,
                // we're omitting the check that `address(this)` has sufficient value to
                // send (we know it does), and we're omitting the check that `target`
                // contains code (we already checked in `_rejectIfERC20`).
                assembly ("memory-safe") {
                    result := mload(0x40)
                    calldatacopy(result, data.offset, data.length)
                    // ERC-2771 style msgSender forwarding https://eips.ethereum.org/EIPS/eip-2771
                    mstore(add(result, data.length), shl(0x60, sender))
                    let success := call(gas(), target, callvalue(), result, add(data.length, 0x14), 0x00, 0x00)
                    let ptr := add(result, 0x20)
                    returndatacopy(ptr, 0x00, returndatasize())
                    switch success
                    case 0 { revert(ptr, returndatasize()) }
                    default {
                        mstore(result, returndatasize())
                        mstore(0x40, add(ptr, returndatasize()))
                    }
                }
            }
            /// @dev This provides the implementation of the function of the same name
            ///      in `IAllowanceHolder`.
            function transferFrom(address token, address owner, address recipient, uint256 amount) internal {
                // msg.sender is the assumed and later validated operator
                TSlot allowance = _ephemeralAllowance(msg.sender, owner, token);
                // validation of the ephemeral allowance for operator, owner, token via
                // uint underflow
                _set(allowance, _get(allowance) - amount);
                // `safeTransferFrom` does not check that `token` actually contains
                // code. It is the responsibility of integrating code to check for that
                // if vacuous success is a security concern.
                IERC20(token).safeTransferFrom(owner, recipient, amount);
            }
            fallback() external payable {
                uint256 selector;
                assembly ("memory-safe") {
                    selector := shr(0xe0, calldataload(0x00))
                }
                if (selector == uint256(uint32(IAllowanceHolder.transferFrom.selector))) {
                    address token;
                    address owner;
                    address recipient;
                    uint256 amount;
                    assembly ("memory-safe") {
                        // We do not validate `calldatasize()`. If the calldata is short
                        // enough that `amount` is null, this call is a harmless no-op.
                        let err := callvalue()
                        token := calldataload(0x04)
                        err := or(err, shr(0xa0, token))
                        owner := calldataload(0x24)
                        err := or(err, shr(0xa0, owner))
                        recipient := calldataload(0x44)
                        err := or(err, shr(0xa0, recipient))
                        if err { revert(0x00, 0x00) }
                        amount := calldataload(0x64)
                    }
                    transferFrom(token, owner, recipient, amount);
                    // return true;
                    assembly ("memory-safe") {
                        mstore(0x00, 0x01)
                        return(0x00, 0x20)
                    }
                } else if (selector == uint256(uint32(IAllowanceHolder.exec.selector))) {
                    address operator;
                    address token;
                    uint256 amount;
                    address payable target;
                    bytes calldata data;
                    assembly ("memory-safe") {
                        // We do not validate `calldatasize()`. If the calldata is short
                        // enough that `data` is null, it will alias `operator`. This
                        // results in either an OOG (because `operator` encodes a
                        // too-long `bytes`) or is a harmless no-op (because `operator`
                        // encodes a valid length, but not an address capable of making
                        // calls). If the calldata is _so_ sort that `target` is null,
                        // we will revert because it contains no code.
                        operator := calldataload(0x04)
                        let err := shr(0xa0, operator)
                        token := calldataload(0x24)
                        err := or(err, shr(0xa0, token))
                        amount := calldataload(0x44)
                        target := calldataload(0x64)
                        err := or(err, shr(0xa0, target))
                        if err { revert(0x00, 0x00) }
                        // We perform no validation that `data` is reasonable.
                        data.offset := add(0x04, calldataload(0x84))
                        data.length := calldataload(data.offset)
                        data.offset := add(0x20, data.offset)
                    }
                    bytes memory result = exec(operator, token, amount, target, data);
                    // return result;
                    assembly ("memory-safe") {
                        let returndata := sub(result, 0x20)
                        mstore(returndata, 0x20)
                        return(returndata, add(0x40, mload(result)))
                    }
                } else if (selector == uint256(uint32(IERC20.balanceOf.selector))) {
                    // balanceOf(address) reverts with a single byte of returndata,
                    // making it more gas efficient to pass the `_rejectERC20` check
                    assembly ("memory-safe") {
                        revert(0x00, 0x01)
                    }
                } else {
                    // emulate standard Solidity behavior
                    assembly ("memory-safe") {
                        revert(0x00, 0x00)
                    }
                }
            }
        }
        // SPDX-License-Identifier: MIT
        pragma solidity ^0.8.25;
        import {TransientStorageBase} from "./TransientStorageBase.sol";
        abstract contract TransientStorage is TransientStorageBase {
            function _get(TSlot s) internal view override returns (uint256 r) {
                assembly ("memory-safe") {
                    r := tload(s)
                }
            }
            function _set(TSlot s, uint256 v) internal override {
                assembly ("memory-safe") {
                    tstore(s, v)
                }
            }
        }
        // SPDX-License-Identifier: MIT
        pragma solidity ^0.8.25;
        interface IAllowanceHolder {
            /// @notice Executes against `target` with the `data` payload. Prior to execution, token permits
            ///         are temporarily stored for the duration of the transaction. These permits can be
            ///         consumed by the `operator` during the execution
            /// @notice `operator` consumes the funds during its operations by calling back into
            ///         `AllowanceHolder` with `transferFrom`, consuming a token permit.
            /// @dev Neither `exec` nor `transferFrom` check that `token` contains code.
            /// @dev msg.sender is forwarded to target appended to the msg data (similar to ERC-2771)
            /// @param operator An address which is allowed to consume the token permits
            /// @param token The ERC20 token the caller has authorised to be consumed
            /// @param amount The quantity of `token` the caller has authorised to be consumed
            /// @param target A contract to execute operations with `data`
            /// @param data The data to forward to `target`
            /// @return result The returndata from calling `target` with `data`
            /// @notice If calling `target` with `data` reverts, the revert is propagated
            function exec(address operator, address token, uint256 amount, address payable target, bytes calldata data)
                external
                payable
                returns (bytes memory result);
            /// @notice The counterpart to `exec` which allows for the consumption of token permits later
            ///         during execution
            /// @dev *DOES NOT* check that `token` contains code. This function vacuously succeeds if
            ///      `token` is empty.
            /// @dev can only be called by the `operator` previously registered in `exec`
            /// @param token The ERC20 token to transfer
            /// @param owner The owner of tokens to transfer
            /// @param recipient The destination/beneficiary of the ERC20 `transferFrom`
            /// @param amount The quantity of `token` to transfer`
            /// @return true
            function transferFrom(address token, address owner, address recipient, uint256 amount) external returns (bool);
        }
        // SPDX-License-Identifier: MIT
        pragma solidity ^0.8.25;
        interface IERC20 {
            function totalSupply() external view returns (uint256);
            function balanceOf(address) external view returns (uint256);
            function transfer(address, uint256) external returns (bool);
            function transferFrom(address, address, uint256) external returns (bool);
            function approve(address, uint256) external returns (bool);
            function allowance(address, address) external view returns (uint256);
            event Transfer(address indexed, address indexed, uint256);
            event Approval(address indexed, address indexed, uint256);
        }
        interface IERC20Meta is IERC20 {
            function name() external view returns (string memory);
            function symbol() external view returns (string memory);
            function decimals() external view returns (uint8);
        }
        // SPDX-License-Identifier: AGPL-3.0-only
        pragma solidity >=0.8.25;
        import {IERC20} from "../IERC20.sol";
        /// @notice Safe ETH and ERC20 transfer library that gracefully handles missing return values.
        /// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/SafeTransferLib.sol)
        /// @dev Use with caution! Some functions in this library knowingly create dirty bits at the destination of the free memory pointer.
        /// @dev Note that none of the functions in this library check that a token has code at all! That responsibility is delegated to the caller.
        library SafeTransferLib {
            uint32 private constant _TRANSFER_FROM_FAILED_SELECTOR = 0x7939f424; // bytes4(keccak256("TransferFromFailed()"))
            uint32 private constant _TRANSFER_FAILED_SELECTOR = 0x90b8ec18; // bytes4(keccak256("TransferFailed()"))
            uint32 private constant _APPROVE_FAILED_SELECTOR = 0x3e3f8f73; // bytes4(keccak256("ApproveFailed()"))
            /*//////////////////////////////////////////////////////////////
                                     ETH OPERATIONS
            //////////////////////////////////////////////////////////////*/
            function safeTransferETH(address payable to, uint256 amount) internal {
                assembly ("memory-safe") {
                    // Transfer the ETH and store if it succeeded or not.
                    if iszero(call(gas(), to, amount, 0, 0, 0, 0)) {
                        let freeMemoryPointer := mload(0x40)
                        returndatacopy(freeMemoryPointer, 0, returndatasize())
                        revert(freeMemoryPointer, returndatasize())
                    }
                }
            }
            /*//////////////////////////////////////////////////////////////
                                    ERC20 OPERATIONS
            //////////////////////////////////////////////////////////////*/
            function safeTransferFrom(IERC20 token, address from, address to, uint256 amount) internal {
                assembly ("memory-safe") {
                    // Get a pointer to some free memory.
                    let freeMemoryPointer := mload(0x40)
                    // Write the abi-encoded calldata into memory, beginning with the function selector.
                    mstore(freeMemoryPointer, 0x23b872dd00000000000000000000000000000000000000000000000000000000)
                    mstore(add(freeMemoryPointer, 4), and(from, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "from" argument.
                    mstore(add(freeMemoryPointer, 36), and(to, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "to" argument.
                    mstore(add(freeMemoryPointer, 68), amount) // Append the "amount" argument. Masking not required as it's a full 32 byte type.
                    // We use 100 because the length of our calldata totals up like so: 4 + 32 * 3.
                    // We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
                    if iszero(call(gas(), token, 0, freeMemoryPointer, 100, 0, 32)) {
                        returndatacopy(freeMemoryPointer, 0, returndatasize())
                        revert(freeMemoryPointer, returndatasize())
                    }
                    // We check that the call either returned exactly 1 (can't just be non-zero data), or had no
                    // return data.
                    if iszero(or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize()))) {
                        mstore(0, _TRANSFER_FROM_FAILED_SELECTOR)
                        revert(0x1c, 0x04)
                    }
                }
            }
            function safeTransfer(IERC20 token, address to, uint256 amount) internal {
                assembly ("memory-safe") {
                    // Get a pointer to some free memory.
                    let freeMemoryPointer := mload(0x40)
                    // Write the abi-encoded calldata into memory, beginning with the function selector.
                    mstore(freeMemoryPointer, 0xa9059cbb00000000000000000000000000000000000000000000000000000000)
                    mstore(add(freeMemoryPointer, 4), and(to, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "to" argument.
                    mstore(add(freeMemoryPointer, 36), amount) // Append the "amount" argument. Masking not required as it's a full 32 byte type.
                    // We use 68 because the length of our calldata totals up like so: 4 + 32 * 2.
                    // We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
                    if iszero(call(gas(), token, 0, freeMemoryPointer, 68, 0, 32)) {
                        returndatacopy(freeMemoryPointer, 0, returndatasize())
                        revert(freeMemoryPointer, returndatasize())
                    }
                    // We check that the call either returned exactly 1 (can't just be non-zero data), or had no
                    // return data.
                    if iszero(or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize()))) {
                        mstore(0, _TRANSFER_FAILED_SELECTOR)
                        revert(0x1c, 0x04)
                    }
                }
            }
            function safeApprove(IERC20 token, address to, uint256 amount) internal {
                assembly ("memory-safe") {
                    // Get a pointer to some free memory.
                    let freeMemoryPointer := mload(0x40)
                    // Write the abi-encoded calldata into memory, beginning with the function selector.
                    mstore(freeMemoryPointer, 0x095ea7b300000000000000000000000000000000000000000000000000000000)
                    mstore(add(freeMemoryPointer, 4), and(to, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "to" argument.
                    mstore(add(freeMemoryPointer, 36), amount) // Append the "amount" argument. Masking not required as it's a full 32 byte type.
                    // We use 68 because the length of our calldata totals up like so: 4 + 32 * 2.
                    // We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
                    if iszero(call(gas(), token, 0, freeMemoryPointer, 68, 0, 32)) {
                        returndatacopy(freeMemoryPointer, 0, returndatasize())
                        revert(freeMemoryPointer, returndatasize())
                    }
                    // We check that the call either returned exactly 1 (can't just be non-zero data), or had no
                    // return data.
                    if iszero(or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize()))) {
                        mstore(0, _APPROVE_FAILED_SELECTOR)
                        revert(0x1c, 0x04)
                    }
                }
            }
            function safeApproveIfBelow(IERC20 token, address spender, uint256 amount) internal {
                uint256 allowance = token.allowance(address(this), spender);
                if (allowance < amount) {
                    if (allowance != 0) {
                        safeApprove(token, spender, 0);
                    }
                    safeApprove(token, spender, type(uint256).max);
                }
            }
        }
        // SPDX-License-Identifier: MIT
        pragma solidity ^0.8.25;
        library CheckCall {
            /**
             * @notice `staticcall` another contract. Check the length of the return without reading it.
             * @dev contains protections against EIP-150-induced insufficient gas griefing
             * @dev reverts iff the target is not a contract or we encounter an out-of-gas
             * @return success true iff the call succeeded and returned at least `minReturnBytes` of return
             *                 data
             * @param target the contract (reverts if non-contract) on which to make the `staticcall`
             * @param data the calldata to pass
             * @param minReturnBytes `success` is false if the call doesn't return at least this much return
             *                       data
             */
            function checkCall(address target, bytes memory data, uint256 minReturnBytes)
                internal
                view
                returns (bool success)
            {
                assembly ("memory-safe") {
                    let beforeGas
                    {
                        let offset := add(data, 0x20)
                        let length := mload(data)
                        beforeGas := gas()
                        success := staticcall(gas(), target, offset, length, 0x00, 0x00)
                    }
                    // `verbatim` can't work in inline assembly. Assignment of a value to a variable costs
                    // gas (although how much is unpredictable because it depends on the Yul/IR optimizer),
                    // as does the `GAS` opcode itself. Therefore, the `gas()` below returns less than the
                    // actual amount of gas available for computation at the end of the call. Also
                    // `beforeGas` above is exclusive of the preparing of the stack for `staticcall` as well
                    // as the gas costs of the `staticcall` paid by the caller (e.g. cold account
                    // access). All this makes the check below slightly too conservative. However, we do not
                    // correct this because the correction would become outdated (possibly too permissive)
                    // if the opcodes are repriced.
                    let afterGas := gas()
                    for {} 1 {} {
                        if iszero(returndatasize()) {
                            // The absence of returndata means that it's possible that either we called an
                            // address without code or that the call reverted due to out-of-gas. We must
                            // check.
                            switch success
                            case 0 {
                                // Check whether the call reverted due to out-of-gas.
                                // https://eips.ethereum.org/EIPS/eip-150
                                // https://ronan.eth.limo/blog/ethereum-gas-dangers/
                                // We apply the "all but one 64th" rule twice because `target` could
                                // plausibly be a proxy. We apply it only twice because we assume only a
                                // single level of indirection.
                                let remainingGas := shr(6, beforeGas)
                                remainingGas := add(remainingGas, shr(6, sub(beforeGas, remainingGas)))
                                if iszero(lt(remainingGas, afterGas)) {
                                    // The call failed due to not enough gas left. We deliberately consume
                                    // all remaining gas with `invalid` (instead of `revert`) to make this
                                    // failure distinguishable to our caller.
                                    invalid()
                                }
                                // `success` is false because the call reverted
                            }
                            default {
                                // Check whether we called an address with no code (gas expensive).
                                if iszero(extcodesize(target)) { revert(0x00, 0x00) }
                                // We called a contract which returned no data; this is only a success if we
                                // were expecting no data.
                                success := iszero(minReturnBytes)
                            }
                            break
                        }
                        // The presence of returndata indicates that we definitely executed code. It also
                        // means that the call didn't revert due to out-of-gas, if it reverted. We can omit
                        // a bunch of checks.
                        success := gt(success, lt(returndatasize(), minReturnBytes))
                        break
                    }
                }
            }
        }
        // SPDX-License-Identifier: MIT
        pragma solidity ^0.8.25;
        abstract contract FreeMemory {
            modifier DANGEROUS_freeMemory() {
                uint256 freeMemPtr;
                assembly ("memory-safe") {
                    freeMemPtr := mload(0x40)
                }
                _;
                assembly ("memory-safe") {
                    mstore(0x40, freeMemPtr)
                }
            }
        }
        // SPDX-License-Identifier: MIT
        pragma solidity ^0.8.25;
        import {TransientStorageBase} from "./TransientStorageBase.sol";
        abstract contract TransientStorageLayout is TransientStorageBase {
            /// @dev The key for this ephemeral allowance is keccak256(abi.encodePacked(operator, owner, token)).
            function _ephemeralAllowance(address operator, address owner, address token) internal pure returns (TSlot r) {
                assembly ("memory-safe") {
                    let ptr := mload(0x40)
                    mstore(0x28, token)
                    mstore(0x14, owner)
                    mstore(0x00, operator)
                    // allowance slot is keccak256(abi.encodePacked(operator, owner, token))
                    r := keccak256(0x0c, 0x3c)
                    // restore dirtied free pointer
                    mstore(0x40, ptr)
                }
            }
        }
        // SPDX-License-Identifier: MIT
        pragma solidity ^0.8.25;
        abstract contract TransientStorageBase {
            type TSlot is bytes32;
            function _get(TSlot s) internal view virtual returns (uint256);
            function _set(TSlot s, uint256 v) internal virtual;
        }
        

        File 2 of 5: WETH9
        // Copyright (C) 2015, 2016, 2017 Dapphub
        
        // 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 <http://www.gnu.org/licenses/>.
        
        pragma solidity ^0.4.18;
        
        contract WETH9 {
            string public name     = "Wrapped Ether";
            string public symbol   = "WETH";
            uint8  public decimals = 18;
        
            event  Approval(address indexed src, address indexed guy, uint wad);
            event  Transfer(address indexed src, address indexed dst, uint wad);
            event  Deposit(address indexed dst, uint wad);
            event  Withdrawal(address indexed src, uint wad);
        
            mapping (address => uint)                       public  balanceOf;
            mapping (address => mapping (address => uint))  public  allowance;
        
            function() public payable {
                deposit();
            }
            function deposit() public payable {
                balanceOf[msg.sender] += msg.value;
                Deposit(msg.sender, msg.value);
            }
            function withdraw(uint wad) public {
                require(balanceOf[msg.sender] >= wad);
                balanceOf[msg.sender] -= wad;
                msg.sender.transfer(wad);
                Withdrawal(msg.sender, wad);
            }
        
            function totalSupply() public view returns (uint) {
                return this.balance;
            }
        
            function approve(address guy, uint wad) public returns (bool) {
                allowance[msg.sender][guy] = wad;
                Approval(msg.sender, guy, wad);
                return true;
            }
        
            function transfer(address dst, uint wad) public returns (bool) {
                return transferFrom(msg.sender, dst, wad);
            }
        
            function transferFrom(address src, address dst, uint wad)
                public
                returns (bool)
            {
                require(balanceOf[src] >= wad);
        
                if (src != msg.sender && allowance[src][msg.sender] != uint(-1)) {
                    require(allowance[src][msg.sender] >= wad);
                    allowance[src][msg.sender] -= wad;
                }
        
                balanceOf[src] -= wad;
                balanceOf[dst] += wad;
        
                Transfer(src, dst, wad);
        
                return true;
            }
        }
        
        
        /*
                            GNU GENERAL PUBLIC LICENSE
                               Version 3, 29 June 2007
        
         Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
         Everyone is permitted to copy and distribute verbatim copies
         of this license document, but changing it is not allowed.
        
                                    Preamble
        
          The GNU General Public License is a free, copyleft license for
        software and other kinds of works.
        
          The licenses for most software and other practical works are designed
        to take away your freedom to share and change the works.  By contrast,
        the GNU General Public License is intended to guarantee your freedom to
        share and change all versions of a program--to make sure it remains free
        software for all its users.  We, the Free Software Foundation, use the
        GNU General Public License for most of our software; it applies also to
        any other work released this way by its authors.  You can apply it to
        your programs, too.
        
          When we speak of free software, we are referring to freedom, not
        price.  Our General Public Licenses are designed to make sure that you
        have the freedom to distribute copies of free software (and charge for
        them if you wish), that you receive source code or can get it if you
        want it, that you can change the software or use pieces of it in new
        free programs, and that you know you can do these things.
        
          To protect your rights, we need to prevent others from denying you
        these rights or asking you to surrender the rights.  Therefore, you have
        certain responsibilities if you distribute copies of the software, or if
        you modify it: responsibilities to respect the freedom of others.
        
          For example, if you distribute copies of such a program, whether
        gratis or for a fee, you must pass on to the recipients the same
        freedoms that you received.  You must make sure that they, too, receive
        or can get the source code.  And you must show them these terms so they
        know their rights.
        
          Developers that use the GNU GPL protect your rights with two steps:
        (1) assert copyright on the software, and (2) offer you this License
        giving you legal permission to copy, distribute and/or modify it.
        
          For the developers' and authors' protection, the GPL clearly explains
        that there is no warranty for this free software.  For both users' and
        authors' sake, the GPL requires that modified versions be marked as
        changed, so that their problems will not be attributed erroneously to
        authors of previous versions.
        
          Some devices are designed to deny users access to install or run
        modified versions of the software inside them, although the manufacturer
        can do so.  This is fundamentally incompatible with the aim of
        protecting users' freedom to change the software.  The systematic
        pattern of such abuse occurs in the area of products for individuals to
        use, which is precisely where it is most unacceptable.  Therefore, we
        have designed this version of the GPL to prohibit the practice for those
        products.  If such problems arise substantially in other domains, we
        stand ready to extend this provision to those domains in future versions
        of the GPL, as needed to protect the freedom of users.
        
          Finally, every program is threatened constantly by software patents.
        States should not allow patents to restrict development and use of
        software on general-purpose computers, but in those that do, we wish to
        avoid the special danger that patents applied to a free program could
        make it effectively proprietary.  To prevent this, the GPL assures that
        patents cannot be used to render the program non-free.
        
          The precise terms and conditions for copying, distribution and
        modification follow.
        
                               TERMS AND CONDITIONS
        
          0. Definitions.
        
          "This License" refers to version 3 of the GNU General Public License.
        
          "Copyright" also means copyright-like laws that apply to other kinds of
        works, such as semiconductor masks.
        
          "The Program" refers to any copyrightable work licensed under this
        License.  Each licensee is addressed as "you".  "Licensees" and
        "recipients" may be individuals or organizations.
        
          To "modify" a work means to copy from or adapt all or part of the work
        in a fashion requiring copyright permission, other than the making of an
        exact copy.  The resulting work is called a "modified version" of the
        earlier work or a work "based on" the earlier work.
        
          A "covered work" means either the unmodified Program or a work based
        on the Program.
        
          To "propagate" a work means to do anything with it that, without
        permission, would make you directly or secondarily liable for
        infringement under applicable copyright law, except executing it on a
        computer or modifying a private copy.  Propagation includes copying,
        distribution (with or without modification), making available to the
        public, and in some countries other activities as well.
        
          To "convey" a work means any kind of propagation that enables other
        parties to make or receive copies.  Mere interaction with a user through
        a computer network, with no transfer of a copy, is not conveying.
        
          An interactive user interface displays "Appropriate Legal Notices"
        to the extent that it includes a convenient and prominently visible
        feature that (1) displays an appropriate copyright notice, and (2)
        tells the user that there is no warranty for the work (except to the
        extent that warranties are provided), that licensees may convey the
        work under this License, and how to view a copy of this License.  If
        the interface presents a list of user commands or options, such as a
        menu, a prominent item in the list meets this criterion.
        
          1. Source Code.
        
          The "source code" for a work means the preferred form of the work
        for making modifications to it.  "Object code" means any non-source
        form of a work.
        
          A "Standard Interface" means an interface that either is an official
        standard defined by a recognized standards body, or, in the case of
        interfaces specified for a particular programming language, one that
        is widely used among developers working in that language.
        
          The "System Libraries" of an executable work include anything, other
        than the work as a whole, that (a) is included in the normal form of
        packaging a Major Component, but which is not part of that Major
        Component, and (b) serves only to enable use of the work with that
        Major Component, or to implement a Standard Interface for which an
        implementation is available to the public in source code form.  A
        "Major Component", in this context, means a major essential component
        (kernel, window system, and so on) of the specific operating system
        (if any) on which the executable work runs, or a compiler used to
        produce the work, or an object code interpreter used to run it.
        
          The "Corresponding Source" for a work in object code form means all
        the source code needed to generate, install, and (for an executable
        work) run the object code and to modify the work, including scripts to
        control those activities.  However, it does not include the work's
        System Libraries, or general-purpose tools or generally available free
        programs which are used unmodified in performing those activities but
        which are not part of the work.  For example, Corresponding Source
        includes interface definition files associated with source files for
        the work, and the source code for shared libraries and dynamically
        linked subprograms that the work is specifically designed to require,
        such as by intimate data communication or control flow between those
        subprograms and other parts of the work.
        
          The Corresponding Source need not include anything that users
        can regenerate automatically from other parts of the Corresponding
        Source.
        
          The Corresponding Source for a work in source code form is that
        same work.
        
          2. Basic Permissions.
        
          All rights granted under this License are granted for the term of
        copyright on the Program, and are irrevocable provided the stated
        conditions are met.  This License explicitly affirms your unlimited
        permission to run the unmodified Program.  The output from running a
        covered work is covered by this License only if the output, given its
        content, constitutes a covered work.  This License acknowledges your
        rights of fair use or other equivalent, as provided by copyright law.
        
          You may make, run and propagate covered works that you do not
        convey, without conditions so long as your license otherwise remains
        in force.  You may convey covered works to others for the sole purpose
        of having them make modifications exclusively for you, or provide you
        with facilities for running those works, provided that you comply with
        the terms of this License in conveying all material for which you do
        not control copyright.  Those thus making or running the covered works
        for you must do so exclusively on your behalf, under your direction
        and control, on terms that prohibit them from making any copies of
        your copyrighted material outside their relationship with you.
        
          Conveying under any other circumstances is permitted solely under
        the conditions stated below.  Sublicensing is not allowed; section 10
        makes it unnecessary.
        
          3. Protecting Users' Legal Rights From Anti-Circumvention Law.
        
          No covered work shall be deemed part of an effective technological
        measure under any applicable law fulfilling obligations under article
        11 of the WIPO copyright treaty adopted on 20 December 1996, or
        similar laws prohibiting or restricting circumvention of such
        measures.
        
          When you convey a covered work, you waive any legal power to forbid
        circumvention of technological measures to the extent such circumvention
        is effected by exercising rights under this License with respect to
        the covered work, and you disclaim any intention to limit operation or
        modification of the work as a means of enforcing, against the work's
        users, your or third parties' legal rights to forbid circumvention of
        technological measures.
        
          4. Conveying Verbatim Copies.
        
          You may convey verbatim copies of the Program's source code as you
        receive it, in any medium, provided that you conspicuously and
        appropriately publish on each copy an appropriate copyright notice;
        keep intact all notices stating that this License and any
        non-permissive terms added in accord with section 7 apply to the code;
        keep intact all notices of the absence of any warranty; and give all
        recipients a copy of this License along with the Program.
        
          You may charge any price or no price for each copy that you convey,
        and you may offer support or warranty protection for a fee.
        
          5. Conveying Modified Source Versions.
        
          You may convey a work based on the Program, or the modifications to
        produce it from the Program, in the form of source code under the
        terms of section 4, provided that you also meet all of these conditions:
        
            a) The work must carry prominent notices stating that you modified
            it, and giving a relevant date.
        
            b) The work must carry prominent notices stating that it is
            released under this License and any conditions added under section
            7.  This requirement modifies the requirement in section 4 to
            "keep intact all notices".
        
            c) You must license the entire work, as a whole, under this
            License to anyone who comes into possession of a copy.  This
            License will therefore apply, along with any applicable section 7
            additional terms, to the whole of the work, and all its parts,
            regardless of how they are packaged.  This License gives no
            permission to license the work in any other way, but it does not
            invalidate such permission if you have separately received it.
        
            d) If the work has interactive user interfaces, each must display
            Appropriate Legal Notices; however, if the Program has interactive
            interfaces that do not display Appropriate Legal Notices, your
            work need not make them do so.
        
          A compilation of a covered work with other separate and independent
        works, which are not by their nature extensions of the covered work,
        and which are not combined with it such as to form a larger program,
        in or on a volume of a storage or distribution medium, is called an
        "aggregate" if the compilation and its resulting copyright are not
        used to limit the access or legal rights of the compilation's users
        beyond what the individual works permit.  Inclusion of a covered work
        in an aggregate does not cause this License to apply to the other
        parts of the aggregate.
        
          6. Conveying Non-Source Forms.
        
          You may convey a covered work in object code form under the terms
        of sections 4 and 5, provided that you also convey the
        machine-readable Corresponding Source under the terms of this License,
        in one of these ways:
        
            a) Convey the object code in, or embodied in, a physical product
            (including a physical distribution medium), accompanied by the
            Corresponding Source fixed on a durable physical medium
            customarily used for software interchange.
        
            b) Convey the object code in, or embodied in, a physical product
            (including a physical distribution medium), accompanied by a
            written offer, valid for at least three years and valid for as
            long as you offer spare parts or customer support for that product
            model, to give anyone who possesses the object code either (1) a
            copy of the Corresponding Source for all the software in the
            product that is covered by this License, on a durable physical
            medium customarily used for software interchange, for a price no
            more than your reasonable cost of physically performing this
            conveying of source, or (2) access to copy the
            Corresponding Source from a network server at no charge.
        
            c) Convey individual copies of the object code with a copy of the
            written offer to provide the Corresponding Source.  This
            alternative is allowed only occasionally and noncommercially, and
            only if you received the object code with such an offer, in accord
            with subsection 6b.
        
            d) Convey the object code by offering access from a designated
            place (gratis or for a charge), and offer equivalent access to the
            Corresponding Source in the same way through the same place at no
            further charge.  You need not require recipients to copy the
            Corresponding Source along with the object code.  If the place to
            copy the object code is a network server, the Corresponding Source
            may be on a different server (operated by you or a third party)
            that supports equivalent copying facilities, provided you maintain
            clear directions next to the object code saying where to find the
            Corresponding Source.  Regardless of what server hosts the
            Corresponding Source, you remain obligated to ensure that it is
            available for as long as needed to satisfy these requirements.
        
            e) Convey the object code using peer-to-peer transmission, provided
            you inform other peers where the object code and Corresponding
            Source of the work are being offered to the general public at no
            charge under subsection 6d.
        
          A separable portion of the object code, whose source code is excluded
        from the Corresponding Source as a System Library, need not be
        included in conveying the object code work.
        
          A "User Product" is either (1) a "consumer product", which means any
        tangible personal property which is normally used for personal, family,
        or household purposes, or (2) anything designed or sold for incorporation
        into a dwelling.  In determining whether a product is a consumer product,
        doubtful cases shall be resolved in favor of coverage.  For a particular
        product received by a particular user, "normally used" refers to a
        typical or common use of that class of product, regardless of the status
        of the particular user or of the way in which the particular user
        actually uses, or expects or is expected to use, the product.  A product
        is a consumer product regardless of whether the product has substantial
        commercial, industrial or non-consumer uses, unless such uses represent
        the only significant mode of use of the product.
        
          "Installation Information" for a User Product means any methods,
        procedures, authorization keys, or other information required to install
        and execute modified versions of a covered work in that User Product from
        a modified version of its Corresponding Source.  The information must
        suffice to ensure that the continued functioning of the modified object
        code is in no case prevented or interfered with solely because
        modification has been made.
        
          If you convey an object code work under this section in, or with, or
        specifically for use in, a User Product, and the conveying occurs as
        part of a transaction in which the right of possession and use of the
        User Product is transferred to the recipient in perpetuity or for a
        fixed term (regardless of how the transaction is characterized), the
        Corresponding Source conveyed under this section must be accompanied
        by the Installation Information.  But this requirement does not apply
        if neither you nor any third party retains the ability to install
        modified object code on the User Product (for example, the work has
        been installed in ROM).
        
          The requirement to provide Installation Information does not include a
        requirement to continue to provide support service, warranty, or updates
        for a work that has been modified or installed by the recipient, or for
        the User Product in which it has been modified or installed.  Access to a
        network may be denied when the modification itself materially and
        adversely affects the operation of the network or violates the rules and
        protocols for communication across the network.
        
          Corresponding Source conveyed, and Installation Information provided,
        in accord with this section must be in a format that is publicly
        documented (and with an implementation available to the public in
        source code form), and must require no special password or key for
        unpacking, reading or copying.
        
          7. Additional Terms.
        
          "Additional permissions" are terms that supplement the terms of this
        License by making exceptions from one or more of its conditions.
        Additional permissions that are applicable to the entire Program shall
        be treated as though they were included in this License, to the extent
        that they are valid under applicable law.  If additional permissions
        apply only to part of the Program, that part may be used separately
        under those permissions, but the entire Program remains governed by
        this License without regard to the additional permissions.
        
          When you convey a copy of a covered work, you may at your option
        remove any additional permissions from that copy, or from any part of
        it.  (Additional permissions may be written to require their own
        removal in certain cases when you modify the work.)  You may place
        additional permissions on material, added by you to a covered work,
        for which you have or can give appropriate copyright permission.
        
          Notwithstanding any other provision of this License, for material you
        add to a covered work, you may (if authorized by the copyright holders of
        that material) supplement the terms of this License with terms:
        
            a) Disclaiming warranty or limiting liability differently from the
            terms of sections 15 and 16 of this License; or
        
            b) Requiring preservation of specified reasonable legal notices or
            author attributions in that material or in the Appropriate Legal
            Notices displayed by works containing it; or
        
            c) Prohibiting misrepresentation of the origin of that material, or
            requiring that modified versions of such material be marked in
            reasonable ways as different from the original version; or
        
            d) Limiting the use for publicity purposes of names of licensors or
            authors of the material; or
        
            e) Declining to grant rights under trademark law for use of some
            trade names, trademarks, or service marks; or
        
            f) Requiring indemnification of licensors and authors of that
            material by anyone who conveys the material (or modified versions of
            it) with contractual assumptions of liability to the recipient, for
            any liability that these contractual assumptions directly impose on
            those licensors and authors.
        
          All other non-permissive additional terms are considered "further
        restrictions" within the meaning of section 10.  If the Program as you
        received it, or any part of it, contains a notice stating that it is
        governed by this License along with a term that is a further
        restriction, you may remove that term.  If a license document contains
        a further restriction but permits relicensing or conveying under this
        License, you may add to a covered work material governed by the terms
        of that license document, provided that the further restriction does
        not survive such relicensing or conveying.
        
          If you add terms to a covered work in accord with this section, you
        must place, in the relevant source files, a statement of the
        additional terms that apply to those files, or a notice indicating
        where to find the applicable terms.
        
          Additional terms, permissive or non-permissive, may be stated in the
        form of a separately written license, or stated as exceptions;
        the above requirements apply either way.
        
          8. Termination.
        
          You may not propagate or modify a covered work except as expressly
        provided under this License.  Any attempt otherwise to propagate or
        modify it is void, and will automatically terminate your rights under
        this License (including any patent licenses granted under the third
        paragraph of section 11).
        
          However, if you cease all violation of this License, then your
        license from a particular copyright holder is reinstated (a)
        provisionally, unless and until the copyright holder explicitly and
        finally terminates your license, and (b) permanently, if the copyright
        holder fails to notify you of the violation by some reasonable means
        prior to 60 days after the cessation.
        
          Moreover, your license from a particular copyright holder is
        reinstated permanently if the copyright holder notifies you of the
        violation by some reasonable means, this is the first time you have
        received notice of violation of this License (for any work) from that
        copyright holder, and you cure the violation prior to 30 days after
        your receipt of the notice.
        
          Termination of your rights under this section does not terminate the
        licenses of parties who have received copies or rights from you under
        this License.  If your rights have been terminated and not permanently
        reinstated, you do not qualify to receive new licenses for the same
        material under section 10.
        
          9. Acceptance Not Required for Having Copies.
        
          You are not required to accept this License in order to receive or
        run a copy of the Program.  Ancillary propagation of a covered work
        occurring solely as a consequence of using peer-to-peer transmission
        to receive a copy likewise does not require acceptance.  However,
        nothing other than this License grants you permission to propagate or
        modify any covered work.  These actions infringe copyright if you do
        not accept this License.  Therefore, by modifying or propagating a
        covered work, you indicate your acceptance of this License to do so.
        
          10. Automatic Licensing of Downstream Recipients.
        
          Each time you convey a covered work, the recipient automatically
        receives a license from the original licensors, to run, modify and
        propagate that work, subject to this License.  You are not responsible
        for enforcing compliance by third parties with this License.
        
          An "entity transaction" is a transaction transferring control of an
        organization, or substantially all assets of one, or subdividing an
        organization, or merging organizations.  If propagation of a covered
        work results from an entity transaction, each party to that
        transaction who receives a copy of the work also receives whatever
        licenses to the work the party's predecessor in interest had or could
        give under the previous paragraph, plus a right to possession of the
        Corresponding Source of the work from the predecessor in interest, if
        the predecessor has it or can get it with reasonable efforts.
        
          You may not impose any further restrictions on the exercise of the
        rights granted or affirmed under this License.  For example, you may
        not impose a license fee, royalty, or other charge for exercise of
        rights granted under this License, and you may not initiate litigation
        (including a cross-claim or counterclaim in a lawsuit) alleging that
        any patent claim is infringed by making, using, selling, offering for
        sale, or importing the Program or any portion of it.
        
          11. Patents.
        
          A "contributor" is a copyright holder who authorizes use under this
        License of the Program or a work on which the Program is based.  The
        work thus licensed is called the contributor's "contributor version".
        
          A contributor's "essential patent claims" are all patent claims
        owned or controlled by the contributor, whether already acquired or
        hereafter acquired, that would be infringed by some manner, permitted
        by this License, of making, using, or selling its contributor version,
        but do not include claims that would be infringed only as a
        consequence of further modification of the contributor version.  For
        purposes of this definition, "control" includes the right to grant
        patent sublicenses in a manner consistent with the requirements of
        this License.
        
          Each contributor grants you a non-exclusive, worldwide, royalty-free
        patent license under the contributor's essential patent claims, to
        make, use, sell, offer for sale, import and otherwise run, modify and
        propagate the contents of its contributor version.
        
          In the following three paragraphs, a "patent license" is any express
        agreement or commitment, however denominated, not to enforce a patent
        (such as an express permission to practice a patent or covenant not to
        sue for patent infringement).  To "grant" such a patent license to a
        party means to make such an agreement or commitment not to enforce a
        patent against the party.
        
          If you convey a covered work, knowingly relying on a patent license,
        and the Corresponding Source of the work is not available for anyone
        to copy, free of charge and under the terms of this License, through a
        publicly available network server or other readily accessible means,
        then you must either (1) cause the Corresponding Source to be so
        available, or (2) arrange to deprive yourself of the benefit of the
        patent license for this particular work, or (3) arrange, in a manner
        consistent with the requirements of this License, to extend the patent
        license to downstream recipients.  "Knowingly relying" means you have
        actual knowledge that, but for the patent license, your conveying the
        covered work in a country, or your recipient's use of the covered work
        in a country, would infringe one or more identifiable patents in that
        country that you have reason to believe are valid.
        
          If, pursuant to or in connection with a single transaction or
        arrangement, you convey, or propagate by procuring conveyance of, a
        covered work, and grant a patent license to some of the parties
        receiving the covered work authorizing them to use, propagate, modify
        or convey a specific copy of the covered work, then the patent license
        you grant is automatically extended to all recipients of the covered
        work and works based on it.
        
          A patent license is "discriminatory" if it does not include within
        the scope of its coverage, prohibits the exercise of, or is
        conditioned on the non-exercise of one or more of the rights that are
        specifically granted under this License.  You may not convey a covered
        work if you are a party to an arrangement with a third party that is
        in the business of distributing software, under which you make payment
        to the third party based on the extent of your activity of conveying
        the work, and under which the third party grants, to any of the
        parties who would receive the covered work from you, a discriminatory
        patent license (a) in connection with copies of the covered work
        conveyed by you (or copies made from those copies), or (b) primarily
        for and in connection with specific products or compilations that
        contain the covered work, unless you entered into that arrangement,
        or that patent license was granted, prior to 28 March 2007.
        
          Nothing in this License shall be construed as excluding or limiting
        any implied license or other defenses to infringement that may
        otherwise be available to you under applicable patent law.
        
          12. No Surrender of Others' Freedom.
        
          If conditions are imposed on you (whether by court order, agreement or
        otherwise) that contradict the conditions of this License, they do not
        excuse you from the conditions of this License.  If you cannot convey a
        covered work so as to satisfy simultaneously your obligations under this
        License and any other pertinent obligations, then as a consequence you may
        not convey it at all.  For example, if you agree to terms that obligate you
        to collect a royalty for further conveying from those to whom you convey
        the Program, the only way you could satisfy both those terms and this
        License would be to refrain entirely from conveying the Program.
        
          13. Use with the GNU Affero General Public License.
        
          Notwithstanding any other provision of this License, you have
        permission to link or combine any covered work with a work licensed
        under version 3 of the GNU Affero General Public License into a single
        combined work, and to convey the resulting work.  The terms of this
        License will continue to apply to the part which is the covered work,
        but the special requirements of the GNU Affero General Public License,
        section 13, concerning interaction through a network will apply to the
        combination as such.
        
          14. Revised Versions of this License.
        
          The Free Software Foundation may publish revised and/or new versions of
        the GNU General Public License from time to time.  Such new versions will
        be similar in spirit to the present version, but may differ in detail to
        address new problems or concerns.
        
          Each version is given a distinguishing version number.  If the
        Program specifies that a certain numbered version of the GNU General
        Public License "or any later version" applies to it, you have the
        option of following the terms and conditions either of that numbered
        version or of any later version published by the Free Software
        Foundation.  If the Program does not specify a version number of the
        GNU General Public License, you may choose any version ever published
        by the Free Software Foundation.
        
          If the Program specifies that a proxy can decide which future
        versions of the GNU General Public License can be used, that proxy's
        public statement of acceptance of a version permanently authorizes you
        to choose that version for the Program.
        
          Later license versions may give you additional or different
        permissions.  However, no additional obligations are imposed on any
        author or copyright holder as a result of your choosing to follow a
        later version.
        
          15. Disclaimer of Warranty.
        
          THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
        APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
        HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
        OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
        THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
        PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
        IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
        ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
        
          16. Limitation of Liability.
        
          IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
        WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
        THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
        GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
        USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
        DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
        PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
        EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
        SUCH DAMAGES.
        
          17. Interpretation of Sections 15 and 16.
        
          If the disclaimer of warranty and limitation of liability provided
        above cannot be given local legal effect according to their terms,
        reviewing courts shall apply local law that most closely approximates
        an absolute waiver of all civil liability in connection with the
        Program, unless a warranty or assumption of liability accompanies a
        copy of the Program in return for a fee.
        
                             END OF TERMS AND CONDITIONS
        
                    How to Apply These Terms to Your New Programs
        
          If you develop a new program, and you want it to be of the greatest
        possible use to the public, the best way to achieve this is to make it
        free software which everyone can redistribute and change under these terms.
        
          To do so, attach the following notices to the program.  It is safest
        to attach them to the start of each source file to most effectively
        state the exclusion of warranty; and each file should have at least
        the "copyright" line and a pointer to where the full notice is found.
        
            <one line to give the program's name and a brief idea of what it does.>
            Copyright (C) <year>  <name of author>
        
            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 <http://www.gnu.org/licenses/>.
        
        Also add information on how to contact you by electronic and paper mail.
        
          If the program does terminal interaction, make it output a short
        notice like this when it starts in an interactive mode:
        
            <program>  Copyright (C) <year>  <name of author>
            This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
            This is free software, and you are welcome to redistribute it
            under certain conditions; type `show c' for details.
        
        The hypothetical commands `show w' and `show c' should show the appropriate
        parts of the General Public License.  Of course, your program's commands
        might be different; for a GUI interface, you would use an "about box".
        
          You should also get your employer (if you work as a programmer) or school,
        if any, to sign a "copyright disclaimer" for the program, if necessary.
        For more information on this, and how to apply and follow the GNU GPL, see
        <http://www.gnu.org/licenses/>.
        
          The GNU General Public License does not permit incorporating your program
        into proprietary programs.  If your program is a subroutine library, you
        may consider it more useful to permit linking proprietary applications with
        the library.  If this is what you want to do, use the GNU Lesser General
        Public License instead of this License.  But first, please read
        <http://www.gnu.org/philosophy/why-not-lgpl.html>.
        
        */

        File 3 of 5: MainnetSettler
        // SPDX-License-Identifier: MIT
        pragma solidity >=0.6.2 >=0.8.25 ^0.8.17 ^0.8.25;
        // lib/forge-std/src/interfaces/IERC20.sol
        /// @dev Interface of the ERC20 standard as defined in the EIP.
        /// @dev This includes the optional name, symbol, and decimals metadata.
        interface IERC20 {
            /// @dev Emitted when `value` tokens are moved from one account (`from`) to another (`to`).
            event Transfer(address indexed from, address indexed to, uint256 value);
            /// @dev Emitted when the allowance of a `spender` for an `owner` is set, where `value`
            /// is the new allowance.
            event Approval(address indexed owner, address indexed spender, uint256 value);
            /// @notice Returns the amount of tokens in existence.
            function totalSupply() external view returns (uint256);
            /// @notice Returns the amount of tokens owned by `account`.
            function balanceOf(address account) external view returns (uint256);
            /// @notice Moves `amount` tokens from the caller's account to `to`.
            function transfer(address to, uint256 amount) external returns (bool);
            /// @notice Returns the remaining number of tokens that `spender` is allowed
            /// to spend on behalf of `owner`
            function allowance(address owner, address spender) external view returns (uint256);
            /// @notice Sets `amount` as the allowance of `spender` over the caller's tokens.
            /// @dev Be aware of front-running risks: https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
            function approve(address spender, uint256 amount) external returns (bool);
            /// @notice Moves `amount` tokens from `from` to `to` using the allowance mechanism.
            /// `amount` is then deducted from the caller's allowance.
            function transferFrom(address from, address to, uint256 amount) external returns (bool);
            /// @notice Returns the name of the token.
            function name() external view returns (string memory);
            /// @notice Returns the symbol of the token.
            function symbol() external view returns (string memory);
            /// @notice Returns the decimals places of the token.
            function decimals() external view returns (uint8);
        }
        // lib/permit2/src/interfaces/IEIP712.sol
        interface IEIP712 {
            function DOMAIN_SEPARATOR() external view returns (bytes32);
        }
        // src/Context.sol
        abstract contract AbstractContext {
            function _msgSender() internal view virtual returns (address);
            function _msgData() internal view virtual returns (bytes calldata);
            function _isForwarded() internal view virtual returns (bool);
        }
        abstract contract Context is AbstractContext {
            function _msgSender() internal view virtual override returns (address) {
                return msg.sender;
            }
            function _msgData() internal view virtual override returns (bytes calldata) {
                return msg.data;
            }
            function _isForwarded() internal view virtual override returns (bool) {
                return false;
            }
        }
        // src/IERC721Owner.sol
        interface IERC721Owner {
            function ownerOf(uint256) external view returns (address);
        }
        // src/allowanceholder/IAllowanceHolder.sol
        interface IAllowanceHolder {
            /// @notice Executes against `target` with the `data` payload. Prior to execution, token permits
            ///         are temporarily stored for the duration of the transaction. These permits can be
            ///         consumed by the `operator` during the execution
            /// @notice `operator` consumes the funds during its operations by calling back into
            ///         `AllowanceHolder` with `transferFrom`, consuming a token permit.
            /// @dev Neither `exec` nor `transferFrom` check that `token` contains code.
            /// @dev msg.sender is forwarded to target appended to the msg data (similar to ERC-2771)
            /// @param operator An address which is allowed to consume the token permits
            /// @param token The ERC20 token the caller has authorised to be consumed
            /// @param amount The quantity of `token` the caller has authorised to be consumed
            /// @param target A contract to execute operations with `data`
            /// @param data The data to forward to `target`
            /// @return result The returndata from calling `target` with `data`
            /// @notice If calling `target` with `data` reverts, the revert is propagated
            function exec(address operator, address token, uint256 amount, address payable target, bytes calldata data)
                external
                payable
                returns (bytes memory result);
            /// @notice The counterpart to `exec` which allows for the consumption of token permits later
            ///         during execution
            /// @dev *DOES NOT* check that `token` contains code. This function vacuously succeeds if
            ///      `token` is empty.
            /// @dev can only be called by the `operator` previously registered in `exec`
            /// @param token The ERC20 token to transfer
            /// @param owner The owner of tokens to transfer
            /// @param recipient The destination/beneficiary of the ERC20 `transferFrom`
            /// @param amount The quantity of `token` to transfer`
            /// @return true
            function transferFrom(address token, address owner, address recipient, uint256 amount) external returns (bool);
        }
        // src/core/univ3forks/PancakeSwapV3.sol
        address constant pancakeSwapV3Factory = 0x41ff9AA7e16B8B1a8a8dc4f0eFacd93D02d071c9;
        bytes32 constant pancakeSwapV3InitHash = 0x6ce8eb472fa82df5469c6ab6d485f17c3ad13c8cd7af59b3d4a8026c5ce0f7e2;
        uint8 constant pancakeSwapV3ForkId = 1;
        interface IPancakeSwapV3Callback {
            function pancakeV3SwapCallback(int256 amount0Delta, int256 amount1Delta, bytes calldata data) external;
        }
        // src/core/univ3forks/SolidlyV3.sol
        address constant solidlyV3Factory = 0x70Fe4a44EA505cFa3A57b95cF2862D4fd5F0f687;
        bytes32 constant solidlyV3InitHash = 0xe9b68c5f77858eecac2e651646e208175e9b1359d68d0e14fc69f8c54e5010bf;
        uint8 constant solidlyV3ForkId = 3;
        interface ISolidlyV3Callback {
            function solidlyV3SwapCallback(int256 amount0Delta, int256 amount1Delta, bytes calldata data) external;
        }
        // src/core/univ3forks/SushiswapV3.sol
        address constant sushiswapV3MainnetFactory = 0xbACEB8eC6b9355Dfc0269C18bac9d6E2Bdc29C4F;
        address constant sushiswapV3Factory = 0xc35DADB65012eC5796536bD9864eD8773aBc74C4; // Base, Linea
        address constant sushiswapV3ArbitrumFactory = 0x1af415a1EbA07a4986a52B6f2e7dE7003D82231e;
        //address constant sushiswapV3AvalancheFactory = 0x3e603C14aF37EBdaD31709C4f848Fc6aD5BEc715;
        //address constant sushiswapV3BlastFactory = 0x7680D4B43f3d1d54d6cfEeB2169463bFa7a6cf0d;
        //address constant sushiswapV3BnbFactory = 0x126555dd55a39328F69400d6aE4F782Bd4C34ABb;
        address constant sushiswapV3OptimismFactory = 0x9c6522117e2ed1fE5bdb72bb0eD5E3f2bdE7DBe0;
        address constant sushiswapV3PolygonFactory = 0x917933899c6a5F8E37F31E19f92CdBFF7e8FF0e2;
        address constant sushiswapV3ScrollFactory = 0x46B3fDF7b5CDe91Ac049936bF0bDb12c5d22202e;
        //bytes32 constant sushiswapV3BlastInitHash = 0x8e13daee7f5a62e37e71bf852bcd44e7d16b90617ed2b17c24c2ee62411c5bae;
        uint8 constant sushiswapV3ForkId = 2;
        // src/core/univ3forks/UniswapV3.sol
        address constant uniswapV3MainnetFactory = 0x1F98431c8aD98523631AE4a59f267346ea31F984;
        address constant uniswapV3SepoliaFactory = 0x0227628f3F023bb0B980b67D528571c95c6DaC1c;
        address constant uniswapV3BaseFactory = 0x33128a8fC17869897dcE68Ed026d694621f6FDfD;
        address constant uniswapV3BnbFactory = 0xdB1d10011AD0Ff90774D0C6Bb92e5C5c8b4461F7;
        address constant uniswapV3AvalancheFactory = 0x740b1c1de25031C31FF4fC9A62f554A55cdC1baD;
        address constant uniswapV3BlastFactory = 0x792edAdE80af5fC680d96a2eD80A44247D2Cf6Fd;
        address constant uniswapV3ScrollFactory = 0x70C62C8b8e801124A4Aa81ce07b637A3e83cb919;
        address constant uniswapV3LineaFactory = 0x31FAfd4889FA1269F7a13A66eE0fB458f27D72A9;
        address constant uniswapV3MantleFactory = 0x0d922Fb1Bc191F64970ac40376643808b4B74Df9;
        bytes32 constant uniswapV3InitHash = 0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54;
        uint8 constant uniswapV3ForkId = 0;
        interface IUniswapV3Callback {
            function uniswapV3SwapCallback(int256 amount0Delta, int256 amount1Delta, bytes calldata data) external;
        }
        // src/utils/FreeMemory.sol
        abstract contract FreeMemory {
            modifier DANGEROUS_freeMemory() {
                uint256 freeMemPtr;
                assembly ("memory-safe") {
                    freeMemPtr := mload(0x40)
                }
                _;
                assembly ("memory-safe") {
                    mstore(0x40, freeMemPtr)
                }
            }
        }
        // src/utils/Panic.sol
        library Panic {
            function panic(uint256 code) internal pure {
                assembly ("memory-safe") {
                    mstore(0x00, 0x4e487b71) // selector for `Panic(uint256)`
                    mstore(0x20, code)
                    revert(0x1c, 0x24)
                }
            }
            // https://docs.soliditylang.org/en/latest/control-structures.html#panic-via-assert-and-error-via-require
            uint8 internal constant GENERIC = 0x00;
            uint8 internal constant ASSERT_FAIL = 0x01;
            uint8 internal constant ARITHMETIC_OVERFLOW = 0x11;
            uint8 internal constant DIVISION_BY_ZERO = 0x12;
            uint8 internal constant ENUM_CAST = 0x21;
            uint8 internal constant CORRUPT_STORAGE_ARRAY = 0x22;
            uint8 internal constant POP_EMPTY_ARRAY = 0x31;
            uint8 internal constant ARRAY_OUT_OF_BOUNDS = 0x32;
            uint8 internal constant OUT_OF_MEMORY = 0x41;
            uint8 internal constant ZERO_FUNCTION_POINTER = 0x51;
        }
        // src/utils/Revert.sol
        library Revert {
            function _revert(bytes memory reason) internal pure {
                assembly ("memory-safe") {
                    revert(add(reason, 0x20), mload(reason))
                }
            }
            function maybeRevert(bool success, bytes memory reason) internal pure {
                if (!success) {
                    _revert(reason);
                }
            }
        }
        // src/utils/UnsafeMath.sol
        library UnsafeMath {
            function unsafeInc(uint256 x) internal pure returns (uint256) {
                unchecked {
                    return x + 1;
                }
            }
            function unsafeInc(int256 x) internal pure returns (int256) {
                unchecked {
                    return x + 1;
                }
            }
            function unsafeNeg(int256 x) internal pure returns (int256) {
                unchecked {
                    return -x;
                }
            }
            function unsafeDiv(uint256 numerator, uint256 denominator) internal pure returns (uint256 quotient) {
                assembly ("memory-safe") {
                    quotient := div(numerator, denominator)
                }
            }
            function unsafeDiv(int256 numerator, int256 denominator) internal pure returns (int256 quotient) {
                assembly ("memory-safe") {
                    quotient := sdiv(numerator, denominator)
                }
            }
            function unsafeMod(uint256 numerator, uint256 denominator) internal pure returns (uint256 remainder) {
                assembly ("memory-safe") {
                    remainder := mod(numerator, denominator)
                }
            }
            function unsafeMod(int256 numerator, int256 denominator) internal pure returns (int256 remainder) {
                assembly ("memory-safe") {
                    remainder := smod(numerator, denominator)
                }
            }
            function unsafeMulMod(uint256 a, uint256 b, uint256 m) internal pure returns (uint256 r) {
                assembly ("memory-safe") {
                    r := mulmod(a, b, m)
                }
            }
            function unsafeAddMod(uint256 a, uint256 b, uint256 m) internal pure returns (uint256 r) {
                assembly ("memory-safe") {
                    r := addmod(a, b, m)
                }
            }
        }
        // lib/permit2/src/interfaces/ISignatureTransfer.sol
        /// @title SignatureTransfer
        /// @notice Handles ERC20 token transfers through signature based actions
        /// @dev Requires user's token approval on the Permit2 contract
        interface ISignatureTransfer is IEIP712 {
            /// @notice Thrown when the requested amount for a transfer is larger than the permissioned amount
            /// @param maxAmount The maximum amount a spender can request to transfer
            error InvalidAmount(uint256 maxAmount);
            /// @notice Thrown when the number of tokens permissioned to a spender does not match the number of tokens being transferred
            /// @dev If the spender does not need to transfer the number of tokens permitted, the spender can request amount 0 to be transferred
            error LengthMismatch();
            /// @notice Emits an event when the owner successfully invalidates an unordered nonce.
            event UnorderedNonceInvalidation(address indexed owner, uint256 word, uint256 mask);
            /// @notice The token and amount details for a transfer signed in the permit transfer signature
            struct TokenPermissions {
                // ERC20 token address
                address token;
                // the maximum amount that can be spent
                uint256 amount;
            }
            /// @notice The signed permit message for a single token transfer
            struct PermitTransferFrom {
                TokenPermissions permitted;
                // a unique value for every token owner's signature to prevent signature replays
                uint256 nonce;
                // deadline on the permit signature
                uint256 deadline;
            }
            /// @notice Specifies the recipient address and amount for batched transfers.
            /// @dev Recipients and amounts correspond to the index of the signed token permissions array.
            /// @dev Reverts if the requested amount is greater than the permitted signed amount.
            struct SignatureTransferDetails {
                // recipient address
                address to;
                // spender requested amount
                uint256 requestedAmount;
            }
            /// @notice Used to reconstruct the signed permit message for multiple token transfers
            /// @dev Do not need to pass in spender address as it is required that it is msg.sender
            /// @dev Note that a user still signs over a spender address
            struct PermitBatchTransferFrom {
                // the tokens and corresponding amounts permitted for a transfer
                TokenPermissions[] permitted;
                // a unique value for every token owner's signature to prevent signature replays
                uint256 nonce;
                // deadline on the permit signature
                uint256 deadline;
            }
            /// @notice A map from token owner address and a caller specified word index to a bitmap. Used to set bits in the bitmap to prevent against signature replay protection
            /// @dev Uses unordered nonces so that permit messages do not need to be spent in a certain order
            /// @dev The mapping is indexed first by the token owner, then by an index specified in the nonce
            /// @dev It returns a uint256 bitmap
            /// @dev The index, or wordPosition is capped at type(uint248).max
            function nonceBitmap(address, uint256) external view returns (uint256);
            /// @notice Transfers a token using a signed permit message
            /// @dev Reverts if the requested amount is greater than the permitted signed amount
            /// @param permit The permit data signed over by the owner
            /// @param owner The owner of the tokens to transfer
            /// @param transferDetails The spender's requested transfer details for the permitted token
            /// @param signature The signature to verify
            function permitTransferFrom(
                PermitTransferFrom memory permit,
                SignatureTransferDetails calldata transferDetails,
                address owner,
                bytes calldata signature
            ) external;
            /// @notice Transfers a token using a signed permit message
            /// @notice Includes extra data provided by the caller to verify signature over
            /// @dev The witness type string must follow EIP712 ordering of nested structs and must include the TokenPermissions type definition
            /// @dev Reverts if the requested amount is greater than the permitted signed amount
            /// @param permit The permit data signed over by the owner
            /// @param owner The owner of the tokens to transfer
            /// @param transferDetails The spender's requested transfer details for the permitted token
            /// @param witness Extra data to include when checking the user signature
            /// @param witnessTypeString The EIP-712 type definition for remaining string stub of the typehash
            /// @param signature The signature to verify
            function permitWitnessTransferFrom(
                PermitTransferFrom memory permit,
                SignatureTransferDetails calldata transferDetails,
                address owner,
                bytes32 witness,
                string calldata witnessTypeString,
                bytes calldata signature
            ) external;
            /// @notice Transfers multiple tokens using a signed permit message
            /// @param permit The permit data signed over by the owner
            /// @param owner The owner of the tokens to transfer
            /// @param transferDetails Specifies the recipient and requested amount for the token transfer
            /// @param signature The signature to verify
            function permitTransferFrom(
                PermitBatchTransferFrom memory permit,
                SignatureTransferDetails[] calldata transferDetails,
                address owner,
                bytes calldata signature
            ) external;
            /// @notice Transfers multiple tokens using a signed permit message
            /// @dev The witness type string must follow EIP712 ordering of nested structs and must include the TokenPermissions type definition
            /// @notice Includes extra data provided by the caller to verify signature over
            /// @param permit The permit data signed over by the owner
            /// @param owner The owner of the tokens to transfer
            /// @param transferDetails Specifies the recipient and requested amount for the token transfer
            /// @param witness Extra data to include when checking the user signature
            /// @param witnessTypeString The EIP-712 type definition for remaining string stub of the typehash
            /// @param signature The signature to verify
            function permitWitnessTransferFrom(
                PermitBatchTransferFrom memory permit,
                SignatureTransferDetails[] calldata transferDetails,
                address owner,
                bytes32 witness,
                string calldata witnessTypeString,
                bytes calldata signature
            ) external;
            /// @notice Invalidates the bits specified in mask for the bitmap at the word position
            /// @dev The wordPos is maxed at type(uint248).max
            /// @param wordPos A number to index the nonceBitmap at
            /// @param mask A bitmap masked against msg.sender's current bitmap at the word position
            function invalidateUnorderedNonces(uint256 wordPos, uint256 mask) external;
        }
        // src/core/SettlerErrors.sol
        /// @notice Thrown when an offset is not the expected value
        error InvalidOffset();
        /// @notice Thrown when a validating a target contract to avoid certain types of targets
        error ConfusedDeputy();
        /// @notice Thrown when a target contract is invalid given the context
        error InvalidTarget();
        /// @notice Thrown when validating the caller against the expected caller
        error InvalidSender();
        /// @notice Thrown in cases when using a Trusted Forwarder / AllowanceHolder is not allowed
        error ForwarderNotAllowed();
        /// @notice Thrown when a signature length is not the expected length
        error InvalidSignatureLen();
        /// @notice Thrown when a slippage limit is exceeded
        error TooMuchSlippage(IERC20 token, uint256 expected, uint256 actual);
        /// @notice Thrown when a byte array that is supposed to encode a function from ISettlerActions is
        ///         not recognized in context.
        error ActionInvalid(uint256 i, bytes4 action, bytes data);
        /// @notice Thrown when the encoded fork ID as part of UniswapV3 fork path is not on the list of
        ///         recognized forks for this chain.
        error UnknownForkId(uint8 forkId);
        /// @notice Thrown when an AllowanceHolder transfer's permit is past its deadline
        error SignatureExpired(uint256 deadline);
        /// @notice An internal error that should never be thrown. Thrown when a callback reenters the
        ///         entrypoint and attempts to clobber the existing callback.
        error ReentrantCallback(uint256 callbackInt);
        /// @notice An internal error that should never be thrown. This error can only be thrown by
        ///         non-metatx-supporting Settler instances. Thrown when a callback-requiring liquidity
        ///         source is called, but Settler never receives the callback.
        error CallbackNotSpent(uint256 callbackInt);
        /// @notice Thrown when a metatransaction has reentrancy.
        error ReentrantMetatransaction(bytes32 oldWitness);
        /// @notice Thrown when any transaction has reentrancy, not just taker-submitted or metatransaction.
        error ReentrantPayer(address oldPayer);
        /// @notice An internal error that should never be thrown. Thrown when a metatransaction fails to
        ///         spend a coupon.
        error WitnessNotSpent(bytes32 oldWitness);
        /// @notice An internal error that should never be thrown. Thrown when the payer is unset
        ///         unexpectedly.
        error PayerSpent();
        // src/vendor/SafeTransferLib.sol
        /// @notice Safe ETH and ERC20 transfer library that gracefully handles missing return values.
        /// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/SafeTransferLib.sol)
        /// @dev Use with caution! Some functions in this library knowingly create dirty bits at the destination of the free memory pointer.
        /// @dev Note that none of the functions in this library check that a token has code at all! That responsibility is delegated to the caller.
        library SafeTransferLib {
            uint32 private constant _TRANSFER_FROM_FAILED_SELECTOR = 0x7939f424; // bytes4(keccak256("TransferFromFailed()"))
            uint32 private constant _TRANSFER_FAILED_SELECTOR = 0x90b8ec18; // bytes4(keccak256("TransferFailed()"))
            uint32 private constant _APPROVE_FAILED_SELECTOR = 0x3e3f8f73; // bytes4(keccak256("ApproveFailed()"))
            /*//////////////////////////////////////////////////////////////
                                     ETH OPERATIONS
            //////////////////////////////////////////////////////////////*/
            function safeTransferETH(address payable to, uint256 amount) internal {
                assembly ("memory-safe") {
                    // Transfer the ETH and store if it succeeded or not.
                    if iszero(call(gas(), to, amount, 0, 0, 0, 0)) {
                        let freeMemoryPointer := mload(0x40)
                        returndatacopy(freeMemoryPointer, 0, returndatasize())
                        revert(freeMemoryPointer, returndatasize())
                    }
                }
            }
            /*//////////////////////////////////////////////////////////////
                                    ERC20 OPERATIONS
            //////////////////////////////////////////////////////////////*/
            function safeTransferFrom(IERC20 token, address from, address to, uint256 amount) internal {
                assembly ("memory-safe") {
                    // Get a pointer to some free memory.
                    let freeMemoryPointer := mload(0x40)
                    // Write the abi-encoded calldata into memory, beginning with the function selector.
                    mstore(freeMemoryPointer, 0x23b872dd00000000000000000000000000000000000000000000000000000000)
                    mstore(add(freeMemoryPointer, 4), and(from, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "from" argument.
                    mstore(add(freeMemoryPointer, 36), and(to, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "to" argument.
                    mstore(add(freeMemoryPointer, 68), amount) // Append the "amount" argument. Masking not required as it's a full 32 byte type.
                    // We use 100 because the length of our calldata totals up like so: 4 + 32 * 3.
                    // We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
                    if iszero(call(gas(), token, 0, freeMemoryPointer, 100, 0, 32)) {
                        returndatacopy(freeMemoryPointer, 0, returndatasize())
                        revert(freeMemoryPointer, returndatasize())
                    }
                    // We check that the call either returned exactly 1 (can't just be non-zero data), or had no
                    // return data.
                    if iszero(or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize()))) {
                        mstore(0, _TRANSFER_FROM_FAILED_SELECTOR)
                        revert(0x1c, 0x04)
                    }
                }
            }
            function safeTransfer(IERC20 token, address to, uint256 amount) internal {
                assembly ("memory-safe") {
                    // Get a pointer to some free memory.
                    let freeMemoryPointer := mload(0x40)
                    // Write the abi-encoded calldata into memory, beginning with the function selector.
                    mstore(freeMemoryPointer, 0xa9059cbb00000000000000000000000000000000000000000000000000000000)
                    mstore(add(freeMemoryPointer, 4), and(to, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "to" argument.
                    mstore(add(freeMemoryPointer, 36), amount) // Append the "amount" argument. Masking not required as it's a full 32 byte type.
                    // We use 68 because the length of our calldata totals up like so: 4 + 32 * 2.
                    // We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
                    if iszero(call(gas(), token, 0, freeMemoryPointer, 68, 0, 32)) {
                        returndatacopy(freeMemoryPointer, 0, returndatasize())
                        revert(freeMemoryPointer, returndatasize())
                    }
                    // We check that the call either returned exactly 1 (can't just be non-zero data), or had no
                    // return data.
                    if iszero(or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize()))) {
                        mstore(0, _TRANSFER_FAILED_SELECTOR)
                        revert(0x1c, 0x04)
                    }
                }
            }
            function safeApprove(IERC20 token, address to, uint256 amount) internal {
                assembly ("memory-safe") {
                    // Get a pointer to some free memory.
                    let freeMemoryPointer := mload(0x40)
                    // Write the abi-encoded calldata into memory, beginning with the function selector.
                    mstore(freeMemoryPointer, 0x095ea7b300000000000000000000000000000000000000000000000000000000)
                    mstore(add(freeMemoryPointer, 4), and(to, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "to" argument.
                    mstore(add(freeMemoryPointer, 36), amount) // Append the "amount" argument. Masking not required as it's a full 32 byte type.
                    // We use 68 because the length of our calldata totals up like so: 4 + 32 * 2.
                    // We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
                    if iszero(call(gas(), token, 0, freeMemoryPointer, 68, 0, 32)) {
                        returndatacopy(freeMemoryPointer, 0, returndatasize())
                        revert(freeMemoryPointer, returndatasize())
                    }
                    // We check that the call either returned exactly 1 (can't just be non-zero data), or had no
                    // return data.
                    if iszero(or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize()))) {
                        mstore(0, _APPROVE_FAILED_SELECTOR)
                        revert(0x1c, 0x04)
                    }
                }
            }
            function safeApproveIfBelow(IERC20 token, address spender, uint256 amount) internal {
                uint256 allowance = token.allowance(address(this), spender);
                if (allowance < amount) {
                    if (allowance != 0) {
                        safeApprove(token, spender, 0);
                    }
                    safeApprove(token, spender, type(uint256).max);
                }
            }
        }
        // src/ISettlerActions.sol
        interface ISettlerActions {
            /// @dev Transfer funds from msg.sender Permit2.
            function TRANSFER_FROM(address recipient, ISignatureTransfer.PermitTransferFrom memory permit, bytes memory sig)
                external;
            /// @dev Transfer funds from metatransaction requestor into the Settler contract using Permit2. Only for use in `Settler.executeMetaTxn` where the signature is provided as calldata
            function METATXN_TRANSFER_FROM(address recipient, ISignatureTransfer.PermitTransferFrom memory permit) external;
            /// @dev Settle an RfqOrder between maker and taker transfering funds directly between the parties
            // Post-req: Payout if recipient != taker
            function RFQ_VIP(
                address recipient,
                ISignatureTransfer.PermitTransferFrom memory makerPermit,
                address maker,
                bytes memory makerSig,
                ISignatureTransfer.PermitTransferFrom memory takerPermit,
                bytes memory takerSig
            ) external;
            /// @dev Settle an RfqOrder between maker and taker transfering funds directly between the parties for the entire amount
            function METATXN_RFQ_VIP(
                address recipient,
                ISignatureTransfer.PermitTransferFrom memory makerPermit,
                address maker,
                bytes memory makerSig,
                ISignatureTransfer.PermitTransferFrom memory takerPermit
            ) external;
            /// @dev Settle an RfqOrder between Maker and Settler. Transfering funds from the Settler contract to maker.
            /// Retaining funds in the settler contract.
            // Pre-req: Funded
            // Post-req: Payout
            function RFQ(
                address recipient,
                ISignatureTransfer.PermitTransferFrom memory permit,
                address maker,
                bytes memory makerSig,
                address takerToken,
                uint256 maxTakerAmount
            ) external;
            /// @dev Trades against UniswapV3 using the contracts balance for funding
            // Pre-req: Funded
            // Post-req: Payout
            function UNISWAPV3(address recipient, uint256 bps, bytes memory path, uint256 amountOutMin) external;
            /// @dev Trades against UniswapV3 using user funds via Permit2 for funding
            function UNISWAPV3_VIP(
                address recipient,
                bytes memory path,
                ISignatureTransfer.PermitTransferFrom memory permit,
                bytes memory sig,
                uint256 amountOutMin
            ) external;
            function MAKERPSM(address recipient, address gemToken, uint256 bps, address psm, bool buyGem, uint256 amountOutMin)
                external;
            function CURVE_TRICRYPTO_VIP(
                address recipient,
                uint80 poolInfo,
                ISignatureTransfer.PermitTransferFrom memory permit,
                bytes memory sig,
                uint256 minBuyAmount
            ) external;
            function METATXN_CURVE_TRICRYPTO_VIP(
                address recipient,
                uint80 poolInfo,
                ISignatureTransfer.PermitTransferFrom memory permit,
                uint256 minBuyAmount
            ) external;
            function DODOV1(address sellToken, uint256 bps, address pool, bool quoteForBase, uint256 minBuyAmount) external;
            function DODOV2(
                address recipient,
                address sellToken,
                uint256 bps,
                address pool,
                bool quoteForBase,
                uint256 minBuyAmount
            ) external;
            function VELODROME(address recipient, uint256 bps, address pool, uint24 swapInfo, uint256 minBuyAmount) external;
            /// @dev Trades against UniswapV3 using user funds via Permit2 for funding. Metatransaction variant. Signature is over all actions.
            function METATXN_UNISWAPV3_VIP(
                address recipient,
                bytes memory path,
                ISignatureTransfer.PermitTransferFrom memory permit,
                uint256 amountOutMin
            ) external;
            /// @dev Trades against MaverickV2 using the contracts balance for funding
            /// This action does not use the MaverickV2 callback, so it takes an arbitrary pool address to make calls against.
            /// Passing `tokenAIn` as a parameter actually saves gas relative to introspecting the pool's `tokenA()` accessor.
            function MAVERICKV2(
                address recipient,
                address sellToken,
                uint256 bps,
                address pool,
                bool tokenAIn,
                uint256 minBuyAmount
            ) external;
            /// @dev Trades against MaverickV2, spending the taker's coupon inside the callback
            /// This action requires the use of the MaverickV2 callback, so we take the MaverickV2 CREATE2 salt as an argument to derive the pool address from the trusted factory and inithash.
            /// @param salt is formed as `keccak256(abi.encode(feeAIn, feeBIn, tickSpacing, lookback, tokenA, tokenB, kinds, address(0)))`
            function MAVERICKV2_VIP(
                address recipient,
                bytes32 salt,
                bool tokenAIn,
                ISignatureTransfer.PermitTransferFrom memory permit,
                bytes memory sig,
                uint256 minBuyAmount
            ) external;
            /// @dev Trades against MaverickV2, spending the taker's coupon inside the callback; metatransaction variant
            function METATXN_MAVERICKV2_VIP(
                address recipient,
                bytes32 salt,
                bool tokenAIn,
                ISignatureTransfer.PermitTransferFrom memory permit,
                uint256 minBuyAmount
            ) external;
            /// @dev Trades against UniswapV2 using the contracts balance for funding
            /// @param swapInfo is encoded as the upper 16 bits as the fee of the pool in bps, the second
            ///                 lowest bit as "sell token has transfer fee", and the lowest bit as the
            ///                 "token0 for token1" flag.
            function UNISWAPV2(
                address recipient,
                address sellToken,
                uint256 bps,
                address pool,
                uint24 swapInfo,
                uint256 amountOutMin
            ) external;
            function POSITIVE_SLIPPAGE(address recipient, address token, uint256 expectedAmount) external;
            /// @dev Trades against a basic AMM which follows the approval, transferFrom(msg.sender) interaction
            // Pre-req: Funded
            // Post-req: Payout
            function BASIC(address sellToken, uint256 bps, address pool, uint256 offset, bytes calldata data) external;
        }
        // src/allowanceholder/AllowanceHolderContext.sol
        abstract contract AllowanceHolderContext is Context {
            IAllowanceHolder internal constant _ALLOWANCE_HOLDER = IAllowanceHolder(0x0000000000001fF3684f28c67538d4D072C22734);
            function _isForwarded() internal view virtual override returns (bool) {
                return super._isForwarded() || super._msgSender() == address(_ALLOWANCE_HOLDER);
            }
            function _msgSender() internal view virtual override returns (address sender) {
                sender = super._msgSender();
                if (sender == address(_ALLOWANCE_HOLDER)) {
                    // ERC-2771 like usage where the _trusted_ `AllowanceHolder` has appended the appropriate
                    // msg.sender to the msg data
                    assembly ("memory-safe") {
                        sender := shr(0x60, calldataload(sub(calldatasize(), 0x14)))
                    }
                }
            }
            // this is here to avoid foot-guns and make it very explicit that we intend
            // to pass the confused deputy check in AllowanceHolder
            function balanceOf(address) external pure {
                assembly ("memory-safe") {
                    mstore8(0x00, 0x00)
                    return(0x00, 0x01)
                }
            }
        }
        // src/utils/AddressDerivation.sol
        library AddressDerivation {
            using UnsafeMath for uint256;
            uint256 internal constant _SECP256K1_P = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F;
            uint256 internal constant _SECP256K1_N = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141;
            uint256 internal constant SECP256K1_GX = 0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798;
            uint256 internal constant SECP256K1_GY = 0x483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8;
            error InvalidCurve(uint256 x, uint256 y);
            // keccak256(abi.encodePacked(ECMUL([x, y], k)))[12:]
            function deriveEOA(uint256 x, uint256 y, uint256 k) internal pure returns (address) {
                if (k == 0) {
                    Panic.panic(Panic.DIVISION_BY_ZERO);
                }
                if (k >= _SECP256K1_N || x >= _SECP256K1_P || y >= _SECP256K1_P) {
                    Panic.panic(Panic.ARITHMETIC_OVERFLOW);
                }
                // +/-7 are neither square nor cube mod p, so we only have to check one
                // coordinate against 0. if it is 0, then the other is too (the point at
                // infinity) or the point is invalid
                if (
                    x == 0
                        || y.unsafeMulMod(y, _SECP256K1_P)
                            != x.unsafeMulMod(x, _SECP256K1_P).unsafeMulMod(x, _SECP256K1_P).unsafeAddMod(7, _SECP256K1_P)
                ) {
                    revert InvalidCurve(x, y);
                }
                unchecked {
                    // https://ethresear.ch/t/you-can-kinda-abuse-ecrecover-to-do-ecmul-in-secp256k1-today/2384
                    return ecrecover(
                        bytes32(0), uint8(27 + (y & 1)), bytes32(x), bytes32(UnsafeMath.unsafeMulMod(x, k, _SECP256K1_N))
                    );
                }
            }
            // keccak256(RLP([deployer, nonce]))[12:]
            function deriveContract(address deployer, uint64 nonce) internal pure returns (address result) {
                if (nonce == 0) {
                    assembly ("memory-safe") {
                        mstore(
                            0x00,
                            or(
                                0xd694000000000000000000000000000000000000000080,
                                shl(8, and(0xffffffffffffffffffffffffffffffffffffffff, deployer))
                            )
                        )
                        result := keccak256(0x09, 0x17)
                    }
                } else if (nonce < 0x80) {
                    assembly ("memory-safe") {
                        // we don't care about dirty bits in `deployer`; they'll be overwritten later
                        mstore(0x14, deployer)
                        mstore(0x00, 0xd694)
                        mstore8(0x34, nonce)
                        result := keccak256(0x1e, 0x17)
                    }
                } else {
                    // compute ceil(log_256(nonce)) + 1
                    uint256 nonceLength = 8;
                    unchecked {
                        if ((uint256(nonce) >> 32) != 0) {
                            nonceLength += 32;
                            if (nonce == type(uint64).max) {
                                Panic.panic(Panic.ARITHMETIC_OVERFLOW);
                            }
                        }
                        if ((uint256(nonce) >> 8) >= (1 << nonceLength)) {
                            nonceLength += 16;
                        }
                        if (uint256(nonce) >= (1 << nonceLength)) {
                            nonceLength += 8;
                        }
                        // ceil
                        if ((uint256(nonce) << 8) >= (1 << nonceLength)) {
                            nonceLength += 8;
                        }
                        // bytes, not bits
                        nonceLength >>= 3;
                    }
                    assembly ("memory-safe") {
                        // we don't care about dirty bits in `deployer` or `nonce`. they'll be overwritten later
                        mstore(nonceLength, nonce)
                        mstore8(0x20, add(0x7f, nonceLength))
                        mstore(0x00, deployer)
                        mstore8(0x0a, add(0xd5, nonceLength))
                        mstore8(0x0b, 0x94)
                        result := keccak256(0x0a, add(0x16, nonceLength))
                    }
                }
            }
            // keccak256(abi.encodePacked(bytes1(0xff), deployer, salt, initHash))[12:]
            function deriveDeterministicContract(address deployer, bytes32 salt, bytes32 initHash)
                internal
                pure
                returns (address result)
            {
                assembly ("memory-safe") {
                    let ptr := mload(0x40)
                    // we don't care about dirty bits in `deployer`; they'll be overwritten later
                    mstore(ptr, deployer)
                    mstore8(add(ptr, 0x0b), 0xff)
                    mstore(add(ptr, 0x20), salt)
                    mstore(add(ptr, 0x40), initHash)
                    result := keccak256(add(ptr, 0x0b), 0x55)
                }
            }
        }
        // src/vendor/FullMath.sol
        /// @title Contains 512-bit math functions
        /// @notice Facilitates multiplication and division that can have overflow of an intermediate value without any loss of precision
        /// @dev Handles "phantom overflow" i.e., allows multiplication and division where an intermediate value overflows 256 bits
        /// @dev Credit to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv
        library FullMath {
            using UnsafeMath for uint256;
            /// @notice 512-bit multiply [prod1 prod0] = a * b
            /// @param a The multiplicand
            /// @param b The multiplier
            /// @param denominator The divisor
            /// @return prod0 Least significant 256 bits of the product
            /// @return prod1 Most significant 256 bits of the product
            /// @return remainder Remainder of full-precision division
            function _mulDivSetup(uint256 a, uint256 b, uint256 denominator)
                private
                pure
                returns (uint256 prod0, uint256 prod1, uint256 remainder)
            {
                // Compute the product mod 2**256 and mod 2**256 - 1 then use the Chinese
                // Remainder Theorem to reconstruct the 512 bit result. The result is stored
                // in two 256 variables such that product = prod1 * 2**256 + prod0
                assembly ("memory-safe") {
                    // Full-precision multiplication
                    {
                        let mm := mulmod(a, b, 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)
                        prod0 := mul(a, b)
                        prod1 := sub(sub(mm, prod0), lt(mm, prod0))
                    }
                    remainder := mulmod(a, b, denominator)
                }
            }
            /// @notice 512-bit by 256-bit division.
            /// @param prod0 Least significant 256 bits of the product
            /// @param prod1 Most significant 256 bits of the product
            /// @param denominator The divisor
            /// @param remainder Remainder of full-precision division
            /// @return The 256-bit result
            /// @dev Overflow and division by zero aren't checked and are GIGO errors
            function _mulDivInvert(uint256 prod0, uint256 prod1, uint256 denominator, uint256 remainder)
                private
                pure
                returns (uint256)
            {
                uint256 inv;
                assembly ("memory-safe") {
                    // Make division exact by rounding [prod1 prod0] down to a multiple of
                    // denominator
                    // Subtract 256 bit number from 512 bit number
                    prod1 := sub(prod1, gt(remainder, prod0))
                    prod0 := sub(prod0, remainder)
                    // Factor powers of two out of denominator
                    {
                        // Compute largest power of two divisor of denominator.
                        // Always >= 1.
                        let twos := and(sub(0, denominator), denominator)
                        // Divide denominator by power of two
                        denominator := div(denominator, twos)
                        // Divide [prod1 prod0] by the factors of two
                        prod0 := div(prod0, twos)
                        // Shift in bits from prod1 into prod0. For this we need to flip `twos`
                        // such that it is 2**256 / twos.
                        // If twos is zero, then it becomes one
                        twos := add(div(sub(0, twos), twos), 1)
                        prod0 := or(prod0, mul(prod1, twos))
                    }
                    // Invert denominator mod 2**256
                    // Now that denominator is an odd number, it has an inverse modulo 2**256
                    // such that denominator * inv = 1 mod 2**256.
                    // Compute the inverse by starting with a seed that is correct correct for
                    // four bits. That is, denominator * inv = 1 mod 2**4
                    inv := xor(mul(3, denominator), 2)
                    // Now use Newton-Raphson iteration to improve the precision.
                    // Thanks to Hensel's lifting lemma, this also works in modular
                    // arithmetic, doubling the correct bits in each step.
                    inv := mul(inv, sub(2, mul(denominator, inv))) // inverse mod 2**8
                    inv := mul(inv, sub(2, mul(denominator, inv))) // inverse mod 2**16
                    inv := mul(inv, sub(2, mul(denominator, inv))) // inverse mod 2**32
                    inv := mul(inv, sub(2, mul(denominator, inv))) // inverse mod 2**64
                    inv := mul(inv, sub(2, mul(denominator, inv))) // inverse mod 2**128
                    inv := mul(inv, sub(2, mul(denominator, inv))) // inverse mod 2**256
                }
                // Because the division is now exact we can divide by multiplying with the
                // modular inverse of denominator. This will give us the correct result
                // modulo 2**256. Since the precoditions guarantee that the outcome is less
                // than 2**256, this is the final result.  We don't need to compute the high
                // bits of the result and prod1 is no longer required.
                unchecked {
                    return prod0 * inv;
                }
            }
            /// @notice Calculates a×b÷denominator with full precision then rounds towards 0. Throws if result overflows a uint256 or denominator == 0
            /// @param a The multiplicand
            /// @param b The multiplier
            /// @param denominator The divisor
            /// @return The 256-bit result
            function mulDiv(uint256 a, uint256 b, uint256 denominator) internal pure returns (uint256) {
                (uint256 prod0, uint256 prod1, uint256 remainder) = _mulDivSetup(a, b, denominator);
                // Make sure the result is less than 2**256.
                // Also prevents denominator == 0
                if (denominator <= prod1) {
                    Panic.panic(denominator == 0 ? Panic.DIVISION_BY_ZERO : Panic.ARITHMETIC_OVERFLOW);
                }
                // Handle non-overflow cases, 256 by 256 division
                if (prod1 == 0) {
                    return prod0.unsafeDiv(denominator);
                }
                return _mulDivInvert(prod0, prod1, denominator, remainder);
            }
            /// @notice Calculates a×b÷denominator with full precision then rounds towards 0. Overflowing a uint256 or denominator == 0 are GIGO errors
            /// @param a The multiplicand
            /// @param b The multiplier
            /// @param denominator The divisor
            /// @return The 256-bit result
            function unsafeMulDiv(uint256 a, uint256 b, uint256 denominator) internal pure returns (uint256) {
                (uint256 prod0, uint256 prod1, uint256 remainder) = _mulDivSetup(a, b, denominator);
                // Overflow and zero-division checks are skipped
                // Handle non-overflow cases, 256 by 256 division
                if (prod1 == 0) {
                    return prod0.unsafeDiv(denominator);
                }
                return _mulDivInvert(prod0, prod1, denominator, remainder);
            }
        }
        // src/core/Permit2PaymentAbstract.sol
        abstract contract Permit2PaymentAbstract is AbstractContext {
            string internal constant TOKEN_PERMISSIONS_TYPE = "TokenPermissions(address token,uint256 amount)";
            function _isRestrictedTarget(address) internal view virtual returns (bool);
            function _operator() internal view virtual returns (address);
            function _permitToSellAmount(ISignatureTransfer.PermitTransferFrom memory permit)
                internal
                view
                virtual
                returns (uint256 sellAmount);
            function _permitToTransferDetails(ISignatureTransfer.PermitTransferFrom memory permit, address recipient)
                internal
                view
                virtual
                returns (ISignatureTransfer.SignatureTransferDetails memory transferDetails, uint256 sellAmount);
            function _transferFromIKnowWhatImDoing(
                ISignatureTransfer.PermitTransferFrom memory permit,
                ISignatureTransfer.SignatureTransferDetails memory transferDetails,
                address from,
                bytes32 witness,
                string memory witnessTypeString,
                bytes memory sig,
                bool isForwarded
            ) internal virtual;
            function _transferFromIKnowWhatImDoing(
                ISignatureTransfer.PermitTransferFrom memory permit,
                ISignatureTransfer.SignatureTransferDetails memory transferDetails,
                address from,
                bytes32 witness,
                string memory witnessTypeString,
                bytes memory sig
            ) internal virtual;
            function _transferFrom(
                ISignatureTransfer.PermitTransferFrom memory permit,
                ISignatureTransfer.SignatureTransferDetails memory transferDetails,
                bytes memory sig,
                bool isForwarded
            ) internal virtual;
            function _transferFrom(
                ISignatureTransfer.PermitTransferFrom memory permit,
                ISignatureTransfer.SignatureTransferDetails memory transferDetails,
                bytes memory sig
            ) internal virtual;
            function _setOperatorAndCall(
                address target,
                bytes memory data,
                uint32 selector,
                function (bytes calldata) internal returns (bytes memory) callback
            ) internal virtual returns (bytes memory);
            modifier metaTx(address msgSender, bytes32 witness) virtual;
            modifier takerSubmitted() virtual;
            function _allowanceHolderTransferFrom(address token, address owner, address recipient, uint256 amount)
                internal
                virtual;
        }
        // src/SettlerAbstract.sol
        abstract contract SettlerAbstract is Permit2PaymentAbstract {
            // Permit2 Witness for meta transactions
            string internal constant SLIPPAGE_AND_ACTIONS_TYPE =
                "SlippageAndActions(address recipient,address buyToken,uint256 minAmountOut,bytes[] actions)";
            bytes32 internal constant SLIPPAGE_AND_ACTIONS_TYPEHASH =
                0x615e8d716cef7295e75dd3f1f10d679914ad6d7759e8e9459f0109ef75241701;
            uint256 internal constant BASIS = 10_000;
            constructor() {
                assert(SLIPPAGE_AND_ACTIONS_TYPEHASH == keccak256(bytes(SLIPPAGE_AND_ACTIONS_TYPE)));
            }
            function _hasMetaTxn() internal pure virtual returns (bool);
            function _dispatch(uint256 i, bytes4 action, bytes calldata data) internal virtual returns (bool);
        }
        // src/core/MakerPSM.sol
        interface IPSM {
            /// @dev Get the fee for selling DAI to USDC in PSM
            /// @return tout toll out [wad]
            function tout() external view returns (uint256);
            /// @dev Get the address of the underlying vault powering PSM
            /// @return address of gemJoin contract
            function gemJoin() external view returns (address);
            /// @dev Sell USDC for DAI
            /// @param usr The address of the account trading USDC for DAI.
            /// @param gemAmt The amount of USDC to sell in USDC base units
            function sellGem(address usr, uint256 gemAmt) external;
            /// @dev Buy USDC for DAI
            /// @param usr The address of the account trading DAI for USDC
            /// @param gemAmt The amount of USDC to buy in USDC base units
            function buyGem(address usr, uint256 gemAmt) external;
        }
        // Maker units https://github.com/makerdao/dss/blob/master/DEVELOPING.md
        // wad: fixed point decimal with 18 decimals (for basic quantities, e.g. balances)
        uint256 constant WAD = 10 ** 18;
        IERC20 constant DAI = IERC20(0x6B175474E89094C44Da98b954EedeAC495271d0F);
        abstract contract MakerPSM is SettlerAbstract {
            using UnsafeMath for uint256;
            using SafeTransferLib for IERC20;
            constructor() {
                assert(block.chainid == 1 || block.chainid == 31337);
            }
            function sellToMakerPsm(
                address recipient,
                IERC20 gemToken,
                uint256 bps,
                IPSM psm,
                bool buyGem,
                uint256 amountOutMin
            ) internal {
                if (buyGem) {
                    // phantom overflow can't happen here because DAI has decimals = 18
                    uint256 sellAmount = (DAI.balanceOf(address(this)) * bps).unsafeDiv(BASIS);
                    unchecked {
                        uint256 feeDivisor = psm.tout() + WAD; // eg. 1.001 * 10 ** 18 with 0.1% fee [tout is in wad];
                        // overflow can't happen at all because DAI is reasonable and PSM prohibits gemToken with decimals > 18
                        uint256 buyAmount = (sellAmount * 10 ** uint256(gemToken.decimals())).unsafeDiv(feeDivisor);
                        if (buyAmount < amountOutMin) {
                            revert TooMuchSlippage(gemToken, amountOutMin, buyAmount);
                        }
                        DAI.safeApproveIfBelow(address(psm), sellAmount);
                        psm.buyGem(recipient, buyAmount);
                    }
                } else {
                    // phantom overflow can't happen here because PSM prohibits gemToken with decimals > 18
                    uint256 sellAmount = (gemToken.balanceOf(address(this)) * bps).unsafeDiv(BASIS);
                    gemToken.safeApproveIfBelow(psm.gemJoin(), sellAmount);
                    psm.sellGem(recipient, sellAmount);
                    if (amountOutMin != 0) {
                        uint256 buyAmount;
                        assembly ("memory-safe") {
                            // `returndatacopy` causes an exceptional revert if there's an out-of-bounds access.
                            // "LitePSM USDC A" (0xf6e72Db5454dd049d0788e411b06CfAF16853042) returns the amount out
                            // "MCD PSM USDC A" (0x89B78CfA322F6C5dE0aBcEecab66Aee45393cC5A) returns nothing
                            // When interacting with "MCD PSM USDC A", `amountOutMin` must be zero
                            returndatacopy(0x00, 0x00, 0x20)
                            buyAmount := mload(0x00)
                        }
                        if (buyAmount < amountOutMin) {
                            revert TooMuchSlippage(DAI, amountOutMin, buyAmount);
                        }
                    }
                }
            }
        }
        // src/core/UniswapV2.sol
        interface IUniV2Pair {
            function token0() external view returns (address);
            function token1() external view returns (address);
            function getReserves() external view returns (uint112, uint112, uint32);
            function swap(uint256, uint256, address, bytes calldata) external;
        }
        abstract contract UniswapV2 is SettlerAbstract {
            using UnsafeMath for uint256;
            // bytes4(keccak256("getReserves()"))
            uint32 private constant UNI_PAIR_RESERVES_SELECTOR = 0x0902f1ac;
            // bytes4(keccak256("swap(uint256,uint256,address,bytes)"))
            uint32 private constant UNI_PAIR_SWAP_SELECTOR = 0x022c0d9f;
            // bytes4(keccak256("transfer(address,uint256)"))
            uint32 private constant ERC20_TRANSFER_SELECTOR = 0xa9059cbb;
            // bytes4(keccak256("balanceOf(address)"))
            uint32 private constant ERC20_BALANCEOF_SELECTOR = 0x70a08231;
            /// @dev Sell a token for another token using UniswapV2.
            function sellToUniswapV2(
                address recipient,
                address sellToken,
                uint256 bps,
                address pool,
                uint24 swapInfo,
                uint256 minBuyAmount
            ) internal {
                // Preventing calls to Permit2 or AH is not explicitly required as neither of these contracts implement the `swap` nor `transfer` selector
                // |7|6|5|4|3|2|1|0| - bit positions in swapInfo (uint8)
                // |0|0|0|0|0|0|F|Z| - Z: zeroForOne flag, F: sellTokenHasFee flag
                bool zeroForOne = (swapInfo & 1) == 1; // Extract the least significant bit (bit 0)
                bool sellTokenHasFee = (swapInfo & 2) >> 1 == 1; // Extract the second least significant bit (bit 1) and shift it right
                uint256 feeBps = swapInfo >> 8;
                uint256 sellAmount;
                uint256 buyAmount;
                // If bps is zero we assume there are no funds within this contract, skip the updating sellAmount.
                // This case occurs if the pool is being chained, in which the funds have been sent directly to the pool
                if (bps != 0) {
                    // We don't care about phantom overflow here because reserves are
                    // limited to 112 bits. Any token balance that would overflow here would
                    // also break UniV2.
                    // It is *possible* to set `bps` above the basis and therefore
                    // cause an overflow on this multiplication. However, `bps` is
                    // passed as authenticated calldata, so this is a GIGO error that we
                    // do not attempt to fix.
                    unchecked {
                        sellAmount = (IERC20(sellToken).balanceOf(address(this)) * bps).unsafeDiv(BASIS);
                    }
                }
                assembly ("memory-safe") {
                    let ptr := mload(0x40)
                    // transfer sellAmount (a non zero amount) of sellToken to the pool
                    if sellAmount {
                        mstore(ptr, ERC20_TRANSFER_SELECTOR)
                        mstore(add(ptr, 0x20), pool)
                        mstore(add(ptr, 0x40), sellAmount)
                        // ...||ERC20_TRANSFER_SELECTOR|pool|sellAmount|
                        if iszero(call(gas(), sellToken, 0, add(ptr, 0x1c), 0x44, 0x00, 0x20)) { bubbleRevert(ptr) }
                        if iszero(or(iszero(returndatasize()), and(iszero(lt(returndatasize(), 0x20)), eq(mload(0x00), 1)))) {
                            revert(0, 0)
                        }
                    }
                    // get pool reserves
                    let sellReserve
                    let buyReserve
                    mstore(0x00, UNI_PAIR_RESERVES_SELECTOR)
                    // ||UNI_PAIR_RESERVES_SELECTOR|
                    if iszero(staticcall(gas(), pool, 0x1c, 0x04, 0x00, 0x40)) { bubbleRevert(ptr) }
                    if lt(returndatasize(), 0x40) { revert(0, 0) }
                    {
                        let r := shl(5, zeroForOne)
                        buyReserve := mload(r)
                        sellReserve := mload(xor(0x20, r))
                    }
                    // Update the sell amount in the following cases:
                    //   the funds are in the pool already (flagged by sellAmount being 0)
                    //   the sell token has a fee (flagged by sellTokenHasFee)
                    if or(iszero(sellAmount), sellTokenHasFee) {
                        // retrieve the sellToken balance of the pool
                        mstore(0x00, ERC20_BALANCEOF_SELECTOR)
                        mstore(0x20, and(0xffffffffffffffffffffffffffffffffffffffff, pool))
                        // ||ERC20_BALANCEOF_SELECTOR|pool|
                        if iszero(staticcall(gas(), sellToken, 0x1c, 0x24, 0x00, 0x20)) { bubbleRevert(ptr) }
                        if lt(returndatasize(), 0x20) { revert(0, 0) }
                        let bal := mload(0x00)
                        // determine real sellAmount by comparing pool's sellToken balance to reserve amount
                        if lt(bal, sellReserve) {
                            mstore(0x00, 0x4e487b71) // selector for `Panic(uint256)`
                            mstore(0x20, 0x11) // panic code for arithmetic underflow
                            revert(0x1c, 0x24)
                        }
                        sellAmount := sub(bal, sellReserve)
                    }
                    // compute buyAmount based on sellAmount and reserves
                    let sellAmountWithFee := mul(sellAmount, sub(10000, feeBps))
                    buyAmount := div(mul(sellAmountWithFee, buyReserve), add(sellAmountWithFee, mul(sellReserve, 10000)))
                    let swapCalldata := add(ptr, 0x1c)
                    // set up swap call selector and empty callback data
                    mstore(ptr, UNI_PAIR_SWAP_SELECTOR)
                    mstore(add(ptr, 0x80), 0x80) // offset to length of data
                    mstore(add(ptr, 0xa0), 0) // length of data
                    // set amount0Out and amount1Out
                    {
                        // If `zeroForOne`, offset is 0x24, else 0x04
                        let offset := add(0x04, shl(5, zeroForOne))
                        mstore(add(swapCalldata, offset), buyAmount)
                        mstore(add(swapCalldata, xor(0x20, offset)), 0)
                    }
                    mstore(add(swapCalldata, 0x44), and(0xffffffffffffffffffffffffffffffffffffffff, recipient))
                    // ...||UNI_PAIR_SWAP_SELECTOR|amount0Out|amount1Out|recipient|data|
                    // perform swap at the pool sending bought tokens to the recipient
                    if iszero(call(gas(), pool, 0, swapCalldata, 0xa4, 0, 0)) { bubbleRevert(swapCalldata) }
                    // revert with the return data from the most recent call
                    function bubbleRevert(p) {
                        returndatacopy(p, 0, returndatasize())
                        revert(p, returndatasize())
                    }
                }
                if (buyAmount < minBuyAmount) {
                    revert TooMuchSlippage(
                        IERC20(zeroForOne ? IUniV2Pair(pool).token1() : IUniV2Pair(pool).token0()), minBuyAmount, buyAmount
                    );
                }
            }
        }
        // src/core/Velodrome.sol
        interface IVelodromePair {
            function metadata()
                external
                view
                returns (
                    uint256 basis0,
                    uint256 basis1,
                    uint256 reserve0,
                    uint256 reserve1,
                    bool stable,
                    IERC20 token0,
                    IERC20 token1
                );
            function swap(uint256 amount0Out, uint256 amount1Out, address to, bytes calldata data) external;
        }
        abstract contract Velodrome is SettlerAbstract {
            using UnsafeMath for uint256;
            using SafeTransferLib for IERC20;
            uint256 private constant _BASIS = 1 ether;
            // This is the `k = x^3 * y + y^3 * x` constant function
            function _k(uint256 x, uint256 y) private pure returns (uint256) {
                unchecked {
                    return _k(x, y, x * x / _BASIS);
                }
            }
            function _k(uint256 x, uint256 y, uint256 x_squared) private pure returns (uint256) {
                unchecked {
                    return _k(x, y, x_squared, y * y / _BASIS);
                }
            }
            function _k(uint256 x, uint256 y, uint256 x_squared, uint256 y_squared) private pure returns (uint256) {
                unchecked {
                    return x * y / _BASIS * (x_squared + y_squared) / _BASIS;
                }
            }
            // For numerically approximating a solution to the `k = x^3 * y + y^3 * x` constant function
            // using Newton-Raphson, this is `∂k/∂y = 3 * x * y^2 + x^3`.
            function _d(uint256 y, uint256 three_x0, uint256 x0_cubed) private pure returns (uint256) {
                unchecked {
                    return _d(y, three_x0, x0_cubed, y * y / _BASIS);
                }
            }
            function _d(uint256, uint256 three_x0, uint256 x0_cubed, uint256 y_squared) private pure returns (uint256) {
                unchecked {
                    return y_squared * three_x0 / _BASIS + x0_cubed;
                }
            }
            error NotConverged();
            // Using Newton-Raphson iterations, compute the smallest `new_y` such that `_k(x0, new_y) >=
            // xy`. As a function of `y`, we find the root of `_k(x0, y) - xy`.
            function _get_y(uint256 x0, uint256 xy, uint256 y) private pure returns (uint256) {
                unchecked {
                    uint256 three_x0 = 3 * x0;
                    uint256 x0_squared = x0 * x0 / _BASIS;
                    uint256 x0_cubed = x0_squared * x0 / _BASIS;
                    for (uint256 i; i < 255; i++) {
                        uint256 y_squared = y * y / _BASIS;
                        uint256 k = _k(x0, y, x0_squared, y_squared);
                        if (k < xy) {
                            // there are two cases where dy == 0
                            // case 1: The y is converged and we find the correct answer
                            // case 2: _d(x0, y) is too large compare to (xy - k) and the rounding error
                            //         screwed us.
                            //         In this case, we need to increase y by 1
                            uint256 dy = ((xy - k) * _BASIS).unsafeDiv(_d(y, three_x0, x0_cubed, y_squared));
                            if (dy == 0) {
                                if (k == xy) {
                                    // We found the correct answer. Return y
                                    return y;
                                }
                                if (_k(x0, y + 1, x0_squared) > xy) {
                                    // If _k(x0, y + 1) > xy, then we are close to the correct answer.
                                    // There's no closer answer than y + 1
                                    return y + 1;
                                }
                                dy = 1;
                            }
                            y += dy;
                        } else {
                            uint256 dy = ((k - xy) * _BASIS).unsafeDiv(_d(y, three_x0, x0_cubed, y_squared));
                            if (dy == 0) {
                                if (k == xy || _k(x0, y - 1, x0_squared) < xy) {
                                    // Likewise, if k == xy, we found the correct answer.
                                    // If _k(x0, y - 1) < xy, then we are close to the correct answer.
                                    // There's no closer answer than "y"
                                    // It's worth mentioning that we need to find y where _k(x0, y) >= xy
                                    // As a result, we can't return y - 1 even it's closer to the correct answer
                                    return y;
                                }
                                dy = 1;
                            }
                            y -= dy;
                        }
                    }
                    revert NotConverged();
                }
            }
            function sellToVelodrome(address recipient, uint256 bps, IVelodromePair pair, uint24 swapInfo, uint256 minAmountOut)
                internal
            {
                // Preventing calls to Permit2 or AH is not explicitly required as neither of these contracts implement the `swap` nor `transfer` selector
                // |7|6|5|4|3|2|1|0| - bit positions in swapInfo (uint8)
                // |0|0|0|0|0|0|F|Z| - Z: zeroForOne flag, F: sellTokenHasFee flag
                bool zeroForOne = (swapInfo & 1) == 1; // Extract the least significant bit (bit 0)
                bool sellTokenHasFee = (swapInfo & 2) >> 1 == 1; // Extract the second least significant bit (bit 1) and shift it right
                uint256 feeBps = swapInfo >> 8;
                (
                    uint256 sellBasis,
                    uint256 buyBasis,
                    uint256 sellReserve,
                    uint256 buyReserve,
                    bool stable,
                    IERC20 sellToken,
                    IERC20 buyToken
                ) = pair.metadata();
                assert(stable);
                if (!zeroForOne) {
                    (sellBasis, buyBasis, sellReserve, buyReserve, sellToken, buyToken) =
                        (buyBasis, sellBasis, buyReserve, sellReserve, buyToken, sellToken);
                }
                uint256 buyAmount;
                unchecked {
                    // Compute sell amount in native units
                    uint256 sellAmount;
                    if (bps != 0) {
                        // It must be possible to square the sell token balance of the pool, otherwise it
                        // will revert with an overflow. Therefore, it can't be so large that multiplying by
                        // a "reasonable" `bps` value could overflow. We don't care to protect against
                        // unreasonable `bps` values because that just means the taker is griefing themself.
                        sellAmount = (sellToken.balanceOf(address(this)) * bps).unsafeDiv(BASIS);
                    }
                    if (sellAmount != 0) {
                        sellToken.safeTransfer(address(pair), sellAmount);
                    }
                    if (sellAmount == 0 || sellTokenHasFee) {
                        sellAmount = sellToken.balanceOf(address(pair)) - sellReserve;
                    }
                    // Apply the fee
                    sellAmount -= sellAmount * feeBps / 10_000; // can't overflow
                    // Convert everything from native units to `_BASIS`
                    sellReserve = (sellReserve * _BASIS).unsafeDiv(sellBasis);
                    buyReserve = (buyReserve * _BASIS).unsafeDiv(buyBasis);
                    sellAmount = (sellAmount * _BASIS).unsafeDiv(sellBasis);
                    // Solve the constant function numerically to get `buyAmount` from `sellAmount`
                    buyAmount = buyReserve - _get_y(sellAmount + sellReserve, _k(sellReserve, buyReserve), buyReserve);
                    // Convert `buyAmount` from `_BASIS` to native units
                    buyAmount = buyAmount * buyBasis / _BASIS;
                }
                if (buyAmount < minAmountOut) {
                    revert TooMuchSlippage(sellToken, minAmountOut, buyAmount);
                }
                {
                    (uint256 buyAmount0, uint256 buyAmount1) = zeroForOne ? (uint256(0), buyAmount) : (buyAmount, uint256(0));
                    pair.swap(buyAmount0, buyAmount1, recipient, new bytes(0));
                }
            }
        }
        // src/core/RfqOrderSettlement.sol
        abstract contract RfqOrderSettlement is SettlerAbstract {
            using SafeTransferLib for IERC20;
            using FullMath for uint256;
            struct Consideration {
                IERC20 token;
                uint256 amount;
                address counterparty;
                bool partialFillAllowed;
            }
            string internal constant CONSIDERATION_TYPE =
                "Consideration(address token,uint256 amount,address counterparty,bool partialFillAllowed)";
            // `string.concat` isn't recognized by solc as compile-time constant, but `abi.encodePacked` is
            string internal constant CONSIDERATION_WITNESS =
                string(abi.encodePacked("Consideration consideration)", CONSIDERATION_TYPE, TOKEN_PERMISSIONS_TYPE));
            bytes32 internal constant CONSIDERATION_TYPEHASH =
                0x7d806873084f389a66fd0315dead7adaad8ae6e8b6cf9fb0d3db61e5a91c3ffa;
            string internal constant RFQ_ORDER_TYPE =
                "RfqOrder(Consideration makerConsideration,Consideration takerConsideration)";
            string internal constant RFQ_ORDER_TYPE_RECURSIVE = string(abi.encodePacked(RFQ_ORDER_TYPE, CONSIDERATION_TYPE));
            bytes32 internal constant RFQ_ORDER_TYPEHASH = 0x49fa719b76f0f6b7e76be94b56c26671a548e1c712d5b13dc2874f70a7598276;
            function _hashConsideration(Consideration memory consideration) internal pure returns (bytes32 result) {
                assembly ("memory-safe") {
                    let ptr := sub(consideration, 0x20)
                    let oldValue := mload(ptr)
                    mstore(ptr, CONSIDERATION_TYPEHASH)
                    result := keccak256(ptr, 0xa0)
                    mstore(ptr, oldValue)
                }
            }
            function _logRfqOrder(bytes32 makerConsiderationHash, bytes32 takerConsiderationHash, uint128 makerFilledAmount)
                private
            {
                assembly ("memory-safe") {
                    mstore(0x00, RFQ_ORDER_TYPEHASH)
                    mstore(0x20, makerConsiderationHash)
                    let ptr := mload(0x40)
                    mstore(0x40, takerConsiderationHash)
                    let orderHash := keccak256(0x00, 0x60)
                    mstore(0x40, ptr)
                    mstore(0x10, makerFilledAmount)
                    mstore(0x00, orderHash)
                    log0(0x00, 0x30)
                }
            }
            constructor() {
                assert(CONSIDERATION_TYPEHASH == keccak256(bytes(CONSIDERATION_TYPE)));
                assert(RFQ_ORDER_TYPEHASH == keccak256(bytes(RFQ_ORDER_TYPE_RECURSIVE)));
            }
            /// @dev Settle an RfqOrder between maker and taker transfering funds directly between the counterparties. Either
            ///      two Permit2 signatures are consumed, with the maker Permit2 containing a witness of the RfqOrder, or
            ///      AllowanceHolder is supported for the taker payment. The Maker has signed the same order as the
            ///      Taker. Submission may be directly by the taker or via a third party with the Taker signing a witness.
            /// @dev if used, the taker's witness is not calculated nor verified here as calling function is trusted
            function fillRfqOrderVIP(
                address recipient,
                ISignatureTransfer.PermitTransferFrom memory makerPermit,
                address maker,
                bytes memory makerSig,
                ISignatureTransfer.PermitTransferFrom memory takerPermit,
                bytes memory takerSig
            ) internal {
                assert(makerPermit.permitted.amount <= type(uint256).max - BASIS);
                (ISignatureTransfer.SignatureTransferDetails memory makerTransferDetails, uint256 makerAmount) =
                    _permitToTransferDetails(makerPermit, recipient);
                (ISignatureTransfer.SignatureTransferDetails memory takerTransferDetails, uint256 takerAmount) =
                    _permitToTransferDetails(takerPermit, maker);
                bytes32 witness = _hashConsideration(
                    Consideration({
                        token: IERC20(takerPermit.permitted.token),
                        amount: takerAmount,
                        counterparty: _msgSender(),
                        partialFillAllowed: false
                    })
                );
                _transferFrom(takerPermit, takerTransferDetails, takerSig);
                _transferFromIKnowWhatImDoing(
                    makerPermit, makerTransferDetails, maker, witness, CONSIDERATION_WITNESS, makerSig, false
                );
                _logRfqOrder(
                    witness,
                    _hashConsideration(
                        Consideration({
                            token: IERC20(makerPermit.permitted.token),
                            amount: makerAmount,
                            counterparty: maker,
                            partialFillAllowed: false
                        })
                    ),
                    uint128(makerAmount)
                );
            }
            /// @dev Settle an RfqOrder between maker and Settler retaining funds in this contract.
            /// @dev pre-condition: msgSender has been authenticated against the requestor
            /// One Permit2 signature is consumed, with the maker Permit2 containing a witness of the RfqOrder.
            // In this variant, Maker pays recipient and Settler pays Maker
            function fillRfqOrderSelfFunded(
                address recipient,
                ISignatureTransfer.PermitTransferFrom memory permit,
                address maker,
                bytes memory makerSig,
                IERC20 takerToken,
                uint256 maxTakerAmount
            ) internal {
                assert(permit.permitted.amount <= type(uint256).max - BASIS);
                // Compute witnesses. These are based on the quoted maximum amounts. We will modify them
                // later to adjust for the actual settled amount, which may be modified by encountered
                // slippage.
                (ISignatureTransfer.SignatureTransferDetails memory transferDetails, uint256 makerAmount) =
                    _permitToTransferDetails(permit, recipient);
                bytes32 takerWitness = _hashConsideration(
                    Consideration({
                        token: IERC20(permit.permitted.token),
                        amount: makerAmount,
                        counterparty: maker,
                        partialFillAllowed: true
                    })
                );
                bytes32 makerWitness = _hashConsideration(
                    Consideration({
                        token: takerToken,
                        amount: maxTakerAmount,
                        counterparty: _msgSender(),
                        partialFillAllowed: true
                    })
                );
                // Now we adjust the transfer amounts to compensate for encountered slippage. Rounding is
                // performed in the maker's favor.
                uint256 takerAmount = takerToken.balanceOf(address(this));
                if (takerAmount > maxTakerAmount) {
                    takerAmount = maxTakerAmount;
                }
                transferDetails.requestedAmount = makerAmount = makerAmount.unsafeMulDiv(takerAmount, maxTakerAmount);
                // Now that we have all the relevant information, make the transfers and log the order.
                takerToken.safeTransfer(maker, takerAmount);
                _transferFromIKnowWhatImDoing(
                    permit, transferDetails, maker, makerWitness, CONSIDERATION_WITNESS, makerSig, false
                );
                _logRfqOrder(makerWitness, takerWitness, uint128(makerAmount));
            }
        }
        // src/core/CurveTricrypto.sol
        interface ICurveTricrypto {
            function exchange_extended(
                uint256 sellIndex,
                uint256 buyIndex,
                uint256 sellAmount,
                uint256 minBuyAmount,
                bool useEth,
                address payer,
                address receiver,
                bytes32 callbackSelector
            ) external returns (uint256 buyAmount);
        }
        interface ICurveTricryptoCallback {
            // The function name/selector is arbitrary, but the arguments are controlled by the pool
            function curveTricryptoSwapCallback(
                address payer,
                address receiver,
                IERC20 sellToken,
                uint256 sellAmount,
                uint256 buyAmount
            ) external;
        }
        abstract contract CurveTricrypto is SettlerAbstract {
            using UnsafeMath for uint256;
            using SafeTransferLib for IERC20;
            using AddressDerivation for address;
            function _curveFactory() internal virtual returns (address);
            // uint256 private constant codePrefixLen = 0x539d;
            // bytes32 private constant codePrefixHash = 0xec96085e693058e09a27755c07882ced27117a3161b1fdaf131a14c7db9978b7;
            function sellToCurveTricryptoVIP(
                address recipient,
                uint80 poolInfo,
                ISignatureTransfer.PermitTransferFrom memory permit,
                bytes memory sig,
                uint256 minBuyAmount
            ) internal {
                uint256 sellAmount = _permitToSellAmount(permit);
                uint64 factoryNonce = uint64(poolInfo >> 16);
                uint8 sellIndex = uint8(poolInfo >> 8);
                uint8 buyIndex = uint8(poolInfo);
                address pool = _curveFactory().deriveContract(factoryNonce);
                /*
                bytes32 codePrefixHashActual;
                assembly ("memory-safe") {
                    let ptr := mload(0x40)
                    extcodecopy(pool, ptr, 0x00, codePrefixLen)
                    codePrefixHashActual := keccak256(ptr, codePrefixLen)
                }
                if (codePrefixHashActual != codePrefixHash) {
                    revert ConfusedDeputy();
                }
                */
                bool isForwarded = _isForwarded();
                assembly ("memory-safe") {
                    tstore(0x00, isForwarded)
                    tstore(0x01, mload(add(0x20, mload(permit)))) // amount
                    tstore(0x02, mload(add(0x20, permit))) // nonce
                    tstore(0x03, mload(add(0x40, permit))) // deadline
                    for {
                        let src := add(0x20, sig)
                        let end
                        {
                            let len := mload(sig)
                            end := add(len, src)
                            tstore(0x04, len)
                        }
                        let dst := 0x05
                    } lt(src, end) {
                        src := add(0x20, src)
                        dst := add(0x01, dst)
                    } { tstore(dst, mload(src)) }
                }
                _setOperatorAndCall(
                    pool,
                    abi.encodeCall(
                        ICurveTricrypto.exchange_extended,
                        (
                            sellIndex,
                            buyIndex,
                            sellAmount,
                            minBuyAmount,
                            false,
                            address(0), // payer
                            recipient,
                            bytes32(ICurveTricryptoCallback.curveTricryptoSwapCallback.selector)
                        )
                    ),
                    uint32(ICurveTricryptoCallback.curveTricryptoSwapCallback.selector),
                    _curveTricryptoSwapCallback
                );
            }
            function _curveTricryptoSwapCallback(bytes calldata data) private returns (bytes memory) {
                require(data.length == 0xa0);
                address payer;
                IERC20 sellToken;
                uint256 sellAmount;
                assembly ("memory-safe") {
                    payer := calldataload(data.offset)
                    let err := shr(0xa0, payer)
                    sellToken := calldataload(add(0x40, data.offset))
                    err := or(shr(0xa0, sellToken), err)
                    sellAmount := calldataload(add(0x60, data.offset))
                    if err { revert(0x00, 0x00) }
                }
                curveTricryptoSwapCallback(payer, address(0), sellToken, sellAmount, 0);
                return new bytes(0);
            }
            function curveTricryptoSwapCallback(address payer, address, IERC20 sellToken, uint256 sellAmount, uint256)
                private
            {
                assert(payer == address(0));
                bool isForwarded;
                uint256 permittedAmount;
                uint256 nonce;
                uint256 deadline;
                bytes memory sig;
                assembly ("memory-safe") {
                    isForwarded := tload(0x00)
                    tstore(0x00, 0x00)
                    permittedAmount := tload(0x01)
                    tstore(0x01, 0x00)
                    nonce := tload(0x02)
                    tstore(0x02, 0x00)
                    deadline := tload(0x03)
                    tstore(0x03, 0x00)
                    sig := mload(0x40)
                    for {
                        let dst := add(0x20, sig)
                        let end
                        {
                            let len := tload(0x04)
                            tstore(0x04, 0x00)
                            end := add(dst, len)
                            mstore(sig, len)
                            mstore(0x40, end)
                        }
                        let src := 0x05
                    } lt(dst, end) {
                        src := add(0x01, src)
                        dst := add(0x20, dst)
                    } {
                        mstore(dst, tload(src))
                        tstore(src, 0x00)
                    }
                }
                ISignatureTransfer.PermitTransferFrom memory permit = ISignatureTransfer.PermitTransferFrom({
                    permitted: ISignatureTransfer.TokenPermissions({token: address(sellToken), amount: permittedAmount}),
                    nonce: nonce,
                    deadline: deadline
                });
                ISignatureTransfer.SignatureTransferDetails memory transferDetails =
                    ISignatureTransfer.SignatureTransferDetails({to: msg.sender, requestedAmount: sellAmount});
                _transferFrom(permit, transferDetails, sig, isForwarded);
            }
        }
        // src/core/DodoV1.sol
        interface IDodoV1 {
            function sellBaseToken(uint256 amount, uint256 minReceiveQuote, bytes calldata data) external returns (uint256);
            function buyBaseToken(uint256 amount, uint256 maxPayQuote, bytes calldata data) external returns (uint256);
            function _R_STATUS_() external view returns (uint8);
            function _QUOTE_BALANCE_() external view returns (uint256);
            function _BASE_BALANCE_() external view returns (uint256);
            function _K_() external view returns (uint256);
            function _MT_FEE_RATE_() external view returns (uint256);
            function _LP_FEE_RATE_() external view returns (uint256);
            function getExpectedTarget() external view returns (uint256 baseTarget, uint256 quoteTarget);
            function getOraclePrice() external view returns (uint256);
        }
        library Math {
            function divCeil(uint256 a, uint256 b) internal pure returns (uint256) {
                uint256 quotient = a / b;
                unchecked {
                    uint256 remainder = a - quotient * b;
                    if (remainder > 0) {
                        return quotient + 1;
                    } else {
                        return quotient;
                    }
                }
            }
            function sqrt(uint256 x) internal pure returns (uint256 y) {
                unchecked {
                    uint256 z = x / 2 + 1;
                    y = x;
                    while (z < y) {
                        y = z;
                        z = (x / z + z) / 2;
                    }
                }
            }
        }
        library DecimalMath {
            using Math for uint256;
            uint256 constant ONE = 10 ** 18;
            function mul(uint256 target, uint256 d) internal pure returns (uint256) {
                unchecked {
                    return target * d / ONE;
                }
            }
            function mulCeil(uint256 target, uint256 d) internal pure returns (uint256) {
                unchecked {
                    return (target * d).divCeil(ONE);
                }
            }
            function divFloor(uint256 target, uint256 d) internal pure returns (uint256) {
                unchecked {
                    return target * ONE / d;
                }
            }
            function divCeil(uint256 target, uint256 d) internal pure returns (uint256) {
                unchecked {
                    return (target * ONE).divCeil(d);
                }
            }
        }
        library DodoMath {
            using Math for uint256;
            /*
                Integrate dodo curve fron V1 to V2
                require V0>=V1>=V2>0
                res = (1-k)i(V1-V2)+ikV0*V0(1/V2-1/V1)
                let V1-V2=delta
                res = i*delta*(1-k+k(V0^2/V1/V2))
            */
            function _GeneralIntegrate(uint256 V0, uint256 V1, uint256 V2, uint256 i, uint256 k)
                internal
                pure
                returns (uint256)
            {
                unchecked {
                    uint256 fairAmount = DecimalMath.mul(i, V1 - V2); // i*delta
                    uint256 V0V0V1V2 = DecimalMath.divCeil(V0 * V0 / V1, V2);
                    uint256 penalty = DecimalMath.mul(k, V0V0V1V2); // k(V0^2/V1/V2)
                    return DecimalMath.mul(fairAmount, DecimalMath.ONE - k + penalty);
                }
            }
            /*
                The same with integration expression above, we have:
                i*deltaB = (Q2-Q1)*(1-k+kQ0^2/Q1/Q2)
                Given Q1 and deltaB, solve Q2
                This is a quadratic function and the standard version is
                aQ2^2 + bQ2 + c = 0, where
                a=1-k
                -b=(1-k)Q1-kQ0^2/Q1+i*deltaB
                c=-kQ0^2
                and Q2=(-b+sqrt(b^2+4(1-k)kQ0^2))/2(1-k)
                note: another root is negative, abondan
                if deltaBSig=true, then Q2>Q1
                if deltaBSig=false, then Q2<Q1
            */
            function _SolveQuadraticFunctionForTrade(uint256 Q0, uint256 Q1, uint256 ideltaB, bool deltaBSig, uint256 k)
                internal
                pure
                returns (uint256)
            {
                unchecked {
                    // calculate -b value and sig
                    // -b = (1-k)Q1-kQ0^2/Q1+i*deltaB
                    uint256 kQ02Q1 = DecimalMath.mul(k, Q0) * Q0 / Q1; // kQ0^2/Q1
                    uint256 b = DecimalMath.mul(DecimalMath.ONE - k, Q1); // (1-k)Q1
                    bool minusbSig = true;
                    if (deltaBSig) {
                        b += ideltaB; // (1-k)Q1+i*deltaB
                    } else {
                        kQ02Q1 += ideltaB; // i*deltaB+kQ0^2/Q1
                    }
                    if (b >= kQ02Q1) {
                        b -= kQ02Q1;
                        minusbSig = true;
                    } else {
                        b = kQ02Q1 - b;
                        minusbSig = false;
                    }
                    // calculate sqrt
                    uint256 squareRoot = DecimalMath.mul((DecimalMath.ONE - k) * 4, DecimalMath.mul(k, Q0) * Q0); // 4(1-k)kQ0^2
                    squareRoot = (b * b + squareRoot).sqrt(); // sqrt(b*b+4(1-k)kQ0*Q0)
                    // final res
                    uint256 denominator = (DecimalMath.ONE - k) * 2; // 2(1-k)
                    uint256 numerator;
                    if (minusbSig) {
                        numerator = b + squareRoot;
                    } else {
                        numerator = squareRoot - b;
                    }
                    if (deltaBSig) {
                        return DecimalMath.divFloor(numerator, denominator);
                    } else {
                        return DecimalMath.divCeil(numerator, denominator);
                    }
                }
            }
            /*
                Start from the integration function
                i*deltaB = (Q2-Q1)*(1-k+kQ0^2/Q1/Q2)
                Assume Q2=Q0, Given Q1 and deltaB, solve Q0
                let fairAmount = i*deltaB
            */
            function _SolveQuadraticFunctionForTarget(uint256 V1, uint256 k, uint256 fairAmount)
                internal
                pure
                returns (uint256 V0)
            {
                unchecked {
                    // V0 = V1+V1*(sqrt-1)/2k
                    uint256 sqrt = DecimalMath.divCeil(DecimalMath.mul(k, fairAmount) * 4, V1);
                    sqrt = ((sqrt + DecimalMath.ONE) * DecimalMath.ONE).sqrt();
                    uint256 premium = DecimalMath.divCeil(sqrt - DecimalMath.ONE, k * 2);
                    // V0 is greater than or equal to V1 according to the solution
                    return DecimalMath.mul(V1, DecimalMath.ONE + premium);
                }
            }
        }
        abstract contract DodoSellHelper {
            using Math for uint256;
            enum RStatus {
                ONE,
                ABOVE_ONE,
                BELOW_ONE
            }
            struct DodoState {
                uint256 oraclePrice;
                uint256 K;
                uint256 B;
                uint256 Q;
                uint256 baseTarget;
                uint256 quoteTarget;
                RStatus rStatus;
            }
            function dodoQuerySellQuoteToken(IDodoV1 dodo, uint256 amount) internal view returns (uint256) {
                DodoState memory state;
                (state.baseTarget, state.quoteTarget) = dodo.getExpectedTarget();
                state.rStatus = RStatus(dodo._R_STATUS_());
                state.oraclePrice = dodo.getOraclePrice();
                state.Q = dodo._QUOTE_BALANCE_();
                state.B = dodo._BASE_BALANCE_();
                state.K = dodo._K_();
                unchecked {
                    uint256 boughtAmount;
                    // Determine the status (RStatus) and calculate the amount based on the
                    // state
                    if (state.rStatus == RStatus.ONE) {
                        boughtAmount = _ROneSellQuoteToken(amount, state);
                    } else if (state.rStatus == RStatus.ABOVE_ONE) {
                        boughtAmount = _RAboveSellQuoteToken(amount, state);
                    } else {
                        uint256 backOneBase = state.B - state.baseTarget;
                        uint256 backOneQuote = state.quoteTarget - state.Q;
                        if (amount <= backOneQuote) {
                            boughtAmount = _RBelowSellQuoteToken(amount, state);
                        } else {
                            boughtAmount = backOneBase + _ROneSellQuoteToken(amount - backOneQuote, state);
                        }
                    }
                    // Calculate fees
                    return DecimalMath.divFloor(boughtAmount, DecimalMath.ONE + dodo._MT_FEE_RATE_() + dodo._LP_FEE_RATE_());
                }
            }
            function _ROneSellQuoteToken(uint256 amount, DodoState memory state)
                private
                pure
                returns (uint256 receiveBaseToken)
            {
                unchecked {
                    uint256 i = DecimalMath.divFloor(DecimalMath.ONE, state.oraclePrice);
                    uint256 B2 = DodoMath._SolveQuadraticFunctionForTrade(
                        state.baseTarget, state.baseTarget, DecimalMath.mul(i, amount), false, state.K
                    );
                    return state.baseTarget - B2;
                }
            }
            function _RAboveSellQuoteToken(uint256 amount, DodoState memory state)
                private
                pure
                returns (uint256 receieBaseToken)
            {
                unchecked {
                    uint256 i = DecimalMath.divFloor(DecimalMath.ONE, state.oraclePrice);
                    uint256 B2 = DodoMath._SolveQuadraticFunctionForTrade(
                        state.baseTarget, state.B, DecimalMath.mul(i, amount), false, state.K
                    );
                    return state.B - B2;
                }
            }
            function _RBelowSellQuoteToken(uint256 amount, DodoState memory state)
                private
                pure
                returns (uint256 receiveBaseToken)
            {
                unchecked {
                    uint256 Q1 = state.Q + amount;
                    uint256 i = DecimalMath.divFloor(DecimalMath.ONE, state.oraclePrice);
                    return DodoMath._GeneralIntegrate(state.quoteTarget, Q1, state.Q, i, state.K);
                }
            }
        }
        abstract contract DodoV1 is SettlerAbstract, DodoSellHelper {
            using FullMath for uint256;
            using SafeTransferLib for IERC20;
            function sellToDodoV1(IERC20 sellToken, uint256 bps, IDodoV1 dodo, bool quoteForBase, uint256 minBuyAmount)
                internal
            {
                uint256 sellAmount = sellToken.balanceOf(address(this)).mulDiv(bps, BASIS);
                sellToken.safeApproveIfBelow(address(dodo), sellAmount);
                if (quoteForBase) {
                    uint256 buyAmount = dodoQuerySellQuoteToken(dodo, sellAmount);
                    if (buyAmount < minBuyAmount) {
                        revert TooMuchSlippage(sellToken, minBuyAmount, buyAmount);
                    }
                    dodo.buyBaseToken(buyAmount, sellAmount, new bytes(0));
                } else {
                    dodo.sellBaseToken(sellAmount, minBuyAmount, new bytes(0));
                }
            }
        }
        // src/core/DodoV2.sol
        interface IDodoV2 {
            function sellBase(address to) external returns (uint256 receiveQuoteAmount);
            function sellQuote(address to) external returns (uint256 receiveBaseAmount);
            function _BASE_TOKEN_() external view returns (IERC20);
            function _QUOTE_TOKEN_() external view returns (IERC20);
        }
        abstract contract DodoV2 is SettlerAbstract {
            using FullMath for uint256;
            using SafeTransferLib for IERC20;
            function sellToDodoV2(
                address recipient,
                IERC20 sellToken,
                uint256 bps,
                IDodoV2 dodo,
                bool quoteForBase,
                uint256 minBuyAmount
            ) internal returns (uint256 buyAmount) {
                if (bps != 0) {
                    uint256 sellAmount = sellToken.balanceOf(address(this)).mulDiv(bps, BASIS);
                    sellToken.safeTransfer(address(dodo), sellAmount);
                }
                if (quoteForBase) {
                    buyAmount = dodo.sellQuote(recipient);
                    if (buyAmount < minBuyAmount) {
                        revert TooMuchSlippage(dodo._BASE_TOKEN_(), minBuyAmount, buyAmount);
                    }
                } else {
                    buyAmount = dodo.sellBase(recipient);
                    if (buyAmount < minBuyAmount) {
                        revert TooMuchSlippage(dodo._QUOTE_TOKEN_(), minBuyAmount, buyAmount);
                    }
                }
            }
        }
        // src/core/MaverickV2.sol
        // Maverick AMM V2 is not open-source. The source code was disclosed to the
        // developers of 0x Settler confidentially and recompiled privately. The
        // deployed bytecode inithash matches the privately recompiled inithash.
        bytes32 constant maverickV2InitHash = 0xbb7b783eb4b8ca46925c5384a6b9919df57cb83da8f76e37291f58d0dd5c439a;
        // https://docs.mav.xyz/technical-reference/contract-addresses/v2-contract-addresses
        // For chains: mainnet, base, bnb, arbitrum, scroll, sepolia
        address constant maverickV2Factory = 0x0A7e848Aca42d879EF06507Fca0E7b33A0a63c1e;
        interface IMaverickV2Pool {
            /**
             * @notice Parameters for swap.
             * @param amount Amount of the token that is either the input if exactOutput is false
             * or the output if exactOutput is true.
             * @param tokenAIn Boolean indicating whether tokenA is the input.
             * @param exactOutput Boolean indicating whether the amount specified is
             * the exact output amount (true).
             * @param tickLimit The furthest tick a swap will execute in. If no limit
             * is desired, value should be set to type(int32).max for a tokenAIn swap
             * and type(int32).min for a swap where tokenB is the input.
             */
            struct SwapParams {
                uint256 amount;
                bool tokenAIn;
                bool exactOutput;
                int32 tickLimit;
            }
            /**
             * @notice Swap tokenA/tokenB assets in the pool.  The swap user has two
             * options for funding their swap.
             * - The user can push the input token amount to the pool before calling
             * the swap function. In order to avoid having the pool call the callback,
             * the user should pass a zero-length `data` bytes object with the swap
             * call.
             * - The user can send the input token amount to the pool when the pool
             * calls the `maverickV2SwapCallback` function on the calling contract.
             * That callback has input parameters that specify the token address of the
             * input token, the input and output amounts, and the bytes data sent to
             * the swap function.
             * @dev  If the users elects to do a callback-based swap, the output
             * assets will be sent before the callback is called, allowing the user to
             * execute flash swaps.  However, the pool does have reentrancy protection,
             * so a swapper will not be able to interact with the same pool again
             * while they are in the callback function.
             * @param recipient The address to receive the output tokens.
             * @param params Parameters containing the details of the swap
             * @param data Bytes information that gets passed to the callback.
             */
            function swap(address recipient, SwapParams calldata params, bytes calldata data)
                external
                returns (uint256 amountIn, uint256 amountOut);
            /**
             * @notice Pool tokenA.  Address of tokenA is such that tokenA < tokenB.
             */
            function tokenA() external view returns (IERC20);
            /**
             * @notice Pool tokenB.
             */
            function tokenB() external view returns (IERC20);
            /**
             * @notice State of the pool.
             * @param reserveA Pool tokenA balanceOf at end of last operation
             * @param reserveB Pool tokenB balanceOf at end of last operation
             * @param lastTwaD8 Value of log time weighted average price at last block.
             * Value is 8-decimal scale and is in the fractional tick domain.  E.g. a
             * value of 12.3e8 indicates the TWAP was 3/10ths of the way into the 12th
             * tick.
             * @param lastLogPriceD8 Value of log price at last block. Value is
             * 8-decimal scale and is in the fractional tick domain.  E.g. a value of
             * 12.3e8 indicates the price was 3/10ths of the way into the 12th tick.
             * @param lastTimestamp Last block.timestamp value in seconds for latest
             * swap transaction.
             * @param activeTick Current tick position that contains the active bins.
             * @param isLocked Pool isLocked, E.g., locked or unlocked; isLocked values
             * defined in Pool.sol.
             * @param binCounter Index of the last bin created.
             * @param protocolFeeRatioD3 Ratio of the swap fee that is kept for the
             * protocol.
             */
            struct State {
                uint128 reserveA;
                uint128 reserveB;
                int64 lastTwaD8;
                int64 lastLogPriceD8;
                uint40 lastTimestamp;
                int32 activeTick;
                bool isLocked;
                uint32 binCounter;
                uint8 protocolFeeRatioD3;
            }
            /**
             * @notice External function to get the state of the pool.
             */
            function getState() external view returns (State memory);
        }
        interface IMaverickV2SwapCallback {
            function maverickV2SwapCallback(IERC20 tokenIn, uint256 amountIn, uint256 amountOut, bytes calldata data)
                external;
        }
        abstract contract MaverickV2 is SettlerAbstract {
            using UnsafeMath for uint256;
            using SafeTransferLib for IERC20;
            function _encodeSwapCallback(ISignatureTransfer.PermitTransferFrom memory permit, bytes memory sig)
                internal
                view
                returns (bytes memory result)
            {
                bool isForwarded = _isForwarded();
                assembly ("memory-safe") {
                    result := mload(0x40)
                    mcopy(add(0x20, result), mload(permit), 0x40)
                    mcopy(add(0x60, result), add(0x20, permit), 0x40)
                    mstore8(add(0xa0, result), isForwarded)
                    let sigLength := mload(sig)
                    mcopy(add(0xa1, result), add(0x20, sig), sigLength)
                    mstore(result, add(0x81, sigLength))
                    mstore(0x40, add(sigLength, add(0xa1, result)))
                }
            }
            function sellToMaverickV2VIP(
                address recipient,
                bytes32 salt,
                bool tokenAIn,
                ISignatureTransfer.PermitTransferFrom memory permit,
                bytes memory sig,
                uint256 minBuyAmount
            ) internal returns (uint256 buyAmount) {
                bytes memory swapCallbackData = _encodeSwapCallback(permit, sig);
                address pool = AddressDerivation.deriveDeterministicContract(maverickV2Factory, salt, maverickV2InitHash);
                (, buyAmount) = abi.decode(
                    _setOperatorAndCall(
                        pool,
                        abi.encodeCall(
                            IMaverickV2Pool.swap,
                            (
                                recipient,
                                IMaverickV2Pool.SwapParams({
                                    amount: _permitToSellAmount(permit),
                                    tokenAIn: tokenAIn,
                                    exactOutput: false,
                                    // TODO: actually set a tick limit so that we can partial fill
                                    tickLimit: tokenAIn ? type(int32).max : type(int32).min
                                }),
                                swapCallbackData
                            )
                        ),
                        uint32(IMaverickV2SwapCallback.maverickV2SwapCallback.selector),
                        _maverickV2Callback
                    ),
                    (uint256, uint256)
                );
                if (buyAmount < minBuyAmount) {
                    IERC20 buyToken = tokenAIn ? IMaverickV2Pool(pool).tokenB() : IMaverickV2Pool(pool).tokenA();
                    revert TooMuchSlippage(buyToken, minBuyAmount, buyAmount);
                }
            }
            function sellToMaverickV2(
                address recipient,
                IERC20 sellToken,
                uint256 bps,
                IMaverickV2Pool pool,
                bool tokenAIn,
                uint256 minBuyAmount
            ) internal returns (uint256 buyAmount) {
                uint256 sellAmount;
                if (bps != 0) {
                    unchecked {
                        // We don't care about phantom overflow here because reserves
                        // are limited to 128 bits. Any token balance that would
                        // overflow here would also break MaverickV2.
                        sellAmount = (sellToken.balanceOf(address(this)) * bps).unsafeDiv(BASIS);
                    }
                }
                if (sellAmount == 0) {
                    sellAmount = sellToken.balanceOf(address(pool));
                    IMaverickV2Pool.State memory poolState = pool.getState();
                    unchecked {
                        sellAmount -= tokenAIn ? poolState.reserveA : poolState.reserveB;
                    }
                } else {
                    sellToken.safeTransfer(address(pool), sellAmount);
                }
                (, buyAmount) = pool.swap(
                    recipient,
                    IMaverickV2Pool.SwapParams({
                        amount: sellAmount,
                        tokenAIn: tokenAIn,
                        exactOutput: false,
                        // TODO: actually set a tick limit so that we can partial fill
                        tickLimit: tokenAIn ? type(int32).max : type(int32).min
                    }),
                    new bytes(0)
                );
                if (buyAmount < minBuyAmount) {
                    revert TooMuchSlippage(tokenAIn ? pool.tokenB() : pool.tokenA(), minBuyAmount, buyAmount);
                }
            }
            function _maverickV2Callback(bytes calldata data) private returns (bytes memory) {
                require(data.length >= 0xa0);
                IERC20 tokenIn;
                uint256 amountIn;
                assembly ("memory-safe") {
                    // we don't bother checking for dirty bits because we trust the
                    // initcode (by its hash) to produce well-behaved bytecode that
                    // produces strict ABI-encoded calldata
                    tokenIn := calldataload(data.offset)
                    amountIn := calldataload(add(0x20, data.offset))
                    // likewise, we don't bother to perform the indirection to find the
                    // nested data. we just index directly to it because we know that
                    // the pool follows strict ABI encoding
                    data.length := calldataload(add(0x80, data.offset))
                    data.offset := add(0xa0, data.offset)
                }
                maverickV2SwapCallback(
                    tokenIn,
                    amountIn,
                    // forgefmt: disable-next-line
                    0 /* we didn't bother loading `amountOut` because we don't use it */,
                    data
                );
                return new bytes(0);
            }
            // forgefmt: disable-next-line
            function maverickV2SwapCallback(IERC20 tokenIn, uint256 amountIn, uint256 /* amountOut */, bytes calldata data)
                private
            {
                ISignatureTransfer.PermitTransferFrom calldata permit;
                bool isForwarded;
                assembly ("memory-safe") {
                    permit := data.offset
                    isForwarded := and(0x01, calldataload(add(0x61, data.offset)))
                    data.offset := add(0x81, data.offset)
                    data.length := sub(data.length, 0x81)
                }
                assert(tokenIn == IERC20(permit.permitted.token));
                ISignatureTransfer.SignatureTransferDetails memory transferDetails =
                    ISignatureTransfer.SignatureTransferDetails({to: msg.sender, requestedAmount: amountIn});
                _transferFrom(permit, transferDetails, data, isForwarded);
            }
        }
        // src/core/UniswapV3Fork.sol
        interface IUniswapV3Pool {
            /// @notice Swap token0 for token1, or token1 for token0
            /// @dev The caller of this method receives a callback in the form of IUniswapV3SwapCallback#uniswapV3SwapCallback
            /// @param recipient The address to receive the output of the swap
            /// @param zeroForOne The direction of the swap, true for token0 to token1, false for token1 to token0
            /// @param amountSpecified The amount of the swap, which implicitly configures the swap as exact input (positive),
            /// or exact output (negative)
            /// @param sqrtPriceLimitX96 The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this
            /// value after the swap. If one for zero, the price cannot be greater than this value after the swap
            /// @param data Any data to be passed through to the callback
            /// @return amount0 The delta of the balance of token0 of the pool, exact when negative, minimum when positive
            /// @return amount1 The delta of the balance of token1 of the pool, exact when negative, minimum when positive
            function swap(
                address recipient,
                bool zeroForOne,
                int256 amountSpecified,
                uint160 sqrtPriceLimitX96,
                bytes calldata data
            ) external returns (int256 amount0, int256 amount1);
        }
        abstract contract UniswapV3Fork is SettlerAbstract {
            using UnsafeMath for uint256;
            using SafeTransferLib for IERC20;
            /// @dev Minimum size of an encoded swap path:
            ///      sizeof(address(inputToken) | uint8(forkId) | uint24(poolId) | address(outputToken))
            uint256 private constant SINGLE_HOP_PATH_SIZE = 0x2c;
            /// @dev How many bytes to skip ahead in an encoded path to start at the next hop:
            ///      sizeof(address(inputToken) | uint8(forkId) | uint24(poolId))
            uint256 private constant PATH_SKIP_HOP_SIZE = 0x18;
            /// @dev The size of the swap callback prefix data before the Permit2 data.
            uint256 private constant SWAP_CALLBACK_PREFIX_DATA_SIZE = 0x28;
            /// @dev The offset from the pointer to the length of the swap callback prefix data to the start of the Permit2 data.
            uint256 private constant SWAP_CALLBACK_PERMIT2DATA_OFFSET = 0x48;
            uint256 private constant PERMIT_DATA_SIZE = 0x60;
            uint256 private constant ISFORWARDED_DATA_SIZE = 0x01;
            /// @dev Minimum tick price sqrt ratio.
            uint160 private constant MIN_PRICE_SQRT_RATIO = 4295128739;
            /// @dev Minimum tick price sqrt ratio.
            uint160 private constant MAX_PRICE_SQRT_RATIO = 1461446703485210103287273052203988822378723970342;
            /// @dev Mask of lower 20 bytes.
            uint256 private constant ADDRESS_MASK = 0x00ffffffffffffffffffffffffffffffffffffffff;
            /// @dev Mask of lower 3 bytes.
            uint256 private constant UINT24_MASK = 0xffffff;
            /// @dev Sell a token for another token directly against uniswap v3.
            /// @param encodedPath Uniswap-encoded path.
            /// @param bps proportion of current balance of the first token in the path to sell.
            /// @param minBuyAmount Minimum amount of the last token in the path to buy.
            /// @param recipient The recipient of the bought tokens.
            /// @return buyAmount Amount of the last token in the path bought.
            function sellToUniswapV3(address recipient, uint256 bps, bytes memory encodedPath, uint256 minBuyAmount)
                internal
                returns (uint256 buyAmount)
            {
                buyAmount = _uniV3ForkSwap(
                    recipient,
                    encodedPath,
                    // We don't care about phantom overflow here because reserves are
                    // limited to 128 bits. Any token balance that would overflow here
                    // would also break UniV3.
                    (IERC20(address(bytes20(encodedPath))).balanceOf(address(this)) * bps).unsafeDiv(BASIS),
                    minBuyAmount,
                    address(this), // payer
                    new bytes(SWAP_CALLBACK_PREFIX_DATA_SIZE)
                );
            }
            /// @dev Sell a token for another token directly against uniswap v3. Payment is using a Permit2 signature (or AllowanceHolder).
            /// @param encodedPath Uniswap-encoded path.
            /// @param minBuyAmount Minimum amount of the last token in the path to buy.
            /// @param recipient The recipient of the bought tokens.
            /// @param permit The PermitTransferFrom allowing this contract to spend the taker's tokens
            /// @param sig The taker's signature for Permit2
            /// @return buyAmount Amount of the last token in the path bought.
            function sellToUniswapV3VIP(
                address recipient,
                bytes memory encodedPath,
                ISignatureTransfer.PermitTransferFrom memory permit,
                bytes memory sig,
                uint256 minBuyAmount
            ) internal returns (uint256 buyAmount) {
                bytes memory swapCallbackData =
                    new bytes(SWAP_CALLBACK_PREFIX_DATA_SIZE + PERMIT_DATA_SIZE + ISFORWARDED_DATA_SIZE + sig.length);
                _encodePermit2Data(swapCallbackData, permit, sig, _isForwarded());
                buyAmount = _uniV3ForkSwap(
                    recipient,
                    encodedPath,
                    _permitToSellAmount(permit),
                    minBuyAmount,
                    address(0), // payer
                    swapCallbackData
                );
            }
            // Executes successive swaps along an encoded uniswap path.
            function _uniV3ForkSwap(
                address recipient,
                bytes memory encodedPath,
                uint256 sellAmount,
                uint256 minBuyAmount,
                address payer,
                bytes memory swapCallbackData
            ) internal returns (uint256 buyAmount) {
                if (sellAmount > uint256(type(int256).max)) {
                    Panic.panic(Panic.ARITHMETIC_OVERFLOW);
                }
                IERC20 outputToken;
                while (true) {
                    bool isPathMultiHop = _isPathMultiHop(encodedPath);
                    bool zeroForOne;
                    IUniswapV3Pool pool;
                    uint32 callbackSelector;
                    {
                        (IERC20 token0, uint8 forkId, uint24 poolId, IERC20 token1) = _decodeFirstPoolInfoFromPath(encodedPath);
                        IERC20 sellToken = token0;
                        outputToken = token1;
                        if (!(zeroForOne = token0 < token1)) {
                            (token0, token1) = (token1, token0);
                        }
                        address factory;
                        bytes32 initHash;
                        (factory, initHash, callbackSelector) = _uniV3ForkInfo(forkId);
                        pool = _toPool(factory, initHash, token0, token1, poolId);
                        _updateSwapCallbackData(swapCallbackData, sellToken, payer);
                    }
                    int256 amount0;
                    int256 amount1;
                    if (isPathMultiHop) {
                        uint256 freeMemPtr;
                        assembly ("memory-safe") {
                            freeMemPtr := mload(0x40)
                        }
                        (amount0, amount1) = abi.decode(
                            _setOperatorAndCall(
                                address(pool),
                                abi.encodeCall(
                                    pool.swap,
                                    (
                                        // Intermediate tokens go to this contract.
                                        address(this),
                                        zeroForOne,
                                        int256(sellAmount),
                                        zeroForOne ? MIN_PRICE_SQRT_RATIO + 1 : MAX_PRICE_SQRT_RATIO - 1,
                                        swapCallbackData
                                    )
                                ),
                                callbackSelector,
                                _uniV3ForkCallback
                            ),
                            (int256, int256)
                        );
                        assembly ("memory-safe") {
                            mstore(0x40, freeMemPtr)
                        }
                    } else {
                        (amount0, amount1) = abi.decode(
                            _setOperatorAndCall(
                                address(pool),
                                abi.encodeCall(
                                    pool.swap,
                                    (
                                        recipient,
                                        zeroForOne,
                                        int256(sellAmount),
                                        zeroForOne ? MIN_PRICE_SQRT_RATIO + 1 : MAX_PRICE_SQRT_RATIO - 1,
                                        swapCallbackData
                                    )
                                ),
                                callbackSelector,
                                _uniV3ForkCallback
                            ),
                            (int256, int256)
                        );
                    }
                    {
                        int256 _buyAmount = -(zeroForOne ? amount1 : amount0);
                        if (_buyAmount < 0) {
                            Panic.panic(Panic.ARITHMETIC_OVERFLOW);
                        }
                        buyAmount = uint256(_buyAmount);
                    }
                    if (!isPathMultiHop) {
                        // Done.
                        break;
                    }
                    // Continue with next hop.
                    payer = address(this); // Subsequent hops are paid for by us.
                    sellAmount = buyAmount;
                    // Skip to next hop along path.
                    encodedPath = _shiftHopFromPathInPlace(encodedPath);
                    assembly ("memory-safe") {
                        mstore(swapCallbackData, SWAP_CALLBACK_PREFIX_DATA_SIZE)
                    }
                }
                if (buyAmount < minBuyAmount) {
                    revert TooMuchSlippage(outputToken, minBuyAmount, buyAmount);
                }
            }
            // Return whether or not an encoded uniswap path contains more than one hop.
            function _isPathMultiHop(bytes memory encodedPath) private pure returns (bool) {
                return encodedPath.length > SINGLE_HOP_PATH_SIZE;
            }
            function _decodeFirstPoolInfoFromPath(bytes memory encodedPath)
                private
                pure
                returns (IERC20 inputToken, uint8 forkId, uint24 poolId, IERC20 outputToken)
            {
                if (encodedPath.length < SINGLE_HOP_PATH_SIZE) {
                    Panic.panic(Panic.ARRAY_OUT_OF_BOUNDS);
                }
                assembly ("memory-safe") {
                    // Solidity cleans dirty bits automatically
                    inputToken := mload(add(encodedPath, 0x14))
                    forkId := mload(add(encodedPath, 0x15))
                    poolId := mload(add(encodedPath, 0x18))
                    outputToken := mload(add(encodedPath, SINGLE_HOP_PATH_SIZE))
                }
            }
            // Skip past the first hop of an encoded uniswap path in-place.
            function _shiftHopFromPathInPlace(bytes memory encodedPath) private pure returns (bytes memory) {
                if (encodedPath.length < PATH_SKIP_HOP_SIZE) {
                    Panic.panic(Panic.ARRAY_OUT_OF_BOUNDS);
                }
                assembly ("memory-safe") {
                    let length := sub(mload(encodedPath), PATH_SKIP_HOP_SIZE)
                    encodedPath := add(encodedPath, PATH_SKIP_HOP_SIZE)
                    mstore(encodedPath, length)
                }
                return encodedPath;
            }
            function _encodePermit2Data(
                bytes memory swapCallbackData,
                ISignatureTransfer.PermitTransferFrom memory permit,
                bytes memory sig,
                bool isForwarded
            ) private pure {
                assembly ("memory-safe") {
                    mstore(add(SWAP_CALLBACK_PERMIT2DATA_OFFSET, swapCallbackData), mload(add(0x20, mload(permit))))
                    mcopy(add(add(SWAP_CALLBACK_PERMIT2DATA_OFFSET, 0x20), swapCallbackData), add(0x20, permit), 0x40)
                    mstore8(add(add(SWAP_CALLBACK_PERMIT2DATA_OFFSET, PERMIT_DATA_SIZE), swapCallbackData), isForwarded)
                    mcopy(
                        add(
                            add(add(SWAP_CALLBACK_PERMIT2DATA_OFFSET, PERMIT_DATA_SIZE), ISFORWARDED_DATA_SIZE),
                            swapCallbackData
                        ),
                        add(0x20, sig),
                        mload(sig)
                    )
                }
            }
            // Update `swapCallbackData` in place with new values.
            function _updateSwapCallbackData(bytes memory swapCallbackData, IERC20 sellToken, address payer) private pure {
                assembly ("memory-safe") {
                    let length := mload(swapCallbackData)
                    mstore(add(0x28, swapCallbackData), sellToken)
                    mstore(add(0x14, swapCallbackData), payer)
                    mstore(swapCallbackData, length)
                }
            }
            // Compute the pool address given two tokens and a poolId.
            function _toPool(address factory, bytes32 initHash, IERC20 token0, IERC20 token1, uint24 poolId)
                private
                pure
                returns (IUniswapV3Pool)
            {
                // address(keccak256(abi.encodePacked(
                //     hex"ff",
                //     factory,
                //     keccak256(abi.encode(token0, token1, poolId)),
                //     initHash
                // )))
                bytes32 salt;
                assembly ("memory-safe") {
                    token0 := and(ADDRESS_MASK, token0)
                    token1 := and(ADDRESS_MASK, token1)
                    poolId := and(UINT24_MASK, poolId)
                    let ptr := mload(0x40)
                    mstore(0x00, token0)
                    mstore(0x20, token1)
                    mstore(0x40, poolId)
                    salt := keccak256(0x00, sub(0x60, shl(0x05, iszero(poolId))))
                    mstore(0x40, ptr)
                }
                return IUniswapV3Pool(AddressDerivation.deriveDeterministicContract(factory, salt, initHash));
            }
            function _uniV3ForkInfo(uint8 forkId) internal view virtual returns (address, bytes32, uint32);
            function _uniV3ForkCallback(bytes calldata data) private returns (bytes memory) {
                require(data.length >= 0x80);
                int256 amount0Delta;
                int256 amount1Delta;
                assembly ("memory-safe") {
                    amount0Delta := calldataload(data.offset)
                    amount1Delta := calldataload(add(0x20, data.offset))
                    data.offset := add(data.offset, calldataload(add(0x40, data.offset)))
                    data.length := calldataload(data.offset)
                    data.offset := add(0x20, data.offset)
                }
                uniswapV3SwapCallback(amount0Delta, amount1Delta, data);
                return new bytes(0);
            }
            /// @dev The UniswapV3 pool swap callback which pays the funds requested
            ///      by the caller/pool to the pool. Can only be called by a valid
            ///      UniswapV3 pool.
            /// @param amount0Delta Token0 amount owed.
            /// @param amount1Delta Token1 amount owed.
            /// @param data Arbitrary data forwarded from swap() caller. A packed encoding of: payer, sellToken, (optionally: permit[0x20:], isForwarded, sig)
            function uniswapV3SwapCallback(int256 amount0Delta, int256 amount1Delta, bytes calldata data) private {
                address payer = address(uint160(bytes20(data)));
                data = data[0x14:];
                uint256 sellAmount = amount0Delta > 0 ? uint256(amount0Delta) : uint256(amount1Delta);
                _pay(payer, sellAmount, data);
            }
            function _pay(address payer, uint256 amount, bytes calldata permit2Data) private {
                if (payer == address(this)) {
                    IERC20(address(uint160(bytes20(permit2Data)))).safeTransfer(msg.sender, amount);
                } else {
                    assert(payer == address(0));
                    ISignatureTransfer.PermitTransferFrom calldata permit;
                    bool isForwarded;
                    bytes calldata sig;
                    assembly ("memory-safe") {
                        // this is super dirty, but it works because although `permit` is aliasing in the
                        // middle of `payer`, because `payer` is all zeroes, it's treated as padding for the
                        // first word of `permit`, which is the sell token
                        permit := sub(permit2Data.offset, 0x0c)
                        isForwarded := and(0x01, calldataload(add(0x55, permit2Data.offset)))
                        sig.offset := add(0x75, permit2Data.offset)
                        sig.length := sub(permit2Data.length, 0x75)
                    }
                    ISignatureTransfer.SignatureTransferDetails memory transferDetails =
                        ISignatureTransfer.SignatureTransferDetails({to: msg.sender, requestedAmount: amount});
                    _transferFrom(permit, transferDetails, sig, isForwarded);
                }
            }
        }
        // src/core/Basic.sol
        abstract contract Basic is SettlerAbstract {
            using SafeTransferLib for IERC20;
            using FullMath for uint256;
            using Revert for bool;
            IERC20 internal constant ETH_ADDRESS = IERC20(0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE);
            /// @dev Sell to a pool with a generic approval, transferFrom interaction.
            /// offset in the calldata is used to update the sellAmount given a proportion of the sellToken balance
            function basicSellToPool(IERC20 sellToken, uint256 bps, address pool, uint256 offset, bytes memory data) internal {
                if (_isRestrictedTarget(pool)) {
                    revert ConfusedDeputy();
                }
                bool success;
                bytes memory returnData;
                uint256 value;
                if (sellToken == IERC20(ETH_ADDRESS)) {
                    value = address(this).balance.mulDiv(bps, BASIS);
                    if (data.length == 0) {
                        if (offset != 0) revert InvalidOffset();
                        (success, returnData) = payable(pool).call{value: value}("");
                        success.maybeRevert(returnData);
                        return;
                    } else {
                        if ((offset += 32) > data.length) {
                            Panic.panic(Panic.ARRAY_OUT_OF_BOUNDS);
                        }
                        assembly ("memory-safe") {
                            mstore(add(data, offset), value)
                        }
                    }
                } else if (address(sellToken) == address(0)) {
                    // TODO: check for zero `bps`
                    if (offset != 0) revert InvalidOffset();
                } else {
                    uint256 amount = sellToken.balanceOf(address(this)).mulDiv(bps, BASIS);
                    if ((offset += 32) > data.length) {
                        Panic.panic(Panic.ARRAY_OUT_OF_BOUNDS);
                    }
                    assembly ("memory-safe") {
                        mstore(add(data, offset), amount)
                    }
                    if (address(sellToken) != pool) {
                        sellToken.safeApproveIfBelow(pool, amount);
                    }
                }
                (success, returnData) = payable(pool).call{value: value}(data);
                success.maybeRevert(returnData);
                // forbid sending data to EOAs
                if (returnData.length == 0 && pool.code.length == 0) revert InvalidTarget();
            }
        }
        // src/core/Permit2Payment.sol
        library TransientStorage {
            // bytes32(uint256(keccak256("operator slot")) - 1)
            bytes32 private constant _OPERATOR_SLOT = 0x009355806b743562f351db2e3726091207f49fa1cdccd5c65a7d4860ce3abbe9;
            // bytes32(uint256(keccak256("witness slot")) - 1)
            bytes32 private constant _WITNESS_SLOT = 0x1643bf8e9fdaef48c4abf5a998de359be44a235ac7aebfbc05485e093720deaa;
            // bytes32(uint256(keccak256("payer slot")) - 1)
            bytes32 private constant _PAYER_SLOT = 0x46bacb9b87ba1d2910347e4a3e052d06c824a45acd1e9517bb0cb8d0d5cde893;
            // We assume (and our CI enforces) that internal function pointers cannot be
            // greater than 2 bytes. On chains not supporting the ViaIR pipeline, not
            // supporting EOF, and where the Spurious Dragon size limit is not enforced,
            // it might be possible to violate this assumption. However, our
            // `foundry.toml` enforces the use of the IR pipeline, so the point is moot.
            //
            // `operator` must not be `address(0)`. This is not checked.
            // `callback` must not be zero. This is checked in `_invokeCallback`.
            function setOperatorAndCallback(
                address operator,
                uint32 selector,
                function (bytes calldata) internal returns (bytes memory) callback
            ) internal {
                address currentSigner;
                assembly ("memory-safe") {
                    currentSigner := tload(_PAYER_SLOT)
                }
                if (operator == currentSigner) {
                    revert ConfusedDeputy();
                }
                uint256 callbackInt;
                assembly ("memory-safe") {
                    callbackInt := tload(_OPERATOR_SLOT)
                }
                if (callbackInt != 0) {
                    // It should be impossible to reach this error because the first thing the fallback does
                    // is clear the operator. It's also not possible to reenter the entrypoint function
                    // because `_PAYER_SLOT` is an implicit reentrancy guard.
                    revert ReentrantCallback(callbackInt);
                }
                assembly ("memory-safe") {
                    tstore(
                        _OPERATOR_SLOT,
                        or(
                            shl(0xe0, selector),
                            or(shl(0xa0, and(0xffff, callback)), and(0xffffffffffffffffffffffffffffffffffffffff, operator))
                        )
                    )
                }
            }
            function checkSpentOperatorAndCallback() internal view {
                uint256 callbackInt;
                assembly ("memory-safe") {
                    callbackInt := tload(_OPERATOR_SLOT)
                }
                if (callbackInt != 0) {
                    revert CallbackNotSpent(callbackInt);
                }
            }
            function getAndClearOperatorAndCallback()
                internal
                returns (bytes4 selector, function (bytes calldata) internal returns (bytes memory) callback, address operator)
            {
                assembly ("memory-safe") {
                    selector := tload(_OPERATOR_SLOT)
                    callback := and(0xffff, shr(0xa0, selector))
                    operator := selector
                    tstore(_OPERATOR_SLOT, 0x00)
                }
            }
            // `newWitness` must not be `bytes32(0)`. This is not checked.
            function setWitness(bytes32 newWitness) internal {
                bytes32 currentWitness;
                assembly ("memory-safe") {
                    currentWitness := tload(_WITNESS_SLOT)
                }
                if (currentWitness != bytes32(0)) {
                    // It should be impossible to reach this error because the first thing a metatransaction
                    // does on entry is to spend the `witness` (either directly or via a callback)
                    revert ReentrantMetatransaction(currentWitness);
                }
                assembly ("memory-safe") {
                    tstore(_WITNESS_SLOT, newWitness)
                }
            }
            function checkSpentWitness() internal view {
                bytes32 currentWitness;
                assembly ("memory-safe") {
                    currentWitness := tload(_WITNESS_SLOT)
                }
                if (currentWitness != bytes32(0)) {
                    revert WitnessNotSpent(currentWitness);
                }
            }
            function getAndClearWitness() internal returns (bytes32 witness) {
                assembly ("memory-safe") {
                    witness := tload(_WITNESS_SLOT)
                    tstore(_WITNESS_SLOT, 0x00)
                }
            }
            function setPayer(address payer) internal {
                if (payer == address(0)) {
                    revert ConfusedDeputy();
                }
                address oldPayer;
                assembly ("memory-safe") {
                    oldPayer := tload(_PAYER_SLOT)
                }
                if (oldPayer != address(0)) {
                    revert ReentrantPayer(oldPayer);
                }
                assembly ("memory-safe") {
                    tstore(_PAYER_SLOT, and(0xffffffffffffffffffffffffffffffffffffffff, payer))
                }
            }
            function getPayer() internal view returns (address payer) {
                assembly ("memory-safe") {
                    payer := tload(_PAYER_SLOT)
                }
            }
            function clearPayer(address expectedOldPayer) internal {
                address oldPayer;
                assembly ("memory-safe") {
                    oldPayer := tload(_PAYER_SLOT)
                }
                if (oldPayer != expectedOldPayer) {
                    revert PayerSpent();
                }
                assembly ("memory-safe") {
                    tstore(_PAYER_SLOT, 0x00)
                }
            }
        }
        abstract contract Permit2PaymentBase is SettlerAbstract {
            using Revert for bool;
            /// @dev Permit2 address
            ISignatureTransfer internal constant _PERMIT2 = ISignatureTransfer(0x000000000022D473030F116dDEE9F6B43aC78BA3);
            function _isRestrictedTarget(address target) internal pure virtual override returns (bool) {
                return target == address(_PERMIT2);
            }
            function _msgSender() internal view virtual override returns (address) {
                return TransientStorage.getPayer();
            }
            /// @dev You must ensure that `target` is derived by hashing trusted initcode or another
            ///      equivalent mechanism that guarantees "reasonable"ness. `target` must not be
            ///      user-supplied or attacker-controlled. This is required for security and is not checked
            ///      here. For example, it must not do something weird like modifying the spender (possibly
            ///      setting it to itself). If the callback is expected to relay a
            ///      `ISignatureTransfer.PermitTransferFrom` struct, then the computation of `target` using
            ///      the trusted initcode (or equivalent) must ensure that that calldata is relayed
            ///      unmodified. The library function `AddressDerivation.deriveDeterministicContract` is
            ///      recommended.
            function _setOperatorAndCall(
                address payable target,
                uint256 value,
                bytes memory data,
                uint32 selector,
                function (bytes calldata) internal returns (bytes memory) callback
            ) internal returns (bytes memory) {
                TransientStorage.setOperatorAndCallback(target, selector, callback);
                (bool success, bytes memory returndata) = target.call{value: value}(data);
                success.maybeRevert(returndata);
                TransientStorage.checkSpentOperatorAndCallback();
                return returndata;
            }
            function _setOperatorAndCall(
                address target,
                bytes memory data,
                uint32 selector,
                function (bytes calldata) internal returns (bytes memory) callback
            ) internal override returns (bytes memory) {
                return _setOperatorAndCall(payable(target), 0, data, selector, callback);
            }
            function _invokeCallback(bytes calldata data) internal returns (bytes memory) {
                // Retrieve callback and perform call with untrusted calldata
                (bytes4 selector, function (bytes calldata) internal returns (bytes memory) callback, address operator) =
                    TransientStorage.getAndClearOperatorAndCallback();
                require(bytes4(data) == selector);
                require(msg.sender == operator);
                return callback(data[4:]);
            }
        }
        abstract contract Permit2Payment is Permit2PaymentBase {
            using FullMath for uint256;
            fallback(bytes calldata data) external virtual returns (bytes memory) {
                return _invokeCallback(data);
            }
            function _permitToSellAmount(ISignatureTransfer.PermitTransferFrom memory permit)
                internal
                view
                override
                returns (uint256 sellAmount)
            {
                sellAmount = permit.permitted.amount;
                if (sellAmount > type(uint256).max - BASIS) {
                    unchecked {
                        sellAmount -= type(uint256).max - BASIS;
                    }
                    sellAmount = IERC20(permit.permitted.token).balanceOf(_msgSender()).mulDiv(sellAmount, BASIS);
                }
            }
            function _permitToTransferDetails(ISignatureTransfer.PermitTransferFrom memory permit, address recipient)
                internal
                view
                override
                returns (ISignatureTransfer.SignatureTransferDetails memory transferDetails, uint256 sellAmount)
            {
                transferDetails.to = recipient;
                transferDetails.requestedAmount = sellAmount = _permitToSellAmount(permit);
            }
            // This function is provided *EXCLUSIVELY* for use here and in RfqOrderSettlement. Any other use
            // of this function is forbidden. You must use the version that does *NOT* take a `from` or
            // `witness` argument.
            function _transferFromIKnowWhatImDoing(
                ISignatureTransfer.PermitTransferFrom memory permit,
                ISignatureTransfer.SignatureTransferDetails memory transferDetails,
                address from,
                bytes32 witness,
                string memory witnessTypeString,
                bytes memory sig,
                bool isForwarded
            ) internal override {
                if (isForwarded) revert ForwarderNotAllowed();
                _PERMIT2.permitWitnessTransferFrom(permit, transferDetails, from, witness, witnessTypeString, sig);
            }
            // See comment in above overload; don't use this function
            function _transferFromIKnowWhatImDoing(
                ISignatureTransfer.PermitTransferFrom memory permit,
                ISignatureTransfer.SignatureTransferDetails memory transferDetails,
                address from,
                bytes32 witness,
                string memory witnessTypeString,
                bytes memory sig
            ) internal override {
                _transferFromIKnowWhatImDoing(permit, transferDetails, from, witness, witnessTypeString, sig, _isForwarded());
            }
            function _transferFrom(
                ISignatureTransfer.PermitTransferFrom memory permit,
                ISignatureTransfer.SignatureTransferDetails memory transferDetails,
                bytes memory sig
            ) internal override {
                _transferFrom(permit, transferDetails, sig, _isForwarded());
            }
        }
        abstract contract Permit2PaymentTakerSubmitted is AllowanceHolderContext, Permit2Payment {
            constructor() {
                assert(!_hasMetaTxn());
            }
            function _isRestrictedTarget(address target) internal pure virtual override returns (bool) {
                return target == address(_ALLOWANCE_HOLDER) || super._isRestrictedTarget(target);
            }
            function _operator() internal view override returns (address) {
                return AllowanceHolderContext._msgSender();
            }
            function _msgSender()
                internal
                view
                virtual
                override(Permit2PaymentBase, AllowanceHolderContext)
                returns (address)
            {
                return Permit2PaymentBase._msgSender();
            }
            function _transferFrom(
                ISignatureTransfer.PermitTransferFrom memory permit,
                ISignatureTransfer.SignatureTransferDetails memory transferDetails,
                bytes memory sig,
                bool isForwarded
            ) internal override {
                if (isForwarded) {
                    if (sig.length != 0) revert InvalidSignatureLen();
                    if (permit.nonce != 0) Panic.panic(Panic.ARITHMETIC_OVERFLOW);
                    if (block.timestamp > permit.deadline) revert SignatureExpired(permit.deadline);
                    // we don't check `requestedAmount` because it's checked by AllowanceHolder itself
                    _allowanceHolderTransferFrom(
                        permit.permitted.token, _msgSender(), transferDetails.to, transferDetails.requestedAmount
                    );
                } else {
                    _PERMIT2.permitTransferFrom(permit, transferDetails, _msgSender(), sig);
                }
            }
            function _allowanceHolderTransferFrom(address token, address owner, address recipient, uint256 amount)
                internal
                override
            {
                // `owner` is always `_msgSender()`
                _ALLOWANCE_HOLDER.transferFrom(token, owner, recipient, amount);
            }
            modifier takerSubmitted() override {
                address msgSender = _operator();
                TransientStorage.setPayer(msgSender);
                _;
                TransientStorage.clearPayer(msgSender);
            }
            modifier metaTx(address, bytes32) override {
                revert();
                _;
            }
        }
        abstract contract Permit2PaymentMetaTxn is Context, Permit2Payment {
            constructor() {
                assert(_hasMetaTxn());
            }
            function _operator() internal view override returns (address) {
                return Context._msgSender();
            }
            function _msgSender() internal view virtual override(Permit2PaymentBase, Context) returns (address) {
                return Permit2PaymentBase._msgSender();
            }
            // `string.concat` isn't recognized by solc as compile-time constant, but `abi.encodePacked` is
            // This is defined here as `private` and not in `SettlerAbstract` as `internal` because no other
            // contract/file should reference it. The *ONLY* approved way to make a transfer using this
            // witness string is by setting the witness with modifier `metaTx`
            string private constant _SLIPPAGE_AND_ACTIONS_WITNESS = string(
                abi.encodePacked("SlippageAndActions slippageAndActions)", SLIPPAGE_AND_ACTIONS_TYPE, TOKEN_PERMISSIONS_TYPE)
            );
            function _transferFrom(
                ISignatureTransfer.PermitTransferFrom memory permit,
                ISignatureTransfer.SignatureTransferDetails memory transferDetails,
                bytes memory sig,
                bool isForwarded // must be false
            ) internal override {
                bytes32 witness = TransientStorage.getAndClearWitness();
                if (witness == bytes32(0)) {
                    revert ConfusedDeputy();
                }
                _transferFromIKnowWhatImDoing(
                    permit, transferDetails, _msgSender(), witness, _SLIPPAGE_AND_ACTIONS_WITNESS, sig, isForwarded
                );
            }
            function _allowanceHolderTransferFrom(address, address, address, uint256) internal pure override {
                revert ConfusedDeputy();
            }
            modifier takerSubmitted() override {
                revert();
                _;
            }
            modifier metaTx(address msgSender, bytes32 witness) override {
                if (_isForwarded()) {
                    revert ForwarderNotAllowed();
                }
                TransientStorage.setWitness(witness);
                TransientStorage.setPayer(msgSender);
                _;
                TransientStorage.clearPayer(msgSender);
                // It should not be possible for this check to revert because the very first thing that a
                // metatransaction does is spend the witness.
                TransientStorage.checkSpentWitness();
            }
        }
        // src/SettlerBase.sol
        /// @dev This library's ABIDeocding is more lax than the Solidity ABIDecoder. This library omits index bounds/overflow
        /// checking when accessing calldata arrays for gas efficiency. It also omits checks against `calldatasize()`. This
        /// means that it is possible that `args` will run off the end of calldata and be implicitly padded with zeroes. That we
        /// don't check for overflow means that offsets can be negative. This can also result in `args` that alias other parts
        /// of calldata, or even the `actions` array itself.
        library CalldataDecoder {
            function decodeCall(bytes[] calldata data, uint256 i)
                internal
                pure
                returns (bytes4 selector, bytes calldata args)
            {
                assembly ("memory-safe") {
                    // initially, we set `args.offset` to the pointer to the length. this is 32 bytes before the actual start of data
                    args.offset :=
                        add(
                            data.offset,
                            // We allow the indirection/offset to `calls[i]` to be negative
                            calldataload(
                                add(shl(5, i), data.offset) // can't overflow; we assume `i` is in-bounds
                            )
                        )
                    // now we load `args.length` and set `args.offset` to the start of data
                    args.length := calldataload(args.offset)
                    args.offset := add(args.offset, 0x20)
                    // slice off the first 4 bytes of `args` as the selector
                    selector := calldataload(args.offset) // solidity cleans dirty bits automatically
                    args.length := sub(args.length, 0x04)
                    args.offset := add(args.offset, 0x04)
                }
            }
        }
        abstract contract SettlerBase is Basic, RfqOrderSettlement, UniswapV3Fork, UniswapV2, Velodrome {
            using SafeTransferLib for IERC20;
            using SafeTransferLib for address payable;
            receive() external payable {}
            event GitCommit(bytes20 indexed);
            constructor(bytes20 gitCommit, uint256 tokenId) {
                if (block.chainid != 31337) {
                    emit GitCommit(gitCommit);
                    assert(IERC721Owner(0x00000000000004533Fe15556B1E086BB1A72cEae).ownerOf(tokenId) == address(this));
                } else {
                    assert(gitCommit == bytes20(0));
                }
            }
            struct AllowedSlippage {
                address recipient;
                IERC20 buyToken;
                uint256 minAmountOut;
            }
            function _checkSlippageAndTransfer(AllowedSlippage calldata slippage) internal {
                // This final slippage check effectively prohibits custody optimization on the
                // final hop of every swap. This is gas-inefficient. This is on purpose. Because
                // ISettlerActions.BASIC could interact with an intents-based settlement
                // mechanism, we must ensure that the user's want token increase is coming
                // directly from us instead of from some other form of exchange of value.
                (address recipient, IERC20 buyToken, uint256 minAmountOut) =
                    (slippage.recipient, slippage.buyToken, slippage.minAmountOut);
                if (minAmountOut != 0 || address(buyToken) != address(0)) {
                    if (buyToken == ETH_ADDRESS) {
                        uint256 amountOut = address(this).balance;
                        if (amountOut < minAmountOut) {
                            revert TooMuchSlippage(buyToken, minAmountOut, amountOut);
                        }
                        payable(recipient).safeTransferETH(amountOut);
                    } else {
                        uint256 amountOut = buyToken.balanceOf(address(this));
                        if (amountOut < minAmountOut) {
                            revert TooMuchSlippage(buyToken, minAmountOut, amountOut);
                        }
                        buyToken.safeTransfer(recipient, amountOut);
                    }
                }
            }
            function _dispatch(uint256, bytes4 action, bytes calldata data) internal virtual override returns (bool) {
                if (action == ISettlerActions.TRANSFER_FROM.selector) {
                    (address recipient, ISignatureTransfer.PermitTransferFrom memory permit, bytes memory sig) =
                        abi.decode(data, (address, ISignatureTransfer.PermitTransferFrom, bytes));
                    (ISignatureTransfer.SignatureTransferDetails memory transferDetails,) =
                        _permitToTransferDetails(permit, recipient);
                    _transferFrom(permit, transferDetails, sig);
                } else if (action == ISettlerActions.RFQ.selector) {
                    (
                        address recipient,
                        ISignatureTransfer.PermitTransferFrom memory permit,
                        address maker,
                        bytes memory makerSig,
                        IERC20 takerToken,
                        uint256 maxTakerAmount
                    ) = abi.decode(data, (address, ISignatureTransfer.PermitTransferFrom, address, bytes, IERC20, uint256));
                    fillRfqOrderSelfFunded(recipient, permit, maker, makerSig, takerToken, maxTakerAmount);
                } else if (action == ISettlerActions.UNISWAPV3.selector) {
                    (address recipient, uint256 bps, bytes memory path, uint256 amountOutMin) =
                        abi.decode(data, (address, uint256, bytes, uint256));
                    sellToUniswapV3(recipient, bps, path, amountOutMin);
                } else if (action == ISettlerActions.UNISWAPV2.selector) {
                    (address recipient, address sellToken, uint256 bps, address pool, uint24 swapInfo, uint256 amountOutMin) =
                        abi.decode(data, (address, address, uint256, address, uint24, uint256));
                    sellToUniswapV2(recipient, sellToken, bps, pool, swapInfo, amountOutMin);
                } else if (action == ISettlerActions.BASIC.selector) {
                    (IERC20 sellToken, uint256 bps, address pool, uint256 offset, bytes memory _data) =
                        abi.decode(data, (IERC20, uint256, address, uint256, bytes));
                    basicSellToPool(sellToken, bps, pool, offset, _data);
                } else if (action == ISettlerActions.VELODROME.selector) {
                    (address recipient, uint256 bps, IVelodromePair pool, uint24 swapInfo, uint256 minAmountOut) =
                        abi.decode(data, (address, uint256, IVelodromePair, uint24, uint256));
                    sellToVelodrome(recipient, bps, pool, swapInfo, minAmountOut);
                } else if (action == ISettlerActions.POSITIVE_SLIPPAGE.selector) {
                    (address recipient, IERC20 token, uint256 expectedAmount) = abi.decode(data, (address, IERC20, uint256));
                    if (token == IERC20(ETH_ADDRESS)) {
                        uint256 balance = address(this).balance;
                        if (balance > expectedAmount) {
                            unchecked {
                                payable(recipient).safeTransferETH(balance - expectedAmount);
                            }
                        }
                    } else {
                        uint256 balance = token.balanceOf(address(this));
                        if (balance > expectedAmount) {
                            unchecked {
                                token.safeTransfer(recipient, balance - expectedAmount);
                            }
                        }
                    }
                } else {
                    return false;
                }
                return true;
            }
        }
        // src/Settler.sol
        abstract contract Settler is Permit2PaymentTakerSubmitted, SettlerBase {
            using UnsafeMath for uint256;
            using CalldataDecoder for bytes[];
            // When/if you change this, you must make corresponding changes to
            // `sh/deploy_new_chain.sh` and 'sh/common_deploy_settler.sh' to set
            // `constructor_args`.
            constructor(bytes20 gitCommit) SettlerBase(gitCommit, 2) {}
            function _hasMetaTxn() internal pure override returns (bool) {
                return false;
            }
            function _msgSender()
                internal
                view
                virtual
                // Solidity inheritance is so stupid
                override(Permit2PaymentTakerSubmitted, AbstractContext)
                returns (address)
            {
                return super._msgSender();
            }
            function _isRestrictedTarget(address target)
                internal
                pure
                virtual
                // Solidity inheritance is so stupid
                override(Permit2PaymentTakerSubmitted, Permit2PaymentAbstract)
                returns (bool)
            {
                return super._isRestrictedTarget(target);
            }
            function _dispatchVIP(bytes4 action, bytes calldata data) internal virtual returns (bool) {
                if (action == ISettlerActions.RFQ_VIP.selector) {
                    (
                        address recipient,
                        ISignatureTransfer.PermitTransferFrom memory makerPermit,
                        address maker,
                        bytes memory makerSig,
                        ISignatureTransfer.PermitTransferFrom memory takerPermit,
                        bytes memory takerSig
                    ) = abi.decode(
                        data,
                        (
                            address,
                            ISignatureTransfer.PermitTransferFrom,
                            address,
                            bytes,
                            ISignatureTransfer.PermitTransferFrom,
                            bytes
                        )
                    );
                    fillRfqOrderVIP(recipient, makerPermit, maker, makerSig, takerPermit, takerSig);
                } else if (action == ISettlerActions.UNISWAPV3_VIP.selector) {
                    (
                        address recipient,
                        bytes memory path,
                        ISignatureTransfer.PermitTransferFrom memory permit,
                        bytes memory sig,
                        uint256 amountOutMin
                    ) = abi.decode(data, (address, bytes, ISignatureTransfer.PermitTransferFrom, bytes, uint256));
                    sellToUniswapV3VIP(recipient, path, permit, sig, amountOutMin);
                } else {
                    return false;
                }
                return true;
            }
            function execute(AllowedSlippage calldata slippage, bytes[] calldata actions, bytes32 /* zid & affiliate */ )
                public
                payable
                takerSubmitted
                returns (bool)
            {
                if (actions.length != 0) {
                    (bytes4 action, bytes calldata data) = actions.decodeCall(0);
                    if (!_dispatchVIP(action, data)) {
                        if (!_dispatch(0, action, data)) {
                            revert ActionInvalid(0, action, data);
                        }
                    }
                }
                for (uint256 i = 1; i < actions.length; i = i.unsafeInc()) {
                    (bytes4 action, bytes calldata data) = actions.decodeCall(i);
                    if (!_dispatch(i, action, data)) {
                        revert ActionInvalid(i, action, data);
                    }
                }
                _checkSlippageAndTransfer(slippage);
                return true;
            }
        }
        // src/SettlerMetaTxn.sol
        abstract contract SettlerMetaTxn is Permit2PaymentMetaTxn, SettlerBase {
            using UnsafeMath for uint256;
            using CalldataDecoder for bytes[];
            // When/if you change this, you must make corresponding changes to
            // `sh/deploy_new_chain.sh` and 'sh/common_deploy_settler.sh' to set
            // `constructor_args`.
            constructor(bytes20 gitCommit) SettlerBase(gitCommit, 3) {}
            function _hasMetaTxn() internal pure override returns (bool) {
                return true;
            }
            function _msgSender()
                internal
                view
                virtual
                // Solidity inheritance is so stupid
                override(Permit2PaymentMetaTxn, AbstractContext)
                returns (address)
            {
                return super._msgSender();
            }
            function _hashArrayOfBytes(bytes[] calldata actions) internal pure returns (bytes32 result) {
                // This function deliberately does no bounds checking on `actions` for
                // gas efficiency. We assume that `actions` will get used elsewhere in
                // this context and any OOB or other malformed calldata will result in a
                // revert later.
                assembly ("memory-safe") {
                    let ptr := mload(0x40)
                    let hashesLength := shl(5, actions.length)
                    for {
                        let i := actions.offset
                        let dst := ptr
                        let end := add(i, hashesLength)
                    } lt(i, end) {
                        i := add(i, 0x20)
                        dst := add(dst, 0x20)
                    } {
                        let src := add(actions.offset, calldataload(i))
                        let length := calldataload(src)
                        calldatacopy(dst, add(src, 0x20), length)
                        mstore(dst, keccak256(dst, length))
                    }
                    result := keccak256(ptr, hashesLength)
                }
            }
            function _hashActionsAndSlippage(bytes[] calldata actions, AllowedSlippage calldata slippage)
                internal
                pure
                returns (bytes32 result)
            {
                // This function does not check for or clean any dirty bits that might
                // exist in `slippage`. We assume that `slippage` will be used elsewhere
                // in this context and that if there are dirty bits it will result in a
                // revert later.
                bytes32 arrayOfBytesHash = _hashArrayOfBytes(actions);
                assembly ("memory-safe") {
                    let ptr := mload(0x40)
                    mstore(ptr, SLIPPAGE_AND_ACTIONS_TYPEHASH)
                    calldatacopy(add(ptr, 0x20), slippage, 0x60)
                    mstore(add(ptr, 0x80), arrayOfBytesHash)
                    result := keccak256(ptr, 0xa0)
                }
            }
            function _dispatchVIP(bytes4 action, bytes calldata data, bytes calldata sig) internal virtual returns (bool) {
                if (action == ISettlerActions.METATXN_RFQ_VIP.selector) {
                    // An optimized path involving a maker/taker in a single trade
                    // The RFQ order is signed by both maker and taker, validation is
                    // performed inside the RfqOrderSettlement so there is no need to
                    // validate `sig` against `actions` here
                    (
                        address recipient,
                        ISignatureTransfer.PermitTransferFrom memory makerPermit,
                        address maker,
                        bytes memory makerSig,
                        ISignatureTransfer.PermitTransferFrom memory takerPermit
                    ) = abi.decode(
                        data,
                        (address, ISignatureTransfer.PermitTransferFrom, address, bytes, ISignatureTransfer.PermitTransferFrom)
                    );
                    fillRfqOrderVIP(recipient, makerPermit, maker, makerSig, takerPermit, sig);
                } else if (action == ISettlerActions.METATXN_TRANSFER_FROM.selector) {
                    (address recipient, ISignatureTransfer.PermitTransferFrom memory permit) =
                        abi.decode(data, (address, ISignatureTransfer.PermitTransferFrom));
                    (ISignatureTransfer.SignatureTransferDetails memory transferDetails,) =
                        _permitToTransferDetails(permit, recipient);
                    // We simultaneously transfer-in the taker's tokens and authenticate the
                    // metatransaction.
                    _transferFrom(permit, transferDetails, sig);
                } else if (action == ISettlerActions.METATXN_UNISWAPV3_VIP.selector) {
                    (
                        address recipient,
                        bytes memory path,
                        ISignatureTransfer.PermitTransferFrom memory permit,
                        uint256 amountOutMin
                    ) = abi.decode(data, (address, bytes, ISignatureTransfer.PermitTransferFrom, uint256));
                    sellToUniswapV3VIP(recipient, path, permit, sig, amountOutMin);
                } else {
                    return false;
                }
                return true;
            }
            function executeMetaTxn(
                AllowedSlippage calldata slippage,
                bytes[] calldata actions,
                bytes32, /* zid & affiliate */
                address msgSender,
                bytes calldata sig
            ) public metaTx(msgSender, _hashActionsAndSlippage(actions, slippage)) returns (bool) {
                require(actions.length != 0);
                {
                    (bytes4 action, bytes calldata data) = actions.decodeCall(0);
                    // By forcing the first action to be one of the witness-aware
                    // actions, we ensure that the entire sequence of actions is
                    // authorized. `msgSender` is the signer of the metatransaction.
                    if (!_dispatchVIP(action, data, sig)) {
                        revert ActionInvalid(0, action, data);
                    }
                }
                for (uint256 i = 1; i < actions.length; i = i.unsafeInc()) {
                    (bytes4 action, bytes calldata data) = actions.decodeCall(i);
                    if (!_dispatch(i, action, data)) {
                        revert ActionInvalid(i, action, data);
                    }
                }
                _checkSlippageAndTransfer(slippage);
                return true;
            }
        }
        // src/chains/Mainnet.sol
        // Solidity inheritance is stupid
        abstract contract MainnetMixin is FreeMemory, SettlerBase, MakerPSM, MaverickV2, CurveTricrypto, DodoV1, DodoV2 {
            constructor() {
                assert(block.chainid == 1 || block.chainid == 31337);
            }
            function _dispatch(uint256 i, bytes4 action, bytes calldata data)
                internal
                virtual
                override(SettlerAbstract, SettlerBase)
                DANGEROUS_freeMemory
                returns (bool)
            {
                if (super._dispatch(i, action, data)) {
                    return true;
                } else if (action == ISettlerActions.MAKERPSM.selector) {
                    (address recipient, IERC20 gemToken, uint256 bps, IPSM psm, bool buyGem, uint256 amountOutMin) =
                        abi.decode(data, (address, IERC20, uint256, IPSM, bool, uint256));
                    sellToMakerPsm(recipient, gemToken, bps, psm, buyGem, amountOutMin);
                } else if (action == ISettlerActions.MAVERICKV2.selector) {
                    (
                        address recipient,
                        IERC20 sellToken,
                        uint256 bps,
                        IMaverickV2Pool pool,
                        bool tokenAIn,
                        uint256 minBuyAmount
                    ) = abi.decode(data, (address, IERC20, uint256, IMaverickV2Pool, bool, uint256));
                    sellToMaverickV2(recipient, sellToken, bps, pool, tokenAIn, minBuyAmount);
                } else if (action == ISettlerActions.DODOV2.selector) {
                    (address recipient, IERC20 sellToken, uint256 bps, IDodoV2 dodo, bool quoteForBase, uint256 minBuyAmount) =
                        abi.decode(data, (address, IERC20, uint256, IDodoV2, bool, uint256));
                    sellToDodoV2(recipient, sellToken, bps, dodo, quoteForBase, minBuyAmount);
                } else if (action == ISettlerActions.DODOV1.selector) {
                    (IERC20 sellToken, uint256 bps, IDodoV1 dodo, bool quoteForBase, uint256 minBuyAmount) =
                        abi.decode(data, (IERC20, uint256, IDodoV1, bool, uint256));
                    sellToDodoV1(sellToken, bps, dodo, quoteForBase, minBuyAmount);
                } else {
                    return false;
                }
                return true;
            }
            function _uniV3ForkInfo(uint8 forkId)
                internal
                pure
                override
                returns (address factory, bytes32 initHash, uint32 callbackSelector)
            {
                if (forkId == uniswapV3ForkId) {
                    factory = uniswapV3MainnetFactory;
                    initHash = uniswapV3InitHash;
                    callbackSelector = uint32(IUniswapV3Callback.uniswapV3SwapCallback.selector);
                } else if (forkId == pancakeSwapV3ForkId) {
                    factory = pancakeSwapV3Factory;
                    initHash = pancakeSwapV3InitHash;
                    callbackSelector = uint32(IPancakeSwapV3Callback.pancakeV3SwapCallback.selector);
                } else if (forkId == sushiswapV3ForkId) {
                    factory = sushiswapV3MainnetFactory;
                    initHash = uniswapV3InitHash;
                    callbackSelector = uint32(IUniswapV3Callback.uniswapV3SwapCallback.selector);
                } else if (forkId == solidlyV3ForkId) {
                    factory = solidlyV3Factory;
                    initHash = solidlyV3InitHash;
                    callbackSelector = uint32(ISolidlyV3Callback.solidlyV3SwapCallback.selector);
                } else {
                    revert UnknownForkId(forkId);
                }
            }
            function _curveFactory() internal pure override returns (address) {
                return 0x0c0e5f2fF0ff18a3be9b835635039256dC4B4963;
            }
        }
        /// @custom:security-contact [email protected]
        contract MainnetSettler is Settler, MainnetMixin {
            constructor(bytes20 gitCommit) Settler(gitCommit) {}
            function _dispatchVIP(bytes4 action, bytes calldata data) internal override DANGEROUS_freeMemory returns (bool) {
                if (super._dispatchVIP(action, data)) {
                    return true;
                } else if (action == ISettlerActions.MAVERICKV2_VIP.selector) {
                    (
                        address recipient,
                        bytes32 salt,
                        bool tokenAIn,
                        ISignatureTransfer.PermitTransferFrom memory permit,
                        bytes memory sig,
                        uint256 minBuyAmount
                    ) = abi.decode(data, (address, bytes32, bool, ISignatureTransfer.PermitTransferFrom, bytes, uint256));
                    sellToMaverickV2VIP(recipient, salt, tokenAIn, permit, sig, minBuyAmount);
                } else if (action == ISettlerActions.CURVE_TRICRYPTO_VIP.selector) {
                    (
                        address recipient,
                        uint80 poolInfo,
                        ISignatureTransfer.PermitTransferFrom memory permit,
                        bytes memory sig,
                        uint256 minBuyAmount
                    ) = abi.decode(data, (address, uint80, ISignatureTransfer.PermitTransferFrom, bytes, uint256));
                    sellToCurveTricryptoVIP(recipient, poolInfo, permit, sig, minBuyAmount);
                } else {
                    return false;
                }
                return true;
            }
            // Solidity inheritance is stupid
            function _isRestrictedTarget(address target)
                internal
                pure
                override(Settler, Permit2PaymentAbstract)
                returns (bool)
            {
                return super._isRestrictedTarget(target);
            }
            function _dispatch(uint256 i, bytes4 action, bytes calldata data)
                internal
                override(SettlerAbstract, SettlerBase, MainnetMixin)
                returns (bool)
            {
                return super._dispatch(i, action, data);
            }
            function _msgSender() internal view override(Settler, AbstractContext) returns (address) {
                return super._msgSender();
            }
        }
        /// @custom:security-contact [email protected]
        contract MainnetSettlerMetaTxn is SettlerMetaTxn, MainnetMixin {
            constructor(bytes20 gitCommit) SettlerMetaTxn(gitCommit) {}
            function _dispatchVIP(bytes4 action, bytes calldata data, bytes calldata sig)
                internal
                override
                DANGEROUS_freeMemory
                returns (bool)
            {
                if (super._dispatchVIP(action, data, sig)) {
                    return true;
                } else if (action == ISettlerActions.METATXN_MAVERICKV2_VIP.selector) {
                    (
                        address recipient,
                        bytes32 salt,
                        bool tokenAIn,
                        ISignatureTransfer.PermitTransferFrom memory permit,
                        uint256 minBuyAmount
                    ) = abi.decode(data, (address, bytes32, bool, ISignatureTransfer.PermitTransferFrom, uint256));
                    sellToMaverickV2VIP(recipient, salt, tokenAIn, permit, sig, minBuyAmount);
                } else if (action == ISettlerActions.METATXN_CURVE_TRICRYPTO_VIP.selector) {
                    (
                        address recipient,
                        uint80 poolInfo,
                        ISignatureTransfer.PermitTransferFrom memory permit,
                        uint256 minBuyAmount
                    ) = abi.decode(data, (address, uint80, ISignatureTransfer.PermitTransferFrom, uint256));
                    sellToCurveTricryptoVIP(recipient, poolInfo, permit, sig, minBuyAmount);
                } else {
                    return false;
                }
                return true;
            }
            // Solidity inheritance is stupid
            function _dispatch(uint256 i, bytes4 action, bytes calldata data)
                internal
                override(SettlerAbstract, SettlerBase, MainnetMixin)
                returns (bool)
            {
                return super._dispatch(i, action, data);
            }
            function _msgSender() internal view override(SettlerMetaTxn, AbstractContext) returns (address) {
                return super._msgSender();
            }
        }
        

        File 4 of 5: UniswapV2Pair
        // File: contracts/interfaces/IUniswapV2Pair.sol
        
        pragma solidity >=0.5.0;
        
        interface IUniswapV2Pair {
            event Approval(address indexed owner, address indexed spender, uint value);
            event Transfer(address indexed from, address indexed to, uint value);
        
            function name() external pure returns (string memory);
            function symbol() external pure returns (string memory);
            function decimals() external pure returns (uint8);
            function totalSupply() external view returns (uint);
            function balanceOf(address owner) external view returns (uint);
            function allowance(address owner, address spender) external view returns (uint);
        
            function approve(address spender, uint value) external returns (bool);
            function transfer(address to, uint value) external returns (bool);
            function transferFrom(address from, address to, uint value) external returns (bool);
        
            function DOMAIN_SEPARATOR() external view returns (bytes32);
            function PERMIT_TYPEHASH() external pure returns (bytes32);
            function nonces(address owner) external view returns (uint);
        
            function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
        
            event Mint(address indexed sender, uint amount0, uint amount1);
            event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
            event Swap(
                address indexed sender,
                uint amount0In,
                uint amount1In,
                uint amount0Out,
                uint amount1Out,
                address indexed to
            );
            event Sync(uint112 reserve0, uint112 reserve1);
        
            function MINIMUM_LIQUIDITY() external pure returns (uint);
            function factory() external view returns (address);
            function token0() external view returns (address);
            function token1() external view returns (address);
            function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
            function price0CumulativeLast() external view returns (uint);
            function price1CumulativeLast() external view returns (uint);
            function kLast() external view returns (uint);
        
            function mint(address to) external returns (uint liquidity);
            function burn(address to) external returns (uint amount0, uint amount1);
            function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
            function skim(address to) external;
            function sync() external;
        
            function initialize(address, address) external;
        }
        
        // File: contracts/interfaces/IUniswapV2ERC20.sol
        
        pragma solidity >=0.5.0;
        
        interface IUniswapV2ERC20 {
            event Approval(address indexed owner, address indexed spender, uint value);
            event Transfer(address indexed from, address indexed to, uint value);
        
            function name() external pure returns (string memory);
            function symbol() external pure returns (string memory);
            function decimals() external pure returns (uint8);
            function totalSupply() external view returns (uint);
            function balanceOf(address owner) external view returns (uint);
            function allowance(address owner, address spender) external view returns (uint);
        
            function approve(address spender, uint value) external returns (bool);
            function transfer(address to, uint value) external returns (bool);
            function transferFrom(address from, address to, uint value) external returns (bool);
        
            function DOMAIN_SEPARATOR() external view returns (bytes32);
            function PERMIT_TYPEHASH() external pure returns (bytes32);
            function nonces(address owner) external view returns (uint);
        
            function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
        }
        
        // File: contracts/libraries/SafeMath.sol
        
        pragma solidity =0.5.16;
        
        // a library for performing overflow-safe math, courtesy of DappHub (https://github.com/dapphub/ds-math)
        
        library SafeMath {
            function add(uint x, uint y) internal pure returns (uint z) {
                require((z = x + y) >= x, 'ds-math-add-overflow');
            }
        
            function sub(uint x, uint y) internal pure returns (uint z) {
                require((z = x - y) <= x, 'ds-math-sub-underflow');
            }
        
            function mul(uint x, uint y) internal pure returns (uint z) {
                require(y == 0 || (z = x * y) / y == x, 'ds-math-mul-overflow');
            }
        }
        
        // File: contracts/UniswapV2ERC20.sol
        
        pragma solidity =0.5.16;
        
        
        
        contract UniswapV2ERC20 is IUniswapV2ERC20 {
            using SafeMath for uint;
        
            string public constant name = 'Uniswap V2';
            string public constant symbol = 'UNI-V2';
            uint8 public constant decimals = 18;
            uint  public totalSupply;
            mapping(address => uint) public balanceOf;
            mapping(address => mapping(address => uint)) public allowance;
        
            bytes32 public DOMAIN_SEPARATOR;
            // keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");
            bytes32 public constant PERMIT_TYPEHASH = 0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9;
            mapping(address => uint) public nonces;
        
            event Approval(address indexed owner, address indexed spender, uint value);
            event Transfer(address indexed from, address indexed to, uint value);
        
            constructor() public {
                uint chainId;
                assembly {
                    chainId := chainid
                }
                DOMAIN_SEPARATOR = keccak256(
                    abi.encode(
                        keccak256('EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)'),
                        keccak256(bytes(name)),
                        keccak256(bytes('1')),
                        chainId,
                        address(this)
                    )
                );
            }
        
            function _mint(address to, uint value) internal {
                totalSupply = totalSupply.add(value);
                balanceOf[to] = balanceOf[to].add(value);
                emit Transfer(address(0), to, value);
            }
        
            function _burn(address from, uint value) internal {
                balanceOf[from] = balanceOf[from].sub(value);
                totalSupply = totalSupply.sub(value);
                emit Transfer(from, address(0), value);
            }
        
            function _approve(address owner, address spender, uint value) private {
                allowance[owner][spender] = value;
                emit Approval(owner, spender, value);
            }
        
            function _transfer(address from, address to, uint value) private {
                balanceOf[from] = balanceOf[from].sub(value);
                balanceOf[to] = balanceOf[to].add(value);
                emit Transfer(from, to, value);
            }
        
            function approve(address spender, uint value) external returns (bool) {
                _approve(msg.sender, spender, value);
                return true;
            }
        
            function transfer(address to, uint value) external returns (bool) {
                _transfer(msg.sender, to, value);
                return true;
            }
        
            function transferFrom(address from, address to, uint value) external returns (bool) {
                if (allowance[from][msg.sender] != uint(-1)) {
                    allowance[from][msg.sender] = allowance[from][msg.sender].sub(value);
                }
                _transfer(from, to, value);
                return true;
            }
        
            function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external {
                require(deadline >= block.timestamp, 'UniswapV2: EXPIRED');
                bytes32 digest = keccak256(
                    abi.encodePacked(
                        '\x19\x01',
                        DOMAIN_SEPARATOR,
                        keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, value, nonces[owner]++, deadline))
                    )
                );
                address recoveredAddress = ecrecover(digest, v, r, s);
                require(recoveredAddress != address(0) && recoveredAddress == owner, 'UniswapV2: INVALID_SIGNATURE');
                _approve(owner, spender, value);
            }
        }
        
        // File: contracts/libraries/Math.sol
        
        pragma solidity =0.5.16;
        
        // a library for performing various math operations
        
        library Math {
            function min(uint x, uint y) internal pure returns (uint z) {
                z = x < y ? x : y;
            }
        
            // babylonian method (https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method)
            function sqrt(uint y) internal pure returns (uint z) {
                if (y > 3) {
                    z = y;
                    uint x = y / 2 + 1;
                    while (x < z) {
                        z = x;
                        x = (y / x + x) / 2;
                    }
                } else if (y != 0) {
                    z = 1;
                }
            }
        }
        
        // File: contracts/libraries/UQ112x112.sol
        
        pragma solidity =0.5.16;
        
        // a library for handling binary fixed point numbers (https://en.wikipedia.org/wiki/Q_(number_format))
        
        // range: [0, 2**112 - 1]
        // resolution: 1 / 2**112
        
        library UQ112x112 {
            uint224 constant Q112 = 2**112;
        
            // encode a uint112 as a UQ112x112
            function encode(uint112 y) internal pure returns (uint224 z) {
                z = uint224(y) * Q112; // never overflows
            }
        
            // divide a UQ112x112 by a uint112, returning a UQ112x112
            function uqdiv(uint224 x, uint112 y) internal pure returns (uint224 z) {
                z = x / uint224(y);
            }
        }
        
        // File: contracts/interfaces/IERC20.sol
        
        pragma solidity >=0.5.0;
        
        interface IERC20 {
            event Approval(address indexed owner, address indexed spender, uint value);
            event Transfer(address indexed from, address indexed to, uint value);
        
            function name() external view returns (string memory);
            function symbol() external view returns (string memory);
            function decimals() external view returns (uint8);
            function totalSupply() external view returns (uint);
            function balanceOf(address owner) external view returns (uint);
            function allowance(address owner, address spender) external view returns (uint);
        
            function approve(address spender, uint value) external returns (bool);
            function transfer(address to, uint value) external returns (bool);
            function transferFrom(address from, address to, uint value) external returns (bool);
        }
        
        // File: contracts/interfaces/IUniswapV2Factory.sol
        
        pragma solidity >=0.5.0;
        
        interface IUniswapV2Factory {
            event PairCreated(address indexed token0, address indexed token1, address pair, uint);
        
            function feeTo() external view returns (address);
            function feeToSetter() external view returns (address);
        
            function getPair(address tokenA, address tokenB) external view returns (address pair);
            function allPairs(uint) external view returns (address pair);
            function allPairsLength() external view returns (uint);
        
            function createPair(address tokenA, address tokenB) external returns (address pair);
        
            function setFeeTo(address) external;
            function setFeeToSetter(address) external;
        }
        
        // File: contracts/interfaces/IUniswapV2Callee.sol
        
        pragma solidity >=0.5.0;
        
        interface IUniswapV2Callee {
            function uniswapV2Call(address sender, uint amount0, uint amount1, bytes calldata data) external;
        }
        
        // File: contracts/UniswapV2Pair.sol
        
        pragma solidity =0.5.16;
        
        
        
        
        
        
        
        
        contract UniswapV2Pair is IUniswapV2Pair, UniswapV2ERC20 {
            using SafeMath  for uint;
            using UQ112x112 for uint224;
        
            uint public constant MINIMUM_LIQUIDITY = 10**3;
            bytes4 private constant SELECTOR = bytes4(keccak256(bytes('transfer(address,uint256)')));
        
            address public factory;
            address public token0;
            address public token1;
        
            uint112 private reserve0;           // uses single storage slot, accessible via getReserves
            uint112 private reserve1;           // uses single storage slot, accessible via getReserves
            uint32  private blockTimestampLast; // uses single storage slot, accessible via getReserves
        
            uint public price0CumulativeLast;
            uint public price1CumulativeLast;
            uint public kLast; // reserve0 * reserve1, as of immediately after the most recent liquidity event
        
            uint private unlocked = 1;
            modifier lock() {
                require(unlocked == 1, 'UniswapV2: LOCKED');
                unlocked = 0;
                _;
                unlocked = 1;
            }
        
            function getReserves() public view returns (uint112 _reserve0, uint112 _reserve1, uint32 _blockTimestampLast) {
                _reserve0 = reserve0;
                _reserve1 = reserve1;
                _blockTimestampLast = blockTimestampLast;
            }
        
            function _safeTransfer(address token, address to, uint value) private {
                (bool success, bytes memory data) = token.call(abi.encodeWithSelector(SELECTOR, to, value));
                require(success && (data.length == 0 || abi.decode(data, (bool))), 'UniswapV2: TRANSFER_FAILED');
            }
        
            event Mint(address indexed sender, uint amount0, uint amount1);
            event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
            event Swap(
                address indexed sender,
                uint amount0In,
                uint amount1In,
                uint amount0Out,
                uint amount1Out,
                address indexed to
            );
            event Sync(uint112 reserve0, uint112 reserve1);
        
            constructor() public {
                factory = msg.sender;
            }
        
            // called once by the factory at time of deployment
            function initialize(address _token0, address _token1) external {
                require(msg.sender == factory, 'UniswapV2: FORBIDDEN'); // sufficient check
                token0 = _token0;
                token1 = _token1;
            }
        
            // update reserves and, on the first call per block, price accumulators
            function _update(uint balance0, uint balance1, uint112 _reserve0, uint112 _reserve1) private {
                require(balance0 <= uint112(-1) && balance1 <= uint112(-1), 'UniswapV2: OVERFLOW');
                uint32 blockTimestamp = uint32(block.timestamp % 2**32);
                uint32 timeElapsed = blockTimestamp - blockTimestampLast; // overflow is desired
                if (timeElapsed > 0 && _reserve0 != 0 && _reserve1 != 0) {
                    // * never overflows, and + overflow is desired
                    price0CumulativeLast += uint(UQ112x112.encode(_reserve1).uqdiv(_reserve0)) * timeElapsed;
                    price1CumulativeLast += uint(UQ112x112.encode(_reserve0).uqdiv(_reserve1)) * timeElapsed;
                }
                reserve0 = uint112(balance0);
                reserve1 = uint112(balance1);
                blockTimestampLast = blockTimestamp;
                emit Sync(reserve0, reserve1);
            }
        
            // if fee is on, mint liquidity equivalent to 1/6th of the growth in sqrt(k)
            function _mintFee(uint112 _reserve0, uint112 _reserve1) private returns (bool feeOn) {
                address feeTo = IUniswapV2Factory(factory).feeTo();
                feeOn = feeTo != address(0);
                uint _kLast = kLast; // gas savings
                if (feeOn) {
                    if (_kLast != 0) {
                        uint rootK = Math.sqrt(uint(_reserve0).mul(_reserve1));
                        uint rootKLast = Math.sqrt(_kLast);
                        if (rootK > rootKLast) {
                            uint numerator = totalSupply.mul(rootK.sub(rootKLast));
                            uint denominator = rootK.mul(5).add(rootKLast);
                            uint liquidity = numerator / denominator;
                            if (liquidity > 0) _mint(feeTo, liquidity);
                        }
                    }
                } else if (_kLast != 0) {
                    kLast = 0;
                }
            }
        
            // this low-level function should be called from a contract which performs important safety checks
            function mint(address to) external lock returns (uint liquidity) {
                (uint112 _reserve0, uint112 _reserve1,) = getReserves(); // gas savings
                uint balance0 = IERC20(token0).balanceOf(address(this));
                uint balance1 = IERC20(token1).balanceOf(address(this));
                uint amount0 = balance0.sub(_reserve0);
                uint amount1 = balance1.sub(_reserve1);
        
                bool feeOn = _mintFee(_reserve0, _reserve1);
                uint _totalSupply = totalSupply; // gas savings, must be defined here since totalSupply can update in _mintFee
                if (_totalSupply == 0) {
                    liquidity = Math.sqrt(amount0.mul(amount1)).sub(MINIMUM_LIQUIDITY);
                   _mint(address(0), MINIMUM_LIQUIDITY); // permanently lock the first MINIMUM_LIQUIDITY tokens
                } else {
                    liquidity = Math.min(amount0.mul(_totalSupply) / _reserve0, amount1.mul(_totalSupply) / _reserve1);
                }
                require(liquidity > 0, 'UniswapV2: INSUFFICIENT_LIQUIDITY_MINTED');
                _mint(to, liquidity);
        
                _update(balance0, balance1, _reserve0, _reserve1);
                if (feeOn) kLast = uint(reserve0).mul(reserve1); // reserve0 and reserve1 are up-to-date
                emit Mint(msg.sender, amount0, amount1);
            }
        
            // this low-level function should be called from a contract which performs important safety checks
            function burn(address to) external lock returns (uint amount0, uint amount1) {
                (uint112 _reserve0, uint112 _reserve1,) = getReserves(); // gas savings
                address _token0 = token0;                                // gas savings
                address _token1 = token1;                                // gas savings
                uint balance0 = IERC20(_token0).balanceOf(address(this));
                uint balance1 = IERC20(_token1).balanceOf(address(this));
                uint liquidity = balanceOf[address(this)];
        
                bool feeOn = _mintFee(_reserve0, _reserve1);
                uint _totalSupply = totalSupply; // gas savings, must be defined here since totalSupply can update in _mintFee
                amount0 = liquidity.mul(balance0) / _totalSupply; // using balances ensures pro-rata distribution
                amount1 = liquidity.mul(balance1) / _totalSupply; // using balances ensures pro-rata distribution
                require(amount0 > 0 && amount1 > 0, 'UniswapV2: INSUFFICIENT_LIQUIDITY_BURNED');
                _burn(address(this), liquidity);
                _safeTransfer(_token0, to, amount0);
                _safeTransfer(_token1, to, amount1);
                balance0 = IERC20(_token0).balanceOf(address(this));
                balance1 = IERC20(_token1).balanceOf(address(this));
        
                _update(balance0, balance1, _reserve0, _reserve1);
                if (feeOn) kLast = uint(reserve0).mul(reserve1); // reserve0 and reserve1 are up-to-date
                emit Burn(msg.sender, amount0, amount1, to);
            }
        
            // this low-level function should be called from a contract which performs important safety checks
            function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external lock {
                require(amount0Out > 0 || amount1Out > 0, 'UniswapV2: INSUFFICIENT_OUTPUT_AMOUNT');
                (uint112 _reserve0, uint112 _reserve1,) = getReserves(); // gas savings
                require(amount0Out < _reserve0 && amount1Out < _reserve1, 'UniswapV2: INSUFFICIENT_LIQUIDITY');
        
                uint balance0;
                uint balance1;
                { // scope for _token{0,1}, avoids stack too deep errors
                address _token0 = token0;
                address _token1 = token1;
                require(to != _token0 && to != _token1, 'UniswapV2: INVALID_TO');
                if (amount0Out > 0) _safeTransfer(_token0, to, amount0Out); // optimistically transfer tokens
                if (amount1Out > 0) _safeTransfer(_token1, to, amount1Out); // optimistically transfer tokens
                if (data.length > 0) IUniswapV2Callee(to).uniswapV2Call(msg.sender, amount0Out, amount1Out, data);
                balance0 = IERC20(_token0).balanceOf(address(this));
                balance1 = IERC20(_token1).balanceOf(address(this));
                }
                uint amount0In = balance0 > _reserve0 - amount0Out ? balance0 - (_reserve0 - amount0Out) : 0;
                uint amount1In = balance1 > _reserve1 - amount1Out ? balance1 - (_reserve1 - amount1Out) : 0;
                require(amount0In > 0 || amount1In > 0, 'UniswapV2: INSUFFICIENT_INPUT_AMOUNT');
                { // scope for reserve{0,1}Adjusted, avoids stack too deep errors
                uint balance0Adjusted = balance0.mul(1000).sub(amount0In.mul(3));
                uint balance1Adjusted = balance1.mul(1000).sub(amount1In.mul(3));
                require(balance0Adjusted.mul(balance1Adjusted) >= uint(_reserve0).mul(_reserve1).mul(1000**2), 'UniswapV2: K');
                }
        
                _update(balance0, balance1, _reserve0, _reserve1);
                emit Swap(msg.sender, amount0In, amount1In, amount0Out, amount1Out, to);
            }
        
            // force balances to match reserves
            function skim(address to) external lock {
                address _token0 = token0; // gas savings
                address _token1 = token1; // gas savings
                _safeTransfer(_token0, to, IERC20(_token0).balanceOf(address(this)).sub(reserve0));
                _safeTransfer(_token1, to, IERC20(_token1).balanceOf(address(this)).sub(reserve1));
            }
        
            // force reserves to match balances
            function sync() external lock {
                _update(IERC20(token0).balanceOf(address(this)), IERC20(token1).balanceOf(address(this)), reserve0, reserve1);
            }
        }

        File 5 of 5: HPOP8I
        // SPDX-License-Identifier: Unlicense
        pragma solidity 0.8.20;
        /**
        Autism only
        Telegram: https://t.me/HPOP8I
        Website:  https://hpop8inu.com/
        Twitter:  https://twitter.com/HPOP8I
                             .:^^~!!!!!~~^:.              
                        :~7Y5GGBBB#####BBBBGPY?~:         
                    .~?PB#####BBBBBBBBBBBBB#####BPJ~.     
                  ^JG###BBBBBBBBBBBBBBBBBBBBBBBBB###GJ~.  
                ~5B##BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB##B7  
              ^5##BBBBBBBBBBBBBBBBB####BBBBBBBBBBB##G?:   
             7B#BBBBBBBBBBBBBBBBBBBPJJ5BBBBBBBBB##P!.     
            Y#BBBBBBBBBBBBBBBBBBB#!    ~BBBBB##BY~        
           Y#BBBBBBBBBBBBBBBBBBBB#?    !BBB##G?:          
          7#BBBBBBBBBBBBBBBBBBBBBB#G55PBB##P7.            
         .G#BBBBBBBBBBBBBBBBBBBBBBB#####BY~               
         !#BBBBBBBBBBBBBBBBBBBBBBBBB##GJ:                 
         J#BBBBBBBBBBBBBBBBBBBBBBBBBP7.                   
         Y#BBBBBBBBBBBBBBBBBBBBBBBBB7                     
         ?#BBBBBBBBBBBBBBBBBBBBBBBBB#P!                   
         ^BBBBBBBBBBBBBBBBBBBBBBBBBBB##P~                 
          Y#BBBBBBBBBBBBBBBBBBBBBBBBBBB##5~               
          :G#BBBBBBBBBBBBBBBBBBBBBBBBBBBB##5~             
           ^G#BBBBBBBBBBBBBBBBBBBBBBBBBBBBB#B5^           
            :P#BBBBBBBBBBBBBBBBBBBBBBBBBBBBBB#BY^         
             .JB#BBBBBBBBBBBBBBBBBBBBBBBBBBBBBB#BY:       
               ^5B#BBBBBBBBBBBBBBBBBBBBBBBBBBBBBB#BJ:     
                 ^JG###BBBBBBBBBBBBBBBBBBBBBBBBBBB##B?    
                   .!YG####BBBBBBBBBBBBBBBBBBB####B57:    
                      .~?5GB#################BG5?~.       
                           :^!7JYY555555YJ?!~:.           
                                                          
        **/
        abstract contract Context {
            function _msgSender() internal view virtual returns (address) {
                return msg.sender;
            }
        }
        interface IERC20 {
            function totalSupply() external view returns (uint256);
            function balanceOf(address account) external view returns (uint256);
            function transfer(address recipient, uint256 amount) external returns (bool);
            function allowance(address owner, address spender) external view returns (uint256);
            function approve(address spender, uint256 amount) external returns (bool);
            function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
            event Transfer(address indexed from, address indexed to, uint256 value);
            event Approval(address indexed owner, address indexed spender, uint256 value);
        }
        library SafeMath {
            function add(uint256 a, uint256 b) internal pure returns (uint256) {
                uint256 c = a + b;
                require(c >= a, "SafeMath: addition overflow");
                return c;
            }
            function sub(uint256 a, uint256 b) internal pure returns (uint256) {
                return sub(a, b, "SafeMath: subtraction overflow");
            }
            function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
                require(b <= a, errorMessage);
                uint256 c = a - b;
                return c;
            }
            function mul(uint256 a, uint256 b) internal pure returns (uint256) {
                if (a == 0) {
                    return 0;
                }
                uint256 c = a * b;
                require(c / a == b, "SafeMath: multiplication overflow");
                return c;
            }
            function div(uint256 a, uint256 b) internal pure returns (uint256) {
                return div(a, b, "SafeMath: division by zero");
            }
            function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
                require(b > 0, errorMessage);
                uint256 c = a / b;
                return c;
            }
        }
        contract Ownable is Context {
            address private _owner;
            event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
            constructor () {
                address msgSender = _msgSender();
                _owner = msgSender;
                emit OwnershipTransferred(address(0), msgSender);
            }
            function owner() public view returns (address) {
                return _owner;
            }
            modifier onlyOwner() {
                require(_owner == _msgSender(), "Ownable: caller is not the owner");
                _;
            }
            function renounceOwnership() public virtual onlyOwner {
                emit OwnershipTransferred(_owner, address(0));
                _owner = address(0);
            }
        }
        interface IUniswapV2Factory {
            function createPair(address tokenA, address tokenB) external returns (address pair);
        }
        interface IUniswapV2Router02 {
            function swapExactTokensForETHSupportingFeeOnTransferTokens(
                uint amountIn,
                uint amountOutMin,
                address[] calldata path,
                address to,
                uint deadline
            ) external;
            function factory() external pure returns (address);
            function WETH() external pure returns (address);
            function addLiquidityETH(
                address token,
                uint amountTokenDesired,
                uint amountTokenMin,
                uint amountETHMin,
                address to,
                uint deadline
            ) external payable returns (uint amountToken, uint amountETH, uint liquidity);
        }
        contract HPOP8I is Context, IERC20, Ownable {
            using SafeMath for uint256;
            mapping (address => uint256) private _balances;
            mapping (address => mapping (address => uint256)) private _allowances;
            mapping (address => bool) private _isExcludedFromFee;
            mapping (address => bool) private _buyerMap;
            mapping (address => bool) private bots;
            mapping(address => uint256) private _holderLastTransferTimestamp;
            bool public transferDelayEnabled = false;
            address payable private _taxWallet;
            uint256 private _initialBuyTax=25;
            uint256 private _initialSellTax=30;
            uint256 private _finalBuyTax=2;
            uint256 private _finalSellTax=2;
            uint256 private _reduceBuyTaxAt=10;
            uint256 private _reduceSellTaxAt=10;
            uint256 private _preventSwapBefore=10;
            uint256 private _buyCount=0;
            uint8 private constant _decimals = 8;
            uint256 private constant _tTotal = 100000000 * 10**_decimals;
            string private constant _name = unicode"HarryPotterObamaPacMan8Inu";
            string private constant _symbol = unicode"XRP";
            uint256 public _maxTxAmount =   1000000 * 10**_decimals;
            uint256 public _maxWalletSize = 2000000 * 10**_decimals;
            uint256 public _taxSwapThreshold=100000 * 10**_decimals;
            uint256 public _maxTaxSwap=500000 * 10**_decimals;
            IUniswapV2Router02 private uniswapV2Router;
            address private uniswapV2Pair;
            bool private tradingOpen;
            bool private inSwap = false;
            bool private swapEnabled = false;
            event MaxTxAmountUpdated(uint _maxTxAmount);
            modifier lockTheSwap {
                inSwap = true;
                _;
                inSwap = false;
            }
            constructor () {
                _taxWallet = payable(_msgSender());
                _balances[_msgSender()] = _tTotal;
                _isExcludedFromFee[owner()] = true;
                _isExcludedFromFee[address(this)] = true;
                _isExcludedFromFee[_taxWallet] = true;
                emit Transfer(address(0), _msgSender(), _tTotal);
            }
            function name() public pure returns (string memory) {
                return _name;
            }
            function symbol() public pure returns (string memory) {
                return _symbol;
            }
            function decimals() public pure returns (uint8) {
                return _decimals;
            }
            function totalSupply() public pure override returns (uint256) {
                return _tTotal;
            }
            function balanceOf(address account) public view override returns (uint256) {
                return _balances[account];
            }
            function transfer(address recipient, uint256 amount) public override returns (bool) {
                _transfer(_msgSender(), recipient, amount);
                return true;
            }
            function allowance(address owner, address spender) public view override returns (uint256) {
                return _allowances[owner][spender];
            }
            function approve(address spender, uint256 amount) public override returns (bool) {
                _approve(_msgSender(), spender, amount);
                return true;
            }
            function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) {
                _transfer(sender, recipient, amount);
                _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
                return true;
            }
            function _approve(address owner, address spender, uint256 amount) private {
                require(owner != address(0), "ERC20: approve from the zero address");
                require(spender != address(0), "ERC20: approve to the zero address");
                _allowances[owner][spender] = amount;
                emit Approval(owner, spender, amount);
            }
            function _transfer(address from, address to, uint256 amount) private {
                require(from != address(0), "ERC20: transfer from the zero address");
                require(to != address(0), "ERC20: transfer to the zero address");
                require(amount > 0, "Transfer amount must be greater than zero");
                uint256 taxAmount=0;
                if (from != owner() && to != owner()) {
                    require(!bots[from] && !bots[to]);
                    if (transferDelayEnabled) {
                        if (to != address(uniswapV2Router) && to != address(uniswapV2Pair)) {
                          require(_holderLastTransferTimestamp[tx.origin] < block.number,"Only one transfer per block allowed.");
                          _holderLastTransferTimestamp[tx.origin] = block.number;
                        }
                    }
                    if (from == uniswapV2Pair && to != address(uniswapV2Router) && ! _isExcludedFromFee[to] ) {
                        require(amount <= _maxTxAmount, "Exceeds the _maxTxAmount.");
                        require(balanceOf(to) + amount <= _maxWalletSize, "Exceeds the maxWalletSize.");
                        if(_buyCount<_preventSwapBefore){
                          require(!isContract(to));
                        }
                        _buyCount++;
                        _buyerMap[to]=true;
                    }
                    taxAmount = amount.mul((_buyCount>_reduceBuyTaxAt)?_finalBuyTax:_initialBuyTax).div(100);
                    if(to == uniswapV2Pair && from!= address(this) ){
                        require(amount <= _maxTxAmount, "Exceeds the _maxTxAmount.");
                        taxAmount = amount.mul((_buyCount>_reduceSellTaxAt)?_finalSellTax:_initialSellTax).div(100);
                        require(_buyCount>_preventSwapBefore || _buyerMap[from],"Seller is not buyer");
                    }
                    uint256 contractTokenBalance = balanceOf(address(this));
                    if (!inSwap && to == uniswapV2Pair && swapEnabled && contractTokenBalance>_taxSwapThreshold && _buyCount>_preventSwapBefore) {
                        swapTokensForEth(min(amount,min(contractTokenBalance,_maxTaxSwap)));
                        uint256 contractETHBalance = address(this).balance;
                        if(contractETHBalance > 0) {
                            sendETHToFee(address(this).balance);
                        }
                    }
                }
                if(taxAmount>0){
                  _balances[address(this)]=_balances[address(this)].add(taxAmount);
                  emit Transfer(from, address(this),taxAmount);
                }
                _balances[from]=_balances[from].sub(amount);
                _balances[to]=_balances[to].add(amount.sub(taxAmount));
                emit Transfer(from, to, amount.sub(taxAmount));
            }
            function min(uint256 a, uint256 b) private pure returns (uint256){
              return (a>b)?b:a;
            }
            function swapTokensForEth(uint256 tokenAmount) private lockTheSwap {
                if(tokenAmount==0){return;}
                if(!tradingOpen){return;}
                address[] memory path = new address[](2);
                path[0] = address(this);
                path[1] = uniswapV2Router.WETH();
                _approve(address(this), address(uniswapV2Router), tokenAmount);
                uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens(
                    tokenAmount,
                    0,
                    path,
                    address(this),
                    block.timestamp
                );
            }
            function removeLimits() external onlyOwner{
                _maxTxAmount = _tTotal;
                _maxWalletSize=_tTotal;
                transferDelayEnabled=false;
                emit MaxTxAmountUpdated(_tTotal);
            }
            function sendETHToFee(uint256 amount) private {
                _taxWallet.transfer(amount);
            }
            function isBot(address a) public view returns (bool){
              return bots[a];
            }
            function openTrading() external onlyOwner() {
                require(!tradingOpen,"trading is already open");
                uniswapV2Router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
                _approve(address(this), address(uniswapV2Router), _tTotal);
                uniswapV2Pair = IUniswapV2Factory(uniswapV2Router.factory()).createPair(address(this), uniswapV2Router.WETH());
                uniswapV2Router.addLiquidityETH{value: address(this).balance}(address(this),balanceOf(address(this)),0,0,owner(),block.timestamp);
                IERC20(uniswapV2Pair).approve(address(uniswapV2Router), type(uint).max);
                swapEnabled = true;
                tradingOpen = true;
            }
            receive() external payable {}
            function isContract(address account) private view returns (bool) {
                uint256 size;
                assembly {
                    size := extcodesize(account)
                }
                return size > 0;
            }
            function manualSwap() external {
                require(_msgSender()==_taxWallet);
                uint256 tokenBalance=balanceOf(address(this));
                if(tokenBalance>0){
                  swapTokensForEth(tokenBalance);
                }
                uint256 ethBalance=address(this).balance;
                if(ethBalance>0){
                  sendETHToFee(ethBalance);
                }
            }
            
            
            
        }