Skip to main content
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

ParameterTypeRequiredDescription
yieldTypeYieldTypeYesYield strategy type (CORE, TREASURY, or FRONTIER)
wantAssetAddressAddressYesToken address the user wants to receive
chainIdnumberYesBlockchain 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

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;
}

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)

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 CodeDescriptionResolution
SDK_NOT_INITIALIZEDSDK not initializedCall initAmplifySDK() first
VAULT_NOT_FOUNDNo vault matches parametersVerify yieldType, chainId
INVALID_WANT_ASSETWant asset not supportedCheck supported withdrawal assets