VaultClient

Static Methods
  • findConfigPda(programId?) — Derive the vault config PDA
  • findStakePda(agentPda, programId?) — Derive the stake account PDA
  • findWithdrawalPda(stakeAccountPda, programId?) — Derive the withdrawal request PDA
  • findVaultTokenAccount(usdcMint, programId?) — Derive the vault's USDC token account (returns PublicKey, not a tuple)
Instance Methods
  • deposit(params) — Deposit USDC
  • requestWithdrawal(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 withdrawal
  • closeStake(params) — Close an empty stake account and reclaim rent (params: owner, agentPda)
Fetchers
  • fetchConfig() — Fetch the vault configuration
  • fetchStakeAccount(stakePda) — Fetch stake account by PDA
  • fetchStakeByAgent(agentPda) — Fetch stake by agent PDA
  • fetchWithdrawalRequest(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
}