diff --git a/Cargo.lock b/Cargo.lock index 69219d89f..2f26412c9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4482,7 +4482,7 @@ dependencies = [ [[package]] name = "hydradx" -version = "12.0.0" +version = "12.1.0" dependencies = [ "async-trait", "clap 4.4.11", @@ -4571,7 +4571,7 @@ dependencies = [ [[package]] name = "hydradx-adapters" -version = "1.1.0" +version = "1.1.1" dependencies = [ "cumulus-pallet-parachain-system", "cumulus-primitives-core", @@ -4619,7 +4619,7 @@ dependencies = [ [[package]] name = "hydradx-runtime" -version = "209.0.0" +version = "210.0.0" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", @@ -4742,7 +4742,7 @@ dependencies = [ [[package]] name = "hydradx-traits" -version = "2.8.4" +version = "3.0.0" dependencies = [ "frame-support", "impl-trait-for-tuples", @@ -6980,15 +6980,17 @@ checksum = "e2355d85b9a3786f481747ced0e0ff2ba35213a1f9bd406ed906554d7af805a1" [[package]] name = "pallet-asset-registry" -version = "2.3.3" +version = "3.0.0" dependencies = [ "frame-benchmarking", "frame-support", "frame-system", "hydradx-traits", "log", + "orml-tokens", "orml-traits", "parity-scale-codec", + "pretty_assertions", "primitive-types", "scale-info", "serde", @@ -7192,7 +7194,7 @@ dependencies = [ [[package]] name = "pallet-bonds" -version = "2.0.1" +version = "2.1.0" dependencies = [ "frame-benchmarking", "frame-support", @@ -7253,7 +7255,7 @@ dependencies = [ [[package]] name = "pallet-circuit-breaker" -version = "1.1.19" +version = "1.1.20" dependencies = [ "frame-benchmarking", "frame-support", @@ -7396,7 +7398,7 @@ dependencies = [ [[package]] name = "pallet-dca" -version = "1.3.3" +version = "1.3.4" dependencies = [ "cumulus-pallet-parachain-system", "cumulus-primitives-core", @@ -7843,7 +7845,7 @@ dependencies = [ [[package]] name = "pallet-lbp" -version = "4.7.3" +version = "4.7.4" dependencies = [ "frame-benchmarking", "frame-support", @@ -7868,7 +7870,7 @@ dependencies = [ [[package]] name = "pallet-liquidity-mining" -version = "4.2.5" +version = "4.3.0" dependencies = [ "fixed", "frame-support", @@ -8090,7 +8092,7 @@ dependencies = [ [[package]] name = "pallet-omnipool" -version = "4.1.2" +version = "4.1.3" dependencies = [ "bitflags 1.3.2", "frame-benchmarking", @@ -8117,9 +8119,8 @@ dependencies = [ [[package]] name = "pallet-omnipool-liquidity-mining" -version = "2.0.13" +version = "2.1.0" dependencies = [ - "bitflags 1.3.2", "frame-benchmarking", "frame-support", "frame-system", @@ -8145,7 +8146,7 @@ dependencies = [ [[package]] name = "pallet-otc" -version = "1.0.3" +version = "1.1.0" dependencies = [ "frame-benchmarking", "frame-support", @@ -8287,7 +8288,7 @@ dependencies = [ [[package]] name = "pallet-route-executor" -version = "2.0.0" +version = "2.0.1" dependencies = [ "frame-benchmarking", "frame-support", @@ -8386,7 +8387,7 @@ dependencies = [ [[package]] name = "pallet-stableswap" -version = "3.4.3" +version = "3.4.4" dependencies = [ "bitflags 1.3.2", "frame-benchmarking", @@ -8556,7 +8557,7 @@ dependencies = [ [[package]] name = "pallet-transaction-multi-payment" -version = "9.2.1" +version = "9.3.0" dependencies = [ "frame-support", "frame-system", @@ -8764,7 +8765,7 @@ dependencies = [ [[package]] name = "pallet-xcm-rate-limiter" -version = "0.1.4" +version = "0.1.5" dependencies = [ "cumulus-pallet-xcmp-queue", "frame-benchmarking", @@ -8791,7 +8792,7 @@ dependencies = [ [[package]] name = "pallet-xyk" -version = "6.3.4" +version = "6.4.0" dependencies = [ "frame-benchmarking", "frame-support", @@ -11330,7 +11331,7 @@ dependencies = [ [[package]] name = "runtime-integration-tests" -version = "1.17.5" +version = "1.18.0" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index 808800428..788c27c14 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "runtime-integration-tests" -version = "1.17.5" +version = "1.18.0" description = "Integration tests" authors = ["GalacticCouncil"] edition = "2021" diff --git a/integration-tests/src/asset_registry.rs b/integration-tests/src/asset_registry.rs new file mode 100644 index 000000000..499d5cf03 --- /dev/null +++ b/integration-tests/src/asset_registry.rs @@ -0,0 +1,169 @@ +#![cfg(test)] + +use crate::asset_registry::Junction::GeneralIndex; +use crate::polkadot_test_net::*; +use frame_support::{assert_noop, assert_ok}; +use frame_system::RawOrigin; +use hydradx_runtime::{AssetRegistry as Registry, TechnicalCollective}; +use polkadot_xcm::v3::{ + Junction::{self, Parachain}, + Junctions::X2, + MultiLocation, +}; +use pretty_assertions::{assert_eq, assert_ne}; +use xcm_emulator::TestExt; + +#[test] +fn root_should_update_decimals_when_it_was_already_set() { + TestNet::reset(); + Hydra::execute_with(|| { + let new_decimals = 53_u8; + + assert_ne!(Registry::assets(HDX).unwrap().decimals.unwrap(), new_decimals); + + assert_ok!(Registry::update( + RawOrigin::Root.into(), + HDX, + None, + None, + None, + None, + None, + None, + Some(new_decimals), + None + )); + + assert_eq!(Registry::assets(HDX).unwrap().decimals.unwrap(), new_decimals); + }); +} + +#[test] +fn tech_comm_should_not_update_decimals_when_it_was_aleady_set() { + TestNet::reset(); + Hydra::execute_with(|| { + let tech_comm = pallet_collective::RawOrigin::::Members(1, 1); + let new_decimals = 53_u8; + + assert_ne!(Registry::assets(HDX).unwrap().decimals.unwrap(), new_decimals); + + assert_noop!( + Registry::update( + tech_comm.into(), + HDX, + None, + None, + None, + None, + None, + None, + Some(new_decimals), + None + ), + pallet_asset_registry::Error::::Forbidden + ); + }); +} + +#[test] +fn tech_comm_should_update_decimals_when_it_wasnt_set_yet() { + TestNet::reset(); + Hydra::execute_with(|| { + let tech_comm = pallet_collective::RawOrigin::::Members(1, 1); + let new_decimals = 12_u8; + + assert!(Registry::assets(LRNA).unwrap().decimals.is_none()); + + assert_ok!(Registry::update( + tech_comm.into(), + LRNA, + None, + None, + None, + None, + None, + None, + Some(new_decimals), + None + )); + + assert_eq!(Registry::assets(LRNA).unwrap().decimals.unwrap(), new_decimals); + }); +} + +#[test] +fn tech_comm_should_not_update_location_when_asset_exists() { + TestNet::reset(); + Hydra::execute_with(|| { + let tech_comm = pallet_collective::RawOrigin::::Members(1, 1); + + assert!(Registry::locations(LRNA).is_none()); + + assert_noop!( + Registry::update( + tech_comm.into(), + LRNA, + None, + None, + None, + None, + None, + None, + None, + Some(hydradx_runtime::AssetLocation(MultiLocation::new( + 1, + X2(Parachain(MOONBEAM_PARA_ID), GeneralIndex(0)) + ))), + ), + pallet_asset_registry::Error::::Forbidden + ); + }); +} + +#[test] +fn root_should_update_location_when_asset_exists() { + TestNet::reset(); + Hydra::execute_with(|| { + assert!(Registry::locations(LRNA).is_none()); + + let loc_1 = + hydradx_runtime::AssetLocation(MultiLocation::new(1, X2(Parachain(MOONBEAM_PARA_ID), GeneralIndex(0)))); + + //Set location 1-th time. + assert_ok!(Registry::update( + RawOrigin::Root.into(), + LRNA, + None, + None, + None, + None, + None, + None, + None, + Some(loc_1.clone()) + ),); + assert_eq!(Registry::locations(LRNA).unwrap(), loc_1); + assert_eq!(Registry::location_assets(loc_1.clone()).unwrap(), LRNA); + + // Update location if it was previously set. + let loc_2 = + hydradx_runtime::AssetLocation(MultiLocation::new(1, X2(Parachain(INTERLAY_PARA_ID), GeneralIndex(0)))); + + assert_ok!(Registry::update( + RawOrigin::Root.into(), + LRNA, + None, + None, + None, + None, + None, + None, + None, + Some(loc_2.clone()) + ),); + assert_eq!(Registry::locations(LRNA).unwrap(), loc_2); + assert_eq!(Registry::location_assets(loc_2).unwrap(), LRNA); + + assert!(Registry::location_assets(loc_1).is_none()); + }); +} diff --git a/integration-tests/src/bonds.rs b/integration-tests/src/bonds.rs index 5209a6835..4542af70d 100644 --- a/integration-tests/src/bonds.rs +++ b/integration-tests/src/bonds.rs @@ -3,18 +3,23 @@ use crate::assert_balance; use crate::polkadot_test_net::*; +use frame_support::storage::with_transaction; use frame_support::{assert_noop, assert_ok}; +use frame_system::RawOrigin; +use hydradx_traits::registry::{AssetKind, Create}; use orml_traits::MultiCurrency; -use sp_runtime::BoundedVec; +use sp_runtime::{DispatchResult, TransactionOutcome}; use xcm_emulator::TestExt; -use hydradx_runtime::{AssetRegistry, Bonds, Currencies, Runtime, RuntimeOrigin}; +use hydradx_runtime::{AssetRegistry, Bonds, Currencies, MultiTransactionPayment, Runtime, RuntimeOrigin, Tokens}; use primitives::constants::time::unix_time::MONTH; #[test] fn issue_bonds_should_work_when_issued_for_native_asset() { Hydra::execute_with(|| { // Arrange + set_fee_asset_and_fund(ALICE.into(), BTC, 1_000_000); + let amount = 100 * UNITS; let fee = ::ProtocolFee::get().mul_ceil(amount); let amount_without_fee: Balance = amount.checked_sub(fee).unwrap(); @@ -33,7 +38,10 @@ fn issue_bonds_should_work_when_issued_for_native_asset() { let bond_asset_details = AssetRegistry::assets(bond_id).unwrap(); assert_eq!(bond_asset_details.asset_type, pallet_asset_registry::AssetType::Bond); - assert_eq!(bond_asset_details.name.into_inner(), Bonds::bond_name(HDX, maturity)); + assert_eq!( + bond_asset_details.name.unwrap().into_inner(), + Bonds::bond_name(HDX, maturity) + ); assert_eq!(bond_asset_details.existential_deposit, NativeExistentialDeposit::get()); assert_balance!(&ALICE.into(), HDX, ALICE_INITIAL_NATIVE_BALANCE - amount); @@ -52,82 +60,117 @@ fn issue_bonds_should_work_when_issued_for_native_asset() { #[test] fn issue_bonds_should_work_when_issued_for_share_asset() { Hydra::execute_with(|| { - // Arrange - let amount = 100 * UNITS; - let fee = ::ProtocolFee::get().mul_ceil(amount); - let amount_without_fee: Balance = amount.checked_sub(fee).unwrap(); + let _ = with_transaction(|| { + // Arrange + set_fee_asset_and_fund(ALICE.into(), BTC, 1_000_000); + + let amount = 100 * UNITS; + let fee = ::ProtocolFee::get().mul_ceil(amount); + let amount_without_fee: Balance = amount.checked_sub(fee).unwrap(); + + let maturity = NOW + MONTH; + + let name = b"SHARED".to_vec(); + let share_asset_id = AssetRegistry::register_insufficient_asset( + None, + Some(name.try_into().unwrap()), + AssetKind::XYK, + Some(1_000), + None, + None, + None, + None, + ) + .unwrap(); + assert_ok!(Currencies::deposit(share_asset_id, &ALICE.into(), amount,)); + + // Act + let bond_id = AssetRegistry::next_asset_id().unwrap(); + assert_ok!(Bonds::issue( + RuntimeOrigin::signed(ALICE.into()), + share_asset_id, + amount, + maturity + )); - let maturity = NOW + MONTH; + // Assert + assert_eq!(Bonds::bond(bond_id).unwrap(), (share_asset_id, maturity)); - let bounded_name: BoundedVec::StringLimit> = - "SHARED".as_bytes().to_vec().try_into().unwrap(); - let share_asset_id = AssetRegistry::register_asset( - bounded_name, - pallet_asset_registry::AssetType::PoolShare(HDX, DOT), - 1_000, - None, - None, - ) - .unwrap(); - assert_ok!(Currencies::deposit(share_asset_id, &ALICE.into(), amount,)); + let bond_asset_details = AssetRegistry::assets(bond_id).unwrap(); - // Act - let bond_id = AssetRegistry::next_asset_id().unwrap(); - assert_ok!(Bonds::issue( - RuntimeOrigin::signed(ALICE.into()), - share_asset_id, - amount, - maturity - )); + assert_eq!(bond_asset_details.asset_type, pallet_asset_registry::AssetType::Bond); + assert_eq!( + bond_asset_details.name.unwrap().into_inner(), + Bonds::bond_name(share_asset_id, maturity) + ); + assert_eq!(bond_asset_details.existential_deposit, 1_000); - // Assert - assert_eq!(Bonds::bond(bond_id).unwrap(), (share_asset_id, maturity)); + assert_balance!(&ALICE.into(), share_asset_id, 0); + assert_balance!(&ALICE.into(), bond_id, amount_without_fee); - let bond_asset_details = AssetRegistry::assets(bond_id).unwrap(); + assert_balance!( + &::FeeReceiver::get(), + share_asset_id, + fee + ); - assert_eq!(bond_asset_details.asset_type, pallet_asset_registry::AssetType::Bond); - assert_eq!( - bond_asset_details.name.into_inner(), - Bonds::bond_name(share_asset_id, maturity) - ); - assert_eq!(bond_asset_details.existential_deposit, 1_000); + assert_balance!(&Bonds::pallet_account_id(), share_asset_id, amount_without_fee); - assert_balance!(&ALICE.into(), share_asset_id, 0); - assert_balance!(&ALICE.into(), bond_id, amount_without_fee); - - assert_balance!( - &::FeeReceiver::get(), - share_asset_id, - fee - ); - - assert_balance!(&Bonds::pallet_account_id(), share_asset_id, amount_without_fee); + TransactionOutcome::Commit(DispatchResult::Ok(())) + }); }); } #[test] fn issue_bonds_should_not_work_when_issued_for_bond_asset() { Hydra::execute_with(|| { - // Arrange - let amount = 100 * UNITS; - let maturity = NOW + MONTH; - - let bounded_name: BoundedVec::StringLimit> = - "BOND".as_bytes().to_vec().try_into().unwrap(); - let underlying_asset_id = - AssetRegistry::register_asset(bounded_name, pallet_asset_registry::AssetType::Bond, 1_000, None, None) - .unwrap(); - assert_ok!(Currencies::deposit(underlying_asset_id, &ALICE.into(), amount,)); - - // Act & Assert - assert_noop!( - Bonds::issue( - RuntimeOrigin::signed(ALICE.into()), - underlying_asset_id, - amount, - maturity - ), - pallet_bonds::Error::::DisallowedAsset - ); + let _ = with_transaction(|| { + // Arrange + let amount = 100 * UNITS; + let maturity = NOW + MONTH; + + let name = b"BOND".to_vec(); + let underlying_asset_id = AssetRegistry::register_insufficient_asset( + None, + Some(name.try_into().unwrap()), + AssetKind::Bond, + Some(1_000), + None, + None, + None, + None, + ) + .unwrap(); + + assert_ok!(Currencies::deposit(underlying_asset_id, &ALICE.into(), amount,)); + + // Act & Assert + assert_noop!( + Bonds::issue( + RuntimeOrigin::signed(ALICE.into()), + underlying_asset_id, + amount, + maturity + ), + pallet_bonds::Error::::DisallowedAsset + ); + + TransactionOutcome::Commit(DispatchResult::Ok(())) + }); }); } + +fn set_fee_asset_and_fund(who: AccountId, fee_asset: AssetId, amount: Balance) { + assert_ok!(Tokens::set_balance( + RawOrigin::Root.into(), + who.clone(), + fee_asset, + amount, + 0, + )); + + assert_ok!(MultiTransactionPayment::set_currency( + hydradx_runtime::RuntimeOrigin::signed(who), + fee_asset + )); +} diff --git a/integration-tests/src/cross_chain_transfer.rs b/integration-tests/src/cross_chain_transfer.rs index 06f6d2cfb..523fc63b6 100644 --- a/integration-tests/src/cross_chain_transfer.rs +++ b/integration-tests/src/cross_chain_transfer.rs @@ -8,6 +8,7 @@ use polkadot_xcm::{latest::prelude::*, v3::WeightLimit, VersionedMultiAssets, Ve use cumulus_primitives_core::ParaId; use frame_support::weights::Weight; use hex_literal::hex; +use hydradx_traits::registry::Mutate; use orml_traits::currency::MultiCurrency; use pretty_assertions::assert_eq; use sp_core::H256; @@ -28,7 +29,6 @@ fn hydra_should_receive_asset_when_transferred_from_polkadot_relay_chain() { //Arrange Hydra::execute_with(|| { assert_ok!(hydradx_runtime::AssetRegistry::set_location( - hydradx_runtime::RuntimeOrigin::root(), 1, hydradx_runtime::AssetLocation(MultiLocation::parent()) )); @@ -75,7 +75,6 @@ fn polkadot_should_receive_asset_when_sent_from_hydra() { Hydra::execute_with(|| { assert_ok!(hydradx_runtime::AssetRegistry::set_location( - hydradx_runtime::RuntimeOrigin::root(), 1, hydradx_runtime::AssetLocation(MultiLocation::parent()) )); @@ -111,7 +110,6 @@ fn hydra_should_receive_asset_when_transferred_from_acala() { Hydra::execute_with(|| { assert_ok!(hydradx_runtime::AssetRegistry::set_location( - hydradx_runtime::RuntimeOrigin::root(), ACA, hydradx_runtime::AssetLocation(MultiLocation::new(1, X2(Parachain(ACALA_PARA_ID), GeneralIndex(0)))) )); @@ -162,7 +160,6 @@ fn transfer_from_acala_should_fail_when_transferring_insufficient_amount() { Hydra::execute_with(|| { assert_ok!(hydradx_runtime::AssetRegistry::set_location( - hydradx_runtime::RuntimeOrigin::root(), 1, hydradx_runtime::AssetLocation(MultiLocation::new(1, X2(Parachain(ACALA_PARA_ID), GeneralIndex(0)))) )); @@ -213,7 +210,6 @@ fn hydra_treasury_should_receive_asset_when_transferred_to_protocol_account() { init_omnipool(); assert_ok!(hydradx_runtime::AssetRegistry::set_location( - hydradx_runtime::RuntimeOrigin::root(), DAI, // we pretend that the incoming tokens are DAI hydradx_runtime::AssetLocation(MultiLocation::new(1, X2(Parachain(ACALA_PARA_ID), GeneralIndex(0)))) )); @@ -325,7 +321,6 @@ fn claim_trapped_asset_should_work() { // register the asset Hydra::execute_with(|| { assert_ok!(hydradx_runtime::AssetRegistry::set_location( - hydradx_runtime::RuntimeOrigin::root(), 1, hydradx_runtime::AssetLocation(MultiLocation::new(1, X2(Parachain(ACALA_PARA_ID), GeneralIndex(0)))) )); diff --git a/integration-tests/src/dca.rs b/integration-tests/src/dca.rs index 7956b8ec2..7a34902fa 100644 --- a/integration-tests/src/dca.rs +++ b/integration-tests/src/dca.rs @@ -9,14 +9,13 @@ use frame_support::storage::with_transaction; use frame_system::RawOrigin; use hydradx_runtime::XYK; use hydradx_runtime::{ - AssetRegistry, Balances, Currencies, Omnipool, Router, Runtime, RuntimeEvent, RuntimeOrigin, Stableswap, Tokens, - Treasury, DCA, + AssetRegistry, Balances, Currencies, InsufficientEDinHDX, Omnipool, Router, Runtime, RuntimeEvent, RuntimeOrigin, + Stableswap, Tokens, Treasury, DCA, }; - +use hydradx_traits::registry::{AssetKind, Create}; use hydradx_traits::router::AssetPair; use hydradx_traits::router::PoolType; use hydradx_traits::router::Trade; -use hydradx_traits::Registry; use orml_traits::MultiCurrency; use orml_traits::MultiReservableCurrency; use pallet_dca::types::{Order, Schedule}; @@ -26,8 +25,8 @@ use primitives::{AssetId, Balance}; use sp_runtime::traits::ConstU32; use sp_runtime::DispatchError; use sp_runtime::Permill; -use sp_runtime::TransactionOutcome; use sp_runtime::{BoundedVec, FixedU128}; +use sp_runtime::{DispatchResult, TransactionOutcome}; use xcm_emulator::TestExt; const TREASURY_ACCOUNT_INIT_BALANCE: Balance = 1000 * UNITS; @@ -1134,66 +1133,69 @@ mod stableswap { fn sell_should_work_when_two_stableassets_swapped() { TestNet::reset(); Hydra::execute_with(|| { - //Arrange - let (pool_id, asset_a, asset_b) = init_stableswap().unwrap(); - - assert_ok!(hydradx_runtime::MultiTransactionPayment::add_currency( - RuntimeOrigin::root(), - asset_a, - FixedU128::from_rational(88, 100), - )); - - let alice_init_asset_a_balance = 5000 * UNITS; - assert_ok!(Currencies::update_balance( - RuntimeOrigin::root(), - ALICE.into(), - asset_a, - alice_init_asset_a_balance as i128, - )); - - assert_ok!(Currencies::update_balance( - RuntimeOrigin::root(), - CHARLIE.into(), - asset_a, - 5000 * UNITS as i128, - )); - assert_ok!(Stableswap::sell( - RuntimeOrigin::signed(CHARLIE.into()), - pool_id, - asset_a, - asset_b, - 100 * UNITS, - 0u128, - )); - - let dca_budget = 1100 * UNITS; - let amount_to_sell = 100 * UNITS; - let schedule1 = schedule_fake_with_sell_order( - ALICE, - PoolType::Stableswap(pool_id), - dca_budget, - asset_a, - asset_b, - amount_to_sell, - ); - set_relaychain_block_number(10); - - create_schedule(ALICE, schedule1); + let _ = with_transaction(|| { + //Arrange + let (pool_id, asset_a, asset_b) = init_stableswap().unwrap(); + + assert_ok!(hydradx_runtime::MultiTransactionPayment::add_currency( + RuntimeOrigin::root(), + asset_a, + FixedU128::from_rational(88, 100), + )); - assert_balance!(ALICE.into(), asset_a, alice_init_asset_a_balance - dca_budget); - assert_balance!(ALICE.into(), asset_b, 0); - assert_reserved_balance!(&ALICE.into(), asset_a, dca_budget); - assert_balance!(&Treasury::account_id(), asset_a, 0); + let alice_init_asset_a_balance = 5000 * UNITS; + assert_ok!(Currencies::update_balance( + RuntimeOrigin::root(), + ALICE.into(), + asset_a, + alice_init_asset_a_balance as i128, + )); - //Act - set_relaychain_block_number(11); + assert_ok!(Currencies::update_balance( + RuntimeOrigin::root(), + CHARLIE.into(), + asset_a, + 5000 * UNITS as i128, + )); + assert_ok!(Stableswap::sell( + RuntimeOrigin::signed(CHARLIE.into()), + pool_id, + asset_a, + asset_b, + 100 * UNITS, + 0u128, + )); - //Assert - let fee = Currencies::free_balance(asset_a, &Treasury::account_id()); - assert!(fee > 0, "The treasury did not receive the fee"); - assert_balance!(ALICE.into(), asset_a, alice_init_asset_a_balance - dca_budget); - assert_balance!(ALICE.into(), asset_b, 98999999706917); - assert_reserved_balance!(&ALICE.into(), asset_a, dca_budget - amount_to_sell - fee); + let dca_budget = 1100 * UNITS; + let amount_to_sell = 100 * UNITS; + let schedule1 = schedule_fake_with_sell_order( + ALICE, + PoolType::Stableswap(pool_id), + dca_budget, + asset_a, + asset_b, + amount_to_sell, + ); + set_relaychain_block_number(10); + + create_schedule(ALICE, schedule1); + + assert_balance!(ALICE.into(), asset_a, alice_init_asset_a_balance - dca_budget); + assert_balance!(ALICE.into(), asset_b, 0); + assert_reserved_balance!(&ALICE.into(), asset_a, dca_budget); + assert_balance!(&Treasury::account_id(), asset_a, 0); + + //Act + set_relaychain_block_number(11); + + //Assert + let fee = Currencies::free_balance(asset_a, &Treasury::account_id()); + assert!(fee > 0, "The treasury did not receive the fee"); + assert_balance!(ALICE.into(), asset_a, alice_init_asset_a_balance - dca_budget); + assert_balance!(ALICE.into(), asset_b, 98999999706917); + assert_reserved_balance!(&ALICE.into(), asset_a, dca_budget - amount_to_sell - fee); + TransactionOutcome::Commit(DispatchResult::Ok(())) + }); }); } @@ -1201,67 +1203,71 @@ mod stableswap { fn two_stableswap_asssets_should_be_swapped_when_they_have_different_decimals() { TestNet::reset(); Hydra::execute_with(|| { - //Arrange - let (pool_id, asset_a, asset_b) = init_stableswap_with_three_assets_having_different_decimals().unwrap(); - - //Populate oracle - assert_ok!(Currencies::update_balance( - RuntimeOrigin::root(), - CHARLIE.into(), - asset_b, - 5000 * UNITS as i128, - )); - assert_ok!(Stableswap::sell( - RuntimeOrigin::signed(CHARLIE.into()), - pool_id, - asset_a, - asset_b, - 10_000_000, - 0u128, - )); - - assert_ok!(hydradx_runtime::MultiTransactionPayment::add_currency( - RuntimeOrigin::root(), - asset_a, - FixedU128::from_rational(88, 100), - )); - - let alice_init_asset_a_balance = 5000 * UNITS; - assert_ok!(Currencies::update_balance( - RuntimeOrigin::root(), - ALICE.into(), - asset_a, - alice_init_asset_a_balance as i128, - )); - - let dca_budget = 1100 * UNITS; - let amount_to_sell = 100 * UNITS; - let schedule1 = schedule_fake_with_sell_order( - ALICE, - PoolType::Stableswap(pool_id), - dca_budget, - asset_a, - asset_b, - amount_to_sell, - ); - set_relaychain_block_number(10); - - create_schedule(ALICE, schedule1); + let _ = with_transaction(|| { + //Arrange + let (pool_id, asset_a, asset_b) = + init_stableswap_with_three_assets_having_different_decimals().unwrap(); + + //Populate oracle + assert_ok!(Currencies::update_balance( + RuntimeOrigin::root(), + CHARLIE.into(), + asset_b, + 5000 * UNITS as i128, + )); + assert_ok!(Stableswap::sell( + RuntimeOrigin::signed(CHARLIE.into()), + pool_id, + asset_a, + asset_b, + 10_000_000, + 0u128, + )); - assert_balance!(ALICE.into(), asset_a, alice_init_asset_a_balance - dca_budget); - assert_balance!(ALICE.into(), asset_b, 0); - assert_reserved_balance!(&ALICE.into(), asset_a, dca_budget); - assert_balance!(&Treasury::account_id(), asset_a, 0); + assert_ok!(hydradx_runtime::MultiTransactionPayment::add_currency( + RuntimeOrigin::root(), + asset_a, + FixedU128::from_rational(88, 100), + )); - //Act - set_relaychain_block_number(11); + let alice_init_asset_a_balance = 5000 * UNITS; + assert_ok!(Currencies::update_balance( + RuntimeOrigin::root(), + ALICE.into(), + asset_a, + alice_init_asset_a_balance as i128, + )); - //Assert - let fee = Currencies::free_balance(asset_a, &Treasury::account_id()); - assert!(fee > 0, "The treasury did not receive the fee"); - assert_balance!(ALICE.into(), asset_a, alice_init_asset_a_balance - dca_budget); - assert_balance!(ALICE.into(), asset_b, 93176719400532); - assert_reserved_balance!(&ALICE.into(), asset_a, dca_budget - amount_to_sell - fee); + let dca_budget = 1100 * UNITS; + let amount_to_sell = 100 * UNITS; + let schedule1 = schedule_fake_with_sell_order( + ALICE, + PoolType::Stableswap(pool_id), + dca_budget, + asset_a, + asset_b, + amount_to_sell, + ); + set_relaychain_block_number(10); + + create_schedule(ALICE, schedule1); + + assert_balance!(ALICE.into(), asset_a, alice_init_asset_a_balance - dca_budget); + assert_balance!(ALICE.into(), asset_b, 0); + assert_reserved_balance!(&ALICE.into(), asset_a, dca_budget); + assert_balance!(&Treasury::account_id(), asset_a, 0); + + //Act + set_relaychain_block_number(11); + + //Assert + let fee = Currencies::free_balance(asset_a, &Treasury::account_id()); + assert!(fee > 0, "The treasury did not receive the fee"); + assert_balance!(ALICE.into(), asset_a, alice_init_asset_a_balance - dca_budget); + assert_balance!(ALICE.into(), asset_b, 93176719400532); + assert_reserved_balance!(&ALICE.into(), asset_a, dca_budget - amount_to_sell - fee); + TransactionOutcome::Commit(DispatchResult::Ok(())) + }); }); } @@ -1272,240 +1278,251 @@ mod stableswap { //With DCA TestNet::reset(); Hydra::execute_with(|| { - //Arrange - let (pool_id, stable_asset_1, stable_asset_2) = init_stableswap().unwrap(); + let _ = with_transaction(|| { + //Arrange + let (pool_id, stable_asset_1, stable_asset_2) = init_stableswap().unwrap(); - assert_ok!(Currencies::update_balance( - RuntimeOrigin::root(), - CHARLIE.into(), - stable_asset_1, - 10000 * UNITS as i128, - )); - assert_ok!(Stableswap::sell( - RuntimeOrigin::signed(CHARLIE.into()), - pool_id, - stable_asset_1, - stable_asset_2, - 10000 * UNITS, - 0, - )); + assert_ok!(Currencies::update_balance( + RuntimeOrigin::root(), + CHARLIE.into(), + stable_asset_1, + 10000 * UNITS as i128, + )); + assert_ok!(Stableswap::sell( + RuntimeOrigin::signed(CHARLIE.into()), + pool_id, + stable_asset_1, + stable_asset_2, + 10000 * UNITS, + 0, + )); - init_omnipol(); - assert_ok!(Currencies::update_balance( - RuntimeOrigin::root(), - Omnipool::protocol_account(), - pool_id, - 30_000_000 * UNITS as i128, - )); + init_omnipol(); + assert_ok!(Currencies::update_balance( + RuntimeOrigin::root(), + Omnipool::protocol_account(), + pool_id, + 30_000_000 * UNITS as i128, + )); - assert_ok!(Omnipool::add_token( - RuntimeOrigin::root(), - pool_id, - FixedU128::from_rational(50, 100), - Permill::from_percent(100), - AccountId::from(BOB), - )); - set_zero_reward_for_referrals(pool_id); - do_trade_to_populate_oracle(DAI, HDX, UNITS); + assert_ok!(Omnipool::add_token( + RuntimeOrigin::root(), + pool_id, + FixedU128::from_rational(50, 100), + Permill::from_percent(100), + AccountId::from(BOB), + )); + set_zero_reward_for_referrals(pool_id); + do_trade_to_populate_oracle(DAI, HDX, UNITS); - set_relaychain_block_number(10); + set_relaychain_block_number(10); - let alice_init_hdx_balance = 5000 * UNITS; - assert_ok!(Balances::force_set_balance( - RawOrigin::Root.into(), - ALICE.into(), - alice_init_hdx_balance, - )); + let alice_init_hdx_balance = 5000 * UNITS; + assert_ok!(Balances::force_set_balance( + RawOrigin::Root.into(), + ALICE.into(), + alice_init_hdx_balance, + )); - let trades = vec![ - Trade { - pool: PoolType::Omnipool, - asset_in: HDX, - asset_out: pool_id, - }, - Trade { - pool: PoolType::Stableswap(pool_id), - asset_in: pool_id, - asset_out: stable_asset_1, - }, - ]; - let dca_budget = 1100 * UNITS; + let trades = vec![ + Trade { + pool: PoolType::Omnipool, + asset_in: HDX, + asset_out: pool_id, + }, + Trade { + pool: PoolType::Stableswap(pool_id), + asset_in: pool_id, + asset_out: stable_asset_1, + }, + ]; + let dca_budget = 1100 * UNITS; + + let schedule = Schedule { + owner: AccountId::from(ALICE), + period: 3u32, + total_amount: dca_budget, + max_retries: None, + stability_threshold: None, + slippage: Some(Permill::from_percent(10)), + order: Order::Sell { + asset_in: HDX, + asset_out: stable_asset_1, + amount_in: amount_to_sell, + min_amount_out: Balance::MIN, + route: create_bounded_vec(trades), + }, + }; - let schedule = Schedule { - owner: AccountId::from(ALICE), - period: 3u32, - total_amount: dca_budget, - max_retries: None, - stability_threshold: None, - slippage: Some(Permill::from_percent(10)), - order: Order::Sell { - asset_in: HDX, - asset_out: stable_asset_1, - amount_in: amount_to_sell, - min_amount_out: Balance::MIN, - route: create_bounded_vec(trades), - }, - }; + create_schedule(ALICE, schedule); - create_schedule(ALICE, schedule); + assert_balance!(ALICE.into(), HDX, alice_init_hdx_balance - dca_budget); + assert_balance!(ALICE.into(), stable_asset_1, 0); + assert_reserved_balance!(&ALICE.into(), HDX, dca_budget); + assert_balance!(&Treasury::account_id(), HDX, TREASURY_ACCOUNT_INIT_BALANCE); - assert_balance!(ALICE.into(), HDX, alice_init_hdx_balance - dca_budget); - assert_balance!(ALICE.into(), stable_asset_1, 0); - assert_reserved_balance!(&ALICE.into(), HDX, dca_budget); - assert_balance!(&Treasury::account_id(), HDX, TREASURY_ACCOUNT_INIT_BALANCE); + //Act + set_relaychain_block_number(11); - //Act - set_relaychain_block_number(11); + //Assert + let fee = Currencies::free_balance(HDX, &Treasury::account_id()) - TREASURY_ACCOUNT_INIT_BALANCE; + assert!(fee > 0, "The treasury did not receive the fee"); + assert_balance!(ALICE.into(), HDX, alice_init_hdx_balance - dca_budget); + assert_balance!(ALICE.into(), stable_asset_1, amount_to_receive); - //Assert - let fee = Currencies::free_balance(HDX, &Treasury::account_id()) - TREASURY_ACCOUNT_INIT_BALANCE; - assert!(fee > 0, "The treasury did not receive the fee"); - assert_balance!(ALICE.into(), HDX, alice_init_hdx_balance - dca_budget); - assert_balance!(ALICE.into(), stable_asset_1, amount_to_receive); + assert_reserved_balance!(&ALICE.into(), HDX, dca_budget - amount_to_sell - fee); - assert_reserved_balance!(&ALICE.into(), HDX, dca_budget - amount_to_sell - fee); + let treasury_balance = Currencies::free_balance(HDX, &Treasury::account_id()); + assert!(treasury_balance > TREASURY_ACCOUNT_INIT_BALANCE); - let treasury_balance = Currencies::free_balance(HDX, &Treasury::account_id()); - assert!(treasury_balance > TREASURY_ACCOUNT_INIT_BALANCE); + TransactionOutcome::Commit(DispatchResult::Ok(())) + }); }); //Do the same in with pool trades TestNet::reset(); Hydra::execute_with(|| { - //Arrange - let (pool_id, stable_asset_1, stable_asset_2) = init_stableswap().unwrap(); - assert_ok!(Currencies::update_balance( - RuntimeOrigin::root(), - CHARLIE.into(), - stable_asset_1, - 10000 * UNITS as i128, - )); - assert_ok!(Stableswap::sell( - RuntimeOrigin::signed(CHARLIE.into()), - pool_id, - stable_asset_1, - stable_asset_2, - 10000 * UNITS, - 0, - )); + let _ = with_transaction(|| { + //Arrange + let (pool_id, stable_asset_1, stable_asset_2) = init_stableswap().unwrap(); + assert_ok!(Currencies::update_balance( + RuntimeOrigin::root(), + CHARLIE.into(), + stable_asset_1, + 10000 * UNITS as i128, + )); + assert_ok!(Stableswap::sell( + RuntimeOrigin::signed(CHARLIE.into()), + pool_id, + stable_asset_1, + stable_asset_2, + 10000 * UNITS, + 0, + )); - init_omnipol(); + init_omnipol(); - assert_ok!(Currencies::update_balance( - RuntimeOrigin::root(), - Omnipool::protocol_account(), - pool_id, - 30_000_000 * UNITS as i128, - )); + assert_ok!(Currencies::update_balance( + RuntimeOrigin::root(), + Omnipool::protocol_account(), + pool_id, + 30_000_000 * UNITS as i128, + )); - assert_ok!(Omnipool::add_token( - RuntimeOrigin::root(), - pool_id, - FixedU128::from_rational(50, 100), - Permill::from_percent(100), - AccountId::from(BOB), - )); - set_zero_reward_for_referrals(pool_id); - do_trade_to_populate_oracle(DAI, HDX, UNITS); + assert_ok!(Omnipool::add_token( + RuntimeOrigin::root(), + pool_id, + FixedU128::from_rational(50, 100), + Permill::from_percent(100), + AccountId::from(BOB), + )); + set_zero_reward_for_referrals(pool_id); + do_trade_to_populate_oracle(DAI, HDX, UNITS); - set_relaychain_block_number(10); + set_relaychain_block_number(10); - //Act - assert_ok!(Omnipool::sell( - RuntimeOrigin::signed(ALICE.into()), - HDX, - pool_id, - amount_to_sell, - 0, - )); + //Act + assert_ok!(Omnipool::sell( + RuntimeOrigin::signed(ALICE.into()), + HDX, + pool_id, + amount_to_sell, + 0, + )); - let pool_id_balance = Currencies::free_balance(pool_id, &AccountId::from(ALICE)); + let pool_id_balance = Currencies::free_balance(pool_id, &AccountId::from(ALICE)); - assert_ok!(Stableswap::remove_liquidity_one_asset( - RuntimeOrigin::signed(ALICE.into()), - pool_id, - stable_asset_1, - pool_id_balance, - 0 - )); + assert_ok!(Stableswap::remove_liquidity_one_asset( + RuntimeOrigin::signed(ALICE.into()), + pool_id, + stable_asset_1, + pool_id_balance, + 0 + )); - //Assert - assert_balance!(ALICE.into(), HDX, ALICE_INITIAL_NATIVE_BALANCE - amount_to_sell); - assert_balance!(ALICE.into(), stable_asset_1, amount_to_receive); + //Assert + assert_balance!(ALICE.into(), HDX, ALICE_INITIAL_NATIVE_BALANCE - amount_to_sell); + assert_balance!(ALICE.into(), stable_asset_1, amount_to_receive); + TransactionOutcome::Commit(DispatchResult::Ok(())) + }); }); //Do the same with plain router TestNet::reset(); Hydra::execute_with(|| { - //Arrange - let (pool_id, stable_asset_1, stable_asset_2) = init_stableswap().unwrap(); - assert_ok!(Currencies::update_balance( - RuntimeOrigin::root(), - CHARLIE.into(), - stable_asset_1, - 10000 * UNITS as i128, - )); - assert_ok!(Stableswap::sell( - RuntimeOrigin::signed(CHARLIE.into()), - pool_id, - stable_asset_1, - stable_asset_2, - 10000 * UNITS, - 0, - )); + let _ = with_transaction(|| { + //Arrange + let (pool_id, stable_asset_1, stable_asset_2) = init_stableswap().unwrap(); + assert_ok!(Currencies::update_balance( + RuntimeOrigin::root(), + CHARLIE.into(), + stable_asset_1, + 10000 * UNITS as i128, + )); + assert_ok!(Stableswap::sell( + RuntimeOrigin::signed(CHARLIE.into()), + pool_id, + stable_asset_1, + stable_asset_2, + 10000 * UNITS, + 0, + )); - init_omnipol(); - assert_ok!(Currencies::update_balance( - RuntimeOrigin::root(), - Omnipool::protocol_account(), - pool_id, - 30_000_000 * UNITS as i128, - )); + init_omnipol(); + assert_ok!(Currencies::update_balance( + RuntimeOrigin::root(), + Omnipool::protocol_account(), + pool_id, + 30_000_000 * UNITS as i128, + )); - assert_ok!(Omnipool::add_token( - RuntimeOrigin::root(), - pool_id, - FixedU128::from_rational(50, 100), - Permill::from_percent(100), - AccountId::from(BOB), - )); - set_zero_reward_for_referrals(pool_id); - do_trade_to_populate_oracle(DAI, HDX, UNITS); + assert_ok!(Omnipool::add_token( + RuntimeOrigin::root(), + pool_id, + FixedU128::from_rational(50, 100), + Permill::from_percent(100), + AccountId::from(BOB), + )); + set_zero_reward_for_referrals(pool_id); + do_trade_to_populate_oracle(DAI, HDX, UNITS); - set_relaychain_block_number(10); + set_relaychain_block_number(10); - let alice_init_hdx_balance = 5000 * UNITS; - assert_ok!(Balances::force_set_balance( - RawOrigin::Root.into(), - ALICE.into(), - alice_init_hdx_balance, - )); + let alice_init_hdx_balance = 5000 * UNITS; + assert_ok!(Balances::force_set_balance( + RawOrigin::Root.into(), + ALICE.into(), + alice_init_hdx_balance, + )); - let trades = vec![ - Trade { - pool: PoolType::Omnipool, - asset_in: HDX, - asset_out: pool_id, - }, - Trade { - pool: PoolType::Stableswap(pool_id), - asset_in: pool_id, - asset_out: stable_asset_1, - }, - ]; + let trades = vec![ + Trade { + pool: PoolType::Omnipool, + asset_in: HDX, + asset_out: pool_id, + }, + Trade { + pool: PoolType::Stableswap(pool_id), + asset_in: pool_id, + asset_out: stable_asset_1, + }, + ]; - assert_ok!(Router::sell( - RuntimeOrigin::signed(ALICE.into()), - HDX, - stable_asset_1, - amount_to_sell, - 0, - trades - )); + assert_ok!(Router::sell( + RuntimeOrigin::signed(ALICE.into()), + HDX, + stable_asset_1, + amount_to_sell, + 0, + trades + )); - //Assert - assert_balance!(ALICE.into(), HDX, alice_init_hdx_balance - amount_to_sell); - assert_balance!(ALICE.into(), stable_asset_1, amount_to_receive); + //Assert + assert_balance!(ALICE.into(), HDX, alice_init_hdx_balance - amount_to_sell); + assert_balance!(ALICE.into(), stable_asset_1, amount_to_receive); + + TransactionOutcome::Commit(DispatchResult::Ok(())) + }); }); } @@ -1516,318 +1533,329 @@ mod stableswap { let amount_to_receive = 70832735995328; TestNet::reset(); Hydra::execute_with(|| { - //Arrange - let (pool_id, stable_asset_1, stable_asset_2) = init_stableswap().unwrap(); + let _ = with_transaction(|| { + //Arrange + let (pool_id, stable_asset_1, stable_asset_2) = init_stableswap().unwrap(); + + //To populate stableswap oracle + assert_ok!(Currencies::update_balance( + RuntimeOrigin::root(), + CHARLIE.into(), + stable_asset_1, + 10000 * UNITS as i128, + )); + assert_ok!(Stableswap::sell( + RuntimeOrigin::signed(CHARLIE.into()), + pool_id, + stable_asset_1, + stable_asset_2, + 100 * UNITS, + 0, + )); - //To populate stableswap oracle - assert_ok!(Currencies::update_balance( - RuntimeOrigin::root(), - CHARLIE.into(), - stable_asset_1, - 10000 * UNITS as i128, - )); - assert_ok!(Stableswap::sell( - RuntimeOrigin::signed(CHARLIE.into()), - pool_id, - stable_asset_1, - stable_asset_2, - 100 * UNITS, - 0, - )); + //Set stable asset 1 as accepted payment currency + assert_ok!(hydradx_runtime::MultiTransactionPayment::add_currency( + RuntimeOrigin::root(), + stable_asset_1, + FixedU128::from_rational(50, 100), + )); - //Set stable asset 1 as accepted payment currency - assert_ok!(hydradx_runtime::MultiTransactionPayment::add_currency( - RuntimeOrigin::root(), - stable_asset_1, - FixedU128::from_rational(50, 100), - )); + //Init omnipool and add pool id as token + init_omnipol(); + assert_ok!(Currencies::update_balance( + RuntimeOrigin::root(), + Omnipool::protocol_account(), + pool_id, + 3000 * UNITS as i128, + )); - //Init omnipool and add pool id as token - init_omnipol(); - assert_ok!(Currencies::update_balance( - RuntimeOrigin::root(), - Omnipool::protocol_account(), - pool_id, - 3000 * UNITS as i128, - )); - - assert_ok!(Omnipool::add_token( - RuntimeOrigin::root(), - pool_id, - FixedU128::from_rational(50, 100), - Permill::from_percent(100), - AccountId::from(BOB), - )); - set_zero_reward_for_referrals(pool_id); - //Populate oracle with omnipool source - assert_ok!(Tokens::set_balance( - RawOrigin::Root.into(), - CHARLIE.into(), - pool_id, - 1000 * UNITS, - 0, - )); - - assert_ok!(Omnipool::sell( - RuntimeOrigin::signed(CHARLIE.into()), - pool_id, - HDX, - 500 * UNITS, - Balance::MIN - )); - - set_relaychain_block_number(1000); - - let alice_init_stable1_balance = 5000 * UNITS; - assert_ok!(Currencies::update_balance( - RuntimeOrigin::root(), - ALICE.into(), - stable_asset_1, - alice_init_stable1_balance as i128, - )); - - let trades = vec![ - Trade { - pool: PoolType::Stableswap(pool_id), - asset_in: stable_asset_1, - asset_out: pool_id, - }, - Trade { - pool: PoolType::Omnipool, - asset_in: pool_id, - asset_out: HDX, - }, - ]; - let dca_budget = 1100 * UNITS; - - let schedule = Schedule { - owner: AccountId::from(ALICE), - period: 3u32, - total_amount: dca_budget, - max_retries: None, - stability_threshold: None, - slippage: Some(Permill::from_percent(10)), - order: Order::Sell { - asset_in: stable_asset_1, - asset_out: HDX, - amount_in: amount_to_sell, - min_amount_out: Balance::MIN, - route: create_bounded_vec(trades), - }, - }; + assert_ok!(Omnipool::add_token( + RuntimeOrigin::root(), + pool_id, + FixedU128::from_rational(50, 100), + Permill::from_percent(100), + AccountId::from(BOB), + )); + set_zero_reward_for_referrals(pool_id); + //Populate oracle with omnipool source + assert_ok!(Tokens::set_balance( + RawOrigin::Root.into(), + CHARLIE.into(), + pool_id, + 1000 * UNITS, + 0, + )); - create_schedule(ALICE, schedule); + assert_ok!(Omnipool::sell( + RuntimeOrigin::signed(CHARLIE.into()), + pool_id, + HDX, + 500 * UNITS, + Balance::MIN + )); - assert_balance!(ALICE.into(), stable_asset_1, alice_init_stable1_balance - dca_budget); - assert_balance!(ALICE.into(), HDX, ALICE_INITIAL_NATIVE_BALANCE); - assert_reserved_balance!(&ALICE.into(), stable_asset_1, dca_budget); - assert_balance!(&Treasury::account_id(), stable_asset_1, 0); + set_relaychain_block_number(1000); - //Act - set_relaychain_block_number(1001); - - //Assert - let fee = Currencies::free_balance(stable_asset_1, &Treasury::account_id()); - assert!(fee > 0, "The treasury did not receive the fee"); - assert_balance!(ALICE.into(), stable_asset_1, alice_init_stable1_balance - dca_budget); - assert_balance!(ALICE.into(), HDX, ALICE_INITIAL_NATIVE_BALANCE + amount_to_receive_1); + let alice_init_stable1_balance = 5000 * UNITS; + assert_ok!(Currencies::update_balance( + RuntimeOrigin::root(), + ALICE.into(), + stable_asset_1, + alice_init_stable1_balance as i128, + )); - assert_reserved_balance!(&ALICE.into(), stable_asset_1, dca_budget - amount_to_sell - fee); + let trades = vec![ + Trade { + pool: PoolType::Stableswap(pool_id), + asset_in: stable_asset_1, + asset_out: pool_id, + }, + Trade { + pool: PoolType::Omnipool, + asset_in: pool_id, + asset_out: HDX, + }, + ]; + let dca_budget = 1100 * UNITS; + + let schedule = Schedule { + owner: AccountId::from(ALICE), + period: 3u32, + total_amount: dca_budget, + max_retries: None, + stability_threshold: None, + slippage: Some(Permill::from_percent(10)), + order: Order::Sell { + asset_in: stable_asset_1, + asset_out: HDX, + amount_in: amount_to_sell, + min_amount_out: Balance::MIN, + route: create_bounded_vec(trades), + }, + }; + + create_schedule(ALICE, schedule); + + assert_balance!(ALICE.into(), stable_asset_1, alice_init_stable1_balance - dca_budget); + assert_balance!(ALICE.into(), HDX, ALICE_INITIAL_NATIVE_BALANCE); + assert_reserved_balance!(&ALICE.into(), stable_asset_1, dca_budget); + assert_balance!(&Treasury::account_id(), stable_asset_1, 0); + + //Act + set_relaychain_block_number(1001); + + //Assert + let fee = Currencies::free_balance(stable_asset_1, &Treasury::account_id()); + assert!(fee > 0, "The treasury did not receive the fee"); + assert_balance!(ALICE.into(), stable_asset_1, alice_init_stable1_balance - dca_budget); + assert_balance!(ALICE.into(), HDX, ALICE_INITIAL_NATIVE_BALANCE + amount_to_receive_1); + + assert_reserved_balance!(&ALICE.into(), stable_asset_1, dca_budget - amount_to_sell - fee); + TransactionOutcome::Commit(DispatchResult::Ok(())) + }); }); //Do the same in with pool trades TestNet::reset(); Hydra::execute_with(|| { - //Arrange - let (pool_id, stable_asset_1, stable_asset_2) = init_stableswap().unwrap(); - - //To populate stableswap oracle - assert_ok!(Currencies::update_balance( - RuntimeOrigin::root(), - CHARLIE.into(), - stable_asset_1, - 10000 * UNITS as i128, - )); - assert_ok!(Stableswap::sell( - RuntimeOrigin::signed(CHARLIE.into()), - pool_id, - stable_asset_1, - stable_asset_2, - 100 * UNITS, - 0, - )); + let _ = with_transaction(|| { + //Arrange + let (pool_id, stable_asset_1, stable_asset_2) = init_stableswap().unwrap(); + + //To populate stableswap oracle + assert_ok!(Currencies::update_balance( + RuntimeOrigin::root(), + CHARLIE.into(), + stable_asset_1, + 10000 * UNITS as i128, + )); + assert_ok!(Stableswap::sell( + RuntimeOrigin::signed(CHARLIE.into()), + pool_id, + stable_asset_1, + stable_asset_2, + 100 * UNITS, + 0, + )); - init_omnipol(); + init_omnipol(); - assert_ok!(Currencies::update_balance( - RuntimeOrigin::root(), - Omnipool::protocol_account(), - pool_id, - 3000 * UNITS as i128, - )); + assert_ok!(Currencies::update_balance( + RuntimeOrigin::root(), + Omnipool::protocol_account(), + pool_id, + 3000 * UNITS as i128, + )); - assert_ok!(Omnipool::add_token( - RuntimeOrigin::root(), - pool_id, - FixedU128::from_rational(50, 100), - Permill::from_percent(100), - AccountId::from(BOB), - )); - set_zero_reward_for_referrals(pool_id); + assert_ok!(Omnipool::add_token( + RuntimeOrigin::root(), + pool_id, + FixedU128::from_rational(50, 100), + Permill::from_percent(100), + AccountId::from(BOB), + )); + set_zero_reward_for_referrals(pool_id); + + //Populate oracle with omnipool source + assert_ok!(Tokens::set_balance( + RawOrigin::Root.into(), + CHARLIE.into(), + pool_id, + 1000 * UNITS, + 0, + )); + assert_ok!(Omnipool::sell( + RuntimeOrigin::signed(CHARLIE.into()), + pool_id, + HDX, + 500 * UNITS, + Balance::MIN + )); - //Populate oracle with omnipool source - assert_ok!(Tokens::set_balance( - RawOrigin::Root.into(), - CHARLIE.into(), - pool_id, - 1000 * UNITS, - 0, - )); - assert_ok!(Omnipool::sell( - RuntimeOrigin::signed(CHARLIE.into()), - pool_id, - HDX, - 500 * UNITS, - Balance::MIN - )); + let alice_init_stable1_balance = 5000 * UNITS; + assert_ok!(Currencies::update_balance( + RuntimeOrigin::root(), + ALICE.into(), + stable_asset_1, + alice_init_stable1_balance as i128, + )); - let alice_init_stable1_balance = 5000 * UNITS; - assert_ok!(Currencies::update_balance( - RuntimeOrigin::root(), - ALICE.into(), - stable_asset_1, - alice_init_stable1_balance as i128, - )); + assert_balance!(ALICE.into(), pool_id, 0); - assert_balance!(ALICE.into(), pool_id, 0); + set_relaychain_block_number(10); - set_relaychain_block_number(10); + //Act + assert_ok!(Stableswap::add_liquidity( + RuntimeOrigin::signed(ALICE.into()), + pool_id, + vec![AssetAmount { + asset_id: stable_asset_1, + amount: amount_to_sell, + }], + )); + let alice_pool_id_balance = Currencies::free_balance(pool_id, &AccountId::from(ALICE)); - //Act - assert_ok!(Stableswap::add_liquidity( - RuntimeOrigin::signed(ALICE.into()), - pool_id, - vec![AssetAmount { - asset_id: stable_asset_1, - amount: amount_to_sell, - }], - )); - let alice_pool_id_balance = Currencies::free_balance(pool_id, &AccountId::from(ALICE)); + assert_ok!(Omnipool::sell( + RuntimeOrigin::signed(ALICE.into()), + pool_id, + HDX, + alice_pool_id_balance, + 0, + )); - assert_ok!(Omnipool::sell( - RuntimeOrigin::signed(ALICE.into()), - pool_id, - HDX, - alice_pool_id_balance, - 0, - )); + //Assert + assert_balance!( + ALICE.into(), + stable_asset_1, + alice_init_stable1_balance - amount_to_sell + ); + assert_balance!(ALICE.into(), HDX, ALICE_INITIAL_NATIVE_BALANCE + amount_to_receive); - //Assert - assert_balance!( - ALICE.into(), - stable_asset_1, - alice_init_stable1_balance - amount_to_sell - ); - assert_balance!(ALICE.into(), HDX, ALICE_INITIAL_NATIVE_BALANCE + amount_to_receive); + TransactionOutcome::Commit(DispatchResult::Ok(())) + }); }); //Do the same with plain router TestNet::reset(); Hydra::execute_with(|| { - //Arrange - let (pool_id, stable_asset_1, stable_asset_2) = init_stableswap().unwrap(); - - //To populate stableswap oracle - assert_ok!(Currencies::update_balance( - RuntimeOrigin::root(), - CHARLIE.into(), - stable_asset_1, - 10000 * UNITS as i128, - )); - assert_ok!(Stableswap::sell( - RuntimeOrigin::signed(CHARLIE.into()), - pool_id, - stable_asset_1, - stable_asset_2, - 100 * UNITS, - 0, - )); + let _ = with_transaction(|| { + //Arrange + let (pool_id, stable_asset_1, stable_asset_2) = init_stableswap().unwrap(); + + //To populate stableswap oracle + assert_ok!(Currencies::update_balance( + RuntimeOrigin::root(), + CHARLIE.into(), + stable_asset_1, + 10000 * UNITS as i128, + )); + assert_ok!(Stableswap::sell( + RuntimeOrigin::signed(CHARLIE.into()), + pool_id, + stable_asset_1, + stable_asset_2, + 100 * UNITS, + 0, + )); - init_omnipol(); + init_omnipol(); - assert_ok!(Currencies::update_balance( - RuntimeOrigin::root(), - Omnipool::protocol_account(), - pool_id, - 3000 * UNITS as i128, - )); + assert_ok!(Currencies::update_balance( + RuntimeOrigin::root(), + Omnipool::protocol_account(), + pool_id, + 3000 * UNITS as i128, + )); - assert_ok!(Omnipool::add_token( - RuntimeOrigin::root(), - pool_id, - FixedU128::from_rational(50, 100), - Permill::from_percent(100), - AccountId::from(BOB), - )); - set_zero_reward_for_referrals(pool_id); + assert_ok!(Omnipool::add_token( + RuntimeOrigin::root(), + pool_id, + FixedU128::from_rational(50, 100), + Permill::from_percent(100), + AccountId::from(BOB), + )); + set_zero_reward_for_referrals(pool_id); + + //Populate oracle with omnipool source + assert_ok!(Tokens::set_balance( + RawOrigin::Root.into(), + CHARLIE.into(), + pool_id, + 1000 * UNITS, + 0, + )); + assert_ok!(Omnipool::sell( + RuntimeOrigin::signed(CHARLIE.into()), + pool_id, + HDX, + 500 * UNITS, + Balance::MIN + )); - //Populate oracle with omnipool source - assert_ok!(Tokens::set_balance( - RawOrigin::Root.into(), - CHARLIE.into(), - pool_id, - 1000 * UNITS, - 0, - )); - assert_ok!(Omnipool::sell( - RuntimeOrigin::signed(CHARLIE.into()), - pool_id, - HDX, - 500 * UNITS, - Balance::MIN - )); + let alice_init_stable1_balance = 5000 * UNITS; + assert_ok!(Currencies::update_balance( + RuntimeOrigin::root(), + ALICE.into(), + stable_asset_1, + alice_init_stable1_balance as i128, + )); - let alice_init_stable1_balance = 5000 * UNITS; - assert_ok!(Currencies::update_balance( - RuntimeOrigin::root(), - ALICE.into(), - stable_asset_1, - alice_init_stable1_balance as i128, - )); + assert_balance!(ALICE.into(), pool_id, 0); - assert_balance!(ALICE.into(), pool_id, 0); + set_relaychain_block_number(10); - set_relaychain_block_number(10); + //Act + let trades = vec![ + Trade { + pool: PoolType::Stableswap(pool_id), + asset_in: stable_asset_1, + asset_out: pool_id, + }, + Trade { + pool: PoolType::Omnipool, + asset_in: pool_id, + asset_out: HDX, + }, + ]; + assert_ok!(Router::sell( + RuntimeOrigin::signed(ALICE.into()), + stable_asset_1, + HDX, + amount_to_sell, + 0, + trades + )); - //Act - let trades = vec![ - Trade { - pool: PoolType::Stableswap(pool_id), - asset_in: stable_asset_1, - asset_out: pool_id, - }, - Trade { - pool: PoolType::Omnipool, - asset_in: pool_id, - asset_out: HDX, - }, - ]; - assert_ok!(Router::sell( - RuntimeOrigin::signed(ALICE.into()), - stable_asset_1, - HDX, - amount_to_sell, - 0, - trades - )); + //Assert + assert_balance!( + ALICE.into(), + stable_asset_1, + alice_init_stable1_balance - amount_to_sell + ); + assert_balance!(ALICE.into(), HDX, ALICE_INITIAL_NATIVE_BALANCE + amount_to_receive); - //Assert - assert_balance!( - ALICE.into(), - stable_asset_1, - alice_init_stable1_balance - amount_to_sell - ); - assert_balance!(ALICE.into(), HDX, ALICE_INITIAL_NATIVE_BALANCE + amount_to_receive); + TransactionOutcome::Commit(DispatchResult::Ok(())) + }); }); } @@ -1837,97 +1865,101 @@ mod stableswap { //With DCA TestNet::reset(); Hydra::execute_with(|| { - //Arrange - let (pool_id, stable_asset_1, stable_asset_2) = init_stableswap().unwrap(); - - //To populate stableswap oracle - assert_ok!(Currencies::update_balance( - RuntimeOrigin::root(), - CHARLIE.into(), - stable_asset_1, - 10000 * UNITS as i128, - )); - assert_ok!(Stableswap::sell( - RuntimeOrigin::signed(CHARLIE.into()), - pool_id, - stable_asset_1, - stable_asset_2, - 3000 * UNITS, - 0, - )); - - init_omnipol(); - assert_ok!(Currencies::update_balance( - RuntimeOrigin::root(), - Omnipool::protocol_account(), - pool_id, - 3000 * UNITS as i128, - )); - - assert_ok!(Omnipool::add_token( - RuntimeOrigin::root(), - pool_id, - FixedU128::from_rational(50, 100), - Permill::from_percent(100), - AccountId::from(BOB), - )); - do_trade_to_populate_oracle(DAI, HDX, UNITS); - set_zero_reward_for_referrals(pool_id); - - set_relaychain_block_number(10); - - let alice_init_hdx_balance = 5000 * UNITS; - assert_ok!(Balances::force_set_balance( - RawOrigin::Root.into(), - ALICE.into(), - alice_init_hdx_balance, - )); - - let trades = vec![ - Trade { - pool: PoolType::Omnipool, - asset_in: HDX, - asset_out: pool_id, - }, - Trade { - pool: PoolType::Stableswap(pool_id), - asset_in: pool_id, - asset_out: stable_asset_1, - }, - ]; - let dca_budget = 1100 * UNITS; + let _ = with_transaction(|| { + //Arrange + let (pool_id, stable_asset_1, stable_asset_2) = init_stableswap().unwrap(); + + //To populate stableswap oracle + assert_ok!(Currencies::update_balance( + RuntimeOrigin::root(), + CHARLIE.into(), + stable_asset_1, + 10000 * UNITS as i128, + )); + assert_ok!(Stableswap::sell( + RuntimeOrigin::signed(CHARLIE.into()), + pool_id, + stable_asset_1, + stable_asset_2, + 3000 * UNITS, + 0, + )); - let schedule = Schedule { - owner: AccountId::from(ALICE), - period: 3u32, - total_amount: dca_budget, - max_retries: None, - stability_threshold: None, - slippage: Some(Permill::from_percent(10)), - order: Order::Buy { - asset_in: HDX, - asset_out: stable_asset_1, - amount_out: amount_to_buy, - max_amount_in: Balance::MAX, - route: create_bounded_vec(trades), - }, - }; + init_omnipol(); + assert_ok!(Currencies::update_balance( + RuntimeOrigin::root(), + Omnipool::protocol_account(), + pool_id, + 3000 * UNITS as i128, + )); - create_schedule(ALICE, schedule); + assert_ok!(Omnipool::add_token( + RuntimeOrigin::root(), + pool_id, + FixedU128::from_rational(50, 100), + Permill::from_percent(100), + AccountId::from(BOB), + )); + do_trade_to_populate_oracle(DAI, HDX, UNITS); + set_zero_reward_for_referrals(pool_id); - assert_balance!(ALICE.into(), HDX, alice_init_hdx_balance - dca_budget); - assert_balance!(ALICE.into(), stable_asset_1, 0); - assert_reserved_balance!(&ALICE.into(), HDX, dca_budget); - assert_balance!(&Treasury::account_id(), HDX, TREASURY_ACCOUNT_INIT_BALANCE); + set_relaychain_block_number(10); - //Act - set_relaychain_block_number(11); + let alice_init_hdx_balance = 5000 * UNITS; + assert_ok!(Balances::force_set_balance( + RawOrigin::Root.into(), + ALICE.into(), + alice_init_hdx_balance, + )); - //Assert - let fee = Currencies::free_balance(HDX, &Treasury::account_id()) - TREASURY_ACCOUNT_INIT_BALANCE; - assert!(fee > 0, "The treasury did not receive the fee"); - assert_balance!(ALICE.into(), HDX, alice_init_hdx_balance - dca_budget); - assert_balance!(ALICE.into(), stable_asset_1, amount_to_buy); + let trades = vec![ + Trade { + pool: PoolType::Omnipool, + asset_in: HDX, + asset_out: pool_id, + }, + Trade { + pool: PoolType::Stableswap(pool_id), + asset_in: pool_id, + asset_out: stable_asset_1, + }, + ]; + let dca_budget = 1100 * UNITS; + + let schedule = Schedule { + owner: AccountId::from(ALICE), + period: 3u32, + total_amount: dca_budget, + max_retries: None, + stability_threshold: None, + slippage: Some(Permill::from_percent(10)), + order: Order::Buy { + asset_in: HDX, + asset_out: stable_asset_1, + amount_out: amount_to_buy, + max_amount_in: Balance::MAX, + route: create_bounded_vec(trades), + }, + }; + + create_schedule(ALICE, schedule); + + assert_balance!(ALICE.into(), HDX, alice_init_hdx_balance - dca_budget); + assert_balance!(ALICE.into(), stable_asset_1, 0); + assert_reserved_balance!(&ALICE.into(), HDX, dca_budget); + assert_balance!(&Treasury::account_id(), HDX, TREASURY_ACCOUNT_INIT_BALANCE); + + //Act + set_relaychain_block_number(11); + + //Assert + let fee = Currencies::free_balance(HDX, &Treasury::account_id()) - TREASURY_ACCOUNT_INIT_BALANCE; + assert!(fee > 0, "The treasury did not receive the fee"); + assert_balance!(ALICE.into(), HDX, alice_init_hdx_balance - dca_budget); + assert_balance!(ALICE.into(), stable_asset_1, amount_to_buy); + + TransactionOutcome::Commit(DispatchResult::Ok(())) + }); }); } @@ -1935,64 +1967,68 @@ mod stableswap { fn buy_should_work_when_two_stableassets_swapped() { TestNet::reset(); Hydra::execute_with(|| { - //Arrange - let (pool_id, asset_a, asset_b) = init_stableswap().unwrap(); - - assert_ok!(hydradx_runtime::MultiTransactionPayment::add_currency( - RuntimeOrigin::root(), - asset_a, - FixedU128::from_rational(88, 100), - )); - - let alice_init_asset_a_balance = 5000 * UNITS; - assert_ok!(Currencies::update_balance( - RuntimeOrigin::root(), - ALICE.into(), - asset_a, - alice_init_asset_a_balance as i128, - )); - - assert_ok!(Currencies::update_balance( - RuntimeOrigin::root(), - CHARLIE.into(), - asset_a, - 5000 * UNITS as i128, - )); - assert_ok!(Stableswap::sell( - RuntimeOrigin::signed(CHARLIE.into()), - pool_id, - asset_a, - asset_b, - 100 * UNITS, - 0u128, - )); - - let dca_budget = 1100 * UNITS; - let amount_to_buy = 100 * UNITS; - let schedule1 = schedule_fake_with_buy_order( - PoolType::Stableswap(pool_id), - asset_a, - asset_b, - amount_to_buy, - dca_budget, - ); - set_relaychain_block_number(10); - - create_schedule(ALICE, schedule1); + let _ = with_transaction(|| { + //Arrange + let (pool_id, asset_a, asset_b) = init_stableswap().unwrap(); + + assert_ok!(hydradx_runtime::MultiTransactionPayment::add_currency( + RuntimeOrigin::root(), + asset_a, + FixedU128::from_rational(88, 100), + )); - assert_balance!(ALICE.into(), asset_a, alice_init_asset_a_balance - dca_budget); - assert_balance!(ALICE.into(), asset_b, 0); - assert_reserved_balance!(&ALICE.into(), asset_a, dca_budget); - assert_balance!(&Treasury::account_id(), asset_a, 0); + let alice_init_asset_a_balance = 5000 * UNITS; + assert_ok!(Currencies::update_balance( + RuntimeOrigin::root(), + ALICE.into(), + asset_a, + alice_init_asset_a_balance as i128, + )); - //Act - set_relaychain_block_number(11); + assert_ok!(Currencies::update_balance( + RuntimeOrigin::root(), + CHARLIE.into(), + asset_a, + 5000 * UNITS as i128, + )); + assert_ok!(Stableswap::sell( + RuntimeOrigin::signed(CHARLIE.into()), + pool_id, + asset_a, + asset_b, + 100 * UNITS, + 0u128, + )); - //Assert - let fee = Currencies::free_balance(asset_a, &Treasury::account_id()); - assert!(fee > 0, "The treasury did not receive the fee"); - assert_balance!(ALICE.into(), asset_a, alice_init_asset_a_balance - dca_budget); - assert_balance!(ALICE.into(), asset_b, amount_to_buy); + let dca_budget = 1100 * UNITS; + let amount_to_buy = 100 * UNITS; + let schedule1 = schedule_fake_with_buy_order( + PoolType::Stableswap(pool_id), + asset_a, + asset_b, + amount_to_buy, + dca_budget, + ); + set_relaychain_block_number(10); + + create_schedule(ALICE, schedule1); + + assert_balance!(ALICE.into(), asset_a, alice_init_asset_a_balance - dca_budget); + assert_balance!(ALICE.into(), asset_b, 0); + assert_reserved_balance!(&ALICE.into(), asset_a, dca_budget); + assert_balance!(&Treasury::account_id(), asset_a, 0); + + //Act + set_relaychain_block_number(11); + + //Assert + let fee = Currencies::free_balance(asset_a, &Treasury::account_id()); + assert!(fee > 0, "The treasury did not receive the fee"); + assert_balance!(ALICE.into(), asset_a, alice_init_asset_a_balance - dca_budget); + assert_balance!(ALICE.into(), asset_b, amount_to_buy); + + TransactionOutcome::Commit(DispatchResult::Ok(())) + }); }); } @@ -2001,106 +2037,110 @@ mod stableswap { let amount_to_buy = 100 * UNITS; TestNet::reset(); Hydra::execute_with(|| { - //Arrange - let (pool_id, stable_asset_1, stable_asset_2) = init_stableswap().unwrap(); - - //Set stable asset 1 as accepted payment currency - assert_ok!(hydradx_runtime::MultiTransactionPayment::add_currency( - RuntimeOrigin::root(), - stable_asset_1, - FixedU128::from_rational(50, 100), - )); - - //For populating oracle - assert_ok!(Currencies::update_balance( - RuntimeOrigin::root(), - CHARLIE.into(), - stable_asset_1, - 5000 * UNITS as i128, - )); - assert_ok!(Stableswap::sell( - RuntimeOrigin::signed(CHARLIE.into()), - pool_id, - stable_asset_1, - stable_asset_2, - 1000 * UNITS, - 0u128, - )); - - //Init omnipool and add pool id as token - init_omnipol(); - assert_ok!(Currencies::update_balance( - RuntimeOrigin::root(), - Omnipool::protocol_account(), - pool_id, - 3000 * UNITS as i128, - )); - - assert_ok!(Omnipool::add_token( - RuntimeOrigin::root(), - pool_id, - FixedU128::from_rational(50, 100), - Permill::from_percent(100), - AccountId::from(BOB), - )); - set_zero_reward_for_referrals(pool_id); - do_trade_to_populate_oracle(pool_id, HDX, 100 * UNITS); + let _ = with_transaction(|| { + //Arrange + let (pool_id, stable_asset_1, stable_asset_2) = init_stableswap().unwrap(); - set_relaychain_block_number(10); - - let alice_init_stable1_balance = 5000 * UNITS; - assert_ok!(Currencies::update_balance( - RuntimeOrigin::root(), - ALICE.into(), - stable_asset_1, - alice_init_stable1_balance as i128, - )); + //Set stable asset 1 as accepted payment currency + assert_ok!(hydradx_runtime::MultiTransactionPayment::add_currency( + RuntimeOrigin::root(), + stable_asset_1, + FixedU128::from_rational(50, 100), + )); - let trades = vec![ - Trade { - pool: PoolType::Stableswap(pool_id), - asset_in: stable_asset_1, - asset_out: pool_id, - }, - Trade { - pool: PoolType::Omnipool, - asset_in: pool_id, - asset_out: HDX, - }, - ]; - let dca_budget = 1100 * UNITS; + //For populating oracle + assert_ok!(Currencies::update_balance( + RuntimeOrigin::root(), + CHARLIE.into(), + stable_asset_1, + 5000 * UNITS as i128, + )); + assert_ok!(Stableswap::sell( + RuntimeOrigin::signed(CHARLIE.into()), + pool_id, + stable_asset_1, + stable_asset_2, + 1000 * UNITS, + 0u128, + )); - let schedule = Schedule { - owner: AccountId::from(ALICE), - period: 3u32, - total_amount: dca_budget, - max_retries: None, - stability_threshold: None, - slippage: Some(Permill::from_percent(70)), - order: Order::Buy { - asset_in: stable_asset_1, - asset_out: HDX, - amount_out: amount_to_buy, - max_amount_in: Balance::MAX, - route: create_bounded_vec(trades), - }, - }; + //Init omnipool and add pool id as token + init_omnipol(); + assert_ok!(Currencies::update_balance( + RuntimeOrigin::root(), + Omnipool::protocol_account(), + pool_id, + 3000 * UNITS as i128, + )); - create_schedule(ALICE, schedule); + assert_ok!(Omnipool::add_token( + RuntimeOrigin::root(), + pool_id, + FixedU128::from_rational(50, 100), + Permill::from_percent(100), + AccountId::from(BOB), + )); + set_zero_reward_for_referrals(pool_id); + do_trade_to_populate_oracle(pool_id, HDX, 100 * UNITS); - assert_balance!(ALICE.into(), stable_asset_1, alice_init_stable1_balance - dca_budget); - assert_balance!(ALICE.into(), HDX, ALICE_INITIAL_NATIVE_BALANCE); - assert_reserved_balance!(&ALICE.into(), stable_asset_1, dca_budget); - assert_balance!(&Treasury::account_id(), stable_asset_1, 0); + set_relaychain_block_number(10); - //Act - set_relaychain_block_number(11); + let alice_init_stable1_balance = 5000 * UNITS; + assert_ok!(Currencies::update_balance( + RuntimeOrigin::root(), + ALICE.into(), + stable_asset_1, + alice_init_stable1_balance as i128, + )); - //Assert - let fee = Currencies::free_balance(stable_asset_1, &Treasury::account_id()); - assert!(fee > 0, "The treasury did not receive the fee"); - assert_balance!(ALICE.into(), stable_asset_1, alice_init_stable1_balance - dca_budget); - assert_balance!(ALICE.into(), HDX, ALICE_INITIAL_NATIVE_BALANCE + amount_to_buy); + let trades = vec![ + Trade { + pool: PoolType::Stableswap(pool_id), + asset_in: stable_asset_1, + asset_out: pool_id, + }, + Trade { + pool: PoolType::Omnipool, + asset_in: pool_id, + asset_out: HDX, + }, + ]; + let dca_budget = 1100 * UNITS; + + let schedule = Schedule { + owner: AccountId::from(ALICE), + period: 3u32, + total_amount: dca_budget, + max_retries: None, + stability_threshold: None, + slippage: Some(Permill::from_percent(70)), + order: Order::Buy { + asset_in: stable_asset_1, + asset_out: HDX, + amount_out: amount_to_buy, + max_amount_in: Balance::MAX, + route: create_bounded_vec(trades), + }, + }; + + create_schedule(ALICE, schedule); + + assert_balance!(ALICE.into(), stable_asset_1, alice_init_stable1_balance - dca_budget); + assert_balance!(ALICE.into(), HDX, ALICE_INITIAL_NATIVE_BALANCE); + assert_reserved_balance!(&ALICE.into(), stable_asset_1, dca_budget); + assert_balance!(&Treasury::account_id(), stable_asset_1, 0); + + //Act + set_relaychain_block_number(11); + + //Assert + let fee = Currencies::free_balance(stable_asset_1, &Treasury::account_id()); + assert!(fee > 0, "The treasury did not receive the fee"); + assert_balance!(ALICE.into(), stable_asset_1, alice_init_stable1_balance - dca_budget); + assert_balance!(ALICE.into(), HDX, ALICE_INITIAL_NATIVE_BALANCE + amount_to_buy); + + TransactionOutcome::Commit(DispatchResult::Ok(())) + }); }); } } @@ -2182,7 +2222,7 @@ mod xyk { TestNet::reset(); Hydra::execute_with(|| { //Arrange - crate_xyk_pool(HDX, 1000 * UNITS, DAI, 2000 * UNITS); + create_xyk_pool(HDX, 1000 * UNITS, DAI, 2000 * UNITS); //For populating oracle assert_ok!(Currencies::update_balance( @@ -2210,7 +2250,7 @@ mod xyk { set_relaychain_block_number(10); let dca_budget = 1100 * UNITS; - let amount_to_buy = 100 * UNITS; + let amount_to_buy = 150 * UNITS; let schedule1 = schedule_fake_with_buy_order(PoolType::XYK, HDX, DAI, amount_to_buy, dca_budget); create_schedule(ALICE, schedule1); @@ -2236,125 +2276,133 @@ mod all_pools { TestNet::reset(); Hydra::execute_with(|| { - //Arrange - //Create stableswap and populate oracle - let (pool_id, stable_asset_1, stable_asset_2) = init_stableswap().unwrap(); - - assert_ok!(Currencies::update_balance( - RuntimeOrigin::root(), - CHARLIE.into(), - stable_asset_1, - 10000 * UNITS as i128, - )); - assert_ok!(Stableswap::sell( - RuntimeOrigin::signed(CHARLIE.into()), - pool_id, - stable_asset_1, - stable_asset_2, - 1000 * UNITS, - 0, - )); - - //Create omnipool and populate oracle - init_omnipol(); - assert_ok!(Currencies::update_balance( - RuntimeOrigin::root(), - Omnipool::protocol_account(), - pool_id, - 1000000 * UNITS as i128, - )); - - assert_ok!(Omnipool::add_token( - RuntimeOrigin::root(), - pool_id, - FixedU128::from_rational(50, 100), - Permill::from_percent(100), - AccountId::from(BOB), - )); - set_zero_reward_for_referrals(pool_id); - do_trade_to_populate_oracle(DAI, HDX, UNITS); - - //Create xyk and populate oracle - crate_xyk_pool(stable_asset_1, 10000 * UNITS, DAI, 20000 * UNITS); - assert_ok!(Currencies::update_balance( - RawOrigin::Root.into(), - BOB.into(), - stable_asset_1, - 200 * UNITS as i128, - )); - assert_ok!(XYK::sell( - RuntimeOrigin::signed(BOB.into()), - stable_asset_1, - DAI, - 100 * UNITS, - 0, - false - )); + let _ = with_transaction(|| { + //Arrange + //Create stableswap and populate oracle + let (pool_id, stable_asset_1, stable_asset_2) = init_stableswap().unwrap(); + + assert_ok!(Currencies::update_balance( + RuntimeOrigin::root(), + CHARLIE.into(), + stable_asset_1, + 10000 * UNITS as i128, + )); + assert_ok!(Stableswap::sell( + RuntimeOrigin::signed(CHARLIE.into()), + pool_id, + stable_asset_1, + stable_asset_2, + 1000 * UNITS, + 0, + )); - set_relaychain_block_number(10); + //Create omnipool and populate oracle + init_omnipol(); + assert_ok!(Currencies::update_balance( + RuntimeOrigin::root(), + Omnipool::protocol_account(), + pool_id, + 1000000 * UNITS as i128, + )); - let alice_init_hdx_balance = 5000 * UNITS; - assert_ok!(Balances::force_set_balance( - RawOrigin::Root.into(), - ALICE.into(), - alice_init_hdx_balance, - )); + assert_ok!(Omnipool::add_token( + RuntimeOrigin::root(), + pool_id, + FixedU128::from_rational(50, 100), + Permill::from_percent(100), + AccountId::from(BOB), + )); + set_zero_reward_for_referrals(pool_id); + do_trade_to_populate_oracle(DAI, HDX, UNITS); + + //Create xyk and populate oracle + create_xyk_pool(stable_asset_1, 10000 * UNITS, DAI, 20000 * UNITS); + assert_ok!(Currencies::update_balance( + RawOrigin::Root.into(), + BOB.into(), + stable_asset_1, + 200 * UNITS as i128, + )); + assert_ok!(XYK::sell( + RuntimeOrigin::signed(BOB.into()), + stable_asset_1, + DAI, + 100 * UNITS, + 0, + false + )); - let trades = vec![ - Trade { - pool: PoolType::Omnipool, - asset_in: HDX, - asset_out: pool_id, - }, - Trade { - pool: PoolType::Stableswap(pool_id), - asset_in: pool_id, - asset_out: stable_asset_1, - }, - Trade { - pool: PoolType::XYK, - asset_in: stable_asset_1, - asset_out: DAI, - }, - ]; - let dca_budget = 1100 * UNITS; + set_relaychain_block_number(10); - let schedule = Schedule { - owner: AccountId::from(ALICE), - period: 3u32, - total_amount: dca_budget, - max_retries: None, - stability_threshold: None, - slippage: Some(Permill::from_percent(15)), - order: Order::Sell { - asset_in: HDX, - asset_out: DAI, - amount_in: amount_to_sell, - min_amount_out: Balance::MIN, - route: create_bounded_vec(trades), - }, - }; + let alice_init_hdx_balance = 5000 * UNITS; + assert_ok!(Balances::force_set_balance( + RawOrigin::Root.into(), + ALICE.into(), + alice_init_hdx_balance, + )); - create_schedule(ALICE, schedule); + let trades = vec![ + Trade { + pool: PoolType::Omnipool, + asset_in: HDX, + asset_out: pool_id, + }, + Trade { + pool: PoolType::Stableswap(pool_id), + asset_in: pool_id, + asset_out: stable_asset_1, + }, + Trade { + pool: PoolType::XYK, + asset_in: stable_asset_1, + asset_out: DAI, + }, + ]; + let dca_budget = 1100 * UNITS; + + let schedule = Schedule { + owner: AccountId::from(ALICE), + period: 3u32, + total_amount: dca_budget, + max_retries: None, + stability_threshold: None, + slippage: Some(Permill::from_percent(15)), + order: Order::Sell { + asset_in: HDX, + asset_out: DAI, + amount_in: amount_to_sell, + min_amount_out: Balance::MIN, + route: create_bounded_vec(trades), + }, + }; + + create_schedule(ALICE, schedule); + + assert_balance!(ALICE.into(), HDX, alice_init_hdx_balance - dca_budget); + assert_balance!(ALICE.into(), DAI, ALICE_INITIAL_DAI_BALANCE); + assert_reserved_balance!(&ALICE.into(), HDX, dca_budget); + assert_balance!( + &Treasury::account_id(), + HDX, + TREASURY_ACCOUNT_INIT_BALANCE + InsufficientEDinHDX::get() + ); - assert_balance!(ALICE.into(), HDX, alice_init_hdx_balance - dca_budget); - assert_balance!(ALICE.into(), DAI, ALICE_INITIAL_DAI_BALANCE); - assert_reserved_balance!(&ALICE.into(), HDX, dca_budget); - assert_balance!(&Treasury::account_id(), HDX, TREASURY_ACCOUNT_INIT_BALANCE); + //Act + set_relaychain_block_number(11); - //Act - set_relaychain_block_number(11); + //Assert + let amount_to_receive = 380211607465242; - //Assert - let amount_to_receive = 380211607465242; + assert_balance!(ALICE.into(), HDX, alice_init_hdx_balance - dca_budget); + assert_balance!(ALICE.into(), DAI, ALICE_INITIAL_DAI_BALANCE + amount_to_receive); - assert_balance!(ALICE.into(), HDX, alice_init_hdx_balance - dca_budget); - assert_balance!(ALICE.into(), DAI, ALICE_INITIAL_DAI_BALANCE + amount_to_receive); + TransactionOutcome::Commit(DispatchResult::Ok(())) + }); }); } } -fn crate_xyk_pool(asset_a: AssetId, amount_a: Balance, asset_b: AssetId, amount_b: Balance) { +fn create_xyk_pool(asset_a: AssetId, amount_a: Balance, asset_b: AssetId, amount_b: Balance) { //Arrange assert_ok!(Currencies::update_balance( RawOrigin::Root.into(), @@ -2377,119 +2425,124 @@ fn crate_xyk_pool(asset_a: AssetId, amount_a: Balance, asset_b: AssetId, amount_ asset_b, amount_b, )); -} - -mod with_onchain_route { - use super::*; - use hydradx_traits::router::PoolType; - - #[test] - fn buy_should_work_with_omnipool_and_stable_with_onchain_routes() { - let amount_to_buy = 200 * UNITS; - //With DCA - TestNet::reset(); - Hydra::execute_with(|| { - //Arrange - let (pool_id, stable_asset_1, stable_asset_2) = init_stableswap().unwrap(); - - //To populate stableswap oracle - assert_ok!(Currencies::update_balance( - RuntimeOrigin::root(), - CHARLIE.into(), - stable_asset_1, - 10000 * UNITS as i128, - )); - assert_ok!(Stableswap::sell( - RuntimeOrigin::signed(CHARLIE.into()), - pool_id, - stable_asset_1, - stable_asset_2, - 3000 * UNITS, - 0, - )); - - init_omnipol(); - assert_ok!(Currencies::update_balance( - RuntimeOrigin::root(), - Omnipool::protocol_account(), - pool_id, - 300_000_000 * UNITS as i128, - )); - - assert_ok!(Omnipool::add_token( - RuntimeOrigin::root(), - pool_id, - FixedU128::from_rational(50, 100), - Permill::from_percent(100), - AccountId::from(BOB), - )); - set_zero_reward_for_referrals(pool_id); - do_trade_to_populate_oracle(DAI, HDX, UNITS); +} - set_relaychain_block_number(10); +mod with_onchain_route { + use super::*; + use frame_support::pallet_prelude::DispatchResult; + use hydradx_traits::router::PoolType; - let alice_init_hdx_balance = 5000 * UNITS; - assert_ok!(Balances::force_set_balance( - RawOrigin::Root.into(), - ALICE.into(), - alice_init_hdx_balance, - )); + #[test] + fn buy_should_work_with_omnipool_and_stable_with_onchain_routes() { + let amount_to_buy = 200 * UNITS; + //With DCA + TestNet::reset(); + Hydra::execute_with(|| { + let _ = with_transaction(|| { + //Arrange + let (pool_id, stable_asset_1, stable_asset_2) = init_stableswap().unwrap(); + + //To populate stableswap oracle + assert_ok!(Currencies::update_balance( + RuntimeOrigin::root(), + CHARLIE.into(), + stable_asset_1, + 10000 * UNITS as i128, + )); + assert_ok!(Stableswap::sell( + RuntimeOrigin::signed(CHARLIE.into()), + pool_id, + stable_asset_1, + stable_asset_2, + 3000 * UNITS, + 0, + )); - let trades = vec![ - Trade { - pool: PoolType::Omnipool, - asset_in: HDX, - asset_out: pool_id, - }, - Trade { - pool: PoolType::Stableswap(pool_id), - asset_in: pool_id, - asset_out: stable_asset_1, - }, - ]; + init_omnipol(); + assert_ok!(Currencies::update_balance( + RuntimeOrigin::root(), + Omnipool::protocol_account(), + pool_id, + 300_000_000 * UNITS as i128, + )); - let asset_pair = AssetPair::new(HDX, stable_asset_1); - assert_ok!(Router::set_route( - hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), - asset_pair, - trades.clone() - )); - assert_eq!(Router::route(asset_pair).unwrap(), trades); + assert_ok!(Omnipool::add_token( + RuntimeOrigin::root(), + pool_id, + FixedU128::from_rational(50, 100), + Permill::from_percent(100), + AccountId::from(BOB), + )); + set_zero_reward_for_referrals(pool_id); + do_trade_to_populate_oracle(DAI, HDX, UNITS); - let dca_budget = 1100 * UNITS; + set_relaychain_block_number(10); - let schedule = Schedule { - owner: AccountId::from(ALICE), - period: 3u32, - total_amount: dca_budget, - max_retries: None, - stability_threshold: None, - slippage: Some(Permill::from_percent(10)), - order: Order::Buy { - asset_in: HDX, - asset_out: stable_asset_1, - amount_out: amount_to_buy, - max_amount_in: Balance::MAX, - route: create_bounded_vec(vec![]), - }, - }; + let alice_init_hdx_balance = 5000 * UNITS; + assert_ok!(Balances::force_set_balance( + RawOrigin::Root.into(), + ALICE.into(), + alice_init_hdx_balance, + )); - create_schedule(ALICE, schedule); + let trades = vec![ + Trade { + pool: PoolType::Omnipool, + asset_in: HDX, + asset_out: pool_id, + }, + Trade { + pool: PoolType::Stableswap(pool_id), + asset_in: pool_id, + asset_out: stable_asset_1, + }, + ]; + + let asset_pair = AssetPair::new(HDX, stable_asset_1); + assert_ok!(Router::set_route( + hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), + asset_pair, + trades.clone() + )); + assert_eq!(Router::route(asset_pair).unwrap(), trades); + + let dca_budget = 1100 * UNITS; + + let schedule = Schedule { + owner: AccountId::from(ALICE), + period: 3u32, + total_amount: dca_budget, + max_retries: None, + stability_threshold: None, + slippage: Some(Permill::from_percent(10)), + order: Order::Buy { + asset_in: HDX, + asset_out: stable_asset_1, + amount_out: amount_to_buy, + max_amount_in: Balance::MAX, + route: create_bounded_vec(vec![]), + }, + }; - assert_balance!(ALICE.into(), HDX, alice_init_hdx_balance - dca_budget); - assert_balance!(ALICE.into(), stable_asset_1, 0); - assert_reserved_balance!(&ALICE.into(), HDX, dca_budget); - assert_balance!(&Treasury::account_id(), HDX, TREASURY_ACCOUNT_INIT_BALANCE); + create_schedule(ALICE, schedule); - //Act - set_relaychain_block_number(11); + assert_balance!(ALICE.into(), HDX, alice_init_hdx_balance - dca_budget); + assert_balance!(ALICE.into(), stable_asset_1, 0); + assert_reserved_balance!(&ALICE.into(), HDX, dca_budget); + assert_balance!(&Treasury::account_id(), HDX, TREASURY_ACCOUNT_INIT_BALANCE); - //Assert - assert_balance!(ALICE.into(), HDX, alice_init_hdx_balance - dca_budget); - assert_balance!(ALICE.into(), stable_asset_1, amount_to_buy); + //Act + set_relaychain_block_number(11); + + //Assert + assert_balance!(ALICE.into(), HDX, alice_init_hdx_balance - dca_budget); + assert_balance!(ALICE.into(), stable_asset_1, amount_to_buy); - assert_balance!(Router::router_account(), HDX, 0); - assert_balance!(Router::router_account(), stable_asset_1, 0); + assert_balance!(Router::router_account(), HDX, 0); + assert_balance!(Router::router_account(), stable_asset_1, 0); + + TransactionOutcome::Commit(DispatchResult::Ok(())) + }); }); } @@ -2500,109 +2553,113 @@ mod with_onchain_route { TestNet::reset(); Hydra::execute_with(|| { - //Arrange - let (pool_id, stable_asset_1, stable_asset_2) = init_stableswap().unwrap(); - - assert_ok!(Currencies::update_balance( - RuntimeOrigin::root(), - CHARLIE.into(), - stable_asset_1, - 10000 * UNITS as i128, - )); - assert_ok!(Stableswap::sell( - RuntimeOrigin::signed(CHARLIE.into()), - pool_id, - stable_asset_1, - stable_asset_2, - 10000 * UNITS, - 0, - )); - - init_omnipol(); - assert_ok!(Currencies::update_balance( - RuntimeOrigin::root(), - Omnipool::protocol_account(), - pool_id, - 300_000_000 * UNITS as i128, - )); - - assert_ok!(Omnipool::add_token( - RuntimeOrigin::root(), - pool_id, - FixedU128::from_rational(50, 100), - Permill::from_percent(100), - AccountId::from(BOB), - )); - set_zero_reward_for_referrals(pool_id); - do_trade_to_populate_oracle(DAI, HDX, UNITS); - - set_relaychain_block_number(10); - - let alice_init_hdx_balance = 5000 * UNITS; - assert_ok!(Balances::force_set_balance( - RawOrigin::Root.into(), - ALICE.into(), - alice_init_hdx_balance, - )); - - let trades = vec![ - Trade { - pool: PoolType::Omnipool, - asset_in: HDX, - asset_out: pool_id, - }, - Trade { - pool: PoolType::Stableswap(pool_id), - asset_in: pool_id, - asset_out: stable_asset_1, - }, - ]; - - let asset_pair = AssetPair::new(HDX, stable_asset_1); - assert_ok!(Router::set_route( - hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), - asset_pair, - trades.clone() - )); - assert_eq!(Router::route(asset_pair).unwrap(), trades); - - let dca_budget = 1100 * UNITS; + let _ = with_transaction(|| { + //Arrange + let (pool_id, stable_asset_1, stable_asset_2) = init_stableswap().unwrap(); - let schedule = Schedule { - owner: AccountId::from(ALICE), - period: 3u32, - total_amount: dca_budget, - max_retries: None, - stability_threshold: None, - slippage: Some(Permill::from_percent(10)), - order: Order::Sell { - asset_in: HDX, - asset_out: stable_asset_1, - amount_in: amount_to_sell, - min_amount_out: Balance::MIN, - route: create_bounded_vec(vec![]), - }, - }; + assert_ok!(Currencies::update_balance( + RuntimeOrigin::root(), + CHARLIE.into(), + stable_asset_1, + 10000 * UNITS as i128, + )); + assert_ok!(Stableswap::sell( + RuntimeOrigin::signed(CHARLIE.into()), + pool_id, + stable_asset_1, + stable_asset_2, + 10000 * UNITS, + 0, + )); - create_schedule(ALICE, schedule); + init_omnipol(); + assert_ok!(Currencies::update_balance( + RuntimeOrigin::root(), + Omnipool::protocol_account(), + pool_id, + 300_000_000 * UNITS as i128, + )); - assert_balance!(ALICE.into(), HDX, alice_init_hdx_balance - dca_budget); - assert_balance!(ALICE.into(), stable_asset_1, 0); - assert_reserved_balance!(&ALICE.into(), HDX, dca_budget); - assert_balance!(&Treasury::account_id(), HDX, TREASURY_ACCOUNT_INIT_BALANCE); + assert_ok!(Omnipool::add_token( + RuntimeOrigin::root(), + pool_id, + FixedU128::from_rational(50, 100), + Permill::from_percent(100), + AccountId::from(BOB), + )); + set_zero_reward_for_referrals(pool_id); + do_trade_to_populate_oracle(DAI, HDX, UNITS); - //Act - set_relaychain_block_number(11); + set_relaychain_block_number(10); - //Assert - let fee = Currencies::free_balance(HDX, &Treasury::account_id()) - TREASURY_ACCOUNT_INIT_BALANCE; - assert!(fee > 0, "The treasury did not receive the fee"); - assert_balance!(ALICE.into(), HDX, alice_init_hdx_balance - dca_budget); - assert_balance!(ALICE.into(), stable_asset_1, amount_to_receive); - assert_reserved_balance!(&ALICE.into(), HDX, dca_budget - amount_to_sell - fee); + let alice_init_hdx_balance = 5000 * UNITS; + assert_ok!(Balances::force_set_balance( + RawOrigin::Root.into(), + ALICE.into(), + alice_init_hdx_balance, + )); - assert_balance!(Router::router_account(), HDX, 0); - assert_balance!(Router::router_account(), stable_asset_1, 0); + let trades = vec![ + Trade { + pool: PoolType::Omnipool, + asset_in: HDX, + asset_out: pool_id, + }, + Trade { + pool: PoolType::Stableswap(pool_id), + asset_in: pool_id, + asset_out: stable_asset_1, + }, + ]; + + let asset_pair = AssetPair::new(HDX, stable_asset_1); + assert_ok!(Router::set_route( + hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), + asset_pair, + trades.clone() + )); + assert_eq!(Router::route(asset_pair).unwrap(), trades); + + let dca_budget = 1100 * UNITS; + + let schedule = Schedule { + owner: AccountId::from(ALICE), + period: 3u32, + total_amount: dca_budget, + max_retries: None, + stability_threshold: None, + slippage: Some(Permill::from_percent(10)), + order: Order::Sell { + asset_in: HDX, + asset_out: stable_asset_1, + amount_in: amount_to_sell, + min_amount_out: Balance::MIN, + route: create_bounded_vec(vec![]), + }, + }; + + create_schedule(ALICE, schedule); + + assert_balance!(ALICE.into(), HDX, alice_init_hdx_balance - dca_budget); + assert_balance!(ALICE.into(), stable_asset_1, 0); + assert_reserved_balance!(&ALICE.into(), HDX, dca_budget); + assert_balance!(&Treasury::account_id(), HDX, TREASURY_ACCOUNT_INIT_BALANCE); + + //Act + set_relaychain_block_number(11); + + //Assert + let fee = Currencies::free_balance(HDX, &Treasury::account_id()) - TREASURY_ACCOUNT_INIT_BALANCE; + assert!(fee > 0, "The treasury did not receive the fee"); + assert_balance!(ALICE.into(), HDX, alice_init_hdx_balance - dca_budget); + assert_balance!(ALICE.into(), stable_asset_1, amount_to_receive); + assert_reserved_balance!(&ALICE.into(), HDX, dca_budget - amount_to_sell - fee); + + assert_balance!(Router::router_account(), HDX, 0); + assert_balance!(Router::router_account(), stable_asset_1, 0); + + TransactionOutcome::Commit(DispatchResult::Ok(())) + }); }); } @@ -2713,137 +2770,140 @@ mod with_onchain_route { TestNet::reset(); Hydra::execute_with(|| { - //Arrange - let (pool_id, stable_asset_1, stable_asset_2) = init_stableswap().unwrap(); - - assert_ok!(hydradx_runtime::MultiTransactionPayment::add_currency( - hydradx_runtime::RuntimeOrigin::root(), - stable_asset_1, - FixedU128::from_rational(50, 100), - )); - - assert_ok!(Currencies::update_balance( - RuntimeOrigin::root(), - CHARLIE.into(), - stable_asset_1, - 10000 * UNITS as i128, - )); - assert_ok!(Stableswap::sell( - RuntimeOrigin::signed(CHARLIE.into()), - pool_id, - stable_asset_1, - stable_asset_2, - 10000 * UNITS, - 0, - )); - - init_omnipol(); - assert_ok!(Currencies::update_balance( - RuntimeOrigin::root(), - Omnipool::protocol_account(), - pool_id, - 300_000_000 * UNITS as i128, - )); - - assert_ok!(Omnipool::add_token( - RuntimeOrigin::root(), - pool_id, - FixedU128::from_rational(50, 100), - Permill::from_percent(100), - AccountId::from(BOB), - )); - set_zero_reward_for_referrals(pool_id); - do_trade_to_populate_oracle(pool_id, HDX, 10000000 * UNITS); - - set_relaychain_block_number(10); - - let alice_init_hdx_balance = 5000 * UNITS; - assert_ok!(Balances::force_set_balance( - RawOrigin::Root.into(), - ALICE.into(), - alice_init_hdx_balance, - )); - - let alice_init_stable_balance = 5000 * UNITS; - assert_ok!(Currencies::update_balance( - RuntimeOrigin::root(), - ALICE.into(), - stable_asset_1, - alice_init_stable_balance as i128, - )); + let _ = with_transaction(|| { + //Arrange + let (pool_id, stable_asset_1, stable_asset_2) = init_stableswap().unwrap(); - let trades = vec![ - Trade { - pool: PoolType::Omnipool, - asset_in: HDX, - asset_out: pool_id, - }, - Trade { - pool: PoolType::Stableswap(pool_id), - asset_in: pool_id, - asset_out: stable_asset_1, - }, - ]; - - let asset_pair = AssetPair::new(HDX, stable_asset_1); - assert_ok!(Router::set_route( - hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), - asset_pair, - trades.clone() - )); - assert_eq!(Router::route(asset_pair).unwrap(), trades); - - let dca_budget = 1100 * UNITS; - - let schedule = Schedule { - owner: AccountId::from(ALICE), - period: 3u32, - total_amount: dca_budget, - max_retries: None, - stability_threshold: None, - slippage: Some(Permill::from_percent(10)), - order: Order::Sell { - asset_in: stable_asset_1, - asset_out: HDX, - amount_in: amount_to_sell, - min_amount_out: Balance::MIN, - route: create_bounded_vec(vec![]), - }, - }; + assert_ok!(hydradx_runtime::MultiTransactionPayment::add_currency( + hydradx_runtime::RuntimeOrigin::root(), + stable_asset_1, + FixedU128::from_rational(50, 100), + )); - //We verify the price diff between hdx and stable asset. - //If we sell 6503744780645, we receive 5385180382312 - //So fee should be like 0.8x normal HDX fee - let _stable_amount = with_transaction::<_, _, _>(|| { - let amount_to_sell = 6503744780645; - assert_ok!(Router::sell( - hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), - HDX, + assert_ok!(Currencies::update_balance( + RuntimeOrigin::root(), + CHARLIE.into(), stable_asset_1, - amount_to_sell, + 10000 * UNITS as i128, + )); + assert_ok!(Stableswap::sell( + RuntimeOrigin::signed(CHARLIE.into()), + pool_id, + stable_asset_1, + stable_asset_2, + 10000 * UNITS, 0, - vec![] )); - let alice_received_stable = - Currencies::free_balance(stable_asset_1, &AccountId::from(ALICE)) - alice_init_stable_balance; - TransactionOutcome::Rollback(Ok::(alice_received_stable)) - }) - .unwrap(); + init_omnipol(); + assert_ok!(Currencies::update_balance( + RuntimeOrigin::root(), + Omnipool::protocol_account(), + pool_id, + 300_000_000 * UNITS as i128, + )); - create_schedule(ALICE, schedule); + assert_ok!(Omnipool::add_token( + RuntimeOrigin::root(), + pool_id, + FixedU128::from_rational(50, 100), + Permill::from_percent(100), + AccountId::from(BOB), + )); + set_zero_reward_for_referrals(pool_id); + do_trade_to_populate_oracle(pool_id, HDX, 10000000 * UNITS); - //Act - set_relaychain_block_number(11); + set_relaychain_block_number(10); - //Assert - let fee = Currencies::free_balance(stable_asset_1, &Treasury::account_id()); - assert!(fee > 0, "The treasury did not receive the fee"); + let alice_init_hdx_balance = 5000 * UNITS; + assert_ok!(Balances::force_set_balance( + RawOrigin::Root.into(), + ALICE.into(), + alice_init_hdx_balance, + )); - assert_balance!(ALICE.into(), stable_asset_1, alice_init_stable_balance - dca_budget); - assert!(Currencies::free_balance(HDX, &ALICE.into()) > alice_init_hdx_balance); + let alice_init_stable_balance = 5000 * UNITS; + assert_ok!(Currencies::update_balance( + RuntimeOrigin::root(), + ALICE.into(), + stable_asset_1, + alice_init_stable_balance as i128, + )); - assert_reserved_balance!(&ALICE.into(), stable_asset_1, dca_budget - amount_to_sell - fee); + let trades = vec![ + Trade { + pool: PoolType::Omnipool, + asset_in: HDX, + asset_out: pool_id, + }, + Trade { + pool: PoolType::Stableswap(pool_id), + asset_in: pool_id, + asset_out: stable_asset_1, + }, + ]; + + let asset_pair = AssetPair::new(HDX, stable_asset_1); + assert_ok!(Router::set_route( + hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), + asset_pair, + trades.clone() + )); + assert_eq!(Router::route(asset_pair).unwrap(), trades); + + let dca_budget = 1100 * UNITS; + + let schedule = Schedule { + owner: AccountId::from(ALICE), + period: 3u32, + total_amount: dca_budget, + max_retries: None, + stability_threshold: None, + slippage: Some(Permill::from_percent(10)), + order: Order::Sell { + asset_in: stable_asset_1, + asset_out: HDX, + amount_in: amount_to_sell, + min_amount_out: Balance::MIN, + route: create_bounded_vec(vec![]), + }, + }; + + //We verify the price diff between hdx and stable asset. + //If we sell 6503744780645, we receive 5385180382312 + //So fee should be like 0.8x normal HDX fee + let _stable_amount = with_transaction::<_, _, _>(|| { + let amount_to_sell = 6503744780645; + assert_ok!(Router::sell( + hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), + HDX, + stable_asset_1, + amount_to_sell, + 0, + vec![] + )); + let alice_received_stable = + Currencies::free_balance(stable_asset_1, &AccountId::from(ALICE)) - alice_init_stable_balance; + + TransactionOutcome::Rollback(Ok::(alice_received_stable)) + }) + .unwrap(); + + create_schedule(ALICE, schedule); + + //Act + set_relaychain_block_number(11); + + //Assert + let fee = Currencies::free_balance(stable_asset_1, &Treasury::account_id()); + assert!(fee > 0, "The treasury did not receive the fee"); + + assert_balance!(ALICE.into(), stable_asset_1, alice_init_stable_balance - dca_budget); + assert!(Currencies::free_balance(HDX, &ALICE.into()) > alice_init_hdx_balance); + + assert_reserved_balance!(&ALICE.into(), stable_asset_1, dca_budget - amount_to_sell - fee); + TransactionOutcome::Commit(DispatchResult::Ok(())) + }); }); } @@ -3254,9 +3314,17 @@ pub fn init_stableswap() -> Result<(AssetId, AssetId, AssetId), DispatchError> { let mut asset_ids: Vec<::AssetId> = Vec::new(); for idx in 0u32..MAX_ASSETS_IN_POOL { let name: Vec = idx.to_ne_bytes().to_vec(); - //let asset_id = regi_asset(name.clone(), 1_000_000, 10000 + idx as u32)?; - let asset_id = AssetRegistry::create_asset(&name, 1u128)?; - AssetRegistry::set_metadata(RuntimeOrigin::root(), asset_id, b"xDUM".to_vec(), 18u8)?; + let asset_id = AssetRegistry::register_sufficient_asset( + None, + Some(name.try_into().unwrap()), + AssetKind::Token, + 1u128, + Some(b"xDUM".to_vec().try_into().unwrap()), + Some(18u8), + None, + None, + )?; + asset_ids.push(asset_id); Currencies::update_balance( RuntimeOrigin::root(), @@ -3266,7 +3334,16 @@ pub fn init_stableswap() -> Result<(AssetId, AssetId, AssetId), DispatchError> { )?; initial.push(AssetAmount::new(asset_id, initial_liquidity)); } - let pool_id = AssetRegistry::create_asset(&b"pool".to_vec(), 1u128)?; + let pool_id = AssetRegistry::register_sufficient_asset( + None, + Some(b"pool".to_vec().try_into().unwrap()), + AssetKind::Token, + 1u128, + None, + None, + None, + None, + )?; let amplification = 100u16; let fee = Permill::from_percent(1); @@ -3293,13 +3370,18 @@ pub fn init_stableswap_with_three_assets_having_different_decimals( let decimals_for_each_asset = vec![12u8, 6u8, 6u8]; for idx in 0u32..3 { let name: Vec = idx.to_ne_bytes().to_vec(); - let asset_id = AssetRegistry::create_asset(&name, 1u128)?; - AssetRegistry::set_metadata( - RuntimeOrigin::root(), - asset_id, - b"xDUM".to_vec(), - decimals_for_each_asset[idx as usize], + + let asset_id = AssetRegistry::register_sufficient_asset( + None, + Some(name.try_into().unwrap()), + AssetKind::Token, + 1u128, + Some(b"xDUM".to_vec().try_into().unwrap()), + Some(decimals_for_each_asset[idx as usize]), + None, + None, )?; + asset_ids.push(asset_id); Currencies::update_balance( RuntimeOrigin::root(), @@ -3316,7 +3398,16 @@ pub fn init_stableswap_with_three_assets_having_different_decimals( initial.push(AssetAmount::new(asset_id, initial_liquidity)); added_liquidity.push(AssetAmount::new(asset_id, liquidity_added)); } - let pool_id = AssetRegistry::create_asset(&b"pool".to_vec(), 1u128)?; + let pool_id = AssetRegistry::register_insufficient_asset( + None, + Some(b"pool".to_vec().try_into().unwrap()), + AssetKind::Token, + Some(1u128), + None, + None, + None, + None, + )?; let amplification = 100u16; let fee = Permill::from_percent(1); diff --git a/integration-tests/src/evm.rs b/integration-tests/src/evm.rs index 035832a79..10127bf03 100644 --- a/integration-tests/src/evm.rs +++ b/integration-tests/src/evm.rs @@ -633,7 +633,19 @@ mod currency_precompile { Hydra::execute_with(|| { //Arrange - AssetRegistry::set_metadata(hydradx_runtime::RuntimeOrigin::root(), HDX, b"xHDX".to_vec(), 12u8).unwrap(); + AssetRegistry::update( + hydradx_runtime::RuntimeOrigin::root(), + HDX, + Some(b"xHDX".to_vec().try_into().unwrap()), + None, + None, + None, + None, + Some(b"xHDX".to_vec().try_into().unwrap()), + Some(12u8), + None, + ) + .unwrap(); let data = EvmDataWriter::new_with_selector(Action::Symbol).build(); @@ -669,7 +681,19 @@ mod currency_precompile { Hydra::execute_with(|| { //Arrange - AssetRegistry::set_metadata(hydradx_runtime::RuntimeOrigin::root(), HDX, b"xHDX".to_vec(), 12u8).unwrap(); + AssetRegistry::update( + hydradx_runtime::RuntimeOrigin::root(), + HDX, + Some(b"xHDX".to_vec().try_into().unwrap()), + None, + None, + None, + None, + None, + Some(12u8), + None, + ) + .unwrap(); let data = EvmDataWriter::new_with_selector(Action::Decimals).build(); diff --git a/integration-tests/src/exchange_asset.rs b/integration-tests/src/exchange_asset.rs index 60d1bba23..96bb03cf4 100644 --- a/integration-tests/src/exchange_asset.rs +++ b/integration-tests/src/exchange_asset.rs @@ -276,48 +276,54 @@ fn transfer_and_swap_should_work_with_4_hops() { fn register_glmr() { assert_ok!(hydradx_runtime::AssetRegistry::register( hydradx_runtime::RuntimeOrigin::root(), - b"GLRM".to_vec(), - pallet_asset_registry::AssetType::Token, - 1_000_000, Some(GLMR), + Some(b"GLRM".to_vec().try_into().unwrap()), + pallet_asset_registry::AssetType::Token, + Some(1_000_000), + None, None, Some(hydradx_runtime::AssetLocation(MultiLocation::new( 1, X2(Parachain(MOONBEAM_PARA_ID), GeneralIndex(0)) ))), - None + None, + false )); } fn register_aca() { assert_ok!(hydradx_runtime::AssetRegistry::register( hydradx_runtime::RuntimeOrigin::root(), - b"ACAL".to_vec(), - pallet_asset_registry::AssetType::Token, - 1_000_000, Some(ACA), + Some(b"ACAL".to_vec().try_into().unwrap()), + pallet_asset_registry::AssetType::Token, + Some(1_000_000), + None, None, Some(hydradx_runtime::AssetLocation(MultiLocation::new( 1, X2(Parachain(ACALA_PARA_ID), GeneralIndex(0)) ))), - None + None, + false )); } fn register_ibtc() { assert_ok!(hydradx_runtime::AssetRegistry::register( hydradx_runtime::RuntimeOrigin::root(), - b"iBTC".to_vec(), - pallet_asset_registry::AssetType::Token, - 1_000_000, Some(IBTC), + Some(b"iBTC".to_vec().try_into().unwrap()), + pallet_asset_registry::AssetType::Token, + Some(1_000_000), + None, None, Some(hydradx_runtime::AssetLocation(MultiLocation::new( 1, X2(Parachain(INTERLAY_PARA_ID), GeneralIndex(0)) ))), - None + None, + false )); } diff --git a/integration-tests/src/insufficient_assets_ed.rs b/integration-tests/src/insufficient_assets_ed.rs new file mode 100644 index 000000000..8b83607b5 --- /dev/null +++ b/integration-tests/src/insufficient_assets_ed.rs @@ -0,0 +1,1455 @@ +#![cfg(test)] + +use crate::assert_event_times; +use crate::insufficient_assets_ed::v3::Junction::GeneralIndex; +use crate::polkadot_test_net::*; +use frame_support::{assert_noop, assert_ok, traits::Contains}; +use frame_system::RawOrigin; +use hydradx_runtime::RuntimeOrigin as hydra_origin; +use hydradx_runtime::{ + AssetRegistry as Registry, Currencies, DustRemovalWhitelist, InsufficientEDinHDX, MultiTransactionPayment, + NativeExistentialDeposit, RuntimeEvent, TechnicalCollective, Tokens, TreasuryAccount, SUFFICIENCY_LOCK, +}; +use hydradx_traits::NativePriceOracle; +use orml_traits::MultiCurrency; +use polkadot_xcm::v3::{self, Junction::Parachain, Junctions::X2, MultiLocation}; +use sp_runtime::FixedPointNumber; +use xcm_emulator::TestExt; + +#[test] +fn sender_should_pay_ed_in_hdx_when_it_is_not_whitelisted() { + TestNet::reset(); + Hydra::execute_with(|| { + let sht1: AssetId = register_external_asset(0_u128); + assert_ok!(Tokens::set_balance( + RawOrigin::Root.into(), + BOB.into(), + sht1, + 100_000_000 * UNITS, + 0, + )); + + let alice_balance = Currencies::free_balance(HDX, &ALICE.into()); + let bob_balance = Currencies::free_balance(HDX, &BOB.into()); + let treasury_balance = Currencies::free_balance(HDX, &TreasuryAccount::get()); + + assert_eq!(Currencies::free_balance(sht1, &ALICE.into()), 0); + assert_eq!(treasury_sufficiency_lock(), 0); + + //Act + assert_ok!(Tokens::transfer( + hydra_origin::signed(BOB.into()), + ALICE.into(), + sht1, + 1_000_000 * UNITS + )); + + //Assert + assert_eq!(Currencies::free_balance(HDX, &ALICE.into()), alice_balance); + assert_eq!(Currencies::free_balance(sht1, &ALICE.into()), 1_000_000 * UNITS); + + assert_eq!( + Currencies::free_balance(HDX, &BOB.into()), + bob_balance - InsufficientEDinHDX::get() + ); + + assert_eq!( + Currencies::free_balance(HDX, &TreasuryAccount::get()), + treasury_balance + InsufficientEDinHDX::get() + ); + assert_eq!(treasury_sufficiency_lock(), NativeExistentialDeposit::get()); + + assert_eq!( + pallet_asset_registry::pallet::ExistentialDepositCounter::::get(), + 1_u128 + ); + + assert_event_times!( + RuntimeEvent::AssetRegistry(pallet_asset_registry::Event::ExistentialDepositPaid { + who: BOB.into(), + fee_asset: HDX, + amount: InsufficientEDinHDX::get() + }), + 1 + ); + }); +} + +#[test] +fn reciever_should_pay_ed_in_hdx_when_insuficcient_asset_was_deposited() { + TestNet::reset(); + Hydra::execute_with(|| { + let sht1: AssetId = register_external_asset(0_u128); + assert_ok!(Tokens::set_balance( + RawOrigin::Root.into(), + BOB.into(), + sht1, + 100_000_000 * UNITS, + 0, + )); + + let alice_balance = Currencies::free_balance(HDX, &ALICE.into()); + let treasury_balance = Currencies::free_balance(HDX, &TreasuryAccount::get()); + + assert_eq!(Currencies::free_balance(sht1, &ALICE.into()), 0); + assert_eq!(treasury_sufficiency_lock(), 0); + + //Act + assert_ok!(Tokens::deposit(sht1, &ALICE.into(), 1_000_000 * UNITS)); + + //Assert + assert_eq!( + Currencies::free_balance(HDX, &ALICE.into()), + alice_balance - InsufficientEDinHDX::get() + ); + assert_eq!(Currencies::free_balance(sht1, &ALICE.into()), 1_000_000 * UNITS); + + assert_eq!( + Currencies::free_balance(HDX, &TreasuryAccount::get()), + treasury_balance + InsufficientEDinHDX::get() + ); + + assert_eq!(treasury_sufficiency_lock(), NativeExistentialDeposit::get()); + + assert_eq!( + pallet_asset_registry::pallet::ExistentialDepositCounter::::get(), + 1_u128 + ); + + assert_event_times!( + RuntimeEvent::AssetRegistry(pallet_asset_registry::Event::ExistentialDepositPaid { + who: ALICE.into(), + fee_asset: HDX, + amount: InsufficientEDinHDX::get() + }), + 1 + ); + }); +} + +#[test] +fn hdx_ed_should_be_released_when_account_is_killed_and_ed_was_paid_in_hdx() { + TestNet::reset(); + Hydra::execute_with(|| { + let sht1: AssetId = register_external_asset(0_u128); + assert_ok!(Tokens::set_balance( + RawOrigin::Root.into(), + BOB.into(), + sht1, + 100_000_000 * UNITS, + 0, + )); + + assert_ok!(Tokens::deposit(sht1, &ALICE.into(), 1_000_000 * UNITS)); + + let alice_balance = Currencies::free_balance(HDX, &ALICE.into()); + let treasury_balance = Currencies::free_balance(HDX, &TreasuryAccount::get()); + + assert_eq!(treasury_sufficiency_lock(), NativeExistentialDeposit::get()); + + //Act + assert_ok!(Tokens::transfer( + hydra_origin::signed(ALICE.into()), + BOB.into(), + sht1, + 1_000_000 * UNITS + )); + + //Assert + assert_eq!( + Currencies::free_balance(HDX, &ALICE.into()), + alice_balance + NativeExistentialDeposit::get() + ); + assert_eq!(Currencies::free_balance(sht1, &ALICE.into()), 0); + + assert_eq!( + Currencies::free_balance(HDX, &TreasuryAccount::get()), + treasury_balance - NativeExistentialDeposit::get() + ); + + assert_eq!(treasury_sufficiency_lock(), 0); + + assert_eq!( + pallet_asset_registry::pallet::ExistentialDepositCounter::::get(), + 0_u128 + ); + + assert_event_times!( + RuntimeEvent::AssetRegistry(pallet_asset_registry::Event::ExistentialDepositPaid { + who: ALICE.into(), + fee_asset: HDX, + amount: InsufficientEDinHDX::get() + }), + 1 + ); + }); +} + +#[test] +fn sender_should_pay_ed_only_when_dest_didnt_pay_yet() { + TestNet::reset(); + Hydra::execute_with(|| { + let sht1: AssetId = register_external_asset(0_u128); + let fee_asset = BTC; + + assert_ok!(Tokens::set_balance( + RawOrigin::Root.into(), + BOB.into(), + sht1, + 100_000_000 * UNITS, + 0, + )); + + assert_ok!(Tokens::set_balance( + RawOrigin::Root.into(), + BOB.into(), + fee_asset, + 1_000_000, + 0, + )); + + assert_ok!(MultiTransactionPayment::set_currency( + hydra_origin::signed(BOB.into()), + fee_asset + )); + + assert_ok!(Tokens::transfer( + hydra_origin::signed(BOB.into()), + ALICE.into(), + sht1, + 1_000_000 * UNITS + )); + + let bob_fee_asset_balance = Currencies::free_balance(fee_asset, &BOB.into()); + let alice_hdx_balance = Currencies::free_balance(HDX, &ALICE.into()); + let treasury_hdx_balance = Currencies::free_balance(HDX, &TreasuryAccount::get()); + let treasury_fee_asset_balance = Currencies::free_balance(fee_asset, &TreasuryAccount::get()); + + //Act + assert_ok!(Tokens::transfer( + hydra_origin::signed(BOB.into()), + ALICE.into(), + sht1, + 1_000_000 * UNITS + )); + + //Assert + assert_eq!(Currencies::free_balance(HDX, &ALICE.into()), alice_hdx_balance); + assert_eq!(Currencies::free_balance(sht1, &ALICE.into()), 2_000_000 * UNITS); + assert_eq!(Currencies::free_balance(fee_asset, &BOB.into()), bob_fee_asset_balance); + + assert_eq!( + Currencies::free_balance(HDX, &TreasuryAccount::get()), + treasury_hdx_balance + ); + assert_eq!( + Currencies::free_balance(fee_asset, &TreasuryAccount::get()), + treasury_fee_asset_balance + ); + + let ed_in_hdx: Balance = MultiTransactionPayment::price(fee_asset) + .unwrap() + .saturating_mul_int(InsufficientEDinHDX::get()); + + assert_eq!(treasury_sufficiency_lock(), NativeExistentialDeposit::get()); + + assert_eq!( + pallet_asset_registry::pallet::ExistentialDepositCounter::::get(), + 1_u128 + ); + + assert_event_times!( + RuntimeEvent::AssetRegistry(pallet_asset_registry::Event::ExistentialDepositPaid { + who: BOB.into(), + fee_asset, + amount: ed_in_hdx + }), + 1 + ); + }); +} + +#[test] +fn dest_should_pay_ed_only_once_when_insufficient_asset_was_depsitted() { + TestNet::reset(); + Hydra::execute_with(|| { + let sht1: AssetId = register_external_asset(0_u128); + let fee_asset = BTC; + + assert_ok!(Tokens::set_balance( + RawOrigin::Root.into(), + ALICE.into(), + fee_asset, + 1_000_000, + 0, + )); + + assert_ok!(MultiTransactionPayment::set_currency( + hydra_origin::signed(ALICE.into()), + fee_asset + )); + + assert_ok!(Tokens::deposit(sht1, &ALICE.into(), 1_000 * UNITS)); + + let alice_fee_asset_balance = Currencies::free_balance(fee_asset, &ALICE.into()); + let alice_hdx_balance = Currencies::free_balance(HDX, &ALICE.into()); + let treasury_hdx_balance = Currencies::free_balance(HDX, &TreasuryAccount::get()); + let treasury_fee_asset_balance = Currencies::free_balance(fee_asset, &TreasuryAccount::get()); + + //Act + assert_ok!(Tokens::deposit(sht1, &ALICE.into(), 1_000 * UNITS)); + + //Assert + assert_eq!(Currencies::free_balance(HDX, &ALICE.into()), alice_hdx_balance); + assert_eq!(Currencies::free_balance(sht1, &ALICE.into()), 2_000 * UNITS); + assert_eq!( + Currencies::free_balance(fee_asset, &ALICE.into()), + alice_fee_asset_balance + ); + + assert_eq!( + Currencies::free_balance(HDX, &TreasuryAccount::get()), + treasury_hdx_balance + ); + assert_eq!( + Currencies::free_balance(fee_asset, &TreasuryAccount::get()), + treasury_fee_asset_balance + ); + let ed_in_fee_asset: Balance = MultiTransactionPayment::price(fee_asset) + .unwrap() + .saturating_mul_int(InsufficientEDinHDX::get()); + + assert_eq!(treasury_sufficiency_lock(), NativeExistentialDeposit::get()); + + assert_eq!( + pallet_asset_registry::pallet::ExistentialDepositCounter::::get(), + 1_u128 + ); + + assert_event_times!( + RuntimeEvent::AssetRegistry(pallet_asset_registry::Event::ExistentialDepositPaid { + who: ALICE.into(), + fee_asset, + amount: ed_in_fee_asset + }), + 1 + ); + }); +} + +#[test] +fn hdx_ed_should_be_released_when_account_is_killed_and_ed_was_paid_in_fee_asset() { + TestNet::reset(); + Hydra::execute_with(|| { + let sht1: AssetId = register_external_asset(0_u128); + let fee_asset = BTC; + + //NOTE: this is important for this tests - it basically mean that Bob already paid ED. + assert_ok!(Tokens::set_balance( + RawOrigin::Root.into(), + BOB.into(), + sht1, + 100_000_000 * UNITS, + 0, + )); + + assert_ok!(Tokens::set_balance( + RawOrigin::Root.into(), + ALICE.into(), + fee_asset, + 1_000_000, + 0, + )); + + assert_ok!(Tokens::deposit(sht1, &ALICE.into(), 1_000_000 * UNITS)); + assert_ok!(MultiTransactionPayment::set_currency( + hydra_origin::signed(ALICE.into()), + fee_asset + )); + + let alice_fee_asset_balance = Currencies::free_balance(fee_asset, &ALICE.into()); + let alice_hdx_balance = Currencies::free_balance(HDX, &ALICE.into()); + let treasury_hdx_balance = Currencies::free_balance(HDX, &TreasuryAccount::get()); + let treasury_fee_asset_balance = Currencies::free_balance(fee_asset, &TreasuryAccount::get()); + + assert_eq!(treasury_sufficiency_lock(), NativeExistentialDeposit::get()); + + //Act + assert_ok!(Tokens::transfer( + hydra_origin::signed(ALICE.into()), + BOB.into(), + sht1, + 1_000_000 * UNITS + )); + + //Assert + //NOTE: we always returns ED in HDX + assert_eq!( + Currencies::free_balance(HDX, &ALICE.into()), + alice_hdx_balance + NativeExistentialDeposit::get() + ); + assert_eq!(Currencies::free_balance(sht1, &ALICE.into()), 0); + assert_eq!( + Currencies::free_balance(fee_asset, &ALICE.into()), + alice_fee_asset_balance + ); + + assert_eq!( + Currencies::free_balance(HDX, &TreasuryAccount::get()), + treasury_hdx_balance - NativeExistentialDeposit::get() + ); + assert_eq!( + Currencies::free_balance(fee_asset, &TreasuryAccount::get()), + treasury_fee_asset_balance + ); + + assert_eq!(treasury_sufficiency_lock(), 0); + + assert_eq!( + pallet_asset_registry::pallet::ExistentialDepositCounter::::get(), + 0_u128 + ); + + //NOTE: this is colected amount, not locked amount. + assert_event_times!( + RuntimeEvent::AssetRegistry(pallet_asset_registry::Event::ExistentialDepositPaid { + who: ALICE.into(), + fee_asset: HDX, + amount: InsufficientEDinHDX::get() + }), + 1 + ); + }); +} + +#[test] +fn tx_should_fail_with_existential_deposit_err_when_dest_account_cant_pay_ed() { + TestNet::reset(); + Hydra::execute_with(|| { + let sht1: AssetId = register_external_asset(0_u128); + let fee_asset = BTC; + + assert_ok!(MultiTransactionPayment::set_currency( + hydra_origin::signed(ALICE.into()), + fee_asset + )); + + let ed_in_hdx: Balance = MultiTransactionPayment::price(fee_asset) + .unwrap() + .saturating_mul_int(InsufficientEDinHDX::get()); + assert!(Tokens::free_balance(fee_asset, &ALICE.into()) < ed_in_hdx); + + assert_noop!( + Tokens::deposit(sht1, &ALICE.into(), 1_000_000 * UNITS), + orml_tokens::Error::::ExistentialDeposit + ); + }); +} + +#[test] +fn sender_should_pay_ed_in_fee_asset_when_sending_insufficient_asset() { + TestNet::reset(); + Hydra::execute_with(|| { + let sht1: AssetId = register_external_asset(0_u128); + let fee_asset = BTC; + + assert_ok!(Tokens::set_balance( + RawOrigin::Root.into(), + BOB.into(), + sht1, + 100_000_000 * UNITS, + 0, + )); + + assert_ok!(Tokens::set_balance( + RawOrigin::Root.into(), + BOB.into(), + fee_asset, + 1_000_000, + 0, + )); + + assert_ok!(MultiTransactionPayment::set_currency( + hydra_origin::signed(BOB.into()), + fee_asset + )); + + let bob_fee_asset_balance = Currencies::free_balance(fee_asset, &BOB.into()); + let alice_hdx_balance = Currencies::free_balance(HDX, &ALICE.into()); + let treasury_hdx_balance = Currencies::free_balance(HDX, &TreasuryAccount::get()); + let treasury_fee_asset_balance = Currencies::free_balance(fee_asset, &TreasuryAccount::get()); + + assert_eq!(Currencies::free_balance(sht1, &ALICE.into()), 0); + assert_eq!(treasury_sufficiency_lock(), 0); + + //Act + assert_ok!(Tokens::transfer( + hydra_origin::signed(BOB.into()), + ALICE.into(), + sht1, + 1_000_000 * UNITS + )); + + //Assert + let ed_in_fee_asset: Balance = MultiTransactionPayment::price(fee_asset) + .unwrap() + .saturating_mul_int(InsufficientEDinHDX::get()); + assert_eq!(Currencies::free_balance(HDX, &ALICE.into()), alice_hdx_balance); + + assert_eq!( + Currencies::free_balance(sht1, &BOB.into()), + (100_000_000 - 1_000_000) * UNITS + ); + assert_eq!( + Currencies::free_balance(fee_asset, &BOB.into()), + bob_fee_asset_balance - ed_in_fee_asset + ); + + assert_eq!( + Currencies::free_balance(HDX, &TreasuryAccount::get()), + treasury_hdx_balance + ); + assert_eq!( + Currencies::free_balance(fee_asset, &TreasuryAccount::get()), + treasury_fee_asset_balance + ed_in_fee_asset + ); + + assert_eq!(treasury_sufficiency_lock(), NativeExistentialDeposit::get()); + + assert_eq!( + pallet_asset_registry::pallet::ExistentialDepositCounter::::get(), + 1_u128 + ); + + assert_event_times!( + RuntimeEvent::AssetRegistry(pallet_asset_registry::Event::ExistentialDepositPaid { + who: BOB.into(), + fee_asset, + amount: ed_in_fee_asset + }), + 1 + ); + }); +} + +#[test] +fn account_with_zero_sufficients_should_not_release_ed() { + TestNet::reset(); + Hydra::execute_with(|| { + let dummy: AssetId = 1_000_001; + + //NOTE: set balance baypass `MutationHooks` so Bob received insufficient asset without + //locking ED. + assert_ok!(Tokens::set_balance( + RawOrigin::Root.into(), + BOB.into(), + dummy, + 100_000_000 * UNITS, + 0, + )); + + assert_ok!(Tokens::deposit(dummy, &ALICE.into(), 1_000_000 * UNITS)); + assert_eq!( + pallet_asset_registry::pallet::ExistentialDepositCounter::::get(), + 1_u128 + ); + + let bob_balance = Currencies::free_balance(HDX, &BOB.into()); + let treasury_hdx_balance = Currencies::free_balance(HDX, &TreasuryAccount::get()); + + let dummy_balance = Currencies::free_balance(dummy, &BOB.into()); + //Act + assert_ok!(Tokens::transfer( + hydra_origin::signed(BOB.into()), + ALICE.into(), + dummy, + dummy_balance + )); + + //Assert + assert_eq!(Currencies::free_balance(HDX, &BOB.into()), bob_balance); + + assert_eq!( + Currencies::free_balance(HDX, &TreasuryAccount::get()), + treasury_hdx_balance + ); + + assert_eq!(treasury_sufficiency_lock(), NativeExistentialDeposit::get()); + assert_eq!( + pallet_asset_registry::pallet::ExistentialDepositCounter::::get(), + 1_u128 + ); + + assert_event_times!( + RuntimeEvent::AssetRegistry(pallet_asset_registry::Event::ExistentialDepositPaid { + who: ALICE.into(), + fee_asset: HDX, + amount: InsufficientEDinHDX::get() + }), + 1 + ); + }); +} + +#[test] +fn ed_should_not_be_collected_when_transfering_or_depositing_sufficient_assets() { + TestNet::reset(); + Hydra::execute_with(|| { + let sht1 = register_external_asset(0_u128); + let sufficient_asset = DAI; + + //This pays ED. + assert_ok!(Tokens::deposit(sht1, &BOB.into(), 100_000_000 * UNITS)); + + let alice_hdx_balance = Currencies::free_balance(HDX, &ALICE.into()); + let alice_sufficient_asset_balance = Currencies::free_balance(DAI, &ALICE.into()); + let treasury_hdx_balance = Currencies::free_balance(HDX, &TreasuryAccount::get()); + + assert_eq!(treasury_sufficiency_lock(), NativeExistentialDeposit::get()); + assert_eq!( + pallet_asset_registry::pallet::ExistentialDepositCounter::::get(), + 1_u128 + ); + + //Act 1 - transfer + assert_ok!(Tokens::transfer( + hydra_origin::signed(BOB.into()), + ALICE.into(), + sufficient_asset, + 1_000_000 * UNITS + )); + + //Assert + assert_eq!(Currencies::free_balance(HDX, &ALICE.into()), alice_hdx_balance); + assert_eq!( + Currencies::free_balance(sufficient_asset, &ALICE.into()), + alice_sufficient_asset_balance + 1_000_000 * UNITS + ); + + assert_eq!( + Currencies::free_balance(HDX, &TreasuryAccount::get()), + treasury_hdx_balance + ); + assert_eq!(treasury_sufficiency_lock(), NativeExistentialDeposit::get()); + assert_eq!( + pallet_asset_registry::pallet::ExistentialDepositCounter::::get(), + 1_u128 + ); + + //Arrange 2 + let alice_hdx_balance = Currencies::free_balance(HDX, &ALICE.into()); + let alice_sufficient_asset_balance = Currencies::free_balance(DAI, &ALICE.into()); + let treasury_hdx_balance = Currencies::free_balance(HDX, &TreasuryAccount::get()); + + //Act 2 - deposit + assert_ok!(Tokens::deposit(sufficient_asset, &ALICE.into(), 1_000_000 * UNITS)); + + //Assert + assert_eq!(Currencies::free_balance(HDX, &ALICE.into()), alice_hdx_balance); + assert_eq!( + Currencies::free_balance(sufficient_asset, &ALICE.into()), + alice_sufficient_asset_balance + 1_000_000 * UNITS + ); + + assert_eq!( + Currencies::free_balance(HDX, &TreasuryAccount::get()), + treasury_hdx_balance + ); + assert_eq!(treasury_sufficiency_lock(), NativeExistentialDeposit::get()); + assert_eq!( + pallet_asset_registry::pallet::ExistentialDepositCounter::::get(), + 1_u128 + ); + + assert_event_times!( + RuntimeEvent::AssetRegistry(pallet_asset_registry::Event::ExistentialDepositPaid { + who: BOB.into(), + fee_asset: HDX, + amount: InsufficientEDinHDX::get() + }), + 1 + ); + }); +} + +#[test] +fn ed_should_not_be_released_when_sufficient_asset_killed_account() { + TestNet::reset(); + Hydra::execute_with(|| { + let sht1: AssetId = register_external_asset(0_u128); + let sufficient_asset = DAI; + + //This pays ED. + assert_ok!(Tokens::deposit(sht1, &BOB.into(), 100_000_000 * UNITS)); + assert_eq!( + pallet_asset_registry::pallet::ExistentialDepositCounter::::get(), + 1_u128 + ); + + let alice_hdx_balance = Currencies::free_balance(HDX, &ALICE.into()); + let alice_sufficient_asset_balance = Currencies::free_balance(DAI, &ALICE.into()); + let treasury_hdx_balance = Currencies::free_balance(HDX, &TreasuryAccount::get()); + + assert_eq!(treasury_sufficiency_lock(), NativeExistentialDeposit::get()); + assert_eq!( + pallet_asset_registry::pallet::ExistentialDepositCounter::::get(), + 1_u128 + ); + + //Act + assert_ok!(Tokens::transfer( + hydra_origin::signed(ALICE.into()), + BOB.into(), + sufficient_asset, + alice_sufficient_asset_balance + )); + + //Assert + assert_eq!(Currencies::free_balance(HDX, &ALICE.into()), alice_hdx_balance); + assert_eq!(Currencies::free_balance(sufficient_asset, &ALICE.into()), 0); + //NOTE: make sure storage was killed + assert!(orml_tokens::Accounts::::try_get( + sp_runtime::AccountId32::from(ALICE), + sufficient_asset + ) + .is_err()); + + assert_eq!( + Currencies::free_balance(HDX, &TreasuryAccount::get()), + treasury_hdx_balance + ); + assert_eq!(treasury_sufficiency_lock(), NativeExistentialDeposit::get()); + assert_eq!( + pallet_asset_registry::pallet::ExistentialDepositCounter::::get(), + 1_u128 + ); + + assert_event_times!( + RuntimeEvent::AssetRegistry(pallet_asset_registry::Event::ExistentialDepositPaid { + who: BOB.into(), + fee_asset: HDX, + amount: InsufficientEDinHDX::get() + }), + 1 + ); + }); +} + +#[test] +fn ed_should_be_collected_for_each_insufficient_asset_when_transfered_or_depositted() { + TestNet::reset(); + Hydra::execute_with(|| { + let sht1: AssetId = register_external_asset(0_u128); + let sht2: AssetId = register_external_asset(1_u128); + let sht3: AssetId = register_external_asset(2_u128); + let sht4: AssetId = register_external_asset(3_u128); + + let alice_hdx_balance = Currencies::free_balance(HDX, &ALICE.into()); + let bob_hdx_balance = Currencies::free_balance(HDX, &BOB.into()); + let treasury_hdx_balance = Currencies::free_balance(HDX, &TreasuryAccount::get()); + + assert_eq!(MultiTransactionPayment::account_currency(&ALICE.into()), HDX); + assert_eq!(MultiTransactionPayment::account_currency(&BOB.into()), HDX); + assert_eq!(treasury_sufficiency_lock(), 0); + + assert_ok!(Tokens::set_balance( + RawOrigin::Root.into(), + BOB.into(), + sht1, + 100_000_000 * UNITS, + 0, + )); + assert_ok!(Tokens::set_balance( + RawOrigin::Root.into(), + BOB.into(), + sht2, + 100_000_000 * UNITS, + 0, + )); + assert_ok!(Tokens::set_balance( + RawOrigin::Root.into(), + BOB.into(), + sht3, + 100_000_000 * UNITS, + 0, + )); + + //Act + assert_ok!(Tokens::transfer( + hydra_origin::signed(BOB.into()), + ALICE.into(), + sht1, + 10_000 * UNITS + )); + + assert_ok!(Tokens::transfer( + hydra_origin::signed(BOB.into()), + ALICE.into(), + sht3, + 10_000 * UNITS + )); + + assert_ok!(Tokens::transfer( + hydra_origin::signed(BOB.into()), + ALICE.into(), + sht2, + 10_000 * UNITS + )); + + assert_ok!(Tokens::deposit(sht4, &ALICE.into(), 1_000_000 * UNITS)); + + //Assert + //NOTE: Alice paid ED for deposit. + assert_eq!( + Currencies::free_balance(HDX, &ALICE.into()), + alice_hdx_balance - InsufficientEDinHDX::get() + ); + + //NOTE: Bob paid ED for transfers. + assert_eq!( + Currencies::free_balance(HDX, &BOB.into()), + bob_hdx_balance - InsufficientEDinHDX::get() * 3 + ); + + assert_eq!( + Currencies::free_balance(HDX, &TreasuryAccount::get()), + treasury_hdx_balance + InsufficientEDinHDX::get() * 4 + ); + assert_eq!(treasury_sufficiency_lock(), NativeExistentialDeposit::get() * 4); + assert_eq!( + pallet_asset_registry::pallet::ExistentialDepositCounter::::get(), + 4_u128 + ); + + assert_event_times!( + RuntimeEvent::AssetRegistry(pallet_asset_registry::Event::ExistentialDepositPaid { + who: BOB.into(), + fee_asset: HDX, + amount: InsufficientEDinHDX::get() + }), + 3 + ); + + assert_event_times!( + RuntimeEvent::AssetRegistry(pallet_asset_registry::Event::ExistentialDepositPaid { + who: ALICE.into(), + fee_asset: HDX, + amount: InsufficientEDinHDX::get() + }), + 1 + ); + }); +} + +#[test] +fn ed_should_be_released_for_each_insufficient_asset_when_account_is_killed() { + TestNet::reset(); + Hydra::execute_with(|| { + let sht1: AssetId = register_external_asset(0_u128); + let sht2: AssetId = register_external_asset(1_u128); + let sht3: AssetId = register_external_asset(2_u128); + let sht4: AssetId = register_external_asset(3_u128); + + //so bob doesn't pay ed + assert_ok!(Tokens::set_balance(RawOrigin::Root.into(), BOB.into(), sht1, 1, 0)); + assert_ok!(Tokens::set_balance(RawOrigin::Root.into(), BOB.into(), sht2, 1, 0)); + assert_ok!(Tokens::set_balance(RawOrigin::Root.into(), BOB.into(), sht3, 1, 0)); + assert_ok!(Tokens::set_balance(RawOrigin::Root.into(), BOB.into(), sht4, 1, 0)); + + assert_ok!(Tokens::deposit(sht1, &ALICE.into(), 10_000 * UNITS)); + assert_ok!(Tokens::deposit(sht2, &ALICE.into(), 10_000 * UNITS)); + assert_ok!(Tokens::deposit(sht3, &ALICE.into(), 10_000 * UNITS)); + assert_ok!(Tokens::deposit(sht4, &ALICE.into(), 10_000 * UNITS)); + + assert_event_times!( + RuntimeEvent::AssetRegistry(pallet_asset_registry::Event::ExistentialDepositPaid { + who: ALICE.into(), + fee_asset: HDX, + amount: InsufficientEDinHDX::get() + }), + 4 + ); + + let alice_hdx_balance = Currencies::free_balance(HDX, &ALICE.into()); + let treasury_hdx_balance = Currencies::free_balance(HDX, &TreasuryAccount::get()); + assert_eq!(treasury_sufficiency_lock(), NativeExistentialDeposit::get() * 4); + + //Act 1 + assert_ok!(Tokens::transfer( + hydra_origin::signed(ALICE.into()), + BOB.into(), + sht1, + 10_000 * UNITS + )); + + //Assert 1 + assert_eq!( + Currencies::free_balance(HDX, &ALICE.into()), + alice_hdx_balance + NativeExistentialDeposit::get() + ); + assert_eq!( + Currencies::free_balance(HDX, &TreasuryAccount::get()), + treasury_hdx_balance - NativeExistentialDeposit::get() + ); + assert_eq!(treasury_sufficiency_lock(), NativeExistentialDeposit::get() * 3); + assert_eq!( + pallet_asset_registry::pallet::ExistentialDepositCounter::::get(), + 3_u128 + ); + + //Act 2 + assert_ok!(Tokens::transfer( + hydra_origin::signed(ALICE.into()), + BOB.into(), + sht2, + 10_000 * UNITS + )); + + //Assert 2 + assert_eq!( + Currencies::free_balance(HDX, &ALICE.into()), + alice_hdx_balance + NativeExistentialDeposit::get() * 2 + ); + assert_eq!( + Currencies::free_balance(HDX, &TreasuryAccount::get()), + treasury_hdx_balance - NativeExistentialDeposit::get() * 2 + ); + assert_eq!(treasury_sufficiency_lock(), NativeExistentialDeposit::get() * 2); + assert_eq!( + pallet_asset_registry::pallet::ExistentialDepositCounter::::get(), + 2_u128 + ); + + //Act 3 + assert_ok!(Tokens::transfer( + hydra_origin::signed(ALICE.into()), + BOB.into(), + sht3, + 10_000 * UNITS + )); + + //Assert 3 + assert_eq!( + Currencies::free_balance(HDX, &ALICE.into()), + alice_hdx_balance + NativeExistentialDeposit::get() * 3 + ); + assert_eq!( + Currencies::free_balance(HDX, &TreasuryAccount::get()), + treasury_hdx_balance - NativeExistentialDeposit::get() * 3 + ); + assert_eq!(treasury_sufficiency_lock(), NativeExistentialDeposit::get()); + assert_eq!( + pallet_asset_registry::pallet::ExistentialDepositCounter::::get(), + 1_u128 + ); + + //Act 4 + assert_ok!(Tokens::transfer( + hydra_origin::signed(ALICE.into()), + BOB.into(), + sht4, + 10_000 * UNITS + )); + + //Assert 3 + assert_eq!( + Currencies::free_balance(HDX, &ALICE.into()), + alice_hdx_balance + NativeExistentialDeposit::get() * 4 + ); + assert_eq!( + Currencies::free_balance(HDX, &TreasuryAccount::get()), + treasury_hdx_balance - NativeExistentialDeposit::get() * 4 + ); + assert_eq!(treasury_sufficiency_lock(), 0); + assert_eq!( + pallet_asset_registry::pallet::ExistentialDepositCounter::::get(), + 0_u128 + ); + }); +} + +#[test] +fn mix_of_sufficinet_and_insufficient_assets_should_lock_unlock_ed_correctly() { + TestNet::reset(); + Hydra::execute_with(|| { + let sht1: AssetId = register_external_asset(0_u128); + let sht2: AssetId = register_external_asset(1_u128); + let sht3: AssetId = register_external_asset(2_u128); + let sht4: AssetId = register_external_asset(3_u128); + + //so bob doesn't pay ed + assert_ok!(Tokens::set_balance(RawOrigin::Root.into(), BOB.into(), sht1, 1, 0)); + assert_ok!(Tokens::set_balance(RawOrigin::Root.into(), BOB.into(), sht2, 1, 0)); + assert_ok!(Tokens::set_balance(RawOrigin::Root.into(), BOB.into(), sht3, 1, 0)); + assert_ok!(Tokens::set_balance(RawOrigin::Root.into(), BOB.into(), sht4, 1, 0)); + + assert_ok!(Tokens::deposit(sht1, &ALICE.into(), 10_000 * UNITS)); + assert_ok!(Tokens::deposit(sht4, &ALICE.into(), 10_000 * UNITS)); + //NOTE: set_balance bypass mutation hooks so these doesn't pay ED + assert_ok!(Tokens::set_balance( + RawOrigin::Root.into(), + ALICE.into(), + sht2, + 10_000 * UNITS, + 0 + )); + assert_ok!(Tokens::set_balance( + RawOrigin::Root.into(), + ALICE.into(), + sht3, + 10_000 * UNITS, + 0 + )); + + assert_event_times!( + RuntimeEvent::AssetRegistry(pallet_asset_registry::Event::ExistentialDepositPaid { + who: ALICE.into(), + fee_asset: HDX, + amount: InsufficientEDinHDX::get() + }), + 2 + ); + + let alice_hdx_balance = Currencies::free_balance(HDX, &ALICE.into()); + let treasury_hdx_balance = Currencies::free_balance(HDX, &TreasuryAccount::get()); + assert_eq!(treasury_sufficiency_lock(), NativeExistentialDeposit::get() * 2); + assert_eq!( + pallet_asset_registry::pallet::ExistentialDepositCounter::::get(), + 2_u128 + ); + + //Act 1 + assert_ok!(Tokens::transfer( + hydra_origin::signed(ALICE.into()), + BOB.into(), + sht1, + 10_000 * UNITS + )); + + //Assert 1 + assert_eq!( + Currencies::free_balance(HDX, &ALICE.into()), + alice_hdx_balance + NativeExistentialDeposit::get() + ); + assert_eq!( + Currencies::free_balance(HDX, &TreasuryAccount::get()), + treasury_hdx_balance - NativeExistentialDeposit::get() + ); + assert_eq!(treasury_sufficiency_lock(), NativeExistentialDeposit::get()); + assert_eq!( + pallet_asset_registry::pallet::ExistentialDepositCounter::::get(), + 1_u128 + ); + + //Arrange 2 + let alice_dai_balance = Currencies::free_balance(DAI, &ALICE.into()); + let alice_hdx_balance = Currencies::free_balance(HDX, &ALICE.into()); + let treasury_hdx_balance = Currencies::free_balance(HDX, &TreasuryAccount::get()); + + //Act 2 + assert_ok!(Tokens::transfer( + hydra_origin::signed(ALICE.into()), + BOB.into(), + DAI, + alice_dai_balance + )); + + //Assert 2 - sufficient asset so nothing should change + assert_eq!(Currencies::free_balance(HDX, &ALICE.into()), alice_hdx_balance); + assert_eq!( + Currencies::free_balance(HDX, &TreasuryAccount::get()), + treasury_hdx_balance + ); + assert_eq!(treasury_sufficiency_lock(), NativeExistentialDeposit::get()); + assert_eq!( + pallet_asset_registry::pallet::ExistentialDepositCounter::::get(), + 1_u128 + ); + + //Arrange 3 + let alice_hdx_balance = Currencies::free_balance(HDX, &ALICE.into()); + let treasury_hdx_balance = Currencies::free_balance(HDX, &TreasuryAccount::get()); + + //Act 3 + assert_ok!(Tokens::transfer( + hydra_origin::signed(ALICE.into()), + BOB.into(), + sht2, + 10_000 * UNITS + )); + + //Assert 3 + assert_eq!( + Currencies::free_balance(HDX, &ALICE.into()), + alice_hdx_balance + NativeExistentialDeposit::get() + ); + assert_eq!( + Currencies::free_balance(HDX, &TreasuryAccount::get()), + treasury_hdx_balance - NativeExistentialDeposit::get() + ); + assert_eq!(treasury_sufficiency_lock(), 0); + assert_eq!( + pallet_asset_registry::pallet::ExistentialDepositCounter::::get(), + 0_u128 + ); + + //Arrange 4 + let alice_hdx_balance = Currencies::free_balance(HDX, &ALICE.into()); + let treasury_hdx_balance = Currencies::free_balance(HDX, &TreasuryAccount::get()); + + //Act 4 + assert_ok!(Tokens::transfer( + hydra_origin::signed(ALICE.into()), + BOB.into(), + sht3, + 10_000 * UNITS + )); + + //Assert 4 - we used set_balance, nobody paid for this ED so nothing can be unlocked. + assert_eq!(Currencies::free_balance(HDX, &ALICE.into()), alice_hdx_balance); + assert_eq!( + Currencies::free_balance(HDX, &TreasuryAccount::get()), + treasury_hdx_balance + ); + assert_eq!(treasury_sufficiency_lock(), 0); + assert_eq!( + pallet_asset_registry::pallet::ExistentialDepositCounter::::get(), + 0_u128 + ); + + //Arrange 5 + let alice_hdx_balance = Currencies::free_balance(HDX, &ALICE.into()); + let treasury_hdx_balance = Currencies::free_balance(HDX, &TreasuryAccount::get()); + + //Act 5 - we used set_balance, nobody paid for this ED so nothing can be unlocked. + assert_ok!(Tokens::transfer( + hydra_origin::signed(ALICE.into()), + BOB.into(), + sht4, + 10_000 * UNITS + )); + + //Assert 5 + assert_eq!(Currencies::free_balance(HDX, &ALICE.into()), alice_hdx_balance); + assert_eq!( + Currencies::free_balance(HDX, &TreasuryAccount::get()), + treasury_hdx_balance + ); + assert_eq!(treasury_sufficiency_lock(), 0); + assert_eq!( + pallet_asset_registry::pallet::ExistentialDepositCounter::::get(), + 0_u128 + ); + }); +} + +#[test] +fn sender_should_pay_ed_when_tranferred_or_deposited_to_whitelisted_dest() { + TestNet::reset(); + Hydra::execute_with(|| { + let sht1: AssetId = register_external_asset(0_u128); + let sht2: AssetId = register_external_asset(1_u128); + + assert_ok!(Tokens::set_balance( + RawOrigin::Root.into(), + BOB.into(), + sht1, + 1_000_000 * UNITS, + 0, + )); + + let treasury = TreasuryAccount::get(); + + assert!(DustRemovalWhitelist::contains(&treasury)); + assert_eq!(MultiTransactionPayment::account_currency(&BOB.into()), HDX); + + let bob_fee_asset_balance = Currencies::free_balance(HDX, &BOB.into()); + let treasury_hdx_balance = Currencies::free_balance(HDX, &treasury); + + //Act 1 + assert_ok!(Tokens::transfer( + hydra_origin::signed(BOB.into()), + treasury.clone(), + sht1, + 10 + )); + + //Assert 1 + assert_eq!( + Currencies::free_balance(HDX, &treasury), + treasury_hdx_balance + InsufficientEDinHDX::get() + ); + assert_eq!( + Currencies::free_balance(HDX, &BOB.into()), + bob_fee_asset_balance - InsufficientEDinHDX::get() + ); + assert_eq!(Currencies::free_balance(sht1, &treasury), 10); + assert_eq!(treasury_sufficiency_lock(), NativeExistentialDeposit::get()); + assert_eq!( + pallet_asset_registry::pallet::ExistentialDepositCounter::::get(), + 1_u128 + ); + + //Act 2 + assert_ok!(Tokens::deposit(sht2, &treasury, 20)); + + //Assert 2 + assert_eq!( + Currencies::free_balance(HDX, &treasury), + treasury_hdx_balance + InsufficientEDinHDX::get() + ); + assert_eq!(Currencies::free_balance(sht1, &treasury), 10); + assert_eq!(Currencies::free_balance(sht2, &treasury), 20); + //NOTE: treasury paid ED in hdx so hdx balance didn't changed but locked was increased. + assert_eq!(treasury_sufficiency_lock(), 2 * NativeExistentialDeposit::get()); + assert_eq!( + pallet_asset_registry::pallet::ExistentialDepositCounter::::get(), + 2_u128 + ); + + assert_event_times!( + RuntimeEvent::AssetRegistry(pallet_asset_registry::Event::ExistentialDepositPaid { + who: BOB.into(), + fee_asset: HDX, + amount: InsufficientEDinHDX::get() + }), + 1 + ); + assert_event_times!( + RuntimeEvent::AssetRegistry(pallet_asset_registry::Event::ExistentialDepositPaid { + who: treasury.clone(), + fee_asset: HDX, + amount: InsufficientEDinHDX::get() + }), + 1 + ); + }); +} + +#[test] +fn ed_should_be_released_when_whitelisted_account_was_killed() { + TestNet::reset(); + Hydra::execute_with(|| { + let sht1: AssetId = register_external_asset(0_u128); + let treasury = TreasuryAccount::get(); + + assert_ok!(Tokens::set_balance( + RawOrigin::Root.into(), + BOB.into(), + sht1, + 2_000_000 * UNITS, + 0, + )); + + assert_ok!(Tokens::transfer( + hydra_origin::signed(BOB.into()), + treasury.clone(), + sht1, + 1_000_000 * UNITS + )); + + assert_event_times!( + RuntimeEvent::AssetRegistry(pallet_asset_registry::Event::ExistentialDepositPaid { + who: BOB.into(), + fee_asset: HDX, + amount: InsufficientEDinHDX::get() + }), + 1 + ); + + assert!(DustRemovalWhitelist::contains(&treasury)); + assert_eq!(MultiTransactionPayment::account_currency(&treasury), HDX); + let treasury_hdx_balance = Currencies::free_balance(HDX, &treasury); + + //NOTE: set_balance bypass mutation hooks so only Bob paid ED for Treasury. + assert_eq!(treasury_sufficiency_lock(), NativeExistentialDeposit::get()); + assert_eq!( + pallet_asset_registry::pallet::ExistentialDepositCounter::::get(), + 1_u128 + ); + + //Act 1 + assert_ok!(Tokens::transfer( + hydra_origin::signed(treasury.clone()), + BOB.into(), + sht1, + 1_000_000 * UNITS + )); + + //Assert 1 + assert_eq!(Currencies::free_balance(HDX, &treasury), treasury_hdx_balance); + assert_eq!(Currencies::free_balance(sht1, &treasury), 0); + assert_eq!(Currencies::free_balance(sht1, &BOB.into()), 2_000_000 * UNITS); + + //NOTE: bob already holds sht1 so it means additional ed is not necessary. + assert_eq!(treasury_sufficiency_lock(), 0); + assert_eq!( + pallet_asset_registry::pallet::ExistentialDepositCounter::::get(), + 0_u128 + ); + + assert!(orml_tokens::Accounts::::try_get(&treasury, sht1).is_err()); + }); +} + +#[test] +fn tx_should_fail_with_unsupported_currency_error_when_fee_asset_price_was_not_provided() { + TestNet::reset(); + Hydra::execute_with(|| { + let sht1: AssetId = register_external_asset(0_u128); + let sht2: AssetId = register_external_asset(1_u128); + let fee_asset = BTC; + + assert_ok!(Tokens::set_balance( + RawOrigin::Root.into(), + BOB.into(), + sht1, + 100_000_000 * UNITS, + 0, + )); + + assert_ok!(Tokens::set_balance( + RawOrigin::Root.into(), + BOB.into(), + fee_asset, + 1_000_000, + 0, + )); + + assert_ok!(MultiTransactionPayment::set_currency( + hydra_origin::signed(BOB.into()), + fee_asset + )); + + assert_ok!(MultiTransactionPayment::remove_currency(RawOrigin::Root.into(), BTC)); + + hydradx_run_to_block(4); + + //Act 1 - transfer + assert_noop!( + Tokens::transfer(hydra_origin::signed(BOB.into()), ALICE.into(), sht1, 1_000_000 * UNITS), + pallet_transaction_multi_payment::Error::::UnsupportedCurrency + ); + + //Act 2 - deposit + assert_noop!( + Tokens::deposit(sht2, &BOB.into(), 1_000_000 * UNITS), + pallet_transaction_multi_payment::Error::::UnsupportedCurrency + ); + }); +} + +#[test] +fn banned_asset_should_not_create_new_account() { + TestNet::reset(); + Hydra::execute_with(|| { + let tech_comm = pallet_collective::RawOrigin::::Members(1, 1); + //Arrange + let sht1: AssetId = register_external_asset(0_u128); + assert_ok!(Tokens::set_balance( + RawOrigin::Root.into(), + BOB.into(), + sht1, + 100_000_000 * UNITS, + 0, + )); + + assert_ok!(Registry::ban_asset(tech_comm.into(), sht1)); + + assert_eq!(Currencies::free_balance(sht1, &ALICE.into()), 0); + assert_eq!(treasury_sufficiency_lock(), 0); + + //Act & assert + assert_noop!( + Tokens::transfer(hydra_origin::signed(BOB.into()), ALICE.into(), sht1, 1_000_000 * UNITS), + sp_runtime::DispatchError::Other("BannedAssetTransfer") + ); + }); +} + +#[test] +fn banned_asset_should_not_be_transferable_to_existing_account() { + TestNet::reset(); + Hydra::execute_with(|| { + let tech_comm = pallet_collective::RawOrigin::::Members(1, 1); + //Arrange + let sht1: AssetId = register_external_asset(0_u128); + assert_ok!(Tokens::set_balance( + RawOrigin::Root.into(), + BOB.into(), + sht1, + 100_000_000 * UNITS, + 0, + )); + + assert_ok!(Tokens::set_balance( + RawOrigin::Root.into(), + ALICE.into(), + sht1, + 100_000_000 * UNITS, + 0, + )); + + assert_ok!(Registry::ban_asset(tech_comm.into(), sht1)); + + //Act & assert + assert_noop!( + Tokens::transfer(hydra_origin::signed(BOB.into()), ALICE.into(), sht1, 1_000_000 * UNITS), + sp_runtime::DispatchError::Other("BannedAssetTransfer") + ); + }); +} + +fn register_external_asset(general_index: u128) -> AssetId { + let location = hydradx_runtime::AssetLocation(MultiLocation::new( + 1, + X2(Parachain(MOONBEAM_PARA_ID), GeneralIndex(general_index)), + )); + + let next_asset_id = Registry::next_asset_id().unwrap(); + Registry::register_external(hydra_origin::signed(BOB.into()), location).unwrap(); + + next_asset_id +} + +fn treasury_sufficiency_lock() -> Balance { + pallet_balances::Locks::::get(TreasuryAccount::get()) + .iter() + .find(|x| x.id == SUFFICIENCY_LOCK) + .map(|p| p.amount) + .unwrap_or_default() +} + +/// Assert RuntimeEvent specified number of times. +/// +/// Parameters: +/// - `event` +/// - `times` - number of times event should occur. +#[macro_export] +macro_rules! assert_event_times { + ( $x:expr, $y: expr ) => {{ + let mut found: u32 = 0; + + let runtime_events: Vec = frame_system::Pallet::::events() + .into_iter() + .map(|e| e.event) + .collect(); + + for evt in runtime_events { + if evt == $x { + found += 1; + } + + if found > $y { + panic!("Event found more than: {:?} times.", $y); + } + } + if found != $y { + if found == 0 { + panic!("Event not found."); + } + + panic!("Event found {:?} times, expected: {:?}", found, $y); + } + }}; +} diff --git a/integration-tests/src/lib.rs b/integration-tests/src/lib.rs index 241f661c6..af37c2859 100644 --- a/integration-tests/src/lib.rs +++ b/integration-tests/src/lib.rs @@ -1,5 +1,6 @@ // DCA pallet uses dummy router for benchmarks and some tests fail when benchmarking feature is enabled #![cfg(not(feature = "runtime-benchmarks"))] +mod asset_registry; mod bonds; mod call_filter; mod circuit_breaker; @@ -10,6 +11,7 @@ mod dust_removal_whitelist; mod dynamic_fees; mod evm; mod exchange_asset; +mod insufficient_assets_ed; mod non_native_fee; mod omnipool_init; mod omnipool_liquidity_mining; diff --git a/integration-tests/src/polkadot_test_net.rs b/integration-tests/src/polkadot_test_net.rs index ed03d5d7e..b9f3df5a7 100644 --- a/integration-tests/src/polkadot_test_net.rs +++ b/integration-tests/src/polkadot_test_net.rs @@ -18,6 +18,7 @@ use cumulus_test_relay_sproof_builder::RelayStateSproofBuilder; pub use frame_system::{pallet_prelude::BlockNumberFor, RawOrigin}; use hex_literal::hex; use hydradx_runtime::{evm::WETH_ASSET_LOCATION, Referrals, RuntimeOrigin}; +use hydradx_traits::registry::Mutate; use pallet_referrals::{FeeDistribution, Level}; pub use polkadot_primitives::v5::{BlockNumber, MAX_CODE_SIZE, MAX_POV_SIZE}; use polkadot_runtime_parachains::configuration::HostConfiguration; @@ -119,7 +120,7 @@ decl_test_parachains! { hydradx_runtime::Timestamp::set_timestamp(NOW); // Make sure the prices are up-to-date. hydradx_runtime::MultiTransactionPayment::on_initialize(1); - hydradx_runtime::AssetRegistry::set_location(RuntimeOrigin::root(), WETH, WETH_ASSET_LOCATION).unwrap(); + hydradx_runtime::AssetRegistry::set_location(WETH, WETH_ASSET_LOCATION).unwrap(); }, runtime = hydradx_runtime, core = { @@ -406,19 +407,93 @@ pub mod hydra { }, asset_registry: hydradx_runtime::AssetRegistryConfig { registered_assets: vec![ - (b"LRNA".to_vec(), 1_000u128, Some(LRNA)), - (b"DAI".to_vec(), 1_000u128, Some(DAI)), - (b"DOT".to_vec(), 1_000u128, Some(DOT)), - (b"ETH".to_vec(), 1_000u128, Some(ETH)), - (b"BTC".to_vec(), 1_000u128, Some(BTC)), - (b"ACA".to_vec(), 1_000u128, Some(ACA)), - (b"WETH".to_vec(), 1_000u128, Some(WETH)), - (b"PEPE".to_vec(), 1_000u128, Some(PEPE)), + ( + Some(LRNA), + Some(b"LRNA".to_vec().try_into().unwrap()), + 1_000u128, + None, + None, + None, + true, + ), + ( + Some(DAI), + Some(b"DAI".to_vec().try_into().unwrap()), + 1_000u128, + None, + None, + None, + true, + ), + ( + Some(DOT), + Some(b"DOT".to_vec().try_into().unwrap()), + 1_000u128, + None, + None, + None, + true, + ), + ( + Some(ETH), + Some(b"ETH".to_vec().try_into().unwrap()), + 1_000u128, + None, + None, + None, + true, + ), + ( + Some(BTC), + Some(b"BTC".to_vec().try_into().unwrap()), + 1_000u128, + None, + None, + None, + true, + ), + ( + Some(ACA), + Some(b"ACA".to_vec().try_into().unwrap()), + 1_000u128, + None, + None, + None, + true, + ), + ( + Some(WETH), + Some(b"WETH".to_vec().try_into().unwrap()), + 1_000u128, + None, + None, + None, + true, + ), + ( + Some(PEPE), + Some(b"PEPE".to_vec().try_into().unwrap()), + 1_000u128, + None, + None, + None, + true, + ), // workaround for next_asset_id() to return correct values - (b"DUMMY".to_vec(), 1_000u128, None), + ( + None, + Some(b"DUMMY".to_vec().try_into().unwrap()), + 1_000u128, + None, + None, + None, + false, + ), ], - native_asset_name: b"HDX".to_vec(), + native_asset_name: b"HDX".to_vec().try_into().unwrap(), native_existential_deposit: existential_deposit, + native_symbol: b"HDX".to_vec().try_into().unwrap(), + native_decimals: 12, }, parachain_info: hydradx_runtime::ParachainInfoConfig { parachain_id: HYDRA_PARA_ID.into(), diff --git a/integration-tests/src/router.rs b/integration-tests/src/router.rs index e1ba323ea..80cd5676b 100644 --- a/integration-tests/src/router.rs +++ b/integration-tests/src/router.rs @@ -7,10 +7,10 @@ use hydradx_runtime::{ AssetRegistry, BlockNumber, Currencies, Omnipool, Router, RouterWeightInfo, Runtime, RuntimeOrigin, Stableswap, LBP, XYK, }; -use hydradx_traits::Registry; use hydradx_traits::{ + registry::Create, router::{PoolType, Trade}, - AMM, + AssetKind, AMM, }; use pallet_lbp::weights::WeightInfo as LbpWeights; use pallet_lbp::WeightCurveType; @@ -27,11 +27,12 @@ use primitives::AssetId; use frame_support::{assert_noop, assert_ok}; use xcm_emulator::TestExt; +use frame_support::storage::with_transaction; use pallet_stableswap::types::AssetAmount; use pallet_stableswap::MAX_ASSETS_IN_POOL; use sp_runtime::{ traits::{ConstU32, Zero}, - DispatchError, FixedU128, Permill, + DispatchError, DispatchResult, FixedU128, Permill, TransactionOutcome, }; use orml_traits::MultiCurrency; @@ -114,66 +115,70 @@ mod router_different_pools_tests { TestNet::reset(); Hydra::execute_with(|| { - //Arrange - let (stable_pool_id, stable_asset_1, stable_asset_2) = init_stableswap().unwrap(); - create_lbp_pool(DAI, HDX); + let _ = with_transaction(|| { + //Arrange + let (stable_pool_id, stable_asset_1, stable_asset_2) = init_stableswap().unwrap(); + create_lbp_pool(DAI, HDX); - assert_ok!(Currencies::update_balance( - hydradx_runtime::RuntimeOrigin::root(), - ALICE.into(), - stable_asset_1, - 3000 * UNITS as i128, - )); + assert_ok!(Currencies::update_balance( + hydradx_runtime::RuntimeOrigin::root(), + ALICE.into(), + stable_asset_1, + 3000 * UNITS as i128, + )); - create_xyk_pool(HDX, stable_asset_1); + create_xyk_pool(HDX, stable_asset_1); - let amount_to_sell = UNITS / 100; - let limit = 0; - let trades = vec![ - Trade { - pool: PoolType::LBP, - asset_in: DAI, - asset_out: HDX, - }, - Trade { - pool: PoolType::XYK, - asset_in: HDX, - asset_out: stable_asset_1, - }, - Trade { - pool: PoolType::Stableswap(stable_pool_id), - asset_in: stable_asset_1, - asset_out: stable_asset_2, - }, - ]; + let amount_to_sell = UNITS / 100; + let limit = 0; + let trades = vec![ + Trade { + pool: PoolType::LBP, + asset_in: DAI, + asset_out: HDX, + }, + Trade { + pool: PoolType::XYK, + asset_in: HDX, + asset_out: stable_asset_1, + }, + Trade { + pool: PoolType::Stableswap(stable_pool_id), + asset_in: stable_asset_1, + asset_out: stable_asset_2, + }, + ]; - start_lbp_campaign(); + start_lbp_campaign(); - //Act - assert_ok!(Router::sell( - RuntimeOrigin::signed(BOB.into()), - DAI, - stable_asset_2, - amount_to_sell, - limit, - trades - )); + //Act + assert_ok!(Router::sell( + RuntimeOrigin::signed(BOB.into()), + DAI, + stable_asset_2, + amount_to_sell, + limit, + trades + )); - //Assert - let amount_out = 2_783_595_233; + //Assert + let amount_out = 2_783_595_233; - assert_balance!(BOB.into(), DAI, 1_000_000_000 * UNITS - amount_to_sell); - assert_balance!(BOB.into(), HDX, BOB_INITIAL_NATIVE_BALANCE); - assert_balance!(BOB.into(), stable_asset_1, 0); - assert_balance!(BOB.into(), stable_asset_2, amount_out); + assert_balance!(BOB.into(), DAI, 1_000_000_000 * UNITS - amount_to_sell); + assert_balance!(BOB.into(), HDX, BOB_INITIAL_NATIVE_BALANCE); + assert_balance!(BOB.into(), stable_asset_1, 0); + assert_balance!(BOB.into(), stable_asset_2, amount_out); - expect_hydra_events(vec![pallet_route_executor::Event::Executed { - asset_in: DAI, - asset_out: stable_asset_2, - amount_in: amount_to_sell, - amount_out, - } - .into()]); + expect_hydra_events(vec![pallet_route_executor::Event::Executed { + asset_in: DAI, + asset_out: stable_asset_2, + amount_in: amount_to_sell, + amount_out, + } + .into()]); + + TransactionOutcome::Commit(DispatchResult::Ok(())) + }); }); } @@ -239,66 +244,69 @@ mod router_different_pools_tests { TestNet::reset(); Hydra::execute_with(|| { - //Arrange - let (stable_pool_id, stable_asset_1, stable_asset_2) = init_stableswap().unwrap(); - create_lbp_pool(DAI, HDX); + let _ = with_transaction(|| { + //Arrange + let (stable_pool_id, stable_asset_1, stable_asset_2) = init_stableswap().unwrap(); + create_lbp_pool(DAI, HDX); - assert_ok!(Currencies::update_balance( - hydradx_runtime::RuntimeOrigin::root(), - ALICE.into(), - stable_asset_1, - 3000 * UNITS as i128, - )); + assert_ok!(Currencies::update_balance( + hydradx_runtime::RuntimeOrigin::root(), + ALICE.into(), + stable_asset_1, + 3000 * UNITS as i128, + )); - create_xyk_pool(HDX, stable_asset_1); + create_xyk_pool(HDX, stable_asset_1); - let amount_to_buy = UNITS; - let limit = 100 * UNITS; - let trades = vec![ - Trade { - pool: PoolType::LBP, - asset_in: DAI, - asset_out: HDX, - }, - Trade { - pool: PoolType::XYK, - asset_in: HDX, - asset_out: stable_asset_1, - }, - Trade { - pool: PoolType::Stableswap(stable_pool_id), - asset_in: stable_asset_1, - asset_out: stable_asset_2, - }, - ]; + let amount_to_buy = UNITS; + let limit = 100 * UNITS; + let trades = vec![ + Trade { + pool: PoolType::LBP, + asset_in: DAI, + asset_out: HDX, + }, + Trade { + pool: PoolType::XYK, + asset_in: HDX, + asset_out: stable_asset_1, + }, + Trade { + pool: PoolType::Stableswap(stable_pool_id), + asset_in: stable_asset_1, + asset_out: stable_asset_2, + }, + ]; - start_lbp_campaign(); + start_lbp_campaign(); - //Act - assert_ok!(Router::buy( - RuntimeOrigin::signed(BOB.into()), - DAI, - stable_asset_2, - amount_to_buy, - limit, - trades - )); + //Act + assert_ok!(Router::buy( + RuntimeOrigin::signed(BOB.into()), + DAI, + stable_asset_2, + amount_to_buy, + limit, + trades + )); - //Assert - let amount_in = 3_753_549_142_038; + //Assert + let amount_in = 3_753_549_142_038; - assert_balance!(BOB.into(), DAI, 1_000_000_000 * UNITS - amount_in); - assert_balance!(BOB.into(), HDX, BOB_INITIAL_NATIVE_BALANCE); - assert_balance!(BOB.into(), stable_asset_1, 0); - assert_balance!(BOB.into(), stable_asset_2, amount_to_buy); + assert_balance!(BOB.into(), DAI, 1_000_000_000 * UNITS - amount_in); + assert_balance!(BOB.into(), HDX, BOB_INITIAL_NATIVE_BALANCE); + assert_balance!(BOB.into(), stable_asset_1, 0); + assert_balance!(BOB.into(), stable_asset_2, amount_to_buy); - expect_hydra_events(vec![pallet_route_executor::Event::Executed { - asset_in: DAI, - asset_out: stable_asset_2, - amount_in, - amount_out: amount_to_buy, - } - .into()]); + expect_hydra_events(vec![pallet_route_executor::Event::Executed { + asset_in: DAI, + asset_out: stable_asset_2, + amount_in, + amount_out: amount_to_buy, + } + .into()]); + TransactionOutcome::Commit(DispatchResult::Ok(())) + }); }); } @@ -307,55 +315,58 @@ mod router_different_pools_tests { TestNet::reset(); Hydra::execute_with(|| { - //Arrange - let (pool_id, stable_asset_1, stable_asset_2) = init_stableswap().unwrap(); + let _ = with_transaction(|| { + //Arrange + let (pool_id, stable_asset_1, stable_asset_2) = init_stableswap().unwrap(); - init_omnipool(); + init_omnipool(); - assert_ok!(Currencies::update_balance( - hydradx_runtime::RuntimeOrigin::root(), - Omnipool::protocol_account(), - stable_asset_1, - 3000 * UNITS as i128, - )); + assert_ok!(Currencies::update_balance( + hydradx_runtime::RuntimeOrigin::root(), + Omnipool::protocol_account(), + stable_asset_1, + 3000 * UNITS as i128, + )); - assert_ok!(hydradx_runtime::Omnipool::add_token( - hydradx_runtime::RuntimeOrigin::root(), - stable_asset_1, - FixedU128::from_inner(25_650_000_000_000_000), - Permill::from_percent(1), - AccountId::from(BOB), - )); + assert_ok!(hydradx_runtime::Omnipool::add_token( + hydradx_runtime::RuntimeOrigin::root(), + stable_asset_1, + FixedU128::from_inner(25_650_000_000_000_000), + Permill::from_percent(1), + AccountId::from(BOB), + )); - let trades = vec![ - Trade { - pool: PoolType::Omnipool, - asset_in: HDX, - asset_out: stable_asset_1, - }, - Trade { - pool: PoolType::Stableswap(pool_id), - asset_in: stable_asset_1, - asset_out: stable_asset_2, - }, - ]; + let trades = vec![ + Trade { + pool: PoolType::Omnipool, + asset_in: HDX, + asset_out: stable_asset_1, + }, + Trade { + pool: PoolType::Stableswap(pool_id), + asset_in: stable_asset_1, + asset_out: stable_asset_2, + }, + ]; - //Act - let amount_to_sell = 100 * UNITS; - assert_ok!(Router::sell( - hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), - HDX, - stable_asset_2, - amount_to_sell, - 0, - trades - )); + //Act + let amount_to_sell = 100 * UNITS; + assert_ok!(Router::sell( + hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), + HDX, + stable_asset_2, + amount_to_sell, + 0, + trades + )); - //Assert - assert_eq!( - hydradx_runtime::Balances::free_balance(AccountId::from(ALICE)), - ALICE_INITIAL_NATIVE_BALANCE - amount_to_sell - ); + //Assert + assert_eq!( + hydradx_runtime::Balances::free_balance(AccountId::from(ALICE)), + ALICE_INITIAL_NATIVE_BALANCE - amount_to_sell + ); + TransactionOutcome::Commit(DispatchResult::Ok(())) + }); }); } @@ -364,59 +375,62 @@ mod router_different_pools_tests { TestNet::reset(); Hydra::execute_with(|| { - //Arrange - let (pool_id, stable_asset_1, _) = init_stableswap().unwrap(); + let _ = with_transaction(|| { + //Arrange + let (pool_id, stable_asset_1, _) = init_stableswap().unwrap(); - init_omnipool(); + init_omnipool(); - assert_ok!(Currencies::update_balance( - hydradx_runtime::RuntimeOrigin::root(), - Omnipool::protocol_account(), - stable_asset_1, - 3000 * UNITS as i128, - )); + assert_ok!(Currencies::update_balance( + hydradx_runtime::RuntimeOrigin::root(), + Omnipool::protocol_account(), + stable_asset_1, + 3000 * UNITS as i128, + )); - assert_ok!(hydradx_runtime::Omnipool::add_token( - hydradx_runtime::RuntimeOrigin::root(), - stable_asset_1, - FixedU128::from_inner(25_650_000_000_000_000), - Permill::from_percent(1), - AccountId::from(BOB), - )); + assert_ok!(hydradx_runtime::Omnipool::add_token( + hydradx_runtime::RuntimeOrigin::root(), + stable_asset_1, + FixedU128::from_inner(25_650_000_000_000_000), + Permill::from_percent(1), + AccountId::from(BOB), + )); - let trades = vec![ - Trade { - pool: PoolType::Omnipool, - asset_in: HDX, - asset_out: stable_asset_1, - }, - Trade { - pool: PoolType::Stableswap(pool_id), - asset_in: stable_asset_1, - asset_out: pool_id, - }, - ]; + let trades = vec![ + Trade { + pool: PoolType::Omnipool, + asset_in: HDX, + asset_out: stable_asset_1, + }, + Trade { + pool: PoolType::Stableswap(pool_id), + asset_in: stable_asset_1, + asset_out: pool_id, + }, + ]; - assert_balance!(ALICE.into(), pool_id, 0); + assert_balance!(ALICE.into(), pool_id, 0); - //Act - let amount_to_sell = 100 * UNITS; - assert_ok!(Router::sell( - hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), - HDX, - pool_id, - amount_to_sell, - 0, - trades - )); + //Act + let amount_to_sell = 100 * UNITS; + assert_ok!(Router::sell( + hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), + HDX, + pool_id, + amount_to_sell, + 0, + trades + )); - //Assert - assert_eq!( - hydradx_runtime::Balances::free_balance(AccountId::from(ALICE)), - ALICE_INITIAL_NATIVE_BALANCE - amount_to_sell - ); + //Assert + assert_eq!( + hydradx_runtime::Balances::free_balance(AccountId::from(ALICE)), + ALICE_INITIAL_NATIVE_BALANCE - amount_to_sell + ); - assert_balance!(ALICE.into(), pool_id, 4638992258357); + assert_balance!(ALICE.into(), pool_id, 4638992258357); + TransactionOutcome::Commit(DispatchResult::Ok(())) + }); }); } @@ -425,57 +439,60 @@ mod router_different_pools_tests { TestNet::reset(); Hydra::execute_with(|| { - //Arrange - let (pool_id, stable_asset_1, _) = init_stableswap().unwrap(); + let _ = with_transaction(|| { + //Arrange + let (pool_id, stable_asset_1, _) = init_stableswap().unwrap(); - init_omnipool(); + init_omnipool(); - assert_ok!(Currencies::update_balance( - hydradx_runtime::RuntimeOrigin::root(), - Omnipool::protocol_account(), - pool_id, - 3000 * UNITS as i128, - )); + assert_ok!(Currencies::update_balance( + hydradx_runtime::RuntimeOrigin::root(), + Omnipool::protocol_account(), + pool_id, + 3000 * UNITS as i128, + )); - assert_ok!(hydradx_runtime::Omnipool::add_token( - hydradx_runtime::RuntimeOrigin::root(), - pool_id, - FixedU128::from_inner(25_650_000_000_000_000), - Permill::from_percent(1), - AccountId::from(BOB), - )); + assert_ok!(hydradx_runtime::Omnipool::add_token( + hydradx_runtime::RuntimeOrigin::root(), + pool_id, + FixedU128::from_inner(25_650_000_000_000_000), + Permill::from_percent(1), + AccountId::from(BOB), + )); - let trades = vec![ - Trade { - pool: PoolType::Omnipool, - asset_in: HDX, - asset_out: pool_id, - }, - Trade { - pool: PoolType::Stableswap(pool_id), - asset_in: pool_id, - asset_out: stable_asset_1, - }, - ]; + let trades = vec![ + Trade { + pool: PoolType::Omnipool, + asset_in: HDX, + asset_out: pool_id, + }, + Trade { + pool: PoolType::Stableswap(pool_id), + asset_in: pool_id, + asset_out: stable_asset_1, + }, + ]; - assert_balance!(ALICE.into(), pool_id, 0); + assert_balance!(ALICE.into(), pool_id, 0); - //Act - let amount_to_sell = 100 * UNITS; + //Act + let amount_to_sell = 100 * UNITS; - assert_ok!(Router::sell( - hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), - HDX, - stable_asset_1, - amount_to_sell, - 0, - trades - )); + assert_ok!(Router::sell( + hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), + HDX, + stable_asset_1, + amount_to_sell, + 0, + trades + )); - //Assert - assert_balance!(ALICE.into(), pool_id, 0); - assert_balance!(ALICE.into(), HDX, ALICE_INITIAL_NATIVE_BALANCE - amount_to_sell); - assert_balance!(ALICE.into(), stable_asset_1, 2899390145403); + //Assert + assert_balance!(ALICE.into(), pool_id, 0); + assert_balance!(ALICE.into(), HDX, ALICE_INITIAL_NATIVE_BALANCE - amount_to_sell); + assert_balance!(ALICE.into(), stable_asset_1, 2899390145403); + TransactionOutcome::Commit(DispatchResult::Ok(())) + }); }); } @@ -484,56 +501,59 @@ mod router_different_pools_tests { TestNet::reset(); Hydra::execute_with(|| { - //Arrange - let (pool_id, stable_asset_1, _) = init_stableswap().unwrap(); + let _ = with_transaction(|| { + //Arrange + let (pool_id, stable_asset_1, _) = init_stableswap().unwrap(); - init_omnipool(); + init_omnipool(); - assert_ok!(Currencies::update_balance( - hydradx_runtime::RuntimeOrigin::root(), - Omnipool::protocol_account(), - pool_id, - 3000 * UNITS as i128, - )); + assert_ok!(Currencies::update_balance( + hydradx_runtime::RuntimeOrigin::root(), + Omnipool::protocol_account(), + pool_id, + 3000 * UNITS as i128, + )); - assert_ok!(hydradx_runtime::Omnipool::add_token( - hydradx_runtime::RuntimeOrigin::root(), - pool_id, - FixedU128::from_inner(25_650_000_000_000_000), - Permill::from_percent(1), - AccountId::from(BOB), - )); + assert_ok!(hydradx_runtime::Omnipool::add_token( + hydradx_runtime::RuntimeOrigin::root(), + pool_id, + FixedU128::from_inner(25_650_000_000_000_000), + Permill::from_percent(1), + AccountId::from(BOB), + )); - let trades = vec![ - Trade { - pool: PoolType::Omnipool, - asset_in: HDX, - asset_out: pool_id, - }, - Trade { - pool: PoolType::Stableswap(pool_id), - asset_in: pool_id, - asset_out: stable_asset_1, - }, - ]; + let trades = vec![ + Trade { + pool: PoolType::Omnipool, + asset_in: HDX, + asset_out: pool_id, + }, + Trade { + pool: PoolType::Stableswap(pool_id), + asset_in: pool_id, + asset_out: stable_asset_1, + }, + ]; - assert_balance!(ALICE.into(), pool_id, 0); + assert_balance!(ALICE.into(), pool_id, 0); - //Act - let amount_to_buy = UNITS / 1000; + //Act + let amount_to_buy = UNITS / 1000; - assert_ok!(Router::buy( - hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), - HDX, - stable_asset_1, - amount_to_buy, - u128::MAX, - trades - )); + assert_ok!(Router::buy( + hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), + HDX, + stable_asset_1, + amount_to_buy, + u128::MAX, + trades + )); - //Assert - //assert_balance!(ALICE.into(), HDX, ALICE_INITIAL_NATIVE_BALANCE); - assert_balance!(ALICE.into(), stable_asset_1, amount_to_buy); + //Assert + //assert_balance!(ALICE.into(), HDX, ALICE_INITIAL_NATIVE_BALANCE); + assert_balance!(ALICE.into(), stable_asset_1, amount_to_buy); + TransactionOutcome::Commit(DispatchResult::Ok(())) + }); }); } @@ -542,62 +562,65 @@ mod router_different_pools_tests { TestNet::reset(); Hydra::execute_with(|| { - //Arrange - let (pool_id, stable_asset_1, _) = init_stableswap().unwrap(); - - init_omnipool(); - - assert_ok!(Currencies::update_balance( - hydradx_runtime::RuntimeOrigin::root(), - Omnipool::protocol_account(), - pool_id, - 3000 * UNITS as i128, - )); + let _ = with_transaction(|| { + //Arrange + let (pool_id, stable_asset_1, _) = init_stableswap().unwrap(); - assert_ok!(hydradx_runtime::Omnipool::add_token( - hydradx_runtime::RuntimeOrigin::root(), - pool_id, - FixedU128::from_inner(25_650_000_000_000_000), - Permill::from_percent(1), - AccountId::from(BOB), - )); + init_omnipool(); - let trades = vec![ - Trade { - pool: PoolType::Stableswap(pool_id), - asset_in: stable_asset_1, - asset_out: pool_id, - }, - Trade { - pool: PoolType::Omnipool, - asset_in: pool_id, - asset_out: HDX, - }, - ]; + assert_ok!(Currencies::update_balance( + hydradx_runtime::RuntimeOrigin::root(), + Omnipool::protocol_account(), + pool_id, + 3000 * UNITS as i128, + )); - assert_balance!(ALICE.into(), HDX, ALICE_INITIAL_NATIVE_BALANCE); + assert_ok!(hydradx_runtime::Omnipool::add_token( + hydradx_runtime::RuntimeOrigin::root(), + pool_id, + FixedU128::from_inner(25_650_000_000_000_000), + Permill::from_percent(1), + AccountId::from(BOB), + )); - //Act - assert_ok!(Currencies::update_balance( - hydradx_runtime::RuntimeOrigin::root(), - ALICE.into(), - stable_asset_1, - 3000 * UNITS as i128, - )); + let trades = vec![ + Trade { + pool: PoolType::Stableswap(pool_id), + asset_in: stable_asset_1, + asset_out: pool_id, + }, + Trade { + pool: PoolType::Omnipool, + asset_in: pool_id, + asset_out: HDX, + }, + ]; - let amount_to_buy = 100 * UNITS; + assert_balance!(ALICE.into(), HDX, ALICE_INITIAL_NATIVE_BALANCE); - assert_ok!(Router::buy( - hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), - stable_asset_1, - HDX, - amount_to_buy, - u128::MAX, - trades - )); + //Act + assert_ok!(Currencies::update_balance( + hydradx_runtime::RuntimeOrigin::root(), + ALICE.into(), + stable_asset_1, + 3000 * UNITS as i128, + )); - //Assert - assert_balance!(ALICE.into(), HDX, ALICE_INITIAL_NATIVE_BALANCE + amount_to_buy); + let amount_to_buy = 100 * UNITS; + + assert_ok!(Router::buy( + hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), + stable_asset_1, + HDX, + amount_to_buy, + u128::MAX, + trades + )); + + //Assert + assert_balance!(ALICE.into(), HDX, ALICE_INITIAL_NATIVE_BALANCE + amount_to_buy); + TransactionOutcome::Commit(DispatchResult::Ok(())) + }); }); } @@ -2105,42 +2128,45 @@ mod omnipool_stableswap_router_tests { TestNet::reset(); Hydra::execute_with(|| { - //Arrange - let (pool_id, stable_asset_1, _) = init_stableswap().unwrap(); + let _ = with_transaction(|| { + //Arrange + let (pool_id, stable_asset_1, _) = init_stableswap().unwrap(); - init_omnipool(); + init_omnipool(); - assert_ok!(Currencies::update_balance( - hydradx_runtime::RuntimeOrigin::root(), - ALICE.into(), - stable_asset_1, - 3000 * UNITS as i128, - )); + assert_ok!(Currencies::update_balance( + hydradx_runtime::RuntimeOrigin::root(), + ALICE.into(), + stable_asset_1, + 3000 * UNITS as i128, + )); - let trades = vec![Trade { - pool: PoolType::Stableswap(pool_id), - asset_in: stable_asset_1, - asset_out: pool_id, - }]; + let trades = vec![Trade { + pool: PoolType::Stableswap(pool_id), + asset_in: stable_asset_1, + asset_out: pool_id, + }]; - assert_balance!(ALICE.into(), pool_id, 0); + assert_balance!(ALICE.into(), pool_id, 0); - //Act - let amount_to_sell = 100 * UNITS; - assert_ok!(Router::sell( - hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), - stable_asset_1, - pool_id, - amount_to_sell, - 0, - trades - )); + //Act + let amount_to_sell = 100 * UNITS; + assert_ok!(Router::sell( + hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), + stable_asset_1, + pool_id, + amount_to_sell, + 0, + trades + )); - //Assert - assert_eq!( - hydradx_runtime::Currencies::free_balance(stable_asset_1, &AccountId::from(ALICE)), - 3000 * UNITS - amount_to_sell - ); + //Assert + assert_eq!( + hydradx_runtime::Currencies::free_balance(stable_asset_1, &AccountId::from(ALICE)), + 3000 * UNITS - amount_to_sell + ); + TransactionOutcome::Commit(DispatchResult::Ok(())) + }); }); } @@ -2149,35 +2175,38 @@ mod omnipool_stableswap_router_tests { TestNet::reset(); Hydra::execute_with(|| { - //Arrange - let (pool_id, stable_asset_1, _) = init_stableswap().unwrap(); + let _ = with_transaction(|| { + //Arrange + let (pool_id, stable_asset_1, _) = init_stableswap().unwrap(); - let trades = vec![Trade { - pool: PoolType::Stableswap(pool_id), - asset_in: stable_asset_1, - asset_out: pool_id, - }]; + let trades = vec![Trade { + pool: PoolType::Stableswap(pool_id), + asset_in: stable_asset_1, + asset_out: pool_id, + }]; - assert_balance!(ALICE.into(), HDX, ALICE_INITIAL_NATIVE_BALANCE); + assert_balance!(ALICE.into(), HDX, ALICE_INITIAL_NATIVE_BALANCE); - //Act - assert_ok!(Currencies::update_balance( - hydradx_runtime::RuntimeOrigin::root(), - ALICE.into(), - stable_asset_1, - 3000 * UNITS as i128, - )); + //Act + assert_ok!(Currencies::update_balance( + hydradx_runtime::RuntimeOrigin::root(), + ALICE.into(), + stable_asset_1, + 3000 * UNITS as i128, + )); - let amount_to_buy = 100 * UNITS; + let amount_to_buy = 100 * UNITS; - assert_ok!(Router::buy( - hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), - stable_asset_1, - pool_id, - amount_to_buy, - u128::MAX, - trades - )); + assert_ok!(Router::buy( + hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), + stable_asset_1, + pool_id, + amount_to_buy, + u128::MAX, + trades + )); + TransactionOutcome::Commit(DispatchResult::Ok(())) + }); }); } @@ -2186,33 +2215,36 @@ mod omnipool_stableswap_router_tests { TestNet::reset(); Hydra::execute_with(|| { - //Arrange - let (pool_id, stable_asset_1, _) = init_stableswap().unwrap(); + let _ = with_transaction(|| { + //Arrange + let (pool_id, stable_asset_1, _) = init_stableswap().unwrap(); - let trades = vec![Trade { - pool: PoolType::Stableswap(pool_id), - asset_in: pool_id, - asset_out: stable_asset_1, - }]; + let trades = vec![Trade { + pool: PoolType::Stableswap(pool_id), + asset_in: pool_id, + asset_out: stable_asset_1, + }]; - //Act - assert_ok!(Currencies::update_balance( - hydradx_runtime::RuntimeOrigin::root(), - ALICE.into(), - pool_id, - 3000 * UNITS as i128, - )); + //Act + assert_ok!(Currencies::update_balance( + hydradx_runtime::RuntimeOrigin::root(), + ALICE.into(), + pool_id, + 3000 * UNITS as i128, + )); - let amount_to_buy = 100 * UNITS; + let amount_to_buy = 100 * UNITS; - assert_ok!(Router::buy( - hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), - pool_id, - stable_asset_1, - amount_to_buy, - u128::MAX, - trades - )); + assert_ok!(Router::buy( + hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), + pool_id, + stable_asset_1, + amount_to_buy, + u128::MAX, + trades + )); + TransactionOutcome::Commit(DispatchResult::Ok(())) + }); }); } } @@ -2230,169 +2262,175 @@ mod set_route { TestNet::reset(); Hydra::execute_with(|| { - //Arrange - let (pool_id, stable_asset_1, _) = - init_stableswap_with_liquidity(1_000_000_000_000_000_000u128, 300_000_000_000_000_000u128).unwrap(); - - init_omnipool(); - - assert_ok!(Currencies::update_balance( - hydradx_runtime::RuntimeOrigin::root(), - Omnipool::protocol_account(), - pool_id, - 60000 * UNITS as i128, - )); - - assert_ok!(hydradx_runtime::Omnipool::add_token( - hydradx_runtime::RuntimeOrigin::root(), - pool_id, - FixedU128::from_rational(1, 2), - Permill::from_percent(1), - AccountId::from(BOB), - )); - - create_xyk_pool_with_amounts(DOT, 1000000 * UNITS, stable_asset_1, 20000 * UNITS); - - create_lbp_pool_with_amounts(DOT, 1000000 * UNITS, stable_asset_1, 20000 * UNITS); - //Start lbp campaign - set_relaychain_block_number(LBP_SALE_START + 15); - - let route1 = vec![ - Trade { - pool: PoolType::Omnipool, - asset_in: HDX, - asset_out: pool_id, - }, - Trade { - pool: PoolType::Stableswap(pool_id), - asset_in: pool_id, - asset_out: stable_asset_1, - }, - Trade { - pool: PoolType::XYK, - asset_in: stable_asset_1, - asset_out: DOT, - }, - ]; - - let route2_cheaper = vec![ - Trade { - pool: PoolType::Omnipool, - asset_in: HDX, - asset_out: pool_id, - }, - Trade { - pool: PoolType::Stableswap(pool_id), - asset_in: pool_id, - asset_out: stable_asset_1, - }, - Trade { - pool: PoolType::LBP, - asset_in: stable_asset_1, - asset_out: DOT, - }, - ]; - - let asset_pair = Pair::new(HDX, DOT); - - //Verify if the cheaper route is indeed cheaper in both ways - let amount_to_sell = 100 * UNITS; - - //Check for normal route - let dot_amount_out = with_transaction::<_, _, _>(|| { - assert_ok!(Router::sell( - hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), - HDX, - DOT, - amount_to_sell, - 0, - route1.clone() + let _ = with_transaction(|| { + //Arrange + let (pool_id, stable_asset_1, _) = + init_stableswap_with_liquidity(1_000_000_000_000_000_000u128, 300_000_000_000_000_000u128) + .unwrap(); + + init_omnipool(); + + assert_ok!(Currencies::update_balance( + hydradx_runtime::RuntimeOrigin::root(), + Omnipool::protocol_account(), + pool_id, + 60000 * UNITS as i128, )); - let alice_received_dot = - Currencies::free_balance(DOT, &AccountId::from(ALICE)) - ALICE_INITIAL_DOT_BALANCE; - - TransactionOutcome::Rollback(Ok::(alice_received_dot)) - }) - .unwrap(); - //Check for normal route - let dot_amout_out_for_cheaper_route = with_transaction::<_, _, _>(|| { - assert_ok!(Router::sell( - hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), - HDX, - DOT, - amount_to_sell, - 0, - route2_cheaper.clone() + assert_ok!(hydradx_runtime::Omnipool::add_token( + hydradx_runtime::RuntimeOrigin::root(), + pool_id, + FixedU128::from_rational(1, 2), + Permill::from_percent(1), + AccountId::from(BOB), )); - let alice_received_dot = - Currencies::free_balance(DOT, &AccountId::from(ALICE)) - ALICE_INITIAL_DOT_BALANCE; - - TransactionOutcome::Rollback(Ok::(alice_received_dot)) - }) - .unwrap(); - - assert!(dot_amout_out_for_cheaper_route > dot_amount_out); - // Check for inverse route - let amount_out_for_inverse = with_transaction::<_, _, _>(|| { - let alice_hdx_balance = Currencies::free_balance(HDX, &AccountId::from(ALICE)); - assert_ok!(Router::sell( + create_xyk_pool_with_amounts(DOT, 1000000 * UNITS, stable_asset_1, 20000 * UNITS); + + create_lbp_pool_with_amounts(DOT, 1000000 * UNITS, stable_asset_1, 20000 * UNITS); + //Start lbp campaign + set_relaychain_block_number(LBP_SALE_START + 15); + + let route1 = vec![ + Trade { + pool: PoolType::Omnipool, + asset_in: HDX, + asset_out: pool_id, + }, + Trade { + pool: PoolType::Stableswap(pool_id), + asset_in: pool_id, + asset_out: stable_asset_1, + }, + Trade { + pool: PoolType::XYK, + asset_in: stable_asset_1, + asset_out: DOT, + }, + ]; + + let route2_cheaper = vec![ + Trade { + pool: PoolType::Omnipool, + asset_in: HDX, + asset_out: pool_id, + }, + Trade { + pool: PoolType::Stableswap(pool_id), + asset_in: pool_id, + asset_out: stable_asset_1, + }, + Trade { + pool: PoolType::LBP, + asset_in: stable_asset_1, + asset_out: DOT, + }, + ]; + + let asset_pair = Pair::new(HDX, DOT); + + //Verify if the cheaper route is indeed cheaper in both ways + let amount_to_sell = 100 * UNITS; + + //Check for normal route + let dot_amount_out = with_transaction::<_, _, _>(|| { + assert_ok!(Router::sell( + hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), + HDX, + DOT, + amount_to_sell, + 0, + route1.clone() + )); + let alice_received_dot = + Currencies::free_balance(DOT, &AccountId::from(ALICE)) - ALICE_INITIAL_DOT_BALANCE; + + TransactionOutcome::Rollback(Ok::(alice_received_dot)) + }) + .unwrap(); + + //Check for normal route + let dot_amout_out_for_cheaper_route = with_transaction::<_, _, _>(|| { + assert_ok!(Router::sell( + hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), + HDX, + DOT, + amount_to_sell, + 0, + route2_cheaper.clone() + )); + let alice_received_dot = + Currencies::free_balance(DOT, &AccountId::from(ALICE)) - ALICE_INITIAL_DOT_BALANCE; + + TransactionOutcome::Rollback(Ok::(alice_received_dot)) + }) + .unwrap(); + + assert!(dot_amout_out_for_cheaper_route > dot_amount_out); + + // Check for inverse route + let amount_out_for_inverse = with_transaction::<_, _, _>(|| { + let alice_hdx_balance = Currencies::free_balance(HDX, &AccountId::from(ALICE)); + assert_ok!(Router::sell( + hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), + DOT, + HDX, + amount_to_sell, + 0, + inverse_route(route1.clone()) + )); + let alice_received_hdx = + Currencies::free_balance(HDX, &AccountId::from(ALICE)) - alice_hdx_balance; + + TransactionOutcome::Rollback(Ok::(alice_received_hdx)) + }) + .unwrap(); + + let amount_out_for_inverse_with_chaper_route = with_transaction::<_, _, _>(|| { + let alice_hdx_balance = Currencies::free_balance(HDX, &AccountId::from(ALICE)); + assert_ok!(Router::sell( + hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), + DOT, + HDX, + amount_to_sell, + 0, + inverse_route(route2_cheaper.clone()) + )); + let alice_received_hdx = + Currencies::free_balance(HDX, &AccountId::from(ALICE)) - alice_hdx_balance; + + TransactionOutcome::Rollback(Ok::(alice_received_hdx)) + }) + .unwrap(); + + assert!(amount_out_for_inverse_with_chaper_route > amount_out_for_inverse); + + //ACT AND ASSERT + + //We set first the more expensive route + assert_ok!(Router::set_route( hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), - DOT, - HDX, - amount_to_sell, - 0, - inverse_route(route1.clone()) + asset_pair, + route1.clone() )); - let alice_received_hdx = Currencies::free_balance(HDX, &AccountId::from(ALICE)) - alice_hdx_balance; - - TransactionOutcome::Rollback(Ok::(alice_received_hdx)) - }) - .unwrap(); + assert_eq!(Router::route(asset_pair).unwrap(), route1); - let amount_out_for_inverse_with_chaper_route = with_transaction::<_, _, _>(|| { - let alice_hdx_balance = Currencies::free_balance(HDX, &AccountId::from(ALICE)); - assert_ok!(Router::sell( + //We set the cheaper one so it should replace + assert_ok!(Router::set_route( hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), - DOT, - HDX, - amount_to_sell, - 0, - inverse_route(route2_cheaper.clone()) + asset_pair, + route2_cheaper.clone() )); - let alice_received_hdx = Currencies::free_balance(HDX, &AccountId::from(ALICE)) - alice_hdx_balance; - - TransactionOutcome::Rollback(Ok::(alice_received_hdx)) - }) - .unwrap(); - - assert!(amount_out_for_inverse_with_chaper_route > amount_out_for_inverse); - - //ACT AND ASSERT - - //We set first the more expensive route - assert_ok!(Router::set_route( - hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), - asset_pair, - route1.clone() - )); - assert_eq!(Router::route(asset_pair).unwrap(), route1); - - //We set the cheaper one so it should replace - assert_ok!(Router::set_route( - hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), - asset_pair, - route2_cheaper.clone() - )); - assert_eq!(Router::route(asset_pair).unwrap(), route2_cheaper); - - //We try to set back the more expensive but did not replace - assert_noop!( - Router::set_route(hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), asset_pair, route1), - pallet_route_executor::Error::::RouteUpdateIsNotSuccessful - ); - assert_eq!(Router::route(asset_pair).unwrap(), route2_cheaper); + assert_eq!(Router::route(asset_pair).unwrap(), route2_cheaper); + + //We try to set back the more expensive but did not replace + assert_noop!( + Router::set_route(hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), asset_pair, route1), + pallet_route_executor::Error::::RouteUpdateIsNotSuccessful + ); + assert_eq!(Router::route(asset_pair).unwrap(), route2_cheaper); + TransactionOutcome::Commit(DispatchResult::Ok(())) + }); }); } } @@ -2946,75 +2984,78 @@ mod with_on_chain_and_default_route { TestNet::reset(); Hydra::execute_with(|| { - //Arrange - let (pool_id, stable_asset_1, _) = init_stableswap().unwrap(); - - init_omnipool(); + let _ = with_transaction(|| { + //Arrange + let (pool_id, stable_asset_1, _) = init_stableswap().unwrap(); - assert_ok!(Currencies::update_balance( - hydradx_runtime::RuntimeOrigin::root(), - Omnipool::protocol_account(), - pool_id, - 3000 * UNITS as i128, - )); + init_omnipool(); - assert_ok!(hydradx_runtime::Omnipool::add_token( - hydradx_runtime::RuntimeOrigin::root(), - pool_id, - FixedU128::from_rational(1, 2), - Permill::from_percent(1), - AccountId::from(BOB), - )); + assert_ok!(Currencies::update_balance( + hydradx_runtime::RuntimeOrigin::root(), + Omnipool::protocol_account(), + pool_id, + 3000 * UNITS as i128, + )); - create_xyk_pool_with_amounts(DOT, 1000 * UNITS, stable_asset_1, 1000 * UNITS); + assert_ok!(hydradx_runtime::Omnipool::add_token( + hydradx_runtime::RuntimeOrigin::root(), + pool_id, + FixedU128::from_rational(1, 2), + Permill::from_percent(1), + AccountId::from(BOB), + )); - let route1 = vec![ - Trade { - pool: PoolType::Omnipool, - asset_in: HDX, - asset_out: pool_id, - }, - Trade { - pool: PoolType::Stableswap(pool_id), - asset_in: pool_id, - asset_out: stable_asset_1, - }, - Trade { - pool: PoolType::XYK, - asset_in: stable_asset_1, - asset_out: DOT, - }, - ]; + create_xyk_pool_with_amounts(DOT, 1000 * UNITS, stable_asset_1, 1000 * UNITS); - let asset_pair = Pair::new(HDX, DOT); - let amount_to_buy = 100 * UNITS; + let route1 = vec![ + Trade { + pool: PoolType::Omnipool, + asset_in: HDX, + asset_out: pool_id, + }, + Trade { + pool: PoolType::Stableswap(pool_id), + asset_in: pool_id, + asset_out: stable_asset_1, + }, + Trade { + pool: PoolType::XYK, + asset_in: stable_asset_1, + asset_out: DOT, + }, + ]; - assert_ok!(Router::set_route( - hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), - asset_pair, - route1.clone() - )); - assert_eq!(Router::route(asset_pair).unwrap(), route1); + let asset_pair = Pair::new(HDX, DOT); + let amount_to_buy = 100 * UNITS; - //Act - assert_ok!(Currencies::update_balance( - hydradx_runtime::RuntimeOrigin::root(), - ALICE.into(), - HDX, - 100000 * UNITS as i128, - )); + assert_ok!(Router::set_route( + hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), + asset_pair, + route1.clone() + )); + assert_eq!(Router::route(asset_pair).unwrap(), route1); - assert_balance!(ALICE.into(), DOT, ALICE_INITIAL_DOT_BALANCE); - assert_ok!(Router::buy( - RuntimeOrigin::signed(ALICE.into()), - HDX, - DOT, - amount_to_buy, - u128::MAX, - vec![], - )); + //Act + assert_ok!(Currencies::update_balance( + hydradx_runtime::RuntimeOrigin::root(), + ALICE.into(), + HDX, + 100000 * UNITS as i128, + )); + + assert_balance!(ALICE.into(), DOT, ALICE_INITIAL_DOT_BALANCE); + assert_ok!(Router::buy( + RuntimeOrigin::signed(ALICE.into()), + HDX, + DOT, + amount_to_buy, + u128::MAX, + vec![], + )); - assert_balance!(ALICE.into(), DOT, ALICE_INITIAL_DOT_BALANCE + amount_to_buy); + assert_balance!(ALICE.into(), DOT, ALICE_INITIAL_DOT_BALANCE + amount_to_buy); + TransactionOutcome::Commit(DispatchResult::Ok(())) + }); }); } @@ -3023,68 +3064,71 @@ mod with_on_chain_and_default_route { TestNet::reset(); Hydra::execute_with(|| { - //Arrange - let (pool_id, stable_asset_1, _) = init_stableswap().unwrap(); + let _ = with_transaction(|| { + //Arrange + let (pool_id, stable_asset_1, _) = init_stableswap().unwrap(); - init_omnipool(); + init_omnipool(); - assert_ok!(Currencies::update_balance( - hydradx_runtime::RuntimeOrigin::root(), - Omnipool::protocol_account(), - pool_id, - 3000 * UNITS as i128, - )); + assert_ok!(Currencies::update_balance( + hydradx_runtime::RuntimeOrigin::root(), + Omnipool::protocol_account(), + pool_id, + 3000 * UNITS as i128, + )); - assert_ok!(hydradx_runtime::Omnipool::add_token( - hydradx_runtime::RuntimeOrigin::root(), - pool_id, - FixedU128::from_rational(1, 2), - Permill::from_percent(1), - AccountId::from(BOB), - )); + assert_ok!(hydradx_runtime::Omnipool::add_token( + hydradx_runtime::RuntimeOrigin::root(), + pool_id, + FixedU128::from_rational(1, 2), + Permill::from_percent(1), + AccountId::from(BOB), + )); - create_xyk_pool_with_amounts(DOT, 1000 * UNITS, stable_asset_1, 1000 * UNITS); + create_xyk_pool_with_amounts(DOT, 1000 * UNITS, stable_asset_1, 1000 * UNITS); - let route1 = vec![ - Trade { - pool: PoolType::Omnipool, - asset_in: HDX, - asset_out: pool_id, - }, - Trade { - pool: PoolType::Stableswap(pool_id), - asset_in: pool_id, - asset_out: stable_asset_1, - }, - Trade { - pool: PoolType::XYK, - asset_in: stable_asset_1, - asset_out: DOT, - }, - ]; + let route1 = vec![ + Trade { + pool: PoolType::Omnipool, + asset_in: HDX, + asset_out: pool_id, + }, + Trade { + pool: PoolType::Stableswap(pool_id), + asset_in: pool_id, + asset_out: stable_asset_1, + }, + Trade { + pool: PoolType::XYK, + asset_in: stable_asset_1, + asset_out: DOT, + }, + ]; - let asset_pair = Pair::new(HDX, DOT); - let amount_to_sell = 100 * UNITS; + let asset_pair = Pair::new(HDX, DOT); + let amount_to_sell = 100 * UNITS; - assert_ok!(Router::set_route( - hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), - asset_pair, - route1.clone() - )); - assert_eq!(Router::route(asset_pair).unwrap(), route1); + assert_ok!(Router::set_route( + hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), + asset_pair, + route1.clone() + )); + assert_eq!(Router::route(asset_pair).unwrap(), route1); - //Act - assert_balance!(ALICE.into(), HDX, ALICE_INITIAL_NATIVE_BALANCE); - assert_ok!(Router::sell( - RuntimeOrigin::signed(ALICE.into()), - HDX, - DOT, - amount_to_sell, - 0, - vec![], - )); + //Act + assert_balance!(ALICE.into(), HDX, ALICE_INITIAL_NATIVE_BALANCE); + assert_ok!(Router::sell( + RuntimeOrigin::signed(ALICE.into()), + HDX, + DOT, + amount_to_sell, + 0, + vec![], + )); - assert_balance!(ALICE.into(), HDX, ALICE_INITIAL_NATIVE_BALANCE - amount_to_sell); + assert_balance!(ALICE.into(), HDX, ALICE_INITIAL_NATIVE_BALANCE - amount_to_sell); + TransactionOutcome::Commit(DispatchResult::Ok(())) + }); }); } @@ -3093,68 +3137,71 @@ mod with_on_chain_and_default_route { TestNet::reset(); Hydra::execute_with(|| { - //Arrange - let (pool_id, stable_asset_1, _) = init_stableswap().unwrap(); + let _ = with_transaction(|| { + //Arrange + let (pool_id, stable_asset_1, _) = init_stableswap().unwrap(); - init_omnipool(); + init_omnipool(); - assert_ok!(Currencies::update_balance( - hydradx_runtime::RuntimeOrigin::root(), - Omnipool::protocol_account(), - pool_id, - 3000 * UNITS as i128, - )); + assert_ok!(Currencies::update_balance( + hydradx_runtime::RuntimeOrigin::root(), + Omnipool::protocol_account(), + pool_id, + 3000 * UNITS as i128, + )); - assert_ok!(hydradx_runtime::Omnipool::add_token( - hydradx_runtime::RuntimeOrigin::root(), - pool_id, - FixedU128::from_rational(1, 2), - Permill::from_percent(1), - AccountId::from(BOB), - )); + assert_ok!(hydradx_runtime::Omnipool::add_token( + hydradx_runtime::RuntimeOrigin::root(), + pool_id, + FixedU128::from_rational(1, 2), + Permill::from_percent(1), + AccountId::from(BOB), + )); - create_xyk_pool_with_amounts(DOT, 1000 * UNITS, stable_asset_1, 1000 * UNITS); + create_xyk_pool_with_amounts(DOT, 1000 * UNITS, stable_asset_1, 1000 * UNITS); - let route1 = vec![ - Trade { - pool: PoolType::Omnipool, - asset_in: HDX, - asset_out: pool_id, - }, - Trade { - pool: PoolType::Stableswap(pool_id), - asset_in: pool_id, - asset_out: stable_asset_1, - }, - Trade { - pool: PoolType::XYK, - asset_in: stable_asset_1, - asset_out: DOT, - }, - ]; + let route1 = vec![ + Trade { + pool: PoolType::Omnipool, + asset_in: HDX, + asset_out: pool_id, + }, + Trade { + pool: PoolType::Stableswap(pool_id), + asset_in: pool_id, + asset_out: stable_asset_1, + }, + Trade { + pool: PoolType::XYK, + asset_in: stable_asset_1, + asset_out: DOT, + }, + ]; - let asset_pair = Pair::new(HDX, DOT); - let amount_to_sell = 100 * UNITS; + let asset_pair = Pair::new(HDX, DOT); + let amount_to_sell = 100 * UNITS; - assert_ok!(Router::set_route( - hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), - asset_pair, - route1.clone() - )); - assert_eq!(Router::route(asset_pair).unwrap(), route1); + assert_ok!(Router::set_route( + hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), + asset_pair, + route1.clone() + )); + assert_eq!(Router::route(asset_pair).unwrap(), route1); - //Act - assert_balance!(ALICE.into(), HDX, ALICE_INITIAL_NATIVE_BALANCE); - assert_ok!(Router::sell( - RuntimeOrigin::signed(ALICE.into()), - DOT, - HDX, - amount_to_sell, - 0, - vec![], - )); + //Act + assert_balance!(ALICE.into(), HDX, ALICE_INITIAL_NATIVE_BALANCE); + assert_ok!(Router::sell( + RuntimeOrigin::signed(ALICE.into()), + DOT, + HDX, + amount_to_sell, + 0, + vec![], + )); - assert_balance!(ALICE.into(), DOT, ALICE_INITIAL_DOT_BALANCE - amount_to_sell); + assert_balance!(ALICE.into(), DOT, ALICE_INITIAL_DOT_BALANCE - amount_to_sell); + TransactionOutcome::Commit(DispatchResult::Ok(())) + }); }); } @@ -3373,8 +3420,16 @@ pub fn init_stableswap_with_liquidity( let mut asset_ids: Vec<::AssetId> = Vec::new(); for idx in 0u32..MAX_ASSETS_IN_POOL { let name: Vec = idx.to_ne_bytes().to_vec(); - let asset_id = AssetRegistry::create_asset(&name, 1u128)?; - AssetRegistry::set_metadata(hydradx_runtime::RuntimeOrigin::root(), asset_id, b"xDUM".to_vec(), 18u8)?; + let asset_id = AssetRegistry::register_sufficient_asset( + None, + Some(name.try_into().unwrap()), + AssetKind::Token, + 1u128, + Some(b"xDUM".to_vec().try_into().unwrap()), + Some(18u8), + None, + None, + )?; asset_ids.push(asset_id); Currencies::update_balance( @@ -3393,7 +3448,16 @@ pub fn init_stableswap_with_liquidity( initial.push(AssetAmount::new(asset_id, initial_liquidity)); added_liquidity.push(AssetAmount::new(asset_id, liquidity_added)); } - let pool_id = AssetRegistry::create_asset(&b"pool".to_vec(), 1u128)?; + let pool_id = AssetRegistry::register_sufficient_asset( + None, + Some(b"pool".to_vec().try_into().unwrap()), + AssetKind::Token, + 1u128, + None, + None, + None, + None, + )?; let amplification = 100u16; let fee = Permill::from_percent(1); diff --git a/integration-tests/src/staking.rs b/integration-tests/src/staking.rs index 3f9bbab29..32e200ff3 100644 --- a/integration-tests/src/staking.rs +++ b/integration-tests/src/staking.rs @@ -664,6 +664,7 @@ fn democracy_vote_should_work_correctly_when_account_has_no_stake() { fn democracy_remote_vote_should_work_correctly_when_account_has_no_stake() { TestNet::reset(); Hydra::execute_with(|| { + System::set_block_number(0); init_omnipool(); assert_ok!(Staking::initialize_staking(RawOrigin::Root.into())); @@ -698,6 +699,7 @@ fn democracy_remote_vote_should_work_correctly_when_account_has_no_stake() { fn staking_position_transfer_should_fail_when_origin_is_owner() { TestNet::reset(); Hydra::execute_with(|| { + System::set_block_number(1); init_omnipool(); assert_ok!(Staking::initialize_staking(RawOrigin::Root.into())); @@ -743,6 +745,7 @@ fn staking_position_transfer_should_fail_when_origin_is_owner() { fn thaw_staking_position_should_fail_when_origin_is_position_owner() { TestNet::reset(); Hydra::execute_with(|| { + System::set_block_number(1); init_omnipool(); assert_ok!(Staking::initialize_staking(RawOrigin::Root.into())); @@ -787,6 +790,7 @@ fn thaw_staking_position_should_fail_when_origin_is_position_owner() { fn thaw_staking_collection_should_fail_when_origin_is_not_pallet_account() { TestNet::reset(); Hydra::execute_with(|| { + System::set_block_number(1); init_omnipool(); assert_ok!(Staking::initialize_staking(RawOrigin::Root.into())); @@ -824,6 +828,7 @@ fn thaw_staking_collection_should_fail_when_origin_is_not_pallet_account() { fn stake_should_fail_when_tokens_are_vested() { TestNet::reset(); Hydra::execute_with(|| { + System::set_block_number(1); init_omnipool(); assert_ok!(Staking::initialize_staking(RawOrigin::Root.into())); @@ -860,6 +865,7 @@ fn stake_should_fail_when_tokens_are_vested() { fn stake_should_fail_when_tokens_are_already_staked() { TestNet::reset(); Hydra::execute_with(|| { + System::set_block_number(1); init_omnipool(); assert_ok!(Staking::initialize_staking(RawOrigin::Root.into())); diff --git a/integration-tests/src/xcm_rate_limiter.rs b/integration-tests/src/xcm_rate_limiter.rs index a1c21763f..5c5fc6725 100644 --- a/integration-tests/src/xcm_rate_limiter.rs +++ b/integration-tests/src/xcm_rate_limiter.rs @@ -3,8 +3,8 @@ use crate::polkadot_test_net::*; use frame_support::{assert_ok, pallet_prelude::Weight}; +use hydradx_traits::registry::Mutate; use orml_traits::currency::MultiCurrency; -use pallet_asset_registry::AssetType; use polkadot_xcm::prelude::*; use xcm_emulator::TestExt; @@ -26,7 +26,6 @@ fn xcm_rate_limiter_should_limit_aca_when_limit_is_exceeded() { Hydra::execute_with(|| { assert_ok!(hydradx_runtime::AssetRegistry::set_location( - hydradx_runtime::RuntimeOrigin::root(), ACA, hydradx_runtime::AssetLocation(MultiLocation::new(1, X2(Parachain(ACALA_PARA_ID), GeneralIndex(0)))) )); @@ -35,10 +34,14 @@ fn xcm_rate_limiter_should_limit_aca_when_limit_is_exceeded() { assert_ok!(hydradx_runtime::AssetRegistry::update( hydradx_runtime::RuntimeOrigin::root(), ACA, - b"ACA".to_vec(), - AssetType::Token, + None, + None, None, Some(50 * UNITS), + None, + None, + None, + None )); assert_eq!(hydradx_runtime::Tokens::free_balance(ACA, &AccountId::from(BOB)), 0); @@ -109,7 +112,6 @@ fn xcm_rate_limiter_should_not_limit_aca_when_limit_is_not_exceeded() { Hydra::execute_with(|| { assert_ok!(hydradx_runtime::AssetRegistry::set_location( - hydradx_runtime::RuntimeOrigin::root(), ACA, hydradx_runtime::AssetLocation(MultiLocation::new(1, X2(Parachain(ACALA_PARA_ID), GeneralIndex(0)))) )); @@ -118,10 +120,14 @@ fn xcm_rate_limiter_should_not_limit_aca_when_limit_is_not_exceeded() { assert_ok!(hydradx_runtime::AssetRegistry::update( hydradx_runtime::RuntimeOrigin::root(), ACA, - b"ACA".to_vec(), - AssetType::Token, + None, + None, None, Some(101 * UNITS), + None, + None, + None, + None )); }); @@ -168,7 +174,6 @@ fn deferred_messages_should_be_executable_by_root() { Hydra::execute_with(|| { assert_ok!(hydradx_runtime::AssetRegistry::set_location( - hydradx_runtime::RuntimeOrigin::root(), ACA, hydradx_runtime::AssetLocation(MultiLocation::new(1, X2(Parachain(ACALA_PARA_ID), GeneralIndex(0)))) )); @@ -177,10 +182,14 @@ fn deferred_messages_should_be_executable_by_root() { assert_ok!(hydradx_runtime::AssetRegistry::update( hydradx_runtime::RuntimeOrigin::root(), ACA, - b"ACA".to_vec(), - AssetType::Token, + None, + None, None, Some(50 * UNITS), + None, + None, + None, + None )); assert_eq!(hydradx_runtime::Tokens::free_balance(ACA, &AccountId::from(BOB)), 0); diff --git a/node/Cargo.toml b/node/Cargo.toml index c5591126c..d246a8cd5 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hydradx" -version = "12.0.0" +version = "12.1.0" description = "HydraDX node" authors = ["GalacticCouncil"] edition = "2021" diff --git a/node/src/chain_spec/local.rs b/node/src/chain_spec/local.rs index aa9030959..38246ddd4 100644 --- a/node/src/chain_spec/local.rs +++ b/node/src/chain_spec/local.rs @@ -81,8 +81,24 @@ pub fn parachain_config() -> Result { vec![], // registered assets vec![ - (b"KSM".to_vec(), 1_000u128, Some(1)), - (b"KUSD".to_vec(), 1_000u128, Some(2)), + ( + Some(1), + Some(b"KSM".to_vec().try_into().expect("Name is too long")), + 1_000u128, + None, + None, + None, + true, + ), + ( + Some(2), + Some(b"KUSD".to_vec().try_into().expect("Name is too long")), + 1_000u128, + None, + None, + None, + true, + ), ], // accepted assets vec![(1, Price::from_float(0.0000212)), (2, Price::from_float(0.000806))], diff --git a/node/src/chain_spec/mod.rs b/node/src/chain_spec/mod.rs index a47255ac8..a9e1ff8cb 100644 --- a/node/src/chain_spec/mod.rs +++ b/node/src/chain_spec/mod.rs @@ -30,8 +30,8 @@ use hex_literal::hex; use hydradx_runtime::{ pallet_claims::EthereumAddress, AccountId, AssetRegistryConfig, AuraId, Balance, BalancesConfig, ClaimsConfig, CollatorSelectionConfig, CouncilConfig, DusterConfig, ElectionsConfig, GenesisHistoryConfig, - MultiTransactionPaymentConfig, ParachainInfoConfig, RuntimeGenesisConfig, SessionConfig, Signature, SystemConfig, - TechnicalCommitteeConfig, TokensConfig, VestingConfig, WASM_BINARY, + MultiTransactionPaymentConfig, ParachainInfoConfig, RegistryStrLimit, RuntimeGenesisConfig, SessionConfig, + Signature, SystemConfig, TechnicalCommitteeConfig, TokensConfig, VestingConfig, WASM_BINARY, }; use primitives::{ constants::currency::{NATIVE_EXISTENTIAL_DEPOSIT, UNITS}, @@ -42,7 +42,10 @@ use sc_service::ChainType; use serde::{Deserialize, Serialize}; use serde_json::map::Map; use sp_core::{crypto::UncheckedInto, sr25519, Pair, Public}; -use sp_runtime::traits::{IdentifyAccount, Verify}; +use sp_runtime::{ + traits::{IdentifyAccount, Verify}, + BoundedVec, +}; const PARA_ID: u32 = 2034; const TOKEN_DECIMALS: u8 = 12; @@ -89,6 +92,7 @@ where AccountPublic::from(get_from_seed::(seed)).into_account() } +#[allow(clippy::type_complexity)] pub fn parachain_genesis( wasm_binary: &[u8], _root_key: AccountId, @@ -97,7 +101,15 @@ pub fn parachain_genesis( council_members: Vec, tech_committee_members: Vec, vesting_list: Vec<(AccountId, BlockNumber, BlockNumber, u32, Balance)>, - registered_assets: Vec<(Vec, Balance, Option)>, // (Asset name, Existential deposit, Chosen asset id) + registered_assets: Vec<( + Option, + Option>, + Balance, + Option>, + Option, + Option, + bool, + )>, // (asset_id, name, existential deposit, symbol, decimals, xcm_rate_limit, is_sufficient) accepted_assets: Vec<(AssetId, Price)>, // (Asset id, Fallback price) - asset which fee can be paid with token_balances: Vec<(AccountId, Vec<(AssetId, Balance)>)>, claims_data: Vec<(EthereumAddress, Balance)>, @@ -149,8 +161,18 @@ pub fn parachain_genesis( vesting: VestingConfig { vesting: vesting_list }, asset_registry: AssetRegistryConfig { registered_assets: registered_assets.clone(), - native_asset_name: TOKEN_SYMBOL.as_bytes().to_vec(), + native_asset_name: TOKEN_SYMBOL + .as_bytes() + .to_vec() + .try_into() + .expect("Native asset name is too long."), native_existential_deposit: NATIVE_EXISTENTIAL_DEPOSIT, + native_symbol: TOKEN_SYMBOL + .as_bytes() + .to_vec() + .try_into() + .expect("Native symbol is too long."), + native_decimals: TOKEN_DECIMALS, }, multi_transaction_payment: MultiTransactionPaymentConfig { currencies: accepted_assets, diff --git a/pallets/asset-registry/Cargo.toml b/pallets/asset-registry/Cargo.toml index 13a9788ae..5d1d802ae 100644 --- a/pallets/asset-registry/Cargo.toml +++ b/pallets/asset-registry/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-asset-registry" -version = "2.3.3" +version = "3.0.0" description = "Pallet for asset registry management" authors = ["GalacticCouncil"] edition = "2021" @@ -39,9 +39,11 @@ frame-benchmarking = { workspace = true, optional = true } sp-api = { workspace = true, optional = true } [dev-dependencies] +orml-tokens = { workspace = true } sp-io = { workspace = true } polkadot-xcm = { workspace = true } test-utils = { workspace = true } +pretty_assertions = "1.2.1" [features] default = ["std"] @@ -63,6 +65,7 @@ std = [ "frame-benchmarking/std", "scale-info/std", "polkadot-xcm/std", + "orml-tokens/std", ] try-runtime = ["frame-support/try-runtime"] diff --git a/pallets/asset-registry/README.md b/pallets/asset-registry/README.md index 73e676aaa..170b522e5 100644 --- a/pallets/asset-registry/README.md +++ b/pallets/asset-registry/README.md @@ -8,22 +8,17 @@ Asset registry provides functionality to create, store and keep tracking of exis - **CoreAssetId** - asset id of native/core asset. Usually 0. - **NextAssetId** - asset id to be assigned for next asset added to the system. - **AssetIds** - list of existing asset ids -- **AssetDetail** - details of an asset such as type, name or whether it is locked or not. -- **AssetMetadata** - additional optional metadata of an asset ( symbol, decimals) +- **AssetDetail** - details of an asset such as type, name, symbol, decimals. - **AssetLocation** - information of native location of an asset. Used in XCM. ### Implementation detail For each newly registered asset, a sequential id is assigned to that asset. This id identifies the asset and can be used directly in transfers or any other operation which works with an asset ( without performing any additioanl asset check or asset retrieval). -There is a mapping between the name and asset id stored as well, which helps and is used in AMM Implementation where there is a need to register a pool asset and only name is provided ( see `get_or_create_asset` ). +There is a mapping between the name and asset id stored as well, which helps and is used in AMM Implementation where there is a need to register a pool asset and only name is provided. An asset has additional details stored on chain such as name and type. -Optional metadata can be also set for an asset. - The registry pallet supports storing of native location of an asset. This can be used in XCM where it is possible to create mapping between native location and local system asset ids. -### Interface -- `get_or_create_asset` - creates new asset id for give asset name. If such asset already exists, it returns the corresponding asset id. - +The registry pallet implements single ppermissionles extrinsic `register_external` that collects storage deposit for created asset. diff --git a/pallets/asset-registry/src/benchmarking.rs b/pallets/asset-registry/src/benchmarking.rs index 4f92be61e..49141b4c2 100644 --- a/pallets/asset-registry/src/benchmarking.rs +++ b/pallets/asset-registry/src/benchmarking.rs @@ -19,115 +19,122 @@ use super::*; -use frame_benchmarking::benchmarks; +use crate::types::AssetDetails; +use frame_benchmarking::{account, benchmarks}; +use frame_support::traits::tokens::fungibles::Mutate as FungiblesMutate; use frame_system::RawOrigin; - -use crate::types::Metadata; - use sp_std::vec; benchmarks! { - register{ - let name = vec![1; T::StringLimit::get() as usize]; - let ed = T::Balance::from(1_000_000u32); - - let symbol = vec![1; T::StringLimit::get() as usize]; - - let metadata = Metadata { - symbol, - decimals: 100, - }; + where_clause { where + T::Currency: FungiblesMutate, + T: crate::pallet::Config, + } - }: _(RawOrigin::Root, name.clone(), AssetType::Token, ed, None, Some(metadata), Some(Default::default()), None) + register { + let asset_id= T::AssetId::from(3); + let name: BoundedVec = vec![97u8; T::StringLimit::get() as usize].try_into().unwrap(); + let ed = 1_000_000_u128; + let symbol: BoundedVec = vec![97u8; T::StringLimit::get() as usize].try_into().unwrap(); + let decimals = 12_u8; + let location: T::AssetNativeLocation = Default::default(); + let xcm_rate_limit = 1_000_u128; + let is_sufficient = true; + + }: _(RawOrigin::Root, Some(asset_id), Some(name.clone()), AssetType::Token, Some(ed), Some(symbol), Some(decimals), Some(location), Some(xcm_rate_limit), is_sufficient) verify { - let bname = crate::Pallet::::to_bounded_name(name).unwrap(); - assert!(crate::Pallet::::asset_ids(bname).is_some()); + assert!(Pallet::::asset_ids(name).is_some()); + + assert!(Pallet::::assets(asset_id).is_some()); } - update{ - let name = b"NAME".to_vec(); - let ed = T::Balance::from(1_000_000u32); - let asset_id = T::AssetId::from(10u8); - let _ = crate::Pallet::::register(RawOrigin::Root.into(), name, AssetType::Token, ed, Some(asset_id), None, None, None); + update { + let asset_id = T::AssetId::from(3); + let name = vec![97u8; T::StringLimit::get() as usize].try_into().unwrap(); + let ed = 1_000_000_u128; + let symbol = vec![97u8; T::StringLimit::get() as usize].try_into().unwrap(); + let decimals = 12_u8; + let location: T::AssetNativeLocation = Default::default(); + let xcm_rate_limit = 1_000_u128; + let is_sufficient = false; - let new_name= vec![1; T::StringLimit::get() as usize]; + let _ = Pallet::::register(RawOrigin::Root.into(), Some(asset_id), Some(name), AssetType::Token, Some(ed), Some(symbol), Some(decimals), Some(location), Some(xcm_rate_limit), is_sufficient); - let new_ed = T::Balance::from(2_000_000u32); + let new_name:BoundedVec = vec![98u8; T::StringLimit::get() as usize].try_into().unwrap(); + let new_type = AssetType::XYK; + let new_ed = 1_000_000_u128; + let new_xcm_rate_limit = 1_000_u128; + let new_is_sufficient = true; + let new_symbol: BoundedVec = vec![98u8; T::StringLimit::get() as usize].try_into().unwrap(); + let new_decimals = 12_u8; - let rate_limit = T::Balance::from(10_000_000u32); - }: _(RawOrigin::Root, asset_id, new_name.clone(), AssetType::PoolShare(T::AssetId::from(10u8),T::AssetId::from(20u8)), Some(new_ed), Some(rate_limit)) + }: _(RawOrigin::Root, asset_id, Some(new_name.clone()), Some(new_type), Some(new_ed), Some(new_xcm_rate_limit), Some(new_is_sufficient), Some(new_symbol.clone()), Some(new_decimals), Some(Default::default())) verify { - let bname = crate::Pallet::::to_bounded_name(new_name).unwrap(); - assert_eq!(crate::Pallet::::asset_ids(&bname), Some(asset_id)); - - let stored = crate::Pallet::::assets(asset_id); + assert_eq!(Pallet::::asset_ids(&new_name), Some(asset_id)); - assert!(stored.is_some()); - let stored = stored.unwrap(); - - let expected = AssetDetails{ - asset_type: AssetType::PoolShare(T::AssetId::from(10u8), T::AssetId::from(20u8)), + assert_eq!(crate::Pallet::::assets(asset_id), Some(AssetDetails { + name: Some(new_name), + asset_type: new_type, existential_deposit: new_ed, - name: bname, - xcm_rate_limit: Some(rate_limit), - }; - - assert_eq!(stored.asset_type, expected.asset_type); - assert_eq!(stored.existential_deposit, expected.existential_deposit); - assert_eq!(stored.name.to_vec(), expected.name.to_vec()); + symbol: Some(new_symbol), + decimals: Some(new_decimals), + xcm_rate_limit: Some(xcm_rate_limit), + is_sufficient: new_is_sufficient, + })); } - set_metadata{ - let name = b"NAME".to_vec(); - let bname = crate::Pallet::::to_bounded_name(name.clone()).unwrap(); - let ed = T::Balance::from(1_000_000u32); - let _ = crate::Pallet::::register(RawOrigin::Root.into(), name, AssetType::Token, ed, None, None, None, None); + register_external { + let caller: T::AccountId = account("caller", 0, 1); - let asset_id = crate::Pallet::::asset_ids(bname).unwrap(); + let expected_asset_id = Pallet::::next_asset_id().unwrap(); + let location: T::AssetNativeLocation = Default::default(); - let max_symbol = vec![1; T::StringLimit::get() as usize]; - - }: _(RawOrigin::Root, asset_id, max_symbol.clone(), 10u8) + assert!(Pallet::::location_assets(location.clone()).is_none()); + }: _(RawOrigin::Signed(caller), location.clone()) verify { - let bsymbol= crate::Pallet::::to_bounded_name(max_symbol).unwrap(); - - let stored = crate::Pallet::::asset_metadata(asset_id); - - assert!(stored.is_some()); + assert_eq!(Pallet::::locations(expected_asset_id), Some(location.clone())); + assert_eq!(Pallet::::location_assets(location), Some(expected_asset_id)); + } - let stored = stored.unwrap(); + ban_asset { + let asset_id = T::AssetId::from(3); + let name = vec![97u8; T::StringLimit::get() as usize].try_into().unwrap(); + let ed = 1_000_000_u128; + let symbol = vec![97u8; T::StringLimit::get() as usize].try_into().unwrap(); + let decimals = 12_u8; + let location: T::AssetNativeLocation = Default::default(); + let xcm_rate_limit = 1_000_u128; + let is_sufficient = true; - let expected =AssetMetadata{ - symbol: bsymbol, - decimals: 10u8 - }; + let _ = Pallet::::register(RawOrigin::Root.into(), Some(asset_id), Some(name), AssetType::Token, Some(ed), Some(symbol), Some(decimals), Some(location), Some(xcm_rate_limit), is_sufficient); - assert_eq!(stored.symbol.to_vec(), expected.symbol.to_vec()); - assert_eq!(stored.decimals, expected.decimals); + let origin = T::UpdateOrigin::try_successful_origin().unwrap(); + }: _(origin, asset_id) + verify { + assert_eq!(Pallet::::banned_assets(asset_id), Some(())); } - set_location{ - let name = b"NAME".to_vec(); - let ed = T::Balance::from(1_000_000u32); - let asset_id = T::AssetId::from(10u8); - let _ = crate::Pallet::::register(RawOrigin::Root.into(), name.clone(), AssetType::Token, ed, Some(asset_id), None, None, None); - - }: _(RawOrigin::Root, asset_id, Default::default()) + unban_asset { + let asset_id = T::AssetId::from(3); + let name = vec![97u8; T::StringLimit::get() as usize].try_into().unwrap(); + let ed = 1_000_000_u128; + let symbol = vec![97u8; T::StringLimit::get() as usize].try_into().unwrap(); + let decimals = 12_u8; + let location: T::AssetNativeLocation = Default::default(); + let xcm_rate_limit = 1_000_u128; + let is_sufficient = true; + + let origin = T::UpdateOrigin::try_successful_origin().unwrap(); + let _ = Pallet::::register(RawOrigin::Root.into(), Some(asset_id), Some(name), AssetType::Token, Some(ed), Some(symbol), Some(decimals), Some(location), Some(xcm_rate_limit), is_sufficient); + let _ = Pallet::::ban_asset(origin.clone(), asset_id); + + assert_eq!(Pallet::::banned_assets(asset_id), Some(())); + }: _(origin, asset_id) verify { - let bname = crate::Pallet::::to_bounded_name(name).unwrap(); - let bsymbol= crate::Pallet::::to_bounded_name(b"SYMBOL".to_vec()).unwrap(); - - assert_eq!(crate::Pallet::::locations(asset_id), Some(Default::default())); - assert_eq!(crate::Pallet::::location_assets(T::AssetNativeLocation::default()), Some(asset_id)); + assert_eq!(Pallet::::banned_assets(asset_id), None); } -} -#[cfg(test)] -mod tests { - use super::Pallet; - use crate::mock::*; - use frame_benchmarking::impl_benchmark_test_suite; - impl_benchmark_test_suite!(Pallet, super::ExtBuilder::default().build(), super::Test); + impl_benchmark_test_suite!(Pallet, crate::tests::mock::ExtBuilder::default().build(), crate::tests::mock::Test); } diff --git a/pallets/asset-registry/src/lib.rs b/pallets/asset-registry/src/lib.rs index c32b11d64..c91188006 100644 --- a/pallets/asset-registry/src/lib.rs +++ b/pallets/asset-registry/src/lib.rs @@ -18,7 +18,9 @@ #![cfg_attr(not(feature = "std"), no_std)] use frame_support::pallet_prelude::*; +use frame_support::require_transactional; use frame_support::sp_runtime::traits::CheckedAdd; +use frame_support::traits::tokens::fungibles::{Inspect as FungiblesInspect, Mutate as FungiblesMutate}; use frame_system::pallet_prelude::*; use scale_info::TypeInfo; use sp_arithmetic::traits::BaseArithmetic; @@ -26,9 +28,6 @@ use sp_runtime::DispatchError; use sp_std::convert::TryInto; use sp_std::vec::Vec; -#[cfg(test)] -mod mock; - #[cfg(test)] mod tests; @@ -44,20 +43,29 @@ pub use types::AssetType; // Re-export pallet items so that they can be accessed from the crate namespace. pub use pallet::*; -pub use crate::types::{AssetDetails, AssetMetadata}; +pub use crate::types::{AssetDetails, Balance, Name, Symbol}; +use frame_support::storage::with_transaction; use frame_support::BoundedVec; -use hydradx_traits::{AssetKind, CreateRegistry, InspectRegistry, Registry, ShareTokenRegistry}; +use hydradx_traits::{ + registry::{Create, Inspect, Mutate}, + AssetKind, +}; +use sp_runtime::TransactionOutcome; + +/// Default value of existential deposit. This value is used if existential deposit wasn't +/// provided. +pub const DEFAULT_ED: Balance = 1; #[frame_support::pallet] +#[allow(clippy::too_many_arguments)] pub mod pallet { + use sp_std::fmt::Debug; + use super::*; - use crate::types::Metadata; - use frame_support::sp_runtime::traits::AtLeast32BitUnsigned; - const STORAGE_VERSION: StorageVersion = StorageVersion::new(1); + const STORAGE_VERSION: StorageVersion = StorageVersion::new(2); - pub type AssetDetailsT = - AssetDetails<::AssetId, ::Balance, BoundedVec::StringLimit>>; + pub type AssetDetailsT = AssetDetails<::StringLimit>; #[pallet::config] pub trait Config: frame_system::Config { @@ -66,6 +74,9 @@ pub mod pallet { /// The origin which can work with asset-registry. type RegistryOrigin: EnsureOrigin; + /// The origin which can update assets' detail. + type UpdateOrigin: EnsureOrigin; + /// Asset type type AssetId: Parameter + Member @@ -76,27 +87,27 @@ pub mod pallet { + MaxEncodedLen + TypeInfo; - /// Balance type - type Balance: Parameter - + Member - + AtLeast32BitUnsigned - + Default - + Copy - + MaybeSerializeDeserialize - + MaxEncodedLen; - /// Asset location type type AssetNativeLocation: Parameter + Member + Default + MaxEncodedLen; - /// The maximum length of a name or symbol stored on-chain. - type StringLimit: Get; + /// Multi currency mechanism + type Currency: FungiblesInspect + + FungiblesMutate; #[pallet::constant] type SequentialIdStartAt: Get; - /// Native Asset Id + /// The maximum length of a name or symbol stored on-chain. + #[pallet::constant] + type StringLimit: Get + Debug + PartialEq; + + /// The min length of a name or symbol stored on-chain. #[pallet::constant] - type NativeAssetId: Get; + type MinStringLimit: Get + Debug + PartialEq; + + /// Weight multiplier for `register_external` extrinsic + #[pallet::constant] + type RegExternalWeightMultiplier: Get; /// Weight information for the extrinsics type WeightInfo: WeightInfo; @@ -107,7 +118,14 @@ pub mod pallet { pub struct Pallet(_); #[pallet::hooks] - impl Hooks> for Pallet {} + impl Hooks> for Pallet { + fn integrity_test() { + assert!( + T::RegExternalWeightMultiplier::get().ge(&1_u64), + "`T::RegExternalWeightMultiplier` must be greater than zero." + ); + } + } #[pallet::error] pub enum Error { @@ -117,8 +135,11 @@ pub mod pallet { /// Invalid asset name or symbol. AssetNotFound, - /// Invalid asset name or symbol. - TooLong, + /// Length of name or symbol is less than min. length. + TooShort, + + /// Asset's symbol can't contain whitespace characters . + InvalidSymbol, /// Asset ID is not registered in the asset-registry. AssetNotRegistered, @@ -129,24 +150,46 @@ pub mod pallet { /// Incorrect number of assets provided to create shared asset. InvalidSharedAssetLen, - /// Cannot update asset location + /// Cannot update asset location. CannotUpdateLocation, /// Selected asset id is out of reserved range. NotInReservedRange, - /// Location already registered with different asset + /// Location already registered with different asset. LocationAlreadyRegistered, + + /// Origin is forbidden to set/update value. + Forbidden, + + /// Balance too low. + InsufficientBalance, + + /// Sufficient assets can't be changed to insufficient. + ForbiddenSufficiencyChange, + + /// Asset is already banned. + AssetAlreadyBanned, + + /// Asset is not banned. + AssetNotBanned, + } + + #[pallet::type_value] + /// Default value of NextAssetId if storage is empty. + /// 1 is used to offset the native asset with id 0. + pub fn DefaultNextAssetId() -> T::AssetId { + 1.into() } #[pallet::storage] #[pallet::getter(fn assets)] /// Details of an asset. - pub type Assets = StorageMap<_, Twox64Concat, T::AssetId, AssetDetailsT, OptionQuery>; + pub type Assets = StorageMap<_, Blake2_128Concat, T::AssetId, AssetDetailsT, OptionQuery>; #[pallet::storage] /// Next available asset id. This is sequential id assigned for each new registered asset. - pub type NextAssetId = StorageValue<_, T::AssetId, ValueQuery>; + pub type NextAssetId = StorageValue<_, T::AssetId, ValueQuery, DefaultNextAssetId>; #[pallet::storage] #[pallet::getter(fn asset_ids)] @@ -157,7 +200,13 @@ pub mod pallet { #[pallet::storage] #[pallet::getter(fn locations)] /// Native location of an asset. - pub type AssetLocations = StorageMap<_, Twox64Concat, T::AssetId, T::AssetNativeLocation, OptionQuery>; + pub type AssetLocations = + StorageMap<_, Blake2_128Concat, T::AssetId, T::AssetNativeLocation, OptionQuery>; + + #[pallet::storage] + #[pallet::getter(fn banned_assets)] + /// Non-native assets which transfer is banned. + pub type BannedAssets = StorageMap<_, Blake2_128Concat, T::AssetId, (), OptionQuery>; #[pallet::storage] #[pallet::getter(fn location_assets)] @@ -166,82 +215,114 @@ pub mod pallet { StorageMap<_, Blake2_128Concat, T::AssetNativeLocation, T::AssetId, OptionQuery>; #[pallet::storage] - #[pallet::getter(fn asset_metadata)] - /// Metadata of an asset. - pub type AssetMetadataMap = - StorageMap<_, Twox64Concat, T::AssetId, AssetMetadata>, OptionQuery>; + /// Number of accounts that paid existential deposits for insufficient assets. + /// This storage is used by `SufficiencyCheck`. + pub type ExistentialDepositCounter = StorageValue<_, u128, ValueQuery>; #[allow(clippy::type_complexity)] #[pallet::genesis_config] pub struct GenesisConfig { - pub registered_assets: Vec<(Vec, T::Balance, Option)>, - pub native_asset_name: Vec, - pub native_existential_deposit: T::Balance, + //asset_id, name, existential deposit, symbol, decimals, xcm_rate_limit, is_sufficient + pub registered_assets: Vec<( + Option, + Option>, + Balance, + Option>, + Option, + Option, + bool, + )>, + pub native_asset_name: Name, + pub native_existential_deposit: Balance, + pub native_symbol: Symbol, + pub native_decimals: u8, } impl Default for GenesisConfig { fn default() -> Self { GenesisConfig:: { registered_assets: sp_std::vec![], - native_asset_name: b"HDX".to_vec(), - native_existential_deposit: Default::default(), + native_asset_name: b"HDX".to_vec().try_into().expect("Invalid native asset name!"), + native_existential_deposit: DEFAULT_ED, + native_symbol: b"HDX".to_vec().try_into().expect("Invalid native asset symbol!"), + native_decimals: 12, } } } #[pallet::genesis_build] impl BuildGenesisConfig for GenesisConfig { fn build(&self) { - // Register native asset first - // It is to make sure that native is registered as any other asset - let native_asset_name = Pallet::::to_bounded_name(self.native_asset_name.to_vec()) - .map_err(|_| panic!("Invalid native asset name!")) - .unwrap(); - - AssetIds::::insert(&native_asset_name, T::NativeAssetId::get()); - let details = AssetDetails { - name: native_asset_name, - asset_type: AssetType::Token, - existential_deposit: self.native_existential_deposit, - - xcm_rate_limit: None, - }; - - Assets::::insert(T::NativeAssetId::get(), details); - - self.registered_assets.iter().for_each(|(name, ed, id)| { - let bounded_name = Pallet::::to_bounded_name(name.to_vec()) - .map_err(|_| panic!("Invalid asset name!")) - .unwrap(); - let _ = Pallet::::register_asset(bounded_name, AssetType::Token, *ed, *id, None) - .map_err(|_| panic!("Failed to register asset")); + with_transaction(|| { + // Register native asset first + // It is to make sure that native is registered as any other asset + let native_asset_id = T::AssetId::from(0); + AssetIds::::insert(&self.native_asset_name, native_asset_id); + let details = AssetDetails { + name: Some(self.native_asset_name.clone()), + asset_type: AssetType::Token, + existential_deposit: self.native_existential_deposit, + xcm_rate_limit: None, + symbol: Some(self.native_symbol.clone()), + decimals: Some(self.native_decimals), + is_sufficient: true, + }; + + Assets::::insert(native_asset_id, details); + + self.registered_assets.iter().for_each( + |(id, name, ed, symbol, decimals, xcm_rate_limit, is_sufficient)| { + let details = AssetDetails { + name: name.clone(), + asset_type: AssetType::Token, + existential_deposit: *ed, + xcm_rate_limit: *xcm_rate_limit, + symbol: symbol.clone(), + decimals: *decimals, + is_sufficient: *is_sufficient, + }; + let _ = Pallet::::do_register_asset(*id, &details, None).expect("Failed to register asset"); + }, + ); + + TransactionOutcome::Commit(DispatchResult::Ok(())) }) + .expect("Genesis build failed.") } } #[pallet::event] - #[pallet::generate_deposit(pub(super) fn deposit_event)] + #[pallet::generate_deposit(pub fn deposit_event)] pub enum Event { + /// Existential deposit for insufficinet asset was paid. + /// `SufficiencyCheck` triggers this event. + ExistentialDepositPaid { + who: T::AccountId, + fee_asset: T::AssetId, + amount: Balance, + }, + /// Asset was registered. Registered { asset_id: T::AssetId, - asset_name: BoundedVec, - asset_type: AssetType, + asset_name: Option>, + asset_type: AssetType, + existential_deposit: Balance, + xcm_rate_limit: Option, + symbol: Option>, + decimals: Option, + is_sufficient: bool, }, /// Asset was updated. Updated { asset_id: T::AssetId, - asset_name: BoundedVec, - asset_type: AssetType, - existential_deposit: T::Balance, - xcm_rate_limit: Option, - }, - - /// Metadata set for an asset. - MetadataSet { - asset_id: T::AssetId, - symbol: BoundedVec, - decimals: u8, + asset_name: Option>, + asset_type: AssetType, + existential_deposit: Balance, + xcm_rate_limit: Option, + symbol: Option>, + decimals: Option, + is_sufficient: bool, }, /// Native location set for an asset. @@ -249,16 +330,25 @@ pub mod pallet { asset_id: T::AssetId, location: T::AssetNativeLocation, }, + + /// Asset was banned. + AssetBanned { asset_id: T::AssetId }, + + /// Asset's ban was removed. + AssetUnbanned { asset_id: T::AssetId }, } #[pallet::call] impl Pallet { /// Register a new asset. /// - /// Asset is identified by `name` and the name must not be used to register another asset. - /// /// New asset is given `NextAssetId` - sequential asset id /// + /// Asset's id is optional and it can't be used by another asset if it's provided. + /// Provided `asset_id` must be from within reserved range. + /// If `asset_id` is `None`, new asset is given id for sequential ids. + /// + /// Asset's name is optional and it can't be used by another asset if it's provided. /// Adds mapping between `name` and assigned `asset_id` so asset id can be retrieved by name too (Note: this approach is used in AMM implementation (xyk)) /// /// Emits 'Registered` event when successful. @@ -267,232 +357,227 @@ pub mod pallet { #[pallet::weight(::WeightInfo::register())] pub fn register( origin: OriginFor, - name: Vec, - asset_type: AssetType, - existential_deposit: T::Balance, asset_id: Option, - metadata: Option, + name: Option>, + asset_type: AssetType, + existential_deposit: Option, + symbol: Option>, + decimals: Option, location: Option, - xcm_rate_limit: Option, + xcm_rate_limit: Option, + is_sufficient: bool, ) -> DispatchResult { T::RegistryOrigin::ensure_origin(origin)?; - let bounded_name = Self::to_bounded_name(name)?; - - ensure!( - Self::asset_ids(&bounded_name).is_none(), - Error::::AssetAlreadyRegistered + let details = AssetDetails::new( + name, + asset_type, + existential_deposit.unwrap_or(DEFAULT_ED), + symbol, + decimals, + xcm_rate_limit, + is_sufficient, ); - let asset_id = - Self::register_asset(bounded_name, asset_type, existential_deposit, asset_id, xcm_rate_limit)?; - - if let Some(meta) = metadata { - let symbol = Self::to_bounded_name(meta.symbol)?; - AssetMetadataMap::::insert( - asset_id, - AssetMetadata { - symbol: symbol.clone(), - decimals: meta.decimals, - }, - ); - - Self::deposit_event(Event::MetadataSet { - asset_id, - symbol, - decimals: meta.decimals, - }); - } - - if let Some(loc) = location { - ensure!(asset_id != T::NativeAssetId::get(), Error::::CannotUpdateLocation); - ensure!( - Self::location_assets(&loc).is_none(), - Error::::LocationAlreadyRegistered - ); - AssetLocations::::insert(asset_id, &loc); - LocationAssets::::insert(&loc, asset_id); - - Self::deposit_event(Event::LocationSet { - asset_id, - location: loc, - }); - } - + Self::do_register_asset(asset_id, &details, location)?; Ok(()) } /// Update registered asset. /// - /// Updates also mapping between name and asset id if provided name is different than currently registered. + /// All parameteres are optional and value is not updated if param is `None`. + /// + /// `decimals` - can be update by `UpdateOrigin` only if it wasn't set yet. Only + /// `RegistryOrigin` can update `decimals` if it was previously set. + /// + /// `location` - can be updated only by `RegistryOrigin`. /// /// Emits `Updated` event when successful. - - // TODO: No tests #[pallet::call_index(1)] #[pallet::weight(::WeightInfo::update())] pub fn update( origin: OriginFor, asset_id: T::AssetId, - name: Vec, - asset_type: AssetType, - existential_deposit: Option, - xcm_rate_limit: Option, + name: Option>, + asset_type: Option, + existential_deposit: Option, + xcm_rate_limit: Option, + is_sufficient: Option, + symbol: Option>, + decimals: Option, + location: Option, ) -> DispatchResult { - T::RegistryOrigin::ensure_origin(origin)?; + let is_registry_origin = T::RegistryOrigin::ensure_origin(origin.clone()).is_ok(); + if !is_registry_origin { + T::UpdateOrigin::ensure_origin(origin)?; + } + + if let Some(n) = name.as_ref() { + ensure!(n.len() >= T::MinStringLimit::get() as usize, Error::::TooShort); + } + + Self::validate_symbol(&symbol)?; Assets::::try_mutate(asset_id, |maybe_detail| -> DispatchResult { let detail = maybe_detail.as_mut().ok_or(Error::::AssetNotFound)?; - let bounded_name = Self::to_bounded_name(name)?; + if let Some(new_name) = name.as_ref() { + ensure!(Self::asset_ids(new_name).is_none(), Error::::AssetAlreadyRegistered); - if bounded_name != detail.name { - // Make sure that there is no such name already registered - ensure!( - Self::asset_ids(&bounded_name).is_none(), - Error::::AssetAlreadyRegistered - ); + if let Some(old_name) = &detail.name { + AssetIds::::remove(old_name); + } - // update also name map - remove old one first - AssetIds::::remove(&detail.name); - AssetIds::::insert(&bounded_name, asset_id); - } + if Some(new_name.clone()) != detail.name { + AssetIds::::insert(new_name, asset_id); + } + }; - detail.name = bounded_name.clone(); - detail.asset_type = asset_type; + detail.name = name.or_else(|| detail.name.clone()); + detail.asset_type = asset_type.unwrap_or(detail.asset_type); detail.existential_deposit = existential_deposit.unwrap_or(detail.existential_deposit); - detail.xcm_rate_limit = xcm_rate_limit; + detail.xcm_rate_limit = xcm_rate_limit.or(detail.xcm_rate_limit); + detail.symbol = symbol.or_else(|| detail.symbol.clone()); + + let suff = is_sufficient.unwrap_or(detail.is_sufficient); + if detail.is_sufficient != suff { + //NOTE: Change sufficient -> insufficient require storage migration and is not + //allowed by extrinsic. + ensure!(!detail.is_sufficient, Error::::ForbiddenSufficiencyChange); + detail.is_sufficient = suff; + } + + if decimals.is_some() { + if detail.decimals.is_none() { + detail.decimals = decimals; + } else { + //Only highest origin can change decimal if it was set previously. + ensure!(is_registry_origin, Error::::Forbidden); + detail.decimals = decimals; + }; + } + + if let Some(loc) = location { + //Only highest origin can update location. + ensure!(is_registry_origin, Error::::Forbidden); + + if let Some(old_location) = AssetLocations::::take(asset_id) { + LocationAssets::::remove(&old_location); + } + Self::do_set_location(asset_id, loc)?; + } Self::deposit_event(Event::Updated { asset_id, - asset_name: bounded_name, - asset_type, + asset_name: detail.name.clone(), + asset_type: detail.asset_type, existential_deposit: detail.existential_deposit, xcm_rate_limit: detail.xcm_rate_limit, + symbol: detail.symbol.clone(), + decimals: detail.decimals, + is_sufficient: detail.is_sufficient, }); Ok(()) }) } - /// Set metadata for an asset. - /// - /// - `asset_id`: Asset identifier. - /// - `symbol`: The exchange symbol for this asset. Limited in length by `StringLimit`. - /// - `decimals`: The number of decimals this asset uses to represent one unit. - /// - /// Emits `MetadataSet` event when successful. - #[pallet::call_index(2)] - #[pallet::weight(::WeightInfo::set_metadata())] - pub fn set_metadata( - origin: OriginFor, - asset_id: T::AssetId, - symbol: Vec, - decimals: u8, - ) -> DispatchResult { - T::RegistryOrigin::ensure_origin(origin)?; + //NOTE: call indices 2 and 3 were used by removed extrinsics. + #[pallet::call_index(4)] + #[pallet::weight(::WeightInfo::register_external().saturating_mul(::RegExternalWeightMultiplier::get()))] + pub fn register_external(origin: OriginFor, location: T::AssetNativeLocation) -> DispatchResult { + let _ = ensure_signed(origin)?; - ensure!(Self::assets(asset_id).is_some(), Error::::AssetNotFound); + Self::do_register_asset( + None, + &AssetDetails::new(None, AssetType::External, DEFAULT_ED, None, None, None, false), + Some(location), + )?; + + Ok(()) + } - let b_symbol = Self::to_bounded_name(symbol)?; + #[pallet::call_index(5)] + #[pallet::weight(::WeightInfo::ban_asset())] + pub fn ban_asset(origin: OriginFor, asset_id: T::AssetId) -> DispatchResult { + T::UpdateOrigin::ensure_origin(origin)?; - let metadata = AssetMetadata::> { - symbol: b_symbol.clone(), - decimals, - }; + ensure!(Assets::::contains_key(asset_id), Error::::AssetNotFound); - AssetMetadataMap::::insert(asset_id, metadata); + ensure!( + !BannedAssets::::contains_key(asset_id), + Error::::AssetAlreadyBanned + ); - Self::deposit_event(Event::MetadataSet { - asset_id, - symbol: b_symbol, - decimals, - }); + BannedAssets::::insert(asset_id, ()); + Self::deposit_event(Event::AssetBanned { asset_id }); Ok(()) } - /// Set asset native location. - /// - /// Adds mapping between native location and local asset id and vice versa. - /// - /// Mainly used in XCM. - /// - /// Emits `LocationSet` event when successful. - #[pallet::call_index(3)] - #[pallet::weight(::WeightInfo::set_location())] - pub fn set_location( - origin: OriginFor, - asset_id: T::AssetId, - location: T::AssetNativeLocation, - ) -> DispatchResult { - T::RegistryOrigin::ensure_origin(origin)?; - - ensure!(asset_id != T::NativeAssetId::get(), Error::::CannotUpdateLocation); - ensure!(Self::assets(asset_id).is_some(), Error::::AssetNotRegistered); - ensure!( - Self::location_assets(&location).is_none(), - Error::::LocationAlreadyRegistered - ); + #[pallet::call_index(6)] + #[pallet::weight(::WeightInfo::unban_asset())] + pub fn unban_asset(origin: OriginFor, asset_id: T::AssetId) -> DispatchResult { + T::UpdateOrigin::ensure_origin(origin)?; - if let Some(old_location) = AssetLocations::::take(asset_id) { - LocationAssets::::remove(&old_location); - } - AssetLocations::::insert(asset_id, &location); - LocationAssets::::insert(&location, asset_id); + ensure!(BannedAssets::::contains_key(asset_id), Error::::AssetNotBanned); - Self::deposit_event(Event::LocationSet { asset_id, location }); + BannedAssets::::remove(asset_id); + Self::deposit_event(Event::AssetUnbanned { asset_id }); Ok(()) } } } impl Pallet { + fn validate_symbol(symbol: &Option>) -> Result<(), DispatchError> { + if let Some(s) = symbol.clone() { + ensure!(s.len() >= T::MinStringLimit::get() as usize, Error::::TooShort); + + ensure!( + s.into_inner().iter().all(|c| !char::is_whitespace(*c as char)), + Error::::InvalidSymbol + ); + } + Ok(()) + } + pub fn next_asset_id() -> Option { NextAssetId::::get().checked_add(&T::SequentialIdStartAt::get()) } - /// Convert Vec to BoundedVec so it respects the max set limit, otherwise return TooLong error - pub fn to_bounded_name(name: Vec) -> Result, Error> { - name.try_into().map_err(|_| Error::::TooLong) + fn do_set_location(asset_id: T::AssetId, location: T::AssetNativeLocation) -> Result<(), DispatchError> { + ensure!( + Self::location_assets(&location).is_none(), + Error::::LocationAlreadyRegistered + ); + + AssetLocations::::insert(asset_id, &location); + LocationAssets::::insert(&location, asset_id); + + Self::deposit_event(Event::LocationSet { asset_id, location }); + + Ok(()) } - /// Register new asset. - /// - /// Does not perform any check whether an asset for given name already exists. This has to be prior to calling this function. - pub fn register_asset( - name: BoundedVec, - asset_type: AssetType, - existential_deposit: T::Balance, + #[require_transactional] + fn do_register_asset( selected_asset_id: Option, - xcm_rate_limit: Option, + details: &AssetDetails, + location: Option, ) -> Result { - let asset_id = if let Some(selected_id) = selected_asset_id { - ensure!( - selected_id < T::SequentialIdStartAt::get(), - Error::::NotInReservedRange - ); + Self::validate_symbol(&details.symbol)?; - ensure!( - !Assets::::contains_key(selected_id), - Error::::AssetAlreadyRegistered - ); + let asset_id = if let Some(id) = selected_asset_id { + ensure!(id < T::SequentialIdStartAt::get(), Error::::NotInReservedRange); + + ensure!(!Assets::::contains_key(id), Error::::AssetAlreadyRegistered); - selected_id + id } else { NextAssetId::::mutate(|value| -> Result { - // Check if current id does not clash with CORE ASSET ID. - // If yes, just skip it and use next one, otherwise use it. - // Note: this way we prevent accidental clashes with native asset id, so no need to set next asset id to be > next asset id - let next_asset_id = if *value == T::NativeAssetId::get() { - value - .checked_add(&T::AssetId::from(1)) - .ok_or(Error::::NoIdAvailable)? - } else { - *value - }; - + let next_asset_id = *value; *value = next_asset_id .checked_add(&T::AssetId::from(1)) .ok_or(Error::::NoIdAvailable)?; @@ -503,45 +588,31 @@ impl Pallet { })? }; - AssetIds::::insert(&name, asset_id); - - let details = AssetDetails { - name: name.clone(), - asset_type, - existential_deposit, - xcm_rate_limit, - }; - - // Store the details Assets::::insert(asset_id, details); + if let Some(name) = details.name.as_ref() { + ensure!(name.len() >= T::MinStringLimit::get() as usize, Error::::TooShort); + ensure!(!AssetIds::::contains_key(name), Error::::AssetAlreadyRegistered); + AssetIds::::insert(name, asset_id); + } - // Increase asset id to be assigned for following asset. + if let Some(loc) = location { + Self::do_set_location(asset_id, loc)?; + } Self::deposit_event(Event::Registered { asset_id, - asset_name: name, - asset_type, + asset_name: details.name.clone(), + asset_type: details.asset_type, + existential_deposit: details.existential_deposit, + xcm_rate_limit: details.xcm_rate_limit, + symbol: details.symbol.clone(), + decimals: details.decimals, + is_sufficient: details.is_sufficient, }); Ok(asset_id) } - /// Create asset for given name or return existing AssetId if such asset already exists. - pub fn get_or_create_asset( - name: Vec, - asset_type: AssetType, - existential_deposit: T::Balance, - asset_id: Option, - ) -> Result { - let bounded_name: BoundedVec = Self::to_bounded_name(name)?; - - if let Some(asset_id) = AssetIds::::get(&bounded_name) { - Ok(asset_id) - } else { - Self::register_asset(bounded_name, asset_type, existential_deposit, asset_id, None) - } - } - /// Return location for given asset. pub fn asset_to_location(asset_id: T::AssetId) -> Option { Self::locations(asset_id) @@ -553,62 +624,16 @@ impl Pallet { } } -impl Registry, T::Balance, DispatchError> for Pallet { - fn exists(asset_id: T::AssetId) -> bool { - Assets::::contains_key(asset_id) - } - - fn retrieve_asset(name: &Vec) -> Result { - let bounded_name = Self::to_bounded_name(name.clone())?; - if let Some(asset_id) = AssetIds::::get(bounded_name) { - Ok(asset_id) - } else { - Err(Error::::AssetNotFound.into()) - } - } - - fn retrieve_asset_type(asset_id: T::AssetId) -> Result { - let asset_details = - Assets::::get(asset_id).ok_or_else(|| Into::::into(Error::::AssetNotFound))?; - Ok(asset_details.asset_type.into()) - } - - fn create_asset(name: &Vec, existential_deposit: T::Balance) -> Result { - Self::get_or_create_asset(name.clone(), AssetType::Token, existential_deposit, None) - } -} - -impl ShareTokenRegistry, T::Balance, DispatchError> for Pallet { - fn retrieve_shared_asset(name: &Vec, _assets: &[T::AssetId]) -> Result { - Self::retrieve_asset(name) - } - - fn create_shared_asset( - name: &Vec, - assets: &[T::AssetId], - existential_deposit: T::Balance, - ) -> Result { - ensure!(assets.len() == 2, Error::::InvalidSharedAssetLen); - Self::get_or_create_asset( - name.clone(), - AssetType::PoolShare(assets[0], assets[1]), - existential_deposit, - None, - ) - } -} - use orml_traits::GetByKey; -use sp_arithmetic::traits::Bounded; // Return Existential deposit of an asset -impl GetByKey for Pallet { - fn get(k: &T::AssetId) -> T::Balance { +impl GetByKey for Pallet { + fn get(k: &T::AssetId) -> Balance { if let Some(details) = Self::assets(k) { details.existential_deposit } else { // Asset does not exist - not supported - T::Balance::max_value() + Balance::max_value() } } } @@ -617,37 +642,113 @@ impl GetByKey for Pallet { pub struct XcmRateLimitsInRegistry(PhantomData); /// Allows querying the XCM rate limit for an asset by its id. /// Both a unknown asset and an unset rate limit will return `None`. -impl GetByKey> for XcmRateLimitsInRegistry { - fn get(k: &T::AssetId) -> Option { +impl GetByKey> for XcmRateLimitsInRegistry { + fn get(k: &T::AssetId) -> Option { Pallet::::assets(k).and_then(|details| details.xcm_rate_limit) } } -impl CreateRegistry for Pallet { - type Error = DispatchError; +impl Inspect for Pallet { + type AssetId = T::AssetId; + type Location = T::AssetNativeLocation; - fn create_asset(name: &[u8], kind: AssetKind, existential_deposit: T::Balance) -> Result { - let bounded_name: BoundedVec = Self::to_bounded_name(name.to_vec())?; - Pallet::::register_asset(bounded_name, kind.into(), existential_deposit, None, None) + fn is_sufficient(id: Self::AssetId) -> bool { + match Self::assets(id) { + Some(a) => a.is_sufficient, + None => false, + } + } + + fn exists(id: Self::AssetId) -> bool { + Assets::::contains_key(id) + } + + fn decimals(id: Self::AssetId) -> Option { + Self::assets(id).and_then(|a| a.decimals) } -} -impl InspectRegistry for Pallet { - fn exists(asset_id: T::AssetId) -> bool { - Assets::::contains_key(asset_id) + fn asset_type(id: Self::AssetId) -> Option { + Self::assets(id).map(|a| a.asset_type.into()) } - fn decimals(asset_id: T::AssetId) -> Option { - Some(AssetMetadataMap::::get(asset_id)?.decimals) + fn is_banned(id: Self::AssetId) -> bool { + BannedAssets::::contains_key(id) + } + + fn asset_name(id: Self::AssetId) -> Option> { + Self::assets(id).and_then(|a| a.name.map(|v| v.into())) + } + + fn asset_symbol(id: Self::AssetId) -> Option> { + Self::assets(id).and_then(|a| a.symbol.map(|v| v.into())) + } +} + +impl Mutate for Pallet { + type Error = DispatchError; + + fn set_location(asset_id: Self::AssetId, location: T::AssetNativeLocation) -> Result<(), Self::Error> { + ensure!(Self::exists(asset_id), Error::::AssetNotFound); + + Self::do_set_location(asset_id, location) } +} + +impl Create for Pallet { + type Error = DispatchError; + type Name = Name; + type Symbol = Symbol; + + fn register_asset( + asset_id: Option, + name: Option, + kind: AssetKind, + existential_deposit: Option, + symbol: Option, + decimals: Option, + location: Option, + xcm_rate_limit: Option, + is_sufficient: bool, + ) -> Result { + let details = AssetDetails::new( + name, + kind.into(), + existential_deposit.unwrap_or(DEFAULT_ED), + symbol, + decimals, + xcm_rate_limit, + is_sufficient, + ); - fn asset_name(asset_id: T::AssetId) -> Option> { - let asset = Assets::::get(asset_id)?; - Some(asset.name.into_inner()) + Self::do_register_asset(asset_id, &details, location) } - fn asset_symbol(asset_id: T::AssetId) -> Option> { - let asset_metadata = AssetMetadataMap::::get(asset_id)?; - Some(asset_metadata.symbol.into_inner()) + fn get_or_register_asset( + name: Self::Name, + kind: AssetKind, + existential_deposit: Option, + symbol: Option, + decimals: Option, + location: Option, + xcm_rate_limit: Option, + is_sufficient: bool, + ) -> Result { + //NOTE: in this case `try_into_bounded()` should never return None. + match Self::asset_ids(&name) { + Some(id) => Ok(id), + None => { + let details = AssetDetails::new( + Some(name), + kind.into(), + existential_deposit.unwrap_or(DEFAULT_ED), + symbol, + decimals, + xcm_rate_limit, + is_sufficient, + ); + + Self::do_register_asset(None, &details, location) + } + } } } diff --git a/pallets/asset-registry/src/migration.rs b/pallets/asset-registry/src/migration.rs index 26fc5986d..1d0da1840 100644 --- a/pallets/asset-registry/src/migration.rs +++ b/pallets/asset-registry/src/migration.rs @@ -7,7 +7,7 @@ // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, @@ -15,33 +15,92 @@ // See the License for the specific language governing permissions and // limitations under the License.. -use crate::{AssetDetails, AssetType, Assets, Config, Pallet}; +use crate::{AssetDetails, AssetType, Assets, Balance, Config, Pallet}; use frame_support::{ traits::{Get, StorageVersion}, weights::Weight, + Twox64Concat, }; -/// +use crate::*; + pub mod v1 { use super::*; use codec::{Decode, Encode}; + use frame_support::storage_alias; use scale_info::TypeInfo; use sp_core::RuntimeDebug; + use sp_runtime::BoundedVec; + + #[derive(Encode, Decode, Eq, PartialEq, Copy, Clone, RuntimeDebug, TypeInfo, MaxEncodedLen)] + pub enum AssetType { + Token, + PoolShare(AssetId, AssetId), // Use XYX instead + XYK, + StableSwap, + Bond, + External, + } #[derive(Encode, Decode, Eq, PartialEq, Copy, Clone, RuntimeDebug, TypeInfo)] - pub struct OldAssetDetails { - /// The name of this asset. Limited in length by `StringLimit`. - pub(super) name: BoundedString, + pub struct AssetDetails { + pub name: BoundedString, + pub asset_type: AssetType, + pub existential_deposit: Balance, + pub xcm_rate_limit: Option, + } + + #[derive(Clone, Encode, Decode, Eq, PartialEq, Default, RuntimeDebug, TypeInfo)] + pub struct AssetMetadata { + pub(super) symbol: BoundedString, + pub(super) decimals: u8, + } - pub(super) asset_type: AssetType, + #[storage_alias] + pub type Assets = StorageMap< + Pallet, + Twox64Concat, + ::AssetId, + AssetDetails<::AssetId, Balance, BoundedVec::StringLimit>>, + OptionQuery, + >; + + #[storage_alias] + pub type AssetMetadataMap = StorageMap< + Pallet, + Twox64Concat, + ::AssetId, + AssetMetadata::StringLimit>>, + OptionQuery, + >; + + #[storage_alias] + pub type AssetLocations = StorageMap< + Pallet, + Twox64Concat, + ::AssetId, + ::AssetNativeLocation, + OptionQuery, + >; +} - pub(super) existential_deposit: Balance, +pub mod v2 { + use super::*; - pub(super) locked: bool, + impl From> for AssetType { + fn from(value: v1::AssetType) -> Self { + match value { + v1::AssetType::Token => Self::Token, + v1::AssetType::PoolShare(_, _) => Self::XYK, + v1::AssetType::XYK => Self::XYK, + v1::AssetType::StableSwap => Self::StableSwap, + v1::AssetType::Bond => Self::Bond, + v1::AssetType::External => Self::External, + } + } } - pub fn pre_migrate() { - assert_eq!(StorageVersion::get::>(), 0, "Storage version too high."); + assert_eq!(StorageVersion::get::>(), 1, "Storage version too high."); log::info!( target: "runtime::asset-registry", @@ -49,38 +108,99 @@ pub mod v1 { ); } - pub fn migrate() -> Weight { + pub fn migrate>() -> Weight { + log::info!( + target: "runtime::asset-registry", + "Running migration to v2 for Asset Registry" + ); + log::info!( target: "runtime::asset-registry", - "Running migration to v1 for Asset Registry" + "Migrating Assets storage" ); - let mut i = 0; - Assets::::translate( - |_key, - OldAssetDetails { - name, - asset_type, - existential_deposit, - locked: _, - }| { - i += 1; - Some(AssetDetails { - name, - asset_type, - existential_deposit, - xcm_rate_limit: None, - }) - }, + let mut reads = 0; + let mut writes = 0; + + let mut v2_assets_details = Vec::<( + ::AssetId, + AssetDetails<::StringLimit>, + )>::new(); + + let mut assets_count = 0; + for (k, v) in v1::Assets::::iter() { + assets_count += 1; + let (symbol, decimals) = if let Some(meta) = v1::AssetMetadataMap::::get(k) { + (Some(meta.symbol), Some(meta.decimals)) + } else { + (None, None) + }; + + v2_assets_details.push(( + k, + AssetDetails { + name: Some(v.name), + asset_type: v.asset_type.into(), + existential_deposit: v.existential_deposit, + symbol, + decimals, + xcm_rate_limit: v.xcm_rate_limit, + //All assets created before this are sufficient + is_sufficient: true, + }, + )); + } + reads += assets_count; + + let _ = v1::Assets::::clear(u32::MAX, None); + writes += assets_count; + + for (k, v) in v2_assets_details { + writes += 1; + Assets::::insert(k, v); + log::info!( + target: "runtime::asset-registry", + "Migrated asset: {:?}", k + ); + } + + //This assumes every asset has metadata and each metadata is touched. + let _ = v1::AssetMetadataMap::::clear(u32::MAX, None); + writes += assets_count; + + log::info!( + target: "runtime::asset-registry", + "Migrating AssetLocations storage" ); - StorageVersion::new(1).put::>(); + for k in v1::AssetLocations::::iter_keys() { + reads += 1; + writes += 1; - T::DbWeight::get().reads_writes(i, i) + AssetLocations::::migrate_key::::AssetId>(k); + + log::info!( + target: "runtime::asset-registry", + "Migrated asset's location: {:?}", k + ); + } + + StorageVersion::new(2).put::>(); + T::DbWeight::get().reads_writes(reads, writes) } pub fn post_migrate() { - assert_eq!(StorageVersion::get::>(), 1, "Unexpected storage version."); + for a in Assets::::iter_keys() { + let _ = Assets::::get(a).expect("Assets data must be valid"); + } + + for l in AssetLocations::::iter_keys() { + let _ = AssetLocations::::get(l).expect("AssetLocations data must be valid"); + } + + assert_eq!(v1::AssetMetadataMap::::iter().count(), 0); + + assert_eq!(StorageVersion::get::>(), 2, "Unexpected storage version."); log::info!( target: "runtime::asset-registry", diff --git a/pallets/asset-registry/src/tests.rs b/pallets/asset-registry/src/tests.rs deleted file mode 100644 index ed4f60fcb..000000000 --- a/pallets/asset-registry/src/tests.rs +++ /dev/null @@ -1,865 +0,0 @@ -// This file is part of pallet-asset-registry. - -// Copyright (C) 2020-2022 Intergalactic, Limited (GIB). -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use super::Error; -use crate::mock::AssetId as RegistryAssetId; -use crate::types::{AssetDetails, AssetMetadata, AssetType, Metadata}; -use crate::Event; -use crate::{mock::*, XcmRateLimitsInRegistry}; -use codec::Encode; -use frame_support::{assert_noop, assert_ok, BoundedVec}; -use orml_traits::GetByKey; -use polkadot_xcm::v3::prelude::*; -use sp_std::convert::TryInto; - -#[test] -fn register_asset_works() { - new_test_ext().execute_with(|| { - let too_long = [1u8; ::StringLimit::get() as usize + 1]; - - let ed = 1_000_000u128; - - assert_noop!( - AssetRegistryPallet::register( - RuntimeOrigin::root(), - too_long.to_vec(), - AssetType::Token, - ed, - None, - None, - None, - None - ), - Error::::TooLong - ); - - let name: Vec = b"BSX".to_vec(); - - assert_ok!(AssetRegistryPallet::register( - RuntimeOrigin::root(), - name.clone(), - AssetType::Token, - ed, - None, - None, - None, - None - )); - - let bn = AssetRegistryPallet::to_bounded_name(name.clone()).unwrap(); - - expect_events(vec![Event::Registered { - asset_id: 1 + SequentialIdStart::get(), - asset_name: bn.clone(), - asset_type: AssetType::Token, - } - .into()]); - - assert_eq!( - AssetRegistryPallet::asset_ids(&bn).unwrap(), - 1u32 + SequentialIdStart::get() - ); - assert_eq!( - AssetRegistryPallet::assets(1u32 + SequentialIdStart::get()).unwrap(), - AssetDetails { - name: bn, - asset_type: AssetType::Token, - existential_deposit: ed, - xcm_rate_limit: None, - } - ); - - assert_noop!( - AssetRegistryPallet::register( - RuntimeOrigin::root(), - name, - AssetType::Token, - ed, - None, - None, - None, - None - ), - Error::::AssetAlreadyRegistered - ); - }); -} - -#[test] -fn create_asset() { - new_test_ext().execute_with(|| { - let ed = 1_000_000u128; - - assert_ok!(AssetRegistryPallet::get_or_create_asset( - b"BSX".to_vec(), - AssetType::Token, - ed, - None, - )); - - let dot_asset = AssetRegistryPallet::get_or_create_asset(b"DOT".to_vec(), AssetType::Token, ed, None); - assert_ok!(dot_asset); - let dot_asset_id = dot_asset.ok().unwrap(); - - assert_ok!(AssetRegistryPallet::get_or_create_asset( - b"BTC".to_vec(), - AssetType::Token, - ed, - None, - )); - - let current_asset_id = AssetRegistryPallet::next_asset_id().unwrap(); - - // Existing asset should return previously created one. - assert_ok!( - AssetRegistryPallet::get_or_create_asset(b"DOT".to_vec(), AssetType::Token, ed, None), - dot_asset_id - ); - - // Retrieving existing asset should not increased the next asset id counter. - assert_eq!(AssetRegistryPallet::next_asset_id().unwrap(), current_asset_id); - - let dot: BoundedVec::StringLimit> = b"DOT".to_vec().try_into().unwrap(); - let aaa: BoundedVec::StringLimit> = b"AAA".to_vec().try_into().unwrap(); - - assert_eq!( - AssetRegistryPallet::asset_ids(dot).unwrap(), - 2u32 + SequentialIdStart::get() - ); - assert!(AssetRegistryPallet::asset_ids(aaa).is_none()); - }); -} - -#[test] -fn location_mapping_works() { - new_test_ext().execute_with(|| { - let bn = AssetRegistryPallet::to_bounded_name(b"BSX".to_vec()).unwrap(); - - let ed = 1_000_000u128; - - assert_ok!(AssetRegistryPallet::get_or_create_asset( - b"BSX".to_vec(), - AssetType::Token, - ed, - None, - )); - let asset_id: RegistryAssetId = - AssetRegistryPallet::get_or_create_asset(b"BSX".to_vec(), AssetType::Token, ed, None).unwrap(); - - crate::Assets::::insert( - asset_id, - AssetDetails::> { - name: bn, - asset_type: AssetType::Token, - existential_deposit: ed, - xcm_rate_limit: None, - }, - ); - - let key = Junction::from(BoundedVec::try_from(asset_id.encode()).unwrap()); - let asset_location = AssetLocation(MultiLocation::new(0, X2(Parachain(200), key))); - - assert_ok!(AssetRegistryPallet::set_location( - RuntimeOrigin::root(), - asset_id, - asset_location.clone() - )); - - expect_events(vec![Event::LocationSet { - asset_id: 1 + SequentialIdStart::get(), - location: asset_location.clone(), - } - .into()]); - - assert_eq!( - AssetRegistryPallet::location_to_asset(asset_location.clone()), - Some(asset_id) - ); - assert_eq!( - AssetRegistryPallet::asset_to_location(asset_id), - Some(asset_location.clone()) - ); - - // asset location for the native asset cannot be changed - assert_noop!( - AssetRegistryPallet::set_location( - RuntimeOrigin::root(), - ::NativeAssetId::get(), - asset_location - ), - Error::::CannotUpdateLocation - ); - }); -} - -#[test] -fn genesis_config_works() { - ExtBuilder::default() - .with_native_asset_name(b"NATIVE".to_vec()) - .build() - .execute_with(|| { - let native: BoundedVec::StringLimit> = b"NATIVE".to_vec().try_into().unwrap(); - assert_eq!(AssetRegistryPallet::asset_ids(native).unwrap(), 0u32); - }); - - let one = b"ONE".to_vec(); - let life = b"LIFE".to_vec(); - - ExtBuilder::default() - .with_assets(vec![ - (one.clone(), 1_000u128, None), - (life.clone(), 1_000u128, Some(42)), - ]) - .build() - .execute_with(|| { - let native: BoundedVec::StringLimit> = b"NATIVE".to_vec().try_into().unwrap(); - assert_eq!(AssetRegistryPallet::asset_ids(native), None); - - let bsx: BoundedVec::StringLimit> = b"HDX".to_vec().try_into().unwrap(); - assert_eq!(AssetRegistryPallet::asset_ids(bsx).unwrap(), 0u32); - - let one: BoundedVec::StringLimit> = one.try_into().unwrap(); - assert_eq!( - AssetRegistryPallet::asset_ids(one.clone()).unwrap(), - 1u32 + SequentialIdStart::get() - ); - assert_eq!( - AssetRegistryPallet::assets(1u32 + SequentialIdStart::get()).unwrap(), - AssetDetails { - name: one, - asset_type: AssetType::Token, - existential_deposit: 1_000u128, - xcm_rate_limit: None, - } - ); - - let life: BoundedVec::StringLimit> = life.try_into().unwrap(); - assert_eq!(AssetRegistryPallet::asset_ids(life.clone()).unwrap(), 42u32); - assert_eq!( - AssetRegistryPallet::assets(42u32).unwrap(), - AssetDetails { - name: life, - asset_type: AssetType::Token, - existential_deposit: 1_000u128, - xcm_rate_limit: None, - } - ); - }); -} - -#[test] -fn set_metadata_works() { - ExtBuilder::default() - .with_assets(vec![(b"DOT".to_vec(), 1_000u128, None)]) - .build() - .execute_with(|| { - System::set_block_number(1); //TO have the ement emitted - - let dot: BoundedVec::StringLimit> = b"DOT".to_vec().try_into().unwrap(); - let dot_id = AssetRegistryPallet::asset_ids(dot).unwrap(); - let b_symbol: BoundedVec::StringLimit> = b"xDOT".to_vec().try_into().unwrap(); - - assert_ok!(AssetRegistryPallet::set_metadata( - RuntimeOrigin::root(), - dot_id, - b"xDOT".to_vec(), - 12u8 - )); - - expect_events(vec![Event::MetadataSet { - asset_id: dot_id, - symbol: b_symbol.clone(), - decimals: 12u8, - } - .into()]); - - assert_eq!( - AssetRegistryPallet::asset_metadata(dot_id).unwrap(), - AssetMetadata { - decimals: 12u8, - symbol: b_symbol.clone(), - } - ); - - assert_ok!(AssetRegistryPallet::set_metadata( - RuntimeOrigin::root(), - dot_id, - b"xDOT".to_vec(), - 30u8 - )); - - assert_eq!( - AssetRegistryPallet::asset_metadata(dot_id).unwrap(), - AssetMetadata { - decimals: 30u8, - symbol: b_symbol, - } - ); - - assert_noop!( - AssetRegistryPallet::set_metadata(RuntimeOrigin::root(), dot_id, b"JUST_TOO_LONG".to_vec(), 30u8), - Error::::TooLong - ); - - assert_noop!( - AssetRegistryPallet::set_metadata(RuntimeOrigin::root(), 100, b"NONE".to_vec(), 30u8), - Error::::AssetNotFound - ); - }); -} - -#[test] -fn update_asset() { - new_test_ext().execute_with(|| { - let ed = 1_000_000u128; - - let btc_asset_id: RegistryAssetId = - AssetRegistryPallet::get_or_create_asset(b"BTC".to_vec(), AssetType::Token, ed, None).unwrap(); - let usd_asset_id: RegistryAssetId = - AssetRegistryPallet::get_or_create_asset(b"USD".to_vec(), AssetType::Token, ed, None).unwrap(); - - let next_asset_id = AssetRegistryPallet::next_asset_id().unwrap(); - - // set a new name and type for an existing asset - assert_ok!(AssetRegistryPallet::update( - RuntimeOrigin::root(), - btc_asset_id, - b"superBTC".to_vec(), - AssetType::Token, - None, - None, - )); - let bn = AssetRegistryPallet::to_bounded_name(b"superBTC".to_vec()).unwrap(); - - expect_events(vec![Event::Updated { - asset_id: btc_asset_id, - asset_name: bn.clone(), - asset_type: AssetType::Token, - existential_deposit: 1_000_000, - xcm_rate_limit: None, - } - .into()]); - - assert_eq!( - AssetRegistryPallet::assets(btc_asset_id).unwrap(), - AssetDetails { - name: bn, - asset_type: AssetType::Token, - existential_deposit: ed, - xcm_rate_limit: None, - } - ); - - let new_btc_name: BoundedVec::StringLimit> = - b"superBTC".to_vec().try_into().unwrap(); - assert_eq!( - AssetRegistryPallet::asset_ids(new_btc_name).unwrap(), - 1u32 + SequentialIdStart::get() - ); - - // cannot set existing name for an existing asset - assert_noop!( - (AssetRegistryPallet::update( - RuntimeOrigin::root(), - usd_asset_id, - b"superBTC".to_vec(), - AssetType::Token, - None, - None, - )), - Error::::AssetAlreadyRegistered - ); - - // cannot set a new name for a non-existent asset - assert_noop!( - (AssetRegistryPallet::update( - RuntimeOrigin::root(), - next_asset_id, - b"VOID".to_vec(), - AssetType::Token, - None, - None, - )), - Error::::AssetNotFound - ); - - // corner case: change the name and also the type for an existing asset (token -> pool share) - assert_ok!(AssetRegistryPallet::update( - RuntimeOrigin::root(), - btc_asset_id, - b"BTCUSD".to_vec(), - AssetType::PoolShare(btc_asset_id, usd_asset_id), - None, - None, - )); - - // Update ED - assert_ok!(AssetRegistryPallet::update( - RuntimeOrigin::root(), - btc_asset_id, - b"BTCUSD".to_vec(), - AssetType::PoolShare(btc_asset_id, usd_asset_id), - Some(1_234_567u128), - None, - )); - - let btcusd = AssetRegistryPallet::to_bounded_name(b"BTCUSD".to_vec()).unwrap(); - - assert_eq!( - AssetRegistryPallet::assets(btc_asset_id).unwrap(), - AssetDetails { - name: btcusd, - asset_type: AssetType::PoolShare(btc_asset_id, usd_asset_id), - existential_deposit: 1_234_567u128, - xcm_rate_limit: None, - } - ); - - // corner case: change the name and also the type for an existing asset (pool share -> token) - assert_ok!(AssetRegistryPallet::update( - RuntimeOrigin::root(), - btc_asset_id, - b"superBTC".to_vec(), - AssetType::Token, - None, - None, - )); - - let superbtc_name: BoundedVec::StringLimit> = - b"superBTC".to_vec().try_into().unwrap(); - - assert_eq!( - AssetRegistryPallet::assets(1u32 + SequentialIdStart::get()).unwrap(), - AssetDetails { - name: superbtc_name, - asset_type: AssetType::Token, - existential_deposit: 1_234_567u128, - xcm_rate_limit: None, - } - ); - }); -} - -#[test] -fn update_should_update_xcm_rate_limit() { - new_test_ext().execute_with(|| { - let ed = 1_000_000u128; - - let btc_asset_id: RegistryAssetId = - AssetRegistryPallet::get_or_create_asset(b"BTC".to_vec(), AssetType::Token, ed, None).unwrap(); - - assert_ok!(AssetRegistryPallet::update( - RuntimeOrigin::root(), - btc_asset_id, - b"superBTC".to_vec(), - AssetType::Token, - None, - Some(1000 * UNIT) - )); - - let bn = AssetRegistryPallet::to_bounded_name(b"superBTC".to_vec()).unwrap(); - - assert_eq!( - AssetRegistryPallet::assets(btc_asset_id).unwrap(), - AssetDetails { - name: bn.clone(), - asset_type: AssetType::Token, - existential_deposit: ed, - xcm_rate_limit: Some(1000 * UNIT), - } - ); - - assert_eq!(XcmRateLimitsInRegistry::::get(&btc_asset_id), Some(1000 * UNIT)); - - expect_events(vec![Event::Updated { - asset_id: btc_asset_id, - asset_name: bn, - asset_type: AssetType::Token, - existential_deposit: ed, - xcm_rate_limit: Some(1000 * UNIT), - } - .into()]); - }); -} - -#[test] -fn get_ed_by_key_works() { - ExtBuilder::default() - .with_native_asset_name(b"NATIVE".to_vec()) - .with_assets(vec![ - (b"ONE".to_vec(), 1_000u128, None), - (b"TWO".to_vec(), 2_000u128, None), - ]) - .build() - .execute_with(|| { - assert_eq!(AssetRegistryPallet::get(&(1u32 + SequentialIdStart::get())), 1_000u128); - assert_eq!(AssetRegistryPallet::get(&(2u32 + SequentialIdStart::get())), 2_000u128); - assert_eq!(AssetRegistryPallet::get(&0u32), 1_000_000u128); - assert_eq!( - AssetRegistryPallet::get(&(1_000u32 + SequentialIdStart::get())), - Balance::MAX - ); // Non-existing assets are not supported - }); -} - -#[test] -fn register_asset_should_work_when_asset_is_provided() { - ExtBuilder::default() - .with_native_asset_name(b"NATIVE".to_vec()) - .build() - .execute_with(|| { - assert_ok!(AssetRegistryPallet::register( - RuntimeOrigin::root(), - b"asset_id".to_vec(), - AssetType::Token, - 1_000_000, - Some(1u32), - None, - None, - None - ),); - - let bn = AssetRegistryPallet::to_bounded_name(b"asset_id".to_vec()).unwrap(); - assert_eq!( - AssetRegistryPallet::assets(1u32).unwrap(), - AssetDetails { - name: bn, - asset_type: AssetType::Token, - existential_deposit: 1_000_000, - xcm_rate_limit: None, - } - ); - }); -} - -#[test] -fn register_asset_should_fail_when_provided_asset_is_native_asset() { - ExtBuilder::default().build().execute_with(|| { - assert_noop!( - AssetRegistryPallet::register( - RuntimeOrigin::root(), - b"asset_id".to_vec(), - AssetType::Token, - 1_000_000, - Some(NativeAssetId::get()), - None, - None, - None - ), - Error::::AssetAlreadyRegistered - ); - }); -} - -#[test] -fn register_asset_should_fail_when_provided_asset_is_already_registered() { - ExtBuilder::default().build().execute_with(|| { - assert_ok!(AssetRegistryPallet::register( - RuntimeOrigin::root(), - b"asset_id".to_vec(), - AssetType::Token, - 1_000_000, - Some(10), - None, - None, - None - )); - assert_noop!( - AssetRegistryPallet::register( - RuntimeOrigin::root(), - b"asset_id_2".to_vec(), - AssetType::Token, - 1_000_000, - Some(10), - None, - None, - None - ), - Error::::AssetAlreadyRegistered - ); - }); -} - -#[test] -fn register_asset_should_fail_when_provided_asset_is_outside_reserved_range() { - ExtBuilder::default() - .with_native_asset_name(b"NATIVE".to_vec()) - .build() - .execute_with(|| { - assert_noop!( - AssetRegistryPallet::register( - RuntimeOrigin::root(), - b"asset_id".to_vec(), - AssetType::Token, - 1_000_000, - Some(SequentialIdStart::get()), - None, - None, - None - ), - Error::::NotInReservedRange - ); - - assert_noop!( - AssetRegistryPallet::register( - RuntimeOrigin::root(), - b"asset_id".to_vec(), - AssetType::Token, - 1_000_000, - Some(SequentialIdStart::get() + 100), - None, - None, - None - ), - Error::::NotInReservedRange - ); - }); -} - -#[test] -fn register_asset_should_work_when_metadata_is_provided() { - new_test_ext().execute_with(|| { - let asset_id: RegistryAssetId = 10; - let decimals = 18; - let symbol = b"SYM".to_vec(); - let asset_name = b"asset_name".to_vec(); - let b_symbol = AssetRegistryPallet::to_bounded_name(symbol.clone()).unwrap(); - let b_asset_name = AssetRegistryPallet::to_bounded_name(asset_name.clone()).unwrap(); - - assert_ok!(AssetRegistryPallet::register( - RuntimeOrigin::root(), - asset_name, - AssetType::Token, - 1_000_000, - Some(asset_id), - Some(Metadata { symbol, decimals }), - None, - None, - )); - - expect_events(vec![ - Event::Registered { - asset_id, - asset_name: b_asset_name.clone(), - asset_type: AssetType::Token, - } - .into(), - Event::MetadataSet { - asset_id, - symbol: b_symbol.clone(), - decimals, - } - .into(), - ]); - - assert_eq!( - AssetRegistryPallet::assets(asset_id).unwrap(), - AssetDetails { - name: b_asset_name, - asset_type: AssetType::Token, - existential_deposit: 1_000_000, - xcm_rate_limit: None, - } - ); - - assert_eq!( - AssetRegistryPallet::asset_metadata(asset_id).unwrap(), - AssetMetadata { - decimals: 18u8, - symbol: b_symbol, - } - ); - }); -} - -#[test] -fn register_asset_should_work_when_location_is_provided() { - ExtBuilder::default().build().execute_with(|| { - let asset_id: RegistryAssetId = 10; - - let key = Junction::from(BoundedVec::try_from(asset_id.encode()).unwrap()); - let asset_location = AssetLocation(MultiLocation::new(0, X2(Parachain(200), key))); - - assert_ok!(AssetRegistryPallet::register( - RuntimeOrigin::root(), - b"asset_id".to_vec(), - AssetType::Token, - 1_000_000, - Some(asset_id), - None, - Some(asset_location.clone()), - None - ),); - - let bn = AssetRegistryPallet::to_bounded_name(b"asset_id".to_vec()).unwrap(); - assert_eq!( - AssetRegistryPallet::assets(asset_id).unwrap(), - AssetDetails { - name: bn, - asset_type: AssetType::Token, - existential_deposit: 1_000_000, - xcm_rate_limit: None, - } - ); - assert_eq!( - AssetRegistryPallet::location_to_asset(asset_location.clone()), - Some(asset_id) - ); - assert_eq!(AssetRegistryPallet::asset_to_location(asset_id), Some(asset_location)); - - assert!(AssetRegistryPallet::asset_metadata(asset_id).is_none(),); - }); -} - -#[test] -fn register_asset_should_fail_when_location_is_already_registered() { - ExtBuilder::default().build().execute_with(|| { - // Arrange - let asset_id: RegistryAssetId = 10; - let key = Junction::from(BoundedVec::try_from(asset_id.encode()).unwrap()); - let asset_location = AssetLocation(MultiLocation::new(0, X2(Parachain(2021), key))); - assert_ok!(AssetRegistryPallet::register( - RuntimeOrigin::root(), - b"asset_id".to_vec(), - AssetType::Token, - 1_000_000, - Some(asset_id), - None, - Some(asset_location.clone()), - None - ),); - - // Act & Assert - assert_noop!( - AssetRegistryPallet::register( - RuntimeOrigin::root(), - b"asset_id_2".to_vec(), - AssetType::Token, - 1_000_000, - Some(asset_id + 1), - None, - Some(asset_location), - None - ), - Error::::LocationAlreadyRegistered - ); - }); -} - -#[test] -fn set_location_should_fail_when_location_is_already_registered() { - ExtBuilder::default().build().execute_with(|| { - // Arrange - let asset_id: RegistryAssetId = 10; - let key = Junction::from(BoundedVec::try_from(asset_id.encode()).unwrap()); - let asset_location = AssetLocation(MultiLocation::new(0, X2(Parachain(2021), key))); - assert_ok!(AssetRegistryPallet::register( - RuntimeOrigin::root(), - b"asset_id".to_vec(), - AssetType::Token, - 1_000_000, - Some(asset_id), - None, - Some(asset_location.clone()), - None - ),); - - // Act & Assert - assert_noop!( - AssetRegistryPallet::set_location(RuntimeOrigin::root(), asset_id, asset_location), - Error::::LocationAlreadyRegistered - ); - }); -} - -#[test] -fn set_location_should_remove_old_location() { - ExtBuilder::default().build().execute_with(|| { - // Arrange - let asset_id: RegistryAssetId = 10; - let key = Junction::from(BoundedVec::try_from(asset_id.encode()).unwrap()); - let old_asset_location = AssetLocation(MultiLocation::new(0, X2(Parachain(2021), key))); - assert_ok!(AssetRegistryPallet::register( - RuntimeOrigin::root(), - b"asset_id".to_vec(), - AssetType::Token, - 1_000_000, - Some(asset_id), - None, - Some(old_asset_location.clone()), - None - ),); - - // Act - assert_ok!(AssetRegistryPallet::set_location( - RuntimeOrigin::root(), - asset_id, - AssetLocation(MultiLocation::new(0, X2(Parachain(2022), key))) - )); - - // Assert - assert_eq!(AssetRegistryPallet::location_to_asset(old_asset_location), None); - }); -} - -#[test] -fn register_asset_should_work_when_all_optional_are_provided() { - ExtBuilder::default().build().execute_with(|| { - let asset_id: RegistryAssetId = 10; - - let key = Junction::from(BoundedVec::try_from(asset_id.encode()).unwrap()); - let asset_location = AssetLocation(MultiLocation::new(0, X2(Parachain(200), key))); - - assert_ok!(AssetRegistryPallet::register( - RuntimeOrigin::root(), - b"asset_id".to_vec(), - AssetType::Token, - 1_000_000, - Some(asset_id), - Some(Metadata { - symbol: b"SYM".to_vec(), - decimals: 18 - }), - Some(asset_location.clone()), - Some(1000 * UNIT) - ),); - - let bn = AssetRegistryPallet::to_bounded_name(b"asset_id".to_vec()).unwrap(); - assert_eq!( - AssetRegistryPallet::assets(asset_id).unwrap(), - AssetDetails { - name: bn, - asset_type: AssetType::Token, - existential_deposit: 1_000_000, - xcm_rate_limit: Some(1000 * UNIT), - } - ); - assert_eq!( - AssetRegistryPallet::location_to_asset(asset_location.clone()), - Some(asset_id) - ); - assert_eq!(AssetRegistryPallet::asset_to_location(asset_id), Some(asset_location)); - let b_symbol: BoundedVec::StringLimit> = b"SYM".to_vec().try_into().unwrap(); - assert_eq!( - AssetRegistryPallet::asset_metadata(asset_id).unwrap(), - AssetMetadata { - decimals: 18u8, - symbol: b_symbol, - } - ); - }); -} diff --git a/pallets/asset-registry/src/tests/create_trait.rs b/pallets/asset-registry/src/tests/create_trait.rs new file mode 100644 index 000000000..8c39bb0fe --- /dev/null +++ b/pallets/asset-registry/src/tests/create_trait.rs @@ -0,0 +1,508 @@ +use super::*; + +use hydradx_traits::registry::Create; +use mock::Registry; + +use frame_support::storage::with_transaction; +use polkadot_xcm::v3::{ + Junction::{self, Parachain}, + Junctions::X2, + MultiLocation, +}; +use sp_runtime::{DispatchResult, TransactionOutcome}; + +#[test] +fn register_asset_should_work() { + ExtBuilder::default().build().execute_with(|| { + let _ = with_transaction(|| { + let asset_id = 1; + let name: BoundedVec = b"Test asset".to_vec().try_into().unwrap(); + let symbol: BoundedVec = b"TKN".to_vec().try_into().unwrap(); + let decimals = 12; + let xcm_rate_limit = 1_000; + let ed = 10_000; + let is_sufficient = true; + + let key = Junction::from(BoundedVec::try_from(asset_id.encode()).unwrap()); + let asset_location = AssetLocation(MultiLocation::new(0, X2(Parachain(200), key))); + + //Act + assert_ok!(>::register_asset( + Some(asset_id), + Some(name.clone()), + AssetKind::XYK, + Some(ed), + Some(symbol.clone()), + Some(decimals), + Some(asset_location.clone()), + Some(xcm_rate_limit), + is_sufficient + )); + + //Assert + assert_eq!( + Registry::assets(asset_id), + Some(AssetDetails { + name: Some(name.clone()), + asset_type: AssetType::XYK, + existential_deposit: ed, + xcm_rate_limit: Some(xcm_rate_limit), + symbol: Some(symbol.clone()), + decimals: Some(decimals), + is_sufficient + }) + ); + + assert_eq!(Registry::asset_ids(name.clone()), Some(asset_id)); + + assert_eq!(Registry::location_assets(asset_location.clone()), Some(asset_id)); + assert_eq!(Registry::locations(asset_id), Some(asset_location.clone())); + + assert!(has_event( + Event::::Registered { + asset_id, + asset_name: Some(name), + asset_type: AssetType::XYK, + existential_deposit: ed, + xcm_rate_limit: Some(xcm_rate_limit), + symbol: Some(symbol), + decimals: Some(decimals), + is_sufficient + } + .into() + )); + + assert!(has_event( + Event::::LocationSet { + asset_id, + location: asset_location + } + .into() + )); + + TransactionOutcome::Commit(DispatchResult::Ok(())) + }); + }); +} + +#[test] +fn register_insufficient_asset_should_work() { + ExtBuilder::default().build().execute_with(|| { + let _ = with_transaction(|| { + let asset_id = 1; + let name: BoundedVec = b"Test asset".to_vec().try_into().unwrap(); + let symbol: BoundedVec = b"TKN".to_vec().try_into().unwrap(); + let decimals = 12; + let xcm_rate_limit = 1_000; + let ed = 10_000; + + let key = Junction::from(BoundedVec::try_from(asset_id.encode()).unwrap()); + let asset_location = AssetLocation(MultiLocation::new(0, X2(Parachain(200), key))); + + //Act + assert_ok!(>::register_insufficient_asset( + Some(asset_id), + Some(name.clone()), + AssetKind::XYK, + Some(ed), + Some(symbol.clone()), + Some(decimals), + Some(asset_location.clone()), + Some(xcm_rate_limit), + )); + + //Assert + assert_eq!( + Registry::assets(asset_id), + Some(AssetDetails { + name: Some(name.clone()), + asset_type: AssetType::XYK, + existential_deposit: ed, + xcm_rate_limit: Some(xcm_rate_limit), + symbol: Some(symbol.clone()), + decimals: Some(decimals), + is_sufficient: false + }) + ); + + assert_eq!(Registry::asset_ids(name.clone()), Some(asset_id)); + + assert_eq!(Registry::location_assets(asset_location.clone()), Some(asset_id)); + assert_eq!(Registry::locations(asset_id), Some(asset_location.clone())); + + assert!(has_event( + Event::::Registered { + asset_id, + asset_name: Some(name), + asset_type: AssetType::XYK, + existential_deposit: ed, + xcm_rate_limit: Some(xcm_rate_limit), + symbol: Some(symbol), + decimals: Some(decimals), + is_sufficient: false + } + .into() + )); + + assert!(has_event( + Event::::LocationSet { + asset_id, + location: asset_location + } + .into() + )); + + TransactionOutcome::Commit(DispatchResult::Ok(())) + }); + }); +} + +#[test] +fn register_sufficient_asset_should_work() { + ExtBuilder::default().build().execute_with(|| { + let _ = with_transaction(|| { + let asset_id = 1; + let name: BoundedVec = b"Test asset".to_vec().try_into().unwrap(); + let symbol: BoundedVec = b"TKN".to_vec().try_into().unwrap(); + let decimals = 12; + let xcm_rate_limit = 1_000; + let ed = 10_000; + + let key = Junction::from(BoundedVec::try_from(asset_id.encode()).unwrap()); + let asset_location = AssetLocation(MultiLocation::new(0, X2(Parachain(200), key))); + + //Act + assert_ok!(>::register_sufficient_asset( + Some(asset_id), + Some(name.clone()), + AssetKind::XYK, + ed, + Some(symbol.clone()), + Some(decimals), + Some(asset_location.clone()), + Some(xcm_rate_limit), + )); + + //Assert + assert_eq!( + Registry::assets(asset_id), + Some(AssetDetails { + name: Some(name.clone()), + asset_type: AssetType::XYK, + existential_deposit: ed, + xcm_rate_limit: Some(xcm_rate_limit), + symbol: Some(symbol.clone()), + decimals: Some(decimals), + is_sufficient: true + }) + ); + + assert_eq!(Registry::asset_ids(name.clone()), Some(asset_id)); + + assert_eq!(Registry::location_assets(asset_location.clone()), Some(asset_id)); + assert_eq!(Registry::locations(asset_id), Some(asset_location.clone())); + + assert!(has_event( + Event::::Registered { + asset_id, + asset_name: Some(name), + asset_type: AssetType::XYK, + existential_deposit: ed, + xcm_rate_limit: Some(xcm_rate_limit), + symbol: Some(symbol), + decimals: Some(decimals), + is_sufficient: true + } + .into() + )); + + assert!(has_event( + Event::::LocationSet { + asset_id, + location: asset_location + } + .into() + )); + + TransactionOutcome::Commit(DispatchResult::Ok(())) + }); + }); +} + +#[test] +fn get_or_register_asset_should_register_asset_when_does_not_exists() { + ExtBuilder::default().build().execute_with(|| { + let _ = with_transaction(|| { + let new_asset_id = Registry::next_asset_id().unwrap(); + let name: BoundedVec = b"Test asset".to_vec().try_into().unwrap(); + let symbol: BoundedVec = b"TKN".to_vec().try_into().unwrap(); + let decimals = 12; + let xcm_rate_limit = 1_000; + let ed = 10_000; + let is_sufficient = true; + + let key = Junction::from(BoundedVec::try_from(new_asset_id.encode()).unwrap()); + let asset_location = AssetLocation(MultiLocation::new(0, X2(Parachain(200), key))); + + //Act + assert_ok!( + >::get_or_register_asset( + name.clone(), + AssetKind::XYK, + Some(ed), + Some(symbol.clone()), + Some(decimals), + Some(asset_location.clone()), + Some(xcm_rate_limit), + is_sufficient + ), + new_asset_id + ); + + //Assert + assert_eq!( + Registry::assets(new_asset_id), + Some(AssetDetails { + name: Some(name.clone()), + asset_type: AssetType::XYK, + existential_deposit: ed, + xcm_rate_limit: Some(xcm_rate_limit), + symbol: Some(symbol.clone()), + decimals: Some(decimals), + is_sufficient + }) + ); + + assert_eq!(Registry::asset_ids(name.clone()), Some(new_asset_id)); + + assert_eq!(Registry::location_assets(asset_location.clone()), Some(new_asset_id)); + assert_eq!(Registry::locations(new_asset_id), Some(asset_location.clone())); + + assert!(has_event( + Event::::Registered { + asset_id: new_asset_id, + asset_name: Some(name), + asset_type: AssetType::XYK, + existential_deposit: ed, + xcm_rate_limit: Some(xcm_rate_limit), + symbol: Some(symbol), + decimals: Some(decimals), + is_sufficient + } + .into() + )); + + assert!(has_event( + Event::::LocationSet { + asset_id: new_asset_id, + location: asset_location + } + .into() + )); + + TransactionOutcome::Commit(DispatchResult::Ok(())) + }); + }); +} + +#[test] +fn get_or_register_asset_should_return_asset_id_when_asset_exists() { + let existing_asset_id = 1_u32; + ExtBuilder::default() + .with_assets(vec![( + Some(existing_asset_id), + Some(b"Asset".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + false, + )]) + .build() + .execute_with(|| { + let _ = with_transaction(|| { + let name: BoundedVec = b"Asset".to_vec().try_into().unwrap(); + let symbol: BoundedVec = b"TKN".to_vec().try_into().unwrap(); + let decimals = 12; + let xcm_rate_limit = 1_000; + let ed = 10_000; + let is_sufficient = true; + + let key = Junction::from(BoundedVec::try_from(1_000.encode()).unwrap()); + let asset_location = AssetLocation(MultiLocation::new(0, X2(Parachain(200), key))); + + //Act + assert_ok!( + >::get_or_register_asset( + name.clone(), + AssetKind::XYK, + Some(ed), + Some(symbol), + Some(decimals), + Some(asset_location), + Some(xcm_rate_limit), + is_sufficient + ), + existing_asset_id + ); + + //Assert + assert_eq!( + Registry::assets(existing_asset_id), + Some(AssetDetails { + name: Some(name), + asset_type: AssetType::Token, + existential_deposit: UNIT, + xcm_rate_limit: None, + symbol: None, + decimals: None, + is_sufficient: false + }) + ); + + TransactionOutcome::Commit(DispatchResult::Ok(())) + }); + }); +} + +#[test] +fn get_or_register_sufficient_asset_should_work() { + ExtBuilder::default().build().execute_with(|| { + let _ = with_transaction(|| { + let new_asset_id = Registry::next_asset_id().unwrap(); + let name: BoundedVec = b"Test asset".to_vec().try_into().unwrap(); + let symbol: BoundedVec = b"TKN".to_vec().try_into().unwrap(); + let decimals = 12; + let xcm_rate_limit = 1_000; + let ed = 10_000; + + let key = Junction::from(BoundedVec::try_from(new_asset_id.encode()).unwrap()); + let asset_location = AssetLocation(MultiLocation::new(0, X2(Parachain(200), key))); + + //Act + assert_ok!(>::get_or_register_sufficient_asset( + name.clone(), + AssetKind::XYK, + ed, + Some(symbol.clone()), + Some(decimals), + Some(asset_location.clone()), + Some(xcm_rate_limit), + ),); + + //Assert + assert_eq!( + Registry::assets(new_asset_id), + Some(AssetDetails { + name: Some(name.clone()), + asset_type: AssetType::XYK, + existential_deposit: ed, + xcm_rate_limit: Some(xcm_rate_limit), + symbol: Some(symbol.clone()), + decimals: Some(decimals), + is_sufficient: true + }) + ); + + assert_eq!(Registry::asset_ids(name.clone()), Some(new_asset_id)); + + assert_eq!(Registry::location_assets(asset_location.clone()), Some(new_asset_id)); + assert_eq!(Registry::locations(new_asset_id), Some(asset_location.clone())); + + assert!(has_event( + Event::::Registered { + asset_id: new_asset_id, + asset_name: Some(name), + asset_type: AssetType::XYK, + existential_deposit: ed, + xcm_rate_limit: Some(xcm_rate_limit), + symbol: Some(symbol), + decimals: Some(decimals), + is_sufficient: true + } + .into() + )); + + assert!(has_event( + Event::::LocationSet { + asset_id: new_asset_id, + location: asset_location + } + .into() + )); + + TransactionOutcome::Commit(DispatchResult::Ok(())) + }); + }); +} + +#[test] +fn get_or_register_insufficient_asset_should_work() { + ExtBuilder::default().build().execute_with(|| { + let _ = with_transaction(|| { + let new_asset_id = Registry::next_asset_id().unwrap(); + let name: BoundedVec = b"Test asset".to_vec().try_into().unwrap(); + let symbol: BoundedVec = b"TKN".to_vec().try_into().unwrap(); + let decimals = 12; + let xcm_rate_limit = 1_000; + let ed = 10_000; + + let key = Junction::from(BoundedVec::try_from(new_asset_id.encode()).unwrap()); + let asset_location = AssetLocation(MultiLocation::new(0, X2(Parachain(200), key))); + + //Act + assert_ok!(>::get_or_register_insufficient_asset( + name.clone(), + AssetKind::XYK, + Some(ed), + Some(symbol.clone()), + Some(decimals), + Some(asset_location.clone()), + Some(xcm_rate_limit), + ),); + + //Assert + assert_eq!( + Registry::assets(new_asset_id), + Some(AssetDetails { + name: Some(name.clone()), + asset_type: AssetType::XYK, + existential_deposit: ed, + xcm_rate_limit: Some(xcm_rate_limit), + symbol: Some(symbol.clone()), + decimals: Some(decimals), + is_sufficient: false + }) + ); + + assert_eq!(Registry::asset_ids(name.clone()), Some(new_asset_id)); + + assert_eq!(Registry::location_assets(asset_location.clone()), Some(new_asset_id)); + assert_eq!(Registry::locations(new_asset_id), Some(asset_location.clone())); + + assert!(has_event( + Event::::Registered { + asset_id: new_asset_id, + asset_name: Some(name), + asset_type: AssetType::XYK, + existential_deposit: ed, + xcm_rate_limit: Some(xcm_rate_limit), + symbol: Some(symbol), + decimals: Some(decimals), + is_sufficient: false + } + .into() + )); + + assert!(has_event( + Event::::LocationSet { + asset_id: new_asset_id, + location: asset_location + } + .into() + )); + + TransactionOutcome::Commit(DispatchResult::Ok(())) + }); + }); +} diff --git a/pallets/asset-registry/src/tests/inspect_trait.rs b/pallets/asset-registry/src/tests/inspect_trait.rs new file mode 100644 index 000000000..ee57dde96 --- /dev/null +++ b/pallets/asset-registry/src/tests/inspect_trait.rs @@ -0,0 +1,269 @@ +use super::*; + +use frame_support::storage::with_transaction; +use hydradx_traits::registry::{AssetKind, Inspect}; +use mock::Registry; + +use pretty_assertions::assert_eq; +use sp_runtime::{DispatchResult, TransactionOutcome}; + +#[test] +fn is_sufficient_should_work() { + let suff_asset_id = 1_u32; + let insuff_asset_id = 2_u32; + let non_existing_id = 3_u32; + + ExtBuilder::default() + .with_assets(vec![ + ( + Some(suff_asset_id), + Some(b"Suff".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ( + Some(insuff_asset_id), + Some(b"Insuff".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + false, + ), + ]) + .build() + .execute_with(|| { + assert_eq!(::is_sufficient(suff_asset_id), true); + + assert_eq!(::is_sufficient(insuff_asset_id), false); + + assert_eq!(::is_sufficient(non_existing_id), false); + }); +} + +#[test] +fn exists_should_work() { + let asset_id = 2_u32; + let non_existing_id = 3_u32; + + ExtBuilder::default() + .with_assets(vec![( + Some(asset_id), + Some(b"Suff".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + )]) + .build() + .execute_with(|| { + assert_eq!(::exists(asset_id), true); + + assert_eq!(::exists(non_existing_id), false); + }); +} + +#[test] +fn decimals_should_work() { + let non_existing_id = 543_u32; + + ExtBuilder::default() + .with_assets(vec![ + ( + Some(1), + Some(b"TKN1".to_vec().try_into().unwrap()), + UNIT, + None, + Some(5_u8), + None, + true, + ), + ( + Some(2), + Some(b"TKN2".to_vec().try_into().unwrap()), + UNIT, + None, + Some(0_u8), + None, + true, + ), + ( + Some(3), + Some(b"TKN3".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ]) + .build() + .execute_with(|| { + assert_eq!(::decimals(1), Some(5)); + + assert_eq!(::decimals(2), Some(0)); + + assert_eq!(::decimals(3), None); + + assert_eq!(::decimals(non_existing_id), None); + }); +} + +#[test] +fn asset_type_should_work() { + let non_existing_id = 543_u32; + + ExtBuilder::default().build().execute_with(|| { + let _ = with_transaction(|| { + //Arrange + let token_type_id = + Registry::register_insufficient_asset(None, None, AssetKind::Token, None, None, None, None, None) + .unwrap(); + let xyk_type_id = + Registry::register_insufficient_asset(None, None, AssetKind::XYK, None, None, None, None, None) + .unwrap(); + let stableswap_type_id = + Registry::register_insufficient_asset(None, None, AssetKind::StableSwap, None, None, None, None, None) + .unwrap(); + let bond_type_id = + Registry::register_insufficient_asset(None, None, AssetKind::Bond, None, None, None, None, None) + .unwrap(); + let external_type_id = + Registry::register_insufficient_asset(None, None, AssetKind::External, None, None, None, None, None) + .unwrap(); + + //Assert + assert_eq!(::asset_type(token_type_id), Some(AssetKind::Token)); + assert_eq!(::asset_type(xyk_type_id), Some(AssetKind::XYK)); + assert_eq!( + ::asset_type(stableswap_type_id), + Some(AssetKind::StableSwap) + ); + assert_eq!(::asset_type(bond_type_id), Some(AssetKind::Bond)); + assert_eq!( + ::asset_type(external_type_id), + Some(AssetKind::External) + ); + + assert_eq!(::asset_type(non_existing_id), None); + + TransactionOutcome::Commit(DispatchResult::Ok(())) + }); + }); +} + +#[test] +fn is_banned_should_work() { + ExtBuilder::default() + .with_assets(vec![ + ( + Some(1), + Some(b"Suff".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ( + Some(2), + Some(b"Insuff".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + false, + ), + ]) + .build() + .execute_with(|| { + //Arrange + //NOTE: update origin is set to ensure_signed in tests + assert_ok!(Registry::ban_asset(RuntimeOrigin::signed(ALICE), 1)); + + //Act & assert + assert_eq!(::is_banned(1), true); + + assert_eq!(::is_banned(2), false); + }); +} + +#[test] +fn asset_name_should_work() { + let non_existing_id = 543_u32; + let asset_one_name = b"Tkn1".to_vec(); + + ExtBuilder::default() + .with_assets(vec![ + ( + Some(1), + Some(asset_one_name.clone().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + (Some(2), None, UNIT, None, None, None, false), + ( + Some(3), + Some(b"Tkn3".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ]) + .build() + .execute_with(|| { + //Act & assert + assert_eq!(::asset_name(1), Some(asset_one_name)); + + assert_eq!(::asset_name(2), None); + + assert_eq!(::asset_name(non_existing_id), None); + }); +} + +#[test] +fn asset_symbol_should_work() { + let non_existing_id = 543_u32; + let asset_one_symbol = b"TKN".to_vec(); + + ExtBuilder::default() + .with_assets(vec![ + ( + Some(1), + Some(b"Tkn1".to_vec().try_into().unwrap()), + UNIT, + Some(asset_one_symbol.clone().try_into().unwrap()), + None, + None, + true, + ), + (Some(2), None, UNIT, None, None, None, false), + ( + Some(3), + Some(b"Tkn3".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ]) + .build() + .execute_with(|| { + //Act & assert + assert_eq!(::asset_symbol(1), Some(asset_one_symbol)); + + assert_eq!(::asset_name(2), None); + + assert_eq!(::asset_name(non_existing_id), None); + }); +} diff --git a/pallets/asset-registry/src/mock.rs b/pallets/asset-registry/src/tests/mock.rs similarity index 62% rename from pallets/asset-registry/src/mock.rs rename to pallets/asset-registry/src/tests/mock.rs index b3cb36938..dad279dde 100644 --- a/pallets/asset-registry/src/mock.rs +++ b/pallets/asset-registry/src/tests/mock.rs @@ -19,6 +19,7 @@ use frame_support::parameter_types; use frame_system as system; +use orml_traits::parameter_type_with_key; use sp_core::H256; use sp_runtime::{ traits::{BlakeTwo256, IdentityLookup}, @@ -29,12 +30,15 @@ use frame_support::traits::Everything; use polkadot_xcm::v3::MultiLocation; -use crate::{self as asset_registry, Config}; +use crate as pallet_asset_registry; +use crate::types::{Name, Symbol}; pub type AssetId = u32; pub type Balance = u128; pub const UNIT: Balance = 1_000_000_000_000; +pub const ALICE: u64 = 1_000; +pub const TREASURY: u64 = 2_222; type Block = frame_system::mocking::MockBlock; @@ -42,7 +46,8 @@ frame_support::construct_runtime!( pub enum Test { System: frame_system, - Registry: asset_registry, + Tokens: orml_tokens, + Registry: pallet_asset_registry, } ); @@ -51,7 +56,10 @@ parameter_types! { pub const BlockHashCount: u64 = 250; pub const SS58Prefix: u8 = 63; pub const NativeAssetId: AssetId = 0; + #[derive(PartialEq, Debug)] pub const RegistryStringLimit: u32 = 10; + #[derive(PartialEq, Debug)] + pub const RegistryMinStringLimit: u32 = 2; pub const SequentialIdStart: u32 = 1_000_000; } @@ -87,63 +95,87 @@ use scale_info::TypeInfo; #[derive(Debug, Default, Encode, Decode, Clone, PartialEq, Eq, TypeInfo, MaxEncodedLen)] pub struct AssetLocation(pub MultiLocation); -impl Config for Test { +impl pallet_asset_registry::Config for Test { type RuntimeEvent = RuntimeEvent; + type Currency = Tokens; type RegistryOrigin = frame_system::EnsureRoot; + type UpdateOrigin = frame_system::EnsureSigned; type AssetId = u32; - type Balance = Balance; type AssetNativeLocation = AssetLocation; type StringLimit = RegistryStringLimit; + type MinStringLimit = RegistryMinStringLimit; type SequentialIdStartAt = SequentialIdStart; - type NativeAssetId = NativeAssetId; + type RegExternalWeightMultiplier = frame_support::traits::ConstU64<1>; + type WeightInfo = (); +} + +parameter_type_with_key! { + pub ExistentialDeposits: |_currency_id: AssetId| -> Balance { + 0 + }; +} + +impl orml_tokens::Config for Test { + type RuntimeEvent = RuntimeEvent; + type Balance = Balance; + type Amount = i128; + type CurrencyId = AssetId; type WeightInfo = (); + type ExistentialDeposits = ExistentialDeposits; + type MaxLocks = (); + type DustRemovalWhitelist = Everything; + type MaxReserves = (); + type ReserveIdentifier = (); + type CurrencyHooks = (); } -pub type AssetRegistryPallet = crate::Pallet; #[derive(Default)] +#[allow(clippy::type_complexity)] pub struct ExtBuilder { - registered_assets: Vec<(Vec, Balance, Option)>, - native_asset_name: Option>, + registered_assets: Vec<( + Option, + Option>, + Balance, + Option>, + Option, + Option, + bool, + )>, } impl ExtBuilder { - pub fn with_assets(mut self, asset_ids: Vec<(Vec, Balance, Option)>) -> Self { - self.registered_assets = asset_ids; - self - } - - pub fn with_native_asset_name(mut self, name: Vec) -> Self { - self.native_asset_name = Some(name); + #[allow(clippy::type_complexity)] + pub fn with_assets( + mut self, + assets: Vec<( + Option, + Option>, + Balance, + Option>, + Option, + Option, + bool, + )>, + ) -> Self { + self.registered_assets = assets; self } pub fn build(self) -> sp_io::TestExternalities { let mut t = frame_system::GenesisConfig::::default().build_storage().unwrap(); - if let Some(name) = self.native_asset_name { - crate::GenesisConfig:: { - registered_assets: self.registered_assets, - native_asset_name: name, - native_existential_deposit: 1_000_000u128, - } - } else { - crate::GenesisConfig:: { - registered_assets: self.registered_assets, - ..Default::default() - } + crate::GenesisConfig:: { + registered_assets: self.registered_assets, + ..Default::default() } .assimilate_storage(&mut t) .unwrap(); - t.into() - } -} -pub fn new_test_ext() -> sp_io::TestExternalities { - let mut ext = ExtBuilder::default().build(); - ext.execute_with(|| System::set_block_number(1)); - ext -} + let mut r: sp_io::TestExternalities = t.into(); + r.execute_with(|| { + System::set_block_number(1); + }); -pub fn expect_events(e: Vec) { - test_utils::expect_events::(e); + r + } } diff --git a/pallets/asset-registry/src/tests/mod.rs b/pallets/asset-registry/src/tests/mod.rs new file mode 100644 index 000000000..4e789aee6 --- /dev/null +++ b/pallets/asset-registry/src/tests/mod.rs @@ -0,0 +1,24 @@ +use mock::*; + +use crate::*; +use frame_support::{assert_noop, assert_ok}; + +mod create_trait; +mod inspect_trait; +pub(crate) mod mock; +mod mutate_trait; +mod register; +#[allow(clippy::module_inception)] +mod tests; +mod update; + +#[macro_export] +macro_rules! assert_last_event { + ( $x:expr ) => {{ + pretty_assertions::assert_eq!(System::events().last().expect("events expected").event, $x); + }}; +} + +pub fn has_event(event: mock::RuntimeEvent) -> bool { + System::events().iter().any(|record| record.event == event) +} diff --git a/pallets/asset-registry/src/tests/mutate_trait.rs b/pallets/asset-registry/src/tests/mutate_trait.rs new file mode 100644 index 000000000..991a5b557 --- /dev/null +++ b/pallets/asset-registry/src/tests/mutate_trait.rs @@ -0,0 +1,82 @@ +use super::*; + +use hydradx_traits::registry::Mutate; +use mock::Registry; + +use polkadot_xcm::v3::{ + Junction::{self, Parachain}, + Junctions::X2, + MultiLocation, +}; + +#[test] +fn set_location_should_work_when_location_was_not_set_yet() { + let asset_id = 1_u32; + ExtBuilder::default() + .with_assets(vec![( + Some(asset_id), + Some(b"Suff".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + )]) + .build() + .execute_with(|| { + let key = Junction::from(BoundedVec::try_from(asset_id.encode()).unwrap()); + let location = AssetLocation(MultiLocation::new(0, X2(Parachain(200), key))); + assert_eq!(Registry::locations(asset_id), None); + + //Act + assert_ok!(::set_location(asset_id, location.clone())); + + //Assert + assert_eq!(Registry::location_assets(location.clone()), Some(asset_id)); + assert_eq!(Registry::locations(asset_id), Some(location)); + }); +} + +#[test] +fn set_location_should_not_work_when_location_was_not() { + let asset_id = 1_u32; + ExtBuilder::default() + .with_assets(vec![( + Some(asset_id), + Some(b"Suff".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + )]) + .build() + .execute_with(|| { + //Arrange + let key = Junction::from(BoundedVec::try_from(asset_id.encode()).unwrap()); + let location = AssetLocation(MultiLocation::new(0, X2(Parachain(200), key))); + Pallet::::set_location(asset_id, location.clone()).unwrap(); + + //Act + assert_noop!( + ::set_location(asset_id, location), + Error::::LocationAlreadyRegistered + ); + }); +} + +#[test] +fn set_location_should_not_work_when_asset_does_not_exists() { + let non_existing_id = 190_u32; + ExtBuilder::default().build().execute_with(|| { + //Arrange + let key = Junction::from(BoundedVec::try_from(non_existing_id.encode()).unwrap()); + let location = AssetLocation(MultiLocation::new(0, X2(Parachain(200), key))); + + //Act + assert_noop!( + ::set_location(non_existing_id, location), + Error::::AssetNotFound + ); + }); +} diff --git a/pallets/asset-registry/src/tests/register.rs b/pallets/asset-registry/src/tests/register.rs new file mode 100644 index 000000000..f877acbf0 --- /dev/null +++ b/pallets/asset-registry/src/tests/register.rs @@ -0,0 +1,826 @@ +use super::*; + +use crate::types::AssetType; +use frame_support::error::BadOrigin; +use frame_support::traits::tokens::fungibles::Mutate as MutateFungibles; +use mock::RegistryStringLimit; +use mock::{AssetId, Registry}; +use polkadot_xcm::v3::{ + Junction::{self, Parachain}, + Junctions::X2, + MultiLocation, +}; +use pretty_assertions::assert_eq; + +#[test] +fn register_should_work_when_all_params_are_provided() { + ExtBuilder::default().build().execute_with(|| { + let asset_id = 1; + let name: BoundedVec = b"Test asset".to_vec().try_into().unwrap(); + let symbol: BoundedVec = b"TKN".to_vec().try_into().unwrap(); + let decimals = 12; + let xcm_rate_limit = 1_000; + let ed = 10_000; + let is_sufficient = true; + + let key = Junction::from(BoundedVec::try_from(asset_id.encode()).unwrap()); + let asset_location = AssetLocation(MultiLocation::new(0, X2(Parachain(200), key))); + + //Act + assert_ok!(Registry::register( + RuntimeOrigin::root(), + Some(asset_id), + Some(name.clone()), + AssetType::Token, + Some(ed), + Some(symbol.clone()), + Some(decimals), + Some(asset_location.clone()), + Some(xcm_rate_limit), + is_sufficient + )); + + //Assert + assert_eq!( + Registry::assets(asset_id), + Some(AssetDetails { + name: Some(name.clone()), + asset_type: AssetType::Token, + existential_deposit: ed, + xcm_rate_limit: Some(xcm_rate_limit), + symbol: Some(symbol.clone()), + decimals: Some(decimals), + is_sufficient + }) + ); + + assert_eq!(Registry::asset_ids(name.clone()), Some(asset_id)); + + assert_eq!(Registry::location_assets(asset_location.clone()), Some(asset_id)); + assert_eq!(Registry::locations(asset_id), Some(asset_location.clone())); + + assert!(has_event( + Event::::Registered { + asset_id, + asset_name: Some(name), + asset_type: AssetType::Token, + existential_deposit: ed, + xcm_rate_limit: Some(xcm_rate_limit), + symbol: Some(symbol), + decimals: Some(decimals), + is_sufficient + } + .into() + )); + + assert!(has_event( + Event::::LocationSet { + asset_id, + location: asset_location + } + .into() + )); + }); +} + +#[test] +fn register_should_work_when_only_required_params_were_provided() { + ExtBuilder::default().build().execute_with(|| { + let expected_id = Pallet::::next_asset_id().unwrap(); + let is_sufficient = true; + + //Act + assert_ok!(Registry::register( + RuntimeOrigin::root(), + None, + None, + AssetType::Token, + None, + None, + None, + None, + None, + is_sufficient + )); + + //Assert + assert_eq!( + Registry::assets(expected_id), + Some(AssetDetails { + name: None, + asset_type: AssetType::Token, + existential_deposit: 1, + xcm_rate_limit: None, + symbol: None, + decimals: None, + is_sufficient + }) + ); + + assert!(has_event( + Event::::Registered { + asset_id: expected_id, + asset_name: None, + asset_type: AssetType::Token, + existential_deposit: 1, + xcm_rate_limit: None, + symbol: None, + decimals: None, + is_sufficient + } + .into() + )); + }); +} + +#[test] +fn register_should_not_work_when_asset_id_is_not_from_reserved_range() { + ExtBuilder::default().build().execute_with(|| { + let asset_id: AssetId = Pallet::::next_asset_id().unwrap(); + let name: BoundedVec = b"Test asset".to_vec().try_into().unwrap(); + let symbol: BoundedVec = b"TKN".to_vec().try_into().unwrap(); + let decimals = 12; + let xcm_rate_limit = 1_000; + let ed = 10_000; + let is_sufficient = true; + + let key = Junction::from(BoundedVec::try_from(asset_id.encode()).unwrap()); + let asset_location = AssetLocation(MultiLocation::new(0, X2(Parachain(200), key))); + + //Act + assert_noop!( + Registry::register( + RuntimeOrigin::root(), + Some(asset_id), + Some(name), + AssetType::Token, + Some(ed), + Some(symbol), + Some(decimals), + Some(asset_location), + Some(xcm_rate_limit), + is_sufficient + ), + Error::::NotInReservedRange + ); + }); +} + +#[test] +fn register_should_not_work_when_asset_id_is_already_used() { + ExtBuilder::default() + .with_assets(vec![ + ( + Some(1), + Some(b"Tkn1".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ( + Some(2), + Some(b"Tkn2".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ( + Some(3), + Some(b"Tkn3".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ]) + .build() + .execute_with(|| { + let asset_id = 1; + let name: BoundedVec = b"Test asset".to_vec().try_into().unwrap(); + let symbol: BoundedVec = b"TKN".to_vec().try_into().unwrap(); + let decimals = 12; + let xcm_rate_limit = 1_000; + let ed = 10_000; + let is_sufficient = true; + + let key = Junction::from(BoundedVec::try_from(asset_id.encode()).unwrap()); + let asset_location = AssetLocation(MultiLocation::new(0, X2(Parachain(200), key))); + + //Act + assert_noop!( + Registry::register( + RuntimeOrigin::root(), + Some(asset_id), + Some(name), + AssetType::Token, + Some(ed), + Some(symbol), + Some(decimals), + Some(asset_location), + Some(xcm_rate_limit), + is_sufficient + ), + Error::::AssetAlreadyRegistered + ); + }); +} + +#[test] +fn register_should_not_work_when_asset_name_is_already_used() { + ExtBuilder::default() + .with_assets(vec![ + ( + Some(1), + Some(b"Tkn1".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ( + Some(2), + Some(b"Tkn2".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ( + Some(3), + Some(b"Tkn3".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ]) + .build() + .execute_with(|| { + let asset_id = 4; + let name: BoundedVec = b"Tkn3".to_vec().try_into().unwrap(); + let symbol: BoundedVec = b"TKN".to_vec().try_into().unwrap(); + let decimals = 12; + let xcm_rate_limit = 1_000; + let ed = 10_000; + let is_sufficient = true; + + let key = Junction::from(BoundedVec::try_from(asset_id.encode()).unwrap()); + let asset_location = AssetLocation(MultiLocation::new(0, X2(Parachain(200), key))); + + //Act + assert_noop!( + Registry::register( + RuntimeOrigin::root(), + Some(asset_id), + Some(name), + AssetType::Token, + Some(ed), + Some(symbol), + Some(decimals), + Some(asset_location), + Some(xcm_rate_limit), + is_sufficient + ), + Error::::AssetAlreadyRegistered + ); + }); +} + +#[test] +fn register_should_not_work_when_asset_location_is_already_used() { + ExtBuilder::default() + .with_assets(vec![ + ( + Some(1), + Some(b"Tkn1".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ( + Some(2), + Some(b"Tkn2".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ( + Some(3), + Some(b"Tkn3".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ]) + .build() + .execute_with(|| { + //Arrange + let asset_id = 4; + + let key = Junction::from(BoundedVec::try_from(asset_id.encode()).unwrap()); + let asset_location = AssetLocation(MultiLocation::new(0, X2(Parachain(200), key))); + Pallet::::set_location(3, asset_location.clone()).unwrap(); + + let name: BoundedVec = b"Tkn4".to_vec().try_into().unwrap(); + let symbol: BoundedVec = b"TKN".to_vec().try_into().unwrap(); + let decimals = 12; + let xcm_rate_limit = 1_000; + let ed = 10_000; + let is_sufficient = true; + + //Act + assert_noop!( + Registry::register( + RuntimeOrigin::root(), + Some(asset_id), + Some(name), + AssetType::Token, + Some(ed), + Some(symbol), + Some(decimals), + Some(asset_location), + Some(xcm_rate_limit), + is_sufficient + ), + Error::::LocationAlreadyRegistered + ); + }); +} + +#[test] +fn register_should_not_work_when_origin_is_none() { + ExtBuilder::default() + .with_assets(vec![ + ( + Some(1), + Some(b"Tkn1".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ( + Some(2), + Some(b"Tkn2".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ( + Some(3), + Some(b"Tkn3".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ]) + .build() + .execute_with(|| { + //Arrange + let asset_id = 4; + + let name: BoundedVec = b"Tkn4".to_vec().try_into().unwrap(); + let symbol: BoundedVec = b"TKN".to_vec().try_into().unwrap(); + let decimals = 12; + let xcm_rate_limit = 1_000; + let ed = 10_000; + let is_sufficient = true; + + let key = Junction::from(BoundedVec::try_from(asset_id.encode()).unwrap()); + let asset_location = AssetLocation(MultiLocation::new(0, X2(Parachain(200), key))); + + //Act + assert_noop!( + Registry::register( + RuntimeOrigin::none(), + Some(asset_id), + Some(name), + AssetType::Token, + Some(ed), + Some(symbol), + Some(decimals), + Some(asset_location), + Some(xcm_rate_limit), + is_sufficient + ), + BadOrigin + ); + }); +} + +#[test] +fn register_should_not_work_when_origin_is_not_allowed() { + ExtBuilder::default() + .with_assets(vec![ + ( + Some(1), + Some(b"Tkn1".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ( + Some(2), + Some(b"Tkn2".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ( + Some(3), + Some(b"Tkn3".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ]) + .build() + .execute_with(|| { + //Arrange + let asset_id = 4; + + let name: BoundedVec = b"Tkn4".to_vec().try_into().unwrap(); + let symbol: BoundedVec = b"TKN".to_vec().try_into().unwrap(); + let decimals = 12; + let xcm_rate_limit = 1_000; + let ed = 10_000; + let is_sufficient = true; + + let key = Junction::from(BoundedVec::try_from(asset_id.encode()).unwrap()); + let asset_location = AssetLocation(MultiLocation::new(0, X2(Parachain(200), key))); + + //Act + assert_noop!( + Registry::register( + RuntimeOrigin::signed(ALICE), + Some(asset_id), + Some(name), + AssetType::Token, + Some(ed), + Some(symbol), + Some(decimals), + Some(asset_location), + Some(xcm_rate_limit), + is_sufficient + ), + BadOrigin + ); + }); +} + +#[test] +fn register_external_asset_should_work_when_location_is_provided() { + ExtBuilder::default().build().execute_with(|| { + let expected_id = Pallet::::next_asset_id().unwrap(); + + let key = Junction::from(BoundedVec::try_from(528.encode()).unwrap()); + let asset_location = AssetLocation(MultiLocation::new(0, X2(Parachain(200), key))); + + let alice_balance = 10_000 * UNIT; + Tokens::mint_into(NativeAssetId::get(), &ALICE, alice_balance).unwrap(); + assert_eq!(Tokens::balance(NativeAssetId::get(), &TREASURY), 0); + + //Act + assert_ok!(Registry::register_external( + RuntimeOrigin::signed(ALICE), + asset_location.clone() + )); + + //Assert + assert_eq!( + Registry::assets(expected_id), + Some(AssetDetails { + name: None, + asset_type: AssetType::External, + existential_deposit: crate::DEFAULT_ED, + xcm_rate_limit: None, + symbol: None, + decimals: None, + is_sufficient: false + }) + ); + + assert_eq!(Registry::location_assets(asset_location.clone()), Some(expected_id)); + assert_eq!(Registry::locations(expected_id), Some(asset_location.clone())); + + assert!(has_event( + Event::::Registered { + asset_id: expected_id, + asset_name: None, + asset_type: AssetType::External, + existential_deposit: crate::DEFAULT_ED, + xcm_rate_limit: None, + symbol: None, + decimals: None, + is_sufficient: false + } + .into() + )); + + assert!(has_event( + Event::::LocationSet { + asset_id: expected_id, + location: asset_location + } + .into() + )); + }); +} + +#[test] +fn register_external_asset_should_not_work_when_location_is_already_used() { + ExtBuilder::default().build().execute_with(|| { + //Arrange + let asset_id = 1; + let name: BoundedVec = b"Test asset".to_vec().try_into().unwrap(); + let symbol: BoundedVec = b"TKN".to_vec().try_into().unwrap(); + let decimals = 12; + let xcm_rate_limit = 1_000; + let ed = 10_000; + let is_sufficient = true; + + let key = Junction::from(BoundedVec::try_from(asset_id.encode()).unwrap()); + let asset_location = AssetLocation(MultiLocation::new(0, X2(Parachain(200), key))); + + assert_ok!(Registry::register( + RuntimeOrigin::root(), + Some(asset_id), + Some(name), + AssetType::Token, + Some(ed), + Some(symbol), + Some(decimals), + Some(asset_location.clone()), + Some(xcm_rate_limit), + is_sufficient + )); + + let alice_balance = 10_000 * UNIT; + Tokens::mint_into(NativeAssetId::get(), &ALICE, alice_balance).unwrap(); + assert_eq!(Tokens::balance(NativeAssetId::get(), &TREASURY), 0); + + //Act + assert_noop!( + Registry::register_external(RuntimeOrigin::signed(ALICE), asset_location), + Error::::LocationAlreadyRegistered + ); + }); +} + +#[test] +fn register_should_not_work_when_symbol_is_not_valid() { + ExtBuilder::default().build().execute_with(|| { + let asset_id = 1; + let name: BoundedVec = b"Test asset".to_vec().try_into().unwrap(); + let decimals = 12; + let xcm_rate_limit = 1_000; + let ed = 10_000; + let is_sufficient = true; + + let key = Junction::from(BoundedVec::try_from(asset_id.encode()).unwrap()); + let asset_location = AssetLocation(MultiLocation::new(0, X2(Parachain(200), key))); + + let symbol: BoundedVec = b"TKN ".to_vec().try_into().unwrap(); + //Act + assert_noop!( + Registry::register( + RuntimeOrigin::root(), + Some(asset_id), + Some(name.clone()), + AssetType::Token, + Some(ed), + Some(symbol), + Some(decimals), + Some(asset_location.clone()), + Some(xcm_rate_limit), + is_sufficient + ), + Error::::InvalidSymbol + ); + + let symbol: BoundedVec = b" TKN".to_vec().try_into().unwrap(); + //Act + assert_noop!( + Registry::register( + RuntimeOrigin::root(), + Some(asset_id), + Some(name.clone()), + AssetType::Token, + Some(ed), + Some(symbol), + Some(decimals), + Some(asset_location.clone()), + Some(xcm_rate_limit), + is_sufficient + ), + Error::::InvalidSymbol + ); + + let symbol: BoundedVec = b"T KN".to_vec().try_into().unwrap(); + //Act + assert_noop!( + Registry::register( + RuntimeOrigin::root(), + Some(asset_id), + Some(name.clone()), + AssetType::Token, + Some(ed), + Some(symbol), + Some(decimals), + Some(asset_location.clone()), + Some(xcm_rate_limit), + is_sufficient + ), + Error::::InvalidSymbol + ); + + let symbol: BoundedVec = b"T\tKN".to_vec().try_into().unwrap(); + //Act + assert_noop!( + Registry::register( + RuntimeOrigin::root(), + Some(asset_id), + Some(name), + AssetType::Token, + Some(ed), + Some(symbol), + Some(decimals), + Some(asset_location), + Some(xcm_rate_limit), + is_sufficient + ), + Error::::InvalidSymbol + ); + }); +} + +#[test] +fn register_should_not_work_when_name_is_too_short() { + ExtBuilder::default() + .with_assets(vec![ + ( + Some(1), + Some(b"Tkn1".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ( + Some(2), + Some(b"Tkn2".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ( + Some(3), + Some(b"Tkn3".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ]) + .build() + .execute_with(|| { + let asset_id = 4; + let name: BoundedVec = b"T".to_vec().try_into().unwrap(); + let symbol: BoundedVec = b"TKN".to_vec().try_into().unwrap(); + let decimals = 12; + let xcm_rate_limit = 1_000; + let ed = 10_000; + let is_sufficient = true; + + let key = Junction::from(BoundedVec::try_from(asset_id.encode()).unwrap()); + let asset_location = AssetLocation(MultiLocation::new(0, X2(Parachain(200), key))); + + //Act + assert_noop!( + Registry::register( + RuntimeOrigin::root(), + Some(asset_id), + Some(name), + AssetType::Token, + Some(ed), + Some(symbol), + Some(decimals), + Some(asset_location), + Some(xcm_rate_limit), + is_sufficient + ), + Error::::TooShort + ); + }); +} + +#[test] +fn register_should_not_work_when_symbol_is_too_short() { + ExtBuilder::default() + .with_assets(vec![ + ( + Some(1), + Some(b"Tkn1".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ( + Some(2), + Some(b"Tkn2".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ( + Some(3), + Some(b"Tkn3".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ]) + .build() + .execute_with(|| { + let asset_id = 4; + let name: BoundedVec = b"TKN".to_vec().try_into().unwrap(); + let symbol: BoundedVec = b"T".to_vec().try_into().unwrap(); + let decimals = 12; + let xcm_rate_limit = 1_000; + let ed = 10_000; + let is_sufficient = true; + + let key = Junction::from(BoundedVec::try_from(asset_id.encode()).unwrap()); + let asset_location = AssetLocation(MultiLocation::new(0, X2(Parachain(200), key))); + + //Act + assert_noop!( + Registry::register( + RuntimeOrigin::root(), + Some(asset_id), + Some(name), + AssetType::Token, + Some(ed), + Some(symbol), + Some(decimals), + Some(asset_location), + Some(xcm_rate_limit), + is_sufficient + ), + Error::::TooShort + ); + }); +} + +#[test] +fn register_externa_should_not_work_when_origin_is_none() { + ExtBuilder::default().build().execute_with(|| { + let key = Junction::from(BoundedVec::try_from(528.encode()).unwrap()); + let asset_location = AssetLocation(MultiLocation::new(0, X2(Parachain(200), key))); + + let alice_balance = 10_000 * UNIT; + Tokens::mint_into(NativeAssetId::get(), &ALICE, alice_balance).unwrap(); + assert_eq!(Tokens::balance(NativeAssetId::get(), &TREASURY), 0); + + //Act + assert_noop!( + Registry::register_external(RuntimeOrigin::none(), asset_location), + BadOrigin + ); + }); +} diff --git a/pallets/asset-registry/src/tests/tests.rs b/pallets/asset-registry/src/tests/tests.rs new file mode 100644 index 000000000..b5c14f673 --- /dev/null +++ b/pallets/asset-registry/src/tests/tests.rs @@ -0,0 +1,240 @@ +use super::*; + +use mock::Registry; +use pretty_assertions::assert_eq; + +#[test] +fn ban_asset_should_work_when_asset_is_not_banned() { + ExtBuilder::default() + .with_assets(vec![ + ( + Some(1), + Some(b"tkn1".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ( + Some(2), + Some(b"tkn2".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + false, + ), + ( + Some(3), + Some(b"Tkn3".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ]) + .build() + .execute_with(|| { + //Act + //NOTE: update origin is set to ensure_signed in tests + assert_ok!(Registry::ban_asset(RuntimeOrigin::signed(ALICE), 1)); + + //Assert + assert_last_event!(Event::::AssetBanned { asset_id: 1 }.into()); + + assert_eq!(Registry::banned_assets(1), Some(())) + }); +} + +#[test] +fn ban_asset_should_fial_when_asset_is_already_banned() { + let asset_id: u32 = 1; + ExtBuilder::default() + .with_assets(vec![ + ( + Some(asset_id), + Some(b"tkn1".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ( + Some(2), + Some(b"tkn2".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + false, + ), + ( + Some(3), + Some(b"Tkn3".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ]) + .build() + .execute_with(|| { + //Arrange + assert_ok!(Registry::ban_asset(RuntimeOrigin::signed(ALICE), 2)); + assert_ok!(Registry::ban_asset(RuntimeOrigin::signed(ALICE), asset_id)); + + //Act + //NOTE: update origin is set to ensure_signed in tests + assert_noop!( + Registry::ban_asset(RuntimeOrigin::signed(ALICE), asset_id), + Error::::AssetAlreadyBanned + ); + }); +} + +#[test] +fn ban_asset_should_fail_when_asset_is_not_registered() { + ExtBuilder::default() + .with_assets(vec![ + ( + Some(1), + Some(b"tkn1".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ( + Some(2), + Some(b"tkn2".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + false, + ), + ( + Some(3), + Some(b"Tkn3".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ]) + .build() + .execute_with(|| { + let not_existing_asset = 112_412_u32; + + //Act + //NOTE: update origin is set to ensure_signed in tests + assert_noop!( + Registry::ban_asset(RuntimeOrigin::signed(ALICE), not_existing_asset), + Error::::AssetNotFound + ); + }); +} + +#[test] +fn unban_asset_should_work_when_asset_is_banned() { + let asset_id: u32 = 1; + ExtBuilder::default() + .with_assets(vec![ + ( + Some(asset_id), + Some(b"tkn1".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ( + Some(2), + Some(b"tkn2".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + false, + ), + ( + Some(3), + Some(b"Tkn3".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ]) + .build() + .execute_with(|| { + //Arrange + assert_ok!(Registry::ban_asset(RuntimeOrigin::signed(ALICE), 3)); + assert_ok!(Registry::ban_asset(RuntimeOrigin::signed(ALICE), asset_id)); + + //Act + //NOTE: update origin is set to ensure_signed in tests + assert_ok!(Registry::unban_asset(RuntimeOrigin::signed(ALICE), asset_id),); + + //Assert + assert_last_event!(Event::::AssetUnbanned { asset_id }.into()); + + assert_eq!(Registry::banned_assets(asset_id), None) + }); +} + +#[test] +fn unban_asset_should_fail_when_asset_is_not_banned() { + let asset_id: u32 = 1; + ExtBuilder::default() + .with_assets(vec![ + ( + Some(asset_id), + Some(b"tkn1".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ( + Some(2), + Some(b"tkn2".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + false, + ), + ( + Some(3), + Some(b"Tkn3".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ]) + .build() + .execute_with(|| { + //Arrange + assert_ok!(Registry::ban_asset(RuntimeOrigin::signed(ALICE), 3)); + assert_ok!(Registry::ban_asset(RuntimeOrigin::signed(ALICE), 2)); + + //Act + //NOTE: update origin is set to ensure_signed in tests + assert_noop!( + Registry::unban_asset(RuntimeOrigin::signed(ALICE), asset_id), + Error::::AssetNotBanned + ); + }); +} diff --git a/pallets/asset-registry/src/tests/update.rs b/pallets/asset-registry/src/tests/update.rs new file mode 100644 index 000000000..d657f87be --- /dev/null +++ b/pallets/asset-registry/src/tests/update.rs @@ -0,0 +1,1115 @@ +use super::*; + +use crate::types::AssetType; +use mock::Registry; +use mock::RegistryStringLimit; +use polkadot_xcm::v3::{ + Junction::{self, Parachain}, + Junctions::X2, + MultiLocation, +}; +use pretty_assertions::assert_eq; + +#[test] +fn update_should_work_when_asset_exists() { + let old_asset_name = b"Tkn2".to_vec(); + ExtBuilder::default() + .with_assets(vec![ + ( + Some(1), + Some(b"Tkn1".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ( + Some(2), + Some(old_asset_name.clone().try_into().unwrap()), + UNIT, + None, + None, + None, + false, + ), + ( + Some(3), + Some(b"Tkn3".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ]) + .build() + .execute_with(|| { + let asset_id = 2; + let name: BoundedVec = b"New Tkn 2".to_vec().try_into().unwrap(); + let ed = 10_000 * UNIT; + let xcm_rate_limit = 463; + let symbol: BoundedVec = b"nTkn2".to_vec().try_into().unwrap(); + let decimals = 23; + let is_sufficient = true; + + //Arrange + let key = Junction::from(BoundedVec::try_from(asset_id.encode()).unwrap()); + let asset_location = AssetLocation(MultiLocation::new(0, X2(Parachain(200), key))); + Pallet::::set_location(asset_id, asset_location.clone()).unwrap(); + + //Act + assert_ok!(Registry::update( + RuntimeOrigin::root(), + asset_id, + Some(name.clone()), + Some(AssetType::External), + Some(ed), + Some(xcm_rate_limit), + Some(is_sufficient), + Some(symbol.clone()), + Some(decimals), + None + )); + + //Assert + assert_eq!( + Registry::assets(asset_id), + Some(AssetDetails { + name: Some(name.clone()), + asset_type: AssetType::External, + existential_deposit: ed, + xcm_rate_limit: Some(xcm_rate_limit), + symbol: Some(symbol.clone()), + decimals: Some(decimals), + is_sufficient: true + }) + ); + + //NOTE: location should't change + assert_eq!(Registry::location_assets(asset_location.clone()), Some(asset_id)); + assert_eq!(Registry::locations(asset_id), Some(asset_location)); + + assert_eq!(Registry::asset_ids(name.clone()).unwrap(), asset_id); + assert!( + Registry::asset_ids::>(old_asset_name.try_into().unwrap()) + .is_none() + ); + + assert_last_event!(Event::::Updated { + asset_id, + asset_name: Some(name), + asset_type: AssetType::External, + existential_deposit: ed, + xcm_rate_limit: Some(xcm_rate_limit), + decimals: Some(decimals), + symbol: Some(symbol), + is_sufficient, + } + .into()); + }); +} + +#[test] +fn update_should_update_provided_params_when_values_was_previously_set() { + let old_asset_name: BoundedVec = b"Tkn2".to_vec().try_into().unwrap(); + ExtBuilder::default().with_assets(vec![]).build().execute_with(|| { + //Arrange + let asset_id = 1; + let key = Junction::from(BoundedVec::try_from(asset_id.encode()).unwrap()); + let asset_location = AssetLocation(MultiLocation::new(0, X2(Parachain(200), key))); + + assert_ok!(Registry::register( + RuntimeOrigin::root(), + Some(asset_id), + Some(b"Test asset".to_vec().try_into().unwrap()), + AssetType::Token, + Some(10_000), + Some(b"TKN".to_vec().try_into().unwrap()), + Some(12), + Some(asset_location.clone()), + Some(1_000), + false + )); + + let name: BoundedVec = b"New name".to_vec().try_into().unwrap(); + let ed = 20_000 * UNIT; + let xcm_rate_limit = 463; + let symbol: BoundedVec = b"nTkn".to_vec().try_into().unwrap(); + let decimals = 23; + let is_sufficient = true; + + //Act + assert_ok!(Registry::update( + RuntimeOrigin::root(), + asset_id, + Some(name.clone()), + Some(AssetType::External), + Some(ed), + Some(xcm_rate_limit), + Some(is_sufficient), + Some(symbol.clone()), + Some(decimals), + None + )); + + //Assert + assert_eq!( + Registry::assets(asset_id), + Some(AssetDetails { + name: Some(name.clone()), + asset_type: AssetType::External, + existential_deposit: ed, + xcm_rate_limit: Some(xcm_rate_limit), + symbol: Some(symbol.clone()), + decimals: Some(decimals), + is_sufficient: true + }) + ); + + //NOTE: location shouldn't change + assert_eq!(Registry::location_assets(asset_location.clone()), Some(asset_id)); + assert_eq!(Registry::locations(asset_id), Some(asset_location)); + + assert_eq!(Registry::asset_ids(name.clone()).unwrap(), asset_id); + assert!(Registry::asset_ids(old_asset_name).is_none()); + + assert_last_event!(Event::::Updated { + asset_id, + asset_name: Some(name), + asset_type: AssetType::External, + existential_deposit: ed, + xcm_rate_limit: Some(xcm_rate_limit), + decimals: Some(decimals), + symbol: Some(symbol), + is_sufficient, + } + .into()); + }); +} + +#[test] +fn update_should_not_change_values_when_param_is_none() { + ExtBuilder::default() + .with_assets(vec![ + ( + Some(1), + Some(b"Tkn1".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ( + Some(2), + Some(b"Tkn2".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ( + Some(3), + Some(b"Tkn3".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ]) + .build() + .execute_with(|| { + let asset_id = 2; + + //Arrange + let key = Junction::from(BoundedVec::try_from(asset_id.encode()).unwrap()); + let asset_location = AssetLocation(MultiLocation::new(0, X2(Parachain(200), key))); + Pallet::::set_location(asset_id, asset_location.clone()).unwrap(); + + let details_0 = Registry::assets(asset_id).unwrap(); + + //Act + assert_ok!(Registry::update( + RuntimeOrigin::root(), + asset_id, + None, + None, + None, + None, + None, + None, + None, + None, + )); + + //Assert + assert_eq!(Registry::assets(asset_id).unwrap(), details_0); + + let old_bounded_name: BoundedVec = b"Tkn2".to_vec().try_into().unwrap(); + assert_eq!(Registry::asset_ids(old_bounded_name).unwrap(), asset_id); + + //NOTE: location shouldn't change + assert_eq!(Registry::location_assets(asset_location.clone()), Some(asset_id)); + assert_eq!(Registry::locations(asset_id), Some(asset_location)); + + assert_last_event!(Event::::Updated { + asset_id, + asset_name: details_0.name, + asset_type: details_0.asset_type, + existential_deposit: details_0.existential_deposit, + xcm_rate_limit: details_0.xcm_rate_limit, + decimals: details_0.decimals, + symbol: details_0.symbol, + is_sufficient: details_0.is_sufficient, + } + .into()); + }); +} + +#[test] +fn update_origin_should_set_decimals_if_its_none() { + ExtBuilder::default() + .with_assets(vec![ + ( + Some(1), + Some(b"Tkn1".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ( + Some(2), + Some(b"Tkn2".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ( + Some(3), + Some(b"Tkn3".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ]) + .build() + .execute_with(|| { + let asset_id = 2; + let decimals = 52; + + //Arrange + let key = Junction::from(BoundedVec::try_from(asset_id.encode()).unwrap()); + let asset_location = AssetLocation(MultiLocation::new(0, X2(Parachain(200), key))); + Pallet::::set_location(asset_id, asset_location).unwrap(); + + let details_0 = Registry::assets(asset_id).unwrap(); + + //NOTE: update origin is set to ensure_signed + //Act + assert_ok!(Registry::update( + RuntimeOrigin::signed(ALICE), + asset_id, + None, + None, + None, + None, + None, + None, + Some(decimals), + None, + )); + + //Assert + assert_eq!( + Registry::assets(asset_id), + Some(AssetDetails { + name: details_0.name.clone(), + asset_type: details_0.asset_type, + existential_deposit: details_0.existential_deposit, + xcm_rate_limit: details_0.xcm_rate_limit, + symbol: details_0.symbol.clone(), + decimals: Some(decimals), + is_sufficient: details_0.is_sufficient + }) + ); + + assert_last_event!(Event::::Updated { + asset_id, + asset_name: details_0.name, + asset_type: details_0.asset_type, + existential_deposit: details_0.existential_deposit, + xcm_rate_limit: details_0.xcm_rate_limit, + decimals: Some(decimals), + symbol: details_0.symbol, + is_sufficient: details_0.is_sufficient, + } + .into()); + }); +} + +#[test] +fn update_origin_should_not_chane_decimals_if_its_some() { + ExtBuilder::default() + .with_assets(vec![ + ( + Some(1), + Some(b"Tkn1".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ( + Some(2), + Some(b"Tkn2".to_vec().try_into().unwrap()), + UNIT, + None, + Some(3), + None, + true, + ), + ( + Some(3), + Some(b"Tkn3".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ]) + .build() + .execute_with(|| { + let asset_id = 2; + let decimals = 52; + + //Arrange + let key = Junction::from(BoundedVec::try_from(asset_id.encode()).unwrap()); + let asset_location = AssetLocation(MultiLocation::new(0, X2(Parachain(200), key))); + Pallet::::set_location(asset_id, asset_location).unwrap(); + + //NOTE: update origin is ste to ensure_signed + //Act & assert + assert_noop!( + Registry::update( + RuntimeOrigin::signed(ALICE), + asset_id, + None, + None, + None, + None, + None, + None, + Some(decimals), + None, + ), + Error::::Forbidden + ); + }); +} + +#[test] +fn create_origin_should_always_set_decimals() { + ExtBuilder::default() + .with_assets(vec![ + ( + Some(1), + Some(b"Tkn1".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ( + Some(2), + Some(b"Tkn2".to_vec().try_into().unwrap()), + UNIT, + None, + Some(3), + None, + true, + ), + ( + Some(3), + Some(b"Tkn3".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ]) + .build() + .execute_with(|| { + let asset_id = 2; + let decimals = 52; + + //Arrange + let key = Junction::from(BoundedVec::try_from(asset_id.encode()).unwrap()); + let asset_location = AssetLocation(MultiLocation::new(0, X2(Parachain(200), key))); + Pallet::::set_location(asset_id, asset_location).unwrap(); + + let details_0 = Registry::assets(asset_id).unwrap(); + + //Act + assert_ok!(Registry::update( + RuntimeOrigin::root(), + asset_id, + None, + None, + None, + None, + None, + None, + Some(decimals), + None, + )); + + assert_ok!(Registry::update( + RuntimeOrigin::root(), + asset_id, + None, + None, + None, + None, + None, + None, + Some(u8::max_value()), + None, + )); + + //Assert + assert_eq!( + Registry::assets(asset_id), + Some(AssetDetails { + name: details_0.name.clone(), + asset_type: details_0.asset_type, + existential_deposit: details_0.existential_deposit, + xcm_rate_limit: details_0.xcm_rate_limit, + symbol: details_0.symbol.clone(), + decimals: Some(u8::max_value()), + is_sufficient: details_0.is_sufficient + }) + ); + + assert_last_event!(Event::::Updated { + asset_id, + asset_name: details_0.name, + asset_type: details_0.asset_type, + existential_deposit: details_0.existential_deposit, + xcm_rate_limit: details_0.xcm_rate_limit, + decimals: Some(u8::max_value()), + symbol: details_0.symbol, + is_sufficient: details_0.is_sufficient, + } + .into()); + }); +} + +#[test] +fn update_should_fail_when_name_is_already_used() { + let old_asset_name: BoundedVec = b"Tkn2".to_vec().try_into().unwrap(); + ExtBuilder::default() + .with_assets(vec![ + ( + Some(1), + Some(b"Tkn1".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + (Some(2), Some(old_asset_name), UNIT, None, None, None, true), + ( + Some(3), + Some(b"Tkn3".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ]) + .build() + .execute_with(|| { + let asset_id = 2; + let name: BoundedVec = b"Tkn3".to_vec().try_into().unwrap(); + let ed = 10_000 * UNIT; + let xcm_rate_limit = 463; + let symbol: BoundedVec = b"nTkn2".to_vec().try_into().unwrap(); + let decimals = 23; + let is_sufficient = false; + + //Arrange + let key = Junction::from(BoundedVec::try_from(asset_id.encode()).unwrap()); + let asset_location = AssetLocation(MultiLocation::new(0, X2(Parachain(200), key))); + Pallet::::set_location(asset_id, asset_location).unwrap(); + + //Act + assert_noop!( + Registry::update( + RuntimeOrigin::root(), + asset_id, + Some(name), + Some(AssetType::External), + Some(ed), + Some(xcm_rate_limit), + Some(is_sufficient), + Some(symbol), + Some(decimals), + None, + ), + Error::::AssetAlreadyRegistered + ); + }); +} + +#[test] +fn update_should_not_update_location_when_origin_is_not_registry_origin() { + let old_asset_name = b"Tkn2".to_vec(); + ExtBuilder::default() + .with_assets(vec![ + ( + Some(1), + Some(b"Tkn1".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ( + Some(2), + Some(old_asset_name.try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ( + Some(3), + Some(b"Tkn3".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ]) + .build() + .execute_with(|| { + let asset_id = 2; + + //Act 1 - asset without location also should work + let key = Junction::from(BoundedVec::try_from(asset_id.encode()).unwrap()); + let asset_location = AssetLocation(MultiLocation::new(0, X2(Parachain(200), key))); + + assert_noop!( + Registry::update( + RuntimeOrigin::signed(ALICE), + asset_id, + None, + None, + None, + None, + None, + None, + None, + Some(asset_location), + ), + Error::::Forbidden + ); + + //Arrange - location should not be updated if it exists + let key = Junction::from(BoundedVec::try_from(asset_id.encode()).unwrap()); + let asset_location = AssetLocation(MultiLocation::new(0, X2(Parachain(200), key))); + Pallet::::set_location(asset_id, asset_location).unwrap(); + + let asset_location = AssetLocation(MultiLocation::new(0, X2(Parachain(400), key))); + //Act + assert_noop!( + Registry::update( + RuntimeOrigin::signed(ALICE), + asset_id, + None, + None, + None, + None, + None, + None, + None, + Some(asset_location) + ), + Error::::Forbidden + ); + }); +} + +#[test] +fn update_should_update_location_when_origin_is_registry_origin() { + let old_asset_name = b"Tkn2".to_vec(); + ExtBuilder::default() + .with_assets(vec![ + ( + Some(1), + Some(b"Tkn1".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ( + Some(2), + Some(old_asset_name.try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ( + Some(3), + Some(b"Tkn3".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ]) + .build() + .execute_with(|| { + let asset_id = 2; + + //Act 1 - asset without location also should work + let key = Junction::from(BoundedVec::try_from(asset_id.encode()).unwrap()); + let asset_location = AssetLocation(MultiLocation::new(0, X2(Parachain(200), key))); + + let details_0 = Registry::assets(asset_id).unwrap(); + assert_ok!(Registry::update( + RuntimeOrigin::root(), + asset_id, + None, + None, + None, + None, + None, + None, + None, + Some(asset_location.clone()), + )); + + assert_eq!(Registry::assets(asset_id).unwrap(), details_0); + assert_eq!(Registry::location_assets(asset_location.clone()), Some(asset_id)); + assert_eq!(Registry::locations(asset_id), Some(asset_location.clone())); + assert!(has_event( + Event::::LocationSet { + asset_id, + location: asset_location.clone() + } + .into() + )); + + //Arrange - location should not be updated if it exists + let key = Junction::from(BoundedVec::try_from(asset_id.encode()).unwrap()); + let second_location = AssetLocation(MultiLocation::new(0, X2(Parachain(400), key))); + let details_0 = Registry::assets(asset_id).unwrap(); + + //Act + assert_ok!(Registry::update( + RuntimeOrigin::root(), + asset_id, + None, + None, + None, + None, + None, + None, + None, + Some(second_location.clone()) + )); + + assert_eq!(Registry::assets(asset_id).unwrap(), details_0); + assert!(Registry::location_assets(asset_location).is_none()); + + assert_eq!(Registry::location_assets(second_location.clone()), Some(asset_id)); + assert_eq!(Registry::locations(asset_id), Some(second_location.clone())); + assert!(has_event( + Event::::LocationSet { + asset_id, + location: second_location + } + .into() + )); + }); +} + +#[test] +fn update_should_not_work_when_name_is_same_as_old() { + let old_asset_name = b"Tkn2".to_vec(); + ExtBuilder::default() + .with_assets(vec![ + ( + Some(1), + Some(b"Tkn1".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ( + Some(2), + Some(old_asset_name.clone().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ( + Some(3), + Some(b"Tkn3".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ]) + .build() + .execute_with(|| { + let asset_id = 2; + let name: BoundedVec = old_asset_name.clone().try_into().unwrap(); + let ed = 10_000 * UNIT; + let xcm_rate_limit = 463; + let symbol: BoundedVec = b"nTkn2".to_vec().try_into().unwrap(); + let decimals = 23; + let is_sufficient = false; + + //Arrange + let key = Junction::from(BoundedVec::try_from(asset_id.encode()).unwrap()); + let asset_location = AssetLocation(MultiLocation::new(0, X2(Parachain(200), key))); + Pallet::::set_location(asset_id, asset_location).unwrap(); + + //Act + assert_noop!( + Registry::update( + RuntimeOrigin::root(), + asset_id, + Some(name), + Some(AssetType::External), + Some(ed), + Some(xcm_rate_limit), + Some(is_sufficient), + Some(symbol), + Some(decimals), + None + ), + Error::::AssetAlreadyRegistered + ); + }); +} + +#[test] +fn change_sufficiency_should_fail_when_asset_is_sufficient() { + ExtBuilder::default() + .with_assets(vec![ + ( + Some(1), + Some(b"Tkn1".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ( + Some(2), + Some(b"Tkn2".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ( + Some(3), + Some(b"Tkn3".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ]) + .build() + .execute_with(|| { + let asset_id = 2; + + //Act + assert_noop!( + Registry::update( + RuntimeOrigin::root(), + asset_id, + None, + None, + None, + None, + Some(false), + None, + None, + None + ), + Error::::ForbiddenSufficiencyChange + ); + }); +} + +#[test] +fn update_should_not_work_when_symbol_is_not_valid() { + ExtBuilder::default() + .with_assets(vec![( + Some(1), + Some(b"Tkn1".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + )]) + .build() + .execute_with(|| { + let asset_id = 1; + let name: BoundedVec = b"New Tkn 2".to_vec().try_into().unwrap(); + let ed = 10_000 * UNIT; + let xcm_rate_limit = 463; + let decimals = 23; + let is_sufficient = true; + + //Arrange + let key = Junction::from(BoundedVec::try_from(asset_id.encode()).unwrap()); + let asset_location = AssetLocation(MultiLocation::new(0, X2(Parachain(200), key))); + Pallet::::set_location(asset_id, asset_location).unwrap(); + + let symbol: BoundedVec = b"nTkn2 ".to_vec().try_into().unwrap(); + //Act + assert_noop!( + Registry::update( + RuntimeOrigin::root(), + asset_id, + Some(name.clone()), + Some(AssetType::External), + Some(ed), + Some(xcm_rate_limit), + Some(is_sufficient), + Some(symbol), + Some(decimals), + None + ), + Error::::InvalidSymbol + ); + + let symbol: BoundedVec = b"nTk n2".to_vec().try_into().unwrap(); + //Act + assert_noop!( + Registry::update( + RuntimeOrigin::root(), + asset_id, + Some(name.clone()), + Some(AssetType::External), + Some(ed), + Some(xcm_rate_limit), + Some(is_sufficient), + Some(symbol), + Some(decimals), + None + ), + Error::::InvalidSymbol + ); + + let symbol: BoundedVec = b" nTkn2".to_vec().try_into().unwrap(); + //Act + assert_noop!( + Registry::update( + RuntimeOrigin::root(), + asset_id, + Some(name.clone()), + Some(AssetType::External), + Some(ed), + Some(xcm_rate_limit), + Some(is_sufficient), + Some(symbol), + Some(decimals), + None + ), + Error::::InvalidSymbol + ); + + let symbol: BoundedVec = b"Tk\n2".to_vec().try_into().unwrap(); + //Act + assert_noop!( + Registry::update( + RuntimeOrigin::root(), + asset_id, + Some(name), + Some(AssetType::External), + Some(ed), + Some(xcm_rate_limit), + Some(is_sufficient), + Some(symbol), + Some(decimals), + None + ), + Error::::InvalidSymbol + ); + }); +} + +#[test] +fn update_should_work_when_name_is_too_short() { + let old_asset_name = b"Tkn2".to_vec(); + ExtBuilder::default() + .with_assets(vec![ + ( + Some(1), + Some(b"Tkn1".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ( + Some(2), + Some(old_asset_name.try_into().unwrap()), + UNIT, + None, + None, + None, + false, + ), + ( + Some(3), + Some(b"Tkn3".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ]) + .build() + .execute_with(|| { + let asset_id = 2; + let name: BoundedVec = b"N".to_vec().try_into().unwrap(); + let ed = 10_000 * UNIT; + let xcm_rate_limit = 463; + let symbol: BoundedVec = b"nTkn2".to_vec().try_into().unwrap(); + let decimals = 23; + let is_sufficient = true; + + //Arrange + let key = Junction::from(BoundedVec::try_from(asset_id.encode()).unwrap()); + let asset_location = AssetLocation(MultiLocation::new(0, X2(Parachain(200), key))); + Pallet::::set_location(asset_id, asset_location).unwrap(); + + //Act + assert_noop!( + Registry::update( + RuntimeOrigin::root(), + asset_id, + Some(name), + Some(AssetType::External), + Some(ed), + Some(xcm_rate_limit), + Some(is_sufficient), + Some(symbol), + Some(decimals), + None + ), + Error::::TooShort + ); + }); +} + +#[test] +fn update_should_work_when_symbol_is_too_short() { + let old_asset_name = b"Tkn2".to_vec(); + ExtBuilder::default() + .with_assets(vec![ + ( + Some(1), + Some(b"Tkn1".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ( + Some(2), + Some(old_asset_name.try_into().unwrap()), + UNIT, + None, + None, + None, + false, + ), + ( + Some(3), + Some(b"Tkn3".to_vec().try_into().unwrap()), + UNIT, + None, + None, + None, + true, + ), + ]) + .build() + .execute_with(|| { + let asset_id = 2; + let name: BoundedVec = b"Name new".to_vec().try_into().unwrap(); + let ed = 10_000 * UNIT; + let xcm_rate_limit = 463; + let symbol: BoundedVec = b"T".to_vec().try_into().unwrap(); + let decimals = 23; + let is_sufficient = true; + + //Arrange + let key = Junction::from(BoundedVec::try_from(asset_id.encode()).unwrap()); + let asset_location = AssetLocation(MultiLocation::new(0, X2(Parachain(200), key))); + Pallet::::set_location(asset_id, asset_location).unwrap(); + + //Act + assert_noop!( + Registry::update( + RuntimeOrigin::root(), + asset_id, + Some(name), + Some(AssetType::External), + Some(ed), + Some(xcm_rate_limit), + Some(is_sufficient), + Some(symbol), + Some(decimals), + None + ), + Error::::TooShort + ); + }); +} diff --git a/pallets/asset-registry/src/types.rs b/pallets/asset-registry/src/types.rs index 9f496c22e..7c819b8a9 100644 --- a/pallets/asset-registry/src/types.rs +++ b/pallets/asset-registry/src/types.rs @@ -17,69 +17,94 @@ use frame_support::pallet_prelude::*; use scale_info::TypeInfo; -use sp_std::vec::Vec; + +pub type Balance = u128; use hydradx_traits::AssetKind; #[cfg(feature = "std")] use serde::{Deserialize, Serialize}; +pub type Name = BoundedVec; +pub type Symbol = BoundedVec; + #[derive(Encode, Decode, Eq, PartialEq, Copy, Clone, RuntimeDebug, TypeInfo, MaxEncodedLen)] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] -pub enum AssetType { +pub enum AssetType { Token, - PoolShare(AssetId, AssetId), // Use XYX instead XYK, StableSwap, Bond, + External, } -impl From for AssetType { +impl From for AssetType { fn from(value: AssetKind) -> Self { match value { AssetKind::Token => Self::Token, AssetKind::XYK => Self::XYK, AssetKind::StableSwap => Self::StableSwap, AssetKind::Bond => Self::Bond, + AssetKind::External => Self::External, } } } -impl From> for AssetKind { - fn from(value: AssetType) -> Self { +impl From for AssetKind { + fn from(value: AssetType) -> Self { match value { AssetType::Token => Self::Token, - AssetType::PoolShare(_, _) => Self::XYK, AssetType::XYK => Self::XYK, AssetType::StableSwap => Self::StableSwap, AssetType::Bond => Self::Bond, + AssetType::External => Self::External, } } } -#[derive(Encode, Decode, Eq, PartialEq, Copy, Clone, RuntimeDebug, TypeInfo, MaxEncodedLen)] +#[derive(Encode, Decode, Eq, PartialEq, Clone, RuntimeDebug, TypeInfo, MaxEncodedLen)] +#[scale_info(skip_type_params(StringLimit))] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] -pub struct AssetDetails { +pub struct AssetDetails> { /// The name of this asset. Limited in length by `StringLimit`. - pub name: BoundedString, + pub name: Option>, - pub asset_type: AssetType, + /// Asset type + pub asset_type: AssetType, + /// Existential deposit pub existential_deposit: Balance, - pub xcm_rate_limit: Option, -} - -#[derive(Clone, Encode, Decode, Eq, PartialEq, Default, RuntimeDebug, TypeInfo, MaxEncodedLen)] -pub struct AssetMetadata { /// The ticker symbol for this asset. Limited in length by `StringLimit`. - pub(super) symbol: BoundedString, + pub symbol: Option>, + /// The number of decimals this asset uses to represent one unit. - pub(super) decimals: u8, + pub decimals: Option, + + /// XCM rate limit. + pub xcm_rate_limit: Option, + + /// Asset sufficiency. + pub is_sufficient: bool, } -#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo)] -#[cfg_attr(feature = "std", derive(Serialize, Deserialize))] -pub struct Metadata { - pub(super) symbol: Vec, - pub(super) decimals: u8, +impl> AssetDetails { + pub fn new( + name: Option>, + asset_type: AssetType, + existential_deposit: Balance, + symbol: Option>, + decimals: Option, + xcm_rate_limit: Option, + is_sufficient: bool, + ) -> Self { + Self { + name, + asset_type, + existential_deposit, + symbol, + decimals, + xcm_rate_limit, + is_sufficient, + } + } } diff --git a/pallets/asset-registry/src/weights.rs b/pallets/asset-registry/src/weights.rs index 3b02c5aef..b40d1c585 100644 --- a/pallets/asset-registry/src/weights.rs +++ b/pallets/asset-registry/src/weights.rs @@ -15,32 +15,30 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! Autogenerated weights for `pallet_asset_registry` +//! Autogenerated weights for pallet_asset_registry //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-12-12, STEPS: `5`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `bench-bot`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` -//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024` +//! DATE: 2023-10-23, STEPS: 10, REPEAT: 20, LOW RANGE: [], HIGH RANGE: [] +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 // Executed Command: // target/release/hydradx // benchmark // pallet -// --pallet=pallet-asset-registry +// --chain=dev +// --steps=10 +// --repeat=20 +// --execution=wasm // --wasm-execution=compiled // --heap-pages=4096 -// --chain=dev +// --template=.maintain/pallet-weight-template-no-back.hbs +// --pallet=pallet_asset_registry +// --output=weights.rs // --extrinsic=* -// --steps=5 -// --repeat=20 -// --output -// ./weights-1.1.0/registry.rs -// --template -// .maintain/pallet-weight-template-no-back.hbs #![allow(unused_parens)] #![allow(unused_imports)] +#![allow(clippy::unnecessary_cast)] use frame_support::{ traits::Get, @@ -48,144 +46,144 @@ use frame_support::{ }; use sp_std::marker::PhantomData; -/// Weight functions needed for lbp. pub trait WeightInfo { fn register() -> Weight; fn update() -> Weight; - fn set_metadata() -> Weight; - fn set_location() -> Weight; + fn register_external() -> Weight; + fn ban_asset() -> Weight; + fn unban_asset() -> Weight; } - -/// Weights for lbp using the hack.hydraDX node and recommended hardware. +/// Weights for pallet_asset_registry using the hydraDX node and recommended hardware. pub struct HydraWeight(PhantomData); impl WeightInfo for HydraWeight { - /// Storage: `AssetRegistry::AssetIds` (r:1 w:1) - /// Proof: `AssetRegistry::AssetIds` (`max_values`: None, `max_size`: Some(53), added: 2528, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::NextAssetId` (r:1 w:1) - /// Proof: `AssetRegistry::NextAssetId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::LocationAssets` (r:1 w:1) - /// Proof: `AssetRegistry::LocationAssets` (`max_values`: None, `max_size`: Some(622), added: 3097, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::AssetLocations` (r:0 w:1) - /// Proof: `AssetRegistry::AssetLocations` (`max_values`: None, `max_size`: Some(614), added: 3089, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::AssetMetadataMap` (r:0 w:1) - /// Proof: `AssetRegistry::AssetMetadataMap` (`max_values`: None, `max_size`: Some(46), added: 2521, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::Assets` (r:0 w:1) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) + // Storage: AssetRegistry Assets (r:1 w:1) + // Proof: AssetRegistry Assets (max_values: None, max_size: Some(133), added: 2608, mode: MaxEncodedLen) + // Storage: AssetRegistry AssetIds (r:1 w:1) + // Proof: AssetRegistry AssetIds (max_values: None, max_size: Some(53), added: 2528, mode: MaxEncodedLen) + // Storage: AssetRegistry LocationAssets (r:1 w:1) + // Proof: AssetRegistry LocationAssets (max_values: None, max_size: Some(622), added: 3097, mode: MaxEncodedLen) + // Storage: AssetRegistry AssetLocations (r:0 w:1) + // Proof: AssetRegistry AssetLocations (max_values: None, max_size: Some(622), added: 3097, mode: MaxEncodedLen) fn register() -> Weight { - // Proof Size summary in bytes: - // Measured: `305` - // Estimated: `4087` - // Minimum execution time: 46_657_000 picoseconds. - Weight::from_parts(47_059_000, 4087) - .saturating_add(T::DbWeight::get().reads(3_u64)) - .saturating_add(T::DbWeight::get().writes(6_u64)) + // Minimum execution time: 39_013 nanoseconds. + Weight::from_parts(39_795_000, 0) + .saturating_add(T::DbWeight::get().reads(3 as u64)) + .saturating_add(T::DbWeight::get().writes(4 as u64)) } - /// Storage: `AssetRegistry::Assets` (r:1 w:1) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::AssetIds` (r:1 w:2) - /// Proof: `AssetRegistry::AssetIds` (`max_values`: None, `max_size`: Some(53), added: 2528, mode: `MaxEncodedLen`) + // Storage: AssetRegistry Assets (r:1 w:1) + // Proof: AssetRegistry Assets (max_values: None, max_size: Some(133), added: 2608, mode: MaxEncodedLen) + // Storage: AssetRegistry AssetIds (r:1 w:2) + // Proof: AssetRegistry AssetIds (max_values: None, max_size: Some(53), added: 2528, mode: MaxEncodedLen) + // Storage: AssetRegistry AssetLocations (r:1 w:1) + // Proof: AssetRegistry AssetLocations (max_values: None, max_size: Some(622), added: 3097, mode: MaxEncodedLen) + // Storage: AssetRegistry LocationAssets (r:0 w:1) + // Proof: AssetRegistry LocationAssets (max_values: None, max_size: Some(622), added: 3097, mode: MaxEncodedLen) fn update() -> Weight { - // Proof Size summary in bytes: - // Measured: `372` - // Estimated: `3552` - // Minimum execution time: 29_123_000 picoseconds. - Weight::from_parts(29_400_000, 3552) - .saturating_add(T::DbWeight::get().reads(2_u64)) - .saturating_add(T::DbWeight::get().writes(3_u64)) + // Minimum execution time: 47_430 nanoseconds. + Weight::from_parts(47_760_000, 0) + .saturating_add(T::DbWeight::get().reads(3 as u64)) + .saturating_add(T::DbWeight::get().writes(5 as u64)) } - /// Storage: `AssetRegistry::Assets` (r:1 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::AssetMetadataMap` (r:0 w:1) - /// Proof: `AssetRegistry::AssetMetadataMap` (`max_values`: None, `max_size`: Some(46), added: 2521, mode: `MaxEncodedLen`) - fn set_metadata() -> Weight { - // Proof Size summary in bytes: - // Measured: `300` - // Estimated: `3552` - // Minimum execution time: 21_806_000 picoseconds. - Weight::from_parts(22_285_000, 3552) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Storage: System Account (r:2 w:2) + // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) + // Storage: AssetRegistry NextAssetId (r:1 w:1) + // Proof: AssetRegistry NextAssetId (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + // Storage: AssetRegistry LocationAssets (r:1 w:1) + // Proof: AssetRegistry LocationAssets (max_values: None, max_size: Some(622), added: 3097, mode: MaxEncodedLen) + // Storage: AssetRegistry AssetLocations (r:0 w:1) + // Proof: AssetRegistry AssetLocations (max_values: None, max_size: Some(622), added: 3097, mode: MaxEncodedLen) + // Storage: AssetRegistry Assets (r:0 w:1) + // Proof: AssetRegistry Assets (max_values: None, max_size: Some(133), added: 2608, mode: MaxEncodedLen) + fn register_external() -> Weight { + // Minimum execution time: 63_891 nanoseconds. + Weight::from_parts(64_922_000, 0) + .saturating_add(T::DbWeight::get().reads(4 as u64)) + .saturating_add(T::DbWeight::get().writes(6 as u64)) } - /// Storage: `AssetRegistry::Assets` (r:1 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::LocationAssets` (r:1 w:1) - /// Proof: `AssetRegistry::LocationAssets` (`max_values`: None, `max_size`: Some(622), added: 3097, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::AssetLocations` (r:1 w:1) - /// Proof: `AssetRegistry::AssetLocations` (`max_values`: None, `max_size`: Some(614), added: 3089, mode: `MaxEncodedLen`) - fn set_location() -> Weight { - // Proof Size summary in bytes: - // Measured: `274` - // Estimated: `4087` - // Minimum execution time: 26_900_000 picoseconds. - Weight::from_parts(27_350_000, 4087) - .saturating_add(T::DbWeight::get().reads(3_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) + + // Storage: AssetRegistry Assets (r:1 w:0) + // Proof: AssetRegistry Assets (max_values: None, max_size: Some(125), added: 2600, mode: MaxEncodedLen) + // Storage: AssetRegistry BlacklistedAssets (r:1 w:1) + // Proof: AssetRegistry BlacklistedAssets (max_values: None, max_size: Some(20), added: 2495, mode: MaxEncodedLen) + fn ban_asset() -> Weight { + // Minimum execution time: 22_677 nanoseconds. + Weight::from_parts(22_950_000, 0) + .saturating_add(T::DbWeight::get().reads(2 as u64)) + .saturating_add(T::DbWeight::get().writes(1 as u64)) + } + // Storage: AssetRegistry BlacklistedAssets (r:1 w:1) + // Proof: AssetRegistry BlacklistedAssets (max_values: None, max_size: Some(20), added: 2495, mode: MaxEncodedLen) + fn unban_asset() -> Weight { + // Minimum execution time: 17_460 nanoseconds. + Weight::from_parts(17_958_000, 0) + .saturating_add(T::DbWeight::get().reads(1 as u64)) + .saturating_add(T::DbWeight::get().writes(1 as u64)) } } -// For backwards compatibility and tests impl WeightInfo for () { - /// Storage: `AssetRegistry::AssetIds` (r:1 w:1) - /// Proof: `AssetRegistry::AssetIds` (`max_values`: None, `max_size`: Some(53), added: 2528, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::NextAssetId` (r:1 w:1) - /// Proof: `AssetRegistry::NextAssetId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::LocationAssets` (r:1 w:1) - /// Proof: `AssetRegistry::LocationAssets` (`max_values`: None, `max_size`: Some(622), added: 3097, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::AssetLocations` (r:0 w:1) - /// Proof: `AssetRegistry::AssetLocations` (`max_values`: None, `max_size`: Some(614), added: 3089, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::AssetMetadataMap` (r:0 w:1) - /// Proof: `AssetRegistry::AssetMetadataMap` (`max_values`: None, `max_size`: Some(46), added: 2521, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::Assets` (r:0 w:1) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) + // Storage: AssetRegistry Assets (r:1 w:1) + // Proof: AssetRegistry Assets (max_values: None, max_size: Some(133), added: 2608, mode: MaxEncodedLen) + // Storage: AssetRegistry AssetIds (r:1 w:1) + // Proof: AssetRegistry AssetIds (max_values: None, max_size: Some(53), added: 2528, mode: MaxEncodedLen) + // Storage: AssetRegistry LocationAssets (r:1 w:1) + // Proof: AssetRegistry LocationAssets (max_values: None, max_size: Some(622), added: 3097, mode: MaxEncodedLen) + // Storage: AssetRegistry AssetLocations (r:0 w:1) + // Proof: AssetRegistry AssetLocations (max_values: None, max_size: Some(622), added: 3097, mode: MaxEncodedLen) fn register() -> Weight { - // Proof Size summary in bytes: - // Measured: `305` - // Estimated: `4087` - // Minimum execution time: 46_657_000 picoseconds. - Weight::from_parts(47_059_000, 4087) - .saturating_add(RocksDbWeight::get().reads(3_u64)) - .saturating_add(RocksDbWeight::get().writes(6_u64)) + // Minimum execution time: 39_013 nanoseconds. + Weight::from_parts(39_795_000, 0) + .saturating_add(RocksDbWeight::get().reads(3 as u64)) + .saturating_add(RocksDbWeight::get().writes(4 as u64)) } - /// Storage: `AssetRegistry::Assets` (r:1 w:1) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::AssetIds` (r:1 w:2) - /// Proof: `AssetRegistry::AssetIds` (`max_values`: None, `max_size`: Some(53), added: 2528, mode: `MaxEncodedLen`) + // Storage: AssetRegistry Assets (r:1 w:1) + // Proof: AssetRegistry Assets (max_values: None, max_size: Some(133), added: 2608, mode: MaxEncodedLen) + // Storage: AssetRegistry AssetIds (r:1 w:2) + // Proof: AssetRegistry AssetIds (max_values: None, max_size: Some(53), added: 2528, mode: MaxEncodedLen) + // Storage: AssetRegistry AssetLocations (r:1 w:1) + // Proof: AssetRegistry AssetLocations (max_values: None, max_size: Some(622), added: 3097, mode: MaxEncodedLen) + // Storage: AssetRegistry LocationAssets (r:0 w:1) + // Proof: AssetRegistry LocationAssets (max_values: None, max_size: Some(622), added: 3097, mode: MaxEncodedLen) fn update() -> Weight { - // Proof Size summary in bytes: - // Measured: `372` - // Estimated: `3552` - // Minimum execution time: 29_123_000 picoseconds. - Weight::from_parts(29_400_000, 3552) - .saturating_add(RocksDbWeight::get().reads(2_u64)) - .saturating_add(RocksDbWeight::get().writes(3_u64)) + // Minimum execution time: 47_430 nanoseconds. + Weight::from_parts(47_760_000, 0) + .saturating_add(RocksDbWeight::get().reads(3 as u64)) + .saturating_add(RocksDbWeight::get().writes(5 as u64)) } - /// Storage: `AssetRegistry::Assets` (r:1 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::AssetMetadataMap` (r:0 w:1) - /// Proof: `AssetRegistry::AssetMetadataMap` (`max_values`: None, `max_size`: Some(46), added: 2521, mode: `MaxEncodedLen`) - fn set_metadata() -> Weight { - // Proof Size summary in bytes: - // Measured: `300` - // Estimated: `3552` - // Minimum execution time: 21_806_000 picoseconds. - Weight::from_parts(22_285_000, 3552) - .saturating_add(RocksDbWeight::get().reads(1_u64)) - .saturating_add(RocksDbWeight::get().writes(1_u64)) + // Storage: System Account (r:2 w:2) + // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) + // Storage: AssetRegistry NextAssetId (r:1 w:1) + // Proof: AssetRegistry NextAssetId (max_values: Some(1), max_size: Some(4), added: 499, mode: MaxEncodedLen) + // Storage: AssetRegistry LocationAssets (r:1 w:1) + // Proof: AssetRegistry LocationAssets (max_values: None, max_size: Some(622), added: 3097, mode: MaxEncodedLen) + // Storage: AssetRegistry AssetLocations (r:0 w:1) + // Proof: AssetRegistry AssetLocations (max_values: None, max_size: Some(622), added: 3097, mode: MaxEncodedLen) + // Storage: AssetRegistry Assets (r:0 w:1) + // Proof: AssetRegistry Assets (max_values: None, max_size: Some(133), added: 2608, mode: MaxEncodedLen) + fn register_external() -> Weight { + // Minimum execution time: 63_891 nanoseconds. + Weight::from_parts(64_922_000, 0) + .saturating_add(RocksDbWeight::get().reads(4 as u64)) + .saturating_add(RocksDbWeight::get().writes(6 as u64)) + } + + // Storage: AssetRegistry Assets (r:1 w:0) + // Proof: AssetRegistry Assets (max_values: None, max_size: Some(125), added: 2600, mode: MaxEncodedLen) + // Storage: AssetRegistry BlacklistedAssets (r:1 w:1) + // Proof: AssetRegistry BlacklistedAssets (max_values: None, max_size: Some(20), added: 2495, mode: MaxEncodedLen) + fn ban_asset() -> Weight { + // Minimum execution time: 22_677 nanoseconds. + Weight::from_parts(22_950_000, 0) + .saturating_add(RocksDbWeight::get().reads(2 as u64)) + .saturating_add(RocksDbWeight::get().writes(1 as u64)) } - /// Storage: `AssetRegistry::Assets` (r:1 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::LocationAssets` (r:1 w:1) - /// Proof: `AssetRegistry::LocationAssets` (`max_values`: None, `max_size`: Some(622), added: 3097, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::AssetLocations` (r:1 w:1) - /// Proof: `AssetRegistry::AssetLocations` (`max_values`: None, `max_size`: Some(614), added: 3089, mode: `MaxEncodedLen`) - fn set_location() -> Weight { - // Proof Size summary in bytes: - // Measured: `274` - // Estimated: `4087` - // Minimum execution time: 26_900_000 picoseconds. - Weight::from_parts(27_350_000, 4087) - .saturating_add(RocksDbWeight::get().reads(3_u64)) - .saturating_add(RocksDbWeight::get().writes(2_u64)) + // Storage: AssetRegistry BlacklistedAssets (r:1 w:1) + // Proof: AssetRegistry BlacklistedAssets (max_values: None, max_size: Some(20), added: 2495, mode: MaxEncodedLen) + fn unban_asset() -> Weight { + // Minimum execution time: 17_460 nanoseconds. + Weight::from_parts(17_958_000, 0) + .saturating_add(RocksDbWeight::get().reads(1 as u64)) + .saturating_add(RocksDbWeight::get().writes(1 as u64)) } } diff --git a/pallets/bonds/Cargo.toml b/pallets/bonds/Cargo.toml index 50e8fd3cf..7556569ab 100644 --- a/pallets/bonds/Cargo.toml +++ b/pallets/bonds/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-bonds" -version = "2.0.1" +version = "2.1.0" authors = ['GalacticCouncil'] edition = "2021" license = "Apache-2.0" diff --git a/pallets/bonds/src/benchmarks.rs b/pallets/bonds/src/benchmarks.rs index 332e358ab..53f867a12 100644 --- a/pallets/bonds/src/benchmarks.rs +++ b/pallets/bonds/src/benchmarks.rs @@ -60,7 +60,8 @@ benchmarks! { let origin = T::IssueOrigin::try_successful_origin().unwrap(); let issuer = T::IssueOrigin::ensure_origin(origin).unwrap(); let amount: T::Balance = (200 * ONE).into(); - T::Currency::deposit(HDX, &issuer, amount)?; + //NOTE: bonds are insufficient so issuer must ED for it + T::Currency::deposit(HDX, &issuer, amount + (100 * ONE).into())?; let maturity = NOW + MONTH; diff --git a/pallets/bonds/src/lib.rs b/pallets/bonds/src/lib.rs index fd3132122..6e443c04c 100644 --- a/pallets/bonds/src/lib.rs +++ b/pallets/bonds/src/lib.rs @@ -55,7 +55,10 @@ use frame_system::{ensure_signed, pallet_prelude::OriginFor}; use sp_core::MaxEncodedLen; use sp_std::vec::Vec; -use hydradx_traits::{AssetKind, CreateRegistry, Registry}; +use hydradx_traits::{ + registry::{Create, Inspect}, + AssetKind, +}; use orml_traits::{GetByKey, MultiCurrency}; use primitives::{AssetId, Moment}; @@ -100,8 +103,7 @@ pub mod pallet { type Currency: MultiCurrency; /// Asset Registry mechanism - used to register bonds in the asset registry. - type AssetRegistry: Registry, Self::Balance, DispatchError> - + CreateRegistry; + type AssetRegistry: Inspect + Create; /// Provider for existential deposits of assets. type ExistentialDeposits: GetByKey; @@ -179,6 +181,10 @@ pub mod pallet { InvalidMaturity, /// Asset type not allowed for underlying asset DisallowedAsset, + /// Asset is not registered in `AssetRegistry` + AssetNotFound, + /// Generated name is not valid. + InvalidBondName, } #[pallet::call] @@ -210,7 +216,9 @@ pub mod pallet { let who = T::IssueOrigin::ensure_origin(origin)?; ensure!( - T::AssetTypeWhitelist::contains(&T::AssetRegistry::retrieve_asset_type(asset_id)?), + T::AssetTypeWhitelist::contains( + &T::AssetRegistry::asset_type(asset_id).ok_or(Error::::AssetNotFound)? + ), Error::::DisallowedAsset ); @@ -225,11 +233,16 @@ pub mod pallet { ensure!(maturity >= T::TimestampProvider::now(), Error::::InvalidMaturity); let ed = T::ExistentialDeposits::get(&asset_id); - - let bond_id = >::create_asset( - &Self::bond_name(asset_id, maturity), + let b_name = Self::bond_name(asset_id, maturity); + let bond_id = T::AssetRegistry::register_insufficient_asset( + None, + Some(b_name.try_into().map_err(|_| Error::::InvalidBondName)?), AssetKind::Bond, - ed, + Some(ed), + None, + None, + None, + None, )?; Bonds::::insert(bond_id, (asset_id, maturity)); diff --git a/pallets/bonds/src/tests/issue.rs b/pallets/bonds/src/tests/issue.rs index 79a071686..42569a292 100644 --- a/pallets/bonds/src/tests/issue.rs +++ b/pallets/bonds/src/tests/issue.rs @@ -494,7 +494,7 @@ fn issue_bonds_should_fail_when_underlying_asset_not_registered() { let asset_id = next_asset_id(); assert_noop!( Bonds::issue(RuntimeOrigin::signed(ALICE), asset_id, ONE, NOW + MONTH), - DispatchError::Other("AssetNotFound") + Error::::AssetNotFound ); }); } diff --git a/pallets/bonds/src/tests/mock.rs b/pallets/bonds/src/tests/mock.rs index 700819798..4ac045b33 100644 --- a/pallets/bonds/src/tests/mock.rs +++ b/pallets/bonds/src/tests/mock.rs @@ -28,9 +28,10 @@ use frame_support::{ }; use frame_system::EnsureSignedBy; use sp_core::H256; +use sp_runtime::BoundedVec; use std::{cell::RefCell, collections::HashMap}; -use hydradx_traits::CreateRegistry; +use hydradx_traits::registry::{Create, Inspect}; use orml_traits::parameter_type_with_key; pub use primitives::constants::{ currency::NATIVE_EXISTENTIAL_DEPOSIT, @@ -42,6 +43,8 @@ pub use primitives::constants::{ type Block = frame_system::mocking::MockBlock; +type AssetLocation = u8; + pub type AccountId = u64; pub type Balance = u128; @@ -99,7 +102,7 @@ impl Contains for AssetTypeWhitelist { } } -impl Config for Test { +impl pallet_bonds::Config for Test { type RuntimeEvent = RuntimeEvent; type Balance = Balance; type Currency = Tokens; @@ -167,40 +170,86 @@ impl pallet_timestamp::Config for Test { pub struct DummyRegistry(sp_std::marker::PhantomData); -impl CreateRegistry for DummyRegistry { +impl Create for DummyRegistry { type Error = DispatchError; + type Name = BoundedVec>; + type Symbol = BoundedVec>; + + fn register_asset( + _asset_id: Option, + _name: Option, + _kind: AssetKind, + _existential_deposit: Option, + _symbol: Option, + _decimals: Option, + _location: Option, + _xcm_rate_limit: Option, + _is_sufficient: bool, + ) -> Result { + unimplemented!() + } - fn create_asset(_name: &[u8], _kind: AssetKind, existential_deposit: Balance) -> Result { + fn register_insufficient_asset( + _asset_id: Option, + _name: Option, + _kind: AssetKind, + existential_deposit: Option, + _symbol: Option, + _decimals: Option, + _location: Option, + _xcm_rate_limit: Option, + ) -> Result { let assigned = REGISTERED_ASSETS.with(|v| { let l = v.borrow().len(); - v.borrow_mut().insert(l as u32, (existential_deposit, AssetKind::Bond)); + v.borrow_mut() + .insert(l as u32, (existential_deposit.unwrap(), AssetKind::Bond)); l as u32 }); Ok(assigned) } + fn get_or_register_asset( + _name: Self::Name, + _kind: AssetKind, + _existential_deposit: Option, + _symbol: Option, + _decimals: Option, + _location: Option, + _xcm_rate_limit: Option, + _is_sufficient: bool, + ) -> Result { + unimplemented!() + } } -impl Registry, Balance, DispatchError> for DummyRegistry { - fn exists(_name: AssetId) -> bool { +impl Inspect for DummyRegistry { + type AssetId = AssetId; + type Location = AssetLocation; + + fn is_sufficient(_id: Self::AssetId) -> bool { unimplemented!() } - fn retrieve_asset(_name: &Vec) -> Result { + fn decimals(_id: Self::AssetId) -> Option { unimplemented!() } - fn retrieve_asset_type(asset_id: AssetId) -> Result { - REGISTERED_ASSETS - .with(|v| v.borrow().get(&asset_id).cloned()) - .map(|v| v.1) - .ok_or(DispatchError::Other("AssetNotFound")) + fn asset_type(id: Self::AssetId) -> Option { + REGISTERED_ASSETS.with(|v| v.borrow().get(&id).cloned()).map(|v| v.1) + } + + fn exists(_name: AssetId) -> bool { + unimplemented!() + } + + fn is_banned(_id: Self::AssetId) -> bool { + unimplemented!() } - fn create_asset(_name: &Vec, _existential_deposit: Balance) -> Result { + fn asset_name(_id: Self::AssetId) -> Option> { unimplemented!() } - fn get_or_create_asset(_name: Vec, _existential_deposit: Balance) -> Result { + fn asset_symbol(_id: Self::AssetId) -> Option> { unimplemented!() } } diff --git a/pallets/circuit-breaker/Cargo.toml b/pallets/circuit-breaker/Cargo.toml index 7b793b2d3..926a8872d 100644 --- a/pallets/circuit-breaker/Cargo.toml +++ b/pallets/circuit-breaker/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-circuit-breaker" -version = "1.1.19" +version = "1.1.20" authors = ["GalacticCouncil "] edition = "2021" license = "Apache-2.0" @@ -47,6 +47,7 @@ std = [ 'frame-system/std', 'serde/std', 'scale-info/std', + 'frame-benchmarking/std', 'pallet-balances/std', 'orml-tokens/std', ] diff --git a/pallets/circuit-breaker/src/tests/mock.rs b/pallets/circuit-breaker/src/tests/mock.rs index a4037aa8d..fe6a0e6db 100644 --- a/pallets/circuit-breaker/src/tests/mock.rs +++ b/pallets/circuit-breaker/src/tests/mock.rs @@ -363,35 +363,45 @@ impl + Into + Copy> Mutate for DummyNFT { } use crate::Config; -use hydradx_traits::{AssetKind, Registry}; +use hydradx_traits::registry::{AssetKind, Inspect as InspectRegistry}; use pallet_omnipool::traits::{AssetInfo, ExternalPriceProvider, OmnipoolHooks}; pub struct DummyRegistry(sp_std::marker::PhantomData); -impl Registry, Balance, DispatchError> for DummyRegistry +impl InspectRegistry for DummyRegistry where T::AssetId: Into + From, { + type AssetId = T::AssetId; + type Location = u8; + + fn is_sufficient(_id: Self::AssetId) -> bool { + unimplemented!() + } + + fn asset_type(_id: Self::AssetId) -> Option { + unimplemented!() + } + + fn decimals(_id: Self::AssetId) -> Option { + unimplemented!() + } + fn exists(asset_id: T::AssetId) -> bool { let asset = REGISTERED_ASSETS.with(|v| v.borrow().get(&(asset_id.into())).copied()); matches!(asset, Some(_)) } - fn retrieve_asset(_name: &Vec) -> Result { - Ok(T::AssetId::default()) + fn is_banned(_id: Self::AssetId) -> bool { + unimplemented!() } - fn retrieve_asset_type(_asset_id: T::AssetId) -> Result { + fn asset_symbol(_id: Self::AssetId) -> Option> { unimplemented!() } - fn create_asset(_name: &Vec, _existential_deposit: Balance) -> Result { - let assigned = REGISTERED_ASSETS.with(|v| { - let l = v.borrow().len(); - v.borrow_mut().insert(l as u32, l as u32); - l as u32 - }); - Ok(T::AssetId::from(assigned)) + fn asset_name(_id: Self::AssetId) -> Option> { + unimplemented!() } } diff --git a/pallets/dca/Cargo.toml b/pallets/dca/Cargo.toml index 5296ec4ad..481420ca1 100644 --- a/pallets/dca/Cargo.toml +++ b/pallets/dca/Cargo.toml @@ -1,6 +1,6 @@ [package] name = 'pallet-dca' -version = "1.3.3" +version = "1.3.4" description = 'A pallet to manage DCA scheduling' authors = ['GalacticCouncil'] edition = '2021' diff --git a/pallets/dca/src/tests/mock.rs b/pallets/dca/src/tests/mock.rs index 2caeb9b67..75e31d006 100644 --- a/pallets/dca/src/tests/mock.rs +++ b/pallets/dca/src/tests/mock.rs @@ -28,7 +28,7 @@ use frame_support::BoundedVec; use frame_support::{assert_ok, parameter_types}; use frame_system as system; use frame_system::{ensure_signed, EnsureRoot}; -use hydradx_traits::{AssetKind, NativePriceOracle, OraclePeriod, PriceOracle, Registry}; +use hydradx_traits::{registry::Inspect as InspectRegistry, AssetKind, NativePriceOracle, OraclePeriod, PriceOracle}; use orml_traits::{parameter_type_with_key, GetByKey}; use pallet_currencies::BasicCurrencyAdapter; use primitive_types::U128; @@ -734,30 +734,40 @@ impl + Into + Copy> Mutate for DummyNFT { pub struct DummyRegistry(sp_std::marker::PhantomData); -impl Registry, Balance, DispatchError> for DummyRegistry +impl InspectRegistry for DummyRegistry where T::AssetId: Into + From, { + type AssetId = T::AssetId; + type Location = u8; + + fn asset_type(_id: Self::AssetId) -> Option { + unimplemented!() + } + + fn is_sufficient(_id: Self::AssetId) -> bool { + unimplemented!() + } + + fn decimals(_id: Self::AssetId) -> Option { + unimplemented!() + } + fn exists(asset_id: T::AssetId) -> bool { let asset = REGISTERED_ASSETS.with(|v| v.borrow().get(&(asset_id.into())).copied()); matches!(asset, Some(_)) } - fn retrieve_asset(_name: &Vec) -> Result { - Ok(1.into()) + fn is_banned(_id: Self::AssetId) -> bool { + unimplemented!() } - fn retrieve_asset_type(_asset_id: T::AssetId) -> Result { + fn asset_name(_id: Self::AssetId) -> Option> { unimplemented!() } - fn create_asset(_name: &Vec, _existential_deposit: Balance) -> Result { - let assigned = REGISTERED_ASSETS.with(|v| { - let l = v.borrow().len(); - v.borrow_mut().insert(l as u32, l as u32); - l as u32 - }); - Ok(T::AssetId::from(assigned)) + fn asset_symbol(_id: Self::AssetId) -> Option> { + unimplemented!() } } diff --git a/pallets/lbp/Cargo.toml b/pallets/lbp/Cargo.toml index 297c239b1..dd2eda000 100644 --- a/pallets/lbp/Cargo.toml +++ b/pallets/lbp/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-lbp" -version = "4.7.3" +version = "4.7.4" description = "HydraDX Liquidity Bootstrapping Pool Pallet" authors = ["GalacticCouncil"] edition = "2021" diff --git a/pallets/lbp/src/types.rs b/pallets/lbp/src/types.rs index 63c51add9..7d1dcf9f0 100644 --- a/pallets/lbp/src/types.rs +++ b/pallets/lbp/src/types.rs @@ -27,10 +27,10 @@ use sp_std::vec::Vec; use serde::{Deserialize, Serialize}; /// Asset Pair representation for AMM trades -/// ( asset_a, asset_b ) combination where asset_a is meant to be exchanged for asset_b +/// `( asset_a, asset_b )` combination where `asset_a` is meant to be exchanged for asset_b /// -/// asset_in represents asset coming into the pool -/// asset_out represents asset coming out of the pool +/// `asset_in` represents asset coming into the pool +/// `asset_out` represents asset coming out of the pool #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] #[derive(Debug, Encode, Decode, Copy, Clone, PartialEq, Eq, Default, TypeInfo)] pub struct AssetPair { diff --git a/pallets/liquidity-mining/Cargo.toml b/pallets/liquidity-mining/Cargo.toml index 6b9cc7e1f..ee0110220 100644 --- a/pallets/liquidity-mining/Cargo.toml +++ b/pallets/liquidity-mining/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-liquidity-mining" -version = "4.2.5" +version = "4.3.0" description = "Liquidity mining" authors = ["GalacticCouncil"] edition = "2021" @@ -56,5 +56,7 @@ std = [ "sp-runtime/std", "scale-info/std", "hydra-dx-math/std", + "pallet-balances/std", + "orml-tokens/std", ] try-runtime = ["frame-support/try-runtime"] diff --git a/pallets/liquidity-mining/src/lib.rs b/pallets/liquidity-mining/src/lib.rs index bf16b8bbd..79aff9e83 100644 --- a/pallets/liquidity-mining/src/lib.rs +++ b/pallets/liquidity-mining/src/lib.rs @@ -115,7 +115,7 @@ use frame_system::pallet_prelude::BlockNumberFor; use sp_runtime::ArithmeticError; use hydra_dx_math::liquidity_mining as math; -use hydradx_traits::{liquidity_mining::PriceAdjustment, pools::DustRemovalAccountWhitelist, registry::Registry}; +use hydradx_traits::{liquidity_mining::PriceAdjustment, pools::DustRemovalAccountWhitelist, registry::Inspect}; use orml_traits::{GetByKey, MultiCurrency}; use scale_info::TypeInfo; use sp_arithmetic::{ @@ -211,7 +211,7 @@ pub mod pallet { /// Asset Registry - used to check if asset is correctly registered in asset registry and /// provides information about existential deposit of the asset. - type AssetRegistry: Registry, Balance, DispatchError> + GetByKey; + type AssetRegistry: Inspect + GetByKey; /// Account whitelist manager to exclude pool accounts from dusting mechanism. type NonDustableWhitelistHandler: DustRemovalAccountWhitelist; diff --git a/pallets/liquidity-mining/src/tests/mock.rs b/pallets/liquidity-mining/src/tests/mock.rs index 8be1303f8..53b64b631 100644 --- a/pallets/liquidity-mining/src/tests/mock.rs +++ b/pallets/liquidity-mining/src/tests/mock.rs @@ -22,7 +22,7 @@ use crate::Config; use crate::{self as liq_mining, types::DefaultPriceAdjustment}; use frame_support::{parameter_types, traits::Contains, traits::Everything, PalletId}; use frame_system as system; -use hydradx_traits::{pools::DustRemovalAccountWhitelist, registry::Registry, AssetKind, AMM}; +use hydradx_traits::{pools::DustRemovalAccountWhitelist, registry::Inspect, AssetKind, AMM}; use orml_traits::GetByKey; use sp_core::H256; use sp_runtime::{ @@ -283,7 +283,7 @@ impl Config for Test { type MaxFarmEntriesPerDeposit = MaxEntriesPerDeposit; type MaxYieldFarmsPerGlobalFarm = MaxYieldFarmsPerGlobalFarm; type NonDustableWhitelistHandler = Whitelist; - type AssetRegistry = AssetRegistry; + type AssetRegistry = DummyRegistry; type PriceAdjustment = DefaultPriceAdjustment; } @@ -307,7 +307,7 @@ impl Config for Test { type MaxFarmEntriesPerDeposit = MaxEntriesPerDeposit2; type MaxYieldFarmsPerGlobalFarm = MaxYieldFarmsPerGlobalFarm; type NonDustableWhitelistHandler = Whitelist; - type AssetRegistry = AssetRegistry; + type AssetRegistry = DummyRegistry; type PriceAdjustment = DefaultPriceAdjustment; } @@ -327,7 +327,7 @@ impl Config for Test { type MaxFarmEntriesPerDeposit = MaxEntriesPerDeposit; type MaxYieldFarmsPerGlobalFarm = MaxYieldFarmsPerGlobalFarm; type NonDustableWhitelistHandler = Whitelist; - type AssetRegistry = AssetRegistry; + type AssetRegistry = DummyRegistry; type PriceAdjustment = DummyOraclePriceAdjustment; } @@ -359,7 +359,7 @@ impl orml_tokens::Config for Test { type Amount = Amount; type CurrencyId = AssetId; type WeightInfo = (); - type ExistentialDeposits = AssetRegistry; + type ExistentialDeposits = DummyRegistry; type MaxLocks = MaxLocks; type DustRemovalWhitelist = Whitelist; type MaxReserves = ConstU32<100_000>; @@ -423,31 +423,42 @@ impl DustRemovalAccountWhitelist for Whitelist { } } -pub struct AssetRegistry; +pub struct DummyRegistry; -impl Registry, Balance, DispatchError> for AssetRegistry { - fn exists(name: AssetId) -> bool { - name != UNKNOWN_ASSET +impl Inspect for DummyRegistry { + type AssetId = AssetId; + type Location = u8; + + fn is_sufficient(_id: Self::AssetId) -> bool { + unimplemented!() } - fn retrieve_asset(_name: &Vec) -> Result { - Err(sp_runtime::DispatchError::Other("NotImplemented")) + fn decimals(_id: Self::AssetId) -> Option { + unimplemented!() } - fn retrieve_asset_type(_asset_id: AssetId) -> Result { + fn asset_type(_id: Self::AssetId) -> Option { unimplemented!() } - fn create_asset(_name: &Vec, _existential_deposit: Balance) -> Result { - Err(sp_runtime::DispatchError::Other("NotImplemented")) + fn exists(name: AssetId) -> bool { + name != UNKNOWN_ASSET } - fn get_or_create_asset(_name: Vec, _existential_deposit: Balance) -> Result { - Err(sp_runtime::DispatchError::Other("NotImplemented")) + fn is_banned(_id: Self::AssetId) -> bool { + unimplemented!() + } + + fn asset_symbol(_id: Self::AssetId) -> Option> { + unimplemented!() + } + + fn asset_name(_id: Self::AssetId) -> Option> { + unimplemented!() } } -impl GetByKey for AssetRegistry { +impl GetByKey for DummyRegistry { fn get(_key: &AssetId) -> Balance { 1_000_u128 } diff --git a/pallets/omnipool-liquidity-mining/Cargo.toml b/pallets/omnipool-liquidity-mining/Cargo.toml index 78dddca28..1098a7f25 100644 --- a/pallets/omnipool-liquidity-mining/Cargo.toml +++ b/pallets/omnipool-liquidity-mining/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-omnipool-liquidity-mining" -version = "2.0.13" +version = "2.1.0" authors = ['GalacticCouncil'] edition = "2021" license = "Apache-2.0" @@ -41,7 +41,6 @@ hydra-dx-math = { workspace = true } # third party primitive-types = { version = "0.12.0", default-features = false } -bitflags = "1.3.2" # Optional imports for benchmarking frame-benchmarking = { workspace = true, optional = true } @@ -59,19 +58,20 @@ pretty_assertions = "1.2.1" default = ["std"] std = [ "codec/std", + "scale-info/std", "sp-runtime/std", "sp-std/std", "frame-support/std", "frame-system/std", - "scale-info/std", "sp-core/std", "sp-io/std", "pallet-balances/std", "orml-tokens/std", - "pallet-omnipool/std", + "pallet-omnipool/std", "pallet-ema-oracle/std", "pallet-liquidity-mining/std", "primitives/std", + "hydra-dx-math/std", ] runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", diff --git a/pallets/omnipool-liquidity-mining/src/benchmarks.rs b/pallets/omnipool-liquidity-mining/src/benchmarks.rs index 6d11b8d7d..7e01ed4a7 100644 --- a/pallets/omnipool-liquidity-mining/src/benchmarks.rs +++ b/pallets/omnipool-liquidity-mining/src/benchmarks.rs @@ -17,12 +17,14 @@ use crate::*; use frame_benchmarking::{account, benchmarks}; +use frame_support::storage::with_transaction; use frame_support::traits::{OnFinalize, OnInitialize}; use frame_system::{Pallet as System, RawOrigin}; -use hydradx_traits::Registry; +use hydradx_traits::registry::{AssetKind, Create}; use orml_traits::MultiCurrencyExtended; use pallet_liquidity_mining::Instance1; use primitives::AssetId; +use sp_runtime::TransactionOutcome; use sp_runtime::{traits::One, FixedU128, Permill}; const ONE: Balance = 1_000_000_000_000; @@ -94,6 +96,8 @@ where ::Currency: MultiCurrencyExtended, T: pallet_ema_oracle::Config, T::AssetId: From, + ::AssetRegistry: Create, + <::AssetRegistry as hydradx_traits::Inspect>::AssetId: From, { let stable_amount: Balance = 1_000_000_000_000_000u128; let native_amount: Balance = 1_000_000_000_000_000u128; @@ -105,6 +109,10 @@ where ::Currency::update_balance(DAI.into(), &acc, stable_amount as i128)?; ::Currency::update_balance(HDX.into(), &acc, native_amount as i128)?; + fund::(acc.clone(), HDX.into(), 10_000 * ONE)?; + ::Currency::update_balance(DAI.into(), &acc, stable_amount as i128)?; + ::Currency::update_balance(T::HdxAssetId::get(), &acc, native_amount as i128)?; + OmnipoolPallet::::add_token( RawOrigin::Root.into(), HDX.into(), @@ -120,10 +128,46 @@ where acc.clone(), )?; + let name = b"BSX".to_vec().try_into().map_err(|_| "BoundedConvertionFailed")?; // Register new asset in asset registry - T::AssetRegistry::create_asset(&b"BSX".to_vec(), Balance::one())?; - T::AssetRegistry::create_asset(&b"ETH".to_vec(), Balance::one())?; - T::AssetRegistry::create_asset(&b"BTC".to_vec(), Balance::one())?; + with_transaction(|| { + TransactionOutcome::Commit(T::AssetRegistry::register_sufficient_asset( + None, + Some(name), + AssetKind::Token, + Balance::one(), + None, + None, + None, + None, + )) + })?; + let name = b"ETH".to_vec().try_into().map_err(|_| "BoundedConvertionFailed")?; + with_transaction(|| { + TransactionOutcome::Commit(T::AssetRegistry::register_sufficient_asset( + None, + Some(name), + AssetKind::Token, + Balance::one(), + None, + None, + None, + None, + )) + })?; + let name = b"BTC".to_vec().try_into().map_err(|_| "BoundedConvertionFailed")?; + with_transaction(|| { + TransactionOutcome::Commit(T::AssetRegistry::register_sufficient_asset( + None, + Some(name), + AssetKind::Token, + Balance::one(), + None, + None, + None, + None, + )) + })?; // Create account for token provider and set balance let owner: T::AccountId = account("owner", 0, 1); @@ -234,6 +278,7 @@ benchmarks! { ::AssetId: From, ::Currency: MultiCurrencyExtended, T: crate::pallet::Config + pallet_ema_oracle::Config + pallet_liquidity_mining::Config, + ::AssetRegistry: Create::AssetId>, } create_global_farm { diff --git a/pallets/omnipool-liquidity-mining/src/tests/mock.rs b/pallets/omnipool-liquidity-mining/src/tests/mock.rs index 72d852964..6df5d991c 100644 --- a/pallets/omnipool-liquidity-mining/src/tests/mock.rs +++ b/pallets/omnipool-liquidity-mining/src/tests/mock.rs @@ -163,7 +163,7 @@ parameter_types! { pub const OracleSource: Source = *b"omnipool"; } -impl Config for Test { +impl omnipool_liquidity_mining::Config for Test { type RuntimeEvent = RuntimeEvent; type Currency = Tokens; type CreateOrigin = frame_system::EnsureRoot; @@ -632,28 +632,69 @@ impl Transfer for DummyNFT { } } -use hydradx_traits::Registry; +use hydradx_traits::Inspect as InspectRegistry; pub struct DummyRegistry(sp_std::marker::PhantomData); -impl Registry, Balance, DispatchError> for DummyRegistry +impl InspectRegistry for DummyRegistry where T::AssetId: Into + From, { + type AssetId = T::AssetId; + type Location = u8; + + fn is_sufficient(_id: Self::AssetId) -> bool { + unimplemented!() + } + + fn asset_type(_id: Self::AssetId) -> Option { + unimplemented!() + } + + fn decimals(_id: Self::AssetId) -> Option { + unimplemented!() + } + fn exists(asset_id: T::AssetId) -> bool { let asset = REGISTERED_ASSETS.with(|v| v.borrow().get(&(asset_id.into())).copied()); matches!(asset, Some(_)) } - fn retrieve_asset(_name: &Vec) -> Result { - Ok(T::AssetId::default()) + fn is_banned(_id: Self::AssetId) -> bool { + unimplemented!() + } + + fn asset_name(_id: Self::AssetId) -> Option> { + unimplemented!() } - fn retrieve_asset_type(_asset_id: T::AssetId) -> Result { + fn asset_symbol(_id: Self::AssetId) -> Option> { unimplemented!() } +} - fn create_asset(_name: &Vec, _existential_deposit: Balance) -> Result { +#[cfg(feature = "runtime-benchmarks")] +use hydradx_traits::Create as CreateRegistry; +#[cfg(feature = "runtime-benchmarks")] +impl CreateRegistry for DummyRegistry +where + T::AssetId: Into + From, +{ + type Error = DispatchError; + type Name = BoundedVec>; + type Symbol = BoundedVec>; + + fn register_asset( + _asset_id: Option, + _name: Option, + _kind: AssetKind, + _existential_deposit: Option, + _symbol: Option, + _decimals: Option, + _location: Option, + _xcm_rate_limit: Option, + _is_sufficient: bool, + ) -> Result { let assigned = REGISTERED_ASSETS.with(|v| { //NOTE: This is to have same ids as real AssetRegistry which is used in the benchmarks. //1_000_000 - offset of the reals AssetRegistry @@ -666,6 +707,19 @@ where }); Ok(T::AssetId::from(assigned)) } + + fn get_or_register_asset( + _name: Self::Name, + _kind: AssetKind, + _existential_deposit: Option, + _symbol: Option, + _decimals: Option, + _location: Option, + _xcm_rate_limit: Option, + _is_sufficient: bool, + ) -> Result { + unimplemented!() + } } use hydradx_traits::oracle::AggregatedPriceOracle; diff --git a/pallets/omnipool/Cargo.toml b/pallets/omnipool/Cargo.toml index c71c6967c..2abae4039 100644 --- a/pallets/omnipool/Cargo.toml +++ b/pallets/omnipool/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-omnipool" -version = "4.1.2" +version = "4.1.3" authors = ['GalacticCouncil'] edition = "2021" license = "Apache-2.0" diff --git a/pallets/omnipool/src/lib.rs b/pallets/omnipool/src/lib.rs index b7a20ff2b..54b45cb99 100644 --- a/pallets/omnipool/src/lib.rs +++ b/pallets/omnipool/src/lib.rs @@ -95,7 +95,7 @@ use sp_std::prelude::*; use frame_support::traits::tokens::nonfungibles::{Create, Inspect, Mutate}; use hydra_dx_math::omnipool::types::{AssetStateChange, BalanceUpdate, I129}; -use hydradx_traits::Registry; +use hydradx_traits::registry::Inspect as RegistryInspect; use orml_traits::{GetByKey, MultiCurrency}; use scale_info::TypeInfo; use sp_runtime::{ArithmeticError, DispatchError, FixedPointNumber, FixedU128, Permill}; @@ -160,7 +160,7 @@ pub mod pallet { type TechnicalOrigin: EnsureOrigin; /// Asset Registry mechanism - used to check if asset is correctly registered in asset registry - type AssetRegistry: Registry, Balance, DispatchError>; + type AssetRegistry: RegistryInspect; /// Native Asset ID #[pallet::constant] diff --git a/pallets/omnipool/src/tests/mock.rs b/pallets/omnipool/src/tests/mock.rs index 71fcb80b9..aac0fb912 100644 --- a/pallets/omnipool/src/tests/mock.rs +++ b/pallets/omnipool/src/tests/mock.rs @@ -31,7 +31,7 @@ use frame_support::{ traits::{ConstU32, ConstU64}, }; use frame_system::EnsureRoot; -use hydradx_traits::{AssetKind, Registry}; +use hydradx_traits::{registry::Inspect as InspectRegistry, AssetKind}; use orml_traits::parameter_type_with_key; use primitive_types::{U128, U256}; use sp_core::H256; @@ -516,30 +516,40 @@ impl + Into + Copy> Mutate for DummyNFT { pub struct DummyRegistry(sp_std::marker::PhantomData); -impl Registry, Balance, DispatchError> for DummyRegistry +impl InspectRegistry for DummyRegistry where T::AssetId: Into + From, { + type AssetId = T::AssetId; + type Location = u8; + + fn is_sufficient(_id: Self::AssetId) -> bool { + unimplemented!() + } + fn exists(asset_id: T::AssetId) -> bool { let asset = REGISTERED_ASSETS.with(|v| v.borrow().get(&(asset_id.into())).copied()); matches!(asset, Some(_)) } - fn retrieve_asset(_name: &Vec) -> Result { - Ok(T::AssetId::default()) + fn decimals(_id: Self::AssetId) -> Option { + unimplemented!() } - fn retrieve_asset_type(_asset_id: T::AssetId) -> Result { + fn asset_type(_id: Self::AssetId) -> Option { unimplemented!() } - fn create_asset(_name: &Vec, _existential_deposit: Balance) -> Result { - let assigned = REGISTERED_ASSETS.with(|v| { - let l = v.borrow().len(); - v.borrow_mut().insert(l as u32, l as u32); - l as u32 - }); - Ok(T::AssetId::from(assigned)) + fn is_banned(_id: Self::AssetId) -> bool { + unimplemented!() + } + + fn asset_name(_id: Self::AssetId) -> Option> { + unimplemented!() + } + + fn asset_symbol(_id: Self::AssetId) -> Option> { + unimplemented!() } } diff --git a/pallets/otc/Cargo.toml b/pallets/otc/Cargo.toml index d25361d1a..e27a5b5b3 100644 --- a/pallets/otc/Cargo.toml +++ b/pallets/otc/Cargo.toml @@ -1,6 +1,6 @@ [package] name = 'pallet-otc' -version = '1.0.3' +version = '1.1.0' description = 'A pallet for trustless over-the-counter trading' authors = ['GalacticCouncil'] edition = '2021' @@ -51,6 +51,7 @@ std = [ "scale-info/std", "orml-tokens/std", "hydradx-traits/std", + "frame-benchmarking/std" ] runtime-benchmarks = [ diff --git a/pallets/otc/src/benchmarks.rs b/pallets/otc/src/benchmarks.rs index 0e494de05..e1e14cfff 100644 --- a/pallets/otc/src/benchmarks.rs +++ b/pallets/otc/src/benchmarks.rs @@ -17,9 +17,10 @@ use super::*; use frame_benchmarking::{account, benchmarks}; use frame_support::assert_ok; use frame_system::RawOrigin; -use hydradx_traits::Registry; +use hydradx_traits::{AssetKind, Create}; use orml_traits::MultiCurrencyExtended; use sp_std::vec; +use sp_std::vec::Vec; pub const ONE: Balance = 1_000_000_000_000; benchmarks! { @@ -28,66 +29,95 @@ benchmarks! { T::Currency: MultiCurrencyExtended, T: crate::pallet::Config, u32: From<::AssetId>, + T::AssetRegistry: Create } place_order { - let (hdx, dai) = seed_registry::()?; + let (dot, dai) = seed_registry::()?; - let owner: T::AccountId = create_account_with_balances::("owner", 1, vec!(hdx, dai))?; - }: _(RawOrigin::Signed(owner.clone()), dai.into(), hdx.into(), 20 * ONE, 100 * ONE, true) + let owner: T::AccountId = create_account_with_balances::("owner", 1, vec!(dot, dai))?; + }: _(RawOrigin::Signed(owner.clone()), dai.into(), dot.into(), 20 * ONE, 100 * ONE, true) verify { - assert_eq!(T::Currency::reserved_balance_named(&NAMED_RESERVE_ID, hdx.into(), &owner), 100 * ONE); + assert_eq!(T::Currency::reserved_balance_named(&NAMED_RESERVE_ID, dot.into(), &owner), 100 * ONE); } partial_fill_order { - let (hdx, dai) = seed_registry::()?; + let (dot, dai) = seed_registry::()?; - let owner: T::AccountId = create_account_with_balances::("owner", 1, vec!(hdx, dai))?; - let filler: T::AccountId = create_account_with_balances::("filler", 2, vec!(hdx, dai))?; + let owner: T::AccountId = create_account_with_balances::("owner", 1, vec!(dot, dai))?; + let filler: T::AccountId = create_account_with_balances::("filler", 2, vec!(dot, dai))?; assert_ok!( - crate::Pallet::::place_order(RawOrigin::Signed(owner.clone()).into(), dai.into(), hdx.into(), 20 * ONE, 100 * ONE, true) + crate::Pallet::::place_order(RawOrigin::Signed(owner.clone()).into(), dai.into(), dot.into(), 20 * ONE, 100 * ONE, true) ); }: _(RawOrigin::Signed(filler.clone()), 0u32, 10 * ONE) verify { - assert_eq!(T::Currency::reserved_balance_named(&NAMED_RESERVE_ID, hdx.into(), &owner), 50 * ONE); + assert_eq!(T::Currency::reserved_balance_named(&NAMED_RESERVE_ID, dot.into(), &owner), 50 * ONE); } fill_order { - let (hdx, dai) = seed_registry::()?; + let (dot, dai) = seed_registry::()?; - let owner: T::AccountId = create_account_with_balances::("owner", 1, vec!(hdx, dai))?; - let filler: T::AccountId = create_account_with_balances::("filler", 2, vec!(hdx, dai))?; + let owner: T::AccountId = create_account_with_balances::("owner", 1, vec!(dot, dai))?; + let filler: T::AccountId = create_account_with_balances::("filler", 2, vec!(dot, dai))?; assert_ok!( - crate::Pallet::::place_order(RawOrigin::Signed(owner.clone()).into(), dai.into(), hdx.into(), 20 * ONE, 100 * ONE, true) + crate::Pallet::::place_order(RawOrigin::Signed(owner.clone()).into(), dai.into(), dot.into(), 20 * ONE, 100 * ONE, true) ); }: _(RawOrigin::Signed(filler.clone()), 0u32) verify { - assert_eq!(T::Currency::reserved_balance_named(&NAMED_RESERVE_ID, hdx.into(), &owner), 0); + assert_eq!(T::Currency::reserved_balance_named(&NAMED_RESERVE_ID, dot.into(), &owner), 0); } cancel_order { - let (hdx, dai) = seed_registry::()?; + let (dot, dai) = seed_registry::()?; - let owner: T::AccountId = create_account_with_balances::("owner", 1, vec!(hdx, dai))?; + let owner: T::AccountId = create_account_with_balances::("owner", 1, vec!(dot, dai))?; assert_ok!( - crate::Pallet::::place_order(RawOrigin::Signed(owner.clone()).into(), dai.into(), hdx.into(), 20 * ONE, 100 * ONE, true) + crate::Pallet::::place_order(RawOrigin::Signed(owner.clone()).into(), dai.into(), dot.into(), 20 * ONE, 100 * ONE, true) ); }: _(RawOrigin::Signed(owner.clone()), 0u32) verify { - assert_eq!(T::Currency::reserved_balance_named(&NAMED_RESERVE_ID, hdx.into(), &owner), 0); + assert_eq!(T::Currency::reserved_balance_named(&NAMED_RESERVE_ID, dot.into(), &owner), 0); } } fn seed_registry() -> Result<(u32, u32), DispatchError> where u32: From<::AssetId>, + T::AssetRegistry: Create, { - // Register new asset in asset registry - let hdx = T::AssetRegistry::create_asset(&b"HDX".to_vec(), ONE)?; - let dai = T::AssetRegistry::create_asset(&b"DAI".to_vec(), ONE)?; + use frame_support::storage::with_transaction; + use sp_runtime::TransactionOutcome; - Ok((hdx.into(), dai.into())) + // Register new asset in asset registry + let name = b"DOT".to_vec().try_into().map_err(|_| "BoundedConvertionFailed")?; + let dot = with_transaction(|| { + TransactionOutcome::Commit(::AssetRegistry::register_sufficient_asset( + None, + Some(name), + AssetKind::Token, + ONE, + None, + None, + None, + None, + )) + })?; + let name = b"DAI".to_vec().try_into().map_err(|_| "BoundedConvertionFailed")?; + let dai = with_transaction(|| { + TransactionOutcome::Commit(::AssetRegistry::register_sufficient_asset( + None, + Some(name), + AssetKind::Token, + ONE, + None, + None, + None, + None, + )) + })?; + + Ok((dot.into(), dai.into())) } fn create_account_with_balances( diff --git a/pallets/otc/src/lib.rs b/pallets/otc/src/lib.rs index feedc8e05..c924a83e8 100644 --- a/pallets/otc/src/lib.rs +++ b/pallets/otc/src/lib.rs @@ -36,14 +36,11 @@ use codec::MaxEncodedLen; use frame_support::{pallet_prelude::*, require_transactional}; use frame_system::{ensure_signed, pallet_prelude::OriginFor}; -use hydradx_traits::Registry; +use hydradx_traits::Inspect; use orml_traits::{GetByKey, MultiCurrency, NamedMultiReservableCurrency}; use sp_core::U256; -use sp_runtime::{ - traits::{One, Zero}, - DispatchError, -}; -use sp_std::vec::Vec; +use sp_runtime::traits::{One, Zero}; + #[cfg(test)] mod tests; @@ -87,7 +84,7 @@ pub mod pallet { type AssetId: Member + Parameter + Copy + HasCompact + MaybeSerializeDeserialize + MaxEncodedLen; /// Asset Registry mechanism - used to check if asset is correctly registered in asset registry - type AssetRegistry: Registry, Balance, DispatchError>; + type AssetRegistry: Inspect; /// Named reservable multi currency type Currency: NamedMultiReservableCurrency< diff --git a/pallets/otc/src/tests/mock.rs b/pallets/otc/src/tests/mock.rs index f6689014a..67b9cb65e 100644 --- a/pallets/otc/src/tests/mock.rs +++ b/pallets/otc/src/tests/mock.rs @@ -20,13 +20,13 @@ use frame_support::{ traits::{Everything, Nothing}, }; use frame_system as system; -use hydradx_traits::{AssetKind, Registry}; +use hydradx_traits::{registry::Inspect, AssetKind}; use orml_tokens::AccountData; use orml_traits::parameter_type_with_key; use sp_core::H256; use sp_runtime::{ traits::{BlakeTwo256, IdentityLookup}, - BuildStorage, DispatchError, + BuildStorage, }; use std::{cell::RefCell, collections::HashMap}; @@ -74,7 +74,7 @@ parameter_type_with_key! { }; } -impl Config for Test { +impl otc::Config for Test { type AssetId = AssetId; type AssetRegistry = DummyRegistry; type Currency = Tokens; @@ -132,28 +132,89 @@ impl orml_tokens::Config for Test { pub struct DummyRegistry(sp_std::marker::PhantomData); -impl Registry, Balance, DispatchError> for DummyRegistry { +impl Inspect for DummyRegistry { + type AssetId = AssetId; + type Location = u8; + + fn asset_type(_id: Self::AssetId) -> Option { + unimplemented!() + } + + fn decimals(_id: Self::AssetId) -> Option { + unimplemented!() + } + + fn is_sufficient(_id: Self::AssetId) -> bool { + unimplemented!() + } + fn exists(asset_id: AssetId) -> bool { let asset = REGISTERED_ASSETS.with(|v| v.borrow().get(&(asset_id)).copied()); matches!(asset, Some(_)) } - fn retrieve_asset(_name: &Vec) -> Result { - Ok(0) + fn is_banned(_id: Self::AssetId) -> bool { + unimplemented!() } - fn retrieve_asset_type(_asset_id: AssetId) -> Result { + fn asset_name(_id: Self::AssetId) -> Option> { unimplemented!() } - fn create_asset(_name: &Vec, _existential_deposit: Balance) -> Result { + fn asset_symbol(_id: Self::AssetId) -> Option> { + unimplemented!() + } +} + +#[cfg(feature = "runtime-benchmarks")] +use hydradx_traits::Create as CreateRegistry; +#[cfg(feature = "runtime-benchmarks")] +use sp_runtime::DispatchError; +#[cfg(feature = "runtime-benchmarks")] +impl CreateRegistry for DummyRegistry +where + T::AssetId: Into + From, +{ + type Error = DispatchError; + type Name = sp_runtime::BoundedVec>; + type Symbol = sp_runtime::BoundedVec>; + + fn register_asset( + _asset_id: Option, + _name: Option, + _kind: AssetKind, + _existential_deposit: Option, + _symbol: Option, + _decimals: Option, + _location: Option, + _xcm_rate_limit: Option, + _is_sufficient: bool, + ) -> Result { let assigned = REGISTERED_ASSETS.with(|v| { - let l = v.borrow().len(); + //NOTE: This is to have same ids as real AssetRegistry which is used in the benchmarks. + //1_000_000 - offset of the reals AssetRegistry + // - 3 - remove assets reagistered by default for the vec.len() + // +1 - first reg asset start with 1 not 0 + // => 1-th asset id == 1_000_001 + let l = 1_000_000 - 3 + 1 + v.borrow().len(); v.borrow_mut().insert(l as u32, l as u32); l as u32 }); Ok(assigned) } + + fn get_or_register_asset( + _name: Self::Name, + _kind: AssetKind, + _existential_deposit: Option, + _symbol: Option, + _decimals: Option, + _location: Option, + _xcm_rate_limit: Option, + _is_sufficient: bool, + ) -> Result { + unimplemented!() + } } pub struct ExtBuilder { diff --git a/pallets/route-executor/Cargo.toml b/pallets/route-executor/Cargo.toml index 4ffa6cdd8..ca5b39e02 100644 --- a/pallets/route-executor/Cargo.toml +++ b/pallets/route-executor/Cargo.toml @@ -1,6 +1,6 @@ [package] name = 'pallet-route-executor' -version = '2.0.0' +version = '2.0.1' description = 'A pallet to execute a route containing a sequence of trades' authors = ['GalacticCouncil'] edition = '2021' diff --git a/pallets/route-executor/src/lib.rs b/pallets/route-executor/src/lib.rs index 2dbb6cc36..8026a7ffe 100644 --- a/pallets/route-executor/src/lib.rs +++ b/pallets/route-executor/src/lib.rs @@ -520,6 +520,13 @@ impl Pallet { with_transaction(|| { let origin: OriginFor = Origin::::Signed(Self::router_account()).into(); + //NOTE: This is necessary so router's account can pay ED for insufficient assets in the + //route. Value is 10K to make sure we can pay ED for really long routes. + let _ = T::Currency::mint_into( + T::NativeAssetId::get(), + &Self::router_account(), + 10_000_000_000_000_000_u128.into(), + ); let _ = T::Currency::mint_into(asset_in, &Self::router_account(), amount_in); let sell_result = Self::sell(origin, asset_in, asset_out, amount_in, u128::MIN.into(), route.clone()); diff --git a/pallets/stableswap/Cargo.toml b/pallets/stableswap/Cargo.toml index 59ed741ea..fda85f6b9 100644 --- a/pallets/stableswap/Cargo.toml +++ b/pallets/stableswap/Cargo.toml @@ -1,6 +1,6 @@ [package] name = 'pallet-stableswap' -version = '3.4.3' +version = '3.4.4' description = 'AMM for correlated assets' authors = ['GalacticCouncil'] edition = '2021' diff --git a/pallets/stableswap/src/lib.rs b/pallets/stableswap/src/lib.rs index cede825ca..a11dc2a54 100644 --- a/pallets/stableswap/src/lib.rs +++ b/pallets/stableswap/src/lib.rs @@ -56,7 +56,7 @@ extern crate core; use frame_support::pallet_prelude::{DispatchResult, Get}; use frame_support::{ensure, require_transactional, transactional}; use frame_system::pallet_prelude::BlockNumberFor; -use hydradx_traits::{registry::InspectRegistry, AccountIdFor}; +use hydradx_traits::{registry::Inspect, AccountIdFor}; pub use pallet::*; use sp_runtime::traits::{BlockNumberProvider, Zero}; use sp_runtime::{ArithmeticError, DispatchError, Permill, SaturatedConversion}; @@ -137,7 +137,7 @@ pub mod pallet { type ShareAccountId: AccountIdFor; /// Asset registry mechanism to check if asset is registered and retrieve asset decimals. - type AssetInspection: InspectRegistry; + type AssetInspection: Inspect; /// The origin which can create a new pool type AuthorityOrigin: EnsureOrigin; diff --git a/pallets/stableswap/src/tests/mock.rs b/pallets/stableswap/src/tests/mock.rs index 37c2c51b2..439edbdde 100644 --- a/pallets/stableswap/src/tests/mock.rs +++ b/pallets/stableswap/src/tests/mock.rs @@ -312,12 +312,15 @@ impl ExtBuilder { use crate::types::BenchmarkHelper; use crate::types::{AssetAmount, PoolInfo, PoolState, StableswapHooks}; use hydradx_traits::pools::DustRemovalAccountWhitelist; -use hydradx_traits::{AccountIdFor, InspectRegistry}; +use hydradx_traits::{AccountIdFor, Inspect}; use sp_runtime::traits::Zero; pub struct DummyRegistry; -impl InspectRegistry for DummyRegistry { +impl Inspect for DummyRegistry { + type AssetId = AssetId; + type Location = u8; + fn exists(asset_id: AssetId) -> bool { let asset = REGISTERED_ASSETS.with(|v| v.borrow().get(&asset_id).copied()); matches!(asset, Some(_)) @@ -328,11 +331,23 @@ impl InspectRegistry for DummyRegistry { Some(asset.1) } - fn asset_name(_asset_id: AssetId) -> Option> { + fn is_sufficient(_id: Self::AssetId) -> bool { + unimplemented!() + } + + fn asset_type(_id: Self::AssetId) -> Option { + unimplemented!() + } + + fn is_banned(_id: Self::AssetId) -> bool { + unimplemented!() + } + + fn asset_name(_id: Self::AssetId) -> Option> { unimplemented!() } - fn asset_symbol(_asset_id: AssetId) -> Option> { + fn asset_symbol(_id: Self::AssetId) -> Option> { unimplemented!() } } diff --git a/pallets/transaction-multi-payment/Cargo.toml b/pallets/transaction-multi-payment/Cargo.toml index 1b1dbf76b..cb2114ac1 100644 --- a/pallets/transaction-multi-payment/Cargo.toml +++ b/pallets/transaction-multi-payment/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-transaction-multi-payment" -version = "9.2.1" +version = "9.3.0" description = "Transaction multi currency payment support module" authors = ["GalacticCoucil"] edition = "2021" diff --git a/pallets/transaction-multi-payment/src/lib.rs b/pallets/transaction-multi-payment/src/lib.rs index 3ba78482f..67be14120 100644 --- a/pallets/transaction-multi-payment/src/lib.rs +++ b/pallets/transaction-multi-payment/src/lib.rs @@ -301,7 +301,7 @@ pub mod pallet { } impl Pallet { - fn account_currency(who: &T::AccountId) -> AssetIdOf + pub fn account_currency(who: &T::AccountId) -> AssetIdOf where BalanceOf: FixedPointOperand, { diff --git a/pallets/xcm-rate-limiter/Cargo.toml b/pallets/xcm-rate-limiter/Cargo.toml index c56229927..a657534ed 100644 --- a/pallets/xcm-rate-limiter/Cargo.toml +++ b/pallets/xcm-rate-limiter/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-xcm-rate-limiter" -version = "0.1.4" +version = "0.1.5" authors = ["GalacticCouncil "] edition = "2021" license = "Apache-2.0" diff --git a/pallets/xcm-rate-limiter/src/tests/mock.rs b/pallets/xcm-rate-limiter/src/tests/mock.rs index d2f630a74..41ff345a4 100644 --- a/pallets/xcm-rate-limiter/src/tests/mock.rs +++ b/pallets/xcm-rate-limiter/src/tests/mock.rs @@ -305,35 +305,45 @@ impl + Into + Copy> Mutate for DummyNFT { } use crate::Config; -use hydradx_traits::{AssetKind, Registry}; +use hydradx_traits::registry::{AssetKind, Inspect as InspectRegistry}; use pallet_omnipool::traits::ExternalPriceProvider; pub struct DummyRegistry(sp_std::marker::PhantomData); -impl Registry, Balance, DispatchError> for DummyRegistry +impl InspectRegistry for DummyRegistry where T::AssetId: Into + From, { + type AssetId = T::AssetId; + type Location = MultiLocation; + + fn is_sufficient(_id: Self::AssetId) -> bool { + unimplemented!() + } + + fn asset_type(_id: Self::AssetId) -> Option { + unimplemented!() + } + + fn decimals(_id: Self::AssetId) -> Option { + unimplemented!() + } + fn exists(asset_id: T::AssetId) -> bool { let asset = REGISTERED_ASSETS.with(|v| v.borrow().get(&(asset_id.into())).copied()); matches!(asset, Some(_)) } - fn retrieve_asset(_name: &Vec) -> Result { - Ok(T::AssetId::default()) + fn is_banned(_id: Self::AssetId) -> bool { + unimplemented!() } - fn retrieve_asset_type(_asset_id: T::AssetId) -> Result { + fn asset_symbol(_id: Self::AssetId) -> Option> { unimplemented!() } - fn create_asset(_name: &Vec, _existential_deposit: Balance) -> Result { - let assigned = REGISTERED_ASSETS.with(|v| { - let l = v.borrow().len(); - v.borrow_mut().insert(l as u32, l as u32); - l as u32 - }); - Ok(T::AssetId::from(assigned)) + fn asset_name(_id: Self::AssetId) -> Option> { + unimplemented!() } } diff --git a/pallets/xyk/Cargo.toml b/pallets/xyk/Cargo.toml index cfe61379c..b995efea9 100644 --- a/pallets/xyk/Cargo.toml +++ b/pallets/xyk/Cargo.toml @@ -1,6 +1,6 @@ [package] name = 'pallet-xyk' -version = "6.3.4" +version = "6.4.0" description = 'XYK automated market maker' authors = ['GalacticCouncil'] edition = '2021' diff --git a/pallets/xyk/src/benchmarking.rs b/pallets/xyk/src/benchmarking.rs deleted file mode 100644 index f8835aa7e..000000000 --- a/pallets/xyk/src/benchmarking.rs +++ /dev/null @@ -1,207 +0,0 @@ -// This file is part of HydraDX-node. - -// Copyright (C) 2022 Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#![cfg(feature = "runtime-benchmarks")] - -use super::*; - -use frame_benchmarking::{account, benchmarks}; -use frame_system::RawOrigin; -use sp_std::prelude::*; - -use crate::Pallet as XYK; - -use crate::types::{AssetId, Balance}; -use hydradx_traits::router::{PoolType, TradeExecution}; - -const SEED: u32 = 1; - -fn funded_account(name: &'static str, index: u32) -> T::AccountId { - let caller: T::AccountId = account(name, index, SEED); - T::Currency::update_balance(1, &caller, 1_000_000_000_000_000).unwrap(); - T::Currency::update_balance(2, &caller, 1_000_000_000_000_000).unwrap(); - caller -} - -benchmarks! { - create_pool { - let caller = funded_account::("caller", 0); - - let asset_a: AssetId = 1; - let asset_b: AssetId = 2; - let amount_a : Balance = 10 * 1_000_000_000; - let amount_b : Balance = 20 * 1_000_000_000; - - }: _(RawOrigin::Signed(caller.clone()), asset_a, amount_a, asset_b, amount_b) - verify { - assert_eq!(T::Currency::free_balance(asset_a, &caller), 999990000000000); - } - - add_liquidity { - let maker = funded_account::("maker", 0); - let caller = funded_account::("caller", 0); - - let asset_a: AssetId = 1; - let asset_b: AssetId = 2; - let amount : Balance = 10 * 1_000_000_000; - let max_limit : Balance = 10 * 1_000_000_000_000; - - XYK::::create_pool(RawOrigin::Signed(maker).into(), asset_a, 1_000_000_000,asset_b, 1_000_000_000)?; - - }: _(RawOrigin::Signed(caller.clone()), asset_a, asset_b, amount, max_limit) - verify { - assert_eq!(T::Currency::free_balance(asset_a, &caller), 999990000000000); - assert_eq!(T::Currency::free_balance(asset_b, &caller), 999990000000000 - 1); // Due to rounding in favor of pool - } - - remove_liquidity { - let maker = funded_account::("maker", 0); - let caller = funded_account::("caller", 0); - - let asset_a: AssetId = 1; - let asset_b: AssetId = 2; - let amount : Balance = 1_000_000_000; - - XYK::::create_pool(RawOrigin::Signed(maker).into(), 1, 10_000_000_000, 2, 20_000_000_000)?; - XYK::::add_liquidity(RawOrigin::Signed(caller.clone()).into(), 1, 2, 5_000_000_000, 10_100_000_000)?; - - assert_eq!(T::Currency::free_balance(asset_a, &caller), 999995000000000); - assert_eq!(T::Currency::free_balance(asset_b, &caller), 999990000000000 - 1);// Due to rounding in favor of pool - - }: _(RawOrigin::Signed(caller.clone()), asset_a, asset_b, amount) - verify { - assert_eq!(T::Currency::free_balance(asset_a, &caller), 999996000000000); - assert_eq!(T::Currency::free_balance(asset_b, &caller), 999992000000000 - 1);// Due to rounding in favor of pool - } - - sell { - let maker = funded_account::("maker", 0); - let caller = funded_account::("caller", 0); - - let asset_a: AssetId = 1; - let asset_b: AssetId = 2; - let amount : Balance = 1_000_000_000; - let discount = false; - - let min_bought: Balance = 10 * 1_000; - - XYK::::create_pool(RawOrigin::Signed(maker).into(), asset_a, 1_000_000_000_000, asset_b, 3_000_000_000_000)?; - - }: _(RawOrigin::Signed(caller.clone()), asset_a, asset_b, amount, min_bought, discount) - verify{ - assert_eq!(T::Currency::free_balance(asset_a, &caller), 999999000000000); - } - - buy { - let maker = funded_account::("maker", 0); - let caller = funded_account::("caller", 0); - - let asset_a: AssetId = 1; - let asset_b: AssetId = 2; - let amount : Balance = 1_000_000_000; - let discount = false; - - let max_sold: Balance = 6_000_000_000; - - XYK::::create_pool(RawOrigin::Signed(maker).into(), asset_a, 1_000_000_000_000, asset_b, 3_000_000_000_000)?; - - }: _(RawOrigin::Signed(caller.clone()), asset_a, asset_b, amount, max_sold, discount) - verify{ - assert_eq!(T::Currency::free_balance(asset_a, &caller), 1000001000000000); - } - - router_execution_sell { - let c in 1..2; // if c == 1, calculate_sell is executed - let e in 0..1; // if e == 1, execute_sell is executed - - let maker = funded_account::("maker", 0); - let caller = funded_account::("caller", 0); - - let asset_a: AssetId = 1; - let asset_b: AssetId = 2; - let amount : Balance = 1_000_000_000; - let discount = false; - - let min_bought: Balance = 10 * 1_000; - - XYK::::create_pool(RawOrigin::Signed(maker).into(), asset_a, 1_000_000_000_000, asset_b, 3_000_000_000_000)?; - - }: { - for _ in 1..c { - assert!( as TradeExecution>::calculate_sell(PoolType::XYK, asset_a, asset_b, amount).is_ok()); - } - if e != 0 { - assert!( as TradeExecution>::execute_sell(RawOrigin::Signed(caller.clone()).into(), PoolType::XYK, asset_a, asset_b, amount, min_bought).is_ok()); - } - } - verify{ - if e != 0 { - assert_eq!(T::Currency::free_balance(asset_a, &caller), 999999000000000); - } - } - - router_execution_buy { - let c in 1..3; // number of times calculate_buy is executed - let e in 0..1; // if e == 1, execute_buy is executed - - let maker = funded_account::("maker", 0); - let caller = funded_account::("caller", 0); - - let asset_a: AssetId = 1; - let asset_b: AssetId = 2; - let amount : Balance = 1_000_000_000; - let discount = false; - - let max_sold: Balance = 6_000_000_000; - - XYK::::create_pool(RawOrigin::Signed(maker).into(), asset_a, 1_000_000_000_000, asset_b, 3_000_000_000_000)?; - - }: { - for _ in 1..c { - assert!( as TradeExecution>::calculate_buy(PoolType::XYK, asset_a, asset_b, amount).is_ok()); - } - if e != 0 { - assert!( as TradeExecution>::execute_buy(RawOrigin::Signed(caller.clone()).into(), PoolType::XYK, asset_a, asset_b, amount, max_sold).is_ok()); - } - } - verify{ - if e != 0 { - assert_eq!(T::Currency::free_balance(asset_b, &caller), 1000001000000000); - } - } -} - -#[cfg(test)] -mod tests { - use super::*; - use crate::tests::mock::{ExtBuilder, System, Test}; - use frame_support::assert_ok; - - #[test] - fn test_benchmarks() { - ExtBuilder::default().build().execute_with(|| { - System::set_block_number(1); - assert_ok!(Pallet::::test_benchmark_create_pool()); - assert_ok!(Pallet::::test_benchmark_add_liquidity()); - assert_ok!(Pallet::::test_benchmark_remove_liquidity()); - assert_ok!(Pallet::::test_benchmark_sell()); - assert_ok!(Pallet::::test_benchmark_buy()); - assert_ok!(Pallet::::test_benchmark_router_execution_sell()); - assert_ok!(Pallet::::test_benchmark_router_execution_buy()); - }); - } -} diff --git a/pallets/xyk/src/lib.rs b/pallets/xyk/src/lib.rs index 1e71d6664..c75ca97ba 100644 --- a/pallets/xyk/src/lib.rs +++ b/pallets/xyk/src/lib.rs @@ -45,8 +45,6 @@ use orml_traits::{MultiCurrency, MultiCurrencyExtended}; #[cfg(test)] mod tests; -mod benchmarking; - mod impls; mod trade_execution; pub mod types; @@ -64,7 +62,11 @@ pub mod pallet { use super::*; use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::OriginFor; - use hydradx_traits::{pools::DustRemovalAccountWhitelist, registry::ShareTokenRegistry, Source}; + use hydradx_traits::{ + pools::DustRemovalAccountWhitelist, + registry::{AssetKind, Create}, + Source, + }; #[pallet::pallet] pub struct Pallet(_); @@ -77,7 +79,7 @@ pub mod pallet { type RuntimeEvent: From> + IsType<::RuntimeEvent>; /// Registry support - type AssetRegistry: ShareTokenRegistry, Balance, DispatchError>; + type AssetRegistry: Create; /// Share token support type AssetPairAccountId: AssetPairAccountIdFor; @@ -344,10 +346,14 @@ pub mod pallet { let token_name = asset_pair.name(); - let share_token = T::AssetRegistry::get_or_create_shared_asset( - token_name, - vec![asset_a, asset_b], - T::MinPoolLiquidity::get(), + let share_token = T::AssetRegistry::get_or_register_insufficient_asset( + token_name.try_into().map_err(|_| Error::::CannotCreatePool)?, + AssetKind::XYK, + None, + None, + None, + None, + None, )?; let _ = T::AMMHandler::on_create_pool(asset_pair.asset_in, asset_pair.asset_out); diff --git a/pallets/xyk/src/tests/creation.rs b/pallets/xyk/src/tests/creation.rs index e6566ecc9..c37fbc48e 100644 --- a/pallets/xyk/src/tests/creation.rs +++ b/pallets/xyk/src/tests/creation.rs @@ -1,7 +1,6 @@ pub use super::mock::*; use crate::{Error, Event}; use frame_support::{assert_noop, assert_ok, BoundedVec}; -use hydradx_traits::Registry; use hydradx_traits::AMM as AmmPool; use orml_traits::MultiCurrency; use pallet_asset_registry::AssetType; @@ -44,8 +43,13 @@ fn create_pool_should_work() { expect_events(vec![ pallet_asset_registry::Event::Registered { asset_id: share_token, - asset_name: bounded_name, - asset_type: AssetType::PoolShare(HDX, ACA), + asset_name: Some(bounded_name), + asset_type: AssetType::XYK, + existential_deposit: pallet_asset_registry::DEFAULT_ED, + xcm_rate_limit: None, + symbol: None, + decimals: None, + is_sufficient: false, } .into(), Event::PoolCreated { @@ -374,13 +378,15 @@ fn share_asset_id_should_be_offset() { // This is how share tokens were registered before the offset was introduced. assert_ok!(AssetRegistry::register( RuntimeOrigin::signed(ALICE), - asset_pair.name(), - AssetType::PoolShare(HDX, ACA), - ::MinPoolLiquidity::get(), Some(next_asset_id), + Some(asset_pair.name().try_into().unwrap()), + AssetType::XYK, + Some(::MinPoolLiquidity::get()), None, None, None, + None, + false )); // Create_pool doesn't register new share token if it already exists @@ -396,7 +402,11 @@ fn share_asset_id_should_be_offset() { let share_token = XYK::share_token(pair_account); assert_eq!(share_token, next_asset_id); - assert_eq!(AssetRegistry::retrieve_asset(&asset_pair.name()).unwrap(), share_token); + assert_eq!( + AssetRegistry::asset_ids::>(asset_pair.name().try_into().unwrap()) + .unwrap(), + share_token + ); // Act let next_asset_id = AssetRegistry::next_asset_id().unwrap(); @@ -420,6 +430,10 @@ fn share_asset_id_should_be_offset() { // Assert assert_eq!(share_token, next_asset_id); - assert_eq!(AssetRegistry::retrieve_asset(&asset_pair.name()).unwrap(), share_token); + assert_eq!( + AssetRegistry::asset_ids::>(asset_pair.name().try_into().unwrap()) + .unwrap(), + share_token + ); }); } diff --git a/pallets/xyk/src/tests/mock.rs b/pallets/xyk/src/tests/mock.rs index eca5ebc1b..b8dffd442 100644 --- a/pallets/xyk/src/tests/mock.rs +++ b/pallets/xyk/src/tests/mock.rs @@ -16,7 +16,6 @@ // limitations under the License. use crate as xyk; -use crate::Config; use crate::*; use frame_support::parameter_types; use frame_system as system; @@ -41,6 +40,7 @@ pub type AccountId = u64; pub const ALICE: AccountId = 1; pub const BOB: AccountId = 2; pub const CHARLIE: AccountId = 3; +pub const TREASURY: AccountId = 4; pub const HDX: AssetId = 1000; pub const DOT: AssetId = 2000; @@ -52,6 +52,8 @@ pub const ONE: Balance = 1_000_000_000_000; type Block = frame_system::mocking::MockBlock; +type AssetLocation = u8; + frame_support::construct_runtime!( pub enum Test { @@ -94,19 +96,26 @@ parameter_types! { pub const BlockHashCount: u64 = 250; pub const SS58Prefix: u8 = 63; pub const NativeAssetId: AssetId = HDX; + #[derive(PartialEq, Debug)] pub RegistryStringLimit: u32 = 100; + #[derive(PartialEq, Debug)] + pub MinRegistryStringLimit: u32 = 2; pub const SequentialIdOffset: u32 = 1_000_000; + pub const StoreFees: Balance = 10 * ONE; + pub const FeesBeneficiarry: u64 = TREASURY; } impl pallet_asset_registry::Config for Test { type RuntimeEvent = RuntimeEvent; type RegistryOrigin = EnsureSigned; + type Currency = Currency; + type UpdateOrigin = EnsureSigned; type AssetId = AssetId; - type Balance = Balance; - type AssetNativeLocation = u8; + type AssetNativeLocation = AssetLocation; type StringLimit = RegistryStringLimit; + type MinStringLimit = MinRegistryStringLimit; type SequentialIdStartAt = SequentialIdOffset; - type NativeAssetId = NativeAssetId; + type RegExternalWeightMultiplier = frame_support::traits::ConstU64<1>; type WeightInfo = (); } @@ -187,7 +196,7 @@ impl CanCreatePool for Disallow10_10Pool { } } -impl Config for Test { +impl xyk::Config for Test { type RuntimeEvent = RuntimeEvent; type AssetRegistry = AssetRegistry; type AssetPairAccountId = AssetPairAccountIdTest; diff --git a/runtime/adapters/Cargo.toml b/runtime/adapters/Cargo.toml index 7c3582797..33c5ad71a 100644 --- a/runtime/adapters/Cargo.toml +++ b/runtime/adapters/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hydradx-adapters" -version = "1.1.0" +version = "1.1.1" description = "Structs and other generic types for building runtimes." authors = ["GalacticCouncil"] edition = "2021" diff --git a/runtime/adapters/src/tests/mock.rs b/runtime/adapters/src/tests/mock.rs index 5eee69147..3c1820c29 100644 --- a/runtime/adapters/src/tests/mock.rs +++ b/runtime/adapters/src/tests/mock.rs @@ -31,7 +31,10 @@ use hydra_dx_math::ema::EmaPrice; use hydra_dx_math::support::rational::Rounding; use hydra_dx_math::to_u128_wrapper; use hydradx_traits::pools::DustRemovalAccountWhitelist; -use hydradx_traits::{router::PoolType, AssetKind, AssetPairAccountIdFor, CanCreatePool, Registry, ShareTokenRegistry}; +use hydradx_traits::{ + router::PoolType, AssetKind, AssetPairAccountIdFor, CanCreatePool, Create as CreateRegistry, + Inspect as InspectRegistry, +}; use orml_traits::{parameter_type_with_key, GetByKey}; use pallet_currencies::fungibles::FungibleCurrencies; use pallet_currencies::BasicCurrencyAdapter; @@ -41,11 +44,11 @@ use pallet_omnipool::traits::ExternalPriceProvider; use primitive_types::{U128, U256}; use sp_core::H256; use sp_runtime::traits::Zero; -use sp_runtime::Permill; use sp_runtime::{ traits::{BlakeTwo256, IdentityLookup}, BuildStorage, DispatchError, DispatchResult, FixedU128, }; +use sp_runtime::{BoundedVec, Permill}; use std::cell::RefCell; use std::collections::HashMap; @@ -573,44 +576,88 @@ impl + Into + Copy> Mutate for DummyNFT { pub struct DummyRegistry(sp_std::marker::PhantomData); -impl Registry, Balance, DispatchError> for DummyRegistry +impl InspectRegistry for DummyRegistry where T::AssetId: Into + From, { - fn exists(asset_id: T::AssetId) -> bool { - let asset = REGISTERED_ASSETS.with(|v| v.borrow().get(&(asset_id.into())).copied()); + type AssetId = AssetId; + type Location = u8; + + fn asset_type(_id: Self::AssetId) -> Option { + unimplemented!() + } + + fn decimals(_id: Self::AssetId) -> Option { + unimplemented!() + } + + fn is_sufficient(_id: Self::AssetId) -> bool { + unimplemented!() + } + + fn exists(asset_id: AssetId) -> bool { + let asset = REGISTERED_ASSETS.with(|v| v.borrow().get(&(asset_id)).copied()); matches!(asset, Some(_)) } - fn retrieve_asset(_name: &Vec) -> Result { - Ok(T::AssetId::default()) + fn is_banned(_id: Self::AssetId) -> bool { + unimplemented!() } - fn retrieve_asset_type(_asset_id: T::AssetId) -> Result { + fn asset_symbol(_id: Self::AssetId) -> Option> { unimplemented!() } - fn create_asset(_name: &Vec, _existential_deposit: Balance) -> Result { - let assigned = REGISTERED_ASSETS.with(|v| { - let l = v.borrow().len(); - v.borrow_mut().insert(l as u32, l as u32); - l as u32 - }); - Ok(T::AssetId::from(assigned)) + fn asset_name(_id: Self::AssetId) -> Option> { + unimplemented!() } } -impl ShareTokenRegistry, Balance, DispatchError> for DummyRegistry +impl CreateRegistry for DummyRegistry where - u32: From<::AssetId>, - ::AssetId: From, + T::AssetId: Into + From, { - fn retrieve_shared_asset(_: &Vec, _: &[T::AssetId]) -> Result { - Ok(T::AssetId::default()) + type Error = DispatchError; + type Name = BoundedVec>; + type Symbol = BoundedVec>; + + fn register_asset( + _asset_id: Option, + _name: Option, + _kind: AssetKind, + _existential_deposit: Option, + _symbol: Option, + _decimals: Option, + _location: Option, + _xcm_rate_limit: Option, + _is_sufficient: bool, + ) -> Result { + unimplemented!() } - fn create_shared_asset(_: &Vec, _: &[T::AssetId], _: Balance) -> Result { - unimplemented!("not implemented method: create_shared_asset") + fn register_insufficient_asset( + _asset_id: Option, + _name: Option, + _kind: AssetKind, + _existential_deposit: Option, + _symbol: Option, + _decimals: Option, + _location: Option, + _xcm_rate_limit: Option, + ) -> Result { + unimplemented!() + } + fn get_or_register_asset( + _name: Self::Name, + _kind: AssetKind, + _existential_deposit: Option, + _symbol: Option, + _decimals: Option, + _location: Option, + _xcm_rate_limit: Option, + _is_sufficient: bool, + ) -> Result { + Ok(T::AssetId::default().into()) } } diff --git a/runtime/adapters/src/xyk.rs b/runtime/adapters/src/xyk.rs index b97d9ef52..05f1f3ba9 100644 --- a/runtime/adapters/src/xyk.rs +++ b/runtime/adapters/src/xyk.rs @@ -1,24 +1,22 @@ use hydradx_traits::CanCreatePool; -use hydradx_traits::Registry; -use primitives::{AssetId, Balance}; -use sp_runtime::DispatchError; -use sp_std::vec::Vec; +use hydradx_traits::Inspect; +use primitives::AssetId; pub struct AllowPoolCreation(sp_std::marker::PhantomData<(LBP, R)>); impl CanCreatePool for AllowPoolCreation where LBP: pallet_lbp::Config, - R: Registry, Balance, DispatchError>, + R: Inspect, { fn can_create(asset_a: AssetId, asset_b: AssetId) -> bool { - let Some(asset_a_type) = R::retrieve_asset_type(asset_a).ok() else { + let Some(asset_a_type) = R::asset_type(asset_a) else { return false; }; if asset_a_type == hydradx_traits::AssetKind::XYK { return false; } - let Some(asset_b_type) = R::retrieve_asset_type(asset_b).ok() else { + let Some(asset_b_type) = R::asset_type(asset_b) else { return false; }; if asset_b_type == hydradx_traits::AssetKind::XYK { diff --git a/runtime/hydradx/Cargo.toml b/runtime/hydradx/Cargo.toml index c56f86ac4..9e6e872d6 100644 --- a/runtime/hydradx/Cargo.toml +++ b/runtime/hydradx/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hydradx-runtime" -version = "209.0.0" +version = "210.0.0" authors = ["GalacticCouncil"] edition = "2021" license = "Apache 2.0" @@ -13,7 +13,7 @@ targets = ["x86_64-unknown-linux-gnu"] substrate-wasm-builder = { workspace = true } [dependencies] -hex-literal = { workspace = true } +hex-literal = "0.4.1" serde = { features = ["derive"], optional = true, version = "1.0.136" } codec = { package = "parity-scale-codec", version = "3.4.0", default-features = false, features = ["derive"] } scale-info = { version = "2.3.1", default-features = false, features = ["derive"] } diff --git a/runtime/hydradx/src/assets.rs b/runtime/hydradx/src/assets.rs index 444f06d68..0e8d3f3d4 100644 --- a/runtime/hydradx/src/assets.rs +++ b/runtime/hydradx/src/assets.rs @@ -18,6 +18,7 @@ use super::*; use crate::system::NativeAssetId; +use frame_support::traits::Defensive; use hydradx_adapters::{ AssetFeeOraclePriceProvider, EmaOraclePriceAdapter, FreezableNFT, MultiCurrencyLockedBalance, OmnipoolHookAdapter, OracleAssetVolumeProvider, PriceAdjustmentAdapter, StableswapHooksAdapter, VestingInfo, @@ -25,8 +26,9 @@ use hydradx_adapters::{ use hydradx_adapters::{RelayChainBlockHashProvider, RelayChainBlockNumberProvider}; use hydradx_traits::{ + registry::Inspect, router::{inverse_route, PoolType, Trade}, - AccountIdFor, AssetKind, AssetPairAccountIdFor, OnTradeHandler, OraclePeriod, Source, + AccountIdFor, AssetKind, AssetPairAccountIdFor, NativePriceOracle, OnTradeHandler, OraclePeriod, Source, }; use pallet_currencies::BasicCurrencyAdapter; use pallet_omnipool::{ @@ -42,6 +44,7 @@ use primitives::constants::{ chain::OMNIPOOL_SOURCE, currency::{NATIVE_EXISTENTIAL_DEPOSIT, UNITS}, }; +use sp_runtime::{traits::Zero, DispatchError, DispatchResult, FixedPointNumber}; use core::ops::RangeInclusive; use frame_support::{ @@ -50,20 +53,20 @@ use frame_support::{ sp_runtime::traits::{One, PhantomData}, sp_runtime::{FixedU128, Perbill, Permill}, traits::{ - AsEnsureOriginWithArg, ConstU32, Contains, Currency, EnsureOrigin, Imbalance, NeverEnsureOrigin, OnUnbalanced, + AsEnsureOriginWithArg, ConstU32, Contains, Currency, EnsureOrigin, Imbalance, LockIdentifier, + NeverEnsureOrigin, OnUnbalanced, }, BoundedVec, PalletId, }; use frame_system::{EnsureRoot, EnsureSigned, RawOrigin}; -use orml_traits::currency::MutationHooks; -use orml_traits::{GetByKey, MultiCurrency}; +use orml_traits::currency::{MultiCurrency, MultiLockableCurrency, MutationHooks, OnDeposit, OnTransfer}; +use orml_traits::{GetByKey, Happened}; use pallet_dynamic_fees::types::FeeParams; use pallet_lbp::weights::WeightInfo as LbpWeights; use pallet_route_executor::{weights::WeightInfo as RouterWeights, AmmTradeWeights, MAX_NUMBER_OF_TRADES}; use pallet_staking::types::{Action, Point}; use pallet_staking::SigmoidPercentage; use pallet_xyk::weights::WeightInfo as XykWeights; -use sp_runtime::{DispatchError, FixedPointNumber}; use sp_std::num::NonZeroU16; parameter_types! { @@ -108,12 +111,178 @@ pub struct CurrencyHooks; impl MutationHooks for CurrencyHooks { type OnDust = Duster; type OnSlash = (); - type PreDeposit = (); + type PreDeposit = SufficiencyCheck; type PostDeposit = (); - type PreTransfer = (); + type PreTransfer = SufficiencyCheck; type PostTransfer = (); type OnNewTokenAccount = AddTxAssetOnAccount; - type OnKilledTokenAccount = RemoveTxAssetOnKilled; + type OnKilledTokenAccount = (RemoveTxAssetOnKilled, OnKilledTokenAccount); +} + +pub const SUFFICIENCY_LOCK: LockIdentifier = *b"insuffED"; + +parameter_types! { + //NOTE: This should always be > 1 otherwise we will payout more than we collected as ED for + //insufficient assets. + pub InsufficientEDinHDX: Balance = FixedU128::from_rational(11, 10) + .saturating_mul_int(::ExistentialDeposit::get()); +} + +pub struct SufficiencyCheck; +impl SufficiencyCheck { + /// This function is used by `orml-toknes::MutationHooks` before a transaction is executed. + /// It is called from `PreDeposit` and `PreTransfer`. + /// If transferred asset is not sufficient asset, it calculates ED amount in user's fee asset + /// and transfers it from user to treasury account. + /// Function also locks corresponding HDX amount in the treasury because returned ED to the users + /// when the account is killed is in the HDX. We are collecting little bit more (currencty 10%)than + /// we are paying back when account is killed. + /// + /// We assume account already paid ED if it holds transferred insufficient asset so additional + /// ED payment is not necessary. + /// + /// NOTE: `OnNewTokenAccount` mutation hooks is not used because it can't fail so we would not + /// be able to fail transactions e.g. if the user doesn't have enough funds to pay ED. + /// + /// ED payment - transfer: + /// - if both sender and dest. accounts are regular accounts, sender pays ED for dest. account. + /// - if sender is whitelisted account, dest. accounts pays its own ED. + /// + /// ED payment - deposit: + /// - dest. accounts always pays its own ED no matter if it's whitelisted or not. + /// + /// ED release: + /// ED is always released on account kill to killed account, whitelisting doesn't matter. + /// Released ED amount is calculated from locked HDX divided by number of accounts that paid + /// ED. + /// + /// WARN: + /// `set_balance` - bypass `MutationHooks` so no one pays ED for these account but ED is still released + /// when account is killed. + /// + /// Emits `pallet_asset_registry::Event::ExistentialDepositPaid` when ED was paid. + fn on_funds(asset: AssetId, paying_account: &AccountId, to: &AccountId) -> DispatchResult { + if AssetRegistry::is_banned(asset) { + return Err(DispatchError::Other("BannedAssetTransfer")); + } + + //NOTE: To prevent duplicate ED collection we assume account already paid ED + //if it has any amount of `asset`(exists in the storage). + if !orml_tokens::Accounts::::contains_key(to, asset) && !AssetRegistry::is_sufficient(asset) { + let fee_payment_asset = MultiTransactionPayment::account_currency(paying_account); + + let ed_in_fee_asset = MultiTransactionPayment::price(fee_payment_asset) + .ok_or(pallet_transaction_multi_payment::Error::::UnsupportedCurrency)? + .saturating_mul_int(InsufficientEDinHDX::get()) + .max(1); + + //NOTE: Account doesn't have enough funds to pay ED if this fail. + >::transfer( + fee_payment_asset, + paying_account, + &TreasuryAccount::get(), + ed_in_fee_asset, + ) + .map_err(|_| orml_tokens::Error::::ExistentialDeposit)?; + + //NOTE: we are locking little bit less than charging. + let to_lock = pallet_balances::Locks::::get(TreasuryAccount::get()) + .iter() + .find(|x| x.id == SUFFICIENCY_LOCK) + .map(|p| p.amount) + .unwrap_or_default() + .saturating_add(::ExistentialDeposit::get()); + + >::set_lock( + SUFFICIENCY_LOCK, + NativeAssetId::get(), + &TreasuryAccount::get(), + to_lock, + )?; + + frame_system::Pallet::::inc_sufficients(to); + + pallet_asset_registry::ExistentialDepositCounter::::mutate(|v| *v = v.saturating_add(1)); + + pallet_asset_registry::Pallet::::deposit_event( + pallet_asset_registry::Event::::ExistentialDepositPaid { + who: paying_account.clone(), + fee_asset: fee_payment_asset, + amount: ed_in_fee_asset, + }, + ); + } + + Ok(()) + } +} + +impl OnTransfer for SufficiencyCheck { + fn on_transfer(asset: AssetId, from: &AccountId, to: &AccountId, _amount: Balance) -> DispatchResult { + //NOTE: `to` is paying ED if `from` is whitelisted. + //This can happen if pallet's account transfers insufficient tokens to another account. + if ::DustRemovalWhitelist::contains(from) { + Self::on_funds(asset, to, to) + } else { + Self::on_funds(asset, from, to) + } + } +} + +impl OnDeposit for SufficiencyCheck { + fn on_deposit(asset: AssetId, to: &AccountId, _amount: Balance) -> DispatchResult { + Self::on_funds(asset, to, to) + } +} + +pub struct OnKilledTokenAccount; +impl Happened<(AccountId, AssetId)> for OnKilledTokenAccount { + fn happened((who, asset): &(AccountId, AssetId)) { + if AssetRegistry::is_sufficient(*asset) || frame_system::Pallet::::account(who).sufficients.is_zero() { + return; + } + + let locked_ed = pallet_balances::Locks::::get(TreasuryAccount::get()) + .iter() + .find(|x| x.id == SUFFICIENCY_LOCK) + .map(|p| p.amount) + .unwrap_or_default(); + + let paid_counts = pallet_asset_registry::ExistentialDepositCounter::::get(); + let ed_to_refund = if paid_counts != 0 { + locked_ed.saturating_div(paid_counts) + } else { + 0 + }; + let to_lock = locked_ed.saturating_sub(ed_to_refund); + + if to_lock.is_zero() { + let _ = >::remove_lock( + SUFFICIENCY_LOCK, + NativeAssetId::get(), + &TreasuryAccount::get(), + ) + .defensive(); + } else { + let _ = >::set_lock( + SUFFICIENCY_LOCK, + NativeAssetId::get(), + &TreasuryAccount::get(), + to_lock, + ) + .defensive(); + } + + let _ = >::transfer( + NativeAssetId::get(), + &TreasuryAccount::get(), + who, + ed_to_refund, + ); + + frame_system::Pallet::::dec_sufficients(who); + pallet_asset_registry::ExistentialDepositCounter::::set(paid_counts.saturating_sub(1)); + } } impl orml_tokens::Config for Runtime { @@ -189,19 +358,25 @@ impl pallet_claims::Config for Runtime { } parameter_types! { + #[derive(PartialEq, Debug)] pub const RegistryStrLimit: u32 = 32; + #[derive(PartialEq, Debug)] + pub const MinRegistryStrLimit: u32 = 3; pub const SequentialIdOffset: u32 = 1_000_000; + pub const RegExternalWeightMultiplier: u64 = 10; } impl pallet_asset_registry::Config for Runtime { type RuntimeEvent = RuntimeEvent; - type RegistryOrigin = SuperMajorityTechCommittee; + type RegistryOrigin = EnsureRoot; + type UpdateOrigin = SuperMajorityTechCommittee; + type Currency = pallet_currencies::fungibles::FungibleCurrencies; type AssetId = AssetId; - type Balance = Balance; type AssetNativeLocation = AssetLocation; type StringLimit = RegistryStrLimit; + type MinStringLimit = MinRegistryStrLimit; type SequentialIdStartAt = SequentialIdOffset; - type NativeAssetId = NativeAssetId; + type RegExternalWeightMultiplier = RegExternalWeightMultiplier; type WeightInfo = weights::registry::HydraWeight; } @@ -853,34 +1028,42 @@ use pallet_currencies::fungibles::FungibleCurrencies; #[cfg(not(feature = "runtime-benchmarks"))] use hydradx_adapters::price::OraclePriceProviderUsingRoute; +#[cfg(feature = "runtime-benchmarks")] +use frame_support::storage::with_transaction; #[cfg(feature = "runtime-benchmarks")] use hydradx_traits::price::PriceProvider; +#[cfg(feature = "runtime-benchmarks")] +use hydradx_traits::registry::Create; use pallet_referrals::traits::Convert; use pallet_referrals::{FeeDistribution, Level}; #[cfg(feature = "runtime-benchmarks")] use pallet_stableswap::BenchmarkHelper; #[cfg(feature = "runtime-benchmarks")] -use sp_runtime::DispatchResult; - +use sp_runtime::TransactionOutcome; #[cfg(feature = "runtime-benchmarks")] pub struct RegisterAsset(PhantomData); #[cfg(feature = "runtime-benchmarks")] impl BenchmarkHelper for RegisterAsset { fn register_asset(asset_id: AssetId, decimals: u8) -> DispatchResult { - let asset_name = asset_id.to_le_bytes().to_vec(); - let name: BoundedVec = asset_name - .clone() + let asset_name: BoundedVec = asset_id + .to_le_bytes() + .to_vec() .try_into() - .map_err(|_| pallet_asset_registry::Error::::TooLong)?; - AssetRegistry::register_asset( - name, - pallet_asset_registry::AssetType::::Token, - 1, - Some(asset_id), - None, - )?; - AssetRegistry::set_metadata(RuntimeOrigin::root(), asset_id, asset_name, decimals)?; + .map_err(|_| "BoundedConversionFailed")?; + + with_transaction(|| { + TransactionOutcome::Commit(AssetRegistry::register_sufficient_asset( + Some(asset_id), + Some(asset_name.clone()), + AssetKind::Token, + 1, + Some(asset_name), + Some(decimals), + None, + None, + )) + })?; Ok(()) } @@ -1187,18 +1370,22 @@ pub struct ReferralsBenchmarkHelper; impl RefBenchmarkHelper for ReferralsBenchmarkHelper { fn prepare_convertible_asset_and_amount() -> (AssetId, Balance) { let asset_id: u32 = 1234u32; - let asset_name = asset_id.to_le_bytes().to_vec(); - let name: BoundedVec = asset_name.clone().try_into().unwrap(); - - AssetRegistry::register_asset( - name, - pallet_asset_registry::AssetType::::Token, - 1_000_000, - Some(asset_id), - None, - ) + let asset_name: BoundedVec = asset_id.to_le_bytes().to_vec().try_into().unwrap(); + + with_transaction(|| { + TransactionOutcome::Commit(AssetRegistry::register_asset( + Some(asset_id), + Some(asset_name.clone()), + AssetKind::Token, + Some(1_000_000), + Some(asset_name), + Some(18), + None, + None, + true, + )) + }) .unwrap(); - AssetRegistry::set_metadata(RuntimeOrigin::root(), asset_id, asset_name, 18).unwrap(); let native_price = FixedU128::from_inner(1201500000000000); let asset_price = FixedU128::from_inner(45_000_000_000); diff --git a/runtime/hydradx/src/benchmarking/dca.rs b/runtime/hydradx/src/benchmarking/dca.rs index 4d0c571b1..9ca9ef5d3 100644 --- a/runtime/hydradx/src/benchmarking/dca.rs +++ b/runtime/hydradx/src/benchmarking/dca.rs @@ -408,6 +408,13 @@ fn funded_account(name: &'static str, index: u32, assets: &[AssetId]) -> Account fn create_xyk_pool(asset_a: u32, asset_b: u32) { let caller: AccountId = funded_account("caller", 0, &[asset_a, asset_b]); + assert_ok!(Currencies::update_balance( + RawOrigin::Root.into(), + caller.clone(), + 0, + 10 * ONE as i128, + )); + let amount = 100000 * ONE; assert_ok!(Currencies::update_balance( RawOrigin::Root.into(), @@ -454,9 +461,19 @@ mod tests { .unwrap(); pallet_asset_registry::GenesisConfig:: { - registered_assets: vec![(b"DAI".to_vec(), 1_000u128, Some(DAI))], - native_asset_name: b"HDX".to_vec(), + registered_assets: vec![( + Some(DAI), + Some(b"DAI".to_vec().try_into().unwrap()), + 1_000u128, + None, + None, + None, + false, + )], + native_asset_name: b"HDX".to_vec().try_into().unwrap(), native_existential_deposit: NativeExistentialDeposit::get(), + native_decimals: 12, + native_symbol: b"HDX".to_vec().try_into().unwrap(), } .assimilate_storage(&mut t) .unwrap(); diff --git a/runtime/hydradx/src/benchmarking/duster.rs b/runtime/hydradx/src/benchmarking/duster.rs index cd47aaa66..720b8cd5c 100644 --- a/runtime/hydradx/src/benchmarking/duster.rs +++ b/runtime/hydradx/src/benchmarking/duster.rs @@ -42,7 +42,7 @@ runtime_benchmarks! { update_balance(asset_id, &to_dust_account, min_deposit); - update_asset(asset_id, b"TST".to_vec(), 110u128).map_err(|_| BenchmarkError::Stop("Failed to update asset"))?; + update_asset(asset_id, None, 110u128).map_err(|_| BenchmarkError::Stop("Failed to update asset"))?; assert_eq!(Tokens::free_balance(asset_id, &to_dust_account), dust_amount); let current_balance = Tokens::free_balance(asset_id, &dest_account.clone().unwrap()); diff --git a/runtime/hydradx/src/benchmarking/mod.rs b/runtime/hydradx/src/benchmarking/mod.rs index bf8347fae..f380d1188 100644 --- a/runtime/hydradx/src/benchmarking/mod.rs +++ b/runtime/hydradx/src/benchmarking/mod.rs @@ -8,37 +8,78 @@ pub mod omnipool; pub mod route_executor; pub mod tokens; pub mod vesting; +pub mod xyk; use crate::AssetRegistry; use frame_system::RawOrigin; +use hydradx_traits::{registry::Create, AssetKind}; use primitives::{AssetId, Balance}; +use sp_runtime::traits::One; use sp_std::vec; use sp_std::vec::Vec; pub const BSX: Balance = primitives::constants::currency::UNITS; +use frame_support::storage::with_transaction; +use sp_runtime::TransactionOutcome; + pub fn register_asset(name: Vec, deposit: Balance) -> Result { - AssetRegistry::register_asset( - AssetRegistry::to_bounded_name(name).map_err(|_| ())?, - pallet_asset_registry::AssetType::::Token, - deposit, - None, - None, - ) + let n = name.try_into().map_err(|_| ())?; + with_transaction(|| { + TransactionOutcome::Commit(AssetRegistry::register_sufficient_asset( + None, + Some(n), + AssetKind::Token, + deposit, + None, + None, + None, + None, + )) + }) + .map_err(|_| ()) +} + +pub fn register_external_asset(name: Vec) -> Result { + let n = name.try_into().map_err(|_| ())?; + with_transaction(|| { + TransactionOutcome::Commit(AssetRegistry::register_insufficient_asset( + None, + Some(n), + AssetKind::External, + Some(Balance::one()), + None, + None, + None, + None, + )) + }) .map_err(|_| ()) } #[allow(dead_code)] -pub fn update_asset(asset_id: AssetId, name: Vec, deposit: Balance) -> Result<(), ()> { - AssetRegistry::update( - RawOrigin::Root.into(), - asset_id, - name, - pallet_asset_registry::AssetType::::Token, - Some(deposit), - None, - ) +pub fn update_asset(asset_id: AssetId, name: Option>, deposit: Balance) -> Result<(), ()> { + let nm = if let Some(n) = name { + Some(n.try_into().map_err(|_| ())?) + } else { + None + }; + + with_transaction(|| { + TransactionOutcome::Commit(AssetRegistry::update( + RawOrigin::Root.into(), + asset_id, + nm, + None, + Some(deposit), + None, + None, + None, + None, + None, + )) + }) .map_err(|_| ()) } diff --git a/runtime/hydradx/src/benchmarking/multi_payment.rs b/runtime/hydradx/src/benchmarking/multi_payment.rs index 45368db5c..0fa89e8c2 100644 --- a/runtime/hydradx/src/benchmarking/multi_payment.rs +++ b/runtime/hydradx/src/benchmarking/multi_payment.rs @@ -16,7 +16,7 @@ // limitations under the License. use super::*; -use crate::{AccountId, AssetId, Balance, Currencies, EmaOracle, Runtime, System}; +use crate::{AccountId, AssetId, Balance, Currencies, EmaOracle, InsufficientEDinHDX, Runtime, System}; use frame_benchmarking::account; use frame_benchmarking::BenchmarkError; use frame_support::assert_ok; @@ -161,6 +161,13 @@ where { let maker: AccountId = account("xyk-maker", 0, SEED); + assert_ok!(Currencies::update_balance( + RawOrigin::Root.into(), + maker.clone(), + 0_u32, + InsufficientEDinHDX::get() as i128, + )); + assert_ok!(Currencies::update_balance( RawOrigin::Root.into(), maker.clone(), diff --git a/runtime/hydradx/src/benchmarking/omnipool.rs b/runtime/hydradx/src/benchmarking/omnipool.rs index 2e88edab0..e1b43a0ae 100644 --- a/runtime/hydradx/src/benchmarking/omnipool.rs +++ b/runtime/hydradx/src/benchmarking/omnipool.rs @@ -1,10 +1,9 @@ -use crate::{ - AccountId, AssetId, AssetRegistry, Balance, EmaOracle, Omnipool, Referrals, Runtime, RuntimeOrigin, System, -}; +use crate::{AccountId, AssetId, Balance, EmaOracle, Omnipool, Referrals, Runtime, RuntimeOrigin, System}; use super::*; use frame_benchmarking::account; +use frame_benchmarking::BenchmarkError; use frame_support::dispatch::DispatchResult; use frame_support::{ assert_ok, @@ -15,10 +14,7 @@ use frame_support::{ traits::{OnFinalize, OnInitialize}, }; use frame_system::RawOrigin; -use hydradx_traits::{ - router::{PoolType, TradeExecution}, - Registry, -}; +use hydradx_traits::router::{PoolType, TradeExecution}; use orml_benchmarking::runtime_benchmarks; use orml_traits::{MultiCurrency, MultiCurrencyExtended}; use pallet_omnipool::types::Tradability; @@ -89,7 +85,7 @@ runtime_benchmarks! { let acc = Omnipool::protocol_account(); // Register new asset in asset registry - let token_id = AssetRegistry::create_asset(&b"FCK".to_vec(), Balance::one())?; + let token_id = register_asset(b"FCK".to_vec(), Balance::one()).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?; // Create account for token provider and set balance let owner: AccountId = account("owner", 0, 1); @@ -111,7 +107,7 @@ runtime_benchmarks! { init()?; let acc = Omnipool::protocol_account(); //Register new asset in asset registry - let token_id = AssetRegistry::create_asset(&b"FCK".to_vec(), Balance::one())?; + let token_id = register_asset(b"FCK".to_vec(), Balance::one()).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?; // Create account for token provider and set balance let owner: AccountId = account("owner", 0, 1); @@ -142,7 +138,7 @@ runtime_benchmarks! { init()?; let acc = Omnipool::protocol_account(); // Register new asset in asset registry - let token_id = AssetRegistry::create_asset(&b"FCK".to_vec(), 1u128)?; + let token_id = register_asset(b"FCK".to_vec(), 1_u128).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?; // Create account for token provider and set balance let owner: AccountId = account("owner", 0, 1); @@ -187,7 +183,7 @@ runtime_benchmarks! { init()?; let acc = Omnipool::protocol_account(); // Register new asset in asset registry - let token_id = AssetRegistry::create_asset(&b"FCK".to_vec(), 1u128)?; + let token_id = register_asset(b"FCK".to_vec(), 1_u128).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?; // Create account for token provider and set balance let owner: AccountId = account("owner", 0, 1); @@ -235,7 +231,7 @@ runtime_benchmarks! { init()?; let acc = Omnipool::protocol_account(); // Register new asset in asset registry - let token_id = AssetRegistry::create_asset(&b"FCK".to_vec(), 1_u128)?; + let token_id = register_asset(b"FCK".to_vec(), 1_u128).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?; // Create account for token provider and set balance let owner: AccountId = account("owner", 0, 1); @@ -289,7 +285,7 @@ runtime_benchmarks! { refund_refused_asset { let recipient: AccountId = account("recipient", 3, 1); - let asset_id = AssetRegistry::create_asset(&b"FCK".to_vec(), 1_u128)?; + let asset_id = register_asset(b"FCK".to_vec(), 1_u128).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?; let amount = 1_000_000_000_000_000_u128; update_balance(asset_id, &Omnipool::protocol_account(), amount); @@ -302,7 +298,7 @@ runtime_benchmarks! { sacrifice_position { init()?; let acc = Omnipool::protocol_account(); - let token_id = AssetRegistry::create_asset(&b"FCK".to_vec(), Balance::one())?; + let token_id = register_asset(b"FCK".to_vec(), Balance::one()).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?; // Create account for token provider and set balance let owner: AccountId = account("owner", 0, 1); @@ -343,7 +339,7 @@ runtime_benchmarks! { init()?; let acc = Omnipool::protocol_account(); // Register new asset in asset registry - let token_id = AssetRegistry::create_asset(&b"FCK".to_vec(), Balance::one())?; + let token_id = register_asset(b"FCK".to_vec(), Balance::one()).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?; // Create account for token provider and set balance let owner: AccountId = account("owner", 0, 1); @@ -382,7 +378,7 @@ runtime_benchmarks! { init()?; let acc = Omnipool::protocol_account(); // Register new asset in asset registry - let token_id = AssetRegistry::create_asset(&b"FCK".to_vec(), Balance::one())?; + let token_id = register_asset(b"FCK".to_vec(), Balance::one()).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?; // Create account for token provider and set balance let owner: AccountId = account("owner", 0, 1); @@ -420,7 +416,7 @@ runtime_benchmarks! { let acc = Omnipool::protocol_account(); // Register new asset in asset registry - let token_id = AssetRegistry::create_asset(&b"FCK".to_vec(), 1u128)?; + let token_id = register_asset(b"FCK".to_vec(), 1_u128).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?; // Create account for token provider and set balance let owner: AccountId = account("owner", 0, 1); @@ -473,7 +469,7 @@ runtime_benchmarks! { let acc = Omnipool::protocol_account(); // Register new asset in asset registry - let token_id = AssetRegistry::create_asset(&b"FCK".to_vec(), 1_u128)?; + let token_id = register_asset(b"FCK".to_vec(), 1_u128).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?; // Create account for token provider and set balance let owner: AccountId = account("owner", 0, 1); @@ -535,11 +531,29 @@ mod tests { pallet_asset_registry::GenesisConfig:: { registered_assets: vec![ - (b"LRNA".to_vec(), 1_000u128, Some(1)), - (b"DAI".to_vec(), 1_000u128, Some(2)), + ( + Some(1), + Some(b"LRNA".to_vec().try_into().unwrap()), + 1_000u128, + None, + None, + None, + true, + ), + ( + Some(2), + Some(b"DAI".to_vec().try_into().unwrap()), + 1_000u128, + None, + None, + None, + true, + ), ], - native_asset_name: b"HDX".to_vec(), + native_asset_name: b"HDX".to_vec().try_into().unwrap(), native_existential_deposit: NativeExistentialDeposit::get(), + native_decimals: 12, + native_symbol: b"HDX".to_vec().try_into().unwrap(), } .assimilate_storage(&mut t) .unwrap(); diff --git a/runtime/hydradx/src/benchmarking/route_executor.rs b/runtime/hydradx/src/benchmarking/route_executor.rs index fa588a27b..d26bfe169 100644 --- a/runtime/hydradx/src/benchmarking/route_executor.rs +++ b/runtime/hydradx/src/benchmarking/route_executor.rs @@ -16,16 +16,18 @@ // limitations under the License. #![allow(clippy::result_large_err)] -use crate::{AccountId, AssetId, AssetRegistry, Balance, Currencies, Router, Runtime, RuntimeOrigin, System, LBP, XYK}; +use crate::{ + AccountId, AssetId, Balance, Currencies, InsufficientEDinHDX, Router, Runtime, RuntimeOrigin, System, LBP, XYK, +}; -use frame_benchmarking::account; +use super::*; + +use frame_benchmarking::{account, BenchmarkError}; use frame_support::dispatch::DispatchResult; -use frame_support::sp_runtime::traits::One; use frame_support::{assert_ok, ensure}; use frame_system::RawOrigin; use hydradx_traits::router::AssetPair; use hydradx_traits::router::{PoolType, RouterT, Trade}; -use hydradx_traits::Registry; use orml_benchmarking::runtime_benchmarks; use orml_traits::{MultiCurrency, MultiCurrencyExtended}; use primitives::constants::currency::UNITS; @@ -35,6 +37,9 @@ pub const INITIAL_BALANCE: Balance = 10_000_000 * UNITS; fn funded_account(name: &'static str, index: u32, assets: &[AssetId]) -> AccountId { let account: AccountId = account(name, index, 0); + //Necessary to pay ED for insufficient assets. + >::update_balance(0, &account, INITIAL_BALANCE as i128).unwrap(); + for asset in assets { assert_ok!(>::update_balance( *asset, @@ -96,7 +101,14 @@ fn setup_lbp(caller: AccountId, asset_in: AssetId, asset_out: AssetId) -> Dispat } fn create_xyk_pool(asset_a: u32, asset_b: u32) { - let caller: AccountId = funded_account("caller", 0, &[asset_a, asset_b]); + let caller: AccountId = funded_account("caller", 3, &[asset_a, asset_b]); + + assert_ok!(Currencies::update_balance( + RawOrigin::Root.into(), + caller.clone(), + 0_u32, + InsufficientEDinHDX::get() as i128, + )); let amount = 100000 * UNITS; assert_ok!(Currencies::update_balance( @@ -129,8 +141,8 @@ runtime_benchmarks! { calculate_and_execute_sell_in_lbp { let c in 0..1; // if c == 1, calculate_sell_trade_amounts is executed - let asset_in = 1u32; - let asset_out = 2u32; + let asset_in = register_external_asset(b"FCA".to_vec()).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?; + let asset_out = register_external_asset(b"FCB".to_vec()).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?; let caller: AccountId = funded_account("caller", 7, &[asset_in, asset_out]); let seller: AccountId = funded_account("seller", 8, &[asset_in, asset_out]); @@ -162,8 +174,8 @@ runtime_benchmarks! { let c in 1..2; // number of times `calculate_buy_trade_amounts` is executed let b in 0..1; // if e == 1, buy is executed - let asset_in = 1u32; - let asset_out = 2u32; + let asset_in = register_external_asset(b"FCA".to_vec()).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?; + let asset_out = register_external_asset(b"FCB".to_vec()).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?; let caller: AccountId = funded_account("caller", 0, &[asset_in, asset_out]); let buyer: AccountId = funded_account("buyer", 1, &[asset_in, asset_out]); @@ -196,12 +208,13 @@ runtime_benchmarks! { // Calculates the weight of xyk set route. Used in the calculation to determine the weight of the overhead. set_route_for_xyk { - let asset_1 = 1u32; - let asset_2 = AssetRegistry::create_asset(&b"FCA".to_vec(), Balance::one())?; - let asset_3 = AssetRegistry::create_asset(&b"FCB".to_vec(), Balance::one())?; + let asset_1 = register_external_asset(b"FCA".to_vec()).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?; + let asset_2 = register_external_asset(b"FCB".to_vec()).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?; + let asset_3 = register_external_asset(b"FCC".to_vec()).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?; + + let caller: AccountId = funded_account("caller", 0, &[asset_1, asset_2, asset_3]); + let buyer: AccountId = funded_account("buyer", 1, &[asset_1, asset_2, asset_3]); - let caller: AccountId = funded_account("caller", 0, &[asset_1, asset_2,asset_3]); - let buyer: AccountId = funded_account("buyer", 1, &[asset_1, asset_2,asset_3]); create_xyk_pool(asset_1, asset_2); create_xyk_pool(asset_1, asset_3); create_xyk_pool(asset_2, asset_3); @@ -244,27 +257,14 @@ runtime_benchmarks! { #[cfg(test)] mod tests { use super::*; - use crate::NativeExistentialDeposit; use orml_benchmarking::impl_benchmark_test_suite; use sp_runtime::BuildStorage; fn new_test_ext() -> sp_io::TestExternalities { - let mut t = frame_system::GenesisConfig::::default() + frame_system::GenesisConfig::::default() .build_storage() - .unwrap(); - - pallet_asset_registry::GenesisConfig:: { - registered_assets: vec![ - (b"LRNA".to_vec(), 1_000u128, Some(1)), - (b"DAI".to_vec(), 1_000u128, Some(2)), - ], - native_asset_name: b"HDX".to_vec(), - native_existential_deposit: NativeExistentialDeposit::get(), - } - .assimilate_storage(&mut t) - .unwrap(); - - sp_io::TestExternalities::new(t) + .unwrap() + .into() } impl_benchmark_test_suite!(new_test_ext(),); diff --git a/runtime/hydradx/src/benchmarking/tokens.rs b/runtime/hydradx/src/benchmarking/tokens.rs index c20000524..6edeae8f6 100644 --- a/runtime/hydradx/src/benchmarking/tokens.rs +++ b/runtime/hydradx/src/benchmarking/tokens.rs @@ -1,21 +1,24 @@ -use crate::{AccountId, AssetId, Balance, Runtime, Tokens}; +use crate::{AccountId, AssetId, Balance, Currencies, MultiTransactionPayment, Runtime, Tokens}; use sp_std::prelude::*; +use frame_benchmarking::account; use frame_benchmarking::BenchmarkError; -use frame_benchmarking::{account, whitelisted_caller}; use frame_system::RawOrigin; use frame_support::assert_ok; use orml_benchmarking::runtime_benchmarks; use orml_traits::MultiCurrency; use orml_traits::MultiCurrencyExtended; +use primitives::Price; use super::*; use sp_runtime::traits::{SaturatedConversion, StaticLookup}; const SEED: u32 = 0; +const HDX: AssetId = 0; +const UNIT: Balance = 1_000_000_000_000; pub fn lookup_of_account(who: AccountId) -> <::Lookup as StaticLookup>::Source { ::Lookup::unlookup(who) @@ -33,60 +36,128 @@ runtime_benchmarks! { { Runtime, orml_tokens } transfer { - let amount: Balance = BSX; + let amount: Balance = 2 * UNIT; - let asset_id = register_asset(b"TST".to_vec(), 1u128).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?; + let asset_id = register_external_asset(b"TST".to_vec()).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?; + let fee_asset = register_asset(b"FEE".to_vec(), 1u128).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?; - let from: AccountId = whitelisted_caller(); + let from: AccountId = account("from", 0, SEED); + >::update_balance(HDX, &from, (10_000 * UNIT) as i128)?; update_balance(asset_id, &from, amount); + update_balance(fee_asset, &from, 1_000 * UNIT); - let to: AccountId = account("to", 0, SEED); + MultiTransactionPayment::add_currency(RawOrigin::Root.into(), fee_asset, Price::from(1)).map_err(|_| BenchmarkError::Stop("Failed to add supported currency"))?; + pallet_transaction_multi_payment::pallet::AcceptedCurrencyPrice::::insert(fee_asset, Price::from(1)); + + MultiTransactionPayment::set_currency( + RawOrigin::Signed(from.clone()).into(), + fee_asset + )?; + + let to: AccountId = account("to", 1, SEED); let to_lookup = lookup_of_account(to.clone()); - }: _(RawOrigin::Signed(from), to_lookup, asset_id, amount) + }: _(RawOrigin::Signed(from.clone()), to_lookup, asset_id, amount) verify { assert_eq!(>::total_balance(asset_id, &to), amount); + assert_eq!(frame_system::Pallet::::account(to).sufficients, 1); + + //NOTE: make sure from was killed + assert!(!orml_tokens::Accounts::::contains_key(from.clone(), asset_id)); + assert_eq!(pallet_asset_registry::ExistentialDepositCounter::::get(), 1); + assert_eq!(frame_system::Pallet::::account(from).sufficients, 0); } transfer_all { - let amount: Balance = BSX; + let amount: Balance = UNIT; - let asset_id = register_asset(b"TST".to_vec(), 1u128).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?; + let asset_id = register_external_asset(b"TST".to_vec()).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?; + let fee_asset = register_asset(b"FEE".to_vec(), 1u128).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?; - let from: AccountId = whitelisted_caller(); + let from: AccountId = account("from", 0, SEED); + >::update_balance(HDX, &from, (10_000 * UNIT) as i128)?; update_balance(asset_id, &from, amount); + update_balance(fee_asset, &from, 1_000 * UNIT); + + MultiTransactionPayment::add_currency(RawOrigin::Root.into(), fee_asset, Price::from(1)).map_err(|_| BenchmarkError::Stop("Failed to add supported currency"))?; + pallet_transaction_multi_payment::pallet::AcceptedCurrencyPrice::::insert(fee_asset, Price::from(1)); + + MultiTransactionPayment::set_currency( + RawOrigin::Signed(from.clone()).into(), + fee_asset + )?; let to: AccountId = account("to", 0, SEED); let to_lookup = lookup_of_account(to); }: _(RawOrigin::Signed(from.clone()), to_lookup, asset_id, false) verify { assert_eq!(>::total_balance(asset_id, &from), 0); + + //NOTE: make sure from was killed + assert!(!orml_tokens::Accounts::::contains_key(from.clone(), asset_id)); + assert_eq!(pallet_asset_registry::ExistentialDepositCounter::::get(), 1); + assert_eq!(frame_system::Pallet::::account(from).sufficients, 0); } transfer_keep_alive { - let from: AccountId = whitelisted_caller(); - let asset_id = register_asset(b"TST".to_vec(), 1u128).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?; - update_balance(asset_id, &from, 2 * BSX); + let asset_id = register_external_asset(b"TST".to_vec()).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?; + let fee_asset = register_asset(b"FEE".to_vec(), 1u128).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?; + + let from: AccountId = account("from", 0, SEED); + >::update_balance(HDX, &from, (10_000 * UNIT) as i128)?; + update_balance(asset_id, &from, 2 * UNIT); + update_balance(fee_asset, &from, 1_000 * UNIT); + + MultiTransactionPayment::add_currency(RawOrigin::Root.into(), fee_asset, Price::from(1)).map_err(|_| BenchmarkError::Stop("Failed to add supported currency"))?; + pallet_transaction_multi_payment::pallet::AcceptedCurrencyPrice::::insert(fee_asset, Price::from(1)); + + MultiTransactionPayment::set_currency( + RawOrigin::Signed(from.clone()).into(), + fee_asset + )?; let to: AccountId = account("to", 0, SEED); let to_lookup = lookup_of_account(to.clone()); - }: _(RawOrigin::Signed(from), to_lookup, asset_id, BSX) + }: _(RawOrigin::Signed(from), to_lookup, asset_id, UNIT) verify { - assert_eq!(>::total_balance(asset_id, &to), BSX); + assert_eq!(>::total_balance(asset_id, &to), UNIT); + + //NOTE: make sure none was killed + assert_eq!(pallet_asset_registry::ExistentialDepositCounter::::get(), 2); } force_transfer { + let amount = 2 * UNIT; + + let asset_id = register_external_asset(b"TST".to_vec()).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?; + let fee_asset = register_asset(b"FEE".to_vec(), 1u128).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?; + let from: AccountId = account("from", 0, SEED); let from_lookup = lookup_of_account(from.clone()); - let asset_id = register_asset(b"TST".to_vec(), 1u128).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?; - update_balance(asset_id, &from, 2 * BSX); + >::update_balance(HDX, &from, (10_000 * UNIT) as i128)?; + update_balance(asset_id, &from, amount); + update_balance(fee_asset, &from, 1_000 * UNIT); + + MultiTransactionPayment::add_currency(RawOrigin::Root.into(), fee_asset, Price::from(1)).map_err(|_| BenchmarkError::Stop("Failed to add supported currency"))?; + pallet_transaction_multi_payment::pallet::AcceptedCurrencyPrice::::insert(fee_asset, Price::from(1)); + + MultiTransactionPayment::set_currency( + RawOrigin::Signed(from.clone()).into(), + fee_asset + )?; let to: AccountId = account("to", 0, SEED); let to_lookup = lookup_of_account(to.clone()); - }: _(RawOrigin::Root, from_lookup, to_lookup, asset_id, BSX) + }: _(RawOrigin::Root, from_lookup, to_lookup, asset_id, amount) verify { - assert_eq!(>::total_balance(asset_id, &to), BSX); + assert_eq!(>::total_balance(asset_id, &to), amount); + + //NOTE: make sure from was killed + assert!(!orml_tokens::Accounts::::contains_key(from.clone(), asset_id)); + assert_eq!(pallet_asset_registry::ExistentialDepositCounter::::get(), 1); + assert_eq!(frame_system::Pallet::::account(from).sufficients, 0); } + //NOTE: set balance bypass MutationHooks so sufficiency check is never triggered. set_balance { let who: AccountId = account("who", 0, SEED); let who_lookup = lookup_of_account(who.clone()); diff --git a/runtime/hydradx/src/benchmarking/xyk.rs b/runtime/hydradx/src/benchmarking/xyk.rs new file mode 100644 index 000000000..e4b29f928 --- /dev/null +++ b/runtime/hydradx/src/benchmarking/xyk.rs @@ -0,0 +1,282 @@ +use crate::{AccountId, AssetId, Balance, Currencies, MultiTransactionPayment, Price, Runtime, RuntimeOrigin, XYK}; + +use super::*; + +use frame_benchmarking::{account, BenchmarkError}; +use frame_system::RawOrigin; +use orml_benchmarking::runtime_benchmarks; +use orml_traits::{MultiCurrency, MultiCurrencyExtended}; +use sp_std::prelude::*; + +use hydradx_traits::router::{PoolType, TradeExecution}; + +const SEED: u32 = 1; + +const INITIAL_BALANCE: Balance = 1_000_000_000_000_000; + +fn funded_account(name: &'static str, index: u32, assets: &[AssetId]) -> T::AccountId { + let caller: T::AccountId = account(name, index, SEED); + //Necessary for ED for insufficient assets. + T::Currency::update_balance(0, &caller, INITIAL_BALANCE as i128).unwrap(); + + for a in assets { + T::Currency::update_balance(*a, &caller, INITIAL_BALANCE as i128).unwrap(); + } + + caller +} + +fn init_fee_asset(fee_asset: AssetId) -> Result<(), BenchmarkError> { + MultiTransactionPayment::add_currency(RawOrigin::Root.into(), fee_asset, Price::from(1)) + .map_err(|_| BenchmarkError::Stop("Failed to add fee asset as supported currency"))?; + + pallet_transaction_multi_payment::pallet::AcceptedCurrencyPrice::::insert(fee_asset, Price::from(1)); + + Ok(()) +} + +runtime_benchmarks! { + { Runtime, pallet_xyk } + + create_pool { + let asset_a = register_external_asset(b"TKNA".to_vec()).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?; + let asset_b = register_external_asset(b"TKNB".to_vec()).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?; + let fee_asset = register_asset(b"FEE".to_vec(), 1u128).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?; + + let caller = funded_account::("caller", 0, &[asset_a, asset_b, fee_asset]); + + init_fee_asset(fee_asset)?; + MultiTransactionPayment::set_currency(RawOrigin::Signed(caller.clone()).into(), fee_asset)?; + + let amount_a : Balance = INITIAL_BALANCE; + let amount_b : Balance = INITIAL_BALANCE; + + assert_eq!(frame_system::Pallet::::account(caller.clone()).sufficients, 2); + }: _(RawOrigin::Signed(caller.clone()), asset_a, amount_a, asset_b, amount_b) + verify { + assert_eq!(Currencies::free_balance(asset_a, &caller), 0); + assert_eq!(Currencies::free_balance(asset_b, &caller), 0); + + assert!(!orml_tokens::Accounts::::contains_key(caller.clone(), asset_a)); + assert!(!orml_tokens::Accounts::::contains_key(caller.clone(), asset_b)); + + //NOTE: xyk shares are insufficinet so that's why not 0. + assert_eq!(frame_system::Pallet::::account(caller).sufficients, 1); + } + + add_liquidity { + let asset_a = register_external_asset(b"TKNA".to_vec()).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?; + let asset_b = register_external_asset(b"TKNB".to_vec()).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?; + let fee_asset = register_asset(b"FEE".to_vec(), 1u128).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?; + + let caller = funded_account::("caller", 0, &[asset_a, asset_b, fee_asset]); + let maker = funded_account::("maker", 1, &[asset_a, asset_b, fee_asset]); + + init_fee_asset(fee_asset)?; + MultiTransactionPayment::set_currency(RawOrigin::Signed(maker.clone()).into(), fee_asset)?; + MultiTransactionPayment::set_currency(RawOrigin::Signed(caller.clone()).into(), fee_asset)?; + + let amount_a : Balance = INITIAL_BALANCE; + let amount_b : Balance = INITIAL_BALANCE; + + let amount : Balance = INITIAL_BALANCE/2; + let max_limit : Balance = INITIAL_BALANCE; + + + XYK::create_pool(RawOrigin::Signed(maker.clone()).into(), asset_a, INITIAL_BALANCE - 10, asset_b, INITIAL_BALANCE - 10)?; + + >::transfer(asset_a, &caller, &maker, INITIAL_BALANCE - amount)?; + + assert_eq!(frame_system::Pallet::::account(caller.clone()).sufficients, 2); + }: _(RawOrigin::Signed(caller.clone()), asset_a, asset_b, amount, max_limit) + verify { + assert_eq!(Currencies::free_balance(asset_a, &caller), 0); + assert_eq!(Currencies::free_balance(asset_b, &caller), 499_999_999_999_999_u128);// Due to rounding in favor of pool + + //NOTE: xyk shares are insufficinet. + assert_eq!(frame_system::Pallet::::account(caller).sufficients, 2); + } + + remove_liquidity { + let asset_a = register_external_asset(b"TKNA".to_vec()).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?; + let asset_b = register_external_asset(b"TKNB".to_vec()).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?; + let fee_asset = register_asset(b"FEE".to_vec(), 1u128).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?; + + let maker = funded_account::("maker", 0, &[asset_a, asset_b, fee_asset]); + + + init_fee_asset(fee_asset)?; + MultiTransactionPayment::set_currency(RawOrigin::Signed(maker.clone()).into(), fee_asset)?; + + XYK::create_pool(RawOrigin::Signed(maker.clone()).into(), asset_a, INITIAL_BALANCE, asset_b, INITIAL_BALANCE)?; + + //Only for XYK shares + assert_eq!(frame_system::Pallet::::account(maker.clone()).sufficients, 1); + }: _(RawOrigin::Signed(maker.clone()), asset_a, asset_b, INITIAL_BALANCE) + verify { + assert_eq!(Currencies::free_balance(asset_a, &maker), INITIAL_BALANCE); + assert_eq!(Currencies::free_balance(asset_b, &maker), INITIAL_BALANCE); + + assert_eq!(frame_system::Pallet::::account(maker).sufficients, 2); + } + + sell { + let asset_a = register_external_asset(b"TKNA".to_vec()).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?; + let asset_b = register_external_asset(b"TKNB".to_vec()).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?; + let fee_asset = register_asset(b"FEE".to_vec(), 1u128).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?; + + let maker = funded_account::("maker", 0, &[asset_a, asset_b, fee_asset]); + let caller = funded_account::("caller", 1, &[asset_a, fee_asset]); + + + init_fee_asset(fee_asset)?; + MultiTransactionPayment::set_currency(RawOrigin::Signed(maker.clone()).into(), fee_asset)?; + MultiTransactionPayment::set_currency(RawOrigin::Signed(caller.clone()).into(), fee_asset)?; + + let discount = false; + let amount: Balance = 250_000_000_000_000; + let min_bought: Balance = 1; + + XYK::create_pool(RawOrigin::Signed(maker.clone()).into(), asset_a, INITIAL_BALANCE, asset_b, INITIAL_BALANCE)?; + + >::transfer(asset_a, &caller, &maker, INITIAL_BALANCE - amount)?; + + assert_eq!(frame_system::Pallet::::account(caller.clone()).sufficients, 1); + }: _(RawOrigin::Signed(caller.clone()), asset_a, asset_b, amount, min_bought, discount) + verify{ + assert_eq!(Currencies::free_balance(asset_a, &caller), 0); + assert_eq!(Currencies::free_balance(asset_b, &caller), 199400000000000); + + //NOTE: `asset_a`'s ED was released `asset_b`'s ED was collected. + assert_eq!(frame_system::Pallet::::account(caller).sufficients, 1); + } + + buy { + let asset_a = register_external_asset(b"TKNA".to_vec()).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?; + let asset_b = register_external_asset(b"TKNB".to_vec()).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?; + let fee_asset = register_asset(b"FEE".to_vec(), 1u128).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?; + + let maker = funded_account::("maker", 0, &[asset_a, asset_b, fee_asset]); + let caller = funded_account::("caller", 1, &[asset_a, fee_asset]); + + + init_fee_asset(fee_asset)?; + MultiTransactionPayment::set_currency(RawOrigin::Signed(maker.clone()).into(), fee_asset)?; + MultiTransactionPayment::set_currency(RawOrigin::Signed(caller.clone()).into(), fee_asset)?; + + let discount = false; + let amount: Balance = 200_000_000_000_000; + let max_sold: Balance = INITIAL_BALANCE; + + XYK::create_pool(RawOrigin::Signed(maker.clone()).into(), asset_a, INITIAL_BALANCE, asset_b, INITIAL_BALANCE)?; + + >::transfer(asset_a, &caller, &maker, 749_249_999_999_999_u128)?; + + assert_eq!(frame_system::Pallet::::account(caller.clone()).sufficients, 1); + }: _(RawOrigin::Signed(caller.clone()), asset_b, asset_a, amount, max_sold, discount) + verify{ + assert_eq!(Currencies::free_balance(asset_a, &caller), 0); + assert_eq!(Currencies::free_balance(asset_b, &caller), amount); + + assert_eq!(frame_system::Pallet::::account(caller).sufficients, 1); + } + + router_execution_sell { + let c in 1..2; // if c == 1, calculate_sell is executed + let e in 0..1; // if e == 1, execute_sell is executed + + let asset_a = register_external_asset(b"TKNA".to_vec()).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?; + let asset_b = register_external_asset(b"TKNB".to_vec()).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?; + let fee_asset = register_asset(b"FEE".to_vec(), 1u128).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?; + + let maker = funded_account::("maker", 0, &[asset_a, asset_b, fee_asset]); + let caller = funded_account::("caller", 1, &[asset_a, fee_asset]); + + + init_fee_asset(fee_asset)?; + MultiTransactionPayment::set_currency(RawOrigin::Signed(maker.clone()).into(), fee_asset)?; + MultiTransactionPayment::set_currency(RawOrigin::Signed(caller.clone()).into(), fee_asset)?; + + let discount = false; + let amount: Balance = 250_000_000_000_000; + let min_bought: Balance = 1; + + XYK::create_pool(RawOrigin::Signed(maker.clone()).into(), asset_a, INITIAL_BALANCE, asset_b, INITIAL_BALANCE)?; + + >::transfer(asset_a, &caller, &maker, INITIAL_BALANCE - amount)?; + assert_eq!(frame_system::Pallet::::account(caller.clone()).sufficients, 1); + }: { + for _ in 1..c { + assert!(>::calculate_sell(PoolType::XYK, asset_a, asset_b, amount).is_ok()); + } + if e != 0 { + assert!(>::execute_sell(RawOrigin::Signed(caller.clone()).into(), PoolType::XYK, asset_a, asset_b, amount, min_bought).is_ok()); + } + } + verify{ + if e != 0 { + assert_eq!(Currencies::free_balance(asset_a, &caller), 0); + assert_eq!(Currencies::free_balance(asset_b, &caller), 199400000000000); + + assert_eq!(frame_system::Pallet::::account(caller).sufficients, 1); + } + } + + router_execution_buy { + let c in 1..3; // number of times calculate_buy is executed + let e in 0..1; // if e == 1, execute_buy is executed + + let asset_a = register_external_asset(b"TKNA".to_vec()).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?; + let asset_b = register_external_asset(b"TKNB".to_vec()).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?; + let fee_asset = register_asset(b"FEE".to_vec(), 1u128).map_err(|_| BenchmarkError::Stop("Failed to register asset"))?; + + let maker = funded_account::("maker", 0, &[asset_a, asset_b, fee_asset]); + let caller = funded_account::("caller", 1, &[asset_a, fee_asset]); + + + init_fee_asset(fee_asset)?; + MultiTransactionPayment::set_currency(RawOrigin::Signed(maker.clone()).into(), fee_asset)?; + MultiTransactionPayment::set_currency(RawOrigin::Signed(caller.clone()).into(), fee_asset)?; + + let discount = false; + let amount: Balance = 200_000_000_000_000; + let max_sold: Balance = INITIAL_BALANCE; + + XYK::create_pool(RawOrigin::Signed(maker.clone()).into(), asset_a, INITIAL_BALANCE, asset_b, INITIAL_BALANCE)?; + + >::transfer(asset_a, &caller, &maker, 749_249_999_999_999_u128)?; + + assert_eq!(frame_system::Pallet::::account(caller.clone()).sufficients, 1); + }: { + for _ in 1..c { + assert!(>::calculate_buy(PoolType::XYK, asset_a, asset_b, amount).is_ok()); + } + if e != 0 { + assert!(>::execute_buy(RawOrigin::Signed(caller.clone()).into(), PoolType::XYK, asset_a, asset_b, amount, max_sold).is_ok()); + } + } + verify{ + if e != 0 { + assert_eq!(Currencies::free_balance(asset_a, &caller), 0); + assert_eq!(Currencies::free_balance(asset_b, &caller), amount); + + assert_eq!(frame_system::Pallet::::account(caller).sufficients, 1); + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + use orml_benchmarking::impl_benchmark_test_suite; + use sp_runtime::BuildStorage; + + fn new_test_ext() -> sp_io::TestExternalities { + frame_system::GenesisConfig::::default() + .build_storage() + .unwrap() + .into() + } + + impl_benchmark_test_suite!(new_test_ext(),); +} diff --git a/runtime/hydradx/src/evm/precompiles/multicurrency.rs b/runtime/hydradx/src/evm/precompiles/multicurrency.rs index 71b2b82d7..b9eb7d568 100644 --- a/runtime/hydradx/src/evm/precompiles/multicurrency.rs +++ b/runtime/hydradx/src/evm/precompiles/multicurrency.rs @@ -33,7 +33,7 @@ use crate::{ }; use codec::EncodeLike; use frame_support::traits::OriginTrait; -use hydradx_traits::InspectRegistry; +use hydradx_traits::registry::Inspect as InspectRegistry; use num_enum::{IntoPrimitive, TryFromPrimitive}; use orml_traits::{MultiCurrency as MultiCurrencyT, MultiCurrency}; use pallet_evm::{AddressMapping, ExitRevert, Precompile, PrecompileFailure, PrecompileHandle, PrecompileResult}; diff --git a/runtime/hydradx/src/lib.rs b/runtime/hydradx/src/lib.rs index d1bd56142..f06cd9325 100644 --- a/runtime/hydradx/src/lib.rs +++ b/runtime/hydradx/src/lib.rs @@ -107,7 +107,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("hydradx"), impl_name: create_runtime_str!("hydradx"), authoring_version: 1, - spec_version: 209, + spec_version: 210, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 1, @@ -128,6 +128,7 @@ pub fn get_all_module_accounts() -> Vec { TreasuryPalletId::get().into_account_truncating(), VestingPalletId::get().into_account_truncating(), ReferralsPalletId::get().into_account_truncating(), + BondsPalletId::get().into_account_truncating(), ] } @@ -638,7 +639,6 @@ impl_runtime_apis! { list_benchmark!(list, extra, pallet_ema_oracle, EmaOracle); list_benchmark!(list, extra, pallet_staking, Staking); list_benchmark!(list, extra, pallet_lbp, LBP); - list_benchmark!(list, extra, pallet_xyk, XYK); list_benchmark!(list, extra, pallet_referrals, Referrals); list_benchmark!(list, extra, pallet_evm_accounts, EVMAccounts); @@ -656,6 +656,7 @@ impl_runtime_apis! { orml_list_benchmark!(list, extra, pallet_omnipool, benchmarking::omnipool); orml_list_benchmark!(list, extra, pallet_route_executor, benchmarking::route_executor); orml_list_benchmark!(list, extra, pallet_dca, benchmarking::dca); + orml_list_benchmark!(list, extra, pallet_xyk, benchmarking::xyk); let storage_info = AllPalletsWithSystem::storage_info(); @@ -719,7 +720,6 @@ impl_runtime_apis! { add_benchmark!(params, batches, pallet_bonds, Bonds); add_benchmark!(params, batches, pallet_staking, Staking); add_benchmark!(params, batches, pallet_lbp, LBP); - add_benchmark!(params, batches, pallet_xyk, XYK); add_benchmark!(params, batches, pallet_stableswap, Stableswap); add_benchmark!(params, batches, pallet_referrals, Referrals); add_benchmark!(params, batches, pallet_evm_accounts, EVMAccounts); @@ -738,6 +738,7 @@ impl_runtime_apis! { orml_add_benchmark!(params, batches, pallet_omnipool, benchmarking::omnipool); orml_add_benchmark!(params, batches, pallet_route_executor, benchmarking::route_executor); orml_add_benchmark!(params, batches, pallet_dca, benchmarking::dca); + orml_add_benchmark!(params, batches, pallet_xyk, benchmarking::xyk); if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) } Ok(batches) diff --git a/runtime/hydradx/src/migrations.rs b/runtime/hydradx/src/migrations.rs index 44ef9717d..653eb51e0 100644 --- a/runtime/hydradx/src/migrations.rs +++ b/runtime/hydradx/src/migrations.rs @@ -9,6 +9,10 @@ pub struct OnRuntimeUpgradeMigration; impl OnRuntimeUpgrade for OnRuntimeUpgradeMigration { #[cfg(feature = "try-runtime")] fn pre_upgrade() -> Result, sp_runtime::DispatchError> { + log::info!("PreMigrate Asset Registry Pallet start"); + pallet_asset_registry::migration::v2::pre_migrate::(); + log::info!("PreMigrate Asset Registry Pallet end"); + log::info!("PreMigrate Collator Selection Pallet start"); let number_of_invulnerables = pallet_collator_selection::migration::v1::MigrateToV1::::pre_upgrade()?; log::info!("PreMigrate Collator Selection Pallet end"); @@ -18,6 +22,10 @@ impl OnRuntimeUpgrade for OnRuntimeUpgradeMigration { fn on_runtime_upgrade() -> Weight { let mut weight: Weight = Weight::zero(); + log::info!("Migrate Asset Registry Pallet"); + weight = weight.saturating_add(pallet_asset_registry::migration::v2::migrate::()); + log::info!("Migrate Asset Registry Pallet end"); + log::info!("Migrate Collator Selection Pallet to v1 start"); weight = weight .saturating_add(pallet_collator_selection::migration::v1::MigrateToV1::::on_runtime_upgrade()); @@ -38,6 +46,10 @@ impl OnRuntimeUpgrade for OnRuntimeUpgradeMigration { #[cfg(feature = "try-runtime")] fn post_upgrade(state: Vec) -> Result<(), sp_runtime::DispatchError> { + log::info!("PostMigrate Asset Registry Pallet start"); + pallet_asset_registry::migration::v2::post_migrate::(); + log::info!("PostMigrate Asset Registry Pallet end"); + log::info!("PostMigrate Collator Selection Pallet start"); let migration_result = pallet_collator_selection::migration::v1::MigrateToV1::::post_upgrade(state); log::info!("PostMigrate Collator Selection Pallet end"); diff --git a/runtime/hydradx/src/weights/balances.rs b/runtime/hydradx/src/weights/balances.rs index 6e7229980..82d13eb48 100644 --- a/runtime/hydradx/src/weights/balances.rs +++ b/runtime/hydradx/src/weights/balances.rs @@ -18,53 +18,46 @@ //! Autogenerated weights for `pallet_balances` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-12-12, STEPS: `5`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-02-15, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `bench-bot`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` -//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 // Executed Command: // target/release/hydradx // benchmark // pallet -// --pallet=pallet-balances +// --chain=dev +// --steps=10 +// --repeat=30 // --wasm-execution=compiled // --heap-pages=4096 -// --chain=dev +// --template=.maintain/pallet-weight-template-no-back.hbs +// --pallet=pallet_balances +// --output=./weights/balances.rs // --extrinsic=* -// --steps=5 -// --repeat=20 -// --output -// ./weights-1.1.0/balances.rs -// --template -// .maintain/pallet-weight-template-no-back.hbs +#![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] -#![allow(clippy::unnecessary_cast)] +#![allow(missing_docs)] -use frame_support::{ - traits::Get, - weights::{constants::RocksDbWeight, Weight}, -}; -use sp_std::marker::PhantomData; +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; -use pallet_balances::weights::WeightInfo; - -/// Weights for pallet_balances using the hydraDX node and recommended hardware. +/// Weight functions for `pallet_balances`. pub struct HydraWeight(PhantomData); - -impl WeightInfo for HydraWeight { +impl pallet_balances::WeightInfo for HydraWeight { /// Storage: `System::Account` (r:2 w:2) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) fn transfer_allow_death() -> Weight { // Proof Size summary in bytes: // Measured: `103` // Estimated: `6196` - // Minimum execution time: 99_306_000 picoseconds. - Weight::from_parts(99_852_000, 6196) - .saturating_add(T::DbWeight::get().reads(2_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) + // Minimum execution time: 95_388_000 picoseconds. + Weight::from_parts(96_245_000, 6196) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(2)) } /// Storage: `System::Account` (r:1 w:1) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) @@ -72,10 +65,10 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `3593` - // Minimum execution time: 57_733_000 picoseconds. - Weight::from_parts(58_369_000, 3593) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 56_336_000 picoseconds. + Weight::from_parts(56_960_000, 3593) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `System::Account` (r:1 w:1) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) @@ -83,10 +76,10 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `174` // Estimated: `3593` - // Minimum execution time: 23_571_000 picoseconds. - Weight::from_parts(24_090_000, 3593) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 23_156_000 picoseconds. + Weight::from_parts(23_520_000, 3593) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `System::Account` (r:1 w:1) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) @@ -94,10 +87,10 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `174` // Estimated: `3593` - // Minimum execution time: 33_669_000 picoseconds. - Weight::from_parts(34_145_000, 3593) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 32_737_000 picoseconds. + Weight::from_parts(33_142_000, 3593) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `System::Account` (r:3 w:3) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) @@ -105,10 +98,10 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `206` // Estimated: `8799` - // Minimum execution time: 99_790_000 picoseconds. - Weight::from_parts(100_634_000, 8799) - .saturating_add(T::DbWeight::get().reads(3_u64)) - .saturating_add(T::DbWeight::get().writes(3_u64)) + // Minimum execution time: 97_418_000 picoseconds. + Weight::from_parts(98_398_000, 8799) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(3)) } /// Storage: `System::Account` (r:1 w:1) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) @@ -116,10 +109,10 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `3593` - // Minimum execution time: 71_626_000 picoseconds. - Weight::from_parts(72_046_000, 3593) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 70_382_000 picoseconds. + Weight::from_parts(71_293_000, 3593) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `System::Account` (r:1 w:1) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) @@ -127,24 +120,24 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `174` // Estimated: `3593` - // Minimum execution time: 27_226_000 picoseconds. - Weight::from_parts(27_500_000, 3593) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 26_552_000 picoseconds. + Weight::from_parts(26_832_000, 3593) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `System::Account` (r:1000 w:1000) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) /// The range of component `u` is `[1, 1000]`. - fn upgrade_accounts(u: u32) -> Weight { + fn upgrade_accounts(u: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `0 + u * (136 ±0)` // Estimated: `990 + u * (2603 ±0)` - // Minimum execution time: 25_150_000 picoseconds. - Weight::from_parts(25_357_000, 990) - // Standard Error: 34_523 - .saturating_add(Weight::from_parts(19_216_979, 0).saturating_mul(u.into())) + // Minimum execution time: 24_327_000 picoseconds. + Weight::from_parts(24_625_000, 990) + // Standard Error: 18_294 + .saturating_add(Weight::from_parts(18_506_542, 0).saturating_mul(u.into())) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(u.into()))) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(u.into()))) .saturating_add(Weight::from_parts(0, 2603).saturating_mul(u.into())) } -} +} \ No newline at end of file diff --git a/runtime/hydradx/src/weights/bonds.rs b/runtime/hydradx/src/weights/bonds.rs index 045ba325d..73b8867e0 100644 --- a/runtime/hydradx/src/weights/bonds.rs +++ b/runtime/hydradx/src/weights/bonds.rs @@ -18,73 +18,74 @@ //! Autogenerated weights for `pallet_bonds` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-12-12, STEPS: `5`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-02-15, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `bench-bot`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` -//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 // Executed Command: // target/release/hydradx // benchmark // pallet -// --pallet=pallet-bonds +// --chain=dev +// --steps=10 +// --repeat=30 // --wasm-execution=compiled // --heap-pages=4096 -// --chain=dev +// --template=.maintain/pallet-weight-template-no-back.hbs +// --pallet=pallet_bonds +// --output=./weights/bonds.rs // --extrinsic=* -// --steps=5 -// --repeat=20 -// --output -// ./weights-1.1.0/bonds.rs -// --template -// .maintain/pallet-weight-template-no-back.hbs +#![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] -#![allow(clippy::unnecessary_cast)] +#![allow(missing_docs)] -use frame_support::{ - traits::Get, - weights::{constants::RocksDbWeight, Weight}, -}; -use sp_std::marker::PhantomData; +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; -use pallet_bonds::weights::WeightInfo; - -/// Weights for pallet_bonds using the hydraDX node and recommended hardware. +/// Weight functions for `pallet_bonds`. pub struct HydraWeight(PhantomData); - -impl WeightInfo for HydraWeight { +impl pallet_bonds::WeightInfo for HydraWeight { /// Storage: `AssetRegistry::Assets` (r:1 w:1) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// Storage: `Bonds::BondIds` (r:1 w:1) /// Proof: `Bonds::BondIds` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) /// Storage: `Timestamp::Now` (r:1 w:0) /// Proof: `Timestamp::Now` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::NextAssetId` (r:1 w:1) /// Proof: `AssetRegistry::NextAssetId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::AssetIds` (r:1 w:1) + /// Proof: `AssetRegistry::AssetIds` (`max_values`: None, `max_size`: Some(53), added: 2528, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:3 w:3) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::BannedAssets` (r:1 w:0) + /// Proof: `AssetRegistry::BannedAssets` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`) /// Storage: `Tokens::Accounts` (r:1 w:1) /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) - /// Storage: `Tokens::TotalIssuance` (r:1 w:1) - /// Proof: `Tokens::TotalIssuance` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) /// Storage: `MultiTransactionPayment::AccountCurrencyMap` (r:1 w:0) /// Proof: `MultiTransactionPayment::AccountCurrencyMap` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`) + /// Storage: `Balances::Locks` (r:1 w:1) + /// Proof: `Balances::Locks` (`max_values`: None, `max_size`: Some(1299), added: 3774, mode: `MaxEncodedLen`) + /// Storage: `Balances::Freezes` (r:1 w:0) + /// Proof: `Balances::Freezes` (`max_values`: None, `max_size`: Some(49), added: 2524, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::ExistentialDepositCounter` (r:1 w:1) + /// Proof: `AssetRegistry::ExistentialDepositCounter` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) + /// Storage: `Tokens::TotalIssuance` (r:1 w:1) + /// Proof: `Tokens::TotalIssuance` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) /// Storage: `MultiTransactionPayment::AcceptedCurrencies` (r:1 w:0) /// Proof: `MultiTransactionPayment::AcceptedCurrencies` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) /// Storage: `Bonds::Bonds` (r:0 w:1) /// Proof: `Bonds::Bonds` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::AssetIds` (r:0 w:1) - /// Proof: `AssetRegistry::AssetIds` (`max_values`: None, `max_size`: Some(53), added: 2528, mode: `MaxEncodedLen`) fn issue() -> Weight { // Proof Size summary in bytes: - // Measured: `1240` + // Measured: `1327` // Estimated: `8799` - // Minimum execution time: 208_163_000 picoseconds. - Weight::from_parts(209_241_000, 8799) - .saturating_add(T::DbWeight::get().reads(11_u64)) - .saturating_add(T::DbWeight::get().writes(10_u64)) + // Minimum execution time: 295_545_000 picoseconds. + Weight::from_parts(297_850_000, 8799) + .saturating_add(T::DbWeight::get().reads(16)) + .saturating_add(T::DbWeight::get().writes(12)) } /// Storage: `Bonds::Bonds` (r:1 w:0) /// Proof: `Bonds::Bonds` (`max_values`: None, `max_size`: Some(32), added: 2507, mode: `MaxEncodedLen`) @@ -93,20 +94,26 @@ impl WeightInfo for HydraWeight { /// Storage: `Tokens::Accounts` (r:1 w:1) /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::Assets` (r:1 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// Storage: `Tokens::TotalIssuance` (r:1 w:1) /// Proof: `Tokens::TotalIssuance` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) - /// Storage: `System::Account` (r:2 w:2) + /// Storage: `System::Account` (r:3 w:3) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) - /// Storage: `MultiTransactionPayment::AccountCurrencyMap` (r:0 w:1) + /// Storage: `MultiTransactionPayment::AccountCurrencyMap` (r:1 w:0) /// Proof: `MultiTransactionPayment::AccountCurrencyMap` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`) + /// Storage: `Balances::Locks` (r:1 w:1) + /// Proof: `Balances::Locks` (`max_values`: None, `max_size`: Some(1299), added: 3774, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::ExistentialDepositCounter` (r:1 w:1) + /// Proof: `AssetRegistry::ExistentialDepositCounter` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) + /// Storage: `Balances::Freezes` (r:1 w:0) + /// Proof: `Balances::Freezes` (`max_values`: None, `max_size`: Some(49), added: 2524, mode: `MaxEncodedLen`) fn redeem() -> Weight { // Proof Size summary in bytes: - // Measured: `1415` - // Estimated: `6196` - // Minimum execution time: 146_646_000 picoseconds. - Weight::from_parts(147_343_000, 6196) - .saturating_add(T::DbWeight::get().reads(7_u64)) - .saturating_add(T::DbWeight::get().writes(5_u64)) + // Measured: `1744` + // Estimated: `8799` + // Minimum execution time: 215_448_000 picoseconds. + Weight::from_parts(216_795_000, 8799) + .saturating_add(T::DbWeight::get().reads(12)) + .saturating_add(T::DbWeight::get().writes(7)) } -} +} \ No newline at end of file diff --git a/runtime/hydradx/src/weights/circuit_breaker.rs b/runtime/hydradx/src/weights/circuit_breaker.rs index c3929949d..bb2901ac9 100644 --- a/runtime/hydradx/src/weights/circuit_breaker.rs +++ b/runtime/hydradx/src/weights/circuit_breaker.rs @@ -18,76 +18,69 @@ //! Autogenerated weights for `pallet_circuit_breaker` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-12-12, STEPS: `5`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-02-15, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `bench-bot`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` -//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 // Executed Command: // target/release/hydradx // benchmark // pallet -// --pallet=pallet-circuit-breaker +// --chain=dev +// --steps=10 +// --repeat=30 // --wasm-execution=compiled // --heap-pages=4096 -// --chain=dev +// --template=.maintain/pallet-weight-template-no-back.hbs +// --pallet=pallet_circuit_breaker +// --output=./weights/circuit_breaker.rs // --extrinsic=* -// --steps=5 -// --repeat=20 -// --output -// ./weights-1.1.0/circuit_breaker.rs -// --template -// .maintain/pallet-weight-template-no-back.hbs +#![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] -#![allow(clippy::unnecessary_cast)] +#![allow(missing_docs)] -use frame_support::{ - traits::Get, - weights::{constants::RocksDbWeight, Weight}, -}; -use sp_std::marker::PhantomData; +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; -use pallet_circuit_breaker::weights::WeightInfo; - -/// Weights for pallet_circuit_breaker using the hydraDX node and recommended hardware. +/// Weight functions for `pallet_circuit_breaker`. pub struct HydraWeight(PhantomData); - -impl WeightInfo for HydraWeight { +impl pallet_circuit_breaker::WeightInfo for HydraWeight { /// The range of component `n` is `[0, 400]`. /// The range of component `m` is `[0, 400]`. - fn on_finalize(n: u32, m: u32) -> Weight { + fn on_finalize(n: u32, m: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `105 + m * (113 ±0) + n * (56 ±0)` + // Measured: `81 + m * (113 ±0) + n * (56 ±0)` // Estimated: `0` - // Minimum execution time: 336_709_000 picoseconds. - Weight::from_parts(338_100_000, 0) - // Standard Error: 34_770 - .saturating_add(Weight::from_parts(304_235, 0).saturating_mul(n.into())) - // Standard Error: 34_770 - .saturating_add(Weight::from_parts(1_161_474, 0).saturating_mul(m.into())) + // Minimum execution time: 337_114_000 picoseconds. + Weight::from_parts(338_524_000, 0) + // Standard Error: 18_748 + .saturating_add(Weight::from_parts(304_800, 0).saturating_mul(n.into())) + // Standard Error: 18_748 + .saturating_add(Weight::from_parts(1_167_299, 0).saturating_mul(m.into())) } fn on_finalize_single_liquidity_limit_entry() -> Weight { // Proof Size summary in bytes: // Measured: `208` // Estimated: `0` - // Minimum execution time: 9_370_000 picoseconds. - Weight::from_parts(9_492_000, 0) + // Minimum execution time: 9_057_000 picoseconds. + Weight::from_parts(9_236_000, 0) } fn on_finalize_single_trade_limit_entry() -> Weight { // Proof Size summary in bytes: // Measured: `208` // Estimated: `0` - // Minimum execution time: 9_297_000 picoseconds. - Weight::from_parts(9_518_000, 0) + // Minimum execution time: 9_038_000 picoseconds. + Weight::from_parts(9_276_000, 0) } fn on_finalize_empty() -> Weight { // Proof Size summary in bytes: // Measured: `208` // Estimated: `0` - // Minimum execution time: 9_320_000 picoseconds. - Weight::from_parts(9_566_000, 0) + // Minimum execution time: 8_991_000 picoseconds. + Weight::from_parts(9_236_000, 0) } /// Storage: `CircuitBreaker::TradeVolumeLimitPerAsset` (r:0 w:1) /// Proof: `CircuitBreaker::TradeVolumeLimitPerAsset` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) @@ -95,8 +88,9 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 12_401_000 picoseconds. - Weight::from_parts(12_601_000, 0).saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 12_675_000 picoseconds. + Weight::from_parts(12_914_000, 0) + .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `CircuitBreaker::LiquidityAddLimitPerAsset` (r:0 w:1) /// Proof: `CircuitBreaker::LiquidityAddLimitPerAsset` (`max_values`: None, `max_size`: Some(29), added: 2504, mode: `MaxEncodedLen`) @@ -104,8 +98,9 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 12_366_000 picoseconds. - Weight::from_parts(12_660_000, 0).saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 12_902_000 picoseconds. + Weight::from_parts(13_224_000, 0) + .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `CircuitBreaker::LiquidityRemoveLimitPerAsset` (r:0 w:1) /// Proof: `CircuitBreaker::LiquidityRemoveLimitPerAsset` (`max_values`: None, `max_size`: Some(29), added: 2504, mode: `MaxEncodedLen`) @@ -113,8 +108,9 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 12_543_000 picoseconds. - Weight::from_parts(12_729_000, 0).saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 12_583_000 picoseconds. + Weight::from_parts(12_901_000, 0) + .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `CircuitBreaker::LiquidityAddLimitPerAsset` (r:1 w:0) /// Proof: `CircuitBreaker::LiquidityAddLimitPerAsset` (`max_values`: None, `max_size`: Some(29), added: 2504, mode: `MaxEncodedLen`) @@ -128,10 +124,10 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `262` // Estimated: `3517` - // Minimum execution time: 20_930_000 picoseconds. - Weight::from_parts(21_398_000, 3517) - .saturating_add(T::DbWeight::get().reads(4_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) + // Minimum execution time: 20_836_000 picoseconds. + Weight::from_parts(21_079_000, 3517) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().writes(2)) } /// Storage: `CircuitBreaker::LiquidityAddLimitPerAsset` (r:1 w:0) /// Proof: `CircuitBreaker::LiquidityAddLimitPerAsset` (`max_values`: None, `max_size`: Some(29), added: 2504, mode: `MaxEncodedLen`) @@ -145,10 +141,10 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `208` // Estimated: `3517` - // Minimum execution time: 17_808_000 picoseconds. - Weight::from_parts(18_193_000, 3517) - .saturating_add(T::DbWeight::get().reads(4_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) + // Minimum execution time: 17_939_000 picoseconds. + Weight::from_parts(18_095_000, 3517) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().writes(2)) } /// Storage: `CircuitBreaker::AllowedTradeVolumeLimitPerAsset` (r:2 w:2) /// Proof: `CircuitBreaker::AllowedTradeVolumeLimitPerAsset` (`max_values`: None, `max_size`: Some(68), added: 2543, mode: `MaxEncodedLen`) @@ -158,9 +154,9 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `208` // Estimated: `6076` - // Minimum execution time: 18_243_000 picoseconds. - Weight::from_parts(18_729_000, 6076) - .saturating_add(T::DbWeight::get().reads(4_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) + // Minimum execution time: 18_569_000 picoseconds. + Weight::from_parts(18_816_000, 6076) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().writes(2)) } -} +} \ No newline at end of file diff --git a/runtime/hydradx/src/weights/claims.rs b/runtime/hydradx/src/weights/claims.rs index 631a69ff6..e32c1935b 100644 --- a/runtime/hydradx/src/weights/claims.rs +++ b/runtime/hydradx/src/weights/claims.rs @@ -18,42 +18,37 @@ //! Autogenerated weights for `pallet_claims` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-12-12, STEPS: `5`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-02-15, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `bench-bot`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` -//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 // Executed Command: // target/release/hydradx // benchmark // pallet -// --pallet=pallet-claims +// --chain=dev +// --steps=10 +// --repeat=30 // --wasm-execution=compiled // --heap-pages=4096 -// --chain=dev +// --template=.maintain/pallet-weight-template-no-back.hbs +// --pallet=pallet_claims +// --output=./weights/claims.rs // --extrinsic=* -// --steps=5 -// --repeat=20 -// --output -// ./weights-1.1.0/claims.rs -// --template -// .maintain/pallet-weight-template-no-back.hbs +#![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] -#![allow(clippy::unnecessary_cast)] +#![allow(missing_docs)] -use frame_support::{ - traits::Get, - weights::{constants::RocksDbWeight, Weight}, -}; -use sp_std::marker::PhantomData; +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; use pallet_claims::weights::WeightInfo; -/// Weights for pallet_claims using the hydraDX node and recommended hardware. +/// Weight functions for `pallet_claims`. pub struct HydraWeight(PhantomData); - impl WeightInfo for HydraWeight { /// Storage: `Claims::Claims` (r:1 w:1) /// Proof: `Claims::Claims` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`) @@ -63,9 +58,9 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `382` // Estimated: `3593` - // Minimum execution time: 82_736_000 picoseconds. - Weight::from_parts(83_275_000, 3593) - .saturating_add(T::DbWeight::get().reads(2_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) + // Minimum execution time: 82_475_000 picoseconds. + Weight::from_parts(82_992_000, 3593) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(2)) } } diff --git a/runtime/hydradx/src/weights/collator_selection.rs b/runtime/hydradx/src/weights/collator_selection.rs index e1f72a306..efb4407a0 100644 --- a/runtime/hydradx/src/weights/collator_selection.rs +++ b/runtime/hydradx/src/weights/collator_selection.rs @@ -18,7 +18,7 @@ //! Autogenerated weights for `pallet_collator_selection` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-12-15, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-02-15, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `bench-bot`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 @@ -33,8 +33,8 @@ // --wasm-execution=compiled // --heap-pages=4096 // --template=.maintain/pallet-weight-template-no-back.hbs -// --pallet=pallet-collator-selection -// --output=weights-1.1.0/collator-selection.rs +// --pallet=pallet_collator_selection +// --output=./weights/collator_selection.rs // --extrinsic=* #![cfg_attr(rustfmt, rustfmt_skip)] @@ -42,17 +42,12 @@ #![allow(unused_imports)] #![allow(missing_docs)] -use frame_support::{ - traits::Get, - weights::{constants::RocksDbWeight, Weight}, -}; -use sp_std::marker::PhantomData; - -use pallet_collator_selection::weights::WeightInfo; +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; +/// Weight functions for `pallet_collator_selection`. pub struct HydraWeight(PhantomData); - -impl WeightInfo for HydraWeight { +impl pallet_collator_selection::WeightInfo for HydraWeight { /// Storage: `Session::NextKeys` (r:50 w:0) /// Proof: `Session::NextKeys` (`max_values`: None, `max_size`: None, mode: `Measured`) /// Storage: `CollatorSelection::Invulnerables` (r:0 w:1) @@ -62,10 +57,10 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `205 + b * (79 ±0)` // Estimated: `1194 + b * (2554 ±0)` - // Minimum execution time: 20_455_000 picoseconds. - Weight::from_parts(19_594_151, 1194) - // Standard Error: 8_370 - .saturating_add(Weight::from_parts(3_470_262, 0).saturating_mul(b.into())) + // Minimum execution time: 20_628_000 picoseconds. + Weight::from_parts(19_568_734, 1194) + // Standard Error: 7_340 + .saturating_add(Weight::from_parts(3_478_925, 0).saturating_mul(b.into())) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(b.into()))) .saturating_add(T::DbWeight::get().writes(1)) .saturating_add(Weight::from_parts(0, 2554).saturating_mul(b.into())) @@ -75,39 +70,39 @@ impl WeightInfo for HydraWeight { /// Storage: `CollatorSelection::Invulnerables` (r:1 w:1) /// Proof: `CollatorSelection::Invulnerables` (`max_values`: Some(1), `max_size`: Some(1601), added: 2096, mode: `MaxEncodedLen`) /// Storage: `CollatorSelection::Candidates` (r:1 w:1) - /// Proof: `CollatorSelection::Candidates` (`max_values`: Some(1), `max_size`: Some(193), added: 688, mode: `MaxEncodedLen`) + /// Proof: `CollatorSelection::Candidates` (`max_values`: Some(1), `max_size`: Some(2401), added: 2896, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:1 w:1) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) /// The range of component `b` is `[1, 49]`. - /// The range of component `c` is `[1, 3]`. + /// The range of component `c` is `[1, 49]`. fn add_invulnerable(b: u32, c: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `835 + b * (44 ±0) + c * (48 ±0)` - // Estimated: `4283 + b * (45 ±0) + c * (56 ±2)` - // Minimum execution time: 58_595_000 picoseconds. - Weight::from_parts(58_147_234, 4283) - // Standard Error: 2_112 - .saturating_add(Weight::from_parts(110_403, 0).saturating_mul(b.into())) - // Standard Error: 41_169 - .saturating_add(Weight::from_parts(341_824, 0).saturating_mul(c.into())) + // Measured: `1444 + b * (32 ±0) + c * (48 ±0)` + // Estimated: `4909 + b * (32 ±0) + c * (48 ±0)` + // Minimum execution time: 62_617_000 picoseconds. + Weight::from_parts(62_633_538, 4909) + // Standard Error: 1_299 + .saturating_add(Weight::from_parts(19_587, 0).saturating_mul(b.into())) + // Standard Error: 1_299 + .saturating_add(Weight::from_parts(43_332, 0).saturating_mul(c.into())) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(3)) - .saturating_add(Weight::from_parts(0, 45).saturating_mul(b.into())) - .saturating_add(Weight::from_parts(0, 56).saturating_mul(c.into())) + .saturating_add(Weight::from_parts(0, 32).saturating_mul(b.into())) + .saturating_add(Weight::from_parts(0, 48).saturating_mul(c.into())) } /// Storage: `CollatorSelection::Candidates` (r:1 w:0) - /// Proof: `CollatorSelection::Candidates` (`max_values`: Some(1), `max_size`: Some(193), added: 688, mode: `MaxEncodedLen`) + /// Proof: `CollatorSelection::Candidates` (`max_values`: Some(1), `max_size`: Some(2401), added: 2896, mode: `MaxEncodedLen`) /// Storage: `CollatorSelection::Invulnerables` (r:1 w:1) /// Proof: `CollatorSelection::Invulnerables` (`max_values`: Some(1), `max_size`: Some(1601), added: 2096, mode: `MaxEncodedLen`) /// The range of component `b` is `[5, 50]`. fn remove_invulnerable(b: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `285 + b * (32 ±0)` - // Estimated: `3086` - // Minimum execution time: 22_755_000 picoseconds. - Weight::from_parts(23_093_354, 3086) - // Standard Error: 1_094 - .saturating_add(Weight::from_parts(46_083, 0).saturating_mul(b.into())) + // Estimated: `3886` + // Minimum execution time: 22_662_000 picoseconds. + Weight::from_parts(23_030_075, 3886) + // Standard Error: 939 + .saturating_add(Weight::from_parts(41_972, 0).saturating_mul(b.into())) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -117,8 +112,8 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 11_217_000 picoseconds. - Weight::from_parts(11_385_000, 0) + // Minimum execution time: 11_095_000 picoseconds. + Weight::from_parts(11_241_000, 0) .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `CollatorSelection::CandidacyBond` (r:0 w:1) @@ -127,12 +122,12 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 11_244_000 picoseconds. - Weight::from_parts(11_602_000, 0) + // Minimum execution time: 11_004_000 picoseconds. + Weight::from_parts(11_197_000, 0) .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `CollatorSelection::Candidates` (r:1 w:1) - /// Proof: `CollatorSelection::Candidates` (`max_values`: Some(1), `max_size`: Some(193), added: 688, mode: `MaxEncodedLen`) + /// Proof: `CollatorSelection::Candidates` (`max_values`: Some(1), `max_size`: Some(2401), added: 2896, mode: `MaxEncodedLen`) /// Storage: `CollatorSelection::DesiredCandidates` (r:1 w:0) /// Proof: `CollatorSelection::DesiredCandidates` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) /// Storage: `CollatorSelection::Invulnerables` (r:1 w:0) @@ -143,34 +138,34 @@ impl WeightInfo for HydraWeight { /// Proof: `CollatorSelection::CandidacyBond` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) /// Storage: `CollatorSelection::LastAuthoredBlock` (r:0 w:1) /// Proof: `CollatorSelection::LastAuthoredBlock` (`max_values`: None, `max_size`: Some(44), added: 2519, mode: `MaxEncodedLen`) - /// The range of component `c` is `[1, 3]`. + /// The range of component `c` is `[1, 49]`. fn register_as_candidate(c: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `700 + c * (82 ±0)` - // Estimated: `4179 + c * (71 ±0)` - // Minimum execution time: 55_650_000 picoseconds. - Weight::from_parts(56_276_004, 4179) - // Standard Error: 19_512 - .saturating_add(Weight::from_parts(185_775, 0).saturating_mul(c.into())) + // Measured: `730 + c * (60 ±0)` + // Estimated: `4213 + c * (59 ±0)` + // Minimum execution time: 55_657_000 picoseconds. + Weight::from_parts(57_084_118, 4213) + // Standard Error: 2_209 + .saturating_add(Weight::from_parts(101_671, 0).saturating_mul(c.into())) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(2)) - .saturating_add(Weight::from_parts(0, 71).saturating_mul(c.into())) + .saturating_add(Weight::from_parts(0, 59).saturating_mul(c.into())) } /// Storage: `CollatorSelection::Candidates` (r:1 w:1) - /// Proof: `CollatorSelection::Candidates` (`max_values`: Some(1), `max_size`: Some(193), added: 688, mode: `MaxEncodedLen`) + /// Proof: `CollatorSelection::Candidates` (`max_values`: Some(1), `max_size`: Some(2401), added: 2896, mode: `MaxEncodedLen`) /// Storage: `CollatorSelection::Invulnerables` (r:1 w:0) /// Proof: `CollatorSelection::Invulnerables` (`max_values`: Some(1), `max_size`: Some(1601), added: 2096, mode: `MaxEncodedLen`) /// Storage: `CollatorSelection::LastAuthoredBlock` (r:0 w:1) /// Proof: `CollatorSelection::LastAuthoredBlock` (`max_values`: None, `max_size`: Some(44), added: 2519, mode: `MaxEncodedLen`) - /// The range of component `c` is `[3, 4]`. + /// The range of component `c` is `[3, 50]`. fn leave_intent(c: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `445 + c * (82 ±0)` - // Estimated: `3086` - // Minimum execution time: 45_906_000 picoseconds. - Weight::from_parts(45_386_687, 3086) - // Standard Error: 27_981 - .saturating_add(Weight::from_parts(387_687, 0).saturating_mul(c.into())) + // Measured: `556 + c * (50 ±0)` + // Estimated: `3886` + // Minimum execution time: 46_120_000 picoseconds. + Weight::from_parts(46_397_357, 3886) + // Standard Error: 1_574 + .saturating_add(Weight::from_parts(90_362, 0).saturating_mul(c.into())) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(2)) } @@ -184,36 +179,36 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `192` // Estimated: `6196` - // Minimum execution time: 64_565_000 picoseconds. - Weight::from_parts(65_177_000, 6196) + // Minimum execution time: 63_730_000 picoseconds. + Weight::from_parts(64_351_000, 6196) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(4)) } /// Storage: `CollatorSelection::Candidates` (r:1 w:0) - /// Proof: `CollatorSelection::Candidates` (`max_values`: Some(1), `max_size`: Some(193), added: 688, mode: `MaxEncodedLen`) - /// Storage: `CollatorSelection::LastAuthoredBlock` (r:4 w:0) + /// Proof: `CollatorSelection::Candidates` (`max_values`: Some(1), `max_size`: Some(2401), added: 2896, mode: `MaxEncodedLen`) + /// Storage: `CollatorSelection::LastAuthoredBlock` (r:50 w:0) /// Proof: `CollatorSelection::LastAuthoredBlock` (`max_values`: None, `max_size`: Some(44), added: 2519, mode: `MaxEncodedLen`) /// Storage: `CollatorSelection::Invulnerables` (r:1 w:0) /// Proof: `CollatorSelection::Invulnerables` (`max_values`: Some(1), `max_size`: Some(1601), added: 2096, mode: `MaxEncodedLen`) /// Storage: `System::BlockWeight` (r:1 w:1) /// Proof: `System::BlockWeight` (`max_values`: Some(1), `max_size`: Some(48), added: 543, mode: `MaxEncodedLen`) - /// Storage: `System::Account` (r:2 w:2) + /// Storage: `System::Account` (r:44 w:44) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) - /// The range of component `r` is `[1, 4]`. - /// The range of component `c` is `[1, 4]`. + /// The range of component `r` is `[1, 50]`. + /// The range of component `c` is `[1, 50]`. fn new_session(r: u32, c: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `764 + c * (101 ±0)` - // Estimated: `3593 + c * (2519 ±0) + r * (1302 ±64)` - // Minimum execution time: 28_492_000 picoseconds. - Weight::from_parts(43_856_926, 3593) - // Standard Error: 1_235_538 - .saturating_add(Weight::from_parts(17_366_925, 0).saturating_mul(c.into())) + // Measured: `1276 + c * (98 ±0) + r * (116 ±0)` + // Estimated: `3886 + c * (2519 ±0) + r * (2603 ±0)` + // Minimum execution time: 28_836_000 picoseconds. + Weight::from_parts(29_061_000, 3886) + // Standard Error: 714_438 + .saturating_add(Weight::from_parts(16_538_136, 0).saturating_mul(c.into())) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(c.into()))) - .saturating_add(T::DbWeight::get().writes(3)) + .saturating_add(T::DbWeight::get().writes(1)) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(c.into()))) .saturating_add(Weight::from_parts(0, 2519).saturating_mul(c.into())) - .saturating_add(Weight::from_parts(0, 1302).saturating_mul(r.into())) + .saturating_add(Weight::from_parts(0, 2603).saturating_mul(r.into())) } -} +} \ No newline at end of file diff --git a/runtime/hydradx/src/weights/council.rs b/runtime/hydradx/src/weights/council.rs index aa07c42de..caa01468f 100644 --- a/runtime/hydradx/src/weights/council.rs +++ b/runtime/hydradx/src/weights/council.rs @@ -18,42 +18,37 @@ //! Autogenerated weights for `council` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-12-12, STEPS: `5`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-02-15, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `bench-bot`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` -//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 // Executed Command: // target/release/hydradx // benchmark // pallet -// --pallet=council +// --chain=dev +// --steps=10 +// --repeat=30 // --wasm-execution=compiled // --heap-pages=4096 -// --chain=dev +// --template=.maintain/pallet-weight-template-no-back.hbs +// --pallet=council +// --output=./weights/council.rs // --extrinsic=* -// --steps=5 -// --repeat=20 -// --output -// ./weights-1.1.0/council.rs -// --template -// .maintain/pallet-weight-template-no-back.hbs +#![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] -#![allow(clippy::unnecessary_cast)] +#![allow(missing_docs)] -use frame_support::{ - traits::Get, - weights::{constants::RocksDbWeight, Weight}, -}; -use sp_std::marker::PhantomData; +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; use pallet_collective::WeightInfo; -/// Weights for council using the hydraDX node and recommended hardware. +/// Weight functions for `council`. pub struct HydraWeight(PhantomData); - impl WeightInfo for HydraWeight { /// Storage: `Council::Members` (r:1 w:1) /// Proof: `Council::Members` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) @@ -66,40 +61,38 @@ impl WeightInfo for HydraWeight { /// The range of component `m` is `[0, 13]`. /// The range of component `n` is `[0, 13]`. /// The range of component `p` is `[0, 30]`. - fn set_members(m: u32, _n: u32, p: u32) -> Weight { + fn set_members(m: u32, _n: u32, p: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `0 + m * (992 ±0) + p * (405 ±0)` - // Estimated: `21811 + m * (615 ±25) + p * (2394 ±10)` - // Minimum execution time: 13_593_000 picoseconds. - Weight::from_parts(13_892_000, 21811) - // Standard Error: 392_175 - .saturating_add(Weight::from_parts(4_636_136, 0).saturating_mul(m.into())) - // Standard Error: 170_899 - .saturating_add(Weight::from_parts(3_787_560, 0).saturating_mul(p.into())) - .saturating_add(T::DbWeight::get().reads(2_u64)) - .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(m.into()))) + // Estimated: `10288 + m * (587 ±12) + p * (2585 ±5)` + // Minimum execution time: 13_811_000 picoseconds. + Weight::from_parts(13_892_000, 10288) + // Standard Error: 175_369 + .saturating_add(Weight::from_parts(2_946_800, 0).saturating_mul(m.into())) + // Standard Error: 76_976 + .saturating_add(Weight::from_parts(4_083_732, 0).saturating_mul(p.into())) + .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(p.into()))) - .saturating_add(T::DbWeight::get().writes(2_u64)) - .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(m.into()))) + .saturating_add(T::DbWeight::get().writes(2)) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(p.into()))) - .saturating_add(Weight::from_parts(0, 615).saturating_mul(m.into())) - .saturating_add(Weight::from_parts(0, 2394).saturating_mul(p.into())) + .saturating_add(Weight::from_parts(0, 587).saturating_mul(m.into())) + .saturating_add(Weight::from_parts(0, 2585).saturating_mul(p.into())) } /// Storage: `Council::Members` (r:1 w:0) /// Proof: `Council::Members` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) /// The range of component `b` is `[2, 1024]`. /// The range of component `m` is `[1, 13]`. - fn execute(b: u32, m: u32) -> Weight { + fn execute(b: u32, m: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `104 + m * (32 ±0)` - // Estimated: `1588 + m * (32 ±0)` - // Minimum execution time: 21_886_000 picoseconds. - Weight::from_parts(21_919_709, 1588) - // Standard Error: 49 - .saturating_add(Weight::from_parts(1_347, 0).saturating_mul(b.into())) - // Standard Error: 4_183 - .saturating_add(Weight::from_parts(26_796, 0).saturating_mul(m.into())) - .saturating_add(T::DbWeight::get().reads(1_u64)) + // Estimated: `1589 + m * (32 ±0)` + // Minimum execution time: 21_838_000 picoseconds. + Weight::from_parts(21_813_079, 1589) + // Standard Error: 23 + .saturating_add(Weight::from_parts(1_429, 0).saturating_mul(b.into())) + // Standard Error: 1_981 + .saturating_add(Weight::from_parts(26_339, 0).saturating_mul(m.into())) + .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(Weight::from_parts(0, 32).saturating_mul(m.into())) } /// Storage: `Council::Members` (r:1 w:0) @@ -108,17 +101,17 @@ impl WeightInfo for HydraWeight { /// Proof: `Council::ProposalOf` (`max_values`: None, `max_size`: None, mode: `Measured`) /// The range of component `b` is `[2, 1024]`. /// The range of component `m` is `[1, 13]`. - fn propose_execute(b: u32, m: u32) -> Weight { + fn propose_execute(b: u32, m: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `104 + m * (32 ±0)` - // Estimated: `3568 + m * (32 ±0)` - // Minimum execution time: 25_705_000 picoseconds. - Weight::from_parts(25_390_343, 3568) - // Standard Error: 58 - .saturating_add(Weight::from_parts(1_400, 0).saturating_mul(b.into())) - // Standard Error: 4_956 - .saturating_add(Weight::from_parts(39_729, 0).saturating_mul(m.into())) - .saturating_add(T::DbWeight::get().reads(2_u64)) + // Estimated: `3569 + m * (32 ±0)` + // Minimum execution time: 25_493_000 picoseconds. + Weight::from_parts(25_297_365, 3569) + // Standard Error: 28 + .saturating_add(Weight::from_parts(1_433, 0).saturating_mul(b.into())) + // Standard Error: 2_368 + .saturating_add(Weight::from_parts(52_183, 0).saturating_mul(m.into())) + .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(Weight::from_parts(0, 32).saturating_mul(m.into())) } /// Storage: `Council::Members` (r:1 w:0) @@ -134,36 +127,36 @@ impl WeightInfo for HydraWeight { /// The range of component `b` is `[2, 1024]`. /// The range of component `m` is `[2, 13]`. /// The range of component `p` is `[1, 30]`. - fn propose_proposed(b: u32, m: u32, p: u32) -> Weight { + fn propose_proposed(b: u32, m: u32, p: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `187 + m * (32 ±0) + p * (49 ±0)` - // Estimated: `3617 + m * (33 ±0) + p * (51 ±0)` - // Minimum execution time: 32_994_000 picoseconds. - Weight::from_parts(32_250_127, 3617) - // Standard Error: 206 - .saturating_add(Weight::from_parts(2_216, 0).saturating_mul(b.into())) - // Standard Error: 7_213 - .saturating_add(Weight::from_parts(339_379, 0).saturating_mul(p.into())) - .saturating_add(T::DbWeight::get().reads(4_u64)) - .saturating_add(T::DbWeight::get().writes(4_u64)) + // Measured: `269 + m * (32 ±0) + p * (46 ±0)` + // Estimated: `3676 + m * (33 ±0) + p * (48 ±0)` + // Minimum execution time: 32_929_000 picoseconds. + Weight::from_parts(33_435_771, 3676) + // Standard Error: 121 + .saturating_add(Weight::from_parts(2_403, 0).saturating_mul(b.into())) + // Standard Error: 4_207 + .saturating_add(Weight::from_parts(303_367, 0).saturating_mul(p.into())) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().writes(4)) .saturating_add(Weight::from_parts(0, 33).saturating_mul(m.into())) - .saturating_add(Weight::from_parts(0, 51).saturating_mul(p.into())) + .saturating_add(Weight::from_parts(0, 48).saturating_mul(p.into())) } /// Storage: `Council::Members` (r:1 w:0) /// Proof: `Council::Members` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) /// Storage: `Council::Voting` (r:1 w:1) /// Proof: `Council::Voting` (`max_values`: None, `max_size`: None, mode: `Measured`) /// The range of component `m` is `[5, 13]`. - fn vote(m: u32) -> Weight { + fn vote(m: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `638 + m * (64 ±0)` // Estimated: `4103 + m * (64 ±0)` - // Minimum execution time: 26_864_000 picoseconds. - Weight::from_parts(26_990_860, 4103) - // Standard Error: 5_236 - .saturating_add(Weight::from_parts(51_000, 0).saturating_mul(m.into())) - .saturating_add(T::DbWeight::get().reads(2_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 26_460_000 picoseconds. + Weight::from_parts(26_812_332, 4103) + // Standard Error: 3_093 + .saturating_add(Weight::from_parts(29_350, 0).saturating_mul(m.into())) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(1)) .saturating_add(Weight::from_parts(0, 64).saturating_mul(m.into())) } /// Storage: `Council::Voting` (r:1 w:1) @@ -176,20 +169,20 @@ impl WeightInfo for HydraWeight { /// Proof: `Council::ProposalOf` (`max_values`: None, `max_size`: None, mode: `Measured`) /// The range of component `m` is `[4, 13]`. /// The range of component `p` is `[1, 30]`. - fn close_early_disapproved(m: u32, p: u32) -> Weight { + fn close_early_disapproved(m: u32, p: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `208 + m * (64 ±0) + p * (46 ±0)` - // Estimated: `3673 + m * (69 ±1) + p * (45 ±0)` - // Minimum execution time: 34_511_000 picoseconds. - Weight::from_parts(34_588_685, 3673) - // Standard Error: 14_766 - .saturating_add(Weight::from_parts(54_177, 0).saturating_mul(m.into())) - // Standard Error: 4_664 - .saturating_add(Weight::from_parts(280_182, 0).saturating_mul(p.into())) - .saturating_add(T::DbWeight::get().reads(3_u64)) - .saturating_add(T::DbWeight::get().writes(3_u64)) - .saturating_add(Weight::from_parts(0, 69).saturating_mul(m.into())) - .saturating_add(Weight::from_parts(0, 45).saturating_mul(p.into())) + // Measured: `298 + m * (64 ±0) + p * (43 ±0)` + // Estimated: `3710 + m * (70 ±0) + p * (44 ±0)` + // Minimum execution time: 34_584_000 picoseconds. + Weight::from_parts(34_586_760, 3710) + // Standard Error: 9_925 + .saturating_add(Weight::from_parts(93_668, 0).saturating_mul(m.into())) + // Standard Error: 3_040 + .saturating_add(Weight::from_parts(263_683, 0).saturating_mul(p.into())) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(3)) + .saturating_add(Weight::from_parts(0, 70).saturating_mul(m.into())) + .saturating_add(Weight::from_parts(0, 44).saturating_mul(p.into())) } /// Storage: `Council::Voting` (r:1 w:1) /// Proof: `Council::Voting` (`max_values`: None, `max_size`: None, mode: `Measured`) @@ -202,23 +195,23 @@ impl WeightInfo for HydraWeight { /// The range of component `b` is `[2, 1024]`. /// The range of component `m` is `[4, 13]`. /// The range of component `p` is `[1, 30]`. - fn close_early_approved(b: u32, m: u32, p: u32) -> Weight { + fn close_early_approved(b: u32, m: u32, p: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `305 + m * (64 ±0) + p * (59 ±0)` - // Estimated: `3683 + b * (1 ±0) + m * (71 ±2) + p * (61 ±0)` - // Minimum execution time: 49_998_000 picoseconds. - Weight::from_parts(48_993_560, 3683) - // Standard Error: 191 - .saturating_add(Weight::from_parts(1_582, 0).saturating_mul(b.into())) - // Standard Error: 21_188 - .saturating_add(Weight::from_parts(44_398, 0).saturating_mul(m.into())) - // Standard Error: 6_705 - .saturating_add(Weight::from_parts(306_716, 0).saturating_mul(p.into())) - .saturating_add(T::DbWeight::get().reads(4_u64)) - .saturating_add(T::DbWeight::get().writes(3_u64)) + // Measured: `543 + m * (64 ±0) + p * (56 ±0)` + // Estimated: `3803 + b * (1 ±0) + m * (73 ±1) + p * (58 ±0)` + // Minimum execution time: 49_680_000 picoseconds. + Weight::from_parts(50_379_903, 3803) + // Standard Error: 120 + .saturating_add(Weight::from_parts(589, 0).saturating_mul(b.into())) + // Standard Error: 13_657 + .saturating_add(Weight::from_parts(65_319, 0).saturating_mul(m.into())) + // Standard Error: 4_179 + .saturating_add(Weight::from_parts(296_427, 0).saturating_mul(p.into())) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().writes(3)) .saturating_add(Weight::from_parts(0, 1).saturating_mul(b.into())) - .saturating_add(Weight::from_parts(0, 71).saturating_mul(m.into())) - .saturating_add(Weight::from_parts(0, 61).saturating_mul(p.into())) + .saturating_add(Weight::from_parts(0, 73).saturating_mul(m.into())) + .saturating_add(Weight::from_parts(0, 58).saturating_mul(p.into())) } /// Storage: `Council::Voting` (r:1 w:1) /// Proof: `Council::Voting` (`max_values`: None, `max_size`: None, mode: `Measured`) @@ -232,20 +225,20 @@ impl WeightInfo for HydraWeight { /// Proof: `Council::ProposalOf` (`max_values`: None, `max_size`: None, mode: `Measured`) /// The range of component `m` is `[4, 13]`. /// The range of component `p` is `[1, 30]`. - fn close_disapproved(m: u32, p: u32) -> Weight { + fn close_disapproved(m: u32, p: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `228 + m * (64 ±0) + p * (46 ±0)` - // Estimated: `3693 + m * (69 ±1) + p * (45 ±0)` - // Minimum execution time: 37_803_000 picoseconds. - Weight::from_parts(37_595_157, 3693) - // Standard Error: 15_571 - .saturating_add(Weight::from_parts(76_506, 0).saturating_mul(m.into())) - // Standard Error: 4_918 - .saturating_add(Weight::from_parts(273_488, 0).saturating_mul(p.into())) - .saturating_add(T::DbWeight::get().reads(4_u64)) - .saturating_add(T::DbWeight::get().writes(3_u64)) - .saturating_add(Weight::from_parts(0, 69).saturating_mul(m.into())) - .saturating_add(Weight::from_parts(0, 45).saturating_mul(p.into())) + // Measured: `318 + m * (64 ±0) + p * (43 ±0)` + // Estimated: `3730 + m * (70 ±0) + p * (44 ±0)` + // Minimum execution time: 37_700_000 picoseconds. + Weight::from_parts(38_156_308, 3730) + // Standard Error: 10_153 + .saturating_add(Weight::from_parts(60_234, 0).saturating_mul(m.into())) + // Standard Error: 3_109 + .saturating_add(Weight::from_parts(263_287, 0).saturating_mul(p.into())) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().writes(3)) + .saturating_add(Weight::from_parts(0, 70).saturating_mul(m.into())) + .saturating_add(Weight::from_parts(0, 44).saturating_mul(p.into())) } /// Storage: `Council::Voting` (r:1 w:1) /// Proof: `Council::Voting` (`max_values`: None, `max_size`: None, mode: `Measured`) @@ -260,23 +253,23 @@ impl WeightInfo for HydraWeight { /// The range of component `b` is `[2, 1024]`. /// The range of component `m` is `[4, 13]`. /// The range of component `p` is `[1, 30]`. - fn close_approved(b: u32, m: u32, p: u32) -> Weight { + fn close_approved(b: u32, m: u32, p: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `325 + m * (64 ±0) + p * (59 ±0)` - // Estimated: `3703 + b * (1 ±0) + m * (71 ±2) + p * (61 ±0)` - // Minimum execution time: 52_723_000 picoseconds. - Weight::from_parts(52_530_548, 3703) - // Standard Error: 221 - .saturating_add(Weight::from_parts(1_271, 0).saturating_mul(b.into())) - // Standard Error: 24_430 - .saturating_add(Weight::from_parts(29_682, 0).saturating_mul(m.into())) - // Standard Error: 7_731 - .saturating_add(Weight::from_parts(308_096, 0).saturating_mul(p.into())) - .saturating_add(T::DbWeight::get().reads(5_u64)) - .saturating_add(T::DbWeight::get().writes(3_u64)) + // Measured: `563 + m * (64 ±0) + p * (56 ±0)` + // Estimated: `3823 + b * (1 ±0) + m * (73 ±1) + p * (58 ±0)` + // Minimum execution time: 52_927_000 picoseconds. + Weight::from_parts(54_289_519, 3823) + // Standard Error: 189 + .saturating_add(Weight::from_parts(215, 0).saturating_mul(b.into())) + // Standard Error: 21_474 + .saturating_add(Weight::from_parts(60_622, 0).saturating_mul(m.into())) + // Standard Error: 6_571 + .saturating_add(Weight::from_parts(292_243, 0).saturating_mul(p.into())) + .saturating_add(T::DbWeight::get().reads(5)) + .saturating_add(T::DbWeight::get().writes(3)) .saturating_add(Weight::from_parts(0, 1).saturating_mul(b.into())) - .saturating_add(Weight::from_parts(0, 71).saturating_mul(m.into())) - .saturating_add(Weight::from_parts(0, 61).saturating_mul(p.into())) + .saturating_add(Weight::from_parts(0, 73).saturating_mul(m.into())) + .saturating_add(Weight::from_parts(0, 58).saturating_mul(p.into())) } /// Storage: `Council::Proposals` (r:1 w:1) /// Proof: `Council::Proposals` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) @@ -285,16 +278,16 @@ impl WeightInfo for HydraWeight { /// Storage: `Council::ProposalOf` (r:0 w:1) /// Proof: `Council::ProposalOf` (`max_values`: None, `max_size`: None, mode: `Measured`) /// The range of component `p` is `[1, 30]`. - fn disapprove_proposal(p: u32) -> Weight { + fn disapprove_proposal(p: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `260 + p * (32 ±0)` - // Estimated: `1744 + p * (32 ±0)` - // Minimum execution time: 22_405_000 picoseconds. - Weight::from_parts(23_004_470, 1744) - // Standard Error: 5_058 - .saturating_add(Weight::from_parts(217_141, 0).saturating_mul(p.into())) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(3_u64)) + // Estimated: `1745 + p * (32 ±0)` + // Minimum execution time: 22_476_000 picoseconds. + Weight::from_parts(23_113_774, 1745) + // Standard Error: 2_083 + .saturating_add(Weight::from_parts(201_829, 0).saturating_mul(p.into())) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(3)) .saturating_add(Weight::from_parts(0, 32).saturating_mul(p.into())) } } diff --git a/runtime/hydradx/src/weights/currencies.rs b/runtime/hydradx/src/weights/currencies.rs index 370d11e43..429c4d4cd 100644 --- a/runtime/hydradx/src/weights/currencies.rs +++ b/runtime/hydradx/src/weights/currencies.rs @@ -18,47 +18,44 @@ //! Autogenerated weights for `pallet_currencies` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-12-12, STEPS: `5`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-02-15, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `bench-bot`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` -//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 // Executed Command: // target/release/hydradx // benchmark // pallet -// --pallet=pallet-currencies +// --chain=dev +// --steps=10 +// --repeat=30 // --wasm-execution=compiled // --heap-pages=4096 -// --chain=dev +// --template=.maintain/pallet-weight-template-no-back.hbs +// --pallet=pallet-currencies +// --output=./weights/currencies.rs // --extrinsic=* -// --steps=5 -// --repeat=20 -// --output -// ./weights-1.1.0/currencies.rs -// --template -// .maintain/pallet-weight-template-no-back.hbs +#![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] -#![allow(clippy::unnecessary_cast)] - -use frame_support::{ - traits::Get, - weights::{constants::RocksDbWeight, Weight}, -}; -use sp_std::marker::PhantomData; +#![allow(missing_docs)] -use pallet_currencies::WeightInfo; +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; -/// Weights for pallet_currencies using the hydraDX node and recommended hardware. +/// Weight functions for `pallet_currencies`. pub struct HydraWeight(PhantomData); - -impl WeightInfo for HydraWeight { +impl pallet_currencies::WeightInfo for HydraWeight { + /// Storage: `Duster::AccountBlacklist` (r:1 w:0) + /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::BannedAssets` (r:1 w:0) + /// Proof: `AssetRegistry::BannedAssets` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`) /// Storage: `Tokens::Accounts` (r:2 w:2) /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::Assets` (r:1 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:1 w:1) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) /// Storage: `MultiTransactionPayment::AccountCurrencyMap` (r:1 w:1) @@ -67,28 +64,30 @@ impl WeightInfo for HydraWeight { /// Proof: `MultiTransactionPayment::AcceptedCurrencies` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) fn transfer_non_native_currency() -> Weight { // Proof Size summary in bytes: - // Measured: `2335` + // Measured: `2513` // Estimated: `6156` - // Minimum execution time: 96_394_000 picoseconds. - Weight::from_parts(96_942_000, 6156) - .saturating_add(T::DbWeight::get().reads(6_u64)) - .saturating_add(T::DbWeight::get().writes(4_u64)) + // Minimum execution time: 108_145_000 picoseconds. + Weight::from_parts(109_086_000, 6156) + .saturating_add(T::DbWeight::get().reads(8)) + .saturating_add(T::DbWeight::get().writes(4)) } /// Storage: `System::Account` (r:1 w:1) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) fn transfer_native_currency() -> Weight { // Proof Size summary in bytes: - // Measured: `1668` + // Measured: `1672` // Estimated: `3593` - // Minimum execution time: 92_953_000 picoseconds. - Weight::from_parts(94_336_000, 3593) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 89_180_000 picoseconds. + Weight::from_parts(89_986_000, 3593) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } + /// Storage: `AssetRegistry::BannedAssets` (r:1 w:0) + /// Proof: `AssetRegistry::BannedAssets` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`) /// Storage: `Tokens::Accounts` (r:1 w:1) /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::Assets` (r:1 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// Storage: `Tokens::TotalIssuance` (r:1 w:1) /// Proof: `Tokens::TotalIssuance` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:1 w:1) @@ -99,33 +98,33 @@ impl WeightInfo for HydraWeight { /// Proof: `MultiTransactionPayment::AcceptedCurrencies` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) fn update_balance_non_native_currency() -> Weight { // Proof Size summary in bytes: - // Measured: `2127` + // Measured: `2143` // Estimated: `3593` - // Minimum execution time: 73_636_000 picoseconds. - Weight::from_parts(74_177_000, 3593) - .saturating_add(T::DbWeight::get().reads(6_u64)) - .saturating_add(T::DbWeight::get().writes(3_u64)) + // Minimum execution time: 78_116_000 picoseconds. + Weight::from_parts(78_984_000, 3593) + .saturating_add(T::DbWeight::get().reads(7)) + .saturating_add(T::DbWeight::get().writes(3)) } /// Storage: `System::Account` (r:1 w:1) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) fn update_balance_native_currency_creating() -> Weight { // Proof Size summary in bytes: - // Measured: `1528` + // Measured: `1532` // Estimated: `3593` - // Minimum execution time: 54_370_000 picoseconds. - Weight::from_parts(55_148_000, 3593) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 52_733_000 picoseconds. + Weight::from_parts(53_610_000, 3593) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `System::Account` (r:1 w:1) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) fn update_balance_native_currency_killing() -> Weight { // Proof Size summary in bytes: - // Measured: `1616` + // Measured: `1620` // Estimated: `3593` - // Minimum execution time: 54_487_000 picoseconds. - Weight::from_parts(55_170_000, 3593) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 52_641_000 picoseconds. + Weight::from_parts(53_186_000, 3593) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } -} +} \ No newline at end of file diff --git a/runtime/hydradx/src/weights/dca.rs b/runtime/hydradx/src/weights/dca.rs index 5a8715eac..143e19da8 100644 --- a/runtime/hydradx/src/weights/dca.rs +++ b/runtime/hydradx/src/weights/dca.rs @@ -18,7 +18,7 @@ //! Autogenerated weights for `pallet_dca` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-12-27, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-02-15, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `bench-bot`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 @@ -33,26 +33,22 @@ // --wasm-execution=compiled // --heap-pages=4096 // --template=.maintain/pallet-weight-template-no-back.hbs -// --pallet=pallet-dca -// --output=weights-1.1.0/dca.rs +// --pallet=pallet_dca +// --output=./weights/dca.rs // --extrinsic=* #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] -#![allow(clippy::unnecessary_cast)] +#![allow(missing_docs)] -use frame_support::{ - traits::Get, - weights::{constants::RocksDbWeight, Weight}, -}; -use sp_std::marker::PhantomData; +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; use pallet_dca::weights::WeightInfo; -/// Weights for pallet_dca using the hydraDX node and recommended hardware. +/// Weight functions for `pallet_dca`. pub struct HydraWeight(PhantomData); - impl WeightInfo for HydraWeight { /// Storage: `DCA::ScheduleIdsPerBlock` (r:12 w:2) /// Proof: `DCA::ScheduleIdsPerBlock` (`max_values`: None, `max_size`: Some(101), added: 2576, mode: `MaxEncodedLen`) @@ -70,8 +66,8 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `54411` // Estimated: `31902` - // Minimum execution time: 244_530_000 picoseconds. - Weight::from_parts(249_044_000, 31902) + // Minimum execution time: 237_105_000 picoseconds. + Weight::from_parts(240_959_000, 31902) .saturating_add(T::DbWeight::get().reads(17)) .saturating_add(T::DbWeight::get().writes(7)) } @@ -91,8 +87,8 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `54411` // Estimated: `31902` - // Minimum execution time: 244_929_000 picoseconds. - Weight::from_parts(249_576_000, 31902) + // Minimum execution time: 238_379_000 picoseconds. + Weight::from_parts(241_004_000, 31902) .saturating_add(T::DbWeight::get().reads(17)) .saturating_add(T::DbWeight::get().writes(7)) } @@ -102,8 +98,8 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `1075` // Estimated: `3566` - // Minimum execution time: 17_904_000 picoseconds. - Weight::from_parts(18_177_000, 3566) + // Minimum execution time: 17_306_000 picoseconds. + Weight::from_parts(17_642_000, 3566) .saturating_add(T::DbWeight::get().reads(1)) } /// Storage: `MultiTransactionPayment::AcceptedCurrencies` (r:1 w:0) @@ -117,7 +113,7 @@ impl WeightInfo for HydraWeight { /// Storage: `Tokens::Accounts` (r:1 w:1) /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::Assets` (r:1 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// Storage: `DCA::ScheduleIdsPerBlock` (r:11 w:1) /// Proof: `DCA::ScheduleIdsPerBlock` (`max_values`: None, `max_size`: Some(101), added: 2576, mode: `MaxEncodedLen`) /// Storage: `DCA::RetriesOnError` (r:0 w:1) @@ -130,10 +126,10 @@ impl WeightInfo for HydraWeight { /// Proof: `DCA::RemainingAmounts` (`max_values`: None, `max_size`: Some(36), added: 2511, mode: `MaxEncodedLen`) fn schedule() -> Weight { // Proof Size summary in bytes: - // Measured: `52577` + // Measured: `52552` // Estimated: `29326` - // Minimum execution time: 175_288_000 picoseconds. - Weight::from_parts(178_961_000, 29326) + // Minimum execution time: 174_494_000 picoseconds. + Weight::from_parts(176_197_000, 29326) .saturating_add(T::DbWeight::get().reads(17)) .saturating_add(T::DbWeight::get().writes(8)) } @@ -155,8 +151,8 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `2526` // Estimated: `4714` - // Minimum execution time: 82_404_000 picoseconds. - Weight::from_parts(83_099_000, 4714) + // Minimum execution time: 80_303_000 picoseconds. + Weight::from_parts(81_183_000, 4714) .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(7)) } diff --git a/runtime/hydradx/src/weights/democracy.rs b/runtime/hydradx/src/weights/democracy.rs index b0d2327de..da99aec3c 100644 --- a/runtime/hydradx/src/weights/democracy.rs +++ b/runtime/hydradx/src/weights/democracy.rs @@ -1,5 +1,4 @@ // This file is part of HydraDX. -// This file is part of HydraDX. // Copyright (C) 2020-2023 Intergalactic, Limited (GIB). // SPDX-License-Identifier: Apache-2.0 @@ -19,43 +18,36 @@ //! Autogenerated weights for `pallet_democracy` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-12-12, STEPS: `5`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-02-15, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `bench-bot`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` -//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 // Executed Command: // target/release/hydradx // benchmark // pallet -// --pallet=pallet-democracy +// --chain=dev +// --steps=10 +// --repeat=30 // --wasm-execution=compiled // --heap-pages=4096 -// --chain=dev +// --template=.maintain/pallet-weight-template-no-back.hbs +// --pallet=pallet_democracy +// --output=./weights/democracy.rs // --extrinsic=* -// --steps=5 -// --repeat=20 -// --output -// ./weights-1.1.0/democracy.rs -// --template -// .maintain/pallet-weight-template-no-back.hbs +#![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] -#![allow(clippy::unnecessary_cast)] +#![allow(missing_docs)] -use frame_support::{ - traits::Get, - weights::{constants::RocksDbWeight, Weight}, -}; -use sp_std::marker::PhantomData; +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; -use pallet_democracy::weights::WeightInfo; - -/// Weights for pallet_democracy using the hydraDX node and recommended hardware. +/// Weight functions for `pallet_democracy`. pub struct HydraWeight(PhantomData); - -impl WeightInfo for HydraWeight { +impl pallet_democracy::WeightInfo for HydraWeight { /// Storage: `Democracy::PublicPropCount` (r:1 w:1) /// Proof: `Democracy::PublicPropCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) /// Storage: `Democracy::PublicProps` (r:1 w:1) @@ -68,10 +60,10 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `4688` // Estimated: `18187` - // Minimum execution time: 52_594_000 picoseconds. - Weight::from_parts(53_207_000, 18187) - .saturating_add(T::DbWeight::get().reads(3_u64)) - .saturating_add(T::DbWeight::get().writes(3_u64)) + // Minimum execution time: 52_817_000 picoseconds. + Weight::from_parts(53_361_000, 18187) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(3)) } /// Storage: `Democracy::DepositOf` (r:1 w:1) /// Proof: `Democracy::DepositOf` (`max_values`: None, `max_size`: Some(3230), added: 5705, mode: `MaxEncodedLen`) @@ -79,10 +71,10 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `3443` // Estimated: `6695` - // Minimum execution time: 47_180_000 picoseconds. - Weight::from_parts(47_748_000, 6695) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 47_312_000 picoseconds. + Weight::from_parts(48_028_000, 6695) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `Democracy::ReferendumInfoOf` (r:100 w:1) /// Proof: `Democracy::ReferendumInfoOf` (`max_values`: None, `max_size`: Some(201), added: 2676, mode: `MaxEncodedLen`) @@ -102,10 +94,10 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `15343` // Estimated: `268590` - // Minimum execution time: 452_520_000 picoseconds. - Weight::from_parts(456_752_000, 268590) - .saturating_add(T::DbWeight::get().reads(107_u64)) - .saturating_add(T::DbWeight::get().writes(5_u64)) + // Minimum execution time: 457_000_000 picoseconds. + Weight::from_parts(463_662_000, 268590) + .saturating_add(T::DbWeight::get().reads(107)) + .saturating_add(T::DbWeight::get().writes(5)) } /// Storage: `Democracy::ReferendumInfoOf` (r:100 w:1) /// Proof: `Democracy::ReferendumInfoOf` (`max_values`: None, `max_size`: Some(201), added: 2676, mode: `MaxEncodedLen`) @@ -125,10 +117,10 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `15365` // Estimated: `268590` - // Minimum execution time: 451_312_000 picoseconds. - Weight::from_parts(457_827_000, 268590) - .saturating_add(T::DbWeight::get().reads(107_u64)) - .saturating_add(T::DbWeight::get().writes(5_u64)) + // Minimum execution time: 458_732_000 picoseconds. + Weight::from_parts(462_786_000, 268590) + .saturating_add(T::DbWeight::get().reads(107)) + .saturating_add(T::DbWeight::get().writes(5)) } /// Storage: `Democracy::ReferendumInfoOf` (r:1 w:1) /// Proof: `Democracy::ReferendumInfoOf` (`max_values`: None, `max_size`: Some(201), added: 2676, mode: `MaxEncodedLen`) @@ -140,10 +132,10 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `249` // Estimated: `3666` - // Minimum execution time: 35_636_000 picoseconds. - Weight::from_parts(36_070_000, 3666) - .saturating_add(T::DbWeight::get().reads(3_u64)) - .saturating_add(T::DbWeight::get().writes(3_u64)) + // Minimum execution time: 35_202_000 picoseconds. + Weight::from_parts(35_727_000, 3666) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(3)) } /// Storage: `Democracy::PublicProps` (r:1 w:1) /// Proof: `Democracy::PublicProps` (`max_values`: Some(1), `max_size`: Some(16702), added: 17197, mode: `MaxEncodedLen`) @@ -163,10 +155,10 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `6191` // Estimated: `18187` - // Minimum execution time: 132_102_000 picoseconds. - Weight::from_parts(133_131_000, 18187) - .saturating_add(T::DbWeight::get().reads(9_u64)) - .saturating_add(T::DbWeight::get().writes(8_u64)) + // Minimum execution time: 133_106_000 picoseconds. + Weight::from_parts(134_384_000, 18187) + .saturating_add(T::DbWeight::get().reads(9)) + .saturating_add(T::DbWeight::get().writes(8)) } /// Storage: `Democracy::NextExternal` (r:1 w:1) /// Proof: `Democracy::NextExternal` (`max_values`: Some(1), `max_size`: Some(132), added: 627, mode: `MaxEncodedLen`) @@ -176,10 +168,10 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `3276` // Estimated: `6703` - // Minimum execution time: 16_474_000 picoseconds. - Weight::from_parts(16_722_000, 6703) - .saturating_add(T::DbWeight::get().reads(2_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 16_191_000 picoseconds. + Weight::from_parts(16_552_000, 6703) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `Democracy::NextExternal` (r:0 w:1) /// Proof: `Democracy::NextExternal` (`max_values`: Some(1), `max_size`: Some(132), added: 627, mode: `MaxEncodedLen`) @@ -187,8 +179,9 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 5_354_000 picoseconds. - Weight::from_parts(5_544_000, 0).saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 5_348_000 picoseconds. + Weight::from_parts(5_614_000, 0) + .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `Democracy::NextExternal` (r:0 w:1) /// Proof: `Democracy::NextExternal` (`max_values`: Some(1), `max_size`: Some(132), added: 627, mode: `MaxEncodedLen`) @@ -196,8 +189,9 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 5_302_000 picoseconds. - Weight::from_parts(5_556_000, 0).saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 5_475_000 picoseconds. + Weight::from_parts(5_653_000, 0) + .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `Democracy::NextExternal` (r:1 w:1) /// Proof: `Democracy::NextExternal` (`max_values`: Some(1), `max_size`: Some(132), added: 627, mode: `MaxEncodedLen`) @@ -211,10 +205,10 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `147` // Estimated: `3518` - // Minimum execution time: 35_393_000 picoseconds. - Weight::from_parts(36_025_000, 3518) - .saturating_add(T::DbWeight::get().reads(3_u64)) - .saturating_add(T::DbWeight::get().writes(5_u64)) + // Minimum execution time: 35_067_000 picoseconds. + Weight::from_parts(35_615_000, 3518) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(5)) } /// Storage: `Democracy::NextExternal` (r:1 w:1) /// Proof: `Democracy::NextExternal` (`max_values`: Some(1), `max_size`: Some(132), added: 627, mode: `MaxEncodedLen`) @@ -226,10 +220,10 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `3377` // Estimated: `6703` - // Minimum execution time: 37_183_000 picoseconds. - Weight::from_parts(37_728_000, 6703) - .saturating_add(T::DbWeight::get().reads(3_u64)) - .saturating_add(T::DbWeight::get().writes(3_u64)) + // Minimum execution time: 37_167_000 picoseconds. + Weight::from_parts(37_496_000, 6703) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(3)) } /// Storage: `Democracy::PublicProps` (r:1 w:1) /// Proof: `Democracy::PublicProps` (`max_values`: Some(1), `max_size`: Some(16702), added: 17197, mode: `MaxEncodedLen`) @@ -243,10 +237,10 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `6076` // Estimated: `18187` - // Minimum execution time: 107_143_000 picoseconds. - Weight::from_parts(107_867_000, 18187) - .saturating_add(T::DbWeight::get().reads(5_u64)) - .saturating_add(T::DbWeight::get().writes(5_u64)) + // Minimum execution time: 106_446_000 picoseconds. + Weight::from_parts(107_332_000, 18187) + .saturating_add(T::DbWeight::get().reads(5)) + .saturating_add(T::DbWeight::get().writes(5)) } /// Storage: `Democracy::MetadataOf` (r:1 w:1) /// Proof: `Democracy::MetadataOf` (`max_values`: None, `max_size`: Some(53), added: 2528, mode: `MaxEncodedLen`) @@ -256,10 +250,10 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `181` // Estimated: `3518` - // Minimum execution time: 27_379_000 picoseconds. - Weight::from_parts(27_886_000, 3518) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) + // Minimum execution time: 27_026_000 picoseconds. + Weight::from_parts(27_252_000, 3518) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(2)) } /// Storage: `Democracy::LowestUnbaked` (r:1 w:1) /// Proof: `Democracy::LowestUnbaked` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) @@ -268,17 +262,17 @@ impl WeightInfo for HydraWeight { /// Storage: `Democracy::ReferendumInfoOf` (r:99 w:0) /// Proof: `Democracy::ReferendumInfoOf` (`max_values`: None, `max_size`: Some(201), added: 2676, mode: `MaxEncodedLen`) /// The range of component `r` is `[0, 99]`. - fn on_initialize_base(r: u32) -> Weight { + fn on_initialize_base(r: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `108 + r * (86 ±0)` + // Measured: `125 + r * (86 ±0)` // Estimated: `1489 + r * (2676 ±0)` - // Minimum execution time: 6_121_000 picoseconds. - Weight::from_parts(8_592_893, 1489) - // Standard Error: 15_703 - .saturating_add(Weight::from_parts(3_531_200, 0).saturating_mul(r.into())) - .saturating_add(T::DbWeight::get().reads(2_u64)) + // Minimum execution time: 6_449_000 picoseconds. + Weight::from_parts(10_202_160, 1489) + // Standard Error: 9_155 + .saturating_add(Weight::from_parts(3_512_494, 0).saturating_mul(r.into())) + .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(r.into()))) - .saturating_add(T::DbWeight::get().writes(1_u64)) + .saturating_add(T::DbWeight::get().writes(1)) .saturating_add(Weight::from_parts(0, 2676).saturating_mul(r.into())) } /// Storage: `Democracy::LowestUnbaked` (r:1 w:1) @@ -294,17 +288,17 @@ impl WeightInfo for HydraWeight { /// Storage: `Democracy::ReferendumInfoOf` (r:99 w:0) /// Proof: `Democracy::ReferendumInfoOf` (`max_values`: None, `max_size`: Some(201), added: 2676, mode: `MaxEncodedLen`) /// The range of component `r` is `[0, 99]`. - fn on_initialize_base_with_launch_period(r: u32) -> Weight { + fn on_initialize_base_with_launch_period(r: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `108 + r * (86 ±0)` + // Measured: `125 + r * (86 ±0)` // Estimated: `18187 + r * (2676 ±0)` - // Minimum execution time: 10_482_000 picoseconds. - Weight::from_parts(12_899_855, 18187) - // Standard Error: 16_258 - .saturating_add(Weight::from_parts(3_555_121, 0).saturating_mul(r.into())) - .saturating_add(T::DbWeight::get().reads(5_u64)) + // Minimum execution time: 10_851_000 picoseconds. + Weight::from_parts(14_487_601, 18187) + // Standard Error: 11_289 + .saturating_add(Weight::from_parts(3_526_832, 0).saturating_mul(r.into())) + .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(r.into()))) - .saturating_add(T::DbWeight::get().writes(1_u64)) + .saturating_add(T::DbWeight::get().writes(1)) .saturating_add(Weight::from_parts(0, 2676).saturating_mul(r.into())) } /// Storage: `Democracy::VotingOf` (r:3 w:3) @@ -316,17 +310,17 @@ impl WeightInfo for HydraWeight { /// Storage: `Balances::Freezes` (r:1 w:0) /// Proof: `Balances::Freezes` (`max_values`: None, `max_size`: Some(49), added: 2524, mode: `MaxEncodedLen`) /// The range of component `r` is `[0, 99]`. - fn delegate(r: u32) -> Weight { + fn delegate(r: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `658 + r * (108 ±0)` + // Measured: `677 + r * (108 ±0)` // Estimated: `19800 + r * (2676 ±0)` - // Minimum execution time: 52_402_000 picoseconds. - Weight::from_parts(54_800_637, 19800) - // Standard Error: 20_146 - .saturating_add(Weight::from_parts(4_621_419, 0).saturating_mul(r.into())) - .saturating_add(T::DbWeight::get().reads(5_u64)) + // Minimum execution time: 51_565_000 picoseconds. + Weight::from_parts(54_150_506, 19800) + // Standard Error: 11_442 + .saturating_add(Weight::from_parts(4_583_970, 0).saturating_mul(r.into())) + .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(r.into()))) - .saturating_add(T::DbWeight::get().writes(4_u64)) + .saturating_add(T::DbWeight::get().writes(4)) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(r.into()))) .saturating_add(Weight::from_parts(0, 2676).saturating_mul(r.into())) } @@ -335,17 +329,17 @@ impl WeightInfo for HydraWeight { /// Storage: `Democracy::ReferendumInfoOf` (r:99 w:99) /// Proof: `Democracy::ReferendumInfoOf` (`max_values`: None, `max_size`: Some(201), added: 2676, mode: `MaxEncodedLen`) /// The range of component `r` is `[0, 99]`. - fn undelegate(r: u32) -> Weight { + fn undelegate(r: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `356 + r * (108 ±0)` + // Measured: `373 + r * (108 ±0)` // Estimated: `13530 + r * (2676 ±0)` - // Minimum execution time: 25_946_000 picoseconds. - Weight::from_parts(27_003_784, 13530) - // Standard Error: 14_228 - .saturating_add(Weight::from_parts(4_553_164, 0).saturating_mul(r.into())) - .saturating_add(T::DbWeight::get().reads(2_u64)) + // Minimum execution time: 25_418_000 picoseconds. + Weight::from_parts(25_764_904, 13530) + // Standard Error: 11_050 + .saturating_add(Weight::from_parts(4_467_732, 0).saturating_mul(r.into())) + .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(r.into()))) - .saturating_add(T::DbWeight::get().writes(2_u64)) + .saturating_add(T::DbWeight::get().writes(2)) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(r.into()))) .saturating_add(Weight::from_parts(0, 2676).saturating_mul(r.into())) } @@ -355,8 +349,9 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 5_588_000 picoseconds. - Weight::from_parts(5_693_000, 0).saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 5_514_000 picoseconds. + Weight::from_parts(5_649_000, 0) + .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `Democracy::VotingOf` (r:1 w:1) /// Proof: `Democracy::VotingOf` (`max_values`: None, `max_size`: Some(3795), added: 6270, mode: `MaxEncodedLen`) @@ -367,16 +362,16 @@ impl WeightInfo for HydraWeight { /// Storage: `System::Account` (r:1 w:1) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) /// The range of component `r` is `[0, 99]`. - fn unlock_remove(r: u32) -> Weight { + fn unlock_remove(r: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `432` // Estimated: `7260` - // Minimum execution time: 31_199_000 picoseconds. - Weight::from_parts(38_826_891, 7260) - // Standard Error: 21_192 - .saturating_add(Weight::from_parts(155_153, 0).saturating_mul(r.into())) - .saturating_add(T::DbWeight::get().reads(4_u64)) - .saturating_add(T::DbWeight::get().writes(3_u64)) + // Minimum execution time: 31_065_000 picoseconds. + Weight::from_parts(43_368_306, 7260) + // Standard Error: 11_713 + .saturating_add(Weight::from_parts(105_510, 0).saturating_mul(r.into())) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().writes(3)) } /// Storage: `Democracy::VotingOf` (r:1 w:1) /// Proof: `Democracy::VotingOf` (`max_values`: None, `max_size`: Some(3795), added: 6270, mode: `MaxEncodedLen`) @@ -387,16 +382,16 @@ impl WeightInfo for HydraWeight { /// Storage: `System::Account` (r:1 w:1) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) /// The range of component `r` is `[0, 99]`. - fn unlock_set(r: u32) -> Weight { + fn unlock_set(r: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `432 + r * (22 ±0)` // Estimated: `7260` - // Minimum execution time: 46_808_000 picoseconds. - Weight::from_parts(47_316_553, 7260) - // Standard Error: 2_010 - .saturating_add(Weight::from_parts(32_507, 0).saturating_mul(r.into())) - .saturating_add(T::DbWeight::get().reads(4_u64)) - .saturating_add(T::DbWeight::get().writes(3_u64)) + // Minimum execution time: 45_967_000 picoseconds. + Weight::from_parts(46_641_334, 7260) + // Standard Error: 1_430 + .saturating_add(Weight::from_parts(52_962, 0).saturating_mul(r.into())) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().writes(3)) } /// Storage: `Democracy::ReferendumInfoOf` (r:100 w:1) /// Proof: `Democracy::ReferendumInfoOf` (`max_values`: None, `max_size`: Some(201), added: 2676, mode: `MaxEncodedLen`) @@ -409,17 +404,17 @@ impl WeightInfo for HydraWeight { /// Storage: `Staking::PositionVotes` (r:1 w:1) /// Proof: `Staking::PositionVotes` (`max_values`: None, `max_size`: Some(2134), added: 4609, mode: `MaxEncodedLen`) /// The range of component `r` is `[1, 100]`. - fn remove_vote(r: u32) -> Weight { + fn remove_vote(r: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `1081 + r * (129 ±0)` + // Measured: `1078 + r * (129 ±0)` // Estimated: `7260 + r * (2676 ±0)` - // Minimum execution time: 50_224_000 picoseconds. - Weight::from_parts(48_115_552, 7260) - // Standard Error: 12_377 - .saturating_add(Weight::from_parts(3_620_792, 0).saturating_mul(r.into())) - .saturating_add(T::DbWeight::get().reads(5_u64)) + // Minimum execution time: 49_607_000 picoseconds. + Weight::from_parts(47_295_651, 7260) + // Standard Error: 9_326 + .saturating_add(Weight::from_parts(3_651_350, 0).saturating_mul(r.into())) + .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(r.into()))) - .saturating_add(T::DbWeight::get().writes(4_u64)) + .saturating_add(T::DbWeight::get().writes(4)) .saturating_add(Weight::from_parts(0, 2676).saturating_mul(r.into())) } /// Storage: `Democracy::ReferendumInfoOf` (r:100 w:1) @@ -433,17 +428,17 @@ impl WeightInfo for HydraWeight { /// Storage: `Staking::PositionVotes` (r:1 w:1) /// Proof: `Staking::PositionVotes` (`max_values`: None, `max_size`: Some(2134), added: 4609, mode: `MaxEncodedLen`) /// The range of component `r` is `[1, 100]`. - fn remove_other_vote(r: u32) -> Weight { + fn remove_other_vote(r: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `1081 + r * (129 ±0)` + // Measured: `1078 + r * (129 ±0)` // Estimated: `7260 + r * (2676 ±0)` - // Minimum execution time: 50_234_000 picoseconds. - Weight::from_parts(48_913_493, 7260) - // Standard Error: 9_632 - .saturating_add(Weight::from_parts(3_610_105, 0).saturating_mul(r.into())) - .saturating_add(T::DbWeight::get().reads(5_u64)) + // Minimum execution time: 49_376_000 picoseconds. + Weight::from_parts(47_208_359, 7260) + // Standard Error: 7_655 + .saturating_add(Weight::from_parts(3_658_412, 0).saturating_mul(r.into())) + .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(r.into()))) - .saturating_add(T::DbWeight::get().writes(4_u64)) + .saturating_add(T::DbWeight::get().writes(4)) .saturating_add(Weight::from_parts(0, 2676).saturating_mul(r.into())) } /// Storage: `Democracy::NextExternal` (r:1 w:0) @@ -456,10 +451,10 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `287` // Estimated: `3556` - // Minimum execution time: 23_854_000 picoseconds. - Weight::from_parts(24_292_000, 3556) - .saturating_add(T::DbWeight::get().reads(2_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 23_578_000 picoseconds. + Weight::from_parts(24_114_000, 3556) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `Democracy::NextExternal` (r:1 w:0) /// Proof: `Democracy::NextExternal` (`max_values`: Some(1), `max_size`: Some(132), added: 627, mode: `MaxEncodedLen`) @@ -469,10 +464,10 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `147` // Estimated: `3518` - // Minimum execution time: 21_276_000 picoseconds. - Weight::from_parts(21_525_000, 3518) - .saturating_add(T::DbWeight::get().reads(2_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 21_024_000 picoseconds. + Weight::from_parts(21_324_000, 3518) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `Democracy::PublicProps` (r:1 w:0) /// Proof: `Democracy::PublicProps` (`max_values`: Some(1), `max_size`: Some(16702), added: 17197, mode: `MaxEncodedLen`) @@ -484,10 +479,10 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `4842` // Estimated: `18187` - // Minimum execution time: 47_143_000 picoseconds. - Weight::from_parts(47_852_000, 18187) - .saturating_add(T::DbWeight::get().reads(2_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 47_604_000 picoseconds. + Weight::from_parts(47_974_000, 18187) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `Democracy::PublicProps` (r:1 w:0) /// Proof: `Democracy::PublicProps` (`max_values`: Some(1), `max_size`: Some(16702), added: 17197, mode: `MaxEncodedLen`) @@ -497,10 +492,10 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `4706` // Estimated: `18187` - // Minimum execution time: 43_821_000 picoseconds. - Weight::from_parts(44_144_000, 18187) - .saturating_add(T::DbWeight::get().reads(2_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 44_046_000 picoseconds. + Weight::from_parts(44_746_000, 18187) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `Preimage::StatusFor` (r:1 w:0) /// Proof: `Preimage::StatusFor` (`max_values`: None, `max_size`: Some(91), added: 2566, mode: `MaxEncodedLen`) @@ -510,10 +505,10 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `211` // Estimated: `3556` - // Minimum execution time: 20_772_000 picoseconds. - Weight::from_parts(21_133_000, 3556) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 20_917_000 picoseconds. + Weight::from_parts(21_223_000, 3556) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `Democracy::ReferendumInfoOf` (r:1 w:0) /// Proof: `Democracy::ReferendumInfoOf` (`max_values`: None, `max_size`: Some(201), added: 2676, mode: `MaxEncodedLen`) @@ -523,9 +518,9 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `159` // Estimated: `3666` - // Minimum execution time: 23_308_000 picoseconds. - Weight::from_parts(23_661_000, 3666) - .saturating_add(T::DbWeight::get().reads(2_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 23_184_000 picoseconds. + Weight::from_parts(23_505_000, 3666) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(1)) } -} +} \ No newline at end of file diff --git a/runtime/hydradx/src/weights/duster.rs b/runtime/hydradx/src/weights/duster.rs index d48869f11..d57ad0429 100644 --- a/runtime/hydradx/src/weights/duster.rs +++ b/runtime/hydradx/src/weights/duster.rs @@ -3,11 +3,6 @@ // Copyright (C) 2020-2023 Intergalactic, Limited (GIB). // SPDX-License-Identifier: Apache-2.0 -// This file is part of HydraDX. - -// Copyright (C) 2020-2023 Intergalactic, Limited (GIB). -// SPDX-License-Identifier: Apache-2.0 - // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at @@ -23,51 +18,48 @@ //! Autogenerated weights for `pallet_duster` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-12-12, STEPS: `5`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-02-15, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `bench-bot`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` -//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 // Executed Command: // target/release/hydradx // benchmark // pallet -// --pallet=pallet-duster +// --chain=dev +// --steps=10 +// --repeat=30 // --wasm-execution=compiled // --heap-pages=4096 -// --chain=dev +// --template=.maintain/pallet-weight-template-no-back.hbs +// --pallet=pallet_duster +// --output=./weights/duster.rs // --extrinsic=* -// --steps=5 -// --repeat=20 -// --output -// ./weights-1.1.0/duster.rs -// --template -// .maintain/pallet-weight-template-no-back.hbs +#![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] -#![allow(clippy::unnecessary_cast)] +#![allow(missing_docs)] -use frame_support::{ - traits::Get, - weights::{constants::RocksDbWeight, Weight}, -}; -use sp_std::marker::PhantomData; +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; use pallet_duster::weights::WeightInfo; -/// Weights for pallet_duster using the hydraDX node and recommended hardware. +/// Weight functions for `pallet_duster`. pub struct HydraWeight(PhantomData); - impl WeightInfo for HydraWeight { /// Storage: `Duster::AccountBlacklist` (r:1 w:0) /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::Assets` (r:1 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// Storage: `Tokens::Accounts` (r:2 w:2) /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) /// Storage: `Duster::DustAccount` (r:1 w:0) /// Proof: `Duster::DustAccount` (`max_values`: Some(1), `max_size`: Some(32), added: 527, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::BannedAssets` (r:1 w:0) + /// Proof: `AssetRegistry::BannedAssets` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:1 w:1) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) /// Storage: `Duster::RewardAccount` (r:1 w:0) @@ -76,31 +68,32 @@ impl WeightInfo for HydraWeight { /// Proof: `MultiTransactionPayment::AccountCurrencyMap` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`) fn dust_account() -> Weight { // Proof Size summary in bytes: - // Measured: `2538` + // Measured: `2554` // Estimated: `6156` - // Minimum execution time: 90_102_000 picoseconds. - Weight::from_parts(90_700_000, 6156) - .saturating_add(T::DbWeight::get().reads(7_u64)) - .saturating_add(T::DbWeight::get().writes(4_u64)) + // Minimum execution time: 99_580_000 picoseconds. + Weight::from_parts(100_367_000, 6156) + .saturating_add(T::DbWeight::get().reads(8)) + .saturating_add(T::DbWeight::get().writes(4)) } /// Storage: `Duster::AccountBlacklist` (r:0 w:1) /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) fn add_nondustable_account() -> Weight { // Proof Size summary in bytes: - // Measured: `1008` + // Measured: `1012` // Estimated: `0` - // Minimum execution time: 21_071_000 picoseconds. - Weight::from_parts(21_591_000, 0).saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 20_681_000 picoseconds. + Weight::from_parts(21_171_000, 0) + .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `Duster::AccountBlacklist` (r:1 w:1) /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) fn remove_nondustable_account() -> Weight { // Proof Size summary in bytes: - // Measured: `1296` + // Measured: `1300` // Estimated: `3513` - // Minimum execution time: 26_630_000 picoseconds. - Weight::from_parts(27_026_000, 3513) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 26_184_000 picoseconds. + Weight::from_parts(26_513_000, 3513) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } } diff --git a/runtime/hydradx/src/weights/ema_oracle.rs b/runtime/hydradx/src/weights/ema_oracle.rs index 78dca3a04..621a35424 100644 --- a/runtime/hydradx/src/weights/ema_oracle.rs +++ b/runtime/hydradx/src/weights/ema_oracle.rs @@ -18,42 +18,37 @@ //! Autogenerated weights for `pallet_ema_oracle` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-12-12, STEPS: `5`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-02-15, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `bench-bot`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` -//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 // Executed Command: // target/release/hydradx // benchmark // pallet -// --pallet=pallet-ema-oracle +// --chain=dev +// --steps=10 +// --repeat=30 // --wasm-execution=compiled // --heap-pages=4096 -// --chain=dev +// --template=.maintain/pallet-weight-template-no-back.hbs +// --pallet=pallet-ema-oracle +// --output=./weights/ema_oracle.rs // --extrinsic=* -// --steps=5 -// --repeat=20 -// --output -// ./weights-1.1.0/ema_oracle.rs -// --template -// .maintain/pallet-weight-template-no-back.hbs +#![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] -#![allow(clippy::unnecessary_cast)] +#![allow(missing_docs)] -use frame_support::{ - traits::Get, - weights::{constants::RocksDbWeight, Weight}, -}; -use sp_std::marker::PhantomData; +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; use pallet_ema_oracle::weights::WeightInfo; -/// Weights for pallet_ema_oracle using the hydraDX node and recommended hardware. +/// Weight functions for `pallet_ema_oracle`. pub struct HydraWeight(PhantomData); - impl WeightInfo for HydraWeight { /// Storage: `EmaOracle::Accumulator` (r:1 w:0) /// Proof: `EmaOracle::Accumulator` (`max_values`: Some(1), `max_size`: Some(5921), added: 6416, mode: `MaxEncodedLen`) @@ -61,55 +56,56 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `208` // Estimated: `7406` - // Minimum execution time: 3_108_000 picoseconds. - Weight::from_parts(3_213_000, 7406).saturating_add(T::DbWeight::get().reads(1_u64)) + // Minimum execution time: 3_140_000 picoseconds. + Weight::from_parts(3_253_000, 7406) + .saturating_add(T::DbWeight::get().reads(1)) } /// Storage: `EmaOracle::Accumulator` (r:1 w:1) /// Proof: `EmaOracle::Accumulator` (`max_values`: Some(1), `max_size`: Some(5921), added: 6416, mode: `MaxEncodedLen`) /// Storage: `EmaOracle::Oracles` (r:117 w:117) /// Proof: `EmaOracle::Oracles` (`max_values`: None, `max_size`: Some(177), added: 2652, mode: `MaxEncodedLen`) /// The range of component `b` is `[1, 39]`. - fn on_finalize_multiple_tokens(b: u32) -> Weight { + fn on_finalize_multiple_tokens(b: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `270 + b * (626 ±0)` // Estimated: `7406 + b * (7956 ±0)` - // Minimum execution time: 46_197_000 picoseconds. - Weight::from_parts(6_894_077, 7406) - // Standard Error: 58_512 - .saturating_add(Weight::from_parts(36_389_579, 0).saturating_mul(b.into())) - .saturating_add(T::DbWeight::get().reads(1_u64)) + // Minimum execution time: 46_946_000 picoseconds. + Weight::from_parts(9_495_798, 7406) + // Standard Error: 18_892 + .saturating_add(Weight::from_parts(36_363_503, 0).saturating_mul(b.into())) + .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().reads((3_u64).saturating_mul(b.into()))) - .saturating_add(T::DbWeight::get().writes(1_u64)) + .saturating_add(T::DbWeight::get().writes(1)) .saturating_add(T::DbWeight::get().writes((3_u64).saturating_mul(b.into()))) .saturating_add(Weight::from_parts(0, 7956).saturating_mul(b.into())) } /// Storage: `EmaOracle::Accumulator` (r:1 w:1) /// Proof: `EmaOracle::Accumulator` (`max_values`: Some(1), `max_size`: Some(5921), added: 6416, mode: `MaxEncodedLen`) /// The range of component `b` is `[1, 39]`. - fn on_trade_multiple_tokens(b: u32) -> Weight { + fn on_trade_multiple_tokens(b: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `270 + b * (148 ±0)` // Estimated: `7406` - // Minimum execution time: 9_225_000 picoseconds. - Weight::from_parts(9_309_132, 7406) - // Standard Error: 2_681 - .saturating_add(Weight::from_parts(395_788, 0).saturating_mul(b.into())) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 9_605_000 picoseconds. + Weight::from_parts(9_734_841, 7406) + // Standard Error: 1_636 + .saturating_add(Weight::from_parts(368_579, 0).saturating_mul(b.into())) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `EmaOracle::Accumulator` (r:1 w:1) /// Proof: `EmaOracle::Accumulator` (`max_values`: Some(1), `max_size`: Some(5921), added: 6416, mode: `MaxEncodedLen`) /// The range of component `b` is `[1, 39]`. - fn on_liquidity_changed_multiple_tokens(b: u32) -> Weight { + fn on_liquidity_changed_multiple_tokens(b: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `270 + b * (148 ±0)` // Estimated: `7406` - // Minimum execution time: 9_353_000 picoseconds. - Weight::from_parts(9_378_483, 7406) - // Standard Error: 1_820 - .saturating_add(Weight::from_parts(397_535, 0).saturating_mul(b.into())) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 9_580_000 picoseconds. + Weight::from_parts(9_817_291, 7406) + // Standard Error: 1_899 + .saturating_add(Weight::from_parts(364_892, 0).saturating_mul(b.into())) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `EmaOracle::Oracles` (r:2 w:0) /// Proof: `EmaOracle::Oracles` (`max_values`: None, `max_size`: Some(177), added: 2652, mode: `MaxEncodedLen`) @@ -117,7 +113,8 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `604` // Estimated: `6294` - // Minimum execution time: 18_642_000 picoseconds. - Weight::from_parts(19_015_000, 6294).saturating_add(T::DbWeight::get().reads(2_u64)) + // Minimum execution time: 18_804_000 picoseconds. + Weight::from_parts(19_169_000, 6294) + .saturating_add(T::DbWeight::get().reads(2)) } } diff --git a/runtime/hydradx/src/weights/identity.rs b/runtime/hydradx/src/weights/identity.rs index 7eab3d306..7144de19c 100644 --- a/runtime/hydradx/src/weights/identity.rs +++ b/runtime/hydradx/src/weights/identity.rs @@ -18,73 +18,66 @@ //! Autogenerated weights for `pallet_identity` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-12-12, STEPS: `5`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-02-15, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `bench-bot`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` -//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 // Executed Command: // target/release/hydradx // benchmark // pallet -// --pallet=pallet-identity +// --chain=dev +// --steps=10 +// --repeat=30 // --wasm-execution=compiled // --heap-pages=4096 -// --chain=dev +// --template=.maintain/pallet-weight-template-no-back.hbs +// --pallet=pallet-identity +// --output=./weights/identity.rs // --extrinsic=* -// --steps=5 -// --repeat=20 -// --output -// ./weights-1.1.0/identity.rs -// --template -// .maintain/pallet-weight-template-no-back.hbs +#![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] -#![allow(clippy::unnecessary_cast)] - -use frame_support::{ - traits::Get, - weights::{constants::RocksDbWeight, Weight}, -}; -use sp_std::marker::PhantomData; +#![allow(missing_docs)] -use pallet_identity::weights::WeightInfo; +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; -/// Weights for pallet_identity using the hydraDX node and recommended hardware. +/// Weight functions for `pallet_identity`. pub struct HydraWeight(PhantomData); - -impl WeightInfo for HydraWeight { +impl pallet_identity::WeightInfo for HydraWeight { /// Storage: `Identity::Registrars` (r:1 w:1) /// Proof: `Identity::Registrars` (`max_values`: Some(1), `max_size`: Some(1141), added: 1636, mode: `MaxEncodedLen`) /// The range of component `r` is `[1, 19]`. - fn add_registrar(r: u32) -> Weight { + fn add_registrar(r: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `32 + r * (57 ±0)` // Estimated: `2626` - // Minimum execution time: 16_934_000 picoseconds. - Weight::from_parts(17_553_576, 2626) - // Standard Error: 6_083 - .saturating_add(Weight::from_parts(104_428, 0).saturating_mul(r.into())) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 17_261_000 picoseconds. + Weight::from_parts(18_025_223, 2626) + // Standard Error: 3_087 + .saturating_add(Weight::from_parts(88_219, 0).saturating_mul(r.into())) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `Identity::IdentityOf` (r:1 w:1) /// Proof: `Identity::IdentityOf` (`max_values`: None, `max_size`: Some(7538), added: 10013, mode: `MaxEncodedLen`) /// The range of component `r` is `[1, 20]`. /// The range of component `x` is `[0, 100]`. - fn set_identity(r: u32, x: u32) -> Weight { + fn set_identity(r: u32, x: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `442 + r * (5 ±0)` // Estimated: `11003` - // Minimum execution time: 44_671_000 picoseconds. - Weight::from_parts(43_380_570, 11003) - // Standard Error: 3_398 - .saturating_add(Weight::from_parts(89_436, 0).saturating_mul(r.into())) - // Standard Error: 659 - .saturating_add(Weight::from_parts(714_757, 0).saturating_mul(x.into())) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 44_163_000 picoseconds. + Weight::from_parts(42_727_355, 11003) + // Standard Error: 4_678 + .saturating_add(Weight::from_parts(103_190, 0).saturating_mul(r.into())) + // Standard Error: 897 + .saturating_add(Weight::from_parts(697_595, 0).saturating_mul(x.into())) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `Identity::IdentityOf` (r:1 w:0) /// Proof: `Identity::IdentityOf` (`max_values`: None, `max_size`: Some(7538), added: 10013, mode: `MaxEncodedLen`) @@ -93,17 +86,17 @@ impl WeightInfo for HydraWeight { /// Storage: `Identity::SuperOf` (r:100 w:100) /// Proof: `Identity::SuperOf` (`max_values`: None, `max_size`: Some(114), added: 2589, mode: `MaxEncodedLen`) /// The range of component `s` is `[0, 100]`. - fn set_subs_new(s: u32) -> Weight { + fn set_subs_new(s: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `101` // Estimated: `11003 + s * (2589 ±0)` - // Minimum execution time: 14_570_000 picoseconds. - Weight::from_parts(23_863_560, 11003) - // Standard Error: 25_763 - .saturating_add(Weight::from_parts(4_280_870, 0).saturating_mul(s.into())) - .saturating_add(T::DbWeight::get().reads(2_u64)) + // Minimum execution time: 14_699_000 picoseconds. + Weight::from_parts(29_345_813, 11003) + // Standard Error: 14_245 + .saturating_add(Weight::from_parts(4_057_797, 0).saturating_mul(s.into())) + .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(s.into()))) - .saturating_add(T::DbWeight::get().writes(1_u64)) + .saturating_add(T::DbWeight::get().writes(1)) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(s.into()))) .saturating_add(Weight::from_parts(0, 2589).saturating_mul(s.into())) } @@ -114,16 +107,16 @@ impl WeightInfo for HydraWeight { /// Storage: `Identity::SuperOf` (r:0 w:100) /// Proof: `Identity::SuperOf` (`max_values`: None, `max_size`: Some(114), added: 2589, mode: `MaxEncodedLen`) /// The range of component `p` is `[0, 100]`. - fn set_subs_old(p: u32) -> Weight { + fn set_subs_old(p: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `192 + p * (32 ±0)` + // Measured: `193 + p * (32 ±0)` // Estimated: `11003` - // Minimum execution time: 14_562_000 picoseconds. - Weight::from_parts(22_949_900, 11003) - // Standard Error: 23_636 - .saturating_add(Weight::from_parts(1_793_279, 0).saturating_mul(p.into())) - .saturating_add(T::DbWeight::get().reads(2_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 14_679_000 picoseconds. + Weight::from_parts(27_894_942, 11003) + // Standard Error: 12_742 + .saturating_add(Weight::from_parts(1_675_500, 0).saturating_mul(p.into())) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(1)) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(p.into()))) } /// Storage: `Identity::SubsOf` (r:1 w:1) @@ -135,20 +128,20 @@ impl WeightInfo for HydraWeight { /// The range of component `r` is `[1, 20]`. /// The range of component `s` is `[0, 100]`. /// The range of component `x` is `[0, 100]`. - fn clear_identity(r: u32, s: u32, x: u32) -> Weight { + fn clear_identity(r: u32, s: u32, x: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `467 + r * (5 ±0) + s * (32 ±0) + x * (66 ±0)` + // Measured: `468 + r * (5 ±0) + s * (32 ±0) + x * (66 ±0)` // Estimated: `11003` - // Minimum execution time: 78_708_000 picoseconds. - Weight::from_parts(39_980_565, 11003) - // Standard Error: 16_719 - .saturating_add(Weight::from_parts(151_091, 0).saturating_mul(r.into())) - // Standard Error: 3_247 - .saturating_add(Weight::from_parts(1_645_822, 0).saturating_mul(s.into())) - // Standard Error: 3_247 - .saturating_add(Weight::from_parts(372_874, 0).saturating_mul(x.into())) - .saturating_add(T::DbWeight::get().reads(2_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 78_695_000 picoseconds. + Weight::from_parts(41_668_144, 11003) + // Standard Error: 7_894 + .saturating_add(Weight::from_parts(85_933, 0).saturating_mul(r.into())) + // Standard Error: 1_517 + .saturating_add(Weight::from_parts(1_590_914, 0).saturating_mul(s.into())) + // Standard Error: 1_517 + .saturating_add(Weight::from_parts(375_705, 0).saturating_mul(x.into())) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(2)) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(s.into()))) } /// Storage: `Identity::Registrars` (r:1 w:0) @@ -157,77 +150,77 @@ impl WeightInfo for HydraWeight { /// Proof: `Identity::IdentityOf` (`max_values`: None, `max_size`: Some(7538), added: 10013, mode: `MaxEncodedLen`) /// The range of component `r` is `[1, 20]`. /// The range of component `x` is `[0, 100]`. - fn request_judgement(r: u32, x: u32) -> Weight { + fn request_judgement(r: u32, x: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `365 + r * (57 ±0) + x * (66 ±0)` // Estimated: `11003` - // Minimum execution time: 45_052_000 picoseconds. - Weight::from_parts(44_230_262, 11003) - // Standard Error: 5_797 - .saturating_add(Weight::from_parts(68_847, 0).saturating_mul(r.into())) - // Standard Error: 1_125 - .saturating_add(Weight::from_parts(723_782, 0).saturating_mul(x.into())) - .saturating_add(T::DbWeight::get().reads(2_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 44_784_000 picoseconds. + Weight::from_parts(43_971_070, 11003) + // Standard Error: 5_047 + .saturating_add(Weight::from_parts(80_761, 0).saturating_mul(r.into())) + // Standard Error: 968 + .saturating_add(Weight::from_parts(702_450, 0).saturating_mul(x.into())) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `Identity::IdentityOf` (r:1 w:1) /// Proof: `Identity::IdentityOf` (`max_values`: None, `max_size`: Some(7538), added: 10013, mode: `MaxEncodedLen`) /// The range of component `r` is `[1, 20]`. /// The range of component `x` is `[0, 100]`. - fn cancel_request(r: u32, x: u32) -> Weight { + fn cancel_request(r: u32, x: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `396 + x * (66 ±0)` // Estimated: `11003` - // Minimum execution time: 41_286_000 picoseconds. - Weight::from_parts(40_750_967, 11003) - // Standard Error: 6_724 - .saturating_add(Weight::from_parts(49_172, 0).saturating_mul(r.into())) - // Standard Error: 1_305 - .saturating_add(Weight::from_parts(723_915, 0).saturating_mul(x.into())) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 41_076_000 picoseconds. + Weight::from_parts(40_739_871, 11003) + // Standard Error: 6_026 + .saturating_add(Weight::from_parts(54_796, 0).saturating_mul(r.into())) + // Standard Error: 1_156 + .saturating_add(Weight::from_parts(702_783, 0).saturating_mul(x.into())) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `Identity::Registrars` (r:1 w:1) /// Proof: `Identity::Registrars` (`max_values`: Some(1), `max_size`: Some(1141), added: 1636, mode: `MaxEncodedLen`) /// The range of component `r` is `[1, 19]`. - fn set_fee(r: u32) -> Weight { + fn set_fee(r: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `89 + r * (57 ±0)` // Estimated: `2626` - // Minimum execution time: 10_775_000 picoseconds. - Weight::from_parts(11_396_553, 2626) - // Standard Error: 6_015 - .saturating_add(Weight::from_parts(78_325, 0).saturating_mul(r.into())) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 11_308_000 picoseconds. + Weight::from_parts(11_832_550, 2626) + // Standard Error: 2_040 + .saturating_add(Weight::from_parts(72_446, 0).saturating_mul(r.into())) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `Identity::Registrars` (r:1 w:1) /// Proof: `Identity::Registrars` (`max_values`: Some(1), `max_size`: Some(1141), added: 1636, mode: `MaxEncodedLen`) /// The range of component `r` is `[1, 19]`. - fn set_account_id(r: u32) -> Weight { + fn set_account_id(r: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `89 + r * (57 ±0)` // Estimated: `2626` - // Minimum execution time: 11_285_000 picoseconds. - Weight::from_parts(11_718_851, 2626) - // Standard Error: 2_957 - .saturating_add(Weight::from_parts(68_141, 0).saturating_mul(r.into())) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 11_782_000 picoseconds. + Weight::from_parts(12_164_081, 2626) + // Standard Error: 1_710 + .saturating_add(Weight::from_parts(69_398, 0).saturating_mul(r.into())) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `Identity::Registrars` (r:1 w:1) /// Proof: `Identity::Registrars` (`max_values`: Some(1), `max_size`: Some(1141), added: 1636, mode: `MaxEncodedLen`) /// The range of component `r` is `[1, 19]`. - fn set_fields(r: u32) -> Weight { + fn set_fields(r: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `89 + r * (57 ±0)` // Estimated: `2626` - // Minimum execution time: 10_902_000 picoseconds. - Weight::from_parts(11_350_705, 2626) - // Standard Error: 4_692 - .saturating_add(Weight::from_parts(72_095, 0).saturating_mul(r.into())) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 11_490_000 picoseconds. + Weight::from_parts(11_819_190, 2626) + // Standard Error: 1_612 + .saturating_add(Weight::from_parts(65_269, 0).saturating_mul(r.into())) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `Identity::Registrars` (r:1 w:0) /// Proof: `Identity::Registrars` (`max_values`: Some(1), `max_size`: Some(1141), added: 1636, mode: `MaxEncodedLen`) @@ -235,18 +228,18 @@ impl WeightInfo for HydraWeight { /// Proof: `Identity::IdentityOf` (`max_values`: None, `max_size`: Some(7538), added: 10013, mode: `MaxEncodedLen`) /// The range of component `r` is `[1, 19]`. /// The range of component `x` is `[0, 100]`. - fn provide_judgement(r: u32, x: u32) -> Weight { + fn provide_judgement(r: u32, x: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `443 + r * (57 ±0) + x * (66 ±0)` // Estimated: `11003` - // Minimum execution time: 32_313_000 picoseconds. - Weight::from_parts(30_931_150, 11003) - // Standard Error: 6_730 - .saturating_add(Weight::from_parts(97_823, 0).saturating_mul(r.into())) - // Standard Error: 1_225 - .saturating_add(Weight::from_parts(1_117_375, 0).saturating_mul(x.into())) - .saturating_add(T::DbWeight::get().reads(2_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 32_212_000 picoseconds. + Weight::from_parts(30_951_168, 11003) + // Standard Error: 5_657 + .saturating_add(Weight::from_parts(98_160, 0).saturating_mul(r.into())) + // Standard Error: 1_016 + .saturating_add(Weight::from_parts(1_087_740, 0).saturating_mul(x.into())) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `Identity::SubsOf` (r:1 w:1) /// Proof: `Identity::SubsOf` (`max_values`: None, `max_size`: Some(3258), added: 5733, mode: `MaxEncodedLen`) @@ -259,18 +252,20 @@ impl WeightInfo for HydraWeight { /// The range of component `r` is `[1, 20]`. /// The range of component `s` is `[0, 100]`. /// The range of component `x` is `[0, 100]`. - fn kill_identity(_r: u32, s: u32, x: u32) -> Weight { + fn kill_identity(r: u32, s: u32, x: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `732 + r * (17 ±0) + s * (32 ±0) + x * (66 ±0)` + // Measured: `760 + r * (16 ±0) + s * (32 ±0) + x * (66 ±0)` // Estimated: `11003` - // Minimum execution time: 102_506_000 picoseconds. - Weight::from_parts(68_340_447, 11003) - // Standard Error: 2_827 - .saturating_add(Weight::from_parts(1_654_468, 0).saturating_mul(s.into())) - // Standard Error: 2_827 - .saturating_add(Weight::from_parts(360_303, 0).saturating_mul(x.into())) - .saturating_add(T::DbWeight::get().reads(4_u64)) - .saturating_add(T::DbWeight::get().writes(3_u64)) + // Minimum execution time: 102_051_000 picoseconds. + Weight::from_parts(67_588_586, 11003) + // Standard Error: 12_409 + .saturating_add(Weight::from_parts(167_208, 0).saturating_mul(r.into())) + // Standard Error: 2_384 + .saturating_add(Weight::from_parts(1_609_560, 0).saturating_mul(s.into())) + // Standard Error: 2_384 + .saturating_add(Weight::from_parts(344_185, 0).saturating_mul(x.into())) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().writes(4)) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(s.into()))) } /// Storage: `Identity::IdentityOf` (r:1 w:0) @@ -280,32 +275,32 @@ impl WeightInfo for HydraWeight { /// Storage: `Identity::SubsOf` (r:1 w:1) /// Proof: `Identity::SubsOf` (`max_values`: None, `max_size`: Some(3258), added: 5733, mode: `MaxEncodedLen`) /// The range of component `s` is `[0, 99]`. - fn add_sub(s: u32) -> Weight { + fn add_sub(s: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `263 + s * (39 ±0)` + // Measured: `428 + s * (36 ±0)` // Estimated: `11003` - // Minimum execution time: 40_861_000 picoseconds. - Weight::from_parts(43_416_491, 11003) - // Standard Error: 5_902 - .saturating_add(Weight::from_parts(84_100, 0).saturating_mul(s.into())) - .saturating_add(T::DbWeight::get().reads(3_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) + // Minimum execution time: 40_751_000 picoseconds. + Weight::from_parts(44_490_675, 11003) + // Standard Error: 3_411 + .saturating_add(Weight::from_parts(72_803, 0).saturating_mul(s.into())) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(2)) } /// Storage: `Identity::IdentityOf` (r:1 w:0) /// Proof: `Identity::IdentityOf` (`max_values`: None, `max_size`: Some(7538), added: 10013, mode: `MaxEncodedLen`) /// Storage: `Identity::SuperOf` (r:1 w:1) /// Proof: `Identity::SuperOf` (`max_values`: None, `max_size`: Some(114), added: 2589, mode: `MaxEncodedLen`) /// The range of component `s` is `[1, 100]`. - fn rename_sub(s: u32) -> Weight { + fn rename_sub(s: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `450 + s * (5 ±0)` + // Measured: `563 + s * (3 ±0)` // Estimated: `11003` - // Minimum execution time: 18_907_000 picoseconds. - Weight::from_parts(20_162_889, 11003) - // Standard Error: 2_842 - .saturating_add(Weight::from_parts(32_962, 0).saturating_mul(s.into())) - .saturating_add(T::DbWeight::get().reads(2_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 19_092_000 picoseconds. + Weight::from_parts(20_893_870, 11003) + // Standard Error: 1_498 + .saturating_add(Weight::from_parts(29_141, 0).saturating_mul(s.into())) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `Identity::IdentityOf` (r:1 w:0) /// Proof: `Identity::IdentityOf` (`max_values`: None, `max_size`: Some(7538), added: 10013, mode: `MaxEncodedLen`) @@ -314,16 +309,16 @@ impl WeightInfo for HydraWeight { /// Storage: `Identity::SubsOf` (r:1 w:1) /// Proof: `Identity::SubsOf` (`max_values`: None, `max_size`: Some(3258), added: 5733, mode: `MaxEncodedLen`) /// The range of component `s` is `[1, 100]`. - fn remove_sub(s: u32) -> Weight { + fn remove_sub(s: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `499 + s * (37 ±0)` + // Measured: `611 + s * (35 ±0)` // Estimated: `11003` - // Minimum execution time: 44_474_000 picoseconds. - Weight::from_parts(46_128_496, 11003) - // Standard Error: 3_813 - .saturating_add(Weight::from_parts(55_997, 0).saturating_mul(s.into())) - .saturating_add(T::DbWeight::get().reads(3_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) + // Minimum execution time: 44_470_000 picoseconds. + Weight::from_parts(46_580_204, 11003) + // Standard Error: 1_811 + .saturating_add(Weight::from_parts(51_699, 0).saturating_mul(s.into())) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(2)) } /// Storage: `Identity::SuperOf` (r:1 w:1) /// Proof: `Identity::SuperOf` (`max_values`: None, `max_size`: Some(114), added: 2589, mode: `MaxEncodedLen`) @@ -332,15 +327,15 @@ impl WeightInfo for HydraWeight { /// Storage: `System::Account` (r:1 w:0) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) /// The range of component `s` is `[0, 99]`. - fn quit_sub(s: u32) -> Weight { + fn quit_sub(s: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `603 + s * (38 ±0)` + // Measured: `638 + s * (38 ±0)` // Estimated: `6723` - // Minimum execution time: 32_790_000 picoseconds. - Weight::from_parts(34_581_789, 6723) - // Standard Error: 3_665 - .saturating_add(Weight::from_parts(57_073, 0).saturating_mul(s.into())) - .saturating_add(T::DbWeight::get().reads(3_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) + // Minimum execution time: 33_030_000 picoseconds. + Weight::from_parts(35_034_240, 6723) + // Standard Error: 1_832 + .saturating_add(Weight::from_parts(54_735, 0).saturating_mul(s.into())) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(2)) } -} +} \ No newline at end of file diff --git a/runtime/hydradx/src/weights/lbp.rs b/runtime/hydradx/src/weights/lbp.rs index 8d7348d11..2a4238477 100644 --- a/runtime/hydradx/src/weights/lbp.rs +++ b/runtime/hydradx/src/weights/lbp.rs @@ -18,42 +18,37 @@ //! Autogenerated weights for `pallet_lbp` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-12-12, STEPS: `5`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-02-15, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `bench-bot`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` -//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 // Executed Command: // target/release/hydradx // benchmark // pallet -// --pallet=pallet-lbp +// --chain=dev +// --steps=10 +// --repeat=30 // --wasm-execution=compiled // --heap-pages=4096 -// --chain=dev +// --template=.maintain/pallet-weight-template-no-back.hbs +// --pallet=pallet_lbp +// --output=./weights/lbp.rs // --extrinsic=* -// --steps=5 -// --repeat=20 -// --output -// ./weights-1.1.0/lbp.rs -// --template -// .maintain/pallet-weight-template-no-back.hbs +#![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] -#![allow(clippy::unnecessary_cast)] +#![allow(missing_docs)] -use frame_support::{ - traits::Get, - weights::{constants::RocksDbWeight, Weight}, -}; -use sp_std::marker::PhantomData; +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; use pallet_lbp::weights::WeightInfo; -/// Weights for pallet_lbp using the hydraDX node and recommended hardware. +/// Weight functions for `pallet_lbp`. pub struct HydraWeight(PhantomData); - impl WeightInfo for HydraWeight { /// Storage: `LBP::PoolData` (r:1 w:1) /// Proof: `LBP::PoolData` (`max_values`: None, `max_size`: Some(163), added: 2638, mode: `MaxEncodedLen`) @@ -61,8 +56,12 @@ impl WeightInfo for HydraWeight { /// Proof: `LBP::FeeCollectorWithAsset` (`max_values`: None, `max_size`: Some(69), added: 2544, mode: `MaxEncodedLen`) /// Storage: `Tokens::Accounts` (r:4 w:4) /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) + /// Storage: `Duster::AccountBlacklist` (r:1 w:0) + /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::BannedAssets` (r:2 w:0) + /// Proof: `AssetRegistry::BannedAssets` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::Assets` (r:2 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:2 w:1) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) /// Storage: `MultiTransactionPayment::AccountCurrencyMap` (r:1 w:1) @@ -71,12 +70,12 @@ impl WeightInfo for HydraWeight { /// Proof: `MultiTransactionPayment::AcceptedCurrencies` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) fn create_pool() -> Weight { // Proof Size summary in bytes: - // Measured: `992` + // Measured: `1178` // Estimated: `11322` - // Minimum execution time: 144_386_000 picoseconds. - Weight::from_parts(145_196_000, 11322) - .saturating_add(T::DbWeight::get().reads(12_u64)) - .saturating_add(T::DbWeight::get().writes(8_u64)) + // Minimum execution time: 162_938_000 picoseconds. + Weight::from_parts(164_251_000, 11322) + .saturating_add(T::DbWeight::get().reads(15)) + .saturating_add(T::DbWeight::get().writes(8)) } /// Storage: `LBP::PoolData` (r:1 w:1) /// Proof: `LBP::PoolData` (`max_values`: None, `max_size`: Some(163), added: 2638, mode: `MaxEncodedLen`) @@ -86,34 +85,42 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `351` // Estimated: `3628` - // Minimum execution time: 30_461_000 picoseconds. - Weight::from_parts(30_686_000, 3628) - .saturating_add(T::DbWeight::get().reads(2_u64)) - .saturating_add(T::DbWeight::get().writes(3_u64)) + // Minimum execution time: 30_041_000 picoseconds. + Weight::from_parts(30_468_000, 3628) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(3)) } /// Storage: `LBP::PoolData` (r:1 w:0) /// Proof: `LBP::PoolData` (`max_values`: None, `max_size`: Some(163), added: 2638, mode: `MaxEncodedLen`) /// Storage: `Tokens::Accounts` (r:4 w:4) /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) + /// Storage: `Duster::AccountBlacklist` (r:1 w:0) + /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::BannedAssets` (r:2 w:0) + /// Proof: `AssetRegistry::BannedAssets` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::Assets` (r:2 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:1 w:0) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) fn add_liquidity() -> Weight { // Proof Size summary in bytes: - // Measured: `1180` + // Measured: `1439` // Estimated: `11322` - // Minimum execution time: 100_583_000 picoseconds. - Weight::from_parts(101_592_000, 11322) - .saturating_add(T::DbWeight::get().reads(8_u64)) - .saturating_add(T::DbWeight::get().writes(4_u64)) + // Minimum execution time: 118_411_000 picoseconds. + Weight::from_parts(119_467_000, 11322) + .saturating_add(T::DbWeight::get().reads(11)) + .saturating_add(T::DbWeight::get().writes(4)) } /// Storage: `LBP::PoolData` (r:1 w:1) /// Proof: `LBP::PoolData` (`max_values`: None, `max_size`: Some(163), added: 2638, mode: `MaxEncodedLen`) /// Storage: `Tokens::Accounts` (r:4 w:4) /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) + /// Storage: `Duster::AccountBlacklist` (r:1 w:0) + /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::BannedAssets` (r:2 w:0) + /// Proof: `AssetRegistry::BannedAssets` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::Assets` (r:2 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:1 w:1) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) /// Storage: `MultiTransactionPayment::AccountCurrencyMap` (r:1 w:1) @@ -124,12 +131,12 @@ impl WeightInfo for HydraWeight { /// Proof: `LBP::FeeCollectorWithAsset` (`max_values`: None, `max_size`: Some(69), added: 2544, mode: `MaxEncodedLen`) fn remove_liquidity() -> Weight { // Proof Size summary in bytes: - // Measured: `1368` + // Measured: `1554` // Estimated: `11322` - // Minimum execution time: 133_274_000 picoseconds. - Weight::from_parts(134_648_000, 11322) - .saturating_add(T::DbWeight::get().reads(10_u64)) - .saturating_add(T::DbWeight::get().writes(8_u64)) + // Minimum execution time: 153_550_000 picoseconds. + Weight::from_parts(154_890_000, 11322) + .saturating_add(T::DbWeight::get().reads(13)) + .saturating_add(T::DbWeight::get().writes(8)) } /// Storage: `Tokens::Accounts` (r:5 w:5) /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) @@ -137,18 +144,22 @@ impl WeightInfo for HydraWeight { /// Proof: `LBP::PoolData` (`max_values`: None, `max_size`: Some(163), added: 2638, mode: `MaxEncodedLen`) /// Storage: `Tokens::Locks` (r:1 w:1) /// Proof: `Tokens::Locks` (`max_values`: None, `max_size`: Some(1261), added: 3736, mode: `MaxEncodedLen`) + /// Storage: `Duster::AccountBlacklist` (r:2 w:0) + /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::BannedAssets` (r:2 w:0) + /// Proof: `AssetRegistry::BannedAssets` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::Assets` (r:2 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:3 w:1) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) fn sell() -> Weight { // Proof Size summary in bytes: - // Measured: `1585` + // Measured: `1844` // Estimated: `13905` - // Minimum execution time: 218_344_000 picoseconds. - Weight::from_parts(220_109_000, 13905) - .saturating_add(T::DbWeight::get().reads(12_u64)) - .saturating_add(T::DbWeight::get().writes(7_u64)) + // Minimum execution time: 243_058_000 picoseconds. + Weight::from_parts(244_292_000, 13905) + .saturating_add(T::DbWeight::get().reads(16)) + .saturating_add(T::DbWeight::get().writes(7)) } /// Storage: `LBP::PoolData` (r:1 w:0) /// Proof: `LBP::PoolData` (`max_values`: None, `max_size`: Some(163), added: 2638, mode: `MaxEncodedLen`) @@ -156,18 +167,22 @@ impl WeightInfo for HydraWeight { /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) /// Storage: `Tokens::Locks` (r:1 w:1) /// Proof: `Tokens::Locks` (`max_values`: None, `max_size`: Some(1261), added: 3736, mode: `MaxEncodedLen`) + /// Storage: `Duster::AccountBlacklist` (r:2 w:0) + /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::BannedAssets` (r:2 w:0) + /// Proof: `AssetRegistry::BannedAssets` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::Assets` (r:2 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:3 w:1) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) fn buy() -> Weight { // Proof Size summary in bytes: - // Measured: `1585` + // Measured: `1844` // Estimated: `13905` - // Minimum execution time: 219_060_000 picoseconds. - Weight::from_parts(220_516_000, 13905) - .saturating_add(T::DbWeight::get().reads(12_u64)) - .saturating_add(T::DbWeight::get().writes(7_u64)) + // Minimum execution time: 242_758_000 picoseconds. + Weight::from_parts(244_140_000, 13905) + .saturating_add(T::DbWeight::get().reads(16)) + .saturating_add(T::DbWeight::get().writes(7)) } /// Storage: `LBP::PoolData` (r:1 w:0) /// Proof: `LBP::PoolData` (`max_values`: None, `max_size`: Some(163), added: 2638, mode: `MaxEncodedLen`) @@ -175,24 +190,28 @@ impl WeightInfo for HydraWeight { /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) /// Storage: `Tokens::Locks` (r:1 w:1) /// Proof: `Tokens::Locks` (`max_values`: None, `max_size`: Some(1261), added: 3736, mode: `MaxEncodedLen`) + /// Storage: `Duster::AccountBlacklist` (r:2 w:0) + /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::BannedAssets` (r:2 w:0) + /// Proof: `AssetRegistry::BannedAssets` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::Assets` (r:2 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:3 w:1) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) /// The range of component `c` is `[1, 2]`. /// The range of component `e` is `[0, 1]`. - fn router_execution_sell(c: u32, e: u32) -> Weight { + fn router_execution_sell(c: u32, e: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `756 + e * (829 ±0)` - // Estimated: `6156 + e * (7749 ±0)` - // Minimum execution time: 65_722_000 picoseconds. - Weight::from_parts(66_193_000, 6156) - // Standard Error: 1_355_364 - .saturating_add(Weight::from_parts(3_961_882, 0).saturating_mul(c.into())) - // Standard Error: 2_927_921 - .saturating_add(Weight::from_parts(163_724_923, 0).saturating_mul(e.into())) - .saturating_add(T::DbWeight::get().reads(3_u64)) - .saturating_add(T::DbWeight::get().reads((9_u64).saturating_mul(e.into()))) + // Measured: `756 + e * (1088 ±0)` + // Estimated: `6156 + e * (7749 ±251_795_645_551_580_832)` + // Minimum execution time: 66_583_000 picoseconds. + Weight::from_parts(67_060_000, 6156) + // Standard Error: 587_908 + .saturating_add(Weight::from_parts(2_276_829, 0).saturating_mul(c.into())) + // Standard Error: 1_290_627 + .saturating_add(Weight::from_parts(183_046_701, 0).saturating_mul(e.into())) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().reads((13_u64).saturating_mul(e.into()))) .saturating_add(T::DbWeight::get().writes((7_u64).saturating_mul(e.into()))) .saturating_add(Weight::from_parts(0, 7749).saturating_mul(e.into())) } @@ -202,24 +221,28 @@ impl WeightInfo for HydraWeight { /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) /// Storage: `Tokens::Locks` (r:1 w:1) /// Proof: `Tokens::Locks` (`max_values`: None, `max_size`: Some(1261), added: 3736, mode: `MaxEncodedLen`) + /// Storage: `Duster::AccountBlacklist` (r:2 w:0) + /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::BannedAssets` (r:2 w:0) + /// Proof: `AssetRegistry::BannedAssets` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::Assets` (r:2 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:3 w:1) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) /// The range of component `c` is `[1, 3]`. /// The range of component `e` is `[0, 1]`. - fn router_execution_buy(c: u32, e: u32) -> Weight { + fn router_execution_buy(c: u32, e: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `756 + e * (829 ±0)` + // Measured: `756 + e * (1088 ±0)` // Estimated: `6156 + e * (7749 ±0)` - // Minimum execution time: 116_733_000 picoseconds. - Weight::from_parts(117_433_000, 6156) - // Standard Error: 1_509_020 - .saturating_add(Weight::from_parts(5_197_432, 0).saturating_mul(c.into())) - // Standard Error: 4_928_439 - .saturating_add(Weight::from_parts(141_782_318, 0).saturating_mul(e.into())) - .saturating_add(T::DbWeight::get().reads(3_u64)) - .saturating_add(T::DbWeight::get().reads((9_u64).saturating_mul(e.into()))) + // Minimum execution time: 117_561_000 picoseconds. + Weight::from_parts(118_264_000, 6156) + // Standard Error: 751_682 + .saturating_add(Weight::from_parts(3_708_043, 0).saturating_mul(c.into())) + // Standard Error: 2_482_101 + .saturating_add(Weight::from_parts(155_294_743, 0).saturating_mul(e.into())) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().reads((13_u64).saturating_mul(e.into()))) .saturating_add(T::DbWeight::get().writes((7_u64).saturating_mul(e.into()))) .saturating_add(Weight::from_parts(0, 7749).saturating_mul(e.into())) } @@ -231,7 +254,8 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `756` // Estimated: `6156` - // Minimum execution time: 65_795_000 picoseconds. - Weight::from_parts(66_370_000, 6156).saturating_add(T::DbWeight::get().reads(3_u64)) + // Minimum execution time: 66_616_000 picoseconds. + Weight::from_parts(67_128_000, 6156) + .saturating_add(T::DbWeight::get().reads(3)) } } diff --git a/runtime/hydradx/src/weights/omnipool.rs b/runtime/hydradx/src/weights/omnipool.rs index 777d91214..8cd6318d1 100644 --- a/runtime/hydradx/src/weights/omnipool.rs +++ b/runtime/hydradx/src/weights/omnipool.rs @@ -18,7 +18,7 @@ //! Autogenerated weights for `pallet_omnipool` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2024-01-09, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-02-15, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `bench-bot`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 @@ -33,31 +33,25 @@ // --wasm-execution=compiled // --heap-pages=4096 // --template=.maintain/pallet-weight-template-no-back.hbs -// --pallet=pallet-omnipool -// --output=weights-1.1.0/omnipool.rs +// --pallet=pallet_omnipool +// --output=./weights/omnipool.rs // --extrinsic=* #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] -#![allow(clippy::unnecessary_cast)] +#![allow(missing_docs)] -use frame_support::{ - traits::Get, - weights::{constants::RocksDbWeight, Weight}, -}; -use sp_std::marker::PhantomData; +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; -use pallet_omnipool::weights::WeightInfo; - -/// Weights for pallet_omnipool using the hydraDX node and recommended hardware. +/// Weight functions for `pallet_omnipool`. pub struct HydraWeight(PhantomData); - -impl WeightInfo for HydraWeight { +impl pallet_omnipool::WeightInfo for HydraWeight { /// Storage: `Omnipool::Assets` (r:1 w:1) /// Proof: `Omnipool::Assets` (`max_values`: None, `max_size`: Some(85), added: 2560, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::Assets` (r:2 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// Storage: `Uniques::Class` (r:1 w:1) /// Proof: `Uniques::Class` (`max_values`: None, `max_size`: Some(190), added: 2665, mode: `MaxEncodedLen`) /// Storage: `Tokens::Accounts` (r:2 w:1) @@ -70,6 +64,8 @@ impl WeightInfo for HydraWeight { /// Proof: `Uniques::CollectionMaxSupply` (`max_values`: None, `max_size`: Some(36), added: 2511, mode: `MaxEncodedLen`) /// Storage: `Omnipool::HubAssetImbalance` (r:1 w:1) /// Proof: `Omnipool::HubAssetImbalance` (`max_values`: Some(1), `max_size`: Some(17), added: 512, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::BannedAssets` (r:1 w:0) + /// Proof: `AssetRegistry::BannedAssets` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`) /// Storage: `Tokens::TotalIssuance` (r:1 w:1) /// Proof: `Tokens::TotalIssuance` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) /// Storage: `EmaOracle::Accumulator` (r:1 w:1) @@ -80,11 +76,11 @@ impl WeightInfo for HydraWeight { /// Proof: `Omnipool::Positions` (`max_values`: None, `max_size`: Some(100), added: 2575, mode: `MaxEncodedLen`) fn add_token() -> Weight { // Proof Size summary in bytes: - // Measured: `3004` + // Measured: `3028` // Estimated: `7406` - // Minimum execution time: 141_394_000 picoseconds. - Weight::from_parts(142_349_000, 7406) - .saturating_add(T::DbWeight::get().reads(12)) + // Minimum execution time: 146_309_000 picoseconds. + Weight::from_parts(147_552_000, 7406) + .saturating_add(T::DbWeight::get().reads(13)) .saturating_add(T::DbWeight::get().writes(10)) } /// Storage: `Tokens::Accounts` (r:3 w:3) @@ -103,8 +99,12 @@ impl WeightInfo for HydraWeight { /// Proof: `Uniques::Class` (`max_values`: None, `max_size`: Some(190), added: 2665, mode: `MaxEncodedLen`) /// Storage: `Uniques::CollectionMaxSupply` (r:1 w:0) /// Proof: `Uniques::CollectionMaxSupply` (`max_values`: None, `max_size`: Some(36), added: 2511, mode: `MaxEncodedLen`) + /// Storage: `Duster::AccountBlacklist` (r:1 w:0) + /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::BannedAssets` (r:2 w:0) + /// Proof: `AssetRegistry::BannedAssets` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::Assets` (r:2 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:1 w:0) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) /// Storage: `Tokens::TotalIssuance` (r:1 w:1) @@ -125,11 +125,11 @@ impl WeightInfo for HydraWeight { /// Proof: `Omnipool::Positions` (`max_values`: None, `max_size`: Some(100), added: 2575, mode: `MaxEncodedLen`) fn add_liquidity() -> Weight { // Proof Size summary in bytes: - // Measured: `3919` + // Measured: `4178` // Estimated: `8739` - // Minimum execution time: 220_969_000 picoseconds. - Weight::from_parts(222_574_000, 8739) - .saturating_add(T::DbWeight::get().reads(20)) + // Minimum execution time: 236_030_000 picoseconds. + Weight::from_parts(237_610_000, 8739) + .saturating_add(T::DbWeight::get().reads(23)) .saturating_add(T::DbWeight::get().writes(14)) } /// Storage: `Uniques::Asset` (r:1 w:1) @@ -144,8 +144,12 @@ impl WeightInfo for HydraWeight { /// Proof: `EmaOracle::Oracles` (`max_values`: None, `max_size`: Some(177), added: 2652, mode: `MaxEncodedLen`) /// Storage: `Omnipool::HubAssetImbalance` (r:1 w:1) /// Proof: `Omnipool::HubAssetImbalance` (`max_values`: Some(1), `max_size`: Some(17), added: 512, mode: `MaxEncodedLen`) + /// Storage: `Duster::AccountBlacklist` (r:1 w:0) + /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::BannedAssets` (r:2 w:0) + /// Proof: `AssetRegistry::BannedAssets` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::Assets` (r:2 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:2 w:1) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) /// Storage: `Tokens::TotalIssuance` (r:1 w:1) @@ -172,11 +176,11 @@ impl WeightInfo for HydraWeight { /// Proof: `Uniques::ItemPriceOf` (`max_values`: None, `max_size`: Some(113), added: 2588, mode: `MaxEncodedLen`) fn remove_liquidity() -> Weight { // Proof Size summary in bytes: - // Measured: `6903` + // Measured: `7089` // Estimated: `11322` - // Minimum execution time: 297_780_000 picoseconds. - Weight::from_parts(299_506_000, 11322) - .saturating_add(T::DbWeight::get().reads(23)) + // Minimum execution time: 316_738_000 picoseconds. + Weight::from_parts(319_501_000, 11322) + .saturating_add(T::DbWeight::get().reads(26)) .saturating_add(T::DbWeight::get().writes(16)) } /// Storage: `Tokens::Accounts` (r:5 w:5) @@ -187,8 +191,12 @@ impl WeightInfo for HydraWeight { /// Proof: `Omnipool::HubAssetImbalance` (`max_values`: Some(1), `max_size`: Some(17), added: 512, mode: `MaxEncodedLen`) /// Storage: `DynamicFees::AssetFee` (r:2 w:0) /// Proof: `DynamicFees::AssetFee` (`max_values`: None, `max_size`: Some(24), added: 2499, mode: `MaxEncodedLen`) + /// Storage: `Duster::AccountBlacklist` (r:2 w:0) + /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::BannedAssets` (r:2 w:0) + /// Proof: `AssetRegistry::BannedAssets` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::Assets` (r:2 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:3 w:2) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) /// Storage: `MultiTransactionPayment::AccountCurrencyMap` (r:2 w:2) @@ -225,11 +233,11 @@ impl WeightInfo for HydraWeight { /// Proof: `Referrals::CounterForPendingConversions` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) fn sell() -> Weight { // Proof Size summary in bytes: - // Measured: `7179` + // Measured: `7327` // Estimated: `13905` - // Minimum execution time: 333_598_000 picoseconds. - Weight::from_parts(336_465_000, 13905) - .saturating_add(T::DbWeight::get().reads(35)) + // Minimum execution time: 360_954_000 picoseconds. + Weight::from_parts(362_880_000, 13905) + .saturating_add(T::DbWeight::get().reads(39)) .saturating_add(T::DbWeight::get().writes(23)) } /// Storage: `Omnipool::Assets` (r:3 w:3) @@ -240,8 +248,12 @@ impl WeightInfo for HydraWeight { /// Proof: `Omnipool::HubAssetImbalance` (`max_values`: Some(1), `max_size`: Some(17), added: 512, mode: `MaxEncodedLen`) /// Storage: `DynamicFees::AssetFee` (r:2 w:0) /// Proof: `DynamicFees::AssetFee` (`max_values`: None, `max_size`: Some(24), added: 2499, mode: `MaxEncodedLen`) + /// Storage: `Duster::AccountBlacklist` (r:2 w:0) + /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::BannedAssets` (r:2 w:0) + /// Proof: `AssetRegistry::BannedAssets` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::Assets` (r:2 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:3 w:2) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) /// Storage: `MultiTransactionPayment::AccountCurrencyMap` (r:2 w:2) @@ -278,11 +290,11 @@ impl WeightInfo for HydraWeight { /// Proof: `Referrals::CounterForPendingConversions` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) fn buy() -> Weight { // Proof Size summary in bytes: - // Measured: `7179` + // Measured: `7327` // Estimated: `13905` - // Minimum execution time: 333_688_000 picoseconds. - Weight::from_parts(335_133_000, 13905) - .saturating_add(T::DbWeight::get().reads(35)) + // Minimum execution time: 364_573_000 picoseconds. + Weight::from_parts(365_989_000, 13905) + .saturating_add(T::DbWeight::get().reads(39)) .saturating_add(T::DbWeight::get().writes(23)) } /// Storage: `Omnipool::Assets` (r:1 w:1) @@ -291,8 +303,8 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `1305` // Estimated: `3550` - // Minimum execution time: 32_634_000 picoseconds. - Weight::from_parts(33_024_000, 3550) + // Minimum execution time: 32_736_000 picoseconds. + Weight::from_parts(33_138_000, 3550) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -300,8 +312,12 @@ impl WeightInfo for HydraWeight { /// Proof: `Omnipool::Assets` (`max_values`: None, `max_size`: Some(85), added: 2560, mode: `MaxEncodedLen`) /// Storage: `Tokens::Accounts` (r:2 w:2) /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) + /// Storage: `Duster::AccountBlacklist` (r:1 w:0) + /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::BannedAssets` (r:1 w:0) + /// Proof: `AssetRegistry::BannedAssets` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::Assets` (r:1 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:2 w:2) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) /// Storage: `MultiTransactionPayment::AccountCurrencyMap` (r:1 w:1) @@ -310,11 +326,11 @@ impl WeightInfo for HydraWeight { /// Proof: `MultiTransactionPayment::AcceptedCurrencies` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) fn refund_refused_asset() -> Weight { // Proof Size summary in bytes: - // Measured: `2336` + // Measured: `2510` // Estimated: `6196` - // Minimum execution time: 107_435_000 picoseconds. - Weight::from_parts(108_211_000, 6196) - .saturating_add(T::DbWeight::get().reads(8)) + // Minimum execution time: 122_163_000 picoseconds. + Weight::from_parts(123_392_000, 6196) + .saturating_add(T::DbWeight::get().reads(10)) .saturating_add(T::DbWeight::get().writes(5)) } /// Storage: `Omnipool::Positions` (r:1 w:1) @@ -333,8 +349,8 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `2876` // Estimated: `3655` - // Minimum execution time: 75_289_000 picoseconds. - Weight::from_parts(76_090_000, 3655) + // Minimum execution time: 75_629_000 picoseconds. + Weight::from_parts(76_582_000, 3655) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(6)) } @@ -344,8 +360,8 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `1305` // Estimated: `3550` - // Minimum execution time: 32_857_000 picoseconds. - Weight::from_parts(33_349_000, 3550) + // Minimum execution time: 32_944_000 picoseconds. + Weight::from_parts(33_586_000, 3550) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -355,8 +371,12 @@ impl WeightInfo for HydraWeight { /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) /// Storage: `Omnipool::HubAssetImbalance` (r:1 w:1) /// Proof: `Omnipool::HubAssetImbalance` (`max_values`: Some(1), `max_size`: Some(17), added: 512, mode: `MaxEncodedLen`) + /// Storage: `Duster::AccountBlacklist` (r:1 w:0) + /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::BannedAssets` (r:1 w:0) + /// Proof: `AssetRegistry::BannedAssets` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::Assets` (r:2 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:2 w:1) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) /// Storage: `MultiTransactionPayment::AccountCurrencyMap` (r:1 w:0) @@ -369,11 +389,11 @@ impl WeightInfo for HydraWeight { /// Proof: `EmaOracle::Accumulator` (`max_values`: Some(1), `max_size`: Some(5921), added: 6416, mode: `MaxEncodedLen`) fn withdraw_protocol_liquidity() -> Weight { // Proof Size summary in bytes: - // Measured: `4019` + // Measured: `4205` // Estimated: `8739` - // Minimum execution time: 161_313_000 picoseconds. - Weight::from_parts(162_354_000, 8739) - .saturating_add(T::DbWeight::get().reads(13)) + // Minimum execution time: 174_415_000 picoseconds. + Weight::from_parts(174_998_000, 8739) + .saturating_add(T::DbWeight::get().reads(15)) .saturating_add(T::DbWeight::get().writes(8)) } /// Storage: `Omnipool::Assets` (r:1 w:1) @@ -383,9 +403,13 @@ impl WeightInfo for HydraWeight { /// Storage: `Omnipool::HubAssetImbalance` (r:1 w:1) /// Proof: `Omnipool::HubAssetImbalance` (`max_values`: Some(1), `max_size`: Some(17), added: 512, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::Assets` (r:2 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// Storage: `Tokens::TotalIssuance` (r:1 w:1) /// Proof: `Tokens::TotalIssuance` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) + /// Storage: `Duster::AccountBlacklist` (r:1 w:0) + /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::BannedAssets` (r:1 w:0) + /// Proof: `AssetRegistry::BannedAssets` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:2 w:2) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) /// Storage: `MultiTransactionPayment::AccountCurrencyMap` (r:2 w:0) @@ -394,11 +418,11 @@ impl WeightInfo for HydraWeight { /// Proof: `MultiTransactionPayment::AcceptedCurrencies` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) fn remove_token() -> Weight { // Proof Size summary in bytes: - // Measured: `3110` + // Measured: `3296` // Estimated: `11322` - // Minimum execution time: 160_104_000 picoseconds. - Weight::from_parts(161_947_000, 11322) - .saturating_add(T::DbWeight::get().reads(14)) + // Minimum execution time: 175_638_000 picoseconds. + Weight::from_parts(176_841_000, 11322) + .saturating_add(T::DbWeight::get().reads(16)) .saturating_add(T::DbWeight::get().writes(8)) } /// Storage: `Omnipool::Assets` (r:3 w:3) @@ -409,8 +433,12 @@ impl WeightInfo for HydraWeight { /// Proof: `Omnipool::HubAssetImbalance` (`max_values`: Some(1), `max_size`: Some(17), added: 512, mode: `MaxEncodedLen`) /// Storage: `DynamicFees::AssetFee` (r:2 w:0) /// Proof: `DynamicFees::AssetFee` (`max_values`: None, `max_size`: Some(24), added: 2499, mode: `MaxEncodedLen`) + /// Storage: `Duster::AccountBlacklist` (r:2 w:0) + /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::BannedAssets` (r:2 w:0) + /// Proof: `AssetRegistry::BannedAssets` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::Assets` (r:2 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:3 w:2) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) /// Storage: `MultiTransactionPayment::AccountCurrencyMap` (r:2 w:2) @@ -443,18 +471,16 @@ impl WeightInfo for HydraWeight { /// Proof: `Referrals::CounterForPendingConversions` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) /// The range of component `c` is `[1, 2]`. /// The range of component `e` is `[0, 1]`. - fn router_execution_sell(c: u32, e: u32, ) -> Weight { + fn router_execution_sell(_c: u32, e: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `1974 + e * (4750 ±0)` - // Estimated: `6156 + e * (7749 ±118_379_753_737_997_488)` - // Minimum execution time: 49_393_000 picoseconds. - Weight::from_parts(47_313_937, 6156) - // Standard Error: 84_954 - .saturating_add(Weight::from_parts(1_522_262, 0).saturating_mul(c.into())) - // Standard Error: 84_954 - .saturating_add(Weight::from_parts(288_560_770, 0).saturating_mul(e.into())) + // Measured: `1974 + e * (4936 ±0)` + // Estimated: `6156 + e * (7749 ±201_913_854_157_949_888)` + // Minimum execution time: 48_921_000 picoseconds. + Weight::from_parts(51_507_911, 6156) + // Standard Error: 122_017 + .saturating_add(Weight::from_parts(316_472_235, 0).saturating_mul(e.into())) .saturating_add(T::DbWeight::get().reads(7)) - .saturating_add(T::DbWeight::get().reads((25_u64).saturating_mul(e.into()))) + .saturating_add(T::DbWeight::get().reads((29_u64).saturating_mul(e.into()))) .saturating_add(T::DbWeight::get().writes((21_u64).saturating_mul(e.into()))) .saturating_add(Weight::from_parts(0, 7749).saturating_mul(e.into())) } @@ -466,8 +492,12 @@ impl WeightInfo for HydraWeight { /// Proof: `Omnipool::HubAssetImbalance` (`max_values`: Some(1), `max_size`: Some(17), added: 512, mode: `MaxEncodedLen`) /// Storage: `DynamicFees::AssetFee` (r:2 w:0) /// Proof: `DynamicFees::AssetFee` (`max_values`: None, `max_size`: Some(24), added: 2499, mode: `MaxEncodedLen`) + /// Storage: `Duster::AccountBlacklist` (r:2 w:0) + /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::BannedAssets` (r:2 w:0) + /// Proof: `AssetRegistry::BannedAssets` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::Assets` (r:2 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:3 w:2) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) /// Storage: `MultiTransactionPayment::AccountCurrencyMap` (r:2 w:2) @@ -500,17 +530,15 @@ impl WeightInfo for HydraWeight { /// Proof: `Referrals::CounterForPendingConversions` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) /// The range of component `c` is `[1, 2]`. /// The range of component `e` is `[0, 1]`. - fn router_execution_buy(c: u32, e: u32, ) -> Weight { + fn router_execution_buy(c: u32, _e: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `6724` + // Measured: `6910` // Estimated: `13905` - // Minimum execution time: 319_950_000 picoseconds. - Weight::from_parts(308_443_101, 13905) - // Standard Error: 135_443 - .saturating_add(Weight::from_parts(14_990_074, 0).saturating_mul(c.into())) - // Standard Error: 135_443 - .saturating_add(Weight::from_parts(285_316, 0).saturating_mul(e.into())) - .saturating_add(T::DbWeight::get().reads(32)) + // Minimum execution time: 350_132_000 picoseconds. + Weight::from_parts(340_475_478, 13905) + // Standard Error: 178_513 + .saturating_add(Weight::from_parts(13_719_977, 0).saturating_mul(c.into())) + .saturating_add(T::DbWeight::get().reads(36)) .saturating_add(T::DbWeight::get().writes(21)) } -} +} \ No newline at end of file diff --git a/runtime/hydradx/src/weights/omnipool_lm.rs b/runtime/hydradx/src/weights/omnipool_lm.rs index 534e2145a..2e257585f 100644 --- a/runtime/hydradx/src/weights/omnipool_lm.rs +++ b/runtime/hydradx/src/weights/omnipool_lm.rs @@ -18,45 +18,38 @@ //! Autogenerated weights for `pallet_omnipool_liquidity_mining` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-12-12, STEPS: `5`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-02-15, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `bench-bot`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` -//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 // Executed Command: // target/release/hydradx // benchmark // pallet -// --pallet=pallet-omnipool-liquidity-mining +// --chain=dev +// --steps=10 +// --repeat=30 // --wasm-execution=compiled // --heap-pages=4096 -// --chain=dev +// --template=.maintain/pallet-weight-template-no-back.hbs +// --pallet=pallet_omnipool_liquidity_mining +// --output=./weights/omnipool_lm.rs // --extrinsic=* -// --steps=5 -// --repeat=20 -// --output -// ./weights-1.1.0/omnipool_lm.rs -// --template -// .maintain/pallet-weight-template-no-back.hbs +#![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] -#![allow(clippy::unnecessary_cast)] +#![allow(missing_docs)] -use frame_support::{ - traits::Get, - weights::{constants::RocksDbWeight, Weight}, -}; -use sp_std::marker::PhantomData; +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; -use pallet_omnipool_liquidity_mining::weights::WeightInfo; - -/// Weights for pallet_omnipool_liquidity_mining using the hydraDX node and recommended hardware. +/// Weight functions for `pallet_omnipool_liquidity_mining`. pub struct HydraWeight(PhantomData); - -impl WeightInfo for HydraWeight { +impl pallet_omnipool_liquidity_mining::WeightInfo for HydraWeight { /// Storage: `AssetRegistry::Assets` (r:2 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:2 w:2) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) /// Storage: `OmnipoolWarehouseLM::FarmSequencer` (r:1 w:1) @@ -67,12 +60,12 @@ impl WeightInfo for HydraWeight { /// Proof: `OmnipoolWarehouseLM::GlobalFarm` (`max_values`: None, `max_size`: Some(205), added: 2680, mode: `MaxEncodedLen`) fn create_global_farm() -> Weight { // Proof Size summary in bytes: - // Measured: `462` + // Measured: `491` // Estimated: `6196` - // Minimum execution time: 104_411_000 picoseconds. - Weight::from_parts(105_372_000, 6196) - .saturating_add(T::DbWeight::get().reads(5_u64)) - .saturating_add(T::DbWeight::get().writes(5_u64)) + // Minimum execution time: 104_814_000 picoseconds. + Weight::from_parts(105_633_000, 6196) + .saturating_add(T::DbWeight::get().reads(5)) + .saturating_add(T::DbWeight::get().writes(5)) } /// Storage: `OmnipoolWarehouseLM::GlobalFarm` (r:1 w:1) /// Proof: `OmnipoolWarehouseLM::GlobalFarm` (`max_values`: None, `max_size`: Some(205), added: 2680, mode: `MaxEncodedLen`) @@ -84,10 +77,10 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `898` // Estimated: `6196` - // Minimum execution time: 101_766_000 picoseconds. - Weight::from_parts(102_892_000, 6196) - .saturating_add(T::DbWeight::get().reads(4_u64)) - .saturating_add(T::DbWeight::get().writes(4_u64)) + // Minimum execution time: 100_225_000 picoseconds. + Weight::from_parts(101_025_000, 6196) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().writes(4)) } /// Storage: `Omnipool::Assets` (r:1 w:0) /// Proof: `Omnipool::Assets` (`max_values`: None, `max_size`: Some(85), added: 2560, mode: `MaxEncodedLen`) @@ -96,7 +89,7 @@ impl WeightInfo for HydraWeight { /// Storage: `OmnipoolWarehouseLM::ActiveYieldFarm` (r:1 w:1) /// Proof: `OmnipoolWarehouseLM::ActiveYieldFarm` (`max_values`: None, `max_size`: Some(44), added: 2519, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::Assets` (r:1 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:2 w:2) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) /// Storage: `EmaOracle::Oracles` (r:2 w:0) @@ -107,12 +100,12 @@ impl WeightInfo for HydraWeight { /// Proof: `OmnipoolWarehouseLM::YieldFarm` (`max_values`: None, `max_size`: Some(198), added: 2673, mode: `MaxEncodedLen`) fn create_yield_farm() -> Weight { // Proof Size summary in bytes: - // Measured: `2287` + // Measured: `2271` // Estimated: `6294` - // Minimum execution time: 140_071_000 picoseconds. - Weight::from_parts(141_599_000, 6294) - .saturating_add(T::DbWeight::get().reads(9_u64)) - .saturating_add(T::DbWeight::get().writes(6_u64)) + // Minimum execution time: 140_947_000 picoseconds. + Weight::from_parts(141_851_000, 6294) + .saturating_add(T::DbWeight::get().reads(9)) + .saturating_add(T::DbWeight::get().writes(6)) } /// Storage: `Omnipool::Assets` (r:1 w:0) /// Proof: `Omnipool::Assets` (`max_values`: None, `max_size`: Some(85), added: 2560, mode: `MaxEncodedLen`) @@ -123,19 +116,19 @@ impl WeightInfo for HydraWeight { /// Storage: `OmnipoolWarehouseLM::GlobalFarm` (r:1 w:1) /// Proof: `OmnipoolWarehouseLM::GlobalFarm` (`max_values`: None, `max_size`: Some(205), added: 2680, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::Assets` (r:1 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:2 w:2) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) /// Storage: `EmaOracle::Oracles` (r:2 w:0) /// Proof: `EmaOracle::Oracles` (`max_values`: None, `max_size`: Some(177), added: 2652, mode: `MaxEncodedLen`) fn update_yield_farm() -> Weight { // Proof Size summary in bytes: - // Measured: `2457` + // Measured: `2441` // Estimated: `6294` - // Minimum execution time: 145_051_000 picoseconds. - Weight::from_parts(146_213_000, 6294) - .saturating_add(T::DbWeight::get().reads(9_u64)) - .saturating_add(T::DbWeight::get().writes(4_u64)) + // Minimum execution time: 145_933_000 picoseconds. + Weight::from_parts(147_109_000, 6294) + .saturating_add(T::DbWeight::get().reads(9)) + .saturating_add(T::DbWeight::get().writes(4)) } /// Storage: `OmnipoolWarehouseLM::ActiveYieldFarm` (r:1 w:1) /// Proof: `OmnipoolWarehouseLM::ActiveYieldFarm` (`max_values`: None, `max_size`: Some(44), added: 2519, mode: `MaxEncodedLen`) @@ -144,19 +137,19 @@ impl WeightInfo for HydraWeight { /// Storage: `OmnipoolWarehouseLM::GlobalFarm` (r:1 w:1) /// Proof: `OmnipoolWarehouseLM::GlobalFarm` (`max_values`: None, `max_size`: Some(205), added: 2680, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::Assets` (r:1 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:2 w:2) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) /// Storage: `EmaOracle::Oracles` (r:2 w:0) /// Proof: `EmaOracle::Oracles` (`max_values`: None, `max_size`: Some(177), added: 2652, mode: `MaxEncodedLen`) fn stop_yield_farm() -> Weight { // Proof Size summary in bytes: - // Measured: `2096` + // Measured: `2080` // Estimated: `6294` - // Minimum execution time: 139_750_000 picoseconds. - Weight::from_parts(140_646_000, 6294) - .saturating_add(T::DbWeight::get().reads(8_u64)) - .saturating_add(T::DbWeight::get().writes(5_u64)) + // Minimum execution time: 138_770_000 picoseconds. + Weight::from_parts(140_134_000, 6294) + .saturating_add(T::DbWeight::get().reads(8)) + .saturating_add(T::DbWeight::get().writes(5)) } /// Storage: `Omnipool::Assets` (r:1 w:0) /// Proof: `Omnipool::Assets` (`max_values`: None, `max_size`: Some(85), added: 2560, mode: `MaxEncodedLen`) @@ -167,19 +160,19 @@ impl WeightInfo for HydraWeight { /// Storage: `OmnipoolWarehouseLM::GlobalFarm` (r:1 w:1) /// Proof: `OmnipoolWarehouseLM::GlobalFarm` (`max_values`: None, `max_size`: Some(205), added: 2680, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::Assets` (r:1 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:2 w:2) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) /// Storage: `EmaOracle::Oracles` (r:2 w:0) /// Proof: `EmaOracle::Oracles` (`max_values`: None, `max_size`: Some(177), added: 2652, mode: `MaxEncodedLen`) fn resume_yield_farm() -> Weight { // Proof Size summary in bytes: - // Measured: `2493` + // Measured: `2477` // Estimated: `6294` - // Minimum execution time: 141_404_000 picoseconds. - Weight::from_parts(142_349_000, 6294) - .saturating_add(T::DbWeight::get().reads(9_u64)) - .saturating_add(T::DbWeight::get().writes(5_u64)) + // Minimum execution time: 140_945_000 picoseconds. + Weight::from_parts(142_502_000, 6294) + .saturating_add(T::DbWeight::get().reads(9)) + .saturating_add(T::DbWeight::get().writes(5)) } /// Storage: `OmnipoolWarehouseLM::ActiveYieldFarm` (r:1 w:0) /// Proof: `OmnipoolWarehouseLM::ActiveYieldFarm` (`max_values`: None, `max_size`: Some(44), added: 2519, mode: `MaxEncodedLen`) @@ -193,10 +186,10 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `924` // Estimated: `6196` - // Minimum execution time: 90_529_000 picoseconds. - Weight::from_parts(91_011_000, 6196) - .saturating_add(T::DbWeight::get().reads(5_u64)) - .saturating_add(T::DbWeight::get().writes(4_u64)) + // Minimum execution time: 89_994_000 picoseconds. + Weight::from_parts(90_683_000, 6196) + .saturating_add(T::DbWeight::get().reads(5)) + .saturating_add(T::DbWeight::get().writes(4)) } /// Storage: `Uniques::Asset` (r:2 w:2) /// Proof: `Uniques::Asset` (`max_values`: None, `max_size`: Some(146), added: 2621, mode: `MaxEncodedLen`) @@ -209,7 +202,7 @@ impl WeightInfo for HydraWeight { /// Storage: `OmnipoolWarehouseLM::GlobalFarm` (r:1 w:1) /// Proof: `OmnipoolWarehouseLM::GlobalFarm` (`max_values`: None, `max_size`: Some(205), added: 2680, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::Assets` (r:1 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:2 w:2) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) /// Storage: `EmaOracle::Oracles` (r:4 w:0) @@ -230,12 +223,12 @@ impl WeightInfo for HydraWeight { /// Proof: `OmnipoolWarehouseLM::Deposit` (`max_values`: None, `max_size`: Some(385), added: 2860, mode: `MaxEncodedLen`) fn deposit_shares() -> Weight { // Proof Size summary in bytes: - // Measured: `3989` + // Measured: `3973` // Estimated: `11598` - // Minimum execution time: 240_264_000 picoseconds. - Weight::from_parts(241_286_000, 11598) - .saturating_add(T::DbWeight::get().reads(17_u64)) - .saturating_add(T::DbWeight::get().writes(14_u64)) + // Minimum execution time: 236_325_000 picoseconds. + Weight::from_parts(239_018_000, 11598) + .saturating_add(T::DbWeight::get().reads(17)) + .saturating_add(T::DbWeight::get().writes(14)) } /// Storage: `Uniques::Asset` (r:2 w:0) /// Proof: `Uniques::Asset` (`max_values`: None, `max_size`: Some(146), added: 2621, mode: `MaxEncodedLen`) @@ -252,19 +245,19 @@ impl WeightInfo for HydraWeight { /// Storage: `OmnipoolWarehouseLM::GlobalFarm` (r:1 w:1) /// Proof: `OmnipoolWarehouseLM::GlobalFarm` (`max_values`: None, `max_size`: Some(205), added: 2680, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::Assets` (r:1 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:2 w:2) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) /// Storage: `EmaOracle::Oracles` (r:4 w:0) /// Proof: `EmaOracle::Oracles` (`max_values`: None, `max_size`: Some(177), added: 2652, mode: `MaxEncodedLen`) fn redeposit_shares() -> Weight { // Proof Size summary in bytes: - // Measured: `4331` + // Measured: `4315` // Estimated: `11598` - // Minimum execution time: 195_833_000 picoseconds. - Weight::from_parts(196_912_000, 11598) - .saturating_add(T::DbWeight::get().reads(15_u64)) - .saturating_add(T::DbWeight::get().writes(5_u64)) + // Minimum execution time: 197_087_000 picoseconds. + Weight::from_parts(198_393_000, 11598) + .saturating_add(T::DbWeight::get().reads(15)) + .saturating_add(T::DbWeight::get().writes(5)) } /// Storage: `Uniques::Asset` (r:1 w:0) /// Proof: `Uniques::Asset` (`max_values`: None, `max_size`: Some(146), added: 2621, mode: `MaxEncodedLen`) @@ -275,19 +268,19 @@ impl WeightInfo for HydraWeight { /// Storage: `OmnipoolWarehouseLM::GlobalFarm` (r:1 w:1) /// Proof: `OmnipoolWarehouseLM::GlobalFarm` (`max_values`: None, `max_size`: Some(205), added: 2680, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::Assets` (r:1 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:3 w:3) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) /// Storage: `EmaOracle::Oracles` (r:2 w:0) /// Proof: `EmaOracle::Oracles` (`max_values`: None, `max_size`: Some(177), added: 2652, mode: `MaxEncodedLen`) fn claim_rewards() -> Weight { // Proof Size summary in bytes: - // Measured: `2896` + // Measured: `2880` // Estimated: `8799` - // Minimum execution time: 195_680_000 picoseconds. - Weight::from_parts(196_827_000, 8799) - .saturating_add(T::DbWeight::get().reads(10_u64)) - .saturating_add(T::DbWeight::get().writes(6_u64)) + // Minimum execution time: 195_915_000 picoseconds. + Weight::from_parts(197_475_000, 8799) + .saturating_add(T::DbWeight::get().reads(10)) + .saturating_add(T::DbWeight::get().writes(6)) } /// Storage: `Uniques::Asset` (r:2 w:2) /// Proof: `Uniques::Asset` (`max_values`: None, `max_size`: Some(146), added: 2621, mode: `MaxEncodedLen`) @@ -302,7 +295,7 @@ impl WeightInfo for HydraWeight { /// Storage: `OmnipoolWarehouseLM::GlobalFarm` (r:1 w:1) /// Proof: `OmnipoolWarehouseLM::GlobalFarm` (`max_values`: None, `max_size`: Some(205), added: 2680, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::Assets` (r:1 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:3 w:3) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) /// Storage: `EmaOracle::Oracles` (r:2 w:0) @@ -315,11 +308,11 @@ impl WeightInfo for HydraWeight { /// Proof: `Uniques::ItemPriceOf` (`max_values`: None, `max_size`: Some(113), added: 2588, mode: `MaxEncodedLen`) fn withdraw_shares() -> Weight { // Proof Size summary in bytes: - // Measured: `3857` + // Measured: `3841` // Estimated: `8799` - // Minimum execution time: 294_229_000 picoseconds. - Weight::from_parts(296_004_000, 8799) - .saturating_add(T::DbWeight::get().reads(15_u64)) - .saturating_add(T::DbWeight::get().writes(15_u64)) + // Minimum execution time: 294_171_000 picoseconds. + Weight::from_parts(296_256_000, 8799) + .saturating_add(T::DbWeight::get().reads(15)) + .saturating_add(T::DbWeight::get().writes(15)) } -} +} \ No newline at end of file diff --git a/runtime/hydradx/src/weights/otc.rs b/runtime/hydradx/src/weights/otc.rs index d26b68380..9911cb4cd 100644 --- a/runtime/hydradx/src/weights/otc.rs +++ b/runtime/hydradx/src/weights/otc.rs @@ -18,113 +18,118 @@ //! Autogenerated weights for `pallet_otc` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-12-12, STEPS: `5`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-02-15, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `bench-bot`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` -//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 // Executed Command: // target/release/hydradx // benchmark // pallet -// --pallet=pallet-otc +// --chain=dev +// --steps=10 +// --repeat=30 // --wasm-execution=compiled // --heap-pages=4096 -// --chain=dev +// --template=.maintain/pallet-weight-template-no-back.hbs +// --pallet=pallet_otc +// --output=./weights/otc.rs // --extrinsic=* -// --steps=5 -// --repeat=20 -// --output -// ./weights-1.1.0/otc.rs -// --template -// .maintain/pallet-weight-template-no-back.hbs +#![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] -#![allow(clippy::unnecessary_cast)] +#![allow(missing_docs)] -use frame_support::{ - traits::Get, - weights::{constants::RocksDbWeight, Weight}, -}; -use sp_std::marker::PhantomData; +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; use pallet_otc::weights::WeightInfo; -/// Weights for pallet_otc using the hydraDX node and recommended hardware. +/// Weight functions for `pallet_otc`. pub struct HydraWeight(PhantomData); - impl WeightInfo for HydraWeight { /// Storage: `AssetRegistry::Assets` (r:2 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// Storage: `OTC::NextOrderId` (r:1 w:1) /// Proof: `OTC::NextOrderId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) - /// Storage: `Balances::Reserves` (r:1 w:1) - /// Proof: `Balances::Reserves` (`max_values`: None, `max_size`: Some(1249), added: 3724, mode: `MaxEncodedLen`) - /// Storage: `System::Account` (r:1 w:1) - /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Tokens::Reserves` (r:1 w:1) + /// Proof: `Tokens::Reserves` (`max_values`: None, `max_size`: Some(1261), added: 3736, mode: `MaxEncodedLen`) + /// Storage: `Tokens::Accounts` (r:1 w:1) + /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) /// Storage: `OTC::Orders` (r:0 w:1) /// Proof: `OTC::Orders` (`max_values`: None, `max_size`: Some(93), added: 2568, mode: `MaxEncodedLen`) fn place_order() -> Weight { // Proof Size summary in bytes: - // Measured: `624` - // Estimated: `6114` - // Minimum execution time: 54_176_000 picoseconds. - Weight::from_parts(54_920_000, 6114) - .saturating_add(T::DbWeight::get().reads(5_u64)) - .saturating_add(T::DbWeight::get().writes(4_u64)) + // Measured: `897` + // Estimated: `6190` + // Minimum execution time: 55_411_000 picoseconds. + Weight::from_parts(56_027_000, 6190) + .saturating_add(T::DbWeight::get().reads(5)) + .saturating_add(T::DbWeight::get().writes(4)) } /// Storage: `OTC::Orders` (r:1 w:1) /// Proof: `OTC::Orders` (`max_values`: None, `max_size`: Some(93), added: 2568, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::Assets` (r:2 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) - /// Storage: `Tokens::Accounts` (r:2 w:2) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) + /// Storage: `Duster::AccountBlacklist` (r:2 w:0) + /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::BannedAssets` (r:2 w:0) + /// Proof: `AssetRegistry::BannedAssets` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`) + /// Storage: `Tokens::Accounts` (r:4 w:4) /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) - /// Storage: `System::Account` (r:2 w:2) + /// Storage: `System::Account` (r:2 w:0) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) - /// Storage: `Balances::Reserves` (r:1 w:1) - /// Proof: `Balances::Reserves` (`max_values`: None, `max_size`: Some(1249), added: 3724, mode: `MaxEncodedLen`) + /// Storage: `Tokens::Reserves` (r:1 w:1) + /// Proof: `Tokens::Reserves` (`max_values`: None, `max_size`: Some(1261), added: 3736, mode: `MaxEncodedLen`) fn partial_fill_order() -> Weight { // Proof Size summary in bytes: - // Measured: `1404` - // Estimated: `6196` - // Minimum execution time: 138_354_000 picoseconds. - Weight::from_parts(140_113_000, 6196) - .saturating_add(T::DbWeight::get().reads(8_u64)) - .saturating_add(T::DbWeight::get().writes(6_u64)) + // Measured: `1882` + // Estimated: `11322` + // Minimum execution time: 138_653_000 picoseconds. + Weight::from_parts(139_630_000, 11322) + .saturating_add(T::DbWeight::get().reads(14)) + .saturating_add(T::DbWeight::get().writes(6)) } /// Storage: `OTC::Orders` (r:1 w:1) /// Proof: `OTC::Orders` (`max_values`: None, `max_size`: Some(93), added: 2568, mode: `MaxEncodedLen`) - /// Storage: `Tokens::Accounts` (r:2 w:2) + /// Storage: `Duster::AccountBlacklist` (r:2 w:0) + /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::BannedAssets` (r:2 w:0) + /// Proof: `AssetRegistry::BannedAssets` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`) + /// Storage: `Tokens::Accounts` (r:4 w:4) /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::Assets` (r:1 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) - /// Storage: `System::Account` (r:2 w:2) + /// Storage: `AssetRegistry::Assets` (r:2 w:0) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:2 w:0) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) - /// Storage: `Balances::Reserves` (r:1 w:1) - /// Proof: `Balances::Reserves` (`max_values`: None, `max_size`: Some(1249), added: 3724, mode: `MaxEncodedLen`) + /// Storage: `Tokens::Reserves` (r:1 w:1) + /// Proof: `Tokens::Reserves` (`max_values`: None, `max_size`: Some(1261), added: 3736, mode: `MaxEncodedLen`) fn fill_order() -> Weight { // Proof Size summary in bytes: - // Measured: `1399` - // Estimated: `6196` - // Minimum execution time: 136_927_000 picoseconds. - Weight::from_parts(137_782_000, 6196) - .saturating_add(T::DbWeight::get().reads(7_u64)) - .saturating_add(T::DbWeight::get().writes(6_u64)) + // Measured: `1882` + // Estimated: `11322` + // Minimum execution time: 135_774_000 picoseconds. + Weight::from_parts(137_332_000, 11322) + .saturating_add(T::DbWeight::get().reads(14)) + .saturating_add(T::DbWeight::get().writes(6)) } /// Storage: `OTC::Orders` (r:1 w:1) /// Proof: `OTC::Orders` (`max_values`: None, `max_size`: Some(93), added: 2568, mode: `MaxEncodedLen`) - /// Storage: `Balances::Reserves` (r:1 w:1) - /// Proof: `Balances::Reserves` (`max_values`: None, `max_size`: Some(1249), added: 3724, mode: `MaxEncodedLen`) - /// Storage: `System::Account` (r:1 w:1) - /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Tokens::Reserves` (r:1 w:1) + /// Proof: `Tokens::Reserves` (`max_values`: None, `max_size`: Some(1261), added: 3736, mode: `MaxEncodedLen`) + /// Storage: `Tokens::Accounts` (r:1 w:1) + /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::Assets` (r:1 w:0) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) fn cancel_order() -> Weight { // Proof Size summary in bytes: - // Measured: `525` - // Estimated: `4714` - // Minimum execution time: 44_402_000 picoseconds. - Weight::from_parts(44_773_000, 4714) - .saturating_add(T::DbWeight::get().reads(3_u64)) - .saturating_add(T::DbWeight::get().writes(3_u64)) + // Measured: `1131` + // Estimated: `4726` + // Minimum execution time: 50_061_000 picoseconds. + Weight::from_parts(50_721_000, 4726) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().writes(3)) } } diff --git a/runtime/hydradx/src/weights/payment.rs b/runtime/hydradx/src/weights/payment.rs index f3b1b6eeb..6faa12376 100644 --- a/runtime/hydradx/src/weights/payment.rs +++ b/runtime/hydradx/src/weights/payment.rs @@ -18,7 +18,7 @@ //! Autogenerated weights for `pallet_transaction_multi_payment` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-12-27, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-02-15, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `bench-bot`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 @@ -33,26 +33,22 @@ // --wasm-execution=compiled // --heap-pages=4096 // --template=.maintain/pallet-weight-template-no-back.hbs -// --pallet=pallet-transaction-multi-payment -// --output=weights-1.1.0/transaction_multi_payment.rs +// --pallet=pallet_transaction_multi_payment +// --output=./weights/payment.rs // --extrinsic=* #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] -#![allow(clippy::unnecessary_cast)] +#![allow(missing_docs)] -use frame_support::{ - traits::Get, - weights::{constants::RocksDbWeight, Weight}, -}; -use sp_std::marker::PhantomData; +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; use pallet_transaction_multi_payment::weights::WeightInfo; -/// Weights for pallet_transaction_multi_payment using the hydraDX node and recommended hardware. +/// Weight functions for `pallet_transaction_multi_payment`. pub struct HydraWeight(PhantomData); - impl WeightInfo for HydraWeight { /// Storage: `MultiTransactionPayment::AcceptedCurrencies` (r:1 w:1) /// Proof: `MultiTransactionPayment::AcceptedCurrencies` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) @@ -60,8 +56,8 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `1176` // Estimated: `3493` - // Minimum execution time: 24_548_000 picoseconds. - Weight::from_parts(25_118_000, 3493) + // Minimum execution time: 24_211_000 picoseconds. + Weight::from_parts(24_571_000, 3493) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -71,8 +67,8 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `1207` // Estimated: `3493` - // Minimum execution time: 25_178_000 picoseconds. - Weight::from_parts(25_545_000, 3493) + // Minimum execution time: 24_768_000 picoseconds. + Weight::from_parts(24_992_000, 3493) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -84,8 +80,8 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `1241` // Estimated: `3493` - // Minimum execution time: 30_284_000 picoseconds. - Weight::from_parts(30_744_000, 3493) + // Minimum execution time: 30_095_000 picoseconds. + Weight::from_parts(30_539_000, 3493) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -97,8 +93,8 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `3221` // Estimated: `27510` - // Minimum execution time: 93_281_000 picoseconds. - Weight::from_parts(94_259_000, 27510) + // Minimum execution time: 94_272_000 picoseconds. + Weight::from_parts(95_196_000, 27510) .saturating_add(T::DbWeight::get().reads(11)) } } diff --git a/runtime/hydradx/src/weights/preimage.rs b/runtime/hydradx/src/weights/preimage.rs index 8e3671a5c..60afab1b5 100644 --- a/runtime/hydradx/src/weights/preimage.rs +++ b/runtime/hydradx/src/weights/preimage.rs @@ -18,89 +18,83 @@ //! Autogenerated weights for `pallet_preimage` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-12-12, STEPS: `5`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-02-15, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `bench-bot`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` -//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 // Executed Command: // target/release/hydradx // benchmark // pallet -// --pallet=pallet-preimage +// --chain=dev +// --steps=10 +// --repeat=30 // --wasm-execution=compiled // --heap-pages=4096 -// --chain=dev +// --template=.maintain/pallet-weight-template-no-back.hbs +// --pallet=pallet-preimage +// --output=./weights/preimage.rs // --extrinsic=* -// --steps=5 -// --repeat=20 -// --output -// ./weights-1.1.0/preimage.rs -// --template -// .maintain/pallet-weight-template-no-back.hbs +#![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] -#![allow(clippy::unnecessary_cast)] - -use frame_support::{ - traits::Get, - weights::{constants::RocksDbWeight, Weight}, -}; -use sp_std::marker::PhantomData; +#![allow(missing_docs)] -use pallet_preimage::weights::WeightInfo; +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; +/// Weight functions for `pallet_preimage`. pub struct HydraWeight(PhantomData); - -impl WeightInfo for HydraWeight { +impl pallet_preimage::WeightInfo for HydraWeight { /// Storage: `Preimage::StatusFor` (r:1 w:1) /// Proof: `Preimage::StatusFor` (`max_values`: None, `max_size`: Some(91), added: 2566, mode: `MaxEncodedLen`) /// Storage: `Preimage::PreimageFor` (r:0 w:1) /// Proof: `Preimage::PreimageFor` (`max_values`: None, `max_size`: Some(4194344), added: 4196819, mode: `MaxEncodedLen`) /// The range of component `s` is `[0, 4194304]`. - fn note_preimage(s: u32) -> Weight { + fn note_preimage(s: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `210` // Estimated: `3556` - // Minimum execution time: 41_621_000 picoseconds. - Weight::from_parts(42_113_000, 3556) - // Standard Error: 2 - .saturating_add(Weight::from_parts(1_993, 0).saturating_mul(s.into())) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) + // Minimum execution time: 41_276_000 picoseconds. + Weight::from_parts(41_498_000, 3556) + // Standard Error: 1 + .saturating_add(Weight::from_parts(1_985, 0).saturating_mul(s.into())) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(2)) } /// Storage: `Preimage::StatusFor` (r:1 w:1) /// Proof: `Preimage::StatusFor` (`max_values`: None, `max_size`: Some(91), added: 2566, mode: `MaxEncodedLen`) /// Storage: `Preimage::PreimageFor` (r:0 w:1) /// Proof: `Preimage::PreimageFor` (`max_values`: None, `max_size`: Some(4194344), added: 4196819, mode: `MaxEncodedLen`) /// The range of component `s` is `[0, 4194304]`. - fn note_requested_preimage(s: u32) -> Weight { + fn note_requested_preimage(s: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `173` // Estimated: `3556` - // Minimum execution time: 23_232_000 picoseconds. - Weight::from_parts(23_575_000, 3556) - // Standard Error: 3 - .saturating_add(Weight::from_parts(1_998, 0).saturating_mul(s.into())) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) + // Minimum execution time: 23_090_000 picoseconds. + Weight::from_parts(23_405_000, 3556) + // Standard Error: 9 + .saturating_add(Weight::from_parts(2_041, 0).saturating_mul(s.into())) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(2)) } /// Storage: `Preimage::StatusFor` (r:1 w:1) /// Proof: `Preimage::StatusFor` (`max_values`: None, `max_size`: Some(91), added: 2566, mode: `MaxEncodedLen`) /// Storage: `Preimage::PreimageFor` (r:0 w:1) /// Proof: `Preimage::PreimageFor` (`max_values`: None, `max_size`: Some(4194344), added: 4196819, mode: `MaxEncodedLen`) /// The range of component `s` is `[0, 4194304]`. - fn note_no_deposit_preimage(s: u32) -> Weight { + fn note_no_deposit_preimage(s: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `173` // Estimated: `3556` - // Minimum execution time: 22_316_000 picoseconds. - Weight::from_parts(22_663_000, 3556) - // Standard Error: 2 - .saturating_add(Weight::from_parts(1_995, 0).saturating_mul(s.into())) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) + // Minimum execution time: 22_229_000 picoseconds. + Weight::from_parts(8_603_845, 3556) + // Standard Error: 8 + .saturating_add(Weight::from_parts(1_999, 0).saturating_mul(s.into())) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(2)) } /// Storage: `Preimage::StatusFor` (r:1 w:1) /// Proof: `Preimage::StatusFor` (`max_values`: None, `max_size`: Some(91), added: 2566, mode: `MaxEncodedLen`) @@ -110,10 +104,10 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `356` // Estimated: `3556` - // Minimum execution time: 52_679_000 picoseconds. - Weight::from_parts(53_474_000, 3556) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) + // Minimum execution time: 53_648_000 picoseconds. + Weight::from_parts(55_277_000, 3556) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(2)) } /// Storage: `Preimage::StatusFor` (r:1 w:1) /// Proof: `Preimage::StatusFor` (`max_values`: None, `max_size`: Some(91), added: 2566, mode: `MaxEncodedLen`) @@ -123,10 +117,10 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `211` // Estimated: `3556` - // Minimum execution time: 31_545_000 picoseconds. - Weight::from_parts(32_646_000, 3556) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) + // Minimum execution time: 31_781_000 picoseconds. + Weight::from_parts(32_720_000, 3556) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(2)) } /// Storage: `Preimage::StatusFor` (r:1 w:1) /// Proof: `Preimage::StatusFor` (`max_values`: None, `max_size`: Some(91), added: 2566, mode: `MaxEncodedLen`) @@ -134,10 +128,10 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `255` // Estimated: `3556` - // Minimum execution time: 28_243_000 picoseconds. - Weight::from_parts(29_512_000, 3556) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 28_938_000 picoseconds. + Weight::from_parts(29_985_000, 3556) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `Preimage::StatusFor` (r:1 w:1) /// Proof: `Preimage::StatusFor` (`max_values`: None, `max_size`: Some(91), added: 2566, mode: `MaxEncodedLen`) @@ -145,10 +139,10 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `211` // Estimated: `3556` - // Minimum execution time: 17_312_000 picoseconds. - Weight::from_parts(18_097_000, 3556) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 17_683_000 picoseconds. + Weight::from_parts(18_217_000, 3556) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `Preimage::StatusFor` (r:1 w:1) /// Proof: `Preimage::StatusFor` (`max_values`: None, `max_size`: Some(91), added: 2566, mode: `MaxEncodedLen`) @@ -156,10 +150,10 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `109` // Estimated: `3556` - // Minimum execution time: 18_766_000 picoseconds. - Weight::from_parts(19_233_000, 3556) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 18_566_000 picoseconds. + Weight::from_parts(19_082_000, 3556) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `Preimage::StatusFor` (r:1 w:1) /// Proof: `Preimage::StatusFor` (`max_values`: None, `max_size`: Some(91), added: 2566, mode: `MaxEncodedLen`) @@ -167,10 +161,10 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `173` // Estimated: `3556` - // Minimum execution time: 12_350_000 picoseconds. - Weight::from_parts(12_757_000, 3556) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 12_526_000 picoseconds. + Weight::from_parts(12_808_000, 3556) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `Preimage::StatusFor` (r:1 w:1) /// Proof: `Preimage::StatusFor` (`max_values`: None, `max_size`: Some(91), added: 2566, mode: `MaxEncodedLen`) @@ -180,10 +174,10 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `211` // Estimated: `3556` - // Minimum execution time: 30_134_000 picoseconds. - Weight::from_parts(31_219_000, 3556) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) + // Minimum execution time: 29_887_000 picoseconds. + Weight::from_parts(30_842_000, 3556) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(2)) } /// Storage: `Preimage::StatusFor` (r:1 w:1) /// Proof: `Preimage::StatusFor` (`max_values`: None, `max_size`: Some(91), added: 2566, mode: `MaxEncodedLen`) @@ -191,10 +185,10 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `173` // Estimated: `3556` - // Minimum execution time: 12_288_000 picoseconds. - Weight::from_parts(12_700_000, 3556) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 12_510_000 picoseconds. + Weight::from_parts(12_886_000, 3556) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `Preimage::StatusFor` (r:1 w:1) /// Proof: `Preimage::StatusFor` (`max_values`: None, `max_size`: Some(91), added: 2566, mode: `MaxEncodedLen`) @@ -202,9 +196,9 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `173` // Estimated: `3556` - // Minimum execution time: 12_628_000 picoseconds. - Weight::from_parts(12_949_000, 3556) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 12_820_000 picoseconds. + Weight::from_parts(13_056_000, 3556) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } -} +} \ No newline at end of file diff --git a/runtime/hydradx/src/weights/proxy.rs b/runtime/hydradx/src/weights/proxy.rs index ecc53ef07..efa83756f 100644 --- a/runtime/hydradx/src/weights/proxy.rs +++ b/runtime/hydradx/src/weights/proxy.rs @@ -18,55 +18,48 @@ //! Autogenerated weights for `pallet_proxy` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-12-12, STEPS: `5`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-02-15, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `bench-bot`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` -//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 // Executed Command: // target/release/hydradx // benchmark // pallet -// --pallet=pallet-proxy +// --chain=dev +// --steps=10 +// --repeat=30 // --wasm-execution=compiled // --heap-pages=4096 -// --chain=dev +// --template=.maintain/pallet-weight-template-no-back.hbs +// --pallet=pallet-proxy +// --output=./weights/proxy.rs // --extrinsic=* -// --steps=5 -// --repeat=20 -// --output -// ./weights-1.1.0/proxy.rs -// --template -// .maintain/pallet-weight-template-no-back.hbs +#![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] -#![allow(clippy::unnecessary_cast)] - -use frame_support::{ - traits::Get, - weights::{constants::RocksDbWeight, Weight}, -}; -use sp_std::marker::PhantomData; +#![allow(missing_docs)] -use pallet_proxy::weights::WeightInfo; +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; -/// Weights for pallet_proxy using the hydraDX node and recommended hardware. +/// Weight functions for `pallet_proxy`. pub struct HydraWeight(PhantomData); - -impl WeightInfo for HydraWeight { +impl pallet_proxy::WeightInfo for HydraWeight { /// Storage: `Proxy::Proxies` (r:1 w:0) /// Proof: `Proxy::Proxies` (`max_values`: None, `max_size`: Some(1241), added: 3716, mode: `MaxEncodedLen`) /// The range of component `p` is `[1, 31]`. - fn proxy(p: u32) -> Weight { + fn proxy(p: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `293 + p * (37 ±0)` // Estimated: `4706` - // Minimum execution time: 22_719_000 picoseconds. - Weight::from_parts(23_093_311, 4706) - // Standard Error: 1_907 - .saturating_add(Weight::from_parts(38_448, 0).saturating_mul(p.into())) - .saturating_add(T::DbWeight::get().reads(1_u64)) + // Minimum execution time: 23_362_000 picoseconds. + Weight::from_parts(23_716_894, 4706) + // Standard Error: 1_411 + .saturating_add(Weight::from_parts(31_936, 0).saturating_mul(p.into())) + .saturating_add(T::DbWeight::get().reads(1)) } /// Storage: `Proxy::Proxies` (r:1 w:0) /// Proof: `Proxy::Proxies` (`max_values`: None, `max_size`: Some(1241), added: 3716, mode: `MaxEncodedLen`) @@ -76,18 +69,18 @@ impl WeightInfo for HydraWeight { /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) /// The range of component `a` is `[0, 31]`. /// The range of component `p` is `[1, 31]`. - fn proxy_announced(a: u32, p: u32) -> Weight { + fn proxy_announced(a: u32, p: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `620 + a * (68 ±0) + p * (37 ±0)` // Estimated: `5698` - // Minimum execution time: 51_590_000 picoseconds. - Weight::from_parts(50_716_699, 5698) - // Standard Error: 4_159 - .saturating_add(Weight::from_parts(178_083, 0).saturating_mul(a.into())) - // Standard Error: 4_325 - .saturating_add(Weight::from_parts(30_784, 0).saturating_mul(p.into())) - .saturating_add(T::DbWeight::get().reads(3_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) + // Minimum execution time: 51_500_000 picoseconds. + Weight::from_parts(51_077_709, 5698) + // Standard Error: 2_902 + .saturating_add(Weight::from_parts(168_254, 0).saturating_mul(a.into())) + // Standard Error: 3_017 + .saturating_add(Weight::from_parts(29_333, 0).saturating_mul(p.into())) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(2)) } /// Storage: `Proxy::Announcements` (r:1 w:1) /// Proof: `Proxy::Announcements` (`max_values`: None, `max_size`: Some(2233), added: 4708, mode: `MaxEncodedLen`) @@ -95,16 +88,16 @@ impl WeightInfo for HydraWeight { /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) /// The range of component `a` is `[0, 31]`. /// The range of component `p` is `[1, 31]`. - fn remove_announcement(a: u32, _p: u32) -> Weight { + fn remove_announcement(a: u32, _p: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `535 + a * (68 ±0)` // Estimated: `5698` - // Minimum execution time: 34_482_000 picoseconds. - Weight::from_parts(34_652_525, 5698) - // Standard Error: 4_201 - .saturating_add(Weight::from_parts(155_744, 0).saturating_mul(a.into())) - .saturating_add(T::DbWeight::get().reads(2_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) + // Minimum execution time: 34_322_000 picoseconds. + Weight::from_parts(34_848_430, 5698) + // Standard Error: 2_484 + .saturating_add(Weight::from_parts(157_646, 0).saturating_mul(a.into())) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(2)) } /// Storage: `Proxy::Announcements` (r:1 w:1) /// Proof: `Proxy::Announcements` (`max_values`: None, `max_size`: Some(2233), added: 4708, mode: `MaxEncodedLen`) @@ -112,16 +105,16 @@ impl WeightInfo for HydraWeight { /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) /// The range of component `a` is `[0, 31]`. /// The range of component `p` is `[1, 31]`. - fn reject_announcement(a: u32, _p: u32) -> Weight { + fn reject_announcement(a: u32, _p: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `535 + a * (68 ±0)` // Estimated: `5698` - // Minimum execution time: 34_516_000 picoseconds. - Weight::from_parts(34_407_038, 5698) - // Standard Error: 3_233 - .saturating_add(Weight::from_parts(163_369, 0).saturating_mul(a.into())) - .saturating_add(T::DbWeight::get().reads(2_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) + // Minimum execution time: 34_010_000 picoseconds. + Weight::from_parts(34_723_018, 5698) + // Standard Error: 2_442 + .saturating_add(Weight::from_parts(164_732, 0).saturating_mul(a.into())) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(2)) } /// Storage: `Proxy::Proxies` (r:1 w:0) /// Proof: `Proxy::Proxies` (`max_values`: None, `max_size`: Some(1241), added: 3716, mode: `MaxEncodedLen`) @@ -131,85 +124,87 @@ impl WeightInfo for HydraWeight { /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) /// The range of component `a` is `[0, 31]`. /// The range of component `p` is `[1, 31]`. - fn announce(a: u32, p: u32) -> Weight { + fn announce(a: u32, p: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `552 + a * (68 ±0) + p * (37 ±0)` // Estimated: `5698` - // Minimum execution time: 44_879_000 picoseconds. - Weight::from_parts(44_863_459, 5698) - // Standard Error: 2_277 - .saturating_add(Weight::from_parts(186_705, 0).saturating_mul(a.into())) - // Standard Error: 2_368 - .saturating_add(Weight::from_parts(25_596, 0).saturating_mul(p.into())) - .saturating_add(T::DbWeight::get().reads(3_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) + // Minimum execution time: 46_184_000 picoseconds. + Weight::from_parts(45_983_861, 5698) + // Standard Error: 2_006 + .saturating_add(Weight::from_parts(172_287, 0).saturating_mul(a.into())) + // Standard Error: 2_086 + .saturating_add(Weight::from_parts(26_773, 0).saturating_mul(p.into())) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(2)) } /// Storage: `Proxy::Proxies` (r:1 w:1) /// Proof: `Proxy::Proxies` (`max_values`: None, `max_size`: Some(1241), added: 3716, mode: `MaxEncodedLen`) /// The range of component `p` is `[1, 31]`. - fn add_proxy(p: u32) -> Weight { + fn add_proxy(p: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `293 + p * (37 ±0)` // Estimated: `4706` - // Minimum execution time: 34_980_000 picoseconds. - Weight::from_parts(35_443_005, 4706) - // Standard Error: 2_435 - .saturating_add(Weight::from_parts(30_168, 0).saturating_mul(p.into())) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 35_158_000 picoseconds. + Weight::from_parts(35_671_577, 4706) + // Standard Error: 1_904 + .saturating_add(Weight::from_parts(43_085, 0).saturating_mul(p.into())) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `Proxy::Proxies` (r:1 w:1) /// Proof: `Proxy::Proxies` (`max_values`: None, `max_size`: Some(1241), added: 3716, mode: `MaxEncodedLen`) /// The range of component `p` is `[1, 31]`. - fn remove_proxy(_p: u32) -> Weight { + fn remove_proxy(p: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `293 + p * (37 ±0)` // Estimated: `4706` - // Minimum execution time: 35_573_000 picoseconds. - Weight::from_parts(36_596_298, 4706) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 35_277_000 picoseconds. + Weight::from_parts(36_469_179, 4706) + // Standard Error: 4_286 + .saturating_add(Weight::from_parts(13_586, 0).saturating_mul(p.into())) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `Proxy::Proxies` (r:1 w:1) /// Proof: `Proxy::Proxies` (`max_values`: None, `max_size`: Some(1241), added: 3716, mode: `MaxEncodedLen`) /// The range of component `p` is `[1, 31]`. - fn remove_proxies(p: u32) -> Weight { + fn remove_proxies(p: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `293 + p * (37 ±0)` // Estimated: `4706` - // Minimum execution time: 31_724_000 picoseconds. - Weight::from_parts(32_119_569, 4706) - // Standard Error: 2_666 - .saturating_add(Weight::from_parts(32_815, 0).saturating_mul(p.into())) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 31_983_000 picoseconds. + Weight::from_parts(32_492_459, 4706) + // Standard Error: 1_600 + .saturating_add(Weight::from_parts(30_213, 0).saturating_mul(p.into())) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `Proxy::Proxies` (r:1 w:1) /// Proof: `Proxy::Proxies` (`max_values`: None, `max_size`: Some(1241), added: 3716, mode: `MaxEncodedLen`) /// The range of component `p` is `[1, 31]`. - fn create_pure(p: u32) -> Weight { + fn create_pure(p: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `305` // Estimated: `4706` - // Minimum execution time: 37_850_000 picoseconds. - Weight::from_parts(38_490_275, 4706) - // Standard Error: 2_156 - .saturating_add(Weight::from_parts(1_048, 0).saturating_mul(p.into())) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 37_955_000 picoseconds. + Weight::from_parts(38_652_892, 4706) + // Standard Error: 2_122 + .saturating_add(Weight::from_parts(14_074, 0).saturating_mul(p.into())) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `Proxy::Proxies` (r:1 w:1) /// Proof: `Proxy::Proxies` (`max_values`: None, `max_size`: Some(1241), added: 3716, mode: `MaxEncodedLen`) /// The range of component `p` is `[0, 30]`. - fn kill_pure(p: u32) -> Weight { + fn kill_pure(p: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `330 + p * (37 ±0)` // Estimated: `4706` - // Minimum execution time: 32_796_000 picoseconds. - Weight::from_parts(33_380_258, 4706) - // Standard Error: 2_079 - .saturating_add(Weight::from_parts(29_420, 0).saturating_mul(p.into())) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 32_767_000 picoseconds. + Weight::from_parts(33_326_886, 4706) + // Standard Error: 1_559 + .saturating_add(Weight::from_parts(38_563, 0).saturating_mul(p.into())) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } -} +} \ No newline at end of file diff --git a/runtime/hydradx/src/weights/referrals.rs b/runtime/hydradx/src/weights/referrals.rs index e28a17288..43620ecf6 100644 --- a/runtime/hydradx/src/weights/referrals.rs +++ b/runtime/hydradx/src/weights/referrals.rs @@ -18,7 +18,7 @@ //! Autogenerated weights for `pallet_referrals` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2024-01-09, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-02-15, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `bench-bot`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 @@ -33,26 +33,22 @@ // --wasm-execution=compiled // --heap-pages=4096 // --template=.maintain/pallet-weight-template-no-back.hbs -// --pallet=pallet-referrals -// --output=weights-1.1.0/referrals.rs +// --pallet=pallet_referrals +// --output=./weights/referrlas.rs // --extrinsic=* #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] -#![allow(clippy::unnecessary_cast)] +#![allow(missing_docs)] -use frame_support::{ - traits::Get, - weights::{constants::RocksDbWeight, Weight}, -}; -use sp_std::marker::PhantomData; +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; use pallet_referrals::weights::WeightInfo; -/// Weights for pallet_referrals using the hydraDX node and recommended hardware. +/// Weight functions for `pallet_referrals`. pub struct HydraWeight(PhantomData); - impl WeightInfo for HydraWeight { /// Storage: `Referrals::ReferralAccounts` (r:1 w:1) /// Proof: `Referrals::ReferralAccounts` (`max_values`: None, `max_size`: Some(59), added: 2534, mode: `MaxEncodedLen`) @@ -66,8 +62,8 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `284` // Estimated: `6196` - // Minimum execution time: 64_118_000 picoseconds. - Weight::from_parts(64_600_000, 6196) + // Minimum execution time: 63_867_000 picoseconds. + Weight::from_parts(64_488_000, 6196) .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().writes(5)) } @@ -79,8 +75,8 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `194` // Estimated: `3545` - // Minimum execution time: 22_117_000 picoseconds. - Weight::from_parts(22_358_000, 3545) + // Minimum execution time: 21_841_000 picoseconds. + Weight::from_parts(22_151_000, 3545) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -96,8 +92,10 @@ impl WeightInfo for HydraWeight { /// Proof: `DynamicFees::AssetFee` (`max_values`: None, `max_size`: Some(24), added: 2499, mode: `MaxEncodedLen`) /// Storage: `EmaOracle::Oracles` (r:2 w:0) /// Proof: `EmaOracle::Oracles` (`max_values`: None, `max_size`: Some(177), added: 2652, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::BannedAssets` (r:1 w:0) + /// Proof: `AssetRegistry::BannedAssets` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::Assets` (r:1 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// Storage: `EmaOracle::Accumulator` (r:1 w:1) /// Proof: `EmaOracle::Accumulator` (`max_values`: Some(1), `max_size`: Some(5921), added: 6416, mode: `MaxEncodedLen`) /// Storage: `CircuitBreaker::AllowedTradeVolumeLimitPerAsset` (r:2 w:2) @@ -122,11 +120,11 @@ impl WeightInfo for HydraWeight { /// Proof: `MultiTransactionPayment::AccountCurrencyMap` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`) fn convert() -> Weight { // Proof Size summary in bytes: - // Measured: `2105` + // Measured: `2088` // Estimated: `7406` - // Minimum execution time: 290_406_000 picoseconds. - Weight::from_parts(291_955_000, 7406) - .saturating_add(T::DbWeight::get().reads(24)) + // Minimum execution time: 295_663_000 picoseconds. + Weight::from_parts(297_036_000, 7406) + .saturating_add(T::DbWeight::get().reads(25)) .saturating_add(T::DbWeight::get().writes(15)) } /// Storage: `Referrals::PendingConversions` (r:1 w:0) @@ -145,8 +143,8 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `655` // Estimated: `6196` - // Minimum execution time: 88_340_000 picoseconds. - Weight::from_parts(89_429_000, 6196) + // Minimum execution time: 88_579_000 picoseconds. + Weight::from_parts(89_353_000, 6196) .saturating_add(T::DbWeight::get().reads(7)) .saturating_add(T::DbWeight::get().writes(6)) } @@ -156,8 +154,8 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `42` // Estimated: `3514` - // Minimum execution time: 16_024_000 picoseconds. - Weight::from_parts(16_319_000, 3514) + // Minimum execution time: 15_398_000 picoseconds. + Weight::from_parts(15_676_000, 3514) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } diff --git a/runtime/hydradx/src/weights/registry.rs b/runtime/hydradx/src/weights/registry.rs index 4863a7b56..26c0398c7 100644 --- a/runtime/hydradx/src/weights/registry.rs +++ b/runtime/hydradx/src/weights/registry.rs @@ -18,103 +18,113 @@ //! Autogenerated weights for `pallet_asset_registry` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-12-12, STEPS: `5`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-02-15, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `bench-bot`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` -//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 // Executed Command: // target/release/hydradx // benchmark // pallet -// --pallet=pallet-asset-registry +// --chain=dev +// --steps=10 +// --repeat=30 // --wasm-execution=compiled // --heap-pages=4096 -// --chain=dev +// --template=.maintain/pallet-weight-template-no-back.hbs +// --pallet=pallet_asset_registry +// --output=./weights/registry.rs // --extrinsic=* -// --steps=5 -// --repeat=20 -// --output -// ./weights-1.1.0/registry.rs -// --template -// .maintain/pallet-weight-template-no-back.hbs +#![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] -#![allow(clippy::unnecessary_cast)] +#![allow(missing_docs)] -use frame_support::{ - traits::Get, - weights::{constants::RocksDbWeight, Weight}, -}; -use sp_std::marker::PhantomData; +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; use pallet_asset_registry::weights::WeightInfo; -/// Weights for pallet_asset_registry using the hydraDX node and recommended hardware. +/// Weight functions for `pallet_asset_registry`. pub struct HydraWeight(PhantomData); - impl WeightInfo for HydraWeight { + /// Storage: `AssetRegistry::Assets` (r:1 w:1) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::AssetIds` (r:1 w:1) /// Proof: `AssetRegistry::AssetIds` (`max_values`: None, `max_size`: Some(53), added: 2528, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::NextAssetId` (r:1 w:1) - /// Proof: `AssetRegistry::NextAssetId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::LocationAssets` (r:1 w:1) /// Proof: `AssetRegistry::LocationAssets` (`max_values`: None, `max_size`: Some(622), added: 3097, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::AssetLocations` (r:0 w:1) - /// Proof: `AssetRegistry::AssetLocations` (`max_values`: None, `max_size`: Some(614), added: 3089, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::AssetMetadataMap` (r:0 w:1) - /// Proof: `AssetRegistry::AssetMetadataMap` (`max_values`: None, `max_size`: Some(46), added: 2521, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::Assets` (r:0 w:1) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) + /// Proof: `AssetRegistry::AssetLocations` (`max_values`: None, `max_size`: Some(622), added: 3097, mode: `MaxEncodedLen`) fn register() -> Weight { // Proof Size summary in bytes: - // Measured: `305` + // Measured: `322` // Estimated: `4087` - // Minimum execution time: 46_657_000 picoseconds. - Weight::from_parts(47_059_000, 4087) - .saturating_add(T::DbWeight::get().reads(3_u64)) - .saturating_add(T::DbWeight::get().writes(6_u64)) + // Minimum execution time: 40_579_000 picoseconds. + Weight::from_parts(41_148_000, 4087) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(4)) } /// Storage: `AssetRegistry::Assets` (r:1 w:1) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::AssetIds` (r:1 w:2) /// Proof: `AssetRegistry::AssetIds` (`max_values`: None, `max_size`: Some(53), added: 2528, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::AssetLocations` (r:1 w:1) + /// Proof: `AssetRegistry::AssetLocations` (`max_values`: None, `max_size`: Some(622), added: 3097, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::LocationAssets` (r:0 w:1) + /// Proof: `AssetRegistry::LocationAssets` (`max_values`: None, `max_size`: Some(622), added: 3097, mode: `MaxEncodedLen`) fn update() -> Weight { // Proof Size summary in bytes: - // Measured: `372` - // Estimated: `3552` - // Minimum execution time: 29_123_000 picoseconds. - Weight::from_parts(29_400_000, 3552) - .saturating_add(T::DbWeight::get().reads(2_u64)) - .saturating_add(T::DbWeight::get().writes(3_u64)) + // Measured: `551` + // Estimated: `4087` + // Minimum execution time: 48_132_000 picoseconds. + Weight::from_parts(48_483_000, 4087) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(5)) } - /// Storage: `AssetRegistry::Assets` (r:1 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::AssetMetadataMap` (r:0 w:1) - /// Proof: `AssetRegistry::AssetMetadataMap` (`max_values`: None, `max_size`: Some(46), added: 2521, mode: `MaxEncodedLen`) - fn set_metadata() -> Weight { + /// Storage: `System::Account` (r:2 w:2) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::NextAssetId` (r:1 w:1) + /// Proof: `AssetRegistry::NextAssetId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::LocationAssets` (r:1 w:1) + /// Proof: `AssetRegistry::LocationAssets` (`max_values`: None, `max_size`: Some(622), added: 3097, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::AssetLocations` (r:0 w:1) + /// Proof: `AssetRegistry::AssetLocations` (`max_values`: None, `max_size`: Some(622), added: 3097, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::Assets` (r:0 w:1) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) + fn register_external() -> Weight { // Proof Size summary in bytes: - // Measured: `300` - // Estimated: `3552` - // Minimum execution time: 21_806_000 picoseconds. - Weight::from_parts(22_285_000, 3552) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Measured: `477` + // Estimated: `6196` + // Minimum execution time: 80_033_000 picoseconds. + Weight::from_parts(80_684_000, 6196) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().writes(6)) } /// Storage: `AssetRegistry::Assets` (r:1 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::LocationAssets` (r:1 w:1) - /// Proof: `AssetRegistry::LocationAssets` (`max_values`: None, `max_size`: Some(622), added: 3097, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::AssetLocations` (r:1 w:1) - /// Proof: `AssetRegistry::AssetLocations` (`max_values`: None, `max_size`: Some(614), added: 3089, mode: `MaxEncodedLen`) - fn set_location() -> Weight { + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::BannedAssets` (r:1 w:1) + /// Proof: `AssetRegistry::BannedAssets` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`) + fn ban_asset() -> Weight { // Proof Size summary in bytes: - // Measured: `274` - // Estimated: `4087` - // Minimum execution time: 26_900_000 picoseconds. - Weight::from_parts(27_350_000, 4087) - .saturating_add(T::DbWeight::get().reads(3_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) + // Measured: `361` + // Estimated: `3590` + // Minimum execution time: 21_799_000 picoseconds. + Weight::from_parts(22_232_000, 3590) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(1)) + } + /// Storage: `AssetRegistry::BannedAssets` (r:1 w:1) + /// Proof: `AssetRegistry::BannedAssets` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`) + fn unban_asset() -> Weight { + // Proof Size summary in bytes: + // Measured: `254` + // Estimated: `3485` + // Minimum execution time: 18_853_000 picoseconds. + Weight::from_parts(19_166_000, 3485) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } } diff --git a/runtime/hydradx/src/weights/route_executor.rs b/runtime/hydradx/src/weights/route_executor.rs index 8dc7fe923..b61909e67 100644 --- a/runtime/hydradx/src/weights/route_executor.rs +++ b/runtime/hydradx/src/weights/route_executor.rs @@ -18,42 +18,37 @@ //! Autogenerated weights for `pallet_route_executor` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-12-12, STEPS: `5`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-02-15, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `bench-bot`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` -//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 // Executed Command: // target/release/hydradx // benchmark // pallet -// --pallet=pallet-route-executor +// --chain=dev +// --steps=10 +// --repeat=30 // --wasm-execution=compiled // --heap-pages=4096 -// --chain=dev +// --template=.maintain/pallet-weight-template-no-back.hbs +// --pallet=pallet-route-executor +// --output=./weights/route_executor.rs // --extrinsic=* -// --steps=5 -// --repeat=20 -// --output -// ./weights-1.1.0/route_executor.rs -// --template -// .maintain/pallet-weight-template-no-back.hbs +#![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] -#![allow(clippy::unnecessary_cast)] +#![allow(missing_docs)] -use frame_support::{ - traits::Get, - weights::{constants::RocksDbWeight, Weight}, -}; -use sp_std::marker::PhantomData; +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; use pallet_route_executor::weights::WeightInfo; -/// Weights for pallet_route_executor using the hydraDX node and recommended hardware. +/// Weight functions for `pallet_route_executor`. pub struct HydraWeight(PhantomData); - impl WeightInfo for HydraWeight { /// Storage: `LBP::PoolData` (r:1 w:0) /// Proof: `LBP::PoolData` (`max_values`: None, `max_size`: Some(163), added: 2638, mode: `MaxEncodedLen`) @@ -63,19 +58,23 @@ impl WeightInfo for HydraWeight { /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) /// Storage: `Tokens::Locks` (r:1 w:1) /// Proof: `Tokens::Locks` (`max_values`: None, `max_size`: Some(1261), added: 3736, mode: `MaxEncodedLen`) + /// Storage: `Duster::AccountBlacklist` (r:2 w:0) + /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::BannedAssets` (r:2 w:0) + /// Proof: `AssetRegistry::BannedAssets` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::Assets` (r:2 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// The range of component `c` is `[0, 1]`. - fn calculate_and_execute_sell_in_lbp(c: u32) -> Weight { + fn calculate_and_execute_sell_in_lbp(c: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `3016` + // Measured: `3402` // Estimated: `13905` - // Minimum execution time: 316_311_000 picoseconds. - Weight::from_parts(318_353_450, 13905) - // Standard Error: 164_994 - .saturating_add(Weight::from_parts(50_546_750, 0).saturating_mul(c.into())) - .saturating_add(T::DbWeight::get().reads(12_u64)) - .saturating_add(T::DbWeight::get().writes(7_u64)) + // Minimum execution time: 342_380_000 picoseconds. + Weight::from_parts(344_960_058, 13905) + // Standard Error: 141_835 + .saturating_add(Weight::from_parts(50_412_253, 0).saturating_mul(c.into())) + .saturating_add(T::DbWeight::get().reads(16)) + .saturating_add(T::DbWeight::get().writes(7)) } /// Storage: `LBP::PoolData` (r:1 w:0) /// Proof: `LBP::PoolData` (`max_values`: None, `max_size`: Some(163), added: 2638, mode: `MaxEncodedLen`) @@ -85,22 +84,26 @@ impl WeightInfo for HydraWeight { /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) /// Storage: `Tokens::Locks` (r:1 w:1) /// Proof: `Tokens::Locks` (`max_values`: None, `max_size`: Some(1261), added: 3736, mode: `MaxEncodedLen`) + /// Storage: `Duster::AccountBlacklist` (r:2 w:0) + /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::BannedAssets` (r:2 w:0) + /// Proof: `AssetRegistry::BannedAssets` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::Assets` (r:2 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// The range of component `c` is `[1, 2]`. /// The range of component `b` is `[0, 1]`. - fn calculate_and_execute_buy_in_lbp(c: u32, b: u32) -> Weight { + fn calculate_and_execute_buy_in_lbp(c: u32, b: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `1567 + b * (1418 ±0)` - // Estimated: `6156 + b * (7749 ±0)` - // Minimum execution time: 75_646_000 picoseconds. - Weight::from_parts(76_052_000, 6156) - // Standard Error: 1_389_058 - .saturating_add(Weight::from_parts(4_096_946, 0).saturating_mul(c.into())) - // Standard Error: 3_000_708 - .saturating_add(Weight::from_parts(250_139_938, 0).saturating_mul(b.into())) - .saturating_add(T::DbWeight::get().reads(3_u64)) - .saturating_add(T::DbWeight::get().reads((9_u64).saturating_mul(b.into()))) + // Measured: `1571 + b * (1836 ±0)` + // Estimated: `6156 + b * (7749 ±245_709_589_663_843_264)` + // Minimum execution time: 75_535_000 picoseconds. + Weight::from_parts(76_397_000, 6156) + // Standard Error: 600_512 + .saturating_add(Weight::from_parts(2_328_934, 0).saturating_mul(c.into())) + // Standard Error: 1_318_297 + .saturating_add(Weight::from_parts(272_259_348, 0).saturating_mul(b.into())) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().reads((13_u64).saturating_mul(b.into()))) .saturating_add(T::DbWeight::get().writes((7_u64).saturating_mul(b.into()))) .saturating_add(Weight::from_parts(0, 7749).saturating_mul(b.into())) } @@ -108,27 +111,37 @@ impl WeightInfo for HydraWeight { /// Proof: `Router::Routes` (`max_values`: None, `max_size`: Some(90), added: 2565, mode: `MaxEncodedLen`) /// Storage: `Tokens::Accounts` (r:9 w:0) /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:5 w:0) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) /// Storage: `Tokens::TotalIssuance` (r:2 w:0) /// Proof: `Tokens::TotalIssuance` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::Assets` (r:3 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) - /// Storage: `System::Account` (r:4 w:0) - /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::BannedAssets` (r:3 w:0) + /// Proof: `AssetRegistry::BannedAssets` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`) /// Storage: `MultiTransactionPayment::AccountCurrencyMap` (r:1 w:0) /// Proof: `MultiTransactionPayment::AccountCurrencyMap` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`) + /// Storage: `Balances::Locks` (r:1 w:0) + /// Proof: `Balances::Locks` (`max_values`: None, `max_size`: Some(1299), added: 3774, mode: `MaxEncodedLen`) + /// Storage: `Balances::Freezes` (r:1 w:0) + /// Proof: `Balances::Freezes` (`max_values`: None, `max_size`: Some(49), added: 2524, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::ExistentialDepositCounter` (r:1 w:0) + /// Proof: `AssetRegistry::ExistentialDepositCounter` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) /// Storage: `MultiTransactionPayment::AcceptedCurrencies` (r:3 w:0) /// Proof: `MultiTransactionPayment::AcceptedCurrencies` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) /// Storage: `XYK::ShareToken` (r:3 w:0) /// Proof: `XYK::ShareToken` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`) + /// Storage: `Duster::AccountBlacklist` (r:4 w:0) + /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) /// Storage: `EmaOracle::Accumulator` (r:1 w:0) /// Proof: `EmaOracle::Accumulator` (`max_values`: Some(1), `max_size`: Some(5921), added: 6416, mode: `MaxEncodedLen`) fn set_route_for_xyk() -> Weight { // Proof Size summary in bytes: - // Measured: `4201` + // Measured: `4957` // Estimated: `24237` - // Minimum execution time: 1_126_027_000 picoseconds. - Weight::from_parts(1_133_155_000, 24237) - .saturating_add(T::DbWeight::get().reads(27_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 2_485_264_000 picoseconds. + Weight::from_parts(2_495_249_000, 24237) + .saturating_add(T::DbWeight::get().reads(38)) + .saturating_add(T::DbWeight::get().writes(1)) } } diff --git a/runtime/hydradx/src/weights/scheduler.rs b/runtime/hydradx/src/weights/scheduler.rs index ea11e8d37..d39faa62a 100644 --- a/runtime/hydradx/src/weights/scheduler.rs +++ b/runtime/hydradx/src/weights/scheduler.rs @@ -18,90 +18,83 @@ //! Autogenerated weights for `pallet_scheduler` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-12-12, STEPS: `5`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-02-15, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `bench-bot`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` -//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 // Executed Command: // target/release/hydradx // benchmark // pallet -// --pallet=pallet-scheduler +// --chain=dev +// --steps=10 +// --repeat=30 // --wasm-execution=compiled // --heap-pages=4096 -// --chain=dev +// --template=.maintain/pallet-weight-template-no-back.hbs +// --pallet=pallet_scheduler +// --output=./weights/scheduler.rs // --extrinsic=* -// --steps=5 -// --repeat=20 -// --output -// ./weights-1.1.0/scheduler.rs -// --template -// .maintain/pallet-weight-template-no-back.hbs +#![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] -#![allow(clippy::unnecessary_cast)] +#![allow(missing_docs)] -use frame_support::{ - traits::Get, - weights::{constants::RocksDbWeight, Weight}, -}; -use sp_std::marker::PhantomData; +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; -use pallet_scheduler::weights::WeightInfo; - -/// Weights for pallet_scheduler using the hydraDX node and recommended hardware. +/// Weight functions for `pallet_scheduler`. pub struct HydraWeight(PhantomData); - -impl WeightInfo for HydraWeight { +impl pallet_scheduler::WeightInfo for HydraWeight { /// Storage: `Scheduler::IncompleteSince` (r:1 w:1) /// Proof: `Scheduler::IncompleteSince` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) fn service_agendas_base() -> Weight { // Proof Size summary in bytes: // Measured: `31` // Estimated: `1489` - // Minimum execution time: 4_643_000 picoseconds. - Weight::from_parts(4_787_000, 1489) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 4_766_000 picoseconds. + Weight::from_parts(4_908_000, 1489) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `Scheduler::Agenda` (r:1 w:1) /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(38963), added: 41438, mode: `MaxEncodedLen`) /// The range of component `s` is `[0, 50]`. - fn service_agenda_base(s: u32) -> Weight { + fn service_agenda_base(s: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `78 + s * (177 ±0)` // Estimated: `42428` - // Minimum execution time: 4_686_000 picoseconds. - Weight::from_parts(6_756_919, 42428) - // Standard Error: 11_265 - .saturating_add(Weight::from_parts(959_261, 0).saturating_mul(s.into())) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 4_580_000 picoseconds. + Weight::from_parts(7_795_367, 42428) + // Standard Error: 6_252 + .saturating_add(Weight::from_parts(905_945, 0).saturating_mul(s.into())) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } fn service_task_base() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 7_940_000 picoseconds. - Weight::from_parts(8_088_000, 0) + // Minimum execution time: 8_057_000 picoseconds. + Weight::from_parts(8_214_000, 0) } /// Storage: `Preimage::PreimageFor` (r:1 w:1) /// Proof: `Preimage::PreimageFor` (`max_values`: None, `max_size`: Some(4194344), added: 4196819, mode: `Measured`) /// Storage: `Preimage::StatusFor` (r:1 w:1) /// Proof: `Preimage::StatusFor` (`max_values`: None, `max_size`: Some(91), added: 2566, mode: `MaxEncodedLen`) /// The range of component `s` is `[128, 4194304]`. - fn service_task_fetched(s: u32) -> Weight { + fn service_task_fetched(s: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `246 + s * (1 ±0)` - // Estimated: `3708 + s * (1 ±0)` - // Minimum execution time: 27_177_000 picoseconds. - Weight::from_parts(16_696_892, 3708) - // Standard Error: 1 - .saturating_add(Weight::from_parts(1_259, 0).saturating_mul(s.into())) - .saturating_add(T::DbWeight::get().reads(2_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) + // Estimated: `3709 + s * (1 ±0)` + // Minimum execution time: 27_147_000 picoseconds. + Weight::from_parts(27_475_000, 3709) + // Standard Error: 19 + .saturating_add(Weight::from_parts(1_397, 0).saturating_mul(s.into())) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(2)) .saturating_add(Weight::from_parts(0, 1).saturating_mul(s.into())) } /// Storage: `Scheduler::Lookup` (r:0 w:1) @@ -110,90 +103,91 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 10_369_000 picoseconds. - Weight::from_parts(10_613_000, 0).saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 10_368_000 picoseconds. + Weight::from_parts(10_520_000, 0) + .saturating_add(T::DbWeight::get().writes(1)) } fn service_task_periodic() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 8_045_000 picoseconds. - Weight::from_parts(8_135_000, 0) + // Minimum execution time: 7_981_000 picoseconds. + Weight::from_parts(8_201_000, 0) } fn execute_dispatch_signed() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 4_361_000 picoseconds. - Weight::from_parts(4_491_000, 0) + // Minimum execution time: 4_335_000 picoseconds. + Weight::from_parts(4_499_000, 0) } fn execute_dispatch_unsigned() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 4_376_000 picoseconds. - Weight::from_parts(4_505_000, 0) + // Minimum execution time: 4_214_000 picoseconds. + Weight::from_parts(4_391_000, 0) } /// Storage: `Scheduler::Agenda` (r:1 w:1) /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(38963), added: 41438, mode: `MaxEncodedLen`) /// The range of component `s` is `[0, 49]`. - fn schedule(s: u32) -> Weight { + fn schedule(s: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `78 + s * (177 ±0)` // Estimated: `42428` - // Minimum execution time: 18_064_000 picoseconds. - Weight::from_parts(20_065_367, 42428) - // Standard Error: 10_260 - .saturating_add(Weight::from_parts(953_244, 0).saturating_mul(s.into())) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 17_694_000 picoseconds. + Weight::from_parts(21_031_139, 42428) + // Standard Error: 6_108 + .saturating_add(Weight::from_parts(896_821, 0).saturating_mul(s.into())) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `Scheduler::Agenda` (r:1 w:1) /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(38963), added: 41438, mode: `MaxEncodedLen`) /// Storage: `Scheduler::Lookup` (r:0 w:1) /// Proof: `Scheduler::Lookup` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) /// The range of component `s` is `[1, 50]`. - fn cancel(s: u32) -> Weight { + fn cancel(s: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `78 + s * (177 ±0)` // Estimated: `42428` - // Minimum execution time: 24_575_000 picoseconds. - Weight::from_parts(23_596_290, 42428) - // Standard Error: 6_439 - .saturating_add(Weight::from_parts(1_644_619, 0).saturating_mul(s.into())) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) + // Minimum execution time: 24_274_000 picoseconds. + Weight::from_parts(23_345_538, 42428) + // Standard Error: 1_887 + .saturating_add(Weight::from_parts(1_577_518, 0).saturating_mul(s.into())) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(2)) } /// Storage: `Scheduler::Lookup` (r:1 w:1) /// Proof: `Scheduler::Lookup` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) /// Storage: `Scheduler::Agenda` (r:1 w:1) /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(38963), added: 41438, mode: `MaxEncodedLen`) /// The range of component `s` is `[0, 49]`. - fn schedule_named(s: u32) -> Weight { + fn schedule_named(s: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `148 + s * (188 ±0)` + // Measured: `192 + s * (187 ±0)` // Estimated: `42428` - // Minimum execution time: 22_396_000 picoseconds. - Weight::from_parts(25_018_609, 42428) - // Standard Error: 12_955 - .saturating_add(Weight::from_parts(1_010_928, 0).saturating_mul(s.into())) - .saturating_add(T::DbWeight::get().reads(2_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) + // Minimum execution time: 22_839_000 picoseconds. + Weight::from_parts(26_341_432, 42428) + // Standard Error: 6_685 + .saturating_add(Weight::from_parts(941_746, 0).saturating_mul(s.into())) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(2)) } /// Storage: `Scheduler::Lookup` (r:1 w:1) /// Proof: `Scheduler::Lookup` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) /// Storage: `Scheduler::Agenda` (r:1 w:1) /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(38963), added: 41438, mode: `MaxEncodedLen`) /// The range of component `s` is `[1, 50]`. - fn cancel_named(s: u32) -> Weight { + fn cancel_named(s: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `277 + s * (185 ±0)` + // Measured: `263 + s * (186 ±0)` // Estimated: `42428` - // Minimum execution time: 26_539_000 picoseconds. - Weight::from_parts(25_956_508, 42428) - // Standard Error: 4_676 - .saturating_add(Weight::from_parts(1_656_608, 0).saturating_mul(s.into())) - .saturating_add(T::DbWeight::get().reads(2_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) + // Minimum execution time: 26_360_000 picoseconds. + Weight::from_parts(25_724_190, 42428) + // Standard Error: 3_550 + .saturating_add(Weight::from_parts(1_590_016, 0).saturating_mul(s.into())) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(2)) } -} +} \ No newline at end of file diff --git a/runtime/hydradx/src/weights/stableswap.rs b/runtime/hydradx/src/weights/stableswap.rs index 60d676438..d507ae37e 100644 --- a/runtime/hydradx/src/weights/stableswap.rs +++ b/runtime/hydradx/src/weights/stableswap.rs @@ -1,5 +1,4 @@ // This file is part of HydraDX. -// This file is part of HydraDX. // Copyright (C) 2020-2023 Intergalactic, Limited (GIB). // SPDX-License-Identifier: Apache-2.0 @@ -19,7 +18,7 @@ //! Autogenerated weights for `pallet_stableswap` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-12-18, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-02-15, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `bench-bot`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 @@ -34,8 +33,8 @@ // --wasm-execution=compiled // --heap-pages=4096 // --template=.maintain/pallet-weight-template-no-back.hbs -// --pallet=pallet-stableswap -// --output=weights-1.1.0/stableswap.rs +// --pallet=pallet_stableswap +// --output=./weights/stableswap.rs // --extrinsic=* #![cfg_attr(rustfmt, rustfmt_skip)] @@ -43,30 +42,26 @@ #![allow(unused_imports)] #![allow(missing_docs)] -use frame_support::{ - traits::Get, - weights::{constants::RocksDbWeight, Weight}, -}; -use sp_std::marker::PhantomData; +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; use pallet_stableswap::weights::WeightInfo; -/// Weights for pallet_stableswap using the hydraDX node and recommended hardware. +/// Weight functions for `pallet_stableswap`. pub struct HydraWeight(PhantomData); - impl WeightInfo for HydraWeight { /// Storage: `Stableswap::Pools` (r:1 w:1) /// Proof: `Stableswap::Pools` (`max_values`: None, `max_size`: Some(57), added: 2532, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::Assets` (r:6 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// Storage: `Duster::AccountBlacklist` (r:0 w:1) /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) fn create_pool() -> Weight { // Proof Size summary in bytes: - // Measured: `717` - // Estimated: `16362` - // Minimum execution time: 52_498_000 picoseconds. - Weight::from_parts(52_992_000, 16362) + // Measured: `789` + // Estimated: `16590` + // Minimum execution time: 53_155_000 picoseconds. + Weight::from_parts(53_722_000, 16590) .saturating_add(T::DbWeight::get().reads(7)) .saturating_add(T::DbWeight::get().writes(2)) } @@ -76,54 +71,60 @@ impl WeightInfo for HydraWeight { /// Proof: `Stableswap::AssetTradability` (`max_values`: None, `max_size`: Some(41), added: 2516, mode: `MaxEncodedLen`) /// Storage: `Tokens::Accounts` (r:11 w:11) /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::AssetMetadataMap` (r:5 w:0) - /// Proof: `AssetRegistry::AssetMetadataMap` (`max_values`: None, `max_size`: Some(46), added: 2521, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::Assets` (r:6 w:0) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// Storage: `Tokens::TotalIssuance` (r:1 w:1) /// Proof: `Tokens::TotalIssuance` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::Assets` (r:6 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::BannedAssets` (r:6 w:0) + /// Proof: `AssetRegistry::BannedAssets` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:1 w:1) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) /// Storage: `MultiTransactionPayment::AccountCurrencyMap` (r:1 w:0) /// Proof: `MultiTransactionPayment::AccountCurrencyMap` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`) /// Storage: `MultiTransactionPayment::AcceptedCurrencies` (r:1 w:0) /// Proof: `MultiTransactionPayment::AcceptedCurrencies` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) + /// Storage: `Duster::AccountBlacklist` (r:1 w:0) + /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) /// Storage: `EmaOracle::Accumulator` (r:1 w:1) /// Proof: `EmaOracle::Accumulator` (`max_values`: Some(1), `max_size`: Some(5921), added: 6416, mode: `MaxEncodedLen`) fn add_liquidity() -> Weight { // Proof Size summary in bytes: - // Measured: `3168` + // Measured: `3339` // Estimated: `29403` - // Minimum execution time: 1_087_109_000 picoseconds. - Weight::from_parts(1_090_256_000, 29403) - .saturating_add(T::DbWeight::get().reads(33)) + // Minimum execution time: 1_155_933_000 picoseconds. + Weight::from_parts(1_159_202_000, 29403) + .saturating_add(T::DbWeight::get().reads(35)) .saturating_add(T::DbWeight::get().writes(14)) } + /// Storage: `Stableswap::AssetTradability` (r:1 w:0) + /// Proof: `Stableswap::AssetTradability` (`max_values`: None, `max_size`: Some(41), added: 2516, mode: `MaxEncodedLen`) /// Storage: `Stableswap::Pools` (r:1 w:0) /// Proof: `Stableswap::Pools` (`max_values`: None, `max_size`: Some(57), added: 2532, mode: `MaxEncodedLen`) /// Storage: `Tokens::TotalIssuance` (r:1 w:1) /// Proof: `Tokens::TotalIssuance` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) /// Storage: `Tokens::Accounts` (r:7 w:3) /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::AssetMetadataMap` (r:5 w:0) - /// Proof: `AssetRegistry::AssetMetadataMap` (`max_values`: None, `max_size`: Some(46), added: 2521, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::Assets` (r:2 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::Assets` (r:6 w:0) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::BannedAssets` (r:2 w:0) + /// Proof: `AssetRegistry::BannedAssets` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:1 w:1) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) /// Storage: `MultiTransactionPayment::AccountCurrencyMap` (r:1 w:0) /// Proof: `MultiTransactionPayment::AccountCurrencyMap` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`) /// Storage: `MultiTransactionPayment::AcceptedCurrencies` (r:1 w:0) /// Proof: `MultiTransactionPayment::AcceptedCurrencies` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) + /// Storage: `Duster::AccountBlacklist` (r:1 w:0) + /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) /// Storage: `EmaOracle::Accumulator` (r:1 w:1) /// Proof: `EmaOracle::Accumulator` (`max_values`: Some(1), `max_size`: Some(5921), added: 6416, mode: `MaxEncodedLen`) fn add_liquidity_shares() -> Weight { // Proof Size summary in bytes: - // Measured: `3014` + // Measured: `3207` // Estimated: `19071` - // Minimum execution time: 739_668_000 picoseconds. - Weight::from_parts(743_517_000, 19071) - .saturating_add(T::DbWeight::get().reads(20)) + // Minimum execution time: 775_198_000 picoseconds. + Weight::from_parts(779_737_000, 19071) + .saturating_add(T::DbWeight::get().reads(23)) .saturating_add(T::DbWeight::get().writes(6)) } /// Storage: `Stableswap::AssetTradability` (r:1 w:0) @@ -132,14 +133,16 @@ impl WeightInfo for HydraWeight { /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) /// Storage: `Stableswap::Pools` (r:1 w:0) /// Proof: `Stableswap::Pools` (`max_values`: None, `max_size`: Some(57), added: 2532, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::AssetMetadataMap` (r:5 w:0) - /// Proof: `AssetRegistry::AssetMetadataMap` (`max_values`: None, `max_size`: Some(46), added: 2521, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::Assets` (r:6 w:0) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// Storage: `Tokens::TotalIssuance` (r:1 w:1) /// Proof: `Tokens::TotalIssuance` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::Assets` (r:2 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:2 w:1) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Duster::AccountBlacklist` (r:1 w:0) + /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::BannedAssets` (r:1 w:0) + /// Proof: `AssetRegistry::BannedAssets` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`) /// Storage: `MultiTransactionPayment::AcceptedCurrencies` (r:1 w:0) /// Proof: `MultiTransactionPayment::AcceptedCurrencies` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) /// Storage: `EmaOracle::Accumulator` (r:1 w:1) @@ -148,11 +151,11 @@ impl WeightInfo for HydraWeight { /// Proof: `MultiTransactionPayment::AccountCurrencyMap` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`) fn remove_liquidity_one_asset() -> Weight { // Proof Size summary in bytes: - // Measured: `3017` + // Measured: `3231` // Estimated: `19071` - // Minimum execution time: 777_557_000 picoseconds. - Weight::from_parts(781_094_000, 19071) - .saturating_add(T::DbWeight::get().reads(21)) + // Minimum execution time: 807_519_000 picoseconds. + Weight::from_parts(811_614_000, 19071) + .saturating_add(T::DbWeight::get().reads(22)) .saturating_add(T::DbWeight::get().writes(7)) } /// Storage: `Stableswap::AssetTradability` (r:1 w:0) @@ -161,12 +164,14 @@ impl WeightInfo for HydraWeight { /// Proof: `Stableswap::Pools` (`max_values`: None, `max_size`: Some(57), added: 2532, mode: `MaxEncodedLen`) /// Storage: `Tokens::Accounts` (r:7 w:3) /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::AssetMetadataMap` (r:5 w:0) - /// Proof: `AssetRegistry::AssetMetadataMap` (`max_values`: None, `max_size`: Some(46), added: 2521, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::Assets` (r:6 w:0) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// Storage: `Tokens::TotalIssuance` (r:1 w:1) /// Proof: `Tokens::TotalIssuance` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::Assets` (r:2 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) + /// Storage: `Duster::AccountBlacklist` (r:1 w:0) + /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::BannedAssets` (r:1 w:0) + /// Proof: `AssetRegistry::BannedAssets` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:2 w:1) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) /// Storage: `MultiTransactionPayment::AccountCurrencyMap` (r:1 w:0) @@ -177,11 +182,11 @@ impl WeightInfo for HydraWeight { /// Proof: `EmaOracle::Accumulator` (`max_values`: Some(1), `max_size`: Some(5921), added: 6416, mode: `MaxEncodedLen`) fn withdraw_asset_amount() -> Weight { // Proof Size summary in bytes: - // Measured: `3017` + // Measured: `3231` // Estimated: `19071` - // Minimum execution time: 1_041_027_000 picoseconds. - Weight::from_parts(1_050_193_000, 19071) - .saturating_add(T::DbWeight::get().reads(22)) + // Minimum execution time: 1_061_520_000 picoseconds. + Weight::from_parts(1_068_689_000, 19071) + .saturating_add(T::DbWeight::get().reads(23)) .saturating_add(T::DbWeight::get().writes(6)) } /// Storage: `Stableswap::AssetTradability` (r:2 w:0) @@ -190,10 +195,12 @@ impl WeightInfo for HydraWeight { /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) /// Storage: `Stableswap::Pools` (r:1 w:0) /// Proof: `Stableswap::Pools` (`max_values`: None, `max_size`: Some(57), added: 2532, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::AssetMetadataMap` (r:5 w:0) - /// Proof: `AssetRegistry::AssetMetadataMap` (`max_values`: None, `max_size`: Some(46), added: 2521, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::Assets` (r:2 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::Assets` (r:5 w:0) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) + /// Storage: `Duster::AccountBlacklist` (r:2 w:0) + /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::BannedAssets` (r:2 w:0) + /// Proof: `AssetRegistry::BannedAssets` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:2 w:1) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) /// Storage: `MultiTransactionPayment::AcceptedCurrencies` (r:1 w:0) @@ -206,11 +213,11 @@ impl WeightInfo for HydraWeight { /// Proof: `MultiTransactionPayment::AccountCurrencyMap` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`) fn sell() -> Weight { // Proof Size summary in bytes: - // Measured: `3043` + // Measured: `3269` // Estimated: `19071` - // Minimum execution time: 730_301_000 picoseconds. - Weight::from_parts(735_887_000, 19071) - .saturating_add(T::DbWeight::get().reads(22)) + // Minimum execution time: 767_301_000 picoseconds. + Weight::from_parts(771_963_000, 19071) + .saturating_add(T::DbWeight::get().reads(24)) .saturating_add(T::DbWeight::get().writes(7)) } /// Storage: `Stableswap::AssetTradability` (r:2 w:0) @@ -219,10 +226,12 @@ impl WeightInfo for HydraWeight { /// Proof: `Stableswap::Pools` (`max_values`: None, `max_size`: Some(57), added: 2532, mode: `MaxEncodedLen`) /// Storage: `Tokens::Accounts` (r:7 w:4) /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::AssetMetadataMap` (r:5 w:0) - /// Proof: `AssetRegistry::AssetMetadataMap` (`max_values`: None, `max_size`: Some(46), added: 2521, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::Assets` (r:2 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::Assets` (r:5 w:0) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) + /// Storage: `Duster::AccountBlacklist` (r:2 w:0) + /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::BannedAssets` (r:2 w:0) + /// Proof: `AssetRegistry::BannedAssets` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:2 w:1) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) /// Storage: `MultiTransactionPayment::AccountCurrencyMap` (r:1 w:0) @@ -235,11 +244,11 @@ impl WeightInfo for HydraWeight { /// Proof: `EmaOracle::Accumulator` (`max_values`: Some(1), `max_size`: Some(5921), added: 6416, mode: `MaxEncodedLen`) fn buy() -> Weight { // Proof Size summary in bytes: - // Measured: `3013` + // Measured: `3239` // Estimated: `19071` - // Minimum execution time: 710_874_000 picoseconds. - Weight::from_parts(714_006_000, 19071) - .saturating_add(T::DbWeight::get().reads(23)) + // Minimum execution time: 745_716_000 picoseconds. + Weight::from_parts(748_811_000, 19071) + .saturating_add(T::DbWeight::get().reads(25)) .saturating_add(T::DbWeight::get().writes(6)) } /// Storage: `Stableswap::Pools` (r:1 w:0) @@ -250,8 +259,8 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `291` // Estimated: `3522` - // Minimum execution time: 25_547_000 picoseconds. - Weight::from_parts(25_951_000, 3522) + // Minimum execution time: 25_044_000 picoseconds. + Weight::from_parts(25_584_000, 3522) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -261,8 +270,8 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `291` // Estimated: `3522` - // Minimum execution time: 23_026_000 picoseconds. - Weight::from_parts(23_457_000, 3522) + // Minimum execution time: 22_703_000 picoseconds. + Weight::from_parts(23_093_000, 3522) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -272,8 +281,8 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `291` // Estimated: `3522` - // Minimum execution time: 24_839_000 picoseconds. - Weight::from_parts(25_332_000, 3522) + // Minimum execution time: 24_632_000 picoseconds. + Weight::from_parts(24_919_000, 3522) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -281,12 +290,14 @@ impl WeightInfo for HydraWeight { /// Proof: `Stableswap::Pools` (`max_values`: None, `max_size`: Some(57), added: 2532, mode: `MaxEncodedLen`) /// Storage: `Tokens::Accounts` (r:7 w:4) /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::AssetMetadataMap` (r:5 w:0) - /// Proof: `AssetRegistry::AssetMetadataMap` (`max_values`: None, `max_size`: Some(46), added: 2521, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::Assets` (r:5 w:0) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// Storage: `Stableswap::AssetTradability` (r:2 w:0) /// Proof: `Stableswap::AssetTradability` (`max_values`: None, `max_size`: Some(41), added: 2516, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::Assets` (r:2 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) + /// Storage: `Duster::AccountBlacklist` (r:2 w:0) + /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::BannedAssets` (r:2 w:0) + /// Proof: `AssetRegistry::BannedAssets` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:2 w:1) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) /// Storage: `MultiTransactionPayment::AcceptedCurrencies` (r:1 w:0) @@ -301,14 +312,14 @@ impl WeightInfo for HydraWeight { /// The range of component `e` is `[0, 1]`. fn router_execution_sell(_c: u32, e: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `1276 + e * (1767 ±0)` - // Estimated: `13905 + e * (5797 ±124_823_812_913_251_024)` - // Minimum execution time: 305_934_000 picoseconds. - Weight::from_parts(312_030_194, 13905) - // Standard Error: 324_777 - .saturating_add(Weight::from_parts(704_923_524, 0).saturating_mul(e.into())) + // Measured: `1555 + e * (1714 ±0)` + // Estimated: `13990 + e * (5797 ±245_709_589_663_843_264)` + // Minimum execution time: 314_654_000 picoseconds. + Weight::from_parts(321_208_138, 13990) + // Standard Error: 305_814 + .saturating_add(Weight::from_parts(731_985_555, 0).saturating_mul(e.into())) .saturating_add(T::DbWeight::get().reads(11)) - .saturating_add(T::DbWeight::get().reads((11_u64).saturating_mul(e.into()))) + .saturating_add(T::DbWeight::get().reads((13_u64).saturating_mul(e.into()))) .saturating_add(T::DbWeight::get().writes((7_u64).saturating_mul(e.into()))) .saturating_add(Weight::from_parts(0, 5797).saturating_mul(e.into())) } @@ -316,12 +327,14 @@ impl WeightInfo for HydraWeight { /// Proof: `Stableswap::Pools` (`max_values`: None, `max_size`: Some(57), added: 2532, mode: `MaxEncodedLen`) /// Storage: `Tokens::Accounts` (r:7 w:4) /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::AssetMetadataMap` (r:5 w:0) - /// Proof: `AssetRegistry::AssetMetadataMap` (`max_values`: None, `max_size`: Some(46), added: 2521, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::Assets` (r:5 w:0) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// Storage: `Stableswap::AssetTradability` (r:2 w:0) /// Proof: `Stableswap::AssetTradability` (`max_values`: None, `max_size`: Some(41), added: 2516, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::Assets` (r:2 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) + /// Storage: `Duster::AccountBlacklist` (r:2 w:0) + /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::BannedAssets` (r:2 w:0) + /// Proof: `AssetRegistry::BannedAssets` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:2 w:1) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) /// Storage: `MultiTransactionPayment::AccountCurrencyMap` (r:1 w:0) @@ -336,16 +349,16 @@ impl WeightInfo for HydraWeight { /// The range of component `e` is `[0, 1]`. fn router_execution_buy(c: u32, e: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `1275 + e * (1738 ±0)` - // Estimated: `13905 + e * (5797 ±201_913_854_157_949_888)` - // Minimum execution time: 304_954_000 picoseconds. - Weight::from_parts(306_226_000, 13905) - // Standard Error: 3_224_854 - .saturating_add(Weight::from_parts(12_176_535, 0).saturating_mul(c.into())) - // Standard Error: 7_079_475 - .saturating_add(Weight::from_parts(445_329_428, 0).saturating_mul(e.into())) + // Measured: `1554 + e * (1685 ±0)` + // Estimated: `13990 + e * (5797 ±201_913_854_157_949_888)` + // Minimum execution time: 312_997_000 picoseconds. + Weight::from_parts(314_359_000, 13990) + // Standard Error: 3_248_945 + .saturating_add(Weight::from_parts(12_345_948, 0).saturating_mul(c.into())) + // Standard Error: 7_132_362 + .saturating_add(Weight::from_parts(468_057_036, 0).saturating_mul(e.into())) .saturating_add(T::DbWeight::get().reads(11)) - .saturating_add(T::DbWeight::get().reads((12_u64).saturating_mul(e.into()))) + .saturating_add(T::DbWeight::get().reads((14_u64).saturating_mul(e.into()))) .saturating_add(T::DbWeight::get().writes((6_u64).saturating_mul(e.into()))) .saturating_add(Weight::from_parts(0, 5797).saturating_mul(e.into())) } diff --git a/runtime/hydradx/src/weights/staking.rs b/runtime/hydradx/src/weights/staking.rs index 35b209837..818119012 100644 --- a/runtime/hydradx/src/weights/staking.rs +++ b/runtime/hydradx/src/weights/staking.rs @@ -18,43 +18,36 @@ //! Autogenerated weights for `pallet_staking` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-12-12, STEPS: `5`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-02-15, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `bench-bot`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` -//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 // Executed Command: // target/release/hydradx // benchmark // pallet -// --pallet=pallet-staking +// --chain=dev +// --steps=10 +// --repeat=30 // --wasm-execution=compiled // --heap-pages=4096 -// --chain=dev +// --template=.maintain/pallet-weight-template-no-back.hbs +// --pallet=pallet_staking +// --output=./weights/staking.rs // --extrinsic=* -// --steps=5 -// --repeat=20 -// --output -// ./weights-1.1.0/staking.rs -// --template -// .maintain/pallet-weight-template-no-back.hbs +#![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] -#![allow(clippy::unnecessary_cast)] +#![allow(missing_docs)] -use frame_support::{ - traits::Get, - weights::{constants::RocksDbWeight, Weight}, -}; -use sp_std::marker::PhantomData; +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; -use pallet_staking::weights::WeightInfo; - -/// Weights for pallet_staking using the hydraDX node and recommended hardware. +/// Weight functions for `pallet_staking`. pub struct HydraWeight(PhantomData); - -impl WeightInfo for HydraWeight { +impl pallet_staking::WeightInfo for HydraWeight { /// Storage: `Staking::Staking` (r:1 w:1) /// Proof: `Staking::Staking` (`max_values`: Some(1), `max_size`: Some(48), added: 543, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:1 w:0) @@ -67,10 +60,10 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `513` // Estimated: `3655` - // Minimum execution time: 46_433_000 picoseconds. - Weight::from_parts(47_121_000, 3655) - .saturating_add(T::DbWeight::get().reads(3_u64)) - .saturating_add(T::DbWeight::get().writes(3_u64)) + // Minimum execution time: 45_589_000 picoseconds. + Weight::from_parts(46_388_000, 3655) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(3)) } /// Storage: `Staking::Staking` (r:1 w:1) /// Proof: `Staking::Staking` (`max_values`: Some(1), `max_size`: Some(48), added: 543, mode: `MaxEncodedLen`) @@ -96,10 +89,10 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `1240` // Estimated: `6196` - // Minimum execution time: 113_477_000 picoseconds. - Weight::from_parts(114_557_000, 6196) - .saturating_add(T::DbWeight::get().reads(10_u64)) - .saturating_add(T::DbWeight::get().writes(8_u64)) + // Minimum execution time: 112_917_000 picoseconds. + Weight::from_parts(113_568_000, 6196) + .saturating_add(T::DbWeight::get().reads(10)) + .saturating_add(T::DbWeight::get().writes(8)) } /// Storage: `Staking::Staking` (r:1 w:1) /// Proof: `Staking::Staking` (`max_values`: Some(1), `max_size`: Some(48), added: 543, mode: `MaxEncodedLen`) @@ -121,10 +114,10 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `3379` // Estimated: `268590` - // Minimum execution time: 297_204_000 picoseconds. - Weight::from_parts(300_714_000, 268590) - .saturating_add(T::DbWeight::get().reads(108_u64)) - .saturating_add(T::DbWeight::get().writes(6_u64)) + // Minimum execution time: 293_910_000 picoseconds. + Weight::from_parts(296_894_000, 268590) + .saturating_add(T::DbWeight::get().reads(108)) + .saturating_add(T::DbWeight::get().writes(6)) } /// Storage: `Staking::Staking` (r:1 w:1) /// Proof: `Staking::Staking` (`max_values`: Some(1), `max_size`: Some(48), added: 543, mode: `MaxEncodedLen`) @@ -146,10 +139,10 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `3379` // Estimated: `268590` - // Minimum execution time: 291_136_000 picoseconds. - Weight::from_parts(294_313_000, 268590) - .saturating_add(T::DbWeight::get().reads(108_u64)) - .saturating_add(T::DbWeight::get().writes(6_u64)) + // Minimum execution time: 286_701_000 picoseconds. + Weight::from_parts(288_861_000, 268590) + .saturating_add(T::DbWeight::get().reads(108)) + .saturating_add(T::DbWeight::get().writes(6)) } /// Storage: `Staking::Staking` (r:1 w:1) /// Proof: `Staking::Staking` (`max_values`: Some(1), `max_size`: Some(48), added: 543, mode: `MaxEncodedLen`) @@ -177,9 +170,9 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `3598` // Estimated: `268590` - // Minimum execution time: 330_733_000 picoseconds. - Weight::from_parts(334_301_000, 268590) - .saturating_add(T::DbWeight::get().reads(109_u64)) - .saturating_add(T::DbWeight::get().writes(10_u64)) + // Minimum execution time: 321_948_000 picoseconds. + Weight::from_parts(324_370_000, 268590) + .saturating_add(T::DbWeight::get().reads(109)) + .saturating_add(T::DbWeight::get().writes(10)) } -} +} \ No newline at end of file diff --git a/runtime/hydradx/src/weights/system.rs b/runtime/hydradx/src/weights/system.rs index 238cd887f..57270ed7c 100644 --- a/runtime/hydradx/src/weights/system.rs +++ b/runtime/hydradx/src/weights/system.rs @@ -18,62 +18,55 @@ //! Autogenerated weights for `frame_system` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-12-12, STEPS: `5`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-02-15, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `bench-bot`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` -//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 // Executed Command: // target/release/hydradx // benchmark // pallet -// --pallet=frame-system +// --chain=dev +// --steps=10 +// --repeat=30 // --wasm-execution=compiled // --heap-pages=4096 -// --chain=dev +// --template=.maintain/pallet-weight-template-no-back.hbs +// --pallet=frame-system +// --output=./weights/system.rs // --extrinsic=* -// --steps=5 -// --repeat=20 -// --output -// ./weights-1.1.0/system.rs -// --template -// .maintain/pallet-weight-template-no-back.hbs +#![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] -#![allow(clippy::unnecessary_cast)] - -use frame_support::{ - traits::Get, - weights::{constants::RocksDbWeight, Weight}, -}; -use sp_std::marker::PhantomData; +#![allow(missing_docs)] -use frame_system::weights::WeightInfo; +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; -/// Weights for frame_system using the hydraDX node and recommended hardware. +/// Weight functions for `frame_system`. pub struct HydraWeight(PhantomData); - -impl WeightInfo for HydraWeight { +impl frame_system::WeightInfo for HydraWeight { /// The range of component `b` is `[0, 3932160]`. - fn remark(b: u32) -> Weight { + fn remark(b: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 3_478_000 picoseconds. - Weight::from_parts(3_592_000, 0) + // Minimum execution time: 3_612_000 picoseconds. + Weight::from_parts(3_700_000, 0) // Standard Error: 0 - .saturating_add(Weight::from_parts(411, 0).saturating_mul(b.into())) + .saturating_add(Weight::from_parts(406, 0).saturating_mul(b.into())) } /// The range of component `b` is `[0, 3932160]`. - fn remark_with_event(b: u32) -> Weight { + fn remark_with_event(b: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 11_351_000 picoseconds. - Weight::from_parts(11_460_000, 0) + // Minimum execution time: 11_260_000 picoseconds. + Weight::from_parts(11_496_000, 0) // Standard Error: 1 - .saturating_add(Weight::from_parts(1_443, 0).saturating_mul(b.into())) + .saturating_add(Weight::from_parts(1_444, 0).saturating_mul(b.into())) } /// Storage: `System::Digest` (r:1 w:1) /// Proof: `System::Digest` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) @@ -83,10 +76,10 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `1485` - // Minimum execution time: 6_633_000 picoseconds. - Weight::from_parts(6_863_000, 1485) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) + // Minimum execution time: 6_621_000 picoseconds. + Weight::from_parts(6_809_000, 1485) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(2)) } /// Storage: `ParachainSystem::ValidationData` (r:1 w:0) /// Proof: `ParachainSystem::ValidationData` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) @@ -104,50 +97,50 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `198` // Estimated: `1683` - // Minimum execution time: 119_638_616_000 picoseconds. - Weight::from_parts(121_649_253_000, 1683) - .saturating_add(T::DbWeight::get().reads(4_u64)) - .saturating_add(T::DbWeight::get().writes(3_u64)) + // Minimum execution time: 117_242_692_000 picoseconds. + Weight::from_parts(118_784_037_000, 1683) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().writes(3)) } /// Storage: `Skipped::Metadata` (r:0 w:0) /// Proof: `Skipped::Metadata` (`max_values`: None, `max_size`: None, mode: `Measured`) /// The range of component `i` is `[0, 1000]`. - fn set_storage(i: u32) -> Weight { + fn set_storage(i: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 3_817_000 picoseconds. - Weight::from_parts(3_879_000, 0) - // Standard Error: 8_053 - .saturating_add(Weight::from_parts(944_155, 0).saturating_mul(i.into())) + // Minimum execution time: 3_808_000 picoseconds. + Weight::from_parts(3_867_000, 0) + // Standard Error: 3_843 + .saturating_add(Weight::from_parts(894_266, 0).saturating_mul(i.into())) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(i.into()))) } /// Storage: `Skipped::Metadata` (r:0 w:0) /// Proof: `Skipped::Metadata` (`max_values`: None, `max_size`: None, mode: `Measured`) /// The range of component `i` is `[0, 1000]`. - fn kill_storage(i: u32) -> Weight { + fn kill_storage(i: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 3_690_000 picoseconds. - Weight::from_parts(3_824_000, 0) - // Standard Error: 2_460 - .saturating_add(Weight::from_parts(642_858, 0).saturating_mul(i.into())) + // Minimum execution time: 3_791_000 picoseconds. + Weight::from_parts(3_854_000, 0) + // Standard Error: 1_362 + .saturating_add(Weight::from_parts(614_354, 0).saturating_mul(i.into())) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(i.into()))) } /// Storage: `Skipped::Metadata` (r:0 w:0) /// Proof: `Skipped::Metadata` (`max_values`: None, `max_size`: None, mode: `Measured`) /// The range of component `p` is `[0, 1000]`. - fn kill_prefix(p: u32) -> Weight { + fn kill_prefix(p: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `194 + p * (69 ±0)` - // Estimated: `148 + p * (70 ±0)` - // Minimum execution time: 7_319_000 picoseconds. - Weight::from_parts(7_381_000, 148) - // Standard Error: 2_908 - .saturating_add(Weight::from_parts(1_100_356, 0).saturating_mul(p.into())) + // Measured: `119 + p * (69 ±0)` + // Estimated: `130 + p * (70 ±0)` + // Minimum execution time: 7_002_000 picoseconds. + Weight::from_parts(7_100_000, 130) + // Standard Error: 1_619 + .saturating_add(Weight::from_parts(1_101_962, 0).saturating_mul(p.into())) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(p.into()))) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(p.into()))) .saturating_add(Weight::from_parts(0, 70).saturating_mul(p.into())) } -} +} \ No newline at end of file diff --git a/runtime/hydradx/src/weights/technical_committee.rs b/runtime/hydradx/src/weights/technical_committee.rs index 78bba68bf..f8e7d2eb2 100644 --- a/runtime/hydradx/src/weights/technical_committee.rs +++ b/runtime/hydradx/src/weights/technical_committee.rs @@ -18,42 +18,37 @@ //! Autogenerated weights for `tech` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-12-12, STEPS: `5`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-02-15, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `bench-bot`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` -//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 // Executed Command: // target/release/hydradx // benchmark // pallet -// --pallet=tech +// --chain=dev +// --steps=10 +// --repeat=30 // --wasm-execution=compiled // --heap-pages=4096 -// --chain=dev +// --template=.maintain/pallet-weight-template-no-back.hbs +// --pallet=tech +// --output=./weights/technical_committee.rs // --extrinsic=* -// --steps=5 -// --repeat=20 -// --output -// ./weights-1.1.0/technical_committee.rs -// --template -// .maintain/pallet-weight-template-no-back.hbs +#![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] -#![allow(clippy::unnecessary_cast)] +#![allow(missing_docs)] -use frame_support::{ - traits::Get, - weights::{constants::RocksDbWeight, Weight}, -}; -use sp_std::marker::PhantomData; +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; use pallet_collective::WeightInfo; -/// Weights for tech using the hydraDX node and recommended hardware. +/// Weight functions for `tech`. pub struct HydraWeight(PhantomData); - impl WeightInfo for HydraWeight { /// Storage: `TechnicalCommittee::Members` (r:1 w:1) /// Proof: `TechnicalCommittee::Members` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) @@ -66,40 +61,38 @@ impl WeightInfo for HydraWeight { /// The range of component `m` is `[0, 10]`. /// The range of component `n` is `[0, 10]`. /// The range of component `p` is `[0, 20]`. - fn set_members(m: u32, _n: u32, p: u32) -> Weight { + fn set_members(m: u32, _n: u32, p: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `0 + m * (666 ±0) + p * (310 ±0)` - // Estimated: `15440 + m * (409 ±16) + p * (2331 ±8)` - // Minimum execution time: 13_516_000 picoseconds. - Weight::from_parts(13_611_000, 15440) - // Standard Error: 346_205 - .saturating_add(Weight::from_parts(3_915_806, 0).saturating_mul(m.into())) - // Standard Error: 174_852 - .saturating_add(Weight::from_parts(3_762_675, 0).saturating_mul(p.into())) - .saturating_add(T::DbWeight::get().reads(2_u64)) - .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(m.into()))) + // Measured: `0 + m * (672 ±0) + p * (310 ±0)` + // Estimated: `7085 + m * (396 ±7) + p * (2539 ±3)` + // Minimum execution time: 13_876_000 picoseconds. + Weight::from_parts(14_129_000, 7085) + // Standard Error: 155_547 + .saturating_add(Weight::from_parts(2_657_114, 0).saturating_mul(m.into())) + // Standard Error: 78_133 + .saturating_add(Weight::from_parts(4_151_945, 0).saturating_mul(p.into())) + .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(p.into()))) - .saturating_add(T::DbWeight::get().writes(2_u64)) - .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(m.into()))) + .saturating_add(T::DbWeight::get().writes(2)) .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(p.into()))) - .saturating_add(Weight::from_parts(0, 409).saturating_mul(m.into())) - .saturating_add(Weight::from_parts(0, 2331).saturating_mul(p.into())) + .saturating_add(Weight::from_parts(0, 396).saturating_mul(m.into())) + .saturating_add(Weight::from_parts(0, 2539).saturating_mul(p.into())) } /// Storage: `TechnicalCommittee::Members` (r:1 w:0) /// Proof: `TechnicalCommittee::Members` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) /// The range of component `b` is `[2, 1024]`. /// The range of component `m` is `[1, 10]`. - fn execute(b: u32, m: u32) -> Weight { + fn execute(b: u32, m: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `70 + m * (32 ±0)` - // Estimated: `1554 + m * (32 ±0)` - // Minimum execution time: 21_681_000 picoseconds. - Weight::from_parts(21_863_772, 1554) - // Standard Error: 55 - .saturating_add(Weight::from_parts(1_268, 0).saturating_mul(b.into())) - // Standard Error: 6_176 - .saturating_add(Weight::from_parts(21_902, 0).saturating_mul(m.into())) - .saturating_add(T::DbWeight::get().reads(1_u64)) + // Estimated: `1555 + m * (32 ±0)` + // Minimum execution time: 22_086_000 picoseconds. + Weight::from_parts(22_142_927, 1555) + // Standard Error: 27 + .saturating_add(Weight::from_parts(1_188, 0).saturating_mul(b.into())) + // Standard Error: 3_174 + .saturating_add(Weight::from_parts(24_985, 0).saturating_mul(m.into())) + .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(Weight::from_parts(0, 32).saturating_mul(m.into())) } /// Storage: `TechnicalCommittee::Members` (r:1 w:0) @@ -108,17 +101,17 @@ impl WeightInfo for HydraWeight { /// Proof: `TechnicalCommittee::ProposalOf` (`max_values`: None, `max_size`: None, mode: `Measured`) /// The range of component `b` is `[2, 1024]`. /// The range of component `m` is `[1, 10]`. - fn propose_execute(b: u32, m: u32) -> Weight { + fn propose_execute(b: u32, m: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `70 + m * (32 ±0)` - // Estimated: `3534 + m * (32 ±0)` - // Minimum execution time: 25_160_000 picoseconds. - Weight::from_parts(25_278_856, 3534) - // Standard Error: 55 - .saturating_add(Weight::from_parts(1_402, 0).saturating_mul(b.into())) - // Standard Error: 6_187 - .saturating_add(Weight::from_parts(55_858, 0).saturating_mul(m.into())) - .saturating_add(T::DbWeight::get().reads(2_u64)) + // Estimated: `3535 + m * (32 ±0)` + // Minimum execution time: 25_870_000 picoseconds. + Weight::from_parts(25_809_413, 3535) + // Standard Error: 26 + .saturating_add(Weight::from_parts(1_349, 0).saturating_mul(b.into())) + // Standard Error: 3_065 + .saturating_add(Weight::from_parts(39_651, 0).saturating_mul(m.into())) + .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(Weight::from_parts(0, 32).saturating_mul(m.into())) } /// Storage: `TechnicalCommittee::Members` (r:1 w:0) @@ -134,38 +127,38 @@ impl WeightInfo for HydraWeight { /// The range of component `b` is `[2, 1024]`. /// The range of component `m` is `[2, 10]`. /// The range of component `p` is `[1, 20]`. - fn propose_proposed(b: u32, m: u32, p: u32) -> Weight { + fn propose_proposed(b: u32, m: u32, p: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `0 + m * (32 ±0) + p * (58 ±0)` - // Estimated: `3460 + m * (36 ±1) + p * (56 ±0)` - // Minimum execution time: 32_705_000 picoseconds. - Weight::from_parts(30_842_242, 3460) - // Standard Error: 168 - .saturating_add(Weight::from_parts(2_782, 0).saturating_mul(b.into())) - // Standard Error: 21_583 - .saturating_add(Weight::from_parts(45_202, 0).saturating_mul(m.into())) - // Standard Error: 8_890 - .saturating_add(Weight::from_parts(408_142, 0).saturating_mul(p.into())) - .saturating_add(T::DbWeight::get().reads(4_u64)) - .saturating_add(T::DbWeight::get().writes(4_u64)) - .saturating_add(Weight::from_parts(0, 36).saturating_mul(m.into())) - .saturating_add(Weight::from_parts(0, 56).saturating_mul(p.into())) + // Measured: `156 + m * (32 ±0) + p * (50 ±0)` + // Estimated: `3574 + m * (32 ±0) + p * (53 ±0)` + // Minimum execution time: 33_389_000 picoseconds. + Weight::from_parts(33_070_270, 3574) + // Standard Error: 101 + .saturating_add(Weight::from_parts(2_087, 0).saturating_mul(b.into())) + // Standard Error: 12_061 + .saturating_add(Weight::from_parts(57_103, 0).saturating_mul(m.into())) + // Standard Error: 5_380 + .saturating_add(Weight::from_parts(365_489, 0).saturating_mul(p.into())) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().writes(4)) + .saturating_add(Weight::from_parts(0, 32).saturating_mul(m.into())) + .saturating_add(Weight::from_parts(0, 53).saturating_mul(p.into())) } /// Storage: `TechnicalCommittee::Members` (r:1 w:0) /// Proof: `TechnicalCommittee::Members` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) /// Storage: `TechnicalCommittee::Voting` (r:1 w:1) /// Proof: `TechnicalCommittee::Voting` (`max_values`: None, `max_size`: None, mode: `Measured`) /// The range of component `m` is `[5, 10]`. - fn vote(m: u32) -> Weight { + fn vote(m: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `538 + m * (64 ±0)` // Estimated: `4003 + m * (64 ±0)` - // Minimum execution time: 26_154_000 picoseconds. - Weight::from_parts(26_371_710, 4003) - // Standard Error: 9_771 - .saturating_add(Weight::from_parts(58_004, 0).saturating_mul(m.into())) - .saturating_add(T::DbWeight::get().reads(2_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 26_815_000 picoseconds. + Weight::from_parts(27_021_617, 4003) + // Standard Error: 4_949 + .saturating_add(Weight::from_parts(61_849, 0).saturating_mul(m.into())) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(1)) .saturating_add(Weight::from_parts(0, 64).saturating_mul(m.into())) } /// Storage: `TechnicalCommittee::Voting` (r:1 w:1) @@ -178,17 +171,19 @@ impl WeightInfo for HydraWeight { /// Proof: `TechnicalCommittee::ProposalOf` (`max_values`: None, `max_size`: None, mode: `Measured`) /// The range of component `m` is `[4, 10]`. /// The range of component `p` is `[1, 20]`. - fn close_early_disapproved(m: u32, p: u32) -> Weight { + fn close_early_disapproved(m: u32, p: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `231 + m * (64 ±0) + p * (48 ±0)` - // Estimated: `3651 + m * (66 ±1) + p * (50 ±0)` - // Minimum execution time: 34_121_000 picoseconds. - Weight::from_parts(35_042_411, 3651) - // Standard Error: 5_417 - .saturating_add(Weight::from_parts(321_198, 0).saturating_mul(p.into())) - .saturating_add(T::DbWeight::get().reads(3_u64)) - .saturating_add(T::DbWeight::get().writes(3_u64)) - .saturating_add(Weight::from_parts(0, 66).saturating_mul(m.into())) + // Measured: `208 + m * (64 ±0) + p * (49 ±0)` + // Estimated: `3640 + m * (69 ±0) + p * (50 ±0)` + // Minimum execution time: 35_042_000 picoseconds. + Weight::from_parts(36_087_417, 3640) + // Standard Error: 12_149 + .saturating_add(Weight::from_parts(3_876, 0).saturating_mul(m.into())) + // Standard Error: 3_989 + .saturating_add(Weight::from_parts(297_818, 0).saturating_mul(p.into())) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(3)) + .saturating_add(Weight::from_parts(0, 69).saturating_mul(m.into())) .saturating_add(Weight::from_parts(0, 50).saturating_mul(p.into())) } /// Storage: `TechnicalCommittee::Voting` (r:1 w:1) @@ -202,23 +197,23 @@ impl WeightInfo for HydraWeight { /// The range of component `b` is `[2, 1024]`. /// The range of component `m` is `[4, 10]`. /// The range of component `p` is `[1, 20]`. - fn close_early_approved(b: u32, m: u32, p: u32) -> Weight { + fn close_early_approved(b: u32, m: u32, p: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `178 + b * (1 ±0) + m * (64 ±0) + p * (71 ±0)` - // Estimated: `3620 + b * (1 ±0) + m * (71 ±3) + p * (69 ±0)` - // Minimum execution time: 49_393_000 picoseconds. - Weight::from_parts(49_577_674, 3620) - // Standard Error: 179 - .saturating_add(Weight::from_parts(1_043, 0).saturating_mul(b.into())) - // Standard Error: 29_444 - .saturating_add(Weight::from_parts(20_887, 0).saturating_mul(m.into())) - // Standard Error: 9_451 - .saturating_add(Weight::from_parts(371_478, 0).saturating_mul(p.into())) - .saturating_add(T::DbWeight::get().reads(4_u64)) - .saturating_add(T::DbWeight::get().writes(3_u64)) + // Measured: `290 + b * (1 ±0) + m * (64 ±0) + p * (65 ±0)` + // Estimated: `3656 + b * (1 ±0) + m * (69 ±1) + p * (66 ±0)` + // Minimum execution time: 50_836_000 picoseconds. + Weight::from_parts(50_461_445, 3656) + // Standard Error: 117 + .saturating_add(Weight::from_parts(1_279, 0).saturating_mul(b.into())) + // Standard Error: 18_953 + .saturating_add(Weight::from_parts(100_270, 0).saturating_mul(m.into())) + // Standard Error: 6_210 + .saturating_add(Weight::from_parts(330_642, 0).saturating_mul(p.into())) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().writes(3)) .saturating_add(Weight::from_parts(0, 1).saturating_mul(b.into())) - .saturating_add(Weight::from_parts(0, 71).saturating_mul(m.into())) - .saturating_add(Weight::from_parts(0, 69).saturating_mul(p.into())) + .saturating_add(Weight::from_parts(0, 69).saturating_mul(m.into())) + .saturating_add(Weight::from_parts(0, 66).saturating_mul(p.into())) } /// Storage: `TechnicalCommittee::Voting` (r:1 w:1) /// Proof: `TechnicalCommittee::Voting` (`max_values`: None, `max_size`: None, mode: `Measured`) @@ -232,19 +227,19 @@ impl WeightInfo for HydraWeight { /// Proof: `TechnicalCommittee::ProposalOf` (`max_values`: None, `max_size`: None, mode: `Measured`) /// The range of component `m` is `[4, 10]`. /// The range of component `p` is `[1, 20]`. - fn close_disapproved(m: u32, p: u32) -> Weight { + fn close_disapproved(m: u32, p: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `251 + m * (64 ±0) + p * (48 ±0)` - // Estimated: `3671 + m * (66 ±1) + p * (50 ±0)` - // Minimum execution time: 37_061_000 picoseconds. - Weight::from_parts(37_585_589, 3671) - // Standard Error: 18_492 - .saturating_add(Weight::from_parts(16_560, 0).saturating_mul(m.into())) - // Standard Error: 5_928 - .saturating_add(Weight::from_parts(325_412, 0).saturating_mul(p.into())) - .saturating_add(T::DbWeight::get().reads(4_u64)) - .saturating_add(T::DbWeight::get().writes(3_u64)) - .saturating_add(Weight::from_parts(0, 66).saturating_mul(m.into())) + // Measured: `228 + m * (64 ±0) + p * (49 ±0)` + // Estimated: `3660 + m * (69 ±0) + p * (50 ±0)` + // Minimum execution time: 38_419_000 picoseconds. + Weight::from_parts(39_480_671, 3660) + // Standard Error: 14_633 + .saturating_add(Weight::from_parts(23_963, 0).saturating_mul(m.into())) + // Standard Error: 4_805 + .saturating_add(Weight::from_parts(275_614, 0).saturating_mul(p.into())) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().writes(3)) + .saturating_add(Weight::from_parts(0, 69).saturating_mul(m.into())) .saturating_add(Weight::from_parts(0, 50).saturating_mul(p.into())) } /// Storage: `TechnicalCommittee::Voting` (r:1 w:1) @@ -260,23 +255,23 @@ impl WeightInfo for HydraWeight { /// The range of component `b` is `[2, 1024]`. /// The range of component `m` is `[4, 10]`. /// The range of component `p` is `[1, 20]`. - fn close_approved(b: u32, m: u32, p: u32) -> Weight { + fn close_approved(b: u32, m: u32, p: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `198 + b * (1 ±0) + m * (64 ±0) + p * (71 ±0)` - // Estimated: `3640 + b * (1 ±0) + m * (71 ±3) + p * (69 ±0)` - // Minimum execution time: 52_845_000 picoseconds. - Weight::from_parts(52_535_618, 3640) - // Standard Error: 191 - .saturating_add(Weight::from_parts(1_017, 0).saturating_mul(b.into())) - // Standard Error: 31_471 - .saturating_add(Weight::from_parts(81_957, 0).saturating_mul(m.into())) - // Standard Error: 10_102 - .saturating_add(Weight::from_parts(356_674, 0).saturating_mul(p.into())) - .saturating_add(T::DbWeight::get().reads(5_u64)) - .saturating_add(T::DbWeight::get().writes(3_u64)) + // Measured: `310 + b * (1 ±0) + m * (64 ±0) + p * (65 ±0)` + // Estimated: `3676 + b * (1 ±0) + m * (69 ±1) + p * (66 ±0)` + // Minimum execution time: 53_648_000 picoseconds. + Weight::from_parts(54_698_175, 3676) + // Standard Error: 135 + .saturating_add(Weight::from_parts(1_012, 0).saturating_mul(b.into())) + // Standard Error: 21_972 + .saturating_add(Weight::from_parts(50_246, 0).saturating_mul(m.into())) + // Standard Error: 7_199 + .saturating_add(Weight::from_parts(311_701, 0).saturating_mul(p.into())) + .saturating_add(T::DbWeight::get().reads(5)) + .saturating_add(T::DbWeight::get().writes(3)) .saturating_add(Weight::from_parts(0, 1).saturating_mul(b.into())) - .saturating_add(Weight::from_parts(0, 71).saturating_mul(m.into())) - .saturating_add(Weight::from_parts(0, 69).saturating_mul(p.into())) + .saturating_add(Weight::from_parts(0, 69).saturating_mul(m.into())) + .saturating_add(Weight::from_parts(0, 66).saturating_mul(p.into())) } /// Storage: `TechnicalCommittee::Proposals` (r:1 w:1) /// Proof: `TechnicalCommittee::Proposals` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) @@ -285,16 +280,16 @@ impl WeightInfo for HydraWeight { /// Storage: `TechnicalCommittee::ProposalOf` (r:0 w:1) /// Proof: `TechnicalCommittee::ProposalOf` (`max_values`: None, `max_size`: None, mode: `Measured`) /// The range of component `p` is `[1, 20]`. - fn disapprove_proposal(p: u32) -> Weight { + fn disapprove_proposal(p: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `226 + p * (32 ±0)` - // Estimated: `1710 + p * (32 ±0)` - // Minimum execution time: 22_267_000 picoseconds. - Weight::from_parts(22_677_377, 1710) - // Standard Error: 4_842 - .saturating_add(Weight::from_parts(232_066, 0).saturating_mul(p.into())) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(3_u64)) + // Estimated: `1711 + p * (32 ±0)` + // Minimum execution time: 22_647_000 picoseconds. + Weight::from_parts(23_173_979, 1711) + // Standard Error: 3_421 + .saturating_add(Weight::from_parts(222_829, 0).saturating_mul(p.into())) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(3)) .saturating_add(Weight::from_parts(0, 32).saturating_mul(p.into())) } } diff --git a/runtime/hydradx/src/weights/timestamp.rs b/runtime/hydradx/src/weights/timestamp.rs index c6da1f0a6..07f6fac65 100644 --- a/runtime/hydradx/src/weights/timestamp.rs +++ b/runtime/hydradx/src/weights/timestamp.rs @@ -18,59 +18,52 @@ //! Autogenerated weights for `pallet_timestamp` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-12-12, STEPS: `5`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-02-15, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `bench-bot`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` -//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 // Executed Command: // target/release/hydradx // benchmark // pallet -// --pallet=pallet-timestamp +// --chain=dev +// --steps=10 +// --repeat=30 // --wasm-execution=compiled // --heap-pages=4096 -// --chain=dev +// --template=.maintain/pallet-weight-template-no-back.hbs +// --pallet=pallet_timestamp +// --output=./weights/timestamp.rs // --extrinsic=* -// --steps=5 -// --repeat=20 -// --output -// ./weights-1.1.0/timestamp.rs -// --template -// .maintain/pallet-weight-template-no-back.hbs +#![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] -#![allow(clippy::unnecessary_cast)] +#![allow(missing_docs)] -use frame_support::{ - traits::Get, - weights::{constants::RocksDbWeight, Weight}, -}; -use sp_std::marker::PhantomData; +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; -use pallet_timestamp::weights::WeightInfo; - -/// Weights for pallet_timestamp using the hydraDX node and recommended hardware. +/// Weight functions for `pallet_timestamp`. pub struct HydraWeight(PhantomData); - -impl WeightInfo for HydraWeight { +impl pallet_timestamp::WeightInfo for HydraWeight { /// Storage: `Timestamp::Now` (r:1 w:1) /// Proof: `Timestamp::Now` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) fn set() -> Weight { // Proof Size summary in bytes: // Measured: `42` // Estimated: `1493` - // Minimum execution time: 9_605_000 picoseconds. - Weight::from_parts(9_858_000, 1493) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 9_400_000 picoseconds. + Weight::from_parts(9_641_000, 1493) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } fn on_finalize() -> Weight { // Proof Size summary in bytes: // Measured: `94` // Estimated: `0` - // Minimum execution time: 4_868_000 picoseconds. - Weight::from_parts(4_992_000, 0) + // Minimum execution time: 4_863_000 picoseconds. + Weight::from_parts(5_000_000, 0) } -} +} \ No newline at end of file diff --git a/runtime/hydradx/src/weights/tokens.rs b/runtime/hydradx/src/weights/tokens.rs index 47a4ab420..51a44f5c7 100644 --- a/runtime/hydradx/src/weights/tokens.rs +++ b/runtime/hydradx/src/weights/tokens.rs @@ -18,123 +18,164 @@ //! Autogenerated weights for `orml_tokens` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-12-12, STEPS: `5`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-02-15, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `bench-bot`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` -//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 // Executed Command: // target/release/hydradx // benchmark // pallet -// --pallet=orml-tokens +// --chain=dev +// --steps=10 +// --repeat=30 // --wasm-execution=compiled // --heap-pages=4096 -// --chain=dev +// --template=.maintain/pallet-weight-template-no-back.hbs +// --pallet=orml_tokens +// --output=./weights/tokens.rs // --extrinsic=* -// --steps=5 -// --repeat=20 -// --output -// ./weights-1.1.0/tokens.rs -// --template -// .maintain/pallet-weight-template-no-back.hbs +#![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] -#![allow(clippy::unnecessary_cast)] - -use frame_support::{ - traits::Get, - weights::{constants::RocksDbWeight, Weight}, -}; -use sp_std::marker::PhantomData; +#![allow(missing_docs)] -use orml_tokens::WeightInfo; +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; -/// Weights for orml_tokens using the hydraDX node and recommended hardware. +/// Weight functions for `orml_tokens`. pub struct HydraWeight(PhantomData); - -impl WeightInfo for HydraWeight { - /// Storage: `Tokens::Accounts` (r:2 w:2) +impl orml_tokens::WeightInfo for HydraWeight { + /// Storage: `Duster::AccountBlacklist` (r:1 w:0) + /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::BannedAssets` (r:2 w:0) + /// Proof: `AssetRegistry::BannedAssets` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`) + /// Storage: `Tokens::Accounts` (r:4 w:4) /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::Assets` (r:1 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) - /// Storage: `System::Account` (r:1 w:1) - /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) - /// Storage: `MultiTransactionPayment::AccountCurrencyMap` (r:1 w:1) + /// Storage: `AssetRegistry::Assets` (r:2 w:0) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) + /// Storage: `MultiTransactionPayment::AccountCurrencyMap` (r:3 w:0) /// Proof: `MultiTransactionPayment::AccountCurrencyMap` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`) - /// Storage: `MultiTransactionPayment::AcceptedCurrencies` (r:1 w:0) + /// Storage: `MultiTransactionPayment::AcceptedCurrencyPrice` (r:1 w:0) + /// Proof: `MultiTransactionPayment::AcceptedCurrencyPrice` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:3 w:3) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `MultiTransactionPayment::AcceptedCurrencies` (r:2 w:0) /// Proof: `MultiTransactionPayment::AcceptedCurrencies` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) + /// Storage: `Balances::Locks` (r:1 w:1) + /// Proof: `Balances::Locks` (`max_values`: None, `max_size`: Some(1299), added: 3774, mode: `MaxEncodedLen`) + /// Storage: `Balances::Freezes` (r:1 w:0) + /// Proof: `Balances::Freezes` (`max_values`: None, `max_size`: Some(49), added: 2524, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::ExistentialDepositCounter` (r:1 w:1) + /// Proof: `AssetRegistry::ExistentialDepositCounter` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) fn transfer() -> Weight { // Proof Size summary in bytes: - // Measured: `2335` - // Estimated: `6156` - // Minimum execution time: 91_456_000 picoseconds. - Weight::from_parts(92_161_000, 6156) - .saturating_add(T::DbWeight::get().reads(6_u64)) - .saturating_add(T::DbWeight::get().writes(4_u64)) + // Measured: `3102` + // Estimated: `11322` + // Minimum execution time: 282_258_000 picoseconds. + Weight::from_parts(285_181_000, 11322) + .saturating_add(T::DbWeight::get().reads(21)) + .saturating_add(T::DbWeight::get().writes(9)) } - /// Storage: `Tokens::Accounts` (r:2 w:2) + /// Storage: `Tokens::Accounts` (r:4 w:4) /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::Assets` (r:1 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) - /// Storage: `System::Account` (r:1 w:1) + /// Storage: `System::Account` (r:3 w:3) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) - /// Storage: `MultiTransactionPayment::AccountCurrencyMap` (r:1 w:1) + /// Storage: `Duster::AccountBlacklist` (r:1 w:0) + /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::BannedAssets` (r:2 w:0) + /// Proof: `AssetRegistry::BannedAssets` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::Assets` (r:2 w:0) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) + /// Storage: `MultiTransactionPayment::AccountCurrencyMap` (r:3 w:0) /// Proof: `MultiTransactionPayment::AccountCurrencyMap` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`) - /// Storage: `MultiTransactionPayment::AcceptedCurrencies` (r:1 w:0) + /// Storage: `MultiTransactionPayment::AcceptedCurrencyPrice` (r:1 w:0) + /// Proof: `MultiTransactionPayment::AcceptedCurrencyPrice` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) + /// Storage: `MultiTransactionPayment::AcceptedCurrencies` (r:2 w:0) /// Proof: `MultiTransactionPayment::AcceptedCurrencies` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) + /// Storage: `Balances::Locks` (r:1 w:1) + /// Proof: `Balances::Locks` (`max_values`: None, `max_size`: Some(1299), added: 3774, mode: `MaxEncodedLen`) + /// Storage: `Balances::Freezes` (r:1 w:0) + /// Proof: `Balances::Freezes` (`max_values`: None, `max_size`: Some(49), added: 2524, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::ExistentialDepositCounter` (r:1 w:1) + /// Proof: `AssetRegistry::ExistentialDepositCounter` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) fn transfer_all() -> Weight { // Proof Size summary in bytes: - // Measured: `2335` - // Estimated: `6156` - // Minimum execution time: 95_160_000 picoseconds. - Weight::from_parts(95_870_000, 6156) - .saturating_add(T::DbWeight::get().reads(6_u64)) - .saturating_add(T::DbWeight::get().writes(4_u64)) + // Measured: `3154` + // Estimated: `11322` + // Minimum execution time: 286_100_000 picoseconds. + Weight::from_parts(287_775_000, 11322) + .saturating_add(T::DbWeight::get().reads(21)) + .saturating_add(T::DbWeight::get().writes(9)) } - /// Storage: `Tokens::Accounts` (r:2 w:2) + /// Storage: `Duster::AccountBlacklist` (r:1 w:0) + /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::BannedAssets` (r:2 w:0) + /// Proof: `AssetRegistry::BannedAssets` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`) + /// Storage: `Tokens::Accounts` (r:4 w:4) /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::Assets` (r:1 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) - /// Storage: `System::Account` (r:1 w:1) - /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) - /// Storage: `MultiTransactionPayment::AccountCurrencyMap` (r:1 w:0) + /// Storage: `AssetRegistry::Assets` (r:2 w:0) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) + /// Storage: `MultiTransactionPayment::AccountCurrencyMap` (r:3 w:0) /// Proof: `MultiTransactionPayment::AccountCurrencyMap` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`) - /// Storage: `MultiTransactionPayment::AcceptedCurrencies` (r:1 w:0) + /// Storage: `MultiTransactionPayment::AcceptedCurrencyPrice` (r:1 w:0) + /// Proof: `MultiTransactionPayment::AcceptedCurrencyPrice` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:3 w:2) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `MultiTransactionPayment::AcceptedCurrencies` (r:2 w:0) /// Proof: `MultiTransactionPayment::AcceptedCurrencies` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) + /// Storage: `Balances::Locks` (r:1 w:1) + /// Proof: `Balances::Locks` (`max_values`: None, `max_size`: Some(1299), added: 3774, mode: `MaxEncodedLen`) + /// Storage: `Balances::Freezes` (r:1 w:0) + /// Proof: `Balances::Freezes` (`max_values`: None, `max_size`: Some(49), added: 2524, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::ExistentialDepositCounter` (r:1 w:1) + /// Proof: `AssetRegistry::ExistentialDepositCounter` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) fn transfer_keep_alive() -> Weight { // Proof Size summary in bytes: - // Measured: `2195` - // Estimated: `6156` - // Minimum execution time: 75_713_000 picoseconds. - Weight::from_parts(76_553_000, 6156) - .saturating_add(T::DbWeight::get().reads(6_u64)) - .saturating_add(T::DbWeight::get().writes(3_u64)) + // Measured: `3152` + // Estimated: `11322` + // Minimum execution time: 198_176_000 picoseconds. + Weight::from_parts(199_598_000, 11322) + .saturating_add(T::DbWeight::get().reads(21)) + .saturating_add(T::DbWeight::get().writes(8)) } - /// Storage: `Tokens::Accounts` (r:2 w:2) + /// Storage: `Duster::AccountBlacklist` (r:1 w:0) + /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::BannedAssets` (r:2 w:0) + /// Proof: `AssetRegistry::BannedAssets` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`) + /// Storage: `Tokens::Accounts` (r:4 w:4) /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::Assets` (r:1 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) - /// Storage: `System::Account` (r:2 w:1) - /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) - /// Storage: `MultiTransactionPayment::AccountCurrencyMap` (r:1 w:0) + /// Storage: `AssetRegistry::Assets` (r:2 w:0) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) + /// Storage: `MultiTransactionPayment::AccountCurrencyMap` (r:3 w:0) /// Proof: `MultiTransactionPayment::AccountCurrencyMap` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`) - /// Storage: `MultiTransactionPayment::AcceptedCurrencies` (r:1 w:0) + /// Storage: `MultiTransactionPayment::AcceptedCurrencyPrice` (r:1 w:0) + /// Proof: `MultiTransactionPayment::AcceptedCurrencyPrice` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:3 w:3) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `MultiTransactionPayment::AcceptedCurrencies` (r:2 w:0) /// Proof: `MultiTransactionPayment::AcceptedCurrencies` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) + /// Storage: `Balances::Locks` (r:1 w:1) + /// Proof: `Balances::Locks` (`max_values`: None, `max_size`: Some(1299), added: 3774, mode: `MaxEncodedLen`) + /// Storage: `Balances::Freezes` (r:1 w:0) + /// Proof: `Balances::Freezes` (`max_values`: None, `max_size`: Some(49), added: 2524, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::ExistentialDepositCounter` (r:1 w:1) + /// Proof: `AssetRegistry::ExistentialDepositCounter` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) fn force_transfer() -> Weight { // Proof Size summary in bytes: - // Measured: `2333` - // Estimated: `6196` - // Minimum execution time: 79_242_000 picoseconds. - Weight::from_parts(79_954_000, 6196) - .saturating_add(T::DbWeight::get().reads(7_u64)) - .saturating_add(T::DbWeight::get().writes(3_u64)) + // Measured: `3154` + // Estimated: `11322` + // Minimum execution time: 282_695_000 picoseconds. + Weight::from_parts(284_482_000, 11322) + .saturating_add(T::DbWeight::get().reads(21)) + .saturating_add(T::DbWeight::get().writes(9)) } /// Storage: `Tokens::Accounts` (r:1 w:1) /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::Assets` (r:1 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) /// Storage: `Tokens::TotalIssuance` (r:1 w:1) /// Proof: `Tokens::TotalIssuance` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:1 w:1) @@ -145,11 +186,11 @@ impl WeightInfo for HydraWeight { /// Proof: `MultiTransactionPayment::AcceptedCurrencies` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) fn set_balance() -> Weight { // Proof Size summary in bytes: - // Measured: `2127` + // Measured: `2143` // Estimated: `3593` - // Minimum execution time: 68_117_000 picoseconds. - Weight::from_parts(68_690_000, 3593) - .saturating_add(T::DbWeight::get().reads(6_u64)) - .saturating_add(T::DbWeight::get().writes(3_u64)) + // Minimum execution time: 67_017_000 picoseconds. + Weight::from_parts(67_929_000, 3593) + .saturating_add(T::DbWeight::get().reads(6)) + .saturating_add(T::DbWeight::get().writes(3)) } -} +} \ No newline at end of file diff --git a/runtime/hydradx/src/weights/transaction_pause.rs b/runtime/hydradx/src/weights/transaction_pause.rs index a8c7f1e5d..37995911f 100644 --- a/runtime/hydradx/src/weights/transaction_pause.rs +++ b/runtime/hydradx/src/weights/transaction_pause.rs @@ -18,63 +18,56 @@ //! Autogenerated weights for `pallet_transaction_pause` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-12-12, STEPS: `5`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-02-15, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `bench-bot`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` -//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 // Executed Command: // target/release/hydradx // benchmark // pallet -// --pallet=pallet-transaction-pause +// --chain=dev +// --steps=10 +// --repeat=30 // --wasm-execution=compiled // --heap-pages=4096 -// --chain=dev +// --template=.maintain/pallet-weight-template-no-back.hbs +// --pallet=pallet_transaction_pause +// --output=./weights/transaction_pause.rs // --extrinsic=* -// --steps=5 -// --repeat=20 -// --output -// ./weights-1.1.0/transaction_pause.rs -// --template -// .maintain/pallet-weight-template-no-back.hbs +#![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] -#![allow(clippy::unnecessary_cast)] +#![allow(missing_docs)] -use frame_support::{ - traits::Get, - weights::{constants::RocksDbWeight, Weight}, -}; -use sp_std::marker::PhantomData; +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; -use pallet_transaction_pause::weights::WeightInfo; - -/// Weights for pallet_transaction_pause using the hydraDX node and recommended hardware. +/// Weight functions for `pallet_transaction_pause`. pub struct HydraWeight(PhantomData); - -impl WeightInfo for HydraWeight { +impl pallet_transaction_pause::WeightInfo for HydraWeight { /// Storage: `TransactionPause::PausedTransactions` (r:1 w:1) /// Proof: `TransactionPause::PausedTransactions` (`max_values`: None, `max_size`: Some(90), added: 2565, mode: `MaxEncodedLen`) fn pause_transaction() -> Weight { // Proof Size summary in bytes: - // Measured: `109` + // Measured: `147` // Estimated: `3555` - // Minimum execution time: 15_060_000 picoseconds. - Weight::from_parts(15_317_000, 3555) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 16_343_000 picoseconds. + Weight::from_parts(16_726_000, 3555) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `TransactionPause::PausedTransactions` (r:1 w:1) /// Proof: `TransactionPause::PausedTransactions` (`max_values`: None, `max_size`: Some(90), added: 2565, mode: `MaxEncodedLen`) fn unpause_transaction() -> Weight { // Proof Size summary in bytes: - // Measured: `160` + // Measured: `198` // Estimated: `3555` - // Minimum execution time: 17_304_000 picoseconds. - Weight::from_parts(17_780_000, 3555) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 17_899_000 picoseconds. + Weight::from_parts(18_371_000, 3555) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } -} +} \ No newline at end of file diff --git a/runtime/hydradx/src/weights/treasury.rs b/runtime/hydradx/src/weights/treasury.rs index 52dca557b..0e1a664bd 100644 --- a/runtime/hydradx/src/weights/treasury.rs +++ b/runtime/hydradx/src/weights/treasury.rs @@ -18,49 +18,42 @@ //! Autogenerated weights for `pallet_treasury` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-12-12, STEPS: `5`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-02-15, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `bench-bot`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` -//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 // Executed Command: // target/release/hydradx // benchmark // pallet -// --pallet=pallet-treasury +// --chain=dev +// --steps=10 +// --repeat=30 // --wasm-execution=compiled // --heap-pages=4096 -// --chain=dev +// --template=.maintain/pallet-weight-template-no-back.hbs +// --pallet=pallet_treasury +// --output=./weights/treasury.rs // --extrinsic=* -// --steps=5 -// --repeat=20 -// --output -// ./weights-1.1.0/treasury.rs -// --template -// .maintain/pallet-weight-template-no-back.hbs +#![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] -#![allow(clippy::unnecessary_cast)] +#![allow(missing_docs)] -use frame_support::{ - traits::Get, - weights::{constants::RocksDbWeight, Weight}, -}; -use sp_std::marker::PhantomData; +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; -use pallet_treasury::weights::WeightInfo; - -/// Weights for pallet_treasury using the hydraDX node and recommended hardware. +/// Weight functions for `pallet_treasury`. pub struct HydraWeight(PhantomData); - -impl WeightInfo for HydraWeight { +impl pallet_treasury::WeightInfo for HydraWeight { fn spend() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 422_000 picoseconds. - Weight::from_parts(449_000, 0) + // Minimum execution time: 377_000 picoseconds. + Weight::from_parts(415_000, 0) } /// Storage: `Treasury::ProposalCount` (r:1 w:1) /// Proof: `Treasury::ProposalCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) @@ -70,10 +63,10 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `210` // Estimated: `1489` - // Minimum execution time: 39_374_000 picoseconds. - Weight::from_parts(39_839_000, 1489) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) + // Minimum execution time: 37_853_000 picoseconds. + Weight::from_parts(38_512_000, 1489) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(2)) } /// Storage: `Treasury::Proposals` (r:1 w:1) /// Proof: `Treasury::Proposals` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) @@ -83,26 +76,26 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `471` // Estimated: `6196` - // Minimum execution time: 58_400_000 picoseconds. - Weight::from_parts(58_832_000, 6196) - .saturating_add(T::DbWeight::get().reads(3_u64)) - .saturating_add(T::DbWeight::get().writes(3_u64)) + // Minimum execution time: 56_828_000 picoseconds. + Weight::from_parts(57_266_000, 6196) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(3)) } /// Storage: `Treasury::Proposals` (r:1 w:0) /// Proof: `Treasury::Proposals` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) /// Storage: `Treasury::Approvals` (r:1 w:1) /// Proof: `Treasury::Approvals` (`max_values`: Some(1), `max_size`: Some(402), added: 897, mode: `MaxEncodedLen`) /// The range of component `p` is `[0, 99]`. - fn approve_proposal(p: u32) -> Weight { + fn approve_proposal(p: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `417 + p * (11 ±0)` + // Measured: `571 + p * (7 ±0)` // Estimated: `3573` - // Minimum execution time: 14_121_000 picoseconds. - Weight::from_parts(15_974_273, 3573) - // Standard Error: 4_650 - .saturating_add(Weight::from_parts(58_332, 0).saturating_mul(p.into())) - .saturating_add(T::DbWeight::get().reads(2_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 14_617_000 picoseconds. + Weight::from_parts(17_552_607, 3573) + // Standard Error: 2_701 + .saturating_add(Weight::from_parts(41_981, 0).saturating_mul(p.into())) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `Treasury::Approvals` (r:1 w:1) /// Proof: `Treasury::Approvals` (`max_values`: Some(1), `max_size`: Some(402), added: 897, mode: `MaxEncodedLen`) @@ -110,10 +103,10 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `194` // Estimated: `1887` - // Minimum execution time: 9_887_000 picoseconds. - Weight::from_parts(10_028_000, 1887) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 9_955_000 picoseconds. + Weight::from_parts(10_322_000, 1887) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `System::Account` (r:201 w:201) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) @@ -126,18 +119,18 @@ impl WeightInfo for HydraWeight { /// Storage: `Treasury::Proposals` (r:100 w:100) /// Proof: `Treasury::Proposals` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) /// The range of component `p` is `[0, 100]`. - fn on_initialize_proposals(p: u32) -> Weight { + fn on_initialize_proposals(p: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `459 + p * (251 ±0)` + // Measured: `316 + p * (253 ±0)` // Estimated: `3593 + p * (5206 ±0)` - // Minimum execution time: 39_458_000 picoseconds. - Weight::from_parts(53_941_800, 3593) - // Standard Error: 121_853 - .saturating_add(Weight::from_parts(51_771_233, 0).saturating_mul(p.into())) - .saturating_add(T::DbWeight::get().reads(4_u64)) + // Minimum execution time: 38_716_000 picoseconds. + Weight::from_parts(47_514_413, 3593) + // Standard Error: 29_010 + .saturating_add(Weight::from_parts(50_516_662, 0).saturating_mul(p.into())) + .saturating_add(T::DbWeight::get().reads(4)) .saturating_add(T::DbWeight::get().reads((3_u64).saturating_mul(p.into()))) - .saturating_add(T::DbWeight::get().writes(3_u64)) + .saturating_add(T::DbWeight::get().writes(4)) .saturating_add(T::DbWeight::get().writes((3_u64).saturating_mul(p.into()))) .saturating_add(Weight::from_parts(0, 5206).saturating_mul(p.into())) } -} +} \ No newline at end of file diff --git a/runtime/hydradx/src/weights/utility.rs b/runtime/hydradx/src/weights/utility.rs index 4839f642f..b986763e2 100644 --- a/runtime/hydradx/src/weights/utility.rs +++ b/runtime/hydradx/src/weights/utility.rs @@ -18,85 +18,78 @@ //! Autogenerated weights for `pallet_utility` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-12-12, STEPS: `5`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-02-15, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `bench-bot`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` -//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 // Executed Command: // target/release/hydradx // benchmark // pallet -// --pallet=pallet-utility +// --chain=dev +// --steps=10 +// --repeat=30 // --wasm-execution=compiled // --heap-pages=4096 -// --chain=dev +// --template=.maintain/pallet-weight-template-no-back.hbs +// --pallet=pallet_utility +// --output=./weights/utility.rs // --extrinsic=* -// --steps=5 -// --repeat=20 -// --output -// ./weights-1.1.0/utility.rs -// --template -// .maintain/pallet-weight-template-no-back.hbs +#![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] -#![allow(clippy::unnecessary_cast)] +#![allow(missing_docs)] -use frame_support::{ - traits::Get, - weights::{constants::RocksDbWeight, Weight}, -}; -use sp_std::marker::PhantomData; +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; -use pallet_utility::weights::WeightInfo; - -/// Weights for pallet_utility using the hydraDX node and recommended hardware. +/// Weight functions for `pallet_utility`. pub struct HydraWeight(PhantomData); - -impl WeightInfo for HydraWeight { +impl pallet_utility::WeightInfo for HydraWeight { /// The range of component `c` is `[0, 1000]`. - fn batch(c: u32) -> Weight { + fn batch(c: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 10_344_000 picoseconds. - Weight::from_parts(18_082_840, 0) - // Standard Error: 4_915 - .saturating_add(Weight::from_parts(6_792_341, 0).saturating_mul(c.into())) + // Minimum execution time: 10_239_000 picoseconds. + Weight::from_parts(9_506_750, 0) + // Standard Error: 4_964 + .saturating_add(Weight::from_parts(6_554_896, 0).saturating_mul(c.into())) } fn as_derivative() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 7_899_000 picoseconds. - Weight::from_parts(8_182_000, 0) + // Minimum execution time: 7_602_000 picoseconds. + Weight::from_parts(7_828_000, 0) } /// The range of component `c` is `[0, 1000]`. - fn batch_all(c: u32) -> Weight { + fn batch_all(c: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 10_308_000 picoseconds. - Weight::from_parts(14_711_160, 0) - // Standard Error: 4_844 - .saturating_add(Weight::from_parts(7_186_588, 0).saturating_mul(c.into())) + // Minimum execution time: 10_351_000 picoseconds. + Weight::from_parts(19_343_913, 0) + // Standard Error: 5_903 + .saturating_add(Weight::from_parts(6_958_305, 0).saturating_mul(c.into())) } fn dispatch_as() -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 13_395_000 picoseconds. - Weight::from_parts(13_566_000, 0) + // Minimum execution time: 13_448_000 picoseconds. + Weight::from_parts(13_627_000, 0) } /// The range of component `c` is `[0, 1000]`. - fn force_batch(c: u32) -> Weight { + fn force_batch(c: u32, ) -> Weight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 10_686_000 picoseconds. - Weight::from_parts(7_857_460, 0) - // Standard Error: 4_105 - .saturating_add(Weight::from_parts(6_820_383, 0).saturating_mul(c.into())) + // Minimum execution time: 10_282_000 picoseconds. + Weight::from_parts(21_770_041, 0) + // Standard Error: 6_324 + .saturating_add(Weight::from_parts(6_570_955, 0).saturating_mul(c.into())) } -} +} \ No newline at end of file diff --git a/runtime/hydradx/src/weights/vesting.rs b/runtime/hydradx/src/weights/vesting.rs index f35946a95..c8c72e4dd 100644 --- a/runtime/hydradx/src/weights/vesting.rs +++ b/runtime/hydradx/src/weights/vesting.rs @@ -18,43 +18,36 @@ //! Autogenerated weights for `orml_vesting` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-12-12, STEPS: `5`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-02-15, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `bench-bot`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` -//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 // Executed Command: // target/release/hydradx // benchmark // pallet -// --pallet=orml-vesting +// --chain=dev +// --steps=10 +// --repeat=30 // --wasm-execution=compiled // --heap-pages=4096 -// --chain=dev +// --template=.maintain/pallet-weight-template-no-back.hbs +// --pallet=orml_vesting +// --output=./weights/vesting.rs // --extrinsic=* -// --steps=5 -// --repeat=20 -// --output -// ./weights-1.1.0/vesting.rs -// --template -// .maintain/pallet-weight-template-no-back.hbs +#![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] -#![allow(clippy::unnecessary_cast)] +#![allow(missing_docs)] -use frame_support::{ - traits::Get, - weights::{constants::RocksDbWeight, Weight}, -}; -use sp_std::marker::PhantomData; +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; -use orml_vesting::WeightInfo; - -/// Weights for orml_vesting using the hydraDX node and recommended hardware. +/// Weight functions for `orml_vesting`. pub struct HydraWeight(PhantomData); - -impl WeightInfo for HydraWeight { +impl orml_vesting::WeightInfo for HydraWeight { /// Storage: `Vesting::VestingSchedules` (r:1 w:1) /// Proof: `Vesting::VestingSchedules` (`max_values`: None, `max_size`: Some(2850), added: 5325, mode: `MaxEncodedLen`) /// Storage: `System::Account` (r:2 w:2) @@ -65,12 +58,12 @@ impl WeightInfo for HydraWeight { /// Proof: `Balances::Freezes` (`max_values`: None, `max_size`: Some(49), added: 2524, mode: `MaxEncodedLen`) fn vested_transfer() -> Weight { // Proof Size summary in bytes: - // Measured: `1914` + // Measured: `1918` // Estimated: `6315` - // Minimum execution time: 119_563_000 picoseconds. - Weight::from_parts(120_581_000, 6315) - .saturating_add(T::DbWeight::get().reads(5_u64)) - .saturating_add(T::DbWeight::get().writes(4_u64)) + // Minimum execution time: 118_969_000 picoseconds. + Weight::from_parts(120_010_000, 6315) + .saturating_add(T::DbWeight::get().reads(5)) + .saturating_add(T::DbWeight::get().writes(4)) } /// Storage: `Vesting::VestingSchedules` (r:1 w:1) /// Proof: `Vesting::VestingSchedules` (`max_values`: None, `max_size`: Some(2850), added: 5325, mode: `MaxEncodedLen`) @@ -79,16 +72,16 @@ impl WeightInfo for HydraWeight { /// Storage: `Balances::Freezes` (r:1 w:0) /// Proof: `Balances::Freezes` (`max_values`: None, `max_size`: Some(49), added: 2524, mode: `MaxEncodedLen`) /// The range of component `i` is `[1, 100]`. - fn claim(i: u32) -> Weight { + fn claim(i: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `2032 + i * (18 ±0)` + // Measured: `2037 + i * (18 ±0)` // Estimated: `6315` - // Minimum execution time: 68_015_000 picoseconds. - Weight::from_parts(68_850_181, 6315) - // Standard Error: 1_475 - .saturating_add(Weight::from_parts(86_367, 0).saturating_mul(i.into())) - .saturating_add(T::DbWeight::get().reads(3_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) + // Minimum execution time: 66_914_000 picoseconds. + Weight::from_parts(68_653_438, 6315) + // Standard Error: 1_016 + .saturating_add(Weight::from_parts(84_943, 0).saturating_mul(i.into())) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(2)) } /// Storage: `System::Account` (r:1 w:1) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) @@ -99,15 +92,15 @@ impl WeightInfo for HydraWeight { /// Storage: `Vesting::VestingSchedules` (r:0 w:1) /// Proof: `Vesting::VestingSchedules` (`max_values`: None, `max_size`: Some(2850), added: 5325, mode: `MaxEncodedLen`) /// The range of component `i` is `[1, 100]`. - fn update_vesting_schedules(i: u32) -> Weight { + fn update_vesting_schedules(i: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `1615` + // Measured: `1619` // Estimated: `4764` - // Minimum execution time: 59_122_000 picoseconds. - Weight::from_parts(59_638_156, 4764) - // Standard Error: 730 - .saturating_add(Weight::from_parts(78_296, 0).saturating_mul(i.into())) - .saturating_add(T::DbWeight::get().reads(3_u64)) - .saturating_add(T::DbWeight::get().writes(3_u64)) + // Minimum execution time: 58_382_000 picoseconds. + Weight::from_parts(59_008_204, 4764) + // Standard Error: 546 + .saturating_add(Weight::from_parts(82_456, 0).saturating_mul(i.into())) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(3)) } -} +} \ No newline at end of file diff --git a/runtime/hydradx/src/weights/xcm.rs b/runtime/hydradx/src/weights/xcm.rs index 796617c51..183f43b07 100644 --- a/runtime/hydradx/src/weights/xcm.rs +++ b/runtime/hydradx/src/weights/xcm.rs @@ -18,43 +18,36 @@ //! Autogenerated weights for `pallet_xcm` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-12-12, STEPS: `5`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-02-15, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `bench-bot`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` -//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 // Executed Command: // target/release/hydradx // benchmark // pallet -// --pallet=pallet-xcm +// --chain=dev +// --steps=10 +// --repeat=30 // --wasm-execution=compiled // --heap-pages=4096 -// --chain=dev +// --template=.maintain/pallet-weight-template-no-back.hbs +// --pallet=pallet-xcm +// --output=./weights/xcm.rs // --extrinsic=* -// --steps=5 -// --repeat=20 -// --output -// ./weights-1.1.0/xcm.rs -// --template -// .maintain/pallet-weight-template-no-back.hbs +#![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] -#![allow(clippy::unnecessary_cast)] - -use frame_support::{ - traits::Get, - weights::{constants::RocksDbWeight, Weight}, -}; -use sp_std::marker::PhantomData; +#![allow(missing_docs)] -use pallet_xcm::WeightInfo; +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; -/// Weights for pallet_xcm using the hydraDX node and recommended hardware. +/// Weight functions for `pallet_xcm`. pub struct HydraWeight(PhantomData); - -impl WeightInfo for HydraWeight { +impl pallet_xcm::WeightInfo for HydraWeight { /// Storage: `PolkadotXcm::SupportedVersion` (r:1 w:0) /// Proof: `PolkadotXcm::SupportedVersion` (`max_values`: None, `max_size`: None, mode: `Measured`) /// Storage: `PolkadotXcm::VersionDiscoveryQueue` (r:1 w:1) @@ -69,10 +62,10 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `145` // Estimated: `3610` - // Minimum execution time: 38_308_000 picoseconds. - Weight::from_parts(39_025_000, 3610) - .saturating_add(T::DbWeight::get().reads(5_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) + // Minimum execution time: 38_630_000 picoseconds. + Weight::from_parts(39_297_000, 3610) + .saturating_add(T::DbWeight::get().reads(5)) + .saturating_add(T::DbWeight::get().writes(2)) } /// Storage: `Benchmark::Override` (r:0 w:0) /// Proof: `Benchmark::Override` (`max_values`: None, `max_size`: None, mode: `Measured`) @@ -89,8 +82,9 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `69` // Estimated: `1489` - // Minimum execution time: 30_501_000 picoseconds. - Weight::from_parts(31_561_000, 1489).saturating_add(T::DbWeight::get().reads(1_u64)) + // Minimum execution time: 30_159_000 picoseconds. + Weight::from_parts(30_412_000, 1489) + .saturating_add(T::DbWeight::get().reads(1)) } /// Storage: `Benchmark::Override` (r:0 w:0) /// Proof: `Benchmark::Override` (`max_values`: None, `max_size`: None, mode: `Measured`) @@ -107,8 +101,9 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 14_258_000 picoseconds. - Weight::from_parts(14_635_000, 0).saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 13_988_000 picoseconds. + Weight::from_parts(14_343_000, 0) + .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `PolkadotXcm::SafeXcmVersion` (r:0 w:1) /// Proof: `PolkadotXcm::SafeXcmVersion` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) @@ -116,8 +111,9 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 5_144_000 picoseconds. - Weight::from_parts(5_275_000, 0).saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 5_051_000 picoseconds. + Weight::from_parts(5_221_000, 0) + .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `PolkadotXcm::VersionNotifiers` (r:1 w:1) /// Proof: `PolkadotXcm::VersionNotifiers` (`max_values`: None, `max_size`: None, mode: `Measured`) @@ -139,10 +135,10 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `145` // Estimated: `3610` - // Minimum execution time: 45_191_000 picoseconds. - Weight::from_parts(45_866_000, 3610) - .saturating_add(T::DbWeight::get().reads(7_u64)) - .saturating_add(T::DbWeight::get().writes(5_u64)) + // Minimum execution time: 45_381_000 picoseconds. + Weight::from_parts(45_916_000, 3610) + .saturating_add(T::DbWeight::get().reads(7)) + .saturating_add(T::DbWeight::get().writes(5)) } /// Storage: `PolkadotXcm::VersionNotifiers` (r:1 w:1) /// Proof: `PolkadotXcm::VersionNotifiers` (`max_values`: None, `max_size`: None, mode: `Measured`) @@ -162,10 +158,10 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `328` // Estimated: `3793` - // Minimum execution time: 45_127_000 picoseconds. - Weight::from_parts(45_519_000, 3793) - .saturating_add(T::DbWeight::get().reads(6_u64)) - .saturating_add(T::DbWeight::get().writes(4_u64)) + // Minimum execution time: 44_926_000 picoseconds. + Weight::from_parts(45_579_000, 3793) + .saturating_add(T::DbWeight::get().reads(6)) + .saturating_add(T::DbWeight::get().writes(4)) } /// Storage: `PolkadotXcm::XcmExecutionSuspended` (r:0 w:1) /// Proof: `PolkadotXcm::XcmExecutionSuspended` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) @@ -173,8 +169,9 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 5_213_000 picoseconds. - Weight::from_parts(5_354_000, 0).saturating_add(T::DbWeight::get().writes(1_u64)) + // Minimum execution time: 4_986_000 picoseconds. + Weight::from_parts(5_153_000, 0) + .saturating_add(T::DbWeight::get().writes(1)) } /// Storage: `PolkadotXcm::SupportedVersion` (r:4 w:2) /// Proof: `PolkadotXcm::SupportedVersion` (`max_values`: None, `max_size`: None, mode: `Measured`) @@ -182,10 +179,10 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `167` // Estimated: `11057` - // Minimum execution time: 24_438_000 picoseconds. - Weight::from_parts(24_889_000, 11057) - .saturating_add(T::DbWeight::get().reads(4_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) + // Minimum execution time: 23_374_000 picoseconds. + Weight::from_parts(24_225_000, 11057) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().writes(2)) } /// Storage: `PolkadotXcm::VersionNotifiers` (r:4 w:2) /// Proof: `PolkadotXcm::VersionNotifiers` (`max_values`: None, `max_size`: None, mode: `Measured`) @@ -193,10 +190,10 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `171` // Estimated: `11061` - // Minimum execution time: 24_317_000 picoseconds. - Weight::from_parts(24_952_000, 11061) - .saturating_add(T::DbWeight::get().reads(4_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) + // Minimum execution time: 23_394_000 picoseconds. + Weight::from_parts(24_116_000, 11061) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().writes(2)) } /// Storage: `PolkadotXcm::VersionNotifyTargets` (r:5 w:0) /// Proof: `PolkadotXcm::VersionNotifyTargets` (`max_values`: None, `max_size`: None, mode: `Measured`) @@ -204,8 +201,9 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `178` // Estimated: `13543` - // Minimum execution time: 25_401_000 picoseconds. - Weight::from_parts(25_725_000, 13543).saturating_add(T::DbWeight::get().reads(5_u64)) + // Minimum execution time: 24_948_000 picoseconds. + Weight::from_parts(25_329_000, 13543) + .saturating_add(T::DbWeight::get().reads(5)) } /// Storage: `PolkadotXcm::VersionNotifyTargets` (r:2 w:1) /// Proof: `PolkadotXcm::VersionNotifyTargets` (`max_values`: None, `max_size`: None, mode: `Measured`) @@ -223,10 +221,10 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `212` // Estimated: `6152` - // Minimum execution time: 41_914_000 picoseconds. - Weight::from_parts(42_385_000, 6152) - .saturating_add(T::DbWeight::get().reads(7_u64)) - .saturating_add(T::DbWeight::get().writes(3_u64)) + // Minimum execution time: 40_668_000 picoseconds. + Weight::from_parts(41_385_000, 6152) + .saturating_add(T::DbWeight::get().reads(7)) + .saturating_add(T::DbWeight::get().writes(3)) } /// Storage: `PolkadotXcm::VersionNotifyTargets` (r:3 w:0) /// Proof: `PolkadotXcm::VersionNotifyTargets` (`max_values`: None, `max_size`: None, mode: `Measured`) @@ -234,8 +232,9 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `172` // Estimated: `8587` - // Minimum execution time: 13_727_000 picoseconds. - Weight::from_parts(13_964_000, 8587).saturating_add(T::DbWeight::get().reads(3_u64)) + // Minimum execution time: 13_397_000 picoseconds. + Weight::from_parts(13_608_000, 8587) + .saturating_add(T::DbWeight::get().reads(3)) } /// Storage: `PolkadotXcm::VersionNotifyTargets` (r:4 w:2) /// Proof: `PolkadotXcm::VersionNotifyTargets` (`max_values`: None, `max_size`: None, mode: `Measured`) @@ -243,10 +242,10 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `178` // Estimated: `11068` - // Minimum execution time: 24_882_000 picoseconds. - Weight::from_parts(25_611_000, 11068) - .saturating_add(T::DbWeight::get().reads(4_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) + // Minimum execution time: 24_281_000 picoseconds. + Weight::from_parts(24_768_000, 11068) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().writes(2)) } /// Storage: `PolkadotXcm::VersionNotifyTargets` (r:4 w:2) /// Proof: `PolkadotXcm::VersionNotifyTargets` (`max_values`: None, `max_size`: None, mode: `Measured`) @@ -264,9 +263,9 @@ impl WeightInfo for HydraWeight { // Proof Size summary in bytes: // Measured: `254` // Estimated: `11144` - // Minimum execution time: 51_859_000 picoseconds. - Weight::from_parts(52_412_000, 11144) - .saturating_add(T::DbWeight::get().reads(9_u64)) - .saturating_add(T::DbWeight::get().writes(4_u64)) + // Minimum execution time: 50_481_000 picoseconds. + Weight::from_parts(51_043_000, 11144) + .saturating_add(T::DbWeight::get().reads(9)) + .saturating_add(T::DbWeight::get().writes(4)) } -} +} \ No newline at end of file diff --git a/runtime/hydradx/src/weights/xcmp_queue.rs b/runtime/hydradx/src/weights/xcmp_queue.rs index c6197d1d7..1f3673e35 100644 --- a/runtime/hydradx/src/weights/xcmp_queue.rs +++ b/runtime/hydradx/src/weights/xcmp_queue.rs @@ -18,7 +18,7 @@ //! Autogenerated weights for `cumulus_pallet_xcmp_queue` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-12-14, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-02-15, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `bench-bot`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 @@ -30,13 +30,12 @@ // --chain=dev // --steps=10 // --repeat=30 -// --execution=wasm // --wasm-execution=compiled // --heap-pages=4096 // --template=.maintain/pallet-weight-template-no-back.hbs // --pallet=cumulus-pallet-xcmp-queue -// --output=weights-1.1.0/xcmp-queue.rs -// --extrinsic= +// --output=./weights/xcmp_queue.rs +// --extrinsic=* #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] @@ -55,8 +54,8 @@ impl cumulus_pallet_xcmp_queue::WeightInfo for HydraWei // Proof Size summary in bytes: // Measured: `142` // Estimated: `1627` - // Minimum execution time: 8_061_000 picoseconds. - Weight::from_parts(8_243_000, 1627) + // Minimum execution time: 7_816_000 picoseconds. + Weight::from_parts(8_016_000, 1627) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -66,8 +65,8 @@ impl cumulus_pallet_xcmp_queue::WeightInfo for HydraWei // Proof Size summary in bytes: // Measured: `142` // Estimated: `1627` - // Minimum execution time: 8_255_000 picoseconds. - Weight::from_parts(8_413_000, 1627) + // Minimum execution time: 7_869_000 picoseconds. + Weight::from_parts(8_072_000, 1627) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -92,10 +91,10 @@ impl cumulus_pallet_xcmp_queue::WeightInfo for HydraWei // Proof Size summary in bytes: // Measured: `6275 + b * (324357 ±0)` // Estimated: `9740 + b * (373857 ±0)` - // Minimum execution time: 32_529_153_000 picoseconds. - Weight::from_parts(160_904_784, 9740) - // Standard Error: 8_949_581 - .saturating_add(Weight::from_parts(32_575_018_568, 0).saturating_mul(b.into())) + // Minimum execution time: 33_398_415_000 picoseconds. + Weight::from_parts(57_262_807, 9740) + // Standard Error: 7_265_843 + .saturating_add(Weight::from_parts(33_588_589_234, 0).saturating_mul(b.into())) .saturating_add(T::DbWeight::get().reads(6)) .saturating_add(T::DbWeight::get().reads((21_u64).saturating_mul(b.into()))) .saturating_add(T::DbWeight::get().writes(3)) @@ -109,10 +108,10 @@ impl cumulus_pallet_xcmp_queue::WeightInfo for HydraWei // Proof Size summary in bytes: // Measured: `252 + m * (16216 ±0)` // Estimated: `3716 + m * (16216 ±0)` - // Minimum execution time: 1_269_514_000 picoseconds. - Weight::from_parts(254_832_812, 3716) - // Standard Error: 451_448 - .saturating_add(Weight::from_parts(1_075_219_465, 0).saturating_mul(m.into())) + // Minimum execution time: 1_285_382_000 picoseconds. + Weight::from_parts(242_447_351, 3716) + // Standard Error: 426_683 + .saturating_add(Weight::from_parts(1_106_936_264, 0).saturating_mul(m.into())) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) .saturating_add(Weight::from_parts(0, 16216).saturating_mul(m.into())) @@ -124,10 +123,10 @@ impl cumulus_pallet_xcmp_queue::WeightInfo for HydraWei // Proof Size summary in bytes: // Measured: `252 + m * (16216 ±0)` // Estimated: `3716 + m * (16216 ±0)` - // Minimum execution time: 1_331_675_000 picoseconds. - Weight::from_parts(131_637_639, 3716) - // Standard Error: 513_067 - .saturating_add(Weight::from_parts(1_197_225_867, 0).saturating_mul(m.into())) + // Minimum execution time: 1_351_709_000 picoseconds. + Weight::from_parts(116_677_544, 3716) + // Standard Error: 375_367 + .saturating_add(Weight::from_parts(1_225_618_925, 0).saturating_mul(m.into())) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) .saturating_add(Weight::from_parts(0, 16216).saturating_mul(m.into())) @@ -141,12 +140,12 @@ impl cumulus_pallet_xcmp_queue::WeightInfo for HydraWei // Proof Size summary in bytes: // Measured: `0 + m * (16216 ±0)` // Estimated: `9724 + m * (15020 ±55)` - // Minimum execution time: 106_584_000 picoseconds. - Weight::from_parts(125_484_886, 9724) - // Standard Error: 199_725 - .saturating_add(Weight::from_parts(6_590_187, 0).saturating_mul(m.into())) + // Minimum execution time: 107_020_000 picoseconds. + Weight::from_parts(128_836_899, 9724) + // Standard Error: 222_629 + .saturating_add(Weight::from_parts(6_772_210, 0).saturating_mul(m.into())) .saturating_add(T::DbWeight::get().reads(2)) .saturating_add(T::DbWeight::get().writes(2)) .saturating_add(Weight::from_parts(0, 15020).saturating_mul(m.into())) } -} +} \ No newline at end of file diff --git a/runtime/hydradx/src/weights/xyk.rs b/runtime/hydradx/src/weights/xyk.rs index 62ee3d5c9..7a8c24f45 100644 --- a/runtime/hydradx/src/weights/xyk.rs +++ b/runtime/hydradx/src/weights/xyk.rs @@ -18,216 +18,305 @@ //! Autogenerated weights for `pallet_xyk` //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-12-12, STEPS: `5`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2024-02-15, STEPS: `10`, REPEAT: `30`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` //! HOSTNAME: `bench-bot`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` -//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: `1024` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("dev")`, DB CACHE: 1024 // Executed Command: // target/release/hydradx // benchmark // pallet -// --pallet=pallet-xyk +// --chain=dev +// --steps=10 +// --repeat=30 // --wasm-execution=compiled // --heap-pages=4096 -// --chain=dev +// --template=.maintain/pallet-weight-template-no-back.hbs +// --pallet=pallet_xyk +// --output=./weights/xyk.rs // --extrinsic=* -// --steps=5 -// --repeat=20 -// --output -// ./weights-1.1.0/xyk.rs -// --template -// .maintain/pallet-weight-template-no-back.hbs +#![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] -#![allow(clippy::unnecessary_cast)] +#![allow(missing_docs)] -use frame_support::{ - traits::Get, - weights::{constants::RocksDbWeight, Weight}, -}; -use sp_std::marker::PhantomData; +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; use pallet_xyk::weights::WeightInfo; -/// Weights for pallet_xyk using the hydraDX node and recommended hardware. +/// Weight functions for `pallet_xyk`. pub struct HydraWeight(PhantomData); - impl WeightInfo for HydraWeight { /// Storage: `LBP::PoolData` (r:1 w:0) /// Proof: `LBP::PoolData` (`max_values`: None, `max_size`: Some(163), added: 2638, mode: `MaxEncodedLen`) /// Storage: `XYK::ShareToken` (r:1 w:1) /// Proof: `XYK::ShareToken` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`) - /// Storage: `Tokens::Accounts` (r:5 w:5) + /// Storage: `Tokens::Accounts` (r:7 w:7) /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::AssetIds` (r:1 w:1) /// Proof: `AssetRegistry::AssetIds` (`max_values`: None, `max_size`: Some(53), added: 2528, mode: `MaxEncodedLen`) /// Storage: `AssetRegistry::NextAssetId` (r:1 w:1) /// Proof: `AssetRegistry::NextAssetId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::Assets` (r:2 w:1) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) - /// Storage: `System::Account` (r:2 w:2) - /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) - /// Storage: `MultiTransactionPayment::AccountCurrencyMap` (r:2 w:1) + /// Storage: `Duster::AccountBlacklist` (r:1 w:1) + /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::BannedAssets` (r:4 w:0) + /// Proof: `AssetRegistry::BannedAssets` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::Assets` (r:3 w:1) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) + /// Storage: `MultiTransactionPayment::AccountCurrencyMap` (r:3 w:0) /// Proof: `MultiTransactionPayment::AccountCurrencyMap` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`) - /// Storage: `MultiTransactionPayment::AcceptedCurrencies` (r:1 w:0) + /// Storage: `MultiTransactionPayment::AcceptedCurrencyPrice` (r:1 w:0) + /// Proof: `MultiTransactionPayment::AcceptedCurrencyPrice` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:3 w:3) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `MultiTransactionPayment::AcceptedCurrencies` (r:3 w:0) /// Proof: `MultiTransactionPayment::AcceptedCurrencies` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) + /// Storage: `Balances::Locks` (r:1 w:1) + /// Proof: `Balances::Locks` (`max_values`: None, `max_size`: Some(1299), added: 3774, mode: `MaxEncodedLen`) + /// Storage: `Balances::Freezes` (r:1 w:0) + /// Proof: `Balances::Freezes` (`max_values`: None, `max_size`: Some(49), added: 2524, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::ExistentialDepositCounter` (r:1 w:1) + /// Proof: `AssetRegistry::ExistentialDepositCounter` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) /// Storage: `Tokens::TotalIssuance` (r:1 w:1) /// Proof: `Tokens::TotalIssuance` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) - /// Storage: `Duster::AccountBlacklist` (r:0 w:1) - /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) /// Storage: `XYK::TotalLiquidity` (r:0 w:1) /// Proof: `XYK::TotalLiquidity` (`max_values`: None, `max_size`: Some(64), added: 2539, mode: `MaxEncodedLen`) /// Storage: `XYK::PoolAssets` (r:0 w:1) /// Proof: `XYK::PoolAssets` (`max_values`: None, `max_size`: Some(56), added: 2531, mode: `MaxEncodedLen`) fn create_pool() -> Weight { // Proof Size summary in bytes: - // Measured: `1140` - // Estimated: `13905` - // Minimum execution time: 202_507_000 picoseconds. - Weight::from_parts(203_717_000, 13905) - .saturating_add(T::DbWeight::get().reads(17_u64)) - .saturating_add(T::DbWeight::get().writes(16_u64)) + // Measured: `3522` + // Estimated: `19071` + // Minimum execution time: 588_643_000 picoseconds. + Weight::from_parts(592_313_000, 19071) + .saturating_add(T::DbWeight::get().reads(33)) + .saturating_add(T::DbWeight::get().writes(20)) } /// Storage: `XYK::ShareToken` (r:1 w:0) /// Proof: `XYK::ShareToken` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`) - /// Storage: `Tokens::Accounts` (r:5 w:5) + /// Storage: `Tokens::Accounts` (r:7 w:7) /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) /// Storage: `XYK::TotalLiquidity` (r:1 w:1) /// Proof: `XYK::TotalLiquidity` (`max_values`: None, `max_size`: Some(64), added: 2539, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::Assets` (r:3 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) - /// Storage: `System::Account` (r:1 w:1) + /// Storage: `Duster::AccountBlacklist` (r:1 w:0) + /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::BannedAssets` (r:4 w:0) + /// Proof: `AssetRegistry::BannedAssets` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::Assets` (r:4 w:0) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:2 w:2) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) - /// Storage: `Tokens::TotalIssuance` (r:1 w:1) - /// Proof: `Tokens::TotalIssuance` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) /// Storage: `MultiTransactionPayment::AccountCurrencyMap` (r:1 w:0) /// Proof: `MultiTransactionPayment::AccountCurrencyMap` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`) + /// Storage: `Balances::Locks` (r:1 w:1) + /// Proof: `Balances::Locks` (`max_values`: None, `max_size`: Some(1299), added: 3774, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::ExistentialDepositCounter` (r:1 w:1) + /// Proof: `AssetRegistry::ExistentialDepositCounter` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) + /// Storage: `Balances::Freezes` (r:1 w:0) + /// Proof: `Balances::Freezes` (`max_values`: None, `max_size`: Some(49), added: 2524, mode: `MaxEncodedLen`) + /// Storage: `MultiTransactionPayment::AcceptedCurrencyPrice` (r:1 w:0) + /// Proof: `MultiTransactionPayment::AcceptedCurrencyPrice` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) + /// Storage: `Tokens::TotalIssuance` (r:1 w:1) + /// Proof: `Tokens::TotalIssuance` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) /// Storage: `EmaOracle::Accumulator` (r:1 w:1) /// Proof: `EmaOracle::Accumulator` (`max_values`: Some(1), `max_size`: Some(5921), added: 6416, mode: `MaxEncodedLen`) fn add_liquidity() -> Weight { // Proof Size summary in bytes: - // Measured: `1803` - // Estimated: `13905` - // Minimum execution time: 176_176_000 picoseconds. - Weight::from_parts(177_422_000, 13905) - .saturating_add(T::DbWeight::get().reads(14_u64)) - .saturating_add(T::DbWeight::get().writes(9_u64)) + // Measured: `4159` + // Estimated: `19071` + // Minimum execution time: 353_004_000 picoseconds. + Weight::from_parts(354_898_000, 19071) + .saturating_add(T::DbWeight::get().reads(27)) + .saturating_add(T::DbWeight::get().writes(14)) } - /// Storage: `XYK::ShareToken` (r:1 w:0) + /// Storage: `XYK::ShareToken` (r:1 w:1) /// Proof: `XYK::ShareToken` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`) /// Storage: `XYK::TotalLiquidity` (r:1 w:1) /// Proof: `XYK::TotalLiquidity` (`max_values`: None, `max_size`: Some(64), added: 2539, mode: `MaxEncodedLen`) - /// Storage: `Tokens::Accounts` (r:5 w:5) + /// Storage: `Tokens::Accounts` (r:7 w:7) /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::Assets` (r:3 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) - /// Storage: `System::Account` (r:1 w:0) + /// Storage: `Duster::AccountBlacklist` (r:2 w:1) + /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::BannedAssets` (r:3 w:0) + /// Proof: `AssetRegistry::BannedAssets` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::Assets` (r:4 w:0) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) + /// Storage: `MultiTransactionPayment::AccountCurrencyMap` (r:2 w:0) + /// Proof: `MultiTransactionPayment::AccountCurrencyMap` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`) + /// Storage: `MultiTransactionPayment::AcceptedCurrencyPrice` (r:1 w:0) + /// Proof: `MultiTransactionPayment::AcceptedCurrencyPrice` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:3 w:3) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Balances::Locks` (r:1 w:1) + /// Proof: `Balances::Locks` (`max_values`: None, `max_size`: Some(1299), added: 3774, mode: `MaxEncodedLen`) + /// Storage: `Balances::Freezes` (r:1 w:0) + /// Proof: `Balances::Freezes` (`max_values`: None, `max_size`: Some(49), added: 2524, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::ExistentialDepositCounter` (r:1 w:1) + /// Proof: `AssetRegistry::ExistentialDepositCounter` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) /// Storage: `Tokens::TotalIssuance` (r:1 w:1) /// Proof: `Tokens::TotalIssuance` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) /// Storage: `EmaOracle::Accumulator` (r:1 w:1) /// Proof: `EmaOracle::Accumulator` (`max_values`: Some(1), `max_size`: Some(5921), added: 6416, mode: `MaxEncodedLen`) + /// Storage: `XYK::PoolAssets` (r:0 w:1) + /// Proof: `XYK::PoolAssets` (`max_values`: None, `max_size`: Some(56), added: 2531, mode: `MaxEncodedLen`) fn remove_liquidity() -> Weight { // Proof Size summary in bytes: - // Measured: `1749` - // Estimated: `13905` - // Minimum execution time: 168_176_000 picoseconds. - Weight::from_parts(169_296_000, 13905) - .saturating_add(T::DbWeight::get().reads(13_u64)) - .saturating_add(T::DbWeight::get().writes(8_u64)) + // Measured: `4208` + // Estimated: `19071` + // Minimum execution time: 523_229_000 picoseconds. + Weight::from_parts(525_459_000, 19071) + .saturating_add(T::DbWeight::get().reads(29)) + .saturating_add(T::DbWeight::get().writes(18)) } /// Storage: `XYK::ShareToken` (r:1 w:0) /// Proof: `XYK::ShareToken` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`) - /// Storage: `Tokens::Accounts` (r:4 w:4) + /// Storage: `Tokens::Accounts` (r:6 w:6) /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::Assets` (r:2 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) - /// Storage: `System::Account` (r:2 w:0) + /// Storage: `Duster::AccountBlacklist` (r:2 w:0) + /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::BannedAssets` (r:3 w:0) + /// Proof: `AssetRegistry::BannedAssets` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::Assets` (r:3 w:0) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:3 w:2) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `MultiTransactionPayment::AccountCurrencyMap` (r:1 w:0) + /// Proof: `MultiTransactionPayment::AccountCurrencyMap` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`) + /// Storage: `Balances::Locks` (r:1 w:1) + /// Proof: `Balances::Locks` (`max_values`: None, `max_size`: Some(1299), added: 3774, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::ExistentialDepositCounter` (r:1 w:1) + /// Proof: `AssetRegistry::ExistentialDepositCounter` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) + /// Storage: `Balances::Freezes` (r:1 w:0) + /// Proof: `Balances::Freezes` (`max_values`: None, `max_size`: Some(49), added: 2524, mode: `MaxEncodedLen`) + /// Storage: `MultiTransactionPayment::AcceptedCurrencyPrice` (r:1 w:0) + /// Proof: `MultiTransactionPayment::AcceptedCurrencyPrice` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) /// Storage: `EmaOracle::Accumulator` (r:1 w:1) /// Proof: `EmaOracle::Accumulator` (`max_values`: Some(1), `max_size`: Some(5921), added: 6416, mode: `MaxEncodedLen`) fn sell() -> Weight { // Proof Size summary in bytes: - // Measured: `1492` - // Estimated: `11322` - // Minimum execution time: 127_203_000 picoseconds. - Weight::from_parts(127_918_000, 11322) - .saturating_add(T::DbWeight::get().reads(10_u64)) - .saturating_add(T::DbWeight::get().writes(5_u64)) + // Measured: `4057` + // Estimated: `16488` + // Minimum execution time: 306_824_000 picoseconds. + Weight::from_parts(308_832_000, 16488) + .saturating_add(T::DbWeight::get().reads(24)) + .saturating_add(T::DbWeight::get().writes(11)) } /// Storage: `XYK::ShareToken` (r:1 w:0) /// Proof: `XYK::ShareToken` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`) - /// Storage: `Tokens::Accounts` (r:4 w:4) + /// Storage: `Tokens::Accounts` (r:6 w:6) /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::Assets` (r:2 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) - /// Storage: `System::Account` (r:2 w:0) + /// Storage: `Duster::AccountBlacklist` (r:2 w:0) + /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::BannedAssets` (r:3 w:0) + /// Proof: `AssetRegistry::BannedAssets` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::Assets` (r:3 w:0) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) + /// Storage: `MultiTransactionPayment::AccountCurrencyMap` (r:1 w:0) + /// Proof: `MultiTransactionPayment::AccountCurrencyMap` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`) + /// Storage: `MultiTransactionPayment::AcceptedCurrencyPrice` (r:1 w:0) + /// Proof: `MultiTransactionPayment::AcceptedCurrencyPrice` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:3 w:2) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Balances::Locks` (r:1 w:1) + /// Proof: `Balances::Locks` (`max_values`: None, `max_size`: Some(1299), added: 3774, mode: `MaxEncodedLen`) + /// Storage: `Balances::Freezes` (r:1 w:0) + /// Proof: `Balances::Freezes` (`max_values`: None, `max_size`: Some(49), added: 2524, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::ExistentialDepositCounter` (r:1 w:1) + /// Proof: `AssetRegistry::ExistentialDepositCounter` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) /// Storage: `EmaOracle::Accumulator` (r:1 w:1) /// Proof: `EmaOracle::Accumulator` (`max_values`: Some(1), `max_size`: Some(5921), added: 6416, mode: `MaxEncodedLen`) fn buy() -> Weight { // Proof Size summary in bytes: - // Measured: `1492` - // Estimated: `11322` - // Minimum execution time: 126_846_000 picoseconds. - Weight::from_parts(127_737_000, 11322) - .saturating_add(T::DbWeight::get().reads(10_u64)) - .saturating_add(T::DbWeight::get().writes(5_u64)) + // Measured: `4057` + // Estimated: `16488` + // Minimum execution time: 305_679_000 picoseconds. + Weight::from_parts(306_896_000, 16488) + .saturating_add(T::DbWeight::get().reads(24)) + .saturating_add(T::DbWeight::get().writes(11)) } /// Storage: `XYK::ShareToken` (r:1 w:0) /// Proof: `XYK::ShareToken` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`) - /// Storage: `Tokens::Accounts` (r:4 w:4) + /// Storage: `Tokens::Accounts` (r:6 w:6) /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::Assets` (r:2 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) - /// Storage: `System::Account` (r:2 w:0) + /// Storage: `Duster::AccountBlacklist` (r:2 w:0) + /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::BannedAssets` (r:3 w:0) + /// Proof: `AssetRegistry::BannedAssets` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::Assets` (r:3 w:0) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:3 w:2) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `MultiTransactionPayment::AccountCurrencyMap` (r:1 w:0) + /// Proof: `MultiTransactionPayment::AccountCurrencyMap` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`) + /// Storage: `Balances::Locks` (r:1 w:1) + /// Proof: `Balances::Locks` (`max_values`: None, `max_size`: Some(1299), added: 3774, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::ExistentialDepositCounter` (r:1 w:1) + /// Proof: `AssetRegistry::ExistentialDepositCounter` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) + /// Storage: `Balances::Freezes` (r:1 w:0) + /// Proof: `Balances::Freezes` (`max_values`: None, `max_size`: Some(49), added: 2524, mode: `MaxEncodedLen`) + /// Storage: `MultiTransactionPayment::AcceptedCurrencyPrice` (r:1 w:0) + /// Proof: `MultiTransactionPayment::AcceptedCurrencyPrice` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) /// Storage: `EmaOracle::Accumulator` (r:1 w:1) /// Proof: `EmaOracle::Accumulator` (`max_values`: Some(1), `max_size`: Some(5921), added: 6416, mode: `MaxEncodedLen`) /// The range of component `c` is `[1, 2]`. /// The range of component `e` is `[0, 1]`. - fn router_execution_sell(c: u32, e: u32) -> Weight { + fn router_execution_sell(c: u32, e: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `583 + e * (909 ±0)` - // Estimated: `6156 + e * (5166 ±0)` - // Minimum execution time: 22_072_000 picoseconds. - Weight::from_parts(5_201_125, 6156) - // Standard Error: 56_711 - .saturating_add(Weight::from_parts(8_630_075, 0).saturating_mul(c.into())) - // Standard Error: 56_711 - .saturating_add(Weight::from_parts(113_479_825, 0).saturating_mul(e.into())) - .saturating_add(T::DbWeight::get().reads(3_u64)) - .saturating_add(T::DbWeight::get().reads((7_u64).saturating_mul(e.into()))) - .saturating_add(T::DbWeight::get().writes((5_u64).saturating_mul(e.into()))) - .saturating_add(Weight::from_parts(0, 5166).saturating_mul(e.into())) + // Measured: `1187 + e * (2870 ±0)` + // Estimated: `6156 + e * (10332 ±52_268_479_977_062_104)` + // Minimum execution time: 25_878_000 picoseconds. + Weight::from_parts(9_649_436, 6156) + // Standard Error: 80_766 + .saturating_add(Weight::from_parts(8_443_704, 0).saturating_mul(c.into())) + // Standard Error: 80_766 + .saturating_add(Weight::from_parts(289_624_454, 0).saturating_mul(e.into())) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().reads((21_u64).saturating_mul(e.into()))) + .saturating_add(T::DbWeight::get().writes((11_u64).saturating_mul(e.into()))) + .saturating_add(Weight::from_parts(0, 10332).saturating_mul(e.into())) } /// Storage: `XYK::ShareToken` (r:1 w:0) /// Proof: `XYK::ShareToken` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`) - /// Storage: `Tokens::Accounts` (r:4 w:4) + /// Storage: `Tokens::Accounts` (r:6 w:6) /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(108), added: 2583, mode: `MaxEncodedLen`) - /// Storage: `AssetRegistry::Assets` (r:2 w:0) - /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(87), added: 2562, mode: `MaxEncodedLen`) - /// Storage: `System::Account` (r:2 w:0) + /// Storage: `Duster::AccountBlacklist` (r:2 w:0) + /// Proof: `Duster::AccountBlacklist` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::BannedAssets` (r:3 w:0) + /// Proof: `AssetRegistry::BannedAssets` (`max_values`: None, `max_size`: Some(20), added: 2495, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::Assets` (r:3 w:0) + /// Proof: `AssetRegistry::Assets` (`max_values`: None, `max_size`: Some(125), added: 2600, mode: `MaxEncodedLen`) + /// Storage: `MultiTransactionPayment::AccountCurrencyMap` (r:1 w:0) + /// Proof: `MultiTransactionPayment::AccountCurrencyMap` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`) + /// Storage: `MultiTransactionPayment::AcceptedCurrencyPrice` (r:1 w:0) + /// Proof: `MultiTransactionPayment::AcceptedCurrencyPrice` (`max_values`: None, `max_size`: Some(28), added: 2503, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:3 w:2) /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `Balances::Locks` (r:1 w:1) + /// Proof: `Balances::Locks` (`max_values`: None, `max_size`: Some(1299), added: 3774, mode: `MaxEncodedLen`) + /// Storage: `Balances::Freezes` (r:1 w:0) + /// Proof: `Balances::Freezes` (`max_values`: None, `max_size`: Some(49), added: 2524, mode: `MaxEncodedLen`) + /// Storage: `AssetRegistry::ExistentialDepositCounter` (r:1 w:1) + /// Proof: `AssetRegistry::ExistentialDepositCounter` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) /// Storage: `EmaOracle::Accumulator` (r:1 w:1) /// Proof: `EmaOracle::Accumulator` (`max_values`: Some(1), `max_size`: Some(5921), added: 6416, mode: `MaxEncodedLen`) /// The range of component `c` is `[1, 3]`. /// The range of component `e` is `[0, 1]`. - fn router_execution_buy(c: u32, e: u32) -> Weight { + fn router_execution_buy(c: u32, e: u32, ) -> Weight { // Proof Size summary in bytes: - // Measured: `583 + e * (909 ±0)` - // Estimated: `6156 + e * (5166 ±0)` - // Minimum execution time: 30_065_000 picoseconds. - Weight::from_parts(6_816_200, 6156) - // Standard Error: 42_652 - .saturating_add(Weight::from_parts(7_927_825, 0).saturating_mul(c.into())) - // Standard Error: 69_651 - .saturating_add(Weight::from_parts(112_378_650, 0).saturating_mul(e.into())) - .saturating_add(T::DbWeight::get().reads(3_u64)) - .saturating_add(T::DbWeight::get().reads((7_u64).saturating_mul(e.into()))) - .saturating_add(T::DbWeight::get().writes((5_u64).saturating_mul(e.into()))) - .saturating_add(Weight::from_parts(0, 5166).saturating_mul(e.into())) + // Measured: `1187 + e * (2870 ±0)` + // Estimated: `6156 + e * (10332 ±0)` + // Minimum execution time: 33_714_000 picoseconds. + Weight::from_parts(11_014_445, 6156) + // Standard Error: 41_799 + .saturating_add(Weight::from_parts(7_776_697, 0).saturating_mul(c.into())) + // Standard Error: 70_916 + .saturating_add(Weight::from_parts(287_790_853, 0).saturating_mul(e.into())) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().reads((21_u64).saturating_mul(e.into()))) + .saturating_add(T::DbWeight::get().writes((11_u64).saturating_mul(e.into()))) + .saturating_add(Weight::from_parts(0, 10332).saturating_mul(e.into())) } } diff --git a/traits/Cargo.toml b/traits/Cargo.toml index 69143b05b..4d28a2019 100644 --- a/traits/Cargo.toml +++ b/traits/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hydradx-traits" -version = "2.8.4" +version = "3.0.0" description = "Shared traits" authors = ["GalacticCouncil"] edition = "2021" diff --git a/traits/src/registry.rs b/traits/src/registry.rs index b2b25d1bd..3dbcac14f 100644 --- a/traits/src/registry.rs +++ b/traits/src/registry.rs @@ -1,62 +1,12 @@ use sp_std::vec::Vec; -pub trait Registry { - fn exists(name: AssetId) -> bool; - fn retrieve_asset(name: &AssetName) -> Result; - - fn retrieve_asset_type(asset_id: AssetId) -> Result; - - fn create_asset(name: &AssetName, existential_deposit: Balance) -> Result; - - fn get_or_create_asset(name: AssetName, existential_deposit: Balance) -> Result { - if let Ok(asset_id) = Self::retrieve_asset(&name) { - Ok(asset_id) - } else { - Self::create_asset(&name, existential_deposit) - } - } -} -// Use CreateRegistry if possible -pub trait ShareTokenRegistry: Registry { - fn retrieve_shared_asset(name: &AssetName, assets: &[AssetId]) -> Result; - - fn create_shared_asset( - name: &AssetName, - assets: &[AssetId], - existential_deposit: Balance, - ) -> Result; - - fn get_or_create_shared_asset( - name: AssetName, - assets: Vec, - existential_deposit: Balance, - ) -> Result { - if let Ok(asset_id) = Self::retrieve_shared_asset(&name, &assets) { - Ok(asset_id) - } else { - Self::create_shared_asset(&name, &assets, existential_deposit) - } - } -} - -pub trait InspectRegistry { - fn exists(asset_id: AssetId) -> bool; - fn decimals(asset_id: AssetId) -> Option; - fn asset_name(asset_id: AssetId) -> Option>; - fn asset_symbol(asset_id: AssetId) -> Option>; -} - -#[derive(Eq, PartialEq, Copy, Clone)] +#[derive(Eq, PartialEq, Copy, Clone, Debug)] pub enum AssetKind { Token, XYK, StableSwap, Bond, -} - -pub trait CreateRegistry { - type Error; - fn create_asset(name: &[u8], kind: AssetKind, existential_deposit: Balance) -> Result; + External, } // Deprecated. @@ -76,3 +26,149 @@ pub trait AccountIdFor { /// Create a name to uniquely identify a share token for given assets and an identifier. fn name(assets: &Assets, identifier: Option<&[u8]>) -> Vec; } + +use frame_support::dispatch::Parameter; + +pub trait Inspect { + type AssetId: Parameter; + type Location: Parameter; + + fn is_sufficient(id: Self::AssetId) -> bool; + + fn exists(id: Self::AssetId) -> bool; + + fn decimals(id: Self::AssetId) -> Option; + + fn asset_type(id: Self::AssetId) -> Option; + + fn is_banned(id: Self::AssetId) -> bool; + + fn asset_name(id: Self::AssetId) -> Option>; + + fn asset_symbol(id: Self::AssetId) -> Option>; +} + +#[allow(clippy::too_many_arguments)] +pub trait Create: Inspect { + type Error; + type Name: Parameter + TryFrom>; + type Symbol: Parameter + TryFrom>; + + fn register_asset( + asset_id: Option, + name: Option, + kind: AssetKind, + existential_deposit: Option, + symbol: Option, + decimals: Option, + location: Option, + xcm_rate_limit: Option, + is_sufficient: bool, + ) -> Result; + + fn register_insufficient_asset( + asset_id: Option, + name: Option, + kind: AssetKind, + existential_deposit: Option, + symbol: Option, + decimals: Option, + location: Option, + xcm_rate_limit: Option, + ) -> Result { + Self::register_asset( + asset_id, + name, + kind, + existential_deposit, + symbol, + decimals, + location, + xcm_rate_limit, + false, + ) + } + + fn register_sufficient_asset( + asset_id: Option, + name: Option, + kind: AssetKind, + existential_deposit: Balance, + symbol: Option, + decimals: Option, + location: Option, + xcm_rate_limit: Option, + ) -> Result { + Self::register_asset( + asset_id, + name, + kind, + Some(existential_deposit), + symbol, + decimals, + location, + xcm_rate_limit, + true, + ) + } + + fn get_or_register_asset( + name: Self::Name, + kind: AssetKind, + existential_deposit: Option, + symbol: Option, + decimals: Option, + location: Option, + xcm_rate_limit: Option, + is_sufficient: bool, + ) -> Result; + + fn get_or_register_sufficient_asset( + name: Self::Name, + kind: AssetKind, + existential_deposit: Balance, + symbol: Option, + decimals: Option, + location: Option, + xcm_rate_limit: Option, + ) -> Result { + Self::get_or_register_asset( + name, + kind, + Some(existential_deposit), + symbol, + decimals, + location, + xcm_rate_limit, + true, + ) + } + + fn get_or_register_insufficient_asset( + name: Self::Name, + kind: AssetKind, + existential_deposit: Option, + symbol: Option, + decimals: Option, + location: Option, + xcm_rate_limit: Option, + ) -> Result { + Self::get_or_register_asset( + name, + kind, + existential_deposit, + symbol, + decimals, + location, + xcm_rate_limit, + false, + ) + } +} + +pub trait Mutate: Inspect { + type Error; + + /// Set location for existing asset id if it wasn't set yet. + fn set_location(asset_id: Self::AssetId, location: Self::Location) -> Result<(), Self::Error>; +}