-
Notifications
You must be signed in to change notification settings - Fork 83
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
Lending protocol #737
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 30100fe
feat(lend): get unit tests to run
daniel-savu 9122745
feat(lend): use orml-tokens instead of pallet-assets
daniel-savu d1be241
feat(lend): configure lending pallet
daniel-savu 66b4572
chore: bump toolchain to match lending pallet
daniel-savu d45d68d
chore: fix toml files
daniel-savu 8ad2319
fix(lend): PriceFeeder trait import
daniel-savu 64af00e
feat(lend): add loans pallet to standalone runtime
daniel-savu 89a6032
chore(lend): remove liquidate-free collateral
daniel-savu 590a405
fix(lend): btc oracle integration, notes on integrating pTokens with …
daniel-savu cf8a1b0
refactor(lend): cleanup
daniel-savu 7c41e20
feat(lend): update benchmarks and copyrights
daniel-savu a70aa8e
fix(lend): attempt to fix benchmarks
daniel-savu 81d925a
fix(lend): fmt
daniel-savu 50fd3a7
fix(lend): cleanup
daniel-savu bca36ff
feat(loans): import orml pallet with hooks feature
daniel-savu 32c204e
feat(loans): add currency pallet
daniel-savu 409bb8b
feat(loans): split do_collateral_asset
daniel-savu 1d509e9
Merge pull request #1 from interlay/dan/lend
gregdhill 139a314
feat(loans): fully tokenize ptokens
daniel-savu 9ec2ed0
feat(loans): Replace T::Asset actions with Currency pallet
daniel-savu 7fd05bb
feat(loans): clean up ptoken module
daniel-savu 25bec4e
feat(loans): replace local orml-tokens fork with interlay repo
daniel-savu 481957b
Merge branch 'master' into dan/orml-ptoken
daniel-savu 1b6d0b2
fix(loans): fix all local orml imports
daniel-savu a4331b2
fix(loans): benchmark
daniel-savu 815c53f
chore(loans): cleanup and added comments
daniel-savu 4b94319
fix(loans): don't propagate on_slash errors; feature-gate test utils
daniel-savu e3215ef
fix(loans): use a weghts-v1 compatible orml dependency
daniel-savu e18c703
feat(loans): ptokens as currency id
daniel-savu a7028c2
feat(loans): ptoken oracle integration
daniel-savu 156a472
feat(primitives): is_ctoken associated method
daniel-savu cc9ac77
Merge pull request #2 from interlay/dan/orml-ptoken
gregdhill 5cc1cf0
Merge branch 'master' into dan/ptokens-currency
daniel-savu 6283dab
feat(loans): min and max exchange rates as storage items
daniel-savu 85c1bf5
feat(loans): pToken integration tests for issue and redeem
daniel-savu 551692c
feat(loans): nomination integration tests with ptokens collateral
daniel-savu 0b4eef5
chore(loans): improve comments, remove test duplication
daniel-savu 84adbd3
refactor(loans): default CurrencyConversion implementation; remove un…
daniel-savu 2d18a24
fix(loans): replace and vault registry integration tests
daniel-savu 442cfa6
test(loans): replace with pToken collateral
daniel-savu f88e61d
Merge pull request #3 from interlay/dan/ptokens-currency
daniel-savu c4f7aa3
feat(loans): add lending to testnet runtimes
daniel-savu 043d6bf
test(loans): lockable ptokens, lending edge cases
daniel-savu 2395d35
chore(loans): move tests to interest rate file
daniel-savu 716f51d
test(loans): orml ptoken tests
daniel-savu e13c0fa
chore(loans): rename to `compute_collateral_amount`, add market cap, …
daniel-savu 17b5e31
chore(loans): comments, Rate default impl
daniel-savu d32db00
refactor(loans): ptokens to lend_tokens
daniel-savu 0b49fcd
refactor(loans): use interlay assets in tests
daniel-savu 68e0ae7
chore(loans): remove leftover liquidation-free code
daniel-savu e6bcfda
chore(loans): fix tests
daniel-savu ef6a7cb
fix(loans): warnings
daniel-savu 147ade7
Merge branch 'master' of https://github.com/interlay/interbtc into da…
daniel-savu e7cf4f4
feat: use latest orml
daniel-savu bbc912d
fix(loans): upgrade polkadot
daniel-savu f40383c
fix(loans): reset storage version
daniel-savu c089ac3
test(loans): zero amount extrinsics
daniel-savu df3a2d9
test(loans): improve comments for tests.rs
daniel-savu d8a6824
chore(loans): remove comment typo
daniel-savu ca6eccf
fix(loans): failing test and warnings
daniel-savu acc03a7
feat(loans): calculate liquidity with checked math
daniel-savu 6f88113
fix(loans): add missing copyright and authorship acks; reuse Arithmet…
daniel-savu 13e038e
fix(loans): use currency hooks on testnet; refactor constants; improv…
daniel-savu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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:
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?There was a problem hiding this comment.
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: