Skip to main content

init_obligation

Initialize a new obligation (user lending position) in a lending market.

Signature

pub fn init_obligation(
    ctx: Context<InitObligation>,
    args: InitObligationArgs
) -> Result<()>

Parameters

args
InitObligationArgs
required
Initialization arguments containing:
  • tag: u8 - The obligation type tag (0-3)
    • 0: Default (no seed accounts)
    • 1: Two mint seeds
    • 2: Single mint seed (repeated)
    • 3: Two mint seeds (same as 1)
  • id: u8 - The obligation ID (must be 0 for current version)

Accounts

obligation_owner
Signer
required
The owner of the obligation.
fee_payer
Signer
required
The account paying for initialization.
  • Must be mutable
obligation
AccountLoader<Obligation>
required
The obligation account to initialize.
  • Seeds: [[tag], [id], obligation_owner.key(), lending_market.key(), seed1_account.key(), seed2_account.key()]
  • Initialized by this instruction
lending_market
AccountLoader<LendingMarket>
required
The lending market this obligation belongs to.
seed1_account
AccountInfo
required
First seed account (must be default pubkey for tag 0, mint for tags 1-3).
seed2_account
AccountInfo
required
Second seed account (must be default pubkey for tag 0, mint for tags 1 and 3, same as seed1 for tag 2).
owner_user_metadata
AccountLoader<UserMetadata>
required
The owner’s user metadata account (for referrer tracking).
  • Seeds: ["user_metadata", obligation_owner.key()]

Returns

Returns Ok(()) on success.

Errors

  • InvalidObligationSeedsValue: Seed accounts don’t match the tag requirements
  • Standard Anchor errors if account validation fails

init_obligation_farms_for_reserve

Initialize farming state for an obligation on a specific reserve.

Signature

pub fn init_obligation_farms_for_reserve(
    ctx: Context<InitObligationFarmsForReserve>,
    mode: u8
) -> Result<()>

Parameters

mode
u8
required
The farm type:
  • 0: Collateral farming
  • 1: Debt farming

Accounts

payer
Signer
required
The account paying for initialization.
  • Must be mutable
owner
AccountInfo
required
The owner of the obligation.
obligation
AccountLoader<Obligation>
required
The obligation.
  • Must be mutable
  • Must have the specified owner
lending_market_authority
AccountInfo
required
PDA authority for the lending market.
reserve
AccountLoader<Reserve>
required
The reserve.
  • Must be mutable
reserve_farm_state
AccountInfo
required
The farm state account for the reserve.
  • Must be mutable
  • Must match the reserve’s stored farm for the specified mode
obligation_farm
AccountInfo
required
The obligation’s farm account (initialized via CPI).
  • Must be mutable
lending_market
AccountLoader<LendingMarket>
required
The lending market.
farms_program
Program<Farms>
required
The Kamino Farms program.

Returns

Returns Ok(()) on success.

Errors

  • ReserveObsolete: Reserve is marked as obsolete
  • ReserveDeprecated: Reserve version is outdated
  • NoFarmForReserve: Reserve doesn’t have a farm for the specified mode
  • InvalidAccountInput: Farm state account doesn’t match reserve’s stored farm

refresh_obligation

Refresh an obligation’s state, recalculating borrowed and deposited values based on current reserve states.

Signature

pub fn refresh_obligation(
    ctx: Context<RefreshObligation>
) -> Result<()>

Parameters

None.

Accounts

lending_market
AccountLoader<LendingMarket>
required
The lending market.
obligation
AccountLoader<Obligation>
required
The obligation to refresh.
  • Must be mutable
  • Must belong to the lending market

Remaining Accounts

Provide accounts in this order:
  1. All deposit reserve accounts (in order of obligation deposits)
  2. All borrow reserve accounts (in order of obligation borrows)
  3. If obligation has a referrer: referrer token state accounts for each borrow reserve

Returns

Returns Ok(()) on success.

Errors

  • InvalidAccountInput: Wrong number or order of remaining accounts
  • GlobalEmergencyMode: Emergency mode is enabled (via access control)

refresh_obligation_farms_for_reserve

Refresh the farming state for an obligation on a specific reserve.

Signature

pub fn refresh_obligation_farms_for_reserve(
    ctx: Context<RefreshObligationFarmsForReserve>,
    mode: u8
) -> Result<()>

Parameters

mode
u8
required
The farm type:
  • 0: Collateral farming
  • 1: Debt farming

Accounts

crank
Signer
required
Any account (anyone can refresh farms).
base_accounts.obligation
AccountInfo
required
The obligation account.
base_accounts.lending_market_authority
AccountInfo
required
PDA authority for the lending market.
base_accounts.reserve
AccountLoader<Reserve>
required
The reserve.
base_accounts.reserve_farm_state
AccountInfo
required
The farm state account for the reserve.
  • Must be mutable
base_accounts.obligation_farm_user_state
AccountLoader<FarmsUserState>
required
The obligation’s farm user state.
  • Must be mutable
  • Must have delegatee matching the obligation
base_accounts.lending_market
AccountLoader<LendingMarket>
required
The lending market.
farms_program
Program<Farms>
required
The Kamino Farms program.

Returns

Returns Ok(()) on success.

Errors

  • NoFarmForReserve: Reserve doesn’t have a farm for the specified mode
  • InvalidAccountInput: Farm state or obligation farm doesn’t match expected values
  • GlobalEmergencyMode: Emergency mode is enabled (via access control)

Build docs developers (and LLMs) love