Skip to main content

deposit_reserve_liquidity

Deposit liquidity tokens into a reserve and receive collateral tokens (cTokens) in return.

Signature

pub fn deposit_reserve_liquidity(
    ctx: Context<DepositReserveLiquidity>,
    liquidity_amount: u64
) -> Result<()>

Parameters

liquidity_amount
u64
required
The amount of liquidity to deposit (in token native units).

Accounts

owner
Signer
required
The owner of the source liquidity tokens.
reserve
AccountLoader<Reserve>
required
The reserve to deposit into.
  • Must be mutable
lending_market
AccountLoader<LendingMarket>
required
The lending market.
lending_market_authority
AccountInfo
required
PDA authority for the lending market.
reserve_liquidity_mint
InterfaceAccount<Mint>
required
The reserve’s liquidity token mint.
reserve_liquidity_supply
InterfaceAccount<TokenAccount>
required
The reserve’s liquidity supply vault.
  • Must be mutable
reserve_collateral_mint
InterfaceAccount<Mint>
required
The reserve’s collateral token mint.
  • Must be mutable
user_source_liquidity
InterfaceAccount<TokenAccount>
required
The user’s source liquidity token account.
  • Must be mutable
user_destination_collateral
InterfaceAccount<TokenAccount>
required
The user’s destination collateral token account.
  • Must be mutable
collateral_token_program
Program<Token>
required
The SPL Token program (for collateral).
liquidity_token_program
Interface<TokenInterface>
required
The token program for liquidity (SPL Token or Token-2022).
instruction_sysvar_account
AccountInfo
required
The Solana instructions sysvar.

Returns

Returns Ok(()) on success.

Errors

  • GlobalEmergencyMode: Emergency mode is enabled (via access control)
  • WithdrawTooSmall: Deposit amount is too small
  • DepositLimitExceeded: Deposit would exceed reserve’s deposit limit

deposit_reserve_liquidity_and_obligation_collateral

Deposit liquidity into a reserve and immediately add the collateral to an obligation in a single transaction.

Signature

pub fn deposit_reserve_liquidity_and_obligation_collateral_v2(
    ctx: Context<DepositReserveLiquidityAndObligationCollateralV2>,
    liquidity_amount: u64
) -> Result<()>
Use the v2 variant which includes farming support. The v1 variant is deprecated.

Parameters

liquidity_amount
u64
required
The amount of liquidity to deposit.

Accounts

deposit_accounts.owner
Signer
required
The owner of the obligation and source liquidity.
  • Must be mutable
deposit_accounts.obligation
AccountLoader<Obligation>
required
The obligation to add collateral to.
  • Must be mutable
  • Must have the specified owner
deposit_accounts.lending_market
AccountLoader<LendingMarket>
required
The lending market.
deposit_accounts.lending_market_authority
AccountInfo
required
PDA authority for the lending market.
deposit_accounts.reserve
AccountLoader<Reserve>
required
The reserve.
  • Must be mutable
deposit_accounts.reserve_liquidity_mint
InterfaceAccount<Mint>
required
The reserve’s liquidity token mint.
deposit_accounts.reserve_liquidity_supply
InterfaceAccount<TokenAccount>
required
The reserve’s liquidity supply vault.
  • Must be mutable
deposit_accounts.reserve_collateral_mint
InterfaceAccount<Mint>
required
The reserve’s collateral token mint.
  • Must be mutable
deposit_accounts.reserve_destination_deposit_collateral
InterfaceAccount<TokenAccount>
required
The reserve’s collateral supply vault.
  • Must be mutable
deposit_accounts.user_source_liquidity
InterfaceAccount<TokenAccount>
required
The user’s source liquidity token account.
  • Must be mutable
farms_accounts
OptionalObligationFarmsAccounts
required
Optional farming accounts (v2 only).
farms_program
Program<Farms>
required
The Kamino Farms program (v2 only).

Returns

Returns Ok(()) on success.

Errors

  • GlobalEmergencyMode: Emergency mode is enabled
  • ObligationReserveLimit: Obligation has too many different collateral types
  • IsolatedAssetTierViolation: Collateral violates isolated asset rules

borrow_obligation_liquidity

Borrow liquidity from a reserve against an obligation’s collateral.

Signature

pub fn borrow_obligation_liquidity_v2<'info>(
    ctx: Context<'_, '_, '_, 'info, BorrowObligationLiquidityV2<'info>>,
    liquidity_amount: u64
) -> Result<()>
Use the v2 variant which includes farming support. The v1 variant is deprecated.

Parameters

liquidity_amount
u64
required
The amount of liquidity to borrow. Use u64::MAX to borrow the maximum available.

Accounts

borrow_accounts.owner
Signer
required
The owner of the obligation.
borrow_accounts.obligation
AccountLoader<Obligation>
required
The obligation.
  • Must be mutable
  • Must have the specified owner
borrow_accounts.lending_market
AccountLoader<LendingMarket>
required
The lending market.
borrow_accounts.lending_market_authority
AccountInfo
required
PDA authority for the lending market.
borrow_accounts.borrow_reserve
AccountLoader<Reserve>
required
The reserve to borrow from.
  • Must be mutable
borrow_accounts.borrow_reserve_liquidity_mint
InterfaceAccount<Mint>
required
The borrow reserve’s liquidity token mint.
borrow_accounts.reserve_source_liquidity
InterfaceAccount<TokenAccount>
required
The reserve’s liquidity supply vault.
  • Must be mutable
borrow_accounts.borrow_reserve_liquidity_fee_receiver
InterfaceAccount<TokenAccount>
required
The reserve’s fee receiver vault.
  • Must be mutable
borrow_accounts.user_destination_liquidity
InterfaceAccount<TokenAccount>
required
The user’s destination liquidity token account.
  • Must be mutable
  • Must have owner as authority
borrow_accounts.referrer_token_state
Option<AccountLoader<ReferrerTokenState>>
required
Optional referrer token state (required if obligation has a referrer).
  • Must be mutable
borrow_accounts.token_program
Interface<TokenInterface>
required
The token program.
farms_accounts
OptionalObligationFarmsAccounts
required
Optional farming accounts (v2 only).
farms_program
Program<Farms>
required
The Kamino Farms program (v2 only).

Remaining Accounts

All deposit reserves for the obligation (to calculate collateral value).

Returns

Returns Ok(()) on success.

Errors

  • GlobalEmergencyMode: Emergency mode is enabled
  • BorrowTooSmall: Borrow amount is too small
  • BorrowTooLarge: Insufficient collateral for borrow
  • InsufficientLiquidity: Reserve doesn’t have enough liquidity
  • BorrowingDisabled: Borrowing is disabled globally or for this reserve
  • ReferrerAccountMissing: Obligation has referrer but no referrer account provided

repay_obligation_liquidity

Repay borrowed liquidity for an obligation.

Signature

pub fn repay_obligation_liquidity_v2(
    ctx: Context<RepayObligationLiquidityV2>,
    liquidity_amount: u64
) -> Result<()>
Use the v2 variant which includes farming support. The v1 variant is deprecated.

Parameters

liquidity_amount
u64
required
The amount of liquidity to repay. Use u64::MAX to repay all.

Accounts

repay_accounts.owner
Signer
required
The owner of the obligation (or anyone repaying on their behalf).
repay_accounts.obligation
AccountLoader<Obligation>
required
The obligation.
  • Must be mutable
repay_accounts.lending_market
AccountLoader<LendingMarket>
required
The lending market.
repay_accounts.repay_reserve
AccountLoader<Reserve>
required
The reserve to repay.
  • Must be mutable
repay_accounts.reserve_liquidity_mint
InterfaceAccount<Mint>
required
The reserve’s liquidity token mint.
repay_accounts.reserve_destination_liquidity
InterfaceAccount<TokenAccount>
required
The reserve’s liquidity supply vault.
  • Must be mutable
repay_accounts.user_source_liquidity
InterfaceAccount<TokenAccount>
required
The user’s source liquidity token account.
  • Must be mutable
repay_accounts.token_program
Interface<TokenInterface>
required
The token program.
farms_accounts
OptionalObligationFarmsAccounts
required
Optional farming accounts (v2 only).
lending_market_authority
AccountInfo
required
PDA authority (v2 only).
farms_program
Program<Farms>
required
The Kamino Farms program (v2 only).

Remaining Accounts

All deposit reserves for the obligation (to update health factor).

Returns

Returns Ok(()) on success.

Errors

  • RepayTooSmall: Repay amount is too small
  • TransactionIncludesRestrictedPrograms: Transaction contains restricted programs

flash_borrow_reserve_liquidity

Borrow liquidity from a reserve with a flash loan. Must be repaid in the same transaction with flash_repay_reserve_liquidity.

Signature

pub fn flash_borrow_reserve_liquidity(
    ctx: Context<FlashBorrowReserveLiquidity>,
    liquidity_amount: u64
) -> Result<()>

Parameters

liquidity_amount
u64
required
The amount of liquidity to flash borrow.

Accounts

user_transfer_authority
Signer
required
The authority for the user’s token account.
lending_market_authority
AccountInfo
required
PDA authority for the lending market.
lending_market
AccountLoader<LendingMarket>
required
The lending market.
reserve
AccountLoader<Reserve>
required
The reserve to borrow from.
  • Must be mutable
reserve_liquidity_mint
InterfaceAccount<Mint>
required
The reserve’s liquidity token mint.
reserve_source_liquidity
InterfaceAccount<TokenAccount>
required
The reserve’s liquidity supply vault.
  • Must be mutable
user_destination_liquidity
InterfaceAccount<TokenAccount>
required
The user’s destination liquidity token account.
  • Must be mutable
reserve_liquidity_fee_receiver
InterfaceAccount<TokenAccount>
required
The reserve’s fee receiver vault.
  • Must be mutable
referrer_token_state
Option<AccountLoader<ReferrerTokenState>>
required
Optional referrer token state.
  • Must be mutable
sysvar_info
AccountInfo
required
The Solana instructions sysvar.

Returns

Returns Ok(()) on success.

Errors

  • GlobalEmergencyMode: Emergency mode is enabled
  • FlashLoansDisabled: Flash loans are disabled for this reserve
  • FlashBorrowCpi: Flash borrows cannot be called via CPI
  • MultipleFlashBorrows: Multiple flash borrows in same transaction

flash_repay_reserve_liquidity

Repay a flash loan borrowed with flash_borrow_reserve_liquidity.

Signature

pub fn flash_repay_reserve_liquidity(
    ctx: Context<FlashRepayReserveLiquidity>,
    liquidity_amount: u64,
    borrow_instruction_index: u8
) -> Result<()>

Parameters

liquidity_amount
u64
required
The amount originally borrowed (fees are added automatically).
borrow_instruction_index
u8
required
The index in the transaction of the corresponding flash_borrow_reserve_liquidity instruction.

Accounts

user_transfer_authority
Signer
required
The authority for the user’s token account.
lending_market_authority
AccountInfo
required
PDA authority for the lending market.
lending_market
AccountLoader<LendingMarket>
required
The lending market.
reserve
AccountLoader<Reserve>
required
The reserve.
  • Must be mutable
reserve_liquidity_mint
InterfaceAccount<Mint>
required
The reserve’s liquidity token mint.
reserve_destination_liquidity
InterfaceAccount<TokenAccount>
required
The reserve’s liquidity supply vault.
  • Must be mutable
user_source_liquidity
InterfaceAccount<TokenAccount>
required
The user’s source liquidity token account.
  • Must be mutable
reserve_liquidity_fee_receiver
InterfaceAccount<TokenAccount>
required
The reserve’s fee receiver vault.
  • Must be mutable
referrer_token_state
Option<AccountLoader<ReferrerTokenState>>
required
Optional referrer token state.
  • Must be mutable
sysvar_info
AccountInfo
required
The Solana instructions sysvar.

Returns

Returns Ok(()) on success.

Errors

  • GlobalEmergencyMode: Emergency mode is enabled
  • NoFlashRepayFound: No matching flash borrow found
  • InvalidFlashRepay: Repay doesn’t match borrow
  • FlashRepayCpi: Flash repays cannot be called via CPI

Build docs developers (and LLMs) love