Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lending protocol #737

Merged
merged 64 commits into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
0224470
feat(lend): add lending protocol crates
daniel-savu Sep 19, 2022
30100fe
feat(lend): get unit tests to run
daniel-savu Sep 19, 2022
9122745
feat(lend): use orml-tokens instead of pallet-assets
daniel-savu Sep 20, 2022
d1be241
feat(lend): configure lending pallet
daniel-savu Sep 20, 2022
66b4572
chore: bump toolchain to match lending pallet
daniel-savu Sep 20, 2022
d45d68d
chore: fix toml files
daniel-savu Sep 20, 2022
8ad2319
fix(lend): PriceFeeder trait import
daniel-savu Sep 21, 2022
64af00e
feat(lend): add loans pallet to standalone runtime
daniel-savu Sep 21, 2022
89a6032
chore(lend): remove liquidate-free collateral
daniel-savu Sep 21, 2022
590a405
fix(lend): btc oracle integration, notes on integrating pTokens with …
daniel-savu Sep 22, 2022
cf8a1b0
refactor(lend): cleanup
daniel-savu Oct 7, 2022
7c41e20
feat(lend): update benchmarks and copyrights
daniel-savu Oct 7, 2022
a70aa8e
fix(lend): attempt to fix benchmarks
daniel-savu Oct 10, 2022
81d925a
fix(lend): fmt
daniel-savu Oct 10, 2022
50fd3a7
fix(lend): cleanup
daniel-savu Oct 10, 2022
bca36ff
feat(loans): import orml pallet with hooks feature
daniel-savu Oct 11, 2022
32c204e
feat(loans): add currency pallet
daniel-savu Oct 11, 2022
409bb8b
feat(loans): split do_collateral_asset
daniel-savu Oct 11, 2022
1d509e9
Merge pull request #1 from interlay/dan/lend
gregdhill Oct 13, 2022
139a314
feat(loans): fully tokenize ptokens
daniel-savu Oct 13, 2022
9ec2ed0
feat(loans): Replace T::Asset actions with Currency pallet
daniel-savu Oct 13, 2022
7fd05bb
feat(loans): clean up ptoken module
daniel-savu Oct 13, 2022
25bec4e
feat(loans): replace local orml-tokens fork with interlay repo
daniel-savu Oct 13, 2022
481957b
Merge branch 'master' into dan/orml-ptoken
daniel-savu Oct 13, 2022
1b6d0b2
fix(loans): fix all local orml imports
daniel-savu Oct 13, 2022
a4331b2
fix(loans): benchmark
daniel-savu Oct 13, 2022
815c53f
chore(loans): cleanup and added comments
daniel-savu Oct 14, 2022
4b94319
fix(loans): don't propagate on_slash errors; feature-gate test utils
daniel-savu Oct 14, 2022
e3215ef
fix(loans): use a weghts-v1 compatible orml dependency
daniel-savu Oct 14, 2022
e18c703
feat(loans): ptokens as currency id
daniel-savu Oct 17, 2022
a7028c2
feat(loans): ptoken oracle integration
daniel-savu Oct 18, 2022
156a472
feat(primitives): is_ctoken associated method
daniel-savu Oct 19, 2022
cc9ac77
Merge pull request #2 from interlay/dan/orml-ptoken
gregdhill Oct 19, 2022
5cc1cf0
Merge branch 'master' into dan/ptokens-currency
daniel-savu Oct 19, 2022
6283dab
feat(loans): min and max exchange rates as storage items
daniel-savu Oct 19, 2022
85c1bf5
feat(loans): pToken integration tests for issue and redeem
daniel-savu Oct 19, 2022
551692c
feat(loans): nomination integration tests with ptokens collateral
daniel-savu Oct 19, 2022
0b4eef5
chore(loans): improve comments, remove test duplication
daniel-savu Oct 20, 2022
84adbd3
refactor(loans): default CurrencyConversion implementation; remove un…
daniel-savu Oct 20, 2022
2d18a24
fix(loans): replace and vault registry integration tests
daniel-savu Oct 20, 2022
442cfa6
test(loans): replace with pToken collateral
daniel-savu Oct 20, 2022
f88e61d
Merge pull request #3 from interlay/dan/ptokens-currency
daniel-savu Oct 21, 2022
c4f7aa3
feat(loans): add lending to testnet runtimes
daniel-savu Oct 21, 2022
043d6bf
test(loans): lockable ptokens, lending edge cases
daniel-savu Oct 24, 2022
2395d35
chore(loans): move tests to interest rate file
daniel-savu Oct 25, 2022
716f51d
test(loans): orml ptoken tests
daniel-savu Oct 25, 2022
e13c0fa
chore(loans): rename to `compute_collateral_amount`, add market cap, …
daniel-savu Oct 27, 2022
17b5e31
chore(loans): comments, Rate default impl
daniel-savu Oct 27, 2022
d32db00
refactor(loans): ptokens to lend_tokens
daniel-savu Oct 27, 2022
0b49fcd
refactor(loans): use interlay assets in tests
daniel-savu Oct 27, 2022
68e0ae7
chore(loans): remove leftover liquidation-free code
daniel-savu Oct 27, 2022
e6bcfda
chore(loans): fix tests
daniel-savu Oct 27, 2022
ef6a7cb
fix(loans): warnings
daniel-savu Oct 27, 2022
147ade7
Merge branch 'master' of https://github.com/interlay/interbtc into da…
daniel-savu Oct 27, 2022
e7cf4f4
feat: use latest orml
daniel-savu Oct 27, 2022
bbc912d
fix(loans): upgrade polkadot
daniel-savu Oct 27, 2022
f40383c
fix(loans): reset storage version
daniel-savu Oct 28, 2022
c089ac3
test(loans): zero amount extrinsics
daniel-savu Oct 28, 2022
df3a2d9
test(loans): improve comments for tests.rs
daniel-savu Oct 28, 2022
d8a6824
chore(loans): remove comment typo
daniel-savu Oct 31, 2022
ca6eccf
fix(loans): failing test and warnings
daniel-savu Nov 2, 2022
acc03a7
feat(loans): calculate liquidity with checked math
daniel-savu Nov 4, 2022
6f88113
fix(loans): add missing copyright and authorship acks; reuse Arithmet…
daniel-savu Nov 4, 2022
13e038e
fix(loans): use currency hooks on testnet; refactor constants; improv…
daniel-savu Nov 8, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
473 changes: 308 additions & 165 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions crates/currency/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ pallet-transaction-payment = { git = "https://github.com/paritytech/substrate",

# Parachain dependencies
primitives = { package = "interbtc-primitives", path = "../../primitives", default-features = false }
pallet-traits = { path = '../traits', default-features = false }

# Orml dependencies
orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "44fda4432b71f49ee59a650cf4775db895ab97af", default-features = false }
orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "44fda4432b71f49ee59a650cf4775db895ab97af", default-features = false }
orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "2c48b626addafbea0227c068c9ab0fc16666b1b5", default-features = false }
orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "2c48b626addafbea0227c068c9ab0fc16666b1b5", default-features = false }

# for other pallets wanting to mock functions
mocktopus = {version = "0.7.0", optional = true }
Expand Down
49 changes: 46 additions & 3 deletions crates/currency/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ pub mod amount;
use codec::{EncodeLike, FullCodec};
use frame_support::{dispatch::DispatchResult, traits::Get};
use orml_traits::{MultiCurrency, MultiReservableCurrency};
use primitives::TruncateFixedPointToInt;
use pallet_traits::{LoansApi, OracleApi};
use primitives::{CurrencyId as PrimitivesCurrencyId, TruncateFixedPointToInt};
use scale_info::TypeInfo;
use sp_runtime::{
traits::{AtLeast32BitUnsigned, CheckedDiv, MaybeSerializeDeserialize},
FixedPointNumber, FixedPointOperand,
DispatchError, FixedPointNumber, FixedPointOperand,
};
use sp_std::{
convert::{TryFrom, TryInto},
Expand All @@ -34,6 +35,46 @@ mod types;
use types::*;
pub use types::{CurrencyConversion, CurrencyId};

pub struct CurrencyConvert<T, Oracle, Loans>(PhantomData<(T, Oracle, Loans)>);
impl<T, Oracle, Loans> CurrencyConversion<Amount<T>, CurrencyId<T>> for CurrencyConvert<T, Oracle, Loans>
where
T: Config,
Oracle: OracleApi<Amount<T>, CurrencyId<T>>,
Loans: LoansApi<CurrencyId<T>, T::AccountId, <T as pallet::Config>::Balance, Amount<T>>,
{
fn convert(amount: &Amount<T>, to: CurrencyId<T>) -> Result<Amount<T>, DispatchError> {
if amount.currency().is_lend_token() && to.is_lend_token() {
// Example (lendDOT to lendINTR):
// collateral_amount(convert(underlying_amount(lendDOT_amount), underlying_id(lendINTR)))
// collateral_amount(convert(dot_amount, INTR))
// collateral_amount(intr_amount)
let to_underlying_id = Loans::underlying_id(to)?;
let from_underlying_amount = Loans::recompute_underlying_amount(amount)?;
let to_underlying_amount = Oracle::convert(&from_underlying_amount, to_underlying_id)?;
Loans::recompute_collateral_amount(&to_underlying_amount)
} else if amount.currency().is_lend_token() {
// Example: LendDOT -> INTR =
// convert(underlying_amount(lendDOT_amount), INTR)
// convert(dot_amount, INTR)
Oracle::convert(&Loans::recompute_underlying_amount(amount)?, to)
} else if to.is_lend_token() {
// Example (DOT to lendINTR):
// collateral_amount(convert(dot_amount, underlying_id(lendINTR)))
// collateral_amount(convert(dot_amount, INTR))
// collateral_amount(intr_amount)
let underlying_id = Loans::underlying_id(to)?;
// get the converted value expressed in the underlying asset
let underlying_amount = Oracle::convert(amount, underlying_id)?;
// get the equivalent lend_token amount using the internal exchange rate
Loans::recompute_collateral_amount(&underlying_amount)
} else {
// Example (DOT to INTR):
// convert(dot_amount, INTR)
Oracle::convert(amount, to)
}
}
}

#[frame_support::pallet]
pub mod pallet {
use super::*;
Expand All @@ -42,7 +83,9 @@ pub mod pallet {
/// ## Configuration
/// The pallet's configuration trait.
#[pallet::config]
pub trait Config: frame_system::Config + orml_tokens::Config<Balance = BalanceOf<Self>> {
pub trait Config:
frame_system::Config + orml_tokens::Config<Balance = BalanceOf<Self>, CurrencyId = PrimitivesCurrencyId>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not use the concrete type:

Suggested change
frame_system::Config + orml_tokens::Config<Balance = BalanceOf<Self>, CurrencyId = PrimitivesCurrencyId>
frame_system::Config + orml_tokens::Config<Balance = BalanceOf<Self>, CurrencyId = CurrencyId<Self>>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This somehow triggers a compiler bug: https://stackoverflow.com/questions/66631251/why-do-i-get-an-overflow-evaluating-the-requirement-error-for-a-simple-trait-i

error[E0275]: overflow evaluating the requirement `<T as orml_tokens::Config>::CurrencyId == _`
  --> crates/currency/src/amount.rs:18:46
   |
18 | #[cfg_attr(feature = "testing-utils", derive(Copy))]
   |                                              ^^^^
   |
   = note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's because CurrencyId is defined like this, so there might be a reference loop?

pub type CurrencyId<T> = <T as orml_tokens::Config>::CurrencyId;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I specified the concrete type in the first place was this error:

error[E0599]: no method named `is_lend_token` found for associated type `<T as orml_tokens::Config>::CurrencyId` in the current scope
  --> crates/currency/src/lib.rs:46:30
   |
46 |         if amount.currency().is_lend_token() && to.is_lend_token() {
   |                              ^^^^^^^^^^^^^ method not found in `<T as orml_tokens::Config>::CurrencyId`

{
type UnsignedFixedPoint: FixedPointNumber<Inner = BalanceOf<Self>>
+ TruncateFixedPointToInt
+ Encode
Expand Down
3 changes: 3 additions & 0 deletions crates/currency/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ impl orml_tokens::Config for Test {
type WeightInfo = ();
type ExistentialDeposits = ExistentialDeposits;
type OnDust = ();
type OnSlash = ();
type OnDeposit = ();
type OnTransfer = ();
type MaxLocks = MaxLocks;
type DustRemovalWhitelist = Everything;
type MaxReserves = ConstU32<0>; // we don't use named reserves
Expand Down
4 changes: 2 additions & 2 deletions crates/fee/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ pallet-timestamp = { git = "https://github.com/paritytech/substrate", branch = "
currency = { path = "../currency", features = ["testing-utils"] }

# Orml dependencies
orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "44fda4432b71f49ee59a650cf4775db895ab97af", default-features = false }
orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "44fda4432b71f49ee59a650cf4775db895ab97af", default-features = false }
orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "2c48b626addafbea0227c068c9ab0fc16666b1b5", default-features = false }
orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "2c48b626addafbea0227c068c9ab0fc16666b1b5", default-features = false }

# Parachain dependencies
primitives = { package = "interbtc-primitives", path = "../../primitives"}
Expand Down
3 changes: 3 additions & 0 deletions crates/fee/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ impl orml_tokens::Config for Test {
type WeightInfo = ();
type ExistentialDeposits = ExistentialDeposits;
type OnDust = ();
type OnSlash = ();
type OnDeposit = ();
type OnTransfer = ();
type MaxLocks = MaxLocks;
type DustRemovalWhitelist = Everything;
type MaxReserves = ConstU32<0>; // we don't use named reserves
Expand Down
8 changes: 4 additions & 4 deletions crates/issue/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ vault-registry = { path = "../vault-registry", default-features = false }
primitives = { package = "interbtc-primitives", path = "../../primitives", default-features = false }

# Orml dependencies
orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "44fda4432b71f49ee59a650cf4775db895ab97af", default-features = false, optional = true }
orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "44fda4432b71f49ee59a650cf4775db895ab97af", default-features = false, optional = true }
orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "2c48b626addafbea0227c068c9ab0fc16666b1b5", default-features = false, optional = true }
orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "2c48b626addafbea0227c068c9ab0fc16666b1b5", default-features = false, optional = true }

[dev-dependencies]
mocktopus = "0.7.0"
Expand All @@ -47,8 +47,8 @@ reward = { path = "../reward" }
staking = { path = "../staking" }

# Orml dependencies
orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "44fda4432b71f49ee59a650cf4775db895ab97af" }
orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "44fda4432b71f49ee59a650cf4775db895ab97af" }
orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "2c48b626addafbea0227c068c9ab0fc16666b1b5" }
orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "2c48b626addafbea0227c068c9ab0fc16666b1b5" }

[features]
default = ["std"]
Expand Down
3 changes: 3 additions & 0 deletions crates/issue/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ impl orml_tokens::Config for Test {
type WeightInfo = ();
type ExistentialDeposits = ExistentialDeposits;
type OnDust = ();
type OnSlash = ();
type OnDeposit = ();
type OnTransfer = ();
type MaxLocks = MaxLocks;
type DustRemovalWhitelist = Everything;
type MaxReserves = ConstU32<0>; // we don't use named reserves
Expand Down
78 changes: 78 additions & 0 deletions crates/loans/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
[package]
authors = ["Parallel Team", "Interlay Ltd"]
edition = "2021"
name = "pallet-loans"
version = "1.9.3"

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
serde = { version = "1.0.136", default-features = false, features = ["derive"], optional = true }
codec = { package = "parity-scale-codec", version = "3.1.5", default-features = false }
scale-info = { version = "2.1.0", default-features = false, features = ["derive"] }
num-traits = { default-features = false, version = "0.2" }

# Substrate dependencies
sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29", default-features = false }
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29", default-features = false }
sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29", default-features = false }
sp-arithmetic = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29", default-features = false }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29", default-features = false }

frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29", default-features = false }
frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29", default-features = false }
frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29", default-features = false, optional = true }
pallet-timestamp = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29", default-features = false }

# Parachain dependencies
currency = { path = "../currency", default-features = false }
pallet-traits = { path = "../traits", default-features = false }

primitives = { package = "interbtc-primitives", path = "../../primitives", default-features = false }

# Orml dependencies
orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "2c48b626addafbea0227c068c9ab0fc16666b1b5", default-features = false }
orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "2c48b626addafbea0227c068c9ab0fc16666b1b5", default-features = false }
orml-oracle = { git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "2c48b626addafbea0227c068c9ab0fc16666b1b5", default-features = false }

[dev-dependencies]
mocktopus = "0.7.0"

[features]
default = ["std"]
std = [
"serde/std",
"codec/std",
"scale-info/std",
"num-traits/std",

"sp-io/std",
"sp-core/std",
"sp-std/std",
"sp-arithmetic/std",
"sp-runtime/std",

"frame-support/std",
"frame-system/std",
"frame-benchmarking/std",
"pallet-timestamp/std",

"currency/std",
"pallet-traits/std",

"primitives/std",

"orml-traits/std",
"orml-oracle/std",
"orml-tokens/std",
]
runtime-benchmarks = [
"frame-benchmarking",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
]
try-runtime = ["frame-support/try-runtime"]

[lib]
doctest = false
21 changes: 21 additions & 0 deletions crates/loans/rpc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
authors = ['Interlay Ltd']
edition = '2021'
name = 'pallet-loans-rpc'
version = '1.9.3'

[dependencies]
codec = { package = 'parity-scale-codec', version = '3.1.5' }
jsonrpsee = { version = "0.15.1", features = ["server", "macros"] }
primitives = { package = 'parallel-primitives', path = '../../../primitives', default-features = false }
serde = { version = '1.0.136', features = ['derive'] }
sp-api = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.29' }
sp-blockchain = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.29' }
sp-core = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.29' }
sp-rpc = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.29', default-features = false }
sp-runtime = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.29' }

pallet-loans-rpc-runtime-api = { path = 'runtime-api', default-features = false }

[lib]
doctest = false
18 changes: 18 additions & 0 deletions crates/loans/rpc/runtime-api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
authors = ['Interlay Ltd']
edition = '2021'
name = 'pallet-loans-rpc-runtime-api'
version = '1.9.3'

[dependencies]
codec = { package = 'parity-scale-codec', version = '3.1.5', default-features = false, features = ['derive'] }
primitives = { package = 'parallel-primitives', path = '../../../../primitives', default-features = false }
sp-api = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.29', default-features = false }
sp-runtime = { git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.29', default-features = false }

[features]
default = ['std']
std = ['codec/std', 'sp-api/std', 'sp-runtime/std']

[lib]
doctest = false
32 changes: 32 additions & 0 deletions crates/loans/rpc/runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2022 Interlay.
// This file is part of Interlay.

// Copyright 2021 Parallel Finance Developer.
// This file is part of Parallel Finance.

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#![cfg_attr(not(feature = "std"), no_std)]

use codec::Codec;
use primitives::{CurrencyId, Liquidity, Rate, Ratio, Shortfall};
use sp_runtime::{DispatchError, FixedU128};

sp_api::decl_runtime_apis! {
pub trait LoansApi<AccountId, Balance> where
AccountId: Codec,
Balance: Codec {
fn get_account_liquidity(account: AccountId) -> Result<(Liquidity, Shortfall, Liquidity, Shortfall), DispatchError>;
fn get_market_status(asset_id: CurrencyId) -> Result<(Rate, Rate, Rate, Ratio, Balance, Balance, FixedU128), DispatchError>;
fn get_liquidation_threshold_liquidity(account: AccountId) -> Result<(Liquidity, Shortfall, Liquidity, Shortfall), DispatchError>;
}
}
Loading