From 3536f46600f169d66aa04d6fcf247adcf85a275d Mon Sep 17 00:00:00 2001 From: Gianfranco Date: Fri, 3 May 2024 11:37:05 -0300 Subject: [PATCH 01/15] add clippy step for ci --- .github/workflows/test-code.yml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test-code.yml b/.github/workflows/test-code.yml index fbc54f046..debcbd465 100644 --- a/.github/workflows/test-code.yml +++ b/.github/workflows/test-code.yml @@ -58,10 +58,6 @@ jobs: # Call `rustup show` as a hack so that the toolchain defined in rust-toolchain.toml is installed run: rustup show - # Enable this for clippy linting. - # - name: Check and Lint Code - # run: cargo +nightly-2021-12-01 clippy -- -D warnings - - name: Install Protoc uses: arduino/setup-protoc@v1 with: @@ -72,3 +68,10 @@ jobs: - name: Test Code run: cargo test + + - name: Clippy -- Main + uses: actions-rs/cargo@v1 + with: + command: clippy + args: --all-features -- -W clippy::all -A clippy::style -A clippy::forget_copy -A clippy::forget_ref + From 48123466479d5170c339e8a55d25ea45a83aa3f9 Mon Sep 17 00:00:00 2001 From: Gianfranco Date: Fri, 3 May 2024 11:58:03 -0300 Subject: [PATCH 02/15] clippy fixes --- .../orml-tokens-management-extension/src/lib.rs | 8 ++++---- pallets/parachain-staking/src/types.rs | 10 ++++------ pallets/treasury-buyout-extension/src/lib.rs | 14 +++++--------- 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/pallets/orml-tokens-management-extension/src/lib.rs b/pallets/orml-tokens-management-extension/src/lib.rs index 59f1c6e2d..523adb16d 100644 --- a/pallets/orml-tokens-management-extension/src/lib.rs +++ b/pallets/orml-tokens-management-extension/src/lib.rs @@ -131,7 +131,7 @@ pub mod pallet { .map_err(|_| Error::::InsufficientBalance)?; CurrencyData::::insert( - currency_id.clone(), + currency_id, CurrencyDetails { owner: creator.clone(), issuer: creator.clone(), @@ -231,7 +231,7 @@ pub mod pallet { ) -> DispatchResult { let origin = ensure_signed(origin)?; - CurrencyData::::try_mutate(currency_id.clone(), |maybe_details| { + CurrencyData::::try_mutate(currency_id, |maybe_details| { let details = maybe_details.as_mut().ok_or(Error::::NotCreated)?; ensure!(origin == details.owner, Error::::NoPermission); @@ -271,7 +271,7 @@ pub mod pallet { ) -> DispatchResult { ensure_root(origin)?; - CurrencyData::::try_mutate(currency_id.clone(), |maybe_details| { + CurrencyData::::try_mutate(currency_id, |maybe_details| { let details = maybe_details.as_mut().ok_or(Error::::NotCreated)?; if details.owner == new_owner { @@ -311,7 +311,7 @@ pub mod pallet { ) -> DispatchResult { let origin = ensure_signed(origin)?; - CurrencyData::::try_mutate(currency_id.clone(), |maybe_details| { + CurrencyData::::try_mutate(currency_id, |maybe_details| { let details = maybe_details.as_mut().ok_or(Error::::NotCreated)?; ensure!(origin == details.owner, Error::::NoPermission); diff --git a/pallets/parachain-staking/src/types.rs b/pallets/parachain-staking/src/types.rs index 9b74b089e..44e6c28fa 100644 --- a/pallets/parachain-staking/src/types.rs +++ b/pallets/parachain-staking/src/types.rs @@ -85,18 +85,16 @@ impl Ord for Stake /// The activity status of the collator. #[derive(Copy, Clone, PartialEq, Eq, Encode, Decode, RuntimeDebug, TypeInfo, MaxEncodedLen)] +#[derive(Default)] pub enum CandidateStatus { /// Committed to be online and producing valid blocks (not equivocating) - Active, + #[default] + Active, /// Staked until the inner round Leaving(SessionIndex), } -impl Default for CandidateStatus { - fn default() -> CandidateStatus { - CandidateStatus::Active - } -} + #[derive(Encode, Decode, Clone, RuntimeDebug, PartialEq, Eq, TypeInfo, MaxEncodedLen)] #[scale_info(skip_type_params(MaxDelegatorsPerCandidate))] diff --git a/pallets/treasury-buyout-extension/src/lib.rs b/pallets/treasury-buyout-extension/src/lib.rs index 1e76cc700..976f50589 100644 --- a/pallets/treasury-buyout-extension/src/lib.rs +++ b/pallets/treasury-buyout-extension/src/lib.rs @@ -290,7 +290,7 @@ impl Pallet { >::block_number().saturated_into::(); let current_period_start_number = current_block_number .checked_div(buyout_period) - .and_then(|n| Some(n.saturating_mul(buyout_period))) + .map(|n| n.saturating_mul(buyout_period)) .unwrap_or_default(); let (mut buyouts, last_buyout) = Buyouts::::get(account_id); @@ -348,8 +348,7 @@ impl Pallet { basic_asset_price_with_fee.into_inner(), exchange_asset_price.into_inner(), ) - .map(|n| n.try_into().ok()) - .flatten() + .and_then(|n| n.try_into().ok()) .ok_or(ArithmeticError::Overflow.into()); exchange_amount @@ -377,8 +376,7 @@ impl Pallet { exchange_asset_price.into_inner(), basic_asset_price_with_fee.into_inner(), ) - .map(|b| b.try_into().ok()) - .flatten() + .and_then(|b| b.try_into().ok()) .ok_or(ArithmeticError::Overflow.into()); buyout_amount @@ -470,11 +468,9 @@ impl Pallet { assets: (&CurrencyIdOf, &CurrencyIdOf), ) -> Result<(FixedU128, FixedU128), DispatchError> { let basic_asset_price: FixedU128 = T::PriceGetter::get_price::(*assets.0) - .map_err(|_| Error::::NoPrice)? - .into(); + .map_err(|_| Error::::NoPrice)?; let exchange_asset_price: FixedU128 = T::PriceGetter::get_price::(*assets.1) - .map_err(|_| Error::::NoPrice)? - .into(); + .map_err(|_| Error::::NoPrice)?; Ok((basic_asset_price, exchange_asset_price)) } } From 6befe83706adce59e89e2350d67aca6061f139a6 Mon Sep 17 00:00:00 2001 From: Gianfranco Date: Fri, 3 May 2024 15:28:58 -0300 Subject: [PATCH 03/15] fix dependencies for clippy all-targets compilation --- .github/workflows/test-code.yml | 7 +++++++ Cargo.lock | 8 -------- pallets/parachain-staking/Cargo.toml | 3 ++- pallets/vesting-manager/Cargo.toml | 1 + runtime/common/Cargo.toml | 2 ++ 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test-code.yml b/.github/workflows/test-code.yml index debcbd465..76fe7f2e1 100644 --- a/.github/workflows/test-code.yml +++ b/.github/workflows/test-code.yml @@ -75,3 +75,10 @@ jobs: command: clippy args: --all-features -- -W clippy::all -A clippy::style -A clippy::forget_copy -A clippy::forget_ref + - name: Clippy -- All Targets + uses: actions-rs/cargo@v1 + with: + command: clippy + # We are a bit more forgiving when it comes to the code in tests and only check for correctness + args: --all-features --all-targets -- -A clippy::all -W clippy::correctness -A clippy::forget_copy -A clippy::forget_ref + diff --git a/Cargo.lock b/Cargo.lock index 8bd0e6266..c793b3467 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6535,13 +6535,11 @@ name = "pallet-asset-tx-payment" version = "4.0.0-dev" source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ - "frame-benchmarking", "frame-support", "frame-system", "pallet-transaction-payment", "parity-scale-codec", "scale-info", - "serde", "sp-core", "sp-io", "sp-runtime", @@ -6753,7 +6751,6 @@ name = "pallet-collator-selection" version = "3.0.0" source = "git+https://github.com/paritytech/cumulus.git?branch=polkadot-v0.9.42#f603a61ff370fc33740c9373833c3c6ba1486846" dependencies = [ - "frame-benchmarking", "frame-support", "frame-system", "log", @@ -7089,7 +7086,6 @@ version = "4.0.0-dev" source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "enumflags2", - "frame-benchmarking", "frame-support", "frame-system", "log", @@ -7555,7 +7551,6 @@ name = "pallet-uniques" version = "4.0.0-dev" source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ - "frame-benchmarking", "frame-support", "frame-system", "log", @@ -13123,7 +13118,6 @@ dependencies = [ "pallet-nfts-runtime-api", "pallet-proxy", "pallet-session", - "pallet-state-trie-migration", "pallet-timestamp", "pallet-transaction-payment", "pallet-transaction-payment-rpc-runtime-api", @@ -13150,7 +13144,6 @@ dependencies = [ "sp-transaction-pool", "sp-version", "sp-weights", - "substrate-wasm-builder", "xcm", "xcm-builder", "xcm-executor", @@ -13212,7 +13205,6 @@ dependencies = [ "sp-transaction-pool", "sp-version", "sp-weights", - "substrate-wasm-builder", "xcm", "xcm-builder", "xcm-executor", diff --git a/pallets/parachain-staking/Cargo.toml b/pallets/parachain-staking/Cargo.toml index fe74b9581..869191bad 100644 --- a/pallets/parachain-staking/Cargo.toml +++ b/pallets/parachain-staking/Cargo.toml @@ -36,9 +36,10 @@ frame-benchmarking = {git = "https://github.com/paritytech/substrate", branch = [features] default = ["std"] runtime-benchmarks = [ - "frame-benchmarking", + "frame-benchmarking/runtime-benchmarks", "frame-support/runtime-benchmarks", "frame-system/runtime-benchmarks", + "pallet-balances/runtime-benchmarks", ] std = [ "frame-support/std", diff --git a/pallets/vesting-manager/Cargo.toml b/pallets/vesting-manager/Cargo.toml index 0443644ae..707011fb2 100644 --- a/pallets/vesting-manager/Cargo.toml +++ b/pallets/vesting-manager/Cargo.toml @@ -27,6 +27,7 @@ runtime-benchmarks = [ "frame-benchmarking", "frame-support/runtime-benchmarks", "frame-system/runtime-benchmarks", + "pallet-vesting/runtime-benchmarks" ] std = [ "frame-support/std", diff --git a/runtime/common/Cargo.toml b/runtime/common/Cargo.toml index 27535c158..e4678a047 100644 --- a/runtime/common/Cargo.toml +++ b/runtime/common/Cargo.toml @@ -67,4 +67,6 @@ runtime-benchmarks = [ "sp-runtime/runtime-benchmarks", "frame-support/runtime-benchmarks", "frame-system/runtime-benchmarks", + "orml-asset-registry/runtime-benchmarks", + ] From d2dc4d552e2434458d8cfb80cc8cd345dfd7add6 Mon Sep 17 00:00:00 2001 From: Gianfranco Date: Fri, 3 May 2024 16:24:52 -0300 Subject: [PATCH 04/15] more clippy fixes --- Cargo.lock | 8 +++++++ chain-extensions/token/src/lib.rs | 21 +++++++++---------- .../src/lib.rs | 10 ++++----- pallets/treasury-buyout-extension/src/lib.rs | 20 ++++++++---------- .../treasury-buyout-extension/src/tests.rs | 6 +++--- 5 files changed, 35 insertions(+), 30 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c793b3467..8bd0e6266 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6535,11 +6535,13 @@ name = "pallet-asset-tx-payment" version = "4.0.0-dev" source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ + "frame-benchmarking", "frame-support", "frame-system", "pallet-transaction-payment", "parity-scale-codec", "scale-info", + "serde", "sp-core", "sp-io", "sp-runtime", @@ -6751,6 +6753,7 @@ name = "pallet-collator-selection" version = "3.0.0" source = "git+https://github.com/paritytech/cumulus.git?branch=polkadot-v0.9.42#f603a61ff370fc33740c9373833c3c6ba1486846" dependencies = [ + "frame-benchmarking", "frame-support", "frame-system", "log", @@ -7086,6 +7089,7 @@ version = "4.0.0-dev" source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ "enumflags2", + "frame-benchmarking", "frame-support", "frame-system", "log", @@ -7551,6 +7555,7 @@ name = "pallet-uniques" version = "4.0.0-dev" source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" dependencies = [ + "frame-benchmarking", "frame-support", "frame-system", "log", @@ -13118,6 +13123,7 @@ dependencies = [ "pallet-nfts-runtime-api", "pallet-proxy", "pallet-session", + "pallet-state-trie-migration", "pallet-timestamp", "pallet-transaction-payment", "pallet-transaction-payment-rpc-runtime-api", @@ -13144,6 +13150,7 @@ dependencies = [ "sp-transaction-pool", "sp-version", "sp-weights", + "substrate-wasm-builder", "xcm", "xcm-builder", "xcm-executor", @@ -13205,6 +13212,7 @@ dependencies = [ "sp-transaction-pool", "sp-version", "sp-weights", + "substrate-wasm-builder", "xcm", "xcm-builder", "xcm-executor", diff --git a/chain-extensions/token/src/lib.rs b/chain-extensions/token/src/lib.rs index c82b2497b..05db0285d 100644 --- a/chain-extensions/token/src/lib.rs +++ b/chain-extensions/token/src/lib.rs @@ -73,7 +73,7 @@ where + orml_currencies_allowance_extension::Config, ::AccountId: UncheckedFrom<::Hash> + AsRef<[u8]>, Tokens: orml_traits::MultiCurrency, - AccountId: sp_std::fmt::Debug + Decode, + AccountId: sp_std::fmt::Debug + Decode + core::clone::Clone, { fn call(&mut self, env: Environment) -> Result where @@ -92,15 +92,14 @@ where 0, ); - let result = match func_id { + match func_id { FuncId::TotalSupply => total_supply(env, overhead_weight), FuncId::BalanceOf => balance_of(env, overhead_weight), FuncId::Transfer => transfer(env, overhead_weight), FuncId::Allowance => allowance(env, overhead_weight), FuncId::Approve => approve(env, overhead_weight), FuncId::TransferFrom => transfer_from(env, overhead_weight), - }; - result + } } fn enabled() -> bool { @@ -200,7 +199,7 @@ where + orml_currencies::Config + orml_currencies_allowance_extension::Config, E: Ext, - AccountId: sp_std::fmt::Debug, + AccountId: sp_std::fmt::Debug + core::clone::Clone, Tokens: orml_traits::MultiCurrency, (CurrencyId, AccountId, >::Balance): Decode, { @@ -219,7 +218,7 @@ where "Calling transfer() sending {:?} {:?}, from {:?} to {:?}", amount, currency_id, - env.ext().caller().clone(), + &(*env.ext().caller()).clone(), recipient ); @@ -292,7 +291,7 @@ where + orml_currencies::Config + orml_currencies_allowance_extension::Config, E: Ext, - AccountId: sp_std::fmt::Debug, + AccountId: sp_std::fmt::Debug + core::clone::Clone, Tokens: orml_traits::MultiCurrency, (CurrencyId, AccountId, >::Balance): Decode, { @@ -311,7 +310,7 @@ where spender, amount, currency_id, - env.ext().caller().clone(), + &(*env.ext().caller()).clone(), ); if !orml_currencies_allowance_extension::Pallet::::is_allowed_currency(currency_id) { @@ -338,7 +337,7 @@ where + orml_currencies::Config + orml_currencies_allowance_extension::Config, E: Ext, - AccountId: sp_std::fmt::Debug, + AccountId: sp_std::fmt::Debug + core::clone::Clone, Tokens: orml_traits::MultiCurrency, (AccountId, CurrencyId, AccountId, >::Balance): Decode, { @@ -358,7 +357,7 @@ where trace!( "Calling transfer_from() for caller {:?}, sending {:?} {:?}, from {:?} to {:?}", - env.ext().caller().clone(), + &(*env.ext().caller()).clone(), amount, currency_id, owner, @@ -372,7 +371,7 @@ where orml_currencies_allowance_extension::Pallet::::do_transfer_approved( currency_id, &owner, - &env.ext().caller().clone(), + &(*env.ext().caller()).clone(), &recipient, amount, )?; diff --git a/pallets/orml-tokens-management-extension/src/lib.rs b/pallets/orml-tokens-management-extension/src/lib.rs index 523adb16d..d2c35e962 100644 --- a/pallets/orml-tokens-management-extension/src/lib.rs +++ b/pallets/orml-tokens-management-extension/src/lib.rs @@ -124,7 +124,7 @@ pub mod pallet { T::CurrencyIdChecker::is_valid_currency_id(¤cy_id), Error::::NotOwnableCurrency ); - ensure!(!CurrencyData::::contains_key(¤cy_id), Error::::AlreadyCreated); + ensure!(!CurrencyData::::contains_key(currency_id), Error::::AlreadyCreated); let deposit = T::AssetDeposit::get(); ext::orml_tokens::reserve::(T::DepositCurrency::get(), &creator, deposit) @@ -175,7 +175,7 @@ pub mod pallet { ensure!(origin == currency_data.issuer, Error::::NoPermission); // do mint via orml-currencies - let _ = ext::orml_tokens::mint::(currency_id, &to, amount)?; + ext::orml_tokens::mint::(currency_id, &to, amount)?; Self::deposit_event(Event::Mint { currency_id, to, amount }); Ok(()) @@ -207,7 +207,7 @@ pub mod pallet { ensure!(origin == currency_data.admin, Error::::NoPermission); // do burn via orml-currencies - let _ = ext::orml_tokens::burn::(currency_id, &from, amount)?; + ext::orml_tokens::burn::(currency_id, &from, amount)?; Self::deposit_event(Event::Burned { currency_id, from, amount }); Ok(()) @@ -241,7 +241,7 @@ pub mod pallet { details.owner = new_owner.clone(); // move reserved balance to the new owner's account - let _ = ext::orml_tokens::repatriate_reserve::( + ext::orml_tokens::repatriate_reserve::( T::DepositCurrency::get(), &origin, &new_owner, @@ -277,7 +277,7 @@ pub mod pallet { if details.owner == new_owner { return Ok(()) } - let _ = ext::orml_tokens::repatriate_reserve::( + ext::orml_tokens::repatriate_reserve::( T::DepositCurrency::get(), &details.owner, &new_owner, diff --git a/pallets/treasury-buyout-extension/src/lib.rs b/pallets/treasury-buyout-extension/src/lib.rs index 976f50589..0d95e88ed 100644 --- a/pallets/treasury-buyout-extension/src/lib.rs +++ b/pallets/treasury-buyout-extension/src/lib.rs @@ -265,7 +265,7 @@ pub mod pallet { // Update `AllowedCurrencies` storage with provided `assets` for asset in assets.clone() { // Check for duplicates - if !AllowedCurrencies::::contains_key(&asset) { + if !AllowedCurrencies::::contains_key(asset) { AllowedCurrencies::::insert(asset, ()); allowed_assets.push(asset); } @@ -343,15 +343,14 @@ impl Pallet { .ok_or::(ArithmeticError::Overflow.into())?; let basic_asset_price_with_fee = basic_asset_price.saturating_mul(fee_plus_one); - let exchange_amount = Self::multiply_by_rational( + Self::multiply_by_rational( buyout_amount.saturated_into::(), basic_asset_price_with_fee.into_inner(), exchange_asset_price.into_inner(), ) .and_then(|n| n.try_into().ok()) - .ok_or(ArithmeticError::Overflow.into()); + .ok_or(ArithmeticError::Overflow.into()) - exchange_amount } /// Used for calculating buyout amount of basic asset user will get for exchange_amount of exchange asset @@ -371,15 +370,13 @@ impl Pallet { .ok_or::(ArithmeticError::Overflow.into())?; let basic_asset_price_with_fee = basic_asset_price.saturating_mul(fee_plus_one); - let buyout_amount = Self::multiply_by_rational( + Self::multiply_by_rational( exchange_amount.saturated_into::(), exchange_asset_price.into_inner(), basic_asset_price_with_fee.into_inner(), ) .and_then(|b| b.try_into().ok()) - .ok_or(ArithmeticError::Overflow.into()); - - buyout_amount + .ok_or(ArithmeticError::Overflow.into()) } /// Used for splitting calculations of amount based on the input given @@ -584,8 +581,7 @@ where _info: &DispatchInfoOf, _len: usize, ) -> TransactionValidity { - if let Some(local_call) = call.is_sub_type() { - if let Call::buyout { asset, amount } = local_call { + if let Some(Call::buyout { asset, amount }) = call.is_sub_type() { Pallet::::ensure_asset_allowed_for_buyout(asset).map_err(|_| { InvalidTransaction::Custom(ValidityError::WrongAssetToBuyout.into()) })?; @@ -609,9 +605,11 @@ where Pallet::::ensure_buyout_limit_not_exceeded(who, buyout_amount).map_err( |_| InvalidTransaction::Custom(ValidityError::BuyoutLimitExceeded.into()), )?; - } + } Ok(ValidTransaction::default()) } + + } diff --git a/pallets/treasury-buyout-extension/src/tests.rs b/pallets/treasury-buyout-extension/src/tests.rs index d3a0957b6..bf2c5d3dc 100644 --- a/pallets/treasury-buyout-extension/src/tests.rs +++ b/pallets/treasury-buyout-extension/src/tests.rs @@ -161,7 +161,7 @@ fn root_update_buyout_amount_limit_succeeds() { let buyout_amount_limit = 200 * UNIT; assert_ok!(crate::Pallet::::update_buyout_limit( RuntimeOrigin::root(), - Some(buyout_amount_limit.into()), + Some(buyout_amount_limit), )); assert_eq!(BuyoutLimit::::get(), buyout_amount_limit.into()); @@ -185,7 +185,7 @@ fn user_update_buyout_amount_limit_fails() { assert_noop!( crate::Pallet::::update_buyout_limit( RuntimeOrigin::signed(user), - Some(buyout_amount_limit.into()), + Some(buyout_amount_limit), ), BadOrigin ); @@ -596,7 +596,7 @@ mod signed_extension { // With buyout limit BuyoutLimit::::put(100 * UNIT); // Previous buyout at current_block - Buyouts::::insert(&user, (80 * UNIT, current_block)); + Buyouts::::insert(user, (80 * UNIT, current_block)); let check = CheckBuyout::::new(); let info = info_from_weight(Weight::zero()); From 0dcf36464d7cb47f38fec0c07280508ad81f6fa3 Mon Sep 17 00:00:00 2001 From: Gianfranco Date: Fri, 3 May 2024 16:31:22 -0300 Subject: [PATCH 05/15] clippy in different step for integration test crate --- .github/workflows/test-code.yml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-code.yml b/.github/workflows/test-code.yml index 76fe7f2e1..c0833d57f 100644 --- a/.github/workflows/test-code.yml +++ b/.github/workflows/test-code.yml @@ -75,10 +75,17 @@ jobs: command: clippy args: --all-features -- -W clippy::all -A clippy::style -A clippy::forget_copy -A clippy::forget_ref - - name: Clippy -- All Targets + - name: Clippy -- All Targets (except integration) + uses: actions-rs/cargo@v1 + with: + command: clippy + # We are a bit more forgiving when it comes to the code in tests and only check for correctness + args: --workspace --all-features --all-targets --exclude runtime-integration-tests -- -A clippy::all -W clippy::correctness -A clippy::forget_copy -A clippy::forget_ref + + - name: Clippy -- Integration uses: actions-rs/cargo@v1 with: command: clippy # We are a bit more forgiving when it comes to the code in tests and only check for correctness - args: --all-features --all-targets -- -A clippy::all -W clippy::correctness -A clippy::forget_copy -A clippy::forget_ref + args: --package runtime-integration-tests --all-features --all-targets -- -A clippy::all -W clippy::correctness -A clippy::forget_copy -A clippy::forget_ref From 258a9cd88c3628217ee11216dbb765030ec19cef Mon Sep 17 00:00:00 2001 From: Gianfranco Date: Fri, 3 May 2024 16:33:32 -0300 Subject: [PATCH 06/15] yml format --- .github/workflows/test-code.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test-code.yml b/.github/workflows/test-code.yml index c0833d57f..2c0495e4a 100644 --- a/.github/workflows/test-code.yml +++ b/.github/workflows/test-code.yml @@ -76,11 +76,11 @@ jobs: args: --all-features -- -W clippy::all -A clippy::style -A clippy::forget_copy -A clippy::forget_ref - name: Clippy -- All Targets (except integration) - uses: actions-rs/cargo@v1 - with: - command: clippy - # We are a bit more forgiving when it comes to the code in tests and only check for correctness - args: --workspace --all-features --all-targets --exclude runtime-integration-tests -- -A clippy::all -W clippy::correctness -A clippy::forget_copy -A clippy::forget_ref + uses: actions-rs/cargo@v1 + with: + command: clippy + # We are a bit more forgiving when it comes to the code in tests and only check for correctness + args: --workspace --all-features --all-targets --exclude runtime-integration-tests -- -A clippy::all -W clippy::correctness -A clippy::forget_copy -A clippy::forget_ref - name: Clippy -- Integration uses: actions-rs/cargo@v1 From 960caadc323d9407c03af349625ab22b84eb915b Mon Sep 17 00:00:00 2001 From: Gianfranco Date: Mon, 6 May 2024 09:53:43 -0300 Subject: [PATCH 07/15] rollback clippy warning fixes --- .github/workflows/test-code.yml | 2 +- chain-extensions/token/src/lib.rs | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test-code.yml b/.github/workflows/test-code.yml index 2c0495e4a..8e07c5e77 100644 --- a/.github/workflows/test-code.yml +++ b/.github/workflows/test-code.yml @@ -88,4 +88,4 @@ jobs: command: clippy # We are a bit more forgiving when it comes to the code in tests and only check for correctness args: --package runtime-integration-tests --all-features --all-targets -- -A clippy::all -W clippy::correctness -A clippy::forget_copy -A clippy::forget_ref - + \ No newline at end of file diff --git a/chain-extensions/token/src/lib.rs b/chain-extensions/token/src/lib.rs index 05db0285d..f539a2c48 100644 --- a/chain-extensions/token/src/lib.rs +++ b/chain-extensions/token/src/lib.rs @@ -73,7 +73,7 @@ where + orml_currencies_allowance_extension::Config, ::AccountId: UncheckedFrom<::Hash> + AsRef<[u8]>, Tokens: orml_traits::MultiCurrency, - AccountId: sp_std::fmt::Debug + Decode + core::clone::Clone, + AccountId: sp_std::fmt::Debug + Decode, { fn call(&mut self, env: Environment) -> Result where @@ -199,7 +199,7 @@ where + orml_currencies::Config + orml_currencies_allowance_extension::Config, E: Ext, - AccountId: sp_std::fmt::Debug + core::clone::Clone, + AccountId: sp_std::fmt::Debug, Tokens: orml_traits::MultiCurrency, (CurrencyId, AccountId, >::Balance): Decode, { @@ -218,7 +218,7 @@ where "Calling transfer() sending {:?} {:?}, from {:?} to {:?}", amount, currency_id, - &(*env.ext().caller()).clone(), + env.ext().caller().clone(), recipient ); @@ -291,7 +291,7 @@ where + orml_currencies::Config + orml_currencies_allowance_extension::Config, E: Ext, - AccountId: sp_std::fmt::Debug + core::clone::Clone, + AccountId: sp_std::fmt::Debug, Tokens: orml_traits::MultiCurrency, (CurrencyId, AccountId, >::Balance): Decode, { @@ -310,7 +310,7 @@ where spender, amount, currency_id, - &(*env.ext().caller()).clone(), + env.ext().caller().clone(), ); if !orml_currencies_allowance_extension::Pallet::::is_allowed_currency(currency_id) { @@ -337,7 +337,7 @@ where + orml_currencies::Config + orml_currencies_allowance_extension::Config, E: Ext, - AccountId: sp_std::fmt::Debug + core::clone::Clone, + AccountId: sp_std::fmt::Debug, Tokens: orml_traits::MultiCurrency, (AccountId, CurrencyId, AccountId, >::Balance): Decode, { @@ -357,7 +357,7 @@ where trace!( "Calling transfer_from() for caller {:?}, sending {:?} {:?}, from {:?} to {:?}", - &(*env.ext().caller()).clone(), + env.ext().caller().clone(), amount, currency_id, owner, @@ -371,7 +371,7 @@ where orml_currencies_allowance_extension::Pallet::::do_transfer_approved( currency_id, &owner, - &(*env.ext().caller()).clone(), + &env.ext().caller().clone(), &recipient, amount, )?; From 11f2eacb4e597fd7fdcb5e159fdbe1eed14d5681 Mon Sep 17 00:00:00 2001 From: Gianfranco Date: Tue, 7 May 2024 13:57:09 -0300 Subject: [PATCH 08/15] clippy warning fixes main target --- chain-extensions/token/src/lib.rs | 18 +++++++++--------- node/src/command.rs | 6 +++--- pallets/parachain-staking/src/benchmarking.rs | 4 ++-- pallets/parachain-staking/src/try_state.rs | 1 + runtime/amplitude/src/chain_ext.rs | 4 ++-- runtime/amplitude/src/lib.rs | 3 +-- runtime/common/src/lib.rs | 2 +- runtime/foucoco/src/chain_ext.rs | 4 ++-- runtime/foucoco/src/lib.rs | 3 +-- runtime/pendulum/src/chain_ext.rs | 4 ++-- runtime/pendulum/src/lib.rs | 2 +- 11 files changed, 25 insertions(+), 26 deletions(-) diff --git a/chain-extensions/token/src/lib.rs b/chain-extensions/token/src/lib.rs index f539a2c48..085da06fb 100644 --- a/chain-extensions/token/src/lib.rs +++ b/chain-extensions/token/src/lib.rs @@ -73,7 +73,7 @@ where + orml_currencies_allowance_extension::Config, ::AccountId: UncheckedFrom<::Hash> + AsRef<[u8]>, Tokens: orml_traits::MultiCurrency, - AccountId: sp_std::fmt::Debug + Decode, + AccountId: sp_std::fmt::Debug + Decode + core::clone::Clone, { fn call(&mut self, env: Environment) -> Result where @@ -199,7 +199,7 @@ where + orml_currencies::Config + orml_currencies_allowance_extension::Config, E: Ext, - AccountId: sp_std::fmt::Debug, + AccountId: sp_std::fmt::Debug + core::clone::Clone, Tokens: orml_traits::MultiCurrency, (CurrencyId, AccountId, >::Balance): Decode, { @@ -218,7 +218,7 @@ where "Calling transfer() sending {:?} {:?}, from {:?} to {:?}", amount, currency_id, - env.ext().caller().clone(), + &(*env.ext().caller()).clone(), recipient ); @@ -228,7 +228,7 @@ where as MultiCurrency>::transfer( currency_id, - &env.ext().caller().clone(), + &&(*env.ext().caller()).clone(), &recipient, amount, )?; @@ -291,7 +291,7 @@ where + orml_currencies::Config + orml_currencies_allowance_extension::Config, E: Ext, - AccountId: sp_std::fmt::Debug, + AccountId: sp_std::fmt::Debug + core::clone::Clone, Tokens: orml_traits::MultiCurrency, (CurrencyId, AccountId, >::Balance): Decode, { @@ -310,7 +310,7 @@ where spender, amount, currency_id, - env.ext().caller().clone(), + &(*env.ext().caller()).clone(), ); if !orml_currencies_allowance_extension::Pallet::::is_allowed_currency(currency_id) { @@ -319,7 +319,7 @@ where orml_currencies_allowance_extension::Pallet::::do_approve_transfer( currency_id, - &env.ext().caller().clone(), + &&(*env.ext().caller()).clone(), &spender, amount, )?; @@ -337,7 +337,7 @@ where + orml_currencies::Config + orml_currencies_allowance_extension::Config, E: Ext, - AccountId: sp_std::fmt::Debug, + AccountId: sp_std::fmt::Debug + core::clone::Clone, Tokens: orml_traits::MultiCurrency, (AccountId, CurrencyId, AccountId, >::Balance): Decode, { @@ -357,7 +357,7 @@ where trace!( "Calling transfer_from() for caller {:?}, sending {:?} {:?}, from {:?} to {:?}", - env.ext().caller().clone(), + &(*env.ext().caller()).clone(), amount, currency_id, owner, diff --git a/node/src/command.rs b/node/src/command.rs index 306a31961..26b94e15e 100644 --- a/node/src/command.rs +++ b/node/src/command.rs @@ -376,19 +376,19 @@ pub fn run() -> Result<()> { .map_err(|e| format!("Error: {:?}", e))?; match runner.config().chain_spec.identify() { - ChainIdentity::Amplitude => runner.async_run(|config| { + ChainIdentity::Amplitude => runner.async_run(|_config| { Ok((cmd.run::::ExtendHostFunctions, >, _>(Some(substrate_info(BLOCK_TIME_MILLIS))), task_manager)) }), - ChainIdentity::Foucoco => runner.async_run(|config| { + ChainIdentity::Foucoco => runner.async_run(|_config| { Ok((cmd.run::::ExtendHostFunctions, >, _>(Some(substrate_info(BLOCK_TIME_MILLIS))), task_manager)) }), - ChainIdentity::Pendulum => runner.async_run(|config| { + ChainIdentity::Pendulum => runner.async_run(|_config| { Ok((cmd.run::::ExtendHostFunctions, diff --git a/pallets/parachain-staking/src/benchmarking.rs b/pallets/parachain-staking/src/benchmarking.rs index d1a748172..9daec6cf4 100644 --- a/pallets/parachain-staking/src/benchmarking.rs +++ b/pallets/parachain-staking/src/benchmarking.rs @@ -305,7 +305,7 @@ benchmarks! { let n in (T::MinCollators::get() + 1) .. T::MaxTopCandidates::get() - 1; let m in 0 .. T::MaxDelegatorsPerCollator::get(); - let u = T::MaxUnstakeRequests::get() as u32 - 1; + let u = T::MaxUnstakeRequests::get() - 1; let candidates = setup_collator_candidates::(n, None); for (i, c) in candidates.iter().enumerate() { fill_delegators::(m, c.clone(), i.saturated_into::()); @@ -530,7 +530,7 @@ benchmarks! { } unlock_unstaked { - let u in 1 .. (T::MaxUnstakeRequests::get() as u32 - 1); + let u in 1 .. (T::MaxUnstakeRequests::get() - 1); let candidate = account("collator", 0u32, COLLATOR_ACCOUNT_SEED); let free_balance = T::CurrencyBalance::from(u128::MAX); diff --git a/pallets/parachain-staking/src/try_state.rs b/pallets/parachain-staking/src/try_state.rs index 899b7bb9e..2deaea2ac 100644 --- a/pallets/parachain-staking/src/try_state.rs +++ b/pallets/parachain-staking/src/try_state.rs @@ -35,6 +35,7 @@ pub fn log_and_return_error_message(error_message: String) -> &'static str { "Sanity test error" } +#[allow(dead_code)] pub(crate) fn do_try_state() -> Result<(), &'static str> { validate_candiate_pool::()?; validate_delegators::()?; diff --git a/runtime/amplitude/src/chain_ext.rs b/runtime/amplitude/src/chain_ext.rs index eafccdcb9..23aa0f7da 100644 --- a/runtime/amplitude/src/chain_ext.rs +++ b/runtime/amplitude/src/chain_ext.rs @@ -6,9 +6,9 @@ pub use price_chain_extension::PriceChainExtension; pub use token_chain_extension::TokensChainExtension; impl RegisteredChainExtension for TokensChainExtension { - const ID: u16 = 01; + const ID: u16 = 1; } impl RegisteredChainExtension for PriceChainExtension { - const ID: u16 = 02; + const ID: u16 = 2; } diff --git a/runtime/amplitude/src/lib.rs b/runtime/amplitude/src/lib.rs index 41504ca7d..090607bc3 100644 --- a/runtime/amplitude/src/lib.rs +++ b/runtime/amplitude/src/lib.rs @@ -86,7 +86,6 @@ pub use dia_oracle::dia::AssetId; pub use issue::{Event as IssueEvent, IssueRequest}; pub use nomination::Event as NominationEvent; use oracle::{ - dia, dia::{DiaOracleAdapter, NativeCurrencyKey, XCMCurrencyConversion}, OracleKey, }; @@ -1472,7 +1471,7 @@ impl treasury_buyout_extension::PriceGetter for OraclePriceGetter { let rate = FixedU128::checked_from_rational(100, 1).expect("This is a valid ratio"); // Account used for feeding values let account = AccountId::from([0u8; 32]); - Oracle::feed_values(account, vec![(key.clone(), rate)])?; + Oracle::feed_values(account, vec![(key, rate)])?; // If feeding was successful, just use the feeded price to spare a read let converted_asset_price = FixedNumber::try_from(rate) diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index bbe5cbc17..a48b1606a 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -3,7 +3,7 @@ use sp_runtime::{ traits::{IdentifyAccount, Verify,Convert}, - DispatchError, MultiSignature, + MultiSignature, }; use spacewalk_primitives::CurrencyId; use xcm::v3::{MultiAsset, AssetId, MultiLocation}; diff --git a/runtime/foucoco/src/chain_ext.rs b/runtime/foucoco/src/chain_ext.rs index eafccdcb9..23aa0f7da 100644 --- a/runtime/foucoco/src/chain_ext.rs +++ b/runtime/foucoco/src/chain_ext.rs @@ -6,9 +6,9 @@ pub use price_chain_extension::PriceChainExtension; pub use token_chain_extension::TokensChainExtension; impl RegisteredChainExtension for TokensChainExtension { - const ID: u16 = 01; + const ID: u16 = 1; } impl RegisteredChainExtension for PriceChainExtension { - const ID: u16 = 02; + const ID: u16 = 2; } diff --git a/runtime/foucoco/src/lib.rs b/runtime/foucoco/src/lib.rs index 55e274192..b3d27927a 100644 --- a/runtime/foucoco/src/lib.rs +++ b/runtime/foucoco/src/lib.rs @@ -105,7 +105,6 @@ use spacewalk_primitives::{ UnsignedFixedPoint, UnsignedInner, }; -use orml_currencies::WeightInfo; use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight}; use frame_support::traits::InstanceFilter; @@ -1079,7 +1078,7 @@ impl treasury_buyout_extension::PriceGetter for OraclePriceGetter { let rate = FixedU128::checked_from_rational(100, 1).expect("This is a valid ratio"); // Account used for feeding values let account = AccountId::from([0u8; 32]); - Oracle::feed_values(account, vec![(key.clone(), rate)])?; + Oracle::feed_values(account, vec![(key, rate)])?; // If feeding was successful, just use the feeded price to spare a read let converted_asset_price = FixedNumber::try_from(rate) diff --git a/runtime/pendulum/src/chain_ext.rs b/runtime/pendulum/src/chain_ext.rs index eafccdcb9..23aa0f7da 100644 --- a/runtime/pendulum/src/chain_ext.rs +++ b/runtime/pendulum/src/chain_ext.rs @@ -6,9 +6,9 @@ pub use price_chain_extension::PriceChainExtension; pub use token_chain_extension::TokensChainExtension; impl RegisteredChainExtension for TokensChainExtension { - const ID: u16 = 01; + const ID: u16 = 1; } impl RegisteredChainExtension for PriceChainExtension { - const ID: u16 = 02; + const ID: u16 = 2; } diff --git a/runtime/pendulum/src/lib.rs b/runtime/pendulum/src/lib.rs index dcda8849f..43480d129 100644 --- a/runtime/pendulum/src/lib.rs +++ b/runtime/pendulum/src/lib.rs @@ -1440,7 +1440,7 @@ impl treasury_buyout_extension::PriceGetter for OraclePriceGetter { let rate = FixedU128::checked_from_rational(100, 1).expect("This is a valid ratio"); // Account used for feeding values let account = AccountId::from([0u8; 32]); - Oracle::feed_values(account, vec![(key.clone(), rate)])?; + Oracle::feed_values(account, vec![(key, rate)])?; // If feeding was successful, just use the feeded price to spare a read let converted_asset_price = FixedNumber::try_from(rate) From 98faeffde3db0fbd9bda0212af8dc5714cee3eb8 Mon Sep 17 00:00:00 2001 From: Gianfranco Date: Tue, 7 May 2024 14:28:56 -0300 Subject: [PATCH 09/15] ignore some unused import warnings --- runtime/amplitude/src/lib.rs | 3 +++ runtime/integration-tests/src/pendulum_tests.rs | 1 + 2 files changed, 4 insertions(+) diff --git a/runtime/amplitude/src/lib.rs b/runtime/amplitude/src/lib.rs index 090607bc3..b1825edb7 100644 --- a/runtime/amplitude/src/lib.rs +++ b/runtime/amplitude/src/lib.rs @@ -89,6 +89,9 @@ use oracle::{ dia::{DiaOracleAdapter, NativeCurrencyKey, XCMCurrencyConversion}, OracleKey, }; +#[allow(unused_imports)] +use oracle::dia; + pub use redeem::{Event as RedeemEvent, RedeemRequest}; pub use replace::{Event as ReplaceEvent, ReplaceRequest}; pub use security::StatusCode; diff --git a/runtime/integration-tests/src/pendulum_tests.rs b/runtime/integration-tests/src/pendulum_tests.rs index 384008fcc..dcbbb8d59 100644 --- a/runtime/integration-tests/src/pendulum_tests.rs +++ b/runtime/integration-tests/src/pendulum_tests.rs @@ -13,6 +13,7 @@ use crate::{ }; use frame_support::assert_ok; +#[allow(unused_imports)] use pendulum_runtime::definitions::moonbeam::PARA_ID as MOONBEAM_PARA_ID; use statemint_runtime as polkadot_asset_hub_runtime; use xcm::latest::NetworkId; From 3635c07de4d964f162906d4d9764cf00e40a6335 Mon Sep 17 00:00:00 2001 From: Gianfranco Date: Tue, 7 May 2024 14:37:57 -0300 Subject: [PATCH 10/15] avoid double reference --- chain-extensions/token/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chain-extensions/token/src/lib.rs b/chain-extensions/token/src/lib.rs index 085da06fb..6e1c12d78 100644 --- a/chain-extensions/token/src/lib.rs +++ b/chain-extensions/token/src/lib.rs @@ -228,7 +228,7 @@ where as MultiCurrency>::transfer( currency_id, - &&(*env.ext().caller()).clone(), + &(*env.ext().caller()).clone(), &recipient, amount, )?; @@ -319,7 +319,7 @@ where orml_currencies_allowance_extension::Pallet::::do_approve_transfer( currency_id, - &&(*env.ext().caller()).clone(), + &(*env.ext().caller()).clone(), &spender, amount, )?; From e2f8afca11ebde869268179b61249fc010c4e7c7 Mon Sep 17 00:00:00 2001 From: Gianfranco Date: Tue, 14 May 2024 13:05:09 -0300 Subject: [PATCH 11/15] remove unnecessary clone --- chain-extensions/token/src/lib.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/chain-extensions/token/src/lib.rs b/chain-extensions/token/src/lib.rs index 6e1c12d78..dad2dc236 100644 --- a/chain-extensions/token/src/lib.rs +++ b/chain-extensions/token/src/lib.rs @@ -218,7 +218,7 @@ where "Calling transfer() sending {:?} {:?}, from {:?} to {:?}", amount, currency_id, - &(*env.ext().caller()).clone(), + env.ext().caller(), recipient ); @@ -228,7 +228,7 @@ where as MultiCurrency>::transfer( currency_id, - &(*env.ext().caller()).clone(), + env.ext().caller(), &recipient, amount, )?; @@ -310,7 +310,7 @@ where spender, amount, currency_id, - &(*env.ext().caller()).clone(), + env.ext().caller(), ); if !orml_currencies_allowance_extension::Pallet::::is_allowed_currency(currency_id) { @@ -319,7 +319,7 @@ where orml_currencies_allowance_extension::Pallet::::do_approve_transfer( currency_id, - &(*env.ext().caller()).clone(), + env.ext().caller(), &spender, amount, )?; @@ -357,7 +357,7 @@ where trace!( "Calling transfer_from() for caller {:?}, sending {:?} {:?}, from {:?} to {:?}", - &(*env.ext().caller()).clone(), + env.ext().caller(), amount, currency_id, owner, @@ -371,7 +371,7 @@ where orml_currencies_allowance_extension::Pallet::::do_transfer_approved( currency_id, &owner, - &env.ext().caller().clone(), + env.ext().caller(), &recipient, amount, )?; From 93981edae80d47eecc2f442f3f7fd25ef91120c4 Mon Sep 17 00:00:00 2001 From: Gianfranco Date: Tue, 14 May 2024 13:08:16 -0300 Subject: [PATCH 12/15] run cargo fmt --- node/src/chain_spec.rs | 1 - node/src/constants/foucoco.rs | 1 - pallets/parachain-staking/src/types.rs | 9 ++- pallets/treasury-buyout-extension/src/lib.rs | 58 +++++++++---------- runtime/amplitude/src/definitions.rs | 1 + runtime/amplitude/src/lib.rs | 6 +- runtime/amplitude/src/xcm_config.rs | 3 +- runtime/common/src/asset_registry.rs | 12 ++-- runtime/common/src/lib.rs | 38 +++++++----- runtime/foucoco/src/definitions.rs | 1 + runtime/foucoco/src/lib.rs | 2 +- runtime/foucoco/src/xcm_config.rs | 12 ++-- .../integration-tests/src/amplitude_tests.rs | 6 +- runtime/integration-tests/src/definitions.rs | 11 ++-- runtime/integration-tests/src/mock.rs | 29 ++++------ .../integration-tests/src/pendulum_tests.rs | 9 ++- runtime/integration-tests/src/sibling.rs | 3 +- runtime/integration-tests/src/test_macros.rs | 2 +- runtime/pendulum/src/definitions.rs | 55 ++++++++---------- runtime/pendulum/src/lib.rs | 11 ++-- runtime/pendulum/src/xcm_config.rs | 2 +- 21 files changed, 133 insertions(+), 139 deletions(-) diff --git a/node/src/chain_spec.rs b/node/src/chain_spec.rs index 5745b41cb..3761542df 100644 --- a/node/src/chain_spec.rs +++ b/node/src/chain_spec.rs @@ -539,7 +539,6 @@ fn foucoco_genesis( .iter() .flat_map(|k| vec![(k.0.clone(), XCM(0), u128::pow(10, 18))]) .collect(); - let stakers: Vec<_> = invulnerables .iter() diff --git a/node/src/constants/foucoco.rs b/node/src/constants/foucoco.rs index 7ff9041fc..e349b20ac 100644 --- a/node/src/constants/foucoco.rs +++ b/node/src/constants/foucoco.rs @@ -10,7 +10,6 @@ pub const COLLATOR_ADDITIONAL: Balance = 10 * UNIT; pub const OFF_CHAIN_WORKER_ADDRESS: &str = "6m69vWMouLarYCbJGJisVaDDpfNGETkD5hsDWf2T7osW4Cn1"; - pub const TOKEN_DECIMALS: u32 = 12; pub const INITIAL_SUDO_SIGNATORIES: [&str; 5] = [ diff --git a/pallets/parachain-staking/src/types.rs b/pallets/parachain-staking/src/types.rs index 44e6c28fa..b2a60a607 100644 --- a/pallets/parachain-staking/src/types.rs +++ b/pallets/parachain-staking/src/types.rs @@ -84,18 +84,17 @@ impl Ord for Stake } /// The activity status of the collator. -#[derive(Copy, Clone, PartialEq, Eq, Encode, Decode, RuntimeDebug, TypeInfo, MaxEncodedLen)] -#[derive(Default)] +#[derive( + Copy, Clone, PartialEq, Eq, Encode, Decode, RuntimeDebug, TypeInfo, MaxEncodedLen, Default, +)] pub enum CandidateStatus { /// Committed to be online and producing valid blocks (not equivocating) #[default] - Active, + Active, /// Staked until the inner round Leaving(SessionIndex), } - - #[derive(Encode, Decode, Clone, RuntimeDebug, PartialEq, Eq, TypeInfo, MaxEncodedLen)] #[scale_info(skip_type_params(MaxDelegatorsPerCandidate))] #[codec(mel_bound(AccountId: MaxEncodedLen, Balance: MaxEncodedLen))] diff --git a/pallets/treasury-buyout-extension/src/lib.rs b/pallets/treasury-buyout-extension/src/lib.rs index 0d95e88ed..cb15a0fa6 100644 --- a/pallets/treasury-buyout-extension/src/lib.rs +++ b/pallets/treasury-buyout-extension/src/lib.rs @@ -350,7 +350,6 @@ impl Pallet { ) .and_then(|n| n.try_into().ok()) .ok_or(ArithmeticError::Overflow.into()) - } /// Used for calculating buyout amount of basic asset user will get for exchange_amount of exchange asset @@ -464,10 +463,10 @@ impl Pallet { fn fetch_prices( assets: (&CurrencyIdOf, &CurrencyIdOf), ) -> Result<(FixedU128, FixedU128), DispatchError> { - let basic_asset_price: FixedU128 = T::PriceGetter::get_price::(*assets.0) - .map_err(|_| Error::::NoPrice)?; - let exchange_asset_price: FixedU128 = T::PriceGetter::get_price::(*assets.1) - .map_err(|_| Error::::NoPrice)?; + let basic_asset_price: FixedU128 = + T::PriceGetter::get_price::(*assets.0).map_err(|_| Error::::NoPrice)?; + let exchange_asset_price: FixedU128 = + T::PriceGetter::get_price::(*assets.1).map_err(|_| Error::::NoPrice)?; Ok((basic_asset_price, exchange_asset_price)) } } @@ -582,34 +581,31 @@ where _len: usize, ) -> TransactionValidity { if let Some(Call::buyout { asset, amount }) = call.is_sub_type() { - Pallet::::ensure_asset_allowed_for_buyout(asset).map_err(|_| { - InvalidTransaction::Custom(ValidityError::WrongAssetToBuyout.into()) - })?; - - let (buyout_amount, exchange_amount) = - Pallet::::split_to_buyout_and_exchange(*asset, *amount) - .map_err(|_| InvalidTransaction::Custom(ValidityError::Math.into()))?; - - ensure!( - buyout_amount >= T::MinAmountToBuyout::get(), - InvalidTransaction::Custom(ValidityError::LessThanMinBuyoutAmount.into()) - ); - - let free_balance = T::Currency::free_balance(*asset, who); - - ensure!( - free_balance >= exchange_amount, - InvalidTransaction::Custom(ValidityError::NotEnoughToBuyout.into()) - ); - - Pallet::::ensure_buyout_limit_not_exceeded(who, buyout_amount).map_err( - |_| InvalidTransaction::Custom(ValidityError::BuyoutLimitExceeded.into()), - )?; - + Pallet::::ensure_asset_allowed_for_buyout(asset).map_err(|_| { + InvalidTransaction::Custom(ValidityError::WrongAssetToBuyout.into()) + })?; + + let (buyout_amount, exchange_amount) = + Pallet::::split_to_buyout_and_exchange(*asset, *amount) + .map_err(|_| InvalidTransaction::Custom(ValidityError::Math.into()))?; + + ensure!( + buyout_amount >= T::MinAmountToBuyout::get(), + InvalidTransaction::Custom(ValidityError::LessThanMinBuyoutAmount.into()) + ); + + let free_balance = T::Currency::free_balance(*asset, who); + + ensure!( + free_balance >= exchange_amount, + InvalidTransaction::Custom(ValidityError::NotEnoughToBuyout.into()) + ); + + Pallet::::ensure_buyout_limit_not_exceeded(who, buyout_amount).map_err(|_| { + InvalidTransaction::Custom(ValidityError::BuyoutLimitExceeded.into()) + })?; } Ok(ValidTransaction::default()) } - - } diff --git a/runtime/amplitude/src/definitions.rs b/runtime/amplitude/src/definitions.rs index e69de29bb..8b1378917 100644 --- a/runtime/amplitude/src/definitions.rs +++ b/runtime/amplitude/src/definitions.rs @@ -0,0 +1 @@ + diff --git a/runtime/amplitude/src/lib.rs b/runtime/amplitude/src/lib.rs index b1825edb7..f09704ac5 100644 --- a/runtime/amplitude/src/lib.rs +++ b/runtime/amplitude/src/lib.rs @@ -7,10 +7,10 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); mod chain_ext; +pub mod definitions; mod weights; pub mod xcm_config; pub mod zenlink; -pub mod definitions; use crate::zenlink::*; use bifrost_farming as farming; @@ -85,12 +85,12 @@ pub use sp_runtime::BuildStorage; pub use dia_oracle::dia::AssetId; pub use issue::{Event as IssueEvent, IssueRequest}; pub use nomination::Event as NominationEvent; +#[allow(unused_imports)] +use oracle::dia; use oracle::{ dia::{DiaOracleAdapter, NativeCurrencyKey, XCMCurrencyConversion}, OracleKey, }; -#[allow(unused_imports)] -use oracle::dia; pub use redeem::{Event as RedeemEvent, RedeemRequest}; pub use replace::{Event as ReplaceEvent, ReplaceRequest}; diff --git a/runtime/amplitude/src/xcm_config.rs b/runtime/amplitude/src/xcm_config.rs index 34634f112..d38925420 100644 --- a/runtime/amplitude/src/xcm_config.rs +++ b/runtime/amplitude/src/xcm_config.rs @@ -22,7 +22,7 @@ use xcm_builder::{ }; use xcm_executor::{traits::ShouldExecute, XcmExecutor}; -use runtime_common::{asset_registry::{FixedConversionRateProvider}, CurrencyIdConvert}; +use runtime_common::{asset_registry::FixedConversionRateProvider, CurrencyIdConvert}; use cumulus_primitives_utility::XcmFeesTo32ByteAccount; @@ -57,7 +57,6 @@ pub type LocationToAccountId = ( AccountId32Aliases, ); - /// A `FilterAssetLocation` implementation. Filters multi native assets whose /// reserve is same with `origin`. pub struct MultiNativeAsset(PhantomData); diff --git a/runtime/common/src/asset_registry.rs b/runtime/common/src/asset_registry.rs index f1e9caa79..00ca87efa 100644 --- a/runtime/common/src/asset_registry.rs +++ b/runtime/common/src/asset_registry.rs @@ -1,15 +1,17 @@ use crate::*; use frame_support::traits::AsEnsureOriginWithArg; use frame_system::EnsureRoot; -use orml_traits::{FixedConversionRateProvider as FixedConversionRateProviderTrait, - asset_registry::{AssetMetadata, AssetProcessor, Inspect}}; +use orml_traits::{ + asset_registry::{AssetMetadata, AssetProcessor, Inspect}, + FixedConversionRateProvider as FixedConversionRateProviderTrait, +}; use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; use scale_info::TypeInfo; use sp_core::Get; -use sp_runtime::{BoundedVec, DispatchError, traits::PhantomData}; +use sp_runtime::{traits::PhantomData, BoundedVec, DispatchError}; use sp_std::fmt::Debug; use spacewalk_primitives::CurrencyId; -use xcm::opaque::v3::{MultiLocation}; +use xcm::opaque::v3::MultiLocation; #[derive(Clone, PartialOrd, Ord, PartialEq, Eq, Debug, Encode, Decode, TypeInfo, MaxEncodedLen)] pub struct StringLimit; @@ -70,4 +72,4 @@ impl< let metadata = OrmlAssetRegistry::metadata_by_location(&location)?; Some(metadata.additional.fee_per_second) } -} \ No newline at end of file +} diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index a48b1606a..52fbec92c 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -1,14 +1,14 @@ #![cfg_attr(not(feature = "std"), no_std)] #![allow(non_snake_case)] +use asset_registry::CustomMetadata; +use orml_traits::asset_registry::Inspect; use sp_runtime::{ - traits::{IdentifyAccount, Verify,Convert}, + traits::{Convert, IdentifyAccount, Verify}, MultiSignature, }; use spacewalk_primitives::CurrencyId; -use xcm::v3::{MultiAsset, AssetId, MultiLocation}; -use orml_traits::asset_registry::Inspect; -use asset_registry::CustomMetadata; +use xcm::v3::{AssetId, MultiAsset, MultiLocation}; pub mod asset_registry; pub mod custom_transactor; @@ -56,8 +56,6 @@ pub type Index = u32; /// A hash of some data used by the chain. pub type Hash = sp_core::H256; - - /// Opaque types. These are used by the CLI to instantiate machinery that don't need to know /// the specifics of the runtime. They can then be made to be agnostic over specific formats /// of data like extrinsics, allowing for them to continue syncing the network through upgrades @@ -150,7 +148,10 @@ pub mod parachains { /// in the form of a `MultiLocation`, in this case a pCfg (Para-Id, Currency-Id). pub struct CurrencyIdConvert(sp_std::marker::PhantomData); -impl> Convert> for CurrencyIdConvert { +impl< + AssetRegistry: Inspect, + > Convert> for CurrencyIdConvert +{ fn convert(id: CurrencyId) -> Option { ::metadata(&id) .filter(|m| m.location.is_some()) @@ -159,13 +160,19 @@ impl> Convert> for CurrencyIdConvert { - fn convert(location: MultiLocation) -> Option { +impl< + AssetRegistry: Inspect, + > Convert> for CurrencyIdConvert +{ + fn convert(location: MultiLocation) -> Option { ::asset_id(&location) } } -impl> Convert> for CurrencyIdConvert { +impl< + AssetRegistry: Inspect, + > Convert> for CurrencyIdConvert +{ fn convert(a: MultiAsset) -> Option { if let MultiAsset { id: AssetId::Concrete(id), fun: _ } = a { >>::convert(id) @@ -178,9 +185,14 @@ impl> xcm_executor::traits::Convert for CurrencyIdConvert { +impl< + AssetRegistry: Inspect, + > xcm_executor::traits::Convert for CurrencyIdConvert +{ fn convert(location: MultiLocation) -> Result { - as Convert>>::convert(location) - .ok_or(location) + as Convert>>::convert( + location, + ) + .ok_or(location) } } diff --git a/runtime/foucoco/src/definitions.rs b/runtime/foucoco/src/definitions.rs index e69de29bb..8b1378917 100644 --- a/runtime/foucoco/src/definitions.rs +++ b/runtime/foucoco/src/definitions.rs @@ -0,0 +1 @@ + diff --git a/runtime/foucoco/src/lib.rs b/runtime/foucoco/src/lib.rs index b3d27927a..04e4a78a6 100644 --- a/runtime/foucoco/src/lib.rs +++ b/runtime/foucoco/src/lib.rs @@ -7,10 +7,10 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); mod chain_ext; +pub mod definitions; mod weights; pub mod xcm_config; pub mod zenlink; -pub mod definitions; use crate::zenlink::*; use xcm::v3::MultiLocation; diff --git a/runtime/foucoco/src/xcm_config.rs b/runtime/foucoco/src/xcm_config.rs index 7979cdab7..186faef95 100644 --- a/runtime/foucoco/src/xcm_config.rs +++ b/runtime/foucoco/src/xcm_config.rs @@ -1,5 +1,6 @@ use core::marker::PhantomData; +use cumulus_primitives_utility::XcmFeesTo32ByteAccount; use frame_support::{ log, match_types, parameter_types, traits::{ConstU32, ContainsPair, Everything, Nothing, ProcessMessageError}, @@ -12,20 +13,20 @@ use orml_traits::{ use orml_xcm_support::{DepositToAlternative, IsNativeConcrete, MultiCurrencyAdapter}; use pallet_xcm::XcmPassthrough; use polkadot_parachain::primitives::Sibling; +use runtime_common::{asset_registry::FixedConversionRateProvider, CurrencyIdConvert}; use sp_runtime::traits::Convert; use xcm::latest::{prelude::*, Weight as XCMWeight}; use xcm_builder::{ - AccountId32Aliases, AllowUnpaidExecutionFrom, AllowSubscriptionsFrom,AllowTopLevelPaidExecutionFrom, AllowKnownQueryResponses, EnsureXcmOrigin, FixedWeightBounds, + AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, + AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, EnsureXcmOrigin, FixedWeightBounds, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, }; use xcm_executor::{traits::ShouldExecute, XcmExecutor}; -use cumulus_primitives_utility::XcmFeesTo32ByteAccount; -use runtime_common::{CurrencyIdConvert, asset_registry::{ FixedConversionRateProvider}}; use super::{ - AccountId, AssetRegistry, Balance, Balances, Currencies, CurrencyId, FoucocoTreasuryAccount, ParachainInfo, - ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, + AccountId, AssetRegistry, Balance, Balances, Currencies, CurrencyId, FoucocoTreasuryAccount, + ParachainInfo, ParachainSystem, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, XcmpQueue, }; use frame_system::EnsureRoot; @@ -51,7 +52,6 @@ pub type LocationToAccountId = ( AccountId32Aliases, ); - /// A `FilterAssetLocation` implementation. Filters multi native assets whose /// reserve is same with `origin`. pub struct MultiNativeAsset(PhantomData); diff --git a/runtime/integration-tests/src/amplitude_tests.rs b/runtime/integration-tests/src/amplitude_tests.rs index 67c2341c8..b9cb36440 100644 --- a/runtime/integration-tests/src/amplitude_tests.rs +++ b/runtime/integration-tests/src/amplitude_tests.rs @@ -18,8 +18,10 @@ use xcm_emulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain // Native fee expected for each token according to the `fee_per_second` values defined in the mock const NATIVE_FEE_WHEN_TRANSFER_TO_PARACHAIN: polkadot_core_primitives::Balance = 4000000000; -const KSM_FEE_WHEN_TRANSFER_TO_PARACHAIN: polkadot_core_primitives::Balance = NATIVE_FEE_WHEN_TRANSFER_TO_PARACHAIN / 20; -const USDT_FEE_WHEN_TRANSFER_TO_PARACHAIN: polkadot_core_primitives::Balance = NATIVE_FEE_WHEN_TRANSFER_TO_PARACHAIN / 10; +const KSM_FEE_WHEN_TRANSFER_TO_PARACHAIN: polkadot_core_primitives::Balance = + NATIVE_FEE_WHEN_TRANSFER_TO_PARACHAIN / 20; +const USDT_FEE_WHEN_TRANSFER_TO_PARACHAIN: polkadot_core_primitives::Balance = + NATIVE_FEE_WHEN_TRANSFER_TO_PARACHAIN / 10; decl_test_relay_chain! { pub struct KusamaRelay { diff --git a/runtime/integration-tests/src/definitions.rs b/runtime/integration-tests/src/definitions.rs index aa9225ee2..b8d52e094 100644 --- a/runtime/integration-tests/src/definitions.rs +++ b/runtime/integration-tests/src/definitions.rs @@ -1,16 +1,13 @@ - pub mod xcm_assets { use runtime_common::create_xcm_id; create_xcm_id!(MOONBEAM_BRZ, 4); } pub mod asset_hub { - use runtime_common::parachain_asset_location; - - pub const PARA_ID: u32 = 1000; - pub const ASSET_PALLET_INDEX: u8 = 50; + use runtime_common::parachain_asset_location; - parachain_asset_location!(USDT, 1984); + pub const PARA_ID: u32 = 1000; + pub const ASSET_PALLET_INDEX: u8 = 50; + parachain_asset_location!(USDT, 1984); } - diff --git a/runtime/integration-tests/src/mock.rs b/runtime/integration-tests/src/mock.rs index 115a8e5e0..ac29012b2 100644 --- a/runtime/integration-tests/src/mock.rs +++ b/runtime/integration-tests/src/mock.rs @@ -1,5 +1,4 @@ -use crate::{sibling, AMPLITUDE_ID, ASSETHUB_ID, PENDULUM_ID, SIBLING_ID, - definitions::asset_hub}; +use crate::{definitions::asset_hub, sibling, AMPLITUDE_ID, ASSETHUB_ID, PENDULUM_ID, SIBLING_ID}; use amplitude_runtime::CurrencyId as AmplitudeCurrencyId; use frame_support::traits::GenesisBuild; use pendulum_runtime::CurrencyId as PendulumCurrencyId; @@ -16,12 +15,9 @@ use codec::Encode; use frame_support::BoundedVec; use runtime_common::asset_registry::{CustomMetadata, DiaKeys, StringLimit}; -use xcm::{ - v3::{MultiLocation}, - VersionedMultiLocation, -}; +use xcm::{v3::MultiLocation, VersionedMultiLocation}; -use pendulum_runtime::definitions::{moonbeam::PARA_ID as MOONBEAM_PARA_ID, moonbeam}; +use pendulum_runtime::definitions::{moonbeam, moonbeam::PARA_ID as MOONBEAM_PARA_ID}; use statemine_runtime as kusama_asset_hub_runtime; use statemint_runtime as polkadot_asset_hub_runtime; @@ -232,9 +228,7 @@ fn assets_metadata_for_registry_pendulum() -> Vec<(PendulumCurrencyId, Vec)> existential_deposit: 1_000u128, location: Some(VersionedMultiLocation::V3(MultiLocation::new( 0u8, - xcm::latest::Junctions::X1( - xcm::latest::Junction::PalletInstance(10), - ), + xcm::latest::Junctions::X1(xcm::latest::Junction::PalletInstance(10)), ))), additional: CustomMetadata { dia_keys: DiaKeys:: { @@ -246,7 +240,6 @@ fn assets_metadata_for_registry_pendulum() -> Vec<(PendulumCurrencyId, Vec)> } .encode(), ), - ( PendulumCurrencyId::XCM(1), orml_asset_registry::AssetMetadata { @@ -260,7 +253,7 @@ fn assets_metadata_for_registry_pendulum() -> Vec<(PendulumCurrencyId, Vec)> blockchain: BoundedVec::truncate_from(vec![1, 2, 3]), symbol: BoundedVec::truncate_from(vec![1, 2, 3]), }, - fee_per_second: UNIT/2, + fee_per_second: UNIT / 2, }, } .encode(), @@ -278,7 +271,7 @@ fn assets_metadata_for_registry_pendulum() -> Vec<(PendulumCurrencyId, Vec)> blockchain: BoundedVec::truncate_from(vec![1, 2, 3]), symbol: BoundedVec::truncate_from(vec![1, 2, 3]), }, - fee_per_second: UNIT/4, + fee_per_second: UNIT / 4, }, } .encode(), @@ -296,7 +289,7 @@ fn assets_metadata_for_registry_pendulum() -> Vec<(PendulumCurrencyId, Vec)> blockchain: BoundedVec::truncate_from(vec![1, 2, 3]), symbol: BoundedVec::truncate_from(vec![1, 2, 3]), }, - fee_per_second: 2*UNIT, + fee_per_second: 2 * UNIT, }, } .encode(), @@ -315,9 +308,7 @@ fn assets_metadata_for_registry_amplitude() -> Vec<(AmplitudeCurrencyId, Vec existential_deposit: 1_000u128, location: Some(VersionedMultiLocation::V3(MultiLocation::new( 0u8, - xcm::latest::Junctions::X1( - xcm::latest::Junction::PalletInstance(10), - ), + xcm::latest::Junctions::X1(xcm::latest::Junction::PalletInstance(10)), ))), additional: CustomMetadata { dia_keys: DiaKeys:: { @@ -342,7 +333,7 @@ fn assets_metadata_for_registry_amplitude() -> Vec<(AmplitudeCurrencyId, Vec blockchain: BoundedVec::truncate_from(vec![1, 2, 3]), symbol: BoundedVec::truncate_from(vec![1, 2, 3]), }, - fee_per_second: UNIT/10, + fee_per_second: UNIT / 10, }, } .encode(), @@ -360,7 +351,7 @@ fn assets_metadata_for_registry_amplitude() -> Vec<(AmplitudeCurrencyId, Vec blockchain: BoundedVec::truncate_from(vec![1, 2, 3]), symbol: BoundedVec::truncate_from(vec![1, 2, 3]), }, - fee_per_second: UNIT/20, + fee_per_second: UNIT / 20, }, } .encode(), diff --git a/runtime/integration-tests/src/pendulum_tests.rs b/runtime/integration-tests/src/pendulum_tests.rs index dcbbb8d59..d193c05ba 100644 --- a/runtime/integration-tests/src/pendulum_tests.rs +++ b/runtime/integration-tests/src/pendulum_tests.rs @@ -21,9 +21,12 @@ use xcm_emulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain // Native fee expected for each token according to the `fee_per_second` values defined in the mock const NATIVE_FEE_WHEN_TRANSFER_TO_PARACHAIN: polkadot_core_primitives::Balance = 4000000000; -const DOT_FEE_WHEN_TRANSFER_TO_PARACHAIN: polkadot_core_primitives::Balance = NATIVE_FEE_WHEN_TRANSFER_TO_PARACHAIN /4; -const MOONBEAM_BRZ_FEE_WHEN_TRANSFER_TO_PARACHAIN: polkadot_core_primitives::Balance = 2*NATIVE_FEE_WHEN_TRANSFER_TO_PARACHAIN; -const USDT_FEE_WHEN_TRANSFER_TO_PARACHAIN: polkadot_core_primitives::Balance = NATIVE_FEE_WHEN_TRANSFER_TO_PARACHAIN /2; +const DOT_FEE_WHEN_TRANSFER_TO_PARACHAIN: polkadot_core_primitives::Balance = + NATIVE_FEE_WHEN_TRANSFER_TO_PARACHAIN / 4; +const MOONBEAM_BRZ_FEE_WHEN_TRANSFER_TO_PARACHAIN: polkadot_core_primitives::Balance = + 2 * NATIVE_FEE_WHEN_TRANSFER_TO_PARACHAIN; +const USDT_FEE_WHEN_TRANSFER_TO_PARACHAIN: polkadot_core_primitives::Balance = + NATIVE_FEE_WHEN_TRANSFER_TO_PARACHAIN / 2; decl_test_relay_chain! { pub struct PolkadotRelay { diff --git a/runtime/integration-tests/src/sibling.rs b/runtime/integration-tests/src/sibling.rs index c228e5098..d6063ab8e 100644 --- a/runtime/integration-tests/src/sibling.rs +++ b/runtime/integration-tests/src/sibling.rs @@ -42,7 +42,7 @@ use xcm_builder::{ SignedToAccountId32, SovereignSignedViaLocation, }; -use crate::{AMPLITUDE_ID, ASSETHUB_ID, PENDULUM_ID, definitions::asset_hub}; +use crate::{definitions::asset_hub, AMPLITUDE_ID, ASSETHUB_ID, PENDULUM_ID}; use pendulum_runtime::definitions::moonbeam::BRZ_location; @@ -141,7 +141,6 @@ impl Convert> for CurrencyIdConvert { } impl Convert> for CurrencyIdConvert { - fn convert(location: MultiLocation) -> Option { match location { MultiLocation { diff --git a/runtime/integration-tests/src/test_macros.rs b/runtime/integration-tests/src/test_macros.rs index 88a2e3aa3..8cbdd3f86 100644 --- a/runtime/integration-tests/src/test_macros.rs +++ b/runtime/integration-tests/src/test_macros.rs @@ -543,7 +543,7 @@ macro_rules! transfer_native_token_from_parachain1_to_parachain2_and_back { WeightLimit::Unlimited )); - // Alternatively, we should be able to use + // Alternatively, we should be able to use // assert_ok!(XTokens::transfer( // $parachain1_runtime::RuntimeOrigin::signed(ALICE.into()), // Parachain1CurrencyId::Native, diff --git a/runtime/pendulum/src/definitions.rs b/runtime/pendulum/src/definitions.rs index c0a4d4303..0c0124843 100644 --- a/runtime/pendulum/src/definitions.rs +++ b/runtime/pendulum/src/definitions.rs @@ -1,37 +1,33 @@ - pub mod moonbeam { - use runtime_common::{parachain_asset_location}; - use xcm::latest::{ - Junction::{AccountKey20, PalletInstance, Parachain}, - Junctions::{X3}, - }; - - pub const PARA_ID: u32 = 2004; - pub const ASSET_PALLET_INDEX: u8 = 110; - pub const BALANCES_PALLET_INDEX: u8 = 10; - - // The address of the BRZ token on Moonbeam `0x3225edCe8aD30Ae282e62fa32e7418E4b9cf197b` as byte array - pub const BRZ_ASSET_ACCOUNT_IN_BYTES: [u8; 20] = [ - 50, 37, 237, 206, 138, 211, 10, 226, 130, 230, 47, 163, 46, 116, 24, 228, 185, 207, 25, 123 - ]; - - parachain_asset_location!( - BRZ, - X3( - Parachain(PARA_ID), - PalletInstance(ASSET_PALLET_INDEX), - AccountKey20 { network: None, key: BRZ_ASSET_ACCOUNT_IN_BYTES } - ) - ); + use runtime_common::parachain_asset_location; + use xcm::latest::{ + Junction::{AccountKey20, PalletInstance, Parachain}, + Junctions::X3, + }; + pub const PARA_ID: u32 = 2004; + pub const ASSET_PALLET_INDEX: u8 = 110; + pub const BALANCES_PALLET_INDEX: u8 = 10; + + // The address of the BRZ token on Moonbeam `0x3225edCe8aD30Ae282e62fa32e7418E4b9cf197b` as byte array + pub const BRZ_ASSET_ACCOUNT_IN_BYTES: [u8; 20] = [ + 50, 37, 237, 206, 138, 211, 10, 226, 130, 230, 47, 163, 46, 116, 24, 228, 185, 207, 25, 123, + ]; + + parachain_asset_location!( + BRZ, + X3( + Parachain(PARA_ID), + PalletInstance(ASSET_PALLET_INDEX), + AccountKey20 { network: None, key: BRZ_ASSET_ACCOUNT_IN_BYTES } + ) + ); } #[cfg(test)] mod tests { - use super::{moonbeam}; - use xcm::{ - latest::prelude::{AccountKey20, PalletInstance, Parachain}, - }; + use super::moonbeam; + use xcm::latest::prelude::{AccountKey20, PalletInstance, Parachain}; #[test] fn test_brz() { @@ -46,5 +42,4 @@ mod tests { ); assert_eq!(junctions.next(), None); } - -} \ No newline at end of file +} diff --git a/runtime/pendulum/src/lib.rs b/runtime/pendulum/src/lib.rs index 43480d129..b5e7e4539 100644 --- a/runtime/pendulum/src/lib.rs +++ b/runtime/pendulum/src/lib.rs @@ -7,10 +7,10 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); mod chain_ext; +pub mod definitions; mod weights; pub mod xcm_config; pub mod zenlink; -pub mod definitions; use crate::zenlink::*; use xcm::v3::MultiLocation; @@ -27,11 +27,11 @@ use sp_runtime::{ create_runtime_str, generic, impl_opaque_keys, traits::{ AccountIdConversion, AccountIdLookup, BlakeTwo256, Block as BlockT, Convert, ConvertInto, - Zero, One, + One, Zero, }, transaction_validity::{TransactionSource, TransactionValidity}, - ApplyExtrinsicResult, DispatchError, FixedPointNumber, MultiAddress, Perbill, Permill, - Perquintill, SaturatedConversion, FixedU128, + ApplyExtrinsicResult, DispatchError, FixedPointNumber, FixedU128, MultiAddress, Perbill, + Permill, Perquintill, SaturatedConversion, }; use bifrost_farming as farming; @@ -43,11 +43,10 @@ use spacewalk_primitives::{ UnsignedInner, }; - #[cfg(any(feature = "runtime-benchmarks", feature = "testing-utils"))] use oracle::testing_utils::MockDataFeeder; -use sp_std::{marker::PhantomData, prelude::*, fmt::Debug}; +use sp_std::{fmt::Debug, marker::PhantomData, prelude::*}; #[cfg(feature = "std")] use sp_version::NativeVersion; use sp_version::RuntimeVersion; diff --git a/runtime/pendulum/src/xcm_config.rs b/runtime/pendulum/src/xcm_config.rs index c39fe5e7f..7754f9f36 100644 --- a/runtime/pendulum/src/xcm_config.rs +++ b/runtime/pendulum/src/xcm_config.rs @@ -25,8 +25,8 @@ use xcm_builder::{ use xcm_executor::{traits::ShouldExecute, XcmExecutor}; use runtime_common::{ + asset_registry::FixedConversionRateProvider, custom_transactor::{AssetData, AutomationPalletConfig, CustomTransactorInterceptor}, - asset_registry::{ FixedConversionRateProvider}, CurrencyIdConvert, }; From 22846d635ef8d1253e5af8848344736f7fdfa467 Mon Sep 17 00:00:00 2001 From: Gianfranco Date: Wed, 12 Jun 2024 16:14:18 -0300 Subject: [PATCH 13/15] fix some clippy warnings --- chain-extensions/price/src/lib.rs | 4 ++-- chain-extensions/token/src/lib.rs | 14 +++++++------- node/src/chain_spec.rs | 4 ++-- pallets/parachain-staking/rpc/src/lib.rs | 4 ++-- runtime/amplitude/src/lib.rs | 5 +++++ runtime/foucoco/src/lib.rs | 1 + runtime/pendulum/src/lib.rs | 1 + 7 files changed, 20 insertions(+), 13 deletions(-) diff --git a/chain-extensions/price/src/lib.rs b/chain-extensions/price/src/lib.rs index 766832705..411905a9f 100644 --- a/chain-extensions/price/src/lib.rs +++ b/chain-extensions/price/src/lib.rs @@ -46,7 +46,7 @@ where T: SysConfig + pallet_contracts::Config + dia_oracle::Config, ::AccountId: UncheckedFrom<::Hash> + AsRef<[u8]>, { - fn call(&mut self, env: Environment) -> Result + fn call(&mut self, env: Environment) -> Result where E: Ext, ::AccountId: UncheckedFrom<::Hash> + AsRef<[u8]>, @@ -74,7 +74,7 @@ where } } -fn get_coin_info( +fn get_coin_info( env: Environment<'_, '_, E, InitState>, overhead_weight: Weight, ) -> Result diff --git a/chain-extensions/token/src/lib.rs b/chain-extensions/token/src/lib.rs index dad2dc236..961f3d485 100644 --- a/chain-extensions/token/src/lib.rs +++ b/chain-extensions/token/src/lib.rs @@ -75,7 +75,7 @@ where Tokens: orml_traits::MultiCurrency, AccountId: sp_std::fmt::Debug + Decode + core::clone::Clone, { - fn call(&mut self, env: Environment) -> Result + fn call(&mut self, env: Environment) -> Result where E: Ext, ::AccountId: UncheckedFrom<::Hash> + AsRef<[u8]>, @@ -107,7 +107,7 @@ where } } -fn total_supply( +fn total_supply( env: Environment<'_, '_, E, InitState>, overhead_weight: Weight, ) -> Result @@ -146,7 +146,7 @@ where return Ok(RetVal::Converging(ChainExtensionOutcome::Success.as_u32())) } -fn balance_of( +fn balance_of( env: Environment<'_, '_, E, InitState>, overhead_weight: Weight, ) -> Result @@ -188,7 +188,7 @@ where return Ok(RetVal::Converging(ChainExtensionOutcome::Success.as_u32())) } -fn transfer( +fn transfer( env: Environment<'_, '_, E, InitState>, overhead_weight: Weight, ) -> Result @@ -235,7 +235,7 @@ where return Ok(RetVal::Converging(ChainExtensionOutcome::Success.as_u32())) } -fn allowance( +fn allowance( env: Environment<'_, '_, E, InitState>, overhead_weight: Weight, ) -> Result @@ -280,7 +280,7 @@ where return Ok(RetVal::Converging(ChainExtensionOutcome::Success.as_u32())) } -fn approve( +fn approve( env: Environment<'_, '_, E, InitState>, overhead_weight: Weight, ) -> Result @@ -326,7 +326,7 @@ where return Ok(RetVal::Converging(ChainExtensionOutcome::Success.as_u32())) } -fn transfer_from( +fn transfer_from( env: Environment<'_, '_, E, InitState>, overhead_weight: Weight, ) -> Result diff --git a/node/src/chain_spec.rs b/node/src/chain_spec.rs index 72ee6970d..1fbdc1c7a 100644 --- a/node/src/chain_spec.rs +++ b/node/src/chain_spec.rs @@ -34,7 +34,7 @@ const SAFE_XCM_VERSION: u32 = xcm::prelude::XCM_VERSION; pub fn create_pendulum_multisig_account(id: &str) -> AccountId { let mut signatories: Vec<_> = pendulum::SUDO_SIGNATORIES .iter() - .chain(vec![id].iter()) + .chain([id].iter()) .map(|ss58| AccountId::from_ss58check(ss58).unwrap()) .collect(); signatories.sort(); @@ -384,7 +384,7 @@ pub fn pendulum_config() -> PendulumChainSpec { pendulum::TREASURY_ALLOCATION * 20 / 100, )); - let multisig_identifiers = vec![ + let multisig_identifiers = [ pendulum::MULTISIG_ID_GENESIS, pendulum::MULTISIG_ID_TEAM, pendulum::MULTISIG_ID_CL_RESERVES, diff --git a/pallets/parachain-staking/rpc/src/lib.rs b/pallets/parachain-staking/rpc/src/lib.rs index bf60f8d1f..10d0ccbbf 100644 --- a/pallets/parachain-staking/rpc/src/lib.rs +++ b/pallets/parachain-staking/rpc/src/lib.rs @@ -72,7 +72,7 @@ where let at = at.unwrap_or_else(|| self.client.info().best_hash); api.get_unclaimed_staking_rewards(at, account) - .map_err(|_e| internal_err(format!("Unable to get unclaimed staking rewards"))) + .map_err(|_e| internal_err("Unable to get unclaimed staking rewards")) } fn get_staking_rates(&self, at: Option<::Hash>) -> RpcResult { @@ -80,6 +80,6 @@ where let at = at.unwrap_or_else(|| self.client.info().best_hash); api.get_staking_rates(at) - .map_err(|_e| internal_err(format!("Unable to get staking rates"))) + .map_err(|_e| internal_err("Unable to get staking rates")) } } diff --git a/runtime/amplitude/src/lib.rs b/runtime/amplitude/src/lib.rs index d034434e6..9a88c90a0 100644 --- a/runtime/amplitude/src/lib.rs +++ b/runtime/amplitude/src/lib.rs @@ -1824,11 +1824,15 @@ impl_runtime_apis! { use frame_system_benchmarking::Pallet as SystemBench; use baseline::Pallet as BaselineBench; + #[allow(clippy::non_local_impl)] impl frame_system_benchmarking::Config for Runtime {} + #[allow(clippy::non_local_impl)] impl baseline::Config for Runtime {} + #[allow(clippy::non_local_impl)] impl runtime_common::benchmarking::orml_asset_registry::Config for Runtime {} use cumulus_pallet_session_benchmarking::Pallet as SessionBench; + #[allow(clippy::non_local_impl)] impl cumulus_pallet_session_benchmarking::Config for Runtime {} let whitelist: Vec = vec![ @@ -2029,6 +2033,7 @@ impl_runtime_apis! { } +#[allow(dead_code)] struct CheckInherents; impl cumulus_pallet_parachain_system::CheckInherents for CheckInherents { diff --git a/runtime/foucoco/src/lib.rs b/runtime/foucoco/src/lib.rs index 898c74687..0ac5ef52d 100644 --- a/runtime/foucoco/src/lib.rs +++ b/runtime/foucoco/src/lib.rs @@ -2027,6 +2027,7 @@ impl_runtime_apis! { } +#[allow(dead_code)] struct CheckInherents; impl cumulus_pallet_parachain_system::CheckInherents for CheckInherents { diff --git a/runtime/pendulum/src/lib.rs b/runtime/pendulum/src/lib.rs index ea33c3730..98c51270c 100644 --- a/runtime/pendulum/src/lib.rs +++ b/runtime/pendulum/src/lib.rs @@ -2015,6 +2015,7 @@ impl_runtime_apis! { } +#[allow(dead_code)] struct CheckInherents; impl cumulus_pallet_parachain_system::CheckInherents for CheckInherents { From 51e82a4565210440be5195c1b8b2f366c339587b Mon Sep 17 00:00:00 2001 From: Gianfranco Date: Thu, 13 Jun 2024 13:20:17 -0300 Subject: [PATCH 14/15] remove some warnings --- runtime/amplitude/src/lib.rs | 4 ---- runtime/foucoco/src/weights/redeem.rs | 1 + runtime/integration-tests/src/sibling.rs | 3 +++ 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/runtime/amplitude/src/lib.rs b/runtime/amplitude/src/lib.rs index 9a88c90a0..0a671202b 100644 --- a/runtime/amplitude/src/lib.rs +++ b/runtime/amplitude/src/lib.rs @@ -1824,15 +1824,11 @@ impl_runtime_apis! { use frame_system_benchmarking::Pallet as SystemBench; use baseline::Pallet as BaselineBench; - #[allow(clippy::non_local_impl)] impl frame_system_benchmarking::Config for Runtime {} - #[allow(clippy::non_local_impl)] impl baseline::Config for Runtime {} - #[allow(clippy::non_local_impl)] impl runtime_common::benchmarking::orml_asset_registry::Config for Runtime {} use cumulus_pallet_session_benchmarking::Pallet as SessionBench; - #[allow(clippy::non_local_impl)] impl cumulus_pallet_session_benchmarking::Config for Runtime {} let whitelist: Vec = vec![ diff --git a/runtime/foucoco/src/weights/redeem.rs b/runtime/foucoco/src/weights/redeem.rs index 973a689c8..da4c4b23e 100644 --- a/runtime/foucoco/src/weights/redeem.rs +++ b/runtime/foucoco/src/weights/redeem.rs @@ -30,6 +30,7 @@ #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] +#![allow(dead_code)] #![allow(unused_imports)] #![allow(missing_docs)] diff --git a/runtime/integration-tests/src/sibling.rs b/runtime/integration-tests/src/sibling.rs index d6063ab8e..9809a89e0 100644 --- a/runtime/integration-tests/src/sibling.rs +++ b/runtime/integration-tests/src/sibling.rs @@ -258,6 +258,8 @@ match_types! { //TODO: move DenyThenTry to polkadot's xcm module. /// Deny executing the xcm message if it matches any of the Deny filter regardless of anything else. /// If it passes the Deny, and matches one of the Allow cases then it is let through. + +#[allow(dead_code)] pub struct DenyThenTry(PhantomData, PhantomData) where Deny: ShouldExecute, @@ -280,6 +282,7 @@ where } // See issue #5233 +#[allow(dead_code)] pub struct DenyReserveTransferToRelayChain; impl ShouldExecute for DenyReserveTransferToRelayChain { fn should_execute( From a765f14d174bb90a3f712dd5cef14689db58297b Mon Sep 17 00:00:00 2001 From: Gianfranco Date: Fri, 14 Jun 2024 09:39:08 -0300 Subject: [PATCH 15/15] unused imports, ignore local impl definition --- .github/workflows/test-code.yml | 3 +++ pallets/vesting-manager/src/lib.rs | 4 +++- runtime/amplitude/src/lib.rs | 4 ++++ runtime/common/src/lib.rs | 5 ++++- runtime/foucoco/src/lib.rs | 4 ++++ runtime/pendulum/src/lib.rs | 4 ++++ 6 files changed, 22 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-code.yml b/.github/workflows/test-code.yml index aa67fd32f..ede53f13b 100644 --- a/.github/workflows/test-code.yml +++ b/.github/workflows/test-code.yml @@ -11,6 +11,9 @@ on: jobs: test-code: runs-on: ubuntu-latest + env: + # Make sure CI fails on all warnings, including Clippy lints + RUSTFLAGS: "-Dwarnings" steps: - uses: actions/checkout@v3 diff --git a/pallets/vesting-manager/src/lib.rs b/pallets/vesting-manager/src/lib.rs index 30579255b..a732746db 100644 --- a/pallets/vesting-manager/src/lib.rs +++ b/pallets/vesting-manager/src/lib.rs @@ -30,8 +30,10 @@ pub mod pallet { #[pallet::call] impl Pallet { + // TODO to remove this manually assigned weight, we need to add benchmarks to the pallet #[pallet::call_index(0)] - #[pallet::weight(10_000_000)] + #[pallet::weight(Weight::from_parts(10_000_000, 0) + .saturating_add(T::DbWeight::get().writes(1_u64)))] pub fn remove_vesting_schedule( origin: OriginFor, who: AccountIdLookupOf, diff --git a/runtime/amplitude/src/lib.rs b/runtime/amplitude/src/lib.rs index 0a671202b..acfb3bd13 100644 --- a/runtime/amplitude/src/lib.rs +++ b/runtime/amplitude/src/lib.rs @@ -1824,11 +1824,15 @@ impl_runtime_apis! { use frame_system_benchmarking::Pallet as SystemBench; use baseline::Pallet as BaselineBench; + #[allow(non_local_definitions)] impl frame_system_benchmarking::Config for Runtime {} + #[allow(non_local_definitions)] impl baseline::Config for Runtime {} + #[allow(non_local_definitions)] impl runtime_common::benchmarking::orml_asset_registry::Config for Runtime {} use cumulus_pallet_session_benchmarking::Pallet as SessionBench; + #[allow(non_local_definitions)] impl cumulus_pallet_session_benchmarking::Config for Runtime {} let whitelist: Vec = vec![ diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index 3152f6b35..1ff272816 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -3,12 +3,15 @@ use asset_registry::CustomMetadata; use core::{fmt::Debug, marker::PhantomData}; -use dia_oracle::{CoinInfo, DiaOracle}; +#[cfg(feature = "runtime-benchmarks")] +use dia_oracle::CoinInfo; +use dia_oracle::DiaOracle; use orml_traits::asset_registry::Inspect; use sp_runtime::{ traits::{Convert, IdentifyAccount, One, Verify, Zero}, DispatchError, FixedPointNumber, FixedU128, MultiSignature, }; +#[cfg(feature = "runtime-benchmarks")] use sp_std::vec; use spacewalk_primitives::CurrencyId; use treasury_buyout_extension::PriceGetter; diff --git a/runtime/foucoco/src/lib.rs b/runtime/foucoco/src/lib.rs index 0ac5ef52d..039a0c3fc 100644 --- a/runtime/foucoco/src/lib.rs +++ b/runtime/foucoco/src/lib.rs @@ -1806,11 +1806,15 @@ impl_runtime_apis! { use frame_system_benchmarking::Pallet as SystemBench; use baseline::Pallet as BaselineBench; + #[allow(non_local_definitions)] impl frame_system_benchmarking::Config for Runtime {} + #[allow(non_local_definitions)] impl baseline::Config for Runtime {} + #[allow(non_local_definitions)] impl runtime_common::benchmarking::orml_asset_registry::Config for Runtime {} use cumulus_pallet_session_benchmarking::Pallet as SessionBench; + #[allow(non_local_definitions)] impl cumulus_pallet_session_benchmarking::Config for Runtime {} let whitelist: Vec = vec![ diff --git a/runtime/pendulum/src/lib.rs b/runtime/pendulum/src/lib.rs index 98c51270c..79d0690a8 100644 --- a/runtime/pendulum/src/lib.rs +++ b/runtime/pendulum/src/lib.rs @@ -1809,11 +1809,15 @@ impl_runtime_apis! { use frame_system_benchmarking::Pallet as SystemBench; use baseline::Pallet as BaselineBench; + #[allow(non_local_definitions)] impl frame_system_benchmarking::Config for Runtime {} + #[allow(non_local_definitions)] impl baseline::Config for Runtime {} + #[allow(non_local_definitions)] impl runtime_common::benchmarking::orml_asset_registry::Config for Runtime {} use cumulus_pallet_session_benchmarking::Pallet as SessionBench; + #[allow(non_local_definitions)] impl cumulus_pallet_session_benchmarking::Config for Runtime {}