Skip to content

Commit

Permalink
Ben/merge ben clippy into main (#438)
Browse files Browse the repository at this point in the history
* Add `clippy::disallowed_method` lint

* Fix clippy lints

* cargo fmt

* Add clippy::indexing_slicing annotation to all crates

* Fix slicing warnings in curve-amm crate.

I wasn't able to fix all of the occurences or slicing; some functions take indexes directly. I feel like these should be using .get(n) and returning some sort of dispatch error instead of panicking, but I'm not knowledgeable enough about substrate to say for sure. All instances of this have been annoted with a `REVIEW: indexing` comment at the function level.

* Fix and/or audit indexing warninggs in oracle crate

* Fix and/or audit indexing in oracle crate

* Fix bug in add_liquidity

* Add type annotation

* Style & formatting

* Fix extra underscore in integer literal

* Add clippy::disallowed_type lint

* Change MockCurrencyId variants to be CONSTANT_CASE

* Remove uses of dbg!() macro

* rustfmt

* Upgrade parachain to polkadot-v0.9.13 (#372)

* bump to 0.9.13

* cargo fmt

* bump subxt

* cargo fmt

* up simuator to 0.9.13

Signed-off-by: Dzmitry Lahoda <dzmitry@lahoda.pro>

* bump

Co-authored-by: Dzmitry Lahoda <dzmitry@lahoda.pro>

Bump picasso chain spec (#375)

* bump spec

* cargo fmt

Composable Runtime (#364)

* composable-runtime

* initial implementation

* support multiple runtimes for subcommand

* cargo fmt

CU-1nbhuu3 - upgrade price feed to match oracle (#373)

* upgrade price feed to match oracle, simplify normalization and allow more configuration

* use latest version of clap and add new required `derive` feature

* fix main

* apply clippy suggestions

adds composable chain spec (#378)

* adds composable chain spec

* cargo fmt

* fix clap

* sigh

Check runtime ci [WIP] (#379)

* Update Makefile

* Update release

* Update

* Updating release

* Added runtime check

* Testing runtime checki ci for chachacha branch

* Testing runtime checki ci for chachacha branch

* Testing runtime checki ci for chachacha branch

* Testing runtime checki ci for chachacha branch

* Testing runtime checki ci for chachacha branch

* Testing runtime checki ci for chachacha branch

* Testing runtime checki ci for chachacha branch

* Testing runtime checki ci for chachacha branch

* Testing runtime checki ci for chachacha branch

* Testing runtime checki ci for chachacha branch

* Testing runtime checki ci for chachacha branch

* Testing runtime checki ci for chachacha branch

* Testing runtime checki ci for chachacha branch

* Testing runtime checki ci for chachacha branch

* Testing runtime checki ci for chachacha branch

* Testing runtime checki ci for chachacha branch

* Testing runtime checki ci for chachacha branch

* Testing runtime checki ci for chachacha branch

* Testing runtime checki ci for chachacha branch

* Testing runtime checki ci for chachacha branch

* Testing runtime checki ci for chachacha branch

* Testing runtime checki ci for chachacha branch

* Testing runtime checki ci for chachacha branch

* Testing runtime checki ci for chachacha branch

* Testing runtime checki ci for chachacha branch

* Testing runtime checki ci for chachacha branch

* remove westend-native

Co-authored-by: Seun Lanlege <seunlanlege@gmail.com>

Add a sequence diagram to explain a work of pallet-assets-registry (#380)

Implement property test for add/remove_liquidity() and exchange().
Also fix minor bug found with proptesting.

CU-1nbj6eq - Cherry develop (#384)

* dex docs, groups for lending, api (#183)

Signed-off-by: dzmitry-lahoda <dzmitry@lahoda.pro>

* 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 <aaorlov1@gmail.com>

* 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 <aaorlov1@gmail.com>

Update ansible picasso (#396)

Resolve conflicting `Cargo.lock` dependencies (#390)

Resolve conflicting `Cargo.lock` dependencies (#390)

Update ansible picasso (#399)

* Update ansible

Update GitHub ansible workflow (#407)

Update GitHub ansible workflow (#408)

CU-1wef6he - add enable/disable hook to call-filter and extract behavior to (#398)

composable-traits

We were previously using a map `Entry -> Option<()>` but a StorageMap `Entry -> ()`
is enough as it uses `OptionQuery` by default.

I added a way to hook into enable/disable call of the filter pallet to make it
more flexible. If we want to block a pallet from being disabled, it can now be
done at the Runtime declaration.

Architecture.md (#405)

* CU-1nbetfw - move `price-feed` in `utils`

* CU-1nbetfw - add `ARCHITECTURE.md` describind the repository architecture

Add `clippy::disallowed_method` lint

parent 62f6e5b
author Hussein Ait-Lahcen <hussein.aitlahcen@gmail.com> 1640264806 +0100
committer Ben Luelo <benluelo@hotmail.com> 1641229158 -0500
gpgsig -----BEGIN PGP SIGNATURE-----

 iQGzBAABCgAdFiEEvcJAWzQ+hHD6e6hZKDJl/2mUhmAFAmHTK2YACgkQKDJl/2mU
 hmAZUgv/YlQbIMXV8utYIgxSDSTAGtW4Ruo5bXSQzDQJWKL8AMk04WJs/A2YgsV4
 v7COvbFaTEKM0BrfAbSd8RhGUI2xQmTtvzr3M7dXhTPh6UIRK1O2QU62XBwFlRiG
 m40HoP+FHnhdMeO49jiD+6JiJQZJ4YysLw3TpF4NMCLLAE+OEVUkTHkbovrawfte
 zPrw2suOz4PIhajPKlThPsyec7GfnLTRZFZcsjovSerI+BYUBIroCWtoLP3Hw873
 nCdve/HigNfwyeFVVw61coa8csqzN8CA2qzg2AFAHfsvNBil8baFJMywm+6vfV7s
 qnN+XK/GgrYZew5V00vNhKmW8h7/K0Gdyeuri/LelokXNE/PGiRrODl+066F/qCN
 U6urzh2nny1lTsbIoVMnOryk5yj3ekFd8Nsy/SmFtaGFjRvErdtZ0Qzd3zENVxie
 YCb4Msgce3UgZbQ8wLo3RaQKg+32i562ewDyWtnATG+CY+jCWeRlAqHYakTKzRrn
 91xqAEMi
 =4XKn
 -----END PGP SIGNATURE-----

CU-1kr4tya - Crowdloan rewards benchmarking (#412)

* CU-1kr4tya - crowdloan rewards benchmarking

* fix main benchmarking

* add crowdloan-rewards to runtime and generated benchmark weights

* update cargo lock

* refactor crowdloan rewards test to use 1:1 benchmarking types

* fix populate weight calculation

* make sure to remove rewards prior to populate

* use runtime prefix in benchmarking

* unused dependency

Run benchmark for develop and fix `cargo vendor` (#419)

CU-1wtx9fb Implement Constant Product AMM.

Democracy (#389)

* CU-1rpbzkw - democracy pallet

Fixed missing test cases and related dependencies

Added missing test cases

Fixed format errors and docs

Fixing docs

 CU-1rpbzkw | Fixed failing test case

CU-1rpbzkw | handle transfer_held() result

CU-1rpbzkw | added few more multi currency tests

CU-1rpbzkw | fixing fmt

Changes & fixes for benchmarking

Linting fixes

* Democracy

Co-authored-by: kaiserkarel <k.l.kubat@gmail.com>

split out dali runtime from picasso (#421)

* split out dali runtime from picasso

* cargo fm

* fix runtimes

* cargo fmt

[BondedFinance] Add benchmarks (#377)

Add email (#431)

Add rust-toolchain.toml (#435)

* Add rust-toolchain.toml
* Remove ConvertInto import

Fix clippy lints

cargo fmt

Add clippy::indexing_slicing annotation to all crates

Fix slicing warnings in curve-amm crate.

I wasn't able to fix all of the occurences or slicing; some functions take indexes directly. I feel like these should be using .get(n) and returning some sort of dispatch error instead of panicking, but I'm not knowledgeable enough about substrate to say for sure. All instances of this have been annoted with a `REVIEW: indexing` comment at the function level.

Fix and/or audit indexing warninggs in oracle crate

Fix and/or audit indexing in oracle crate

Fix bug in add_liquidity

Add type annotation

Style & formatting

Fix extra underscore in integer literal

Add clippy::disallowed_type lint

Change MockCurrencyId variants to be CONSTANT_CASE

Remove uses of dbg!() macro

rustfmt

CU-1p8545r  dutch auction (#410)

* dutch auction

Signed-off-by: dzmitry-lahoda <dzmitry@lahoda.pro>

* fixed tests

Signed-off-by: dzmitry-lahoda <dzmitry@lahoda.pro>

* fixed clippy

Signed-off-by: dzmitry-lahoda <dzmitry@lahoda.pro>

* fixed review comments

Signed-off-by: dzmitry-lahoda <dzmitry@lahoda.pro>

* adding tests and fixing bugs

Signed-off-by: dzmitry-lahoda <dzmitry@lahoda.pro>

* refactoring

Signed-off-by: dzmitry-lahoda <dzmitry@lahoda.pro>

* fix fmt

Signed-off-by: dzmitry-lahoda <dzmitry@lahoda.pro>

* fixed udeps

Signed-off-by: dzmitry-lahoda <dzmitry@lahoda.pro>

* fixed clippy

Signed-off-by: dzmitry-lahoda <dzmitry@lahoda.pro>

Squash

audit use of ValueQuery

audit usage of ValueQuery

audit ValueQuery in vault

audit usage of unwrap and ValueQuery in transaction-fee

Audit clippy warnings in curve-amm pallet

indexing and slicing warning have been suppressed for now; A larger refactor will be required to remove the indexing that remains.

Audit use of ValueQuery in dutch-auction

Fix compilation error in test_interest_rate_model_default

Audit/ fix clippy warnings in assets-registry and dutch-auction

Fix or temporarilly suppress various clippy warnings

rustfmt

Signed-off-by: Ben Luelo <benluelo@hotmail.com>

Audit clippy warnings in curve-amm pallet

indexing and slicing warning have been suppressed for now; A larger refactor will be required to remove the indexing that remains.

Fix compilation error in test_interest_rate_model_default

Audit/ fix clippy warnings in assets-registry and dutch-auction

Fix or temporarilly suppress various clippy warnings

rustfmt

Signed-off-by: Ben Luelo <benluelo@hotmail.com>

rustfmt

Signed-off-by: Ben Luelo <benluelo@hotmail.com>

CU-1kr4tya - Crowdloan rewards benchmarking (#412)

* CU-1kr4tya - crowdloan rewards benchmarking

* fix main benchmarking

* add crowdloan-rewards to runtime and generated benchmark weights

* update cargo lock

* refactor crowdloan rewards test to use 1:1 benchmarking types

* fix populate weight calculation

* make sure to remove rewards prior to populate

* use runtime prefix in benchmarking

* unused dependency

Run benchmark for develop and fix `cargo vendor` (#419)

Democracy (#389)

* CU-1rpbzkw - democracy pallet

Fixed missing test cases and related dependencies

Added missing test cases

Fixed format errors and docs

Fixing docs

 CU-1rpbzkw | Fixed failing test case

CU-1rpbzkw | handle transfer_held() result

CU-1rpbzkw | added few more multi currency tests

CU-1rpbzkw | fixing fmt

Changes & fixes for benchmarking

Linting fixes

* Democracy

Co-authored-by: kaiserkarel <k.l.kubat@gmail.com>

split out dali runtime from picasso (#421)

* split out dali runtime from picasso

* cargo fm

* fix runtimes

* cargo fmt

[BondedFinance] Add benchmarks (#377)

Add email (#431)

Add rust-toolchain.toml (#435)

* Add rust-toolchain.toml
* Remove ConvertInto import

Fix clippy lints

cargo fmt

Add clippy::indexing_slicing annotation to all crates

Fix slicing warnings in curve-amm crate.

I wasn't able to fix all of the occurences or slicing; some functions take indexes directly. I feel like these should be using .get(n) and returning some sort of dispatch error instead of panicking, but I'm not knowledgeable enough about substrate to say for sure. All instances of this have been annoted with a `REVIEW: indexing` comment at the function level.

Fix and/or audit indexing warninggs in oracle crate

Fix bug in add_liquidity

Style & formatting

Add clippy::disallowed_type lint

Change MockCurrencyId variants to be CONSTANT_CASE

Remove uses of dbg!() macro

rustfmt

CU-1p8545r  dutch auction (#410)

* dutch auction

Signed-off-by: dzmitry-lahoda <dzmitry@lahoda.pro>

* fixed tests

Signed-off-by: dzmitry-lahoda <dzmitry@lahoda.pro>

* fixed clippy

Signed-off-by: dzmitry-lahoda <dzmitry@lahoda.pro>

* fixed review comments

Signed-off-by: dzmitry-lahoda <dzmitry@lahoda.pro>

* adding tests and fixing bugs

Signed-off-by: dzmitry-lahoda <dzmitry@lahoda.pro>

* refactoring

Signed-off-by: dzmitry-lahoda <dzmitry@lahoda.pro>

* fix fmt

Signed-off-by: dzmitry-lahoda <dzmitry@lahoda.pro>

* fixed udeps

Signed-off-by: dzmitry-lahoda <dzmitry@lahoda.pro>

* fixed clippy

Signed-off-by: dzmitry-lahoda <dzmitry@lahoda.pro>

rustfmt

* Fix error in pallet-vault

* Fix clippy warnings in dutch-auction

Co-authored-by: Seun Lanlege <seun@composable.finance>
Signed-off-by: Dzmitry Lahoda <dzmitry@lahoda.pro>
  • Loading branch information
2 people authored and dzmitry-lahoda committed Jan 5, 2022
1 parent 0304f68 commit 4a85928
Show file tree
Hide file tree
Showing 54 changed files with 1,252 additions and 911 deletions.
999 changes: 502 additions & 497 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
disallowed-methods = [
"core::result::Result::unwrap", # { path = "core::result::Result::unwrap", reason = "Errors should be handled properly. If panicking is valid in this context, make sure to write a comment explaining why." },
"core::option::Option::unwrap", # { path = "core::option::Option::unwrap", reason = "Errors should be handled properly. If panicking is valid in this context, make sure to write a comment explaining why." },
]

disallowed-types = ["frame_support::storage::types::ValueQuery"]

type-complexity-threshold = 5000
21 changes: 19 additions & 2 deletions frame/assets-registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
//! 2. Assets map added as candidate and waits for approval.
//! 3. After approval map return mapped value.
//! 4. Map of native token to this chain(here) is added unconditionally.

#![cfg_attr(not(test), warn(clippy::disallowed_method, clippy::indexing_slicing))] // allow in tests
#![warn(clippy::unseparated_literal_suffix, clippy::disallowed_type)]
#![cfg_attr(not(feature = "std"), no_std)]

pub use pallet::*;
Expand Down Expand Up @@ -67,12 +70,16 @@ pub mod pallet {
#[pallet::storage]
#[pallet::getter(fn local_admin)]
/// Local admin account
pub type LocalAdmin<T: Config> = StorageValue<_, T::AccountId, ValueQuery>;
#[allow(clippy::disallowed_type)] // LocalAdminOnEmpty provides a default value, so ValueQuery is ok here.
pub type LocalAdmin<T: Config> =
StorageValue<_, T::AccountId, ValueQuery, LocalAdminOnEmpty<T>>;

#[pallet::storage]
#[pallet::getter(fn foreign_admin)]
/// Foreign admin account
pub type ForeignAdmin<T: Config> = StorageValue<_, T::AccountId, ValueQuery>;
#[allow(clippy::disallowed_type)] // ForeignAdminOnEmpty provides a default value, so ValueQuery is ok here.
pub type ForeignAdmin<T: Config> =
StorageValue<_, T::AccountId, ValueQuery, ForeignAdminOnEmpty<T>>;

#[pallet::storage]
#[pallet::getter(fn from_local_asset)]
Expand All @@ -97,6 +104,16 @@ pub mod pallet {
OptionQuery,
>;

#[pallet::type_value]
pub fn LocalAdminOnEmpty<T: Config>() -> T::AccountId {
T::AccountId::default()
}

#[pallet::type_value]
pub fn ForeignAdminOnEmpty<T: Config>() -> T::AccountId {
T::AccountId::default()
}

#[pallet::genesis_config]
pub struct GenesisConfig<T: Config> {
local_admin: Option<T::AccountId>,
Expand Down
8 changes: 4 additions & 4 deletions frame/assets-registry/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ pub type AccountId = u32;
type Block = frame_system::mocking::MockBlock<Test>;
type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;

pub const ROOT: AccountId = 0u32;
pub const ALICE: AccountId = 1u32;
pub const BOB: AccountId = 2u32;
pub const CHARLIE: AccountId = 3u32;
pub const ROOT: AccountId = 0_u32;
pub const ALICE: AccountId = 1_u32;
pub const BOB: AccountId = 2_u32;
pub const CHARLIE: AccountId = 3_u32;

// Configure a mock runtime to test the pallet.
frame_support::construct_runtime!(
Expand Down
2 changes: 2 additions & 0 deletions frame/assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
//! - `mint_into`
//! - `burn_from`

#![cfg_attr(not(test), warn(clippy::disallowed_method, clippy::indexing_slicing))] // allow in tests
#![warn(clippy::unseparated_literal_suffix, clippy::disallowed_type)]
#![cfg_attr(not(feature = "std"), no_std)]

pub use pallet::*;
Expand Down
5 changes: 5 additions & 0 deletions frame/bonded-finance/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg_attr(not(test), warn(clippy::disallowed_method, clippy::indexing_slicing))] // allow in tests
#![warn(clippy::unseparated_literal_suffix, clippy::disallowed_type)]
#![cfg_attr(not(feature = "std"), no_std)]
#![warn(
bad_style,
Expand Down Expand Up @@ -166,6 +168,9 @@ pub mod pallet {
/// The counter used to uniquely identify bond offers within this pallet.
#[pallet::storage]
#[pallet::getter(fn bond_offer_count)]
// `BondOfferOnEmpty<T>` explicitly defines the behaviour when empty, so `ValueQuery` is
// allowed.
#[allow(clippy::disallowed_type)]
pub type BondOfferCount<T: Config> =
StorageValue<_, T::BondOfferId, ValueQuery, BondOfferOnEmpty<T>>;

Expand Down
1 change: 1 addition & 0 deletions frame/bonded-finance/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub const CHARLIE: AccountId = 3;
TypeInfo,
proptest_derive::Arbitrary,
)]
#[allow(clippy::upper_case_acronyms)] // currencies should be CONSTANT_CASE
pub enum MockCurrencyId {
PICA,
BTC,
Expand Down
50 changes: 25 additions & 25 deletions frame/bonded-finance/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,36 +56,36 @@ fn valid_offer() {
assert!(BondOffer {
asset: MockCurrencyId::BTC,
bond_price: MIN_VESTED_TRANSFER as _,
nb_of_bonds: 100_000u128,
nb_of_bonds: 100_000_u128,
maturity: BondDuration::Infinite,
reward: BondOfferReward {
asset: MockCurrencyId::PICA,
amount: 1_000_000u128 * 100_000u128,
maturity: 96u128,
amount: 1_000_000_u128 * 100_000_u128,
maturity: 96_u128,
}
}
.valid(MinVestedTransfer::get() as _, MinReward::get()));
assert!(BondOffer {
asset: MockCurrencyId::BTC,
bond_price: MIN_VESTED_TRANSFER as _,
nb_of_bonds: 1u128,
nb_of_bonds: 1_u128,
maturity: BondDuration::Finite { return_in: 1 },
reward: BondOfferReward {
asset: MockCurrencyId::BTC,
amount: 1_000_000u128,
maturity: 96u128,
amount: 1_000_000_u128,
maturity: 96_u128,
}
}
.valid(MinVestedTransfer::get() as _, MinReward::get()));
assert!(BondOffer {
asset: MockCurrencyId::BTC,
bond_price: 1_000_000 + MIN_VESTED_TRANSFER as u128,
nb_of_bonds: 100_000u128,
nb_of_bonds: 100_000_u128,
maturity: BondDuration::Finite { return_in: 1_000_000 },
reward: BondOfferReward {
asset: MockCurrencyId::BTC,
amount: 1_000_000u128 * 100_000u128,
maturity: 96u128,
amount: 1_000_000_u128 * 100_000_u128,
maturity: 96_u128,
}
}
.valid(MinVestedTransfer::get() as _, MinReward::get()));
Expand All @@ -97,12 +97,12 @@ fn invalid_offer() {
assert!(!BondOffer {
asset: MockCurrencyId::BTC,
bond_price: MIN_VESTED_TRANSFER as u128 - 1,
nb_of_bonds: 100_000u128,
nb_of_bonds: 100_000_u128,
maturity: BondDuration::Infinite,
reward: BondOfferReward {
asset: MockCurrencyId::PICA,
amount: 1_000_000u128,
maturity: 96u128
amount: 1_000_000_u128,
maturity: 96_u128
}
}
.valid(MinVestedTransfer::get() as _, MinReward::get()));
Expand All @@ -115,8 +115,8 @@ fn invalid_offer() {
maturity: BondDuration::Finite { return_in: 1 },
reward: BondOfferReward {
asset: MockCurrencyId::BTC,
amount: 1_000_000u128,
maturity: 96u128,
amount: 1_000_000_u128,
maturity: 96_u128,
}
}
.valid(MinVestedTransfer::get() as _, MinReward::get()));
Expand All @@ -125,12 +125,12 @@ fn invalid_offer() {
assert!(!BondOffer {
asset: MockCurrencyId::BTC,
bond_price: 1_000_000 + MIN_VESTED_TRANSFER as u128,
nb_of_bonds: 100_000u128,
nb_of_bonds: 100_000_u128,
maturity: BondDuration::Finite { return_in: 0 },
reward: BondOfferReward {
asset: MockCurrencyId::BTC,
amount: 1_000_000u128,
maturity: 96u128,
amount: 1_000_000_u128,
maturity: 96_u128,
}
}
.valid(MinVestedTransfer::get() as _, MinReward::get()));
Expand All @@ -139,22 +139,22 @@ fn invalid_offer() {
assert!(!BondOffer {
asset: MockCurrencyId::BTC,
bond_price: 1_000_000 + MIN_VESTED_TRANSFER as u128,
nb_of_bonds: 100_000u128,
nb_of_bonds: 100_000_u128,
maturity: BondDuration::Finite { return_in: 1_000_000 },
reward: BondOfferReward { asset: MockCurrencyId::BTC, amount: 0, maturity: 96u128 }
reward: BondOfferReward { asset: MockCurrencyId::BTC, amount: 0, maturity: 96_u128 }
}
.valid(MinVestedTransfer::get() as _, MinReward::get()));

// invalid reward: < MinVested
assert!(!BondOffer {
asset: MockCurrencyId::BTC,
bond_price: 1_000_000 + MIN_VESTED_TRANSFER as u128,
nb_of_bonds: 100_000u128,
nb_of_bonds: 100_000_u128,
maturity: BondDuration::Finite { return_in: 1_000_000 },
reward: BondOfferReward {
asset: MockCurrencyId::BTC,
amount: 1_000_000u128 * 100_000u128 - 1,
maturity: 96u128
amount: 1_000_000_u128 * 100_000_u128 - 1,
maturity: 96_u128
}
}
.valid(MinVestedTransfer::get() as _, MinReward::get()));
Expand All @@ -163,12 +163,12 @@ fn invalid_offer() {
assert!(!BondOffer {
asset: MockCurrencyId::BTC,
bond_price: 1_000_000 + MIN_VESTED_TRANSFER as u128,
nb_of_bonds: 100_000u128,
nb_of_bonds: 100_000_u128,
maturity: BondDuration::Finite { return_in: 1_000_000 },
reward: BondOfferReward {
asset: MockCurrencyId::BTC,
amount: 1_000_000u128,
maturity: 0u128
amount: 1_000_000_u128,
maturity: 0_u128
}
}
.valid(MinVestedTransfer::get() as _, MinReward::get()));
Expand Down
2 changes: 2 additions & 0 deletions frame/call-filter/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg_attr(not(test), warn(clippy::disallowed_method, clippy::indexing_slicing))] // allow in tests
#![warn(clippy::unseparated_literal_suffix, clippy::disallowed_type)]
#![cfg_attr(not(feature = "std"), no_std)]
#![allow(clippy::unused_unit)]

Expand Down
2 changes: 1 addition & 1 deletion frame/composable-traits/src/currency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ where
{
/// if currency has `decimals` of 3, than it will return
fn unit<T: From<u64>>(&self) -> T {
T::from(10u64.pow(self.decimals() as u32))
T::from(10_u64.pow(self.decimals() as u32))
}

/// Return the decimals of an asset.
Expand Down
2 changes: 2 additions & 0 deletions frame/composable-traits/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg_attr(not(test), warn(clippy::disallowed_method, clippy::indexing_slicing))] // allow in tests
#![warn(clippy::unseparated_literal_suffix, clippy::disallowed_type)]
#![cfg_attr(not(feature = "std"), no_std)]

pub mod assets;
Expand Down
55 changes: 31 additions & 24 deletions frame/composable-traits/src/rate_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ pub fn calc_utilization_ratio(
let utilization_ratio = borrows
.checked_div(&total)
.expect("above checks prove it cannot error")
.checked_mul_int(100u16)
.unwrap()
.checked_mul_int(100_u16)
.ok_or(ArithmeticError::Overflow)?
.try_into()
.unwrap();
.map_err(|_| ArithmeticError::Overflow)?;
Ok(Percent::from_percent(utilization_ratio))
}

Expand All @@ -84,6 +84,8 @@ pub enum InterestRateModel {
}

impl Default for InterestRateModel {
// unwrap is used with known parameters, and unit tested right below.
#[allow(clippy::disallowed_method)]
fn default() -> Self {
Self::new_jump_model(
Rate::saturating_from_rational(2, 100),
Expand All @@ -95,6 +97,11 @@ impl Default for InterestRateModel {
}
}

#[test]
fn test_interest_rate_model_default() {
InterestRateModel::default();
}

impl InterestRateModel {
pub fn new_jump_model(
base_rate: Rate,
Expand Down Expand Up @@ -299,8 +306,8 @@ impl DynamicPIDControllerModel {
utilization_ratio: FixedU128,
) -> Result<Rate, ArithmeticError> {
// compute error term `et = uo - ut`
let et: i128 = self.uo.into_inner().try_into().unwrap_or(0i128) -
utilization_ratio.into_inner().try_into().unwrap_or(0i128);
let et: i128 = self.uo.into_inner().try_into().unwrap_or(0_i128) -
utilization_ratio.into_inner().try_into().unwrap_or(0_i128);
let et: FixedI128 = FixedI128::from_inner(et);
// compute proportional term `pt = kp * et`
let pt = self.kp.checked_mul(&et).ok_or(ArithmeticError::Overflow)?;
Expand All @@ -319,13 +326,13 @@ impl DynamicPIDControllerModel {
// update interest_rate `ir = ir_t_1 + ut`
if ut.is_negative() {
let ut = ut.neg();
self.ir_t_1 = self
.ir_t_1
.saturating_sub(FixedU128::from_inner(ut.into_inner().try_into().unwrap_or(0u128)));
self.ir_t_1 = self.ir_t_1.saturating_sub(FixedU128::from_inner(
ut.into_inner().try_into().unwrap_or(0_u128),
));
} else {
self.ir_t_1 = self
.ir_t_1
.saturating_add(FixedU128::from_inner(ut.into_inner().try_into().unwrap_or(0u128)));
self.ir_t_1 = self.ir_t_1.saturating_add(FixedU128::from_inner(
ut.into_inner().try_into().unwrap_or(0_u128),
));
}
Ok(self.ir_t_1)
}
Expand Down Expand Up @@ -380,7 +387,7 @@ pub struct DoubleExponentModel {
impl DoubleExponentModel {
/// Create a double exponent model
pub fn new_model(coefficients: [u8; 16]) -> Option<Self> {
let sum_of_coefficients = coefficients.iter().fold(0u16, |acc, &c| acc + c as u16);
let sum_of_coefficients = coefficients.iter().fold(0_u16, |acc, &c| acc + c as u16);
if sum_of_coefficients == EXPECTED_COEFFICIENTS_SUM {
return Some(DoubleExponentModel { coefficients })
}
Expand All @@ -402,7 +409,7 @@ impl InterestRate for DoubleExponentModel {
Some((result, polynomial))
});
res.map(|(r, _p)| r.checked_div(&FixedU128::from_inner(EXPECTED_COEFFICIENTS_SUM.into())))
.unwrap()
.flatten()
}
}

Expand Down Expand Up @@ -531,10 +538,10 @@ mod tests {

fn valid_jump_model() -> impl Strategy<Value = JumpModelStrategy> {
(
(1..=10u32).prop_map(|x| Ratio::saturating_from_rational(x, 100)),
(11..=30u32).prop_map(|x| Ratio::saturating_from_rational(x, 100)),
(1..=10_u32).prop_map(|x| Ratio::saturating_from_rational(x, 100)),
(11..=30_u32).prop_map(|x| Ratio::saturating_from_rational(x, 100)),
(31..=50).prop_map(|x| Ratio::saturating_from_rational(x, 100)),
(0..=100u8).prop_map(Percent::from_percent),
(0..=100_u8).prop_map(Percent::from_percent),
)
.prop_filter("Jump rate model", |(base, jump, full, _)| {
// tried high order strategy - failed as it tries to combine collections with not
Expand All @@ -559,9 +566,9 @@ mod tests {
#[test]
fn test_empty_drained_market() {
let mut jump_model = JumpModel::new_model(
FixedU128::from_float(0.010000000000000000),
FixedU128::from_float(0.110000000000000000),
FixedU128::from_float(0.310000000000000000),
FixedU128::from_float(0.01),
FixedU128::from_float(0.11),
FixedU128::from_float(0.31),
Percent::zero(),
)
.unwrap();
Expand All @@ -575,9 +582,9 @@ mod tests {
#[test]
fn test_slope() {
let mut jump_model = JumpModel::new_model(
FixedU128::from_float(0.010000000000000000),
FixedU128::from_float(0.110000000000000000),
FixedU128::from_float(0.310000000000000000),
FixedU128::from_float(0.01),
FixedU128::from_float(0.11),
FixedU128::from_float(0.31),
Percent::from_percent(80),
)
.unwrap();
Expand All @@ -603,7 +610,7 @@ mod tests {
fn proptest_jump_model() {
let mut runner = TestRunner::default();
runner
.run(&(valid_jump_model(), 0..=100u8), |(strategy, utilization)| {
.run(&(valid_jump_model(), 0..=100_u8), |(strategy, utilization)| {
let base_rate = strategy.base_rate;
let jump_rate = strategy.jump_percentage;
let full_rate = strategy.full_percentage;
Expand All @@ -626,7 +633,7 @@ mod tests {
let base_rate = Rate::saturating_from_rational(2, 100);
let jump_rate = Rate::saturating_from_rational(10, 100);
let full_rate = Rate::saturating_from_rational(32, 100);
let strategy = (0..=100u8, 1..=99u8)
let strategy = (0..=100_u8, 1..=99_u8)
.prop_map(|(optimal, utilization)| (optimal, utilization, utilization + 1));

let mut runner = TestRunner::default();
Expand Down

0 comments on commit 4a85928

Please sign in to comment.