Skip to main content
The Executor contract handles destination-side operations for cross-chain transfers, including swapping received tokens and managing ERC20/ERC721/ERC1155 token receipts.

Functions

swapAndCompleteBridgeTokens

Executes swaps on received bridge tokens and transfers them to the final receiver.
function swapAndCompleteBridgeTokens(
  _transactionId: BytesLike,
  _swapData: LibSwap.SwapDataStruct[],
  _transferredAssetId: string,
  _receiver: string
): Promise<ContractTransaction>
_transactionId
bytes32
required
Unique identifier for this transaction
_swapData
LibSwap.SwapData[]
required
Array of swap operations to execute on the received tokens
_transferredAssetId
address
required
Address of the token that was received from the bridge
_receiver
address
required
Final recipient of the swapped tokens

swapAndExecute

Executes swaps with a specific amount and transfers to receiver.
function swapAndExecute(
  _transactionId: BytesLike,
  _swapData: LibSwap.SwapDataStruct[],
  _transferredAssetId: string,
  _receiver: string,
  _amount: BigNumberish
): Promise<ContractTransaction>
_transactionId
bytes32
required
Unique identifier for this transaction
_swapData
LibSwap.SwapData[]
required
Array of swap operations to execute
_transferredAssetId
address
required
Address of the token to swap
_receiver
address
required
Final recipient of the swapped tokens
_amount
uint256
required
Amount of tokens to swap

withdrawToken

Withdraws tokens from the executor (owner only).
function withdrawToken(
  assetId: string,
  receiver: string,
  amount: BigNumberish
): Promise<ContractTransaction>
assetId
address
required
Address of the token to withdraw (zero address for native token)
receiver
address
required
Address to receive the withdrawn tokens
amount
uint256
required
Amount to withdraw

Ownership Functions

The Executor implements a two-step ownership transfer pattern:

transferOwnership

Initiates ownership transfer to a new address.
function transferOwnership(_newOwner: string): Promise<ContractTransaction>
_newOwner
address
required
Address of the new owner

confirmOwnershipTransfer

Confirms the ownership transfer (must be called by pending owner).
function confirmOwnershipTransfer(): Promise<ContractTransaction>

cancelOwnershipTransfer

Cancels a pending ownership transfer (must be called by current owner).
function cancelOwnershipTransfer(): Promise<ContractTransaction>

View Functions

owner

Returns the current owner address.
function owner(): Promise<string>

pendingOwner

Returns the pending owner address (if any).
function pendingOwner(): Promise<string>

erc20Proxy

Returns the ERC20 proxy contract address.
function erc20Proxy(): Promise<string>

supportsInterface

Checks if a given interface is supported.
function supportsInterface(interfaceId: BytesLike): Promise<boolean>
interfaceId
bytes4
required
The interface identifier to check

ERC Token Receivers

The Executor implements handlers for receiving NFTs and multi-tokens:
  • onERC721Received: Handles ERC721 token receipts
  • onERC1155Received: Handles single ERC1155 token receipts
  • onERC1155BatchReceived: Handles batch ERC1155 token receipts

Events

TokensWithdrawn

Emitted when tokens are withdrawn from the executor.
assetId
address
Address of the withdrawn token
receiver
address
Address receiving the tokens
amount
uint256
Amount withdrawn

ERC20ProxySet

Emitted when the ERC20 proxy address is set.
proxy
address
Address of the ERC20 proxy

OwnershipTransferRequested

Emitted when ownership transfer is initiated.
_from
address
Current owner address
_to
address
Pending new owner address

OwnershipTransferred

Emitted when ownership transfer is completed.
previousOwner
address
Previous owner address
newOwner
address
New owner address

Usage Example

import { Executor__factory } from '@lifi/contract-types';
import { ethers } from 'ethers';

const provider = new ethers.providers.JsonRpcProvider(RPC_URL);
const signer = provider.getSigner();
const executor = Executor__factory.connect(EXECUTOR_ADDRESS, signer);

// Execute destination swaps after bridge
const swapData = [
  {
    callTo: '0xDEX_ADDRESS',
    approveTo: '0xDEX_ADDRESS',
    sendingAssetId: '0xUSDC_ADDRESS',
    receivingAssetId: '0xDAI_ADDRESS',
    fromAmount: ethers.utils.parseUnits('100', 6),
    callData: '0x...', // Encoded swap call
    requiresDeposit: true
  }
];

const tx = await executor.swapAndCompleteBridgeTokens(
  ethers.utils.randomBytes(32),
  swapData,
  '0xUSDC_ADDRESS',
  '0xRECEIVER_ADDRESS'
);

await tx.wait();

Build docs developers (and LLMs) love