templar_common::market

Trait MarketExternalInterface

Source
pub trait MarketExternalInterface {
Show 23 methods // Required methods fn get_configuration(&self) -> MarketConfiguration; fn get_current_snapshot(&self) -> Snapshot; fn get_finalized_snapshots_len(&self) -> u32; fn list_finalized_snapshots( &self, offset: Option<u32>, count: Option<u32>, ) -> Vec<&Snapshot>; fn get_borrow_asset_metrics(&self) -> BorrowAssetMetrics; fn list_borrow_positions( &self, offset: Option<u32>, count: Option<u32>, ) -> HashMap<AccountId, BorrowPosition>; fn get_borrow_position( &self, account_id: AccountId, ) -> Option<BorrowPosition>; fn get_borrow_status( &self, account_id: AccountId, oracle_response: OracleResponse, ) -> Option<BorrowStatus>; fn borrow(&mut self, amount: BorrowAssetAmount) -> Promise; fn withdraw_collateral(&mut self, amount: CollateralAssetAmount) -> Promise; fn apply_interest( &mut self, account_id: Option<AccountId>, snapshot_limit: Option<u32>, ); fn list_supply_positions( &self, offset: Option<u32>, count: Option<u32>, ) -> HashMap<AccountId, SupplyPosition>; fn get_supply_position( &self, account_id: AccountId, ) -> Option<SupplyPosition>; fn create_supply_withdrawal_request(&mut self, amount: BorrowAssetAmount); fn cancel_supply_withdrawal_request(&mut self); fn execute_next_supply_withdrawal_request(&mut self) -> PromiseOrValue<()>; fn get_supply_withdrawal_request_status( &self, account_id: AccountId, ) -> Option<WithdrawalRequestStatus>; fn get_supply_withdrawal_queue_status(&self) -> WithdrawalQueueStatus; fn harvest_yield( &mut self, account_id: Option<AccountId>, mode: Option<HarvestYieldMode>, ) -> BorrowAssetAmount; fn get_last_yield_rate(&self) -> Decimal; fn get_static_yield( &self, account_id: AccountId, ) -> Option<Accumulator<BorrowAsset>>; fn accumulate_static_yield( &mut self, account_id: Option<AccountId>, snapshot_limit: Option<u32>, ); fn withdraw_static_yield( &mut self, amount: Option<BorrowAssetAmount>, ) -> Promise;
}

Required Methods§

Source

fn get_configuration(&self) -> MarketConfiguration

Retrieve the market configuration.

Source

fn get_current_snapshot(&self) -> Snapshot

Retrieve the current snapshot (in progress; not yet finalized).

Source

fn get_finalized_snapshots_len(&self) -> u32

Retrieve the count of finalized snapshots.

Source

fn list_finalized_snapshots( &self, offset: Option<u32>, count: Option<u32>, ) -> Vec<&Snapshot>

Retrieve a list of finalized snapshots.

Source

fn get_borrow_asset_metrics(&self) -> BorrowAssetMetrics

Retrieve current contract metrics about borrow asset deposit, availability, usage, etc.

Source

fn list_borrow_positions( &self, offset: Option<u32>, count: Option<u32>, ) -> HashMap<AccountId, BorrowPosition>

Retrieve a map of borrow positions.

Source

fn get_borrow_position(&self, account_id: AccountId) -> Option<BorrowPosition>

Retrieve a specific borrow position, with estimated fees.

This function may report fees slightly inaccurately. This is because the function has to estimate what fees will be applied between the last finalized market snapshot and the (present) time when the function was called.

Source

fn get_borrow_status( &self, account_id: AccountId, oracle_response: OracleResponse, ) -> Option<BorrowStatus>

Retrieves the status of a borrow position (healthy or in liquidation) given some asset prices.

This is just a read-only function, so it does not validate the price data. It is intended to be called by liquidators so they can easily see whether a position is eligible for liquidation.

Source

fn borrow(&mut self, amount: BorrowAssetAmount) -> Promise

Transfers amount of borrow asset tokens to the caller, provided their borrow position will still be sufficiently collateralized.

Source

fn withdraw_collateral(&mut self, amount: CollateralAssetAmount) -> Promise

Transfers amount of collateral asset tokens to the caller, provided their borrow position will still be sufficiently collateralized.

Source

fn apply_interest( &mut self, account_id: Option<AccountId>, snapshot_limit: Option<u32>, )

Applies interest to the predecessor’s borrow record. Not likely to be used in real life, since there it does not affect the final interest calculation, and rounds fractional interest UP.

Source

fn list_supply_positions( &self, offset: Option<u32>, count: Option<u32>, ) -> HashMap<AccountId, SupplyPosition>

Retrieves a set of supply positions.

Source

fn get_supply_position(&self, account_id: AccountId) -> Option<SupplyPosition>

Retrieves a supply position record, with estimated yield.

Source

fn create_supply_withdrawal_request(&mut self, amount: BorrowAssetAmount)

Enters a supply position into the withdrawal queue, requesting to withdraw amount borrow asset tokens.

If the account is already in the queue, it will be moved to the back of the queue with the updated amount.

Source

fn cancel_supply_withdrawal_request(&mut self)

Removes a supply position from the withdrawal queue.

Source

fn execute_next_supply_withdrawal_request(&mut self) -> PromiseOrValue<()>

Attempts to fulfill the first withdrawal request in the queue.

Source

fn get_supply_withdrawal_request_status( &self, account_id: AccountId, ) -> Option<WithdrawalRequestStatus>

Retrieves the status of a withdrawal request in the queue.

Source

fn get_supply_withdrawal_queue_status(&self) -> WithdrawalQueueStatus

Retrieves the status of the withdrawal queue.

Source

fn harvest_yield( &mut self, account_id: Option<AccountId>, mode: Option<HarvestYieldMode>, ) -> BorrowAssetAmount

Claim any distributed yield to the supply record. If mode is set to HarvestYieldMode::Compounding, the all of the yield (including any harvested in previous, non-compounding harvest_yield calls) will be deposited to the supply record, so it can be withdrawn and will contribute to future yield calculations.

Source

fn get_last_yield_rate(&self) -> Decimal

This value is an expected average over time. Supply positions actually earn all of their yield the instant it is distributed.

Source

fn get_static_yield( &self, account_id: AccountId, ) -> Option<Accumulator<BorrowAsset>>

Retrieves the amount of yield earned by an account statically configured to earn yield (e.g. MarketConfiguration::yield_weights or MarketConfiguration::protocol_account_id).

Source

fn accumulate_static_yield( &mut self, account_id: Option<AccountId>, snapshot_limit: Option<u32>, )

Accumulates yield for an account that earns static yield.

Source

fn withdraw_static_yield( &mut self, amount: Option<BorrowAssetAmount>, ) -> Promise

Attempts to withdraw the amount of yield earned by an account statically configured to earn yield (e.g. MarketConfiguration::yield_weights or MarketConfiguration::protocol_account_id).

Calls to this function should be preceded by calls to MarketExternalInterface::accumulate_static_yield.

Implementors§