From 075998584190a1a1f7e3e0a5f4b1449d6765dc84 Mon Sep 17 00:00:00 2001 From: zktony Date: Wed, 6 Mar 2024 12:16:41 +0530 Subject: [PATCH 1/4] Removed sudo access --- pallets/xcm-helper/src/benchmarking.rs | 3 ++- pallets/xcm-helper/src/lib.rs | 2 +- pallets/xcm-helper/src/tests.rs | 8 ++++---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/pallets/xcm-helper/src/benchmarking.rs b/pallets/xcm-helper/src/benchmarking.rs index 7960aa457..fcbb94b86 100644 --- a/pallets/xcm-helper/src/benchmarking.rs +++ b/pallets/xcm-helper/src/benchmarking.rs @@ -33,9 +33,10 @@ benchmarks! { whitelist_token { let b in 1 .. 1000; let token = b as u128; + let account = account::("alice", 1, b); let asset_location = MultiLocation::new(1, Junctions::X1(Junction::Parachain(b))); let token: AssetId = AssetId::Concrete(asset_location); - }: _(RawOrigin::Root, token) + }: _(RawOrigin::Signed(account), token) verify { let token = XcmHelper::::generate_asset_id_for_parachain(token); let whitelisted_tokens = >::get(); diff --git a/pallets/xcm-helper/src/lib.rs b/pallets/xcm-helper/src/lib.rs index c1b54d888..321dee6fd 100644 --- a/pallets/xcm-helper/src/lib.rs +++ b/pallets/xcm-helper/src/lib.rs @@ -393,7 +393,7 @@ pub mod pallet { #[pallet::call_index(1)] #[pallet::weight(T::WeightInfo::whitelist_token(1))] pub fn whitelist_token(origin: OriginFor, token: AssetId) -> DispatchResult { - T::AssetCreateUpdateOrigin::ensure_origin(origin)?; + let _ = ensure_signed(origin)?; let token = Self::generate_asset_id_for_parachain(token); let mut whitelisted_tokens = >::get(); ensure!(!whitelisted_tokens.contains(&token), Error::::TokenIsAlreadyWhitelisted); diff --git a/pallets/xcm-helper/src/tests.rs b/pallets/xcm-helper/src/tests.rs index 20cf72f40..dbc3e9597 100644 --- a/pallets/xcm-helper/src/tests.rs +++ b/pallets/xcm-helper/src/tests.rs @@ -24,7 +24,7 @@ fn test_whitelist_token_returns_ok() { new_test_ext().execute_with(|| { let asset_location = MultiLocation::parent(); let token: AssetId = AssetId::Concrete(asset_location); - assert_ok!(XcmHelper::whitelist_token(RuntimeOrigin::root(), token)); + assert_ok!(XcmHelper::whitelist_token(RuntimeOrigin::signed(1), token)); }); } @@ -46,7 +46,7 @@ fn test_remove_whitelisted_token_returns_ok() { new_test_ext().execute_with(|| { let asset_location = MultiLocation::parent(); let token: AssetId = AssetId::Concrete(asset_location); - assert_ok!(XcmHelper::whitelist_token(RuntimeOrigin::root(), token)); + assert_ok!(XcmHelper::whitelist_token(RuntimeOrigin::signed(1), token)); assert_ok!(XcmHelper::remove_whitelisted_token(RuntimeOrigin::root(), token)); }); } @@ -81,9 +81,9 @@ fn test_whitelist_token_returns_token_is_already_whitelisted() { new_test_ext().execute_with(|| { let asset_location = MultiLocation::parent(); let token: AssetId = AssetId::Concrete(asset_location); - assert_ok!(XcmHelper::whitelist_token(RuntimeOrigin::root(), token)); + assert_ok!(XcmHelper::whitelist_token(RuntimeOrigin::signed(1), token)); assert_noop!( - XcmHelper::whitelist_token(RuntimeOrigin::root(), token), + XcmHelper::whitelist_token(RuntimeOrigin::signed(1), token), Error::::TokenIsAlreadyWhitelisted ); }); From 1187ee8f350c10a1a2a4b28bdc8e174b1a2c0ece Mon Sep 17 00:00:00 2001 From: zktony Date: Wed, 6 Mar 2024 12:36:00 +0530 Subject: [PATCH 2/4] Commented whitelist checking --- pallets/xcm-helper/src/benchmarking.rs | 3 +-- pallets/xcm-helper/src/lib.rs | 2 +- pallets/xcm-helper/src/tests.rs | 8 ++++---- runtimes/parachain/src/xcm_config.rs | 14 ++++++++------ 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/pallets/xcm-helper/src/benchmarking.rs b/pallets/xcm-helper/src/benchmarking.rs index fcbb94b86..7960aa457 100644 --- a/pallets/xcm-helper/src/benchmarking.rs +++ b/pallets/xcm-helper/src/benchmarking.rs @@ -33,10 +33,9 @@ benchmarks! { whitelist_token { let b in 1 .. 1000; let token = b as u128; - let account = account::("alice", 1, b); let asset_location = MultiLocation::new(1, Junctions::X1(Junction::Parachain(b))); let token: AssetId = AssetId::Concrete(asset_location); - }: _(RawOrigin::Signed(account), token) + }: _(RawOrigin::Root, token) verify { let token = XcmHelper::::generate_asset_id_for_parachain(token); let whitelisted_tokens = >::get(); diff --git a/pallets/xcm-helper/src/lib.rs b/pallets/xcm-helper/src/lib.rs index 321dee6fd..c1b54d888 100644 --- a/pallets/xcm-helper/src/lib.rs +++ b/pallets/xcm-helper/src/lib.rs @@ -393,7 +393,7 @@ pub mod pallet { #[pallet::call_index(1)] #[pallet::weight(T::WeightInfo::whitelist_token(1))] pub fn whitelist_token(origin: OriginFor, token: AssetId) -> DispatchResult { - let _ = ensure_signed(origin)?; + T::AssetCreateUpdateOrigin::ensure_origin(origin)?; let token = Self::generate_asset_id_for_parachain(token); let mut whitelisted_tokens = >::get(); ensure!(!whitelisted_tokens.contains(&token), Error::::TokenIsAlreadyWhitelisted); diff --git a/pallets/xcm-helper/src/tests.rs b/pallets/xcm-helper/src/tests.rs index dbc3e9597..543f85352 100644 --- a/pallets/xcm-helper/src/tests.rs +++ b/pallets/xcm-helper/src/tests.rs @@ -24,7 +24,7 @@ fn test_whitelist_token_returns_ok() { new_test_ext().execute_with(|| { let asset_location = MultiLocation::parent(); let token: AssetId = AssetId::Concrete(asset_location); - assert_ok!(XcmHelper::whitelist_token(RuntimeOrigin::signed(1), token)); + assert_ok!(XcmHelper::whitelist_token(RuntimeOrigin::root(), token)); }); } @@ -46,7 +46,7 @@ fn test_remove_whitelisted_token_returns_ok() { new_test_ext().execute_with(|| { let asset_location = MultiLocation::parent(); let token: AssetId = AssetId::Concrete(asset_location); - assert_ok!(XcmHelper::whitelist_token(RuntimeOrigin::signed(1), token)); + assert_ok!(XcmHelper::whitelist_token(RuntimeOrigin::z(), token)); assert_ok!(XcmHelper::remove_whitelisted_token(RuntimeOrigin::root(), token)); }); } @@ -81,9 +81,9 @@ fn test_whitelist_token_returns_token_is_already_whitelisted() { new_test_ext().execute_with(|| { let asset_location = MultiLocation::parent(); let token: AssetId = AssetId::Concrete(asset_location); - assert_ok!(XcmHelper::whitelist_token(RuntimeOrigin::signed(1), token)); + assert_ok!(XcmHelper::whitelist_token(RuntimeOrigin::root(), token)); assert_noop!( - XcmHelper::whitelist_token(RuntimeOrigin::signed(1), token), + XcmHelper::whitelist_token(RuntimeOrigin::root(), token), Error::::TokenIsAlreadyWhitelisted ); }); diff --git a/runtimes/parachain/src/xcm_config.rs b/runtimes/parachain/src/xcm_config.rs index 1eac44850..521965ba8 100644 --- a/runtimes/parachain/src/xcm_config.rs +++ b/runtimes/parachain/src/xcm_config.rs @@ -333,12 +333,14 @@ where let foreign_currency_asset_id = AC::convert_location_to_asset_id(location).ok_or(XcmError::Trap(1001))?; let _path = [PolkadexAssetid::get(), foreign_currency_asset_id]; - let (unused, expected_fee_in_foreign_currency) = - if WH::check_whitelisted_token(foreign_currency_asset_id) { - (payment, 0u128) - } else { - return Err(XcmError::Trap(1004)); - }; + //WILL BE RESTORED LATER + // let (unused, expected_fee_in_foreign_currency) = + // if WH::check_whitelisted_token(foreign_currency_asset_id) { + // (payment, 0u128) + // } else { + // return Err(XcmError::Trap(1004)); + // }; + let (unused, expected_fee_in_foreign_currency) = (payment, 0u128); self.weight = self.weight.saturating_add(weight); if let Some((old_asset_location, _)) = self.asset_location_and_units_per_second { if old_asset_location == location { From f9c8d5ace8933a5244c932ce7287456a1f4b1819 Mon Sep 17 00:00:00 2001 From: zktony Date: Wed, 6 Mar 2024 12:37:56 +0530 Subject: [PATCH 3/4] Fixed test --- pallets/xcm-helper/src/tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/xcm-helper/src/tests.rs b/pallets/xcm-helper/src/tests.rs index 543f85352..20cf72f40 100644 --- a/pallets/xcm-helper/src/tests.rs +++ b/pallets/xcm-helper/src/tests.rs @@ -46,7 +46,7 @@ fn test_remove_whitelisted_token_returns_ok() { new_test_ext().execute_with(|| { let asset_location = MultiLocation::parent(); let token: AssetId = AssetId::Concrete(asset_location); - assert_ok!(XcmHelper::whitelist_token(RuntimeOrigin::z(), token)); + assert_ok!(XcmHelper::whitelist_token(RuntimeOrigin::root(), token)); assert_ok!(XcmHelper::remove_whitelisted_token(RuntimeOrigin::root(), token)); }); } From a151e4d56dabc27e2c29445dc0f75b89855d29bc Mon Sep 17 00:00:00 2001 From: gautham Date: Wed, 6 Mar 2024 13:27:32 +0530 Subject: [PATCH 4/4] Reduce withdrawal delay --- runtimes/parachain/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtimes/parachain/src/lib.rs b/runtimes/parachain/src/lib.rs index 1472602ba..0ce2efe81 100644 --- a/runtimes/parachain/src/lib.rs +++ b/runtimes/parachain/src/lib.rs @@ -470,7 +470,7 @@ impl pallet_sudo::Config for Runtime { parameter_types! { pub const AssetHandlerPalletId: PalletId = PalletId(*b"XcmHandl"); - pub const WithdrawalExecutionBlockDiff: u32 = 1000; + pub const WithdrawalExecutionBlockDiff: u32 = 1; pub ParachainId: u32 = ParachainInfo::get().into(); pub const ParachainNetworkId: u8 = 1; // Our parachain's thea id is one. pub const PolkadexAssetid: u128 = POLKADEX_NATIVE_ASSET_ID;