ETH Price: $2,677.46 (-2.16%)

Contract

0x8CD89Ea14345F24d0299c2180Aec97a417Ca34E3

Overview

ETH Balance

0 ETH

ETH Value

$0.00

More Info

Private Name Tags

Multichain Info

No addresses found
Transaction Hash
Block
From
To

There are no matching entries

> 10 Internal Transactions found.

Latest 25 internal transactions (View All)

Parent Transaction Hash Block From To
4270734272026-01-31 7:17:4218 mins ago1769843862
0x8CD89Ea1...417Ca34E3
0.06443125 ETH
4270734272026-01-31 7:17:4218 mins ago1769843862
0x8CD89Ea1...417Ca34E3
0.06443125 ETH
4270722892026-01-31 7:12:5622 mins ago1769843576
0x8CD89Ea1...417Ca34E3
0.00376675 ETH
4270722892026-01-31 7:12:5622 mins ago1769843576
0x8CD89Ea1...417Ca34E3
0.00376675 ETH
4270722002026-01-31 7:12:3423 mins ago1769843554
0x8CD89Ea1...417Ca34E3
0.00664137 ETH
4270722002026-01-31 7:12:3423 mins ago1769843554
0x8CD89Ea1...417Ca34E3
0.00664137 ETH
4270680412026-01-31 6:55:1540 mins ago1769842515
0x8CD89Ea1...417Ca34E3
0.00157569 ETH
4270680412026-01-31 6:55:1540 mins ago1769842515
0x8CD89Ea1...417Ca34E3
0.00157569 ETH
4270655272026-01-31 6:44:4951 mins ago1769841889
0x8CD89Ea1...417Ca34E3
0.00049691 ETH
4270655272026-01-31 6:44:4951 mins ago1769841889
0x8CD89Ea1...417Ca34E3
0.00049691 ETH
4270648082026-01-31 6:41:4854 mins ago1769841708
0x8CD89Ea1...417Ca34E3
0.0035685 ETH
4270648082026-01-31 6:41:4854 mins ago1769841708
0x8CD89Ea1...417Ca34E3
0.0035685 ETH
4270613002026-01-31 6:27:151 hr ago1769840835
0x8CD89Ea1...417Ca34E3
0.01251194 ETH
4270613002026-01-31 6:27:151 hr ago1769840835
0x8CD89Ea1...417Ca34E3
0.01251194 ETH
4270490982026-01-31 5:36:301 hr ago1769837790
0x8CD89Ea1...417Ca34E3
0.0257725 ETH
4270490982026-01-31 5:36:301 hr ago1769837790
0x8CD89Ea1...417Ca34E3
0.0257725 ETH
4270223472026-01-31 3:45:173 hrs ago1769831117
0x8CD89Ea1...417Ca34E3
0.00921862 ETH
4270223472026-01-31 3:45:173 hrs ago1769831117
0x8CD89Ea1...417Ca34E3
0.00921862 ETH
4270174762026-01-31 3:25:014 hrs ago1769829901
0x8CD89Ea1...417Ca34E3
0.08058862 ETH
4270174762026-01-31 3:25:014 hrs ago1769829901
0x8CD89Ea1...417Ca34E3
0.08058862 ETH
4270159542026-01-31 3:18:434 hrs ago1769829523
0x8CD89Ea1...417Ca34E3
0.14870348 ETH
4270159542026-01-31 3:18:434 hrs ago1769829523
0x8CD89Ea1...417Ca34E3
0.14870348 ETH
4270128482026-01-31 3:05:484 hrs ago1769828748
0x8CD89Ea1...417Ca34E3
0.00183381 ETH
4270128482026-01-31 3:05:484 hrs ago1769828748
0x8CD89Ea1...417Ca34E3
0.00183381 ETH
4270044652026-01-31 2:30:595 hrs ago1769826659
0x8CD89Ea1...417Ca34E3
0.00693875 ETH
View All Internal Transactions

Cross-Chain Transactions
Loading...
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
AcrossFacetPackedV4

Compiler Version
v0.8.17+commit.8df45f5f

Optimization Enabled:
Yes with 1000000 runs

Other Settings:
london EvmVersion
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity ^0.8.17;

import { IAcrossSpokePoolV4 } from "../Interfaces/IAcrossSpokePoolV4.sol";
import { TransferrableOwnership } from "../Helpers/TransferrableOwnership.sol";
import { AcrossFacetV4 } from "./AcrossFacetV4.sol";
import { ILiFi } from "../Interfaces/ILiFi.sol";
import { LibAsset, IERC20 } from "../Libraries/LibAsset.sol";
import { InvalidConfig } from "../Errors/GenericErrors.sol";
import { LiFiData } from "../Helpers/LiFiData.sol";

/// @title AcrossFacetPackedV4
/// @author LI.FI (https://li.fi)
/// @notice Provides functionality for bridging through Across in a gas-optimized way
/// @dev This packed implementation prioritizes gas optimization over runtime validation.
///      Critical parameters like refund addresses are not validated to minimize gas costs.
///      Callers must ensure valid parameters to avoid potential loss of funds.
///      For more validation and safety, use the non-packed AcrossFacetV4 via LiFiDiamond.
/// @custom:version 1.0.0
contract AcrossFacetPackedV4 is ILiFi, TransferrableOwnership, LiFiData {
    /// Storage ///

    /// @notice The contract address of the across spokepool on the source chain.
    IAcrossSpokePoolV4 public immutable SPOKEPOOL;

    /// @notice The WETH address on the current chain.
    bytes32 public immutable WRAPPED_NATIVE;

    /// Events ///

    event LiFiAcrossTransfer(bytes8 _transactionId);
    event CallExecutedAndFundsWithdrawn();

    /// Errors ///

    error WithdrawFailed();

    error InvalidInputAmount();
    error InvalidCalldataLength();

    // using this struct to bundle parameters is required since otherwise we run into stack-too-deep errors
    // (Solidity can only handle a limited amount of parameters at any given time)
    struct PackedParameters {
        bytes8 transactionId;
        bytes32 receiver;
        bytes32 depositor; // also acts as refund address in case release tx cannot be executed
        uint64 destinationChainId;
        bytes32 receivingAssetId;
        uint256 outputAmount;
        bytes32 exclusiveRelayer;
        uint32 quoteTimestamp;
        uint32 fillDeadline;
        uint32 exclusivityParameter;
        bytes message;
    }

    /// Constructor ///

    /// @notice Initialize the contract
    /// @param _spokePool The contract address of the spoke pool on the source chain
    /// @param _wrappedNative The address of the wrapped native token on the source chain
    /// @param _owner The address of the contract owner
    constructor(
        IAcrossSpokePoolV4 _spokePool,
        bytes32 _wrappedNative,
        address _owner
    ) TransferrableOwnership(_owner) {
        if (
            address(_spokePool) == address(0) ||
            _wrappedNative == bytes32(0) ||
            _owner == address(0)
        ) {
            revert InvalidConfig();
        }

        SPOKEPOOL = _spokePool;
        WRAPPED_NATIVE = _wrappedNative;
    }

    /// External Methods ///

    /// @dev Only meant to be called outside of the context of the diamond
    /// @notice Sets approval for the Across spoke pool Router to spend the specified token
    /// @param tokensToApprove The tokens to approve to the Across spoke pool
    function setApprovalForBridge(
        address[] calldata tokensToApprove
    ) external onlyOwner {
        for (uint256 i; i < tokensToApprove.length; i++) {
            // Give Across spoke pool approval to pull tokens from this facet
            LibAsset.maxApproveERC20(
                IERC20(tokensToApprove[i]),
                address(SPOKEPOOL),
                type(uint256).max
            );
        }
    }

    /// @notice Bridges native tokens via Across (packed implementation)
    /// @dev Calldata mapping:
    /// [0:4] - function selector
    /// [4:12] - transactionId (bytes8)
    /// [12:44] - depositor (also acts as refund address in case release tx cannot be executed)
    /// [44:76] - receiver (bytes32)
    /// [76:108] - receivingAssetId (bytes32) - the token to receive on destination chain
    /// [108:140] - outputAmount (uint256) - amount to receive on destination chain
    /// [140:148] - destinationChainId (uint64) - 8 bytes to support large chain IDs like Solana
    /// [148:180] - exclusiveRelayer (bytes32)
    /// [180:184] - quoteTimestamp (uint32)
    /// [184:188] - fillDeadline (uint32)
    /// [188:192] - exclusivityParameter (uint32)
    /// [192:] - message
    /// @dev NOTE: This packed implementation prioritizes gas optimization over runtime validation.
    ///      The depositor parameter (refund address) is not validated to be non-zero.
    ///      Callers must ensure valid parameters to avoid potential loss of funds.
    ///      For full validation, use the non-packed AcrossFacetV4 implementation.
    ///      IMPORTANT: For native transfers, inputToken is always WRAPPED_NATIVE and inputAmount is always msg.value.
    ///      These values are NOT read from calldata but are hardcoded/hardwired for gas optimization.
    ///      The calldata structure has been optimized to remove unnecessary sendingAssetId parameter.
    function startBridgeTokensViaAcrossV4NativePacked() external payable {
        // call Across spoke pool to bridge assets
        SPOKEPOOL.deposit{ value: msg.value }(
            bytes32(msg.data[12:44]), // depositor (refund address)
            bytes32(msg.data[44:76]), // recipient (on destination chain)
            WRAPPED_NATIVE, // inputToken (HARDCODED - always wrapped native, not from calldata)
            bytes32(msg.data[76:108]), // receivingAssetId (token to receive on destination)
            msg.value, // inputAmount (HARDCODED - always msg.value, not from calldata)
            uint256(bytes32(msg.data[108:140])), // outputAmount (amount to receive on destination)
            uint64(bytes8(msg.data[140:148])), // destinationChainId (8 bytes to support large chain IDs)
            bytes32(msg.data[148:180]), // exclusiveRelayer
            uint32(bytes4(msg.data[180:184])), // quoteTimestamp
            uint32(bytes4(msg.data[184:188])), // fillDeadline
            uint32(bytes4(msg.data[188:192])), // exclusivityParameter
            msg.data[192:msg.data.length] // message
        );

        emit LiFiAcrossTransfer(bytes8(msg.data[4:12]));
    }

    /// @notice Bridges native tokens via Across (minimal implementation)
    /// @param _parameters Contains all parameters required for native bridging with AcrossV4
    /// @dev NOTE: This minimal implementation prioritizes gas optimization over runtime validation.
    ///      The depositor parameter (refund address) is not validated to be non-zero.
    ///      Callers must ensure valid parameters to avoid potential loss of funds.
    ///      For full validation, use the non-packed AcrossFacetV4 implementation.
    function startBridgeTokensViaAcrossV4NativeMin(
        PackedParameters calldata _parameters
    ) external payable {
        // call Across spoke pool to bridge assets
        SPOKEPOOL.deposit{ value: msg.value }(
            _parameters.depositor, // depositor
            _parameters.receiver,
            WRAPPED_NATIVE, // inputToken
            _parameters.receivingAssetId, // outputToken
            msg.value, // inputAmount
            _parameters.outputAmount,
            _parameters.destinationChainId,
            _parameters.exclusiveRelayer,
            _parameters.quoteTimestamp,
            _parameters.fillDeadline,
            _parameters.exclusivityParameter,
            _parameters.message
        );

        emit LiFiAcrossTransfer(_parameters.transactionId);
    }

    /// @notice Bridges ERC20 tokens via Across (packed implementation)
    /// @dev Calldata mapping:
    /// [0:4] - function selector
    /// [4:12] - transactionId (bytes8)
    /// [12:44] - depositor (also acts as refund address in case release tx cannot be executed)
    /// [44:76] - receiver (bytes32)
    /// [76:108] - sendingAssetId (bytes32) - the token to be bridged
    /// [108:140] - receivingAssetId (bytes32) - the token to receive on destination chain
    /// [140:156] - inputAmount (uint128) - amount to be bridged (including fees)
    /// [156:188] - outputAmount (uint256) - amount to receive on destination chain
    /// [188:196] - destinationChainId (uint64) - 8 bytes to support large chain IDs like Solana
    /// [196:228] - exclusiveRelayer (bytes32)
    /// [228:232] - quoteTimestamp (uint32)
    /// [232:236] - fillDeadline (uint32)
    /// [236:240] - exclusivityParameter (uint32)
    /// [240:] - message
    /// @dev NOTE: This packed implementation prioritizes gas optimization over runtime validation.
    ///      The depositor parameter (refund address) is not validated to be non-zero.
    ///      Callers must ensure valid parameters to avoid potential loss of funds.
    ///      For full validation, use the non-packed AcrossFacetV4 implementation.
    function startBridgeTokensViaAcrossV4ERC20Packed() external {
        bytes32 sendingAssetId = bytes32(msg.data[76:108]);
        uint256 inputAmount = uint256(uint128(bytes16(msg.data[140:156])));

        // pull tokens from msg.sender
        LibAsset.transferFromERC20(
            address(uint160(uint256(sendingAssetId))),
            msg.sender,
            address(this),
            inputAmount
        );

        SPOKEPOOL.deposit(
            bytes32(msg.data[12:44]), // depositor
            bytes32(msg.data[44:76]), // recipient
            sendingAssetId, // inputToken
            bytes32(msg.data[108:140]), // outputToken (receivingAssetId)
            inputAmount, // inputAmount
            uint256(bytes32(msg.data[156:188])), // outputAmount
            uint64(bytes8(msg.data[188:196])), // destinationChainId
            bytes32(msg.data[196:228]), // exclusiveRelayer
            uint32(bytes4(msg.data[228:232])), // quoteTimestamp
            uint32(bytes4(msg.data[232:236])), // fillDeadline
            uint32(bytes4(msg.data[236:240])), // exclusivityParameter
            msg.data[240:msg.data.length]
        );

        emit LiFiAcrossTransfer(bytes8(msg.data[4:12]));
    }

    /// @notice Bridges ERC20 tokens via Across (minimal implementation)
    /// @param _parameters Contains all base parameters required for bridging with AcrossV4
    /// @param sendingAssetId The address of the asset/token to be bridged
    /// @param inputAmount The amount to be bridged (including fees)
    /// @dev NOTE: This minimal implementation prioritizes gas optimization over runtime validation.
    ///      The depositor parameter (refund address) is not validated to be non-zero.
    ///      Callers must ensure valid parameters to avoid potential loss of funds.
    ///      For full validation, use the non-packed AcrossFacetV4 implementation.
    function startBridgeTokensViaAcrossV4ERC20Min(
        PackedParameters calldata _parameters,
        bytes32 sendingAssetId,
        uint256 inputAmount
    ) external {
        // Deposit assets
        LibAsset.transferFromERC20(
            address(uint160(uint256(sendingAssetId))),
            msg.sender,
            address(this),
            inputAmount
        );

        // call Across SpokePool
        SPOKEPOOL.deposit(
            _parameters.depositor, // depositor
            _parameters.receiver,
            sendingAssetId, // inputToken
            _parameters.receivingAssetId, // outputToken
            inputAmount,
            _parameters.outputAmount,
            _parameters.destinationChainId,
            _parameters.exclusiveRelayer,
            _parameters.quoteTimestamp,
            _parameters.fillDeadline,
            _parameters.exclusivityParameter,
            _parameters.message
        );

        emit LiFiAcrossTransfer(_parameters.transactionId);
    }

    /// @notice Encodes calldata that can be used to call the native 'packed' function
    /// @param _parameters Contains all parameters required for native bridging with AcrossV4
    function encode_startBridgeTokensViaAcrossV4NativePacked(
        PackedParameters calldata _parameters
    ) external pure returns (bytes memory) {
        return
            bytes.concat(
                AcrossFacetPackedV4
                    .startBridgeTokensViaAcrossV4NativePacked
                    .selector,
                _parameters.transactionId,
                _parameters.depositor,
                _parameters.receiver,
                _parameters.receivingAssetId,
                bytes32(_parameters.outputAmount),
                bytes8(_parameters.destinationChainId),
                _parameters.exclusiveRelayer,
                bytes4(_parameters.quoteTimestamp),
                bytes4(_parameters.fillDeadline),
                bytes4(_parameters.exclusivityParameter),
                _parameters.message
            );
    }

    /// @notice Encodes calldata that can be used to call the ERC20 'packed' function
    /// @dev Calldata mapping:
    /// [0:4] - function selector
    /// [4:12] - transactionId (bytes8)
    /// [12:44] - depositor (also acts as refund address in case release tx cannot be executed)
    /// [44:76] - receiver (bytes32)
    /// [76:108] - sendingAssetId (bytes32) - the token to be bridged
    /// [108:140] - receivingAssetId (bytes32) - the token to receive on destination chain
    /// [140:156] - inputAmount (uint128) - amount to be bridged (including fees)
    /// [156:188] - outputAmount (uint256) - amount to receive on destination chain
    /// [188:196] - destinationChainId (uint64) - 8 bytes to support large chain IDs like Solana
    /// [196:228] - exclusiveRelayer (bytes32)
    /// [228:232] - quoteTimestamp (uint32)
    /// [232:236] - fillDeadline (uint32)
    /// [236:240] - exclusivityParameter (uint32)
    /// [240:] - message
    /// @param _parameters Contains all base parameters required for bridging with AcrossV4
    /// @param sendingAssetId The address of the asset/token to be bridged
    /// @param inputAmount The amount to be bridged (including fees)
    function encode_startBridgeTokensViaAcrossV4ERC20Packed(
        PackedParameters calldata _parameters,
        bytes32 sendingAssetId,
        uint256 inputAmount
    ) external pure returns (bytes memory) {
        if (inputAmount > type(uint128).max) {
            revert InvalidInputAmount();
        }

        // Split the concatenation into parts to avoid "stack too deep" errors
        bytes memory part1 = bytes.concat(
            AcrossFacetPackedV4
                .startBridgeTokensViaAcrossV4ERC20Packed
                .selector,
            _parameters.transactionId,
            _parameters.depositor,
            _parameters.receiver,
            bytes32(sendingAssetId)
        );

        bytes memory part2 = bytes.concat(
            _parameters.receivingAssetId,
            bytes16(uint128(inputAmount)),
            bytes32(_parameters.outputAmount),
            bytes8(_parameters.destinationChainId)
        );

        bytes memory part3 = bytes.concat(
            _parameters.exclusiveRelayer,
            bytes4(_parameters.quoteTimestamp),
            bytes4(_parameters.fillDeadline),
            bytes4(_parameters.exclusivityParameter)
        );

        // Combine all parts with the message
        return bytes.concat(part1, part2, part3, _parameters.message);
    }

    /// @notice Decodes calldata that is meant to be used for calling the native 'packed' function
    /// @param data the calldata to be decoded
    function decode_startBridgeTokensViaAcrossV4NativePacked(
        bytes calldata data
    )
        external
        pure
        returns (
            ILiFi.BridgeData memory bridgeData,
            AcrossFacetV4.AcrossV4Data memory acrossData
        )
    {
        // ensure minimum length (without message): 192
        if (data.length < 192) {
            revert InvalidCalldataLength();
        }

        // extract bridgeData
        bridgeData.transactionId = bytes32(data[4:12]);
        // Check if receiver is EVM address (20 bytes) or non-EVM (longer)
        // If the first 12 bytes are zero, it's likely an EVM address
        if (bytes12(data[44:56]) == bytes12(0)) {
            bridgeData.receiver = address(
                uint160(uint256(bytes32(data[44:76])))
            );
        } else {
            bridgeData.receiver = NON_EVM_ADDRESS;
        }
        bridgeData.destinationChainId = uint64(bytes8(data[140:148]));

        // extract acrossData
        acrossData.receiverAddress = bytes32(data[44:76]);
        acrossData.refundAddress = bytes32(data[12:44]);
        acrossData.sendingAssetId = bytes32(0);
        acrossData.receivingAssetId = bytes32(data[76:108]);
        acrossData.outputAmount = uint256(bytes32(data[108:140]));
        acrossData.exclusiveRelayer = bytes32(data[148:180]);
        acrossData.quoteTimestamp = uint32(bytes4(data[180:184]));
        acrossData.fillDeadline = uint32(bytes4(data[184:188]));
        acrossData.exclusivityParameter = uint32(bytes4(data[188:192]));
        acrossData.message = data[192:];

        return (bridgeData, acrossData);
    }

    /// @notice Decodes calldata that is meant to be used for calling the ERC20 'packed' function
    /// @param data the calldata to be decoded
    function decode_startBridgeTokensViaAcrossV4ERC20Packed(
        bytes calldata data
    )
        external
        pure
        returns (
            ILiFi.BridgeData memory bridgeData,
            AcrossFacetV4.AcrossV4Data memory acrossData
        )
    {
        // ensure minimum length (without message): 240
        if (data.length < 240) {
            revert InvalidCalldataLength();
        }

        bridgeData.transactionId = bytes32(data[4:12]); // we truncate intentionally to save gas (not dangerous)
        bridgeData.sendingAssetId = address(
            uint160(uint256(bytes32(data[76:108])))
        ); // sendingAssetId
        // Check if receiver is EVM address (20 bytes) or non-EVM (longer)
        // If the first 12 bytes are zero, it's likely an EVM address
        if (bytes12(data[44:56]) == bytes12(0)) {
            bridgeData.receiver = address(
                uint160(uint256(bytes32(data[44:76])))
            );
        } else {
            bridgeData.receiver = NON_EVM_ADDRESS;
        }
        bridgeData.minAmount = uint256(uint128(bytes16(data[140:156])));
        bridgeData.destinationChainId = uint64(bytes8(data[188:196]));

        acrossData.receiverAddress = bytes32(data[44:76]);
        acrossData.refundAddress = bytes32(data[12:44]);
        acrossData.sendingAssetId = bytes32(data[76:108]);
        acrossData.receivingAssetId = bytes32(data[108:140]);
        acrossData.outputAmount = uint256(bytes32(data[156:188]));
        acrossData.exclusiveRelayer = bytes32(data[196:228]);
        acrossData.quoteTimestamp = uint32(bytes4(data[228:232]));
        acrossData.fillDeadline = uint32(bytes4(data[232:236]));
        acrossData.exclusivityParameter = uint32(bytes4(data[236:240])); // exclusivityParameter
        acrossData.message = data[240:]; // message

        return (bridgeData, acrossData);
    }

    /// @notice Execute calldata and withdraw asset
    /// @param _callTo The address to execute the calldata on
    /// @param _callData The data to execute
    /// @param _assetAddress Asset to be withdrawn
    /// @param _to address to withdraw to
    /// @param _amount amount of asset to withdraw
    function executeCallAndWithdraw(
        address _callTo,
        bytes calldata _callData,
        address _assetAddress,
        address _to,
        uint256 _amount
    ) external onlyOwner {
        // execute calldata
        // solhint-disable-next-line avoid-low-level-calls
        (bool success, ) = _callTo.call(_callData);

        // check success of call
        if (success) {
            // call successful - withdraw the asset
            LibAsset.transferAsset(_assetAddress, payable(_to), _amount);

            emit CallExecutedAndFundsWithdrawn();
        } else {
            // call unsuccessful - revert
            revert WithdrawFailed();
        }
    }
}

File 2 of 18 : IAcrossSpokePoolV4.sol
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity ^0.8.17;

/// @title IAcrossSpokePoolV4
/// @notice Interface for interacting with Across Protocol V4 Spoke Pool
/// @author LI.FI (https://li.fi)
/// @custom:version 1.0.0
interface IAcrossSpokePoolV4 {
    /// @notice Initiates a cross-chain token transfer via Across Protocol V4
    /// @dev This function allows users to deposit tokens on the origin chain for bridging to a destination chain.
    ///      The function supports both EVM and non-EVM chains through the use of bytes32 addresses.
    ///      The deposit can be filled by relayers on the destination chain within the specified deadlines.
    /// @param depositor The address that made the deposit on the origin chain (bytes32 format for cross-chain compatibility)
    /// @param recipient The recipient address on the destination chain (bytes32 format for cross-chain compatibility)
    /// @param inputToken The token address that is deposited on the origin chain by the depositor (bytes32 format)
    /// @param outputToken The token address that will be received on the destination chain by the recipient (bytes32 format)
    /// @param inputAmount The amount of input token deposited by the depositor on the origin chain
    /// @param outputAmount The amount of output token to be received by the recipient on the destination chain (after fees)
    /// @param destinationChainId The chain ID of the destination chain where the tokens will be received
    /// @param exclusiveRelayer The exclusive relayer address who can fill the deposit before the exclusivity deadline.
    ///                         Set to zero bytes32 if no exclusive relayer is specified
    /// @param quoteTimestamp The timestamp when the quote was created, used for fee calculation and validation
    /// @param fillDeadline The timestamp on the destination chain after which this deposit can no longer be filled by any relayer
    /// @param exclusivityParameter This value is used to set the exclusivity deadline timestamp in the emitted deposit
    ///                           event. Before this destination chain timestamp, only the exclusiveRelayer (if set to a non-zero address),
    ///                           can fill this deposit. There are three ways to use this parameter:
    ///                           1. NO EXCLUSIVITY: If this value is set to 0, then a timestamp of 0 will be emitted,
    ///                              meaning that there is no exclusivity period.
    ///                           2. OFFSET: If this value is less than MAX_EXCLUSIVITY_PERIOD_SECONDS, then add this value to
    ///                              the block.timestamp to derive the exclusive relayer deadline.
    ///                           3. TIMESTAMP: Otherwise, set this value as the exclusivity deadline timestamp.
    /// @param message Arbitrary data that can be used to pass additional information to the recipient along with the tokens.
    ///                This can include swap instructions, destination call data, or other cross-chain messages
    function deposit(
        bytes32 depositor,
        bytes32 recipient,
        bytes32 inputToken,
        bytes32 outputToken,
        uint256 inputAmount,
        uint256 outputAmount,
        uint256 destinationChainId,
        bytes32 exclusiveRelayer,
        uint32 quoteTimestamp,
        uint32 fillDeadline,
        uint32 exclusivityParameter,
        bytes calldata message
    ) external payable;
}

// SPDX-License-Identifier: LGPL-3.0-only
/// @custom:version 1.0.0
pragma solidity ^0.8.17;

import { IERC173 } from "../Interfaces/IERC173.sol";
import { LibAsset } from "../Libraries/LibAsset.sol";

contract TransferrableOwnership is IERC173 {
    address public owner;
    address public pendingOwner;

    /// Errors ///
    error UnAuthorized();
    error NoNullOwner();
    error NewOwnerMustNotBeSelf();
    error NoPendingOwnershipTransfer();
    error NotPendingOwner();

    /// Events ///
    event OwnershipTransferRequested(
        address indexed _from,
        address indexed _to
    );

    constructor(address initialOwner) {
        owner = initialOwner;
    }

    modifier onlyOwner() {
        if (msg.sender != owner) revert UnAuthorized();
        _;
    }

    /// @notice Initiates transfer of ownership to a new address
    /// @param _newOwner the address to transfer ownership to
    function transferOwnership(address _newOwner) external onlyOwner {
        if (_newOwner == LibAsset.NULL_ADDRESS) revert NoNullOwner();
        if (_newOwner == msg.sender) revert NewOwnerMustNotBeSelf();
        pendingOwner = _newOwner;
        emit OwnershipTransferRequested(msg.sender, pendingOwner);
    }

    /// @notice Cancel transfer of ownership
    function cancelOwnershipTransfer() external onlyOwner {
        if (pendingOwner == LibAsset.NULL_ADDRESS)
            revert NoPendingOwnershipTransfer();
        pendingOwner = LibAsset.NULL_ADDRESS;
    }

    /// @notice Confirms transfer of ownership to the calling address (msg.sender)
    function confirmOwnershipTransfer() external {
        address _pendingOwner = pendingOwner;
        if (msg.sender != _pendingOwner) revert NotPendingOwner();
        emit OwnershipTransferred(owner, _pendingOwner);
        owner = _pendingOwner;
        pendingOwner = LibAsset.NULL_ADDRESS;
    }
}

// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity ^0.8.17;

import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { ILiFi } from "../Interfaces/ILiFi.sol";
import { IAcrossSpokePoolV4 } from "../Interfaces/IAcrossSpokePoolV4.sol";
import { LibAsset } from "../Libraries/LibAsset.sol";
import { LibSwap } from "../Libraries/LibSwap.sol";
import { ReentrancyGuard } from "../Helpers/ReentrancyGuard.sol";
import { SwapperV2 } from "../Helpers/SwapperV2.sol";
import { Validatable } from "../Helpers/Validatable.sol";
import { InformationMismatch, InvalidNonEVMReceiver, InvalidReceiver, InvalidConfig, InvalidCallData } from "../Errors/GenericErrors.sol";
import { LiFiData } from "../Helpers/LiFiData.sol";

/// @title AcrossFacetV4
/// @author LI.FI (https://li.fi)
/// @notice Provides functionality for bridging through Across Protocol
/// @custom:version 1.0.0
contract AcrossFacetV4 is
    ILiFi,
    ReentrancyGuard,
    SwapperV2,
    Validatable,
    LiFiData
{
    /// Storage ///

    /// @notice The contract address of the spoke pool on the source chain.
    IAcrossSpokePoolV4 public immutable SPOKEPOOL;

    /// @notice The WETH address on the current chain.
    bytes32 public immutable WRAPPED_NATIVE;

    /// @notice The Across custom chain ID for Solana
    uint256 public constant ACROSS_CHAIN_ID_SOLANA = 34268394551451;

    /// @notice The base for the outputAmountMultiplier (to allow room for adjustments in both directions)
    uint256 public constant MULTIPLIER_BASE = 1e18;

    /// Types ///

    /// @param receiverAddress The address that will receive the token on dst chain
    ///                        (our Receiver contract or the user-defined receiver address)
    /// @param refundAddress The address that will be used for potential bridge refunds
    /// @param sendingAssetId The address of the token to be sent from source chain
    /// @param receivingAssetId The address of the token to be received at destination chain
    /// @param outputAmount The amount to be received at destination chain (after fees)
    /// @param outputAmountMultiplier In case of pre-bridge swaps we need to adjust the output amount
    /// @param exclusiveRelayer This is the exclusive relayer who can fill the deposit before the exclusivity deadline.
    /// @param quoteTimestamp The timestamp of the Across quote that was used for this transaction
    /// @param fillDeadline The destination chain timestamp until which the order can be filled
    /// @param exclusivityParameter This value is used to set the exclusivity deadline timestamp in the emitted deposit
    ///                           event. Before this destination chain timestamp, only the exclusiveRelayer (if set to a non-zero address),
    ///                           can fill this deposit. There are three ways to use this parameter:
    ///                           1. NO EXCLUSIVITY: If this value is set to 0, then a timestamp of 0 will be emitted,
    ///                              meaning that there is no exclusivity period.
    ///                           2. OFFSET: If this value is less than MAX_EXCLUSIVITY_PERIOD_SECONDS, then add this value to
    ///                              the block.timestamp to derive the exclusive relayer deadline.
    ///                           3. TIMESTAMP: Otherwise, set this value as the exclusivity deadline timestamp.
    /// @param message Arbitrary data that can be used to pass additional information to the recipient along with the tokens
    struct AcrossV4Data {
        bytes32 receiverAddress;
        bytes32 refundAddress;
        bytes32 sendingAssetId;
        bytes32 receivingAssetId;
        uint256 outputAmount;
        uint128 outputAmountMultiplier;
        bytes32 exclusiveRelayer;
        uint32 quoteTimestamp;
        uint32 fillDeadline;
        uint32 exclusivityParameter;
        bytes message;
    }

    /// Constructor ///

    /// @notice Initialize the contract.
    /// @param _spokePool The contract address of the spoke pool on the source chain.
    /// @param _wrappedNative The address of the wrapped native token on the source chain.
    constructor(IAcrossSpokePoolV4 _spokePool, bytes32 _wrappedNative) {
        if (
            address(_spokePool) == address(0) || _wrappedNative == bytes32(0)
        ) {
            revert InvalidConfig();
        }

        SPOKEPOOL = _spokePool;
        WRAPPED_NATIVE = _wrappedNative;
    }

    /// External Methods ///

    /// @notice Bridges tokens via Across
    /// @param _bridgeData the core information needed for bridging
    /// @param _acrossData data specific to Across
    function startBridgeTokensViaAcrossV4(
        ILiFi.BridgeData memory _bridgeData,
        AcrossV4Data calldata _acrossData
    )
        external
        payable
        nonReentrant
        refundExcessNative(payable(msg.sender))
        validateBridgeData(_bridgeData)
        doesNotContainSourceSwaps(_bridgeData)
    {
        LibAsset.depositAsset(
            _bridgeData.sendingAssetId,
            _bridgeData.minAmount
        );
        _startBridge(_bridgeData, _acrossData);
    }

    /// @notice Performs a swap before bridging via Across
    /// @param _bridgeData the core information needed for bridging
    /// @param _swapData an array of swap related data for performing swaps before bridging
    /// @param _acrossData data specific to Across
    function swapAndStartBridgeTokensViaAcrossV4(
        ILiFi.BridgeData memory _bridgeData,
        LibSwap.SwapData[] calldata _swapData,
        AcrossV4Data calldata _acrossData
    )
        external
        payable
        nonReentrant
        refundExcessNative(payable(msg.sender))
        containsSourceSwaps(_bridgeData)
        validateBridgeData(_bridgeData)
    {
        _bridgeData.minAmount = _depositAndSwap(
            _bridgeData.transactionId,
            _bridgeData.minAmount,
            _swapData,
            payable(msg.sender)
        );

        // Since the minAmount / inputAmount was updated, we also need to adjust the outputAmount.
        // In case any of different decimals between input and output, we will adjust the outputAmount
        // with the outputAmountMultiplier to account for the difference in decimals. We divide by 1e18
        // to allow room for adjustment in both directions, i.e. from 6 > 18 decimals and vice versa.
        // The multiplier should be calculated as:  multiplierPercentage * 1e18 * 10^(outputDecimals - inputDecimals)
        // NOTE: please note that we intentionally do not verify the outputAmount any further. Only use LI.FI backend-
        //       generated calldata to avoid potential loss of funds.
        AcrossV4Data memory modifiedAcrossData = _acrossData;
        modifiedAcrossData.outputAmount =
            (_bridgeData.minAmount * _acrossData.outputAmountMultiplier) /
            MULTIPLIER_BASE;

        _startBridge(_bridgeData, modifiedAcrossData);
    }

    /// Internal Methods ///

    /// @dev Contains the business logic for the bridge via Across
    /// @param _bridgeData the core information needed for bridging
    /// @param _acrossData data specific to Across
    function _startBridge(
        ILiFi.BridgeData memory _bridgeData,
        AcrossV4Data memory _acrossData
    ) internal {
        // validate destination call flag
        if (_acrossData.message.length > 0 != _bridgeData.hasDestinationCall) {
            revert InformationMismatch();
        }

        // get across (custom) destination chain id, if applicable
        uint256 destinationChainId = _getAcrossChainId(
            _bridgeData.destinationChainId
        );

        // validate receiver address
        if (_bridgeData.receiver == NON_EVM_ADDRESS) {
            // destination chain is non-EVM
            // make sure it's non-zero (we cannot validate further)
            if (_acrossData.receiverAddress == bytes32(0)) {
                revert InvalidNonEVMReceiver();
            }

            // emit event for non-EVM chain
            emit BridgeToNonEVMChainBytes32(
                _bridgeData.transactionId,
                _bridgeData.destinationChainId,
                _acrossData.receiverAddress
            );
        } else {
            // destination chain is EVM
            // make sure that bridgeData and acrossData receiver addresses match, but only
            // if there is no destination call, cause in case of destination call the receiver
            // address is the our receiver contract address and not the user-defined receiver address
            if (
                !_bridgeData.hasDestinationCall &&
                _convertAddressToBytes32(_bridgeData.receiver) !=
                _acrossData.receiverAddress
            ) revert InvalidReceiver();

            if (_acrossData.receiverAddress == bytes32(0)) {
                revert InvalidReceiver();
            }
        }

        // validate refund address to prevent lost funds
        if (_acrossData.refundAddress == bytes32(0)) {
            revert InvalidCallData();
        }

        // check if sendingAsset is native or ERC20
        if (LibAsset.isNativeAsset(_bridgeData.sendingAssetId)) {
            // NATIVE
            SPOKEPOOL.deposit{ value: _bridgeData.minAmount }(
                _acrossData.refundAddress, // depositor (also acts as refund address in case release tx cannot be executed)
                _acrossData.receiverAddress, // recipient (on dst)
                WRAPPED_NATIVE, // inputToken
                _acrossData.receivingAssetId, // outputToken
                _bridgeData.minAmount, // inputAmount
                _acrossData.outputAmount, // outputAmount
                destinationChainId, // destinationChainId
                _acrossData.exclusiveRelayer, // exclusiveRelayer
                _acrossData.quoteTimestamp, // quoteTimestamp
                _acrossData.fillDeadline, // fillDeadline
                _acrossData.exclusivityParameter, // exclusivityParameter
                _acrossData.message // message
            );
        } else {
            // ERC20
            LibAsset.maxApproveERC20(
                IERC20(_bridgeData.sendingAssetId),
                address(SPOKEPOOL),
                _bridgeData.minAmount
            );
            SPOKEPOOL.deposit(
                _acrossData.refundAddress, // depositor (also acts as refund address in case release tx cannot be executed)
                _acrossData.receiverAddress, // recipient (on dst)
                _acrossData.sendingAssetId, // inputToken (now from acrossData)
                _acrossData.receivingAssetId, // outputToken
                _bridgeData.minAmount, // inputAmount
                _acrossData.outputAmount, // outputAmount
                destinationChainId, // destinationChainId
                _acrossData.exclusiveRelayer, // exclusiveRelayer
                _acrossData.quoteTimestamp, // quoteTimestamp
                _acrossData.fillDeadline, // fillDeadline
                _acrossData.exclusivityParameter, // exclusivityParameter
                _acrossData.message // message
            );
        }

        emit LiFiTransferStarted(_bridgeData);
    }

    /// @notice Converts LiFi internal (non-EVM) chain IDs to Across chain IDs
    ///         For EVM chainIds there is no need to convert, they will just returned as-is
    /// @param _destinationChainId The LiFi chain ID to convert
    function _getAcrossChainId(
        uint256 _destinationChainId
    ) internal pure returns (uint256) {
        // currently only Solana has a custom chainId
        if (_destinationChainId == LIFI_CHAIN_ID_SOLANA) {
            return ACROSS_CHAIN_ID_SOLANA;
        } else {
            return _destinationChainId;
        }
    }

    /// @notice Converts an address to a bytes32
    /// @param _address The address to convert
    function _convertAddressToBytes32(
        address _address
    ) internal pure returns (bytes32) {
        return bytes32(uint256(uint160(_address)));
    }
}

File 5 of 18 : ILiFi.sol
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity ^0.8.17;

/// @title ILiFi
/// @author LI.FI (https://li.fi)
/// @custom:version 1.0.1
interface ILiFi {
    /// Structs ///

    struct BridgeData {
        bytes32 transactionId;
        string bridge;
        string integrator;
        address referrer;
        address sendingAssetId;
        address receiver;
        uint256 minAmount;
        uint256 destinationChainId;
        bool hasSourceSwaps;
        bool hasDestinationCall;
    }

    /// Events ///

    event LiFiTransferStarted(ILiFi.BridgeData bridgeData);

    event LiFiTransferCompleted(
        bytes32 indexed transactionId,
        address receivingAssetId,
        address receiver,
        uint256 amount,
        uint256 timestamp
    );

    event LiFiTransferRecovered(
        bytes32 indexed transactionId,
        address receivingAssetId,
        address receiver,
        uint256 amount,
        uint256 timestamp
    );

    event LiFiGenericSwapCompleted(
        bytes32 indexed transactionId,
        string integrator,
        string referrer,
        address receiver,
        address fromAssetId,
        address toAssetId,
        uint256 fromAmount,
        uint256 toAmount
    );

    // this event is emitted when a bridge transction is initiated to a non-EVM chain
    event BridgeToNonEVMChain(
        bytes32 indexed transactionId,
        uint256 indexed destinationChainId,
        bytes receiver
    );
    event BridgeToNonEVMChainBytes32(
        bytes32 indexed transactionId,
        uint256 indexed destinationChainId,
        bytes32 receiver
    );

    // Deprecated but kept here to include in ABI to parse historic events
    event LiFiSwappedGeneric(
        bytes32 indexed transactionId,
        string integrator,
        string referrer,
        address fromAssetId,
        address toAssetId,
        uint256 fromAmount,
        uint256 toAmount
    );
}

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.17;

import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { LibSwap } from "./LibSwap.sol";
import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol";

// solhint-disable-next-line max-line-length
import { InvalidReceiver, NullAddrIsNotAValidSpender, InvalidAmount, NullAddrIsNotAnERC20Token } from "../Errors/GenericErrors.sol";

/// @title LibAsset
/// @author LI.FI (https://li.fi)
/// @custom:version 2.1.2
/// @notice This library contains helpers for dealing with onchain transfers
///         of assets, including accounting for the native asset `assetId`
///         conventions and any noncompliant ERC20 transfers
library LibAsset {
    using SafeTransferLib for address;
    using SafeTransferLib for address payable;

    /// @dev All native assets use the empty address for their asset id
    ///      by convention
    address internal constant NULL_ADDRESS = address(0);

    /// @dev EIP-7702 delegation designator prefix for Account Abstraction
    bytes3 internal constant DELEGATION_DESIGNATOR = 0xef0100;

    /// @notice Gets the balance of the inheriting contract for the given asset
    /// @param assetId The asset identifier to get the balance of
    /// @return Balance held by contracts using this library (returns 0 if assetId does not exist)
    function getOwnBalance(address assetId) internal view returns (uint256) {
        return
            isNativeAsset(assetId)
                ? address(this).balance
                : assetId.balanceOf(address(this));
    }

    /// @notice Wrapper function to transfer a given asset (native or erc20) to
    ///         some recipient. Should handle all non-compliant return value
    ///         tokens as well by using the SafeERC20 contract by open zeppelin.
    /// @param assetId Asset id for transfer (address(0) for native asset,
    ///                token address for erc20s)
    /// @param recipient Address to send asset to
    /// @param amount Amount to send to given recipient
    function transferAsset(
        address assetId,
        address payable recipient,
        uint256 amount
    ) internal {
        if (isNativeAsset(assetId)) {
            transferNativeAsset(recipient, amount);
        } else {
            transferERC20(assetId, recipient, amount);
        }
    }

    /// @notice Transfers ether from the inheriting contract to a given
    ///         recipient
    /// @param recipient Address to send ether to
    /// @param amount Amount to send to given recipient
    function transferNativeAsset(
        address payable recipient,
        uint256 amount
    ) private {
        // make sure a meaningful receiver address was provided
        if (recipient == NULL_ADDRESS) revert InvalidReceiver();

        // transfer native asset (will revert if target reverts or contract has insufficient balance)
        recipient.safeTransferETH(amount);
    }

    /// @notice Transfers tokens from the inheriting contract to a given recipient
    /// @param assetId Token address to transfer
    /// @param recipient Address to send tokens to
    /// @param amount Amount to send to given recipient
    function transferERC20(
        address assetId,
        address recipient,
        uint256 amount
    ) internal {
        // make sure a meaningful receiver address was provided
        if (recipient == NULL_ADDRESS) {
            revert InvalidReceiver();
        }

        // transfer ERC20 assets (will revert if target reverts or contract has insufficient balance)
        assetId.safeTransfer(recipient, amount);
    }

    /// @notice Transfers tokens from a sender to a given recipient
    /// @param assetId Token address to transfer
    /// @param from Address of sender/owner
    /// @param recipient Address of recipient/spender
    /// @param amount Amount to transfer from owner to spender
    function transferFromERC20(
        address assetId,
        address from,
        address recipient,
        uint256 amount
    ) internal {
        // check if native asset
        if (isNativeAsset(assetId)) {
            revert NullAddrIsNotAnERC20Token();
        }

        // make sure a meaningful receiver address was provided
        if (recipient == NULL_ADDRESS) {
            revert InvalidReceiver();
        }

        // transfer ERC20 assets (will revert if target reverts or contract has insufficient balance)
        assetId.safeTransferFrom(from, recipient, amount);
    }

    /// @notice Pulls tokens from msg.sender
    /// @param assetId Token address to transfer
    /// @param amount Amount to transfer from owner
    function depositAsset(address assetId, uint256 amount) internal {
        // make sure a meaningful amount was provided
        if (amount == 0) revert InvalidAmount();

        // check if native asset
        if (isNativeAsset(assetId)) {
            // ensure msg.value is equal or greater than amount
            if (msg.value < amount) revert InvalidAmount();
        } else {
            // transfer ERC20 assets (will revert if target reverts or contract has insufficient balance)
            assetId.safeTransferFrom(msg.sender, address(this), amount);
        }
    }

    function depositAssets(LibSwap.SwapData[] calldata swaps) internal {
        for (uint256 i = 0; i < swaps.length; ) {
            LibSwap.SwapData calldata swap = swaps[i];
            if (swap.requiresDeposit) {
                depositAsset(swap.sendingAssetId, swap.fromAmount);
            }
            unchecked {
                i++;
            }
        }
    }

    /// @notice If the current allowance is insufficient, the allowance for a given spender
    ///         is set to MAX_UINT.
    /// @param assetId Token address to transfer
    /// @param spender Address to give spend approval to
    /// @param amount allowance amount required for current transaction
    function maxApproveERC20(
        IERC20 assetId,
        address spender,
        uint256 amount
    ) internal {
        approveERC20(assetId, spender, amount, type(uint256).max);
    }

    /// @notice If the current allowance is insufficient, the allowance for a given spender
    ///         is set to the amount provided
    /// @param assetId Token address to transfer
    /// @param spender Address to give spend approval to
    /// @param requiredAllowance Allowance required for current transaction
    /// @param setAllowanceTo The amount the allowance should be set to if current allowance is insufficient
    function approveERC20(
        IERC20 assetId,
        address spender,
        uint256 requiredAllowance,
        uint256 setAllowanceTo
    ) internal {
        if (isNativeAsset(address(assetId))) {
            return;
        }

        // make sure a meaningful spender address was provided
        if (spender == NULL_ADDRESS) {
            revert NullAddrIsNotAValidSpender();
        }

        // check if allowance is sufficient, otherwise set allowance to provided amount
        // If the initial attempt to approve fails, attempts to reset the approved amount to zero,
        // then retries the approval again (some tokens, e.g. USDT, requires this).
        // Reverts upon failure
        if (assetId.allowance(address(this), spender) < requiredAllowance) {
            address(assetId).safeApproveWithRetry(spender, setAllowanceTo);
        }
    }

    /// @notice Determines whether the given assetId is the native asset
    /// @param assetId The asset identifier to evaluate
    /// @return Boolean indicating if the asset is the native asset
    function isNativeAsset(address assetId) internal pure returns (bool) {
        return assetId == NULL_ADDRESS;
    }

    /// @notice Checks if the given address is a contract
    ///         Returns true for any account with runtime code (excluding EIP-7702 accounts).
    ///         For EIP-7702 accounts, checks if code size is exactly 23 bytes (delegation format).
    ///         Limitations:
    ///         - Cannot distinguish between EOA and self-destructed contract
    /// @param account The address to be checked
    function isContract(address account) internal view returns (bool) {
        uint256 size;
        assembly {
            size := extcodesize(account)
        }

        // Return true only for regular contracts (size > 23)
        // EIP-7702 delegated accounts (size == 23) are still EOAs, not contracts
        return size > 23;
    }
}

File 7 of 18 : GenericErrors.sol
// SPDX-License-Identifier: LGPL-3.0-only
/// @custom:version 1.0.2
pragma solidity ^0.8.17;

error AlreadyInitialized();
error CannotAuthoriseSelf();
error CannotBridgeToSameNetwork();
error ContractCallNotAllowed();
error CumulativeSlippageTooHigh(uint256 minAmount, uint256 receivedAmount);
error DiamondIsPaused();
error ETHTransferFailed();
error ExternalCallFailed();
error FunctionDoesNotExist();
error InformationMismatch();
error InsufficientBalance(uint256 required, uint256 balance);
error InvalidAmount();
error InvalidCallData();
error InvalidConfig();
error InvalidContract();
error InvalidDestinationChain();
error InvalidFallbackAddress();
error InvalidNonEVMReceiver();
error InvalidReceiver();
error InvalidSendingToken();
error NativeAssetNotSupported();
error NativeAssetTransferFailed();
error NoSwapDataProvided();
error NoSwapFromZeroBalance();
error NotAContract();
error NotInitialized();
error NoTransferToNullAddress();
error NullAddrIsNotAnERC20Token();
error NullAddrIsNotAValidSpender();
error OnlyContractOwner();
error RecoveryAddressCannotBeZero();
error ReentrancyError();
error TokenNotSupported();
error TransferFromFailed();
error UnAuthorized();
error UnsupportedChainId(uint256 chainId);
error WithdrawFailed();
error ZeroAmount();

File 8 of 18 : LiFiData.sol
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity ^0.8.17;

/// @title LiFiData
/// @author LI.FI (https://li.fi)
/// @notice A storage for LI.FI-internal config data (addresses, chainIDs, etc.)
/// @custom:version 1.0.0
contract LiFiData {
    address internal constant NON_EVM_ADDRESS =
        0x11f111f111f111F111f111f111F111f111f111F1;

    // LI.FI non-EVM Custom Chain IDs (IDs are made up by the LI.FI team)
    uint256 internal constant LIFI_CHAIN_ID_APTOS = 9271000000000010;
    uint256 internal constant LIFI_CHAIN_ID_BCH = 20000000000002;
    uint256 internal constant LIFI_CHAIN_ID_BTC = 20000000000001;
    uint256 internal constant LIFI_CHAIN_ID_DGE = 20000000000004;
    uint256 internal constant LIFI_CHAIN_ID_LTC = 20000000000003;
    uint256 internal constant LIFI_CHAIN_ID_SOLANA = 1151111081099710;
    uint256 internal constant LIFI_CHAIN_ID_SUI = 9270000000000000;
    uint256 internal constant LIFI_CHAIN_ID_TRON = 1885080386571452;
}

// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity ^0.8.17;

/// @title Interface for ERC-173 (Contract Ownership Standard)
/// @author LI.FI (https://li.fi)
/// Note: the ERC-165 identifier for this interface is 0x7f5828d0
/// @custom:version 1.0.0
interface IERC173 {
    /// @dev This emits when ownership of a contract changes.
    event OwnershipTransferred(
        address indexed previousOwner,
        address indexed newOwner
    );

    /// @notice Get the address of the owner
    /// @return owner_ The address of the owner.
    function owner() external view returns (address owner_);

    /// @notice Set the address of the new owner of the contract
    /// @dev Set _newOwner to address(0) to renounce any ownership.
    /// @param _newOwner The address of the new owner of the contract
    function transferOwnership(address _newOwner) external;
}

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

pragma solidity ^0.8.0;

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

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

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

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

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

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

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

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

// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity ^0.8.17;

import { LibAsset } from "./LibAsset.sol";
import { LibUtil } from "./LibUtil.sol";
import { InvalidContract, NoSwapFromZeroBalance } from "../Errors/GenericErrors.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

/// @title LibSwap
/// @custom:version 1.1.0
/// @notice This library contains functionality to execute mostly swaps but also
///         other calls such as fee collection, token wrapping/unwrapping or
///         sending gas to destination chain
library LibSwap {
    /// @notice Struct containing all necessary data to execute a swap or generic call
    /// @param callTo The address of the contract to call for executing the swap
    /// @param approveTo The address that will receive token approval (can be different than callTo for some DEXs)
    /// @param sendingAssetId The address of the token being sent
    /// @param receivingAssetId The address of the token expected to be received
    /// @param fromAmount The exact amount of the sending asset to be used in the call
    /// @param callData Encoded function call data to be sent to the `callTo` contract
    /// @param requiresDeposit A flag indicating whether the tokens must be deposited (pulled) before the call
    struct SwapData {
        address callTo;
        address approveTo;
        address sendingAssetId;
        address receivingAssetId;
        uint256 fromAmount;
        bytes callData;
        bool requiresDeposit;
    }

    /// @notice Emitted after a successful asset swap or related operation
    /// @param transactionId    The unique identifier associated with the swap operation
    /// @param dex              The address of the DEX or contract that handled the swap
    /// @param fromAssetId      The address of the token that was sent
    /// @param toAssetId        The address of the token that was received
    /// @param fromAmount       The amount of `fromAssetId` sent
    /// @param toAmount         The amount of `toAssetId` received
    /// @param timestamp        The timestamp when the swap was executed
    event AssetSwapped(
        bytes32 transactionId,
        address dex,
        address fromAssetId,
        address toAssetId,
        uint256 fromAmount,
        uint256 toAmount,
        uint256 timestamp
    );

    function swap(bytes32 transactionId, SwapData calldata _swap) internal {
        // make sure callTo is a contract
        if (!LibAsset.isContract(_swap.callTo)) revert InvalidContract();

        // make sure that fromAmount is not 0
        uint256 fromAmount = _swap.fromAmount;
        if (fromAmount == 0) revert NoSwapFromZeroBalance();

        // determine how much native value to send with the swap call
        uint256 nativeValue = LibAsset.isNativeAsset(_swap.sendingAssetId)
            ? _swap.fromAmount
            : 0;

        // store initial balance (required for event emission)
        uint256 initialReceivingAssetBalance = LibAsset.getOwnBalance(
            _swap.receivingAssetId
        );

        // max approve (if ERC20)
        if (nativeValue == 0) {
            LibAsset.maxApproveERC20(
                IERC20(_swap.sendingAssetId),
                _swap.approveTo,
                _swap.fromAmount
            );
        }

        // we used to have a sending asset balance check here (initialSendingAssetBalance >= _swap.fromAmount)
        // this check was removed to allow for more flexibility with rebasing/fee-taking tokens
        // the general assumption is that if not enough tokens are available to execute the calldata,
        // the transaction will fail anyway
        // the error message might not be as explicit though

        // execute the swap
        // solhint-disable-next-line avoid-low-level-calls
        (bool success, bytes memory res) = _swap.callTo.call{
            value: nativeValue
        }(_swap.callData);
        if (!success) {
            LibUtil.revertWith(res);
        }

        // get post-swap balance
        uint256 newBalance = LibAsset.getOwnBalance(_swap.receivingAssetId);

        // emit event
        emit AssetSwapped(
            transactionId,
            _swap.callTo,
            _swap.sendingAssetId,
            _swap.receivingAssetId,
            _swap.fromAmount,
            newBalance > initialReceivingAssetBalance
                ? newBalance - initialReceivingAssetBalance
                : newBalance,
            block.timestamp
        );
    }
}

File 12 of 18 : ReentrancyGuard.sol
// SPDX-License-Identifier: UNLICENSED
/// @custom:version 1.0.0
pragma solidity ^0.8.17;

/// @title Reentrancy Guard
/// @author LI.FI (https://li.fi)
/// @notice Abstract contract to provide protection against reentrancy
abstract contract ReentrancyGuard {
    /// Storage ///

    bytes32 private constant NAMESPACE = keccak256("com.lifi.reentrancyguard");

    /// Types ///

    struct ReentrancyStorage {
        uint256 status;
    }

    /// Errors ///

    error ReentrancyError();

    /// Constants ///

    uint256 private constant _NOT_ENTERED = 0;
    uint256 private constant _ENTERED = 1;

    /// Modifiers ///

    modifier nonReentrant() {
        ReentrancyStorage storage s = reentrancyStorage();
        if (s.status == _ENTERED) revert ReentrancyError();
        s.status = _ENTERED;
        _;
        s.status = _NOT_ENTERED;
    }

    /// Private Methods ///

    /// @dev fetch local storage
    function reentrancyStorage()
        private
        pure
        returns (ReentrancyStorage storage data)
    {
        bytes32 position = NAMESPACE;
        // solhint-disable-next-line no-inline-assembly
        assembly {
            data.slot := position
        }
    }
}

// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity ^0.8.17;

import { ILiFi } from "../Interfaces/ILiFi.sol";
import { LibSwap } from "../Libraries/LibSwap.sol";
import { LibAsset } from "../Libraries/LibAsset.sol";
import { LibAllowList } from "../Libraries/LibAllowList.sol";
import { ContractCallNotAllowed, NoSwapDataProvided, CumulativeSlippageTooHigh } from "../Errors/GenericErrors.sol";

/// @title SwapperV2
/// @author LI.FI (https://li.fi)
/// @notice Abstract contract to provide swap functionality with leftover token handling
/// @custom:version 1.1.0
contract SwapperV2 is ILiFi {
    /// Types ///

    /// @dev only used to get around "Stack Too Deep" errors
    struct ReserveData {
        bytes32 transactionId;
        address payable leftoverReceiver;
        uint256 nativeReserve;
    }

    /// Modifiers ///

    /// @dev Sends any leftover balances back to the user
    /// @notice Sends any leftover balances to the user
    /// @param _swaps Swap data array
    /// @param _leftoverReceiver Address to send leftover tokens to
    /// @param _initialBalances Array of initial token balances
    modifier noLeftovers(
        LibSwap.SwapData[] calldata _swaps,
        address payable _leftoverReceiver,
        uint256[] memory _initialBalances
    ) {
        _;
        _refundLeftovers(_swaps, _leftoverReceiver, _initialBalances, 0);
    }

    /// @dev Sends any leftover balances back to the user reserving native tokens
    /// @notice Sends any leftover balances to the user
    /// @param _swaps Swap data array
    /// @param _leftoverReceiver Address to send leftover tokens to
    /// @param _initialBalances Array of initial token balances
    /// @param _nativeReserve Amount of native token to prevent from being swept
    modifier noLeftoversReserve(
        LibSwap.SwapData[] calldata _swaps,
        address payable _leftoverReceiver,
        uint256[] memory _initialBalances,
        uint256 _nativeReserve
    ) {
        _;
        _refundLeftovers(
            _swaps,
            _leftoverReceiver,
            _initialBalances,
            _nativeReserve
        );
    }

    /// @dev Refunds any excess native asset sent to the contract after the main function
    /// @notice Refunds any excess native asset sent to the contract after the main function
    /// @param _refundReceiver Address to send refunds to
    modifier refundExcessNative(address payable _refundReceiver) {
        uint256 initialBalance = address(this).balance - msg.value;
        _;
        uint256 finalBalance = address(this).balance;

        if (finalBalance > initialBalance) {
            LibAsset.transferAsset(
                LibAsset.NULL_ADDRESS,
                _refundReceiver,
                finalBalance - initialBalance
            );
        }
    }

    /// Internal Methods ///

    /// @dev Deposits value, executes swaps, and performs minimum amount check
    /// @param _transactionId the transaction id associated with the operation
    /// @param _minAmount the minimum amount of the final asset to receive
    /// @param _swaps Array of data used to execute swaps
    /// @param _leftoverReceiver The address to send leftover funds to
    /// @return uint256 result of the swap
    function _depositAndSwap(
        bytes32 _transactionId,
        uint256 _minAmount,
        LibSwap.SwapData[] calldata _swaps,
        address payable _leftoverReceiver
    ) internal returns (uint256) {
        uint256 numSwaps = _swaps.length;

        if (numSwaps == 0) {
            revert NoSwapDataProvided();
        }

        address finalTokenId = _swaps[numSwaps - 1].receivingAssetId;
        uint256 initialBalance = LibAsset.getOwnBalance(finalTokenId);

        if (LibAsset.isNativeAsset(finalTokenId)) {
            initialBalance -= msg.value;
        }

        uint256[] memory initialBalances = _fetchBalances(_swaps);

        LibAsset.depositAssets(_swaps);

        _executeSwaps(
            _transactionId,
            _swaps,
            _leftoverReceiver,
            initialBalances
        );

        uint256 newBalance = LibAsset.getOwnBalance(finalTokenId) -
            initialBalance;

        if (newBalance < _minAmount) {
            revert CumulativeSlippageTooHigh(_minAmount, newBalance);
        }

        return newBalance;
    }

    /// @dev Deposits value, executes swaps, and performs minimum amount check and reserves native token for fees
    /// @param _transactionId the transaction id associated with the operation
    /// @param _minAmount the minimum amount of the final asset to receive
    /// @param _swaps Array of data used to execute swaps
    /// @param _leftoverReceiver The address to send leftover funds to
    /// @param _nativeReserve Amount of native token to prevent from being swept back to the caller
    function _depositAndSwap(
        bytes32 _transactionId,
        uint256 _minAmount,
        LibSwap.SwapData[] calldata _swaps,
        address payable _leftoverReceiver,
        uint256 _nativeReserve
    ) internal returns (uint256) {
        uint256 numSwaps = _swaps.length;

        if (numSwaps == 0) {
            revert NoSwapDataProvided();
        }

        address finalTokenId = _swaps[numSwaps - 1].receivingAssetId;
        uint256 initialBalance = LibAsset.getOwnBalance(finalTokenId);

        if (LibAsset.isNativeAsset(finalTokenId)) {
            initialBalance -= msg.value;
        }

        uint256[] memory initialBalances = _fetchBalances(_swaps);

        LibAsset.depositAssets(_swaps);

        ReserveData memory reserveData = ReserveData({
            transactionId: _transactionId,
            leftoverReceiver: _leftoverReceiver,
            nativeReserve: _nativeReserve
        });

        _executeSwaps(reserveData, _swaps, initialBalances);

        uint256 newBalance = LibAsset.getOwnBalance(finalTokenId) -
            initialBalance;

        if (LibAsset.isNativeAsset(finalTokenId)) {
            newBalance -= _nativeReserve;
        }

        if (newBalance < _minAmount) {
            revert CumulativeSlippageTooHigh(_minAmount, newBalance);
        }

        return newBalance;
    }

    /// Private Methods ///

    /// @dev Executes swaps and checks that DEXs used are in the allowList
    /// @param _transactionId the transaction id associated with the operation
    /// @param _swaps Array of data used to execute swaps
    /// @param _leftoverReceiver Address to send leftover tokens to
    /// @param _initialBalances Array of initial balances
    function _executeSwaps(
        bytes32 _transactionId,
        LibSwap.SwapData[] calldata _swaps,
        address payable _leftoverReceiver,
        uint256[] memory _initialBalances
    ) internal noLeftovers(_swaps, _leftoverReceiver, _initialBalances) {
        uint256 numSwaps = _swaps.length;
        for (uint256 i; i < numSwaps; ++i) {
            LibSwap.SwapData calldata currentSwap = _swaps[i];

            if (
                !((LibAsset.isNativeAsset(currentSwap.sendingAssetId) ||
                    LibAllowList.contractIsAllowed(currentSwap.approveTo)) &&
                    LibAllowList.contractIsAllowed(currentSwap.callTo) &&
                    LibAllowList.selectorIsAllowed(
                        bytes4(currentSwap.callData[:4])
                    ))
            ) revert ContractCallNotAllowed();

            LibSwap.swap(_transactionId, currentSwap);
        }
    }

    /// @dev Executes swaps and checks that DEXs used are in the allowList
    /// @param _reserveData Data passed used to reserve native tokens
    /// @param _swaps Array of data used to execute swaps
    /// @param _initialBalances Array of initial balances
    function _executeSwaps(
        ReserveData memory _reserveData,
        LibSwap.SwapData[] calldata _swaps,
        uint256[] memory _initialBalances
    )
        internal
        noLeftoversReserve(
            _swaps,
            _reserveData.leftoverReceiver,
            _initialBalances,
            _reserveData.nativeReserve
        )
    {
        uint256 numSwaps = _swaps.length;
        for (uint256 i; i < numSwaps; ++i) {
            LibSwap.SwapData calldata currentSwap = _swaps[i];

            if (
                !((LibAsset.isNativeAsset(currentSwap.sendingAssetId) ||
                    LibAllowList.contractIsAllowed(currentSwap.approveTo)) &&
                    LibAllowList.contractIsAllowed(currentSwap.callTo) &&
                    LibAllowList.selectorIsAllowed(
                        bytes4(currentSwap.callData[:4])
                    ))
            ) revert ContractCallNotAllowed();

            LibSwap.swap(_reserveData.transactionId, currentSwap);
        }
    }

    /// @dev Fetches balances of tokens to be swapped before swapping.
    /// @param _swaps Array of data used to execute swaps
    /// @return uint256[] Array of token balances.
    function _fetchBalances(
        LibSwap.SwapData[] calldata _swaps
    ) internal view returns (uint256[] memory) {
        uint256 numSwaps = _swaps.length;
        uint256[] memory balances = new uint256[](numSwaps);
        address asset;
        for (uint256 i; i < numSwaps; ++i) {
            asset = _swaps[i].receivingAssetId;
            balances[i] = LibAsset.getOwnBalance(asset);

            if (LibAsset.isNativeAsset(asset)) {
                balances[i] -= msg.value;
            }
        }

        return balances;
    }

    /// @dev Refunds leftover tokens to a specified receiver after swaps complete
    /// @param _swaps Swap data array
    /// @param _leftoverReceiver Address to send leftover tokens to
    /// @param _initialBalances Array of initial token balances
    /// @param _nativeReserve Amount of native token to prevent from being swept (0 for no reserve)
    function _refundLeftovers(
        LibSwap.SwapData[] calldata _swaps,
        address payable _leftoverReceiver,
        uint256[] memory _initialBalances,
        uint256 _nativeReserve
    ) private {
        uint256 numSwaps = _swaps.length;
        address finalAsset = _swaps[numSwaps - 1].receivingAssetId;

        // Handle both intermediate receiving assets and leftover input tokens in a single loop
        uint256 leftoverAmount;
        address curAsset;
        address inputAsset;
        uint256 curAssetReserve;
        uint256 currentInputBalance;
        uint256 inputAssetReserve;

        for (uint256 i; i < numSwaps; ++i) {
            // Handle intermediate receiving assets (only for non-final swaps when numSwaps > 1)
            if (i < numSwaps - 1 && numSwaps != 1) {
                curAsset = _swaps[i].receivingAssetId;
                // Handle multiple swap steps
                if (curAsset != finalAsset) {
                    leftoverAmount =
                        LibAsset.getOwnBalance(curAsset) -
                        _initialBalances[i];
                    curAssetReserve = LibAsset.isNativeAsset(curAsset)
                        ? _nativeReserve
                        : 0;
                    if (leftoverAmount > curAssetReserve) {
                        LibAsset.transferAsset(
                            curAsset,
                            _leftoverReceiver,
                            leftoverAmount - curAssetReserve
                        );
                    }
                }
            }

            // Handle leftover input tokens (but never sweep the final receiving asset)
            inputAsset = _swaps[i].sendingAssetId;
            currentInputBalance = LibAsset.getOwnBalance(inputAsset);
            inputAssetReserve = LibAsset.isNativeAsset(inputAsset)
                ? _nativeReserve
                : 0;

            // Only transfer leftovers if there's actually a balance remaining after reserve
            // and if it's not the final receiving asset (which should be kept for bridging)
            if (
                currentInputBalance > inputAssetReserve &&
                inputAsset != finalAsset
            ) {
                LibAsset.transferAsset(
                    inputAsset,
                    _leftoverReceiver,
                    currentInputBalance - inputAssetReserve
                );
            }
        }
    }
}

File 14 of 18 : Validatable.sol
// SPDX-License-Identifier: UNLICENSED
/// @custom:version 1.0.0
pragma solidity ^0.8.17;

import { LibAsset } from "../Libraries/LibAsset.sol";
import { LibUtil } from "../Libraries/LibUtil.sol";
// solhint-disable-next-line max-line-length
import { InvalidReceiver, InformationMismatch, InvalidSendingToken, InvalidAmount, NativeAssetNotSupported, InvalidDestinationChain, CannotBridgeToSameNetwork } from "../Errors/GenericErrors.sol";
import { ILiFi } from "../Interfaces/ILiFi.sol";
// solhint-disable-next-line no-unused-import
import { LibSwap } from "../Libraries/LibSwap.sol";

contract Validatable {
    modifier validateBridgeData(ILiFi.BridgeData memory _bridgeData) {
        if (LibUtil.isZeroAddress(_bridgeData.receiver)) {
            revert InvalidReceiver();
        }
        if (_bridgeData.minAmount == 0) {
            revert InvalidAmount();
        }
        if (_bridgeData.destinationChainId == block.chainid) {
            revert CannotBridgeToSameNetwork();
        }
        _;
    }

    modifier noNativeAsset(ILiFi.BridgeData memory _bridgeData) {
        if (LibAsset.isNativeAsset(_bridgeData.sendingAssetId)) {
            revert NativeAssetNotSupported();
        }
        _;
    }

    modifier onlyAllowSourceToken(
        ILiFi.BridgeData memory _bridgeData,
        address _token
    ) {
        if (_bridgeData.sendingAssetId != _token) {
            revert InvalidSendingToken();
        }
        _;
    }

    modifier onlyAllowDestinationChain(
        ILiFi.BridgeData memory _bridgeData,
        uint256 _chainId
    ) {
        if (_bridgeData.destinationChainId != _chainId) {
            revert InvalidDestinationChain();
        }
        _;
    }

    modifier containsSourceSwaps(ILiFi.BridgeData memory _bridgeData) {
        if (!_bridgeData.hasSourceSwaps) {
            revert InformationMismatch();
        }
        _;
    }

    modifier doesNotContainSourceSwaps(ILiFi.BridgeData memory _bridgeData) {
        if (_bridgeData.hasSourceSwaps) {
            revert InformationMismatch();
        }
        _;
    }

    modifier doesNotContainDestinationCalls(
        ILiFi.BridgeData memory _bridgeData
    ) {
        if (_bridgeData.hasDestinationCall) {
            revert InformationMismatch();
        }
        _;
    }
}

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

/// @notice Safe ETH and ERC20 transfer library that gracefully handles missing return values.
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/SafeTransferLib.sol)
/// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/SafeTransferLib.sol)
/// @author Permit2 operations from (https://github.com/Uniswap/permit2/blob/main/src/libraries/Permit2Lib.sol)
///
/// @dev Note:
/// - For ETH transfers, please use `forceSafeTransferETH` for DoS protection.
/// - For ERC20s, this implementation won't check that a token has code,
///   responsibility is delegated to the caller.
library SafeTransferLib {
    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                       CUSTOM ERRORS                        */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev The ETH transfer has failed.
    error ETHTransferFailed();

    /// @dev The ERC20 `transferFrom` has failed.
    error TransferFromFailed();

    /// @dev The ERC20 `transfer` has failed.
    error TransferFailed();

    /// @dev The ERC20 `approve` has failed.
    error ApproveFailed();

    /// @dev The Permit2 operation has failed.
    error Permit2Failed();

    /// @dev The Permit2 amount must be less than `2**160 - 1`.
    error Permit2AmountOverflow();

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                         CONSTANTS                          */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Suggested gas stipend for contract receiving ETH that disallows any storage writes.
    uint256 internal constant GAS_STIPEND_NO_STORAGE_WRITES = 2300;

    /// @dev Suggested gas stipend for contract receiving ETH to perform a few
    /// storage reads and writes, but low enough to prevent griefing.
    uint256 internal constant GAS_STIPEND_NO_GRIEF = 100000;

    /// @dev The unique EIP-712 domain domain separator for the DAI token contract.
    bytes32 internal constant DAI_DOMAIN_SEPARATOR =
        0xdbb8cf42e1ecb028be3f3dbc922e1d878b963f411dc388ced501601c60f7c6f7;

    /// @dev The address for the WETH9 contract on Ethereum mainnet.
    address internal constant WETH9 = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;

    /// @dev The canonical Permit2 address.
    /// [Github](https://github.com/Uniswap/permit2)
    /// [Etherscan](https://etherscan.io/address/0x000000000022D473030F116dDEE9F6B43aC78BA3)
    address internal constant PERMIT2 = 0x000000000022D473030F116dDEE9F6B43aC78BA3;

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                       ETH OPERATIONS                       */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    // If the ETH transfer MUST succeed with a reasonable gas budget, use the force variants.
    //
    // The regular variants:
    // - Forwards all remaining gas to the target.
    // - Reverts if the target reverts.
    // - Reverts if the current contract has insufficient balance.
    //
    // The force variants:
    // - Forwards with an optional gas stipend
    //   (defaults to `GAS_STIPEND_NO_GRIEF`, which is sufficient for most cases).
    // - If the target reverts, or if the gas stipend is exhausted,
    //   creates a temporary contract to force send the ETH via `SELFDESTRUCT`.
    //   Future compatible with `SENDALL`: https://eips.ethereum.org/EIPS/eip-4758.
    // - Reverts if the current contract has insufficient balance.
    //
    // The try variants:
    // - Forwards with a mandatory gas stipend.
    // - Instead of reverting, returns whether the transfer succeeded.

    /// @dev Sends `amount` (in wei) ETH to `to`.
    function safeTransferETH(address to, uint256 amount) internal {
        /// @solidity memory-safe-assembly
        assembly {
            if iszero(call(gas(), to, amount, codesize(), 0x00, codesize(), 0x00)) {
                mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`.
                revert(0x1c, 0x04)
            }
        }
    }

    /// @dev Sends all the ETH in the current contract to `to`.
    function safeTransferAllETH(address to) internal {
        /// @solidity memory-safe-assembly
        assembly {
            // Transfer all the ETH and check if it succeeded or not.
            if iszero(call(gas(), to, selfbalance(), codesize(), 0x00, codesize(), 0x00)) {
                mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`.
                revert(0x1c, 0x04)
            }
        }
    }

    /// @dev Force sends `amount` (in wei) ETH to `to`, with a `gasStipend`.
    function forceSafeTransferETH(address to, uint256 amount, uint256 gasStipend) internal {
        /// @solidity memory-safe-assembly
        assembly {
            if lt(selfbalance(), amount) {
                mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`.
                revert(0x1c, 0x04)
            }
            if iszero(call(gasStipend, to, amount, codesize(), 0x00, codesize(), 0x00)) {
                mstore(0x00, to) // Store the address in scratch space.
                mstore8(0x0b, 0x73) // Opcode `PUSH20`.
                mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`.
                if iszero(create(amount, 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation.
            }
        }
    }

    /// @dev Force sends all the ETH in the current contract to `to`, with a `gasStipend`.
    function forceSafeTransferAllETH(address to, uint256 gasStipend) internal {
        /// @solidity memory-safe-assembly
        assembly {
            if iszero(call(gasStipend, to, selfbalance(), codesize(), 0x00, codesize(), 0x00)) {
                mstore(0x00, to) // Store the address in scratch space.
                mstore8(0x0b, 0x73) // Opcode `PUSH20`.
                mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`.
                if iszero(create(selfbalance(), 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation.
            }
        }
    }

    /// @dev Force sends `amount` (in wei) ETH to `to`, with `GAS_STIPEND_NO_GRIEF`.
    function forceSafeTransferETH(address to, uint256 amount) internal {
        /// @solidity memory-safe-assembly
        assembly {
            if lt(selfbalance(), amount) {
                mstore(0x00, 0xb12d13eb) // `ETHTransferFailed()`.
                revert(0x1c, 0x04)
            }
            if iszero(call(GAS_STIPEND_NO_GRIEF, to, amount, codesize(), 0x00, codesize(), 0x00)) {
                mstore(0x00, to) // Store the address in scratch space.
                mstore8(0x0b, 0x73) // Opcode `PUSH20`.
                mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`.
                if iszero(create(amount, 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation.
            }
        }
    }

    /// @dev Force sends all the ETH in the current contract to `to`, with `GAS_STIPEND_NO_GRIEF`.
    function forceSafeTransferAllETH(address to) internal {
        /// @solidity memory-safe-assembly
        assembly {
            // forgefmt: disable-next-item
            if iszero(call(GAS_STIPEND_NO_GRIEF, to, selfbalance(), codesize(), 0x00, codesize(), 0x00)) {
                mstore(0x00, to) // Store the address in scratch space.
                mstore8(0x0b, 0x73) // Opcode `PUSH20`.
                mstore8(0x20, 0xff) // Opcode `SELFDESTRUCT`.
                if iszero(create(selfbalance(), 0x0b, 0x16)) { revert(codesize(), codesize()) } // For gas estimation.
            }
        }
    }

    /// @dev Sends `amount` (in wei) ETH to `to`, with a `gasStipend`.
    function trySafeTransferETH(address to, uint256 amount, uint256 gasStipend)
        internal
        returns (bool success)
    {
        /// @solidity memory-safe-assembly
        assembly {
            success := call(gasStipend, to, amount, codesize(), 0x00, codesize(), 0x00)
        }
    }

    /// @dev Sends all the ETH in the current contract to `to`, with a `gasStipend`.
    function trySafeTransferAllETH(address to, uint256 gasStipend)
        internal
        returns (bool success)
    {
        /// @solidity memory-safe-assembly
        assembly {
            success := call(gasStipend, to, selfbalance(), codesize(), 0x00, codesize(), 0x00)
        }
    }

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                      ERC20 OPERATIONS                      */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev Sends `amount` of ERC20 `token` from `from` to `to`.
    /// Reverts upon failure.
    ///
    /// The `from` account must have at least `amount` approved for
    /// the current contract to manage.
    function safeTransferFrom(address token, address from, address to, uint256 amount) internal {
        /// @solidity memory-safe-assembly
        assembly {
            let m := mload(0x40) // Cache the free memory pointer.
            mstore(0x60, amount) // Store the `amount` argument.
            mstore(0x40, to) // Store the `to` argument.
            mstore(0x2c, shl(96, from)) // Store the `from` argument.
            mstore(0x0c, 0x23b872dd000000000000000000000000) // `transferFrom(address,address,uint256)`.
            // Perform the transfer, reverting upon failure.
            if iszero(
                and( // The arguments of `and` are evaluated from right to left.
                    or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing.
                    call(gas(), token, 0, 0x1c, 0x64, 0x00, 0x20)
                )
            ) {
                mstore(0x00, 0x7939f424) // `TransferFromFailed()`.
                revert(0x1c, 0x04)
            }
            mstore(0x60, 0) // Restore the zero slot to zero.
            mstore(0x40, m) // Restore the free memory pointer.
        }
    }

    /// @dev Sends `amount` of ERC20 `token` from `from` to `to`.
    ///
    /// The `from` account must have at least `amount` approved for the current contract to manage.
    function trySafeTransferFrom(address token, address from, address to, uint256 amount)
        internal
        returns (bool success)
    {
        /// @solidity memory-safe-assembly
        assembly {
            let m := mload(0x40) // Cache the free memory pointer.
            mstore(0x60, amount) // Store the `amount` argument.
            mstore(0x40, to) // Store the `to` argument.
            mstore(0x2c, shl(96, from)) // Store the `from` argument.
            mstore(0x0c, 0x23b872dd000000000000000000000000) // `transferFrom(address,address,uint256)`.
            success :=
                and( // The arguments of `and` are evaluated from right to left.
                    or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing.
                    call(gas(), token, 0, 0x1c, 0x64, 0x00, 0x20)
                )
            mstore(0x60, 0) // Restore the zero slot to zero.
            mstore(0x40, m) // Restore the free memory pointer.
        }
    }

    /// @dev Sends all of ERC20 `token` from `from` to `to`.
    /// Reverts upon failure.
    ///
    /// The `from` account must have their entire balance approved for the current contract to manage.
    function safeTransferAllFrom(address token, address from, address to)
        internal
        returns (uint256 amount)
    {
        /// @solidity memory-safe-assembly
        assembly {
            let m := mload(0x40) // Cache the free memory pointer.
            mstore(0x40, to) // Store the `to` argument.
            mstore(0x2c, shl(96, from)) // Store the `from` argument.
            mstore(0x0c, 0x70a08231000000000000000000000000) // `balanceOf(address)`.
            // Read the balance, reverting upon failure.
            if iszero(
                and( // The arguments of `and` are evaluated from right to left.
                    gt(returndatasize(), 0x1f), // At least 32 bytes returned.
                    staticcall(gas(), token, 0x1c, 0x24, 0x60, 0x20)
                )
            ) {
                mstore(0x00, 0x7939f424) // `TransferFromFailed()`.
                revert(0x1c, 0x04)
            }
            mstore(0x00, 0x23b872dd) // `transferFrom(address,address,uint256)`.
            amount := mload(0x60) // The `amount` is already at 0x60. We'll need to return it.
            // Perform the transfer, reverting upon failure.
            if iszero(
                and( // The arguments of `and` are evaluated from right to left.
                    or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing.
                    call(gas(), token, 0, 0x1c, 0x64, 0x00, 0x20)
                )
            ) {
                mstore(0x00, 0x7939f424) // `TransferFromFailed()`.
                revert(0x1c, 0x04)
            }
            mstore(0x60, 0) // Restore the zero slot to zero.
            mstore(0x40, m) // Restore the free memory pointer.
        }
    }

    /// @dev Sends `amount` of ERC20 `token` from the current contract to `to`.
    /// Reverts upon failure.
    function safeTransfer(address token, address to, uint256 amount) internal {
        /// @solidity memory-safe-assembly
        assembly {
            mstore(0x14, to) // Store the `to` argument.
            mstore(0x34, amount) // Store the `amount` argument.
            mstore(0x00, 0xa9059cbb000000000000000000000000) // `transfer(address,uint256)`.
            // Perform the transfer, reverting upon failure.
            if iszero(
                and( // The arguments of `and` are evaluated from right to left.
                    or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing.
                    call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)
                )
            ) {
                mstore(0x00, 0x90b8ec18) // `TransferFailed()`.
                revert(0x1c, 0x04)
            }
            mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten.
        }
    }

    /// @dev Sends all of ERC20 `token` from the current contract to `to`.
    /// Reverts upon failure.
    function safeTransferAll(address token, address to) internal returns (uint256 amount) {
        /// @solidity memory-safe-assembly
        assembly {
            mstore(0x00, 0x70a08231) // Store the function selector of `balanceOf(address)`.
            mstore(0x20, address()) // Store the address of the current contract.
            // Read the balance, reverting upon failure.
            if iszero(
                and( // The arguments of `and` are evaluated from right to left.
                    gt(returndatasize(), 0x1f), // At least 32 bytes returned.
                    staticcall(gas(), token, 0x1c, 0x24, 0x34, 0x20)
                )
            ) {
                mstore(0x00, 0x90b8ec18) // `TransferFailed()`.
                revert(0x1c, 0x04)
            }
            mstore(0x14, to) // Store the `to` argument.
            amount := mload(0x34) // The `amount` is already at 0x34. We'll need to return it.
            mstore(0x00, 0xa9059cbb000000000000000000000000) // `transfer(address,uint256)`.
            // Perform the transfer, reverting upon failure.
            if iszero(
                and( // The arguments of `and` are evaluated from right to left.
                    or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing.
                    call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)
                )
            ) {
                mstore(0x00, 0x90b8ec18) // `TransferFailed()`.
                revert(0x1c, 0x04)
            }
            mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten.
        }
    }

    /// @dev Sets `amount` of ERC20 `token` for `to` to manage on behalf of the current contract.
    /// Reverts upon failure.
    function safeApprove(address token, address to, uint256 amount) internal {
        /// @solidity memory-safe-assembly
        assembly {
            mstore(0x14, to) // Store the `to` argument.
            mstore(0x34, amount) // Store the `amount` argument.
            mstore(0x00, 0x095ea7b3000000000000000000000000) // `approve(address,uint256)`.
            // Perform the approval, reverting upon failure.
            if iszero(
                and( // The arguments of `and` are evaluated from right to left.
                    or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing.
                    call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)
                )
            ) {
                mstore(0x00, 0x3e3f8f73) // `ApproveFailed()`.
                revert(0x1c, 0x04)
            }
            mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten.
        }
    }

    /// @dev Sets `amount` of ERC20 `token` for `to` to manage on behalf of the current contract.
    /// If the initial attempt to approve fails, attempts to reset the approved amount to zero,
    /// then retries the approval again (some tokens, e.g. USDT, requires this).
    /// Reverts upon failure.
    function safeApproveWithRetry(address token, address to, uint256 amount) internal {
        /// @solidity memory-safe-assembly
        assembly {
            mstore(0x14, to) // Store the `to` argument.
            mstore(0x34, amount) // Store the `amount` argument.
            mstore(0x00, 0x095ea7b3000000000000000000000000) // `approve(address,uint256)`.
            // Perform the approval, retrying upon failure.
            if iszero(
                and( // The arguments of `and` are evaluated from right to left.
                    or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing.
                    call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)
                )
            ) {
                mstore(0x34, 0) // Store 0 for the `amount`.
                mstore(0x00, 0x095ea7b3000000000000000000000000) // `approve(address,uint256)`.
                pop(call(gas(), token, 0, 0x10, 0x44, codesize(), 0x00)) // Reset the approval.
                mstore(0x34, amount) // Store back the original `amount`.
                // Retry the approval, reverting upon failure.
                if iszero(
                    and(
                        or(eq(mload(0x00), 1), iszero(returndatasize())), // Returned 1 or nothing.
                        call(gas(), token, 0, 0x10, 0x44, 0x00, 0x20)
                    )
                ) {
                    mstore(0x00, 0x3e3f8f73) // `ApproveFailed()`.
                    revert(0x1c, 0x04)
                }
            }
            mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten.
        }
    }

    /// @dev Returns the amount of ERC20 `token` owned by `account`.
    /// Returns zero if the `token` does not exist.
    function balanceOf(address token, address account) internal view returns (uint256 amount) {
        /// @solidity memory-safe-assembly
        assembly {
            mstore(0x14, account) // Store the `account` argument.
            mstore(0x00, 0x70a08231000000000000000000000000) // `balanceOf(address)`.
            amount :=
                mul( // The arguments of `mul` are evaluated from right to left.
                    mload(0x20),
                    and( // The arguments of `and` are evaluated from right to left.
                        gt(returndatasize(), 0x1f), // At least 32 bytes returned.
                        staticcall(gas(), token, 0x10, 0x24, 0x20, 0x20)
                    )
                )
        }
    }

    /// @dev Sends `amount` of ERC20 `token` from `from` to `to`.
    /// If the initial attempt fails, try to use Permit2 to transfer the token.
    /// Reverts upon failure.
    ///
    /// The `from` account must have at least `amount` approved for the current contract to manage.
    function safeTransferFrom2(address token, address from, address to, uint256 amount) internal {
        if (!trySafeTransferFrom(token, from, to, amount)) {
            permit2TransferFrom(token, from, to, amount);
        }
    }

    /// @dev Sends `amount` of ERC20 `token` from `from` to `to` via Permit2.
    /// Reverts upon failure.
    function permit2TransferFrom(address token, address from, address to, uint256 amount)
        internal
    {
        /// @solidity memory-safe-assembly
        assembly {
            let m := mload(0x40)
            mstore(add(m, 0x74), shr(96, shl(96, token)))
            mstore(add(m, 0x54), amount)
            mstore(add(m, 0x34), to)
            mstore(add(m, 0x20), shl(96, from))
            // `transferFrom(address,address,uint160,address)`.
            mstore(m, 0x36c78516000000000000000000000000)
            let p := PERMIT2
            let exists := eq(chainid(), 1)
            if iszero(exists) { exists := iszero(iszero(extcodesize(p))) }
            if iszero(and(call(gas(), p, 0, add(m, 0x10), 0x84, codesize(), 0x00), exists)) {
                mstore(0x00, 0x7939f4248757f0fd) // `TransferFromFailed()` or `Permit2AmountOverflow()`.
                revert(add(0x18, shl(2, iszero(iszero(shr(160, amount))))), 0x04)
            }
        }
    }

    /// @dev Permit a user to spend a given amount of
    /// another user's tokens via native EIP-2612 permit if possible, falling
    /// back to Permit2 if native permit fails or is not implemented on the token.
    function permit2(
        address token,
        address owner,
        address spender,
        uint256 amount,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal {
        bool success;
        /// @solidity memory-safe-assembly
        assembly {
            for {} shl(96, xor(token, WETH9)) {} {
                mstore(0x00, 0x3644e515) // `DOMAIN_SEPARATOR()`.
                if iszero(
                    and( // The arguments of `and` are evaluated from right to left.
                        lt(iszero(mload(0x00)), eq(returndatasize(), 0x20)), // Returns 1 non-zero word.
                        // Gas stipend to limit gas burn for tokens that don't refund gas when
                        // an non-existing function is called. 5K should be enough for a SLOAD.
                        staticcall(5000, token, 0x1c, 0x04, 0x00, 0x20)
                    )
                ) { break }
                // After here, we can be sure that token is a contract.
                let m := mload(0x40)
                mstore(add(m, 0x34), spender)
                mstore(add(m, 0x20), shl(96, owner))
                mstore(add(m, 0x74), deadline)
                if eq(mload(0x00), DAI_DOMAIN_SEPARATOR) {
                    mstore(0x14, owner)
                    mstore(0x00, 0x7ecebe00000000000000000000000000) // `nonces(address)`.
                    mstore(add(m, 0x94), staticcall(gas(), token, 0x10, 0x24, add(m, 0x54), 0x20))
                    mstore(m, 0x8fcbaf0c000000000000000000000000) // `IDAIPermit.permit`.
                    // `nonces` is already at `add(m, 0x54)`.
                    // `1` is already stored at `add(m, 0x94)`.
                    mstore(add(m, 0xb4), and(0xff, v))
                    mstore(add(m, 0xd4), r)
                    mstore(add(m, 0xf4), s)
                    success := call(gas(), token, 0, add(m, 0x10), 0x104, codesize(), 0x00)
                    break
                }
                mstore(m, 0xd505accf000000000000000000000000) // `IERC20Permit.permit`.
                mstore(add(m, 0x54), amount)
                mstore(add(m, 0x94), and(0xff, v))
                mstore(add(m, 0xb4), r)
                mstore(add(m, 0xd4), s)
                success := call(gas(), token, 0, add(m, 0x10), 0xe4, codesize(), 0x00)
                break
            }
        }
        if (!success) simplePermit2(token, owner, spender, amount, deadline, v, r, s);
    }

    /// @dev Simple permit on the Permit2 contract.
    function simplePermit2(
        address token,
        address owner,
        address spender,
        uint256 amount,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal {
        /// @solidity memory-safe-assembly
        assembly {
            let m := mload(0x40)
            mstore(m, 0x927da105) // `allowance(address,address,address)`.
            {
                let addressMask := shr(96, not(0))
                mstore(add(m, 0x20), and(addressMask, owner))
                mstore(add(m, 0x40), and(addressMask, token))
                mstore(add(m, 0x60), and(addressMask, spender))
                mstore(add(m, 0xc0), and(addressMask, spender))
            }
            let p := mul(PERMIT2, iszero(shr(160, amount)))
            if iszero(
                and( // The arguments of `and` are evaluated from right to left.
                    gt(returndatasize(), 0x5f), // Returns 3 words: `amount`, `expiration`, `nonce`.
                    staticcall(gas(), p, add(m, 0x1c), 0x64, add(m, 0x60), 0x60)
                )
            ) {
                mstore(0x00, 0x6b836e6b8757f0fd) // `Permit2Failed()` or `Permit2AmountOverflow()`.
                revert(add(0x18, shl(2, iszero(p))), 0x04)
            }
            mstore(m, 0x2b67b570) // `Permit2.permit` (PermitSingle variant).
            // `owner` is already `add(m, 0x20)`.
            // `token` is already at `add(m, 0x40)`.
            mstore(add(m, 0x60), amount)
            mstore(add(m, 0x80), 0xffffffffffff) // `expiration = type(uint48).max`.
            // `nonce` is already at `add(m, 0xa0)`.
            // `spender` is already at `add(m, 0xc0)`.
            mstore(add(m, 0xe0), deadline)
            mstore(add(m, 0x100), 0x100) // `signature` offset.
            mstore(add(m, 0x120), 0x41) // `signature` length.
            mstore(add(m, 0x140), r)
            mstore(add(m, 0x160), s)
            mstore(add(m, 0x180), shl(248, v))
            if iszero(call(gas(), p, 0, add(m, 0x1c), 0x184, codesize(), 0x00)) {
                mstore(0x00, 0x6b836e6b) // `Permit2Failed()`.
                revert(0x1c, 0x04)
            }
        }
    }
}

// SPDX-License-Identifier: LGPL-3.0-only
/// @custom:version 1.0.0
pragma solidity ^0.8.17;

// solhint-disable-next-line no-global-import
import "./LibBytes.sol";

library LibUtil {
    using LibBytes for bytes;

    function getRevertMsg(
        bytes memory _res
    ) internal pure returns (string memory) {
        // If the _res length is less than 68, then the transaction failed silently (without a revert message)
        if (_res.length < 68) return "Transaction reverted silently";
        bytes memory revertData = _res.slice(4, _res.length - 4); // Remove the selector which is the first 4 bytes
        return abi.decode(revertData, (string)); // All that remains is the revert string
    }

    /// @notice Determines whether the given address is the zero address
    /// @param addr The address to verify
    /// @return Boolean indicating if the address is the zero address
    function isZeroAddress(address addr) internal pure returns (bool) {
        return addr == address(0);
    }

    function revertWith(bytes memory data) internal pure {
        assembly {
            let dataSize := mload(data) // Load the size of the data
            let dataPtr := add(data, 0x20) // Advance data pointer to the next word
            revert(dataPtr, dataSize) // Revert with the given data
        }
    }
}

// SPDX-License-Identifier: LGPL-3.0-only
/// @custom:version 1.0.0
pragma solidity ^0.8.17;

import { InvalidContract } from "../Errors/GenericErrors.sol";

/// @title Lib Allow List
/// @author LI.FI (https://li.fi)
/// @notice Library for managing and accessing the conract address allow list
library LibAllowList {
    /// Storage ///
    bytes32 internal constant NAMESPACE =
        keccak256("com.lifi.library.allow.list");

    struct AllowListStorage {
        mapping(address => bool) allowlist;
        mapping(bytes4 => bool) selectorAllowList;
        address[] contracts;
    }

    /// @dev Adds a contract address to the allow list
    /// @param _contract the contract address to add
    function addAllowedContract(address _contract) internal {
        _checkAddress(_contract);

        AllowListStorage storage als = _getStorage();

        if (als.allowlist[_contract]) return;

        als.allowlist[_contract] = true;
        als.contracts.push(_contract);
    }

    /// @dev Checks whether a contract address has been added to the allow list
    /// @param _contract the contract address to check
    function contractIsAllowed(
        address _contract
    ) internal view returns (bool) {
        return _getStorage().allowlist[_contract];
    }

    /// @dev Remove a contract address from the allow list
    /// @param _contract the contract address to remove
    function removeAllowedContract(address _contract) internal {
        AllowListStorage storage als = _getStorage();

        if (!als.allowlist[_contract]) {
            return;
        }

        als.allowlist[_contract] = false;

        uint256 length = als.contracts.length;
        // Find the contract in the list
        for (uint256 i = 0; i < length; i++) {
            if (als.contracts[i] == _contract) {
                // Move the last element into the place to delete
                als.contracts[i] = als.contracts[length - 1];
                // Remove the last element
                als.contracts.pop();
                break;
            }
        }
    }

    /// @dev Fetch contract addresses from the allow list
    function getAllowedContracts() internal view returns (address[] memory) {
        return _getStorage().contracts;
    }

    /// @dev Add a selector to the allow list
    /// @param _selector the selector to add
    function addAllowedSelector(bytes4 _selector) internal {
        _getStorage().selectorAllowList[_selector] = true;
    }

    /// @dev Removes a selector from the allow list
    /// @param _selector the selector to remove
    function removeAllowedSelector(bytes4 _selector) internal {
        _getStorage().selectorAllowList[_selector] = false;
    }

    /// @dev Returns if selector has been added to the allow list
    /// @param _selector the selector to check
    function selectorIsAllowed(bytes4 _selector) internal view returns (bool) {
        return _getStorage().selectorAllowList[_selector];
    }

    /// @dev Fetch local storage struct
    function _getStorage()
        internal
        pure
        returns (AllowListStorage storage als)
    {
        bytes32 position = NAMESPACE;
        // solhint-disable-next-line no-inline-assembly
        assembly {
            als.slot := position
        }
    }

    /// @dev Contains business logic for validating a contract address.
    /// @param _contract address of the dex to check
    function _checkAddress(address _contract) private view {
        if (_contract == address(0)) revert InvalidContract();

        if (_contract.code.length == 0) revert InvalidContract();
    }
}

// SPDX-License-Identifier: LGPL-3.0-only
/// @custom:version 1.0.0
pragma solidity ^0.8.17;

library LibBytes {
    // solhint-disable no-inline-assembly

    // LibBytes specific errors
    error SliceOverflow();
    error SliceOutOfBounds();
    error AddressOutOfBounds();

    bytes16 private constant _SYMBOLS = "0123456789abcdef";

    // -------------------------

    function slice(
        bytes memory _bytes,
        uint256 _start,
        uint256 _length
    ) internal pure returns (bytes memory) {
        if (_length + 31 < _length) revert SliceOverflow();
        if (_bytes.length < _start + _length) revert SliceOutOfBounds();

        bytes memory tempBytes;

        assembly {
            switch iszero(_length)
            case 0 {
                // Get a location of some free memory and store it in tempBytes as
                // Solidity does for memory variables.
                tempBytes := mload(0x40)

                // The first word of the slice result is potentially a partial
                // word read from the original array. To read it, we calculate
                // the length of that partial word and start copying that many
                // bytes into the array. The first word we copy will start with
                // data we don't care about, but the last `lengthmod` bytes will
                // land at the beginning of the contents of the new array. When
                // we're done copying, we overwrite the full first word with
                // the actual length of the slice.
                let lengthmod := and(_length, 31)

                // The multiplication in the next line is necessary
                // because when slicing multiples of 32 bytes (lengthmod == 0)
                // the following copy loop was copying the origin's length
                // and then ending prematurely not copying everything it should.
                let mc := add(
                    add(tempBytes, lengthmod),
                    mul(0x20, iszero(lengthmod))
                )
                let end := add(mc, _length)

                for {
                    // The multiplication in the next line has the same exact purpose
                    // as the one above.
                    let cc := add(
                        add(
                            add(_bytes, lengthmod),
                            mul(0x20, iszero(lengthmod))
                        ),
                        _start
                    )
                } lt(mc, end) {
                    mc := add(mc, 0x20)
                    cc := add(cc, 0x20)
                } {
                    mstore(mc, mload(cc))
                }

                mstore(tempBytes, _length)

                //update free-memory pointer
                //allocating the array padded to 32 bytes like the compiler does now
                mstore(0x40, and(add(mc, 31), not(31)))
            }
            //if we want a zero-length slice let's just return a zero-length array
            default {
                tempBytes := mload(0x40)
                //zero out the 32 bytes slice we are about to return
                //we need to do it because Solidity does not garbage collect
                mstore(tempBytes, 0)

                mstore(0x40, add(tempBytes, 0x20))
            }
        }

        return tempBytes;
    }

    function toAddress(
        bytes memory _bytes,
        uint256 _start
    ) internal pure returns (address) {
        if (_bytes.length < _start + 20) {
            revert AddressOutOfBounds();
        }
        address tempAddress;

        assembly {
            tempAddress := div(
                mload(add(add(_bytes, 0x20), _start)),
                0x1000000000000000000000000
            )
        }

        return tempAddress;
    }

    /// Copied from OpenZeppelin's `Strings.sol` utility library.
    /// https://github.com/OpenZeppelin/openzeppelin-contracts/blob/8335676b0e99944eef6a742e16dcd9ff6e68e609
    /// /contracts/utils/Strings.sol
    function toHexString(
        uint256 value,
        uint256 length
    ) internal pure returns (string memory) {
        bytes memory buffer = new bytes(2 * length + 2);
        buffer[0] = "0";
        buffer[1] = "x";
        for (uint256 i = 2 * length + 1; i > 1; --i) {
            buffer[i] = _SYMBOLS[value & 0xf];
            value >>= 4;
        }
        // solhint-disable-next-line gas-custom-errors
        require(value == 0, "Strings: hex length insufficient");
        return string(buffer);
    }
}

Settings
{
  "remappings": [
    "@eth-optimism/=node_modules/@hop-protocol/sdk/node_modules/@eth-optimism/",
    "@uniswap/=node_modules/@uniswap/",
    "eth-gas-reporter/=node_modules/eth-gas-reporter/",
    "@openzeppelin/=lib/openzeppelin-contracts/",
    "celer-network/=lib/sgn-v2-contracts/",
    "create3-factory/=lib/create3-factory/src/",
    "solmate/=lib/solmate/src/",
    "solady/=lib/solady/src/",
    "permit2/=lib/Permit2/src/",
    "ds-test/=lib/ds-test/src/",
    "forge-std/=lib/forge-std/src/",
    "lifi/=src/",
    "test/=test/",
    "@cowprotocol/=node_modules/@cowprotocol/",
    "Permit2/=lib/Permit2/",
    "erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
    "forge-gas-snapshot/=lib/Permit2/lib/forge-gas-snapshot/src/",
    "hardhat/=node_modules/hardhat/",
    "openzeppelin-contracts/=lib/openzeppelin-contracts/",
    "openzeppelin/=lib/openzeppelin-contracts/contracts/",
    "sgn-v2-contracts/=lib/sgn-v2-contracts/contracts/"
  ],
  "optimizer": {
    "enabled": true,
    "runs": 1000000
  },
  "metadata": {
    "useLiteralContent": false,
    "bytecodeHash": "ipfs"
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "evmVersion": "london",
  "viaIR": false
}

Contract Security Audit

Contract ABI

API
[{"inputs":[{"internalType":"contract IAcrossSpokePoolV4","name":"_spokePool","type":"address"},{"internalType":"bytes32","name":"_wrappedNative","type":"bytes32"},{"internalType":"address","name":"_owner","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"InvalidCalldataLength","type":"error"},{"inputs":[],"name":"InvalidConfig","type":"error"},{"inputs":[],"name":"InvalidInputAmount","type":"error"},{"inputs":[],"name":"InvalidReceiver","type":"error"},{"inputs":[],"name":"NewOwnerMustNotBeSelf","type":"error"},{"inputs":[],"name":"NoNullOwner","type":"error"},{"inputs":[],"name":"NoPendingOwnershipTransfer","type":"error"},{"inputs":[],"name":"NotPendingOwner","type":"error"},{"inputs":[],"name":"NullAddrIsNotAValidSpender","type":"error"},{"inputs":[],"name":"NullAddrIsNotAnERC20Token","type":"error"},{"inputs":[],"name":"UnAuthorized","type":"error"},{"inputs":[],"name":"WithdrawFailed","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"transactionId","type":"bytes32"},{"indexed":true,"internalType":"uint256","name":"destinationChainId","type":"uint256"},{"indexed":false,"internalType":"bytes","name":"receiver","type":"bytes"}],"name":"BridgeToNonEVMChain","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"transactionId","type":"bytes32"},{"indexed":true,"internalType":"uint256","name":"destinationChainId","type":"uint256"},{"indexed":false,"internalType":"bytes32","name":"receiver","type":"bytes32"}],"name":"BridgeToNonEVMChainBytes32","type":"event"},{"anonymous":false,"inputs":[],"name":"CallExecutedAndFundsWithdrawn","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes8","name":"_transactionId","type":"bytes8"}],"name":"LiFiAcrossTransfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"transactionId","type":"bytes32"},{"indexed":false,"internalType":"string","name":"integrator","type":"string"},{"indexed":false,"internalType":"string","name":"referrer","type":"string"},{"indexed":false,"internalType":"address","name":"receiver","type":"address"},{"indexed":false,"internalType":"address","name":"fromAssetId","type":"address"},{"indexed":false,"internalType":"address","name":"toAssetId","type":"address"},{"indexed":false,"internalType":"uint256","name":"fromAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"toAmount","type":"uint256"}],"name":"LiFiGenericSwapCompleted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"transactionId","type":"bytes32"},{"indexed":false,"internalType":"string","name":"integrator","type":"string"},{"indexed":false,"internalType":"string","name":"referrer","type":"string"},{"indexed":false,"internalType":"address","name":"fromAssetId","type":"address"},{"indexed":false,"internalType":"address","name":"toAssetId","type":"address"},{"indexed":false,"internalType":"uint256","name":"fromAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"toAmount","type":"uint256"}],"name":"LiFiSwappedGeneric","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"transactionId","type":"bytes32"},{"indexed":false,"internalType":"address","name":"receivingAssetId","type":"address"},{"indexed":false,"internalType":"address","name":"receiver","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"LiFiTransferCompleted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"transactionId","type":"bytes32"},{"indexed":false,"internalType":"address","name":"receivingAssetId","type":"address"},{"indexed":false,"internalType":"address","name":"receiver","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"LiFiTransferRecovered","type":"event"},{"anonymous":false,"inputs":[{"components":[{"internalType":"bytes32","name":"transactionId","type":"bytes32"},{"internalType":"string","name":"bridge","type":"string"},{"internalType":"string","name":"integrator","type":"string"},{"internalType":"address","name":"referrer","type":"address"},{"internalType":"address","name":"sendingAssetId","type":"address"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"minAmount","type":"uint256"},{"internalType":"uint256","name":"destinationChainId","type":"uint256"},{"internalType":"bool","name":"hasSourceSwaps","type":"bool"},{"internalType":"bool","name":"hasDestinationCall","type":"bool"}],"indexed":false,"internalType":"struct ILiFi.BridgeData","name":"bridgeData","type":"tuple"}],"name":"LiFiTransferStarted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_from","type":"address"},{"indexed":true,"internalType":"address","name":"_to","type":"address"}],"name":"OwnershipTransferRequested","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[],"name":"SPOKEPOOL","outputs":[{"internalType":"contract IAcrossSpokePoolV4","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"WRAPPED_NATIVE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"cancelOwnershipTransfer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"confirmOwnershipTransfer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes","name":"data","type":"bytes"}],"name":"decode_startBridgeTokensViaAcrossV4ERC20Packed","outputs":[{"components":[{"internalType":"bytes32","name":"transactionId","type":"bytes32"},{"internalType":"string","name":"bridge","type":"string"},{"internalType":"string","name":"integrator","type":"string"},{"internalType":"address","name":"referrer","type":"address"},{"internalType":"address","name":"sendingAssetId","type":"address"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"minAmount","type":"uint256"},{"internalType":"uint256","name":"destinationChainId","type":"uint256"},{"internalType":"bool","name":"hasSourceSwaps","type":"bool"},{"internalType":"bool","name":"hasDestinationCall","type":"bool"}],"internalType":"struct ILiFi.BridgeData","name":"bridgeData","type":"tuple"},{"components":[{"internalType":"bytes32","name":"receiverAddress","type":"bytes32"},{"internalType":"bytes32","name":"refundAddress","type":"bytes32"},{"internalType":"bytes32","name":"sendingAssetId","type":"bytes32"},{"internalType":"bytes32","name":"receivingAssetId","type":"bytes32"},{"internalType":"uint256","name":"outputAmount","type":"uint256"},{"internalType":"uint128","name":"outputAmountMultiplier","type":"uint128"},{"internalType":"bytes32","name":"exclusiveRelayer","type":"bytes32"},{"internalType":"uint32","name":"quoteTimestamp","type":"uint32"},{"internalType":"uint32","name":"fillDeadline","type":"uint32"},{"internalType":"uint32","name":"exclusivityParameter","type":"uint32"},{"internalType":"bytes","name":"message","type":"bytes"}],"internalType":"struct AcrossFacetV4.AcrossV4Data","name":"acrossData","type":"tuple"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"bytes","name":"data","type":"bytes"}],"name":"decode_startBridgeTokensViaAcrossV4NativePacked","outputs":[{"components":[{"internalType":"bytes32","name":"transactionId","type":"bytes32"},{"internalType":"string","name":"bridge","type":"string"},{"internalType":"string","name":"integrator","type":"string"},{"internalType":"address","name":"referrer","type":"address"},{"internalType":"address","name":"sendingAssetId","type":"address"},{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"minAmount","type":"uint256"},{"internalType":"uint256","name":"destinationChainId","type":"uint256"},{"internalType":"bool","name":"hasSourceSwaps","type":"bool"},{"internalType":"bool","name":"hasDestinationCall","type":"bool"}],"internalType":"struct ILiFi.BridgeData","name":"bridgeData","type":"tuple"},{"components":[{"internalType":"bytes32","name":"receiverAddress","type":"bytes32"},{"internalType":"bytes32","name":"refundAddress","type":"bytes32"},{"internalType":"bytes32","name":"sendingAssetId","type":"bytes32"},{"internalType":"bytes32","name":"receivingAssetId","type":"bytes32"},{"internalType":"uint256","name":"outputAmount","type":"uint256"},{"internalType":"uint128","name":"outputAmountMultiplier","type":"uint128"},{"internalType":"bytes32","name":"exclusiveRelayer","type":"bytes32"},{"internalType":"uint32","name":"quoteTimestamp","type":"uint32"},{"internalType":"uint32","name":"fillDeadline","type":"uint32"},{"internalType":"uint32","name":"exclusivityParameter","type":"uint32"},{"internalType":"bytes","name":"message","type":"bytes"}],"internalType":"struct AcrossFacetV4.AcrossV4Data","name":"acrossData","type":"tuple"}],"stateMutability":"pure","type":"function"},{"inputs":[{"components":[{"internalType":"bytes8","name":"transactionId","type":"bytes8"},{"internalType":"bytes32","name":"receiver","type":"bytes32"},{"internalType":"bytes32","name":"depositor","type":"bytes32"},{"internalType":"uint64","name":"destinationChainId","type":"uint64"},{"internalType":"bytes32","name":"receivingAssetId","type":"bytes32"},{"internalType":"uint256","name":"outputAmount","type":"uint256"},{"internalType":"bytes32","name":"exclusiveRelayer","type":"bytes32"},{"internalType":"uint32","name":"quoteTimestamp","type":"uint32"},{"internalType":"uint32","name":"fillDeadline","type":"uint32"},{"internalType":"uint32","name":"exclusivityParameter","type":"uint32"},{"internalType":"bytes","name":"message","type":"bytes"}],"internalType":"struct AcrossFacetPackedV4.PackedParameters","name":"_parameters","type":"tuple"},{"internalType":"bytes32","name":"sendingAssetId","type":"bytes32"},{"internalType":"uint256","name":"inputAmount","type":"uint256"}],"name":"encode_startBridgeTokensViaAcrossV4ERC20Packed","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"pure","type":"function"},{"inputs":[{"components":[{"internalType":"bytes8","name":"transactionId","type":"bytes8"},{"internalType":"bytes32","name":"receiver","type":"bytes32"},{"internalType":"bytes32","name":"depositor","type":"bytes32"},{"internalType":"uint64","name":"destinationChainId","type":"uint64"},{"internalType":"bytes32","name":"receivingAssetId","type":"bytes32"},{"internalType":"uint256","name":"outputAmount","type":"uint256"},{"internalType":"bytes32","name":"exclusiveRelayer","type":"bytes32"},{"internalType":"uint32","name":"quoteTimestamp","type":"uint32"},{"internalType":"uint32","name":"fillDeadline","type":"uint32"},{"internalType":"uint32","name":"exclusivityParameter","type":"uint32"},{"internalType":"bytes","name":"message","type":"bytes"}],"internalType":"struct AcrossFacetPackedV4.PackedParameters","name":"_parameters","type":"tuple"}],"name":"encode_startBridgeTokensViaAcrossV4NativePacked","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"_callTo","type":"address"},{"internalType":"bytes","name":"_callData","type":"bytes"},{"internalType":"address","name":"_assetAddress","type":"address"},{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"executeCallAndWithdraw","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pendingOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"tokensToApprove","type":"address[]"}],"name":"setApprovalForBridge","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"bytes8","name":"transactionId","type":"bytes8"},{"internalType":"bytes32","name":"receiver","type":"bytes32"},{"internalType":"bytes32","name":"depositor","type":"bytes32"},{"internalType":"uint64","name":"destinationChainId","type":"uint64"},{"internalType":"bytes32","name":"receivingAssetId","type":"bytes32"},{"internalType":"uint256","name":"outputAmount","type":"uint256"},{"internalType":"bytes32","name":"exclusiveRelayer","type":"bytes32"},{"internalType":"uint32","name":"quoteTimestamp","type":"uint32"},{"internalType":"uint32","name":"fillDeadline","type":"uint32"},{"internalType":"uint32","name":"exclusivityParameter","type":"uint32"},{"internalType":"bytes","name":"message","type":"bytes"}],"internalType":"struct AcrossFacetPackedV4.PackedParameters","name":"_parameters","type":"tuple"},{"internalType":"bytes32","name":"sendingAssetId","type":"bytes32"},{"internalType":"uint256","name":"inputAmount","type":"uint256"}],"name":"startBridgeTokensViaAcrossV4ERC20Min","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"startBridgeTokensViaAcrossV4ERC20Packed","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"bytes8","name":"transactionId","type":"bytes8"},{"internalType":"bytes32","name":"receiver","type":"bytes32"},{"internalType":"bytes32","name":"depositor","type":"bytes32"},{"internalType":"uint64","name":"destinationChainId","type":"uint64"},{"internalType":"bytes32","name":"receivingAssetId","type":"bytes32"},{"internalType":"uint256","name":"outputAmount","type":"uint256"},{"internalType":"bytes32","name":"exclusiveRelayer","type":"bytes32"},{"internalType":"uint32","name":"quoteTimestamp","type":"uint32"},{"internalType":"uint32","name":"fillDeadline","type":"uint32"},{"internalType":"uint32","name":"exclusivityParameter","type":"uint32"},{"internalType":"bytes","name":"message","type":"bytes"}],"internalType":"struct AcrossFacetPackedV4.PackedParameters","name":"_parameters","type":"tuple"}],"name":"startBridgeTokensViaAcrossV4NativeMin","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"startBridgeTokensViaAcrossV4NativePacked","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"_newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"}]

60c06040523480156200001157600080fd5b5060405162002a3c38038062002a3c8339810160408190526200003491620000c4565b600080546001600160a01b0319166001600160a01b03838116919091179091558316158062000061575081155b806200007457506001600160a01b038116155b1562000093576040516306b7c75960e31b815260040160405180910390fd5b506001600160a01b0390911660805260a0526200010c565b6001600160a01b0381168114620000c157600080fd5b50565b600080600060608486031215620000da57600080fd5b8351620000e781620000ab565b6020850151604086015191945092506200010181620000ab565b809150509250925092565b60805160a0516128d962000163600039600081816102d70152818161112f01526115ed01526000818161036601528181610bb401528181610e2301528181610f88015281816110fd015261159501526128d96000f3fe60806040526004361061010e5760003560e01c806372dd147e116100a5578063c93ff54011610074578063e30c397811610059578063e30c397814610307578063f2fde38b14610334578063f65039921461035457600080fd5b8063c93ff540146102a5578063d999984d146102c557600080fd5b806372dd147e1461021857806379b805121461022b5780638da5cb5b1461024b578063c5d60e971461029d57600080fd5b806336b92404116100e157806336b92404146101ae5780634c478642146101c35780637200b829146101e35780637260352d146101f857600080fd5b8063012f27e7146101135780631458d7ad1461014a5780631626cde11461016c57806323452b9c14610199575b600080fd5b34801561011f57600080fd5b5061013361012e366004611e8f565b610388565b604051610141929190612000565b60405180910390f35b34801561015657600080fd5b5061016a61016536600461215d565b610679565b005b34801561017857600080fd5b5061018c6101873660046121f4565b6107b3565b6040516101419190612242565b3480156101a557600080fd5b5061016a610a8e565b3480156101ba57600080fd5b5061016a610b58565b3480156101cf57600080fd5b5061016a6101de36600461225c565b610d9b565b3480156101ef57600080fd5b5061016a610e7f565b34801561020457600080fd5b5061016a6102133660046121f4565b610f65565b61016a6102263660046122d1565b6110e6565b34801561023757600080fd5b50610133610246366004611e8f565b611278565b34801561025757600080fd5b506000546102789073ffffffffffffffffffffffffffffffffffffffff1681565b60405173ffffffffffffffffffffffffffffffffffffffff9091168152602001610141565b61016a61157e565b3480156102b157600080fd5b5061018c6102c03660046122d1565b61179c565b3480156102d157600080fd5b506102f97f000000000000000000000000000000000000000000000000000000000000000081565b604051908152602001610141565b34801561031357600080fd5b506001546102789073ffffffffffffffffffffffffffffffffffffffff1681565b34801561034057600080fd5b5061016a61034f36600461230e565b611877565b34801561036057600080fd5b506102787f000000000000000000000000000000000000000000000000000000000000000081565b604080516101408101825260008082526060602083018190529282018390529181018290526080810182905260a0810182905260c0810182905260e081018290526101008101829052610120810191909152604080516101608101825260008082526020820181905291810182905260608082018390526080820183905260a0820183905260c0820183905260e08201839052610100820183905261012082019290925261014081019190915260c0831015610470576040517fca0ad26000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61047e600c60048587612329565b61048791612353565b825260006104996038602c8688612329565b6104a291612390565b7fffffffffffffffffffffffff00000000000000000000000000000000000000001603610500576104d7604c602c8587612329565b6104e091612353565b73ffffffffffffffffffffffffffffffffffffffff1660a083015261051b565b7311f111f111f111f111f111f111f111f111f111f160a08301525b6105296094608c8587612329565b610532916123d8565b60c01c60e0830152610548604c602c8587612329565b61055191612353565b8152610561602c600c8587612329565b61056a91612353565b602082015260006040820152610584606c604c8587612329565b61058d91612353565b60608201526105a0608c606c8587612329565b6105a991612353565b60808201526105bc60b460948587612329565b6105c591612353565b60c08201526105d860b860b48587612329565b6105e19161241e565b60e090811c908201526105f860bc60b88587612329565b6106019161241e565b60e01c61010082015261061860c060bc8587612329565b6106219161241e565b60e01c6101208201526106378360c08187612329565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152505050506101408201525b9250929050565b60005473ffffffffffffffffffffffffffffffffffffffff1633146106ca576040517fbe24598300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60008673ffffffffffffffffffffffffffffffffffffffff1686866040516106f3929190612464565b6000604051808303816000865af19150503d8060008114610730576040519150601f19603f3d011682016040523d82523d6000602084013e610735565b606091505b5050905080156107785761074a8484846119d5565b6040517fdfbe65d77c5440a078a2a1d95803d06b4a5f85b26ba3ec87bc9b421781e8dec190600090a16107aa565b6040517f750b219c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b50505050505050565b60606fffffffffffffffffffffffffffffffff8211156107ff576040517f340dabef00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60007f36b924040000000000000000000000000000000000000000000000000000000061082f6020870187612474565b604080517fffffffff000000000000000000000000000000000000000000000000000000009093166020848101919091527fffffffffffffffff0000000000000000000000000000000000000000000000009092166024840152870135602c830152860135604c820152606c8101859052608c01604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe081840301815291905290506000608080870180359186901b9060a0890135906108f49060608b016124b6565b60c01b60405160200161096494939291909384527fffffffffffffffffffffffffffffffff0000000000000000000000000000000092909216602084015260308301527fffffffffffffffff00000000000000000000000000000000000000000000000016605082015260580190565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529190529050600060c08701356109ac610100890160e08a016124e0565b60e01b6109c16101208a016101008b016124e0565b60e01b6109d66101408b016101208c016124e0565b6040805160208101959095527fffffffff0000000000000000000000000000000000000000000000000000000093841690850152908216604484015260e01b166048820152604c01604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529190529050828282610a5f6101408b018b612506565b604051602001610a7395949392919061256b565b60405160208183030381529060405293505050509392505050565b60005473ffffffffffffffffffffffffffffffffffffffff163314610adf576040517fbe24598300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60015473ffffffffffffffffffffffffffffffffffffffff16610b2e576040517f75cdea1200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600180547fffffffffffffffffffffffff0000000000000000000000000000000000000000169055565b6000610b68606c604c3684612329565b610b7191612353565b90506000610b83609c608c3684612329565b610b8c916125bb565b60801c9050610b9d82333084611a05565b73ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001663ad5425c6610be8602c600c366000612329565b610bf191612353565b610c00604c602c366000612329565b610c0991612353565b85610c19608c606c366000612329565b610c2291612353565b86610c3260bc609c366000612329565b610c3b91612353565b610c4a60c460bc366000612329565b610c53916123d8565b60c01c610c6560e460c4366000612329565b610c6e91612353565b610c7d60e860e4366000612329565b610c869161241e565b60e01c610c9860ec60e8366000612329565b610ca19161241e565b60e01c610cb360f060ec366000612329565b610cbc9161241e565b60e01c610ccd3660f0816000612329565b6040518e63ffffffff1660e01b8152600401610cf59d9c9b9a9998979695949392919061264a565b600060405180830381600087803b158015610d0f57600080fd5b505af1158015610d23573d6000803e3d6000fd5b507fe11352fef0e24c9902a94910b5ce929151ea227f4c68572aada8f2105c66c1339250610d5a9150600c90506004366000612329565b610d63916123d8565b6040517fffffffffffffffff000000000000000000000000000000000000000000000000909116815260200160405180910390a15050565b60005473ffffffffffffffffffffffffffffffffffffffff163314610dec576040517fbe24598300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60005b81811015610e7a57610e68838383818110610e0c57610e0c6126d0565b9050602002016020810190610e21919061230e565b7f00000000000000000000000000000000000000000000000000000000000000007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff611ac7565b80610e72816126ff565b915050610def565b505050565b60015473ffffffffffffffffffffffffffffffffffffffff16338114610ed1576040517f1853971c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000805460405173ffffffffffffffffffffffffffffffffffffffff808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a36000805473ffffffffffffffffffffffffffffffffffffffff9092167fffffffffffffffffffffffff0000000000000000000000000000000000000000928316179055600180549091169055565b610f7182333084611a05565b73ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001663ad5425c6604085013560208601358560808801803590879060a08b013590610fd49060608d016124b6565b60c08c0135610fea6101008e0160e08f016124e0565b8d610100016020810190610ffe91906124e0565b8e61012001602081019061101291906124e0565b8f8061014001906110239190612506565b6040518e63ffffffff1660e01b815260040161104b9d9c9b9a9998979695949392919061264a565b600060405180830381600087803b15801561106557600080fd5b505af1158015611079573d6000803e3d6000fd5b507fe11352fef0e24c9902a94910b5ce929151ea227f4c68572aada8f2105c66c13392506110ad9150506020850185612474565b6040517fffffffffffffffff000000000000000000000000000000000000000000000000909116815260200160405180910390a1505050565b73ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001663ad5425c634604084013560208501357f000000000000000000000000000000000000000000000000000000000000000060808701803590859060a08a01359061116a9060608c016124b6565b60c08b01356111806101008d0160e08e016124e0565b6111926101208e016101008f016124e0565b8d6101200160208101906111a691906124e0565b8e8061014001906111b79190612506565b6040518f63ffffffff1660e01b81526004016111df9d9c9b9a9998979695949392919061264a565b6000604051808303818588803b1580156111f857600080fd5b505af115801561120c573d6000803e3d6000fd5b507fe11352fef0e24c9902a94910b5ce929151ea227f4c68572aada8f2105c66c1339350611241925050506020830183612474565b6040517fffffffffffffffff000000000000000000000000000000000000000000000000909116815260200160405180910390a150565b604080516101408082018352600080835260606020808501829052848601829052818501839052608080860184905260a080870185905260c080880186905260e0808901879052610100808a01889052610120808b018990528b5161016081018d528981529687018990529a860188905285870188905293850187905291840186905283018590528201849052810183905294850191909152908301529060f0831015611351576040517fca0ad26000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61135f600c60048587612329565b61136891612353565b8252611378606c604c8587612329565b61138191612353565b73ffffffffffffffffffffffffffffffffffffffff16608083015260006113ac6038602c8688612329565b6113b591612390565b7fffffffffffffffffffffffff00000000000000000000000000000000000000001603611413576113ea604c602c8587612329565b6113f391612353565b73ffffffffffffffffffffffffffffffffffffffff1660a083015261142e565b7311f111f111f111f111f111f111f111f111f111f160a08301525b61143c609c608c8587612329565b611445916125bb565b60801c60c083015261145b60c460bc8587612329565b611464916123d8565b60c01c60e083015261147a604c602c8587612329565b61148391612353565b8152611493602c600c8587612329565b61149c91612353565b60208201526114af606c604c8587612329565b6114b891612353565b60408201526114cb608c606c8587612329565b6114d491612353565b60608201526114e760bc609c8587612329565b6114f091612353565b608082015261150360e460c48587612329565b61150c91612353565b60c082015261151f60e860e48587612329565b6115289161241e565b60e090811c9082015261153f60ec60e88587612329565b6115489161241e565b60e01c61010082015261155f60f060ec8587612329565b6115689161241e565b60e01c6101208201526106378360f08187612329565b73ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000000000000000000000000000000000000000000001663ad5425c6346115ca602c600c366000612329565b6115d391612353565b6115e2604c602c366000612329565b6115eb91612353565b7f000000000000000000000000000000000000000000000000000000000000000061161b606c604c366000612329565b61162491612353565b34611634608c606c366000612329565b61163d91612353565b61164c6094608c366000612329565b611655916123d8565b60c01c61166760b46094366000612329565b61167091612353565b61167f60b860b4366000612329565b6116889161241e565b60e01c61169a60bc60b8366000612329565b6116a39161241e565b60e01c6116b560c060bc366000612329565b6116be9161241e565b60e01c6116cf3660c0816000612329565b6040518f63ffffffff1660e01b81526004016116f79d9c9b9a9998979695949392919061264a565b6000604051808303818588803b15801561171057600080fd5b505af1158015611724573d6000803e3d6000fd5b507fe11352fef0e24c9902a94910b5ce929151ea227f4c68572aada8f2105c66c133935061175d9250600c915060049050366000612329565b611766916123d8565b6040517fffffffffffffffff000000000000000000000000000000000000000000000000909116815260200160405180910390a1565b60607fc5d60e97000000000000000000000000000000000000000000000000000000006117cc6020840184612474565b604084013560208501356080860180359060a0880135906117f09060608a016124b6565b60c090811b9089013561180a6101008b0160e08c016124e0565b60e01b61181f6101208c016101008d016124e0565b60e01b6118346101408d016101208e016124e0565b60e01b6118456101408e018e612506565b6040516020016118619d9c9b9a9998979695949392919061275e565b6040516020818303038152906040529050919050565b60005473ffffffffffffffffffffffffffffffffffffffff1633146118c8576040517fbe24598300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff8116611915576040517f1beca37400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b3373ffffffffffffffffffffffffffffffffffffffff821603611964576040517fbf1ea9fb00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600180547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff831690811790915560405133907fed8889f560326eb138920d842192f0eb3dd22b4f139c87a2c57538e05bae127890600090a350565b73ffffffffffffffffffffffffffffffffffffffff83166119fa57610e7a8282611af3565b610e7a838383611b64565b73ffffffffffffffffffffffffffffffffffffffff8416611a52576040517fd1bebf0c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff8216611a9f576040517f1e4ec46b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b611ac173ffffffffffffffffffffffffffffffffffffffff8516848484611bd2565b50505050565b610e7a8383837fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff611c2f565b73ffffffffffffffffffffffffffffffffffffffff8216611b40576040517f1e4ec46b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b611b6073ffffffffffffffffffffffffffffffffffffffff831682611d58565b5050565b73ffffffffffffffffffffffffffffffffffffffff8216611bb1576040517f1e4ec46b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610e7a73ffffffffffffffffffffffffffffffffffffffff84168383611d74565b60405181606052826040528360601b602c526f23b872dd000000000000000000000000600c52602060006064601c6000895af13d156001600051141716611c2157637939f4246000526004601cfd5b600060605260405250505050565b73ffffffffffffffffffffffffffffffffffffffff841615611ac15773ffffffffffffffffffffffffffffffffffffffff8316611c98576040517f63ba9bff00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040517fdd62ed3e00000000000000000000000000000000000000000000000000000000815230600482015273ffffffffffffffffffffffffffffffffffffffff848116602483015283919086169063dd62ed3e90604401602060405180830381865afa158015611d0d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d31919061288a565b1015611ac157611ac173ffffffffffffffffffffffffffffffffffffffff85168483611dc3565b60003860003884865af1611b605763b12d13eb6000526004601cfd5b81601452806034526fa9059cbb00000000000000000000000060005260206000604460106000875af13d156001600051141716611db9576390b8ec186000526004601cfd5b6000603452505050565b81601452806034526f095ea7b300000000000000000000000060005260206000604460106000875af13d156001600051141716611db95760006034526f095ea7b3000000000000000000000000600052600038604460106000875af1508060345260206000604460106000875af13d156001600051141716611db957633e3f8f736000526004601cfd5b60008083601f840112611e5f57600080fd5b50813567ffffffffffffffff811115611e7757600080fd5b60208301915083602082850101111561067257600080fd5b60008060208385031215611ea257600080fd5b823567ffffffffffffffff811115611eb957600080fd5b611ec585828601611e4d565b90969095509350505050565b60005b83811015611eec578181015183820152602001611ed4565b50506000910152565b60008151808452611f0d816020860160208601611ed1565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169290920160200192915050565b6000610160825184526020830151602085015260408301516040850152606083015160608501526080830151608085015260a0830151611f9360a08601826fffffffffffffffffffffffffffffffff169052565b5060c083015160c085015260e0830151611fb560e086018263ffffffff169052565b506101008381015163ffffffff81168683015250506101208381015163ffffffff8116868301525050610140808401518282870152611ff683870182611ef5565b9695505050505050565b604081528251604082015260006020840151610140806060850152612029610180850183611ef5565b915060408601517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc08584030160808601526120648382611ef5565b925050606086015161208e60a086018273ffffffffffffffffffffffffffffffffffffffff169052565b50608086015173ffffffffffffffffffffffffffffffffffffffff811660c08601525060a086015173ffffffffffffffffffffffffffffffffffffffff811660e08601525060c0860151610100818187015260e0880151915061012082818801528189015192506121028488018415159052565b8801518015156101608801529250612118915050565b50828103602084015261212b8185611f3f565b95945050505050565b803573ffffffffffffffffffffffffffffffffffffffff8116811461215857600080fd5b919050565b60008060008060008060a0878903121561217657600080fd5b61217f87612134565b9550602087013567ffffffffffffffff81111561219b57600080fd5b6121a789828a01611e4d565b90965094506121ba905060408801612134565b92506121c860608801612134565b9150608087013590509295509295509295565b600061016082840312156121ee57600080fd5b50919050565b60008060006060848603121561220957600080fd5b833567ffffffffffffffff81111561222057600080fd5b61222c868287016121db565b9660208601359650604090950135949350505050565b6020815260006122556020830184611ef5565b9392505050565b6000806020838503121561226f57600080fd5b823567ffffffffffffffff8082111561228757600080fd5b818501915085601f83011261229b57600080fd5b8135818111156122aa57600080fd5b8660208260051b85010111156122bf57600080fd5b60209290920196919550909350505050565b6000602082840312156122e357600080fd5b813567ffffffffffffffff8111156122fa57600080fd5b612306848285016121db565b949350505050565b60006020828403121561232057600080fd5b61225582612134565b6000808585111561233957600080fd5b8386111561234657600080fd5b5050820193919092039150565b8035602083101561238a577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff602084900360031b1b165b92915050565b7fffffffffffffffffffffffff0000000000000000000000000000000000000000813581811691600c8510156123d057808186600c0360031b1b83161692505b505092915050565b7fffffffffffffffff00000000000000000000000000000000000000000000000081358181169160088510156123d05760089490940360031b84901b1690921692915050565b7fffffffff0000000000000000000000000000000000000000000000000000000081358181169160048510156123d05760049490940360031b84901b1690921692915050565b8183823760009101908152919050565b60006020828403121561248657600080fd5b81357fffffffffffffffff0000000000000000000000000000000000000000000000008116811461225557600080fd5b6000602082840312156124c857600080fd5b813567ffffffffffffffff8116811461225557600080fd5b6000602082840312156124f257600080fd5b813563ffffffff8116811461225557600080fd5b60008083357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe184360301811261253b57600080fd5b83018035915067ffffffffffffffff82111561255657600080fd5b60200191503681900382131561067257600080fd5b6000865161257d818460208b01611ed1565b865190830190612591818360208b01611ed1565b86519101906125a4818360208a01611ed1565b018385823760009301928352509095945050505050565b7fffffffffffffffffffffffffffffffff0000000000000000000000000000000081358181169160108510156123d05760109490940360031b84901b1690921692915050565b8183528181602085013750600060208284010152600060207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f840116840101905092915050565b60006101808f83528e60208401528d60408401528c60608401528b60808401528a60a084015267ffffffffffffffff8a1660c08401528860e084015263ffffffff80891661010085015280881661012085015280871661014085015250806101608401526126bb8184018587612601565b9150509e9d5050505050505050505050505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8203612757577f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b5060010190565b7fffffffff000000000000000000000000000000000000000000000000000000008e1681527fffffffffffffffff0000000000000000000000000000000000000000000000008d1660048201528b600c8201528a602c82015289604c82015288606c8201527fffffffffffffffff0000000000000000000000000000000000000000000000008816608c8201528660948201527fffffffff00000000000000000000000000000000000000000000000000000000861660b48201527fffffffff00000000000000000000000000000000000000000000000000000000851660b88201527fffffffff00000000000000000000000000000000000000000000000000000000841660bc820152818360c08301376000910160c0019081529c9b505050505050505050505050565b60006020828403121561289c57600080fd5b505191905056fea2646970667358221220bbfe5e7c2d881bb45a5f8bc773a18ed341bff431feeeb0cca02192a2872493c364736f6c63430008110033000000000000000000000000e35e9842fceaca96570b734083f4a58e8f7c5f2a00000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab100000000000000000000000011f1022ca6adef6400e5677528a80d49a069c00c

Deployed Bytecode

0x60806040526004361061010e5760003560e01c806372dd147e116100a5578063c93ff54011610074578063e30c397811610059578063e30c397814610307578063f2fde38b14610334578063f65039921461035457600080fd5b8063c93ff540146102a5578063d999984d146102c557600080fd5b806372dd147e1461021857806379b805121461022b5780638da5cb5b1461024b578063c5d60e971461029d57600080fd5b806336b92404116100e157806336b92404146101ae5780634c478642146101c35780637200b829146101e35780637260352d146101f857600080fd5b8063012f27e7146101135780631458d7ad1461014a5780631626cde11461016c57806323452b9c14610199575b600080fd5b34801561011f57600080fd5b5061013361012e366004611e8f565b610388565b604051610141929190612000565b60405180910390f35b34801561015657600080fd5b5061016a61016536600461215d565b610679565b005b34801561017857600080fd5b5061018c6101873660046121f4565b6107b3565b6040516101419190612242565b3480156101a557600080fd5b5061016a610a8e565b3480156101ba57600080fd5b5061016a610b58565b3480156101cf57600080fd5b5061016a6101de36600461225c565b610d9b565b3480156101ef57600080fd5b5061016a610e7f565b34801561020457600080fd5b5061016a6102133660046121f4565b610f65565b61016a6102263660046122d1565b6110e6565b34801561023757600080fd5b50610133610246366004611e8f565b611278565b34801561025757600080fd5b506000546102789073ffffffffffffffffffffffffffffffffffffffff1681565b60405173ffffffffffffffffffffffffffffffffffffffff9091168152602001610141565b61016a61157e565b3480156102b157600080fd5b5061018c6102c03660046122d1565b61179c565b3480156102d157600080fd5b506102f97f00000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab181565b604051908152602001610141565b34801561031357600080fd5b506001546102789073ffffffffffffffffffffffffffffffffffffffff1681565b34801561034057600080fd5b5061016a61034f36600461230e565b611877565b34801561036057600080fd5b506102787f000000000000000000000000e35e9842fceaca96570b734083f4a58e8f7c5f2a81565b604080516101408101825260008082526060602083018190529282018390529181018290526080810182905260a0810182905260c0810182905260e081018290526101008101829052610120810191909152604080516101608101825260008082526020820181905291810182905260608082018390526080820183905260a0820183905260c0820183905260e08201839052610100820183905261012082019290925261014081019190915260c0831015610470576040517fca0ad26000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61047e600c60048587612329565b61048791612353565b825260006104996038602c8688612329565b6104a291612390565b7fffffffffffffffffffffffff00000000000000000000000000000000000000001603610500576104d7604c602c8587612329565b6104e091612353565b73ffffffffffffffffffffffffffffffffffffffff1660a083015261051b565b7311f111f111f111f111f111f111f111f111f111f160a08301525b6105296094608c8587612329565b610532916123d8565b60c01c60e0830152610548604c602c8587612329565b61055191612353565b8152610561602c600c8587612329565b61056a91612353565b602082015260006040820152610584606c604c8587612329565b61058d91612353565b60608201526105a0608c606c8587612329565b6105a991612353565b60808201526105bc60b460948587612329565b6105c591612353565b60c08201526105d860b860b48587612329565b6105e19161241e565b60e090811c908201526105f860bc60b88587612329565b6106019161241e565b60e01c61010082015261061860c060bc8587612329565b6106219161241e565b60e01c6101208201526106378360c08187612329565b8080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152505050506101408201525b9250929050565b60005473ffffffffffffffffffffffffffffffffffffffff1633146106ca576040517fbe24598300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60008673ffffffffffffffffffffffffffffffffffffffff1686866040516106f3929190612464565b6000604051808303816000865af19150503d8060008114610730576040519150601f19603f3d011682016040523d82523d6000602084013e610735565b606091505b5050905080156107785761074a8484846119d5565b6040517fdfbe65d77c5440a078a2a1d95803d06b4a5f85b26ba3ec87bc9b421781e8dec190600090a16107aa565b6040517f750b219c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b50505050505050565b60606fffffffffffffffffffffffffffffffff8211156107ff576040517f340dabef00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60007f36b924040000000000000000000000000000000000000000000000000000000061082f6020870187612474565b604080517fffffffff000000000000000000000000000000000000000000000000000000009093166020848101919091527fffffffffffffffff0000000000000000000000000000000000000000000000009092166024840152870135602c830152860135604c820152606c8101859052608c01604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe081840301815291905290506000608080870180359186901b9060a0890135906108f49060608b016124b6565b60c01b60405160200161096494939291909384527fffffffffffffffffffffffffffffffff0000000000000000000000000000000092909216602084015260308301527fffffffffffffffff00000000000000000000000000000000000000000000000016605082015260580190565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529190529050600060c08701356109ac610100890160e08a016124e0565b60e01b6109c16101208a016101008b016124e0565b60e01b6109d66101408b016101208c016124e0565b6040805160208101959095527fffffffff0000000000000000000000000000000000000000000000000000000093841690850152908216604484015260e01b166048820152604c01604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe08184030181529190529050828282610a5f6101408b018b612506565b604051602001610a7395949392919061256b565b60405160208183030381529060405293505050509392505050565b60005473ffffffffffffffffffffffffffffffffffffffff163314610adf576040517fbe24598300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60015473ffffffffffffffffffffffffffffffffffffffff16610b2e576040517f75cdea1200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600180547fffffffffffffffffffffffff0000000000000000000000000000000000000000169055565b6000610b68606c604c3684612329565b610b7191612353565b90506000610b83609c608c3684612329565b610b8c916125bb565b60801c9050610b9d82333084611a05565b73ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000e35e9842fceaca96570b734083f4a58e8f7c5f2a1663ad5425c6610be8602c600c366000612329565b610bf191612353565b610c00604c602c366000612329565b610c0991612353565b85610c19608c606c366000612329565b610c2291612353565b86610c3260bc609c366000612329565b610c3b91612353565b610c4a60c460bc366000612329565b610c53916123d8565b60c01c610c6560e460c4366000612329565b610c6e91612353565b610c7d60e860e4366000612329565b610c869161241e565b60e01c610c9860ec60e8366000612329565b610ca19161241e565b60e01c610cb360f060ec366000612329565b610cbc9161241e565b60e01c610ccd3660f0816000612329565b6040518e63ffffffff1660e01b8152600401610cf59d9c9b9a9998979695949392919061264a565b600060405180830381600087803b158015610d0f57600080fd5b505af1158015610d23573d6000803e3d6000fd5b507fe11352fef0e24c9902a94910b5ce929151ea227f4c68572aada8f2105c66c1339250610d5a9150600c90506004366000612329565b610d63916123d8565b6040517fffffffffffffffff000000000000000000000000000000000000000000000000909116815260200160405180910390a15050565b60005473ffffffffffffffffffffffffffffffffffffffff163314610dec576040517fbe24598300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60005b81811015610e7a57610e68838383818110610e0c57610e0c6126d0565b9050602002016020810190610e21919061230e565b7f000000000000000000000000e35e9842fceaca96570b734083f4a58e8f7c5f2a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff611ac7565b80610e72816126ff565b915050610def565b505050565b60015473ffffffffffffffffffffffffffffffffffffffff16338114610ed1576040517f1853971c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000805460405173ffffffffffffffffffffffffffffffffffffffff808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a36000805473ffffffffffffffffffffffffffffffffffffffff9092167fffffffffffffffffffffffff0000000000000000000000000000000000000000928316179055600180549091169055565b610f7182333084611a05565b73ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000e35e9842fceaca96570b734083f4a58e8f7c5f2a1663ad5425c6604085013560208601358560808801803590879060a08b013590610fd49060608d016124b6565b60c08c0135610fea6101008e0160e08f016124e0565b8d610100016020810190610ffe91906124e0565b8e61012001602081019061101291906124e0565b8f8061014001906110239190612506565b6040518e63ffffffff1660e01b815260040161104b9d9c9b9a9998979695949392919061264a565b600060405180830381600087803b15801561106557600080fd5b505af1158015611079573d6000803e3d6000fd5b507fe11352fef0e24c9902a94910b5ce929151ea227f4c68572aada8f2105c66c13392506110ad9150506020850185612474565b6040517fffffffffffffffff000000000000000000000000000000000000000000000000909116815260200160405180910390a1505050565b73ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000e35e9842fceaca96570b734083f4a58e8f7c5f2a1663ad5425c634604084013560208501357f00000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab160808701803590859060a08a01359061116a9060608c016124b6565b60c08b01356111806101008d0160e08e016124e0565b6111926101208e016101008f016124e0565b8d6101200160208101906111a691906124e0565b8e8061014001906111b79190612506565b6040518f63ffffffff1660e01b81526004016111df9d9c9b9a9998979695949392919061264a565b6000604051808303818588803b1580156111f857600080fd5b505af115801561120c573d6000803e3d6000fd5b507fe11352fef0e24c9902a94910b5ce929151ea227f4c68572aada8f2105c66c1339350611241925050506020830183612474565b6040517fffffffffffffffff000000000000000000000000000000000000000000000000909116815260200160405180910390a150565b604080516101408082018352600080835260606020808501829052848601829052818501839052608080860184905260a080870185905260c080880186905260e0808901879052610100808a01889052610120808b018990528b5161016081018d528981529687018990529a860188905285870188905293850187905291840186905283018590528201849052810183905294850191909152908301529060f0831015611351576040517fca0ad26000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61135f600c60048587612329565b61136891612353565b8252611378606c604c8587612329565b61138191612353565b73ffffffffffffffffffffffffffffffffffffffff16608083015260006113ac6038602c8688612329565b6113b591612390565b7fffffffffffffffffffffffff00000000000000000000000000000000000000001603611413576113ea604c602c8587612329565b6113f391612353565b73ffffffffffffffffffffffffffffffffffffffff1660a083015261142e565b7311f111f111f111f111f111f111f111f111f111f160a08301525b61143c609c608c8587612329565b611445916125bb565b60801c60c083015261145b60c460bc8587612329565b611464916123d8565b60c01c60e083015261147a604c602c8587612329565b61148391612353565b8152611493602c600c8587612329565b61149c91612353565b60208201526114af606c604c8587612329565b6114b891612353565b60408201526114cb608c606c8587612329565b6114d491612353565b60608201526114e760bc609c8587612329565b6114f091612353565b608082015261150360e460c48587612329565b61150c91612353565b60c082015261151f60e860e48587612329565b6115289161241e565b60e090811c9082015261153f60ec60e88587612329565b6115489161241e565b60e01c61010082015261155f60f060ec8587612329565b6115689161241e565b60e01c6101208201526106378360f08187612329565b73ffffffffffffffffffffffffffffffffffffffff7f000000000000000000000000e35e9842fceaca96570b734083f4a58e8f7c5f2a1663ad5425c6346115ca602c600c366000612329565b6115d391612353565b6115e2604c602c366000612329565b6115eb91612353565b7f00000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab161161b606c604c366000612329565b61162491612353565b34611634608c606c366000612329565b61163d91612353565b61164c6094608c366000612329565b611655916123d8565b60c01c61166760b46094366000612329565b61167091612353565b61167f60b860b4366000612329565b6116889161241e565b60e01c61169a60bc60b8366000612329565b6116a39161241e565b60e01c6116b560c060bc366000612329565b6116be9161241e565b60e01c6116cf3660c0816000612329565b6040518f63ffffffff1660e01b81526004016116f79d9c9b9a9998979695949392919061264a565b6000604051808303818588803b15801561171057600080fd5b505af1158015611724573d6000803e3d6000fd5b507fe11352fef0e24c9902a94910b5ce929151ea227f4c68572aada8f2105c66c133935061175d9250600c915060049050366000612329565b611766916123d8565b6040517fffffffffffffffff000000000000000000000000000000000000000000000000909116815260200160405180910390a1565b60607fc5d60e97000000000000000000000000000000000000000000000000000000006117cc6020840184612474565b604084013560208501356080860180359060a0880135906117f09060608a016124b6565b60c090811b9089013561180a6101008b0160e08c016124e0565b60e01b61181f6101208c016101008d016124e0565b60e01b6118346101408d016101208e016124e0565b60e01b6118456101408e018e612506565b6040516020016118619d9c9b9a9998979695949392919061275e565b6040516020818303038152906040529050919050565b60005473ffffffffffffffffffffffffffffffffffffffff1633146118c8576040517fbe24598300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff8116611915576040517f1beca37400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b3373ffffffffffffffffffffffffffffffffffffffff821603611964576040517fbf1ea9fb00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600180547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff831690811790915560405133907fed8889f560326eb138920d842192f0eb3dd22b4f139c87a2c57538e05bae127890600090a350565b73ffffffffffffffffffffffffffffffffffffffff83166119fa57610e7a8282611af3565b610e7a838383611b64565b73ffffffffffffffffffffffffffffffffffffffff8416611a52576040517fd1bebf0c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff8216611a9f576040517f1e4ec46b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b611ac173ffffffffffffffffffffffffffffffffffffffff8516848484611bd2565b50505050565b610e7a8383837fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff611c2f565b73ffffffffffffffffffffffffffffffffffffffff8216611b40576040517f1e4ec46b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b611b6073ffffffffffffffffffffffffffffffffffffffff831682611d58565b5050565b73ffffffffffffffffffffffffffffffffffffffff8216611bb1576040517f1e4ec46b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610e7a73ffffffffffffffffffffffffffffffffffffffff84168383611d74565b60405181606052826040528360601b602c526f23b872dd000000000000000000000000600c52602060006064601c6000895af13d156001600051141716611c2157637939f4246000526004601cfd5b600060605260405250505050565b73ffffffffffffffffffffffffffffffffffffffff841615611ac15773ffffffffffffffffffffffffffffffffffffffff8316611c98576040517f63ba9bff00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040517fdd62ed3e00000000000000000000000000000000000000000000000000000000815230600482015273ffffffffffffffffffffffffffffffffffffffff848116602483015283919086169063dd62ed3e90604401602060405180830381865afa158015611d0d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d31919061288a565b1015611ac157611ac173ffffffffffffffffffffffffffffffffffffffff85168483611dc3565b60003860003884865af1611b605763b12d13eb6000526004601cfd5b81601452806034526fa9059cbb00000000000000000000000060005260206000604460106000875af13d156001600051141716611db9576390b8ec186000526004601cfd5b6000603452505050565b81601452806034526f095ea7b300000000000000000000000060005260206000604460106000875af13d156001600051141716611db95760006034526f095ea7b3000000000000000000000000600052600038604460106000875af1508060345260206000604460106000875af13d156001600051141716611db957633e3f8f736000526004601cfd5b60008083601f840112611e5f57600080fd5b50813567ffffffffffffffff811115611e7757600080fd5b60208301915083602082850101111561067257600080fd5b60008060208385031215611ea257600080fd5b823567ffffffffffffffff811115611eb957600080fd5b611ec585828601611e4d565b90969095509350505050565b60005b83811015611eec578181015183820152602001611ed4565b50506000910152565b60008151808452611f0d816020860160208601611ed1565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169290920160200192915050565b6000610160825184526020830151602085015260408301516040850152606083015160608501526080830151608085015260a0830151611f9360a08601826fffffffffffffffffffffffffffffffff169052565b5060c083015160c085015260e0830151611fb560e086018263ffffffff169052565b506101008381015163ffffffff81168683015250506101208381015163ffffffff8116868301525050610140808401518282870152611ff683870182611ef5565b9695505050505050565b604081528251604082015260006020840151610140806060850152612029610180850183611ef5565b915060408601517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc08584030160808601526120648382611ef5565b925050606086015161208e60a086018273ffffffffffffffffffffffffffffffffffffffff169052565b50608086015173ffffffffffffffffffffffffffffffffffffffff811660c08601525060a086015173ffffffffffffffffffffffffffffffffffffffff811660e08601525060c0860151610100818187015260e0880151915061012082818801528189015192506121028488018415159052565b8801518015156101608801529250612118915050565b50828103602084015261212b8185611f3f565b95945050505050565b803573ffffffffffffffffffffffffffffffffffffffff8116811461215857600080fd5b919050565b60008060008060008060a0878903121561217657600080fd5b61217f87612134565b9550602087013567ffffffffffffffff81111561219b57600080fd5b6121a789828a01611e4d565b90965094506121ba905060408801612134565b92506121c860608801612134565b9150608087013590509295509295509295565b600061016082840312156121ee57600080fd5b50919050565b60008060006060848603121561220957600080fd5b833567ffffffffffffffff81111561222057600080fd5b61222c868287016121db565b9660208601359650604090950135949350505050565b6020815260006122556020830184611ef5565b9392505050565b6000806020838503121561226f57600080fd5b823567ffffffffffffffff8082111561228757600080fd5b818501915085601f83011261229b57600080fd5b8135818111156122aa57600080fd5b8660208260051b85010111156122bf57600080fd5b60209290920196919550909350505050565b6000602082840312156122e357600080fd5b813567ffffffffffffffff8111156122fa57600080fd5b612306848285016121db565b949350505050565b60006020828403121561232057600080fd5b61225582612134565b6000808585111561233957600080fd5b8386111561234657600080fd5b5050820193919092039150565b8035602083101561238a577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff602084900360031b1b165b92915050565b7fffffffffffffffffffffffff0000000000000000000000000000000000000000813581811691600c8510156123d057808186600c0360031b1b83161692505b505092915050565b7fffffffffffffffff00000000000000000000000000000000000000000000000081358181169160088510156123d05760089490940360031b84901b1690921692915050565b7fffffffff0000000000000000000000000000000000000000000000000000000081358181169160048510156123d05760049490940360031b84901b1690921692915050565b8183823760009101908152919050565b60006020828403121561248657600080fd5b81357fffffffffffffffff0000000000000000000000000000000000000000000000008116811461225557600080fd5b6000602082840312156124c857600080fd5b813567ffffffffffffffff8116811461225557600080fd5b6000602082840312156124f257600080fd5b813563ffffffff8116811461225557600080fd5b60008083357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe184360301811261253b57600080fd5b83018035915067ffffffffffffffff82111561255657600080fd5b60200191503681900382131561067257600080fd5b6000865161257d818460208b01611ed1565b865190830190612591818360208b01611ed1565b86519101906125a4818360208a01611ed1565b018385823760009301928352509095945050505050565b7fffffffffffffffffffffffffffffffff0000000000000000000000000000000081358181169160108510156123d05760109490940360031b84901b1690921692915050565b8183528181602085013750600060208284010152600060207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f840116840101905092915050565b60006101808f83528e60208401528d60408401528c60608401528b60808401528a60a084015267ffffffffffffffff8a1660c08401528860e084015263ffffffff80891661010085015280881661012085015280871661014085015250806101608401526126bb8184018587612601565b9150509e9d5050505050505050505050505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8203612757577f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b5060010190565b7fffffffff000000000000000000000000000000000000000000000000000000008e1681527fffffffffffffffff0000000000000000000000000000000000000000000000008d1660048201528b600c8201528a602c82015289604c82015288606c8201527fffffffffffffffff0000000000000000000000000000000000000000000000008816608c8201528660948201527fffffffff00000000000000000000000000000000000000000000000000000000861660b48201527fffffffff00000000000000000000000000000000000000000000000000000000851660b88201527fffffffff00000000000000000000000000000000000000000000000000000000841660bc820152818360c08301376000910160c0019081529c9b505050505050505050505050565b60006020828403121561289c57600080fd5b505191905056fea2646970667358221220bbfe5e7c2d881bb45a5f8bc773a18ed341bff431feeeb0cca02192a2872493c364736f6c63430008110033

Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)

000000000000000000000000e35e9842fceaca96570b734083f4a58e8f7c5f2a00000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab100000000000000000000000011f1022ca6adef6400e5677528a80d49a069c00c

-----Decoded View---------------
Arg [0] : _spokePool (address): 0xe35e9842fceaCA96570B734083f4a58e8F7C5f2A
Arg [1] : _wrappedNative (bytes32): 0x00000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab1
Arg [2] : _owner (address): 0x11F1022cA6AdEF6400e5677528a80d49a069C00c

-----Encoded View---------------
3 Constructor Arguments found :
Arg [0] : 000000000000000000000000e35e9842fceaca96570b734083f4a58e8f7c5f2a
Arg [1] : 00000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab1
Arg [2] : 00000000000000000000000011f1022ca6adef6400e5677528a80d49a069c00c


Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

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

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
Loading...
Loading
[ Download: CSV Export  ]

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