Program Addresses
Core Operation Flow
Vault CPI requires two steps:- Initialise Position NFT: creates the on-chain position (one-time per position)
- Operate: a single function for all deposit, withdraw, borrow, and payback operations
1. Initialise Position NFT
Discriminator
Init Position CPI Struct
Init Position Implementation
Init Position Account Explanations
2. Operate Function
Theoperate function handles all vault operations through signed amounts:
- Positive
new_col= deposit collateral - Negative
new_col= withdraw collateral - Positive
new_debt= borrow - Negative
new_debt= payback i128::MIN= max withdraw or max payback
Discriminator
Operate CPI Struct
Operate Account Explanations
User Accounts
Vault Accounts
Position Accounts
Liquidity Integration
Remaining Accounts
Theremaining_accounts_indices vector specifies the count of each dynamic account type:
Accounts in
remaining_accounts are ordered sequentially: oracle sources first, then branches, then tick debt arrays.
Transfer Types
Operation Patterns
Deposit Only
Deposit + Borrow
Payback + Withdraw
Max Withdraw
Max Payback
Context Helpers (TypeScript)
For frontend/client code that needs to resolve CPI accounts, usegetOperateIx from the SDK. For CPI integration, execute the setup instructions before your program’s CPI call:
CPI calls to the vaults program require v0 (versioned) transactions with address lookup tables. The SDK provides
addressLookupTableAccounts for this purpose.Key Notes
Amount Scaling
- All amounts are scaled to 1e9 decimals internally
- Use
i128::MINfor max withdraw/payback operations - Positive values = deposit/borrow, negative values = withdraw/payback
Position Management
- Each position is represented by an NFT
- Position NFT must be owned by the signer for withdraw/borrow operations
- Anyone can deposit to any position or payback debt for any position
- Pass
positionId: 0togetOperateIxto auto-create a new position
Error Codes
Return Values
Theoperate function returns:
nft_id: position NFT IDnew_col_final: final collateral change amount (unscaled)new_debt_final: final debt change amount (unscaled)
