ETH Price: $2,511.98 (-0.21%)

Transaction Decoder

Block:
20779068 at Sep-18-2024 05:47:47 PM +UTC
Transaction Fee:
0.00071428181737835 ETH $1.79
Gas Used:
91,610 Gas / 7.796985235 Gwei

Emitted Events:

315 WETH9.Transfer( src=[Sender] 0x05f6875132b910976ee165171b78d7965e0fbf5c, dst=ERC20Router, wad=63455000000000000 )
316 WETH9.Approval( src=ERC20Router, guy=ERC20Router, wad=63455000000000000 )
317 WETH9.Withdrawal( src=ERC20Router, wad=63455000000000000 )

Account State Difference:

  Address   Before After State Difference Code
0x05f68751...65e0fBF5C
0.001882024476489783 Eth
Nonce: 644
0.001167742659111433 Eth
Nonce: 645
0.00071428181737835
(Titan Builder)
14.01102015143323113 Eth14.01102473193323113 Eth0.0000045805
0xC02aaA39...83C756Cc2 2,900,725.330158900926000346 Eth2,900,725.266703900926000346 Eth0.063455
0xf70da978...8dfA3dbEF 409.640004395664844844 Eth409.703459395664844844 Eth0.063455

Execution Trace

ApprovalProxy.transferAndMulticall( tokens=[0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2], amounts=[63455000000000000], targets=[0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2, 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2, 0xf70da97812CB96acDF810712Aa562db8dfA3dbEF], datas=[CV6nswAAAAAAAAAAAAAAAKG+pf6RdFAEF0jbu+fprFeku+urAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOFv/H448AA=, Lhp9TQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADhb/x+OPAA, ], values=[0, 0, 63455000000000000], refundTo=0xf70da97812CB96acDF810712Aa562db8dfA3dbEF ) => ( 0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000A000000000000000000000000000000000000000000000000000000000000000C00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 )
  • WETH9.transferFrom( src=0x05f6875132b910976ee165171b78D7965e0fBF5C, dst=0xA1BEa5fe917450041748Dbbbe7E9AC57A4bBEBaB, wad=63455000000000000 ) => ( True )
  • ERC20Router.delegatecallMulticall( targets=[0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2, 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2, 0xf70da97812CB96acDF810712Aa562db8dfA3dbEF], datas=[CV6nswAAAAAAAAAAAAAAAKG+pf6RdFAEF0jbu+fprFeku+urAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOFv/H448AA=, Lhp9TQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADhb/x+OPAA, ], values=[0, 0, 63455000000000000], refundTo=0xf70da97812CB96acDF810712Aa562db8dfA3dbEF ) => ( 0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000A000000000000000000000000000000000000000000000000000000000000000C00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 )
    • Multicaller.aggregate( targets=[0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2, 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2, 0xf70da97812CB96acDF810712Aa562db8dfA3dbEF], data=[CV6nswAAAAAAAAAAAAAAAKG+pf6RdFAEF0jbu+fprFeku+urAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOFv/H448AA=, Lhp9TQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADhb/x+OPAA, ], values=[0, 0, 63455000000000000], refundTo=0xf70da97812CB96acDF810712Aa562db8dfA3dbEF ) => ( [AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAE=, , ] )
      • WETH9.approve( guy=0xA1BEa5fe917450041748Dbbbe7E9AC57A4bBEBaB, wad=63455000000000000 ) => ( True )
      • WETH9.withdraw( wad=63455000000000000 )
        • ETH 0.063455 ERC20Router.CALL( )
        • ETH 0.063455 0xf70da97812cb96acdf810712aa562db8dfa3dbef.CALL( )
          transferAndMulticall[ApprovalProxy (ln:37)]
          File 1 of 4: ApprovalProxy
          // SPDX-License-Identifier: MIT
          pragma solidity ^0.8.23;
          import {Ownable} from "solady/src/auth/Ownable.sol";
          import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
          import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
          import {IERC20Router} from "../src/types/interfaces/IERC20Router.sol";
          contract ApprovalProxy is Ownable {
              using SafeERC20 for IERC20;
              error ArrayLengthsMismatch();
              error ERC20TransferFromFailed();
              error NativeTransferFailed();
              event RouterUpdated(address newRouter);
              address public router;
              receive() external payable {}
              constructor(address _owner, address _router) {
                  _initializeOwner(_owner);
                  router = _router;
              }
              /// @notice Withdraw function in case funds get stuck in contract
              function withdraw() external onlyOwner {
                  _send(msg.sender, address(this).balance);
              }
              /// @notice Set the router address
              /// @param _router The address of the router contract
              function setRouter(address _router) external onlyOwner {
                  router = _router;
                  emit RouterUpdated(_router);
              }
              /// @notice Transfer tokens to ERC20Router and perform multicall in a single tx
              /// @dev This contract must be approved to transfer msg.sender's tokens to the ERC20Router
              /// @param tokens An array of token addresses to transfer
              /// @param amounts An array of token amounts to transfer
              /// @param targets An array of target addresses to pass to the multicall
              /// @param datas An array of calldata to pass to the multicall
              /// @param values An array of msg values to pass to the multicall
              /// @param refundTo The address to refund any leftover ETH to
              function transferAndMulticall(
                  address[] calldata tokens,
                  uint256[] calldata amounts,
                  address[] calldata targets,
                  bytes[] calldata datas,
                  uint256[] calldata values,
                  address refundTo
              ) external payable returns (bytes memory) {
                  // Revert if array lengths do not match
                  if ((tokens.length != amounts.length)) {
                      revert ArrayLengthsMismatch();
                  }
                  // Revert if array lengths do not match (split from above for readability)
                  if (targets.length != datas.length || datas.length != values.length) {
                      revert ArrayLengthsMismatch();
                  }
                  // Transfer the tokens to the router
                  for (uint256 i = 0; i < tokens.length; i++) {
                      IERC20(tokens[i]).safeTransferFrom(msg.sender, router, amounts[i]);
                  }
                  // Call delegatecallMulticall on the router. The router will perform a
                  // delegatecall to the Multicaller.
                  // @dev msg.sender for the calls to targets will be the router
                  bytes memory data = IERC20Router(router).delegatecallMulticall{value: msg.value}(
                      targets,
                      datas,
                      values,
                      refundTo
                  );
                  return data;
              }
              function _send(address to, uint256 value) internal {
                  bool success;
                  assembly {
                      // Save gas by avoiding copying the return data to memory.
                      // Provide at most 100k gas to the internal call, which is
                      // more than enough to cover common use-cases of logic for
                      // receiving native tokens (eg. SCW payable fallbacks).
                      success := call(100000, to, value, 0, 0, 0, 0)
                  }
                  if (!success) {
                      revert NativeTransferFailed();
                  }
              }
          }// SPDX-License-Identifier: MIT
          pragma solidity ^0.8.4;
          /// @notice Simple single owner authorization mixin.
          /// @author Solady (https://github.com/vectorized/solady/blob/main/src/auth/Ownable.sol)
          ///
          /// @dev Note:
          /// This implementation does NOT auto-initialize the owner to `msg.sender`.
          /// You MUST call the `_initializeOwner` in the constructor / initializer.
          ///
          /// While the ownable portion follows
          /// [EIP-173](https://eips.ethereum.org/EIPS/eip-173) for compatibility,
          /// the nomenclature for the 2-step ownership handover may be unique to this codebase.
          abstract contract Ownable {
              /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
              /*                       CUSTOM ERRORS                        */
              /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
              /// @dev The caller is not authorized to call the function.
              error Unauthorized();
              /// @dev The `newOwner` cannot be the zero address.
              error NewOwnerIsZeroAddress();
              /// @dev The `pendingOwner` does not have a valid handover request.
              error NoHandoverRequest();
              /// @dev Cannot double-initialize.
              error AlreadyInitialized();
              /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
              /*                           EVENTS                           */
              /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
              /// @dev The ownership is transferred from `oldOwner` to `newOwner`.
              /// This event is intentionally kept the same as OpenZeppelin's Ownable to be
              /// compatible with indexers and [EIP-173](https://eips.ethereum.org/EIPS/eip-173),
              /// despite it not being as lightweight as a single argument event.
              event OwnershipTransferred(address indexed oldOwner, address indexed newOwner);
              /// @dev An ownership handover to `pendingOwner` has been requested.
              event OwnershipHandoverRequested(address indexed pendingOwner);
              /// @dev The ownership handover to `pendingOwner` has been canceled.
              event OwnershipHandoverCanceled(address indexed pendingOwner);
              /// @dev `keccak256(bytes("OwnershipTransferred(address,address)"))`.
              uint256 private constant _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE =
                  0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0;
              /// @dev `keccak256(bytes("OwnershipHandoverRequested(address)"))`.
              uint256 private constant _OWNERSHIP_HANDOVER_REQUESTED_EVENT_SIGNATURE =
                  0xdbf36a107da19e49527a7176a1babf963b4b0ff8cde35ee35d6cd8f1f9ac7e1d;
              /// @dev `keccak256(bytes("OwnershipHandoverCanceled(address)"))`.
              uint256 private constant _OWNERSHIP_HANDOVER_CANCELED_EVENT_SIGNATURE =
                  0xfa7b8eab7da67f412cc9575ed43464468f9bfbae89d1675917346ca6d8fe3c92;
              /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
              /*                          STORAGE                           */
              /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
              /// @dev The owner slot is given by:
              /// `bytes32(~uint256(uint32(bytes4(keccak256("_OWNER_SLOT_NOT")))))`.
              /// It is intentionally chosen to be a high value
              /// to avoid collision with lower slots.
              /// The choice of manual storage layout is to enable compatibility
              /// with both regular and upgradeable contracts.
              bytes32 internal constant _OWNER_SLOT =
                  0xffffffffffffffffffffffffffffffffffffffffffffffffffffffff74873927;
              /// The ownership handover slot of `newOwner` is given by:
              /// ```
              ///     mstore(0x00, or(shl(96, user), _HANDOVER_SLOT_SEED))
              ///     let handoverSlot := keccak256(0x00, 0x20)
              /// ```
              /// It stores the expiry timestamp of the two-step ownership handover.
              uint256 private constant _HANDOVER_SLOT_SEED = 0x389a75e1;
              /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
              /*                     INTERNAL FUNCTIONS                     */
              /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
              /// @dev Override to return true to make `_initializeOwner` prevent double-initialization.
              function _guardInitializeOwner() internal pure virtual returns (bool guard) {}
              /// @dev Initializes the owner directly without authorization guard.
              /// This function must be called upon initialization,
              /// regardless of whether the contract is upgradeable or not.
              /// This is to enable generalization to both regular and upgradeable contracts,
              /// and to save gas in case the initial owner is not the caller.
              /// For performance reasons, this function will not check if there
              /// is an existing owner.
              function _initializeOwner(address newOwner) internal virtual {
                  if (_guardInitializeOwner()) {
                      /// @solidity memory-safe-assembly
                      assembly {
                          let ownerSlot := _OWNER_SLOT
                          if sload(ownerSlot) {
                              mstore(0x00, 0x0dc149f0) // `AlreadyInitialized()`.
                              revert(0x1c, 0x04)
                          }
                          // Clean the upper 96 bits.
                          newOwner := shr(96, shl(96, newOwner))
                          // Store the new value.
                          sstore(ownerSlot, or(newOwner, shl(255, iszero(newOwner))))
                          // Emit the {OwnershipTransferred} event.
                          log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, 0, newOwner)
                      }
                  } else {
                      /// @solidity memory-safe-assembly
                      assembly {
                          // Clean the upper 96 bits.
                          newOwner := shr(96, shl(96, newOwner))
                          // Store the new value.
                          sstore(_OWNER_SLOT, newOwner)
                          // Emit the {OwnershipTransferred} event.
                          log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, 0, newOwner)
                      }
                  }
              }
              /// @dev Sets the owner directly without authorization guard.
              function _setOwner(address newOwner) internal virtual {
                  if (_guardInitializeOwner()) {
                      /// @solidity memory-safe-assembly
                      assembly {
                          let ownerSlot := _OWNER_SLOT
                          // Clean the upper 96 bits.
                          newOwner := shr(96, shl(96, newOwner))
                          // Emit the {OwnershipTransferred} event.
                          log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, sload(ownerSlot), newOwner)
                          // Store the new value.
                          sstore(ownerSlot, or(newOwner, shl(255, iszero(newOwner))))
                      }
                  } else {
                      /// @solidity memory-safe-assembly
                      assembly {
                          let ownerSlot := _OWNER_SLOT
                          // Clean the upper 96 bits.
                          newOwner := shr(96, shl(96, newOwner))
                          // Emit the {OwnershipTransferred} event.
                          log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, sload(ownerSlot), newOwner)
                          // Store the new value.
                          sstore(ownerSlot, newOwner)
                      }
                  }
              }
              /// @dev Throws if the sender is not the owner.
              function _checkOwner() internal view virtual {
                  /// @solidity memory-safe-assembly
                  assembly {
                      // If the caller is not the stored owner, revert.
                      if iszero(eq(caller(), sload(_OWNER_SLOT))) {
                          mstore(0x00, 0x82b42900) // `Unauthorized()`.
                          revert(0x1c, 0x04)
                      }
                  }
              }
              /// @dev Returns how long a two-step ownership handover is valid for in seconds.
              /// Override to return a different value if needed.
              /// Made internal to conserve bytecode. Wrap it in a public function if needed.
              function _ownershipHandoverValidFor() internal view virtual returns (uint64) {
                  return 48 * 3600;
              }
              /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
              /*                  PUBLIC UPDATE FUNCTIONS                   */
              /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
              /// @dev Allows the owner to transfer the ownership to `newOwner`.
              function transferOwnership(address newOwner) public payable virtual onlyOwner {
                  /// @solidity memory-safe-assembly
                  assembly {
                      if iszero(shl(96, newOwner)) {
                          mstore(0x00, 0x7448fbae) // `NewOwnerIsZeroAddress()`.
                          revert(0x1c, 0x04)
                      }
                  }
                  _setOwner(newOwner);
              }
              /// @dev Allows the owner to renounce their ownership.
              function renounceOwnership() public payable virtual onlyOwner {
                  _setOwner(address(0));
              }
              /// @dev Request a two-step ownership handover to the caller.
              /// The request will automatically expire in 48 hours (172800 seconds) by default.
              function requestOwnershipHandover() public payable virtual {
                  unchecked {
                      uint256 expires = block.timestamp + _ownershipHandoverValidFor();
                      /// @solidity memory-safe-assembly
                      assembly {
                          // Compute and set the handover slot to `expires`.
                          mstore(0x0c, _HANDOVER_SLOT_SEED)
                          mstore(0x00, caller())
                          sstore(keccak256(0x0c, 0x20), expires)
                          // Emit the {OwnershipHandoverRequested} event.
                          log2(0, 0, _OWNERSHIP_HANDOVER_REQUESTED_EVENT_SIGNATURE, caller())
                      }
                  }
              }
              /// @dev Cancels the two-step ownership handover to the caller, if any.
              function cancelOwnershipHandover() public payable virtual {
                  /// @solidity memory-safe-assembly
                  assembly {
                      // Compute and set the handover slot to 0.
                      mstore(0x0c, _HANDOVER_SLOT_SEED)
                      mstore(0x00, caller())
                      sstore(keccak256(0x0c, 0x20), 0)
                      // Emit the {OwnershipHandoverCanceled} event.
                      log2(0, 0, _OWNERSHIP_HANDOVER_CANCELED_EVENT_SIGNATURE, caller())
                  }
              }
              /// @dev Allows the owner to complete the two-step ownership handover to `pendingOwner`.
              /// Reverts if there is no existing ownership handover requested by `pendingOwner`.
              function completeOwnershipHandover(address pendingOwner) public payable virtual onlyOwner {
                  /// @solidity memory-safe-assembly
                  assembly {
                      // Compute and set the handover slot to 0.
                      mstore(0x0c, _HANDOVER_SLOT_SEED)
                      mstore(0x00, pendingOwner)
                      let handoverSlot := keccak256(0x0c, 0x20)
                      // If the handover does not exist, or has expired.
                      if gt(timestamp(), sload(handoverSlot)) {
                          mstore(0x00, 0x6f5e8818) // `NoHandoverRequest()`.
                          revert(0x1c, 0x04)
                      }
                      // Set the handover slot to 0.
                      sstore(handoverSlot, 0)
                  }
                  _setOwner(pendingOwner);
              }
              /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
              /*                   PUBLIC READ FUNCTIONS                    */
              /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
              /// @dev Returns the owner of the contract.
              function owner() public view virtual returns (address result) {
                  /// @solidity memory-safe-assembly
                  assembly {
                      result := sload(_OWNER_SLOT)
                  }
              }
              /// @dev Returns the expiry timestamp for the two-step ownership handover to `pendingOwner`.
              function ownershipHandoverExpiresAt(address pendingOwner)
                  public
                  view
                  virtual
                  returns (uint256 result)
              {
                  /// @solidity memory-safe-assembly
                  assembly {
                      // Compute the handover slot.
                      mstore(0x0c, _HANDOVER_SLOT_SEED)
                      mstore(0x00, pendingOwner)
                      // Load the handover slot.
                      result := sload(keccak256(0x0c, 0x20))
                  }
              }
              /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
              /*                         MODIFIERS                          */
              /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
              /// @dev Marks a function as only callable by the owner.
              modifier onlyOwner() virtual {
                  _checkOwner();
                  _;
              }
          }
          // SPDX-License-Identifier: MIT
          // OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)
          pragma solidity ^0.8.20;
          /**
           * @dev Interface of the ERC20 standard as defined in the EIP.
           */
          interface IERC20 {
              /**
               * @dev Emitted when `value` tokens are moved from one account (`from`) to
               * another (`to`).
               *
               * Note that `value` may be zero.
               */
              event Transfer(address indexed from, address indexed to, uint256 value);
              /**
               * @dev Emitted when the allowance of a `spender` for an `owner` is set by
               * a call to {approve}. `value` is the new allowance.
               */
              event Approval(address indexed owner, address indexed spender, uint256 value);
              /**
               * @dev Returns the value of tokens in existence.
               */
              function totalSupply() external view returns (uint256);
              /**
               * @dev Returns the value of tokens owned by `account`.
               */
              function balanceOf(address account) external view returns (uint256);
              /**
               * @dev Moves a `value` amount of tokens from the caller's account to `to`.
               *
               * Returns a boolean value indicating whether the operation succeeded.
               *
               * Emits a {Transfer} event.
               */
              function transfer(address to, uint256 value) external returns (bool);
              /**
               * @dev Returns the remaining number of tokens that `spender` will be
               * allowed to spend on behalf of `owner` through {transferFrom}. This is
               * zero by default.
               *
               * This value changes when {approve} or {transferFrom} are called.
               */
              function allowance(address owner, address spender) external view returns (uint256);
              /**
               * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
               * caller's tokens.
               *
               * Returns a boolean value indicating whether the operation succeeded.
               *
               * IMPORTANT: Beware that changing an allowance with this method brings the risk
               * that someone may use both the old and the new allowance by unfortunate
               * transaction ordering. One possible solution to mitigate this race
               * condition is to first reduce the spender's allowance to 0 and set the
               * desired value afterwards:
               * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
               *
               * Emits an {Approval} event.
               */
              function approve(address spender, uint256 value) external returns (bool);
              /**
               * @dev Moves a `value` amount of tokens from `from` to `to` using the
               * allowance mechanism. `value` is then deducted from the caller's
               * allowance.
               *
               * Returns a boolean value indicating whether the operation succeeded.
               *
               * Emits a {Transfer} event.
               */
              function transferFrom(address from, address to, uint256 value) external returns (bool);
          }
          // SPDX-License-Identifier: MIT
          // OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/utils/SafeERC20.sol)
          pragma solidity ^0.8.20;
          import {IERC20} from "../IERC20.sol";
          import {IERC20Permit} from "../extensions/IERC20Permit.sol";
          import {Address} from "../../../utils/Address.sol";
          /**
           * @title SafeERC20
           * @dev Wrappers around ERC20 operations that throw on failure (when the token
           * contract returns false). Tokens that return no value (and instead revert or
           * throw on failure) are also supported, non-reverting calls are assumed to be
           * successful.
           * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
           * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
           */
          library SafeERC20 {
              using Address for address;
              /**
               * @dev An operation with an ERC20 token failed.
               */
              error SafeERC20FailedOperation(address token);
              /**
               * @dev Indicates a failed `decreaseAllowance` request.
               */
              error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);
              /**
               * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
               * non-reverting calls are assumed to be successful.
               */
              function safeTransfer(IERC20 token, address to, uint256 value) internal {
                  _callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
              }
              /**
               * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
               * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
               */
              function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
                  _callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
              }
              /**
               * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
               * non-reverting calls are assumed to be successful.
               */
              function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
                  uint256 oldAllowance = token.allowance(address(this), spender);
                  forceApprove(token, spender, oldAllowance + value);
              }
              /**
               * @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
               * value, non-reverting calls are assumed to be successful.
               */
              function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
                  unchecked {
                      uint256 currentAllowance = token.allowance(address(this), spender);
                      if (currentAllowance < requestedDecrease) {
                          revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
                      }
                      forceApprove(token, spender, currentAllowance - requestedDecrease);
                  }
              }
              /**
               * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
               * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
               * to be set to zero before setting it to a non-zero value, such as USDT.
               */
              function forceApprove(IERC20 token, address spender, uint256 value) internal {
                  bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));
                  if (!_callOptionalReturnBool(token, approvalCall)) {
                      _callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
                      _callOptionalReturn(token, approvalCall);
                  }
              }
              /**
               * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
               * on the return value: the return value is optional (but if data is returned, it must not be false).
               * @param token The token targeted by the call.
               * @param data The call data (encoded using abi.encode or one of its variants).
               */
              function _callOptionalReturn(IERC20 token, bytes memory data) private {
                  // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
                  // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
                  // the target address contains contract code and also asserts for success in the low-level call.
                  bytes memory returndata = address(token).functionCall(data);
                  if (returndata.length != 0 && !abi.decode(returndata, (bool))) {
                      revert SafeERC20FailedOperation(address(token));
                  }
              }
              /**
               * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
               * on the return value: the return value is optional (but if data is returned, it must not be false).
               * @param token The token targeted by the call.
               * @param data The call data (encoded using abi.encode or one of its variants).
               *
               * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
               */
              function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
                  // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
                  // we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
                  // and not revert is the subcall reverts.
                  (bool success, bytes memory returndata) = address(token).call(data);
                  return success && (returndata.length == 0 || abi.decode(returndata, (bool))) && address(token).code.length > 0;
              }
          }
          // SPDX-License-Identifier: MIT
          pragma solidity ^0.8.23;
          import {ISignatureTransfer} from "permit2-relay/src/interfaces/ISignatureTransfer.sol";
          interface IERC20Router {
              function permitMulticall(
                  address user,
                  ISignatureTransfer.PermitBatchTransferFrom memory permit,
                  address[] calldata targets,
                  bytes[] calldata datas,
                  uint256[] calldata values,
                  address refundTo,
                  bytes memory permitSignature
              ) external payable returns (bytes memory);
              function delegatecallMulticall(
                  address[] calldata targets,
                  bytes[] calldata datas,
                  uint256[] calldata values,
                  address refundTo
              ) external payable returns (bytes memory);
              function cleanupERC20(address token, address refundTo) external;
          }
          // SPDX-License-Identifier: MIT
          // OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Permit.sol)
          pragma solidity ^0.8.20;
          /**
           * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
           * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
           *
           * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
           * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
           * need to send a transaction, and thus is not required to hold Ether at all.
           *
           * ==== Security Considerations
           *
           * There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
           * expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
           * considered as an intention to spend the allowance in any specific way. The second is that because permits have
           * built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
           * take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
           * generally recommended is:
           *
           * ```solidity
           * function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
           *     try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
           *     doThing(..., value);
           * }
           *
           * function doThing(..., uint256 value) public {
           *     token.safeTransferFrom(msg.sender, address(this), value);
           *     ...
           * }
           * ```
           *
           * Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
           * `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
           * {SafeERC20-safeTransferFrom}).
           *
           * Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
           * contracts should have entry points that don't rely on permit.
           */
          interface IERC20Permit {
              /**
               * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
               * given ``owner``'s signed approval.
               *
               * IMPORTANT: The same issues {IERC20-approve} has related to transaction
               * ordering also apply here.
               *
               * Emits an {Approval} event.
               *
               * Requirements:
               *
               * - `spender` cannot be the zero address.
               * - `deadline` must be a timestamp in the future.
               * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
               * over the EIP712-formatted function arguments.
               * - the signature must use ``owner``'s current nonce (see {nonces}).
               *
               * For more information on the signature format, see the
               * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
               * section].
               *
               * CAUTION: See Security Considerations above.
               */
              function permit(
                  address owner,
                  address spender,
                  uint256 value,
                  uint256 deadline,
                  uint8 v,
                  bytes32 r,
                  bytes32 s
              ) external;
              /**
               * @dev Returns the current nonce for `owner`. This value must be
               * included whenever a signature is generated for {permit}.
               *
               * Every successful call to {permit} increases ``owner``'s nonce by one. This
               * prevents a signature from being used multiple times.
               */
              function nonces(address owner) external view returns (uint256);
              /**
               * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
               */
              // solhint-disable-next-line func-name-mixedcase
              function DOMAIN_SEPARATOR() external view returns (bytes32);
          }
          // SPDX-License-Identifier: MIT
          // OpenZeppelin Contracts (last updated v5.0.0) (utils/Address.sol)
          pragma solidity ^0.8.20;
          /**
           * @dev Collection of functions related to the address type
           */
          library Address {
              /**
               * @dev The ETH balance of the account is not enough to perform the operation.
               */
              error AddressInsufficientBalance(address account);
              /**
               * @dev There's no code at `target` (it is not a contract).
               */
              error AddressEmptyCode(address target);
              /**
               * @dev A call to an address target failed. The target may have reverted.
               */
              error FailedInnerCall();
              /**
               * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
               * `recipient`, forwarding all available gas and reverting on errors.
               *
               * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
               * of certain opcodes, possibly making contracts go over the 2300 gas limit
               * imposed by `transfer`, making them unable to receive funds via
               * `transfer`. {sendValue} removes this limitation.
               *
               * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
               *
               * IMPORTANT: because control is transferred to `recipient`, care must be
               * taken to not create reentrancy vulnerabilities. Consider using
               * {ReentrancyGuard} or the
               * https://solidity.readthedocs.io/en/v0.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
               */
              function sendValue(address payable recipient, uint256 amount) internal {
                  if (address(this).balance < amount) {
                      revert AddressInsufficientBalance(address(this));
                  }
                  (bool success, ) = recipient.call{value: amount}("");
                  if (!success) {
                      revert FailedInnerCall();
                  }
              }
              /**
               * @dev Performs a Solidity function call using a low level `call`. A
               * plain `call` is an unsafe replacement for a function call: use this
               * function instead.
               *
               * If `target` reverts with a revert reason or custom error, it is bubbled
               * up by this function (like regular Solidity function calls). However, if
               * the call reverted with no returned reason, this function reverts with a
               * {FailedInnerCall} error.
               *
               * Returns the raw returned data. To convert to the expected return value,
               * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
               *
               * Requirements:
               *
               * - `target` must be a contract.
               * - calling `target` with `data` must not revert.
               */
              function functionCall(address target, bytes memory data) internal returns (bytes memory) {
                  return functionCallWithValue(target, data, 0);
              }
              /**
               * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
               * but also transferring `value` wei to `target`.
               *
               * Requirements:
               *
               * - the calling contract must have an ETH balance of at least `value`.
               * - the called Solidity function must be `payable`.
               */
              function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
                  if (address(this).balance < value) {
                      revert AddressInsufficientBalance(address(this));
                  }
                  (bool success, bytes memory returndata) = target.call{value: value}(data);
                  return verifyCallResultFromTarget(target, success, returndata);
              }
              /**
               * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
               * but performing a static call.
               */
              function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
                  (bool success, bytes memory returndata) = target.staticcall(data);
                  return verifyCallResultFromTarget(target, success, returndata);
              }
              /**
               * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
               * but performing a delegate call.
               */
              function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
                  (bool success, bytes memory returndata) = target.delegatecall(data);
                  return verifyCallResultFromTarget(target, success, returndata);
              }
              /**
               * @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
               * was not a contract or bubbling up the revert reason (falling back to {FailedInnerCall}) in case of an
               * unsuccessful call.
               */
              function verifyCallResultFromTarget(
                  address target,
                  bool success,
                  bytes memory returndata
              ) internal view returns (bytes memory) {
                  if (!success) {
                      _revert(returndata);
                  } else {
                      // only check if target is a contract if the call was successful and the return data is empty
                      // otherwise we already know that it was a contract
                      if (returndata.length == 0 && target.code.length == 0) {
                          revert AddressEmptyCode(target);
                      }
                      return returndata;
                  }
              }
              /**
               * @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
               * revert reason or with a default {FailedInnerCall} error.
               */
              function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
                  if (!success) {
                      _revert(returndata);
                  } else {
                      return returndata;
                  }
              }
              /**
               * @dev Reverts with returndata if present. Otherwise reverts with {FailedInnerCall}.
               */
              function _revert(bytes memory returndata) private pure {
                  // Look for revert reason and bubble it up if present
                  if (returndata.length > 0) {
                      // The easiest way to bubble the revert reason is using memory via assembly
                      /// @solidity memory-safe-assembly
                      assembly {
                          let returndata_size := mload(returndata)
                          revert(add(32, returndata), returndata_size)
                      }
                  } else {
                      revert FailedInnerCall();
                  }
              }
          }
          // SPDX-License-Identifier: MIT
          pragma solidity ^0.8.0;
          import {IEIP712} from "./IEIP712.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;
          }
          // SPDX-License-Identifier: MIT
          pragma solidity ^0.8.0;
          interface IEIP712 {
              function DOMAIN_SEPARATOR() external view returns (bytes32);
          }
          

          File 2 of 4: ERC20Router
          // SPDX-License-Identifier: MIT
          pragma solidity ^0.8.25;
          import {Ownable} from "solady/src/auth/Ownable.sol";
          import {Tstorish} from "tstorish/src/Tstorish.sol";
          import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
          import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
          import {IERC1155} from "@openzeppelin/contracts/token/ERC1155/IERC1155.sol";
          import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
          import {IAllowanceTransfer} from "permit2-relay/src/interfaces/IAllowanceTransfer.sol";
          import {ISignatureTransfer} from "permit2-relay/src/interfaces/ISignatureTransfer.sol";
          import {IPermit2} from "permit2-relay/src/interfaces/IPermit2.sol";
          import {RelayerWitness} from "./types/lib/RelayStructs.sol";
          import {IMulticaller} from "./types/interfaces/IMulticaller.sol";
          contract ERC20Router is Ownable, Tstorish {
              using SafeERC20 for IERC20;
              // --- Errors --- //
              /// @notice Revert if array lengths do not match
              error ArrayLengthsMismatch();
              /// @notice Revert if this contract is set as the recipient
              error InvalidRecipient(address recipient);
              /// @notice Revert if the target is invalid
              error InvalidTarget(address target);
              /// @notice Revert if the native transfer failed
              error NativeTransferFailed();
              /// @notice Revert if no recipient is set
              error NoRecipientSet();
              uint256 RECIPIENT_STORAGE_SLOT = uint256(keccak256("ERC20Router.recipient"));
              address constant ZORA_REWARDS_V1 =
                  0x7777777F279eba3d3Ad8F4E708545291A6fDBA8B;
              IPermit2 private immutable PERMIT2;
              address private immutable MULTICALLER;
              string public constant _RELAYER_WITNESS_TYPE_STRING =
                  "RelayerWitness witness)RelayerWitness(address relayer)TokenPermissions(address token,uint256 amount)";
              bytes32 public constant _EIP_712_RELAYER_WITNESS_TYPE_HASH =
                  keccak256("RelayerWitness(address relayer)");
              constructor(address permit2, address multicaller, address owner) Tstorish() {
                  // Set the address of the Permit2 contract
                  PERMIT2 = IPermit2(permit2);
                  // Set the address of the multicaller contract
                  MULTICALLER = multicaller;
                  // Set the owner that can withdraw funds stuck in the contract
                  _initializeOwner(owner);
              }
              receive() external payable {}
              function withdraw() external onlyOwner {
                  _send(msg.sender, address(this).balance);
              }
              /// @notice Pull user ERC20 tokens through a signed batch permit
              ///         and perform an arbitrary multicall. Pass in an empty
              ///         permitSignature to only perform the multicall.
              /// @dev msg.value will persist across all calls in the multicall
              /// @param user The address of the user
              /// @param permit The permit details
              /// @param targets The addresses of the contracts to call
              /// @param datas The calldata for each call
              /// @param values The value to send with each call
              /// @param refundTo The address to refund any leftover ETH to
              /// @param permitSignature The signature for the permit
              function permitMulticall(
                  address user,
                  ISignatureTransfer.PermitBatchTransferFrom memory permit,
                  address[] calldata targets,
                  bytes[] calldata datas,
                  uint256[] calldata values,
                  address refundTo,
                  bytes memory permitSignature
              ) external payable returns (bytes memory) {
                  // Revert if array lengths do not match
                  if (targets.length != datas.length || datas.length != values.length) {
                      revert ArrayLengthsMismatch();
                  }
                  if (permitSignature.length != 0) {
                      // Use permit to transfer tokens from user to router
                      _handlePermitBatch(user, permit, permitSignature);
                  }
                  // Perform the multicall and send leftover to refundTo
                  bytes memory data = _delegatecallMulticall(
                      targets,
                      datas,
                      values,
                      refundTo
                  );
                  return data;
              }
              /// @notice Call the Multicaller with a delegatecall to set the ERC20Router as the
              ///         sender of the calls to the targets.
              /// @dev    If a multicall is expecting to mint ERC721s or ERC1155s, the recipient must be explicitly set
              ///         All calls to ERC721s and ERC1155s in the multicall will have the same recipient set in refundTo
              ///         If refundTo is address(this), be sure to transfer tokens out of the router as part of the multicall
              /// @param targets The addresses of the contracts to call
              /// @param datas The calldata for each call
              /// @param values The value to send with each call
              /// @param refundTo The address to send any leftover ETH and set as recipient of ERC721/ERC1155 mints
              function delegatecallMulticall(
                  address[] calldata targets,
                  bytes[] calldata datas,
                  uint256[] calldata values,
                  address refundTo
              ) external payable returns (bytes memory) {
                  // Revert if array lengths do not match
                  if (targets.length != datas.length || datas.length != values.length) {
                      revert ArrayLengthsMismatch();
                  }
                  // Set the recipient in storage
                  _setRecipient(refundTo);
                  // Perform the multicall
                  bytes memory data = _delegatecallMulticall(
                      targets,
                      datas,
                      values,
                      refundTo
                  );
                  // Clear the recipient in storage
                  _clearRecipient();
                  return data;
              }
              /// @notice Send leftover ERC20 tokens to the refundTo address
              /// @dev Should be included in the multicall if the router is expecting to receive tokens
              /// @param token The address of the ERC20 token
              /// @param refundTo The address to refund the tokens to
              function cleanupERC20(address token, address refundTo) external {
                  // Check the router's balance for the token
                  uint256 balance = IERC20(token).balanceOf(address(this));
                  // Transfer the token to the refundTo address
                  if (balance > 0) {
                      IERC20(token).safeTransfer(refundTo, balance);
                  }
              }
              /// @notice Internal function to handle a permit batch transfer
              /// @param user The address of the user
              /// @param permit The permit details
              /// @param permitSignature The signature for the permit
              function _handlePermitBatch(
                  address user,
                  ISignatureTransfer.PermitBatchTransferFrom memory permit,
                  bytes memory permitSignature
              ) internal {
                  // Create the witness that should be signed over
                  bytes32 witness = keccak256(
                      abi.encode(_EIP_712_RELAYER_WITNESS_TYPE_HASH, msg.sender)
                  );
                  // Create the SignatureTransferDetails array
                  ISignatureTransfer.SignatureTransferDetails[]
                      memory signatureTransferDetails = new ISignatureTransfer.SignatureTransferDetails[](
                          permit.permitted.length
                      );
                  for (uint256 i = 0; i < permit.permitted.length; i++) {
                      uint256 amount = permit.permitted[i].amount;
                      signatureTransferDetails[i] = ISignatureTransfer
                          .SignatureTransferDetails({
                              to: address(this),
                              requestedAmount: amount
                          });
                  }
                  // Use the SignatureTransferDetails and permit signature to transfer tokens to the router
                  PERMIT2.permitWitnessTransferFrom(
                      permit,
                      signatureTransferDetails,
                      // When using a permit signature, cannot deposit on behalf of someone else other than `user`
                      user,
                      witness,
                      _RELAYER_WITNESS_TYPE_STRING,
                      permitSignature
                  );
              }
              /// @notice Internal function to set the recipient address for ERC721 or ERC1155 mint
              /// @dev If the chain does not support tstore, recipient will be saved in storage
              /// @param recipient The address of the recipient
              function _setRecipient(address recipient) internal {
                  // Return early if the recipient is address(0) or address(1), which are special cases for the multicaller
                  // If a multicall is expecting to mint ERC721s or ERC1155s, the recipient must be explicitly set
                  if (recipient == address(0) || recipient == address(1)) {
                      return;
                  }
                  // For safety, revert if the recipient is this contract
                  // Tokens should either be minted directly to recipient, or transferred to recipient through the onReceived hooks
                  if (recipient == address(this)) {
                      revert InvalidRecipient(address(this));
                  }
                  // Set the recipient in storage
                  _setTstorish(RECIPIENT_STORAGE_SLOT, uint256(uint160(recipient)));
              }
              /// @notice Internal function to get the recipient address for ERC721 or ERC1155 mint
              function _getRecipient() internal view returns (address) {
                  // Get the recipient from storage
                  return address(uint160(_getTstorish(RECIPIENT_STORAGE_SLOT)));
              }
              /// @notice Internal function to clear the recipient address for ERC721 or ERC1155 mint
              function _clearRecipient() internal {
                  // Return if recipient hasn't been set
                  if (_getRecipient() == address(0)) {
                      return;
                  }
                  // Clear the recipient in storage
                  _clearTstorish(RECIPIENT_STORAGE_SLOT);
              }
              /// @notice Internal function to delegatecall the Multicaller contract
              /// @param targets The addresses of the contracts to call
              /// @param datas The calldata for each call
              /// @param values The value to send with each call
              /// @param refundTo The address to send any leftover ETH and set as recipient of ERC721/ERC1155 mints
              function _delegatecallMulticall(
                  address[] calldata targets,
                  bytes[] calldata datas,
                  uint256[] calldata values,
                  address refundTo
              ) internal returns (bytes memory) {
                  for (uint256 i = 0; i < targets.length; i++) {
                      // Revert if the call fails
                      if (targets[i] == ZORA_REWARDS_V1) {
                          revert InvalidTarget(ZORA_REWARDS_V1);
                      }
                  }
                  // Perform the multicall and refund to the user
                  (bool success, bytes memory data) = MULTICALLER.delegatecall(
                      abi.encodeWithSignature(
                          "aggregate(address[],bytes[],uint256[],address)",
                          targets,
                          datas,
                          values,
                          refundTo
                      )
                  );
                  if (!success) {
                      assembly {
                          let returnDataSize := mload(data)
                          revert(add(data, 32), returnDataSize)
                      }
                  }
                  return data;
              }
              function _send(address to, uint256 value) internal {
                  bool success;
                  assembly {
                      // Save gas by avoiding copying the return data to memory.
                      // Provide at most 100k gas to the internal call, which is
                      // more than enough to cover common use-cases of logic for
                      // receiving native tokens (eg. SCW payable fallbacks).
                      success := call(100000, to, value, 0, 0, 0, 0)
                  }
                  if (!success) {
                      revert NativeTransferFailed();
                  }
              }
              function onERC721Received(
                  address /*_operator*/,
                  address /*_from*/,
                  uint256 _tokenId,
                  bytes calldata _data
              ) external returns (bytes4) {
                  // Get the recipient from storage
                  address recipient = _getRecipient();
                  // Revert if no recipient is set
                  // Note this means transferring NFTs to this contract via `safeTransferFrom` will revert,
                  // unless the transfer is part of a multicall that sets the recipient in storage
                  if (recipient == address(0)) {
                      revert NoRecipientSet();
                  }
                  // Transfer the NFT to the recipient
                  IERC721(msg.sender).safeTransferFrom(address(this), recipient, _tokenId, _data);
                  return this.onERC721Received.selector;
              }
              function onERC1155Received(
                  address /*_operator*/,
                  address /*_from*/,
                  uint256 _id,
                  uint256 _value,
                  bytes calldata _data
              ) external returns (bytes4) {
                  // Get the recipient from storage
                  address recipient = _getRecipient();
                  // Revert if no recipient is set
                  // Note this means transferring NFTs to this contract via `safeTransferFrom` will revert,
                  // unless the transfer is part of a multicall that sets the recipient in storage
                  if (recipient == address(0)) {
                      revert NoRecipientSet();
                  }
                  // Transfer the tokens to the recipient
                  IERC1155(msg.sender).safeTransferFrom(address(this), recipient, _id, _value, _data);
                  return this.onERC1155Received.selector;
              }
              function onERC1155BatchReceived(
                  address /*_operator*/,
                  address /*_from*/,
                  uint256[] calldata _ids,
                  uint256[] calldata _values,
                  bytes calldata _data
              ) external returns (bytes4) {
                  // Get the recipient from storage
                  address recipient = _getRecipient();
                  // Revert if no recipient is set
                  // Note this means transferring NFTs to this contract via `safeTransferFrom` will revert,
                  // unless the transfer is part of a multicall that sets the recipient in storage
                  if (recipient == address(0)) {
                      revert NoRecipientSet();
                  }
                  // Transfer the tokens to the recipient
                  IERC1155(msg.sender).safeBatchTransferFrom(address(this), recipient, _ids, _values, _data);
                  return this.onERC1155BatchReceived.selector;
              }
          }
          // SPDX-License-Identifier: MIT
          pragma solidity ^0.8.4;
          /// @notice Simple single owner authorization mixin.
          /// @author Solady (https://github.com/vectorized/solady/blob/main/src/auth/Ownable.sol)
          ///
          /// @dev Note:
          /// This implementation does NOT auto-initialize the owner to `msg.sender`.
          /// You MUST call the `_initializeOwner` in the constructor / initializer.
          ///
          /// While the ownable portion follows
          /// [EIP-173](https://eips.ethereum.org/EIPS/eip-173) for compatibility,
          /// the nomenclature for the 2-step ownership handover may be unique to this codebase.
          abstract contract Ownable {
              /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
              /*                       CUSTOM ERRORS                        */
              /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
              /// @dev The caller is not authorized to call the function.
              error Unauthorized();
              /// @dev The `newOwner` cannot be the zero address.
              error NewOwnerIsZeroAddress();
              /// @dev The `pendingOwner` does not have a valid handover request.
              error NoHandoverRequest();
              /// @dev Cannot double-initialize.
              error AlreadyInitialized();
              /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
              /*                           EVENTS                           */
              /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
              /// @dev The ownership is transferred from `oldOwner` to `newOwner`.
              /// This event is intentionally kept the same as OpenZeppelin's Ownable to be
              /// compatible with indexers and [EIP-173](https://eips.ethereum.org/EIPS/eip-173),
              /// despite it not being as lightweight as a single argument event.
              event OwnershipTransferred(address indexed oldOwner, address indexed newOwner);
              /// @dev An ownership handover to `pendingOwner` has been requested.
              event OwnershipHandoverRequested(address indexed pendingOwner);
              /// @dev The ownership handover to `pendingOwner` has been canceled.
              event OwnershipHandoverCanceled(address indexed pendingOwner);
              /// @dev `keccak256(bytes("OwnershipTransferred(address,address)"))`.
              uint256 private constant _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE =
                  0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0;
              /// @dev `keccak256(bytes("OwnershipHandoverRequested(address)"))`.
              uint256 private constant _OWNERSHIP_HANDOVER_REQUESTED_EVENT_SIGNATURE =
                  0xdbf36a107da19e49527a7176a1babf963b4b0ff8cde35ee35d6cd8f1f9ac7e1d;
              /// @dev `keccak256(bytes("OwnershipHandoverCanceled(address)"))`.
              uint256 private constant _OWNERSHIP_HANDOVER_CANCELED_EVENT_SIGNATURE =
                  0xfa7b8eab7da67f412cc9575ed43464468f9bfbae89d1675917346ca6d8fe3c92;
              /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
              /*                          STORAGE                           */
              /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
              /// @dev The owner slot is given by:
              /// `bytes32(~uint256(uint32(bytes4(keccak256("_OWNER_SLOT_NOT")))))`.
              /// It is intentionally chosen to be a high value
              /// to avoid collision with lower slots.
              /// The choice of manual storage layout is to enable compatibility
              /// with both regular and upgradeable contracts.
              bytes32 internal constant _OWNER_SLOT =
                  0xffffffffffffffffffffffffffffffffffffffffffffffffffffffff74873927;
              /// The ownership handover slot of `newOwner` is given by:
              /// ```
              ///     mstore(0x00, or(shl(96, user), _HANDOVER_SLOT_SEED))
              ///     let handoverSlot := keccak256(0x00, 0x20)
              /// ```
              /// It stores the expiry timestamp of the two-step ownership handover.
              uint256 private constant _HANDOVER_SLOT_SEED = 0x389a75e1;
              /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
              /*                     INTERNAL FUNCTIONS                     */
              /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
              /// @dev Override to return true to make `_initializeOwner` prevent double-initialization.
              function _guardInitializeOwner() internal pure virtual returns (bool guard) {}
              /// @dev Initializes the owner directly without authorization guard.
              /// This function must be called upon initialization,
              /// regardless of whether the contract is upgradeable or not.
              /// This is to enable generalization to both regular and upgradeable contracts,
              /// and to save gas in case the initial owner is not the caller.
              /// For performance reasons, this function will not check if there
              /// is an existing owner.
              function _initializeOwner(address newOwner) internal virtual {
                  if (_guardInitializeOwner()) {
                      /// @solidity memory-safe-assembly
                      assembly {
                          let ownerSlot := _OWNER_SLOT
                          if sload(ownerSlot) {
                              mstore(0x00, 0x0dc149f0) // `AlreadyInitialized()`.
                              revert(0x1c, 0x04)
                          }
                          // Clean the upper 96 bits.
                          newOwner := shr(96, shl(96, newOwner))
                          // Store the new value.
                          sstore(ownerSlot, or(newOwner, shl(255, iszero(newOwner))))
                          // Emit the {OwnershipTransferred} event.
                          log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, 0, newOwner)
                      }
                  } else {
                      /// @solidity memory-safe-assembly
                      assembly {
                          // Clean the upper 96 bits.
                          newOwner := shr(96, shl(96, newOwner))
                          // Store the new value.
                          sstore(_OWNER_SLOT, newOwner)
                          // Emit the {OwnershipTransferred} event.
                          log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, 0, newOwner)
                      }
                  }
              }
              /// @dev Sets the owner directly without authorization guard.
              function _setOwner(address newOwner) internal virtual {
                  if (_guardInitializeOwner()) {
                      /// @solidity memory-safe-assembly
                      assembly {
                          let ownerSlot := _OWNER_SLOT
                          // Clean the upper 96 bits.
                          newOwner := shr(96, shl(96, newOwner))
                          // Emit the {OwnershipTransferred} event.
                          log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, sload(ownerSlot), newOwner)
                          // Store the new value.
                          sstore(ownerSlot, or(newOwner, shl(255, iszero(newOwner))))
                      }
                  } else {
                      /// @solidity memory-safe-assembly
                      assembly {
                          let ownerSlot := _OWNER_SLOT
                          // Clean the upper 96 bits.
                          newOwner := shr(96, shl(96, newOwner))
                          // Emit the {OwnershipTransferred} event.
                          log3(0, 0, _OWNERSHIP_TRANSFERRED_EVENT_SIGNATURE, sload(ownerSlot), newOwner)
                          // Store the new value.
                          sstore(ownerSlot, newOwner)
                      }
                  }
              }
              /// @dev Throws if the sender is not the owner.
              function _checkOwner() internal view virtual {
                  /// @solidity memory-safe-assembly
                  assembly {
                      // If the caller is not the stored owner, revert.
                      if iszero(eq(caller(), sload(_OWNER_SLOT))) {
                          mstore(0x00, 0x82b42900) // `Unauthorized()`.
                          revert(0x1c, 0x04)
                      }
                  }
              }
              /// @dev Returns how long a two-step ownership handover is valid for in seconds.
              /// Override to return a different value if needed.
              /// Made internal to conserve bytecode. Wrap it in a public function if needed.
              function _ownershipHandoverValidFor() internal view virtual returns (uint64) {
                  return 48 * 3600;
              }
              /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
              /*                  PUBLIC UPDATE FUNCTIONS                   */
              /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
              /// @dev Allows the owner to transfer the ownership to `newOwner`.
              function transferOwnership(address newOwner) public payable virtual onlyOwner {
                  /// @solidity memory-safe-assembly
                  assembly {
                      if iszero(shl(96, newOwner)) {
                          mstore(0x00, 0x7448fbae) // `NewOwnerIsZeroAddress()`.
                          revert(0x1c, 0x04)
                      }
                  }
                  _setOwner(newOwner);
              }
              /// @dev Allows the owner to renounce their ownership.
              function renounceOwnership() public payable virtual onlyOwner {
                  _setOwner(address(0));
              }
              /// @dev Request a two-step ownership handover to the caller.
              /// The request will automatically expire in 48 hours (172800 seconds) by default.
              function requestOwnershipHandover() public payable virtual {
                  unchecked {
                      uint256 expires = block.timestamp + _ownershipHandoverValidFor();
                      /// @solidity memory-safe-assembly
                      assembly {
                          // Compute and set the handover slot to `expires`.
                          mstore(0x0c, _HANDOVER_SLOT_SEED)
                          mstore(0x00, caller())
                          sstore(keccak256(0x0c, 0x20), expires)
                          // Emit the {OwnershipHandoverRequested} event.
                          log2(0, 0, _OWNERSHIP_HANDOVER_REQUESTED_EVENT_SIGNATURE, caller())
                      }
                  }
              }
              /// @dev Cancels the two-step ownership handover to the caller, if any.
              function cancelOwnershipHandover() public payable virtual {
                  /// @solidity memory-safe-assembly
                  assembly {
                      // Compute and set the handover slot to 0.
                      mstore(0x0c, _HANDOVER_SLOT_SEED)
                      mstore(0x00, caller())
                      sstore(keccak256(0x0c, 0x20), 0)
                      // Emit the {OwnershipHandoverCanceled} event.
                      log2(0, 0, _OWNERSHIP_HANDOVER_CANCELED_EVENT_SIGNATURE, caller())
                  }
              }
              /// @dev Allows the owner to complete the two-step ownership handover to `pendingOwner`.
              /// Reverts if there is no existing ownership handover requested by `pendingOwner`.
              function completeOwnershipHandover(address pendingOwner) public payable virtual onlyOwner {
                  /// @solidity memory-safe-assembly
                  assembly {
                      // Compute and set the handover slot to 0.
                      mstore(0x0c, _HANDOVER_SLOT_SEED)
                      mstore(0x00, pendingOwner)
                      let handoverSlot := keccak256(0x0c, 0x20)
                      // If the handover does not exist, or has expired.
                      if gt(timestamp(), sload(handoverSlot)) {
                          mstore(0x00, 0x6f5e8818) // `NoHandoverRequest()`.
                          revert(0x1c, 0x04)
                      }
                      // Set the handover slot to 0.
                      sstore(handoverSlot, 0)
                  }
                  _setOwner(pendingOwner);
              }
              /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
              /*                   PUBLIC READ FUNCTIONS                    */
              /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
              /// @dev Returns the owner of the contract.
              function owner() public view virtual returns (address result) {
                  /// @solidity memory-safe-assembly
                  assembly {
                      result := sload(_OWNER_SLOT)
                  }
              }
              /// @dev Returns the expiry timestamp for the two-step ownership handover to `pendingOwner`.
              function ownershipHandoverExpiresAt(address pendingOwner)
                  public
                  view
                  virtual
                  returns (uint256 result)
              {
                  /// @solidity memory-safe-assembly
                  assembly {
                      // Compute the handover slot.
                      mstore(0x0c, _HANDOVER_SLOT_SEED)
                      mstore(0x00, pendingOwner)
                      // Load the handover slot.
                      result := sload(keccak256(0x0c, 0x20))
                  }
              }
              /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
              /*                         MODIFIERS                          */
              /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
              /// @dev Marks a function as only callable by the owner.
              modifier onlyOwner() virtual {
                  _checkOwner();
                  _;
              }
          }
          // SPDX-License-Identifier: MIT
          pragma solidity ^0.8.24;
          contract Tstorish {
              // Declare a storage variable indicating if TSTORE support has been
              // activated post-deployment.
              bool private _tstoreSupport;
              /*
               * ------------------------------------------------------------------------+
               * Opcode      | Mnemonic         | Stack              | Memory            |
               * ------------------------------------------------------------------------|
               * 60 0x02     | PUSH1 0x02       | 0x02               |                   |
               * 60 0x1e     | PUSH1 0x1e       | 0x1e 0x02          |                   |
               * 61 0x3d5c   | PUSH2 0x3d5c     | 0x3d5c 0x1e 0x02   |                   |
               * 3d          | RETURNDATASIZE   | 0 0x3d5c 0x1e 0x02 |                   |
               *                                                                         |
               * :: store deployed bytecode in memory: (3d) RETURNDATASIZE (5c) TLOAD :: |
               * 52          | MSTORE           | 0x1e 0x02          | [0..0x20): 0x3d5c |
               * f3          | RETURN           |                    | [0..0x20): 0x3d5c |
               * ------------------------------------------------------------------------+
               */
              uint256 constant _TLOAD_TEST_PAYLOAD = 0x6002_601e_613d5c_3d_52_f3;
              uint256 constant _TLOAD_TEST_PAYLOAD_LENGTH = 0x0a;
              uint256 constant _TLOAD_TEST_PAYLOAD_OFFSET = 0x16;
              // Declare an immutable variable to store the tstore test contract address.
              address private immutable _tloadTestContract;
              // Declare an immutable variable to store the initial TSTORE support status.
              bool private immutable _tstoreInitialSupport;
              // Declare an immutable function type variable for the _setTstorish function
              // based on chain support for tstore at time of deployment.
              function(uint256,uint256) internal immutable _setTstorish;
              // Declare an immutable function type variable for the _getTstorish function
              // based on chain support for tstore at time of deployment.
              function(uint256) view returns (uint256) internal immutable _getTstorish;
              // Declare an immutable function type variable for the _clearTstorish function
              // based on chain support for tstore at time of deployment.
              function(uint256) internal immutable _clearTstorish;
              // Declare a few custom revert error types.
              error TStoreAlreadyActivated();
              error TStoreNotSupported();
              error TloadTestContractDeploymentFailed();
              error OnlyDirectCalls();
              /**
               * @dev Determine TSTORE availability during deployment. This involves
               *      attempting to deploy a contract that utilizes TLOAD as part of the
               *      contract construction bytecode, and configuring initial support for
               *      using TSTORE in place of SSTORE based on the result.
               */
              constructor() {
                  // Deploy the contract testing TLOAD support and store the address.
                  address tloadTestContract = _prepareTloadTest();
                  // Ensure the deployment was successful.
                  if (tloadTestContract == address(0)) {
                      revert TloadTestContractDeploymentFailed();
                  }
                  // Determine if TSTORE is supported.
                  bool tstoreInitialSupport = _testTload(tloadTestContract);
                  if (tstoreInitialSupport) {
                      // If TSTORE is supported, set functions to their versions that use
                      // tstore/tload directly without support checks.
                      _setTstorish = _setTstore;
                      _getTstorish = _getTstore;
                      _clearTstorish = _clearTstore;
                  } else {
                      // If TSTORE is not supported, set functions to their versions that 
                      // fallback to sstore/sload until _tstoreSupport is true.
                      _setTstorish = _setTstorishWithSstoreFallback;
                      _getTstorish = _getTstorishWithSloadFallback;
                      _clearTstorish = _clearTstorishWithSstoreFallback;
                  }
                  _tstoreInitialSupport = tstoreInitialSupport;
                  // Set the address of the deployed TLOAD test contract as an immutable.
                  _tloadTestContract = tloadTestContract;
              }
              /**
               * @dev External function to activate TSTORE usage. Does not need to be
               *      called if TSTORE is supported from deployment, and only needs to be
               *      called once. Reverts if TSTORE has already been activated or if the
               *      opcode is not available. Note that this must be called directly from
               *      an externally-owned account to avoid potential reentrancy issues.
               */
              function __activateTstore() external {
                  // Ensure this function is triggered from an externally-owned account.
                  if (msg.sender != tx.origin) {
                      revert OnlyDirectCalls();
                  }
                  // Determine if TSTORE can potentially be activated.
                  if (_tstoreInitialSupport || _tstoreSupport) {
                      revert TStoreAlreadyActivated();
                  }
                  // Determine if TSTORE can be activated and revert if not.
                  if (!_testTload(_tloadTestContract)) {
                      revert TStoreNotSupported();
                  }
                  // Mark TSTORE as activated.
                  _tstoreSupport = true;
              }
              /**
               * @dev Private function to set a TSTORISH value. Assigned to _setTstorish 
               *      internal function variable at construction if chain has tstore support.
               *
               * @param storageSlot The slot to write the TSTORISH value to.
               * @param value       The value to write to the given storage slot.
               */
              function _setTstore(uint256 storageSlot, uint256 value) private {
                  assembly {
                      tstore(storageSlot, value)
                  }
              }
              /**
               * @dev Private function to set a TSTORISH value with sstore fallback. 
               *      Assigned to _setTstorish internal function variable at construction
               *      if chain does not have tstore support.
               *
               * @param storageSlot The slot to write the TSTORISH value to.
               * @param value       The value to write to the given storage slot.
               */
              function _setTstorishWithSstoreFallback(uint256 storageSlot, uint256 value) private {
                  if (_tstoreSupport) {
                      assembly {
                          tstore(storageSlot, value)
                      }
                  } else {
                      assembly {
                          sstore(storageSlot, value)
                      }
                  }
              }
              /**
               * @dev Private function to read a TSTORISH value. Assigned to _getTstorish
               *      internal function variable at construction if chain has tstore support.
               *
               * @param storageSlot The slot to read the TSTORISH value from.
               *
               * @return value The TSTORISH value at the given storage slot.
               */
              function _getTstore(
                  uint256 storageSlot
              ) private view returns (uint256 value) {
                  assembly {
                      value := tload(storageSlot)
                  }
              }
              /**
               * @dev Private function to read a TSTORISH value with sload fallback. 
               *      Assigned to _getTstorish internal function variable at construction
               *      if chain does not have tstore support.
               *
               * @param storageSlot The slot to read the TSTORISH value from.
               *
               * @return value The TSTORISH value at the given storage slot.
               */
              function _getTstorishWithSloadFallback(
                  uint256 storageSlot
              ) private view returns (uint256 value) {
                  if (_tstoreSupport) {
                      assembly {
                          value := tload(storageSlot)
                      }
                  } else {
                      assembly {
                          value := sload(storageSlot)
                      }
                  }
              }
              /**
               * @dev Private function to clear a TSTORISH value. Assigned to _clearTstorish internal 
               *      function variable at construction if chain has tstore support.
               *
               * @param storageSlot The slot to clear the TSTORISH value for.
               */
              function _clearTstore(uint256 storageSlot) private {
                  assembly {
                      tstore(storageSlot, 0)
                  }
              }
              /**
               * @dev Private function to clear a TSTORISH value with sstore fallback. 
               *      Assigned to _clearTstorish internal function variable at construction
               *      if chain does not have tstore support.
               *
               * @param storageSlot The slot to clear the TSTORISH value for.
               */
              function _clearTstorishWithSstoreFallback(uint256 storageSlot) private {
                  if (_tstoreSupport) {
                      assembly {
                          tstore(storageSlot, 0)
                      }
                  } else {
                      assembly {
                          sstore(storageSlot, 0)
                      }
                  }
              }
              /**
               * @dev Private function to deploy a test contract that utilizes TLOAD as
               *      part of its fallback logic.
               */
              function _prepareTloadTest() private returns (address contractAddress) {
                  // Utilize assembly to deploy a contract testing TLOAD support.
                  assembly {
                      // Write the contract deployment code payload to scratch space.
                      mstore(0, _TLOAD_TEST_PAYLOAD)
                      // Deploy the contract.
                      contractAddress := create(
                          0,
                          _TLOAD_TEST_PAYLOAD_OFFSET,
                          _TLOAD_TEST_PAYLOAD_LENGTH
                      )
                  }
              }
              /**
               * @dev Private view function to determine if TSTORE/TLOAD are supported by
               *      the current EVM implementation by attempting to call the test
               *      contract, which utilizes TLOAD as part of its fallback logic.
               */
              function _testTload(
                  address tloadTestContract
              ) private view returns (bool ok) {
                  // Call the test contract, which will perform a TLOAD test. If the call
                  // does not revert, then TLOAD/TSTORE is supported. Do not forward all
                  // available gas, as all forwarded gas will be consumed on revert.
                  (ok, ) = tloadTestContract.staticcall{ gas: gasleft() / 10 }("");
              }
          }
          // SPDX-License-Identifier: MIT
          // OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)
          pragma solidity ^0.8.20;
          /**
           * @dev Interface of the ERC20 standard as defined in the EIP.
           */
          interface IERC20 {
              /**
               * @dev Emitted when `value` tokens are moved from one account (`from`) to
               * another (`to`).
               *
               * Note that `value` may be zero.
               */
              event Transfer(address indexed from, address indexed to, uint256 value);
              /**
               * @dev Emitted when the allowance of a `spender` for an `owner` is set by
               * a call to {approve}. `value` is the new allowance.
               */
              event Approval(address indexed owner, address indexed spender, uint256 value);
              /**
               * @dev Returns the value of tokens in existence.
               */
              function totalSupply() external view returns (uint256);
              /**
               * @dev Returns the value of tokens owned by `account`.
               */
              function balanceOf(address account) external view returns (uint256);
              /**
               * @dev Moves a `value` amount of tokens from the caller's account to `to`.
               *
               * Returns a boolean value indicating whether the operation succeeded.
               *
               * Emits a {Transfer} event.
               */
              function transfer(address to, uint256 value) external returns (bool);
              /**
               * @dev Returns the remaining number of tokens that `spender` will be
               * allowed to spend on behalf of `owner` through {transferFrom}. This is
               * zero by default.
               *
               * This value changes when {approve} or {transferFrom} are called.
               */
              function allowance(address owner, address spender) external view returns (uint256);
              /**
               * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
               * caller's tokens.
               *
               * Returns a boolean value indicating whether the operation succeeded.
               *
               * IMPORTANT: Beware that changing an allowance with this method brings the risk
               * that someone may use both the old and the new allowance by unfortunate
               * transaction ordering. One possible solution to mitigate this race
               * condition is to first reduce the spender's allowance to 0 and set the
               * desired value afterwards:
               * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
               *
               * Emits an {Approval} event.
               */
              function approve(address spender, uint256 value) external returns (bool);
              /**
               * @dev Moves a `value` amount of tokens from `from` to `to` using the
               * allowance mechanism. `value` is then deducted from the caller's
               * allowance.
               *
               * Returns a boolean value indicating whether the operation succeeded.
               *
               * Emits a {Transfer} event.
               */
              function transferFrom(address from, address to, uint256 value) external returns (bool);
          }
          // SPDX-License-Identifier: MIT
          // OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/IERC721.sol)
          pragma solidity ^0.8.20;
          import {IERC165} from "../../utils/introspection/IERC165.sol";
          /**
           * @dev Required interface of an ERC721 compliant contract.
           */
          interface IERC721 is IERC165 {
              /**
               * @dev Emitted when `tokenId` token is transferred from `from` to `to`.
               */
              event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
              /**
               * @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
               */
              event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
              /**
               * @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
               */
              event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
              /**
               * @dev Returns the number of tokens in ``owner``'s account.
               */
              function balanceOf(address owner) external view returns (uint256 balance);
              /**
               * @dev Returns the owner of the `tokenId` token.
               *
               * Requirements:
               *
               * - `tokenId` must exist.
               */
              function ownerOf(uint256 tokenId) external view returns (address owner);
              /**
               * @dev Safely transfers `tokenId` token from `from` to `to`.
               *
               * Requirements:
               *
               * - `from` cannot be the zero address.
               * - `to` cannot be the zero address.
               * - `tokenId` token must exist and be owned by `from`.
               * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
               * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon
               *   a safe transfer.
               *
               * Emits a {Transfer} event.
               */
              function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;
              /**
               * @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
               * are aware of the ERC721 protocol to prevent tokens from being forever locked.
               *
               * Requirements:
               *
               * - `from` cannot be the zero address.
               * - `to` cannot be the zero address.
               * - `tokenId` token must exist and be owned by `from`.
               * - If the caller is not `from`, it must have been allowed to move this token by either {approve} or
               *   {setApprovalForAll}.
               * - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon
               *   a safe transfer.
               *
               * Emits a {Transfer} event.
               */
              function safeTransferFrom(address from, address to, uint256 tokenId) external;
              /**
               * @dev Transfers `tokenId` token from `from` to `to`.
               *
               * WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721
               * or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must
               * understand this adds an external call which potentially creates a reentrancy vulnerability.
               *
               * Requirements:
               *
               * - `from` cannot be the zero address.
               * - `to` cannot be the zero address.
               * - `tokenId` token must be owned by `from`.
               * - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
               *
               * Emits a {Transfer} event.
               */
              function transferFrom(address from, address to, uint256 tokenId) external;
              /**
               * @dev Gives permission to `to` to transfer `tokenId` token to another account.
               * The approval is cleared when the token is transferred.
               *
               * Only a single account can be approved at a time, so approving the zero address clears previous approvals.
               *
               * Requirements:
               *
               * - The caller must own the token or be an approved operator.
               * - `tokenId` must exist.
               *
               * Emits an {Approval} event.
               */
              function approve(address to, uint256 tokenId) external;
              /**
               * @dev Approve or remove `operator` as an operator for the caller.
               * Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
               *
               * Requirements:
               *
               * - The `operator` cannot be the address zero.
               *
               * Emits an {ApprovalForAll} event.
               */
              function setApprovalForAll(address operator, bool approved) external;
              /**
               * @dev Returns the account approved for `tokenId` token.
               *
               * Requirements:
               *
               * - `tokenId` must exist.
               */
              function getApproved(uint256 tokenId) external view returns (address operator);
              /**
               * @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
               *
               * See {setApprovalForAll}
               */
              function isApprovedForAll(address owner, address operator) external view returns (bool);
          }
          // SPDX-License-Identifier: MIT
          // OpenZeppelin Contracts (last updated v5.0.1) (token/ERC1155/IERC1155.sol)
          pragma solidity ^0.8.20;
          import {IERC165} from "../../utils/introspection/IERC165.sol";
          /**
           * @dev Required interface of an ERC1155 compliant contract, as defined in the
           * https://eips.ethereum.org/EIPS/eip-1155[EIP].
           */
          interface IERC1155 is IERC165 {
              /**
               * @dev Emitted when `value` amount of tokens of type `id` are transferred from `from` to `to` by `operator`.
               */
              event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value);
              /**
               * @dev Equivalent to multiple {TransferSingle} events, where `operator`, `from` and `to` are the same for all
               * transfers.
               */
              event TransferBatch(
                  address indexed operator,
                  address indexed from,
                  address indexed to,
                  uint256[] ids,
                  uint256[] values
              );
              /**
               * @dev Emitted when `account` grants or revokes permission to `operator` to transfer their tokens, according to
               * `approved`.
               */
              event ApprovalForAll(address indexed account, address indexed operator, bool approved);
              /**
               * @dev Emitted when the URI for token type `id` changes to `value`, if it is a non-programmatic URI.
               *
               * If an {URI} event was emitted for `id`, the standard
               * https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[guarantees] that `value` will equal the value
               * returned by {IERC1155MetadataURI-uri}.
               */
              event URI(string value, uint256 indexed id);
              /**
               * @dev Returns the value of tokens of token type `id` owned by `account`.
               *
               * Requirements:
               *
               * - `account` cannot be the zero address.
               */
              function balanceOf(address account, uint256 id) external view returns (uint256);
              /**
               * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {balanceOf}.
               *
               * Requirements:
               *
               * - `accounts` and `ids` must have the same length.
               */
              function balanceOfBatch(
                  address[] calldata accounts,
                  uint256[] calldata ids
              ) external view returns (uint256[] memory);
              /**
               * @dev Grants or revokes permission to `operator` to transfer the caller's tokens, according to `approved`,
               *
               * Emits an {ApprovalForAll} event.
               *
               * Requirements:
               *
               * - `operator` cannot be the caller.
               */
              function setApprovalForAll(address operator, bool approved) external;
              /**
               * @dev Returns true if `operator` is approved to transfer ``account``'s tokens.
               *
               * See {setApprovalForAll}.
               */
              function isApprovedForAll(address account, address operator) external view returns (bool);
              /**
               * @dev Transfers a `value` amount of tokens of type `id` from `from` to `to`.
               *
               * WARNING: This function can potentially allow a reentrancy attack when transferring tokens
               * to an untrusted contract, when invoking {onERC1155Received} on the receiver.
               * Ensure to follow the checks-effects-interactions pattern and consider employing
               * reentrancy guards when interacting with untrusted contracts.
               *
               * Emits a {TransferSingle} event.
               *
               * Requirements:
               *
               * - `to` cannot be the zero address.
               * - If the caller is not `from`, it must have been approved to spend ``from``'s tokens via {setApprovalForAll}.
               * - `from` must have a balance of tokens of type `id` of at least `value` amount.
               * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the
               * acceptance magic value.
               */
              function safeTransferFrom(address from, address to, uint256 id, uint256 value, bytes calldata data) external;
              /**
               * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}.
               *
               * WARNING: This function can potentially allow a reentrancy attack when transferring tokens
               * to an untrusted contract, when invoking {onERC1155BatchReceived} on the receiver.
               * Ensure to follow the checks-effects-interactions pattern and consider employing
               * reentrancy guards when interacting with untrusted contracts.
               *
               * Emits either a {TransferSingle} or a {TransferBatch} event, depending on the length of the array arguments.
               *
               * Requirements:
               *
               * - `ids` and `values` must have the same length.
               * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the
               * acceptance magic value.
               */
              function safeBatchTransferFrom(
                  address from,
                  address to,
                  uint256[] calldata ids,
                  uint256[] calldata values,
                  bytes calldata data
              ) external;
          }
          // SPDX-License-Identifier: MIT
          // OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/utils/SafeERC20.sol)
          pragma solidity ^0.8.20;
          import {IERC20} from "../IERC20.sol";
          import {IERC20Permit} from "../extensions/IERC20Permit.sol";
          import {Address} from "../../../utils/Address.sol";
          /**
           * @title SafeERC20
           * @dev Wrappers around ERC20 operations that throw on failure (when the token
           * contract returns false). Tokens that return no value (and instead revert or
           * throw on failure) are also supported, non-reverting calls are assumed to be
           * successful.
           * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
           * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
           */
          library SafeERC20 {
              using Address for address;
              /**
               * @dev An operation with an ERC20 token failed.
               */
              error SafeERC20FailedOperation(address token);
              /**
               * @dev Indicates a failed `decreaseAllowance` request.
               */
              error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);
              /**
               * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
               * non-reverting calls are assumed to be successful.
               */
              function safeTransfer(IERC20 token, address to, uint256 value) internal {
                  _callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
              }
              /**
               * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
               * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
               */
              function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
                  _callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
              }
              /**
               * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
               * non-reverting calls are assumed to be successful.
               */
              function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
                  uint256 oldAllowance = token.allowance(address(this), spender);
                  forceApprove(token, spender, oldAllowance + value);
              }
              /**
               * @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
               * value, non-reverting calls are assumed to be successful.
               */
              function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
                  unchecked {
                      uint256 currentAllowance = token.allowance(address(this), spender);
                      if (currentAllowance < requestedDecrease) {
                          revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
                      }
                      forceApprove(token, spender, currentAllowance - requestedDecrease);
                  }
              }
              /**
               * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
               * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
               * to be set to zero before setting it to a non-zero value, such as USDT.
               */
              function forceApprove(IERC20 token, address spender, uint256 value) internal {
                  bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));
                  if (!_callOptionalReturnBool(token, approvalCall)) {
                      _callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
                      _callOptionalReturn(token, approvalCall);
                  }
              }
              /**
               * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
               * on the return value: the return value is optional (but if data is returned, it must not be false).
               * @param token The token targeted by the call.
               * @param data The call data (encoded using abi.encode or one of its variants).
               */
              function _callOptionalReturn(IERC20 token, bytes memory data) private {
                  // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
                  // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
                  // the target address contains contract code and also asserts for success in the low-level call.
                  bytes memory returndata = address(token).functionCall(data);
                  if (returndata.length != 0 && !abi.decode(returndata, (bool))) {
                      revert SafeERC20FailedOperation(address(token));
                  }
              }
              /**
               * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
               * on the return value: the return value is optional (but if data is returned, it must not be false).
               * @param token The token targeted by the call.
               * @param data The call data (encoded using abi.encode or one of its variants).
               *
               * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
               */
              function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
                  // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
                  // we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
                  // and not revert is the subcall reverts.
                  (bool success, bytes memory returndata) = address(token).call(data);
                  return success && (returndata.length == 0 || abi.decode(returndata, (bool))) && address(token).code.length > 0;
              }
          }
          // SPDX-License-Identifier: MIT
          pragma solidity ^0.8.0;
          import {IEIP712} from "./IEIP712.sol";
          /// @title AllowanceTransfer
          /// @notice Handles ERC20 token permissions through signature based allowance setting and ERC20 token transfers by checking allowed amounts
          /// @dev Requires user's token approval on the Permit2 contract
          interface IAllowanceTransfer is IEIP712 {
              /// @notice Thrown when an allowance on a token has expired.
              /// @param deadline The timestamp at which the allowed amount is no longer valid
              error AllowanceExpired(uint256 deadline);
              /// @notice Thrown when an allowance on a token has been depleted.
              /// @param amount The maximum amount allowed
              error InsufficientAllowance(uint256 amount);
              /// @notice Thrown when too many nonces are invalidated.
              error ExcessiveInvalidation();
              /// @notice Emits an event when the owner successfully invalidates an ordered nonce.
              event NonceInvalidation(
                  address indexed owner, address indexed token, address indexed spender, uint48 newNonce, uint48 oldNonce
              );
              /// @notice Emits an event when the owner successfully sets permissions on a token for the spender.
              event Approval(
                  address indexed owner, address indexed token, address indexed spender, uint160 amount, uint48 expiration
              );
              /// @notice Emits an event when the owner successfully sets permissions using a permit signature on a token for the spender.
              event Permit(
                  address indexed owner,
                  address indexed token,
                  address indexed spender,
                  uint160 amount,
                  uint48 expiration,
                  uint48 nonce
              );
              /// @notice Emits an event when the owner sets the allowance back to 0 with the lockdown function.
              event Lockdown(address indexed owner, address token, address spender);
              /// @notice The permit data for a token
              struct PermitDetails {
                  // ERC20 token address
                  address token;
                  // the maximum amount allowed to spend
                  uint160 amount;
                  // timestamp at which a spender's token allowances become invalid
                  uint48 expiration;
                  // an incrementing value indexed per owner,token,and spender for each signature
                  uint48 nonce;
              }
              /// @notice The permit message signed for a single token allowance
              struct PermitSingle {
                  // the permit data for a single token alownce
                  PermitDetails details;
                  // address permissioned on the allowed tokens
                  address spender;
                  // deadline on the permit signature
                  uint256 sigDeadline;
              }
              /// @notice The permit message signed for multiple token allowances
              struct PermitBatch {
                  // the permit data for multiple token allowances
                  PermitDetails[] details;
                  // address permissioned on the allowed tokens
                  address spender;
                  // deadline on the permit signature
                  uint256 sigDeadline;
              }
              /// @notice The saved permissions
              /// @dev This info is saved per owner, per token, per spender and all signed over in the permit message
              /// @dev Setting amount to type(uint160).max sets an unlimited approval
              struct PackedAllowance {
                  // amount allowed
                  uint160 amount;
                  // permission expiry
                  uint48 expiration;
                  // an incrementing value indexed per owner,token,and spender for each signature
                  uint48 nonce;
              }
              /// @notice A token spender pair.
              struct TokenSpenderPair {
                  // the token the spender is approved
                  address token;
                  // the spender address
                  address spender;
              }
              /// @notice Details for a token transfer.
              struct AllowanceTransferDetails {
                  // the owner of the token
                  address from;
                  // the recipient of the token
                  address to;
                  // the amount of the token
                  uint160 amount;
                  // the token to be transferred
                  address token;
              }
              /// @notice A mapping from owner address to token address to spender address to PackedAllowance struct, which contains details and conditions of the approval.
              /// @notice The mapping is indexed in the above order see: allowance[ownerAddress][tokenAddress][spenderAddress]
              /// @dev The packed slot holds the allowed amount, expiration at which the allowed amount is no longer valid, and current nonce thats updated on any signature based approvals.
              function allowance(address user, address token, address spender)
                  external
                  view
                  returns (uint160 amount, uint48 expiration, uint48 nonce);
              /// @notice Approves the spender to use up to amount of the specified token up until the expiration
              /// @param token The token to approve
              /// @param spender The spender address to approve
              /// @param amount The approved amount of the token
              /// @param expiration The timestamp at which the approval is no longer valid
              /// @dev The packed allowance also holds a nonce, which will stay unchanged in approve
              /// @dev Setting amount to type(uint160).max sets an unlimited approval
              function approve(address token, address spender, uint160 amount, uint48 expiration) external;
              /// @notice Permit a spender to a given amount of the owners token via the owner's EIP-712 signature
              /// @dev May fail if the owner's nonce was invalidated in-flight by invalidateNonce
              /// @param owner The owner of the tokens being approved
              /// @param permitSingle Data signed over by the owner specifying the terms of approval
              /// @param signature The owner's signature over the permit data
              function permit(address owner, PermitSingle memory permitSingle, bytes calldata signature) external;
              /// @notice Permit a spender to the signed amounts of the owners tokens via the owner's EIP-712 signature
              /// @dev May fail if the owner's nonce was invalidated in-flight by invalidateNonce
              /// @param owner The owner of the tokens being approved
              /// @param permitBatch Data signed over by the owner specifying the terms of approval
              /// @param signature The owner's signature over the permit data
              function permit(address owner, PermitBatch memory permitBatch, bytes calldata signature) external;
              /// @notice Transfer approved tokens from one address to another
              /// @param from The address to transfer from
              /// @param to The address of the recipient
              /// @param amount The amount of the token to transfer
              /// @param token The token address to transfer
              /// @dev Requires the from address to have approved at least the desired amount
              /// of tokens to msg.sender.
              function transferFrom(address from, address to, uint160 amount, address token) external;
              /// @notice Transfer approved tokens in a batch
              /// @param transferDetails Array of owners, recipients, amounts, and tokens for the transfers
              /// @dev Requires the from addresses to have approved at least the desired amount
              /// of tokens to msg.sender.
              function transferFrom(AllowanceTransferDetails[] calldata transferDetails) external;
              /// @notice Enables performing a "lockdown" of the sender's Permit2 identity
              /// by batch revoking approvals
              /// @param approvals Array of approvals to revoke.
              function lockdown(TokenSpenderPair[] calldata approvals) external;
              /// @notice Invalidate nonces for a given (token, spender) pair
              /// @param token The token to invalidate nonces for
              /// @param spender The spender to invalidate nonces for
              /// @param newNonce The new nonce to set. Invalidates all nonces less than it.
              /// @dev Can't invalidate more than 2**16 nonces per transaction.
              function invalidateNonces(address token, address spender, uint48 newNonce) external;
          }
          // SPDX-License-Identifier: MIT
          pragma solidity ^0.8.0;
          import {IEIP712} from "./IEIP712.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;
          }
          // SPDX-License-Identifier: MIT
          pragma solidity ^0.8.0;
          import {ISignatureTransfer} from "./ISignatureTransfer.sol";
          import {IAllowanceTransfer} from "./IAllowanceTransfer.sol";
          /// @notice Permit2 handles signature-based transfers in SignatureTransfer and allowance-based transfers in AllowanceTransfer.
          /// @dev Users must approve Permit2 before calling any of the transfer functions.
          interface IPermit2 is ISignatureTransfer, IAllowanceTransfer {
          // IPermit2 unifies the two interfaces so users have maximal flexibility with their approval.
          }
          // SPDX-License-Identifier: MIT
          pragma solidity ^0.8.23;
          enum OrderStatus {
              NotInitiated,
              Initiated,
              Settled__FulfilledPrimary,
              Settled__FulfilledSecondary,
              Settled__Refund,
              Cancelled
          }
          enum Verdict {
              FulfilledPrimary,
              FulfilledSecondary,
              Refund
          }
          /// @notice A struct representing an input or output token transfer. These transfers must take place
          ///         on their respective chains in order for validators to sign the order.
          /// @param token   The address of the token to transfer
          /// @param from    The from address
          /// @param to      The to address
          /// @param amount  The amount to transfer
          /// @param chainId The chainId of the transfer
          struct TokenTransfer {
              address token; // address(0) for native, erc20 otherwise
              address from;
              address to;
              uint256 amount;
              uint256 chainId; // chainId of 0 means escrow balance should be transferred between `from` and `to`
          }
          /// @notice A call to be executed as part of the order. If a call is representing a "pre-hook", the output
          ///         of the call will be bridged to the destination chain. If a call is representing a "post-hook",
          ///         the output of the call will be sent to the user.
          /// @param to        The address of the contract to call
          /// @param isPreHook If true, the call is a "pre-hook". If false, the call is a "post-hook"
          /// @param value     The value to send with the call
          /// @param data      The data to send with the call
          struct Route {
              address to;
              uint256 value;
              uint256 chainId;
              bytes data;
          }
          /// @notice An order that can be sequenced and settled by the protocol
          ///         To complete the order lifecycle, the order must be signed by the user, relayer, validator, and oracle
          /// @param user             The address of the user
          /// @param relayer          The address of the relayer
          /// @param validator        The address of the validator
          /// @param collateralAmount The amount of collateral to lock as part of the order
          /// @param expiration       The order expiration timestamp. If a validator determines that input tokens haven't been transferred by expiration,
          ///                         it can cancel the order.
          /// @param intentCommit     A hash of the order's input and output TokenTransfer[], or the order's "intent". Any internal Relay ETH fees to other
          ///                         parties in the order lifecylce should be specified in the output array. Note that the order of the encoded inputs will affect
          ///                         the intentCommit hash. The intentCommit is meant to be revealed in the call to `settleOrder`.
          /// @param primaryCommit    A hash of the order's origin and destination Route[]. This route should satisfy the hashed intentCommit.
          ///                         The routeCommit is meant to be verified offchain between the relayer and the validator.
          /// @param hookCommit       A hash of the order's pre and post hooks, if necessary. Note that the pre hook will be executed with the user's input tokens
          ///                         on the origin chain, and the post hook will be executed with the user's output tokens on the destination chain
          struct Order {
              address user;
              address relayer;
              address validator;
              uint256 nonce;
              uint256 collateralAmount;
              uint256 inputDeadline;
              uint256 primaryDeadline;
              uint256 secondaryDeadline;
              bytes32 intentCommit;
              bytes32 primaryCommit;
              bytes32 secondaryCommit;
          }
          /// @notice Collateral balances (user or relayer)
          /// @param totalBalance The total balance of the account
          /// @param outstandingBalance The balance locked in initiated but unsettled orders
          /// @param relayEthBalance Surplus ETH from fees that can be used to pay for fees or gas
          struct Balances {
              uint256 totalBalance;
              uint256 outstandingBalance;
              uint256 relayEthBalance;
          }
          struct RelayerWitness {
              address relayer;
          }
          struct EscrowBalance {
              uint256 timelock;
              uint256 lockedBalance;
          }
          // SPDX-License-Identifier: MIT
          pragma solidity ^0.8.4;
          /**
           * @title IMulticaller
           * @notice Interface for the Multicaller contract.
           */
          interface IMulticaller {
              /**
               * @dev Aggregates multiple calls in a single transaction.
               * @param targets  An array of addresses to call.
               * @param data     An array of calldata to forward to the targets.
               * @param values   How much ETH to forward to each target.
               * @param refundTo The address to transfer any remaining ETH in the contract after the calls.
               *                 If `address(0)`, remaining ETH will NOT be refunded.
               *                 If `address(1)`, remaining ETH will be refunded to `msg.sender`.
               *                 If anything else, remaining ETH will be refunded to `refundTo`.
               * @return An array of the returndata from each call.
               */
              function aggregate(
                  address[] calldata targets,
                  bytes[] calldata data,
                  uint256[] calldata values,
                  address refundTo
              ) external payable returns (bytes[] memory);
          }
          // SPDX-License-Identifier: MIT
          // OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/IERC165.sol)
          pragma solidity ^0.8.20;
          /**
           * @dev Interface of the ERC165 standard, as defined in the
           * https://eips.ethereum.org/EIPS/eip-165[EIP].
           *
           * Implementers can declare support of contract interfaces, which can then be
           * queried by others ({ERC165Checker}).
           *
           * For an implementation, see {ERC165}.
           */
          interface IERC165 {
              /**
               * @dev Returns true if this contract implements the interface defined by
               * `interfaceId`. See the corresponding
               * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
               * to learn more about how these ids are created.
               *
               * This function call must use less than 30 000 gas.
               */
              function supportsInterface(bytes4 interfaceId) external view returns (bool);
          }
          // SPDX-License-Identifier: MIT
          // OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Permit.sol)
          pragma solidity ^0.8.20;
          /**
           * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
           * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
           *
           * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
           * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
           * need to send a transaction, and thus is not required to hold Ether at all.
           *
           * ==== Security Considerations
           *
           * There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
           * expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
           * considered as an intention to spend the allowance in any specific way. The second is that because permits have
           * built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
           * take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
           * generally recommended is:
           *
           * ```solidity
           * function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
           *     try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
           *     doThing(..., value);
           * }
           *
           * function doThing(..., uint256 value) public {
           *     token.safeTransferFrom(msg.sender, address(this), value);
           *     ...
           * }
           * ```
           *
           * Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
           * `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
           * {SafeERC20-safeTransferFrom}).
           *
           * Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
           * contracts should have entry points that don't rely on permit.
           */
          interface IERC20Permit {
              /**
               * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
               * given ``owner``'s signed approval.
               *
               * IMPORTANT: The same issues {IERC20-approve} has related to transaction
               * ordering also apply here.
               *
               * Emits an {Approval} event.
               *
               * Requirements:
               *
               * - `spender` cannot be the zero address.
               * - `deadline` must be a timestamp in the future.
               * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
               * over the EIP712-formatted function arguments.
               * - the signature must use ``owner``'s current nonce (see {nonces}).
               *
               * For more information on the signature format, see the
               * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
               * section].
               *
               * CAUTION: See Security Considerations above.
               */
              function permit(
                  address owner,
                  address spender,
                  uint256 value,
                  uint256 deadline,
                  uint8 v,
                  bytes32 r,
                  bytes32 s
              ) external;
              /**
               * @dev Returns the current nonce for `owner`. This value must be
               * included whenever a signature is generated for {permit}.
               *
               * Every successful call to {permit} increases ``owner``'s nonce by one. This
               * prevents a signature from being used multiple times.
               */
              function nonces(address owner) external view returns (uint256);
              /**
               * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
               */
              // solhint-disable-next-line func-name-mixedcase
              function DOMAIN_SEPARATOR() external view returns (bytes32);
          }
          // SPDX-License-Identifier: MIT
          // OpenZeppelin Contracts (last updated v5.0.0) (utils/Address.sol)
          pragma solidity ^0.8.20;
          /**
           * @dev Collection of functions related to the address type
           */
          library Address {
              /**
               * @dev The ETH balance of the account is not enough to perform the operation.
               */
              error AddressInsufficientBalance(address account);
              /**
               * @dev There's no code at `target` (it is not a contract).
               */
              error AddressEmptyCode(address target);
              /**
               * @dev A call to an address target failed. The target may have reverted.
               */
              error FailedInnerCall();
              /**
               * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
               * `recipient`, forwarding all available gas and reverting on errors.
               *
               * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
               * of certain opcodes, possibly making contracts go over the 2300 gas limit
               * imposed by `transfer`, making them unable to receive funds via
               * `transfer`. {sendValue} removes this limitation.
               *
               * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
               *
               * IMPORTANT: because control is transferred to `recipient`, care must be
               * taken to not create reentrancy vulnerabilities. Consider using
               * {ReentrancyGuard} or the
               * https://solidity.readthedocs.io/en/v0.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
               */
              function sendValue(address payable recipient, uint256 amount) internal {
                  if (address(this).balance < amount) {
                      revert AddressInsufficientBalance(address(this));
                  }
                  (bool success, ) = recipient.call{value: amount}("");
                  if (!success) {
                      revert FailedInnerCall();
                  }
              }
              /**
               * @dev Performs a Solidity function call using a low level `call`. A
               * plain `call` is an unsafe replacement for a function call: use this
               * function instead.
               *
               * If `target` reverts with a revert reason or custom error, it is bubbled
               * up by this function (like regular Solidity function calls). However, if
               * the call reverted with no returned reason, this function reverts with a
               * {FailedInnerCall} error.
               *
               * Returns the raw returned data. To convert to the expected return value,
               * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
               *
               * Requirements:
               *
               * - `target` must be a contract.
               * - calling `target` with `data` must not revert.
               */
              function functionCall(address target, bytes memory data) internal returns (bytes memory) {
                  return functionCallWithValue(target, data, 0);
              }
              /**
               * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
               * but also transferring `value` wei to `target`.
               *
               * Requirements:
               *
               * - the calling contract must have an ETH balance of at least `value`.
               * - the called Solidity function must be `payable`.
               */
              function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
                  if (address(this).balance < value) {
                      revert AddressInsufficientBalance(address(this));
                  }
                  (bool success, bytes memory returndata) = target.call{value: value}(data);
                  return verifyCallResultFromTarget(target, success, returndata);
              }
              /**
               * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
               * but performing a static call.
               */
              function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
                  (bool success, bytes memory returndata) = target.staticcall(data);
                  return verifyCallResultFromTarget(target, success, returndata);
              }
              /**
               * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
               * but performing a delegate call.
               */
              function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
                  (bool success, bytes memory returndata) = target.delegatecall(data);
                  return verifyCallResultFromTarget(target, success, returndata);
              }
              /**
               * @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
               * was not a contract or bubbling up the revert reason (falling back to {FailedInnerCall}) in case of an
               * unsuccessful call.
               */
              function verifyCallResultFromTarget(
                  address target,
                  bool success,
                  bytes memory returndata
              ) internal view returns (bytes memory) {
                  if (!success) {
                      _revert(returndata);
                  } else {
                      // only check if target is a contract if the call was successful and the return data is empty
                      // otherwise we already know that it was a contract
                      if (returndata.length == 0 && target.code.length == 0) {
                          revert AddressEmptyCode(target);
                      }
                      return returndata;
                  }
              }
              /**
               * @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
               * revert reason or with a default {FailedInnerCall} error.
               */
              function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
                  if (!success) {
                      _revert(returndata);
                  } else {
                      return returndata;
                  }
              }
              /**
               * @dev Reverts with returndata if present. Otherwise reverts with {FailedInnerCall}.
               */
              function _revert(bytes memory returndata) private pure {
                  // Look for revert reason and bubble it up if present
                  if (returndata.length > 0) {
                      // The easiest way to bubble the revert reason is using memory via assembly
                      /// @solidity memory-safe-assembly
                      assembly {
                          let returndata_size := mload(returndata)
                          revert(add(32, returndata), returndata_size)
                      }
                  } else {
                      revert FailedInnerCall();
                  }
              }
          }
          // SPDX-License-Identifier: MIT
          pragma solidity ^0.8.0;
          interface IEIP712 {
              function DOMAIN_SEPARATOR() external view returns (bytes32);
          }
          

          File 3 of 4: 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 4 of 4: Multicaller
          // SPDX-License-Identifier: MIT
          pragma solidity ^0.8.4;
          /**
           * @title Multicaller
           * @author vectorized.eth
           * @notice Contract that allows for efficient aggregation
           *         of multiple calls in a single transaction.
           */
          contract Multicaller {
              // =============================================================
              //                            ERRORS
              // =============================================================
              /**
               * @dev The lengths of the input arrays are not the same.
               */
              error ArrayLengthsMismatch();
              // =============================================================
              //                    AGGREGATION OPERATIONS
              // =============================================================
              /**
               * @dev Aggregates multiple calls in a single transaction.
               * @param targets  An array of addresses to call.
               * @param data     An array of calldata to forward to the targets.
               * @param values   How much ETH to forward to each target.
               * @param refundTo The address to transfer any remaining ETH in the contract after the calls.
               *                 If `address(0)`, remaining ETH will NOT be refunded.
               *                 If `address(1)`, remaining ETH will be refunded to `msg.sender`.
               *                 If anything else, remaining ETH will be refunded to `refundTo`.
               * @return An array of the returndata from each call.
               */
              function aggregate(
                  address[] calldata targets,
                  bytes[] calldata data,
                  uint256[] calldata values,
                  address refundTo
              ) external payable returns (bytes[] memory) {
                  assembly {
                      if iszero(and(eq(targets.length, data.length), eq(data.length, values.length))) {
                          // Store the function selector of `ArrayLengthsMismatch()`.
                          mstore(returndatasize(), 0x3b800a46)
                          // Revert with (offset, size).
                          revert(0x1c, 0x04)
                      }
                      let resultsSize := 0x40
                      if data.length {
                          let results := 0x40
                          // Left shift by 5 is equivalent to multiplying by 0x20.
                          data.length := shl(5, data.length)
                          // Copy the offsets from calldata into memory.
                          calldatacopy(results, data.offset, data.length)
                          // Offset into `results`.
                          let resultsOffset := data.length
                          // Pointer to the end of `results`.
                          let end := add(results, data.length)
                          // For deriving the calldata offsets from the `results` pointer.
                          let valuesOffsetDiff := sub(values.offset, results)
                          let targetsOffsetDiff := sub(targets.offset, results)
                          for {} 1 {} {
                              // The offset of the current bytes in the calldata.
                              let o := add(data.offset, mload(results))
                              let memPtr := add(resultsOffset, 0x40)
                              // Copy the current bytes from calldata to the memory.
                              calldatacopy(
                                  memPtr,
                                  add(o, 0x20), // The offset of the current bytes' bytes.
                                  calldataload(o) // The length of the current bytes.
                              )
                              if iszero(
                                  call(
                                      gas(), // Remaining gas.
                                      calldataload(add(targetsOffsetDiff, results)), // Address to call.
                                      calldataload(add(valuesOffsetDiff, results)), // ETH to send.
                                      memPtr, // Start of input calldata in memory.
                                      calldataload(o), // Size of input calldata.
                                      0x00, // We will use returndatacopy instead.
                                      0x00 // We will use returndatacopy instead.
                                  )
                              ) {
                                  // Bubble up the revert if the call reverts.
                                  returndatacopy(0x00, 0x00, returndatasize())
                                  revert(0x00, returndatasize())
                              }
                              // Append the current `resultsOffset` into `results`.
                              mstore(results, resultsOffset)
                              // Append the returndatasize, and the returndata.
                              mstore(memPtr, returndatasize())
                              returndatacopy(add(memPtr, 0x20), 0x00, returndatasize())
                              // Advance the `resultsOffset` by `returndatasize() + 0x20`,
                              // rounded up to the next multiple of 0x20.
                              resultsOffset := and(add(add(resultsOffset, returndatasize()), 0x3f), not(0x1f))
                              // Advance the `results` pointer.
                              results := add(results, 0x20)
                              if eq(results, end) { break }
                          }
                          resultsSize := add(resultsOffset, 0x40)
                      }
                      if refundTo {
                          // Force transfers all the remaining ETH in the contract to `refundTo`,
                          // with a gas stipend of 100000, which should be enough for most use cases.
                          // If sending via a regular call fails, force sends the ETH by
                          // creating a temporary contract which uses `SELFDESTRUCT` to force send the ETH.
                          if selfbalance() {
                              // If `refundTo` is `address(1)`, replace it with the `msg.sender`.
                              refundTo := xor(refundTo, mul(eq(refundTo, 1), xor(refundTo, caller())))
                              // Transfer the ETH and check if it succeeded or not.
                              if iszero(
                                  call(100000, refundTo, selfbalance(), codesize(), 0x00, codesize(), 0x00)
                              ) {
                                  mstore(0x00, refundTo) // Store the address in scratch space.
                                  mstore8(0x0b, 0x73) // Opcode `PUSH20`.
                                  mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`.
                                  // We can directly use `SELFDESTRUCT` in the contract creation.
                                  // Compatible with `SENDALL`: https://eips.ethereum.org/EIPS/eip-4758
                                  if iszero(create(selfbalance(), 0x0b, 0x16)) {
                                      // Coerce gas estimation to provide enough gas for the `create` above.
                                      revert(codesize(), codesize())
                                  }
                              }
                          }
                      }
                      mstore(0x00, 0x20) // Store the memory offset of the `results`.
                      mstore(0x20, targets.length) // Store `targets.length` into `results`.
                      // Direct return.
                      return(0x00, resultsSize)
                  }
              }
              /**
               * @dev For receiving ETH.
               *      Does nothing and returns nothing.
               *      Called instead of `fallback()` if the calldatasize is zero.
               */
              receive() external payable {}
              /**
               * @dev Decompresses the calldata and performs a delegatecall
               *      with the decompressed calldata to itself.
               *
               *      Accompanying JavaScript library to compress the calldata:
               *      https://github.com/vectorized/solady/blob/main/js/solady.js
               *      (See: `LibZip.cdCompress`)
               */
              fallback() external payable {
                  assembly {
                      // If the calldata starts with the bitwise negation of
                      // `bytes4(keccak256("aggregate(address[],bytes[],uint256[],address)"))`.
                      let s := calldataload(returndatasize())
                      if eq(shr(224, s), 0x66e0daa0) {
                          mstore(returndatasize(), not(s))
                          let o := 4
                          for { let i := o } lt(i, calldatasize()) {} {
                              let c := byte(returndatasize(), calldataload(i))
                              i := add(i, 1)
                              if iszero(c) {
                                  let d := byte(returndatasize(), calldataload(i))
                                  i := add(i, 1)
                                  // Fill with either 0xff or 0x00.
                                  mstore(o, not(returndatasize()))
                                  if iszero(gt(d, 0x7f)) { codecopy(o, codesize(), add(d, 1)) }
                                  o := add(o, add(and(d, 0x7f), 1))
                                  continue
                              }
                              mstore8(o, c)
                              o := add(o, 1)
                          }
                          let success := delegatecall(gas(), address(), 0x00, o, 0x00, 0x00)
                          returndatacopy(0x00, 0x00, returndatasize())
                          if iszero(success) { revert(0x00, returndatasize()) }
                          return(0x00, returndatasize())
                      }
                      revert(returndatasize(), returndatasize())
                  }
              }
          }