Skip to main content

redeem_reserve_collateral

Redeem collateral tokens (cTokens) for underlying liquidity tokens from a reserve.

Signature

pub fn redeem_reserve_collateral(
    ctx: Context<RedeemReserveCollateral>,
    collateral_amount: u64
) -> Result<()>

Parameters

collateral_amount
u64
required
The amount of collateral tokens to redeem.

Accounts

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

Returns

Returns Ok(()) on success.

Errors

  • GlobalEmergencyMode: Emergency mode is enabled (via access control)
  • WithdrawTooSmall: Withdrawal amount is too small
  • InsufficientLiquidity: Reserve doesn’t have enough liquidity

deposit_obligation_collateral

Deposit collateral tokens from a user’s wallet into an obligation.

Signature

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

Parameters

collateral_amount
u64
required
The amount of collateral tokens to deposit.

Accounts

deposit_accounts.owner
Signer
required
The owner of the obligation.
deposit_accounts.obligation
AccountLoader<Obligation>
required
The obligation.
  • Must be mutable
  • Must have the specified owner
deposit_accounts.lending_market
AccountLoader<LendingMarket>
required
The lending market.
deposit_accounts.deposit_reserve
AccountLoader<Reserve>
required
The reserve for the collateral being deposited.
  • Must be mutable
deposit_accounts.reserve_destination_collateral
InterfaceAccount<TokenAccount>
required
The reserve’s collateral supply vault.
  • Must be mutable
deposit_accounts.user_source_collateral
InterfaceAccount<TokenAccount>
required
The user’s source collateral token account.
  • Must be mutable
deposit_accounts.token_program
Program<Token>
required
The SPL Token program.
deposit_accounts.instruction_sysvar_account
AccountInfo
required
The Solana instructions sysvar.
lending_market_authority
AccountInfo
required
PDA authority (v2 only).
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
  • InconsistentElevationGroup: Reserve elevation group doesn’t match obligation

withdraw_obligation_collateral

Withdraw collateral tokens from an obligation to a user’s wallet.

Signature

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

Parameters

collateral_amount
u64
required
The amount of collateral tokens to withdraw.

Accounts

withdraw_accounts.owner
Signer
required
The owner of the obligation.
  • Must be mutable (may receive rent if obligation is closed)
withdraw_accounts.obligation
AccountLoader<Obligation>
required
The obligation.
  • Must be mutable
  • Must have the specified owner
withdraw_accounts.lending_market
AccountLoader<LendingMarket>
required
The lending market.
withdraw_accounts.lending_market_authority
AccountInfo
required
PDA authority for the lending market.
withdraw_accounts.withdraw_reserve
AccountLoader<Reserve>
required
The reserve for the collateral being withdrawn.
  • Must be mutable
withdraw_accounts.reserve_source_collateral
InterfaceAccount<TokenAccount>
required
The reserve’s collateral supply vault.
  • Must be mutable
withdraw_accounts.user_destination_collateral
InterfaceAccount<TokenAccount>
required
The user’s destination collateral token account.
  • Must be mutable
  • Must have owner as authority
withdraw_accounts.token_program
Program<Token>
required
The SPL Token program.
withdraw_accounts.instruction_sysvar_account
AccountInfo
required
The Solana instructions sysvar.
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. The obligation account is automatically closed if it has no remaining deposits or borrows.

Errors

  • GlobalEmergencyMode: Emergency mode is enabled
  • WithdrawTooLarge: Withdrawal would make obligation unhealthy
  • ObligationCollateralLtvZero: Obligation has collateral with LTV=0 that must be withdrawn first
  • WorseLtvBlocked: Withdrawal would worsen the obligation’s LTV

withdraw_obligation_collateral_and_redeem_reserve_collateral

Withdraw collateral from an obligation and immediately redeem it for underlying liquidity in a single transaction.

Signature

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

Parameters

collateral_amount
u64
required
The amount of collateral tokens to withdraw and redeem.

Accounts

withdraw_accounts.owner
Signer
required
The owner of the obligation.
  • Must be mutable
withdraw_accounts.obligation
AccountLoader<Obligation>
required
The obligation.
  • Must be mutable
  • Must have the specified owner
withdraw_accounts.lending_market
AccountLoader<LendingMarket>
required
The lending market.
withdraw_accounts.lending_market_authority
AccountInfo
required
PDA authority for the lending market.
withdraw_accounts.withdraw_reserve
AccountLoader<Reserve>
required
The reserve.
  • Must be mutable
withdraw_accounts.reserve_liquidity_mint
InterfaceAccount<Mint>
required
The reserve’s liquidity token mint.
withdraw_accounts.reserve_source_collateral
InterfaceAccount<TokenAccount>
required
The reserve’s collateral supply vault.
  • Must be mutable
withdraw_accounts.reserve_collateral_mint
InterfaceAccount<Mint>
required
The reserve’s collateral token mint.
  • Must be mutable
withdraw_accounts.reserve_liquidity_supply
InterfaceAccount<TokenAccount>
required
The reserve’s liquidity supply vault.
  • Must be mutable
withdraw_accounts.user_destination_liquidity
InterfaceAccount<TokenAccount>
required
The user’s destination liquidity token account.
  • Must be mutable
  • Must have owner as authority
withdraw_accounts.collateral_token_program
Program<Token>
required
The SPL Token program.
withdraw_accounts.liquidity_token_program
Interface<TokenInterface>
required
The token program for liquidity.
withdraw_accounts.instruction_sysvar_account
AccountInfo
required
The Solana instructions sysvar.
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. The obligation account is automatically closed if it has no remaining deposits or borrows.

Errors

  • GlobalEmergencyMode: Emergency mode is enabled
  • WithdrawTooLarge: Withdrawal would make obligation unhealthy
  • InsufficientLiquidity: Reserve doesn’t have enough liquidity for redemption
  • WorseLtvBlocked: Withdrawal would worsen the obligation’s LTV

Build docs developers (and LLMs) love