Skip to main content

Repaying debt on a multiply position reduces your outstanding debt balance, lowers your LTV (Loan-to-Value) ratio, and improves position health. This example shows how to repay USDC debt on a TSLAx multiply position using the Klend SDK.

Multiply Repay with xStocks

Repay debt on a TSLAx multiply position to reduce leverage and improve position health.
1

Import Dependencies

Import the required packages for Solana RPC communication, Kamino SDK operations, and transaction building.
2

Load Configuration and Initialize Market

Load the keypair and initialize the xStocks market.
3

Find TSLAx Reserve in Market

Dynamically discover the TSLAx token mint by searching the market reserves by symbol.
This dynamic discovery approach allows the code to work across different markets without hardcoding token mint addresses.
4

Configure Repay Parameters

Set the amount of USDC to repay. This example repays $10 USDC.
You can repay any amount up to your total debt. After repaying, you are able to withdraw your collateral.
5

Fetch Existing Multiply Obligation

Create the multiply obligation type and fetch the existing position from the blockchain.
The MultiplyObligation type identifies this as a leveraged position rather than a standard borrow. The obligation must exist before you can repay debt.
6

Build Repay Transaction

Use KaminoAction.buildRepayTxns to generate the repay instructions.
buildRepayTxns handles all the complexity of repaying multiply positions, including ATA creation, scope price refreshes, and obligation updates.
7

Send Transaction

Get a fresh blockhash, build the transaction, sign it, and send it to the network.
The repay transaction is complete, reducing your debt balance and improving your position’s health factor.

Borrow and Multiply SDK Methods

Multiply operations use MultiplyObligation. Vanilla operations use VanillaObligation. The obligation type determines which PDA is derived for your position.