VaultClient
Static Methods
findConfigPda(programId?)— Derive the vault config PDAfindStakePda(agentPda, programId?)— Derive the stake account PDAfindWithdrawalPda(stakeAccountPda, programId?)— Derive the withdrawal request PDAfindVaultTokenAccount(usdcMint, programId?)— Derive the vault's USDC token account (returns PublicKey, not a tuple)
Instance Methods
deposit(params)— Deposit USDCrequestWithdrawal(params)— Start a withdrawal with cooldown period (configurable, check on-chain config)completeWithdrawal(params)— Finalize withdrawal after cooldown period (configurable, check on-chain config)cancelWithdrawal(params)— Cancel a pending withdrawalcloseStake(params)— Close an empty stake account and reclaim rent (params: owner, agentPda)
Fetchers
fetchConfig()— Fetch the vault configurationfetchStakeAccount(stakePda)— Fetch stake account by PDAfetchStakeByAgent(agentPda)— Fetch stake by agent PDAfetchWithdrawalRequest(stakeAccountPda)— Fetch pending withdrawal
TypeScript
import { VaultClient } from '@vouch-protocol/sdk'; // Import the vault client for USDC operations const vault = new VaultClient(program, provider); // Pass Anchor program + provider // Deposit 2 USDC to reach Standard tier (6 decimals) await vault.deposit({ owner: wallet.publicKey, agentPda, ownerTokenAccount, vaultTokenAccount, amount: 2_000_000, }); // Transfer USDC from wallet to program vault // Request withdrawal await vault.requestWithdrawal({ owner: wallet.publicKey, agentPda, stakeAccountPda, amount: 1_000_000, }); // Starts the cooldown period // After cooldown period... await vault.completeWithdrawal({ owner: wallet.publicKey, stakeAccountPda, agentPda, vaultTokenAccount, ownerTokenAccount, }); // Finalize withdrawal — USDC returned to wallet
Example Returns
deposit() / requestWithdrawal() / completeWithdrawal()
Returns
// Transaction signature (string) "5UfDuX...abc123"
fetchStakeAccount() / fetchStakeByAgent()
Returns
// StakeAccount { agent: PublicKey("BKq8rN4EwJQG3R9FnLhSGqJ2tNkh8cVRxvNApj7hbfQM"), owner: PublicKey("7xKXtg2CW87d97TXJSDpHD4vMvnQ1985FchZRgCd9oPr"), depositedAmount: BN(2000000), // $2 USDC lockedAmount: BN(0), pendingWithdrawal: BN(0), bump: 253 }
fetchWithdrawalRequest()
Returns
// WithdrawalRequest { stakeAccount: PublicKey("StakePDA..."), owner: PublicKey("7xKXtg2CW87d97TXJSDpHD4vMvnQ1985FchZRgCd9oPr"), amount: BN(1000000), // $1 USDC unlockAt: BN(1711104800), // cooldown period after request (configurable, check on-chain config) createdAt: BN(1710500000), bump: 252 }