Skip to main content
The WithdrawFacet provides functionality to withdraw tokens from the diamond contract, with an optional capability to execute a call before withdrawal.

Functions

withdraw

Withdraws tokens from the contract to a specified address.
function withdraw(
  _assetAddress: string,
  _to: string,
  _amount: BigNumberish
): Promise<ContractTransaction>
_assetAddress
address
required
Address of the token to withdraw (use zero address for native token)
_to
address
required
Address to receive the withdrawn tokens
_amount
uint256
required
Amount of tokens to withdraw

executeCallAndWithdraw

Executes an arbitrary contract call and then withdraws tokens.
function executeCallAndWithdraw(
  _callTo: string,
  _callData: BytesLike,
  _assetAddress: string,
  _to: string,
  _amount: BigNumberish
): Promise<ContractTransaction>
_callTo
address
required
Address of the contract to call
_callData
bytes
required
Encoded function call data
_assetAddress
address
required
Address of the token to withdraw after the call
_to
address
required
Address to receive the withdrawn tokens
_amount
uint256
required
Amount of tokens to withdraw

Events

LogWithdraw

Emitted when tokens are withdrawn from the contract.
_assetAddress
address
Address of the withdrawn token
_to
address
Address receiving the tokens
amount
uint256
Amount of tokens withdrawn

Usage Example

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

const provider = new ethers.providers.JsonRpcProvider(RPC_URL);
const signer = provider.getSigner();
const facet = WithdrawFacet__factory.connect(DIAMOND_ADDRESS, signer);

// Simple token withdrawal
const usdcAddress = '0xUSDC_ADDRESS';
const amount = ethers.utils.parseUnits('100', 6);

const tx = await facet.withdraw(
  usdcAddress,
  '0xRECEIVER_ADDRESS',
  amount
);
await tx.wait();

// Execute a call and then withdraw
const callData = someContract.interface.encodeFunctionData('someFunction', [args]);

const tx2 = await facet.executeCallAndWithdraw(
  '0xCONTRACT_ADDRESS',
  callData,
  usdcAddress,
  '0xRECEIVER_ADDRESS',
  amount
);
await tx2.wait();

Access Control

These functions are typically restricted to authorized addresses only. The exact access control mechanism depends on the diamond’s configuration and may use the AccessManagerFacet or ownership checks.

Build docs developers (and LLMs) love