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>
Address of the token to withdraw (use zero address for native token)
Address to receive the withdrawn tokens
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>
Address of the contract to call
Encoded function call data
Address of the token to withdraw after the call
Address to receive the withdrawn tokens
Amount of tokens to withdraw
Events
LogWithdraw
Emitted when tokens are withdrawn from the contract.
Address of the withdrawn token
Address receiving the tokens
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.