Prepares the approval transaction that must be executed before withdrawing vault shares. This grants the atomic queue contract permission to transfer shares on behalf of the user.
Import
import { prepareApproveWithdrawTxData } from "@paxoslabs/amplify-sdk";
Usage
const approval = await prepareApproveWithdrawTxData({
yieldType: YieldType.CORE,
wantAssetAddress: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
chainId: 1,
});
Parameters
| Parameter | Type | Required | Description |
|---|
yieldType | YieldType | Yes | Yield strategy type (CORE, TREASURY, or FRONTIER) |
wantAssetAddress | Address | Yes | Token address the user wants to receive |
chainId | number | Yes | Blockchain network ID |
interface PrepareApproveWithdrawParams {
/** Yield strategy type (e.g., YieldType.CORE) */
yieldType: YieldType;
/** Token address users want to receive */
wantAssetAddress: Address;
/** Blockchain network ID */
chainId: number;
}
Return Type
Type Definition
Example Response
interface ApproveWithdrawTxData {
/** Contract ABI for the approve function */
abi: Abi;
/** Vault share token address */
address: Address;
/** Function name to call (always "approve") */
functionName: string;
/** Encoded function arguments */
args: unknown[];
/** Chain ID for the transaction */
chainId: number;
}
{
abi: [...], // ERC20 ABI
address: "0xVault...ShareToken",
functionName: "approve",
args: [
"0xAtomicQueue...Address", // spender
115792089237316195423570985008687907853269984665640564039457584007913129639935n, // max uint256
],
chainId: 1,
}
Examples
import { encodeFunctionData } from "viem";
import { usePrivy } from "@privy-io/react-auth";
import {
prepareApproveWithdrawTxData,
prepareWithdrawTxData,
YieldType,
} from "@paxoslabs/amplify-sdk";
const { sendTransaction } = usePrivy();
const wantAsset = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"; // USDC
// Step 1: Approve withdrawal
const approval = await prepareApproveWithdrawTxData({
yieldType: YieldType.CORE,
wantAssetAddress: wantAsset,
chainId: 1,
});
await sendTransaction({
chainId: approval.chainId,
to: approval.address,
data: encodeFunctionData({
abi: approval.abi,
functionName: approval.functionName,
args: approval.args,
}),
});
// Step 2: Execute withdrawal (see prepareWithdrawTxData)
import { useAccount, useWriteContract } from "wagmi";
import {
prepareApproveWithdrawTxData,
YieldType,
} from "@paxoslabs/amplify-sdk";
const { address, chainId } = useAccount();
const { writeContractAsync } = useWriteContract();
const approval = await prepareApproveWithdrawTxData({
yieldType: YieldType.CORE,
wantAssetAddress: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
chainId: chainId!,
});
await writeContractAsync({
...approval,
account: address,
});
import { createWalletClient, custom } from "viem";
import { mainnet } from "viem/chains";
import {
prepareApproveWithdrawTxData,
YieldType,
} from "@paxoslabs/amplify-sdk";
const client = createWalletClient({
account,
chain: mainnet,
transport: custom(window.ethereum),
});
const approval = await prepareApproveWithdrawTxData({
yieldType: YieldType.CORE,
wantAssetAddress: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
chainId: mainnet.id,
});
await client.writeContract({
...approval,
account,
});
Withdrawal Flow
The complete withdrawal process requires two transactions:
1. Approve -> 2. Withdraw
| |
v v
Grant queue Burn shares,
permission receive tokens
The approval is typically only needed once per vault. After approval, subsequent withdrawals only require the prepareWithdrawTxData step.
Smart Wallet Batching
For smart wallets, you can batch both transactions into a single user confirmation:
// Privy Smart Wallet
const { client: smartWalletClient } = useSmartWallets();
const approval = await prepareApproveWithdrawTxData({...});
const withdraw = await prepareWithdrawTxData({...});
await smartWalletClient.sendTransaction({
calls: [
{
to: approval.address,
data: encodeFunctionData({
abi: approval.abi,
functionName: approval.functionName,
args: approval.args,
}),
},
{
to: withdraw.address,
data: encodeFunctionData({
abi: withdraw.abi,
functionName: withdraw.functionName,
args: withdraw.args,
}),
},
],
}, { sponsor: true });
Error Handling
| Error Code | Description | Resolution |
|---|
SDK_NOT_INITIALIZED | SDK not initialized | Call initAmplifySDK() first |
VAULT_NOT_FOUND | No vault matches parameters | Verify yieldType, chainId |
INVALID_WANT_ASSET | Want asset not supported | Check supported withdrawal assets |