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 (if not already approved)
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
const withdraw = await prepareWithdrawTxData({
yieldType: YieldType.CORE,
offerAmount: "100.5",
wantAssetAddress: wantAsset,
chainId: 1,
});
await sendTransaction({
chainId: withdraw.chainId,
to: withdraw.address,
data: encodeFunctionData({
abi: withdraw.abi,
functionName: withdraw.functionName,
args: withdraw.args,
}),
});