diff --git a/Cargo.lock b/Cargo.lock index c68852399..eba6513a5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3786,7 +3786,7 @@ dependencies = [ [[package]] name = "hydradx-adapters" -version = "0.6.2" +version = "0.6.3" dependencies = [ "cumulus-pallet-parachain-system", "cumulus-primitives-core", @@ -3831,7 +3831,7 @@ dependencies = [ [[package]] name = "hydradx-runtime" -version = "181.0.0" +version = "182.0.0" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", @@ -3873,7 +3873,7 @@ dependencies = [ "pallet-collective", "pallet-currencies", "pallet-dca", - "pallet-democracy 4.0.0-dev", + "pallet-democracy 4.0.1-dev", "pallet-duster", "pallet-dynamic-fees", "pallet-elections-phragmen", @@ -3937,7 +3937,7 @@ dependencies = [ [[package]] name = "hydradx-traits" -version = "2.6.1" +version = "2.7.0" dependencies = [ "frame-support", "impl-trait-for-tuples", @@ -4532,7 +4532,7 @@ dependencies = [ "pallet-child-bounties", "pallet-collective", "pallet-conviction-voting", - "pallet-democracy 4.0.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.38)", + "pallet-democracy 4.0.0-dev", "pallet-election-provider-multi-phase", "pallet-election-provider-support-benchmarking", "pallet-elections-phragmen", @@ -6598,7 +6598,7 @@ dependencies = [ [[package]] name = "pallet-dca" -version = "1.1.10" +version = "1.2.0" dependencies = [ "cumulus-pallet-parachain-system", "cumulus-primitives-core", @@ -6640,14 +6640,12 @@ dependencies = [ [[package]] name = "pallet-democracy" version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.38#bcff60a227d455d95b4712b6cb356ce56b1ff672" dependencies = [ "frame-benchmarking", "frame-support", "frame-system", "log", - "pallet-balances", - "pallet-preimage", - "pallet-scheduler", "parity-scale-codec", "scale-info", "serde", @@ -6659,13 +6657,15 @@ dependencies = [ [[package]] name = "pallet-democracy" -version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.38#bcff60a227d455d95b4712b6cb356ce56b1ff672" +version = "4.0.1-dev" dependencies = [ "frame-benchmarking", "frame-support", "frame-system", "log", + "pallet-balances", + "pallet-preimage", + "pallet-scheduler", "parity-scale-codec", "scale-info", "serde", @@ -6777,7 +6777,7 @@ dependencies = [ [[package]] name = "pallet-ema-oracle" -version = "1.1.1" +version = "1.1.2" dependencies = [ "frame-benchmarking", "frame-support", @@ -6911,7 +6911,7 @@ dependencies = [ [[package]] name = "pallet-lbp" -version = "4.6.15" +version = "4.6.16" dependencies = [ "frame-benchmarking", "frame-support", @@ -7118,7 +7118,7 @@ dependencies = [ [[package]] name = "pallet-omnipool" -version = "3.2.2" +version = "3.2.3" dependencies = [ "bitflags", "frame-benchmarking", @@ -7294,7 +7294,7 @@ dependencies = [ [[package]] name = "pallet-route-executor" -version = "1.1.1" +version = "1.2.0" dependencies = [ "frame-benchmarking", "frame-support", @@ -7387,7 +7387,7 @@ dependencies = [ [[package]] name = "pallet-stableswap" -version = "3.3.0" +version = "3.3.1" dependencies = [ "bitflags", "frame-benchmarking", @@ -7421,7 +7421,7 @@ dependencies = [ "orml-tokens", "orml-traits", "pallet-balances", - "pallet-democracy 4.0.0-dev", + "pallet-democracy 4.0.1-dev", "pallet-uniques", "parity-scale-codec", "pretty_assertions", @@ -7779,7 +7779,7 @@ dependencies = [ [[package]] name = "pallet-xyk" -version = "6.2.9" +version = "6.2.10" dependencies = [ "frame-benchmarking", "frame-support", @@ -9023,7 +9023,7 @@ dependencies = [ "pallet-bounties", "pallet-child-bounties", "pallet-collective", - "pallet-democracy 4.0.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.38)", + "pallet-democracy 4.0.0-dev", "pallet-election-provider-multi-phase", "pallet-election-provider-support-benchmarking", "pallet-elections-phragmen", @@ -10068,7 +10068,7 @@ dependencies = [ "pallet-bounties", "pallet-child-bounties", "pallet-collective", - "pallet-democracy 4.0.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.38)", + "pallet-democracy 4.0.0-dev", "pallet-elections-phragmen", "pallet-grandpa", "pallet-identity", @@ -10220,7 +10220,7 @@ dependencies = [ [[package]] name = "runtime-integration-tests" -version = "1.12.3" +version = "1.12.4" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", @@ -10260,7 +10260,7 @@ dependencies = [ "pallet-collective", "pallet-currencies", "pallet-dca", - "pallet-democracy 4.0.0-dev", + "pallet-democracy 4.0.1-dev", "pallet-duster", "pallet-dynamic-fees", "pallet-elections-phragmen", @@ -14563,7 +14563,7 @@ dependencies = [ "pallet-bags-list", "pallet-balances", "pallet-collective", - "pallet-democracy 4.0.0-dev (git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.38)", + "pallet-democracy 4.0.0-dev", "pallet-election-provider-multi-phase", "pallet-election-provider-support-benchmarking", "pallet-elections-phragmen", diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index d2b2b6953..552a0b9d8 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "runtime-integration-tests" -version = "1.12.3" +version = "1.12.4" description = "Integration tests" authors = ["GalacticCouncil"] edition = "2021" @@ -185,3 +185,8 @@ std = [ "hydradx-runtime/std", "pallet-staking/std", ] + +# we don't include integration tests when benchmarking feature is enabled +runtime-benchmarks = [ + "hydradx-runtime/runtime-benchmarks", +] \ No newline at end of file diff --git a/integration-tests/src/dca.rs b/integration-tests/src/dca.rs index 8f7df8572..9a8853439 100644 --- a/integration-tests/src/dca.rs +++ b/integration-tests/src/dca.rs @@ -1,18 +1,15 @@ #![cfg(test)] +use crate::count_dca_event; use crate::polkadot_test_net::*; use frame_support::assert_ok; use crate::{assert_balance, assert_reserved_balance}; use frame_system::RawOrigin; -use hydradx_runtime::AssetRegistry; -use hydradx_runtime::Balances; -use hydradx_runtime::Currencies; -use hydradx_runtime::Omnipool; -use hydradx_runtime::Router; -use hydradx_runtime::RuntimeOrigin; -use hydradx_runtime::Stableswap; -use hydradx_runtime::Tokens; +use hydradx_runtime::{ + AssetRegistry, Balances, Currencies, Omnipool, Router, Runtime, RuntimeEvent, RuntimeOrigin, Stableswap, Tokens, + Treasury, DCA, +}; use hydradx_traits::router::{PoolType, Trade}; use hydradx_traits::Registry; use orml_traits::MultiCurrency; @@ -48,19 +45,15 @@ mod omnipool { let schedule1 = schedule_fake_with_buy_order(PoolType::Omnipool, HDX, DAI, 100 * UNITS, budget); //Act - assert_ok!(hydradx_runtime::DCA::schedule( - hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), - schedule1, - None - )); + assert_ok!(DCA::schedule(RuntimeOrigin::signed(ALICE.into()), schedule1, None)); //Assert let schedule_id = 0; - let schedule = hydradx_runtime::DCA::schedules(schedule_id); + let schedule = DCA::schedules(schedule_id); assert!(schedule.is_some()); let next_block_id = block_id + 1; - let schedule = hydradx_runtime::DCA::schedule_ids_per_block(next_block_id); + let schedule = DCA::schedule_ids_per_block(next_block_id); assert!(!schedule.is_empty()); expect_hydra_events(vec![pallet_dca::Event::Scheduled { id: 0, @@ -88,25 +81,20 @@ mod omnipool { assert_balance!(ALICE.into(), HDX, ALICE_INITIAL_NATIVE_BALANCE - dca_budget); assert_balance!(ALICE.into(), DAI, ALICE_INITIAL_DAI_BALANCE); assert_reserved_balance!(&ALICE.into(), HDX, dca_budget); - assert_balance!( - &hydradx_runtime::Treasury::account_id(), - HDX, - TREASURY_ACCOUNT_INIT_BALANCE - ); + assert_balance!(&Treasury::account_id(), HDX, TREASURY_ACCOUNT_INIT_BALANCE); //Act set_relaychain_block_number(11); //Assert - let fee = - Currencies::free_balance(HDX, &hydradx_runtime::Treasury::account_id()) - TREASURY_ACCOUNT_INIT_BALANCE; + let fee = Currencies::free_balance(HDX, &Treasury::account_id()) - TREASURY_ACCOUNT_INIT_BALANCE; let amount_in = 140421094431120; assert_balance!(ALICE.into(), DAI, ALICE_INITIAL_DAI_BALANCE + amount_out); assert_balance!(ALICE.into(), HDX, ALICE_INITIAL_NATIVE_BALANCE - dca_budget); assert_reserved_balance!(&ALICE.into(), HDX, dca_budget - amount_in - fee); - let treasury_balance = Currencies::free_balance(HDX, &hydradx_runtime::Treasury::account_id()); + let treasury_balance = Currencies::free_balance(HDX, &Treasury::account_id()); assert!(treasury_balance > TREASURY_ACCOUNT_INIT_BALANCE); }); } @@ -151,33 +139,32 @@ mod omnipool { //Act and assert let schedule_id = 0; set_relaychain_block_number(11); - let fee = - Currencies::free_balance(HDX, &hydradx_runtime::Treasury::account_id()) - TREASURY_ACCOUNT_INIT_BALANCE; + let fee = Currencies::free_balance(HDX, &Treasury::account_id()) - TREASURY_ACCOUNT_INIT_BALANCE; assert_balance!(ALICE.into(), DAI, ALICE_INITIAL_DAI_BALANCE); assert_balance!(ALICE.into(), HDX, ALICE_INITIAL_NATIVE_BALANCE - dca_budget); assert_reserved_balance!(&ALICE.into(), HDX, dca_budget - fee); - assert_eq!(hydradx_runtime::DCA::retries_on_error(schedule_id), 1); + assert_eq!(DCA::retries_on_error(schedule_id), 1); set_relaychain_block_number(21); assert_balance!(ALICE.into(), DAI, ALICE_INITIAL_DAI_BALANCE); assert_balance!(ALICE.into(), HDX, ALICE_INITIAL_NATIVE_BALANCE - dca_budget); assert_reserved_balance!(&ALICE.into(), HDX, dca_budget - 2 * fee); - assert_eq!(hydradx_runtime::DCA::retries_on_error(schedule_id), 2); + assert_eq!(DCA::retries_on_error(schedule_id), 2); set_relaychain_block_number(41); assert_balance!(ALICE.into(), DAI, ALICE_INITIAL_DAI_BALANCE); assert_balance!(ALICE.into(), HDX, ALICE_INITIAL_NATIVE_BALANCE - dca_budget); assert_reserved_balance!(&ALICE.into(), HDX, dca_budget - 3 * fee); - assert_eq!(hydradx_runtime::DCA::retries_on_error(schedule_id), 3); + assert_eq!(DCA::retries_on_error(schedule_id), 3); //After this retry we terminate set_relaychain_block_number(81); assert_balance!(ALICE.into(), DAI, ALICE_INITIAL_DAI_BALANCE); assert_balance!(ALICE.into(), HDX, ALICE_INITIAL_NATIVE_BALANCE - 4 * fee); assert_reserved_balance!(&ALICE.into(), HDX, 0); - assert_eq!(hydradx_runtime::DCA::retries_on_error(schedule_id), 0); - let schedule = hydradx_runtime::DCA::schedules(schedule_id); + assert_eq!(DCA::retries_on_error(schedule_id), 0); + let schedule = DCA::schedules(schedule_id); assert!(schedule.is_none()); }); } @@ -201,19 +188,19 @@ mod omnipool { assert_balance!(ALICE.into(), LRNA, alice_init_hub_balance - dca_budget); assert_balance!(ALICE.into(), DAI, ALICE_INITIAL_DAI_BALANCE); assert_reserved_balance!(&ALICE.into(), LRNA, dca_budget); - assert_balance!(&hydradx_runtime::Treasury::account_id(), LRNA, 0); + assert_balance!(&Treasury::account_id(), LRNA, 0); //Act set_relaychain_block_number(11); //Assert - let fee = Currencies::free_balance(LRNA, &hydradx_runtime::Treasury::account_id()); + let fee = Currencies::free_balance(LRNA, &Treasury::account_id()); let amount_in = 70175440083618; assert_balance!(ALICE.into(), DAI, ALICE_INITIAL_DAI_BALANCE + amount_out); assert_balance!(ALICE.into(), LRNA, alice_init_hub_balance - dca_budget); assert_reserved_balance!(&ALICE.into(), LRNA, dca_budget - amount_in - fee); - let treasury_balance = Currencies::free_balance(LRNA, &hydradx_runtime::Treasury::account_id()); + let treasury_balance = Currencies::free_balance(LRNA, &Treasury::account_id()); assert!(treasury_balance > 0); }); } @@ -241,8 +228,7 @@ mod omnipool { set_relaychain_block_number(11); //Assert - let fee = - Currencies::free_balance(HDX, &hydradx_runtime::Treasury::account_id()) - TREASURY_ACCOUNT_INIT_BALANCE; + let fee = Currencies::free_balance(HDX, &Treasury::account_id()) - TREASURY_ACCOUNT_INIT_BALANCE; assert_reserved_balance!(&ALICE.into(), HDX, dca_budget - amount_in - fee); assert_balance!(ALICE.into(), DAI, ALICE_INITIAL_DAI_BALANCE + amount_out); @@ -258,8 +244,8 @@ mod omnipool { assert_balance!(ALICE.into(), DAI, ALICE_INITIAL_DAI_BALANCE); //Act - assert_ok!(hydradx_runtime::Omnipool::buy( - hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), + assert_ok!(Omnipool::buy( + RuntimeOrigin::signed(ALICE.into()), DAI, HDX, amount_out, @@ -286,8 +272,8 @@ mod omnipool { asset_in: HDX, asset_out: DAI, }]; - assert_ok!(hydradx_runtime::Router::buy( - hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), + assert_ok!(Router::buy( + RuntimeOrigin::signed(ALICE.into()), HDX, DAI, amount_out, @@ -327,7 +313,7 @@ mod omnipool { set_relaychain_block_number(11); //Assert - let fee = Currencies::free_balance(LRNA, &hydradx_runtime::Treasury::account_id()); + let fee = Currencies::free_balance(LRNA, &Treasury::account_id()); assert_reserved_balance!(&ALICE.into(), LRNA, dca_budget - amount_in - fee); assert_balance!(ALICE.into(), DAI, ALICE_INITIAL_DAI_BALANCE + amount_out); @@ -346,8 +332,8 @@ mod omnipool { assert_balance!(ALICE.into(), DAI, ALICE_INITIAL_DAI_BALANCE); //Act - assert_ok!(hydradx_runtime::Omnipool::buy( - hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), + assert_ok!(Omnipool::buy( + RuntimeOrigin::signed(ALICE.into()), DAI, LRNA, amount_out, @@ -377,8 +363,8 @@ mod omnipool { asset_in: LRNA, asset_out: DAI, }]; - assert_ok!(hydradx_runtime::Router::buy( - hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), + assert_ok!(Router::buy( + RuntimeOrigin::signed(ALICE.into()), LRNA, DAI, amount_out, @@ -405,11 +391,7 @@ mod omnipool { assert_balance!(ALICE.into(), DAI, ALICE_INITIAL_DAI_BALANCE); assert_balance!(ALICE.into(), HDX, ALICE_INITIAL_NATIVE_BALANCE - dca_budget); - assert_balance!( - &hydradx_runtime::Treasury::account_id(), - HDX, - TREASURY_ACCOUNT_INIT_BALANCE - ); + assert_balance!(&Treasury::account_id(), HDX, TREASURY_ACCOUNT_INIT_BALANCE); assert_reserved_balance!(&ALICE.into(), HDX, dca_budget); //Act @@ -426,7 +408,7 @@ mod omnipool { assert_reserved_balance!(&ALICE.into(), HDX, 0); - let schedule = hydradx_runtime::DCA::schedules(0); + let schedule = DCA::schedules(0); assert!(schedule.is_none()); }); } @@ -438,8 +420,8 @@ mod omnipool { //Arrange init_omnipool_with_oracle_for_block_10(); let alice_init_hdx_balance = 5000 * UNITS; - assert_ok!(hydradx_runtime::Balances::set_balance( - hydradx_runtime::RuntimeOrigin::root(), + assert_ok!(Balances::set_balance( + RuntimeOrigin::root(), ALICE.into(), alice_init_hdx_balance, 0, @@ -454,26 +436,21 @@ mod omnipool { 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!( - &hydradx_runtime::Treasury::account_id(), - HDX, - TREASURY_ACCOUNT_INIT_BALANCE - ); + assert_balance!(&Treasury::account_id(), HDX, TREASURY_ACCOUNT_INIT_BALANCE); //Act set_relaychain_block_number(11); //Assert let amount_out = 71_214_372_591_631; - let fee = - Currencies::free_balance(HDX, &hydradx_runtime::Treasury::account_id()) - TREASURY_ACCOUNT_INIT_BALANCE; + let fee = Currencies::free_balance(HDX, &Treasury::account_id()) - TREASURY_ACCOUNT_INIT_BALANCE; assert_balance!(ALICE.into(), DAI, ALICE_INITIAL_DAI_BALANCE + amount_out); assert_balance!(ALICE.into(), HDX, alice_init_hdx_balance - dca_budget); assert_reserved_balance!(&ALICE.into(), HDX, dca_budget - amount_to_sell - fee); //Assert that fee is sent to treasury - let treasury_balance = Currencies::free_balance(HDX, &hydradx_runtime::Treasury::account_id()); + let treasury_balance = Currencies::free_balance(HDX, &Treasury::account_id()); assert!(treasury_balance > TREASURY_ACCOUNT_INIT_BALANCE); }); } @@ -485,8 +462,8 @@ mod omnipool { //Arrange init_omnipool_with_oracle_for_block_10(); let alice_init_hdx_balance = 5000 * UNITS; - assert_ok!(hydradx_runtime::Balances::set_balance( - hydradx_runtime::RuntimeOrigin::root(), + assert_ok!(Balances::set_balance( + RuntimeOrigin::root(), ALICE.into(), alice_init_hdx_balance, 0, @@ -501,18 +478,14 @@ mod omnipool { 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!( - &hydradx_runtime::Treasury::account_id(), - HDX, - TREASURY_ACCOUNT_INIT_BALANCE - ); + assert_balance!(&Treasury::account_id(), HDX, TREASURY_ACCOUNT_INIT_BALANCE); //Act run_to_block(11, 15); //Assert let schedule_id = 0; - let schedule = hydradx_runtime::DCA::schedules(schedule_id); + let schedule = DCA::schedules(schedule_id); assert!(schedule.is_none()); assert_balance!(ALICE.into(), HDX, alice_init_hdx_balance - dca_budget); @@ -527,8 +500,8 @@ mod omnipool { //Arrange init_omnipool_with_oracle_for_block_10(); let alice_init_hdx_balance = 5000 * UNITS; - assert_ok!(hydradx_runtime::Balances::set_balance( - hydradx_runtime::RuntimeOrigin::root(), + assert_ok!(Balances::set_balance( + RuntimeOrigin::root(), ALICE.into(), alice_init_hdx_balance, 0, @@ -565,34 +538,33 @@ mod omnipool { let schedule_id = 0; set_relaychain_block_number(11); - let fee = - Currencies::free_balance(HDX, &hydradx_runtime::Treasury::account_id()) - TREASURY_ACCOUNT_INIT_BALANCE; + let fee = Currencies::free_balance(HDX, &Treasury::account_id()) - TREASURY_ACCOUNT_INIT_BALANCE; 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 - fee); - assert_eq!(hydradx_runtime::DCA::retries_on_error(schedule_id), 1); + assert_eq!(DCA::retries_on_error(schedule_id), 1); set_relaychain_block_number(21); 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 - 2 * fee); - assert_eq!(hydradx_runtime::DCA::retries_on_error(schedule_id), 2); + assert_eq!(DCA::retries_on_error(schedule_id), 2); set_relaychain_block_number(41); 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 - 3 * fee); - assert_eq!(hydradx_runtime::DCA::retries_on_error(schedule_id), 3); + assert_eq!(DCA::retries_on_error(schedule_id), 3); //At this point, the schedule will be terminated as retries max number of times set_relaychain_block_number(81); assert_balance!(ALICE.into(), DAI, ALICE_INITIAL_DAI_BALANCE); assert_balance!(ALICE.into(), HDX, alice_init_hdx_balance - 4 * fee); assert_reserved_balance!(&ALICE.into(), HDX, 0); - assert_eq!(hydradx_runtime::DCA::retries_on_error(schedule_id), 0); - let schedule = hydradx_runtime::DCA::schedules(schedule_id); + assert_eq!(DCA::retries_on_error(schedule_id), 0); + let schedule = DCA::schedules(schedule_id); assert!(schedule.is_none()); }); } @@ -616,15 +588,15 @@ mod omnipool { assert_balance!(ALICE.into(), LRNA, alice_init_hub_balance - dca_budget); assert_balance!(ALICE.into(), DAI, ALICE_INITIAL_DAI_BALANCE); assert_reserved_balance!(&ALICE.into(), LRNA, dca_budget); - assert_balance!(&hydradx_runtime::Treasury::account_id(), LRNA, 0); + assert_balance!(&Treasury::account_id(), LRNA, 0); //Act set_relaychain_block_number(11); //Assert let amount_out = 142499995765917; - let fee = Currencies::free_balance(LRNA, &hydradx_runtime::Treasury::account_id()); - let treasury_balance = Currencies::free_balance(LRNA, &hydradx_runtime::Treasury::account_id()); + let fee = Currencies::free_balance(LRNA, &Treasury::account_id()); + let treasury_balance = Currencies::free_balance(LRNA, &Treasury::account_id()); assert!(treasury_balance > 0); assert_balance!(ALICE.into(), DAI, ALICE_INITIAL_DAI_BALANCE + amount_out); @@ -644,8 +616,8 @@ mod omnipool { //Arrange init_omnipool_with_oracle_for_block_10(); let alice_init_hdx_balance = 5000 * UNITS; - assert_ok!(hydradx_runtime::Balances::set_balance( - hydradx_runtime::RuntimeOrigin::root(), + assert_ok!(Balances::set_balance( + RuntimeOrigin::root(), ALICE.into(), alice_init_hdx_balance, 0, @@ -664,8 +636,7 @@ mod omnipool { set_relaychain_block_number(11); //Assert - let fee = - Currencies::free_balance(HDX, &hydradx_runtime::Treasury::account_id()) - TREASURY_ACCOUNT_INIT_BALANCE; + let fee = Currencies::free_balance(HDX, &Treasury::account_id()) - TREASURY_ACCOUNT_INIT_BALANCE; assert_reserved_balance!(&ALICE.into(), HDX, dca_budget - amount_to_sell - fee); assert_balance!(ALICE.into(), DAI, ALICE_INITIAL_DAI_BALANCE + amount_out); @@ -677,16 +648,16 @@ mod omnipool { //Arrange init_omnipool_with_oracle_for_block_10(); let alice_init_hdx_balance = 5000 * UNITS; - assert_ok!(hydradx_runtime::Balances::set_balance( - hydradx_runtime::RuntimeOrigin::root(), + assert_ok!(Balances::set_balance( + RuntimeOrigin::root(), ALICE.into(), alice_init_hdx_balance, 0, )); //Act - assert_ok!(hydradx_runtime::Omnipool::sell( - hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), + assert_ok!(Omnipool::sell( + RuntimeOrigin::signed(ALICE.into()), HDX, DAI, amount_to_sell, @@ -704,8 +675,8 @@ mod omnipool { //Arrange init_omnipool_with_oracle_for_block_10(); let alice_init_hdx_balance = 5000 * UNITS; - assert_ok!(hydradx_runtime::Balances::set_balance( - hydradx_runtime::RuntimeOrigin::root(), + assert_ok!(Balances::set_balance( + RuntimeOrigin::root(), ALICE.into(), alice_init_hdx_balance, 0, @@ -717,8 +688,8 @@ mod omnipool { asset_in: HDX, asset_out: DAI, }]; - assert_ok!(hydradx_runtime::Router::sell( - hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), + assert_ok!(Router::sell( + RuntimeOrigin::signed(ALICE.into()), HDX, DAI, amount_to_sell, @@ -758,7 +729,7 @@ mod omnipool { set_relaychain_block_number(11); //Assert - let fee = Currencies::free_balance(LRNA, &hydradx_runtime::Treasury::account_id()); + let fee = Currencies::free_balance(LRNA, &Treasury::account_id()); assert_reserved_balance!(&ALICE.into(), LRNA, dca_budget - amount_to_sell - fee); assert_balance!(ALICE.into(), DAI, ALICE_INITIAL_DAI_BALANCE + amount_out); @@ -777,8 +748,8 @@ mod omnipool { assert_balance!(ALICE.into(), DAI, ALICE_INITIAL_DAI_BALANCE); //Act - assert_ok!(hydradx_runtime::Omnipool::sell( - hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), + assert_ok!(Omnipool::sell( + RuntimeOrigin::signed(ALICE.into()), LRNA, DAI, amount_to_sell, @@ -804,8 +775,8 @@ mod omnipool { asset_in: LRNA, asset_out: DAI, }]; - assert_ok!(hydradx_runtime::Router::sell( - hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), + assert_ok!(Router::sell( + RuntimeOrigin::signed(ALICE.into()), LRNA, DAI, amount_to_sell, @@ -825,8 +796,8 @@ mod omnipool { Hydra::execute_with(|| { //Arrange let alice_init_hdx_balance = 5000 * UNITS; - assert_ok!(hydradx_runtime::Balances::set_balance( - hydradx_runtime::RuntimeOrigin::root(), + assert_ok!(Balances::set_balance( + RuntimeOrigin::root(), ALICE.into(), alice_init_hdx_balance, 0, @@ -834,7 +805,7 @@ mod omnipool { init_omnipool_with_oracle_for_block_10(); - let amount_to_sell = 100 * UNITS; + let amount_to_sell = 200 * UNITS; let dca_budget = 1200 * UNITS; let schedule1 = schedule_fake_with_sell_order(ALICE, PoolType::Omnipool, dca_budget, HDX, DAI, amount_to_sell); @@ -854,8 +825,10 @@ mod omnipool { assert_balance!(ALICE.into(), HDX, alice_init_hdx_balance - dca_budget); assert_reserved_balance!(&ALICE.into(), HDX, 0); - let schedule = hydradx_runtime::DCA::schedules(0); + let schedule = DCA::schedules(0); assert!(schedule.is_none()); + + check_if_dcas_completed_without_failed_or_terminated_events(); }); } @@ -865,16 +838,16 @@ mod omnipool { Hydra::execute_with(|| { //Arrange let alice_init_hdx_balance = 5000 * UNITS; - assert_ok!(hydradx_runtime::Balances::set_balance( - hydradx_runtime::RuntimeOrigin::root(), + assert_ok!(Balances::set_balance( + RuntimeOrigin::root(), ALICE.into(), alice_init_hdx_balance, 0, )); let bob_init_hdx_balance = 5000 * UNITS; - assert_ok!(hydradx_runtime::Balances::set_balance( - hydradx_runtime::RuntimeOrigin::root(), + assert_ok!(Balances::set_balance( + RuntimeOrigin::root(), BOB.into(), bob_init_hdx_balance, 0, @@ -882,7 +855,7 @@ mod omnipool { init_omnipool_with_oracle_for_block_10(); - let amount_to_sell = 100 * UNITS; + let amount_to_sell = 200 * UNITS; let dca_budget = 1000 * UNITS; let dca_budget_for_bob = 1200 * UNITS; @@ -911,11 +884,13 @@ mod omnipool { assert_reserved_balance!(&ALICE.into(), HDX, 0); assert_reserved_balance!(&BOB.into(), HDX, 0); - let schedule = hydradx_runtime::DCA::schedules(0); + let schedule = DCA::schedules(0); assert!(schedule.is_none()); - let schedule = hydradx_runtime::DCA::schedules(1); + let schedule = DCA::schedules(1); assert!(schedule.is_none()); + + check_if_dcas_completed_without_failed_or_terminated_events(); }); } @@ -925,8 +900,8 @@ mod omnipool { Hydra::execute_with(|| { //Arrange let alice_init_hdx_balance = 50000 * UNITS; - assert_ok!(hydradx_runtime::Balances::set_balance( - hydradx_runtime::RuntimeOrigin::root(), + assert_ok!(Balances::set_balance( + RuntimeOrigin::root(), ALICE.into(), alice_init_hdx_balance, 0, @@ -935,21 +910,21 @@ mod omnipool { init_omnipool_with_oracle_for_block_10(); //Trade 1 - let amount_to_sell1 = 100 * UNITS; + let amount_to_sell1 = 150 * UNITS; let dca_budget1 = 1000 * UNITS; let schedule1 = schedule_fake_with_sell_order(ALICE, PoolType::Omnipool, dca_budget1, HDX, DAI, amount_to_sell1); create_schedule(ALICE, schedule1); //Trade 2 - let amount_to_sell2 = 125 * UNITS; + let amount_to_sell2 = 200 * UNITS; let dca_budget2 = 1500 * UNITS; let schedule2 = schedule_fake_with_sell_order(ALICE, PoolType::Omnipool, dca_budget2, HDX, DAI, amount_to_sell2); create_schedule(ALICE, schedule2); //Trade 3 - let amount_to_sell3 = 250 * UNITS; + let amount_to_sell3 = 300 * UNITS; let dca_budget3 = 2000 * UNITS; let schedule3 = schedule_fake_with_sell_order(ALICE, PoolType::Omnipool, dca_budget3, HDX, DAI, amount_to_sell3); @@ -971,14 +946,16 @@ mod omnipool { alice_init_hdx_balance - dca_budget1 - dca_budget2 - dca_budget3 ); - let schedule = hydradx_runtime::DCA::schedules(0); + let schedule = DCA::schedules(0); assert!(schedule.is_none()); - let schedule = hydradx_runtime::DCA::schedules(1); + let schedule = DCA::schedules(1); assert!(schedule.is_none()); - let schedule = hydradx_runtime::DCA::schedules(2); + let schedule = DCA::schedules(2); assert!(schedule.is_none()); + + check_if_dcas_completed_without_failed_or_terminated_events(); }); } @@ -989,7 +966,7 @@ mod omnipool { //Arrange let native_amount = 100000 * UNITS; assert_ok!(Currencies::update_balance( - hydradx_runtime::RuntimeOrigin::root(), + RuntimeOrigin::root(), ALICE.into(), HDX, native_amount as i128, @@ -1039,17 +1016,30 @@ mod omnipool { Hydra::execute_with(|| { //Arrange init_omnipool_with_oracle_for_block_10(); - let fee = 3178776041665; + + let amount_to_sell = 1000 * UNITS; + let fee = DCA::get_transaction_fee(&Order::Sell { + asset_in: HDX, + asset_out: DAI, + amount_in: amount_to_sell, + min_amount_out: Balance::MIN, + route: create_bounded_vec(vec![Trade { + pool: PoolType::Omnipool, + asset_in: HDX, + asset_out: DAI, + }]), + }) + .unwrap(); + let alice_init_hdx_balance = 1000 * UNITS + fee + 1; - assert_ok!(hydradx_runtime::Balances::set_balance( - hydradx_runtime::RuntimeOrigin::root(), + assert_ok!(Balances::set_balance( + RuntimeOrigin::root(), ALICE.into(), alice_init_hdx_balance, 0, )); let dca_budget = 1000 * UNITS + fee; - let amount_to_sell = 1000 * UNITS; let schedule1 = schedule_fake_with_sell_order(ALICE, PoolType::Omnipool, dca_budget, HDX, DAI, amount_to_sell); create_schedule(ALICE, schedule1); @@ -1057,11 +1047,7 @@ mod omnipool { 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!( - &hydradx_runtime::Treasury::account_id(), - HDX, - TREASURY_ACCOUNT_INIT_BALANCE - ); + assert_balance!(&Treasury::account_id(), HDX, TREASURY_ACCOUNT_INIT_BALANCE); //Act set_relaychain_block_number(11); @@ -1085,27 +1071,27 @@ mod stableswap { let (pool_id, asset_a, asset_b) = init_stableswap().unwrap(); assert_ok!(hydradx_runtime::MultiTransactionPayment::add_currency( - hydradx_runtime::RuntimeOrigin::root(), + RuntimeOrigin::root(), asset_a, FixedU128::from_rational(88, 100), )); let alice_init_asset_a_balance = 5000 * UNITS; assert_ok!(Currencies::update_balance( - hydradx_runtime::RuntimeOrigin::root(), + RuntimeOrigin::root(), ALICE.into(), asset_a, alice_init_asset_a_balance as i128, )); assert_ok!(Currencies::update_balance( - hydradx_runtime::RuntimeOrigin::root(), + RuntimeOrigin::root(), CHARLIE.into(), asset_a, 5000 * UNITS as i128, )); assert_ok!(Stableswap::sell( - hydradx_runtime::RuntimeOrigin::signed(CHARLIE.into()), + RuntimeOrigin::signed(CHARLIE.into()), pool_id, asset_a, asset_b, @@ -1130,13 +1116,13 @@ mod stableswap { 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!(&hydradx_runtime::Treasury::account_id(), asset_a, 0); + assert_balance!(&Treasury::account_id(), asset_a, 0); //Act set_relaychain_block_number(11); //Assert - let fee = Currencies::free_balance(asset_a, &hydradx_runtime::Treasury::account_id()); + 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); @@ -1153,13 +1139,13 @@ mod stableswap { //Populate oracle assert_ok!(Currencies::update_balance( - hydradx_runtime::RuntimeOrigin::root(), + RuntimeOrigin::root(), CHARLIE.into(), asset_b, 5000 * UNITS as i128, )); assert_ok!(Stableswap::sell( - hydradx_runtime::RuntimeOrigin::signed(CHARLIE.into()), + RuntimeOrigin::signed(CHARLIE.into()), pool_id, asset_a, asset_b, @@ -1168,14 +1154,14 @@ mod stableswap { )); assert_ok!(hydradx_runtime::MultiTransactionPayment::add_currency( - hydradx_runtime::RuntimeOrigin::root(), + RuntimeOrigin::root(), asset_a, FixedU128::from_rational(88, 100), )); let alice_init_asset_a_balance = 5000 * UNITS; assert_ok!(Currencies::update_balance( - hydradx_runtime::RuntimeOrigin::root(), + RuntimeOrigin::root(), ALICE.into(), asset_a, alice_init_asset_a_balance as i128, @@ -1198,13 +1184,13 @@ mod stableswap { 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!(&hydradx_runtime::Treasury::account_id(), asset_a, 0); + assert_balance!(&Treasury::account_id(), asset_a, 0); //Act set_relaychain_block_number(11); //Assert - let fee = Currencies::free_balance(asset_a, &hydradx_runtime::Treasury::account_id()); + 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); @@ -1214,8 +1200,8 @@ mod stableswap { #[test] fn sell_should_work_with_omnipool_and_stable_trades() { - let amount_to_sell = 100 * UNITS; - let amount_to_receive = 98219730855737; + let amount_to_sell = 200 * UNITS; + let amount_to_receive = 194514524851196; //With DCA TestNet::reset(); Hydra::execute_with(|| { @@ -1223,7 +1209,7 @@ mod stableswap { let (pool_id, stable_asset_1, stable_asset_2) = init_stableswap().unwrap(); assert_ok!(Currencies::update_balance( - hydradx_runtime::RuntimeOrigin::root(), + RuntimeOrigin::root(), CHARLIE.into(), stable_asset_1, 10000 * UNITS as i128, @@ -1239,14 +1225,14 @@ mod stableswap { init_omnipol(); assert_ok!(Currencies::update_balance( - hydradx_runtime::RuntimeOrigin::root(), + RuntimeOrigin::root(), Omnipool::protocol_account(), pool_id, 10000 * UNITS as i128, )); - assert_ok!(hydradx_runtime::Omnipool::add_token( - hydradx_runtime::RuntimeOrigin::root(), + assert_ok!(Omnipool::add_token( + RuntimeOrigin::root(), pool_id, FixedU128::from_rational(50, 100), Permill::from_percent(100), @@ -1299,25 +1285,20 @@ mod stableswap { 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!( - &hydradx_runtime::Treasury::account_id(), - HDX, - TREASURY_ACCOUNT_INIT_BALANCE - ); + assert_balance!(&Treasury::account_id(), HDX, TREASURY_ACCOUNT_INIT_BALANCE); //Act set_relaychain_block_number(11); //Assert - let fee = - Currencies::free_balance(HDX, &hydradx_runtime::Treasury::account_id()) - TREASURY_ACCOUNT_INIT_BALANCE; + 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 treasury_balance = Currencies::free_balance(HDX, &hydradx_runtime::Treasury::account_id()); + let treasury_balance = Currencies::free_balance(HDX, &Treasury::account_id()); assert!(treasury_balance > TREASURY_ACCOUNT_INIT_BALANCE); }); @@ -1327,7 +1308,7 @@ mod stableswap { //Arrange let (pool_id, stable_asset_1, stable_asset_2) = init_stableswap().unwrap(); assert_ok!(Currencies::update_balance( - hydradx_runtime::RuntimeOrigin::root(), + RuntimeOrigin::root(), CHARLIE.into(), stable_asset_1, 10000 * UNITS as i128, @@ -1344,14 +1325,14 @@ mod stableswap { init_omnipol(); assert_ok!(Currencies::update_balance( - hydradx_runtime::RuntimeOrigin::root(), + RuntimeOrigin::root(), Omnipool::protocol_account(), pool_id, 10000 * UNITS as i128, )); - assert_ok!(hydradx_runtime::Omnipool::add_token( - hydradx_runtime::RuntimeOrigin::root(), + assert_ok!(Omnipool::add_token( + RuntimeOrigin::root(), pool_id, FixedU128::from_rational(50, 100), Permill::from_percent(100), @@ -1363,7 +1344,7 @@ mod stableswap { set_relaychain_block_number(10); //Act - assert_ok!(hydradx_runtime::Omnipool::sell( + assert_ok!(Omnipool::sell( RuntimeOrigin::signed(ALICE.into()), HDX, pool_id, @@ -1374,7 +1355,7 @@ mod stableswap { let pool_id_balance = Currencies::free_balance(pool_id, &AccountId::from(ALICE)); assert_ok!(Stableswap::remove_liquidity_one_asset( - hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), + RuntimeOrigin::signed(ALICE.into()), pool_id, stable_asset_1, pool_id_balance, @@ -1392,7 +1373,7 @@ mod stableswap { //Arrange let (pool_id, stable_asset_1, stable_asset_2) = init_stableswap().unwrap(); assert_ok!(Currencies::update_balance( - hydradx_runtime::RuntimeOrigin::root(), + RuntimeOrigin::root(), CHARLIE.into(), stable_asset_1, 10000 * UNITS as i128, @@ -1408,14 +1389,14 @@ mod stableswap { init_omnipol(); assert_ok!(Currencies::update_balance( - hydradx_runtime::RuntimeOrigin::root(), + RuntimeOrigin::root(), Omnipool::protocol_account(), pool_id, 10000 * UNITS as i128, )); - assert_ok!(hydradx_runtime::Omnipool::add_token( - hydradx_runtime::RuntimeOrigin::root(), + assert_ok!(Omnipool::add_token( + RuntimeOrigin::root(), pool_id, FixedU128::from_rational(50, 100), Permill::from_percent(100), @@ -1463,8 +1444,8 @@ mod stableswap { #[test] fn sell_should_work_with_stable_trades_and_omnipool() { - let amount_to_sell = 50 * UNITS; - let amount_to_receive = 35930705916066; + let amount_to_sell = 100 * UNITS; + let amount_to_receive = 70868187814642; TestNet::reset(); Hydra::execute_with(|| { //Arrange @@ -1472,7 +1453,7 @@ mod stableswap { //To populate stableswap oracle assert_ok!(Currencies::update_balance( - hydradx_runtime::RuntimeOrigin::root(), + RuntimeOrigin::root(), CHARLIE.into(), stable_asset_1, 10000 * UNITS as i128, @@ -1488,7 +1469,7 @@ mod stableswap { //Set stable asset 1 as accepted payment currency assert_ok!(hydradx_runtime::MultiTransactionPayment::add_currency( - hydradx_runtime::RuntimeOrigin::root(), + RuntimeOrigin::root(), stable_asset_1, FixedU128::from_rational(50, 100), )); @@ -1496,14 +1477,14 @@ mod stableswap { //Init omnipool and add pool id as token init_omnipol(); assert_ok!(Currencies::update_balance( - hydradx_runtime::RuntimeOrigin::root(), + RuntimeOrigin::root(), Omnipool::protocol_account(), pool_id, 3000 * UNITS as i128, )); - assert_ok!(hydradx_runtime::Omnipool::add_token( - hydradx_runtime::RuntimeOrigin::root(), + assert_ok!(Omnipool::add_token( + RuntimeOrigin::root(), pool_id, FixedU128::from_rational(50, 100), Permill::from_percent(100), @@ -1520,7 +1501,7 @@ mod stableswap { )); assert_ok!(Omnipool::sell( - hydradx_runtime::RuntimeOrigin::signed(CHARLIE.into()), + RuntimeOrigin::signed(CHARLIE.into()), pool_id, HDX, 500 * UNITS, @@ -1531,7 +1512,7 @@ mod stableswap { let alice_init_stable1_balance = 5000 * UNITS; assert_ok!(Currencies::update_balance( - hydradx_runtime::RuntimeOrigin::root(), + RuntimeOrigin::root(), ALICE.into(), stable_asset_1, alice_init_stable1_balance as i128, @@ -1572,13 +1553,13 @@ mod stableswap { 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!(&hydradx_runtime::Treasury::account_id(), stable_asset_1, 0); + assert_balance!(&Treasury::account_id(), stable_asset_1, 0); //Act set_relaychain_block_number(1001); //Assert - let fee = Currencies::free_balance(stable_asset_1, &hydradx_runtime::Treasury::account_id()); + 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); @@ -1594,7 +1575,7 @@ mod stableswap { //To populate stableswap oracle assert_ok!(Currencies::update_balance( - hydradx_runtime::RuntimeOrigin::root(), + RuntimeOrigin::root(), CHARLIE.into(), stable_asset_1, 10000 * UNITS as i128, @@ -1611,14 +1592,14 @@ mod stableswap { init_omnipol(); assert_ok!(Currencies::update_balance( - hydradx_runtime::RuntimeOrigin::root(), + RuntimeOrigin::root(), Omnipool::protocol_account(), pool_id, 3000 * UNITS as i128, )); - assert_ok!(hydradx_runtime::Omnipool::add_token( - hydradx_runtime::RuntimeOrigin::root(), + assert_ok!(Omnipool::add_token( + RuntimeOrigin::root(), pool_id, FixedU128::from_rational(50, 100), Permill::from_percent(100), @@ -1634,7 +1615,7 @@ mod stableswap { 0, )); assert_ok!(Omnipool::sell( - hydradx_runtime::RuntimeOrigin::signed(CHARLIE.into()), + RuntimeOrigin::signed(CHARLIE.into()), pool_id, HDX, 500 * UNITS, @@ -1643,7 +1624,7 @@ mod stableswap { let alice_init_stable1_balance = 5000 * UNITS; assert_ok!(Currencies::update_balance( - hydradx_runtime::RuntimeOrigin::root(), + RuntimeOrigin::root(), ALICE.into(), stable_asset_1, alice_init_stable1_balance as i128, @@ -1655,7 +1636,7 @@ mod stableswap { //Act assert_ok!(Stableswap::add_liquidity( - hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), + RuntimeOrigin::signed(ALICE.into()), pool_id, vec![AssetAmount { asset_id: stable_asset_1, @@ -1664,7 +1645,7 @@ mod stableswap { )); let alice_pool_id_balance = Currencies::free_balance(pool_id, &AccountId::from(ALICE)); - assert_ok!(hydradx_runtime::Omnipool::sell( + assert_ok!(Omnipool::sell( RuntimeOrigin::signed(ALICE.into()), pool_id, HDX, @@ -1689,7 +1670,7 @@ mod stableswap { //To populate stableswap oracle assert_ok!(Currencies::update_balance( - hydradx_runtime::RuntimeOrigin::root(), + RuntimeOrigin::root(), CHARLIE.into(), stable_asset_1, 10000 * UNITS as i128, @@ -1706,14 +1687,14 @@ mod stableswap { init_omnipol(); assert_ok!(Currencies::update_balance( - hydradx_runtime::RuntimeOrigin::root(), + RuntimeOrigin::root(), Omnipool::protocol_account(), pool_id, 3000 * UNITS as i128, )); - assert_ok!(hydradx_runtime::Omnipool::add_token( - hydradx_runtime::RuntimeOrigin::root(), + assert_ok!(Omnipool::add_token( + RuntimeOrigin::root(), pool_id, FixedU128::from_rational(50, 100), Permill::from_percent(100), @@ -1729,7 +1710,7 @@ mod stableswap { 0, )); assert_ok!(Omnipool::sell( - hydradx_runtime::RuntimeOrigin::signed(CHARLIE.into()), + RuntimeOrigin::signed(CHARLIE.into()), pool_id, HDX, 500 * UNITS, @@ -1738,7 +1719,7 @@ mod stableswap { let alice_init_stable1_balance = 5000 * UNITS; assert_ok!(Currencies::update_balance( - hydradx_runtime::RuntimeOrigin::root(), + RuntimeOrigin::root(), ALICE.into(), stable_asset_1, alice_init_stable1_balance as i128, @@ -1782,7 +1763,7 @@ mod stableswap { #[test] fn buy_should_work_with_omnipool_and_stable_trades() { - let amount_to_buy = 100 * UNITS; + let amount_to_buy = 200 * UNITS; //With DCA TestNet::reset(); Hydra::execute_with(|| { @@ -1791,7 +1772,7 @@ mod stableswap { //To populate stableswap oracle assert_ok!(Currencies::update_balance( - hydradx_runtime::RuntimeOrigin::root(), + RuntimeOrigin::root(), CHARLIE.into(), stable_asset_1, 10000 * UNITS as i128, @@ -1807,14 +1788,14 @@ mod stableswap { init_omnipol(); assert_ok!(Currencies::update_balance( - hydradx_runtime::RuntimeOrigin::root(), + RuntimeOrigin::root(), Omnipool::protocol_account(), pool_id, 3000 * UNITS as i128, )); - assert_ok!(hydradx_runtime::Omnipool::add_token( - hydradx_runtime::RuntimeOrigin::root(), + assert_ok!(Omnipool::add_token( + RuntimeOrigin::root(), pool_id, FixedU128::from_rational(50, 100), Permill::from_percent(100), @@ -1867,18 +1848,13 @@ mod stableswap { 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!( - &hydradx_runtime::Treasury::account_id(), - HDX, - TREASURY_ACCOUNT_INIT_BALANCE - ); + assert_balance!(&Treasury::account_id(), HDX, TREASURY_ACCOUNT_INIT_BALANCE); //Act set_relaychain_block_number(11); //Assert - let fee = - Currencies::free_balance(HDX, &hydradx_runtime::Treasury::account_id()) - TREASURY_ACCOUNT_INIT_BALANCE; + 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); @@ -1893,27 +1869,27 @@ mod stableswap { let (pool_id, asset_a, asset_b) = init_stableswap().unwrap(); assert_ok!(hydradx_runtime::MultiTransactionPayment::add_currency( - hydradx_runtime::RuntimeOrigin::root(), + RuntimeOrigin::root(), asset_a, FixedU128::from_rational(88, 100), )); let alice_init_asset_a_balance = 5000 * UNITS; assert_ok!(Currencies::update_balance( - hydradx_runtime::RuntimeOrigin::root(), + RuntimeOrigin::root(), ALICE.into(), asset_a, alice_init_asset_a_balance as i128, )); assert_ok!(Currencies::update_balance( - hydradx_runtime::RuntimeOrigin::root(), + RuntimeOrigin::root(), CHARLIE.into(), asset_a, 5000 * UNITS as i128, )); assert_ok!(Stableswap::sell( - hydradx_runtime::RuntimeOrigin::signed(CHARLIE.into()), + RuntimeOrigin::signed(CHARLIE.into()), pool_id, asset_a, asset_b, @@ -1937,13 +1913,13 @@ mod stableswap { 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!(&hydradx_runtime::Treasury::account_id(), asset_a, 0); + assert_balance!(&Treasury::account_id(), asset_a, 0); //Act set_relaychain_block_number(11); //Assert - let fee = Currencies::free_balance(asset_a, &hydradx_runtime::Treasury::account_id()); + 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); @@ -1960,20 +1936,20 @@ mod stableswap { //Set stable asset 1 as accepted payment currency assert_ok!(hydradx_runtime::MultiTransactionPayment::add_currency( - hydradx_runtime::RuntimeOrigin::root(), + RuntimeOrigin::root(), stable_asset_1, FixedU128::from_rational(50, 100), )); //For populating oracle assert_ok!(Currencies::update_balance( - hydradx_runtime::RuntimeOrigin::root(), + RuntimeOrigin::root(), CHARLIE.into(), stable_asset_1, 5000 * UNITS as i128, )); assert_ok!(Stableswap::sell( - hydradx_runtime::RuntimeOrigin::signed(CHARLIE.into()), + RuntimeOrigin::signed(CHARLIE.into()), pool_id, stable_asset_1, stable_asset_2, @@ -1984,14 +1960,14 @@ mod stableswap { //Init omnipool and add pool id as token init_omnipol(); assert_ok!(Currencies::update_balance( - hydradx_runtime::RuntimeOrigin::root(), + RuntimeOrigin::root(), Omnipool::protocol_account(), pool_id, 3000 * UNITS as i128, )); - assert_ok!(hydradx_runtime::Omnipool::add_token( - hydradx_runtime::RuntimeOrigin::root(), + assert_ok!(Omnipool::add_token( + RuntimeOrigin::root(), pool_id, FixedU128::from_rational(50, 100), Permill::from_percent(100), @@ -2004,7 +1980,7 @@ mod stableswap { let alice_init_stable1_balance = 5000 * UNITS; assert_ok!(Currencies::update_balance( - hydradx_runtime::RuntimeOrigin::root(), + RuntimeOrigin::root(), ALICE.into(), stable_asset_1, alice_init_stable1_balance as i128, @@ -2045,13 +2021,13 @@ mod stableswap { 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!(&hydradx_runtime::Treasury::account_id(), stable_asset_1, 0); + assert_balance!(&Treasury::account_id(), stable_asset_1, 0); //Act set_relaychain_block_number(11); //Assert - let fee = Currencies::free_balance(stable_asset_1, &hydradx_runtime::Treasury::account_id()); + 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); @@ -2060,11 +2036,7 @@ mod stableswap { } fn create_schedule(owner: [u8; 32], schedule1: Schedule) { - assert_ok!(hydradx_runtime::DCA::schedule( - hydradx_runtime::RuntimeOrigin::signed(owner.into()), - schedule1, - None - )); + assert_ok!(DCA::schedule(RuntimeOrigin::signed(owner.into()), schedule1, None)); } fn schedule_fake_with_buy_order( @@ -2142,9 +2114,9 @@ pub fn create_bounded_vec(trades: Vec>) -> BoundedVec 0, "There has been no dca::Completed events"); +} + pub fn get_last_schedule_ids_from_trade_executed_events() -> Vec { - let last_events: Vec = last_hydra_events(1000); + let last_events: Vec = last_hydra_events(1000); let mut schedule_ids = vec![]; for event in last_events { let e = event.clone(); - if let hydradx_runtime::RuntimeEvent::DCA(pallet_dca::Event::TradeExecuted { id, .. }) = e { + if let RuntimeEvent::DCA(pallet_dca::Event::TradeExecuted { id, .. }) = e { schedule_ids.push(id); } } @@ -2239,35 +2226,46 @@ pub fn get_last_schedule_ids_from_trade_executed_events() -> Vec { } pub fn count_failed_trade_events() -> u32 { - let last_events: Vec = last_hydra_events(100000); + count_dca_event!(pallet_dca::Event::TradeFailed { .. }) +} - let mut counter: u32 = 0; - for event in last_events { - let e = event.clone(); - if matches!( - e, - hydradx_runtime::RuntimeEvent::DCA(pallet_dca::Event::TradeFailed { .. }) - ) { - counter += 1; +pub fn count_terminated_trade_events() -> u32 { + count_dca_event!(pallet_dca::Event::Terminated { .. }) +} + +pub fn count_completed_event() -> u32 { + count_dca_event!(pallet_dca::Event::Completed { .. }) +} +#[macro_export] +macro_rules! count_dca_event { + ($pattern:pat) => {{ + let last_events: Vec = last_hydra_events(100000); + + let mut counter: u32 = 0; + for event in last_events { + let e = event.clone(); + if matches!(e, RuntimeEvent::DCA($pattern)) { + counter += 1; + } } - } - counter + counter + }}; } pub fn init_stableswap() -> Result<(AssetId, AssetId, AssetId), DispatchError> { let initial_liquidity = 1_000_000_000_000_000_000_000u128; - let mut initial: Vec::AssetId>> = vec![]; - let mut asset_ids: Vec<::AssetId> = Vec::new(); + let mut initial: Vec::AssetId>> = vec![]; + 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(hydradx_runtime::RuntimeOrigin::root(), asset_id, b"xDUM".to_vec(), 18u8)?; + AssetRegistry::set_metadata(RuntimeOrigin::root(), asset_id, b"xDUM".to_vec(), 18u8)?; asset_ids.push(asset_id); Currencies::update_balance( - hydradx_runtime::RuntimeOrigin::root(), + RuntimeOrigin::root(), AccountId::from(BOB), asset_id, initial_liquidity as i128, @@ -2282,15 +2280,9 @@ pub fn init_stableswap() -> Result<(AssetId, AssetId, AssetId), DispatchError> { let asset_in: AssetId = *asset_ids.last().unwrap(); let asset_out: AssetId = *asset_ids.first().unwrap(); - Stableswap::create_pool( - hydradx_runtime::RuntimeOrigin::root(), - pool_id, - asset_ids, - amplification, - fee, - )?; + Stableswap::create_pool(RuntimeOrigin::root(), pool_id, asset_ids, amplification, fee)?; - Stableswap::add_liquidity(hydradx_runtime::RuntimeOrigin::signed(BOB.into()), pool_id, initial)?; + Stableswap::add_liquidity(RuntimeOrigin::signed(BOB.into()), pool_id, initial)?; Ok((pool_id, asset_in, asset_out)) } @@ -2300,30 +2292,29 @@ pub fn init_stableswap_with_three_assets_having_different_decimals( let initial_liquidity = 1_000_000_000_000_000u128; let liquidity_added = 300_000_000_000_000u128; - let mut initial: Vec::AssetId>> = vec![]; - let mut added_liquidity: Vec::AssetId>> = - vec![]; + let mut initial: Vec::AssetId>> = vec![]; + let mut added_liquidity: Vec::AssetId>> = vec![]; - let mut asset_ids: Vec<::AssetId> = Vec::new(); + let mut asset_ids: Vec<::AssetId> = Vec::new(); 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( - hydradx_runtime::RuntimeOrigin::root(), + RuntimeOrigin::root(), asset_id, b"xDUM".to_vec(), decimals_for_each_asset[idx as usize], )?; asset_ids.push(asset_id); Currencies::update_balance( - hydradx_runtime::RuntimeOrigin::root(), + RuntimeOrigin::root(), AccountId::from(BOB), asset_id, 1_000_000_000_000_000i128, )?; Currencies::update_balance( - hydradx_runtime::RuntimeOrigin::root(), + RuntimeOrigin::root(), AccountId::from(CHARLIE), asset_id, 1_000_000_000_000_000_000_000i128, @@ -2339,15 +2330,9 @@ pub fn init_stableswap_with_three_assets_having_different_decimals( let asset_in: AssetId = asset_ids[1]; let asset_out: AssetId = asset_ids[2]; - Stableswap::create_pool( - hydradx_runtime::RuntimeOrigin::root(), - pool_id, - asset_ids, - amplification, - fee, - )?; + Stableswap::create_pool(RuntimeOrigin::root(), pool_id, asset_ids, amplification, fee)?; - Stableswap::add_liquidity(hydradx_runtime::RuntimeOrigin::signed(BOB.into()), pool_id, initial)?; + Stableswap::add_liquidity(RuntimeOrigin::signed(BOB.into()), pool_id, initial)?; Ok((pool_id, asset_in, asset_out)) } diff --git a/integration-tests/src/lib.rs b/integration-tests/src/lib.rs index 7103dae84..d5772fb39 100644 --- a/integration-tests/src/lib.rs +++ b/integration-tests/src/lib.rs @@ -1,3 +1,5 @@ +// DCA pallet uses dummy router for benchmarks and some tests fail when benchmarking feature is enabled +#![cfg(not(feature = "runtime-benchmarks"))] mod bonds; mod call_filter; mod circuit_breaker; diff --git a/integration-tests/src/router.rs b/integration-tests/src/router.rs index f008df794..e46cd5d37 100644 --- a/integration-tests/src/router.rs +++ b/integration-tests/src/router.rs @@ -7,7 +7,8 @@ use std::convert::Into; use hydradx_adapters::OmnipoolHookAdapter; use hydradx_runtime::{ - AmmWeights, AssetRegistry, BlockNumber, Currencies, Omnipool, Router, Runtime, RuntimeOrigin, Stableswap, LBP, XYK, + AssetRegistry, BlockNumber, Currencies, Omnipool, Router, RouterWeightInfo, Runtime, RuntimeOrigin, Stableswap, + LBP, XYK, }; use hydradx_traits::Registry; use hydradx_traits::{ @@ -28,8 +29,7 @@ use xcm_emulator::TestExt; use pallet_stableswap::types::AssetAmount; use pallet_stableswap::MAX_ASSETS_IN_POOL; -use sp_runtime::traits::ConstU32; -use sp_runtime::{DispatchError, FixedU128, Permill}; +use sp_runtime::{traits::ConstU32, DispatchError, FixedU128, Permill}; use orml_traits::MultiCurrency; @@ -587,6 +587,90 @@ mod router_different_pools_tests { assert_balance!(ALICE.into(), HDX, ALICE_INITIAL_NATIVE_BALANCE + amount_to_buy); }); } + + #[test] + fn trade_should_return_correct_weight() { + TestNet::reset(); + + Hydra::execute_with(|| { + //Arrange + + let trades = vec![ + Trade { + pool: PoolType::Omnipool, + asset_in: DAI, + asset_out: ACA, + }, + Trade { + pool: PoolType::LBP, + asset_in: ACA, + asset_out: DOT, + }, + ]; + + //Act & Assert + assert_eq!( + RouterWeightInfo::sell_weight(trades.as_slice()), + hydradx_runtime::weights::omnipool::HydraWeight::::router_execution_sell(1, 1) + .checked_add( + &, Runtime> as OmnipoolHooks::< + RuntimeOrigin, + AccountId, + AssetId, + Balance, + >>::on_trade_weight() + ) + .unwrap() + .checked_add( + &, Runtime> as OmnipoolHooks::< + RuntimeOrigin, + AccountId, + AssetId, + Balance, + >>::on_liquidity_changed_weight() + ) + .unwrap() + .checked_add(&hydradx_runtime::weights::lbp::HydraWeight::::router_execution_sell(1, 1)) + .unwrap() + .checked_add( + &RouterWeightInfo::sell_and_calculate_sell_trade_amounts_overhead_weight(0, 1) + .checked_mul(2) + .unwrap() + ) + .unwrap() + ); + assert_eq!( + RouterWeightInfo::buy_weight(trades.as_slice()), + hydradx_runtime::weights::omnipool::HydraWeight::::router_execution_buy(1, 1) + .checked_add( + &, Runtime> as OmnipoolHooks::< + RuntimeOrigin, + AccountId, + AssetId, + Balance, + >>::on_trade_weight() + ) + .unwrap() + .checked_add( + &, Runtime> as OmnipoolHooks::< + RuntimeOrigin, + AccountId, + AssetId, + Balance, + >>::on_liquidity_changed_weight() + ) + .unwrap() + .checked_add(&hydradx_runtime::weights::lbp::HydraWeight::::router_execution_buy(1, 1)) + .unwrap() + .checked_add( + &RouterWeightInfo::buy_and_calculate_buy_trade_amounts_overhead_weight(0, 1) + .checked_mul(2) + .unwrap() + ) + .unwrap() + ); + }); + } } mod omnipool_router_tests { @@ -926,71 +1010,6 @@ mod omnipool_router_tests { ); }); } - - #[test] - fn trade_should_return_correct_weight() { - TestNet::reset(); - - Hydra::execute_with(|| { - //Arrange - - let trades = vec![Trade { - pool: PoolType::Omnipool, - asset_in: DAI, - asset_out: ACA, - }]; - - //Act & Assert - assert_eq!( - AmmWeights::sell_weight(trades.as_slice()), - hydradx_runtime::weights::omnipool::HydraWeight::::router_execution_sell() - .checked_add( - &, Runtime> as OmnipoolHooks::< - RuntimeOrigin, - AccountId, - AssetId, - Balance, - >>::on_trade_weight() - ) - .unwrap() - .checked_add( - &, Runtime> as OmnipoolHooks::< - RuntimeOrigin, - AccountId, - AssetId, - Balance, - >>::on_liquidity_changed_weight() - ) - .unwrap() - .checked_add(&AmmWeights::sell_overhead_weight()) - .unwrap() - ); - assert_eq!( - AmmWeights::buy_weight(trades.as_slice()), - hydradx_runtime::weights::omnipool::HydraWeight::::router_execution_buy() - .checked_add( - &, Runtime> as OmnipoolHooks::< - RuntimeOrigin, - AccountId, - AssetId, - Balance, - >>::on_trade_weight() - ) - .unwrap() - .checked_add( - &, Runtime> as OmnipoolHooks::< - RuntimeOrigin, - AccountId, - AssetId, - Balance, - >>::on_liquidity_changed_weight() - ) - .unwrap() - .checked_add(&AmmWeights::buy_overhead_weight()) - .unwrap() - ); - }); - } } mod lbp_router_tests { @@ -1547,35 +1566,6 @@ mod lbp_router_tests { ); }); } - - #[test] - fn trade_should_return_correct_weight() { - TestNet::reset(); - - Hydra::execute_with(|| { - //Arrange - - let trades = vec![Trade { - pool: PoolType::LBP, - asset_in: DAI, - asset_out: ACA, - }]; - - //Act & Assert - assert_eq!( - AmmWeights::sell_weight(trades.as_slice()), - hydradx_runtime::weights::lbp::HydraWeight::::router_execution_sell() - .checked_add(&AmmWeights::sell_overhead_weight()) - .unwrap() - ); - assert_eq!( - AmmWeights::buy_weight(trades.as_slice()), - hydradx_runtime::weights::lbp::HydraWeight::::router_execution_buy() - .checked_add(&AmmWeights::buy_overhead_weight()) - .unwrap() - ); - }); - } } mod xyk_router_tests { diff --git a/pallets/dca/Cargo.toml b/pallets/dca/Cargo.toml index 84fb1110e..00e5aef6a 100644 --- a/pallets/dca/Cargo.toml +++ b/pallets/dca/Cargo.toml @@ -1,6 +1,6 @@ [package] name = 'pallet-dca' -version = "1.1.10" +version = "1.2.0" description = 'A pallet to manage DCA scheduling' authors = ['GalacticCouncil'] edition = '2021' @@ -34,7 +34,6 @@ hydradx-traits = { workspace = true } hydradx-adapters = { workspace = true } pallet-relaychain-info = { workspace = true } pallet-ema-oracle = { workspace = true } -pallet-route-executor = { workspace = true } hydra-dx-math = { workspace = true } @@ -51,6 +50,7 @@ primitives = { path="../../primitives", default-features = false } [dev-dependencies] +pallet-route-executor = { workspace = true } smallvec = "1.9.0" pallet-balances = { workspace = true } pallet-currencies = { workspace = true } @@ -82,7 +82,6 @@ std = [ "orml-tokens/std", "pallet-omnipool/std", "pallet-ema-oracle/std", - "pallet-route-executor/std", ] runtime-benchmarks = [ diff --git a/pallets/dca/src/benchmarks.rs b/pallets/dca/src/benchmarks.rs deleted file mode 100644 index 14b22ff7e..000000000 --- a/pallets/dca/src/benchmarks.rs +++ /dev/null @@ -1,449 +0,0 @@ -// This file is part of HydraDX-node - -// 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. -#![cfg(feature = "runtime-benchmarks")] -#![allow(unused_assignments)] // At test `on_initialize_with_empty_block` it does not recognize the assignment in the Act block - -use super::*; - -use frame_benchmarking::account; -use frame_benchmarking::benchmarks; -use frame_support::assert_ok; -use frame_system::{Pallet as System, RawOrigin}; -use hydradx_traits::router::PoolType; -use orml_traits::MultiCurrencyExtended; -use scale_info::prelude::vec::Vec; -use sp_runtime::FixedU128; -use sp_runtime::Permill; - -pub type AssetId = u32; - -pub const TVL_CAP: Balance = 222_222_000_000_000_000_000_000_000; - -pub const HDX: AssetId = 0; -pub const LRNA: AssetId = 1; -pub const DAI: AssetId = 2; - -pub const ONE: Balance = 1_000_000_000_000; - -// This is the the sum of all "randomly" generated radiuses. -// In tests the radiuses are always the same as we use a fixed parent hash for generation, -// so it will always generate the same values -pub const DELAY_AFTER_LAST_RADIUS: u32 = 1854; - -pub const RETRY_TO_SEARCH_FOR_FREE_BLOCK: u32 = 10; - -fn schedule_fake( - owner: T::AccountId, - asset_in: ::AssetId, - asset_out: ::AssetId, - amount: Balance, -) -> Schedule::AssetId, T::BlockNumber> { - let schedule1: Schedule::AssetId, T::BlockNumber> = Schedule { - owner, - period: 3u32.into(), - total_amount: 1100 * ONE, - max_retries: None, - stability_threshold: None, - slippage: Some(Permill::from_percent(15)), - order: Order::Buy { - asset_in, - asset_out, - amount_out: amount, - max_amount_in: Balance::MAX, - route: create_bounded_vec::(vec![Trade { - pool: PoolType::Omnipool, - asset_in, - asset_out, - }]), - }, - }; - schedule1 -} - -fn get_named_reseve_balance( - token_id: ::AssetId, - seller: T::AccountId, -) -> Balance { - ::Currencies::reserved_balance_named(&T::NamedReserveId::get(), token_id, &seller) -} - -fn schedule_buy_fake( - owner: T::AccountId, - asset_in: ::AssetId, - asset_out: ::AssetId, - amount: Balance, -) -> Schedule::AssetId, T::BlockNumber> { - let schedule1: Schedule::AssetId, T::BlockNumber> = Schedule { - owner, - period: 3u32.into(), - total_amount: 2000 * ONE, - max_retries: None, - stability_threshold: None, - slippage: Some(Permill::from_percent(15)), - order: Order::Buy { - asset_in, - asset_out, - amount_out: amount, - max_amount_in: Balance::MAX, - route: create_bounded_vec::(vec![Trade { - pool: PoolType::Omnipool, - asset_in, - asset_out, - }]), - }, - }; - schedule1 -} - -fn schedule_sell_fake( - owner: T::AccountId, - asset_in: ::AssetId, - asset_out: ::AssetId, - amount: Balance, -) -> Schedule::AssetId, T::BlockNumber> { - let schedule1: Schedule::AssetId, T::BlockNumber> = Schedule { - owner, - period: 3u32.into(), - total_amount: 2000 * ONE, - max_retries: None, - stability_threshold: None, - slippage: Some(Permill::from_percent(100)), - order: Order::Sell { - asset_in, - asset_out, - amount_in: amount, - min_amount_out: Balance::MIN, - route: create_bounded_vec::(vec![Trade { - pool: PoolType::Omnipool, - asset_in, - asset_out, - }]), - }, - }; - schedule1 -} - -fn set_period(to: u32) -where - T: pallet_ema_oracle::Config, - CurrencyOf: MultiCurrencyExtended, - T: crate::pallet::Config, - ::AssetId: From, - ::AssetId: From, -{ - while System::::block_number() < to.into() { - let b = System::::block_number(); - - System::::on_finalize(b); - pallet_ema_oracle::Pallet::::on_finalize(b); - - System::::on_initialize(b + 1_u32.into()); - pallet_ema_oracle::Pallet::::on_initialize(b + 1_u32.into()); - - System::::set_block_number(b + 1_u32.into()); - } -} - -pub fn create_bounded_vec( - trades: Vec::AssetId>>, -) -> BoundedVec::AssetId>, ConstU32<5>> { - let bounded_vec: BoundedVec::AssetId>, sp_runtime::traits::ConstU32<5>> = - trades.try_into().unwrap(); - bounded_vec -} - -type CurrencyOf = ::Currency; -type OmnipoolPallet = pallet_omnipool::Pallet; - -fn initialize_omnipool() -> DispatchResult -where - ::Currency: MultiCurrencyExtended, - T: pallet_ema_oracle::Config, - ::AssetId: From, - ::AssetId: From, -{ - let stable_amount: Balance = 5_000_000_000_000_000_000_000_000u128; - let native_amount: Balance = 5_000_000_000_000_000_000_000_000u128; - let stable_price: FixedU128 = FixedU128::from((1, 2)); - let native_price: FixedU128 = FixedU128::from(1); - let acc = OmnipoolPallet::::protocol_account(); - - OmnipoolPallet::::set_tvl_cap(RawOrigin::Root.into(), TVL_CAP)?; - - ::Currency::update_balance(T::StableCoinAssetId::get(), &acc, stable_amount as i128)?; - ::Currency::update_balance(T::HdxAssetId::get(), &acc, native_amount as i128)?; - - OmnipoolPallet::::initialize_pool( - RawOrigin::Root.into(), - stable_price, - native_price, - Permill::from_percent(100), - Permill::from_percent(100), - )?; - - //NOTE: This is necessary for oracle to provide price. - do_lrna_hdx_trade::()?; - do_lrna_dai_trade::()?; - - set_period::(10); - - do_lrna_dai_trade::()?; - do_lrna_hdx_trade::() -} - -const SEED: u32 = 0; -fn create_funded_account( - name: &'static str, - index: u32, - amount: Balance, - currency: ::AssetId, -) -> T::AccountId -where - ::AssetId: From, -{ - let caller: T::AccountId = account(name, index, SEED); - - fund::(caller.clone(), currency, amount).unwrap(); - - caller -} - -fn fund( - to: T::AccountId, - currency: ::AssetId, - amount: Balance, -) -> DispatchResult { - CurrencyOf::::deposit(currency, &to, amount) -} - -//NOTE: This is necessary for oracle to provide price. -fn do_lrna_hdx_trade() -> DispatchResult -where - ::Currency: MultiCurrencyExtended, - ::AssetId: From, - ::AssetId: From, -{ - let trader = create_funded_account::("tmp_trader", 0, 100 * ONE, HDX.into()); - - fund::(trader.clone(), LRNA.into(), 100 * ONE)?; - - OmnipoolPallet::::sell(RawOrigin::Signed(trader).into(), LRNA.into(), HDX.into(), ONE, 0) -} - -//NOTE: This is necessary for oracle to provide price. -fn do_lrna_dai_trade() -> DispatchResult -where - ::Currency: MultiCurrencyExtended, - ::AssetId: From, - ::AssetId: From, -{ - let trader = create_funded_account::("tmp_trader", 0, 100 * ONE, DAI.into()); - - fund::(trader.clone(), LRNA.into(), 100 * ONE)?; - - OmnipoolPallet::::sell(RawOrigin::Signed(trader).into(), LRNA.into(), DAI.into(), ONE, 0) -} - -fn create_account_with_native_balance( -) -> Result -where - CurrencyOf: MultiCurrencyExtended, - T: crate::pallet::Config + pallet_omnipool::Config, - ::AssetId: From, -{ - let caller: T::AccountId = account("provider", 1, 1); - let token_amount = 200 * ONE; - ::Currency::update_balance(0.into(), &caller, token_amount as i128)?; - - Ok(caller) -} - -benchmarks! { - where_clause { where - CurrencyOf: MultiCurrencyExtended, - T: crate::pallet::Config + pallet_omnipool::Config + pallet_ema_oracle::Config + pallet_route_executor::Config, - ::AssetId: From, - ::AssetId: From, - ::AssetId: Into, - ::AssetId: Into<::AssetId>, - ::AssetId: From<::AssetId>, - u128: From<::Balance>, - ::AssetId: From<::AssetId>, - ::Balance: From - } - - on_initialize_with_buy_trade{ - //TODO: Rebenchmark it with dynamic length of route once we have other AMMs in hydra - initialize_omnipool::()?; - set_period::(1000); - let seller: T::AccountId = account("seller", 3, 1); - let other_seller: T::AccountId = account("seller", 3, 1); - - let amount_buy = 200 * ONE; - - ::Currency::update_balance(HDX.into(), &seller, 20_000_000_000_000_000_000_000i128)?; - ::Currency::update_balance(0u32.into(), &seller, 500_000_000_000_000i128)?; - - ::Currency::update_balance(HDX.into(), &other_seller, 20_000_000_000_000_000_000_000i128)?; - - let schedule1 = schedule_buy_fake::(seller.clone(), HDX.into(), DAI.into(), amount_buy); - let execution_block = 1001u32; - - assert_ok!(crate::Pallet::::schedule(RawOrigin::Signed(seller.clone()).into(), schedule1.clone(), Option::Some(execution_block.into()))); - - assert_eq!(::Currency::free_balance(T::StableCoinAssetId::get(), &seller),0); - let reserved_balance = get_named_reseve_balance::(HDX.into(), seller.clone()); - - let init_reserved_balance = 2000 * ONE; - assert_eq!(init_reserved_balance, reserved_balance); - - assert_eq!(::Currency::free_balance(DAI.into(), &seller), 0); - - //Make sure that we have other schedules planned in the block where the benchmark schedule is planned, leading to worst case - //We leave only one slot - let schedule_period = 3; - let next_block_to_replan = execution_block + schedule_period; - let number_of_all_schedules = T::MaxSchedulePerBlock::get() + T::MaxSchedulePerBlock::get() * RETRY_TO_SEARCH_FOR_FREE_BLOCK - 1; - for i in 0..number_of_all_schedules { - assert_ok!(crate::Pallet::::schedule(RawOrigin::Signed(other_seller.clone()).into(), schedule1.clone(), Option::Some(next_block_to_replan.into()))); - } - - assert_eq!((T::MaxSchedulePerBlock::get() - 1) as usize, >::get::>((next_block_to_replan + DELAY_AFTER_LAST_RADIUS).into()).len()); - }: { - crate::Pallet::::on_initialize(execution_block.into()); - } - verify { - let new_dai_balance = ::Currency::free_balance(DAI.into(), &seller); - assert_eq!(new_dai_balance, amount_buy); - assert_eq!((T::MaxSchedulePerBlock::get()) as usize, >::get::>((next_block_to_replan + DELAY_AFTER_LAST_RADIUS).into()).len()); - } - - on_initialize_with_sell_trade{ - //TODO: Rebenchmark it with dynamic length of route once we have other AMMs in hydra - initialize_omnipool::()?; - set_period::(1000); - let seller: T::AccountId = account("seller", 3, 1); - let other_seller: T::AccountId = account("seller", 3, 1); - - let amount_sell = 100 * ONE; - - ::Currency::update_balance(HDX.into(), &seller, 20_000_000_000_000_000i128)?; - - ::Currency::update_balance(HDX.into(), &other_seller, 20_000_000_000_000_000_000_000i128)?; - - let schedule1 = schedule_sell_fake::(seller.clone(), HDX.into(), DAI.into(), amount_sell); - let execution_block = 1001u32; - - assert_ok!(crate::Pallet::::schedule(RawOrigin::Signed(seller.clone()).into(), schedule1.clone(), Option::Some(execution_block.into()))); - - assert_eq!(::Currency::free_balance(T::StableCoinAssetId::get(), &seller),0); - let reserved_balance = get_named_reseve_balance::(HDX.into(), seller.clone()); - - let init_reserved_balance = 2000 * ONE; - assert_eq!(init_reserved_balance, reserved_balance); - - assert_eq!(::Currency::free_balance(DAI.into(), &seller), 0); - - //Make sure that we have other schedules planned in the block where the benchmark schedule is planned, leading to worst case - //We leave only one slot - let schedule_period = 3; - let next_block_to_replan = execution_block + schedule_period; - let number_of_all_schedules = T::MaxSchedulePerBlock::get() + T::MaxSchedulePerBlock::get() * RETRY_TO_SEARCH_FOR_FREE_BLOCK - 1; - for i in 0..number_of_all_schedules { - assert_ok!(crate::Pallet::::schedule(RawOrigin::Signed(other_seller.clone()).into(), schedule1.clone(), Option::Some(next_block_to_replan.into()))); - } - assert_eq!((T::MaxSchedulePerBlock::get() - 1) as usize, >::get::>((next_block_to_replan + DELAY_AFTER_LAST_RADIUS).into()).len()); - }: { - crate::Pallet::::on_initialize(execution_block.into()); - } - verify { - let new_dai_balance = ::Currency::free_balance(T::StableCoinAssetId::get(), &seller); - assert!(new_dai_balance > 0); - assert_eq!((T::MaxSchedulePerBlock::get()) as usize, >::get::>((next_block_to_replan + DELAY_AFTER_LAST_RADIUS).into()).len()); - } - - on_initialize_with_empty_block{ - initialize_omnipool::()?; - - let seller: T::AccountId = account("seller", 3, 1); - - let execution_block = 100u32; - assert_eq!(crate::Pallet::::schedules::(execution_block).len(), 0); - let mut weight = Weight::from_ref_time(0); - }: { - weight = crate::Pallet::::on_initialize(execution_block.into()); - } - verify { - assert!(weight.ref_time() > 0u64); - } - - - schedule{ - initialize_omnipool::()?; - - let caller: T::AccountId = create_account_with_native_balance::()?; - ::Currency::update_balance(HDX.into(), &caller, 100_000_000_000_000_000_000_000i128)?; - - let amount_sell = 200 * ONE; - let schedule1 = schedule_fake::(caller.clone(), HDX.into(), DAI.into(), amount_sell); - let execution_block = 100u32; - - //We fill blocks with schedules leaving only one place - let number_of_all_schedules = T::MaxSchedulePerBlock::get() + T::MaxSchedulePerBlock::get() * RETRY_TO_SEARCH_FOR_FREE_BLOCK - 1; - for i in 0..number_of_all_schedules { - assert_ok!(crate::Pallet::::schedule(RawOrigin::Signed(caller.clone()).into(), schedule1.clone(), Option::Some(execution_block.into()))); - } - - let schedule_id : ScheduleId = number_of_all_schedules; - - assert_eq!((T::MaxSchedulePerBlock::get() - 1) as usize, >::get::>((execution_block + DELAY_AFTER_LAST_RADIUS).into()).len()); - - }: _(RawOrigin::Signed(caller.clone()), schedule1, Option::Some(execution_block.into())) - verify { - assert!(>::get::(schedule_id).is_some()); - - assert_eq!((T::MaxSchedulePerBlock::get()) as usize, >::get::>((execution_block + DELAY_AFTER_LAST_RADIUS).into()).len()); - } - - terminate { - initialize_omnipool::()?; - let caller: T::AccountId = create_account_with_native_balance::()?; - ::Currency::update_balance(HDX.into(), &caller, 100_000_000_000_000_000i128)?; - - let amount_sell = 200 * ONE; - let schedule1 = schedule_fake::(caller.clone(), HDX.into(), DAI.into(), amount_sell); - let schedule_id : ScheduleId = 0; - - set_period::(99); - let execution_block = 100u32; - assert_ok!(crate::Pallet::::schedule(RawOrigin::Signed(caller).into(), schedule1, Option::Some(execution_block.into()))); - - }: _(RawOrigin::Root, schedule_id, None) - verify { - assert!(>::get::(schedule_id).is_none()); - } - -} - -#[cfg(test)] -mod tests { - use super::Pallet; - use crate::tests::mock::*; - use frame_benchmarking::impl_benchmark_test_suite; - - impl_benchmark_test_suite!(Pallet, super::ExtBuilder::default().build(), super::Test); -} diff --git a/pallets/dca/src/lib.rs b/pallets/dca/src/lib.rs index 713cd48e6..1008a1b3f 100644 --- a/pallets/dca/src/lib.rs +++ b/pallets/dca/src/lib.rs @@ -73,17 +73,12 @@ use frame_support::{ }; use frame_system::{ensure_signed, pallet_prelude::OriginFor, Origin}; use hydradx_adapters::RelayChainBlockHashProvider; -use hydradx_traits::router::Trade; +use hydradx_traits::router::{AmmTradeWeights, AmountInAndOut, RouterT, Trade}; use hydradx_traits::{NativePriceOracle, OraclePeriod, PriceOracle}; -use orml_traits::arithmetic::CheckedAdd; -use orml_traits::MultiCurrency; -use orml_traits::NamedMultiReservableCurrency; -use pallet_route_executor::AmountInAndOut; -use pallet_route_executor::TradeAmountsCalculator; +use orml_traits::{arithmetic::CheckedAdd, MultiCurrency, NamedMultiReservableCurrency}; use rand::rngs::StdRng; use rand::{Rng, SeedableRng}; -use sp_runtime::traits::CheckedMul; -use sp_runtime::traits::One; +use sp_runtime::traits::{CheckedMul, One}; use sp_runtime::{ traits::{BlockNumberProvider, Saturating}, ArithmeticError, BoundedVec, DispatchError, FixedPointNumber, FixedU128, Permill, @@ -94,9 +89,6 @@ use sp_std::{cmp::min, vec}; #[cfg(test)] mod tests; -#[cfg(any(feature = "runtime-benchmarks", test))] -mod benchmarks; - pub mod types; pub mod weights; @@ -129,11 +121,7 @@ pub mod pallet { pub struct Pallet(_); #[pallet::hooks] - impl Hooks for Pallet - where - ::Balance: From, - Balance: From<::Balance>, - { + impl Hooks for Pallet { fn on_initialize(current_blocknumber: T::BlockNumber) -> Weight { let mut weight = ::WeightInfo::on_initialize_with_empty_block(); @@ -206,10 +194,13 @@ pub mod pallet { } #[pallet::config] - pub trait Config: frame_system::Config + pallet_route_executor::Config { + pub trait Config: frame_system::Config { /// The overarching event type. type RuntimeEvent: From> + IsType<::RuntimeEvent>; + /// Asset id type + type AssetId: Parameter + Member + Copy + MaybeSerializeDeserialize + MaxEncodedLen; + /// Origin able to terminate schedules type TechnicalOrigin: EnsureOrigin; @@ -233,6 +224,9 @@ pub mod pallet { ///Native price provider to get the price of assets that are accepted as fees type NativePriceOracle: NativePriceOracle; + ///Router implementation + type Router: RouterT, AmountInAndOut>; + ///Max price difference allowed between blocks #[pallet::constant] type MaxPriceDifferenceBetweenBlocks: Get; @@ -268,6 +262,9 @@ pub mod pallet { /// Convert a weight value into a deductible fee type WeightToFee: WeightToFee; + /// AMMs trade weight information. + type AmmTradeWeights: AmmTradeWeights>; + /// Weight information for the extrinsics. type WeightInfo: WeightInfo; } @@ -383,11 +380,7 @@ pub mod pallet { StorageMap<_, Blake2_128Concat, BlockNumberFor, BoundedVec, ValueQuery>; #[pallet::call] - impl Pallet - where - ::Balance: From, - Balance: From<::Balance>, - { + impl Pallet { /// Creates a new DCA (Dollar-Cost Averaging) schedule and plans the next execution /// for the specified block. /// @@ -413,7 +406,7 @@ pub mod pallet { /// Emits `Scheduled` and `ExecutionPlanned` event when successful. /// #[pallet::call_index(0)] - #[pallet::weight(::WeightInfo::schedule())] + #[pallet::weight(::WeightInfo::schedule() + ::AmmTradeWeights::calculate_buy_trade_amounts_weight(schedule.order.get_route()))] #[transactional] pub fn schedule( origin: OriginFor, @@ -562,11 +555,7 @@ pub mod pallet { } } -impl Pallet -where - ::Balance: From, - Balance: From<::Balance>, -{ +impl Pallet { fn get_randomness_generator(current_blocknumber: T::BlockNumber, salt: Option) -> StdRng { match T::RandomnessProvider::generator(salt) { Ok(generator) => generator, @@ -650,32 +639,24 @@ where .ok_or(ArithmeticError::Overflow)?; let route = route.to_vec(); - let trade_amounts = - pallet_route_executor::Pallet::::calculate_sell_trade_amounts(&route, amount_to_sell.into())?; + let trade_amounts = T::Router::calculate_sell_trade_amounts(&route, amount_to_sell)?; let last_trade = trade_amounts.last().defensive_ok_or(Error::::InvalidState)?; let amount_out = last_trade.amount_out; if *min_amount_out > last_block_slippage_min_limit { - ensure!(amount_out >= (*min_amount_out).into(), Error::::TradeLimitReached); + ensure!(amount_out >= *min_amount_out, Error::::TradeLimitReached); } else { ensure!( - amount_out >= last_block_slippage_min_limit.into(), + amount_out >= last_block_slippage_min_limit, Error::::SlippageLimitReached ); }; - pallet_route_executor::Pallet::::sell( - origin, - *asset_in, - *asset_out, - (amount_to_sell).into(), - amount_out, - route, - )?; + T::Router::sell(origin, *asset_in, *asset_out, amount_to_sell, amount_out, route)?; Ok(AmountInAndOut { amount_in: amount_to_sell, - amount_out: amount_out.into(), + amount_out, }) } Order::Buy { @@ -704,14 +685,7 @@ where ); }; - pallet_route_executor::Pallet::::buy( - origin, - *asset_in, - *asset_out, - (*amount_out).into(), - amount_in.into(), - route.to_vec(), - )?; + T::Router::buy(origin, *asset_in, *asset_out, *amount_out, amount_in, route.to_vec())?; Ok(AmountInAndOut { amount_in, @@ -850,15 +824,14 @@ where amount_out: &Balance, route: &BoundedVec, ConstU32<5>>, ) -> Result { - let trade_amounts = - pallet_route_executor::Pallet::::calculate_buy_trade_amounts(route.as_ref(), (*amount_out).into())?; + let trade_amounts = T::Router::calculate_buy_trade_amounts(route.as_ref(), *amount_out)?; let first_trade = trade_amounts.last().defensive_ok_or(Error::::InvalidState)?; - Ok(first_trade.amount_in.into()) + Ok(first_trade.amount_in) } - fn get_transaction_fee(order: &Order) -> Result { + pub fn get_transaction_fee(order: &Order) -> Result { Self::convert_weight_to_fee(Self::get_trade_weight(order), order.get_asset_in()) } @@ -1035,10 +1008,13 @@ where Ok(fee_amount_in_sold_asset) } + // returns DCA overhead weight + router execution weight fn get_trade_weight(order: &Order) -> Weight { match order { - Order::Sell { .. } => ::WeightInfo::on_initialize_with_sell_trade(), - Order::Buy { .. } => ::WeightInfo::on_initialize_with_buy_trade(), + Order::Sell { route, .. } => ::WeightInfo::on_initialize_with_sell_trade() + .saturating_add(T::AmmTradeWeights::sell_and_calculate_sell_trade_amounts_weight(route)), + Order::Buy { route, .. } => ::WeightInfo::on_initialize_with_buy_trade() + .saturating_add(T::AmmTradeWeights::buy_and_calculate_buy_trade_amounts_weight(route)), } } diff --git a/pallets/dca/src/tests/mock.rs b/pallets/dca/src/tests/mock.rs index 00a5b6231..2cec929fc 100644 --- a/pallets/dca/src/tests/mock.rs +++ b/pallets/dca/src/tests/mock.rs @@ -58,10 +58,10 @@ pub type BlockNumber = u64; pub type AssetId = u32; type NamedReserveIdentifier = [u8; 8]; -pub const BUY_DCA_FEE_IN_NATIVE: Balance = 3181488000; -pub const BUY_DCA_FEE_IN_DAI: Balance = 2799709440; -pub const SELL_DCA_FEE_IN_NATIVE: Balance = 3175101000; -pub const SELL_DCA_FEE_IN_DAI: Balance = 2794088880; +pub const BUY_DCA_FEE_IN_NATIVE: Balance = 1330108000; +pub const BUY_DCA_FEE_IN_DAI: Balance = 1170495040; +pub const SELL_DCA_FEE_IN_NATIVE: Balance = 1329215000; +pub const SELL_DCA_FEE_IN_DAI: Balance = 1169709200; pub const HDX: AssetId = 0; pub const LRNA: AssetId = 1; @@ -361,7 +361,6 @@ impl pallet_route_executor::Config for Test { type MaxNumberOfTrades = MaxNumberOfTrades; type Currency = MultiInspectAdapter; type AMM = Pools; - type AmmTradeWeights = (); type WeightInfo = (); } @@ -620,6 +619,7 @@ impl RandomnessProvider for RandomnessProviderMock { impl Config for Test { type RuntimeEvent = RuntimeEvent; + type AssetId = AssetId; type Currencies = Currencies; type RandomnessProvider = RandomnessProviderMock; type MinBudgetInNativeCurrency = MinBudgetInNativeCurrency; @@ -629,11 +629,13 @@ impl Config for Test { type WeightToFee = IdentityFee; type WeightInfo = (); type OraclePriceProvider = PriceProviderMock; + type Router = RouteExecutor; type MaxPriceDifferenceBetweenBlocks = OmnipoolMaxAllowedPriceDifference; type NamedReserveId = NamedReserveId; type MaxNumberOfRetriesOnError = MaxNumberOfRetriesOnError; type TechnicalOrigin = EnsureRoot; type RelayChainBlockHashProvider = ParentHashGetterMock; + type AmmTradeWeights = (); type MinimumTradingLimit = MinTradeAmount; type NativePriceOracle = NativePriceOracleMock; } diff --git a/pallets/dca/src/tests/on_initialize.rs b/pallets/dca/src/tests/on_initialize.rs index c8a9f0316..4b66adef2 100644 --- a/pallets/dca/src/tests/on_initialize.rs +++ b/pallets/dca/src/tests/on_initialize.rs @@ -34,7 +34,7 @@ use std::borrow::Borrow; use std::ops::RangeInclusive; #[test] -fn successfull_sell_dca_execution_should_emit_trade_executed_event() { +fn successful_sell_dca_execution_should_emit_trade_executed_event() { ExtBuilder::default() .with_endowed_accounts(vec![(ALICE, HDX, 10000 * ONE)]) .build() @@ -87,7 +87,7 @@ fn successfull_sell_dca_execution_should_emit_trade_executed_event() { } #[test] -fn successfull_buy_dca_execution_should_emit_trade_executed_event() { +fn successful_buy_dca_execution_should_emit_trade_executed_event() { ExtBuilder::default() .with_endowed_accounts(vec![(ALICE, HDX, 10000 * ONE)]) .build() @@ -481,7 +481,7 @@ fn full_sell_dca_should_be_completed_with_selling_leftover_in_last_trade() { } #[test] -fn full_sell_dca_should_be_completed_when_some_successfull_dca_execution_happened_but_less_than_fee_left() { +fn full_sell_dca_should_be_completed_when_some_successful_dca_execution_happened_but_less_than_fee_left() { ExtBuilder::default() .with_endowed_accounts(vec![(ALICE, HDX, 10000 * ONE)]) .build() @@ -526,7 +526,7 @@ fn full_sell_dca_should_be_completed_when_some_successfull_dca_execution_happene } #[test] -fn full_buy_dca_should_be_completed_when_some_successfull_dca_execution_happened_but_less_than_fee_left() { +fn full_buy_dca_should_be_completed_when_some_successful_dca_execution_happened_but_less_than_fee_left() { ExtBuilder::default() .with_endowed_accounts(vec![(ALICE, HDX, 10000 * ONE)]) .build() @@ -743,7 +743,7 @@ fn full_sell_dca_should_be_completed_when_exact_total_amount_specified_for_the_t } #[test] -fn full_buy_dca_should_be_completed_when_some_execution_is_successfull_but_not_enough_balance() { +fn full_buy_dca_should_be_completed_when_some_execution_is_successful_but_not_enough_balance() { let alice_init_hdx_balance = 10000 * ONE; ExtBuilder::default() .with_endowed_accounts(vec![(ALICE, HDX, alice_init_hdx_balance)]) @@ -782,7 +782,7 @@ fn full_buy_dca_should_be_completed_when_some_execution_is_successfull_but_not_e //Assert assert_number_of_executed_buy_trades!(4); assert_eq!(0, Currencies::reserved_balance(HDX, &ALICE)); - let left_over_which_is_not_enough_for_last_trade = 9987274048000; + let left_over_which_is_not_enough_for_last_trade = 9994679568000; assert_balance!( ALICE, HDX, @@ -1346,7 +1346,7 @@ fn sell_dca_schedule_continue_on_slippage_error() { } #[test] -fn dca_schedule_retry_should_be_reset_when_successfull_trade_after_failed_ones() { +fn dca_schedule_retry_should_be_reset_when_successful_trade_after_failed_ones() { ExtBuilder::default() .with_endowed_accounts(vec![(ALICE, HDX, 5000 * ONE)]) .with_max_price_difference(Permill::from_percent(9)) @@ -2437,7 +2437,7 @@ fn dca_should_continue_when_remainder_is_equal_to_min_trading_limit() { } #[test] -fn execution_is_still_successfull_when_no_parent_hash_present() { +fn execution_is_still_successful_when_no_parent_hash_present() { ExtBuilder::default() .with_endowed_accounts(vec![(ALICE, HDX, 10000 * ONE)]) .build() diff --git a/pallets/dca/src/tests/schedule.rs b/pallets/dca/src/tests/schedule.rs index aa1fb18ac..9f1a84c63 100644 --- a/pallets/dca/src/tests/schedule.rs +++ b/pallets/dca/src/tests/schedule.rs @@ -749,7 +749,7 @@ fn sell_schedule_should_work_when_total_amount_is_equal_to_amount_in_plus_fee() .execute_with(|| { //Arrange let amount_in = ONE; - let total_amount = amount_in + BUY_DCA_FEE_IN_NATIVE; + let total_amount = amount_in + SELL_DCA_FEE_IN_NATIVE; let schedule = ScheduleBuilder::new() .with_total_amount(total_amount) .with_order(Order::Sell { diff --git a/pallets/dca/src/types.rs b/pallets/dca/src/types.rs index 262d98c15..2968d8903 100644 --- a/pallets/dca/src/types.rs +++ b/pallets/dca/src/types.rs @@ -71,12 +71,14 @@ where *asset_out } - pub fn get_route_length(&self) -> usize { - let route = match &self { + pub fn get_route(&self) -> &BoundedVec, ConstU32<5>> { + match &self { Order::Sell { route, .. } => route, Order::Buy { route, .. } => route, - }; + } + } - route.len() + pub fn get_route_length(&self) -> usize { + self.get_route().len() } } diff --git a/pallets/dca/src/weights.rs b/pallets/dca/src/weights.rs index a2e947a21..4e47c3c52 100644 --- a/pallets/dca/src/weights.rs +++ b/pallets/dca/src/weights.rs @@ -18,25 +18,23 @@ //! Autogenerated weights for pallet_dca //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-06-16, STEPS: 5, REPEAT: 50, LOW RANGE: [], HIGH RANGE: [] -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("local"), DB CACHE: 1024 +//! DATE: 2023-10-06, STEPS: 10, REPEAT: 30, 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-dca -// --chain=local -// --steps=5 -// --repeat=50 -// --extrinsic=* +// --chain=dev +// --steps=10 +// --repeat=30 // --execution=wasm // --wasm-execution=compiled // --heap-pages=4096 -// --output -// weights-pallet.rs -// --template -// .maintain/pallet-weight-template.hbs +// --template=.maintain/pallet-weight-template-no-back.hbs +// --pallet=pallet-dca +// --output=dca.rs +// --extrinsic=* #![allow(unused_parens)] #![allow(unused_imports)] @@ -69,35 +67,15 @@ impl WeightInfo for HydraWeight { // Proof: DCA RemainingAmounts (max_values: None, max_size: Some(36), added: 2511, 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:3 w:3) + // Storage: System Account (r:2 w:2) // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - // Storage: Omnipool Assets (r:2 w:2) - // Proof: Omnipool Assets (max_values: None, max_size: Some(85), added: 2560, mode: MaxEncodedLen) - // Storage: Tokens Accounts (r:3 w:3) - // Proof: Tokens Accounts (max_values: None, max_size: Some(108), added: 2583, mode: MaxEncodedLen) - // Storage: EmaOracle Oracles (r:4 w:0) - // 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: AssetRegistry Assets (r:2 w:0) - // Proof Skipped: AssetRegistry Assets (max_values: None, max_size: None, mode: Measured) - // 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: 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(2961), added: 3456, mode: MaxEncodedLen) - // Storage: CircuitBreaker AllowedTradeVolumeLimitPerAsset (r:2 w:2) - // Proof: CircuitBreaker AllowedTradeVolumeLimitPerAsset (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen) // Storage: DCA RetriesOnError (r:0 w:1) // Proof: DCA RetriesOnError (max_values: None, max_size: Some(21), added: 2496, mode: MaxEncodedLen) fn on_initialize_with_buy_trade() -> Weight { - // Minimum execution time: 474_453 nanoseconds. - Weight::from_ref_time(481_488_000 as u64) - .saturating_add(T::DbWeight::get().reads(36 as u64)) - .saturating_add(T::DbWeight::get().writes(18 as u64)) + // Minimum execution time: 202_152 nanoseconds. + Weight::from_ref_time(205_108_000 as u64) + .saturating_add(T::DbWeight::get().reads(17 as u64)) + .saturating_add(T::DbWeight::get().writes(7 as u64)) } // Storage: DCA ScheduleIdsPerBlock (r:12 w:2) // Proof: DCA ScheduleIdsPerBlock (max_values: None, max_size: Some(101), added: 2576, mode: MaxEncodedLen) @@ -107,54 +85,28 @@ impl WeightInfo for HydraWeight { // Proof: DCA RemainingAmounts (max_values: None, max_size: Some(36), added: 2511, 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:3 w:3) + // Storage: System Account (r:2 w:2) // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - // Storage: Omnipool Assets (r:2 w:2) - // Proof: Omnipool Assets (max_values: None, max_size: Some(85), added: 2560, mode: MaxEncodedLen) - // Storage: Tokens Accounts (r:3 w:3) - // Proof: Tokens Accounts (max_values: None, max_size: Some(108), added: 2583, mode: MaxEncodedLen) - // Storage: EmaOracle Oracles (r:4 w:0) - // 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: AssetRegistry Assets (r:2 w:0) - // Proof Skipped: AssetRegistry Assets (max_values: None, max_size: None, mode: Measured) - // 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: 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(2961), added: 3456, mode: MaxEncodedLen) - // Storage: CircuitBreaker AllowedTradeVolumeLimitPerAsset (r:2 w:2) - // Proof: CircuitBreaker AllowedTradeVolumeLimitPerAsset (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen) // Storage: DCA RetriesOnError (r:0 w:1) // Proof: DCA RetriesOnError (max_values: None, max_size: Some(21), added: 2496, mode: MaxEncodedLen) fn on_initialize_with_sell_trade() -> Weight { - // Minimum execution time: 468_628 nanoseconds. - Weight::from_ref_time(475_101_000 as u64) - .saturating_add(T::DbWeight::get().reads(36 as u64)) - .saturating_add(T::DbWeight::get().writes(18 as u64)) + // Minimum execution time: 200_514 nanoseconds. + Weight::from_ref_time(204_215_000 as u64) + .saturating_add(T::DbWeight::get().reads(17 as u64)) + .saturating_add(T::DbWeight::get().writes(7 as u64)) } // Storage: DCA ScheduleIdsPerBlock (r:1 w:0) // Proof: DCA ScheduleIdsPerBlock (max_values: None, max_size: Some(101), added: 2576, mode: MaxEncodedLen) fn on_initialize_with_empty_block() -> Weight { - // Minimum execution time: 13_422 nanoseconds. - Weight::from_ref_time(13_685_000 as u64).saturating_add(T::DbWeight::get().reads(1 as u64)) + // Minimum execution time: 18_232 nanoseconds. + Weight::from_ref_time(18_655_000 as u64).saturating_add(T::DbWeight::get().reads(1 as u64)) } - // Storage: Omnipool Assets (r:2 w:0) - // Proof: Omnipool Assets (max_values: None, max_size: Some(85), added: 2560, mode: MaxEncodedLen) - // Storage: Tokens Accounts (r:1 w:0) - // Proof: Tokens Accounts (max_values: None, max_size: Some(108), added: 2583, mode: MaxEncodedLen) - // Storage: Omnipool HubAssetImbalance (r:1 w:0) - // Proof: Omnipool HubAssetImbalance (max_values: Some(1), max_size: Some(17), added: 512, mode: MaxEncodedLen) - // Storage: System Account (r:2 w:1) - // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) // Storage: DCA ScheduleIdSequencer (r:1 w:1) // Proof: DCA ScheduleIdSequencer (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: 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) @@ -166,9 +118,9 @@ impl WeightInfo for HydraWeight { // Storage: DCA RemainingAmounts (r:0 w:1) // Proof: DCA RemainingAmounts (max_values: None, max_size: Some(36), added: 2511, mode: MaxEncodedLen) fn schedule() -> Weight { - // Minimum execution time: 144_478 nanoseconds. - Weight::from_ref_time(147_560_000 as u64) - .saturating_add(T::DbWeight::get().reads(19 as u64)) + // Minimum execution time: 133_110 nanoseconds. + Weight::from_ref_time(134_484_000 as u64) + .saturating_add(T::DbWeight::get().reads(14 as u64)) .saturating_add(T::DbWeight::get().writes(8 as u64)) } // Storage: DCA Schedules (r:1 w:1) @@ -186,8 +138,8 @@ impl WeightInfo for HydraWeight { // Storage: DCA ScheduleOwnership (r:0 w:1) // Proof: DCA ScheduleOwnership (max_values: None, max_size: Some(60), added: 2535, mode: MaxEncodedLen) fn terminate() -> Weight { - // Minimum execution time: 59_201 nanoseconds. - Weight::from_ref_time(59_909_000 as u64) + // Minimum execution time: 74_610 nanoseconds. + Weight::from_ref_time(75_402_000 as u64) .saturating_add(T::DbWeight::get().reads(5 as u64)) .saturating_add(T::DbWeight::get().writes(7 as u64)) } @@ -203,35 +155,15 @@ impl WeightInfo for () { // Proof: DCA RemainingAmounts (max_values: None, max_size: Some(36), added: 2511, 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:3 w:3) + // Storage: System Account (r:2 w:2) // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - // Storage: Omnipool Assets (r:2 w:2) - // Proof: Omnipool Assets (max_values: None, max_size: Some(85), added: 2560, mode: MaxEncodedLen) - // Storage: Tokens Accounts (r:3 w:3) - // Proof: Tokens Accounts (max_values: None, max_size: Some(108), added: 2583, mode: MaxEncodedLen) - // Storage: EmaOracle Oracles (r:4 w:0) - // 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: AssetRegistry Assets (r:2 w:0) - // Proof Skipped: AssetRegistry Assets (max_values: None, max_size: None, mode: Measured) - // 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: 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(2961), added: 3456, mode: MaxEncodedLen) - // Storage: CircuitBreaker AllowedTradeVolumeLimitPerAsset (r:2 w:2) - // Proof: CircuitBreaker AllowedTradeVolumeLimitPerAsset (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen) // Storage: DCA RetriesOnError (r:0 w:1) // Proof: DCA RetriesOnError (max_values: None, max_size: Some(21), added: 2496, mode: MaxEncodedLen) fn on_initialize_with_buy_trade() -> Weight { - // Minimum execution time: 474_453 nanoseconds. - Weight::from_ref_time(481_488_000) - .saturating_add(RocksDbWeight::get().reads(36)) - .saturating_add(RocksDbWeight::get().writes(18)) + // Minimum execution time: 202_152 nanoseconds. + Weight::from_ref_time(205_108_000 as u64) + .saturating_add(RocksDbWeight::get().reads(17 as u64)) + .saturating_add(RocksDbWeight::get().writes(7 as u64)) } // Storage: DCA ScheduleIdsPerBlock (r:12 w:2) // Proof: DCA ScheduleIdsPerBlock (max_values: None, max_size: Some(101), added: 2576, mode: MaxEncodedLen) @@ -241,54 +173,28 @@ impl WeightInfo for () { // Proof: DCA RemainingAmounts (max_values: None, max_size: Some(36), added: 2511, 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:3 w:3) + // Storage: System Account (r:2 w:2) // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - // Storage: Omnipool Assets (r:2 w:2) - // Proof: Omnipool Assets (max_values: None, max_size: Some(85), added: 2560, mode: MaxEncodedLen) - // Storage: Tokens Accounts (r:3 w:3) - // Proof: Tokens Accounts (max_values: None, max_size: Some(108), added: 2583, mode: MaxEncodedLen) - // Storage: EmaOracle Oracles (r:4 w:0) - // 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: AssetRegistry Assets (r:2 w:0) - // Proof Skipped: AssetRegistry Assets (max_values: None, max_size: None, mode: Measured) - // 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: 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(2961), added: 3456, mode: MaxEncodedLen) - // Storage: CircuitBreaker AllowedTradeVolumeLimitPerAsset (r:2 w:2) - // Proof: CircuitBreaker AllowedTradeVolumeLimitPerAsset (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen) // Storage: DCA RetriesOnError (r:0 w:1) // Proof: DCA RetriesOnError (max_values: None, max_size: Some(21), added: 2496, mode: MaxEncodedLen) fn on_initialize_with_sell_trade() -> Weight { - // Minimum execution time: 468_628 nanoseconds. - Weight::from_ref_time(475_101_000) - .saturating_add(RocksDbWeight::get().reads(36)) - .saturating_add(RocksDbWeight::get().writes(18)) + // Minimum execution time: 200_514 nanoseconds. + Weight::from_ref_time(204_215_000 as u64) + .saturating_add(RocksDbWeight::get().reads(17 as u64)) + .saturating_add(RocksDbWeight::get().writes(7 as u64)) } // Storage: DCA ScheduleIdsPerBlock (r:1 w:0) // Proof: DCA ScheduleIdsPerBlock (max_values: None, max_size: Some(101), added: 2576, mode: MaxEncodedLen) fn on_initialize_with_empty_block() -> Weight { - // Minimum execution time: 13_422 nanoseconds. - Weight::from_ref_time(13_685_000).saturating_add(RocksDbWeight::get().reads(1)) + // Minimum execution time: 18_232 nanoseconds. + Weight::from_ref_time(18_655_000 as u64).saturating_add(RocksDbWeight::get().reads(1 as u64)) } - // Storage: Omnipool Assets (r:2 w:0) - // Proof: Omnipool Assets (max_values: None, max_size: Some(85), added: 2560, mode: MaxEncodedLen) - // Storage: Tokens Accounts (r:1 w:0) - // Proof: Tokens Accounts (max_values: None, max_size: Some(108), added: 2583, mode: MaxEncodedLen) - // Storage: Omnipool HubAssetImbalance (r:1 w:0) - // Proof: Omnipool HubAssetImbalance (max_values: Some(1), max_size: Some(17), added: 512, mode: MaxEncodedLen) - // Storage: System Account (r:2 w:1) - // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) // Storage: DCA ScheduleIdSequencer (r:1 w:1) // Proof: DCA ScheduleIdSequencer (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: 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) @@ -300,10 +206,10 @@ impl WeightInfo for () { // Storage: DCA RemainingAmounts (r:0 w:1) // Proof: DCA RemainingAmounts (max_values: None, max_size: Some(36), added: 2511, mode: MaxEncodedLen) fn schedule() -> Weight { - // Minimum execution time: 144_478 nanoseconds. - Weight::from_ref_time(147_560_000) - .saturating_add(RocksDbWeight::get().reads(19)) - .saturating_add(RocksDbWeight::get().writes(8)) + // Minimum execution time: 133_110 nanoseconds. + Weight::from_ref_time(134_484_000 as u64) + .saturating_add(RocksDbWeight::get().reads(14 as u64)) + .saturating_add(RocksDbWeight::get().writes(8 as u64)) } // Storage: DCA Schedules (r:1 w:1) // Proof: DCA Schedules (max_values: None, max_size: Some(191), added: 2666, mode: MaxEncodedLen) @@ -320,9 +226,9 @@ impl WeightInfo for () { // Storage: DCA ScheduleOwnership (r:0 w:1) // Proof: DCA ScheduleOwnership (max_values: None, max_size: Some(60), added: 2535, mode: MaxEncodedLen) fn terminate() -> Weight { - // Minimum execution time: 59_201 nanoseconds. - Weight::from_ref_time(59_909_000) - .saturating_add(RocksDbWeight::get().reads(5)) - .saturating_add(RocksDbWeight::get().writes(7)) + // Minimum execution time: 74_610 nanoseconds. + Weight::from_ref_time(75_402_000 as u64) + .saturating_add(RocksDbWeight::get().reads(5 as u64)) + .saturating_add(RocksDbWeight::get().writes(7 as u64)) } } diff --git a/pallets/democracy/Cargo.toml b/pallets/democracy/Cargo.toml index e58869a65..a2e5fc544 100644 --- a/pallets/democracy/Cargo.toml +++ b/pallets/democracy/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-democracy" -version = "4.0.0-dev" +version = "4.0.1-dev" authors = ["Parity Technologies "] edition = "2021" license = "Apache-2.0" diff --git a/pallets/democracy/src/lib.rs b/pallets/democracy/src/lib.rs index f33ec5478..66fbbf4c0 100644 --- a/pallets/democracy/src/lib.rs +++ b/pallets/democracy/src/lib.rs @@ -169,6 +169,7 @@ use sp_runtime::{ ArithmeticError, DispatchError, DispatchResult, }; use sp_std::prelude::*; +use sp_std::vec; mod conviction; pub mod traits; diff --git a/pallets/ema-oracle/Cargo.toml b/pallets/ema-oracle/Cargo.toml index 2a5aad20b..e713d37c7 100644 --- a/pallets/ema-oracle/Cargo.toml +++ b/pallets/ema-oracle/Cargo.toml @@ -1,6 +1,6 @@ [package] name = 'pallet-ema-oracle' -version = '1.1.1' +version = '1.1.2' description = 'Exponential moving average oracle for AMM pools' authors = ['GalacticCouncil'] edition = '2021' diff --git a/pallets/ema-oracle/src/weights.rs b/pallets/ema-oracle/src/weights.rs index 33bb69b4c..bf68cbc0f 100644 --- a/pallets/ema-oracle/src/weights.rs +++ b/pallets/ema-oracle/src/weights.rs @@ -1,6 +1,6 @@ -// This file is part of pallet-ema-oracle. +// This file is part of HydraDX. -// Copyright (C) 2022-2023 Intergalactic, Limited (GIB). +// Copyright (C) 2020-2023 Intergalactic, Limited (GIB). // SPDX-License-Identifier: Apache-2.0 // Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,23 +18,24 @@ //! Autogenerated weights for pallet_ema_oracle //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-02-23, STEPS: 5, REPEAT: 20, LOW RANGE: [], HIGH RANGE: [] +//! DATE: 2023-10-06, STEPS: 10, REPEAT: 30, LOW RANGE: [], HIGH RANGE: [] //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 // Executed Command: -// target/release/basilisk +// target/release/hydradx // benchmark // pallet // --chain=dev -// --steps=5 -// --repeat=20 +// --steps=10 +// --repeat=30 // --execution=wasm // --wasm-execution=compiled // --heap-pages=4096 // --template=.maintain/pallet-weight-template-no-back.hbs -// --pallet=pallet_ema_oracle -// --output=oracle.rs +// --pallet=pallet-ema-oracle +// --output=ema-oracle.rs // --extrinsic=* + #![allow(unused_parens)] #![allow(unused_imports)] #![allow(clippy::unnecessary_cast)] @@ -57,60 +58,100 @@ pub trait WeightInfo { pub struct BasiliskWeight(PhantomData); impl WeightInfo for BasiliskWeight { + // Storage: EmaOracle Accumulator (r:1 w:0) + // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(5921), added: 6416, mode: MaxEncodedLen) fn on_finalize_no_entry() -> Weight { - Weight::from_ref_time(4_150_000 as u64).saturating_add(T::DbWeight::get().reads(1 as u64)) + // Minimum execution time: 3_226 nanoseconds. + Weight::from_ref_time(3_325_000 as u64).saturating_add(T::DbWeight::get().reads(1 as u64)) } + // 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 { - Weight::from_ref_time(12_487_000 as u64) // Standard Error: 24_000 - .saturating_add(Weight::from_ref_time(39_930_000 as u64).saturating_mul(b as u64)) + // Minimum execution time: 44_637 nanoseconds. + Weight::from_ref_time(9_798_669 as u64) // Standard Error: 47_796 + .saturating_add(Weight::from_ref_time(33_611_646 as u64).saturating_mul(b as u64)) .saturating_add(T::DbWeight::get().reads(1 as u64)) - .saturating_add(T::DbWeight::get().reads((4 as u64).saturating_mul(b as u64))) + .saturating_add(T::DbWeight::get().reads((3 as u64).saturating_mul(b as u64))) .saturating_add(T::DbWeight::get().writes(1 as u64)) - .saturating_add(T::DbWeight::get().writes((4 as u64).saturating_mul(b as u64))) + .saturating_add(T::DbWeight::get().writes((3 as u64).saturating_mul(b as u64))) } + // 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 { - Weight::from_ref_time(19_042_000 as u64) // Standard Error: 4_000 - .saturating_add(Weight::from_ref_time(507_000 as u64).saturating_mul(b as u64)) + // Minimum execution time: 10_368 nanoseconds. + Weight::from_ref_time(10_544_600 as u64) // Standard Error: 2_268 + .saturating_add(Weight::from_ref_time(432_909 as u64).saturating_mul(b as u64)) .saturating_add(T::DbWeight::get().reads(1 as u64)) .saturating_add(T::DbWeight::get().writes(1 as u64)) } + // 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 { - Weight::from_ref_time(19_385_000 as u64) // Standard Error: 4_000 - .saturating_add(Weight::from_ref_time(506_000 as u64).saturating_mul(b as u64)) + // Minimum execution time: 10_369 nanoseconds. + Weight::from_ref_time(10_608_047 as u64) // Standard Error: 2_062 + .saturating_add(Weight::from_ref_time(432_350 as u64).saturating_mul(b as u64)) .saturating_add(T::DbWeight::get().reads(1 as u64)) .saturating_add(T::DbWeight::get().writes(1 as u64)) } + // Storage: EmaOracle Oracles (r:2 w:0) + // Proof: EmaOracle Oracles (max_values: None, max_size: Some(177), added: 2652, mode: MaxEncodedLen) fn get_entry() -> Weight { - Weight::from_ref_time(23_575_000 as u64).saturating_add(T::DbWeight::get().reads(2 as u64)) + // Minimum execution time: 17_936 nanoseconds. + Weight::from_ref_time(18_521_000 as u64).saturating_add(T::DbWeight::get().reads(2 as u64)) } } // For backwards compatibility and tests impl WeightInfo for () { + // Storage: EmaOracle Accumulator (r:1 w:0) + // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(5921), added: 6416, mode: MaxEncodedLen) fn on_finalize_no_entry() -> Weight { - Weight::from_ref_time(4_150_000 as u64).saturating_add(RocksDbWeight::get().reads(1 as u64)) + // Minimum execution time: 3_226 nanoseconds. + Weight::from_ref_time(3_325_000 as u64).saturating_add(RocksDbWeight::get().reads(1 as u64)) } + // 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 { - Weight::from_ref_time(12_487_000 as u64) // Standard Error: 24_000 - .saturating_add(Weight::from_ref_time(39_930_000 as u64).saturating_mul(b as u64)) + // Minimum execution time: 44_637 nanoseconds. + Weight::from_ref_time(9_798_669 as u64) // Standard Error: 47_796 + .saturating_add(Weight::from_ref_time(33_611_646 as u64).saturating_mul(b as u64)) .saturating_add(RocksDbWeight::get().reads(1 as u64)) - .saturating_add(RocksDbWeight::get().reads((4 as u64).saturating_mul(b as u64))) + .saturating_add(RocksDbWeight::get().reads((3 as u64).saturating_mul(b as u64))) .saturating_add(RocksDbWeight::get().writes(1 as u64)) - .saturating_add(RocksDbWeight::get().writes((4 as u64).saturating_mul(b as u64))) + .saturating_add(RocksDbWeight::get().writes((3 as u64).saturating_mul(b as u64))) } + // 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 { - Weight::from_ref_time(19_042_000 as u64) // Standard Error: 4_000 - .saturating_add(Weight::from_ref_time(507_000 as u64).saturating_mul(b as u64)) + // Minimum execution time: 10_368 nanoseconds. + Weight::from_ref_time(10_544_600 as u64) // Standard Error: 2_268 + .saturating_add(Weight::from_ref_time(432_909 as u64).saturating_mul(b as u64)) .saturating_add(RocksDbWeight::get().reads(1 as u64)) .saturating_add(RocksDbWeight::get().writes(1 as u64)) } + // 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 { - Weight::from_ref_time(19_385_000 as u64) // Standard Error: 4_000 - .saturating_add(Weight::from_ref_time(506_000 as u64).saturating_mul(b as u64)) + // Minimum execution time: 10_369 nanoseconds. + Weight::from_ref_time(10_608_047 as u64) // Standard Error: 2_062 + .saturating_add(Weight::from_ref_time(432_350 as u64).saturating_mul(b as u64)) .saturating_add(RocksDbWeight::get().reads(1 as u64)) .saturating_add(RocksDbWeight::get().writes(1 as u64)) } + // Storage: EmaOracle Oracles (r:2 w:0) + // Proof: EmaOracle Oracles (max_values: None, max_size: Some(177), added: 2652, mode: MaxEncodedLen) fn get_entry() -> Weight { - Weight::from_ref_time(23_575_000 as u64).saturating_add(RocksDbWeight::get().reads(2 as u64)) + // Minimum execution time: 17_936 nanoseconds. + Weight::from_ref_time(18_521_000 as u64).saturating_add(RocksDbWeight::get().reads(2 as u64)) } } diff --git a/pallets/lbp/Cargo.toml b/pallets/lbp/Cargo.toml index f6ac69e0a..72c7b5861 100644 --- a/pallets/lbp/Cargo.toml +++ b/pallets/lbp/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-lbp" -version = "4.6.15" +version = "4.6.16" description = "HydraDX Liquidity Bootstrapping Pool Pallet" authors = ["GalacticCouncil"] edition = "2021" diff --git a/pallets/lbp/src/benchmarking.rs b/pallets/lbp/src/benchmarking.rs index c568f6b2d..e9bba5295 100644 --- a/pallets/lbp/src/benchmarking.rs +++ b/pallets/lbp/src/benchmarking.rs @@ -156,6 +156,9 @@ benchmarks! { } 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 caller = funded_account::("caller", 0); let fee_collector = funded_account::("fee_collector", 0); let asset_in: AssetId = ASSET_A_ID; @@ -176,15 +179,24 @@ benchmarks! { frame_system::Pallet::::set_block_number(T::BlockNumber::from(2u32)); }: { - assert!( as TradeExecution>::calculate_sell(PoolType::LBP, asset_in, asset_out, amount).is_ok()); - assert!( as TradeExecution>::execute_sell(RawOrigin::Signed(caller.clone()).into(), PoolType::LBP, asset_in, asset_out, amount, max_limit).is_ok()); + for _ in 1..c { + assert!( as TradeExecution>::calculate_sell(PoolType::LBP, asset_in, asset_out, amount).is_ok()); + } + if e != 0 { + assert!( as TradeExecution>::execute_sell(RawOrigin::Signed(caller.clone()).into(), PoolType::LBP, asset_in, asset_out, amount, max_limit).is_ok()); + } } verify{ - assert_eq!(T::MultiCurrency::free_balance(asset_in, &caller), 999998900000000); - assert_eq!(T::MultiCurrency::free_balance(asset_out, &caller), 999998069275212); + if e != 0 { + assert_eq!(T::MultiCurrency::free_balance(asset_in, &caller), 999998900000000); + assert_eq!(T::MultiCurrency::free_balance(asset_out, &caller), 999998069275212); + } } 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 caller = funded_account::("caller", 0); let fee_collector = funded_account::("fee_collector", 0); let asset_in: AssetId = ASSET_A_ID; @@ -205,12 +217,18 @@ benchmarks! { frame_system::Pallet::::set_block_number(T::BlockNumber::from(2u32)); }: { - assert!( as TradeExecution>::calculate_buy(PoolType::LBP, asset_in, asset_out, amount).is_ok()); - assert!( as TradeExecution>::execute_buy(RawOrigin::Signed(caller.clone()).into(), PoolType::LBP, asset_in, asset_out, amount, max_limit).is_ok()); + for _ in 1..c { + assert!( as TradeExecution>::calculate_buy(PoolType::LBP, asset_in, asset_out, amount).is_ok()); + } + if e != 0 { + assert!( as TradeExecution>::execute_buy(RawOrigin::Signed(caller.clone()).into(), PoolType::LBP, asset_in, asset_out, amount, max_limit).is_ok()); + } } verify{ - assert_eq!(T::MultiCurrency::free_balance(asset_out, &caller), 999998100000000); - assert_eq!(T::MultiCurrency::free_balance(asset_in, &caller), 999998851241411); + if e != 0 { + assert_eq!(T::MultiCurrency::free_balance(asset_out, &caller), 999998100000000); + assert_eq!(T::MultiCurrency::free_balance(asset_in, &caller), 999998851241411); + } } } diff --git a/pallets/lbp/src/weights.rs b/pallets/lbp/src/weights.rs index 575a9734b..1c326bcfc 100644 --- a/pallets/lbp/src/weights.rs +++ b/pallets/lbp/src/weights.rs @@ -18,7 +18,7 @@ //! Autogenerated weights for pallet_lbp //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-09-11, STEPS: 10, REPEAT: 30, LOW RANGE: [], HIGH RANGE: [] +//! DATE: 2023-10-06, STEPS: 10, REPEAT: 30, LOW RANGE: [], HIGH RANGE: [] //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 // Executed Command: @@ -31,10 +31,10 @@ // --execution=wasm // --wasm-execution=compiled // --heap-pages=4096 -// --template=.maintain/pallet-weight-template.hbs +// --template=.maintain/pallet-weight-template-no-back.hbs // --pallet=pallet-lbp -// --extrinsic=* // --output=lbp.rs +// --extrinsic=* #![allow(unused_parens)] #![allow(unused_imports)] @@ -54,8 +54,8 @@ pub trait WeightInfo { fn remove_liquidity() -> Weight; fn sell() -> Weight; fn buy() -> Weight; - fn router_execution_sell() -> Weight; - fn router_execution_buy() -> Weight; + fn router_execution_sell(c: u32, e: u32) -> Weight; + fn router_execution_buy(c: u32, e: u32) -> Weight; } /// Weights for pallet_lbp using the hydraDX node and recommended hardware. @@ -77,8 +77,8 @@ impl WeightInfo for HydraWeight { // Storage: MultiTransactionPayment AcceptedCurrencies (r:1 w:0) // Proof: MultiTransactionPayment AcceptedCurrencies (max_values: None, max_size: Some(28), added: 2503, mode: MaxEncodedLen) fn create_pool() -> Weight { - // Minimum execution time: 151_763 nanoseconds. - Weight::from_ref_time(153_465_000 as u64) + // Minimum execution time: 141_654 nanoseconds. + Weight::from_ref_time(143_331_000 as u64) .saturating_add(T::DbWeight::get().reads(12 as u64)) .saturating_add(T::DbWeight::get().writes(8 as u64)) } @@ -87,8 +87,8 @@ impl WeightInfo for HydraWeight { // Storage: LBP FeeCollectorWithAsset (r:1 w:2) // Proof: LBP FeeCollectorWithAsset (max_values: None, max_size: Some(69), added: 2544, mode: MaxEncodedLen) fn update_pool_data() -> Weight { - // Minimum execution time: 31_781 nanoseconds. - Weight::from_ref_time(32_284_000 as u64) + // Minimum execution time: 30_269 nanoseconds. + Weight::from_ref_time(30_677_000 as u64) .saturating_add(T::DbWeight::get().reads(2 as u64)) .saturating_add(T::DbWeight::get().writes(3 as u64)) } @@ -101,8 +101,8 @@ 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) fn add_liquidity() -> Weight { - // Minimum execution time: 106_414 nanoseconds. - Weight::from_ref_time(107_630_000 as u64) + // Minimum execution time: 98_867 nanoseconds. + Weight::from_ref_time(100_102_000 as u64) .saturating_add(T::DbWeight::get().reads(8 as u64)) .saturating_add(T::DbWeight::get().writes(4 as u64)) } @@ -121,8 +121,8 @@ impl WeightInfo for HydraWeight { // Storage: LBP FeeCollectorWithAsset (r:0 w:1) // Proof: LBP FeeCollectorWithAsset (max_values: None, max_size: Some(69), added: 2544, mode: MaxEncodedLen) fn remove_liquidity() -> Weight { - // Minimum execution time: 136_405 nanoseconds. - Weight::from_ref_time(138_124_000 as u64) + // Minimum execution time: 125_051 nanoseconds. + Weight::from_ref_time(126_556_000 as u64) .saturating_add(T::DbWeight::get().reads(10 as u64)) .saturating_add(T::DbWeight::get().writes(8 as u64)) } @@ -137,8 +137,8 @@ impl WeightInfo for HydraWeight { // Storage: System Account (r:3 w:1) // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) fn sell() -> Weight { - // Minimum execution time: 199_893 nanoseconds. - Weight::from_ref_time(201_395_000 as u64) + // Minimum execution time: 217_207 nanoseconds. + Weight::from_ref_time(218_401_000 as u64) .saturating_add(T::DbWeight::get().reads(12 as u64)) .saturating_add(T::DbWeight::get().writes(7 as u64)) } @@ -153,8 +153,8 @@ impl WeightInfo for HydraWeight { // Storage: System Account (r:3 w:1) // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) fn buy() -> Weight { - // Minimum execution time: 199_112 nanoseconds. - Weight::from_ref_time(200_863_000 as u64) + // Minimum execution time: 211_853 nanoseconds. + Weight::from_ref_time(213_114_000 as u64) .saturating_add(T::DbWeight::get().reads(12 as u64)) .saturating_add(T::DbWeight::get().writes(7 as u64)) } @@ -168,11 +168,17 @@ impl WeightInfo for HydraWeight { // Proof: AssetRegistry Assets (max_values: None, max_size: Some(87), added: 2562, mode: MaxEncodedLen) // Storage: System Account (r:3 w:1) // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - fn router_execution_sell() -> Weight { - // Minimum execution time: 223_028 nanoseconds. - Weight::from_ref_time(225_062_000 as u64) - .saturating_add(T::DbWeight::get().reads(12 as u64)) - .saturating_add(T::DbWeight::get().writes(7 as u64)) + /// 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 { + // Minimum execution time: 66_725 nanoseconds. + Weight::from_ref_time(67_159_000 as u64) // Standard Error: 592_525 + .saturating_add(Weight::from_ref_time(2_278_417 as u64).saturating_mul(c as u64)) + // Standard Error: 1_300_761 + .saturating_add(Weight::from_ref_time(151_794_260 as u64).saturating_mul(e as u64)) + .saturating_add(T::DbWeight::get().reads(3 as u64)) + .saturating_add(T::DbWeight::get().reads((9 as u64).saturating_mul(e as u64))) + .saturating_add(T::DbWeight::get().writes((7 as u64).saturating_mul(e as u64))) } // Storage: LBP PoolData (r:1 w:0) // Proof: LBP PoolData (max_values: None, max_size: Some(163), added: 2638, mode: MaxEncodedLen) @@ -184,11 +190,17 @@ impl WeightInfo for HydraWeight { // Proof: AssetRegistry Assets (max_values: None, max_size: Some(87), added: 2562, mode: MaxEncodedLen) // Storage: System Account (r:3 w:1) // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - fn router_execution_buy() -> Weight { - // Minimum execution time: 223_313 nanoseconds. - Weight::from_ref_time(224_794_000 as u64) - .saturating_add(T::DbWeight::get().reads(12 as u64)) - .saturating_add(T::DbWeight::get().writes(7 as u64)) + /// 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 { + // Minimum execution time: 118_181 nanoseconds. + Weight::from_ref_time(118_740_000 as u64) // Standard Error: 769_691 + .saturating_add(Weight::from_ref_time(3_767_843 as u64).saturating_mul(c as u64)) + // Standard Error: 2_541_567 + .saturating_add(Weight::from_ref_time(124_213_432 as u64).saturating_mul(e as u64)) + .saturating_add(T::DbWeight::get().reads(3 as u64)) + .saturating_add(T::DbWeight::get().reads((9 as u64).saturating_mul(e as u64))) + .saturating_add(T::DbWeight::get().writes((7 as u64).saturating_mul(e as u64))) } } @@ -209,20 +221,20 @@ impl WeightInfo for () { // Storage: MultiTransactionPayment AcceptedCurrencies (r:1 w:0) // Proof: MultiTransactionPayment AcceptedCurrencies (max_values: None, max_size: Some(28), added: 2503, mode: MaxEncodedLen) fn create_pool() -> Weight { - // Minimum execution time: 140_079 nanoseconds. - Weight::from_ref_time(141_129_000) - .saturating_add(RocksDbWeight::get().reads(12)) - .saturating_add(RocksDbWeight::get().writes(8)) + // Minimum execution time: 141_654 nanoseconds. + Weight::from_ref_time(143_331_000 as u64) + .saturating_add(RocksDbWeight::get().reads(12 as u64)) + .saturating_add(RocksDbWeight::get().writes(8 as u64)) } // Storage: LBP PoolData (r:1 w:1) // Proof: LBP PoolData (max_values: None, max_size: Some(163), added: 2638, mode: MaxEncodedLen) // Storage: LBP FeeCollectorWithAsset (r:1 w:2) // Proof: LBP FeeCollectorWithAsset (max_values: None, max_size: Some(69), added: 2544, mode: MaxEncodedLen) fn update_pool_data() -> Weight { - // Minimum execution time: 29_911 nanoseconds. - Weight::from_ref_time(30_391_000) - .saturating_add(RocksDbWeight::get().reads(2)) - .saturating_add(RocksDbWeight::get().writes(3)) + // Minimum execution time: 30_269 nanoseconds. + Weight::from_ref_time(30_677_000 as u64) + .saturating_add(RocksDbWeight::get().reads(2 as u64)) + .saturating_add(RocksDbWeight::get().writes(3 as u64)) } // Storage: LBP PoolData (r:1 w:0) // Proof: LBP PoolData (max_values: None, max_size: Some(163), added: 2638, mode: MaxEncodedLen) @@ -233,10 +245,10 @@ impl WeightInfo for () { // 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 { - // Minimum execution time: 97_880 nanoseconds. - Weight::from_ref_time(98_797_000) - .saturating_add(RocksDbWeight::get().reads(8)) - .saturating_add(RocksDbWeight::get().writes(4)) + // Minimum execution time: 98_867 nanoseconds. + Weight::from_ref_time(100_102_000 as u64) + .saturating_add(RocksDbWeight::get().reads(8 as u64)) + .saturating_add(RocksDbWeight::get().writes(4 as u64)) } // Storage: LBP PoolData (r:1 w:1) // Proof: LBP PoolData (max_values: None, max_size: Some(163), added: 2638, mode: MaxEncodedLen) @@ -253,10 +265,10 @@ impl WeightInfo for () { // Storage: LBP FeeCollectorWithAsset (r:0 w:1) // Proof: LBP FeeCollectorWithAsset (max_values: None, max_size: Some(69), added: 2544, mode: MaxEncodedLen) fn remove_liquidity() -> Weight { - // Minimum execution time: 129_458 nanoseconds. - Weight::from_ref_time(131_018_000) - .saturating_add(RocksDbWeight::get().reads(10)) - .saturating_add(RocksDbWeight::get().writes(8)) + // Minimum execution time: 125_051 nanoseconds. + Weight::from_ref_time(126_556_000 as u64) + .saturating_add(RocksDbWeight::get().reads(10 as u64)) + .saturating_add(RocksDbWeight::get().writes(8 as u64)) } // Storage: Tokens Accounts (r:5 w:5) // Proof: Tokens Accounts (max_values: None, max_size: Some(108), added: 2583, mode: MaxEncodedLen) @@ -269,10 +281,10 @@ impl WeightInfo for () { // Storage: System Account (r:3 w:1) // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) fn sell() -> Weight { - // Minimum execution time: 186_643 nanoseconds. - Weight::from_ref_time(187_855_000) - .saturating_add(RocksDbWeight::get().reads(12)) - .saturating_add(RocksDbWeight::get().writes(7)) + // Minimum execution time: 217_207 nanoseconds. + Weight::from_ref_time(218_401_000 as u64) + .saturating_add(RocksDbWeight::get().reads(12 as u64)) + .saturating_add(RocksDbWeight::get().writes(7 as u64)) } // Storage: LBP PoolData (r:1 w:0) // Proof: LBP PoolData (max_values: None, max_size: Some(163), added: 2638, mode: MaxEncodedLen) @@ -285,10 +297,10 @@ impl WeightInfo for () { // Storage: System Account (r:3 w:1) // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) fn buy() -> Weight { - // Minimum execution time: 186_142 nanoseconds. - Weight::from_ref_time(187_439_000) - .saturating_add(RocksDbWeight::get().reads(12)) - .saturating_add(RocksDbWeight::get().writes(7)) + // Minimum execution time: 211_853 nanoseconds. + Weight::from_ref_time(213_114_000 as u64) + .saturating_add(RocksDbWeight::get().reads(12 as u64)) + .saturating_add(RocksDbWeight::get().writes(7 as u64)) } // Storage: LBP PoolData (r:1 w:0) // Proof: LBP PoolData (max_values: None, max_size: Some(163), added: 2638, mode: MaxEncodedLen) @@ -300,11 +312,17 @@ impl WeightInfo for () { // Proof: AssetRegistry Assets (max_values: None, max_size: Some(87), added: 2562, mode: MaxEncodedLen) // Storage: System Account (r:3 w:1) // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - fn router_execution_sell() -> Weight { - // Minimum execution time: 209_538 nanoseconds. - Weight::from_ref_time(211_086_000) - .saturating_add(RocksDbWeight::get().reads(12)) - .saturating_add(RocksDbWeight::get().writes(7)) + /// 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 { + // Minimum execution time: 66_725 nanoseconds. + Weight::from_ref_time(67_159_000 as u64) // Standard Error: 592_525 + .saturating_add(Weight::from_ref_time(2_278_417 as u64).saturating_mul(c as u64)) + // Standard Error: 1_300_761 + .saturating_add(Weight::from_ref_time(151_794_260 as u64).saturating_mul(e as u64)) + .saturating_add(RocksDbWeight::get().reads(3 as u64)) + .saturating_add(RocksDbWeight::get().reads((9 as u64).saturating_mul(e as u64))) + .saturating_add(RocksDbWeight::get().writes((7 as u64).saturating_mul(e as u64))) } // Storage: LBP PoolData (r:1 w:0) // Proof: LBP PoolData (max_values: None, max_size: Some(163), added: 2638, mode: MaxEncodedLen) @@ -316,10 +334,16 @@ impl WeightInfo for () { // Proof: AssetRegistry Assets (max_values: None, max_size: Some(87), added: 2562, mode: MaxEncodedLen) // Storage: System Account (r:3 w:1) // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - fn router_execution_buy() -> Weight { - // Minimum execution time: 213_308 nanoseconds. - Weight::from_ref_time(214_861_000) - .saturating_add(RocksDbWeight::get().reads(12)) - .saturating_add(RocksDbWeight::get().writes(7)) + /// 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 { + // Minimum execution time: 118_181 nanoseconds. + Weight::from_ref_time(118_740_000 as u64) // Standard Error: 769_691 + .saturating_add(Weight::from_ref_time(3_767_843 as u64).saturating_mul(c as u64)) + // Standard Error: 2_541_567 + .saturating_add(Weight::from_ref_time(124_213_432 as u64).saturating_mul(e as u64)) + .saturating_add(RocksDbWeight::get().reads(3 as u64)) + .saturating_add(RocksDbWeight::get().reads((9 as u64).saturating_mul(e as u64))) + .saturating_add(RocksDbWeight::get().writes((7 as u64).saturating_mul(e as u64))) } } diff --git a/pallets/omnipool/Cargo.toml b/pallets/omnipool/Cargo.toml index befd397ab..7bf8a892d 100644 --- a/pallets/omnipool/Cargo.toml +++ b/pallets/omnipool/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-omnipool" -version = "3.2.2" +version = "3.2.3" authors = ['GalacticCouncil'] edition = "2021" license = "Apache-2.0" diff --git a/pallets/omnipool/src/weights.rs b/pallets/omnipool/src/weights.rs index 149af4061..bb6597f5c 100644 --- a/pallets/omnipool/src/weights.rs +++ b/pallets/omnipool/src/weights.rs @@ -1,6 +1,6 @@ // This file is part of HydraDX. -// Copyright (C) 2020-2021 Intergalactic, Limited (GIB). +// Copyright (C) 2020-2023 Intergalactic, Limited (GIB). // SPDX-License-Identifier: Apache-2.0 // Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,25 +18,24 @@ //! Autogenerated weights for pallet_omnipool //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2022-10-26, STEPS: 5, REPEAT: 20, LOW RANGE: [], HIGH RANGE: [] -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("local"), DB CACHE: 1024 +//! DATE: 2023-10-06, STEPS: 10, REPEAT: 30, 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-omnipool -// --chain=local -// --steps=5 -// --repeat=20 -// --extrinsic=* +// --chain=dev +// --steps=10 +// --repeat=30 // --execution=wasm // --wasm-execution=compiled // --heap-pages=4096 -// --output -// weights.rs -// --template -// .maintain/pallet-weight-template.hbs +// --template=.maintain/pallet-weight-template-no-back.hbs +// --pallet=pallet-omnipool +// --output=omnipool.rs +// --extrinsic=* + #![allow(unused_parens)] #![allow(unused_imports)] #![allow(clippy::unnecessary_cast)] @@ -59,61 +58,281 @@ pub trait WeightInfo { fn refund_refused_asset() -> Weight; fn sacrifice_position() -> Weight; fn set_asset_weight_cap() -> Weight; - fn router_execution_sell() -> Weight; - fn router_execution_buy() -> Weight; + fn router_execution_sell(c: u32, e: u32) -> Weight; + fn router_execution_buy(c: u32, e: u32) -> Weight; } /// Weights for pallet_omnipool using the hydraDX node and recommended hardware. pub struct HydraWeight(PhantomData); impl WeightInfo for HydraWeight { + // Storage: Omnipool Assets (r:2 w:2) + // 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) + // Storage: System Account (r:1 w:1) + // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) + // Storage: Tokens Accounts (r:2 w:1) + // Proof: Tokens Accounts (max_values: None, max_size: Some(108), added: 2583, 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 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: Omnipool TvlCap (r:1 w:0) + // Proof: Omnipool TvlCap (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen) + // Storage: Uniques ClassAccount (r:0 w:1) + // Proof: Uniques ClassAccount (max_values: None, max_size: Some(80), added: 2555, mode: MaxEncodedLen) + // Storage: Omnipool HubAssetTradability (r:0 w:1) + // Proof: Omnipool HubAssetTradability (max_values: Some(1), max_size: Some(1), added: 496, mode: MaxEncodedLen) fn initialize_pool() -> Weight { - Weight::from_ref_time(110_771_000 as u64) - .saturating_add(T::DbWeight::get().reads(10 as u64)) - .saturating_add(T::DbWeight::get().writes(10 as u64)) + // Minimum execution time: 149_531 nanoseconds. + Weight::from_ref_time(150_484_000 as u64) + .saturating_add(T::DbWeight::get().reads(11 as u64)) + .saturating_add(T::DbWeight::get().writes(8 as u64)) } + // Storage: Omnipool Assets (r:2 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) + // Storage: Tokens Accounts (r:3 w:1) + // Proof: Tokens Accounts (max_values: None, max_size: Some(108), added: 2583, mode: MaxEncodedLen) + // Storage: Omnipool NextPositionId (r:1 w:1) + // Proof: Omnipool NextPositionId (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen) + // Storage: Uniques Asset (r:1 w:1) + // Proof: Uniques Asset (max_values: None, max_size: Some(146), added: 2621, mode: MaxEncodedLen) + // Storage: Uniques Class (r:1 w:1) + // 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: Omnipool HubAssetImbalance (r:1 w:1) + // Proof: Omnipool HubAssetImbalance (max_values: Some(1), max_size: Some(17), added: 512, 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: Omnipool TvlCap (r:1 w:0) + // Proof: Omnipool TvlCap (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen) + // Storage: Uniques Account (r:0 w:1) + // Proof: Uniques Account (max_values: None, max_size: Some(112), added: 2587, mode: MaxEncodedLen) + // Storage: Omnipool Positions (r:0 w:1) + // Proof: Omnipool Positions (max_values: None, max_size: Some(100), added: 2575, mode: MaxEncodedLen) fn add_token() -> Weight { - Weight::from_ref_time(103_310_000 as u64) - .saturating_add(T::DbWeight::get().reads(14 as u64)) + // Minimum execution time: 148_641 nanoseconds. + Weight::from_ref_time(150_420_000 as u64) + .saturating_add(T::DbWeight::get().reads(15 as u64)) .saturating_add(T::DbWeight::get().writes(10 as u64)) } + // Storage: Tokens Accounts (r:4 w:3) + // Proof: Tokens Accounts (max_values: None, max_size: Some(108), added: 2583, mode: MaxEncodedLen) + // Storage: Omnipool Assets (r:2 w:1) + // Proof: Omnipool Assets (max_values: None, max_size: Some(85), added: 2560, mode: MaxEncodedLen) + // Storage: EmaOracle Oracles (r:2 w:0) + // 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: Omnipool NextPositionId (r:1 w:1) + // Proof: Omnipool NextPositionId (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen) + // Storage: Uniques Asset (r:1 w:1) + // Proof: Uniques Asset (max_values: None, max_size: Some(146), added: 2621, mode: MaxEncodedLen) + // Storage: Uniques Class (r:1 w:1) + // 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: AssetRegistry Assets (r:2 w:0) + // Proof: AssetRegistry Assets (max_values: None, max_size: Some(87), added: 2562, 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) + // Proof: Tokens TotalIssuance (max_values: None, max_size: Some(28), added: 2503, mode: MaxEncodedLen) + // Storage: Omnipool TvlCap (r:1 w:0) + // Proof: Omnipool TvlCap (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) + // Storage: CircuitBreaker LiquidityAddLimitPerAsset (r:1 w:0) + // Proof: CircuitBreaker LiquidityAddLimitPerAsset (max_values: None, max_size: Some(29), added: 2504, mode: MaxEncodedLen) + // Storage: CircuitBreaker AllowedAddLiquidityAmountPerAsset (r:1 w:1) + // Proof: CircuitBreaker AllowedAddLiquidityAmountPerAsset (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) + // Storage: CircuitBreaker LiquidityRemoveLimitPerAsset (r:1 w:0) + // Proof: CircuitBreaker LiquidityRemoveLimitPerAsset (max_values: None, max_size: Some(29), added: 2504, mode: MaxEncodedLen) + // Storage: CircuitBreaker AllowedRemoveLiquidityAmountPerAsset (r:1 w:1) + // Proof: CircuitBreaker AllowedRemoveLiquidityAmountPerAsset (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) + // Storage: Uniques Account (r:0 w:1) + // Proof: Uniques Account (max_values: None, max_size: Some(112), added: 2587, mode: MaxEncodedLen) + // Storage: Omnipool Positions (r:0 w:1) + // Proof: Omnipool Positions (max_values: None, max_size: Some(100), added: 2575, mode: MaxEncodedLen) fn add_liquidity() -> Weight { - Weight::from_ref_time(139_531_000 as u64) - .saturating_add(T::DbWeight::get().reads(16 as u64)) - .saturating_add(T::DbWeight::get().writes(12 as u64)) + // Minimum execution time: 233_542 nanoseconds. + Weight::from_ref_time(235_489_000 as u64) + .saturating_add(T::DbWeight::get().reads(23 as u64)) + .saturating_add(T::DbWeight::get().writes(14 as u64)) } + // Storage: Uniques Asset (r:1 w:1) + // Proof: Uniques Asset (max_values: None, max_size: Some(146), added: 2621, mode: MaxEncodedLen) + // Storage: Omnipool Positions (r:1 w:1) + // Proof: Omnipool Positions (max_values: None, max_size: Some(100), added: 2575, mode: MaxEncodedLen) + // Storage: Omnipool Assets (r:1 w:1) + // Proof: Omnipool Assets (max_values: None, max_size: Some(85), added: 2560, mode: MaxEncodedLen) + // Storage: Tokens Accounts (r:4 w:4) + // Proof: Tokens Accounts (max_values: None, max_size: Some(108), added: 2583, mode: MaxEncodedLen) + // Storage: EmaOracle Oracles (r:2 w:0) + // 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: 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: 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:1) + // 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: Uniques Class (r:1 w:1) + // Proof: Uniques Class (max_values: None, max_size: Some(190), added: 2665, 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 LiquidityAddLimitPerAsset (r:1 w:0) + // Proof: CircuitBreaker LiquidityAddLimitPerAsset (max_values: None, max_size: Some(29), added: 2504, mode: MaxEncodedLen) + // Storage: CircuitBreaker AllowedAddLiquidityAmountPerAsset (r:1 w:0) + // Proof: CircuitBreaker AllowedAddLiquidityAmountPerAsset (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) + // Storage: CircuitBreaker LiquidityRemoveLimitPerAsset (r:1 w:0) + // Proof: CircuitBreaker LiquidityRemoveLimitPerAsset (max_values: None, max_size: Some(29), added: 2504, mode: MaxEncodedLen) + // Storage: CircuitBreaker AllowedRemoveLiquidityAmountPerAsset (r:1 w:1) + // Proof: CircuitBreaker AllowedRemoveLiquidityAmountPerAsset (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) + // Storage: Uniques Account (r:0 w:1) + // Proof: Uniques Account (max_values: None, max_size: Some(112), added: 2587, mode: MaxEncodedLen) + // Storage: Uniques ItemPriceOf (r:0 w:1) + // Proof: Uniques ItemPriceOf (max_values: None, max_size: Some(113), added: 2588, mode: MaxEncodedLen) fn remove_liquidity() -> Weight { - Weight::from_ref_time(175_741_000 as u64) - .saturating_add(T::DbWeight::get().reads(18 as u64)) - .saturating_add(T::DbWeight::get().writes(15 as u64)) + // Minimum execution time: 295_371 nanoseconds. + Weight::from_ref_time(297_465_000 as u64) + .saturating_add(T::DbWeight::get().reads(23 as u64)) + .saturating_add(T::DbWeight::get().writes(16 as u64)) } + // Storage: Tokens Accounts (r:4 w:4) + // Proof: Tokens Accounts (max_values: None, max_size: Some(108), added: 2583, mode: MaxEncodedLen) + // Storage: Omnipool Assets (r:3 w:3) + // Proof: Omnipool Assets (max_values: None, max_size: Some(85), added: 2560, 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: DynamicFees AssetFee (r:1 w:0) + // Proof: DynamicFees AssetFee (max_values: None, max_size: Some(24), added: 2499, mode: MaxEncodedLen) + // Storage: EmaOracle Oracles (r:1 w:0) + // Proof: EmaOracle Oracles (max_values: None, max_size: Some(177), added: 2652, 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: MultiTransactionPayment AccountCurrencyMap (r:1 w:1) + // 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: 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) + // Proof: CircuitBreaker AllowedTradeVolumeLimitPerAsset (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen) + // Storage: CircuitBreaker LiquidityAddLimitPerAsset (r:1 w:0) + // Proof: CircuitBreaker LiquidityAddLimitPerAsset (max_values: None, max_size: Some(29), added: 2504, mode: MaxEncodedLen) + // Storage: CircuitBreaker AllowedAddLiquidityAmountPerAsset (r:1 w:1) + // Proof: CircuitBreaker AllowedAddLiquidityAmountPerAsset (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) + // Storage: CircuitBreaker LiquidityRemoveLimitPerAsset (r:1 w:0) + // Proof: CircuitBreaker LiquidityRemoveLimitPerAsset (max_values: None, max_size: Some(29), added: 2504, mode: MaxEncodedLen) + // Storage: CircuitBreaker AllowedRemoveLiquidityAmountPerAsset (r:1 w:0) + // Proof: CircuitBreaker AllowedRemoveLiquidityAmountPerAsset (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) fn sell() -> Weight { - Weight::from_ref_time(121_641_000 as u64) - .saturating_add(T::DbWeight::get().reads(14 as u64)) - .saturating_add(T::DbWeight::get().writes(10 as u64)) + // Minimum execution time: 258_297 nanoseconds. + Weight::from_ref_time(260_217_000 as u64) + .saturating_add(T::DbWeight::get().reads(23 as u64)) + .saturating_add(T::DbWeight::get().writes(14 as u64)) } + // Storage: Omnipool Assets (r:3 w:3) + // Proof: Omnipool Assets (max_values: None, max_size: Some(85), added: 2560, mode: MaxEncodedLen) + // Storage: Tokens Accounts (r:4 w:4) + // 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: DynamicFees AssetFee (r:1 w:1) + // 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 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: MultiTransactionPayment AccountCurrencyMap (r:1 w:1) + // 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: 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) + // Proof: CircuitBreaker AllowedTradeVolumeLimitPerAsset (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen) + // Storage: CircuitBreaker LiquidityAddLimitPerAsset (r:1 w:0) + // Proof: CircuitBreaker LiquidityAddLimitPerAsset (max_values: None, max_size: Some(29), added: 2504, mode: MaxEncodedLen) + // Storage: CircuitBreaker AllowedAddLiquidityAmountPerAsset (r:1 w:1) + // Proof: CircuitBreaker AllowedAddLiquidityAmountPerAsset (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) + // Storage: CircuitBreaker LiquidityRemoveLimitPerAsset (r:1 w:0) + // Proof: CircuitBreaker LiquidityRemoveLimitPerAsset (max_values: None, max_size: Some(29), added: 2504, mode: MaxEncodedLen) + // Storage: CircuitBreaker AllowedRemoveLiquidityAmountPerAsset (r:1 w:0) + // Proof: CircuitBreaker AllowedRemoveLiquidityAmountPerAsset (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) fn buy() -> Weight { - Weight::from_ref_time(121_521_000 as u64) - .saturating_add(T::DbWeight::get().reads(14 as u64)) - .saturating_add(T::DbWeight::get().writes(10 as u64)) + // Minimum execution time: 279_260 nanoseconds. + Weight::from_ref_time(280_777_000 as u64) + .saturating_add(T::DbWeight::get().reads(24 as u64)) + .saturating_add(T::DbWeight::get().writes(15 as u64)) } + // Storage: Omnipool Assets (r:1 w:1) + // Proof: Omnipool Assets (max_values: None, max_size: Some(85), added: 2560, mode: MaxEncodedLen) fn set_asset_tradable_state() -> Weight { - Weight::from_ref_time(21_030_000 as u64) + // Minimum execution time: 33_892 nanoseconds. + Weight::from_ref_time(34_292_000 as u64) .saturating_add(T::DbWeight::get().reads(1 as u64)) .saturating_add(T::DbWeight::get().writes(1 as u64)) } + // Storage: Omnipool Assets (r:1 w:0) + // 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: 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) + // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) + // Storage: MultiTransactionPayment AccountCurrencyMap (r:1 w:1) + // 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) fn refund_refused_asset() -> Weight { - Weight::from_ref_time(72_851_000 as u64) + // Minimum execution time: 109_440 nanoseconds. + Weight::from_ref_time(110_207_000 as u64) .saturating_add(T::DbWeight::get().reads(8 as u64)) .saturating_add(T::DbWeight::get().writes(5 as u64)) } + // Storage: Omnipool Positions (r:1 w:1) + // Proof: Omnipool Positions (max_values: None, max_size: Some(100), added: 2575, mode: MaxEncodedLen) + // Storage: Uniques Asset (r:1 w:1) + // Proof: Uniques Asset (max_values: None, max_size: Some(146), added: 2621, mode: MaxEncodedLen) + // Storage: Omnipool Assets (r:1 w:1) + // Proof: Omnipool Assets (max_values: None, max_size: Some(85), added: 2560, mode: MaxEncodedLen) + // Storage: Uniques Class (r:1 w:1) + // Proof: Uniques Class (max_values: None, max_size: Some(190), added: 2665, mode: MaxEncodedLen) + // Storage: Uniques Account (r:0 w:1) + // Proof: Uniques Account (max_values: None, max_size: Some(112), added: 2587, mode: MaxEncodedLen) + // Storage: Uniques ItemPriceOf (r:0 w:1) + // Proof: Uniques ItemPriceOf (max_values: None, max_size: Some(113), added: 2588, mode: MaxEncodedLen) fn sacrifice_position() -> Weight { - Weight::from_ref_time(56_001_000 as u64) + // Minimum execution time: 77_870 nanoseconds. + Weight::from_ref_time(78_533_000 as u64) .saturating_add(T::DbWeight::get().reads(4 as u64)) - .saturating_add(T::DbWeight::get().writes(7 as u64)) + .saturating_add(T::DbWeight::get().writes(6 as u64)) } + // Storage: Omnipool Assets (r:1 w:1) + // Proof: Omnipool Assets (max_values: None, max_size: Some(85), added: 2560, mode: MaxEncodedLen) fn set_asset_weight_cap() -> Weight { - Weight::from_ref_time(20_790_000 as u64) + // Minimum execution time: 34_229 nanoseconds. + Weight::from_ref_time(34_689_000 as u64) .saturating_add(T::DbWeight::get().reads(1 as u64)) .saturating_add(T::DbWeight::get().writes(1 as u64)) } @@ -136,7 +355,7 @@ impl WeightInfo for HydraWeight { // 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) - // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(2961), added: 3456, mode: MaxEncodedLen) + // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(5921), added: 6416, mode: MaxEncodedLen) // Storage: CircuitBreaker AllowedTradeVolumeLimitPerAsset (r:2 w:2) // Proof: CircuitBreaker AllowedTradeVolumeLimitPerAsset (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen) // Storage: CircuitBreaker LiquidityAddLimitPerAsset (r:1 w:0) @@ -147,11 +366,17 @@ impl WeightInfo for HydraWeight { // Proof: CircuitBreaker LiquidityRemoveLimitPerAsset (max_values: None, max_size: Some(29), added: 2504, mode: MaxEncodedLen) // Storage: CircuitBreaker AllowedRemoveLiquidityAmountPerAsset (r:1 w:0) // Proof: CircuitBreaker AllowedRemoveLiquidityAmountPerAsset (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) - fn router_execution_sell() -> Weight { - // Minimum execution time: 269_857 nanoseconds. - Weight::from_ref_time(271_611_000 as u64) - .saturating_add(T::DbWeight::get().reads(23 as u64)) - .saturating_add(T::DbWeight::get().writes(14 as u64)) + /// The range of component `c` is `[0, 1]`. + /// The range of component `e` is `[0, 1]`. + fn router_execution_sell(c: u32, e: u32) -> Weight { + // Minimum execution time: 54_153 nanoseconds. + Weight::from_ref_time(40_444_373 as u64) // Standard Error: 79_703 + .saturating_add(Weight::from_ref_time(14_755_626 as u64).saturating_mul(c as u64)) + // Standard Error: 79_703 + .saturating_add(Weight::from_ref_time(219_012_766 as u64).saturating_mul(e as u64)) + .saturating_add(T::DbWeight::get().reads(7 as u64)) + .saturating_add(T::DbWeight::get().reads((16 as u64).saturating_mul(e as u64))) + .saturating_add(T::DbWeight::get().writes((14 as u64).saturating_mul(e as u64))) } // Storage: Omnipool Assets (r:3 w:3) // Proof: Omnipool Assets (max_values: None, max_size: Some(85), added: 2560, mode: MaxEncodedLen) @@ -172,7 +397,7 @@ impl WeightInfo for HydraWeight { // 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) - // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(2961), added: 3456, mode: MaxEncodedLen) + // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(5921), added: 6416, mode: MaxEncodedLen) // Storage: CircuitBreaker AllowedTradeVolumeLimitPerAsset (r:2 w:2) // Proof: CircuitBreaker AllowedTradeVolumeLimitPerAsset (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen) // Storage: CircuitBreaker LiquidityAddLimitPerAsset (r:1 w:0) @@ -183,9 +408,12 @@ impl WeightInfo for HydraWeight { // Proof: CircuitBreaker LiquidityRemoveLimitPerAsset (max_values: None, max_size: Some(29), added: 2504, mode: MaxEncodedLen) // Storage: CircuitBreaker AllowedRemoveLiquidityAmountPerAsset (r:1 w:0) // Proof: CircuitBreaker AllowedRemoveLiquidityAmountPerAsset (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) - fn router_execution_buy() -> Weight { - // Minimum execution time: 288_769 nanoseconds. - Weight::from_ref_time(290_860_000 as u64) + /// 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 { + // Minimum execution time: 277_855 nanoseconds. + Weight::from_ref_time(269_412_275 as u64) // Standard Error: 112_640 + .saturating_add(Weight::from_ref_time(12_219_983 as u64).saturating_mul(c as u64)) .saturating_add(T::DbWeight::get().reads(24 as u64)) .saturating_add(T::DbWeight::get().writes(15 as u64)) } @@ -193,53 +421,273 @@ impl WeightInfo for HydraWeight { // For backwards compatibility and tests impl WeightInfo for () { + // Storage: Omnipool Assets (r:2 w:2) + // 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) + // Storage: System Account (r:1 w:1) + // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) + // Storage: Tokens Accounts (r:2 w:1) + // Proof: Tokens Accounts (max_values: None, max_size: Some(108), added: 2583, 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 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: Omnipool TvlCap (r:1 w:0) + // Proof: Omnipool TvlCap (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen) + // Storage: Uniques ClassAccount (r:0 w:1) + // Proof: Uniques ClassAccount (max_values: None, max_size: Some(80), added: 2555, mode: MaxEncodedLen) + // Storage: Omnipool HubAssetTradability (r:0 w:1) + // Proof: Omnipool HubAssetTradability (max_values: Some(1), max_size: Some(1), added: 496, mode: MaxEncodedLen) fn initialize_pool() -> Weight { - Weight::from_ref_time(110_771_000 as u64) - .saturating_add(RocksDbWeight::get().reads(10 as u64)) - .saturating_add(RocksDbWeight::get().writes(10 as u64)) + // Minimum execution time: 149_531 nanoseconds. + Weight::from_ref_time(150_484_000 as u64) + .saturating_add(RocksDbWeight::get().reads(11 as u64)) + .saturating_add(RocksDbWeight::get().writes(8 as u64)) } + // Storage: Omnipool Assets (r:2 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) + // Storage: Tokens Accounts (r:3 w:1) + // Proof: Tokens Accounts (max_values: None, max_size: Some(108), added: 2583, mode: MaxEncodedLen) + // Storage: Omnipool NextPositionId (r:1 w:1) + // Proof: Omnipool NextPositionId (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen) + // Storage: Uniques Asset (r:1 w:1) + // Proof: Uniques Asset (max_values: None, max_size: Some(146), added: 2621, mode: MaxEncodedLen) + // Storage: Uniques Class (r:1 w:1) + // 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: Omnipool HubAssetImbalance (r:1 w:1) + // Proof: Omnipool HubAssetImbalance (max_values: Some(1), max_size: Some(17), added: 512, 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: Omnipool TvlCap (r:1 w:0) + // Proof: Omnipool TvlCap (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen) + // Storage: Uniques Account (r:0 w:1) + // Proof: Uniques Account (max_values: None, max_size: Some(112), added: 2587, mode: MaxEncodedLen) + // Storage: Omnipool Positions (r:0 w:1) + // Proof: Omnipool Positions (max_values: None, max_size: Some(100), added: 2575, mode: MaxEncodedLen) fn add_token() -> Weight { - Weight::from_ref_time(103_310_000 as u64) - .saturating_add(RocksDbWeight::get().reads(14 as u64)) + // Minimum execution time: 148_641 nanoseconds. + Weight::from_ref_time(150_420_000 as u64) + .saturating_add(RocksDbWeight::get().reads(15 as u64)) .saturating_add(RocksDbWeight::get().writes(10 as u64)) } + // Storage: Tokens Accounts (r:4 w:3) + // Proof: Tokens Accounts (max_values: None, max_size: Some(108), added: 2583, mode: MaxEncodedLen) + // Storage: Omnipool Assets (r:2 w:1) + // Proof: Omnipool Assets (max_values: None, max_size: Some(85), added: 2560, mode: MaxEncodedLen) + // Storage: EmaOracle Oracles (r:2 w:0) + // 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: Omnipool NextPositionId (r:1 w:1) + // Proof: Omnipool NextPositionId (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen) + // Storage: Uniques Asset (r:1 w:1) + // Proof: Uniques Asset (max_values: None, max_size: Some(146), added: 2621, mode: MaxEncodedLen) + // Storage: Uniques Class (r:1 w:1) + // 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: AssetRegistry Assets (r:2 w:0) + // Proof: AssetRegistry Assets (max_values: None, max_size: Some(87), added: 2562, 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) + // Proof: Tokens TotalIssuance (max_values: None, max_size: Some(28), added: 2503, mode: MaxEncodedLen) + // Storage: Omnipool TvlCap (r:1 w:0) + // Proof: Omnipool TvlCap (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) + // Storage: CircuitBreaker LiquidityAddLimitPerAsset (r:1 w:0) + // Proof: CircuitBreaker LiquidityAddLimitPerAsset (max_values: None, max_size: Some(29), added: 2504, mode: MaxEncodedLen) + // Storage: CircuitBreaker AllowedAddLiquidityAmountPerAsset (r:1 w:1) + // Proof: CircuitBreaker AllowedAddLiquidityAmountPerAsset (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) + // Storage: CircuitBreaker LiquidityRemoveLimitPerAsset (r:1 w:0) + // Proof: CircuitBreaker LiquidityRemoveLimitPerAsset (max_values: None, max_size: Some(29), added: 2504, mode: MaxEncodedLen) + // Storage: CircuitBreaker AllowedRemoveLiquidityAmountPerAsset (r:1 w:1) + // Proof: CircuitBreaker AllowedRemoveLiquidityAmountPerAsset (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) + // Storage: Uniques Account (r:0 w:1) + // Proof: Uniques Account (max_values: None, max_size: Some(112), added: 2587, mode: MaxEncodedLen) + // Storage: Omnipool Positions (r:0 w:1) + // Proof: Omnipool Positions (max_values: None, max_size: Some(100), added: 2575, mode: MaxEncodedLen) fn add_liquidity() -> Weight { - Weight::from_ref_time(139_531_000 as u64) - .saturating_add(RocksDbWeight::get().reads(16 as u64)) - .saturating_add(RocksDbWeight::get().writes(12 as u64)) + // Minimum execution time: 233_542 nanoseconds. + Weight::from_ref_time(235_489_000 as u64) + .saturating_add(RocksDbWeight::get().reads(23 as u64)) + .saturating_add(RocksDbWeight::get().writes(14 as u64)) } + // Storage: Uniques Asset (r:1 w:1) + // Proof: Uniques Asset (max_values: None, max_size: Some(146), added: 2621, mode: MaxEncodedLen) + // Storage: Omnipool Positions (r:1 w:1) + // Proof: Omnipool Positions (max_values: None, max_size: Some(100), added: 2575, mode: MaxEncodedLen) + // Storage: Omnipool Assets (r:1 w:1) + // Proof: Omnipool Assets (max_values: None, max_size: Some(85), added: 2560, mode: MaxEncodedLen) + // Storage: Tokens Accounts (r:4 w:4) + // Proof: Tokens Accounts (max_values: None, max_size: Some(108), added: 2583, mode: MaxEncodedLen) + // Storage: EmaOracle Oracles (r:2 w:0) + // 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: 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: 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:1) + // 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: Uniques Class (r:1 w:1) + // Proof: Uniques Class (max_values: None, max_size: Some(190), added: 2665, 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 LiquidityAddLimitPerAsset (r:1 w:0) + // Proof: CircuitBreaker LiquidityAddLimitPerAsset (max_values: None, max_size: Some(29), added: 2504, mode: MaxEncodedLen) + // Storage: CircuitBreaker AllowedAddLiquidityAmountPerAsset (r:1 w:0) + // Proof: CircuitBreaker AllowedAddLiquidityAmountPerAsset (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) + // Storage: CircuitBreaker LiquidityRemoveLimitPerAsset (r:1 w:0) + // Proof: CircuitBreaker LiquidityRemoveLimitPerAsset (max_values: None, max_size: Some(29), added: 2504, mode: MaxEncodedLen) + // Storage: CircuitBreaker AllowedRemoveLiquidityAmountPerAsset (r:1 w:1) + // Proof: CircuitBreaker AllowedRemoveLiquidityAmountPerAsset (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) + // Storage: Uniques Account (r:0 w:1) + // Proof: Uniques Account (max_values: None, max_size: Some(112), added: 2587, mode: MaxEncodedLen) + // Storage: Uniques ItemPriceOf (r:0 w:1) + // Proof: Uniques ItemPriceOf (max_values: None, max_size: Some(113), added: 2588, mode: MaxEncodedLen) fn remove_liquidity() -> Weight { - Weight::from_ref_time(175_741_000 as u64) - .saturating_add(RocksDbWeight::get().reads(18 as u64)) - .saturating_add(RocksDbWeight::get().writes(15 as u64)) + // Minimum execution time: 295_371 nanoseconds. + Weight::from_ref_time(297_465_000 as u64) + .saturating_add(RocksDbWeight::get().reads(23 as u64)) + .saturating_add(RocksDbWeight::get().writes(16 as u64)) } + // Storage: Tokens Accounts (r:4 w:4) + // Proof: Tokens Accounts (max_values: None, max_size: Some(108), added: 2583, mode: MaxEncodedLen) + // Storage: Omnipool Assets (r:3 w:3) + // Proof: Omnipool Assets (max_values: None, max_size: Some(85), added: 2560, 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: DynamicFees AssetFee (r:1 w:0) + // Proof: DynamicFees AssetFee (max_values: None, max_size: Some(24), added: 2499, mode: MaxEncodedLen) + // Storage: EmaOracle Oracles (r:1 w:0) + // Proof: EmaOracle Oracles (max_values: None, max_size: Some(177), added: 2652, 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: MultiTransactionPayment AccountCurrencyMap (r:1 w:1) + // 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: 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) + // Proof: CircuitBreaker AllowedTradeVolumeLimitPerAsset (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen) + // Storage: CircuitBreaker LiquidityAddLimitPerAsset (r:1 w:0) + // Proof: CircuitBreaker LiquidityAddLimitPerAsset (max_values: None, max_size: Some(29), added: 2504, mode: MaxEncodedLen) + // Storage: CircuitBreaker AllowedAddLiquidityAmountPerAsset (r:1 w:1) + // Proof: CircuitBreaker AllowedAddLiquidityAmountPerAsset (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) + // Storage: CircuitBreaker LiquidityRemoveLimitPerAsset (r:1 w:0) + // Proof: CircuitBreaker LiquidityRemoveLimitPerAsset (max_values: None, max_size: Some(29), added: 2504, mode: MaxEncodedLen) + // Storage: CircuitBreaker AllowedRemoveLiquidityAmountPerAsset (r:1 w:0) + // Proof: CircuitBreaker AllowedRemoveLiquidityAmountPerAsset (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) fn sell() -> Weight { - Weight::from_ref_time(121_641_000 as u64) - .saturating_add(RocksDbWeight::get().reads(14 as u64)) - .saturating_add(RocksDbWeight::get().writes(10 as u64)) + // Minimum execution time: 258_297 nanoseconds. + Weight::from_ref_time(260_217_000 as u64) + .saturating_add(RocksDbWeight::get().reads(23 as u64)) + .saturating_add(RocksDbWeight::get().writes(14 as u64)) } + // Storage: Omnipool Assets (r:3 w:3) + // Proof: Omnipool Assets (max_values: None, max_size: Some(85), added: 2560, mode: MaxEncodedLen) + // Storage: Tokens Accounts (r:4 w:4) + // 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: DynamicFees AssetFee (r:1 w:1) + // 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 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: MultiTransactionPayment AccountCurrencyMap (r:1 w:1) + // 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: 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) + // Proof: CircuitBreaker AllowedTradeVolumeLimitPerAsset (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen) + // Storage: CircuitBreaker LiquidityAddLimitPerAsset (r:1 w:0) + // Proof: CircuitBreaker LiquidityAddLimitPerAsset (max_values: None, max_size: Some(29), added: 2504, mode: MaxEncodedLen) + // Storage: CircuitBreaker AllowedAddLiquidityAmountPerAsset (r:1 w:1) + // Proof: CircuitBreaker AllowedAddLiquidityAmountPerAsset (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) + // Storage: CircuitBreaker LiquidityRemoveLimitPerAsset (r:1 w:0) + // Proof: CircuitBreaker LiquidityRemoveLimitPerAsset (max_values: None, max_size: Some(29), added: 2504, mode: MaxEncodedLen) + // Storage: CircuitBreaker AllowedRemoveLiquidityAmountPerAsset (r:1 w:0) + // Proof: CircuitBreaker AllowedRemoveLiquidityAmountPerAsset (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) fn buy() -> Weight { - Weight::from_ref_time(121_521_000 as u64) - .saturating_add(RocksDbWeight::get().reads(14 as u64)) - .saturating_add(RocksDbWeight::get().writes(10 as u64)) + // Minimum execution time: 279_260 nanoseconds. + Weight::from_ref_time(280_777_000 as u64) + .saturating_add(RocksDbWeight::get().reads(24 as u64)) + .saturating_add(RocksDbWeight::get().writes(15 as u64)) } + // Storage: Omnipool Assets (r:1 w:1) + // Proof: Omnipool Assets (max_values: None, max_size: Some(85), added: 2560, mode: MaxEncodedLen) fn set_asset_tradable_state() -> Weight { - Weight::from_ref_time(21_030_000 as u64) + // Minimum execution time: 33_892 nanoseconds. + Weight::from_ref_time(34_292_000 as u64) .saturating_add(RocksDbWeight::get().reads(1 as u64)) .saturating_add(RocksDbWeight::get().writes(1 as u64)) } + // Storage: Omnipool Assets (r:1 w:0) + // 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: 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) + // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) + // Storage: MultiTransactionPayment AccountCurrencyMap (r:1 w:1) + // 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) fn refund_refused_asset() -> Weight { - Weight::from_ref_time(72_851_000 as u64) + // Minimum execution time: 109_440 nanoseconds. + Weight::from_ref_time(110_207_000 as u64) .saturating_add(RocksDbWeight::get().reads(8 as u64)) .saturating_add(RocksDbWeight::get().writes(5 as u64)) } + // Storage: Omnipool Positions (r:1 w:1) + // Proof: Omnipool Positions (max_values: None, max_size: Some(100), added: 2575, mode: MaxEncodedLen) + // Storage: Uniques Asset (r:1 w:1) + // Proof: Uniques Asset (max_values: None, max_size: Some(146), added: 2621, mode: MaxEncodedLen) + // Storage: Omnipool Assets (r:1 w:1) + // Proof: Omnipool Assets (max_values: None, max_size: Some(85), added: 2560, mode: MaxEncodedLen) + // Storage: Uniques Class (r:1 w:1) + // Proof: Uniques Class (max_values: None, max_size: Some(190), added: 2665, mode: MaxEncodedLen) + // Storage: Uniques Account (r:0 w:1) + // Proof: Uniques Account (max_values: None, max_size: Some(112), added: 2587, mode: MaxEncodedLen) + // Storage: Uniques ItemPriceOf (r:0 w:1) + // Proof: Uniques ItemPriceOf (max_values: None, max_size: Some(113), added: 2588, mode: MaxEncodedLen) fn sacrifice_position() -> Weight { - Weight::from_ref_time(56_001_000 as u64) + // Minimum execution time: 77_870 nanoseconds. + Weight::from_ref_time(78_533_000 as u64) .saturating_add(RocksDbWeight::get().reads(4 as u64)) - .saturating_add(RocksDbWeight::get().writes(7 as u64)) + .saturating_add(RocksDbWeight::get().writes(6 as u64)) } + // Storage: Omnipool Assets (r:1 w:1) + // Proof: Omnipool Assets (max_values: None, max_size: Some(85), added: 2560, mode: MaxEncodedLen) fn set_asset_weight_cap() -> Weight { - Weight::from_ref_time(20_790_000 as u64) + // Minimum execution time: 34_229 nanoseconds. + Weight::from_ref_time(34_689_000 as u64) .saturating_add(RocksDbWeight::get().reads(1 as u64)) .saturating_add(RocksDbWeight::get().writes(1 as u64)) } @@ -262,7 +710,7 @@ impl WeightInfo for () { // 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) - // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(2961), added: 3456, mode: MaxEncodedLen) + // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(5921), added: 6416, mode: MaxEncodedLen) // Storage: CircuitBreaker AllowedTradeVolumeLimitPerAsset (r:2 w:2) // Proof: CircuitBreaker AllowedTradeVolumeLimitPerAsset (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen) // Storage: CircuitBreaker LiquidityAddLimitPerAsset (r:1 w:0) @@ -273,11 +721,17 @@ impl WeightInfo for () { // Proof: CircuitBreaker LiquidityRemoveLimitPerAsset (max_values: None, max_size: Some(29), added: 2504, mode: MaxEncodedLen) // Storage: CircuitBreaker AllowedRemoveLiquidityAmountPerAsset (r:1 w:0) // Proof: CircuitBreaker AllowedRemoveLiquidityAmountPerAsset (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) - fn router_execution_sell() -> Weight { - // Minimum execution time: 269_857 nanoseconds. - Weight::from_ref_time(271_611_000 as u64) - .saturating_add(RocksDbWeight::get().reads(23 as u64)) - .saturating_add(RocksDbWeight::get().writes(14 as u64)) + /// The range of component `c` is `[0, 1]`. + /// The range of component `e` is `[0, 1]`. + fn router_execution_sell(c: u32, e: u32) -> Weight { + // Minimum execution time: 54_153 nanoseconds. + Weight::from_ref_time(40_444_373 as u64) // Standard Error: 79_703 + .saturating_add(Weight::from_ref_time(14_755_626 as u64).saturating_mul(c as u64)) + // Standard Error: 79_703 + .saturating_add(Weight::from_ref_time(219_012_766 as u64).saturating_mul(e as u64)) + .saturating_add(RocksDbWeight::get().reads(7 as u64)) + .saturating_add(RocksDbWeight::get().reads((16 as u64).saturating_mul(e as u64))) + .saturating_add(RocksDbWeight::get().writes((14 as u64).saturating_mul(e as u64))) } // Storage: Omnipool Assets (r:3 w:3) // Proof: Omnipool Assets (max_values: None, max_size: Some(85), added: 2560, mode: MaxEncodedLen) @@ -298,7 +752,7 @@ impl WeightInfo for () { // 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) - // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(2961), added: 3456, mode: MaxEncodedLen) + // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(5921), added: 6416, mode: MaxEncodedLen) // Storage: CircuitBreaker AllowedTradeVolumeLimitPerAsset (r:2 w:2) // Proof: CircuitBreaker AllowedTradeVolumeLimitPerAsset (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen) // Storage: CircuitBreaker LiquidityAddLimitPerAsset (r:1 w:0) @@ -309,9 +763,12 @@ impl WeightInfo for () { // Proof: CircuitBreaker LiquidityRemoveLimitPerAsset (max_values: None, max_size: Some(29), added: 2504, mode: MaxEncodedLen) // Storage: CircuitBreaker AllowedRemoveLiquidityAmountPerAsset (r:1 w:0) // Proof: CircuitBreaker AllowedRemoveLiquidityAmountPerAsset (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) - fn router_execution_buy() -> Weight { - // Minimum execution time: 288_769 nanoseconds. - Weight::from_ref_time(290_860_000 as u64) + /// 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 { + // Minimum execution time: 277_855 nanoseconds. + Weight::from_ref_time(269_412_275 as u64) // Standard Error: 112_640 + .saturating_add(Weight::from_ref_time(12_219_983 as u64).saturating_mul(c as u64)) .saturating_add(RocksDbWeight::get().reads(24 as u64)) .saturating_add(RocksDbWeight::get().writes(15 as u64)) } diff --git a/pallets/route-executor/Cargo.toml b/pallets/route-executor/Cargo.toml index 5fbb51072..435cf8383 100644 --- a/pallets/route-executor/Cargo.toml +++ b/pallets/route-executor/Cargo.toml @@ -1,6 +1,6 @@ [package] name = 'pallet-route-executor' -version = '1.1.1' +version = '1.2.0' 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 608073a19..69cac495d 100644 --- a/pallets/route-executor/src/lib.rs +++ b/pallets/route-executor/src/lib.rs @@ -20,64 +20,29 @@ use codec::MaxEncodedLen; use frame_support::{ ensure, + pallet_prelude::*, traits::{fungibles::Inspect, Get}, transactional, - weights::Weight, }; use frame_system::ensure_signed; -use hydradx_traits::router::Trade; -use hydradx_traits::router::{ExecutorError, TradeExecution}; +pub use hydradx_traits::router::{ + AmmTradeWeights, AmountInAndOut, ExecutorError, PoolType, RouterT, Trade, TradeExecution, +}; use orml_traits::arithmetic::{CheckedAdd, CheckedSub}; use sp_runtime::{ArithmeticError, DispatchError}; -use sp_std::vec::Vec; +use sp_std::{vec, vec::Vec}; #[cfg(test)] mod tests; pub mod weights; -use weights::WeightInfo; - // Re-export pallet items so that they can be accessed from the crate namespace. pub use pallet::*; -pub trait TradeAmountsCalculator { - fn calculate_buy_trade_amounts( - route: &[Trade], - amount_out: Balance, - ) -> Result>, DispatchError>; - - fn calculate_sell_trade_amounts( - route: &[Trade], - amount_in: Balance, - ) -> Result>, DispatchError>; -} - -pub struct AmountInAndOut { - pub amount_in: Balance, - pub amount_out: Balance, -} - -/// Provides weight info for the router. Calculates the weight of a route based on the AMMs. -/// We get the resulting weight as the router extrinsic overhead + AMM weights. -pub trait AmmTradeWeights { - fn sell_weight(route: &[Trade]) -> Weight; - fn buy_weight(route: &[Trade]) -> Weight; -} - -impl AmmTradeWeights for () { - fn sell_weight(_route: &[Trade]) -> Weight { - Weight::zero() - } - fn buy_weight(_route: &[Trade]) -> Weight { - Weight::zero() - } -} - #[frame_support::pallet] pub mod pallet { use super::*; - use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::OriginFor; use hydradx_traits::router::ExecutorError; @@ -117,11 +82,8 @@ pub mod pallet { Error = DispatchError, >; - /// AMMs trade weight information. - type AmmTradeWeights: AmmTradeWeights; - /// Weight information for the extrinsics. - type WeightInfo: WeightInfo; + type WeightInfo: AmmTradeWeights>; } #[pallet::event] @@ -168,7 +130,7 @@ pub mod pallet { /// /// Emits `RouteExecuted` when successful. #[pallet::call_index(0)] - #[pallet::weight(T::AmmTradeWeights::sell_weight(route))] + #[pallet::weight(T::WeightInfo::sell_weight(route))] #[transactional] pub fn sell( origin: OriginFor, @@ -247,7 +209,7 @@ pub mod pallet { /// /// Emits `RouteExecuted` when successful. #[pallet::call_index(1)] - #[pallet::weight(T::AmmTradeWeights::buy_weight(route))] + #[pallet::weight(T::WeightInfo::buy_weight(route))] #[transactional] pub fn buy( origin: OriginFor, @@ -358,9 +320,7 @@ impl Pallet { } Ok(()) } -} -impl TradeAmountsCalculator for Pallet { fn calculate_sell_trade_amounts( route: &[Trade], amount_in: T::Balance, @@ -407,6 +367,93 @@ impl TradeAmountsCalculator for Pallet { } } +impl RouterT, AmountInAndOut> + for Pallet +{ + fn sell( + origin: T::RuntimeOrigin, + asset_in: T::AssetId, + asset_out: T::AssetId, + amount_in: T::Balance, + min_amount_out: T::Balance, + route: Vec>, + ) -> DispatchResult { + Pallet::::sell(origin, asset_in, asset_out, amount_in, min_amount_out, route) + } + + fn buy( + origin: T::RuntimeOrigin, + asset_in: T::AssetId, + asset_out: T::AssetId, + amount_out: T::Balance, + max_amount_in: T::Balance, + route: Vec>, + ) -> DispatchResult { + Pallet::::buy(origin, asset_in, asset_out, amount_out, max_amount_in, route) + } + + fn calculate_sell_trade_amounts( + route: &[Trade], + amount_in: T::Balance, + ) -> Result>, DispatchError> { + Pallet::::calculate_sell_trade_amounts(route, amount_in) + } + + fn calculate_buy_trade_amounts( + route: &[Trade], + amount_out: T::Balance, + ) -> Result>, DispatchError> { + Pallet::::calculate_buy_trade_amounts(route, amount_out) + } +} + +pub struct DummyRouter(PhantomData); +impl RouterT, AmountInAndOut> + for DummyRouter +{ + fn sell( + _origin: T::RuntimeOrigin, + _asset_in: T::AssetId, + _asset_out: T::AssetId, + _amount_in: T::Balance, + _min_amount_out: T::Balance, + _route: Vec>, + ) -> DispatchResult { + Ok(()) + } + + fn buy( + _origin: T::RuntimeOrigin, + _asset_in: T::AssetId, + _asset_out: T::AssetId, + _amount_out: T::Balance, + _max_amount_in: T::Balance, + _route: Vec>, + ) -> DispatchResult { + Ok(()) + } + + fn calculate_sell_trade_amounts( + _route: &[Trade], + amount_in: T::Balance, + ) -> Result>, DispatchError> { + Ok(vec![AmountInAndOut:: { + amount_in, + amount_out: amount_in, + }]) + } + + fn calculate_buy_trade_amounts( + _route: &[Trade], + amount_out: T::Balance, + ) -> Result>, DispatchError> { + Ok(vec![AmountInAndOut:: { + amount_in: amount_out, + amount_out, + }]) + } +} + #[macro_export] macro_rules! handle_execution_error { ($execution_result:expr) => {{ diff --git a/pallets/route-executor/src/tests/mock.rs b/pallets/route-executor/src/tests/mock.rs index 2dd19aebb..d0aa1dd6c 100644 --- a/pallets/route-executor/src/tests/mock.rs +++ b/pallets/route-executor/src/tests/mock.rs @@ -149,7 +149,6 @@ impl Config for Test { type MaxNumberOfTrades = MaxNumberOfTrades; type Currency = MultiInspectAdapter; type AMM = Pools; - type AmmTradeWeights = (); type WeightInfo = (); } diff --git a/pallets/route-executor/src/weights.rs b/pallets/route-executor/src/weights.rs index dc87075bb..fd5a731ac 100644 --- a/pallets/route-executor/src/weights.rs +++ b/pallets/route-executor/src/weights.rs @@ -18,7 +18,7 @@ //! Autogenerated weights for pallet_route_executor //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-09-11, STEPS: 10, REPEAT: 30, LOW RANGE: [], HIGH RANGE: [] +//! DATE: 2023-10-06, STEPS: 10, REPEAT: 30, LOW RANGE: [], HIGH RANGE: [] //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 // Executed Command: @@ -31,10 +31,10 @@ // --execution=wasm // --wasm-execution=compiled // --heap-pages=4096 -// --template=.maintain/pallet-weight-template.hbs +// --template=.maintain/pallet-weight-template-no-back.hbs // --pallet=pallet-route-executor +// --output=route-executor.rs // --extrinsic=* -// --output=route_executor.rs #![allow(unused_parens)] #![allow(unused_imports)] @@ -48,80 +48,104 @@ use sp_std::marker::PhantomData; /// Weight functions needed for pallet_route_executor. pub trait WeightInfo { - fn sell_in_lbp() -> Weight; - fn buy_in_lbp() -> Weight; + fn calculate_and_execute_sell_in_lbp(c: u32, s: u32) -> Weight; + fn calculate_and_execute_buy_in_lbp(c: u32, b: u32) -> Weight; } /// Weights for pallet_route_executor using the hydraDX node and recommended hardware. 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: System Account (r:3 w:3) // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) // Storage: Tokens Accounts (r:2 w:2) // Proof: Tokens Accounts (max_values: None, max_size: Some(108), added: 2583, mode: MaxEncodedLen) - // Storage: LBP PoolData (r:1 w:0) - // Proof: LBP PoolData (max_values: None, max_size: Some(163), added: 2638, 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 Assets (r:1 w:0) // Proof: AssetRegistry Assets (max_values: None, max_size: Some(87), added: 2562, mode: MaxEncodedLen) - fn sell_in_lbp() -> Weight { - // Minimum execution time: 225_028 nanoseconds. - Weight::from_ref_time(229_826_000 as u64) - .saturating_add(T::DbWeight::get().reads(8 as u64)) - .saturating_add(T::DbWeight::get().writes(6 as u64)) + /// The range of component `c` is `[0, 1]`. + /// The range of component `s` is `[0, 1]`. + fn calculate_and_execute_sell_in_lbp(c: u32, s: u32) -> Weight { + // Minimum execution time: 74_851 nanoseconds. + Weight::from_ref_time(26_266_260 as u64) // Standard Error: 251_240 + .saturating_add(Weight::from_ref_time(49_596_533 as u64).saturating_mul(c as u64)) + // Standard Error: 251_240 + .saturating_add(Weight::from_ref_time(252_604_739 as u64).saturating_mul(s as u64)) + .saturating_add(T::DbWeight::get().reads(3 as u64)) + .saturating_add(T::DbWeight::get().reads((5 as u64).saturating_mul(s as u64))) + .saturating_add(T::DbWeight::get().writes((6 as u64).saturating_mul(s as u64))) } - // Storage: System Account (r:3 w:3) - // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) // Storage: LBP PoolData (r:1 w:0) // Proof: LBP PoolData (max_values: None, max_size: Some(163), added: 2638, mode: MaxEncodedLen) + // Storage: System Account (r:3 w:3) + // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) // Storage: Tokens Accounts (r:2 w:2) // Proof: Tokens Accounts (max_values: None, max_size: Some(108), added: 2583, 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 Assets (r:1 w:0) // Proof: AssetRegistry Assets (max_values: None, max_size: Some(87), added: 2562, mode: MaxEncodedLen) - fn buy_in_lbp() -> Weight { - // Minimum execution time: 219_890 nanoseconds. - Weight::from_ref_time(221_506_000 as u64) - .saturating_add(T::DbWeight::get().reads(8 as u64)) - .saturating_add(T::DbWeight::get().writes(6 as u64)) + /// 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 { + // Minimum execution time: 73_996 nanoseconds. + Weight::from_ref_time(74_590_000 as u64) // Standard Error: 576_133 + .saturating_add(Weight::from_ref_time(2_213_808 as u64).saturating_mul(c as u64)) + // Standard Error: 1_264_777 + .saturating_add(Weight::from_ref_time(205_965_931 as u64).saturating_mul(b as u64)) + .saturating_add(T::DbWeight::get().reads(3 as u64)) + .saturating_add(T::DbWeight::get().reads((5 as u64).saturating_mul(b as u64))) + .saturating_add(T::DbWeight::get().writes((6 as u64).saturating_mul(b as u64))) } } // For backwards compatibility and tests impl WeightInfo for () { + // Storage: LBP PoolData (r:1 w:0) + // Proof: LBP PoolData (max_values: None, max_size: Some(163), added: 2638, mode: MaxEncodedLen) // Storage: System Account (r:3 w:3) // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) // Storage: Tokens Accounts (r:2 w:2) // Proof: Tokens Accounts (max_values: None, max_size: Some(108), added: 2583, mode: MaxEncodedLen) - // Storage: LBP PoolData (r:1 w:0) - // Proof: LBP PoolData (max_values: None, max_size: Some(163), added: 2638, 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 Assets (r:1 w:0) // Proof: AssetRegistry Assets (max_values: None, max_size: Some(87), added: 2562, mode: MaxEncodedLen) - fn sell_in_lbp() -> Weight { - // Minimum execution time: 224_215 nanoseconds. - Weight::from_ref_time(225_550_000) - .saturating_add(RocksDbWeight::get().reads(8)) - .saturating_add(RocksDbWeight::get().writes(6)) + /// The range of component `c` is `[0, 1]`. + /// The range of component `s` is `[0, 1]`. + fn calculate_and_execute_sell_in_lbp(c: u32, s: u32) -> Weight { + // Minimum execution time: 74_851 nanoseconds. + Weight::from_ref_time(26_266_260 as u64) // Standard Error: 251_240 + .saturating_add(Weight::from_ref_time(49_596_533 as u64).saturating_mul(c as u64)) + // Standard Error: 251_240 + .saturating_add(Weight::from_ref_time(252_604_739 as u64).saturating_mul(s as u64)) + .saturating_add(RocksDbWeight::get().reads(3 as u64)) + .saturating_add(RocksDbWeight::get().reads((5 as u64).saturating_mul(s as u64))) + .saturating_add(RocksDbWeight::get().writes((6 as u64).saturating_mul(s as u64))) } - // Storage: System Account (r:3 w:3) - // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) // Storage: LBP PoolData (r:1 w:0) // Proof: LBP PoolData (max_values: None, max_size: Some(163), added: 2638, mode: MaxEncodedLen) + // Storage: System Account (r:3 w:3) + // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) // Storage: Tokens Accounts (r:2 w:2) // Proof: Tokens Accounts (max_values: None, max_size: Some(108), added: 2583, 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 Assets (r:1 w:0) // Proof: AssetRegistry Assets (max_values: None, max_size: Some(87), added: 2562, mode: MaxEncodedLen) - fn buy_in_lbp() -> Weight { - // Minimum execution time: 220_676 nanoseconds. - Weight::from_ref_time(221_757_000) - .saturating_add(RocksDbWeight::get().reads(8)) - .saturating_add(RocksDbWeight::get().writes(6)) + /// 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 { + // Minimum execution time: 73_996 nanoseconds. + Weight::from_ref_time(74_590_000 as u64) // Standard Error: 576_133 + .saturating_add(Weight::from_ref_time(2_213_808 as u64).saturating_mul(c as u64)) + // Standard Error: 1_264_777 + .saturating_add(Weight::from_ref_time(205_965_931 as u64).saturating_mul(b as u64)) + .saturating_add(RocksDbWeight::get().reads(3 as u64)) + .saturating_add(RocksDbWeight::get().reads((5 as u64).saturating_mul(b as u64))) + .saturating_add(RocksDbWeight::get().writes((6 as u64).saturating_mul(b as u64))) } } diff --git a/pallets/stableswap/Cargo.toml b/pallets/stableswap/Cargo.toml index 4bdabf660..3025cbcc1 100644 --- a/pallets/stableswap/Cargo.toml +++ b/pallets/stableswap/Cargo.toml @@ -1,6 +1,6 @@ [package] name = 'pallet-stableswap' -version = '3.3.0' +version = '3.3.1' description = 'AMM for correlated assets' authors = ['GalacticCouncil'] edition = '2021' diff --git a/pallets/stableswap/src/benchmarks.rs b/pallets/stableswap/src/benchmarks.rs index b1dadce31..a5bcb11a9 100644 --- a/pallets/stableswap/src/benchmarks.rs +++ b/pallets/stableswap/src/benchmarks.rs @@ -478,6 +478,9 @@ benchmarks! { } router_execution_sell{ + let c in 0..1; // if c == 1, calculate_sell is executed + let e in 0..1; // if e == 1, execute_sell is executed + let caller: T::AccountId = account("caller", 0, 1); let lp_provider: T::AccountId = account("provider", 0, 1); let initial_liquidity = 1_000_000_000_000_000_000u128; @@ -526,15 +529,24 @@ benchmarks! { )?; System::::set_block_number(500u32.into()); }: { - assert!( as TradeExecution>::calculate_sell(PoolType::Stableswap(pool_id), asset_in, asset_out, amount_sell).is_ok()); - assert!( as TradeExecution>::execute_sell(RawOrigin::Signed(seller.clone()).into(), PoolType::Stableswap(pool_id), asset_in, asset_out, amount_sell, buy_min_amount).is_ok()); + if c != 0 { + assert!( as TradeExecution>::calculate_sell(PoolType::Stableswap(pool_id), asset_in, asset_out, amount_sell).is_ok()); + } + if e != 0 { + assert!( as TradeExecution>::execute_sell(RawOrigin::Signed(seller.clone()).into(), PoolType::Stableswap(pool_id), asset_in, asset_out, amount_sell, buy_min_amount).is_ok()); + } } verify { - assert_eq!(T::Currency::free_balance(asset_in, &seller), 0u128); - assert_eq!(T::Currency::free_balance(asset_out, &seller), 98_999_980_239_523); + if e != 0 { + assert_eq!(T::Currency::free_balance(asset_in, &seller), 0u128); + assert_eq!(T::Currency::free_balance(asset_out, &seller), 98_999_980_239_523); + } } router_execution_buy{ + let c in 1..2; // number of times calculate_buy is executed + let e in 0..1; // if e == 1, execute_buy is executed + let caller: T::AccountId = account("caller", 0, 1); let lp_provider: T::AccountId = account("provider", 0, 1); let initial_liquidity = 1_000_000_000_000_000_000u128; @@ -583,12 +595,18 @@ benchmarks! { )?; System::::set_block_number(500u32.into()); }: { - assert!( as TradeExecution>::calculate_buy(PoolType::Stableswap(pool_id), asset_in, asset_out, amount_buy).is_ok()); - assert!( as TradeExecution>::execute_buy(RawOrigin::Signed(buyer.clone()).into(), PoolType::Stableswap(pool_id), asset_in, asset_out, amount_buy, sell_max_limit).is_ok()); + for _ in 1..c { + assert!( as TradeExecution>::calculate_buy(PoolType::Stableswap(pool_id), asset_in, asset_out, amount_buy).is_ok()); + } + if e != 0 { + assert!( as TradeExecution>::execute_buy(RawOrigin::Signed(buyer.clone()).into(), PoolType::Stableswap(pool_id), asset_in, asset_out, amount_buy, sell_max_limit).is_ok()); + } } verify { - assert_eq!(T::Currency::free_balance(asset_out, &buyer), 10_000_000_000_000); - assert_eq!(T::Currency::free_balance(asset_in, &buyer), 89_899_999_798_401); + if e != 0 { + assert_eq!(T::Currency::free_balance(asset_out, &buyer), 10_000_000_000_000); + assert_eq!(T::Currency::free_balance(asset_in, &buyer), 89_899_999_798_401); + } } impl_benchmark_test_suite!(Pallet, crate::tests::mock::ExtBuilder::default().build(), crate::tests::mock::Test); diff --git a/pallets/stableswap/src/weights.rs b/pallets/stableswap/src/weights.rs index 33ac8ef19..c2f22cafd 100644 --- a/pallets/stableswap/src/weights.rs +++ b/pallets/stableswap/src/weights.rs @@ -18,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-09-13, STEPS: 10, REPEAT: 30, LOW RANGE: [], HIGH RANGE: [] +//! DATE: 2023-10-06, STEPS: 10, REPEAT: 30, LOW RANGE: [], HIGH RANGE: [] //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 // Executed Command: @@ -31,7 +31,7 @@ // --execution=wasm // --wasm-execution=compiled // --heap-pages=4096 -// --template=.maintain/pallet-weight-template.hbs +// --template=.maintain/pallet-weight-template-no-back.hbs // --pallet=pallet-stableswap // --output=stableswap.rs // --extrinsic=* @@ -58,8 +58,8 @@ pub trait WeightInfo { fn set_asset_tradable_state() -> Weight; fn update_pool_fee() -> Weight; fn update_amplification() -> Weight; - fn router_execution_sell() -> Weight; - fn router_execution_buy() -> Weight; + fn router_execution_sell(c: u32, e: u32) -> Weight; + fn router_execution_buy(c: u32, e: u32) -> Weight; } /// Weights for pallet_stableswap using the hydraDX node and recommended hardware. @@ -73,8 +73,8 @@ impl WeightInfo for HydraWeight { // 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 { - // Minimum execution time: 50_796 nanoseconds. - Weight::from_ref_time(51_251_000 as u64) + // Minimum execution time: 50_068 nanoseconds. + Weight::from_ref_time(50_557_000 as u64) .saturating_add(T::DbWeight::get().reads(7 as u64)) .saturating_add(T::DbWeight::get().writes(2 as u64)) } @@ -96,11 +96,13 @@ impl WeightInfo for HydraWeight { // 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: 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 { - // Minimum execution time: 888_793 nanoseconds. - Weight::from_ref_time(891_474_000 as u64) - .saturating_add(T::DbWeight::get().reads(32 as u64)) - .saturating_add(T::DbWeight::get().writes(13 as u64)) + // Minimum execution time: 1_140_516 nanoseconds. + Weight::from_ref_time(1_143_845_000 as u64) + .saturating_add(T::DbWeight::get().reads(33 as u64)) + .saturating_add(T::DbWeight::get().writes(14 as u64)) } // Storage: Stableswap Pools (r:1 w:0) // Proof: Stableswap Pools (max_values: None, max_size: Some(57), added: 2532, mode: MaxEncodedLen) @@ -118,11 +120,13 @@ impl WeightInfo for HydraWeight { // 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: 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 { - // Minimum execution time: 488_333 nanoseconds. - Weight::from_ref_time(489_891_000 as u64) - .saturating_add(T::DbWeight::get().reads(19 as u64)) - .saturating_add(T::DbWeight::get().writes(5 as u64)) + // Minimum execution time: 783_827 nanoseconds. + Weight::from_ref_time(787_422_000 as u64) + .saturating_add(T::DbWeight::get().reads(20 as u64)) + .saturating_add(T::DbWeight::get().writes(6 as u64)) } // Storage: Stableswap AssetTradability (r:1 w:0) // Proof: Stableswap AssetTradability (max_values: None, max_size: Some(41), added: 2516, mode: MaxEncodedLen) @@ -140,13 +144,15 @@ impl WeightInfo for HydraWeight { // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, 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) + // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(5921), added: 6416, mode: MaxEncodedLen) // Storage: MultiTransactionPayment AccountCurrencyMap (r:0 w:1) // Proof: MultiTransactionPayment AccountCurrencyMap (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) fn remove_liquidity_one_asset() -> Weight { - // Minimum execution time: 519_711 nanoseconds. - Weight::from_ref_time(521_236_000 as u64) - .saturating_add(T::DbWeight::get().reads(20 as u64)) - .saturating_add(T::DbWeight::get().writes(6 as u64)) + // Minimum execution time: 817_053 nanoseconds. + Weight::from_ref_time(821_506_000 as u64) + .saturating_add(T::DbWeight::get().reads(21 as u64)) + .saturating_add(T::DbWeight::get().writes(7 as u64)) } // Storage: Stableswap AssetTradability (r:1 w:0) // Proof: Stableswap AssetTradability (max_values: None, max_size: Some(41), added: 2516, mode: MaxEncodedLen) @@ -166,11 +172,13 @@ impl WeightInfo for HydraWeight { // 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: EmaOracle Accumulator (r:1 w:1) + // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(5921), added: 6416, mode: MaxEncodedLen) fn withdraw_asset_amount() -> Weight { - // Minimum execution time: 796_068 nanoseconds. - Weight::from_ref_time(799_553_000 as u64) - .saturating_add(T::DbWeight::get().reads(21 as u64)) - .saturating_add(T::DbWeight::get().writes(5 as u64)) + // Minimum execution time: 1_124_456 nanoseconds. + Weight::from_ref_time(1_133_226_000 as u64) + .saturating_add(T::DbWeight::get().reads(22 as u64)) + .saturating_add(T::DbWeight::get().writes(6 as u64)) } // Storage: Stableswap AssetTradability (r:2 w:0) // Proof: Stableswap AssetTradability (max_values: None, max_size: Some(41), added: 2516, mode: MaxEncodedLen) @@ -186,13 +194,17 @@ impl WeightInfo for HydraWeight { // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) // Storage: MultiTransactionPayment AcceptedCurrencies (r:1 w:0) // Proof: MultiTransactionPayment AcceptedCurrencies (max_values: None, max_size: Some(28), added: 2503, mode: MaxEncodedLen) + // Storage: Tokens TotalIssuance (r:1 w:0) + // 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: MultiTransactionPayment AccountCurrencyMap (r:0 w:1) // Proof: MultiTransactionPayment AccountCurrencyMap (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) fn sell() -> Weight { - // Minimum execution time: 445_565 nanoseconds. - Weight::from_ref_time(446_960_000 as u64) - .saturating_add(T::DbWeight::get().reads(20 as u64)) - .saturating_add(T::DbWeight::get().writes(6 as u64)) + // Minimum execution time: 768_776 nanoseconds. + Weight::from_ref_time(772_108_000 as u64) + .saturating_add(T::DbWeight::get().reads(22 as u64)) + .saturating_add(T::DbWeight::get().writes(7 as u64)) } // Storage: Stableswap AssetTradability (r:2 w:0) // Proof: Stableswap AssetTradability (max_values: None, max_size: Some(41), added: 2516, mode: MaxEncodedLen) @@ -210,35 +222,39 @@ impl WeightInfo for HydraWeight { // 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: Tokens TotalIssuance (r:1 w:0) + // 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 buy() -> Weight { - // Minimum execution time: 432_808 nanoseconds. - Weight::from_ref_time(433_580_000 as u64) - .saturating_add(T::DbWeight::get().reads(21 as u64)) - .saturating_add(T::DbWeight::get().writes(5 as u64)) + // Minimum execution time: 747_434 nanoseconds. + Weight::from_ref_time(751_463_000 as u64) + .saturating_add(T::DbWeight::get().reads(23 as u64)) + .saturating_add(T::DbWeight::get().writes(6 as u64)) } // Storage: Stableswap Pools (r:1 w:0) // Proof: Stableswap Pools (max_values: None, max_size: Some(57), added: 2532, mode: MaxEncodedLen) // Storage: Stableswap AssetTradability (r:1 w:1) // Proof: Stableswap AssetTradability (max_values: None, max_size: Some(41), added: 2516, mode: MaxEncodedLen) fn set_asset_tradable_state() -> Weight { - // Minimum execution time: 24_372 nanoseconds. - Weight::from_ref_time(24_699_000 as u64) + // Minimum execution time: 24_470 nanoseconds. + Weight::from_ref_time(24_889_000 as u64) .saturating_add(T::DbWeight::get().reads(2 as u64)) .saturating_add(T::DbWeight::get().writes(1 as u64)) } // Storage: Stableswap Pools (r:1 w:1) // Proof: Stableswap Pools (max_values: None, max_size: Some(57), added: 2532, mode: MaxEncodedLen) fn update_pool_fee() -> Weight { - // Minimum execution time: 22_580 nanoseconds. - Weight::from_ref_time(22_822_000 as u64) + // Minimum execution time: 22_217 nanoseconds. + Weight::from_ref_time(22_890_000 as u64) .saturating_add(T::DbWeight::get().reads(1 as u64)) .saturating_add(T::DbWeight::get().writes(1 as u64)) } // Storage: Stableswap Pools (r:1 w:1) // Proof: Stableswap Pools (max_values: None, max_size: Some(57), added: 2532, mode: MaxEncodedLen) fn update_amplification() -> Weight { - // Minimum execution time: 23_990 nanoseconds. - Weight::from_ref_time(24_487_000 as u64) + // Minimum execution time: 24_168 nanoseconds. + Weight::from_ref_time(24_902_000 as u64) .saturating_add(T::DbWeight::get().reads(1 as u64)) .saturating_add(T::DbWeight::get().writes(1 as u64)) } @@ -256,13 +272,23 @@ impl WeightInfo for HydraWeight { // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) // Storage: MultiTransactionPayment AcceptedCurrencies (r:1 w:0) // Proof: MultiTransactionPayment AcceptedCurrencies (max_values: None, max_size: Some(28), added: 2503, mode: MaxEncodedLen) + // Storage: Tokens TotalIssuance (r:1 w:0) + // 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: MultiTransactionPayment AccountCurrencyMap (r:0 w:1) // Proof: MultiTransactionPayment AccountCurrencyMap (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) - fn router_execution_sell() -> Weight { - // Minimum execution time: 739_292 nanoseconds. - Weight::from_ref_time(740_883_000 as u64) - .saturating_add(T::DbWeight::get().reads(20 as u64)) - .saturating_add(T::DbWeight::get().writes(6 as u64)) + /// The range of component `c` is `[0, 1]`. + /// The range of component `e` is `[0, 1]`. + fn router_execution_sell(c: u32, e: u32) -> Weight { + // Minimum execution time: 333_504 nanoseconds. + Weight::from_ref_time(30_352_727 as u64) // Standard Error: 262_827 + .saturating_add(Weight::from_ref_time(304_810_632 as u64).saturating_mul(c as u64)) + // Standard Error: 262_827 + .saturating_add(Weight::from_ref_time(742_434_706 as u64).saturating_mul(e as u64)) + .saturating_add(T::DbWeight::get().reads(11 as u64)) + .saturating_add(T::DbWeight::get().reads((11 as u64).saturating_mul(e as u64))) + .saturating_add(T::DbWeight::get().writes((7 as u64).saturating_mul(e as u64))) } // Storage: Stableswap Pools (r:1 w:0) // Proof: Stableswap Pools (max_values: None, max_size: Some(57), added: 2532, mode: MaxEncodedLen) @@ -280,11 +306,21 @@ impl WeightInfo for HydraWeight { // 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) - fn router_execution_buy() -> Weight { - // Minimum execution time: 726_292 nanoseconds. - Weight::from_ref_time(727_824_000 as u64) - .saturating_add(T::DbWeight::get().reads(21 as u64)) - .saturating_add(T::DbWeight::get().writes(5 as u64)) + // Storage: Tokens TotalIssuance (r:1 w:0) + // 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) + /// 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 { + // Minimum execution time: 333_253 nanoseconds. + Weight::from_ref_time(334_206_000 as u64) // Standard Error: 3_608_102 + .saturating_add(Weight::from_ref_time(13_465_646 as u64).saturating_mul(c as u64)) + // Standard Error: 7_920_813 + .saturating_add(Weight::from_ref_time(456_375_218 as u64).saturating_mul(e as u64)) + .saturating_add(T::DbWeight::get().reads(11 as u64)) + .saturating_add(T::DbWeight::get().reads((12 as u64).saturating_mul(e as u64))) + .saturating_add(T::DbWeight::get().writes((6 as u64).saturating_mul(e as u64))) } } @@ -297,10 +333,10 @@ impl WeightInfo for () { // 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 { - // Minimum execution time: 50_796 nanoseconds. - Weight::from_ref_time(51_251_000) - .saturating_add(RocksDbWeight::get().reads(7)) - .saturating_add(RocksDbWeight::get().writes(2)) + // Minimum execution time: 50_068 nanoseconds. + Weight::from_ref_time(50_557_000 as u64) + .saturating_add(RocksDbWeight::get().reads(7 as u64)) + .saturating_add(RocksDbWeight::get().writes(2 as u64)) } // Storage: Stableswap Pools (r:1 w:0) // Proof: Stableswap Pools (max_values: None, max_size: Some(57), added: 2532, mode: MaxEncodedLen) @@ -320,11 +356,13 @@ impl WeightInfo for () { // 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: 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 { - // Minimum execution time: 888_793 nanoseconds. - Weight::from_ref_time(891_474_000) - .saturating_add(RocksDbWeight::get().reads(32)) - .saturating_add(RocksDbWeight::get().writes(13)) + // Minimum execution time: 1_140_516 nanoseconds. + Weight::from_ref_time(1_143_845_000 as u64) + .saturating_add(RocksDbWeight::get().reads(33 as u64)) + .saturating_add(RocksDbWeight::get().writes(14 as u64)) } // Storage: Stableswap Pools (r:1 w:0) // Proof: Stableswap Pools (max_values: None, max_size: Some(57), added: 2532, mode: MaxEncodedLen) @@ -342,11 +380,13 @@ impl WeightInfo for () { // 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: 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 { - // Minimum execution time: 488_333 nanoseconds. - Weight::from_ref_time(489_891_000) - .saturating_add(RocksDbWeight::get().reads(19)) - .saturating_add(RocksDbWeight::get().writes(5)) + // Minimum execution time: 783_827 nanoseconds. + Weight::from_ref_time(787_422_000 as u64) + .saturating_add(RocksDbWeight::get().reads(20 as u64)) + .saturating_add(RocksDbWeight::get().writes(6 as u64)) } // Storage: Stableswap AssetTradability (r:1 w:0) // Proof: Stableswap AssetTradability (max_values: None, max_size: Some(41), added: 2516, mode: MaxEncodedLen) @@ -364,13 +404,15 @@ impl WeightInfo for () { // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, 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) + // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(5921), added: 6416, mode: MaxEncodedLen) // Storage: MultiTransactionPayment AccountCurrencyMap (r:0 w:1) // Proof: MultiTransactionPayment AccountCurrencyMap (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) fn remove_liquidity_one_asset() -> Weight { - // Minimum execution time: 519_711 nanoseconds. - Weight::from_ref_time(521_236_000) - .saturating_add(RocksDbWeight::get().reads(20)) - .saturating_add(RocksDbWeight::get().writes(6)) + // Minimum execution time: 817_053 nanoseconds. + Weight::from_ref_time(821_506_000 as u64) + .saturating_add(RocksDbWeight::get().reads(21 as u64)) + .saturating_add(RocksDbWeight::get().writes(7 as u64)) } // Storage: Stableswap AssetTradability (r:1 w:0) // Proof: Stableswap AssetTradability (max_values: None, max_size: Some(41), added: 2516, mode: MaxEncodedLen) @@ -390,11 +432,13 @@ impl WeightInfo for () { // 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: EmaOracle Accumulator (r:1 w:1) + // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(5921), added: 6416, mode: MaxEncodedLen) fn withdraw_asset_amount() -> Weight { - // Minimum execution time: 796_068 nanoseconds. - Weight::from_ref_time(799_553_000) - .saturating_add(RocksDbWeight::get().reads(21)) - .saturating_add(RocksDbWeight::get().writes(5)) + // Minimum execution time: 1_124_456 nanoseconds. + Weight::from_ref_time(1_133_226_000 as u64) + .saturating_add(RocksDbWeight::get().reads(22 as u64)) + .saturating_add(RocksDbWeight::get().writes(6 as u64)) } // Storage: Stableswap AssetTradability (r:2 w:0) // Proof: Stableswap AssetTradability (max_values: None, max_size: Some(41), added: 2516, mode: MaxEncodedLen) @@ -410,13 +454,17 @@ impl WeightInfo for () { // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) // Storage: MultiTransactionPayment AcceptedCurrencies (r:1 w:0) // Proof: MultiTransactionPayment AcceptedCurrencies (max_values: None, max_size: Some(28), added: 2503, mode: MaxEncodedLen) + // Storage: Tokens TotalIssuance (r:1 w:0) + // 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: MultiTransactionPayment AccountCurrencyMap (r:0 w:1) // Proof: MultiTransactionPayment AccountCurrencyMap (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) fn sell() -> Weight { - // Minimum execution time: 445_565 nanoseconds. - Weight::from_ref_time(446_960_000) - .saturating_add(RocksDbWeight::get().reads(20)) - .saturating_add(RocksDbWeight::get().writes(6)) + // Minimum execution time: 768_776 nanoseconds. + Weight::from_ref_time(772_108_000 as u64) + .saturating_add(RocksDbWeight::get().reads(22 as u64)) + .saturating_add(RocksDbWeight::get().writes(7 as u64)) } // Storage: Stableswap AssetTradability (r:2 w:0) // Proof: Stableswap AssetTradability (max_values: None, max_size: Some(41), added: 2516, mode: MaxEncodedLen) @@ -434,37 +482,41 @@ impl WeightInfo for () { // 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: Tokens TotalIssuance (r:1 w:0) + // 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 buy() -> Weight { - // Minimum execution time: 432_808 nanoseconds. - Weight::from_ref_time(433_580_000) - .saturating_add(RocksDbWeight::get().reads(21)) - .saturating_add(RocksDbWeight::get().writes(5)) + // Minimum execution time: 747_434 nanoseconds. + Weight::from_ref_time(751_463_000 as u64) + .saturating_add(RocksDbWeight::get().reads(23 as u64)) + .saturating_add(RocksDbWeight::get().writes(6 as u64)) } // Storage: Stableswap Pools (r:1 w:0) // Proof: Stableswap Pools (max_values: None, max_size: Some(57), added: 2532, mode: MaxEncodedLen) // Storage: Stableswap AssetTradability (r:1 w:1) // Proof: Stableswap AssetTradability (max_values: None, max_size: Some(41), added: 2516, mode: MaxEncodedLen) fn set_asset_tradable_state() -> Weight { - // Minimum execution time: 24_372 nanoseconds. - Weight::from_ref_time(24_699_000) - .saturating_add(RocksDbWeight::get().reads(2)) - .saturating_add(RocksDbWeight::get().writes(1)) + // Minimum execution time: 24_470 nanoseconds. + Weight::from_ref_time(24_889_000 as u64) + .saturating_add(RocksDbWeight::get().reads(2 as u64)) + .saturating_add(RocksDbWeight::get().writes(1 as u64)) } // Storage: Stableswap Pools (r:1 w:1) // Proof: Stableswap Pools (max_values: None, max_size: Some(57), added: 2532, mode: MaxEncodedLen) fn update_pool_fee() -> Weight { - // Minimum execution time: 22_580 nanoseconds. - Weight::from_ref_time(22_822_000) - .saturating_add(RocksDbWeight::get().reads(1)) - .saturating_add(RocksDbWeight::get().writes(1)) + // Minimum execution time: 22_217 nanoseconds. + Weight::from_ref_time(22_890_000 as u64) + .saturating_add(RocksDbWeight::get().reads(1 as u64)) + .saturating_add(RocksDbWeight::get().writes(1 as u64)) } // Storage: Stableswap Pools (r:1 w:1) // Proof: Stableswap Pools (max_values: None, max_size: Some(57), added: 2532, mode: MaxEncodedLen) fn update_amplification() -> Weight { - // Minimum execution time: 23_990 nanoseconds. - Weight::from_ref_time(24_487_000) - .saturating_add(RocksDbWeight::get().reads(1)) - .saturating_add(RocksDbWeight::get().writes(1)) + // Minimum execution time: 24_168 nanoseconds. + Weight::from_ref_time(24_902_000 as u64) + .saturating_add(RocksDbWeight::get().reads(1 as u64)) + .saturating_add(RocksDbWeight::get().writes(1 as u64)) } // Storage: Stableswap Pools (r:1 w:0) // Proof: Stableswap Pools (max_values: None, max_size: Some(57), added: 2532, mode: MaxEncodedLen) @@ -480,13 +532,23 @@ impl WeightInfo for () { // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) // Storage: MultiTransactionPayment AcceptedCurrencies (r:1 w:0) // Proof: MultiTransactionPayment AcceptedCurrencies (max_values: None, max_size: Some(28), added: 2503, mode: MaxEncodedLen) + // Storage: Tokens TotalIssuance (r:1 w:0) + // 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: MultiTransactionPayment AccountCurrencyMap (r:0 w:1) // Proof: MultiTransactionPayment AccountCurrencyMap (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) - fn router_execution_sell() -> Weight { - // Minimum execution time: 739_292 nanoseconds. - Weight::from_ref_time(740_883_000) - .saturating_add(RocksDbWeight::get().reads(20)) - .saturating_add(RocksDbWeight::get().writes(6)) + /// The range of component `c` is `[0, 1]`. + /// The range of component `e` is `[0, 1]`. + fn router_execution_sell(c: u32, e: u32) -> Weight { + // Minimum execution time: 333_504 nanoseconds. + Weight::from_ref_time(30_352_727 as u64) // Standard Error: 262_827 + .saturating_add(Weight::from_ref_time(304_810_632 as u64).saturating_mul(c as u64)) + // Standard Error: 262_827 + .saturating_add(Weight::from_ref_time(742_434_706 as u64).saturating_mul(e as u64)) + .saturating_add(RocksDbWeight::get().reads(11 as u64)) + .saturating_add(RocksDbWeight::get().reads((11 as u64).saturating_mul(e as u64))) + .saturating_add(RocksDbWeight::get().writes((7 as u64).saturating_mul(e as u64))) } // Storage: Stableswap Pools (r:1 w:0) // Proof: Stableswap Pools (max_values: None, max_size: Some(57), added: 2532, mode: MaxEncodedLen) @@ -504,10 +566,20 @@ impl WeightInfo for () { // 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) - fn router_execution_buy() -> Weight { - // Minimum execution time: 726_292 nanoseconds. - Weight::from_ref_time(727_824_000) - .saturating_add(RocksDbWeight::get().reads(21)) - .saturating_add(RocksDbWeight::get().writes(5)) + // Storage: Tokens TotalIssuance (r:1 w:0) + // 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) + /// 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 { + // Minimum execution time: 333_253 nanoseconds. + Weight::from_ref_time(334_206_000 as u64) // Standard Error: 3_608_102 + .saturating_add(Weight::from_ref_time(13_465_646 as u64).saturating_mul(c as u64)) + // Standard Error: 7_920_813 + .saturating_add(Weight::from_ref_time(456_375_218 as u64).saturating_mul(e as u64)) + .saturating_add(RocksDbWeight::get().reads(11 as u64)) + .saturating_add(RocksDbWeight::get().reads((12 as u64).saturating_mul(e as u64))) + .saturating_add(RocksDbWeight::get().writes((6 as u64).saturating_mul(e as u64))) } } diff --git a/pallets/xyk/Cargo.toml b/pallets/xyk/Cargo.toml index eb5c6565b..4c88f9acc 100644 --- a/pallets/xyk/Cargo.toml +++ b/pallets/xyk/Cargo.toml @@ -1,6 +1,6 @@ [package] name = 'pallet-xyk' -version = "6.2.9" +version = "6.2.10" description = 'XYK automated market maker' authors = ['GalacticCouncil'] edition = '2021' diff --git a/pallets/xyk/src/benchmarking.rs b/pallets/xyk/src/benchmarking.rs index c666b127b..6b6acc765 100644 --- a/pallets/xyk/src/benchmarking.rs +++ b/pallets/xyk/src/benchmarking.rs @@ -124,7 +124,10 @@ benchmarks! { assert_eq!(T::Currency::free_balance(asset_a, &caller), 1000001000000000); } - trade_execution_sell { + 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); @@ -138,14 +141,23 @@ benchmarks! { XYK::::create_pool(RawOrigin::Signed(maker).into(), asset_a, 1_000_000_000_000, asset_b, 3_000_000_000_000)?; }: { - assert!( as TradeExecution>::calculate_sell(PoolType::XYK, asset_a, asset_b, amount).is_ok()); - assert!( as TradeExecution>::execute_sell(RawOrigin::Signed(caller.clone()).into(), PoolType::XYK, asset_a, asset_b, amount, min_bought).is_ok()); + 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{ - assert_eq!(T::Currency::free_balance(asset_a, &caller), 999999000000000); + if e != 0 { + assert_eq!(T::Currency::free_balance(asset_a, &caller), 999999000000000); + } } - trade_execution_buy { + 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); @@ -159,11 +171,17 @@ benchmarks! { XYK::::create_pool(RawOrigin::Signed(maker).into(), asset_a, 1_000_000_000_000, asset_b, 3_000_000_000_000)?; }: { - assert!( as TradeExecution>::calculate_buy(PoolType::XYK, asset_a, asset_b, amount).is_ok()); - assert!( as TradeExecution>::execute_buy(RawOrigin::Signed(caller.clone()).into(), PoolType::XYK, asset_a, asset_b, amount, max_sold).is_ok()); + 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{ - assert_eq!(T::Currency::free_balance(asset_b, &caller), 1000001000000000); + if e != 0 { + assert_eq!(T::Currency::free_balance(asset_b, &caller), 1000001000000000); + } } } @@ -182,8 +200,8 @@ mod tests { assert_ok!(Pallet::::test_benchmark_remove_liquidity()); assert_ok!(Pallet::::test_benchmark_sell()); assert_ok!(Pallet::::test_benchmark_buy()); - assert_ok!(Pallet::::test_benchmark_trade_execution_sell()); - assert_ok!(Pallet::::test_benchmark_trade_execution_buy()); + assert_ok!(Pallet::::test_benchmark_router_execution_sell()); + assert_ok!(Pallet::::test_benchmark_router_execution_buy()); }); } } diff --git a/pallets/xyk/src/weights.rs b/pallets/xyk/src/weights.rs index d3ccddc4b..f8ddf13e4 100644 --- a/pallets/xyk/src/weights.rs +++ b/pallets/xyk/src/weights.rs @@ -18,7 +18,7 @@ //! Autogenerated weights for pallet_xyk //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-09-12, STEPS: 10, REPEAT: 30, LOW RANGE: [], HIGH RANGE: [] +//! DATE: 2023-10-06, STEPS: 10, REPEAT: 30, LOW RANGE: [], HIGH RANGE: [] //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 // Executed Command: @@ -31,7 +31,7 @@ // --execution=wasm // --wasm-execution=compiled // --heap-pages=4096 -// --template=.maintain/pallet-weight-template.hbs +// --template=.maintain/pallet-weight-template-no-back.hbs // --pallet=pallet-xyk // --output=xyk.rs // --extrinsic=* @@ -53,16 +53,14 @@ pub trait WeightInfo { fn remove_liquidity() -> Weight; fn sell() -> Weight; fn buy() -> Weight; - fn trade_execution_sell() -> Weight; - fn trade_execution_buy() -> Weight; + fn router_execution_sell(c: u32, e: u32) -> Weight; + fn router_execution_buy(c: u32, e: u32) -> Weight; } /// Weights for amm using the hydraDX node and recommended hardware. pub struct HydraWeight(PhantomData); impl WeightInfo for HydraWeight { - // Storage: ParachainSystem ValidationData (r:1 w:0) - // Proof Skipped: ParachainSystem ValidationData (max_values: Some(1), max_size: None, mode: Measured) // 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) @@ -90,9 +88,9 @@ impl WeightInfo for HydraWeight { // 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 { - // Minimum execution time: 187_840 nanoseconds. - Weight::from_ref_time(189_082_000 as u64) - .saturating_add(T::DbWeight::get().reads(18 as u64)) + // Minimum execution time: 190_185 nanoseconds. + Weight::from_ref_time(192_567_000 as u64) + .saturating_add(T::DbWeight::get().reads(17 as u64)) .saturating_add(T::DbWeight::get().writes(16 as u64)) } // Storage: XYK ShareToken (r:1 w:0) @@ -110,10 +108,10 @@ impl WeightInfo for HydraWeight { // Storage: MultiTransactionPayment AccountCurrencyMap (r:1 w:0) // Proof: MultiTransactionPayment AccountCurrencyMap (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) // Storage: EmaOracle Accumulator (r:1 w:1) - // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(2961), added: 3456, mode: MaxEncodedLen) + // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(5921), added: 6416, mode: MaxEncodedLen) fn add_liquidity() -> Weight { - // Minimum execution time: 162_714 nanoseconds. - Weight::from_ref_time(164_334_000 as u64) + // Minimum execution time: 164_323 nanoseconds. + Weight::from_ref_time(165_841_000 as u64) .saturating_add(T::DbWeight::get().reads(14 as u64)) .saturating_add(T::DbWeight::get().writes(9 as u64)) } @@ -130,10 +128,10 @@ impl WeightInfo for HydraWeight { // 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(2961), added: 3456, mode: MaxEncodedLen) + // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(5921), added: 6416, mode: MaxEncodedLen) fn remove_liquidity() -> Weight { - // Minimum execution time: 153_979 nanoseconds. - Weight::from_ref_time(155_943_000 as u64) + // Minimum execution time: 155_404 nanoseconds. + Weight::from_ref_time(156_560_000 as u64) .saturating_add(T::DbWeight::get().reads(13 as u64)) .saturating_add(T::DbWeight::get().writes(8 as u64)) } @@ -146,10 +144,10 @@ impl WeightInfo for HydraWeight { // Storage: System Account (r:2 w:0) // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) // Storage: EmaOracle Accumulator (r:1 w:1) - // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(2961), added: 3456, mode: MaxEncodedLen) + // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(5921), added: 6416, mode: MaxEncodedLen) fn sell() -> Weight { - // Minimum execution time: 117_084 nanoseconds. - Weight::from_ref_time(118_146_000 as u64) + // Minimum execution time: 119_610 nanoseconds. + Weight::from_ref_time(120_418_000 as u64) .saturating_add(T::DbWeight::get().reads(10 as u64)) .saturating_add(T::DbWeight::get().writes(5 as u64)) } @@ -162,10 +160,10 @@ impl WeightInfo for HydraWeight { // Storage: System Account (r:2 w:0) // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) // Storage: EmaOracle Accumulator (r:1 w:1) - // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(2961), added: 3456, mode: MaxEncodedLen) + // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(5921), added: 6416, mode: MaxEncodedLen) fn buy() -> Weight { - // Minimum execution time: 117_724 nanoseconds. - Weight::from_ref_time(118_763_000 as u64) + // Minimum execution time: 119_865 nanoseconds. + Weight::from_ref_time(120_541_000 as u64) .saturating_add(T::DbWeight::get().reads(10 as u64)) .saturating_add(T::DbWeight::get().writes(5 as u64)) } @@ -178,12 +176,18 @@ impl WeightInfo for HydraWeight { // Storage: System Account (r:2 w:0) // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) // Storage: EmaOracle Accumulator (r:1 w:1) - // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(2961), added: 3456, mode: MaxEncodedLen) - fn trade_execution_sell() -> Weight { - // Minimum execution time: 123_509 nanoseconds. - Weight::from_ref_time(124_413_000 as u64) - .saturating_add(T::DbWeight::get().reads(10 as u64)) - .saturating_add(T::DbWeight::get().writes(5 as u64)) + // 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 { + // Minimum execution time: 20_906 nanoseconds. + Weight::from_ref_time(8_365_948 as u64) // Standard Error: 43_229 + .saturating_add(Weight::from_ref_time(6_554_981 as u64).saturating_mul(c as u64)) + // Standard Error: 43_229 + .saturating_add(Weight::from_ref_time(105_218_621 as u64).saturating_mul(e as u64)) + .saturating_add(T::DbWeight::get().reads(3 as u64)) + .saturating_add(T::DbWeight::get().reads((7 as u64).saturating_mul(e as u64))) + .saturating_add(T::DbWeight::get().writes((5 as u64).saturating_mul(e as u64))) } // Storage: XYK ShareToken (r:1 w:0) // Proof: XYK ShareToken (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) @@ -194,19 +198,23 @@ impl WeightInfo for HydraWeight { // Storage: System Account (r:2 w:0) // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) // Storage: EmaOracle Accumulator (r:1 w:1) - // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(2961), added: 3456, mode: MaxEncodedLen) - fn trade_execution_buy() -> Weight { - // Minimum execution time: 122_535 nanoseconds. - Weight::from_ref_time(124_302_000 as u64) - .saturating_add(T::DbWeight::get().reads(10 as u64)) - .saturating_add(T::DbWeight::get().writes(5 as u64)) + // 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 { + // Minimum execution time: 27_261 nanoseconds. + Weight::from_ref_time(7_044_054 as u64) // Standard Error: 46_197 + .saturating_add(Weight::from_ref_time(7_022_106 as u64).saturating_mul(c as u64)) + // Standard Error: 78_379 + .saturating_add(Weight::from_ref_time(105_927_586 as u64).saturating_mul(e as u64)) + .saturating_add(T::DbWeight::get().reads(3 as u64)) + .saturating_add(T::DbWeight::get().reads((7 as u64).saturating_mul(e as u64))) + .saturating_add(T::DbWeight::get().writes((5 as u64).saturating_mul(e as u64))) } } // For backwards compatibility and tests impl WeightInfo for () { - // Storage: ParachainSystem ValidationData (r:1 w:0) - // Proof Skipped: ParachainSystem ValidationData (max_values: Some(1), max_size: None, mode: Measured) // 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) @@ -234,9 +242,9 @@ impl WeightInfo for () { // 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 { - // Minimum execution time: 187_840 nanoseconds. - Weight::from_ref_time(189_082_000 as u64) - .saturating_add(RocksDbWeight::get().reads(18 as u64)) + // Minimum execution time: 190_185 nanoseconds. + Weight::from_ref_time(192_567_000 as u64) + .saturating_add(RocksDbWeight::get().reads(17 as u64)) .saturating_add(RocksDbWeight::get().writes(16 as u64)) } // Storage: XYK ShareToken (r:1 w:0) @@ -254,10 +262,10 @@ impl WeightInfo for () { // Storage: MultiTransactionPayment AccountCurrencyMap (r:1 w:0) // Proof: MultiTransactionPayment AccountCurrencyMap (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) // Storage: EmaOracle Accumulator (r:1 w:1) - // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(2961), added: 3456, mode: MaxEncodedLen) + // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(5921), added: 6416, mode: MaxEncodedLen) fn add_liquidity() -> Weight { - // Minimum execution time: 162_714 nanoseconds. - Weight::from_ref_time(164_334_000 as u64) + // Minimum execution time: 164_323 nanoseconds. + Weight::from_ref_time(165_841_000 as u64) .saturating_add(RocksDbWeight::get().reads(14 as u64)) .saturating_add(RocksDbWeight::get().writes(9 as u64)) } @@ -274,10 +282,10 @@ impl WeightInfo for () { // 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(2961), added: 3456, mode: MaxEncodedLen) + // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(5921), added: 6416, mode: MaxEncodedLen) fn remove_liquidity() -> Weight { - // Minimum execution time: 153_979 nanoseconds. - Weight::from_ref_time(155_943_000 as u64) + // Minimum execution time: 155_404 nanoseconds. + Weight::from_ref_time(156_560_000 as u64) .saturating_add(RocksDbWeight::get().reads(13 as u64)) .saturating_add(RocksDbWeight::get().writes(8 as u64)) } @@ -290,10 +298,10 @@ impl WeightInfo for () { // Storage: System Account (r:2 w:0) // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) // Storage: EmaOracle Accumulator (r:1 w:1) - // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(2961), added: 3456, mode: MaxEncodedLen) + // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(5921), added: 6416, mode: MaxEncodedLen) fn sell() -> Weight { - // Minimum execution time: 117_084 nanoseconds. - Weight::from_ref_time(118_146_000 as u64) + // Minimum execution time: 119_610 nanoseconds. + Weight::from_ref_time(120_418_000 as u64) .saturating_add(RocksDbWeight::get().reads(10 as u64)) .saturating_add(RocksDbWeight::get().writes(5 as u64)) } @@ -306,10 +314,10 @@ impl WeightInfo for () { // Storage: System Account (r:2 w:0) // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) // Storage: EmaOracle Accumulator (r:1 w:1) - // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(2961), added: 3456, mode: MaxEncodedLen) + // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(5921), added: 6416, mode: MaxEncodedLen) fn buy() -> Weight { - // Minimum execution time: 117_724 nanoseconds. - Weight::from_ref_time(118_763_000 as u64) + // Minimum execution time: 119_865 nanoseconds. + Weight::from_ref_time(120_541_000 as u64) .saturating_add(RocksDbWeight::get().reads(10 as u64)) .saturating_add(RocksDbWeight::get().writes(5 as u64)) } @@ -322,12 +330,18 @@ impl WeightInfo for () { // Storage: System Account (r:2 w:0) // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) // Storage: EmaOracle Accumulator (r:1 w:1) - // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(2961), added: 3456, mode: MaxEncodedLen) - fn trade_execution_sell() -> Weight { - // Minimum execution time: 123_509 nanoseconds. - Weight::from_ref_time(124_413_000 as u64) - .saturating_add(RocksDbWeight::get().reads(10 as u64)) - .saturating_add(RocksDbWeight::get().writes(5 as u64)) + // 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 { + // Minimum execution time: 20_906 nanoseconds. + Weight::from_ref_time(8_365_948 as u64) // Standard Error: 43_229 + .saturating_add(Weight::from_ref_time(6_554_981 as u64).saturating_mul(c as u64)) + // Standard Error: 43_229 + .saturating_add(Weight::from_ref_time(105_218_621 as u64).saturating_mul(e as u64)) + .saturating_add(RocksDbWeight::get().reads(3 as u64)) + .saturating_add(RocksDbWeight::get().reads((7 as u64).saturating_mul(e as u64))) + .saturating_add(RocksDbWeight::get().writes((5 as u64).saturating_mul(e as u64))) } // Storage: XYK ShareToken (r:1 w:0) // Proof: XYK ShareToken (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) @@ -338,11 +352,17 @@ impl WeightInfo for () { // Storage: System Account (r:2 w:0) // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) // Storage: EmaOracle Accumulator (r:1 w:1) - // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(2961), added: 3456, mode: MaxEncodedLen) - fn trade_execution_buy() -> Weight { - // Minimum execution time: 122_535 nanoseconds. - Weight::from_ref_time(124_302_000 as u64) - .saturating_add(RocksDbWeight::get().reads(10 as u64)) - .saturating_add(RocksDbWeight::get().writes(5 as u64)) + // 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 { + // Minimum execution time: 27_261 nanoseconds. + Weight::from_ref_time(7_044_054 as u64) // Standard Error: 46_197 + .saturating_add(Weight::from_ref_time(7_022_106 as u64).saturating_mul(c as u64)) + // Standard Error: 78_379 + .saturating_add(Weight::from_ref_time(105_927_586 as u64).saturating_mul(e as u64)) + .saturating_add(RocksDbWeight::get().reads(3 as u64)) + .saturating_add(RocksDbWeight::get().reads((7 as u64).saturating_mul(e as u64))) + .saturating_add(RocksDbWeight::get().writes((5 as u64).saturating_mul(e as u64))) } } diff --git a/runtime/adapters/Cargo.toml b/runtime/adapters/Cargo.toml index 548b1ea1c..d2129fde7 100644 --- a/runtime/adapters/Cargo.toml +++ b/runtime/adapters/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hydradx-adapters" -version = "0.6.2" +version = "0.6.3" 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 f04ed220c..3dddb08a2 100644 --- a/runtime/adapters/src/tests/mock.rs +++ b/runtime/adapters/src/tests/mock.rs @@ -280,7 +280,6 @@ impl pallet_route_executor::Config for Test { type MaxNumberOfTrades = MaxNumberOfTrades; type Currency = MultiInspectAdapter; type AMM = Pools; - type AmmTradeWeights = (); type WeightInfo = (); } diff --git a/runtime/adapters/src/xcm_exchange.rs b/runtime/adapters/src/xcm_exchange.rs index 3469190f5..3473b0276 100644 --- a/runtime/adapters/src/xcm_exchange.rs +++ b/runtime/adapters/src/xcm_exchange.rs @@ -1,5 +1,4 @@ -use hydradx_traits::router::PoolType; -use hydradx_traits::router::Trade; +use hydradx_traits::router::{PoolType, Trade}; use orml_traits::MultiCurrency; use polkadot_xcm::latest::prelude::*; use sp_core::Get; @@ -72,7 +71,7 @@ where asset_out, amount.into(), min_buy_amount.into(), - vec![Trade { + vec![Trade:: { pool: Pool::get(), asset_in, asset_out, @@ -104,7 +103,7 @@ where asset_out, amount.into(), max_sell_amount.into(), - vec![Trade { + vec![Trade:: { pool: Pool::get(), asset_in, asset_out, diff --git a/runtime/hydradx/Cargo.toml b/runtime/hydradx/Cargo.toml index 92d67ea64..b8e1f245f 100644 --- a/runtime/hydradx/Cargo.toml +++ b/runtime/hydradx/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hydradx-runtime" -version = "181.0.0" +version = "182.0.0" authors = ["GalacticCouncil"] edition = "2021" license = "Apache 2.0" diff --git a/runtime/hydradx/src/assets.rs b/runtime/hydradx/src/assets.rs index 84145ec2e..ef408fae8 100644 --- a/runtime/hydradx/src/assets.rs +++ b/runtime/hydradx/src/assets.rs @@ -20,10 +20,13 @@ use crate::system::NativeAssetId; use hydradx_adapters::{ inspect::MultiInspectAdapter, EmaOraclePriceAdapter, FreezableNFT, MultiCurrencyLockedBalance, OmnipoolHookAdapter, - OracleAssetVolumeProvider, OraclePriceProvider, PriceAdjustmentAdapter, StableswapHooksAdapter, VestingInfo, + OracleAssetVolumeProvider, PriceAdjustmentAdapter, StableswapHooksAdapter, VestingInfo, }; + use hydradx_adapters::{RelayChainBlockHashProvider, RelayChainBlockNumberProvider}; -use hydradx_traits::{router::PoolType, AccountIdFor, AssetKind, AssetPairAccountIdFor, OraclePeriod, Source}; +use hydradx_traits::{ + router::PoolType, AccountIdFor, AssetKind, AssetPairAccountIdFor, OnTradeHandler, OraclePeriod, Source, +}; use pallet_currencies::BasicCurrencyAdapter; use pallet_omnipool::{ traits::{EnsurePriceWithin, OmnipoolHooks}, @@ -56,6 +59,7 @@ use pallet_lbp::weights::WeightInfo as LbpWeights; use pallet_route_executor::{weights::WeightInfo as RouterWeights, AmmTradeWeights}; use pallet_staking::types::Action; use pallet_staking::SigmoidPercentage; +use pallet_xyk::weights::WeightInfo as XykWeights; use sp_std::num::NonZeroU16; parameter_types! { @@ -411,6 +415,41 @@ where } } +#[cfg(feature = "runtime-benchmarks")] +use hydradx_traits::{pools::SpotPriceProvider, PriceOracle}; + +#[cfg(feature = "runtime-benchmarks")] +use hydra_dx_math::ema::EmaPrice; + +#[cfg(feature = "runtime-benchmarks")] +pub struct DummyOraclePriceProvider; +#[cfg(feature = "runtime-benchmarks")] +impl PriceOracle for DummyOraclePriceProvider { + type Price = EmaPrice; + + fn price(_route: &[Trade], _period: OraclePeriod) -> Option { + Some(EmaPrice::one()) + } +} + +#[cfg(not(feature = "runtime-benchmarks"))] +use hydradx_adapters::OraclePriceProvider; + +#[cfg(feature = "runtime-benchmarks")] +pub struct DummySpotPriceProvider; +#[cfg(feature = "runtime-benchmarks")] +impl SpotPriceProvider for DummySpotPriceProvider { + type Price = FixedU128; + + fn pair_exists(_asset_a: AssetId, _asset_b: AssetId) -> bool { + true + } + + fn spot_price(_asset_a: AssetId, _asset_b: AssetId) -> Option { + Some(FixedU128::one()) + } +} + parameter_types! { pub MinBudgetInNativeCurrency: Balance = 1000 * UNITS; pub MaxSchedulesPerBlock: u32 = 20; @@ -421,11 +460,19 @@ parameter_types! { impl pallet_dca::Config for Runtime { type RuntimeEvent = RuntimeEvent; + type AssetId = AssetId; type TechnicalOrigin = SuperMajorityTechCommittee; type Currencies = Currencies; type RelayChainBlockHashProvider = RelayChainBlockHashProviderAdapter; type RandomnessProvider = DCA; + #[cfg(not(feature = "runtime-benchmarks"))] type OraclePriceProvider = OraclePriceProvider; + #[cfg(feature = "runtime-benchmarks")] + type OraclePriceProvider = DummyOraclePriceProvider; + #[cfg(not(feature = "runtime-benchmarks"))] + type Router = Router; + #[cfg(feature = "runtime-benchmarks")] + type Router = pallet_route_executor::DummyRouter; type MaxPriceDifferenceBetweenBlocks = MaxPriceDifference; type MaxSchedulePerBlock = MaxSchedulesPerBlock; type MaxNumberOfRetriesOnError = MaxNumberOfRetriesOnError; @@ -435,33 +482,57 @@ impl pallet_dca::Config for Runtime { type FeeReceiver = TreasuryAccount; type NamedReserveId = NamedReserveId; type WeightToFee = WeightToFee; + type AmmTradeWeights = RouterWeightInfo; type WeightInfo = weights::dca::HydraWeight; type NativePriceOracle = MultiTransactionPayment; } // Provides weight info for the router. Router extrinsics can be executed with different AMMs, so we split the router weights into two parts: // the router extrinsic overhead and the AMM weight. -pub struct AmmWeights; +pub struct RouterWeightInfo; // Calculates the overhead of Router extrinsics. To do that, we benchmark Router::sell with single LBP trade and subtract the weight of LBP::sell. // This allows us to calculate the weight of any route by adding the weight of AMM trades to the overhead of a router extrinsic. -impl AmmWeights { - pub fn sell_overhead_weight() -> Weight { - weights::route_executor::HydraWeight::::sell_in_lbp() - .saturating_sub(weights::lbp::HydraWeight::::router_execution_sell()) +impl RouterWeightInfo { + pub fn sell_and_calculate_sell_trade_amounts_overhead_weight( + num_of_calc_sell: u32, + num_of_execute_sell: u32, + ) -> Weight { + weights::route_executor::HydraWeight::::calculate_and_execute_sell_in_lbp( + num_of_calc_sell, + num_of_execute_sell, + ) + .saturating_sub(weights::lbp::HydraWeight::::router_execution_sell( + num_of_calc_sell.saturating_add(num_of_execute_sell), + num_of_execute_sell, + )) } - pub fn buy_overhead_weight() -> Weight { - weights::route_executor::HydraWeight::::buy_in_lbp() - .saturating_sub(weights::lbp::HydraWeight::::router_execution_buy()) + pub fn buy_and_calculate_buy_trade_amounts_overhead_weight( + num_of_calc_buy: u32, + num_of_execute_buy: u32, + ) -> Weight { + weights::route_executor::HydraWeight::::calculate_and_execute_buy_in_lbp( + num_of_calc_buy, + num_of_execute_buy, + ) + .saturating_sub(weights::lbp::HydraWeight::::router_execution_buy( + num_of_calc_buy.saturating_add(num_of_execute_buy), + num_of_execute_buy, + )) } } -impl AmmTradeWeights for AmmWeights { +impl AmmTradeWeights> for RouterWeightInfo { + // Used in Router::sell extrinsic, which calls AMM::calculate_sell and AMM::execute_sell fn sell_weight(route: &[Trade]) -> Weight { let mut weight = Weight::zero(); + let c = 1; // number of times AMM::calculate_sell is executed + let e = 1; // number of times AMM::execute_sell is executed for trade in route { + weight.saturating_accrue(Self::sell_and_calculate_sell_trade_amounts_overhead_weight(0, 1)); + let amm_weight = match trade.pool { - PoolType::Omnipool => weights::omnipool::HydraWeight::::router_execution_sell() + PoolType::Omnipool => weights::omnipool::HydraWeight::::router_execution_sell(c, e) .saturating_add( as OmnipoolHooks< RuntimeOrigin, AccountId, @@ -474,23 +545,28 @@ impl AmmTradeWeights for AmmWeights { AssetId, Balance, >>::on_liquidity_changed_weight()), - PoolType::LBP => weights::lbp::HydraWeight::::router_execution_sell(), - PoolType::Stableswap(_) => weights::stableswap::HydraWeight::::router_execution_sell(), - PoolType::XYK => weights::omnipool::HydraWeight::::router_execution_sell(), // TODO: replace by XYK weights + AMMHandler::on_trade_weight() + PoolType::LBP => weights::lbp::HydraWeight::::router_execution_sell(c, e), + PoolType::Stableswap(_) => weights::stableswap::HydraWeight::::router_execution_sell(c, e), + PoolType::XYK => weights::xyk::HydraWeight::::router_execution_sell(c, e) + .saturating_add(::AMMHandler::on_trade_weight()), }; weight.saturating_accrue(amm_weight); - weight.saturating_accrue(Self::sell_overhead_weight()); } weight } + // Used in Router::buy extrinsic, which calls AMM::calculate_buy and AMM::execute_buy fn buy_weight(route: &[Trade]) -> Weight { let mut weight = Weight::zero(); + let c = 1; // number of times AMM::calculate_buy is executed + let e = 1; // number of times AMM::execute_buy is executed for trade in route { + weight.saturating_accrue(Self::buy_and_calculate_buy_trade_amounts_overhead_weight(0, 1)); + let amm_weight = match trade.pool { - PoolType::Omnipool => weights::omnipool::HydraWeight::::router_execution_buy() + PoolType::Omnipool => weights::omnipool::HydraWeight::::router_execution_buy(c, e) .saturating_add( as OmnipoolHooks< RuntimeOrigin, AccountId, @@ -503,12 +579,78 @@ impl AmmTradeWeights for AmmWeights { AssetId, Balance, >>::on_liquidity_changed_weight()), - PoolType::LBP => weights::lbp::HydraWeight::::router_execution_buy(), - PoolType::Stableswap(_) => weights::stableswap::HydraWeight::::router_execution_buy(), - PoolType::XYK => weights::omnipool::HydraWeight::::router_execution_buy(), // TODO: replace by XYK weights + AMMHandler::on_trade_weight() + PoolType::LBP => weights::lbp::HydraWeight::::router_execution_buy(c, e), + PoolType::Stableswap(_) => weights::stableswap::HydraWeight::::router_execution_buy(c, e), + PoolType::XYK => weights::xyk::HydraWeight::::router_execution_buy(c, e) + .saturating_add(::AMMHandler::on_trade_weight()), + }; + weight.saturating_accrue(amm_weight); + } + + weight + } + + // Used in DCA::schedule extrinsic, which calls Router::calculate_buy_trade_amounts + fn calculate_buy_trade_amounts_weight(route: &[Trade]) -> Weight { + let mut weight = Weight::zero(); + let c = 1; // number of times AMM::calculate_buy is executed + let e = 0; // number of times AMM::execute_buy is executed + + for trade in route { + weight.saturating_accrue(Self::buy_and_calculate_buy_trade_amounts_overhead_weight(1, 0)); + + let amm_weight = match trade.pool { + PoolType::Omnipool => weights::omnipool::HydraWeight::::router_execution_buy(c, e), + PoolType::LBP => weights::lbp::HydraWeight::::router_execution_buy(c, e), + PoolType::Stableswap(_) => weights::stableswap::HydraWeight::::router_execution_buy(c, e), + PoolType::XYK => weights::xyk::HydraWeight::::router_execution_buy(c, e) + .saturating_add(::AMMHandler::on_trade_weight()), + }; + weight.saturating_accrue(amm_weight); + } + + weight + } + + // Used in DCA::on_initialize for Order::Sell, which calls Router::calculate_sell_trade_amounts and Router::sell. + fn sell_and_calculate_sell_trade_amounts_weight(route: &[Trade]) -> Weight { + let mut weight = Weight::zero(); + let c = 2; // number of times AMM::calculate_sell is executed + let e = 1; // number of times AMM::execute_sell is executed + + for trade in route { + weight.saturating_accrue(Self::sell_and_calculate_sell_trade_amounts_overhead_weight(1, 1)); + + let amm_weight = match trade.pool { + PoolType::Omnipool => weights::omnipool::HydraWeight::::router_execution_sell(c, e), + PoolType::LBP => weights::lbp::HydraWeight::::router_execution_sell(c, e), + PoolType::Stableswap(_) => weights::stableswap::HydraWeight::::router_execution_sell(c, e), + PoolType::XYK => weights::xyk::HydraWeight::::router_execution_sell(c, e) + .saturating_add(::AMMHandler::on_trade_weight()), + }; + weight.saturating_accrue(amm_weight); + } + + weight + } + + // Used in DCA::on_initialize for Order::Buy, which calls 2 * Router::calculate_buy_trade_amounts and Router::buy. + fn buy_and_calculate_buy_trade_amounts_weight(route: &[Trade]) -> Weight { + let mut weight = Weight::zero(); + let c = 3; // number of times AMM::calculate_buy is executed + let e = 1; // number of times AMM::execute_buy is executed + + for trade in route { + weight.saturating_accrue(Self::buy_and_calculate_buy_trade_amounts_overhead_weight(2, 1)); + + let amm_weight = match trade.pool { + PoolType::Omnipool => weights::omnipool::HydraWeight::::router_execution_buy(c, e), + PoolType::LBP => weights::lbp::HydraWeight::::router_execution_buy(c, e), + PoolType::Stableswap(_) => weights::stableswap::HydraWeight::::router_execution_buy(c, e), + PoolType::XYK => weights::xyk::HydraWeight::::router_execution_buy(c, e) + .saturating_add(::AMMHandler::on_trade_weight()), }; weight.saturating_accrue(amm_weight); - weight.saturating_accrue(Self::buy_overhead_weight()); } weight @@ -525,9 +667,8 @@ impl pallet_route_executor::Config for Runtime { type Balance = Balance; type MaxNumberOfTrades = MaxNumberOfTrades; type Currency = MultiInspectAdapter; + type WeightInfo = RouterWeightInfo; type AMM = (Omnipool, Stableswap, XYK, LBP); - type AmmTradeWeights = AmmWeights; - type WeightInfo = weights::route_executor::HydraWeight; } parameter_types! { diff --git a/runtime/hydradx/src/benchmarking/dca.rs b/runtime/hydradx/src/benchmarking/dca.rs new file mode 100644 index 000000000..cc33c1dd4 --- /dev/null +++ b/runtime/hydradx/src/benchmarking/dca.rs @@ -0,0 +1,340 @@ +// This file is part of HydraDX-node + +// 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. +#![allow(unused_assignments)] // At test `on_initialize_with_empty_block` it does not recognize the assignment in the Act block + +use crate::{ + AccountId, AssetId, Balance, BlockNumber, Currencies, EmaOracle, MaxSchedulesPerBlock, NamedReserveId, Runtime, + StableAssetId, System, DCA, +}; + +use frame_benchmarking::account; +use frame_support::{ + assert_ok, + traits::{Hooks, Len}, + weights::Weight, + BoundedVec, +}; +use frame_system::RawOrigin; +use hydradx_traits::router::PoolType; +use orml_benchmarking::runtime_benchmarks; +use orml_traits::{MultiCurrency, MultiCurrencyExtended, NamedMultiReservableCurrency}; +use pallet_dca::types::{Order, Schedule, ScheduleId}; +use pallet_dca::{ScheduleIdsPerBlock, Schedules}; +use pallet_route_executor::Trade; +use scale_info::prelude::vec::Vec; +use sp_runtime::traits::ConstU32; +use sp_runtime::{DispatchError, Permill}; +use sp_std::vec; + +pub const HDX: AssetId = 0; +pub const DAI: AssetId = 2; + +pub const ONE: Balance = 1_000_000_000_000; + +// This is the sum of all "randomly" generated radiuses. +// In tests the radiuses are always the same as we use a fixed parent hash for generation, +// so it will always generate the same values +pub const DELAY_AFTER_LAST_RADIUS: u32 = 1854; + +pub const RETRY_TO_SEARCH_FOR_FREE_BLOCK: u32 = 10; + +fn schedule_fake( + owner: AccountId, + asset_in: AssetId, + asset_out: AssetId, + amount: Balance, +) -> Schedule { + let schedule1: Schedule = Schedule { + owner, + period: 3u32, + total_amount: 1100 * ONE, + max_retries: None, + stability_threshold: None, + slippage: Some(Permill::from_percent(15)), + order: Order::Buy { + asset_in, + asset_out, + amount_out: amount, + max_amount_in: Balance::MAX, + route: create_bounded_vec(vec![Trade { + pool: PoolType::Omnipool, + asset_in, + asset_out, + }]), + }, + }; + schedule1 +} + +fn get_named_reseve_balance(token_id: AssetId, seller: AccountId) -> Balance { + Currencies::reserved_balance_named(&NamedReserveId::get(), token_id, &seller) +} + +fn schedule_buy_fake( + owner: AccountId, + asset_in: AssetId, + asset_out: AssetId, + amount: Balance, +) -> Schedule { + let schedule1: Schedule = Schedule { + owner, + period: 3u32, + total_amount: 2000 * ONE, + max_retries: None, + stability_threshold: None, + slippage: Some(Permill::from_percent(15)), + order: Order::Buy { + asset_in, + asset_out, + amount_out: amount, + max_amount_in: Balance::MAX, + route: create_bounded_vec(vec![Trade { + pool: PoolType::Omnipool, + asset_in, + asset_out, + }]), + }, + }; + schedule1 +} + +fn schedule_sell_fake( + owner: AccountId, + asset_in: AssetId, + asset_out: AssetId, + amount: Balance, +) -> Schedule { + let schedule1: Schedule = Schedule { + owner, + period: 3u32, + total_amount: 2000 * ONE, + max_retries: None, + stability_threshold: None, + slippage: Some(Permill::from_percent(100)), + order: Order::Sell { + asset_in, + asset_out, + amount_in: amount, + min_amount_out: Balance::MIN, + route: create_bounded_vec(vec![Trade { + pool: PoolType::Omnipool, + asset_in, + asset_out, + }]), + }, + }; + schedule1 +} + +fn set_period(to: u32) { + while System::block_number() < Into::::into(to) { + let b = System::block_number(); + + System::on_finalize(b); + EmaOracle::on_finalize(b); + + System::on_initialize(b + 1_u32); + EmaOracle::on_initialize(b + 1_u32); + + System::set_block_number(b + 1_u32); + } +} + +pub fn create_bounded_vec(trades: Vec>) -> BoundedVec, ConstU32<5>> { + let bounded_vec: BoundedVec, ConstU32<5>> = trades.try_into().unwrap(); + bounded_vec +} + +fn create_account_with_native_balance() -> Result { + let caller: AccountId = account("provider", 1, 1); + let token_amount = 200 * ONE; + >::update_balance(0u32, &caller, token_amount as i128)?; + + Ok(caller) +} + +runtime_benchmarks! { + {Runtime, pallet_dca} + + on_initialize_with_buy_trade{ + let seller: AccountId = account("seller", 3, 1); + let other_seller: AccountId = account("seller", 3, 1); + + set_period(1000); + + let amount_buy = 200 * ONE; + + >::update_balance(HDX, &seller, 500_000_000_000_000i128)?; + + >::update_balance(HDX, &other_seller, 20_000_000_000_000_000_000_000i128)?; + + let schedule1 = schedule_buy_fake(seller.clone(), HDX, DAI, amount_buy); + let execution_block = 1001u32; + + assert_ok!(DCA::schedule(RawOrigin::Signed(seller.clone()).into(), schedule1.clone(), Option::Some(execution_block))); + + assert_eq!(Currencies::free_balance(StableAssetId::get(), &seller),0); + let reserved_balance = get_named_reseve_balance(HDX, seller.clone()); + + let init_reserved_balance = 2000 * ONE; + assert_eq!(init_reserved_balance, reserved_balance); + + assert_eq!(Currencies::free_balance(DAI, &seller), 0); + + //Make sure that we have other schedules planned in the block where the benchmark schedule is planned, leading to worst case + //We leave only one slot + let schedule_period = 3; + let next_block_to_replan = execution_block + schedule_period; + let number_of_all_schedules = MaxSchedulesPerBlock::get() + MaxSchedulesPerBlock::get() * RETRY_TO_SEARCH_FOR_FREE_BLOCK - 1; + for i in 0..number_of_all_schedules { + assert_ok!(DCA::schedule(RawOrigin::Signed(other_seller.clone()).into(), schedule1.clone(), Option::Some(next_block_to_replan))); + } + + assert_eq!((MaxSchedulesPerBlock::get() - 1) as usize, >::get::(next_block_to_replan + DELAY_AFTER_LAST_RADIUS).len()); + }: { + DCA::on_initialize(execution_block); + } + verify { + assert_eq!((MaxSchedulesPerBlock::get()) as usize, >::get::(next_block_to_replan + DELAY_AFTER_LAST_RADIUS).len()); + } + + on_initialize_with_sell_trade{ + set_period(1000); + let seller: AccountId = account("seller", 3, 1); + let other_seller: AccountId = account("seller", 3, 1); + + let amount_sell = 100 * ONE; + + >::update_balance(HDX, &seller, 20_000_000_000_000_000i128)?; + + >::update_balance(HDX, &other_seller, 20_000_000_000_000_000_000_000i128)?; + + let schedule1 = schedule_sell_fake(seller.clone(), HDX, DAI, amount_sell); + let execution_block = 1001u32; + + assert_ok!(DCA::schedule(RawOrigin::Signed(seller.clone()).into(), schedule1.clone(), Option::Some(execution_block))); + + assert_eq!(Currencies::free_balance(StableAssetId::get(), &seller),0); + let reserved_balance = get_named_reseve_balance(HDX, seller.clone()); + + let init_reserved_balance = 2000 * ONE; + assert_eq!(init_reserved_balance, reserved_balance); + + assert_eq!(Currencies::free_balance(DAI, &seller), 0); + + //Make sure that we have other schedules planned in the block where the benchmark schedule is planned, leading to worst case + //We leave only one slot + let schedule_period = 3; + let next_block_to_replan = execution_block + schedule_period; + let number_of_all_schedules = MaxSchedulesPerBlock::get() + MaxSchedulesPerBlock::get() * RETRY_TO_SEARCH_FOR_FREE_BLOCK - 1; + for i in 0..number_of_all_schedules { + assert_ok!(DCA::schedule(RawOrigin::Signed(other_seller.clone()).into(), schedule1.clone(), Option::Some(next_block_to_replan))); + } + assert_eq!((MaxSchedulesPerBlock::get() - 1) as usize, >::get::(next_block_to_replan + DELAY_AFTER_LAST_RADIUS).len()); + }: { + DCA::on_initialize(execution_block); + } + verify { + assert_eq!((MaxSchedulesPerBlock::get()) as usize, >::get::(next_block_to_replan + DELAY_AFTER_LAST_RADIUS).len()); + } + + on_initialize_with_empty_block{ + let seller: AccountId = account("seller", 3, 1); + + let execution_block = 100u32; + assert_eq!(DCA::schedules::(execution_block), None); + let r = DCA::schedules::(execution_block); + let mut weight = Weight::from_ref_time(0); + }: { + weight = DCA::on_initialize(execution_block); + } + verify { + assert!(weight.ref_time() > 0u64); + } + + + schedule{ + let caller: AccountId = create_account_with_native_balance()?; + + >::update_balance(HDX, &caller, 100_000_000_000_000_000_000_000i128)?; + + let amount_sell = 200 * ONE; + let schedule1 = schedule_fake(caller.clone(), HDX, DAI, amount_sell); + let execution_block = 100u32; + + //We fill blocks with schedules leaving only one place + let number_of_all_schedules = MaxSchedulesPerBlock::get() + MaxSchedulesPerBlock::get() * RETRY_TO_SEARCH_FOR_FREE_BLOCK - 1; + for i in 0..number_of_all_schedules { + assert_ok!(DCA::schedule(RawOrigin::Signed(caller.clone()).into(), schedule1.clone(), Option::Some(execution_block))); + } + + let schedule_id : ScheduleId = number_of_all_schedules; + + assert_eq!((MaxSchedulesPerBlock::get() - 1) as usize, >::get::(execution_block + DELAY_AFTER_LAST_RADIUS).len()); + + }: _(RawOrigin::Signed(caller.clone()), schedule1, Option::Some(execution_block)) + verify { + assert!(>::get::(schedule_id).is_some()); + + assert_eq!((MaxSchedulesPerBlock::get()) as usize, >::get::(execution_block + DELAY_AFTER_LAST_RADIUS).len()); + } + + terminate { + let caller: AccountId = create_account_with_native_balance()?; + + >::update_balance(HDX, &caller, 100_000_000_000_000_000i128)?; + + let amount_sell = 200 * ONE; + let schedule1 = schedule_fake(caller.clone(), HDX, DAI, amount_sell); + let schedule_id : ScheduleId = 0; + + set_period(99); + let execution_block = 100u32; + assert_ok!(DCA::schedule(RawOrigin::Signed(caller).into(), schedule1, Option::Some(execution_block))); + + }: _(RawOrigin::Root, schedule_id, None) + verify { + assert!(>::get::(schedule_id).is_none()); + } + +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::NativeExistentialDeposit; + use frame_support::traits::GenesisBuild; + use orml_benchmarking::impl_benchmark_test_suite; + + fn new_test_ext() -> sp_io::TestExternalities { + let mut t = frame_system::GenesisConfig::default() + .build_storage::() + .unwrap(); + + pallet_asset_registry::GenesisConfig:: { + registered_assets: vec![(b"DAI".to_vec(), 1_000u128, Some(DAI))], + native_asset_name: b"HDX".to_vec(), + native_existential_deposit: NativeExistentialDeposit::get(), + } + .assimilate_storage(&mut t) + .unwrap(); + + sp_io::TestExternalities::new(t) + } + + impl_benchmark_test_suite!(new_test_ext(),); +} diff --git a/runtime/hydradx/src/benchmarking/mod.rs b/runtime/hydradx/src/benchmarking/mod.rs index 4998fef07..bf8347fae 100644 --- a/runtime/hydradx/src/benchmarking/mod.rs +++ b/runtime/hydradx/src/benchmarking/mod.rs @@ -1,6 +1,7 @@ #![cfg(feature = "runtime-benchmarks")] pub mod currencies; +pub mod dca; pub mod duster; pub mod multi_payment; pub mod omnipool; diff --git a/runtime/hydradx/src/benchmarking/omnipool.rs b/runtime/hydradx/src/benchmarking/omnipool.rs index bf2a14683..f7b57c573 100644 --- a/runtime/hydradx/src/benchmarking/omnipool.rs +++ b/runtime/hydradx/src/benchmarking/omnipool.rs @@ -437,6 +437,9 @@ runtime_benchmarks! { } router_execution_sell { + let c in 0..1; // if c == 1, calculate_sell is executed + let e in 0..1; // if e == 1, execute_sell is executed + // Initialize pool let stable_amount: Balance = 1_000_000_000_000_000u128; let native_amount: Balance = 1_000_000_000_000_000u128; @@ -490,14 +493,23 @@ runtime_benchmarks! { let buy_min_amount = 10_000_000_000_u128; }: { - assert!(>::calculate_sell(PoolType::Omnipool, token_id, stable_id, amount_sell).is_ok()); - assert!(>::execute_sell(RawOrigin::Signed(seller.clone()).into(), PoolType::Omnipool, token_id, stable_id, amount_sell, buy_min_amount).is_ok()); + if c != 0 { + assert!(>::calculate_sell(PoolType::Omnipool, token_id, stable_id, amount_sell).is_ok()); + } + if e != 0 { + assert!(>::execute_sell(RawOrigin::Signed(seller.clone()).into(), PoolType::Omnipool, token_id, stable_id, amount_sell, buy_min_amount).is_ok()); + } } verify { - assert!(::Currency::free_balance(stable_id, &seller) >= buy_min_amount); + if e != 0 { + assert!(::Currency::free_balance(stable_id, &seller) >= buy_min_amount); + } } router_execution_buy { + let c in 1..2; // number of times calculate_buy is executed + let e in 0..1; // if e == 1, execute_buy is executed + // Initialize pool let stable_amount: Balance = 1_000_000_000_000_000u128; let native_amount: Balance = 1_000_000_000_000_000u128; @@ -551,11 +563,15 @@ runtime_benchmarks! { let sell_max_limit = 2_000_000_000_000_u128; }: { - assert!(>::calculate_buy(PoolType::Omnipool, token_id, stable_id, amount_buy).is_ok()); + for _ in 1..c { + assert!(>::calculate_buy(PoolType::Omnipool, token_id, stable_id, amount_buy).is_ok()); + } assert!(>::execute_buy(RawOrigin::Signed(seller.clone()).into(), PoolType::Omnipool, token_id, stable_id, amount_buy, sell_max_limit).is_ok()); } verify { - assert!(::Currency::free_balance(stable_id, &seller) >= Balance::zero()); + if e != 0 { + assert!(::Currency::free_balance(stable_id, &seller) >= Balance::zero()); + } } } diff --git a/runtime/hydradx/src/benchmarking/route_executor.rs b/runtime/hydradx/src/benchmarking/route_executor.rs index dd3e07975..867ce406f 100644 --- a/runtime/hydradx/src/benchmarking/route_executor.rs +++ b/runtime/hydradx/src/benchmarking/route_executor.rs @@ -22,8 +22,7 @@ use frame_benchmarking::account; use frame_support::dispatch::DispatchResult; use frame_support::{assert_ok, ensure}; use frame_system::RawOrigin; -use hydradx_traits::router::PoolType; -use hydradx_traits::router::Trade; +use hydradx_traits::router::{PoolType, RouterT, Trade}; use orml_benchmarking::runtime_benchmarks; use orml_traits::{MultiCurrency, MultiCurrencyExtended}; use primitives::constants::currency::UNITS; @@ -97,11 +96,14 @@ runtime_benchmarks! { {Runtime, pallet_route_executor} // Calculates the weight of LBP trade. Used in the calculation to determine the weight of the overhead. - sell_in_lbp { + calculate_and_execute_sell_in_lbp { + let c in 0..1; // if c == 1, calculate_sell_trade_amounts is executed + let s in 0..1; // if e == 1, sell is executed + let asset_in = 0u32; let asset_out = 1u32; let caller: AccountId = funded_account("caller", 7, &[asset_in, asset_out]); - let seller: AccountId = funded_account("caller2", 8, &[asset_in, asset_out]); + let seller: AccountId = funded_account("seller", 8, &[asset_in, asset_out]); setup_lbp(caller, asset_in, asset_out)?; @@ -113,20 +115,32 @@ runtime_benchmarks! { let amount_to_sell: Balance = UNITS; - }: { Router::sell(RawOrigin::Signed(seller.clone()).into(), asset_in, asset_out, amount_to_sell, 0u128, trades)? } + }: { + if c != 0 { + Router::calculate_sell_trade_amounts(trades.as_slice(), amount_to_sell)?; + } + if s != 0 { + Router::sell(RawOrigin::Signed(seller.clone()).into(), asset_in, asset_out, amount_to_sell, 0u128, trades.clone())?; + } + } verify { - assert_eq!(>::free_balance( - asset_in, - &seller, - ), INITIAL_BALANCE - amount_to_sell); + if s != 0 { + assert_eq!(>::free_balance( + asset_in, + &seller, + ), INITIAL_BALANCE - amount_to_sell); + } } // Calculates the weight of LBP trade. Used in the calculation to determine the weight of the overhead. - buy_in_lbp { + calculate_and_execute_buy_in_lbp { + 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 = 0u32; let asset_out = 1u32; let caller: AccountId = funded_account("caller", 0, &[asset_in, asset_out]); - let buyer: AccountId = funded_account("caller2", 1, &[asset_in, asset_out]); + let buyer: AccountId = funded_account("buyer", 1, &[asset_in, asset_out]); setup_lbp(caller, asset_in, asset_out)?; @@ -138,12 +152,21 @@ runtime_benchmarks! { let amount_to_buy = UNITS; - }: { Router::buy(RawOrigin::Signed(buyer.clone()).into(), asset_in, asset_out, amount_to_buy, u128::MAX, trades)? } + }: { + for _ in 1..c { + Router::calculate_buy_trade_amounts(trades.as_slice(), amount_to_buy)?; + } + if b != 0 { + Router::buy(RawOrigin::Signed(buyer.clone()).into(), asset_in, asset_out, amount_to_buy, u128::MAX, trades)? + } + } verify { - assert!(>::free_balance( - asset_in, - &buyer, - ) < INITIAL_BALANCE); + if b != 0 { + assert!(>::free_balance( + asset_in, + &buyer, + ) < INITIAL_BALANCE); + } } } @@ -156,14 +179,11 @@ mod tests { fn new_test_ext() -> sp_io::TestExternalities { let mut t = frame_system::GenesisConfig::default() - .build_storage::() + .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)), - ], + pallet_asset_registry::GenesisConfig:: { + registered_assets: vec![(b"LRNA".to_vec(), 1_000u128, Some(1))], native_asset_name: b"HDX".to_vec(), native_existential_deposit: NativeExistentialDeposit::get(), } diff --git a/runtime/hydradx/src/lib.rs b/runtime/hydradx/src/lib.rs index 6aaef07b2..42cc5ddf5 100644 --- a/runtime/hydradx/src/lib.rs +++ b/runtime/hydradx/src/lib.rs @@ -94,7 +94,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("hydradx"), impl_name: create_runtime_str!("hydradx"), authoring_version: 1, - spec_version: 181, + spec_version: 182, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 1, @@ -402,7 +402,6 @@ impl_runtime_apis! { list_benchmark!(list, extra, tech, TechnicalCommittee); list_benchmark!(list, extra, pallet_omnipool_liquidity_mining, OmnipoolLiquidityMining); list_benchmark!(list, extra, pallet_circuit_breaker, CircuitBreaker); - list_benchmark!(list, extra, pallet_dca, DCA); list_benchmark!(list, extra, pallet_bonds, Bonds); list_benchmark!(list, extra, pallet_stableswap, Stableswap); @@ -426,6 +425,7 @@ impl_runtime_apis! { orml_list_benchmark!(list, extra, pallet_duster, benchmarking::duster); 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); let storage_info = AllPalletsWithSystem::storage_info(); @@ -473,7 +473,6 @@ impl_runtime_apis! { add_benchmark!(params, batches, tech, TechnicalCommittee); add_benchmark!(params, batches, pallet_omnipool_liquidity_mining, OmnipoolLiquidityMining); add_benchmark!(params, batches, pallet_circuit_breaker, CircuitBreaker); - add_benchmark!(params, batches, pallet_dca, DCA); add_benchmark!(params, batches, pallet_asset_registry, AssetRegistry); add_benchmark!(params, batches, pallet_claims, Claims); add_benchmark!(params, batches, pallet_ema_oracle, EmaOracle); @@ -496,6 +495,7 @@ impl_runtime_apis! { orml_add_benchmark!(params, batches, pallet_duster, benchmarking::duster); 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); if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) } Ok(batches) diff --git a/runtime/hydradx/src/weights/dca.rs b/runtime/hydradx/src/weights/dca.rs index 4ac7ad38d..fc6665253 100644 --- a/runtime/hydradx/src/weights/dca.rs +++ b/runtime/hydradx/src/weights/dca.rs @@ -18,25 +18,23 @@ //! Autogenerated weights for pallet_dca //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-06-16, STEPS: 5, REPEAT: 20, LOW RANGE: [], HIGH RANGE: [] +//! DATE: 2023-10-06, STEPS: 10, REPEAT: 30, 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-dca +// --chain=dev +// --steps=10 +// --repeat=30 // --execution=wasm // --wasm-execution=compiled // --heap-pages=4096 -// --chain=dev +// --template=.maintain/pallet-weight-template-no-back.hbs +// --pallet=pallet-dca +// --output=dca.rs // --extrinsic=* -// --steps=5 -// --repeat=20 -// --output -// dca.rs -// --template -// .maintain/pallet-weight-template-no-back.hbs #![allow(unused_parens)] #![allow(unused_imports)] @@ -62,35 +60,15 @@ impl WeightInfo for HydraWeight { // Proof: DCA RemainingAmounts (max_values: None, max_size: Some(36), added: 2511, 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:3 w:3) + // Storage: System Account (r:2 w:2) // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - // Storage: Omnipool Assets (r:2 w:2) - // Proof: Omnipool Assets (max_values: None, max_size: Some(85), added: 2560, mode: MaxEncodedLen) - // Storage: Tokens Accounts (r:3 w:3) - // Proof: Tokens Accounts (max_values: None, max_size: Some(108), added: 2583, mode: MaxEncodedLen) - // Storage: EmaOracle Oracles (r:4 w:0) - // 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: AssetRegistry Assets (r:2 w:0) - // Proof Skipped: AssetRegistry Assets (max_values: None, max_size: None, mode: Measured) - // 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: 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(2961), added: 3456, mode: MaxEncodedLen) - // Storage: CircuitBreaker AllowedTradeVolumeLimitPerAsset (r:2 w:2) - // Proof: CircuitBreaker AllowedTradeVolumeLimitPerAsset (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen) // Storage: DCA RetriesOnError (r:0 w:1) // Proof: DCA RetriesOnError (max_values: None, max_size: Some(21), added: 2496, mode: MaxEncodedLen) fn on_initialize_with_buy_trade() -> Weight { - // Minimum execution time: 477_615 nanoseconds. - Weight::from_ref_time(482_826_000 as u64) - .saturating_add(T::DbWeight::get().reads(36 as u64)) - .saturating_add(T::DbWeight::get().writes(18 as u64)) + // Minimum execution time: 202_152 nanoseconds. + Weight::from_ref_time(205_108_000 as u64) + .saturating_add(T::DbWeight::get().reads(17 as u64)) + .saturating_add(T::DbWeight::get().writes(7 as u64)) } // Storage: DCA ScheduleIdsPerBlock (r:12 w:2) // Proof: DCA ScheduleIdsPerBlock (max_values: None, max_size: Some(101), added: 2576, mode: MaxEncodedLen) @@ -100,54 +78,28 @@ impl WeightInfo for HydraWeight { // Proof: DCA RemainingAmounts (max_values: None, max_size: Some(36), added: 2511, 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:3 w:3) + // Storage: System Account (r:2 w:2) // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - // Storage: Omnipool Assets (r:2 w:2) - // Proof: Omnipool Assets (max_values: None, max_size: Some(85), added: 2560, mode: MaxEncodedLen) - // Storage: Tokens Accounts (r:3 w:3) - // Proof: Tokens Accounts (max_values: None, max_size: Some(108), added: 2583, mode: MaxEncodedLen) - // Storage: EmaOracle Oracles (r:4 w:0) - // 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: AssetRegistry Assets (r:2 w:0) - // Proof Skipped: AssetRegistry Assets (max_values: None, max_size: None, mode: Measured) - // 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: 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(2961), added: 3456, mode: MaxEncodedLen) - // Storage: CircuitBreaker AllowedTradeVolumeLimitPerAsset (r:2 w:2) - // Proof: CircuitBreaker AllowedTradeVolumeLimitPerAsset (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen) // Storage: DCA RetriesOnError (r:0 w:1) // Proof: DCA RetriesOnError (max_values: None, max_size: Some(21), added: 2496, mode: MaxEncodedLen) fn on_initialize_with_sell_trade() -> Weight { - // Minimum execution time: 469_092 nanoseconds. - Weight::from_ref_time(473_690_000 as u64) - .saturating_add(T::DbWeight::get().reads(36 as u64)) - .saturating_add(T::DbWeight::get().writes(18 as u64)) + // Minimum execution time: 200_514 nanoseconds. + Weight::from_ref_time(204_215_000 as u64) + .saturating_add(T::DbWeight::get().reads(17 as u64)) + .saturating_add(T::DbWeight::get().writes(7 as u64)) } // Storage: DCA ScheduleIdsPerBlock (r:1 w:0) // Proof: DCA ScheduleIdsPerBlock (max_values: None, max_size: Some(101), added: 2576, mode: MaxEncodedLen) fn on_initialize_with_empty_block() -> Weight { - // Minimum execution time: 13_278 nanoseconds. - Weight::from_ref_time(13_554_000 as u64).saturating_add(T::DbWeight::get().reads(1 as u64)) + // Minimum execution time: 18_232 nanoseconds. + Weight::from_ref_time(18_655_000 as u64).saturating_add(T::DbWeight::get().reads(1 as u64)) } - // Storage: Omnipool Assets (r:2 w:0) - // Proof: Omnipool Assets (max_values: None, max_size: Some(85), added: 2560, mode: MaxEncodedLen) - // Storage: Tokens Accounts (r:1 w:0) - // Proof: Tokens Accounts (max_values: None, max_size: Some(108), added: 2583, mode: MaxEncodedLen) - // Storage: Omnipool HubAssetImbalance (r:1 w:0) - // Proof: Omnipool HubAssetImbalance (max_values: Some(1), max_size: Some(17), added: 512, mode: MaxEncodedLen) - // Storage: System Account (r:2 w:1) - // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) // Storage: DCA ScheduleIdSequencer (r:1 w:1) // Proof: DCA ScheduleIdSequencer (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: 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) @@ -159,9 +111,9 @@ impl WeightInfo for HydraWeight { // Storage: DCA RemainingAmounts (r:0 w:1) // Proof: DCA RemainingAmounts (max_values: None, max_size: Some(36), added: 2511, mode: MaxEncodedLen) fn schedule() -> Weight { - // Minimum execution time: 145_109 nanoseconds. - Weight::from_ref_time(146_997_000 as u64) - .saturating_add(T::DbWeight::get().reads(19 as u64)) + // Minimum execution time: 133_110 nanoseconds. + Weight::from_ref_time(134_484_000 as u64) + .saturating_add(T::DbWeight::get().reads(14 as u64)) .saturating_add(T::DbWeight::get().writes(8 as u64)) } // Storage: DCA Schedules (r:1 w:1) @@ -179,8 +131,8 @@ impl WeightInfo for HydraWeight { // Storage: DCA ScheduleOwnership (r:0 w:1) // Proof: DCA ScheduleOwnership (max_values: None, max_size: Some(60), added: 2535, mode: MaxEncodedLen) fn terminate() -> Weight { - // Minimum execution time: 58_609 nanoseconds. - Weight::from_ref_time(59_056_000 as u64) + // Minimum execution time: 74_610 nanoseconds. + Weight::from_ref_time(75_402_000 as u64) .saturating_add(T::DbWeight::get().reads(5 as u64)) .saturating_add(T::DbWeight::get().writes(7 as u64)) } diff --git a/runtime/hydradx/src/weights/ema_oracle.rs b/runtime/hydradx/src/weights/ema_oracle.rs index 9f97c60ae..398c8725a 100644 --- a/runtime/hydradx/src/weights/ema_oracle.rs +++ b/runtime/hydradx/src/weights/ema_oracle.rs @@ -18,25 +18,23 @@ //! Autogenerated weights for pallet_ema_oracle //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-06-16, STEPS: 5, REPEAT: 20, LOW RANGE: [], HIGH RANGE: [] +//! DATE: 2023-10-06, STEPS: 10, REPEAT: 30, 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-ema-oracle +// --chain=dev +// --steps=10 +// --repeat=30 // --execution=wasm // --wasm-execution=compiled // --heap-pages=4096 -// --chain=dev +// --template=.maintain/pallet-weight-template-no-back.hbs +// --pallet=pallet-ema-oracle +// --output=ema-oracle.rs // --extrinsic=* -// --steps=5 -// --repeat=20 -// --output -// ema_oracle.rs -// --template -// .maintain/pallet-weight-template-no-back.hbs #![allow(unused_parens)] #![allow(unused_imports)] @@ -55,49 +53,49 @@ 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(2961), added: 3456, mode: MaxEncodedLen) + // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(5921), added: 6416, mode: MaxEncodedLen) fn on_finalize_no_entry() -> Weight { - // Minimum execution time: 2_946 nanoseconds. - Weight::from_ref_time(3_109_000 as u64).saturating_add(T::DbWeight::get().reads(1 as u64)) + // Minimum execution time: 3_226 nanoseconds. + Weight::from_ref_time(3_325_000 as u64).saturating_add(T::DbWeight::get().reads(1 as u64)) } // Storage: EmaOracle Accumulator (r:1 w:1) - // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(2961), added: 3456, mode: MaxEncodedLen) - // Storage: EmaOracle Oracles (r:57 w:57) + // 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, 19]`. + /// The range of component `b` is `[1, 39]`. fn on_finalize_multiple_tokens(b: u32) -> Weight { - // Minimum execution time: 46_298 nanoseconds. - Weight::from_ref_time(14_321_486 as u64) // Standard Error: 79_212 - .saturating_add(Weight::from_ref_time(35_017_197 as u64).saturating_mul(b as u64)) + // Minimum execution time: 44_637 nanoseconds. + Weight::from_ref_time(9_798_669 as u64) // Standard Error: 47_796 + .saturating_add(Weight::from_ref_time(33_611_646 as u64).saturating_mul(b as u64)) .saturating_add(T::DbWeight::get().reads(1 as u64)) .saturating_add(T::DbWeight::get().reads((3 as u64).saturating_mul(b as u64))) .saturating_add(T::DbWeight::get().writes(1 as u64)) .saturating_add(T::DbWeight::get().writes((3 as u64).saturating_mul(b as u64))) } // Storage: EmaOracle Accumulator (r:1 w:1) - // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(2961), added: 3456, mode: MaxEncodedLen) - /// The range of component `b` is `[1, 19]`. + // 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 { - // Minimum execution time: 10_311 nanoseconds. - Weight::from_ref_time(10_186_198 as u64) // Standard Error: 8_154 - .saturating_add(Weight::from_ref_time(479_845 as u64).saturating_mul(b as u64)) + // Minimum execution time: 10_368 nanoseconds. + Weight::from_ref_time(10_544_600 as u64) // Standard Error: 2_268 + .saturating_add(Weight::from_ref_time(432_909 as u64).saturating_mul(b as u64)) .saturating_add(T::DbWeight::get().reads(1 as u64)) .saturating_add(T::DbWeight::get().writes(1 as u64)) } // Storage: EmaOracle Accumulator (r:1 w:1) - // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(2961), added: 3456, mode: MaxEncodedLen) - /// The range of component `b` is `[1, 19]`. + // 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 { - // Minimum execution time: 10_538 nanoseconds. - Weight::from_ref_time(10_506_636 as u64) // Standard Error: 5_391 - .saturating_add(Weight::from_ref_time(457_947 as u64).saturating_mul(b as u64)) + // Minimum execution time: 10_369 nanoseconds. + Weight::from_ref_time(10_608_047 as u64) // Standard Error: 2_062 + .saturating_add(Weight::from_ref_time(432_350 as u64).saturating_mul(b as u64)) .saturating_add(T::DbWeight::get().reads(1 as u64)) .saturating_add(T::DbWeight::get().writes(1 as u64)) } // Storage: EmaOracle Oracles (r:2 w:0) // Proof: EmaOracle Oracles (max_values: None, max_size: Some(177), added: 2652, mode: MaxEncodedLen) fn get_entry() -> Weight { - // Minimum execution time: 17_723 nanoseconds. - Weight::from_ref_time(18_231_000 as u64).saturating_add(T::DbWeight::get().reads(2 as u64)) + // Minimum execution time: 17_936 nanoseconds. + Weight::from_ref_time(18_521_000 as u64).saturating_add(T::DbWeight::get().reads(2 as u64)) } } diff --git a/runtime/hydradx/src/weights/lbp.rs b/runtime/hydradx/src/weights/lbp.rs index 6ef47a087..42a47dc89 100644 --- a/runtime/hydradx/src/weights/lbp.rs +++ b/runtime/hydradx/src/weights/lbp.rs @@ -18,7 +18,7 @@ //! Autogenerated weights for pallet_lbp //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-09-11, STEPS: 10, REPEAT: 30, LOW RANGE: [], HIGH RANGE: [] +//! DATE: 2023-10-06, STEPS: 10, REPEAT: 30, LOW RANGE: [], HIGH RANGE: [] //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 // Executed Command: @@ -33,8 +33,8 @@ // --heap-pages=4096 // --template=.maintain/pallet-weight-template-no-back.hbs // --pallet=pallet-lbp +// --output=lbp.rs // --extrinsic=* -// --output=lbp_no_back.rs #![allow(unused_parens)] #![allow(unused_imports)] @@ -67,8 +67,8 @@ impl WeightInfo for HydraWeight { // Storage: MultiTransactionPayment AcceptedCurrencies (r:1 w:0) // Proof: MultiTransactionPayment AcceptedCurrencies (max_values: None, max_size: Some(28), added: 2503, mode: MaxEncodedLen) fn create_pool() -> Weight { - // Minimum execution time: 151_763 nanoseconds. - Weight::from_ref_time(153_465_000 as u64) + // Minimum execution time: 141_654 nanoseconds. + Weight::from_ref_time(143_331_000 as u64) .saturating_add(T::DbWeight::get().reads(12 as u64)) .saturating_add(T::DbWeight::get().writes(8 as u64)) } @@ -77,8 +77,8 @@ impl WeightInfo for HydraWeight { // Storage: LBP FeeCollectorWithAsset (r:1 w:2) // Proof: LBP FeeCollectorWithAsset (max_values: None, max_size: Some(69), added: 2544, mode: MaxEncodedLen) fn update_pool_data() -> Weight { - // Minimum execution time: 31_781 nanoseconds. - Weight::from_ref_time(32_284_000 as u64) + // Minimum execution time: 30_269 nanoseconds. + Weight::from_ref_time(30_677_000 as u64) .saturating_add(T::DbWeight::get().reads(2 as u64)) .saturating_add(T::DbWeight::get().writes(3 as u64)) } @@ -91,8 +91,8 @@ 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) fn add_liquidity() -> Weight { - // Minimum execution time: 106_414 nanoseconds. - Weight::from_ref_time(107_630_000 as u64) + // Minimum execution time: 98_867 nanoseconds. + Weight::from_ref_time(100_102_000 as u64) .saturating_add(T::DbWeight::get().reads(8 as u64)) .saturating_add(T::DbWeight::get().writes(4 as u64)) } @@ -111,8 +111,8 @@ impl WeightInfo for HydraWeight { // Storage: LBP FeeCollectorWithAsset (r:0 w:1) // Proof: LBP FeeCollectorWithAsset (max_values: None, max_size: Some(69), added: 2544, mode: MaxEncodedLen) fn remove_liquidity() -> Weight { - // Minimum execution time: 136_405 nanoseconds. - Weight::from_ref_time(138_124_000 as u64) + // Minimum execution time: 125_051 nanoseconds. + Weight::from_ref_time(126_556_000 as u64) .saturating_add(T::DbWeight::get().reads(10 as u64)) .saturating_add(T::DbWeight::get().writes(8 as u64)) } @@ -127,8 +127,8 @@ impl WeightInfo for HydraWeight { // Storage: System Account (r:3 w:1) // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) fn sell() -> Weight { - // Minimum execution time: 199_893 nanoseconds. - Weight::from_ref_time(201_395_000 as u64) + // Minimum execution time: 217_207 nanoseconds. + Weight::from_ref_time(218_401_000 as u64) .saturating_add(T::DbWeight::get().reads(12 as u64)) .saturating_add(T::DbWeight::get().writes(7 as u64)) } @@ -143,8 +143,8 @@ impl WeightInfo for HydraWeight { // Storage: System Account (r:3 w:1) // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) fn buy() -> Weight { - // Minimum execution time: 199_112 nanoseconds. - Weight::from_ref_time(200_863_000 as u64) + // Minimum execution time: 211_853 nanoseconds. + Weight::from_ref_time(213_114_000 as u64) .saturating_add(T::DbWeight::get().reads(12 as u64)) .saturating_add(T::DbWeight::get().writes(7 as u64)) } @@ -158,11 +158,17 @@ impl WeightInfo for HydraWeight { // Proof: AssetRegistry Assets (max_values: None, max_size: Some(87), added: 2562, mode: MaxEncodedLen) // Storage: System Account (r:3 w:1) // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - fn router_execution_sell() -> Weight { - // Minimum execution time: 223_028 nanoseconds. - Weight::from_ref_time(225_062_000 as u64) - .saturating_add(T::DbWeight::get().reads(12 as u64)) - .saturating_add(T::DbWeight::get().writes(7 as u64)) + /// 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 { + // Minimum execution time: 66_725 nanoseconds. + Weight::from_ref_time(67_159_000 as u64) // Standard Error: 592_525 + .saturating_add(Weight::from_ref_time(2_278_417 as u64).saturating_mul(c as u64)) + // Standard Error: 1_300_761 + .saturating_add(Weight::from_ref_time(151_794_260 as u64).saturating_mul(e as u64)) + .saturating_add(T::DbWeight::get().reads(3 as u64)) + .saturating_add(T::DbWeight::get().reads((9 as u64).saturating_mul(e as u64))) + .saturating_add(T::DbWeight::get().writes((7 as u64).saturating_mul(e as u64))) } // Storage: LBP PoolData (r:1 w:0) // Proof: LBP PoolData (max_values: None, max_size: Some(163), added: 2638, mode: MaxEncodedLen) @@ -174,10 +180,16 @@ impl WeightInfo for HydraWeight { // Proof: AssetRegistry Assets (max_values: None, max_size: Some(87), added: 2562, mode: MaxEncodedLen) // Storage: System Account (r:3 w:1) // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) - fn router_execution_buy() -> Weight { - // Minimum execution time: 223_313 nanoseconds. - Weight::from_ref_time(224_794_000 as u64) - .saturating_add(T::DbWeight::get().reads(12 as u64)) - .saturating_add(T::DbWeight::get().writes(7 as u64)) + /// 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 { + // Minimum execution time: 118_181 nanoseconds. + Weight::from_ref_time(118_740_000 as u64) // Standard Error: 769_691 + .saturating_add(Weight::from_ref_time(3_767_843 as u64).saturating_mul(c as u64)) + // Standard Error: 2_541_567 + .saturating_add(Weight::from_ref_time(124_213_432 as u64).saturating_mul(e as u64)) + .saturating_add(T::DbWeight::get().reads(3 as u64)) + .saturating_add(T::DbWeight::get().reads((9 as u64).saturating_mul(e as u64))) + .saturating_add(T::DbWeight::get().writes((7 as u64).saturating_mul(e as u64))) } } diff --git a/runtime/hydradx/src/weights/omnipool.rs b/runtime/hydradx/src/weights/omnipool.rs index 0fdad74df..1273b734f 100644 --- a/runtime/hydradx/src/weights/omnipool.rs +++ b/runtime/hydradx/src/weights/omnipool.rs @@ -18,25 +18,23 @@ //! Autogenerated weights for pallet_omnipool //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-06-16, STEPS: 5, REPEAT: 20, LOW RANGE: [], HIGH RANGE: [] +//! DATE: 2023-10-06, STEPS: 10, REPEAT: 30, 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-omnipool +// --chain=dev +// --steps=10 +// --repeat=30 // --execution=wasm // --wasm-execution=compiled // --heap-pages=4096 -// --chain=dev +// --template=.maintain/pallet-weight-template-no-back.hbs +// --pallet=pallet-omnipool +// --output=omnipool.rs // --extrinsic=* -// --steps=5 -// --repeat=20 -// --output -// omnipool.rs -// --template -// .maintain/pallet-weight-template-no-back.hbs #![allow(unused_parens)] #![allow(unused_imports)] @@ -57,7 +55,7 @@ impl WeightInfo for HydraWeight { // Storage: Omnipool Assets (r:2 w:2) // Proof: Omnipool Assets (max_values: None, max_size: Some(85), added: 2560, mode: MaxEncodedLen) // Storage: AssetRegistry Assets (r:2 w:0) - // Proof Skipped: AssetRegistry Assets (max_values: None, max_size: None, mode: Measured) + // 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: Tokens Accounts (r:2 w:1) @@ -75,15 +73,15 @@ impl WeightInfo for HydraWeight { // Storage: Omnipool HubAssetTradability (r:0 w:1) // Proof: Omnipool HubAssetTradability (max_values: Some(1), max_size: Some(1), added: 496, mode: MaxEncodedLen) fn initialize_pool() -> Weight { - // Minimum execution time: 140_190 nanoseconds. - Weight::from_ref_time(141_127_000 as u64) + // Minimum execution time: 149_531 nanoseconds. + Weight::from_ref_time(150_484_000 as u64) .saturating_add(T::DbWeight::get().reads(11 as u64)) .saturating_add(T::DbWeight::get().writes(8 as u64)) } // Storage: Omnipool Assets (r:2 w:1) // Proof: Omnipool Assets (max_values: None, max_size: Some(85), added: 2560, mode: MaxEncodedLen) // Storage: AssetRegistry Assets (r:2 w:0) - // Proof Skipped: AssetRegistry Assets (max_values: None, max_size: None, mode: Measured) + // Proof: AssetRegistry Assets (max_values: None, max_size: Some(87), added: 2562, mode: MaxEncodedLen) // Storage: Tokens Accounts (r:3 w:1) // Proof: Tokens Accounts (max_values: None, max_size: Some(108), added: 2583, mode: MaxEncodedLen) // Storage: Omnipool NextPositionId (r:1 w:1) @@ -99,7 +97,7 @@ impl WeightInfo for HydraWeight { // 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(2961), added: 3456, mode: MaxEncodedLen) + // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(5921), added: 6416, mode: MaxEncodedLen) // Storage: Omnipool TvlCap (r:1 w:0) // Proof: Omnipool TvlCap (max_values: Some(1), max_size: Some(16), added: 511, mode: MaxEncodedLen) // Storage: Uniques Account (r:0 w:1) @@ -107,8 +105,8 @@ impl WeightInfo for HydraWeight { // Storage: Omnipool Positions (r:0 w:1) // Proof: Omnipool Positions (max_values: None, max_size: Some(100), added: 2575, mode: MaxEncodedLen) fn add_token() -> Weight { - // Minimum execution time: 143_602 nanoseconds. - Weight::from_ref_time(145_117_000 as u64) + // Minimum execution time: 148_641 nanoseconds. + Weight::from_ref_time(150_420_000 as u64) .saturating_add(T::DbWeight::get().reads(15 as u64)) .saturating_add(T::DbWeight::get().writes(10 as u64)) } @@ -129,7 +127,7 @@ impl WeightInfo for HydraWeight { // Storage: Uniques CollectionMaxSupply (r:1 w:0) // Proof: Uniques CollectionMaxSupply (max_values: None, max_size: Some(36), added: 2511, mode: MaxEncodedLen) // Storage: AssetRegistry Assets (r:2 w:0) - // Proof Skipped: AssetRegistry Assets (max_values: None, max_size: None, mode: Measured) + // Proof: AssetRegistry Assets (max_values: None, max_size: Some(87), added: 2562, 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) @@ -137,7 +135,7 @@ impl WeightInfo for HydraWeight { // Storage: Omnipool TvlCap (r:1 w:0) // Proof: Omnipool TvlCap (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(2961), added: 3456, mode: MaxEncodedLen) + // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(5921), added: 6416, mode: MaxEncodedLen) // Storage: CircuitBreaker LiquidityAddLimitPerAsset (r:1 w:0) // Proof: CircuitBreaker LiquidityAddLimitPerAsset (max_values: None, max_size: Some(29), added: 2504, mode: MaxEncodedLen) // Storage: CircuitBreaker AllowedAddLiquidityAmountPerAsset (r:1 w:1) @@ -151,8 +149,8 @@ impl WeightInfo for HydraWeight { // Storage: Omnipool Positions (r:0 w:1) // Proof: Omnipool Positions (max_values: None, max_size: Some(100), added: 2575, mode: MaxEncodedLen) fn add_liquidity() -> Weight { - // Minimum execution time: 225_812 nanoseconds. - Weight::from_ref_time(227_537_000 as u64) + // Minimum execution time: 233_542 nanoseconds. + Weight::from_ref_time(235_489_000 as u64) .saturating_add(T::DbWeight::get().reads(23 as u64)) .saturating_add(T::DbWeight::get().writes(14 as u64)) } @@ -169,7 +167,7 @@ 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 Skipped: AssetRegistry Assets (max_values: None, max_size: None, mode: Measured) + // 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: Tokens TotalIssuance (r:1 w:1) @@ -181,7 +179,7 @@ impl WeightInfo for HydraWeight { // Storage: Uniques Class (r:1 w:1) // Proof: Uniques Class (max_values: None, max_size: Some(190), added: 2665, mode: MaxEncodedLen) // Storage: EmaOracle Accumulator (r:1 w:1) - // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(2961), added: 3456, mode: MaxEncodedLen) + // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(5921), added: 6416, mode: MaxEncodedLen) // Storage: CircuitBreaker LiquidityAddLimitPerAsset (r:1 w:0) // Proof: CircuitBreaker LiquidityAddLimitPerAsset (max_values: None, max_size: Some(29), added: 2504, mode: MaxEncodedLen) // Storage: CircuitBreaker AllowedAddLiquidityAmountPerAsset (r:1 w:0) @@ -195,8 +193,8 @@ impl WeightInfo for HydraWeight { // Storage: Uniques ItemPriceOf (r:0 w:1) // Proof: Uniques ItemPriceOf (max_values: None, max_size: Some(113), added: 2588, mode: MaxEncodedLen) fn remove_liquidity() -> Weight { - // Minimum execution time: 282_512 nanoseconds. - Weight::from_ref_time(284_772_000 as u64) + // Minimum execution time: 295_371 nanoseconds. + Weight::from_ref_time(297_465_000 as u64) .saturating_add(T::DbWeight::get().reads(23 as u64)) .saturating_add(T::DbWeight::get().writes(16 as u64)) } @@ -206,8 +204,12 @@ impl WeightInfo for HydraWeight { // Proof: Omnipool Assets (max_values: None, max_size: Some(85), added: 2560, 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: DynamicFees AssetFee (r:1 w:0) + // Proof: DynamicFees AssetFee (max_values: None, max_size: Some(24), added: 2499, mode: MaxEncodedLen) + // Storage: EmaOracle Oracles (r:1 w:0) + // Proof: EmaOracle Oracles (max_values: None, max_size: Some(177), added: 2652, mode: MaxEncodedLen) // Storage: AssetRegistry Assets (r:2 w:0) - // Proof Skipped: AssetRegistry Assets (max_values: None, max_size: None, mode: Measured) + // 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:1) @@ -215,7 +217,7 @@ impl WeightInfo for HydraWeight { // 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) - // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(2961), added: 3456, mode: MaxEncodedLen) + // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(5921), added: 6416, mode: MaxEncodedLen) // Storage: CircuitBreaker AllowedTradeVolumeLimitPerAsset (r:2 w:2) // Proof: CircuitBreaker AllowedTradeVolumeLimitPerAsset (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen) // Storage: CircuitBreaker LiquidityAddLimitPerAsset (r:1 w:0) @@ -227,9 +229,9 @@ impl WeightInfo for HydraWeight { // Storage: CircuitBreaker AllowedRemoveLiquidityAmountPerAsset (r:1 w:0) // Proof: CircuitBreaker AllowedRemoveLiquidityAmountPerAsset (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) fn sell() -> Weight { - // Minimum execution time: 231_087 nanoseconds. - Weight::from_ref_time(232_886_000 as u64) - .saturating_add(T::DbWeight::get().reads(21 as u64)) + // Minimum execution time: 258_297 nanoseconds. + Weight::from_ref_time(260_217_000 as u64) + .saturating_add(T::DbWeight::get().reads(23 as u64)) .saturating_add(T::DbWeight::get().writes(14 as u64)) } // Storage: Omnipool Assets (r:3 w:3) @@ -238,8 +240,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: DynamicFees AssetFee (r:1 w:1) + // 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 Assets (r:2 w:0) - // Proof Skipped: AssetRegistry Assets (max_values: None, max_size: None, mode: Measured) + // 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:1) @@ -247,7 +253,7 @@ impl WeightInfo for HydraWeight { // 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) - // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(2961), added: 3456, mode: MaxEncodedLen) + // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(5921), added: 6416, mode: MaxEncodedLen) // Storage: CircuitBreaker AllowedTradeVolumeLimitPerAsset (r:2 w:2) // Proof: CircuitBreaker AllowedTradeVolumeLimitPerAsset (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen) // Storage: CircuitBreaker LiquidityAddLimitPerAsset (r:1 w:0) @@ -259,16 +265,16 @@ impl WeightInfo for HydraWeight { // Storage: CircuitBreaker AllowedRemoveLiquidityAmountPerAsset (r:1 w:0) // Proof: CircuitBreaker AllowedRemoveLiquidityAmountPerAsset (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) fn buy() -> Weight { - // Minimum execution time: 232_699 nanoseconds. - Weight::from_ref_time(235_189_000 as u64) - .saturating_add(T::DbWeight::get().reads(21 as u64)) - .saturating_add(T::DbWeight::get().writes(14 as u64)) + // Minimum execution time: 279_260 nanoseconds. + Weight::from_ref_time(280_777_000 as u64) + .saturating_add(T::DbWeight::get().reads(24 as u64)) + .saturating_add(T::DbWeight::get().writes(15 as u64)) } // Storage: Omnipool Assets (r:1 w:1) // Proof: Omnipool Assets (max_values: None, max_size: Some(85), added: 2560, mode: MaxEncodedLen) fn set_asset_tradable_state() -> Weight { - // Minimum execution time: 33_283 nanoseconds. - Weight::from_ref_time(33_775_000 as u64) + // Minimum execution time: 33_892 nanoseconds. + Weight::from_ref_time(34_292_000 as u64) .saturating_add(T::DbWeight::get().reads(1 as u64)) .saturating_add(T::DbWeight::get().writes(1 as u64)) } @@ -277,7 +283,7 @@ impl WeightInfo for HydraWeight { // 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 Skipped: AssetRegistry Assets (max_values: None, max_size: None, mode: Measured) + // 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:1 w:1) @@ -285,8 +291,8 @@ impl WeightInfo for HydraWeight { // Storage: MultiTransactionPayment AcceptedCurrencies (r:1 w:0) // Proof: MultiTransactionPayment AcceptedCurrencies (max_values: None, max_size: Some(28), added: 2503, mode: MaxEncodedLen) fn refund_refused_asset() -> Weight { - // Minimum execution time: 104_885 nanoseconds. - Weight::from_ref_time(105_462_000 as u64) + // Minimum execution time: 109_440 nanoseconds. + Weight::from_ref_time(110_207_000 as u64) .saturating_add(T::DbWeight::get().reads(8 as u64)) .saturating_add(T::DbWeight::get().writes(5 as u64)) } @@ -303,16 +309,16 @@ impl WeightInfo for HydraWeight { // Storage: Uniques ItemPriceOf (r:0 w:1) // Proof: Uniques ItemPriceOf (max_values: None, max_size: Some(113), added: 2588, mode: MaxEncodedLen) fn sacrifice_position() -> Weight { - // Minimum execution time: 74_980 nanoseconds. - Weight::from_ref_time(75_595_000 as u64) + // Minimum execution time: 77_870 nanoseconds. + Weight::from_ref_time(78_533_000 as u64) .saturating_add(T::DbWeight::get().reads(4 as u64)) .saturating_add(T::DbWeight::get().writes(6 as u64)) } // Storage: Omnipool Assets (r:1 w:1) // Proof: Omnipool Assets (max_values: None, max_size: Some(85), added: 2560, mode: MaxEncodedLen) fn set_asset_weight_cap() -> Weight { - // Minimum execution time: 33_345 nanoseconds. - Weight::from_ref_time(33_948_000 as u64) + // Minimum execution time: 34_229 nanoseconds. + Weight::from_ref_time(34_689_000 as u64) .saturating_add(T::DbWeight::get().reads(1 as u64)) .saturating_add(T::DbWeight::get().writes(1 as u64)) } @@ -335,7 +341,7 @@ impl WeightInfo for HydraWeight { // 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) - // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(2961), added: 3456, mode: MaxEncodedLen) + // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(5921), added: 6416, mode: MaxEncodedLen) // Storage: CircuitBreaker AllowedTradeVolumeLimitPerAsset (r:2 w:2) // Proof: CircuitBreaker AllowedTradeVolumeLimitPerAsset (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen) // Storage: CircuitBreaker LiquidityAddLimitPerAsset (r:1 w:0) @@ -346,11 +352,17 @@ impl WeightInfo for HydraWeight { // Proof: CircuitBreaker LiquidityRemoveLimitPerAsset (max_values: None, max_size: Some(29), added: 2504, mode: MaxEncodedLen) // Storage: CircuitBreaker AllowedRemoveLiquidityAmountPerAsset (r:1 w:0) // Proof: CircuitBreaker AllowedRemoveLiquidityAmountPerAsset (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) - fn router_execution_sell() -> Weight { - // Minimum execution time: 269_857 nanoseconds. - Weight::from_ref_time(271_611_000 as u64) - .saturating_add(T::DbWeight::get().reads(23 as u64)) - .saturating_add(T::DbWeight::get().writes(14 as u64)) + /// The range of component `c` is `[0, 1]`. + /// The range of component `e` is `[0, 1]`. + fn router_execution_sell(c: u32, e: u32) -> Weight { + // Minimum execution time: 54_153 nanoseconds. + Weight::from_ref_time(40_444_373 as u64) // Standard Error: 79_703 + .saturating_add(Weight::from_ref_time(14_755_626 as u64).saturating_mul(c as u64)) + // Standard Error: 79_703 + .saturating_add(Weight::from_ref_time(219_012_766 as u64).saturating_mul(e as u64)) + .saturating_add(T::DbWeight::get().reads(7 as u64)) + .saturating_add(T::DbWeight::get().reads((16 as u64).saturating_mul(e as u64))) + .saturating_add(T::DbWeight::get().writes((14 as u64).saturating_mul(e as u64))) } // Storage: Omnipool Assets (r:3 w:3) // Proof: Omnipool Assets (max_values: None, max_size: Some(85), added: 2560, mode: MaxEncodedLen) @@ -371,7 +383,7 @@ impl WeightInfo for HydraWeight { // 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) - // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(2961), added: 3456, mode: MaxEncodedLen) + // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(5921), added: 6416, mode: MaxEncodedLen) // Storage: CircuitBreaker AllowedTradeVolumeLimitPerAsset (r:2 w:2) // Proof: CircuitBreaker AllowedTradeVolumeLimitPerAsset (max_values: None, max_size: Some(68), added: 2543, mode: MaxEncodedLen) // Storage: CircuitBreaker LiquidityAddLimitPerAsset (r:1 w:0) @@ -382,9 +394,12 @@ impl WeightInfo for HydraWeight { // Proof: CircuitBreaker LiquidityRemoveLimitPerAsset (max_values: None, max_size: Some(29), added: 2504, mode: MaxEncodedLen) // Storage: CircuitBreaker AllowedRemoveLiquidityAmountPerAsset (r:1 w:0) // Proof: CircuitBreaker AllowedRemoveLiquidityAmountPerAsset (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) - fn router_execution_buy() -> Weight { - // Minimum execution time: 288_769 nanoseconds. - Weight::from_ref_time(290_860_000 as u64) + /// 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 { + // Minimum execution time: 277_855 nanoseconds. + Weight::from_ref_time(269_412_275 as u64) // Standard Error: 112_640 + .saturating_add(Weight::from_ref_time(12_219_983 as u64).saturating_mul(c as u64)) .saturating_add(T::DbWeight::get().reads(24 as u64)) .saturating_add(T::DbWeight::get().writes(15 as u64)) } diff --git a/runtime/hydradx/src/weights/route_executor.rs b/runtime/hydradx/src/weights/route_executor.rs index b715d6812..6dcd44bb5 100644 --- a/runtime/hydradx/src/weights/route_executor.rs +++ b/runtime/hydradx/src/weights/route_executor.rs @@ -18,7 +18,7 @@ //! Autogenerated weights for pallet_route_executor //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-09-11, STEPS: 10, REPEAT: 30, LOW RANGE: [], HIGH RANGE: [] +//! DATE: 2023-10-06, STEPS: 10, REPEAT: 30, LOW RANGE: [], HIGH RANGE: [] //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 // Executed Command: @@ -33,8 +33,8 @@ // --heap-pages=4096 // --template=.maintain/pallet-weight-template-no-back.hbs // --pallet=pallet-route-executor +// --output=route-executor.rs // --extrinsic=* -// --output=route_executor.rs #![allow(unused_parens)] #![allow(unused_imports)] @@ -52,36 +52,48 @@ use pallet_route_executor::weights::WeightInfo; 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: System Account (r:3 w:3) // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) // Storage: Tokens Accounts (r:2 w:2) // Proof: Tokens Accounts (max_values: None, max_size: Some(108), added: 2583, mode: MaxEncodedLen) - // Storage: LBP PoolData (r:1 w:0) - // Proof: LBP PoolData (max_values: None, max_size: Some(163), added: 2638, 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 Assets (r:1 w:0) // Proof: AssetRegistry Assets (max_values: None, max_size: Some(87), added: 2562, mode: MaxEncodedLen) - fn sell_in_lbp() -> Weight { - // Minimum execution time: 225_028 nanoseconds. - Weight::from_ref_time(229_826_000 as u64) - .saturating_add(T::DbWeight::get().reads(8 as u64)) - .saturating_add(T::DbWeight::get().writes(6 as u64)) + /// The range of component `c` is `[0, 1]`. + /// The range of component `s` is `[0, 1]`. + fn calculate_and_execute_sell_in_lbp(c: u32, s: u32) -> Weight { + // Minimum execution time: 74_851 nanoseconds. + Weight::from_ref_time(26_266_260 as u64) // Standard Error: 251_240 + .saturating_add(Weight::from_ref_time(49_596_533 as u64).saturating_mul(c as u64)) + // Standard Error: 251_240 + .saturating_add(Weight::from_ref_time(252_604_739 as u64).saturating_mul(s as u64)) + .saturating_add(T::DbWeight::get().reads(3 as u64)) + .saturating_add(T::DbWeight::get().reads((5 as u64).saturating_mul(s as u64))) + .saturating_add(T::DbWeight::get().writes((6 as u64).saturating_mul(s as u64))) } - // Storage: System Account (r:3 w:3) - // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) // Storage: LBP PoolData (r:1 w:0) // Proof: LBP PoolData (max_values: None, max_size: Some(163), added: 2638, mode: MaxEncodedLen) + // Storage: System Account (r:3 w:3) + // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) // Storage: Tokens Accounts (r:2 w:2) // Proof: Tokens Accounts (max_values: None, max_size: Some(108), added: 2583, 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 Assets (r:1 w:0) // Proof: AssetRegistry Assets (max_values: None, max_size: Some(87), added: 2562, mode: MaxEncodedLen) - fn buy_in_lbp() -> Weight { - // Minimum execution time: 219_890 nanoseconds. - Weight::from_ref_time(221_506_000 as u64) - .saturating_add(T::DbWeight::get().reads(8 as u64)) - .saturating_add(T::DbWeight::get().writes(6 as u64)) + /// 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 { + // Minimum execution time: 73_996 nanoseconds. + Weight::from_ref_time(74_590_000 as u64) // Standard Error: 576_133 + .saturating_add(Weight::from_ref_time(2_213_808 as u64).saturating_mul(c as u64)) + // Standard Error: 1_264_777 + .saturating_add(Weight::from_ref_time(205_965_931 as u64).saturating_mul(b as u64)) + .saturating_add(T::DbWeight::get().reads(3 as u64)) + .saturating_add(T::DbWeight::get().reads((5 as u64).saturating_mul(b as u64))) + .saturating_add(T::DbWeight::get().writes((6 as u64).saturating_mul(b as u64))) } } diff --git a/runtime/hydradx/src/weights/stableswap.rs b/runtime/hydradx/src/weights/stableswap.rs index 800268d66..4dfeff816 100644 --- a/runtime/hydradx/src/weights/stableswap.rs +++ b/runtime/hydradx/src/weights/stableswap.rs @@ -18,25 +18,23 @@ //! Autogenerated weights for pallet_stableswap //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-10-05, STEPS: 5, REPEAT: 20, LOW RANGE: [], HIGH RANGE: [] +//! DATE: 2023-10-06, STEPS: 10, REPEAT: 30, 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-stableswap +// --chain=dev +// --steps=10 +// --repeat=30 // --execution=wasm // --wasm-execution=compiled // --heap-pages=4096 -// --chain=dev +// --template=.maintain/pallet-weight-template-no-back.hbs +// --pallet=pallet-stableswap +// --output=stableswap.rs // --extrinsic=* -// --steps=5 -// --repeat=20 -// --output -// stableswap.rs -// --template -// .maintain/pallet-weight-template-no-back.hbs #![allow(unused_parens)] #![allow(unused_imports)] @@ -61,8 +59,8 @@ impl WeightInfo for HydraWeight { // 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 { - // Minimum execution time: 50_861 nanoseconds. - Weight::from_ref_time(51_661_000 as u64) + // Minimum execution time: 50_068 nanoseconds. + Weight::from_ref_time(50_557_000 as u64) .saturating_add(T::DbWeight::get().reads(7 as u64)) .saturating_add(T::DbWeight::get().writes(2 as u64)) } @@ -87,8 +85,8 @@ impl WeightInfo for HydraWeight { // 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 { - // Minimum execution time: 1_169_990 nanoseconds. - Weight::from_ref_time(1_196_909_000 as u64) + // Minimum execution time: 1_140_516 nanoseconds. + Weight::from_ref_time(1_143_845_000 as u64) .saturating_add(T::DbWeight::get().reads(33 as u64)) .saturating_add(T::DbWeight::get().writes(14 as u64)) } @@ -111,8 +109,8 @@ impl WeightInfo for HydraWeight { // 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 { - // Minimum execution time: 798_526 nanoseconds. - Weight::from_ref_time(800_618_000 as u64) + // Minimum execution time: 783_827 nanoseconds. + Weight::from_ref_time(787_422_000 as u64) .saturating_add(T::DbWeight::get().reads(20 as u64)) .saturating_add(T::DbWeight::get().writes(6 as u64)) } @@ -137,8 +135,8 @@ impl WeightInfo for HydraWeight { // Storage: MultiTransactionPayment AccountCurrencyMap (r:0 w:1) // Proof: MultiTransactionPayment AccountCurrencyMap (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) fn remove_liquidity_one_asset() -> Weight { - // Minimum execution time: 836_289 nanoseconds. - Weight::from_ref_time(837_878_000 as u64) + // Minimum execution time: 817_053 nanoseconds. + Weight::from_ref_time(821_506_000 as u64) .saturating_add(T::DbWeight::get().reads(21 as u64)) .saturating_add(T::DbWeight::get().writes(7 as u64)) } @@ -163,8 +161,8 @@ impl WeightInfo for HydraWeight { // Storage: EmaOracle Accumulator (r:1 w:1) // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(5921), added: 6416, mode: MaxEncodedLen) fn withdraw_asset_amount() -> Weight { - // Minimum execution time: 1_121_002 nanoseconds. - Weight::from_ref_time(1_127_115_000 as u64) + // Minimum execution time: 1_124_456 nanoseconds. + Weight::from_ref_time(1_133_226_000 as u64) .saturating_add(T::DbWeight::get().reads(22 as u64)) .saturating_add(T::DbWeight::get().writes(6 as u64)) } @@ -189,8 +187,8 @@ impl WeightInfo for HydraWeight { // Storage: MultiTransactionPayment AccountCurrencyMap (r:0 w:1) // Proof: MultiTransactionPayment AccountCurrencyMap (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) fn sell() -> Weight { - // Minimum execution time: 777_852 nanoseconds. - Weight::from_ref_time(779_850_000 as u64) + // Minimum execution time: 768_776 nanoseconds. + Weight::from_ref_time(772_108_000 as u64) .saturating_add(T::DbWeight::get().reads(22 as u64)) .saturating_add(T::DbWeight::get().writes(7 as u64)) } @@ -215,8 +213,8 @@ impl WeightInfo for HydraWeight { // 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 { - // Minimum execution time: 760_607 nanoseconds. - Weight::from_ref_time(762_790_000 as u64) + // Minimum execution time: 747_434 nanoseconds. + Weight::from_ref_time(751_463_000 as u64) .saturating_add(T::DbWeight::get().reads(23 as u64)) .saturating_add(T::DbWeight::get().writes(6 as u64)) } @@ -225,24 +223,24 @@ impl WeightInfo for HydraWeight { // Storage: Stableswap AssetTradability (r:1 w:1) // Proof: Stableswap AssetTradability (max_values: None, max_size: Some(41), added: 2516, mode: MaxEncodedLen) fn set_asset_tradable_state() -> Weight { - // Minimum execution time: 24_372 nanoseconds. - Weight::from_ref_time(24_723_000 as u64) + // Minimum execution time: 24_470 nanoseconds. + Weight::from_ref_time(24_889_000 as u64) .saturating_add(T::DbWeight::get().reads(2 as u64)) .saturating_add(T::DbWeight::get().writes(1 as u64)) } // Storage: Stableswap Pools (r:1 w:1) // Proof: Stableswap Pools (max_values: None, max_size: Some(57), added: 2532, mode: MaxEncodedLen) fn update_pool_fee() -> Weight { - // Minimum execution time: 23_097 nanoseconds. - Weight::from_ref_time(23_531_000 as u64) + // Minimum execution time: 22_217 nanoseconds. + Weight::from_ref_time(22_890_000 as u64) .saturating_add(T::DbWeight::get().reads(1 as u64)) .saturating_add(T::DbWeight::get().writes(1 as u64)) } // Storage: Stableswap Pools (r:1 w:1) // Proof: Stableswap Pools (max_values: None, max_size: Some(57), added: 2532, mode: MaxEncodedLen) fn update_amplification() -> Weight { - // Minimum execution time: 24_390 nanoseconds. - Weight::from_ref_time(24_769_000 as u64) + // Minimum execution time: 24_168 nanoseconds. + Weight::from_ref_time(24_902_000 as u64) .saturating_add(T::DbWeight::get().reads(1 as u64)) .saturating_add(T::DbWeight::get().writes(1 as u64)) } @@ -266,11 +264,17 @@ impl WeightInfo for HydraWeight { // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(5921), added: 6416, mode: MaxEncodedLen) // Storage: MultiTransactionPayment AccountCurrencyMap (r:0 w:1) // Proof: MultiTransactionPayment AccountCurrencyMap (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) - fn router_execution_sell() -> Weight { - // Minimum execution time: 1_085_518 nanoseconds. - Weight::from_ref_time(1_089_781_000 as u64) - .saturating_add(T::DbWeight::get().reads(22 as u64)) - .saturating_add(T::DbWeight::get().writes(7 as u64)) + /// The range of component `c` is `[0, 1]`. + /// The range of component `e` is `[0, 1]`. + fn router_execution_sell(c: u32, e: u32) -> Weight { + // Minimum execution time: 333_504 nanoseconds. + Weight::from_ref_time(30_352_727 as u64) // Standard Error: 262_827 + .saturating_add(Weight::from_ref_time(304_810_632 as u64).saturating_mul(c as u64)) + // Standard Error: 262_827 + .saturating_add(Weight::from_ref_time(742_434_706 as u64).saturating_mul(e as u64)) + .saturating_add(T::DbWeight::get().reads(11 as u64)) + .saturating_add(T::DbWeight::get().reads((11 as u64).saturating_mul(e as u64))) + .saturating_add(T::DbWeight::get().writes((7 as u64).saturating_mul(e as u64))) } // Storage: Stableswap Pools (r:1 w:0) // Proof: Stableswap Pools (max_values: None, max_size: Some(57), added: 2532, mode: MaxEncodedLen) @@ -292,10 +296,16 @@ impl WeightInfo for HydraWeight { // 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 router_execution_buy() -> Weight { - // Minimum execution time: 1_067_098 nanoseconds. - Weight::from_ref_time(1_069_574_000 as u64) - .saturating_add(T::DbWeight::get().reads(23 as u64)) - .saturating_add(T::DbWeight::get().writes(6 as u64)) + /// 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 { + // Minimum execution time: 333_253 nanoseconds. + Weight::from_ref_time(334_206_000 as u64) // Standard Error: 3_608_102 + .saturating_add(Weight::from_ref_time(13_465_646 as u64).saturating_mul(c as u64)) + // Standard Error: 7_920_813 + .saturating_add(Weight::from_ref_time(456_375_218 as u64).saturating_mul(e as u64)) + .saturating_add(T::DbWeight::get().reads(11 as u64)) + .saturating_add(T::DbWeight::get().reads((12 as u64).saturating_mul(e as u64))) + .saturating_add(T::DbWeight::get().writes((6 as u64).saturating_mul(e as u64))) } } diff --git a/runtime/hydradx/src/weights/xyk.rs b/runtime/hydradx/src/weights/xyk.rs index 5c5249c9e..4395c4aaa 100644 --- a/runtime/hydradx/src/weights/xyk.rs +++ b/runtime/hydradx/src/weights/xyk.rs @@ -18,7 +18,7 @@ //! Autogenerated weights for pallet_xyk //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-09-12, STEPS: 10, REPEAT: 30, LOW RANGE: [], HIGH RANGE: [] +//! DATE: 2023-10-06, STEPS: 10, REPEAT: 30, LOW RANGE: [], HIGH RANGE: [] //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 // Executed Command: @@ -33,7 +33,7 @@ // --heap-pages=4096 // --template=.maintain/pallet-weight-template-no-back.hbs // --pallet=pallet-xyk -// --output=xyk_no_back.rs +// --output=xyk.rs // --extrinsic=* #![allow(unused_parens)] @@ -52,8 +52,6 @@ use pallet_xyk::weights::WeightInfo; pub struct HydraWeight(PhantomData); impl WeightInfo for HydraWeight { - // Storage: ParachainSystem ValidationData (r:1 w:0) - // Proof Skipped: ParachainSystem ValidationData (max_values: Some(1), max_size: None, mode: Measured) // 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) @@ -81,9 +79,9 @@ impl WeightInfo for HydraWeight { // 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 { - // Minimum execution time: 188_886 nanoseconds. - Weight::from_ref_time(190_128_000 as u64) - .saturating_add(T::DbWeight::get().reads(18 as u64)) + // Minimum execution time: 190_185 nanoseconds. + Weight::from_ref_time(192_567_000 as u64) + .saturating_add(T::DbWeight::get().reads(17 as u64)) .saturating_add(T::DbWeight::get().writes(16 as u64)) } // Storage: XYK ShareToken (r:1 w:0) @@ -101,10 +99,10 @@ impl WeightInfo for HydraWeight { // Storage: MultiTransactionPayment AccountCurrencyMap (r:1 w:0) // Proof: MultiTransactionPayment AccountCurrencyMap (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) // Storage: EmaOracle Accumulator (r:1 w:1) - // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(2961), added: 3456, mode: MaxEncodedLen) + // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(5921), added: 6416, mode: MaxEncodedLen) fn add_liquidity() -> Weight { - // Minimum execution time: 163_318 nanoseconds. - Weight::from_ref_time(164_777_000 as u64) + // Minimum execution time: 164_323 nanoseconds. + Weight::from_ref_time(165_841_000 as u64) .saturating_add(T::DbWeight::get().reads(14 as u64)) .saturating_add(T::DbWeight::get().writes(9 as u64)) } @@ -121,10 +119,10 @@ impl WeightInfo for HydraWeight { // 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(2961), added: 3456, mode: MaxEncodedLen) + // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(5921), added: 6416, mode: MaxEncodedLen) fn remove_liquidity() -> Weight { - // Minimum execution time: 153_848 nanoseconds. - Weight::from_ref_time(154_840_000 as u64) + // Minimum execution time: 155_404 nanoseconds. + Weight::from_ref_time(156_560_000 as u64) .saturating_add(T::DbWeight::get().reads(13 as u64)) .saturating_add(T::DbWeight::get().writes(8 as u64)) } @@ -137,10 +135,10 @@ impl WeightInfo for HydraWeight { // Storage: System Account (r:2 w:0) // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) // Storage: EmaOracle Accumulator (r:1 w:1) - // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(2961), added: 3456, mode: MaxEncodedLen) + // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(5921), added: 6416, mode: MaxEncodedLen) fn sell() -> Weight { - // Minimum execution time: 117_193 nanoseconds. - Weight::from_ref_time(118_353_000 as u64) + // Minimum execution time: 119_610 nanoseconds. + Weight::from_ref_time(120_418_000 as u64) .saturating_add(T::DbWeight::get().reads(10 as u64)) .saturating_add(T::DbWeight::get().writes(5 as u64)) } @@ -153,10 +151,10 @@ impl WeightInfo for HydraWeight { // Storage: System Account (r:2 w:0) // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) // Storage: EmaOracle Accumulator (r:1 w:1) - // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(2961), added: 3456, mode: MaxEncodedLen) + // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(5921), added: 6416, mode: MaxEncodedLen) fn buy() -> Weight { - // Minimum execution time: 117_277 nanoseconds. - Weight::from_ref_time(118_170_000 as u64) + // Minimum execution time: 119_865 nanoseconds. + Weight::from_ref_time(120_541_000 as u64) .saturating_add(T::DbWeight::get().reads(10 as u64)) .saturating_add(T::DbWeight::get().writes(5 as u64)) } @@ -169,12 +167,18 @@ impl WeightInfo for HydraWeight { // Storage: System Account (r:2 w:0) // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) // Storage: EmaOracle Accumulator (r:1 w:1) - // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(2961), added: 3456, mode: MaxEncodedLen) - fn trade_execution_sell() -> Weight { - // Minimum execution time: 122_926 nanoseconds. - Weight::from_ref_time(124_505_000 as u64) - .saturating_add(T::DbWeight::get().reads(10 as u64)) - .saturating_add(T::DbWeight::get().writes(5 as u64)) + // 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 { + // Minimum execution time: 20_906 nanoseconds. + Weight::from_ref_time(8_365_948 as u64) // Standard Error: 43_229 + .saturating_add(Weight::from_ref_time(6_554_981 as u64).saturating_mul(c as u64)) + // Standard Error: 43_229 + .saturating_add(Weight::from_ref_time(105_218_621 as u64).saturating_mul(e as u64)) + .saturating_add(T::DbWeight::get().reads(3 as u64)) + .saturating_add(T::DbWeight::get().reads((7 as u64).saturating_mul(e as u64))) + .saturating_add(T::DbWeight::get().writes((5 as u64).saturating_mul(e as u64))) } // Storage: XYK ShareToken (r:1 w:0) // Proof: XYK ShareToken (max_values: None, max_size: Some(52), added: 2527, mode: MaxEncodedLen) @@ -185,11 +189,17 @@ impl WeightInfo for HydraWeight { // Storage: System Account (r:2 w:0) // Proof: System Account (max_values: None, max_size: Some(128), added: 2603, mode: MaxEncodedLen) // Storage: EmaOracle Accumulator (r:1 w:1) - // Proof: EmaOracle Accumulator (max_values: Some(1), max_size: Some(2961), added: 3456, mode: MaxEncodedLen) - fn trade_execution_buy() -> Weight { - // Minimum execution time: 124_161 nanoseconds. - Weight::from_ref_time(124_836_000 as u64) - .saturating_add(T::DbWeight::get().reads(10 as u64)) - .saturating_add(T::DbWeight::get().writes(5 as u64)) + // 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 { + // Minimum execution time: 27_261 nanoseconds. + Weight::from_ref_time(7_044_054 as u64) // Standard Error: 46_197 + .saturating_add(Weight::from_ref_time(7_022_106 as u64).saturating_mul(c as u64)) + // Standard Error: 78_379 + .saturating_add(Weight::from_ref_time(105_927_586 as u64).saturating_mul(e as u64)) + .saturating_add(T::DbWeight::get().reads(3 as u64)) + .saturating_add(T::DbWeight::get().reads((7 as u64).saturating_mul(e as u64))) + .saturating_add(T::DbWeight::get().writes((5 as u64).saturating_mul(e as u64))) } } diff --git a/traits/Cargo.toml b/traits/Cargo.toml index a35a68f0e..8a236ed39 100644 --- a/traits/Cargo.toml +++ b/traits/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hydradx-traits" -version = "2.6.1" +version = "2.7.0" description = "Shared traits" authors = ["GalacticCouncil"] edition = "2021" diff --git a/traits/src/router.rs b/traits/src/router.rs index 0c13e83fe..ed17e69c7 100644 --- a/traits/src/router.rs +++ b/traits/src/router.rs @@ -1,13 +1,8 @@ use codec::{Decode, Encode, MaxEncodedLen}; +use frame_support::sp_runtime::{DispatchError, DispatchResult}; +use frame_support::weights::Weight; use scale_info::TypeInfo; - -///A single trade for buy/sell, describing the asset pair and the pool type in which the trade is executed -#[derive(Encode, Decode, Debug, Eq, PartialEq, Copy, Clone, TypeInfo, MaxEncodedLen)] -pub struct Trade { - pub pool: PoolType, - pub asset_in: AssetId, - pub asset_out: AssetId, -} +use sp_std::vec::Vec; #[derive(Encode, Decode, Clone, Copy, Debug, Eq, PartialEq, TypeInfo, MaxEncodedLen)] pub enum PoolType { @@ -23,6 +18,44 @@ pub enum ExecutorError { Error(E), } +///A single trade for buy/sell, describing the asset pair and the pool type in which the trade is executed +#[derive(Encode, Decode, Debug, Eq, PartialEq, Copy, Clone, TypeInfo, MaxEncodedLen)] +pub struct Trade { + pub pool: PoolType, + pub asset_in: AssetId, + pub asset_out: AssetId, +} + +#[derive(Debug, PartialEq)] +pub struct AmountInAndOut { + pub amount_in: Balance, + pub amount_out: Balance, +} + +pub trait RouterT { + fn sell( + origin: Origin, + asset_in: AssetId, + asset_out: AssetId, + amount_in: Balance, + min_amount_out: Balance, + route: Vec, + ) -> DispatchResult; + + fn buy( + origin: Origin, + asset_in: AssetId, + asset_out: AssetId, + amount_out: Balance, + max_amount_in: Balance, + route: Vec, + ) -> DispatchResult; + + fn calculate_sell_trade_amounts(route: &[Trade], amount_in: Balance) -> Result, DispatchError>; + + fn calculate_buy_trade_amounts(route: &[Trade], amount_out: Balance) -> Result, DispatchError>; +} + /// All AMMs used in the router are required to implement this trait. pub trait TradeExecution { type Error; @@ -144,3 +177,30 @@ impl Err(value) } } + +/// Provides weight info for the router. Calculates the weight of a route based on the AMMs. +pub trait AmmTradeWeights { + fn sell_weight(route: &[Trade]) -> Weight; + fn buy_weight(route: &[Trade]) -> Weight; + fn calculate_buy_trade_amounts_weight(route: &[Trade]) -> Weight; + fn sell_and_calculate_sell_trade_amounts_weight(route: &[Trade]) -> Weight; + fn buy_and_calculate_buy_trade_amounts_weight(route: &[Trade]) -> Weight; +} + +impl AmmTradeWeights for () { + fn sell_weight(_route: &[Trade]) -> Weight { + Weight::zero() + } + fn buy_weight(_route: &[Trade]) -> Weight { + Weight::zero() + } + fn calculate_buy_trade_amounts_weight(_route: &[Trade]) -> Weight { + Weight::zero() + } + fn sell_and_calculate_sell_trade_amounts_weight(_route: &[Trade]) -> Weight { + Weight::zero() + } + fn buy_and_calculate_buy_trade_amounts_weight(_route: &[Trade]) -> Weight { + Weight::zero() + } +}