pub struct ObligationContext { /* private fields */ }Expand description
A high-level context that bundles an obligation with all its reserves and auto-resolves farm accounts, providing ergonomic one-call methods for every obligation operation.
§Construction
use klend_interface::helpers::ObligationContext;
let ctx = ObligationContext::new(
obligation_address,
&obligation,
&[(reserve_addr, &reserve)],
);Implementations§
Source§impl ObligationContext
impl ObligationContext
Sourcepub fn borrow(
&self,
owner: Pubkey,
borrow_reserve: &Pubkey,
user_destination_liquidity: Pubkey,
amount: u64,
) -> Result<Vec<Instruction>, ObligationContextError>
pub fn borrow( &self, owner: Pubkey, borrow_reserve: &Pubkey, user_destination_liquidity: Pubkey, amount: u64, ) -> Result<Vec<Instruction>, ObligationContextError>
Borrow liquidity from a reserve against this obligation.
Sourcepub fn deposit(
&self,
owner: Pubkey,
reserve: &Pubkey,
user_source_liquidity: Pubkey,
amount: u64,
) -> Result<Vec<Instruction>, ObligationContextError>
pub fn deposit( &self, owner: Pubkey, reserve: &Pubkey, user_source_liquidity: Pubkey, amount: u64, ) -> Result<Vec<Instruction>, ObligationContextError>
Deposit liquidity into a reserve and credit collateral to this obligation.
Sourcepub fn withdraw(
&self,
owner: Pubkey,
reserve: &Pubkey,
user_destination_liquidity: Pubkey,
collateral_amount: u64,
) -> Result<Vec<Instruction>, ObligationContextError>
pub fn withdraw( &self, owner: Pubkey, reserve: &Pubkey, user_destination_liquidity: Pubkey, collateral_amount: u64, ) -> Result<Vec<Instruction>, ObligationContextError>
Withdraw collateral from this obligation and redeem it for liquidity.
Sourcepub fn withdraw_collateral(
&self,
owner: Pubkey,
reserve: &Pubkey,
user_destination_collateral: Pubkey,
collateral_amount: u64,
) -> Result<Vec<Instruction>, ObligationContextError>
pub fn withdraw_collateral( &self, owner: Pubkey, reserve: &Pubkey, user_destination_collateral: Pubkey, collateral_amount: u64, ) -> Result<Vec<Instruction>, ObligationContextError>
Withdraw collateral (cTokens) from this obligation without redeeming.
Sourcepub fn repay(
&self,
owner: Pubkey,
reserve: &Pubkey,
user_source_liquidity: Pubkey,
amount: u64,
) -> Result<Vec<Instruction>, ObligationContextError>
pub fn repay( &self, owner: Pubkey, reserve: &Pubkey, user_source_liquidity: Pubkey, amount: u64, ) -> Result<Vec<Instruction>, ObligationContextError>
Repay borrowed liquidity.
Sourcepub fn repay_and_withdraw(
&self,
owner: Pubkey,
repay_reserve: &Pubkey,
withdraw_reserve: &Pubkey,
user_source_liquidity: Pubkey,
user_destination_liquidity: Pubkey,
repay_amount: u64,
withdraw_collateral_amount: u64,
) -> Result<Vec<Instruction>, ObligationContextError>
pub fn repay_and_withdraw( &self, owner: Pubkey, repay_reserve: &Pubkey, withdraw_reserve: &Pubkey, user_source_liquidity: Pubkey, user_destination_liquidity: Pubkey, repay_amount: u64, withdraw_collateral_amount: u64, ) -> Result<Vec<Instruction>, ObligationContextError>
Atomically repay a borrow, withdraw collateral, and redeem it for liquidity.
Sourcepub fn deposit_and_withdraw(
&self,
owner: Pubkey,
deposit_reserve: &Pubkey,
withdraw_reserve: &Pubkey,
user_source_liquidity: Pubkey,
user_destination_liquidity: Pubkey,
deposit_amount: u64,
withdraw_collateral_amount: u64,
) -> Result<Vec<Instruction>, ObligationContextError>
pub fn deposit_and_withdraw( &self, owner: Pubkey, deposit_reserve: &Pubkey, withdraw_reserve: &Pubkey, user_source_liquidity: Pubkey, user_destination_liquidity: Pubkey, deposit_amount: u64, withdraw_collateral_amount: u64, ) -> Result<Vec<Instruction>, ObligationContextError>
Atomically deposit to one reserve and withdraw from another (rebalancing).
Sourcepub fn liquidate(
&self,
liquidator: Pubkey,
repay_reserve: &Pubkey,
withdraw_reserve: &Pubkey,
user_source_liquidity: Pubkey,
user_destination_collateral: Pubkey,
user_destination_liquidity: Pubkey,
amount: u64,
min_received: u64,
max_ltv_override: u64,
) -> Result<Vec<Instruction>, ObligationContextError>
pub fn liquidate( &self, liquidator: Pubkey, repay_reserve: &Pubkey, withdraw_reserve: &Pubkey, user_source_liquidity: Pubkey, user_destination_collateral: Pubkey, user_destination_liquidity: Pubkey, amount: u64, min_received: u64, max_ltv_override: u64, ) -> Result<Vec<Instruction>, ObligationContextError>
Liquidate an undercollateralized obligation.
Sourcepub fn request_elevation_group(
&self,
owner: Pubkey,
elevation_group: u8,
) -> Vec<Instruction>
pub fn request_elevation_group( &self, owner: Pubkey, elevation_group: u8, ) -> Vec<Instruction>
Request an elevation group change for this obligation.
Source§impl ObligationContext
impl ObligationContext
Sourcepub fn new(
obligation_address: Pubkey,
obligation: &Obligation,
reserves: &[(Pubkey, &Reserve)],
) -> Self
pub fn new( obligation_address: Pubkey, obligation: &Obligation, reserves: &[(Pubkey, &Reserve)], ) -> Self
Build a context from deserialized on-chain accounts.
Sourcepub fn reserve_addresses_for_obligation(
obligation_data: &[u8],
) -> Result<Vec<Pubkey>, AccountDataError>
pub fn reserve_addresses_for_obligation( obligation_data: &[u8], ) -> Result<Vec<Pubkey>, AccountDataError>
Parse an obligation and return the unique reserve addresses that must be fetched to build a complete context.
Typical RPC flow:
- Fetch the obligation account
- Call
reserve_addresses_for_obligationto discover which reserves are needed - Fetch those reserve accounts (e.g.
getMultipleAccounts) - Call
ObligationContext::from_account_datawith both
Sourcepub fn from_account_data(
obligation_address: Pubkey,
obligation_data: &[u8],
reserves: &[(Pubkey, &[u8])],
) -> Result<Self, AccountDataError>
pub fn from_account_data( obligation_address: Pubkey, obligation_data: &[u8], reserves: &[(Pubkey, &[u8])], ) -> Result<Self, AccountDataError>
Build a context from raw on-chain account data bytes.
reserves must include an entry for every reserve referenced by the
obligation (see ObligationContext::reserve_addresses_for_obligation).
Extra reserves are allowed and will be available for lookups.
Sourcepub fn from_infos(
lending_market: Pubkey,
obligation: ObligationInfo,
reserves: &[ReserveInfo],
) -> Self
pub fn from_infos( lending_market: Pubkey, obligation: ObligationInfo, reserves: &[ReserveInfo], ) -> Self
Build a context from pre-built ReserveInfo values (no farm auto-resolution).
Use this when you already have ReserveInfo and ObligationInfo constructed
from another source, or when farm accounts are not needed.
Sourcepub fn obligation(&self) -> &ObligationInfo
pub fn obligation(&self) -> &ObligationInfo
Get the obligation info.
Sourcepub fn reserve_info(&self, address: &Pubkey) -> Option<&ReserveInfo>
pub fn reserve_info(&self, address: &Pubkey) -> Option<&ReserveInfo>
Look up a reserve by address.
Trait Implementations§
Source§impl Clone for ObligationContext
impl Clone for ObligationContext
Source§fn clone(&self) -> ObligationContext
fn clone(&self) -> ObligationContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more