Skip to main content
This guide covers Cross-Program Invocation (CPI) integration for the Borrow protocol’s vault operations. Use this when your on-chain program needs to call Jupiter Lend Borrow directly. For TypeScript SDK integration (off-chain), see Create Position, Deposit, Borrow, Repay, and Withdraw.

Program Addresses


Core Operation Flow

Vault CPI requires two steps:
  1. Initialise Position NFT: creates the on-chain position (one-time per position)
  2. 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

The operate 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

The remaining_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, use getOperateIx from the SDK. For CPI integration, execute the setup instructions before your program’s CPI call:
Then pass the resolved accounts into your Anchor program:
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::MIN for 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: 0 to getOperateIx to auto-create a new position

Error Codes

Return Values

The operate function returns:
  • nft_id: position NFT ID
  • new_col_final: final collateral change amount (unscaled)
  • new_debt_final: final debt change amount (unscaled)