From 684c8a4116a7b55a33eb2def1a9c123a7a5fe50a Mon Sep 17 00:00:00 2001 From: Martin Date: Tue, 7 Nov 2023 12:08:58 +0100 Subject: [PATCH 01/16] remove tvl cap from omnipool --- Cargo.lock | 10 +- integration-tests/Cargo.toml | 2 +- integration-tests/src/circuit_breaker.rs | 16 +- integration-tests/src/dca.rs | 18 +- integration-tests/src/dynamic_fees.rs | 14 +- integration-tests/src/omnipool_init.rs | 7 +- .../src/omnipool_liquidity_mining.rs | 15 +- integration-tests/src/polkadot_test_net.rs | 27 +- pallets/circuit-breaker/Cargo.toml | 2 +- pallets/circuit-breaker/src/tests/mock.rs | 13 +- pallets/omnipool-liquidity-mining/Cargo.toml | 2 +- .../src/benchmarks.rs | 35 ++- .../src/tests/mock.rs | 1 - pallets/omnipool/Cargo.toml | 2 +- pallets/omnipool/src/lib.rs | 201 ++----------- pallets/omnipool/src/tests/add_liquidity.rs | 8 +- pallets/omnipool/src/tests/add_token.rs | 57 +++- pallets/omnipool/src/tests/buy.rs | 6 +- pallets/omnipool/src/tests/init_pool.rs | 238 --------------- pallets/omnipool/src/tests/invariants.rs | 27 -- pallets/omnipool/src/tests/mock.rs | 38 +-- pallets/omnipool/src/tests/mod.rs | 4 +- pallets/omnipool/src/tests/remove_token.rs | 21 -- pallets/omnipool/src/tests/sell.rs | 6 +- pallets/omnipool/src/tests/tvl.rs | 173 ----------- .../src/tests/verification/scenario_04.rs | 4 +- .../src/tests/verification/scenario_05.rs | 4 +- .../src/tests/verification/scenario_06.rs | 4 +- .../src/tests/verification/scenario_08.rs | 7 +- .../src/tests/verification/scenario_09.rs | 4 +- .../src/tests/verification/scenario_10.rs | 7 +- .../src/tests/verification/scenario_11.rs | 7 +- runtime/hydradx/Cargo.toml | 2 +- runtime/hydradx/src/assets.rs | 2 - runtime/hydradx/src/benchmarking/omnipool.rs | 276 +++--------------- runtime/hydradx/src/lib.rs | 2 +- 36 files changed, 263 insertions(+), 999 deletions(-) delete mode 100644 pallets/omnipool/src/tests/init_pool.rs delete mode 100644 pallets/omnipool/src/tests/tvl.rs diff --git a/Cargo.lock b/Cargo.lock index 09a5ab98c..b448b8881 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3831,7 +3831,7 @@ dependencies = [ [[package]] name = "hydradx-runtime" -version = "187.0.0" +version = "188.0.0" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", @@ -6449,7 +6449,7 @@ dependencies = [ [[package]] name = "pallet-circuit-breaker" -version = "1.1.16" +version = "1.1.17" dependencies = [ "frame-benchmarking", "frame-support", @@ -7117,7 +7117,7 @@ dependencies = [ [[package]] name = "pallet-omnipool" -version = "3.3.0" +version = "4.0.0" dependencies = [ "bitflags", "frame-benchmarking", @@ -7144,7 +7144,7 @@ dependencies = [ [[package]] name = "pallet-omnipool-liquidity-mining" -version = "2.0.11" +version = "2.0.12" dependencies = [ "bitflags", "frame-benchmarking", @@ -10218,7 +10218,7 @@ dependencies = [ [[package]] name = "runtime-integration-tests" -version = "1.15.1" +version = "1.15.2" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index 4bdac3b87..5636df6f3 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "runtime-integration-tests" -version = "1.15.1" +version = "1.15.2" description = "Integration tests" authors = ["GalacticCouncil"] edition = "2021" diff --git a/integration-tests/src/circuit_breaker.rs b/integration-tests/src/circuit_breaker.rs index b1d70eeb0..564567bd0 100644 --- a/integration-tests/src/circuit_breaker.rs +++ b/integration-tests/src/circuit_breaker.rs @@ -578,17 +578,19 @@ fn remove_liquidity_to_omnipool_should_not_fail_when_liquidity_limit_per_block_e } fn init_omnipool() { - assert_ok!(hydradx_runtime::Omnipool::set_tvl_cap( + assert_ok!(hydradx_runtime::Omnipool::add_token( hydradx_runtime::RuntimeOrigin::root(), - 222_222_000_000_000_000_000_000, + HDX, + FixedU128::from(1), + Permill::from_percent(100), + hydradx_runtime::Omnipool::protocol_account(), )); - - assert_ok!(Omnipool::initialize_pool( - RawOrigin::Root.into(), + assert_ok!(hydradx_runtime::Omnipool::add_token( + hydradx_runtime::RuntimeOrigin::root(), + DAI, FixedU128::from_float(0.00001), // adjust the amount of LRNA to roughly match the amount of LRNA that belongs to HDX. This way we can avoid MaxOutRatioExceeded error. - FixedU128::from(1), Permill::from_percent(100), - Permill::from_percent(100) + hydradx_runtime::Omnipool::protocol_account(), )); do_trading_activity_to_populate_oracle(); diff --git a/integration-tests/src/dca.rs b/integration-tests/src/dca.rs index ed15a02c8..853d75997 100644 --- a/integration-tests/src/dca.rs +++ b/integration-tests/src/dca.rs @@ -2227,8 +2227,6 @@ pub fn init_omnipol() { let stable_price = FixedU128::from_float(0.7); let acc = Omnipool::protocol_account(); - assert_ok!(Omnipool::set_tvl_cap(RuntimeOrigin::root(), u128::MAX)); - let stable_amount: Balance = 5_000_000_000_000_000_000_000u128; let native_amount: Balance = 5_000_000_000_000_000_000_000u128; assert_ok!(Tokens::set_balance( @@ -2245,12 +2243,20 @@ pub fn init_omnipol() { native_amount as i128, )); - assert_ok!(Omnipool::initialize_pool( - RuntimeOrigin::root(), - stable_price, + assert_ok!(hydradx_runtime::Omnipool::add_token( + hydradx_runtime::RuntimeOrigin::root(), + HDX, native_price, Permill::from_percent(60), - Permill::from_percent(60) + hydradx_runtime::Omnipool::protocol_account(), + )); + + assert_ok!(hydradx_runtime::Omnipool::add_token( + hydradx_runtime::RuntimeOrigin::root(), + DAI, + stable_price, + Permill::from_percent(60), + hydradx_runtime::Omnipool::protocol_account(), )); assert_ok!(Balances::set_balance( diff --git a/integration-tests/src/dynamic_fees.rs b/integration-tests/src/dynamic_fees.rs index 98da46493..1f7eb55b5 100644 --- a/integration-tests/src/dynamic_fees.rs +++ b/integration-tests/src/dynamic_fees.rs @@ -324,17 +324,19 @@ fn init_omnipool() { let native_price = FixedU128::from_inner(1201500000000000); let stable_price = FixedU128::from_inner(45_000_000_000); - assert_ok!(hydradx_runtime::Omnipool::set_tvl_cap( + assert_ok!(hydradx_runtime::Omnipool::add_token( hydradx_runtime::RuntimeOrigin::root(), - 522_222_000_000_000_000_000_000, + HDX, + native_price, + Permill::from_percent(10), + hydradx_runtime::Omnipool::protocol_account(), )); - - assert_ok!(hydradx_runtime::Omnipool::initialize_pool( + assert_ok!(hydradx_runtime::Omnipool::add_token( hydradx_runtime::RuntimeOrigin::root(), + DAI, stable_price, - native_price, Permill::from_percent(100), - Permill::from_percent(10) + hydradx_runtime::Omnipool::protocol_account(), )); let dot_price = FixedU128::from_inner(25_650_000_000_000_000_000); diff --git a/integration-tests/src/omnipool_init.rs b/integration-tests/src/omnipool_init.rs index a363f4107..9118d98ec 100644 --- a/integration-tests/src/omnipool_init.rs +++ b/integration-tests/src/omnipool_init.rs @@ -271,6 +271,8 @@ fn removing_token_should_work_when_no_shares_remaining() { let bob_account = AccountId::from(UNKNOWN); let dot_amount = 87_719_298_250_000_u128; + let position_id = hydradx_runtime::Omnipool::next_position_id(); + let token_price = FixedU128::from_inner(25_650_000_000_000_000_000); assert_ok!(hydradx_runtime::Omnipool::add_token( hydradx_runtime::RuntimeOrigin::root(), @@ -289,10 +291,11 @@ fn removing_token_should_work_when_no_shares_remaining() { )); let position = - pallet_omnipool::Pallet::::load_position(0, bob_account.clone()).unwrap(); + pallet_omnipool::Pallet::::load_position(position_id, bob_account.clone()) + .unwrap(); assert_ok!(hydradx_runtime::Omnipool::remove_liquidity( hydradx_runtime::RuntimeOrigin::signed(UNKNOWN.into()), - 0, + position_id, position.shares, )); diff --git a/integration-tests/src/omnipool_liquidity_mining.rs b/integration-tests/src/omnipool_liquidity_mining.rs index cd81be2a9..c47f31655 100644 --- a/integration-tests/src/omnipool_liquidity_mining.rs +++ b/integration-tests/src/omnipool_liquidity_mining.rs @@ -542,19 +542,20 @@ fn init_omnipool() { let native_price = FixedU128::from_inner(1201500000000000); let stable_price = FixedU128::from_inner(45_000_000_000); - assert_ok!(hydradx_runtime::Omnipool::set_tvl_cap( + assert_ok!(hydradx_runtime::Omnipool::add_token( hydradx_runtime::RuntimeOrigin::root(), - u128::MAX, + HDX, + native_price, + Permill::from_percent(10), + hydradx_runtime::Omnipool::protocol_account(), )); - - assert_ok!(hydradx_runtime::Omnipool::initialize_pool( + assert_ok!(hydradx_runtime::Omnipool::add_token( hydradx_runtime::RuntimeOrigin::root(), + DAI, stable_price, - native_price, Permill::from_percent(100), - Permill::from_percent(10) + hydradx_runtime::Omnipool::protocol_account(), )); - let token_price = FixedU128::from_inner(25_650_000_000_000_000_000); assert_ok!(hydradx_runtime::Omnipool::add_token( diff --git a/integration-tests/src/polkadot_test_net.rs b/integration-tests/src/polkadot_test_net.rs index c7fe25598..7c4dbbfa5 100644 --- a/integration-tests/src/polkadot_test_net.rs +++ b/integration-tests/src/polkadot_test_net.rs @@ -462,17 +462,34 @@ pub fn init_omnipool() { let native_price = FixedU128::from_inner(1201500000000000); let stable_price = FixedU128::from_inner(45_000_000_000); - assert_ok!(hydradx_runtime::Omnipool::set_tvl_cap( + let native_position_id = hydradx_runtime::Omnipool::next_position_id(); + + assert_ok!(hydradx_runtime::Omnipool::add_token( hydradx_runtime::RuntimeOrigin::root(), - 522_222_000_000_000_000_000_000, + HDX, + native_price, + Permill::from_percent(10), + AccountId::from(ALICE), )); - assert_ok!(hydradx_runtime::Omnipool::initialize_pool( + let stable_position_id = hydradx_runtime::Omnipool::next_position_id(); + + assert_ok!(hydradx_runtime::Omnipool::add_token( hydradx_runtime::RuntimeOrigin::root(), + DAI, stable_price, - native_price, Permill::from_percent(100), - Permill::from_percent(10) + AccountId::from(ALICE), + )); + + assert_ok!(hydradx_runtime::Omnipool::sacrifice_position( + hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), + native_position_id, + )); + + assert_ok!(hydradx_runtime::Omnipool::sacrifice_position( + hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), + stable_position_id, )); } diff --git a/pallets/circuit-breaker/Cargo.toml b/pallets/circuit-breaker/Cargo.toml index 6ebe64d55..c942ae40e 100644 --- a/pallets/circuit-breaker/Cargo.toml +++ b/pallets/circuit-breaker/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-circuit-breaker" -version = "1.1.16" +version = "1.1.17" authors = ["GalacticCouncil "] edition = "2021" license = "Apache-2.0" diff --git a/pallets/circuit-breaker/src/tests/mock.rs b/pallets/circuit-breaker/src/tests/mock.rs index 6ae036067..8e8f18e3b 100644 --- a/pallets/circuit-breaker/src/tests/mock.rs +++ b/pallets/circuit-breaker/src/tests/mock.rs @@ -582,12 +582,19 @@ impl ExtBuilder { if let Some((stable_price, native_price)) = self.init_pool { r.execute_with(|| { - assert_ok!(Omnipool::initialize_pool( + assert_ok!(Omnipool::add_token( RuntimeOrigin::root(), - stable_price, + HDXAssetId::get(), native_price, Permill::from_percent(100), - Permill::from_percent(100) + Omnipool::protocol_account(), + )); + assert_ok!(Omnipool::add_token( + RuntimeOrigin::root(), + DAIAssetId::get(), + stable_price, + Permill::from_percent(100), + Omnipool::protocol_account(), )); for (asset_id, price, owner, amount) in self.pool_tokens { diff --git a/pallets/omnipool-liquidity-mining/Cargo.toml b/pallets/omnipool-liquidity-mining/Cargo.toml index a327bf927..bf395d8b8 100644 --- a/pallets/omnipool-liquidity-mining/Cargo.toml +++ b/pallets/omnipool-liquidity-mining/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-omnipool-liquidity-mining" -version = "2.0.11" +version = "2.0.12" authors = ['GalacticCouncil'] edition = "2021" license = "Apache-2.0" diff --git a/pallets/omnipool-liquidity-mining/src/benchmarks.rs b/pallets/omnipool-liquidity-mining/src/benchmarks.rs index 5132a6f0c..2ee62126e 100644 --- a/pallets/omnipool-liquidity-mining/src/benchmarks.rs +++ b/pallets/omnipool-liquidity-mining/src/benchmarks.rs @@ -17,6 +17,7 @@ use crate::*; use frame_benchmarking::{account, benchmarks}; +use frame_support::assert_ok; use frame_support::traits::{OnFinalize, OnInitialize}; use frame_system::{Pallet as System, RawOrigin}; use hydradx_traits::Registry; @@ -30,6 +31,7 @@ const ONE: Balance = 1_000_000_000_000; const BTC_ONE: Balance = 100_000_000; const HDX: AssetId = 0; const LRNA: AssetId = 1; +const DAI: AssetId = 2; const BSX: AssetId = 1_000_001; const ETH: AssetId = 1_000_002; const BTC: AssetId = 1_000_003; @@ -89,29 +91,46 @@ where Pallet::::create_yield_farm(RawOrigin::Signed(owner).into(), id, asset, FixedU128::one(), None) } +fn update_balance(currency_id: AssetId, who: &T::AccountId, balance: Balance) { + assert_ok!( + <::Currency as MultiCurrencyExtended<_>>::update_balance( + currency_id, + who, + balance.saturated_into() + ) + ); +} + fn initialize_omnipool() -> DispatchResult where ::Currency: MultiCurrencyExtended, T: pallet_ema_oracle::Config, T::AssetId: From, { - let stable_amount: Balance = 1_000_000_000_000_000_u128; - let native_amount: Balance = 1_000_000_000_000_000_u128; + init()?; + let stable_amount: Balance = 1_000_000_000_000_000u128; + let native_amount: Balance = 1_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)?; + let acc = OmnipoolPallet::protocol_account(); - ::Currency::update_balance(T::StableCoinAssetId::get(), &acc, stable_amount as i128)?; - ::Currency::update_balance(T::HdxAssetId::get(), &acc, native_amount as i128)?; + update_balance(DAI, &acc, stable_amount); + update_balance(HDX, &acc, native_amount); - OmnipoolPallet::::initialize_pool( + OmnipoolPallet::add_token( RawOrigin::Root.into(), - stable_price, + HDX, native_price, Permill::from_percent(100), + acc.clone(), + )?; + OmnipoolPallet::add_token( + RawOrigin::Root.into(), + DAI, + stable_price, Permill::from_percent(100), + acc.clone(), )?; // Register new asset in asset registry diff --git a/pallets/omnipool-liquidity-mining/src/tests/mock.rs b/pallets/omnipool-liquidity-mining/src/tests/mock.rs index d1627a73d..e900624e1 100644 --- a/pallets/omnipool-liquidity-mining/src/tests/mock.rs +++ b/pallets/omnipool-liquidity-mining/src/tests/mock.rs @@ -277,7 +277,6 @@ impl pallet_omnipool::Config for Test { type Currency = Tokens; type AuthorityOrigin = EnsureRoot; type HubAssetId = LRNAAssetId; - type StableCoinAssetId = DAIAssetId; type WeightInfo = (); type HdxAssetId = HDXAssetId; type NFTCollectionId = PositionCollectionId; diff --git a/pallets/omnipool/Cargo.toml b/pallets/omnipool/Cargo.toml index dd64f492b..90a7e36e6 100644 --- a/pallets/omnipool/Cargo.toml +++ b/pallets/omnipool/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-omnipool" -version = "3.3.0" +version = "4.0.0" authors = ['GalacticCouncil'] edition = "2021" license = "Apache-2.0" diff --git a/pallets/omnipool/src/lib.rs b/pallets/omnipool/src/lib.rs index bebeaf2b6..b7ac14134 100644 --- a/pallets/omnipool/src/lib.rs +++ b/pallets/omnipool/src/lib.rs @@ -138,10 +138,10 @@ pub mod pallet { /// Multi currency mechanism type Currency: MultiCurrency; - /// Origin that can add token, refund refused asset and set tvl cap. + /// Origin that can add token, refund refused asset etc. type AuthorityOrigin: EnsureOrigin; - /// Origin to be able to suspend asset trades and initialize Omnipool. + /// Origin to be able to suspend asset trades. type TechnicalOrigin: EnsureOrigin; /// Asset Registry mechanism - used to check if asset is correctly registered in asset registry @@ -155,10 +155,6 @@ pub mod pallet { #[pallet::constant] type HubAssetId: Get; - /// Preferred stable Asset ID - #[pallet::constant] - type StableCoinAssetId: Get; - /// Asset and Protocol Fee for given asset type Fee: GetByKey; @@ -224,9 +220,16 @@ pub mod pallet { #[pallet::getter(fn current_imbalance)] pub(super) type HubAssetImbalance = StorageValue<_, SimpleImbalance, ValueQuery>; + // LRNA is only allowed to be sold + #[pallet::type_value] + pub fn DefaultHubAssetTradability() -> Tradability { + Tradability::SELL + } + #[pallet::storage] /// Tradable state of hub asset. - pub(super) type HubAssetTradability = StorageValue<_, Tradability, ValueQuery>; + pub(super) type HubAssetTradability = + StorageValue<_, Tradability, ValueQuery, DefaultHubAssetTradability>; #[pallet::storage] /// LP positions. Maps NFT instance id to corresponding position @@ -239,10 +242,6 @@ pub mod pallet { /// Position ids sequencer pub(super) type NextPositionId = StorageValue<_, T::PositionItemId, ValueQuery>; - #[pallet::storage] - /// TVL cap - pub(super) type TvlCap = StorageValue<_, Balance, ValueQuery>; - #[pallet::event] #[pallet::generate_deposit(pub(crate) fn deposit_event)] pub enum Event { @@ -336,9 +335,6 @@ pub mod pallet { /// Asset's weight cap has been updated. AssetWeightCapUpdated { asset_id: T::AssetId, cap: Permill }, - - /// TVL cap has been updated. - TVLCapUpdated { cap: Balance }, } #[pallet::error] @@ -372,8 +368,6 @@ pub mod pallet { Forbidden, /// Asset weight cap has been exceeded. AssetWeightCapExceeded, - /// TVL cap has been exceeded - TVLCapExceeded, /// Asset is not registered in asset registry AssetNotRegistered, /// Provided liquidity is below minimum allowed limit @@ -414,123 +408,6 @@ pub mod pallet { #[pallet::call] impl Pallet { - /// Initialize Omnipool with stable asset and native asset. - /// - /// First added assets must be: - /// - preferred stable coin asset set as `StableCoinAssetId` pallet parameter - /// - native asset - /// - /// Omnipool account must already have correct balances of stable and native asset. - /// - /// Parameters: - /// - `stable_asset_price`: Initial price of stable asset - /// - `native_asset_price`: Initial price of stable asset - /// - /// Emits two `TokenAdded` events when successful. - /// - #[pallet::call_index(0)] - #[pallet::weight(::WeightInfo::initialize_pool())] - #[transactional] - pub fn initialize_pool( - origin: OriginFor, - stable_asset_price: Price, - native_asset_price: Price, - stable_weight_cap: Permill, - native_weight_cap: Permill, - ) -> DispatchResult { - T::TechnicalOrigin::ensure_origin(origin)?; - - ensure!( - !Assets::::contains_key(T::StableCoinAssetId::get()), - Error::::AssetAlreadyAdded - ); - ensure!( - !Assets::::contains_key(T::HdxAssetId::get()), - Error::::AssetAlreadyAdded - ); - - ensure!( - stable_asset_price > FixedU128::zero(), - Error::::InvalidInitialAssetPrice - ); - ensure!( - native_asset_price > FixedU128::zero(), - Error::::InvalidInitialAssetPrice - ); - - ensure!( - T::AssetRegistry::exists(T::StableCoinAssetId::get()), - Error::::AssetNotRegistered - ); - - let native_asset_reserve = T::Currency::free_balance(T::HdxAssetId::get(), &Self::protocol_account()); - let stable_asset_reserve = - T::Currency::free_balance(T::StableCoinAssetId::get(), &Self::protocol_account()); - - // Ensure that stable asset has been transferred to protocol account - ensure!(stable_asset_reserve > Balance::zero(), Error::::MissingBalance); - - // Ensure that native asset has been transferred to protocol account - ensure!(native_asset_reserve > Balance::zero(), Error::::MissingBalance); - - let stable_asset_hub_reserve = stable_asset_price - .checked_mul_int(stable_asset_reserve) - .ok_or(ArithmeticError::Overflow)?; - - let native_asset_hub_reserve = native_asset_price - .checked_mul_int(native_asset_reserve) - .ok_or(ArithmeticError::Overflow)?; - - // Create NFT class - T::NFTHandler::create_collection( - &T::NFTCollectionId::get(), - &Self::protocol_account(), - &Self::protocol_account(), - )?; - - // Initial stale of native and stable assets - let stable_asset_state = AssetState:: { - hub_reserve: stable_asset_hub_reserve, - shares: stable_asset_reserve, - protocol_shares: stable_asset_reserve, - cap: FixedU128::from(stable_weight_cap).into_inner(), - tradable: Tradability::default(), - }; - - let native_asset_state = AssetState:: { - hub_reserve: native_asset_hub_reserve, - shares: native_asset_reserve, - protocol_shares: native_asset_reserve, - cap: FixedU128::from(native_weight_cap).into_inner(), - tradable: Tradability::default(), - }; - - Self::update_hub_asset_liquidity(&BalanceUpdate::Increase(stable_asset_hub_reserve))?; - Self::update_hub_asset_liquidity(&BalanceUpdate::Increase(native_asset_hub_reserve))?; - - >::insert(T::StableCoinAssetId::get(), stable_asset_state); - >::insert(T::HdxAssetId::get(), native_asset_state); - - Self::ensure_tvl_cap()?; - - // Hub asset is not allowed to be bought from the pool - >::put(Tradability::SELL); - - Self::deposit_event(Event::TokenAdded { - asset_id: T::StableCoinAssetId::get(), - initial_amount: stable_asset_reserve, - initial_price: stable_asset_price, - }); - - Self::deposit_event(Event::TokenAdded { - asset_id: T::HdxAssetId::get(), - initial_amount: native_asset_reserve, - initial_price: native_asset_price, - }); - - Ok(()) - } - /// Add new token to omnipool in quantity `amount` at price `initial_price` /// /// Can be called only after pool is initialized, otherwise it returns `NoStableAssetInPool` @@ -566,6 +443,13 @@ pub mod pallet { ensure!(initial_price > FixedU128::zero(), Error::::InvalidInitialAssetPrice); + // ensure collection is created, we can simply ignore the error if it was already created. + let _ = T::NFTHandler::create_collection( + &T::NFTCollectionId::get(), + &Self::protocol_account(), + &Self::protocol_account(), + ); + let amount = T::Currency::free_balance(asset, &Self::protocol_account()); ensure!( @@ -639,8 +523,6 @@ pub mod pallet { >::insert(asset, state); - Self::ensure_tvl_cap()?; - Self::deposit_event(Event::TokenAdded { asset_id: asset, initial_amount: amount, @@ -786,8 +668,6 @@ pub mod pallet { Self::set_asset_state(asset, new_asset_state); - Self::ensure_tvl_cap()?; - Self::deposit_event(Event::LiquidityAdded { who, asset_id: asset, @@ -1511,22 +1391,6 @@ pub mod pallet { Ok(()) }) } - /// Update TVL cap - /// - /// Parameters: - /// - `cap`: new tvl cap - /// - /// Emits `TVLCapUpdated` event when successful. - /// - #[pallet::call_index(10)] - #[pallet::weight(::WeightInfo::set_asset_weight_cap())] - #[transactional] - pub fn set_tvl_cap(origin: OriginFor, cap: Balance) -> DispatchResult { - T::AuthorityOrigin::ensure_origin(origin)?; - TvlCap::::set(cap); - Self::deposit_event(Event::TVLCapUpdated { cap }); - Ok(()) - } #[pallet::call_index(11)] #[pallet::weight(::WeightInfo::withdraw_protocol_liquidity())] @@ -1621,12 +1485,6 @@ pub mod pallet { #[transactional] pub fn remove_token(origin: OriginFor, asset_id: T::AssetId, beneficiary: T::AccountId) -> DispatchResult { T::AuthorityOrigin::ensure_origin(origin)?; - - ensure!( - asset_id != T::StableCoinAssetId::get(), - Error::::StableAssetCannotBeRemoved - ); - let asset_state = Self::load_asset_state(asset_id)?; // Allow only if no shares owned by LPs and asset is frozen. @@ -1674,11 +1532,6 @@ pub mod pallet { Balance::zero(), "Minimum trading limit is 0." ); - assert_ne!( - T::HdxAssetId::get(), - T::StableCoinAssetId::get(), - "Same Hdx asset id and stable asset id." - ); assert_ne!(T::MaxInRatio::get(), Balance::zero(), "MaxInRatio is 0."); assert_ne!(T::MaxOutRatio::get(), Balance::zero(), "MaxOutRatio is 0."); } @@ -1691,14 +1544,6 @@ impl Pallet { PalletId(*b"omnipool").into_account_truncating() } - /// Retrieve stable asset detail from the pool. - /// Return NoStableCoinInPool if stable asset is not yet in the pool. - fn stable_asset() -> Result<(Balance, Balance), DispatchError> { - let stable_asset = >::get(T::StableCoinAssetId::get()).ok_or(Error::::NoStableAssetInPool)?; - let stable_reserve = T::Currency::free_balance(T::StableCoinAssetId::get(), &Self::protocol_account()); - Ok((stable_reserve, stable_asset.hub_reserve)) - } - /// Retrieve state of asset from the pool and its pool balance pub fn load_asset_state(asset_id: T::AssetId) -> Result, DispatchError> { let state = >::get(asset_id).ok_or(Error::::AssetNotFound)?; @@ -1788,18 +1633,6 @@ impl Pallet { }) } - /// Calculate new tvl balance and ensure that it is below TVL Cap. - fn ensure_tvl_cap() -> DispatchResult { - let current_hub_asset_liquidity = T::Currency::free_balance(T::HubAssetId::get(), &Self::protocol_account()); - let stable_asset = Self::stable_asset()?; - - let updated_tvl = hydra_dx_math::omnipool::calculate_tvl(current_hub_asset_liquidity, stable_asset) - .ok_or(ArithmeticError::Overflow)?; - - ensure!(updated_tvl <= TvlCap::::get(), Error::::TVLCapExceeded); - Ok(()) - } - /// Check if assets can be traded - asset_in must be allowed to be sold and asset_out allowed to be bought. fn allow_assets(asset_in: &AssetReserveState, asset_out: &AssetReserveState) -> bool { asset_in.tradable.contains(Tradability::SELL) && asset_out.tradable.contains(Tradability::BUY) diff --git a/pallets/omnipool/src/tests/add_liquidity.rs b/pallets/omnipool/src/tests/add_liquidity.rs index 1f49c2bf2..e5d64e6ca 100644 --- a/pallets/omnipool/src/tests/add_liquidity.rs +++ b/pallets/omnipool/src/tests/add_liquidity.rs @@ -14,7 +14,7 @@ fn add_liquidity_should_work_when_asset_exists_in_pool() { let liq_added = 400 * ONE; // ACT - + let position_id = last_position_id(); assert_ok!(Omnipool::add_liquidity(RuntimeOrigin::signed(LP1), 1_000, liq_added)); // ASSERT - asset state, pool state, position @@ -30,7 +30,7 @@ fn add_liquidity_should_work_when_asset_exists_in_pool() { } ); - let position = Positions::::get(1).unwrap(); + let position = Positions::::get(position_id).unwrap(); let expected = Position:: { asset_id: 1_000, @@ -45,7 +45,7 @@ fn add_liquidity_should_work_when_asset_exists_in_pool() { assert_balance!(LP1, 1_000, 4600 * ONE); - let minted_position = POSITIONS.with(|v| v.borrow().get(&1).copied()); + let minted_position = POSITIONS.with(|v| v.borrow().get(&position_id).copied()); assert_eq!(minted_position, Some(LP1)); }); @@ -69,7 +69,7 @@ fn add_stable_asset_liquidity_works() { reserve: 1000 * ONE + liq_added, hub_reserve: 700000000000000, shares: 1400000000000000, - protocol_shares: 1000 * ONE, + protocol_shares: 0, cap: DEFAULT_WEIGHT_CAP, tradable: Tradability::default(), } diff --git a/pallets/omnipool/src/tests/add_token.rs b/pallets/omnipool/src/tests/add_token.rs index 0bf66357f..a6dd7623a 100644 --- a/pallets/omnipool/src/tests/add_token.rs +++ b/pallets/omnipool/src/tests/add_token.rs @@ -122,22 +122,6 @@ fn cannot_add_existing_asset() { }); } -#[test] -fn first_assset_must_be_hub_asset() { - ExtBuilder::default().build().execute_with(|| { - assert_noop!( - Omnipool::add_token( - RuntimeOrigin::root(), - HDX, - FixedU128::from_float(0.5), - Permill::from_percent(100), - LP1 - ), - Error::::NoStableAssetInPool - ); - }); -} - #[test] fn add_token_with_insufficient_balance_fails() { ExtBuilder::default() @@ -158,3 +142,44 @@ fn add_token_with_insufficient_balance_fails() { ); }); } + +#[test] +fn update_weight_cap_of_native_stable_asset_should_work_when_pool_is_initialized() { + ExtBuilder::default() + .with_initial_pool(FixedU128::from_float(0.5), FixedU128::from(1)) + .build() + .execute_with(|| { + assert_ok!(Omnipool::set_asset_weight_cap( + RuntimeOrigin::root(), + HDX, + Permill::from_rational(1u32, 100000u32), + )); + assert_asset_state!( + HDX, + AssetReserveState { + reserve: 10000000000000000, + hub_reserve: 10000000000000000, + shares: 10000000000000000, + protocol_shares: 0, + cap: 10_000_000_000_000, + tradable: Tradability::default(), + } + ); + assert_ok!(Omnipool::set_asset_weight_cap( + RuntimeOrigin::root(), + DAI, + Permill::from_percent(2u32), + )); + assert_asset_state!( + DAI, + AssetReserveState { + reserve: 1000000000000000, + hub_reserve: 500000000000000, + shares: 1000000000000000, + protocol_shares: 0, + cap: 20_000_000_000_000_000, + tradable: Tradability::default(), + } + ); + }); +} diff --git a/pallets/omnipool/src/tests/buy.rs b/pallets/omnipool/src/tests/buy.rs index 26675f5d0..621e64f46 100644 --- a/pallets/omnipool/src/tests/buy.rs +++ b/pallets/omnipool/src/tests/buy.rs @@ -288,7 +288,7 @@ fn buy_for_hub_asset_works() { reserve: 1000000000000000, hub_reserve: 500000000000000, shares: 1000000000000000, - protocol_shares: 1000000000000000, + protocol_shares: 0, cap: DEFAULT_WEIGHT_CAP, tradable: Tradability::default(), } @@ -300,7 +300,7 @@ fn buy_for_hub_asset_works() { reserve: 10000000000000000, hub_reserve: 10000000000000000, shares: 10000000000000000, - protocol_shares: 10000000000000000, + protocol_shares: 0, cap: DEFAULT_WEIGHT_CAP, tradable: Tradability::default(), } @@ -595,7 +595,7 @@ fn buy_should_work_when_trading_native_asset() { reserve: 10046645138141372, hub_reserve: 9962857142857142, shares: 10000 * ONE, - protocol_shares: 10000000000000000, + protocol_shares: 0, cap: DEFAULT_WEIGHT_CAP, tradable: Tradability::default(), } diff --git a/pallets/omnipool/src/tests/init_pool.rs b/pallets/omnipool/src/tests/init_pool.rs deleted file mode 100644 index 4ca203542..000000000 --- a/pallets/omnipool/src/tests/init_pool.rs +++ /dev/null @@ -1,238 +0,0 @@ -use super::*; -use frame_support::assert_noop; - -#[test] -fn initialize_pool_should_work_when_called_first_time_with_correct_params() { - ExtBuilder::default() - .with_endowed_accounts(vec![ - (Omnipool::protocol_account(), DAI, 100 * ONE), - (Omnipool::protocol_account(), HDX, 200 * ONE), - ]) - .build() - .execute_with(|| { - let stable_amount = 100 * ONE; - let native_amount = 200 * ONE; - - let stable_price = FixedU128::from_float(0.5); - let native_price = FixedU128::from_float(1.5); - - // ACT - assert_ok!(Omnipool::initialize_pool( - RuntimeOrigin::root(), - stable_price, - native_price, - Permill::from_percent(50), - Permill::from_percent(50) - )); - - // ASSERT - // - pool state - // - native and stable asset states - // - correct balances - assert_pool_state!( - stable_price.checked_mul_int(stable_amount).unwrap() - + native_price.checked_mul_int(native_amount).unwrap(), - native_price.checked_mul_int(native_amount).unwrap() - * (stable_amount / stable_price.checked_mul_int(stable_amount).unwrap()) - + stable_amount, - SimpleImbalance::default() - ); - - assert_asset_state!( - DAI, - AssetReserveState { - reserve: 100000000000000, - hub_reserve: 50000000000000, - shares: 100000000000000, - protocol_shares: 100000000000000, - cap: 500_000_000_000_000_000, - tradable: Tradability::default(), - } - ); - assert_asset_state!( - HDX, - AssetReserveState { - reserve: 200000000000000, - hub_reserve: 300000000000000, - shares: 200000000000000, - protocol_shares: 200000000000000, - cap: 500_000_000_000_000_000, - tradable: Tradability::default(), - } - ); - - assert_balance!(Omnipool::protocol_account(), DAI, stable_amount); - assert_balance!(Omnipool::protocol_account(), HDX, native_amount); - - assert_eq!(HubAssetTradability::::get(), Tradability::SELL); - }); -} - -#[test] -fn initialize_pool_should_fail_when_already_initialized() { - ExtBuilder::default() - .with_initial_pool(FixedU128::from_float(0.5), FixedU128::from(1)) - .build() - .execute_with(|| { - let stable_price = FixedU128::from_float(0.5); - let native_price = FixedU128::from_float(1.5); - - assert_noop!( - Omnipool::initialize_pool( - RuntimeOrigin::root(), - stable_price, - native_price, - Permill::from_percent(100), - Permill::from_percent(100) - ), - Error::::AssetAlreadyAdded - ); - }); -} - -#[test] -fn initialize_pool_should_fail_when_stable_funds_missing_in_pool_account() { - ExtBuilder::default() - .with_endowed_accounts(vec![]) - .build() - .execute_with(|| { - let stable_price = FixedU128::from_float(0.5); - let native_price = FixedU128::from_float(1.5); - - assert_noop!( - Omnipool::initialize_pool( - RuntimeOrigin::root(), - stable_price, - native_price, - Permill::from_percent(100), - Permill::from_percent(100) - ), - Error::::MissingBalance - ); - }); -} - -#[test] -fn initialize_pool_should_fail_when_native_funds_missing_in_pool_account() { - ExtBuilder::default() - .with_endowed_accounts(vec![(Omnipool::protocol_account(), DAI, 1000 * ONE)]) - .build() - .execute_with(|| { - let stable_price = FixedU128::from_float(0.5); - let native_price = FixedU128::from_float(1.5); - - assert_noop!( - Omnipool::initialize_pool( - RuntimeOrigin::root(), - stable_price, - native_price, - Permill::from_percent(100), - Permill::from_percent(100) - ), - Error::::MissingBalance - ); - }); -} - -#[test] -fn initialize_pool_should_fail_when_stable_price_is_zero() { - ExtBuilder::default().build().execute_with(|| { - let stable_price = FixedU128::from(0); - let native_price = FixedU128::from(1); - - assert_noop!( - Omnipool::initialize_pool( - RuntimeOrigin::root(), - stable_price, - native_price, - Permill::from_percent(100), - Permill::from_percent(100) - ), - Error::::InvalidInitialAssetPrice - ); - }); -} - -#[test] -fn initialize_pool_should_fail_when_native_price_is_zero() { - ExtBuilder::default() - .with_endowed_accounts(vec![(Omnipool::protocol_account(), DAI, 1000 * ONE)]) - .build() - .execute_with(|| { - let stable_price = FixedU128::from(1); - let native_price = FixedU128::from(0); - - assert_noop!( - Omnipool::initialize_pool( - RuntimeOrigin::root(), - stable_price, - native_price, - Permill::from_percent(100), - Permill::from_percent(100) - ), - Error::::InvalidInitialAssetPrice - ); - }); -} - -#[test] -fn update_weight_cap_of_native_stable_asset_should_work_when_pool_is_initialized() { - ExtBuilder::default() - .with_initial_pool(FixedU128::from_float(0.5), FixedU128::from(1)) - .build() - .execute_with(|| { - assert_ok!(Omnipool::set_asset_weight_cap( - RuntimeOrigin::root(), - HDX, - Permill::from_rational(1u32, 100000u32), - )); - assert_asset_state!( - HDX, - AssetReserveState { - reserve: 10000000000000000, - hub_reserve: 10000000000000000, - shares: 10000000000000000, - protocol_shares: 10000000000000000, - cap: 10_000_000_000_000, - tradable: Tradability::default(), - } - ); - assert_ok!(Omnipool::set_asset_weight_cap( - RuntimeOrigin::root(), - DAI, - Permill::from_percent(2u32), - )); - assert_asset_state!( - DAI, - AssetReserveState { - reserve: 1000000000000000, - hub_reserve: 500000000000000, - shares: 1000000000000000, - protocol_shares: 1000000000000000, - cap: 20_000_000_000_000_000, - tradable: Tradability::default(), - } - ); - }); -} - -#[test] -fn initialize_pool_should_fail_when_stable_asset_is_not_registered() { - ExtBuilder::default() - .without_stable_asset_in_registry() - .build() - .execute_with(|| { - let stable_price = FixedU128::from_float(0.5); - let native_price = FixedU128::from_float(1.5); - assert_noop!( - Omnipool::initialize_pool( - RuntimeOrigin::root(), - stable_price, - native_price, - Permill::from_percent(50), - Permill::from_percent(50) - ), - Error::::AssetNotRegistered - ); - }); -} diff --git a/pallets/omnipool/src/tests/invariants.rs b/pallets/omnipool/src/tests/invariants.rs index b2fe8de72..c8bbd73e3 100644 --- a/pallets/omnipool/src/tests/invariants.rs +++ b/pallets/omnipool/src/tests/invariants.rs @@ -1003,15 +1003,6 @@ proptest! { FixedU128::from_float(0.000000001), "L/Q ratio changed" ); - - // check enforcement of overall tvl cap - let hub_reserve = Tokens::free_balance(LRNA, &Omnipool::protocol_account()); - - let stable_asset = >::get(DAI).unwrap(); - let stable_reserve = Tokens::free_balance(DAI, &Omnipool::protocol_account()); - - let global_tvl = hydra_dx_math::omnipool::calculate_tvl(hub_reserve, (stable_reserve, stable_asset.hub_reserve)).unwrap(); - assert!( global_tvl <= TvlCap::::get()); }); } } @@ -1100,15 +1091,6 @@ proptest! { FixedU128::from_float(0.000000001), "L/Q ratio changed after remove liquidity" ); - - // check enforcement of overall tvl cap - let hub_reserve = Tokens::free_balance(LRNA, &Omnipool::protocol_account()); - - let stable_asset = >::get(DAI).unwrap(); - let stable_reserve = Tokens::free_balance(DAI, &Omnipool::protocol_account()); - - let global_tvl = hydra_dx_math::omnipool::calculate_tvl(hub_reserve, (stable_reserve, stable_asset.hub_reserve)).unwrap(); - assert!( global_tvl <= TvlCap::::get()); }); } } @@ -1201,15 +1183,6 @@ proptest! { FixedU128::from_float(0.000000001), "L/Q ratio changed after remove liquidity" ); - - // check enforcement of overall tvl cap - let hub_reserve = Tokens::free_balance(LRNA, &Omnipool::protocol_account()); - - let stable_asset = >::get(DAI).unwrap(); - let stable_reserve = Tokens::free_balance(DAI, &Omnipool::protocol_account()); - - let global_tvl = hydra_dx_math::omnipool::calculate_tvl(hub_reserve, (stable_reserve, stable_asset.hub_reserve)).unwrap(); - assert!( global_tvl <= TvlCap::::get()); }); } } diff --git a/pallets/omnipool/src/tests/mock.rs b/pallets/omnipool/src/tests/mock.rs index 5d44fc1f6..1177df7c8 100644 --- a/pallets/omnipool/src/tests/mock.rs +++ b/pallets/omnipool/src/tests/mock.rs @@ -181,7 +181,6 @@ impl Config for Test { type Currency = Tokens; type AuthorityOrigin = EnsureRoot; type HubAssetId = LRNAAssetId; - type StableCoinAssetId = DAIAssetId; type WeightInfo = (); type HdxAssetId = HDXAssetId; type NFTCollectionId = PosiitionCollectionId; @@ -211,10 +210,8 @@ pub struct ExtBuilder { asset_weight_cap: Permill, min_liquidity: u128, min_trade_limit: u128, - register_stable_asset: bool, max_in_ratio: Balance, max_out_ratio: Balance, - tvl_cap: Balance, init_pool: Option<(FixedU128, FixedU128)>, pool_tokens: Vec<(AssetId, FixedU128, AccountId, Balance)>, } @@ -276,11 +273,9 @@ impl Default for ExtBuilder { registered_assets: vec![], min_trade_limit: 0, init_pool: None, - register_stable_asset: true, pool_tokens: vec![], max_in_ratio: 1u128, max_out_ratio: 1u128, - tvl_cap: u128::MAX, } } } @@ -328,10 +323,6 @@ impl ExtBuilder { self } - pub fn without_stable_asset_in_registry(mut self) -> Self { - self.register_stable_asset = false; - self - } pub fn with_max_in_ratio(mut self, value: Balance) -> Self { self.max_in_ratio = value; self @@ -340,10 +331,6 @@ impl ExtBuilder { self.max_out_ratio = value; self } - pub fn with_tvl_cap(mut self, value: Balance) -> Self { - self.tvl_cap = value; - self - } pub fn with_max_allowed_price_difference(self, max_allowed: Permill) -> Self { MAX_PRICE_DIFF.with(|v| { *v.borrow_mut() = max_allowed; @@ -382,9 +369,7 @@ impl ExtBuilder { // Add DAi and HDX as pre-registered assets REGISTERED_ASSETS.with(|v| { - if self.register_stable_asset { - v.borrow_mut().insert(DAI, DAI); - } + v.borrow_mut().insert(DAI, DAI); v.borrow_mut().insert(HDX, HDX); v.borrow_mut().insert(REGISTERED_ASSET, REGISTERED_ASSET); self.registered_assets.iter().for_each(|asset| { @@ -429,18 +414,21 @@ impl ExtBuilder { let mut r: sp_io::TestExternalities = t.into(); - r.execute_with(|| { - assert_ok!(Omnipool::set_tvl_cap(RuntimeOrigin::root(), self.tvl_cap,)); - }); - if let Some((stable_price, native_price)) = self.init_pool { r.execute_with(|| { - assert_ok!(Omnipool::initialize_pool( + assert_ok!(Omnipool::add_token( RuntimeOrigin::root(), - stable_price, + HDXAssetId::get(), native_price, Permill::from_percent(100), - Permill::from_percent(100) + Omnipool::protocol_account(), + )); + assert_ok!(Omnipool::add_token( + RuntimeOrigin::root(), + DAIAssetId::get(), + stable_price, + Permill::from_percent(100), + Omnipool::protocol_account(), )); for (asset_id, price, owner, amount) in self.pool_tokens { @@ -550,6 +538,10 @@ pub(crate) fn get_mock_minted_position(position_id: u32) -> Option { POSITIONS.with(|v| v.borrow().get(&position_id).copied()) } +pub(crate) fn last_position_id() -> u32 { + Omnipool::next_position_id() +} + pub struct MockOracle; impl ExternalPriceProvider for MockOracle { diff --git a/pallets/omnipool/src/tests/mod.rs b/pallets/omnipool/src/tests/mod.rs index 66175136c..c87da02b8 100644 --- a/pallets/omnipool/src/tests/mod.rs +++ b/pallets/omnipool/src/tests/mod.rs @@ -1,7 +1,7 @@ use crate::types::{Position, SimpleImbalance}; use crate::*; use frame_support::assert_ok; -use sp_runtime::{FixedPointNumber, FixedU128}; +use sp_runtime::FixedU128; mod add_liquidity; mod add_token; @@ -12,13 +12,11 @@ mod sell; mod barrier; mod imbalance; -mod init_pool; pub(crate) mod mock; mod positions; mod refund; mod remove_token; mod tradability; -mod tvl; mod types; mod verification; diff --git a/pallets/omnipool/src/tests/remove_token.rs b/pallets/omnipool/src/tests/remove_token.rs index c1bff86c3..c1f1b07d2 100644 --- a/pallets/omnipool/src/tests/remove_token.rs +++ b/pallets/omnipool/src/tests/remove_token.rs @@ -30,27 +30,6 @@ fn remove_token_should_fail_when_not_root() { }); } -#[test] -fn remove_token_should_fail_when_removing_configured_stable_asset() { - ExtBuilder::default() - .with_endowed_accounts(vec![ - (Omnipool::protocol_account(), DAI, 1000 * ONE), - (Omnipool::protocol_account(), HDX, NATIVE_AMOUNT), - (LP2, 1_000, 2000 * ONE), - (LP2, DAI, 2000 * ONE), - (LP1, 1_000, 5000 * ONE), - ]) - .with_initial_pool(FixedU128::from_float(0.5), FixedU128::from(1)) - .with_min_withdrawal_fee(Permill::from_float(0.01)) - .build() - .execute_with(|| { - assert_noop!( - Omnipool::remove_token(RuntimeOrigin::root(), 2, LP1), - Error::::StableAssetCannotBeRemoved - ); - }); -} - #[test] fn remove_token_should_fail_when_asset_is_not_frozen() { ExtBuilder::default() diff --git a/pallets/omnipool/src/tests/sell.rs b/pallets/omnipool/src/tests/sell.rs index ce8ea7d07..74cbeedee 100644 --- a/pallets/omnipool/src/tests/sell.rs +++ b/pallets/omnipool/src/tests/sell.rs @@ -245,7 +245,7 @@ fn sell_hub_works() { reserve: 1000000000000000, hub_reserve: 500000000000000, shares: 1000000000000000, - protocol_shares: 1000000000000000, + protocol_shares: 0, cap: DEFAULT_WEIGHT_CAP, tradable: Tradability::default(), } @@ -257,7 +257,7 @@ fn sell_hub_works() { reserve: 10000000000000000, hub_reserve: 10000000000000000, shares: 10000000000000000, - protocol_shares: 10000000000000000, + protocol_shares: 0, cap: DEFAULT_WEIGHT_CAP, tradable: Tradability::default(), } @@ -551,7 +551,7 @@ fn sell_should_work_when_trading_native_asset() { reserve: 10050000000000000, hub_reserve: 9960199004975124, shares: 10000 * ONE, - protocol_shares: 10000000000000000, + protocol_shares: 0, cap: DEFAULT_WEIGHT_CAP, tradable: Tradability::default(), } diff --git a/pallets/omnipool/src/tests/tvl.rs b/pallets/omnipool/src/tests/tvl.rs deleted file mode 100644 index 2305b79fc..000000000 --- a/pallets/omnipool/src/tests/tvl.rs +++ /dev/null @@ -1,173 +0,0 @@ -use super::*; -use frame_support::assert_noop; - -#[test] -fn add_liquidity_should_fail_when_tvl_is_reached() { - let stable_amount = 50_000 * ONE * 1_000_000; - let native_amount = 936_329_588_000_000_000u128; - let dot_amount = 87_719_298_250_000_u128; - - let native_price = FixedU128::from_inner(1201500000000000); - let stable_price = FixedU128::from_inner(45_000_000_000); - let token_price = FixedU128::from_inner(25_650_000_000_000_000_000); - - let dot_id = 1_000; - - ExtBuilder::default() - .with_endowed_accounts(vec![ - (Omnipool::protocol_account(), DAI, stable_amount), - (Omnipool::protocol_account(), HDX, native_amount), - (LP1, DAI, 200_000 * ONE * 1_000_000), - (LP2, dot_id, dot_amount * 1000), - ]) - .with_registered_asset(dot_id) - .with_initial_pool(stable_price, native_price) - .with_token(1_000, token_price, LP2, dot_amount) - .with_tvl_cap(222_222 * ONE * 1_000_000) - .build() - .execute_with(|| { - assert_pool_state!( - 5625000000094500, - 125000000002100000000000, - SimpleImbalance { - value: 0u128, - negative: true - } - ); - - assert_noop!( - Omnipool::add_liquidity(RuntimeOrigin::signed(LP1), DAI, 100_000 * ONE * 1_000_000), - Error::::TVLCapExceeded - ); - }); -} - -#[test] -fn remove_liquidity_should_work_when_tvl_is_reached() { - let stable_amount = 50_000 * ONE * 1_000_000; - let native_amount = 936_329_588_000_000_000u128; - let dot_amount = 87_719_298_250_000_u128; - - let native_price = FixedU128::from_inner(1201500000000000); - let stable_price = FixedU128::from_inner(45_000_000_000); - let token_price = FixedU128::from_inner(25_650_000_000_000_000_000); - - let dot_id = 1_000; - - ExtBuilder::default() - .with_endowed_accounts(vec![ - (Omnipool::protocol_account(), DAI, stable_amount), - (Omnipool::protocol_account(), HDX, native_amount), - (LP1, DAI, 200_000 * ONE * 1_000_000), - (LP2, dot_id, dot_amount), - (LP2, DAI, 20_000 * ONE * 1_000_000), - ]) - .with_registered_asset(dot_id) - .with_initial_pool(stable_price, native_price) - .with_token(1_000, token_price, LP2, dot_amount) - .with_tvl_cap(222_222 * ONE * 1_000_000) - .build() - .execute_with(|| { - let position_id = >::get(); - // Ensure that tvl cap has been reached - assert_ok!(Omnipool::add_liquidity( - RuntimeOrigin::signed(LP1), - DAI, - 97_000 * ONE * 1_000_000 - ),); - - assert_ok!(Omnipool::sell( - RuntimeOrigin::signed(LP2), - DAI, - dot_id, - 10_000 * ONE * 1_000_000, - 0u128 - )); - - assert_pool_state!( - 9990000000094500, - 253231431350444840163976, // current tvl - SimpleImbalance { - value: 0u128, - negative: true - } - ); - - let position = Positions::::get(position_id).unwrap(); - - assert_ok!(Omnipool::remove_liquidity( - RuntimeOrigin::signed(LP1), - position_id, - position.shares / 100 - ),); - }); -} - -#[test] -fn set_tvl_cap_should_work() { - let stable_amount = 50_000 * ONE * 1_000_000; - let native_amount = 936_329_588_000_000_000u128; - let dot_amount = 87_719_298_250_000_u128; - - let native_price = FixedU128::from_inner(1201500000000000); - let stable_price = FixedU128::from_inner(45_000_000_000); - let token_price = FixedU128::from_inner(25_650_000_000_000_000_000); - - let dot_id = 1_000; - - ExtBuilder::default() - .with_endowed_accounts(vec![ - (Omnipool::protocol_account(), DAI, stable_amount), - (Omnipool::protocol_account(), HDX, native_amount), - (LP1, DAI, 200_000 * ONE * 1_000_000), - (LP2, dot_id, dot_amount), - (LP2, DAI, 20_000 * ONE * 1_000_000), - ]) - .with_registered_asset(dot_id) - .with_initial_pool(stable_price, native_price) - .with_token(1_000, token_price, LP2, dot_amount) - .with_tvl_cap(222_222 * ONE * 1_000_000) - .build() - .execute_with(|| { - assert_eq!(TvlCap::::get(), 222_222 * ONE * 1_000_000); - - assert_ok!(Omnipool::set_tvl_cap(RuntimeOrigin::root(), u128::MAX)); - - assert_eq!(TvlCap::::get(), u128::MAX); - }); -} - -#[test] -fn set_tvl_cap_should_fail_when_not_root_origin() { - let stable_amount = 50_000 * ONE * 1_000_000; - let native_amount = 936_329_588_000_000_000u128; - let dot_amount = 87_719_298_250_000_u128; - - let native_price = FixedU128::from_inner(1201500000000000); - let stable_price = FixedU128::from_inner(45_000_000_000); - let token_price = FixedU128::from_inner(25_650_000_000_000_000_000); - - let dot_id = 1_000; - - ExtBuilder::default() - .with_endowed_accounts(vec![ - (Omnipool::protocol_account(), DAI, stable_amount), - (Omnipool::protocol_account(), HDX, native_amount), - (LP1, DAI, 200_000 * ONE * 1_000_000), - (LP2, dot_id, dot_amount), - (LP2, DAI, 20_000 * ONE * 1_000_000), - ]) - .with_registered_asset(dot_id) - .with_initial_pool(stable_price, native_price) - .with_token(1_000, token_price, LP2, dot_amount) - .with_tvl_cap(222_222 * ONE * 1_000_000) - .build() - .execute_with(|| { - assert_eq!(TvlCap::::get(), 222_222 * ONE * 1_000_000); - - assert_noop!( - Omnipool::set_tvl_cap(RuntimeOrigin::signed(LP1), u128::MAX), - sp_runtime::traits::BadOrigin, - ); - }); -} diff --git a/pallets/omnipool/src/tests/verification/scenario_04.rs b/pallets/omnipool/src/tests/verification/scenario_04.rs index a30a8c8f9..309232a51 100644 --- a/pallets/omnipool/src/tests/verification/scenario_04.rs +++ b/pallets/omnipool/src/tests/verification/scenario_04.rs @@ -53,7 +53,7 @@ fn scenario_04() { reserve: 1000000000000000, hub_reserve: 500000000000000, shares: 1000000000000000, - protocol_shares: 1000000000000000, + protocol_shares: 0, cap: DEFAULT_WEIGHT_CAP, tradable: Tradability::default(), } @@ -65,7 +65,7 @@ fn scenario_04() { reserve: 10000000000000000, hub_reserve: 10000000000000000, shares: 10000000000000000, - protocol_shares: 10000000000000000, + protocol_shares: 0, cap: DEFAULT_WEIGHT_CAP, tradable: Tradability::default(), } diff --git a/pallets/omnipool/src/tests/verification/scenario_05.rs b/pallets/omnipool/src/tests/verification/scenario_05.rs index 71342176f..095d40fd6 100644 --- a/pallets/omnipool/src/tests/verification/scenario_05.rs +++ b/pallets/omnipool/src/tests/verification/scenario_05.rs @@ -53,7 +53,7 @@ fn scenario_05() { reserve: 1000000000000000, hub_reserve: 500000000000000, shares: 1000000000000000, - protocol_shares: 1000000000000000, + protocol_shares: 0, cap: DEFAULT_WEIGHT_CAP, tradable: Tradability::default(), } @@ -65,7 +65,7 @@ fn scenario_05() { reserve: 10000000000000000, hub_reserve: 10000000000000000, shares: 10000000000000000, - protocol_shares: 10000000000000000, + protocol_shares: 0, cap: DEFAULT_WEIGHT_CAP, tradable: Tradability::default(), } diff --git a/pallets/omnipool/src/tests/verification/scenario_06.rs b/pallets/omnipool/src/tests/verification/scenario_06.rs index d89aaadba..b52917619 100644 --- a/pallets/omnipool/src/tests/verification/scenario_06.rs +++ b/pallets/omnipool/src/tests/verification/scenario_06.rs @@ -71,7 +71,7 @@ fn scenario_06() { reserve: 1000000000000000, hub_reserve: 500000000000000, shares: 1000000000000000, - protocol_shares: 1000000000000000, + protocol_shares: 0, cap: DEFAULT_WEIGHT_CAP, tradable: Tradability::default(), } @@ -83,7 +83,7 @@ fn scenario_06() { reserve: 10000000000000000, hub_reserve: 10000000000000000, shares: 10000000000000000, - protocol_shares: 10000000000000000, + protocol_shares: 0, cap: DEFAULT_WEIGHT_CAP, tradable: Tradability::default(), } diff --git a/pallets/omnipool/src/tests/verification/scenario_08.rs b/pallets/omnipool/src/tests/verification/scenario_08.rs index f37bcf367..3b22bee38 100644 --- a/pallets/omnipool/src/tests/verification/scenario_08.rs +++ b/pallets/omnipool/src/tests/verification/scenario_08.rs @@ -48,6 +48,7 @@ fn complex_scenario_works() { 10000000000000 )); + let position_id = last_position_id(); assert_ok!(Omnipool::add_liquidity( RuntimeOrigin::signed(LP3), 200, @@ -66,7 +67,7 @@ fn complex_scenario_works() { assert_ok!(Omnipool::remove_liquidity( RuntimeOrigin::signed(LP3), - 3, + position_id, 200000000000000 )); @@ -99,7 +100,7 @@ fn complex_scenario_works() { reserve: 1000000000000000, hub_reserve: 500000000000000, shares: 1000000000000000, - protocol_shares: 1000000000000000, + protocol_shares: 0, cap: DEFAULT_WEIGHT_CAP, tradable: Tradability::default(), } @@ -111,7 +112,7 @@ fn complex_scenario_works() { reserve: 10000000000000000, hub_reserve: 10000000000000000, shares: 10000000000000000, - protocol_shares: 10000000000000000, + protocol_shares: 0, cap: DEFAULT_WEIGHT_CAP, tradable: Tradability::default(), } diff --git a/pallets/omnipool/src/tests/verification/scenario_09.rs b/pallets/omnipool/src/tests/verification/scenario_09.rs index d7a9be109..ba6058077 100644 --- a/pallets/omnipool/src/tests/verification/scenario_09.rs +++ b/pallets/omnipool/src/tests/verification/scenario_09.rs @@ -64,7 +64,7 @@ fn sell_fee_test() { reserve: 1000000000000000, hub_reserve: 500000000000000, shares: 1000000000000000, - protocol_shares: 1000000000000000, + protocol_shares: 0, cap: DEFAULT_WEIGHT_CAP, tradable: Tradability::default(), } @@ -76,7 +76,7 @@ fn sell_fee_test() { reserve: 10000000000000000, hub_reserve: 10019499999999999, shares: 10000000000000000, - protocol_shares: 10000000000000000, + protocol_shares: 0, cap: DEFAULT_WEIGHT_CAP, tradable: Tradability::default(), } diff --git a/pallets/omnipool/src/tests/verification/scenario_10.rs b/pallets/omnipool/src/tests/verification/scenario_10.rs index bef2be927..a07d73096 100644 --- a/pallets/omnipool/src/tests/verification/scenario_10.rs +++ b/pallets/omnipool/src/tests/verification/scenario_10.rs @@ -46,6 +46,7 @@ fn fee_test_buy_sell() { 10000000000000 )); + let position_id = last_position_id(); assert_ok!(Omnipool::add_liquidity( RuntimeOrigin::signed(LP3), 200, @@ -62,7 +63,7 @@ fn fee_test_buy_sell() { assert_ok!(Omnipool::remove_liquidity( RuntimeOrigin::signed(LP3), - 3, + position_id, 200000000000000 )); @@ -85,7 +86,7 @@ fn fee_test_buy_sell() { reserve: 1000000000000000, hub_reserve: 500000000000000, shares: 1000000000000000, - protocol_shares: 1000000000000000, + protocol_shares: 0, cap: DEFAULT_WEIGHT_CAP, tradable: Tradability::default(), } @@ -97,7 +98,7 @@ fn fee_test_buy_sell() { reserve: 10000000000000000, hub_reserve: 10135523267202732, shares: 10000000000000000, - protocol_shares: 10000000000000000, + protocol_shares: 0, cap: DEFAULT_WEIGHT_CAP, tradable: Tradability::default(), } diff --git a/pallets/omnipool/src/tests/verification/scenario_11.rs b/pallets/omnipool/src/tests/verification/scenario_11.rs index a2ac00811..2452f501a 100644 --- a/pallets/omnipool/src/tests/verification/scenario_11.rs +++ b/pallets/omnipool/src/tests/verification/scenario_11.rs @@ -44,6 +44,7 @@ fn complex_scenario_works() { 10000000000000 )); + let position_id = last_position_id(); assert_ok!(Omnipool::add_liquidity( RuntimeOrigin::signed(LP3), 200, @@ -60,7 +61,7 @@ fn complex_scenario_works() { assert_ok!(Omnipool::remove_liquidity( RuntimeOrigin::signed(LP3), - 3, + position_id, 200000000000000 )); @@ -97,7 +98,7 @@ fn complex_scenario_works() { reserve: 1000000000000000, hub_reserve: 500000000000000, shares: 1000000000000000, - protocol_shares: 1000000000000000, + protocol_shares: 0, cap: DEFAULT_WEIGHT_CAP, tradable: Tradability::default(), } @@ -109,7 +110,7 @@ fn complex_scenario_works() { reserve: 10000000000000000, hub_reserve: 10000000000000000, shares: 10000000000000000, - protocol_shares: 10000000000000000, + protocol_shares: 0, cap: DEFAULT_WEIGHT_CAP, tradable: Tradability::default(), } diff --git a/runtime/hydradx/Cargo.toml b/runtime/hydradx/Cargo.toml index cb89eaa34..2a534dfa5 100644 --- a/runtime/hydradx/Cargo.toml +++ b/runtime/hydradx/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hydradx-runtime" -version = "187.0.0" +version = "188.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 f9016c93a..2d10734cd 100644 --- a/runtime/hydradx/src/assets.rs +++ b/runtime/hydradx/src/assets.rs @@ -216,7 +216,6 @@ impl pallet_uniques::Config for Runtime { parameter_types! { pub const LRNA: AssetId = 1; - pub const StableAssetId: AssetId = 2; pub const MinTradingLimit : Balance = 1_000u128; pub const MinPoolLiquidity: Balance = 1_000_000u128; pub const MaxInRatio: Balance = 3u128; @@ -237,7 +236,6 @@ impl pallet_omnipool::Config for Runtime { type AssetRegistry = AssetRegistry; type HdxAssetId = NativeAssetId; type HubAssetId = LRNA; - type StableCoinAssetId = StableAssetId; type MinWithdrawalFee = MinimumWithdrawalFee; type MinimumTradingLimit = MinTradingLimit; type MinimumPoolLiquidity = MinPoolLiquidity; diff --git a/runtime/hydradx/src/benchmarking/omnipool.rs b/runtime/hydradx/src/benchmarking/omnipool.rs index 7c076a7ee..8dc51f72c 100644 --- a/runtime/hydradx/src/benchmarking/omnipool.rs +++ b/runtime/hydradx/src/benchmarking/omnipool.rs @@ -3,6 +3,7 @@ use crate::{AccountId, AssetId, AssetRegistry, Balance, EmaOracle, Omnipool, Run use super::*; use frame_benchmarking::account; +use frame_support::dispatch::DispatchResult; use frame_support::{ assert_ok, sp_runtime::{ @@ -30,8 +31,6 @@ pub fn update_balance(currency_id: AssetId, who: &AccountId, balance: Balance) { ); } -const TVL_CAP: Balance = 222_222_000_000_000_000_000_000; - fn run_to_block(to: u32) { while System::block_number() < to { let b = System::block_number(); @@ -46,47 +45,43 @@ fn run_to_block(to: u32) { } } +const HDX: AssetId = 0; +const DAI: AssetId = 1; + +fn init() -> DispatchResult { + let stable_amount: Balance = 1_000_000_000_000_000u128; + let native_amount: Balance = 1_000_000_000_000_000u128; + let stable_price: FixedU128 = FixedU128::from((1, 2)); + let native_price: FixedU128 = FixedU128::from(1); + + let acc = Omnipool::protocol_account(); + + update_balance(DAI, &acc, stable_amount); + update_balance(HDX, &acc, native_amount); + + Omnipool::add_token( + RawOrigin::Root.into(), + HDX, + native_price, + Permill::from_percent(100), + acc.clone(), + )?; + Omnipool::add_token( + RawOrigin::Root.into(), + DAI, + stable_price, + Permill::from_percent(100), + acc.clone(), + )?; + + Ok(()) +} + runtime_benchmarks! { {Runtime, pallet_omnipool} - initialize_pool { - let stable_amount: Balance = 1_000_000_000_000_000u128; - let native_amount: Balance = 1_000_000_000_000_000u128; - let stable_price: FixedU128 = FixedU128::from((1,2)); - let native_price: FixedU128 = FixedU128::from(1); - - let acc = Omnipool::protocol_account(); - let native_id = ::HdxAssetId::get(); - let stable_id = ::StableCoinAssetId::get(); - - Omnipool::set_tvl_cap(RawOrigin::Root.into(), TVL_CAP)?; - - update_balance(stable_id, &acc, stable_amount); - update_balance(native_id, &acc, native_amount); - - }: { Omnipool::initialize_pool(RawOrigin::Root.into(), stable_price, native_price, Permill::from_percent(100), Permill::from_percent(100))? } - verify { - assert!(Omnipool::assets(stable_id).is_some()); - assert!(Omnipool::assets(native_id).is_some()); - } - add_token{ - // Initialize pool - let stable_amount: Balance = 1_000_000_000_000_000u128; - let native_amount: Balance = 1_000_000_000_000_000u128; - let stable_price: FixedU128= FixedU128::from((1,2)); - let native_price: FixedU128= FixedU128::from(1); - - let acc = Omnipool::protocol_account(); - let native_id = ::HdxAssetId::get(); - let stable_id = ::StableCoinAssetId::get(); - - Omnipool::set_tvl_cap(RawOrigin::Root.into(), TVL_CAP)?; - - update_balance(stable_id, &acc, stable_amount); - update_balance(native_id, &acc, native_amount); - - Omnipool::initialize_pool(RawOrigin::Root.into(), stable_price, native_price,Permill::from_percent(100), Permill::from_percent(100))?; + init()?; // Register new asset in asset registry let token_id = AssetRegistry::create_asset(&b"FCK".to_vec(), Balance::one())?; @@ -108,23 +103,7 @@ runtime_benchmarks! { } add_liquidity { - // Initialize pool - let stable_amount: Balance = 1_000_000_000_000_000u128; - let native_amount: Balance = 1_000_000_000_000_000u128; - let stable_price: FixedU128= FixedU128::from((1,2)); - let native_price: FixedU128= FixedU128::from(1); - - let acc = Omnipool::protocol_account(); - let native_id = ::HdxAssetId::get(); - let stable_id = ::StableCoinAssetId::get(); - - Omnipool::set_tvl_cap(RawOrigin::Root.into(), TVL_CAP)?; - - update_balance(stable_id, &acc, stable_amount); - update_balance(native_id, &acc, native_amount); - - Omnipool::initialize_pool(RawOrigin::Root.into(), stable_price, native_price,Permill::from_percent(100), Permill::from_percent(100))?; - + init()?; //Register new asset in asset registry let token_id = AssetRegistry::create_asset(&b"FCK".to_vec(), Balance::one())?; @@ -154,23 +133,7 @@ runtime_benchmarks! { } remove_liquidity { - // Initialize pool - let stable_amount: Balance = 1_000_000_000_000_000u128; - let native_amount: Balance = 1_000_000_000_000_000u128; - let stable_price: FixedU128= FixedU128::from((1,2)); - let native_price: FixedU128= FixedU128::from(1); - - let acc = Omnipool::protocol_account(); - let native_id = ::HdxAssetId::get(); - let stable_id = ::StableCoinAssetId::get(); - - Omnipool::set_tvl_cap(RawOrigin::Root.into(), TVL_CAP)?; - - update_balance(stable_id, &acc, stable_amount); - update_balance(native_id, &acc, native_amount); - - Omnipool::initialize_pool(RawOrigin::Root.into(), stable_price, native_price,Permill::from_percent(100), Permill::from_percent(100))?; - + init()?; // Register new asset in asset registry let token_id = AssetRegistry::create_asset(&b"FCK".to_vec(), 1u128)?; @@ -214,23 +177,7 @@ runtime_benchmarks! { } sell { - // Initialize pool - let stable_amount: Balance = 1_000_000_000_000_000u128; - let native_amount: Balance = 1_000_000_000_000_000u128; - let stable_price: FixedU128 = FixedU128::from((1,2)); - let native_price: FixedU128 = FixedU128::from(1); - - let acc = Omnipool::protocol_account(); - let native_id = ::HdxAssetId::get(); - let stable_id = ::StableCoinAssetId::get(); - - Omnipool::set_tvl_cap(RawOrigin::Root.into(), TVL_CAP)?; - - update_balance(stable_id, &acc, stable_amount); - update_balance(native_id, &acc, native_amount); - - Omnipool::initialize_pool(RawOrigin::Root.into(), stable_price, native_price,Permill::from_percent(100), Permill::from_percent(100))?; - + init()?; // Register new asset in asset registry let token_id = AssetRegistry::create_asset(&b"FCK".to_vec(), 1u128)?; @@ -272,23 +219,7 @@ runtime_benchmarks! { } buy { - // Initialize pool - let stable_amount: Balance = 1_000_000_000_000_000u128; - let native_amount: Balance = 1_000_000_000_000_000u128; - let stable_price: FixedU128= FixedU128::from((1,2)); - let native_price: FixedU128= FixedU128::from(1); - - let acc = Omnipool::protocol_account(); - let native_id = ::HdxAssetId::get(); - let stable_id = ::StableCoinAssetId::get(); - - Omnipool::set_tvl_cap(RawOrigin::Root.into(), TVL_CAP)?; - - update_balance(stable_id, &acc, stable_amount); - update_balance(native_id, &acc, native_amount); - - Omnipool::initialize_pool(RawOrigin::Root.into(), stable_price, native_price,Permill::from_percent(100), Permill::from_percent(100))?; - + init()?; // Register new asset in asset registry let token_id = AssetRegistry::create_asset(&b"FCK".to_vec(), 1_u128)?; @@ -330,24 +261,8 @@ runtime_benchmarks! { } set_asset_tradable_state { - // Initialize pool - let stable_amount: Balance = 1_000_000_000_000_000u128; - let native_amount: Balance = 1_000_000_000_000_000u128; - let stable_price: FixedU128 = FixedU128::from((1,2)); - let native_price: FixedU128 = FixedU128::from(1); - - let acc = Omnipool::protocol_account(); - let native_id = ::HdxAssetId::get(); - let stable_id = ::StableCoinAssetId::get(); - - Omnipool::set_tvl_cap(RawOrigin::Root.into(), TVL_CAP)?; - - update_balance(stable_id, &acc, stable_amount); - update_balance(native_id, &acc, native_amount); - - Omnipool::initialize_pool(RawOrigin::Root.into(), stable_price, native_price, Permill::from_percent(100), Permill::from_percent(100))?; - - }: { Omnipool::set_asset_tradable_state(RawOrigin::Root.into(), stable_id, Tradability::BUY)? } + init()?; + }: { Omnipool::set_asset_tradable_state(RawOrigin::Root.into(), DAI, Tradability::BUY)? } verify { let asset_state = Omnipool::assets(stable_id).unwrap(); assert!(asset_state.tradable == Tradability::BUY); @@ -367,24 +282,7 @@ runtime_benchmarks! { } sacrifice_position { - // Initialize pool - let stable_amount: Balance = 1_000_000_000_000_000u128; - let native_amount: Balance = 1_000_000_000_000_000u128; - let stable_price: FixedU128= FixedU128::from((1,2)); - let native_price: FixedU128= FixedU128::from(1); - - let acc = Omnipool::protocol_account(); - let native_id = ::HdxAssetId::get(); - let stable_id = ::StableCoinAssetId::get(); - - Omnipool::set_tvl_cap(RawOrigin::Root.into(), TVL_CAP)?; - - update_balance(stable_id, &acc, stable_amount); - update_balance(native_id, &acc, native_amount); - - Omnipool::initialize_pool(RawOrigin::Root.into(), stable_price, native_price, Permill::from_percent(100), Permill::from_percent(100))?; - - // Register new asset in asset registry + init()?; let token_id = AssetRegistry::create_asset(&b"FCK".to_vec(), Balance::one())?; // Create account for token provider and set balance @@ -415,47 +313,15 @@ runtime_benchmarks! { } set_asset_weight_cap { - // Initialize pool - let stable_amount: Balance = 1_000_000_000_000_000u128; - let native_amount: Balance = 1_000_000_000_000_000u128; - let stable_price: FixedU128 = FixedU128::from((1,2)); - let native_price: FixedU128 = FixedU128::from(1); - - let acc = Omnipool::protocol_account(); - let native_id = ::HdxAssetId::get(); - let stable_id = ::StableCoinAssetId::get(); - - Omnipool::set_tvl_cap(RawOrigin::Root.into(), TVL_CAP)?; - - update_balance(stable_id, &acc, stable_amount); - update_balance(native_id, &acc, native_amount); - - Omnipool::initialize_pool(RawOrigin::Root.into(), stable_price, native_price, Permill::from_percent(100), Permill::from_percent(100))?; - - }: { Omnipool::set_asset_weight_cap(RawOrigin::Root.into(), stable_id, Permill::from_percent(10))? } + init?(); + }: { Omnipool::set_asset_weight_cap(RawOrigin::Root.into(), DAI, Permill::from_percent(10))? } verify { let asset_state = Omnipool::assets(stable_id).unwrap(); assert!(asset_state.cap == 100_000_000_000_000_000u128); } withdraw_protocol_liquidity { - // Initialize pool - let stable_amount: Balance = 1_000_000_000_000_000u128; - let native_amount: Balance = 1_000_000_000_000_000u128; - let stable_price: FixedU128= FixedU128::from((1,2)); - let native_price: FixedU128= FixedU128::from(1); - - let acc = Omnipool::protocol_account(); - let native_id = ::HdxAssetId::get(); - let stable_id = ::StableCoinAssetId::get(); - - Omnipool::set_tvl_cap(RawOrigin::Root.into(), TVL_CAP)?; - - update_balance(stable_id, &acc, stable_amount); - update_balance(native_id, &acc, native_amount); - - Omnipool::initialize_pool(RawOrigin::Root.into(), stable_price, native_price, Permill::from_percent(100), Permill::from_percent(100))?; - + init()?; // Register new asset in asset registry let token_id = AssetRegistry::create_asset(&b"FCK".to_vec(), Balance::one())?; @@ -493,23 +359,7 @@ runtime_benchmarks! { } remove_token{ - // Initialize pool - let stable_amount: Balance = 1_000_000_000_000_000u128; - let native_amount: Balance = 1_000_000_000_000_000u128; - let stable_price: FixedU128= FixedU128::from((1,2)); - let native_price: FixedU128= FixedU128::from(1); - - let acc = Omnipool::protocol_account(); - let native_id = ::HdxAssetId::get(); - let stable_id = ::StableCoinAssetId::get(); - - Omnipool::set_tvl_cap(RawOrigin::Root.into(), TVL_CAP)?; - - update_balance(stable_id, &acc, stable_amount); - update_balance(native_id, &acc, native_amount); - - Omnipool::initialize_pool(RawOrigin::Root.into(), stable_price, native_price, Permill::from_percent(100), Permill::from_percent(100))?; - + init()?; // Register new asset in asset registry let token_id = AssetRegistry::create_asset(&b"FCK".to_vec(), Balance::one())?; @@ -545,23 +395,7 @@ 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; - let stable_price: FixedU128 = FixedU128::from((1,2)); - let native_price: FixedU128 = FixedU128::from(1); - - let acc = Omnipool::protocol_account(); - let native_id = ::HdxAssetId::get(); - let stable_id = ::StableCoinAssetId::get(); - - Omnipool::set_tvl_cap(RawOrigin::Root.into(), TVL_CAP)?; - - update_balance(stable_id, &acc, stable_amount); - update_balance(native_id, &acc, native_amount); - - Omnipool::initialize_pool(RawOrigin::Root.into(), stable_price, native_price,Permill::from_percent(100), Permill::from_percent(100))?; + init()?; // Register new asset in asset registry let token_id = AssetRegistry::create_asset(&b"FCK".to_vec(), 1u128)?; @@ -615,23 +449,7 @@ runtime_benchmarks! { 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; - let stable_price: FixedU128= FixedU128::from((1,2)); - let native_price: FixedU128= FixedU128::from(1); - - let acc = Omnipool::protocol_account(); - let native_id = ::HdxAssetId::get(); - let stable_id = ::StableCoinAssetId::get(); - - Omnipool::set_tvl_cap(RawOrigin::Root.into(), TVL_CAP)?; - - update_balance(stable_id, &acc, stable_amount); - update_balance(native_id, &acc, native_amount); - - Omnipool::initialize_pool(RawOrigin::Root.into(), stable_price, native_price,Permill::from_percent(100), Permill::from_percent(100))?; + init()?; // Register new asset in asset registry let token_id = AssetRegistry::create_asset(&b"FCK".to_vec(), 1_u128)?; diff --git a/runtime/hydradx/src/lib.rs b/runtime/hydradx/src/lib.rs index 9367396d9..9a1bc6173 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: 187, + spec_version: 188, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 1, From 6aa60e1e245bc0d2ef3888a99fc6fe2d77697262 Mon Sep 17 00:00:00 2001 From: Martin Date: Tue, 7 Nov 2023 14:23:55 +0100 Subject: [PATCH 02/16] fix tests where initialize pool is used --- Cargo.lock | 4 ++-- pallets/circuit-breaker/src/tests/mock.rs | 10 +-------- pallets/dca/Cargo.toml | 2 +- pallets/dca/src/tests/mock.rs | 17 ++++++++------ .../src/tests/deposit_shares.rs | 8 +++---- .../src/tests/mock.rs | 21 +++++++++--------- .../src/tests/redeposit_shares.rs | 10 ++++----- .../src/tests/withdraw_shares.rs | 10 ++++----- pallets/xcm-rate-limiter/Cargo.toml | 2 +- pallets/xcm-rate-limiter/src/tests/mock.rs | 21 +++++++++--------- runtime/adapters/src/tests/mock.rs | 22 +++++++++---------- 11 files changed, 59 insertions(+), 68 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b448b8881..df1e7fe32 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6598,7 +6598,7 @@ dependencies = [ [[package]] name = "pallet-dca" -version = "1.2.2" +version = "1.2.3" dependencies = [ "cumulus-pallet-parachain-system", "cumulus-primitives-core", @@ -7749,7 +7749,7 @@ dependencies = [ [[package]] name = "pallet-xcm-rate-limiter" -version = "0.1.1" +version = "0.1.2" dependencies = [ "cumulus-pallet-xcmp-queue", "frame-benchmarking", diff --git a/pallets/circuit-breaker/src/tests/mock.rs b/pallets/circuit-breaker/src/tests/mock.rs index 8e8f18e3b..81c53b3a8 100644 --- a/pallets/circuit-breaker/src/tests/mock.rs +++ b/pallets/circuit-breaker/src/tests/mock.rs @@ -189,7 +189,6 @@ impl orml_tokens::Config for Test { parameter_types! { pub const HDXAssetId: AssetId = HDX; pub const LRNAAssetId: AssetId = LRNA; - pub const DAIAssetId: AssetId = DAI; pub const PosiitionCollectionId: u32= 1000; pub ProtocolFee: Permill = PROTOCOL_FEE.with(|v| *v.borrow()); @@ -210,7 +209,6 @@ impl pallet_omnipool::Config for Test { type Currency = Tokens; type AuthorityOrigin = EnsureRoot; type HubAssetId = LRNAAssetId; - type StableCoinAssetId = DAIAssetId; type WeightInfo = (); type HdxAssetId = HDXAssetId; type NFTCollectionId = PosiitionCollectionId; @@ -405,7 +403,6 @@ pub struct ExtBuilder { register_stable_asset: bool, max_in_ratio: Balance, max_out_ratio: Balance, - tvl_cap: Balance, init_pool: Option<(FixedU128, FixedU128)>, pool_tokens: Vec<(AssetId, FixedU128, AccountId, Balance)>, max_net_trade_volume_limit_per_block: (u32, u32), @@ -465,7 +462,6 @@ impl Default for ExtBuilder { max_net_trade_volume_limit_per_block: (2_000, 10_000), max_add_liquidity_limit_per_block: Some((4_000, 10_000)), max_remove_liquidity_limit_per_block: Some((2_000, 10_000)), - tvl_cap: u128::MAX, } } } @@ -576,10 +572,6 @@ impl ExtBuilder { let mut r: sp_io::TestExternalities = t.into(); - r.execute_with(|| { - assert_ok!(Omnipool::set_tvl_cap(RuntimeOrigin::root(), self.tvl_cap,)); - }); - if let Some((stable_price, native_price)) = self.init_pool { r.execute_with(|| { assert_ok!(Omnipool::add_token( @@ -591,7 +583,7 @@ impl ExtBuilder { )); assert_ok!(Omnipool::add_token( RuntimeOrigin::root(), - DAIAssetId::get(), + DAI, stable_price, Permill::from_percent(100), Omnipool::protocol_account(), diff --git a/pallets/dca/Cargo.toml b/pallets/dca/Cargo.toml index 7e50d9283..5a68f8a88 100644 --- a/pallets/dca/Cargo.toml +++ b/pallets/dca/Cargo.toml @@ -1,6 +1,6 @@ [package] name = 'pallet-dca' -version = "1.2.2" +version = "1.2.3" description = 'A pallet to manage DCA scheduling' authors = ['GalacticCouncil'] edition = '2021' diff --git a/pallets/dca/src/tests/mock.rs b/pallets/dca/src/tests/mock.rs index e59cdee7f..20d77c086 100644 --- a/pallets/dca/src/tests/mock.rs +++ b/pallets/dca/src/tests/mock.rs @@ -224,7 +224,6 @@ impl orml_tokens::Config for Test { parameter_types! { pub const HDXAssetId: AssetId = HDX; pub const LRNAAssetId: AssetId = LRNA; - pub const DAIAssetId: AssetId = DAI; pub const PosiitionCollectionId: u32= 1000; pub const ExistentialDeposit: u128 = 500; @@ -250,7 +249,6 @@ impl pallet_omnipool::Config for Test { type PositionItemId = u32; type Currency = Currencies; type HubAssetId = LRNAAssetId; - type StableCoinAssetId = DAIAssetId; type WeightInfo = (); type HdxAssetId = HDXAssetId; type NFTCollectionId = PosiitionCollectionId; @@ -861,14 +859,19 @@ impl ExtBuilder { if let Some((stable_price, native_price)) = self.init_pool { r.execute_with(|| { - assert_ok!(Omnipool::set_tvl_cap(RuntimeOrigin::root(), u128::MAX)); - - assert_ok!(Omnipool::initialize_pool( + assert_ok!(Omnipool::add_token( RuntimeOrigin::root(), - stable_price, + HDXAssetId::get(), native_price, Permill::from_percent(100), - Permill::from_percent(100) + Omnipool::protocol_account(), + )); + assert_ok!(Omnipool::add_token( + RuntimeOrigin::root(), + DAI, + stable_price, + Permill::from_percent(100), + Omnipool::protocol_account(), )); for (asset_id, price, owner, amount) in self.pool_tokens { diff --git a/pallets/omnipool-liquidity-mining/src/tests/deposit_shares.rs b/pallets/omnipool-liquidity-mining/src/tests/deposit_shares.rs index 4b189a961..3259fae6f 100644 --- a/pallets/omnipool-liquidity-mining/src/tests/deposit_shares.rs +++ b/pallets/omnipool-liquidity-mining/src/tests/deposit_shares.rs @@ -49,7 +49,7 @@ fn deposit_shares_should_work() { .execute_with(|| { let global_farm_id = 1; let yield_farm_id = 2; - let omnipool_position_id = 0; + let omnipool_position_id = 2; let deposit_id = 1; //Act @@ -136,7 +136,7 @@ fn deposit_shares_should_fail_with_forbidden_when_account_is_not_omnipool_positi .execute_with(|| { let global_farm_id = 1; let yield_farm_id = 2; - let omnipool_position_id = 0; + let omnipool_position_id = 4; let not_position_owner = BOB; //Act @@ -230,7 +230,7 @@ fn deposit_shares_should_fail_when_origin_is_none() { .execute_with(|| { let global_farm_id = 1; let yield_farm_id = 2; - let omnipool_position_id = 1; + let omnipool_position_id = 3; //Act & assert assert_noop!( @@ -323,7 +323,7 @@ fn deposit_shares_should_fail_with_asset_not_found_when_omnipool_deosnt_exists() .execute_with(|| { let global_farm_id = 1; let yield_farm_id = 2; - let omnipool_position_id = 1; + let omnipool_position_id = 3; //Arrange: remove asset from omnipool assert_ok!(Omnipool::remove_asset(KSM)); diff --git a/pallets/omnipool-liquidity-mining/src/tests/mock.rs b/pallets/omnipool-liquidity-mining/src/tests/mock.rs index e900624e1..e5a21679e 100644 --- a/pallets/omnipool-liquidity-mining/src/tests/mock.rs +++ b/pallets/omnipool-liquidity-mining/src/tests/mock.rs @@ -257,7 +257,6 @@ impl pallet_ema_oracle::Config for Test { parameter_types! { pub const HDXAssetId: AssetId = HDX; pub const LRNAAssetId: AssetId = LRNA; - pub const DAIAssetId: AssetId = DAI; pub const PositionCollectionId: CollectionId = OMNIPOOL_COLLECTION_ID; pub ProtocolFee: Permill = PROTOCOL_FEE.with(|v| *v.borrow()); @@ -306,7 +305,6 @@ pub struct ExtBuilder { register_stable_asset: bool, max_in_ratio: Balance, max_out_ratio: Balance, - tvl_cap: Balance, init_pool: Option<(FixedU128, FixedU128)>, pool_tokens: Vec<(AssetId, FixedU128, AccountId, Balance)>, omnipool_liquidity: Vec<(AccountId, AssetId, Balance)>, //who, asset, amount/ @@ -376,7 +374,6 @@ impl Default for ExtBuilder { pool_tokens: vec![], max_in_ratio: 1u128, max_out_ratio: 1u128, - tvl_cap: u128::MAX, omnipool_liquidity: vec![], lm_global_farms: vec![], lm_yield_farms: vec![], @@ -503,20 +500,22 @@ impl ExtBuilder { let mut r: sp_io::TestExternalities = t.into(); - r.execute_with(|| { - assert_ok!(Omnipool::set_tvl_cap(RuntimeOrigin::root(), self.tvl_cap,)); - }); - if let Some((stable_price, native_price)) = self.init_pool { r.execute_with(|| { set_block_number(1); - - assert_ok!(Omnipool::initialize_pool( + assert_ok!(Omnipool::add_token( RuntimeOrigin::root(), - stable_price, + HDXAssetId::get(), native_price, Permill::from_percent(100), - Permill::from_percent(100) + Omnipool::protocol_account(), + )); + assert_ok!(Omnipool::add_token( + RuntimeOrigin::root(), + DAI, + stable_price, + Permill::from_percent(100), + Omnipool::protocol_account(), )); for (asset_id, price, owner, amount) in self.pool_tokens { diff --git a/pallets/omnipool-liquidity-mining/src/tests/redeposit_shares.rs b/pallets/omnipool-liquidity-mining/src/tests/redeposit_shares.rs index 6aa87721b..6c019d966 100644 --- a/pallets/omnipool-liquidity-mining/src/tests/redeposit_shares.rs +++ b/pallets/omnipool-liquidity-mining/src/tests/redeposit_shares.rs @@ -64,7 +64,7 @@ fn redeposit_shares_should_work() { let gc_y_farm_id = 3; let charlie_g_farm_id = 2; let charlie_y_farm_id = 4; - let omnipool_position_id = 0; + let omnipool_position_id = 2; let deposit_id = 1; let asset_in_position = KSM; @@ -146,7 +146,7 @@ fn redeposit_shares_should_fail_with_asset_not_found_when_omnipool_doesnt_exists let gc_y_farm_id = 3; let charlie_g_farm_id = 2; let charlie_y_farm_id = 4; - let omnipool_position_id = 1; + let omnipool_position_id = 3; let deposit_id = 1; //Arrange: deposit position and remove asset from omnipool @@ -216,7 +216,7 @@ fn redeposit_shares_should_fail_with_not_deposit_owner_when_account_is_not_owner .execute_with(|| { let gc_g_farm_id = 1; let gc_y_farm_id = 3; - let omnipool_position_id = 0; + let omnipool_position_id = 2; let deposit_id = 1; //Arrange: deposit position and remove asset from omnipool @@ -279,7 +279,7 @@ fn redeposit_shares_should_fail_when_origin_is_none() { .execute_with(|| { let gc_g_farm_id = 1; let gc_y_farm_id = 3; - let omnipool_position_id = 0; + let omnipool_position_id = 2; let deposit_id = 1; //Arrange: deposit position @@ -342,7 +342,7 @@ fn redeposit_shares_should_fail_with_cant_find_deposit_owner_when_nft_is_missing .execute_with(|| { let gc_g_farm_id = 1; let gc_y_farm_id = 3; - let omnipool_position_id = 0; + let omnipool_position_id = 2; let deposit_id = 1; //Arrange: deposit position and burn lm deposit's nft diff --git a/pallets/omnipool-liquidity-mining/src/tests/withdraw_shares.rs b/pallets/omnipool-liquidity-mining/src/tests/withdraw_shares.rs index 0471da16d..ab893e452 100644 --- a/pallets/omnipool-liquidity-mining/src/tests/withdraw_shares.rs +++ b/pallets/omnipool-liquidity-mining/src/tests/withdraw_shares.rs @@ -48,7 +48,7 @@ fn withdraw_shares_should_unlock_omnipool_position_when_last_entry_in_deposit() .execute_with(|| { let global_farm_id = 1; let yield_farm_id = 2; - let omnipool_position_id = 0; + let omnipool_position_id = 2; let deposit_id = 1; //Arrange: deposit shares @@ -154,7 +154,7 @@ fn withdraw_shares_should_not_unlock_omnipool_position_when_deposit_is_not_burne let gc_y_farm_id = 3; let charlie_g_farm_id = 2; let charlie_y_farm_id = 4; - let omnipool_position_id = 0; + let omnipool_position_id = 2; let deposit_id = 1; //Arrange: deposit shares & redeposit @@ -241,7 +241,7 @@ fn withdraw_shares_should_fail_when_origin_is_none() { .execute_with(|| { let global_farm_id = 1; let yield_farm_id = 2; - let omnipool_position_id = 0; + let omnipool_position_id = 2; let deposit_id = 1; //Arrange: deposit shares @@ -293,7 +293,7 @@ fn withdraw_shares_should_fail_with_not_deposit_owner_when_account_is_not_owner( .execute_with(|| { let global_farm_id = 1; let yield_farm_id = 2; - let omnipool_position_id = 0; + let omnipool_position_id = 2; let deposit_id = 1; //Arrange: deposit shares @@ -345,7 +345,7 @@ fn withdraw_shares_should_fail_with_not_deposit_owner_when_nft_is_missing() { .execute_with(|| { let global_farm_id = 1; let yield_farm_id = 2; - let omnipool_position_id = 0; + let omnipool_position_id = 2; let deposit_id = 1; //Arrange: deposit shares diff --git a/pallets/xcm-rate-limiter/Cargo.toml b/pallets/xcm-rate-limiter/Cargo.toml index 170cb8d87..764312eef 100644 --- a/pallets/xcm-rate-limiter/Cargo.toml +++ b/pallets/xcm-rate-limiter/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-xcm-rate-limiter" -version = "0.1.1" +version = "0.1.2" authors = ["GalacticCouncil "] edition = "2021" license = "Apache-2.0" diff --git a/pallets/xcm-rate-limiter/src/tests/mock.rs b/pallets/xcm-rate-limiter/src/tests/mock.rs index a038c5a8f..879e50505 100644 --- a/pallets/xcm-rate-limiter/src/tests/mock.rs +++ b/pallets/xcm-rate-limiter/src/tests/mock.rs @@ -221,7 +221,6 @@ impl orml_tokens::Config for Test { parameter_types! { pub const HDXAssetId: AssetId = HDX; pub const LRNAAssetId: AssetId = LRNA; - pub const DAIAssetId: AssetId = DAI; pub const PosiitionCollectionId: u32= 1000; pub AssetWeightCap: Permill =ASSET_WEIGHT_CAP.with(|v| *v.borrow()); @@ -240,7 +239,6 @@ impl pallet_omnipool::Config for Test { type Currency = Tokens; type AuthorityOrigin = EnsureRoot; type HubAssetId = LRNAAssetId; - type StableCoinAssetId = DAIAssetId; type WeightInfo = (); type HdxAssetId = HDXAssetId; type NFTCollectionId = PosiitionCollectionId; @@ -352,7 +350,6 @@ pub struct ExtBuilder { register_stable_asset: bool, max_in_ratio: Balance, max_out_ratio: Balance, - tvl_cap: Balance, init_pool: Option<(FixedU128, FixedU128)>, pool_tokens: Vec<(AssetId, FixedU128, AccountId, Balance)>, } @@ -406,7 +403,6 @@ impl Default for ExtBuilder { pool_tokens: vec![], max_in_ratio: 1u128, max_out_ratio: 1u128, - tvl_cap: u128::MAX, } } } @@ -464,18 +460,21 @@ impl ExtBuilder { let mut r: sp_io::TestExternalities = t.into(); - r.execute_with(|| { - assert_ok!(Omnipool::set_tvl_cap(RuntimeOrigin::root(), self.tvl_cap,)); - }); - if let Some((stable_price, native_price)) = self.init_pool { r.execute_with(|| { - assert_ok!(Omnipool::initialize_pool( + assert_ok!(Omnipool::add_token( RuntimeOrigin::root(), - stable_price, + HDXAssetId::get(), native_price, Permill::from_percent(100), - Permill::from_percent(100) + Omnipool::protocol_account(), + )); + assert_ok!(Omnipool::add_token( + RuntimeOrigin::root(), + DAI, + stable_price, + Permill::from_percent(100), + Omnipool::protocol_account(), )); for (asset_id, price, owner, amount) in self.pool_tokens { diff --git a/runtime/adapters/src/tests/mock.rs b/runtime/adapters/src/tests/mock.rs index 3dddb08a2..ea893cf17 100644 --- a/runtime/adapters/src/tests/mock.rs +++ b/runtime/adapters/src/tests/mock.rs @@ -154,7 +154,6 @@ impl orml_tokens::Config for Test { parameter_types! { pub const HDXAssetId: AssetId = HDX; pub const LRNAAssetId: AssetId = LRNA; - pub const DAIAssetId: AssetId = DAI; pub const PosiitionCollectionId: u32= 1000; pub const MaxNumberOfTrades: u8 = 5; @@ -179,7 +178,6 @@ impl pallet_omnipool::Config for Test { type AuthorityOrigin = EnsureRoot; type HubAssetId = LRNAAssetId; type Fee = FeeProvider; - type StableCoinAssetId = DAIAssetId; type WeightInfo = (); type HdxAssetId = HDXAssetId; type NFTCollectionId = PosiitionCollectionId; @@ -294,7 +292,6 @@ pub struct ExtBuilder { register_stable_asset: bool, max_in_ratio: Balance, max_out_ratio: Balance, - tvl_cap: Balance, init_pool: Option<(FixedU128, FixedU128)>, pool_tokens: Vec<(AssetId, FixedU128, AccountId, Balance)>, } @@ -360,7 +357,6 @@ impl Default for ExtBuilder { pool_tokens: vec![], max_in_ratio: 1u128, max_out_ratio: 1u128, - tvl_cap: u128::MAX, } } } @@ -446,20 +442,22 @@ impl ExtBuilder { let mut r: sp_io::TestExternalities = t.into(); - r.execute_with(|| { - assert_ok!(Omnipool::set_tvl_cap(RuntimeOrigin::root(), self.tvl_cap,)); - }); - if let Some((stable_price, native_price)) = self.init_pool { r.execute_with(|| { - assert_ok!(Omnipool::initialize_pool( + assert_ok!(Omnipool::add_token( RuntimeOrigin::root(), - stable_price, + HDXAssetId::get(), native_price, Permill::from_percent(100), - Permill::from_percent(100) + Omnipool::protocol_account(), + )); + assert_ok!(Omnipool::add_token( + RuntimeOrigin::root(), + DAI, + stable_price, + Permill::from_percent(100), + Omnipool::protocol_account(), )); - for (asset_id, price, owner, amount) in self.pool_tokens { assert_ok!(Tokens::transfer( RuntimeOrigin::signed(owner), From 2ebcfe0a3e73c7833c9c5a9297c1d97516bb4df6 Mon Sep 17 00:00:00 2001 From: Martin Date: Tue, 7 Nov 2023 14:36:49 +0100 Subject: [PATCH 03/16] fix benchmark tests --- .../src/benchmarks.rs | 27 +++----- runtime/hydradx/src/benchmarking/dca.rs | 6 +- runtime/hydradx/src/benchmarking/omnipool.rs | 61 +++++++++++-------- 3 files changed, 46 insertions(+), 48 deletions(-) diff --git a/pallets/omnipool-liquidity-mining/src/benchmarks.rs b/pallets/omnipool-liquidity-mining/src/benchmarks.rs index 2ee62126e..4f6e4b53e 100644 --- a/pallets/omnipool-liquidity-mining/src/benchmarks.rs +++ b/pallets/omnipool-liquidity-mining/src/benchmarks.rs @@ -17,7 +17,6 @@ use crate::*; use frame_benchmarking::{account, benchmarks}; -use frame_support::assert_ok; use frame_support::traits::{OnFinalize, OnInitialize}; use frame_system::{Pallet as System, RawOrigin}; use hydradx_traits::Registry; @@ -26,7 +25,6 @@ use pallet_liquidity_mining::Instance1; use primitives::AssetId; use sp_runtime::{traits::One, FixedU128, Permill}; -const TVL_CAP: Balance = 222_222_000_000_000_000_000_000; const ONE: Balance = 1_000_000_000_000; const BTC_ONE: Balance = 100_000_000; const HDX: AssetId = 0; @@ -91,43 +89,32 @@ where Pallet::::create_yield_farm(RawOrigin::Signed(owner).into(), id, asset, FixedU128::one(), None) } -fn update_balance(currency_id: AssetId, who: &T::AccountId, balance: Balance) { - assert_ok!( - <::Currency as MultiCurrencyExtended<_>>::update_balance( - currency_id, - who, - balance.saturated_into() - ) - ); -} - fn initialize_omnipool() -> DispatchResult where ::Currency: MultiCurrencyExtended, T: pallet_ema_oracle::Config, T::AssetId: From, { - init()?; let stable_amount: Balance = 1_000_000_000_000_000u128; let native_amount: Balance = 1_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(); + let acc = OmnipoolPallet::::protocol_account(); - update_balance(DAI, &acc, stable_amount); - update_balance(HDX, &acc, native_amount); + ::Currency::update_balance(DAI.into(), &acc, stable_amount as i128)?; + ::Currency::update_balance(HDX.into(), &acc, native_amount as i128)?; - OmnipoolPallet::add_token( + OmnipoolPallet::::add_token( RawOrigin::Root.into(), - HDX, + HDX.into(), native_price, Permill::from_percent(100), acc.clone(), )?; - OmnipoolPallet::add_token( + OmnipoolPallet::::add_token( RawOrigin::Root.into(), - DAI, + DAI.into(), stable_price, Permill::from_percent(100), acc.clone(), diff --git a/runtime/hydradx/src/benchmarking/dca.rs b/runtime/hydradx/src/benchmarking/dca.rs index cc33c1dd4..2ac1e417f 100644 --- a/runtime/hydradx/src/benchmarking/dca.rs +++ b/runtime/hydradx/src/benchmarking/dca.rs @@ -18,7 +18,7 @@ use crate::{ AccountId, AssetId, Balance, BlockNumber, Currencies, EmaOracle, MaxSchedulesPerBlock, NamedReserveId, Runtime, - StableAssetId, System, DCA, + System, DCA, }; use frame_benchmarking::account; @@ -187,7 +187,7 @@ runtime_benchmarks! { assert_ok!(DCA::schedule(RawOrigin::Signed(seller.clone()).into(), schedule1.clone(), Option::Some(execution_block))); - assert_eq!(Currencies::free_balance(StableAssetId::get(), &seller),0); + assert_eq!(Currencies::free_balance(DAI, &seller),0); let reserved_balance = get_named_reseve_balance(HDX, seller.clone()); let init_reserved_balance = 2000 * ONE; @@ -228,7 +228,7 @@ runtime_benchmarks! { assert_ok!(DCA::schedule(RawOrigin::Signed(seller.clone()).into(), schedule1.clone(), Option::Some(execution_block))); - assert_eq!(Currencies::free_balance(StableAssetId::get(), &seller),0); + assert_eq!(Currencies::free_balance(DAI, &seller),0); let reserved_balance = get_named_reseve_balance(HDX, seller.clone()); let init_reserved_balance = 2000 * ONE; diff --git a/runtime/hydradx/src/benchmarking/omnipool.rs b/runtime/hydradx/src/benchmarking/omnipool.rs index 8dc51f72c..af8f3a7fe 100644 --- a/runtime/hydradx/src/benchmarking/omnipool.rs +++ b/runtime/hydradx/src/benchmarking/omnipool.rs @@ -46,7 +46,7 @@ fn run_to_block(to: u32) { } const HDX: AssetId = 0; -const DAI: AssetId = 1; +const DAI: AssetId = 2; fn init() -> DispatchResult { let stable_amount: Balance = 1_000_000_000_000_000u128; @@ -71,7 +71,7 @@ fn init() -> DispatchResult { DAI, stable_price, Permill::from_percent(100), - acc.clone(), + acc, )?; Ok(()) @@ -83,6 +83,8 @@ runtime_benchmarks! { add_token{ init()?; + let acc = Omnipool::protocol_account(); + // Register new asset in asset registry let token_id = AssetRegistry::create_asset(&b"FCK".to_vec(), Balance::one())?; @@ -104,6 +106,7 @@ runtime_benchmarks! { add_liquidity { init()?; + let acc = Omnipool::protocol_account(); //Register new asset in asset registry let token_id = AssetRegistry::create_asset(&b"FCK".to_vec(), Balance::one())?; @@ -134,6 +137,7 @@ runtime_benchmarks! { remove_liquidity { init()?; + let acc = Omnipool::protocol_account(); // Register new asset in asset registry let token_id = AssetRegistry::create_asset(&b"FCK".to_vec(), 1u128)?; @@ -161,8 +165,8 @@ runtime_benchmarks! { // to ensure worst case - Let's do a trade to make sure price changes, so LP provider receives some LRNA ( which does additional transfer) let buyer: AccountId = account("buyer", 2, 1); - update_balance(stable_id, &buyer, 500_000_000_000_000_u128); - Omnipool::buy(RawOrigin::Signed(buyer).into(), token_id, stable_id, 100_000_000_000_u128, 100_000_000_000_000_u128)?; + update_balance(DAI, &buyer, 500_000_000_000_000_u128); + Omnipool::buy(RawOrigin::Signed(buyer).into(), token_id, DAI, 100_000_000_000_u128, 100_000_000_000_000_u128)?; let hub_id = ::HubAssetId::get(); let hub_issuance = ::Currency::total_issuance(hub_id); @@ -178,6 +182,7 @@ runtime_benchmarks! { sell { init()?; + let acc = Omnipool::protocol_account(); // Register new asset in asset registry let token_id = AssetRegistry::create_asset(&b"FCK".to_vec(), 1u128)?; @@ -204,8 +209,8 @@ runtime_benchmarks! { Omnipool::add_liquidity(RawOrigin::Signed(lp_provider).into(), token_id, liquidity_added)?; let buyer: AccountId = account("buyer", 2, 1); - update_balance(stable_id, &buyer, 500_000_000_000_000_u128); - Omnipool::buy(RawOrigin::Signed(buyer).into(), token_id, stable_id, 30_000_000_000_000_u128, 100_000_000_000_000_u128)?; + update_balance(DAI, &buyer, 500_000_000_000_000_u128); + Omnipool::buy(RawOrigin::Signed(buyer).into(), token_id, DAI, 30_000_000_000_000_u128, 100_000_000_000_000_u128)?; let seller: AccountId = account("seller", 3, 1); update_balance(token_id, &seller, 500_000_000_000_000_u128); @@ -213,13 +218,14 @@ runtime_benchmarks! { let amount_sell = 100_000_000_000_u128; let buy_min_amount = 10_000_000_000_u128; - }: { Omnipool::sell(RawOrigin::Signed(seller.clone()).into(), token_id, stable_id, amount_sell, buy_min_amount)? } + }: { Omnipool::sell(RawOrigin::Signed(seller.clone()).into(), token_id, DAI, amount_sell, buy_min_amount)? } verify { - assert!(::Currency::free_balance(stable_id, &seller) >= buy_min_amount); + assert!(::Currency::free_balance(DAI, &seller) >= buy_min_amount); } buy { init()?; + let acc = Omnipool::protocol_account(); // Register new asset in asset registry let token_id = AssetRegistry::create_asset(&b"FCK".to_vec(), 1_u128)?; @@ -246,8 +252,8 @@ runtime_benchmarks! { Omnipool::add_liquidity(RawOrigin::Signed(lp_provider).into(), token_id, liquidity_added)?; let buyer: AccountId = account("buyer", 2, 1); - update_balance(stable_id, &buyer, 500_000_000_000_000_u128); - Omnipool::buy(RawOrigin::Signed(buyer).into(), token_id, stable_id, 30_000_000_000_000_u128, 100_000_000_000_000_u128)?; + update_balance(DAI, &buyer, 500_000_000_000_000_u128); + Omnipool::buy(RawOrigin::Signed(buyer).into(), token_id, DAI, 30_000_000_000_000_u128, 100_000_000_000_000_u128)?; let seller: AccountId = account("seller", 3, 1); update_balance(token_id, &seller, 500_000_000_000_000_u128); @@ -255,16 +261,16 @@ runtime_benchmarks! { let amount_buy = 1_000_000_000_000_u128; let sell_max_limit = 2_000_000_000_000_u128; - }: { Omnipool::buy(RawOrigin::Signed(seller.clone()).into(), stable_id, token_id, amount_buy, sell_max_limit)? } + }: { Omnipool::buy(RawOrigin::Signed(seller.clone()).into(), DAI, token_id, amount_buy, sell_max_limit)? } verify { - assert!(::Currency::free_balance(stable_id, &seller) >= Balance::zero()); + assert!(::Currency::free_balance(DAI, &seller) >= Balance::zero()); } set_asset_tradable_state { init()?; }: { Omnipool::set_asset_tradable_state(RawOrigin::Root.into(), DAI, Tradability::BUY)? } verify { - let asset_state = Omnipool::assets(stable_id).unwrap(); + let asset_state = Omnipool::assets(DAI).unwrap(); assert!(asset_state.tradable == Tradability::BUY); } @@ -283,6 +289,7 @@ runtime_benchmarks! { sacrifice_position { init()?; + let acc = Omnipool::protocol_account(); let token_id = AssetRegistry::create_asset(&b"FCK".to_vec(), Balance::one())?; // Create account for token provider and set balance @@ -313,15 +320,16 @@ runtime_benchmarks! { } set_asset_weight_cap { - init?(); + init()?; }: { Omnipool::set_asset_weight_cap(RawOrigin::Root.into(), DAI, Permill::from_percent(10))? } verify { - let asset_state = Omnipool::assets(stable_id).unwrap(); + let asset_state = Omnipool::assets(DAI).unwrap(); assert!(asset_state.cap == 100_000_000_000_000_000u128); } withdraw_protocol_liquidity { init()?; + let acc = Omnipool::protocol_account(); // Register new asset in asset registry let token_id = AssetRegistry::create_asset(&b"FCK".to_vec(), Balance::one())?; @@ -360,6 +368,7 @@ runtime_benchmarks! { remove_token{ init()?; + let acc = Omnipool::protocol_account(); // Register new asset in asset registry let token_id = AssetRegistry::create_asset(&b"FCK".to_vec(), Balance::one())?; @@ -397,6 +406,7 @@ runtime_benchmarks! { let e in 0..1; // if e == 1, execute_sell is executed init()?; + let acc = Omnipool::protocol_account(); // Register new asset in asset registry let token_id = AssetRegistry::create_asset(&b"FCK".to_vec(), 1u128)?; @@ -423,8 +433,8 @@ runtime_benchmarks! { Omnipool::add_liquidity(RawOrigin::Signed(lp_provider).into(), token_id, liquidity_added)?; let buyer: AccountId = account("buyer", 2, 1); - update_balance(stable_id, &buyer, 500_000_000_000_000_u128); - Omnipool::buy(RawOrigin::Signed(buyer).into(), token_id, stable_id, 30_000_000_000_000_u128, 100_000_000_000_000_u128)?; + update_balance(DAI, &buyer, 500_000_000_000_000_u128); + Omnipool::buy(RawOrigin::Signed(buyer).into(), token_id, DAI, 30_000_000_000_000_u128, 100_000_000_000_000_u128)?; let seller: AccountId = account("seller", 3, 1); update_balance(token_id, &seller, 500_000_000_000_000_u128); @@ -434,15 +444,15 @@ runtime_benchmarks! { }: { if c != 0 { - assert!(>::calculate_sell(PoolType::Omnipool, token_id, stable_id, amount_sell).is_ok()); + assert!(>::calculate_sell(PoolType::Omnipool, token_id, DAI, 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()); + assert!(>::execute_sell(RawOrigin::Signed(seller.clone()).into(), PoolType::Omnipool, token_id, DAI, amount_sell, buy_min_amount).is_ok()); } } verify { if e != 0 { - assert!(::Currency::free_balance(stable_id, &seller) >= buy_min_amount); + assert!(::Currency::free_balance(DAI, &seller) >= buy_min_amount); } } @@ -451,6 +461,7 @@ runtime_benchmarks! { let e in 0..1; // if e == 1, execute_buy is executed init()?; + let acc = Omnipool::protocol_account(); // Register new asset in asset registry let token_id = AssetRegistry::create_asset(&b"FCK".to_vec(), 1_u128)?; @@ -477,8 +488,8 @@ runtime_benchmarks! { Omnipool::add_liquidity(RawOrigin::Signed(lp_provider).into(), token_id, liquidity_added)?; let buyer: AccountId = account("buyer", 2, 1); - update_balance(stable_id, &buyer, 500_000_000_000_000_u128); - Omnipool::buy(RawOrigin::Signed(buyer).into(), token_id, stable_id, 30_000_000_000_000_u128, 100_000_000_000_000_u128)?; + update_balance(DAI, &buyer, 500_000_000_000_000_u128); + Omnipool::buy(RawOrigin::Signed(buyer).into(), token_id, DAI, 30_000_000_000_000_u128, 100_000_000_000_000_u128)?; let seller: AccountId = account("seller", 3, 1); update_balance(token_id, &seller, 500_000_000_000_000_u128); @@ -488,13 +499,13 @@ runtime_benchmarks! { }: { for _ in 1..c { - assert!(>::calculate_buy(PoolType::Omnipool, token_id, stable_id, amount_buy).is_ok()); + assert!(>::calculate_buy(PoolType::Omnipool, token_id, DAI, 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()); + assert!(>::execute_buy(RawOrigin::Signed(seller.clone()).into(), PoolType::Omnipool, token_id, DAI, amount_buy, sell_max_limit).is_ok()); } verify { if e != 0 { - assert!(::Currency::free_balance(stable_id, &seller) >= Balance::zero()); + assert!(::Currency::free_balance(DAI, &seller) >= Balance::zero()); } } From 0920c26df56853c288e604a422fa7e865570f92f Mon Sep 17 00:00:00 2001 From: Martin Date: Tue, 7 Nov 2023 14:37:41 +0100 Subject: [PATCH 04/16] remove init_pool from weighti nfo --- pallets/omnipool/src/weights.rs | 53 ------------------------- runtime/hydradx/src/weights/omnipool.rs | 26 ------------ 2 files changed, 79 deletions(-) diff --git a/pallets/omnipool/src/weights.rs b/pallets/omnipool/src/weights.rs index 17e1ab844..2764e0167 100644 --- a/pallets/omnipool/src/weights.rs +++ b/pallets/omnipool/src/weights.rs @@ -48,7 +48,6 @@ use sp_std::marker::PhantomData; /// Weight functions needed for pallet_omnipool. pub trait WeightInfo { - fn initialize_pool() -> Weight; fn add_token() -> Weight; fn add_liquidity() -> Weight; fn remove_liquidity() -> Weight; @@ -68,32 +67,6 @@ pub trait WeightInfo { 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 { - // 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) @@ -431,32 +404,6 @@ 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 { - // 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) diff --git a/runtime/hydradx/src/weights/omnipool.rs b/runtime/hydradx/src/weights/omnipool.rs index cb121c187..aa3bdd4f6 100644 --- a/runtime/hydradx/src/weights/omnipool.rs +++ b/runtime/hydradx/src/weights/omnipool.rs @@ -54,32 +54,6 @@ use pallet_omnipool::weights::WeightInfo; 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 { - // Minimum execution time: 142_482 nanoseconds. - Weight::from_ref_time(143_649_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) From 806dc093fea8a8620c6df8b67a8ff245cc247b80 Mon Sep 17 00:00:00 2001 From: Martin Date: Tue, 7 Nov 2023 14:45:41 +0100 Subject: [PATCH 05/16] version bump --- Cargo.lock | 2 +- runtime/adapters/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index df1e7fe32..9a3f9aeb2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3786,7 +3786,7 @@ dependencies = [ [[package]] name = "hydradx-adapters" -version = "0.6.4" +version = "0.6.5" dependencies = [ "cumulus-pallet-parachain-system", "cumulus-primitives-core", diff --git a/runtime/adapters/Cargo.toml b/runtime/adapters/Cargo.toml index 1b001889f..8531ae7fd 100644 --- a/runtime/adapters/Cargo.toml +++ b/runtime/adapters/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hydradx-adapters" -version = "0.6.4" +version = "0.6.5" description = "Structs and other generic types for building runtimes." authors = ["GalacticCouncil"] edition = "2021" From fe096e7dc34165cf1f48d6e85b3024241d3c959f Mon Sep 17 00:00:00 2001 From: Martin Date: Wed, 15 Nov 2023 10:01:31 +0100 Subject: [PATCH 06/16] fix evm integration tests --- integration-tests/src/evm.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/integration-tests/src/evm.rs b/integration-tests/src/evm.rs index 8525b3ef3..f0ec3f306 100644 --- a/integration-tests/src/evm.rs +++ b/integration-tests/src/evm.rs @@ -702,8 +702,6 @@ pub fn init_omnipol() { let stable_price = FixedU128::from_float(0.7); let acc = hydradx_runtime::Omnipool::protocol_account(); - assert_ok!(hydradx_runtime::Omnipool::set_tvl_cap(RuntimeOrigin::root(), u128::MAX)); - let stable_amount: Balance = 5_000_000_000_000_000_000_000u128; let native_amount: Balance = 5_000_000_000_000_000_000_000u128; assert_ok!(Tokens::set_balance( @@ -720,12 +718,20 @@ pub fn init_omnipol() { native_amount as i128, )); - assert_ok!(hydradx_runtime::Omnipool::initialize_pool( + assert_ok!(hydradx_runtime::Omnipool::add_token( hydradx_runtime::RuntimeOrigin::root(), - stable_price, + HDX, native_price, Permill::from_percent(60), - Permill::from_percent(60) + AccountId::from(ALICE), + )); + + assert_ok!(hydradx_runtime::Omnipool::add_token( + hydradx_runtime::RuntimeOrigin::root(), + DAI, + stable_price, + Permill::from_percent(60), + AccountId::from(ALICE), )); assert_ok!(Balances::set_balance( From 0d2d1ada201d453b7c72ce039c6620683f3479b6 Mon Sep 17 00:00:00 2001 From: dmoka Date: Wed, 15 Nov 2023 10:24:26 +0100 Subject: [PATCH 07/16] copy evm-utiltiy module because pulling Acala always is performance heavy --- Cargo.lock | 6 +- Cargo.toml | 3 +- .../hydradx/src/evm/evm-utility/Cargo.toml | 32 ++++++++++ .../src/evm/evm-utility/macro/Cargo.toml | 14 ++++ .../src/evm/evm-utility/macro/src/lib.rs | 64 +++++++++++++++++++ .../src/evm/evm-utility/macro/tests/test.rs | 41 ++++++++++++ .../hydradx/src/evm/evm-utility/src/lib.rs | 35 ++++++++++ 7 files changed, 190 insertions(+), 5 deletions(-) create mode 100644 runtime/hydradx/src/evm/evm-utility/Cargo.toml create mode 100644 runtime/hydradx/src/evm/evm-utility/macro/Cargo.toml create mode 100644 runtime/hydradx/src/evm/evm-utility/macro/src/lib.rs create mode 100644 runtime/hydradx/src/evm/evm-utility/macro/tests/test.rs create mode 100644 runtime/hydradx/src/evm/evm-utility/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index d816c3dda..6757002ce 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5974,8 +5974,7 @@ dependencies = [ [[package]] name = "module-evm-utility" -version = "2.22.0" -source = "git+https://github.com/AcalaNetwork/Acala?branch=release-acala-2.22.0#37d9e3604fb3f217869ccc49dcce8a7b632fb73a" +version = "2.21.0" dependencies = [ "ethereum", "evm 0.36.0", @@ -5987,8 +5986,7 @@ dependencies = [ [[package]] name = "module-evm-utility-macro" -version = "2.22.0" -source = "git+https://github.com/AcalaNetwork/Acala?branch=release-acala-2.22.0#37d9e3604fb3f217869ccc49dcce8a7b632fb73a" +version = "2.21.0" dependencies = [ "module-evm-utility", "proc-macro2", diff --git a/Cargo.toml b/Cargo.toml index 649a51331..1f82b1d07 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,6 +35,7 @@ members = [ 'math', 'pallets/staking', 'pallets/democracy', + 'runtime/hydradx/src/evm/evm-utility/macro', ] [workspace.dependencies] @@ -227,7 +228,7 @@ pallet-evm-chain-id = { git = "https://github.com/PureStake/frontier", branch = pallet-evm-precompile-dispatch = { git = "https://github.com/PureStake/frontier", branch = "moonbeam-polkadot-v0.9.38", default-features = false } # EVM from acala -module-evm-utility-macro = { git = "https://github.com/AcalaNetwork/Acala", branch = "release-acala-2.22.0", default-features = false } +module-evm-utility-macro = { path = "runtime/hydradx/src/evm/evm-utility/macro", default-features = false} # Polkadot dependencies pallet-xcm = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.38", default-features = false } diff --git a/runtime/hydradx/src/evm/evm-utility/Cargo.toml b/runtime/hydradx/src/evm/evm-utility/Cargo.toml new file mode 100644 index 000000000..6654fa288 --- /dev/null +++ b/runtime/hydradx/src/evm/evm-utility/Cargo.toml @@ -0,0 +1,32 @@ +[package] +name = "module-evm-utility" +version = "2.21.0" +authors = ["Acala Developers"] +edition = "2021" + +[dependencies] +sha3 = { version = "0.10.6", default-features = false } + +sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0", default-features = false } + +evm = { git = "https://github.com/rust-blockchain/evm", rev = "13240a8a551586fdef0b5028ed73af80b248092a", default-features = false, features = ["with-codec"] } +evm-gasometer = { git = "https://github.com/rust-blockchain/evm", rev = "13240a8a551586fdef0b5028ed73af80b248092a", default-features = false } +evm-runtime = { git = "https://github.com/rust-blockchain/evm", rev = "13240a8a551586fdef0b5028ed73af80b248092a", default-features = false } +ethereum = { version = "0.14.0", default-features = false, features = ["with-codec"] } + +[features] +default = ["std"] +std = [ + "sha3/std", + "sp-std/std", + "evm/std", + "evm/with-serde", + "evm-runtime/std", + "evm-gasometer/std", + "ethereum/with-serde", +] +tracing = [ + "evm/tracing", + "evm-gasometer/tracing", + "evm-runtime/tracing", +] diff --git a/runtime/hydradx/src/evm/evm-utility/macro/Cargo.toml b/runtime/hydradx/src/evm/evm-utility/macro/Cargo.toml new file mode 100644 index 000000000..738d54abe --- /dev/null +++ b/runtime/hydradx/src/evm/evm-utility/macro/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "module-evm-utility-macro" +version = "2.21.0" +authors = ["Acala Developers"] +edition = "2021" + +[lib] +proc-macro = true + +[dependencies] +quote = "1.0.20" +syn = { version = "1.0.98", features = ["full", "fold", "extra-traits", "visit"] } +proc-macro2 = "1.0.40" +module-evm-utility = { path = ".." } diff --git a/runtime/hydradx/src/evm/evm-utility/macro/src/lib.rs b/runtime/hydradx/src/evm/evm-utility/macro/src/lib.rs new file mode 100644 index 000000000..0d090917f --- /dev/null +++ b/runtime/hydradx/src/evm/evm-utility/macro/src/lib.rs @@ -0,0 +1,64 @@ +// This file is an exact copy from the Acala project (https://github.com/AcalaNetwork/Acala/), +// which is licensed under the GNU General Public License. +// +// For more info of its license, please check the Acala project + +use proc_macro::TokenStream; +use proc_macro2::Literal; +use quote::quote; +use syn::{parse_macro_input, Expr, ExprLit, Ident, ItemEnum, Lit, LitByteStr, LitStr}; + +#[proc_macro_attribute] +pub fn generate_function_selector(_: TokenStream, input: TokenStream) -> TokenStream { + let item = parse_macro_input!(input as ItemEnum); + + let ItemEnum { + attrs, + vis, + enum_token, + ident, + variants, + .. + } = item; + + let mut ident_expressions: Vec = vec![]; + let mut variant_expressions: Vec = vec![]; + for variant in variants { + if let Some((_, Expr::Lit(ExprLit { lit, .. }))) = variant.discriminant { + if let Lit::Str(token) = lit { + let selector = module_evm_utility::get_function_selector(&token.value()); + // println!("method: {:?}, selector: {:?}", token.value(), selector); + ident_expressions.push(variant.ident); + variant_expressions.push(Expr::Lit(ExprLit { + lit: Lit::Verbatim(Literal::u32_suffixed(selector)), + attrs: Default::default(), + })); + } else { + panic!("Not method string: `{:?}`", lit); + } + } else { + panic!("Not enum: `{:?}`", variant); + } + } + + (quote! { + #(#attrs)* + #vis #enum_token #ident { + #( + #ident_expressions = #variant_expressions, + )* + } + }) + .into() +} + +#[proc_macro] +pub fn keccak256(input: TokenStream) -> TokenStream { + let lit_str = parse_macro_input!(input as LitStr); + + let result = module_evm_utility::sha3_256(&lit_str.value()); + + let eval = Lit::ByteStr(LitByteStr::new(result.as_ref(), proc_macro2::Span::call_site())); + + quote!(#eval).into() +} diff --git a/runtime/hydradx/src/evm/evm-utility/macro/tests/test.rs b/runtime/hydradx/src/evm/evm-utility/macro/tests/test.rs new file mode 100644 index 000000000..78f11f792 --- /dev/null +++ b/runtime/hydradx/src/evm/evm-utility/macro/tests/test.rs @@ -0,0 +1,41 @@ +// This file is an exact copy from the Acala project (https://github.com/AcalaNetwork/Acala/), +// which is licensed under the GNU General Public License. +// +// For more info of its license, please check the Acala project + +#[cfg(test)] +mod tests { + #[test] + fn generate_function_selector_works() { + #[module_evm_utility_macro::generate_function_selector] + #[derive(Debug, Eq, PartialEq)] + #[repr(u32)] + pub enum Action { + Name = "name()", + Symbol = "symbol()", + Decimals = "decimals()", + TotalSupply = "totalSupply()", + BalanceOf = "balanceOf(address)", + Transfer = "transfer(address,uint256)", + } + + assert_eq!(Action::Name as u32, 0x06fdde03_u32); + assert_eq!(Action::Symbol as u32, 0x95d89b41_u32); + assert_eq!(Action::Decimals as u32, 0x313ce567_u32); + assert_eq!(Action::TotalSupply as u32, 0x18160ddd_u32); + assert_eq!(Action::BalanceOf as u32, 0x70a08231_u32); + assert_eq!(Action::Transfer as u32, 0xa9059cbb_u32); + } + + #[test] + fn keccak256_works() { + assert_eq!( + module_evm_utility_macro::keccak256!(""), + &module_evm_utility::sha3_256("") + ); + assert_eq!( + module_evm_utility_macro::keccak256!("keccak256"), + &module_evm_utility::sha3_256("keccak256") + ); + } +} diff --git a/runtime/hydradx/src/evm/evm-utility/src/lib.rs b/runtime/hydradx/src/evm/evm-utility/src/lib.rs new file mode 100644 index 000000000..360778eec --- /dev/null +++ b/runtime/hydradx/src/evm/evm-utility/src/lib.rs @@ -0,0 +1,35 @@ +// This file is an exact copy from the Acala project (https://github.com/AcalaNetwork/Acala/), +// which is licensed under the GNU General Public License. +// +// For more info of its license, please check the Acala project + +//! # Evm utiltity Module +//! +//! A pallet provides some utility methods. + +#![cfg_attr(not(feature = "std"), no_std)] + +use sha3::{Digest, Keccak256}; + +pub use ethereum; +pub use evm::{self, backend::Basic as Account}; +pub use evm_gasometer; +pub use evm_runtime; + +pub fn sha3_256(s: &str) -> [u8; 32] { + let mut result = [0u8; 32]; + + // create a SHA3-256 object + let mut hasher = Keccak256::new(); + // write input message + hasher.update(s); + // read hash digest + result.copy_from_slice(&hasher.finalize()[..32]); + + result +} + +pub fn get_function_selector(s: &str) -> u32 { + let result = sha3_256(s); + u32::from_be_bytes(result[..4].try_into().unwrap()) +} From 0308b3176844e84d0ca2caf496039839be6f6172 Mon Sep 17 00:00:00 2001 From: Martin Date: Wed, 15 Nov 2023 10:31:43 +0100 Subject: [PATCH 08/16] bump runtime version --- Cargo.lock | 2 +- runtime/hydradx/Cargo.toml | 2 +- runtime/hydradx/src/lib.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3103fbac0..5bdc59ef1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4220,7 +4220,7 @@ dependencies = [ [[package]] name = "hydradx-runtime" -version = "188.0.0" +version = "189.0.0" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", diff --git a/runtime/hydradx/Cargo.toml b/runtime/hydradx/Cargo.toml index 4dfd4c5dd..9d010b1b8 100644 --- a/runtime/hydradx/Cargo.toml +++ b/runtime/hydradx/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hydradx-runtime" -version = "188.0.0" +version = "189.0.0" authors = ["GalacticCouncil"] edition = "2021" license = "Apache 2.0" diff --git a/runtime/hydradx/src/lib.rs b/runtime/hydradx/src/lib.rs index f2eaf84bc..c2e7fabd6 100644 --- a/runtime/hydradx/src/lib.rs +++ b/runtime/hydradx/src/lib.rs @@ -99,7 +99,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("hydradx"), impl_name: create_runtime_str!("hydradx"), authoring_version: 1, - spec_version: 188, + spec_version: 189, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 1, From b4a8da8962acaceac95a60f28a7bf8937bfa92a5 Mon Sep 17 00:00:00 2001 From: Martin Hloska Date: Wed, 15 Nov 2023 14:04:31 +0100 Subject: [PATCH 09/16] update omnipool weights --- runtime/hydradx/src/weights/omnipool.rs | 94 +++++++++++-------------- 1 file changed, 43 insertions(+), 51 deletions(-) diff --git a/runtime/hydradx/src/weights/omnipool.rs b/runtime/hydradx/src/weights/omnipool.rs index aa3bdd4f6..c70eff905 100644 --- a/runtime/hydradx/src/weights/omnipool.rs +++ b/runtime/hydradx/src/weights/omnipool.rs @@ -18,7 +18,7 @@ //! Autogenerated weights for pallet_omnipool //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-10-24, STEPS: 5, REPEAT: 20, LOW RANGE: [], HIGH RANGE: [] +//! DATE: 2023-11-15, STEPS: 5, REPEAT: 20, LOW RANGE: [], HIGH RANGE: [] //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 // Executed Command: @@ -54,18 +54,18 @@ use pallet_omnipool::weights::WeightInfo; pub struct HydraWeight(PhantomData); impl WeightInfo for HydraWeight { - // Storage: Omnipool Assets (r:2 w:1) + // Storage: Omnipool Assets (r:1 w:1) // Proof: Omnipool Assets (max_values: None, max_size: Some(85), added: 2560, mode: MaxEncodedLen) // Storage: AssetRegistry Assets (r:2 w:0) // Proof: AssetRegistry Assets (max_values: None, max_size: Some(87), added: 2562, mode: MaxEncodedLen) - // Storage: Tokens Accounts (r:3 w:1) + // Storage: Uniques Class (r:1 w:1) + // Proof: Uniques Class (max_values: None, max_size: Some(190), added: 2665, mode: MaxEncodedLen) + // Storage: Tokens Accounts (r:2 w:1) // 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) @@ -74,21 +74,19 @@ 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) - // 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 { - // Minimum execution time: 150_622 nanoseconds. - Weight::from_ref_time(151_024_000 as u64) - .saturating_add(T::DbWeight::get().reads(15 as u64)) + // Minimum execution time: 147_434 nanoseconds. + Weight::from_ref_time(148_837_000 as u64) + .saturating_add(T::DbWeight::get().reads(12 as u64)) .saturating_add(T::DbWeight::get().writes(10 as u64)) } - // Storage: Tokens Accounts (r:4 w:3) + // Storage: Tokens Accounts (r:3 w:3) // Proof: Tokens Accounts (max_values: None, max_size: Some(108), added: 2583, mode: MaxEncodedLen) - // Storage: Omnipool Assets (r:2 w:1) + // Storage: Omnipool Assets (r:1 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) @@ -108,8 +106,6 @@ impl WeightInfo for HydraWeight { // 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) @@ -125,9 +121,9 @@ 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: 228_878 nanoseconds. - Weight::from_ref_time(235_865_000 as u64) - .saturating_add(T::DbWeight::get().reads(23 as u64)) + // Minimum execution time: 224_128 nanoseconds. + Weight::from_ref_time(226_321_000 as u64) + .saturating_add(T::DbWeight::get().reads(20 as u64)) .saturating_add(T::DbWeight::get().writes(14 as u64)) } // Storage: Uniques Asset (r:1 w:1) @@ -169,8 +165,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: 287_519 nanoseconds. - Weight::from_ref_time(288_641_000 as u64) + // Minimum execution time: 298_601 nanoseconds. + Weight::from_ref_time(300_078_000 as u64) .saturating_add(T::DbWeight::get().reads(23 as u64)) .saturating_add(T::DbWeight::get().writes(16 as u64)) } @@ -182,8 +178,6 @@ impl WeightInfo for HydraWeight { // 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) @@ -205,9 +199,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: 252_767 nanoseconds. - Weight::from_ref_time(254_421_000 as u64) - .saturating_add(T::DbWeight::get().reads(23 as u64)) + // Minimum execution time: 252_248 nanoseconds. + Weight::from_ref_time(255_333_000 as u64) + .saturating_add(T::DbWeight::get().reads(22 as u64)) .saturating_add(T::DbWeight::get().writes(14 as u64)) } // Storage: Omnipool Assets (r:3 w:3) @@ -241,16 +235,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: 272_781 nanoseconds. - Weight::from_ref_time(274_844_000 as u64) + // Minimum execution time: 285_129 nanoseconds. + Weight::from_ref_time(291_349_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_941 nanoseconds. - Weight::from_ref_time(34_430_000 as u64) + // Minimum execution time: 36_408 nanoseconds. + Weight::from_ref_time(36_896_000 as u64) .saturating_add(T::DbWeight::get().reads(1 as u64)) .saturating_add(T::DbWeight::get().writes(1 as u64)) } @@ -267,8 +261,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: 106_574 nanoseconds. - Weight::from_ref_time(107_433_000 as u64) + // Minimum execution time: 111_080 nanoseconds. + Weight::from_ref_time(114_389_000 as u64) .saturating_add(T::DbWeight::get().reads(8 as u64)) .saturating_add(T::DbWeight::get().writes(5 as u64)) } @@ -285,16 +279,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: 76_552 nanoseconds. - Weight::from_ref_time(77_448_000 as u64) + // Minimum execution time: 78_568 nanoseconds. + Weight::from_ref_time(79_330_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: 34_304 nanoseconds. - Weight::from_ref_time(34_615_000 as u64) + // Minimum execution time: 35_559 nanoseconds. + Weight::from_ref_time(36_075_000 as u64) .saturating_add(T::DbWeight::get().reads(1 as u64)) .saturating_add(T::DbWeight::get().writes(1 as u64)) } @@ -317,8 +311,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_protocol_liquidity() -> Weight { - // Minimum execution time: 160_117 nanoseconds. - Weight::from_ref_time(161_104_000 as u64) + // Minimum execution time: 168_287 nanoseconds. + Weight::from_ref_time(171_781_000 as u64) .saturating_add(T::DbWeight::get().reads(13 as u64)) .saturating_add(T::DbWeight::get().writes(8 as u64)) } @@ -339,8 +333,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 remove_token() -> Weight { - // Minimum execution time: 158_937 nanoseconds. - Weight::from_ref_time(162_234_000 as u64) + // Minimum execution time: 162_935 nanoseconds. + Weight::from_ref_time(167_702_000 as u64) .saturating_add(T::DbWeight::get().reads(14 as u64)) .saturating_add(T::DbWeight::get().writes(8 as u64)) } @@ -352,8 +346,6 @@ impl WeightInfo for HydraWeight { // 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) @@ -377,12 +369,12 @@ impl WeightInfo for HydraWeight { /// 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: 53_821 nanoseconds. - Weight::from_ref_time(41_181_125 as u64) // Standard Error: 379_584 - .saturating_add(Weight::from_ref_time(13_415_900 as u64).saturating_mul(c as u64)) - // Standard Error: 379_584 - .saturating_add(Weight::from_ref_time(214_332_825 as u64).saturating_mul(e as u64)) - .saturating_add(T::DbWeight::get().reads(7 as u64)) + // Minimum execution time: 47_302 nanoseconds. + Weight::from_ref_time(38_172_125 as u64) // Standard Error: 136_198 + .saturating_add(Weight::from_ref_time(10_307_875 as u64).saturating_mul(c as u64)) + // Standard Error: 136_198 + .saturating_add(Weight::from_ref_time(216_455_950 as u64).saturating_mul(e as u64)) + .saturating_add(T::DbWeight::get().reads(6 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))) } @@ -419,11 +411,11 @@ impl WeightInfo for HydraWeight { /// 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: 271_496 nanoseconds. - Weight::from_ref_time(266_903_925 as u64) // Standard Error: 491_298 - .saturating_add(Weight::from_ref_time(9_205_000 as u64).saturating_mul(c as u64)) - // Standard Error: 491_298 - .saturating_add(Weight::from_ref_time(862_825 as u64).saturating_mul(e as u64)) + // Minimum execution time: 281_574 nanoseconds. + Weight::from_ref_time(269_724_625 as u64) // Standard Error: 346_676 + .saturating_add(Weight::from_ref_time(13_487_775 as u64).saturating_mul(c as u64)) + // Standard Error: 346_676 + .saturating_add(Weight::from_ref_time(558_675 as u64).saturating_mul(e as u64)) .saturating_add(T::DbWeight::get().reads(24 as u64)) .saturating_add(T::DbWeight::get().writes(15 as u64)) } From 795d76ef8b7c890700a92da11a3369054886d3e7 Mon Sep 17 00:00:00 2001 From: dmoka Date: Wed, 15 Nov 2023 14:45:07 +0100 Subject: [PATCH 10/16] include the route in weight calculation when default route is used --- Cargo.lock | 4 ++-- integration-tests/Cargo.toml | 2 +- integration-tests/src/dca.rs | 38 ++++++++++++++++++++++++++++++++++++ pallets/dca/Cargo.toml | 2 +- pallets/dca/src/lib.rs | 5 +++-- 5 files changed, 45 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d816c3dda..fe4b3db73 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7050,7 +7050,7 @@ dependencies = [ [[package]] name = "pallet-dca" -version = "1.2.2" +version = "1.2.3" dependencies = [ "cumulus-pallet-parachain-system", "cumulus-primitives-core", @@ -10767,7 +10767,7 @@ dependencies = [ [[package]] name = "runtime-integration-tests" -version = "1.16.0" +version = "1.16.1" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index dff10c86f..6f428a92a 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "runtime-integration-tests" -version = "1.16.0" +version = "1.16.1" description = "Integration tests" authors = ["GalacticCouncil"] edition = "2021" diff --git a/integration-tests/src/dca.rs b/integration-tests/src/dca.rs index 7f91c51b9..efe6c27cd 100644 --- a/integration-tests/src/dca.rs +++ b/integration-tests/src/dca.rs @@ -2110,6 +2110,44 @@ mod stableswap { assert_balance!(ALICE.into(), HDX, ALICE_INITIAL_NATIVE_BALANCE + amount_to_buy); }); } + + #[test] + fn fee_should_be_calculated_properly_when_used_default_route() { + TestNet::reset(); + Hydra::execute_with(|| { + //Arrange + init_omnipool_with_oracle_for_block_10(); + + let dca_budget = 1000 * UNITS; + let amount_out = 100 * UNITS; + + let schedule1 = Schedule { + owner: AccountId::from(ALICE), + period: 2u32, + total_amount: dca_budget, + max_retries: None, + stability_threshold: None, + slippage: Some(Permill::from_percent(5)), + order: Order::Buy { + asset_in: HDX, + asset_out: DAI, + amount_out, + max_amount_in: Balance::MAX, + route: create_bounded_vec(vec![]), + }, + }; + create_schedule(ALICE, schedule1); + + //Act + set_relaychain_block_number(11); + + //Assert + let fee = Currencies::free_balance(HDX, &Treasury::account_id()) - TREASURY_ACCOUNT_INIT_BALANCE; + //The fee should be more than 3 UNITS, around 3_795_361_512_418. + assert!(fee > 3 * UNITS); + assert!(fee < 4 * UNITS); + }); + } } fn create_schedule(owner: [u8; 32], schedule1: Schedule) { diff --git a/pallets/dca/Cargo.toml b/pallets/dca/Cargo.toml index 7e50d9283..5a68f8a88 100644 --- a/pallets/dca/Cargo.toml +++ b/pallets/dca/Cargo.toml @@ -1,6 +1,6 @@ [package] name = 'pallet-dca' -version = "1.2.2" +version = "1.2.3" description = 'A pallet to manage DCA scheduling' authors = ['GalacticCouncil'] edition = '2021' diff --git a/pallets/dca/src/lib.rs b/pallets/dca/src/lib.rs index 7eb1096d2..aadca14c6 100644 --- a/pallets/dca/src/lib.rs +++ b/pallets/dca/src/lib.rs @@ -1025,10 +1025,11 @@ impl Pallet { // returns DCA overhead weight + router execution weight fn get_trade_weight(order: &Order) -> Weight { + let route = &order.get_route_or_default::(); match order { - Order::Sell { route, .. } => ::WeightInfo::on_initialize_with_sell_trade() + Order::Sell { .. } => ::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() + Order::Buy { .. } => ::WeightInfo::on_initialize_with_buy_trade() .saturating_add(T::AmmTradeWeights::buy_and_calculate_buy_trade_amounts_weight(route)), } } From 9b0a33329042f7bf6f2f35b941b826ea460eda0f Mon Sep 17 00:00:00 2001 From: dmoka Date: Wed, 15 Nov 2023 15:08:31 +0100 Subject: [PATCH 11/16] adjust integration tests --- integration-tests/src/dca.rs | 79 +++++++++++------------------------- 1 file changed, 24 insertions(+), 55 deletions(-) diff --git a/integration-tests/src/dca.rs b/integration-tests/src/dca.rs index efe6c27cd..fcd9489a3 100644 --- a/integration-tests/src/dca.rs +++ b/integration-tests/src/dca.rs @@ -134,6 +134,11 @@ mod omnipool { let treasury_balance = Currencies::free_balance(HDX, &Treasury::account_id()); assert!(treasury_balance > TREASURY_ACCOUNT_INIT_BALANCE); + + //We make sure is that the default route is incorporated in the fee calculation + let fee = Currencies::free_balance(HDX, &Treasury::account_id()) - TREASURY_ACCOUNT_INIT_BALANCE; + assert!(fee > 3 * UNITS); + assert!(fee < 4 * UNITS); }); } @@ -490,6 +495,9 @@ mod omnipool { //Assert that fee is sent to treasury let treasury_balance = Currencies::free_balance(HDX, &Treasury::account_id()); assert!(treasury_balance > TREASURY_ACCOUNT_INIT_BALANCE); + + assert!(fee > 3 * UNITS); + assert!(fee < 4 * UNITS); }); } @@ -532,41 +540,40 @@ mod omnipool { } #[test] - fn sell_schedule_should_work_without_route() { + fn sell_schedule_execution_should_work_without_route() { TestNet::reset(); Hydra::execute_with(|| { //Arrange init_omnipool_with_oracle_for_block_10(); - let alice_init_hdx_balance = 5000 * UNITS; - assert_ok!(Balances::set_balance( - RuntimeOrigin::root(), - ALICE.into(), - alice_init_hdx_balance, - 0, - )); let dca_budget = 1000 * UNITS; - let amount_to_sell = 700 * UNITS; + + assert_balance!(ALICE.into(), HDX, ALICE_INITIAL_NATIVE_BALANCE); + + let amount_in = 100 * UNITS; let no_route = vec![]; let schedule1 = - schedule_fake_with_sell_order_with_route(ALICE, dca_budget, HDX, DAI, amount_to_sell, no_route); + schedule_fake_with_sell_order_with_route(ALICE.into(), dca_budget, HDX, DAI, amount_in, no_route); create_schedule(ALICE, schedule1); - assert_balance!(ALICE.into(), HDX, alice_init_hdx_balance - dca_budget); + 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!(&Treasury::account_id(), HDX, TREASURY_ACCOUNT_INIT_BALANCE); //Act - run_to_block(11, 15); + set_relaychain_block_number(11); //Assert - assert_balance!(ALICE.into(), HDX, alice_init_hdx_balance - dca_budget); - assert_reserved_balance!(&ALICE.into(), HDX, 0); + let fee = Currencies::free_balance(HDX, &Treasury::account_id()) - TREASURY_ACCOUNT_INIT_BALANCE; - let schedule_id = 0; - let schedule = DCA::schedules(schedule_id); - assert!(schedule.is_none()); + assert_balance!(ALICE.into(), HDX, ALICE_INITIAL_NATIVE_BALANCE - dca_budget); + assert_balance!(ALICE.into(), DAI, ALICE_INITIAL_DAI_BALANCE + 71214372591631); + assert_reserved_balance!(&ALICE.into(), HDX, dca_budget - amount_in - fee); + + //We make sure is that the default route is incorporated in the fee calculation + assert!(fee > 3 * UNITS); + assert!(fee < 4 * UNITS); }); } @@ -2110,44 +2117,6 @@ mod stableswap { assert_balance!(ALICE.into(), HDX, ALICE_INITIAL_NATIVE_BALANCE + amount_to_buy); }); } - - #[test] - fn fee_should_be_calculated_properly_when_used_default_route() { - TestNet::reset(); - Hydra::execute_with(|| { - //Arrange - init_omnipool_with_oracle_for_block_10(); - - let dca_budget = 1000 * UNITS; - let amount_out = 100 * UNITS; - - let schedule1 = Schedule { - owner: AccountId::from(ALICE), - period: 2u32, - total_amount: dca_budget, - max_retries: None, - stability_threshold: None, - slippage: Some(Permill::from_percent(5)), - order: Order::Buy { - asset_in: HDX, - asset_out: DAI, - amount_out, - max_amount_in: Balance::MAX, - route: create_bounded_vec(vec![]), - }, - }; - create_schedule(ALICE, schedule1); - - //Act - set_relaychain_block_number(11); - - //Assert - let fee = Currencies::free_balance(HDX, &Treasury::account_id()) - TREASURY_ACCOUNT_INIT_BALANCE; - //The fee should be more than 3 UNITS, around 3_795_361_512_418. - assert!(fee > 3 * UNITS); - assert!(fee < 4 * UNITS); - }); - } } fn create_schedule(owner: [u8; 32], schedule1: Schedule) { From 79df5e707e95d25f3ae2ed1098af598ef3c0e008 Mon Sep 17 00:00:00 2001 From: dmoka Date: Wed, 15 Nov 2023 15:22:24 +0100 Subject: [PATCH 12/16] bump runtime version --- Cargo.lock | 2 +- runtime/hydradx/Cargo.toml | 2 +- runtime/hydradx/src/lib.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fe4b3db73..987716a4f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4220,7 +4220,7 @@ dependencies = [ [[package]] name = "hydradx-runtime" -version = "188.0.0" +version = "189.0.0" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", diff --git a/runtime/hydradx/Cargo.toml b/runtime/hydradx/Cargo.toml index 4dfd4c5dd..9d010b1b8 100644 --- a/runtime/hydradx/Cargo.toml +++ b/runtime/hydradx/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hydradx-runtime" -version = "188.0.0" +version = "189.0.0" authors = ["GalacticCouncil"] edition = "2021" license = "Apache 2.0" diff --git a/runtime/hydradx/src/lib.rs b/runtime/hydradx/src/lib.rs index f2eaf84bc..c2e7fabd6 100644 --- a/runtime/hydradx/src/lib.rs +++ b/runtime/hydradx/src/lib.rs @@ -99,7 +99,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("hydradx"), impl_name: create_runtime_str!("hydradx"), authoring_version: 1, - spec_version: 188, + spec_version: 189, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 1, From 8ccd05305a7930e5ae25f081ec713a0dc9b2b621 Mon Sep 17 00:00:00 2001 From: dmoka Date: Wed, 15 Nov 2023 16:36:31 +0100 Subject: [PATCH 13/16] encapsulate fee assertion --- integration-tests/src/dca.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/integration-tests/src/dca.rs b/integration-tests/src/dca.rs index fcd9489a3..a3df36db4 100644 --- a/integration-tests/src/dca.rs +++ b/integration-tests/src/dca.rs @@ -97,6 +97,8 @@ mod omnipool { let treasury_balance = Currencies::free_balance(HDX, &Treasury::account_id()); assert!(treasury_balance > TREASURY_ACCOUNT_INIT_BALANCE); + + assert_that_fee_is_correct(fee); }); } @@ -137,8 +139,7 @@ mod omnipool { //We make sure is that the default route is incorporated in the fee calculation let fee = Currencies::free_balance(HDX, &Treasury::account_id()) - TREASURY_ACCOUNT_INIT_BALANCE; - assert!(fee > 3 * UNITS); - assert!(fee < 4 * UNITS); + assert_that_fee_is_correct(fee); }); } @@ -496,8 +497,7 @@ mod omnipool { let treasury_balance = Currencies::free_balance(HDX, &Treasury::account_id()); assert!(treasury_balance > TREASURY_ACCOUNT_INIT_BALANCE); - assert!(fee > 3 * UNITS); - assert!(fee < 4 * UNITS); + assert_that_fee_is_correct(fee); }); } @@ -572,8 +572,7 @@ mod omnipool { assert_reserved_balance!(&ALICE.into(), HDX, dca_budget - amount_in - fee); //We make sure is that the default route is incorporated in the fee calculation - assert!(fee > 3 * UNITS); - assert!(fee < 4 * UNITS); + assert_that_fee_is_correct(fee); }); } @@ -2454,3 +2453,9 @@ pub fn init_stableswap_with_three_assets_having_different_decimals( Ok((pool_id, asset_in, asset_out)) } + +fn assert_that_fee_is_correct(fee: Balance) { + //The fee is approximately 3795361512418, so we check if we are between 3.5 and 4 UNITS + assert!(fee > 35 / 10 * UNITS); + assert!(fee < 4 * UNITS); +} From 097f65e1c5b793f96cf973f7c521d4fe31b269a4 Mon Sep 17 00:00:00 2001 From: Martin Date: Thu, 16 Nov 2023 09:44:56 +0100 Subject: [PATCH 14/16] adjust stableswap invariant test --- Cargo.lock | 2 +- math/Cargo.toml | 2 +- math/src/stableswap/tests/invariants.rs | 9 +++++---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5bdc59ef1..a68c3a3fa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4069,7 +4069,7 @@ dependencies = [ [[package]] name = "hydra-dx-math" -version = "7.6.2" +version = "7.6.3" dependencies = [ "approx", "criterion", diff --git a/math/Cargo.toml b/math/Cargo.toml index 2604df0de..ff33e7eb3 100644 --- a/math/Cargo.toml +++ b/math/Cargo.toml @@ -6,7 +6,7 @@ license = 'Apache-2.0' name = "hydra-dx-math" description = "A collection of utilities to make performing liquidity pool calculations more convenient." repository = 'https://github.com/galacticcouncil/hydradx-math' -version = "7.6.2" +version = "7.6.3" [dependencies] primitive-types = {default-features = false, version = '0.12.0'} diff --git a/math/src/stableswap/tests/invariants.rs b/math/src/stableswap/tests/invariants.rs index 05c699e31..aa1ff6b88 100644 --- a/math/src/stableswap/tests/invariants.rs +++ b/math/src/stableswap/tests/invariants.rs @@ -407,10 +407,11 @@ proptest! { let result = calculate_shares_for_amount::(&pool, 0, amount, amp, issuance, Permill::zero()).unwrap(); let received = - calculate_withdraw_one_asset::(&pool, result + 3_000 , 0, issuance, amp, Permill::zero()) + calculate_withdraw_one_asset::(&pool, result, 0, issuance, amp, Permill::zero()) .unwrap(); - assert!(received.0 >= amount); - let diff = received.0 - amount; - assert!(diff <= 5000) + // LP should not receive more than provided. + assert!(received.0 <= amount); + let diff = amount - received.0; + assert!(diff <= 1000) } } From 330558d0d200f28f2069a0a735086c03b4f7f323 Mon Sep 17 00:00:00 2001 From: dmoka Date: Fri, 17 Nov 2023 10:38:57 +0100 Subject: [PATCH 15/16] adjust evm module dependencies to keep it consistent --- Cargo.lock | 335 +++++++++--------- .../hydradx/src/evm/evm-utility/Cargo.toml | 4 +- 2 files changed, 168 insertions(+), 171 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 52bcad71c..df497485c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1770,7 +1770,7 @@ dependencies = [ "sp-application-crypto", "sp-consensus-aura", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -1786,7 +1786,7 @@ dependencies = [ "scale-info", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", "xcm", ] @@ -1813,7 +1813,7 @@ dependencies = [ "sp-io", "sp-runtime", "sp-state-machine", - "sp-std 5.0.0", + "sp-std", "sp-trie", "sp-version", "xcm", @@ -1842,7 +1842,7 @@ dependencies = [ "scale-info", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", "xcm", ] @@ -1863,7 +1863,7 @@ dependencies = [ "sp-core", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", "xcm", "xcm-executor", ] @@ -1879,7 +1879,7 @@ dependencies = [ "polkadot-primitives", "sp-api", "sp-runtime", - "sp-std 5.0.0", + "sp-std", "sp-trie", "xcm", ] @@ -1901,7 +1901,7 @@ dependencies = [ "sp-inherents", "sp-runtime", "sp-state-machine", - "sp-std 5.0.0", + "sp-std", "sp-storage", "sp-trie", "tracing", @@ -1916,7 +1916,7 @@ dependencies = [ "futures", "parity-scale-codec", "sp-inherents", - "sp-std 5.0.0", + "sp-std", "sp-timestamp", ] @@ -1932,7 +1932,7 @@ dependencies = [ "polkadot-runtime-common", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", "xcm", "xcm-builder", "xcm-executor", @@ -2061,7 +2061,7 @@ dependencies = [ "polkadot-primitives", "sp-runtime", "sp-state-machine", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -3183,7 +3183,7 @@ dependencies = [ "parity-scale-codec", "sp-core", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -3197,7 +3197,7 @@ dependencies = [ "frame-support", "num_enum", "parity-scale-codec", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -3211,7 +3211,7 @@ dependencies = [ "serde", "sp-core", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -3228,7 +3228,7 @@ dependencies = [ "sp-core", "sp-runtime", "sp-state-machine", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -3278,7 +3278,7 @@ dependencies = [ "sp-io", "sp-runtime", "sp-runtime-interface", - "sp-std 5.0.0", + "sp-std", "sp-storage", "static_assertions", ] @@ -3323,7 +3323,7 @@ dependencies = [ "sp-keystore", "sp-runtime", "sp-state-machine", - "sp-std 5.0.0", + "sp-std", "sp-storage", "sp-trie", "thiserror", @@ -3355,7 +3355,7 @@ dependencies = [ "sp-core", "sp-npos-elections", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -3371,7 +3371,7 @@ dependencies = [ "sp-core", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", "sp-tracing", ] @@ -3429,7 +3429,7 @@ dependencies = [ "sp-runtime", "sp-staking", "sp-state-machine", - "sp-std 5.0.0", + "sp-std", "sp-tracing", "sp-weights", "tt-call", @@ -3485,7 +3485,7 @@ dependencies = [ "sp-core", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", "sp-version", "sp-weights", ] @@ -3502,7 +3502,7 @@ dependencies = [ "scale-info", "sp-core", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -3523,7 +3523,7 @@ dependencies = [ "parity-scale-codec", "sp-api", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -4084,7 +4084,7 @@ dependencies = [ "scale-info", "serde", "sp-arithmetic", - "sp-std 5.0.0", + "sp-std", "test-case 2.2.2", ] @@ -4212,7 +4212,7 @@ dependencies = [ "sp-core", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", "xcm", "xcm-builder", "xcm-executor", @@ -4322,7 +4322,7 @@ dependencies = [ "sp-offchain", "sp-runtime", "sp-session", - "sp-std 5.0.0", + "sp-std", "sp-transaction-pool", "sp-trie", "sp-version", @@ -4343,7 +4343,7 @@ dependencies = [ "scale-info", "serde", "sp-arithmetic", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -5000,7 +5000,7 @@ dependencies = [ "sp-runtime", "sp-session", "sp-staking", - "sp-std 5.0.0", + "sp-std", "sp-transaction-pool", "sp-version", "static_assertions", @@ -5981,7 +5981,7 @@ dependencies = [ "evm-gasometer 0.36.0", "evm-runtime 0.36.0", "sha3", - "sp-std 8.0.0", + "sp-std", ] [[package]] @@ -6481,7 +6481,7 @@ dependencies = [ "sp-io", "sp-runtime", "sp-runtime-interface", - "sp-std 5.0.0", + "sp-std", "sp-storage", ] @@ -6498,7 +6498,7 @@ dependencies = [ "scale-info", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -6513,7 +6513,7 @@ dependencies = [ "scale-info", "serde", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -6531,7 +6531,7 @@ dependencies = [ "sp-core", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", "xcm", ] @@ -6546,7 +6546,7 @@ dependencies = [ "parity-scale-codec", "scale-info", "serde", - "sp-std 5.0.0", + "sp-std", "xcm", ] @@ -6561,7 +6561,7 @@ dependencies = [ "serde", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -6576,7 +6576,7 @@ dependencies = [ "serde", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -6589,7 +6589,7 @@ dependencies = [ "pallet-xcm", "parity-scale-codec", "scale-info", - "sp-std 5.0.0", + "sp-std", "xcm", ] @@ -6602,7 +6602,7 @@ dependencies = [ "orml-traits", "parity-scale-codec", "sp-runtime", - "sp-std 5.0.0", + "sp-std", "xcm", "xcm-executor", ] @@ -6623,7 +6623,7 @@ dependencies = [ "serde", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", "xcm", "xcm-executor", ] @@ -6685,7 +6685,7 @@ dependencies = [ "sp-core", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", "substrate-wasm-builder", "test-utils", "xcm", @@ -6704,7 +6704,7 @@ dependencies = [ "sp-application-crypto", "sp-consensus-aura", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -6720,7 +6720,7 @@ dependencies = [ "sp-application-crypto", "sp-authority-discovery", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -6734,7 +6734,7 @@ dependencies = [ "parity-scale-codec", "scale-info", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -6758,7 +6758,7 @@ dependencies = [ "sp-runtime", "sp-session", "sp-staking", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -6777,7 +6777,7 @@ dependencies = [ "sp-core", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", "sp-tracing", ] @@ -6793,7 +6793,7 @@ dependencies = [ "parity-scale-codec", "scale-info", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -6809,7 +6809,7 @@ dependencies = [ "serde", "sp-beefy", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -6832,7 +6832,7 @@ dependencies = [ "sp-core", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -6856,7 +6856,7 @@ dependencies = [ "sp-core", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", "sp-tracing", ] @@ -6875,7 +6875,7 @@ dependencies = [ "sp-core", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -6894,7 +6894,7 @@ dependencies = [ "sp-core", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -6917,7 +6917,7 @@ dependencies = [ "sp-core", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", "test-case 3.1.0", "test-utils", ] @@ -6944,7 +6944,7 @@ dependencies = [ "sp-core", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -6970,7 +6970,7 @@ dependencies = [ "sp-io", "sp-runtime", "sp-staking", - "sp-std 5.0.0", + "sp-std", "substrate-wasm-builder", ] @@ -6990,7 +6990,7 @@ dependencies = [ "scale-info", "sp-runtime", "sp-staking", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -7007,7 +7007,7 @@ dependencies = [ "sp-core", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -7024,7 +7024,7 @@ dependencies = [ "serde", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -7043,7 +7043,7 @@ dependencies = [ "sp-core", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -7081,7 +7081,7 @@ dependencies = [ "sp-core", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", "sp-tracing", "test-case 2.2.2", "test-utils", @@ -7102,7 +7102,7 @@ dependencies = [ "sp-core", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -7122,7 +7122,7 @@ dependencies = [ "sp-core", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -7145,7 +7145,7 @@ dependencies = [ "sp-core", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", "substrate-wasm-builder", ] @@ -7168,7 +7168,7 @@ dependencies = [ "sp-core", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -7190,7 +7190,7 @@ dependencies = [ "sp-io", "sp-npos-elections", "sp-runtime", - "sp-std 5.0.0", + "sp-std", "strum", ] @@ -7222,7 +7222,7 @@ dependencies = [ "sp-io", "sp-npos-elections", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -7245,7 +7245,7 @@ dependencies = [ "sp-arithmetic", "sp-core", "sp-io", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -7272,7 +7272,7 @@ dependencies = [ "scale-info", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -7296,7 +7296,7 @@ dependencies = [ "sp-core", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -7335,7 +7335,7 @@ dependencies = [ "sp-io", "sp-runtime", "sp-staking", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -7352,7 +7352,7 @@ dependencies = [ "sp-core", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -7375,7 +7375,7 @@ dependencies = [ "sp-runtime", "sp-session", "sp-staking", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -7391,7 +7391,7 @@ dependencies = [ "scale-info", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -7411,7 +7411,7 @@ dependencies = [ "sp-io", "sp-runtime", "sp-staking", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -7428,7 +7428,7 @@ dependencies = [ "sp-io", "sp-keyring", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -7452,7 +7452,7 @@ dependencies = [ "sp-core", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", "substrate-wasm-builder", "test-utils", ] @@ -7479,7 +7479,7 @@ dependencies = [ "sp-core", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", "test-utils", ] @@ -7497,7 +7497,7 @@ dependencies = [ "sp-core", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -7514,7 +7514,7 @@ dependencies = [ "sp-io", "sp-mmr-primitives", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -7530,7 +7530,7 @@ dependencies = [ "scale-info", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -7546,7 +7546,7 @@ dependencies = [ "sp-arithmetic", "sp-core", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -7563,7 +7563,7 @@ dependencies = [ "sp-io", "sp-runtime", "sp-staking", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -7583,7 +7583,7 @@ dependencies = [ "sp-runtime", "sp-runtime-interface", "sp-staking", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -7593,7 +7593,7 @@ source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.38#bc dependencies = [ "parity-scale-codec", "sp-api", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -7610,7 +7610,7 @@ dependencies = [ "serde", "sp-runtime", "sp-staking", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -7634,7 +7634,7 @@ dependencies = [ "scale-info", "sp-runtime", "sp-staking", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -7660,7 +7660,7 @@ dependencies = [ "sp-core", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", "sp-tracing", ] @@ -7689,7 +7689,7 @@ dependencies = [ "sp-core", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", "test-utils", ] @@ -7711,7 +7711,7 @@ dependencies = [ "sp-core", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", "test-utils", ] @@ -7729,7 +7729,7 @@ dependencies = [ "sp-core", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -7744,7 +7744,7 @@ dependencies = [ "scale-info", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -7762,7 +7762,7 @@ dependencies = [ "sp-core", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -7777,7 +7777,7 @@ dependencies = [ "scale-info", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -7796,7 +7796,7 @@ dependencies = [ "sp-arithmetic", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -7810,7 +7810,7 @@ dependencies = [ "parity-scale-codec", "scale-info", "sp-api", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -7834,7 +7834,7 @@ dependencies = [ "sp-core", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", "test-utils", ] @@ -7851,7 +7851,7 @@ dependencies = [ "scale-info", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", "sp-weights", ] @@ -7872,7 +7872,7 @@ dependencies = [ "sp-runtime", "sp-session", "sp-staking", - "sp-std 5.0.0", + "sp-std", "sp-trie", ] @@ -7889,7 +7889,7 @@ dependencies = [ "rand 0.8.5", "sp-runtime", "sp-session", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -7903,7 +7903,7 @@ dependencies = [ "rand_chacha 0.2.2", "scale-info", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -7926,7 +7926,7 @@ dependencies = [ "sp-core", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", "sp-tracing", ] @@ -7951,7 +7951,7 @@ dependencies = [ "sp-core", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -7974,7 +7974,7 @@ dependencies = [ "sp-io", "sp-runtime", "sp-staking", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -8011,7 +8011,7 @@ dependencies = [ "sp-core", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -8025,7 +8025,7 @@ dependencies = [ "scale-info", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -8042,7 +8042,7 @@ dependencies = [ "sp-inherents", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", "sp-timestamp", ] @@ -8062,7 +8062,7 @@ dependencies = [ "sp-core", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -8085,7 +8085,7 @@ dependencies = [ "sp-core", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", "test-utils", ] @@ -8107,7 +8107,7 @@ dependencies = [ "sp-core", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -8123,7 +8123,7 @@ dependencies = [ "sp-core", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -8168,7 +8168,7 @@ dependencies = [ "scale-info", "serde", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -8183,7 +8183,7 @@ dependencies = [ "parity-scale-codec", "scale-info", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -8199,7 +8199,7 @@ dependencies = [ "sp-core", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -8214,7 +8214,7 @@ dependencies = [ "parity-scale-codec", "scale-info", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -8229,7 +8229,7 @@ dependencies = [ "scale-info", "sp-api", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -8247,7 +8247,7 @@ dependencies = [ "sp-core", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", "xcm", "xcm-executor", ] @@ -8265,7 +8265,7 @@ dependencies = [ "scale-info", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", "xcm", "xcm-builder", "xcm-executor", @@ -8294,7 +8294,7 @@ dependencies = [ "sp-core", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", "test-case 3.1.0", "test-utils", "xcm", @@ -8324,7 +8324,7 @@ dependencies = [ "sp-core", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", "substrate-wasm-builder", ] @@ -8845,7 +8845,7 @@ dependencies = [ "scale-info", "sp-core", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -9445,7 +9445,7 @@ dependencies = [ "serde", "sp-core", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -9486,7 +9486,7 @@ dependencies = [ "sp-keystore", "sp-runtime", "sp-staking", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -9600,7 +9600,7 @@ dependencies = [ "sp-runtime", "sp-session", "sp-staking", - "sp-std 5.0.0", + "sp-std", "sp-transaction-pool", "sp-version", "static_assertions", @@ -9654,7 +9654,7 @@ dependencies = [ "sp-runtime", "sp-session", "sp-staking", - "sp-std 5.0.0", + "sp-std", "static_assertions", "xcm", ] @@ -9681,7 +9681,7 @@ dependencies = [ "bs58", "parity-scale-codec", "polkadot-primitives", - "sp-std 5.0.0", + "sp-std", "sp-tracing", ] @@ -9722,7 +9722,7 @@ dependencies = [ "sp-runtime", "sp-session", "sp-staking", - "sp-std 5.0.0", + "sp-std", "static_assertions", "xcm", "xcm-executor", @@ -9999,7 +9999,7 @@ dependencies = [ "scale-info", "serde", "sp-core", - "sp-std 5.0.0", + "sp-std", "static_assertions", ] @@ -10665,7 +10665,7 @@ dependencies = [ "sp-runtime", "sp-session", "sp-staking", - "sp-std 5.0.0", + "sp-std", "sp-transaction-pool", "sp-version", "static_assertions", @@ -10853,7 +10853,7 @@ dependencies = [ "sp-runtime", "sp-session", "sp-staking", - "sp-std 5.0.0", + "sp-std", "sp-transaction-pool", "sp-trie", "sp-version", @@ -11967,7 +11967,7 @@ dependencies = [ "serde_json", "sp-core", "sp-io", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -12485,7 +12485,7 @@ dependencies = [ "parity-scale-codec", "paste", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -12575,7 +12575,7 @@ dependencies = [ "sp-core", "sp-runtime", "sp-state-machine", - "sp-std 5.0.0", + "sp-std", "sp-trie", "sp-version", "thiserror", @@ -12603,7 +12603,7 @@ dependencies = [ "serde", "sp-core", "sp-io", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -12616,7 +12616,7 @@ dependencies = [ "parity-scale-codec", "scale-info", "serde", - "sp-std 5.0.0", + "sp-std", "static_assertions", ] @@ -12630,7 +12630,7 @@ dependencies = [ "sp-api", "sp-application-crypto", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -12647,7 +12647,7 @@ dependencies = [ "sp-io", "sp-mmr-primitives", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -12659,7 +12659,7 @@ dependencies = [ "sp-api", "sp-inherents", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -12693,7 +12693,7 @@ dependencies = [ "sp-inherents", "sp-runtime", "sp-state-machine", - "sp-std 5.0.0", + "sp-std", "sp-version", "thiserror", ] @@ -12712,7 +12712,7 @@ dependencies = [ "sp-consensus-slots", "sp-inherents", "sp-runtime", - "sp-std 5.0.0", + "sp-std", "sp-timestamp", ] @@ -12735,7 +12735,7 @@ dependencies = [ "sp-inherents", "sp-keystore", "sp-runtime", - "sp-std 5.0.0", + "sp-std", "sp-timestamp", ] @@ -12747,7 +12747,7 @@ dependencies = [ "parity-scale-codec", "scale-info", "serde", - "sp-std 5.0.0", + "sp-std", "sp-timestamp", ] @@ -12761,7 +12761,7 @@ dependencies = [ "schnorrkel", "sp-core", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -12797,7 +12797,7 @@ dependencies = [ "sp-debug-derive", "sp-externalities", "sp-runtime-interface", - "sp-std 5.0.0", + "sp-std", "sp-storage", "ss58-registry", "substrate-bip39", @@ -12816,7 +12816,7 @@ dependencies = [ "digest 0.10.7", "sha2 0.10.7", "sha3", - "sp-std 5.0.0", + "sp-std", "twox-hash", ] @@ -12857,7 +12857,7 @@ source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.38#bc dependencies = [ "environmental", "parity-scale-codec", - "sp-std 5.0.0", + "sp-std", "sp-storage", ] @@ -12876,7 +12876,7 @@ dependencies = [ "sp-core", "sp-keystore", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -12889,7 +12889,7 @@ dependencies = [ "parity-scale-codec", "sp-core", "sp-runtime", - "sp-std 5.0.0", + "sp-std", "thiserror", ] @@ -12911,7 +12911,7 @@ dependencies = [ "sp-keystore", "sp-runtime-interface", "sp-state-machine", - "sp-std 5.0.0", + "sp-std", "sp-tracing", "sp-trie", "tracing", @@ -12969,7 +12969,7 @@ dependencies = [ "sp-core", "sp-debug-derive", "sp-runtime", - "sp-std 5.0.0", + "sp-std", "thiserror", ] @@ -12984,7 +12984,7 @@ dependencies = [ "sp-arithmetic", "sp-core", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -13035,7 +13035,7 @@ dependencies = [ "sp-arithmetic", "sp-core", "sp-io", - "sp-std 5.0.0", + "sp-std", "sp-weights", ] @@ -13050,7 +13050,7 @@ dependencies = [ "primitive-types", "sp-externalities", "sp-runtime-interface-proc-macro", - "sp-std 5.0.0", + "sp-std", "sp-storage", "sp-tracing", "sp-wasm-interface", @@ -13080,7 +13080,7 @@ dependencies = [ "sp-core", "sp-runtime", "sp-staking", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -13092,7 +13092,7 @@ dependencies = [ "scale-info", "sp-core", "sp-runtime", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -13109,7 +13109,7 @@ dependencies = [ "sp-core", "sp-externalities", "sp-panic-handler", - "sp-std 5.0.0", + "sp-std", "sp-trie", "thiserror", "tracing", @@ -13120,11 +13120,6 @@ name = "sp-std" version = "5.0.0" source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.38#bcff60a227d455d95b4712b6cb356ce56b1ff672" -[[package]] -name = "sp-std" -version = "8.0.0" -source = "git+https://github.com/paritytech/substrate?branch=polkadot-v1.0.0#948fbd2fd1233dc26dbb9f9bbc1d2cca2c03945d" - [[package]] name = "sp-storage" version = "7.0.0" @@ -13135,7 +13130,7 @@ dependencies = [ "ref-cast", "serde", "sp-debug-derive", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -13149,7 +13144,7 @@ dependencies = [ "parity-scale-codec", "sp-inherents", "sp-runtime", - "sp-std 5.0.0", + "sp-std", "thiserror", ] @@ -13159,7 +13154,7 @@ version = "6.0.0" source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.38#bcff60a227d455d95b4712b6cb356ce56b1ff672" dependencies = [ "parity-scale-codec", - "sp-std 5.0.0", + "sp-std", "tracing", "tracing-core", "tracing-subscriber", @@ -13186,7 +13181,7 @@ dependencies = [ "sp-core", "sp-inherents", "sp-runtime", - "sp-std 5.0.0", + "sp-std", "sp-trie", ] @@ -13206,7 +13201,7 @@ dependencies = [ "scale-info", "schnellru", "sp-core", - "sp-std 5.0.0", + "sp-std", "thiserror", "tracing", "trie-db", @@ -13225,7 +13220,7 @@ dependencies = [ "serde", "sp-core-hashing-proc-macro", "sp-runtime", - "sp-std 5.0.0", + "sp-std", "sp-version-proc-macro", "thiserror", ] @@ -13249,7 +13244,7 @@ dependencies = [ "impl-trait-for-tuples", "log", "parity-scale-codec", - "sp-std 5.0.0", + "sp-std", "wasmi", "wasmtime", ] @@ -13266,7 +13261,7 @@ dependencies = [ "sp-arithmetic", "sp-core", "sp-debug-derive", - "sp-std 5.0.0", + "sp-std", ] [[package]] @@ -15193,7 +15188,7 @@ dependencies = [ "sp-runtime", "sp-session", "sp-staking", - "sp-std 5.0.0", + "sp-std", "sp-transaction-pool", "sp-version", "substrate-wasm-builder", @@ -15602,7 +15597,7 @@ dependencies = [ "sp-arithmetic", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", "xcm", "xcm-executor", ] @@ -15628,7 +15623,7 @@ dependencies = [ "quote", "sp-arithmetic", "sp-io", - "sp-std 5.0.0", + "sp-std", "xcm", "xcm-executor", ] @@ -15648,7 +15643,7 @@ dependencies = [ "sp-core", "sp-io", "sp-runtime", - "sp-std 5.0.0", + "sp-std", "sp-weights", "xcm", ] diff --git a/runtime/hydradx/src/evm/evm-utility/Cargo.toml b/runtime/hydradx/src/evm/evm-utility/Cargo.toml index 6654fa288..f6182015f 100644 --- a/runtime/hydradx/src/evm/evm-utility/Cargo.toml +++ b/runtime/hydradx/src/evm/evm-utility/Cargo.toml @@ -7,8 +7,10 @@ edition = "2021" [dependencies] sha3 = { version = "0.10.6", default-features = false } -sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0", default-features = false } +#Substrate dependencies +sp-std = { workspace = true } +#Evm dependencies evm = { git = "https://github.com/rust-blockchain/evm", rev = "13240a8a551586fdef0b5028ed73af80b248092a", default-features = false, features = ["with-codec"] } evm-gasometer = { git = "https://github.com/rust-blockchain/evm", rev = "13240a8a551586fdef0b5028ed73af80b248092a", default-features = false } evm-runtime = { git = "https://github.com/rust-blockchain/evm", rev = "13240a8a551586fdef0b5028ed73af80b248092a", default-features = false } From 06af02a6d164733e411b6050c9253215810572d5 Mon Sep 17 00:00:00 2001 From: dmoka Date: Fri, 17 Nov 2023 10:40:43 +0100 Subject: [PATCH 16/16] bumped runtime version --- Cargo.lock | 2 +- runtime/hydradx/Cargo.toml | 2 +- runtime/hydradx/src/lib.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index df497485c..797017b51 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4220,7 +4220,7 @@ dependencies = [ [[package]] name = "hydradx-runtime" -version = "189.0.0" +version = "190.0.0" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", diff --git a/runtime/hydradx/Cargo.toml b/runtime/hydradx/Cargo.toml index 9d010b1b8..932dc66a0 100644 --- a/runtime/hydradx/Cargo.toml +++ b/runtime/hydradx/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hydradx-runtime" -version = "189.0.0" +version = "190.0.0" authors = ["GalacticCouncil"] edition = "2021" license = "Apache 2.0" diff --git a/runtime/hydradx/src/lib.rs b/runtime/hydradx/src/lib.rs index c2e7fabd6..93b070a60 100644 --- a/runtime/hydradx/src/lib.rs +++ b/runtime/hydradx/src/lib.rs @@ -99,7 +99,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("hydradx"), impl_name: create_runtime_str!("hydradx"), authoring_version: 1, - spec_version: 189, + spec_version: 190, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 1,