-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* dex docs, groups for lending, api (#183) Signed-off-by: dzmitry-lahoda <[email protected]> * smallest possible unit for currencies + refactor + lending fixes / tests more clear (#186) * make sure we allow liquidation if the source account has zero funds after * introduce PriceableAsset capability * refactor lending pallet + oracle mock to use smallest unit of an asset * fix merge conflicts, make tests more clear * simpler priceable type & upgrade runtime currency to handle it * simplify and better documentation * cleanup unused constraints * Vault-index-configurable (#200) * make VaultId an associated type * Unmanle doc comment * rent implementation (#189) * implement rent and tombstoning * clean up claim_surcharge Also ensure that tombstoned vaults have funds returned by strategies. * handle deletion_reward * add delete_tombstoned functionality * add add_surcharge * fmt and fix doc comment * Use NativeCurrency associated type instead of querying for native id (#202) * Update Vault Readme (#207) * describe vault * sync readme with rustdoc * Tests documentations & refactoring (#254) * introduce composable-helpers * refactor vault/lending tests to use composable-helpers * apply advices * Vault benchmarking (#270) * fix missing runtime paramter * add vault benchmarking * Update CI config Co-authored-by: Andrey Orlov <[email protected]> * CU-1kjehh6 - avoid less than expected bonus by using safe maths (#289) * CU-1kr011f - merge allocations in StrategyOverview (#290) Both Allocations and CapitaalStructure storage map were tied. Which mean you couldn't have an allocation without having a StrategyOverview. This was wrong for the case of the reserve, as the vault itself has an allocation (the reserve) but no StrategyOverview. Because of that, one could trigger a panic by asking for `available_funds` using the vault id. We fix this issue by merging the allocation inside the StrategyOverview. * fix benchmarking * feature gate vault benchmark * apply udeps suggestions * update cargo.lock Co-authored-by: Andrey Orlov <[email protected]>
- Loading branch information
1 parent
2aeb523
commit bbc7879
Showing
60 changed files
with
4,396 additions
and
1,861 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
[package] | ||
name = "composable-tests-helpers" | ||
version = "0.0.1" | ||
authors = ["Composable Developers"] | ||
homepage = "https://composable.finance" | ||
edition = "2018" | ||
|
||
[package.metadata.docs.rs] | ||
targets = ["x86_64-unknown-linux-gnu"] | ||
|
||
[dependencies] | ||
scale-info = { version = "1.0", default-features = false, features = ["derive"] } | ||
serde = { version = "1", optional = true } | ||
sp-arithmetic = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" } | ||
sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" } | ||
sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" } | ||
|
||
[dependencies.codec] | ||
default-features = false | ||
features = ["derive"] | ||
package = "parity-scale-codec" | ||
version = "2.0.0" | ||
|
||
[features] | ||
default = ["std"] | ||
std = [ | ||
"serde", | ||
"codec/std", | ||
"sp-runtime/std", | ||
"scale-info/std", | ||
] |
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,3 @@ | ||
#![cfg_attr(not(feature = "std"), no_std)] | ||
|
||
pub mod test; |
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,28 @@ | ||
use sp_runtime::{FixedPointNumber, FixedU128}; | ||
|
||
/// Default is 0.1% | ||
pub const DEFAULT_ACCEPTABLE_DEVIATION: u128 = 1000; | ||
|
||
/// Check that x/y ~ 1 up to a certain precision | ||
pub fn acceptable_computation_error(x: u128, y: u128, precision: u128) -> Result<(), FixedU128> { | ||
let delta = i128::abs(x as i128 - y as i128); | ||
if delta > 1 { | ||
let epsilon: u128 = 1; | ||
let lower = | ||
FixedU128::saturating_from_rational(precision, precision.saturating_add(epsilon)); | ||
let upper = | ||
FixedU128::saturating_from_rational(precision, precision.saturating_sub(epsilon)); | ||
let q = FixedU128::checked_from_rational(x, y).expect("values too big; qed;"); | ||
if lower <= q && q <= upper { | ||
Ok(()) | ||
} else { | ||
Err(q) | ||
} | ||
} else { | ||
Ok(()) | ||
} | ||
} | ||
|
||
pub fn default_acceptable_computation_error(x: u128, y: u128) -> Result<(), FixedU128> { | ||
acceptable_computation_error(x, y, DEFAULT_ACCEPTABLE_DEVIATION) | ||
} |
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,2 @@ | ||
pub mod helper; | ||
pub mod proptest; |
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,38 @@ | ||
/// Equivalent of assert_ok when inside a proptest context. | ||
#[macro_export] | ||
macro_rules! prop_assert_ok { | ||
($cond:expr) => { | ||
prop_assert_ok!($cond, concat!("assertion failed: ", stringify!($cond))) | ||
}; | ||
|
||
($cond:expr, $($fmt:tt)*) => { | ||
if let Err(e) = $cond { | ||
let message = format!($($fmt)*); | ||
let message = format!("Expected Ok(_), got {:?}, {} at {}:{}", e, message, file!(), line!()); | ||
return ::std::result::Result::Err( | ||
proptest::test_runner::TestCaseError::fail(message)); | ||
} | ||
}; | ||
} | ||
|
||
/// Accept a `dust` deviation. | ||
#[macro_export] | ||
macro_rules! prop_assert_acceptable_computation_error { | ||
($x:expr, $y:expr, $precision:expr) => {{ | ||
match composable_tests_helpers::test::helper::acceptable_computation_error( | ||
$x, $y, $precision, | ||
) { | ||
Ok(()) => {}, | ||
Err(q) => { | ||
prop_assert!(false, "{} * {} / {} = {} != {}", $x, $precision, $y, q, $precision); | ||
}, | ||
} | ||
}}; | ||
($x:expr, $y:expr) => {{ | ||
prop_assert_acceptable_computation_error!( | ||
$x, | ||
$y, | ||
composable_tests_helpers::test::helper::DEFAULT_ACCEPTABLE_DEVIATION | ||
); | ||
}}; | ||
} |
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
Oops, something went wrong.