Documentation Index
Fetch the complete documentation index at: https://developers.paxoslabs.com/llms.txt
Use this file to discover all available pages before exploring further.
Prepare transaction data for canceling a pending withdrawal order on the WithdrawQueue contract. Only the order owner can cancel their order.
prepareCancelWithdrawOrderTxData() is a low-level transaction builder. Use
getWithdrawalRequests
to retrieve the orderIndex for a pending withdrawal before calling this
function.
Import
import { prepareCancelWithdrawOrderTxData } from "@paxoslabs/amplify-sdk";
Usage
const txData = await prepareCancelWithdrawOrderTxData({
yieldType: "CORE",
wantAsset: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC
chainId: 1,
orderIndex: 42n,
});
const hash = await walletClient.writeContract(txData);
Parameters
| Parameter | Type | Required | Description |
|---|
yieldType | YieldType | Yes | Yield strategy (CORE, TREASURY, FRONTIER) |
wantAsset | Address | Yes | Token address to receive as a refund |
chainId | ChainId | Yes | Chain ID where the order exists |
orderIndex | bigint | Yes | Index of the order to cancel in the WithdrawQueue |
interface PrepareCancelWithdrawOrderTxDataParams {
yieldType: YieldType;
wantAsset: Address;
chainId: ChainId;
orderIndex: bigint;
}
Return Type
Type Definition
Example Response
interface CancelWithdrawOrderTxData {
abi: typeof WithdrawQueueAbi;
address: `0x${string}`; // WithdrawQueue contract address
functionName: "cancelOrder";
args: [orderIndex: bigint];
chainId: number;
}
{
abi: [/* WithdrawQueue ABI */],
address: "0x1234567890abcdef...", // WithdrawQueue address
functionName: "cancelOrder",
args: [42n], // Order index
chainId: 1,
}
Examples
import {
getWithdrawalRequests,
prepareCancelWithdrawOrderTxData,
} from "@paxoslabs/amplify-sdk";
import { createWalletClient, createPublicClient, http } from "viem";
import { mainnet } from "viem/chains";
async function cancelWithdrawal(userAddress: `0x${string}`) {
const walletClient = createWalletClient({
account: userAddress,
chain: mainnet,
transport: http(),
});
const publicClient = createPublicClient({
chain: mainnet,
transport: http(),
});
const USDC = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";
// Step 1: Retrieve pending withdrawal requests
const { withdrawalRequests } = await getWithdrawalRequests({
userAddress,
chainId: 1,
status: "PENDING",
});
if (withdrawalRequests.length === 0) {
console.log("No pending withdrawal requests to cancel");
return;
}
const requestToCancel = withdrawalRequests[0];
// Step 2: Prepare and submit cancellation
const txData = await prepareCancelWithdrawOrderTxData({
yieldType: "CORE",
wantAsset: USDC,
chainId: requestToCancel.chainId,
orderIndex: BigInt(requestToCancel.orderIndex),
});
const hash = await walletClient.writeContract(txData);
const receipt = await publicClient.waitForTransactionReceipt({ hash });
console.log("Withdrawal canceled:", receipt.transactionHash);
return hash;
}
import {
getWithdrawalRequests,
prepareCancelWithdrawOrderTxData,
} from "@paxoslabs/amplify-sdk";
import {
useAccount,
useWriteContract,
usePublicClient,
} from "wagmi";
import { useState } from "react";
function CancelWithdrawalButton() {
const { address } = useAccount();
const publicClient = usePublicClient();
const { writeContractAsync } = useWriteContract();
const [status, setStatus] = useState("idle");
const USDC = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";
async function handleCancel() {
if (!address) return;
try {
setStatus("Fetching pending requests...");
const { withdrawalRequests } = await getWithdrawalRequests({
userAddress: address,
chainId: 1,
status: "PENDING",
});
if (withdrawalRequests.length === 0) {
setStatus("No pending requests to cancel");
return;
}
const requestToCancel = withdrawalRequests[0];
setStatus("Submitting cancellation...");
const txData = await prepareCancelWithdrawOrderTxData({
yieldType: "CORE",
wantAsset: USDC,
chainId: requestToCancel.chainId,
orderIndex: BigInt(requestToCancel.orderIndex),
});
const hash = await writeContractAsync(txData);
await publicClient.waitForTransactionReceipt({ hash });
setStatus("Withdrawal canceled!");
} catch (error) {
setStatus(`Error: ${(error as Error).message}`);
}
}
return (
<div>
<button onClick={handleCancel}>Cancel Withdrawal</button>
<p>{status}</p>
</div>
);
}
Error Handling
| Error | Description | Resolution |
|---|
Vault chain mismatch | Vault not on requested chain | Verify chainId matches vault deployment |
WithdrawQueue contract address not configured | Missing contract config | Check vault exists for yieldType/chain |
No vault found for asset | Invalid vault lookup | Verify wantAsset and yieldType combination |
import { prepareCancelWithdrawOrderTxData, APIError } from "@paxoslabs/amplify-sdk";
try {
const txData = await prepareCancelWithdrawOrderTxData({
yieldType: "CORE",
wantAsset: USDC_ADDRESS,
chainId: 1,
orderIndex: 42n,
});
} catch (error) {
if (error instanceof APIError) {
console.error("SDK Error:", error.message);
}
}