Skip to main content

Repay Debt

Repay borrowed assets to improve your position health.
1

Import Dependencies

2

Load Market and Initialize RPC

3

Load the Obligation

Load the wallet’s borrow position so the SDK refreshes every reserve it uses.
4

Build Repay Instructions

Repay part of the USDT loan from the USDT in the wallet.
To repay the whole loan including accrued interest, pass new BN(U64_MAX) as the amount (U64_MAX is exported by the SDK). The program repays the exact debt, so no dust is left.
5

Build the Transaction

6

Sign and Send

The debt in the borrow position is reduced.

Withdraw Collateral

Withdraw collateral from your obligation.
1

Import Dependencies

2

Load Market and Initialize RPC

3

Load the Obligation

Load the wallet’s borrow position so the SDK refreshes every reserve it uses.
4

Build Withdraw Instructions

Withdraw USDC collateral from the borrow position.
With open borrows, the withdrawal must keep the position under its borrow limit. To withdraw all of a deposit, pass new BN(U64_MAX) as the amount.
5

Build the Transaction

6

Sign and Send

The collateral is back in the wallet.