1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use codec::{Decode, Encode};
use frame_support::dispatch::DispatchError;
use primitives::{Rate, Ratio};
use scale_info::TypeInfo;
use sp_runtime::{FixedU128, RuntimeDebug};
use sp_std::prelude::*;
pub trait LoansApi<CurrencyId, AccountId, Amount> {
fn do_mint(supplier: &AccountId, amount: &Amount) -> Result<(), DispatchError>;
fn do_borrow(borrower: &AccountId, borrow: &Amount) -> Result<(), DispatchError>;
fn do_deposit_collateral(supplier: &AccountId, lend_tokens: &Amount) -> Result<(), DispatchError>;
fn do_withdraw_collateral(supplier: &AccountId, voucher: &Amount) -> Result<(), DispatchError>;
fn do_repay_borrow(borrower: &AccountId, borrow: &Amount) -> Result<(), DispatchError>;
fn do_redeem(supplier: &AccountId, amount: &Amount, voucher: &Amount) -> Result<(), DispatchError>;
fn recompute_underlying_amount(lend_tokens: &Amount) -> Result<Amount, DispatchError>;
fn underlying_id(lend_token_id: CurrencyId) -> Result<CurrencyId, DispatchError>;
fn recompute_collateral_amount(underlying: &Amount) -> Result<Amount, DispatchError>;
}
pub trait LoansMarketDataProvider<CurrencyId, Balance> {
fn get_market_info(asset_id: CurrencyId) -> Result<MarketInfo, DispatchError>;
fn get_market_status(asset_id: CurrencyId) -> Result<MarketStatus<Balance>, DispatchError>;
fn get_full_interest_rate(asset_id: CurrencyId) -> Option<Rate>;
}
#[derive(Default, Copy, Clone, Encode, Decode, RuntimeDebug, TypeInfo)]
pub struct MarketInfo {
pub collateral_factor: Ratio,
pub liquidation_threshold: Ratio,
pub reserve_factor: Ratio,
pub close_factor: Ratio,
pub full_rate: Rate,
}
#[derive(Default, Copy, Clone, Encode, Decode, RuntimeDebug, TypeInfo)]
pub struct MarketStatus<Balance> {
pub borrow_rate: Rate,
pub supply_rate: Rate,
pub exchange_rate: Rate,
pub utilization: Ratio,
pub total_borrows: Balance,
pub total_reserves: Balance,
pub borrow_index: FixedU128,
}