From 88c623bcb2e1bf151ae300432be9989bf5855c50 Mon Sep 17 00:00:00 2001 From: dmoka Date: Fri, 1 Dec 2023 16:20:49 +0100 Subject: [PATCH 01/34] WIP - add ethereum address conversion for multilocation --- integration-tests/src/cross_chain_transfer.rs | 85 ++++++++++++++++++- runtime/hydradx/src/xcm.rs | 34 ++++++++ 2 files changed, 118 insertions(+), 1 deletion(-) diff --git a/integration-tests/src/cross_chain_transfer.rs b/integration-tests/src/cross_chain_transfer.rs index 3bc596437..065bcfe3e 100644 --- a/integration-tests/src/cross_chain_transfer.rs +++ b/integration-tests/src/cross_chain_transfer.rs @@ -8,12 +8,18 @@ use polkadot_xcm::{latest::prelude::*, v3::WeightLimit, VersionedMultiAssets, Ve use cumulus_primitives_core::ParaId; use frame_support::weights::Weight; use hex_literal::hex; +use hydradx_runtime::evm::precompiles::EvmAddress; +use hydradx_runtime::evm::ExtendedAddressMapping; use orml_traits::currency::MultiCurrency; +use pallet_evm::AddressMapping; use pretty_assertions::assert_eq; +use primitives::AccountId; +use sp_core::blake2_256; +use sp_core::Encode; +use sp_core::H160; use sp_core::H256; use sp_runtime::traits::{AccountIdConversion, BlakeTwo256, Hash}; use xcm_emulator::TestExt; - // Determine the hash for assets expected to be have been trapped. fn determine_hash(origin: &MultiLocation, assets: M) -> H256 where @@ -154,6 +160,83 @@ fn hydra_should_receive_asset_when_transferred_from_acala() { }); } +#[test] +fn hydra_should_receive_asset_when_transferred_from_acala_to_eth_address() { + // Arrange + TestNet::reset(); + + Hydra::execute_with(|| { + assert_ok!(hydradx_runtime::AssetRegistry::set_location( + hydradx_runtime::RuntimeOrigin::root(), + ACA, + hydradx_runtime::AssetLocation(MultiLocation::new(1, X2(Parachain(ACALA_PARA_ID), GeneralIndex(0)))) + )); + }); + + //TODO: cotninue here, find a way to convert back from 32 to 20 + assert_eq!( + ExtendedAddressMapping::into_account_id(H160::from(hex!["222222ff7Be76052e023Ec1a306fCca8F9659D80"])), + AccountId::from(BOB) + ); + //let bob_evm = ExtendedAddressMapping::try_from_account(AccountId::from(BOB).borrow()).unwrap(); + Acala::execute_with(|| { + // Act + assert_ok!(hydradx_runtime::XTokens::transfer( + hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), + 0, + 30 * UNITS, + Box::new( + MultiLocation::new( + 1, + X2( + Junction::Parachain(HYDRA_PARA_ID), + Junction::AccountKey20 { + network: None, + key: bob_evm_addr().into(), + } + ) + ) + .into() + ), + WeightLimit::Limited(Weight::from_parts(399_600_000_000, 0)) + )); + + // Assert + assert_eq!( + hydradx_runtime::Balances::free_balance(&AccountId::from(ALICE)), + ALICE_INITIAL_NATIVE_BALANCE - 30 * UNITS + ); + }); + + let fee = 321507225875; + Hydra::execute_with(|| { + assert_eq!( + hydradx_runtime::Tokens::free_balance(ACA, &AccountId::from(BOB)), + 30 * UNITS - fee + ); + assert_eq!( + hydradx_runtime::Tokens::free_balance(ACA, &hydradx_runtime::Treasury::account_id()), + fee // fees should go to treasury + ); + }); +} + +//TODO: remove duplication of these functions +fn account_to_default_evm_address(account_id: &impl Encode) -> EvmAddress { + let payload = (b"evm:", account_id); + EvmAddress::from_slice(&payload.using_encoded(blake2_256)[0..20]) +} + +pub fn alice_evm_addr() -> H160 { + //H160::from(hex_literal::hex!("1000000000000000000000000000000000000001")) + account_to_default_evm_address(&ALICE) +} + +pub fn bob_evm_addr() -> H160 { + //H160::from(hex_literal::hex!("1000000000000000000000000000000000000001")) + account_to_default_evm_address(&BOB) +} + #[test] fn transfer_from_acala_should_fail_when_transferring_insufficient_amount() { TestNet::reset(); diff --git a/runtime/hydradx/src/xcm.rs b/runtime/hydradx/src/xcm.rs index 9fd85919b..aeab2ee20 100644 --- a/runtime/hydradx/src/xcm.rs +++ b/runtime/hydradx/src/xcm.rs @@ -1,4 +1,5 @@ use super::*; +use sp_std::marker::PhantomData; use codec::MaxEncodedLen; use hydradx_adapters::RelayChainBlockNumberProvider; @@ -16,6 +17,7 @@ use frame_support::{ use frame_system::EnsureRoot; use orml_traits::{location::AbsoluteReserveProvider, parameter_type_with_key}; use orml_xcm_support::{DepositToAlternative, IsNativeConcrete, MultiNativeAsset}; +use pallet_evm::AddressMapping; use pallet_xcm::XcmPassthrough; use polkadot_parachain::primitives::Sibling; use polkadot_xcm::v3::{prelude::*, Weight as XcmWeight}; @@ -228,6 +230,7 @@ impl pallet_xcm::Config for Runtime { type ReachableDest = ReachableDest; } pub struct CurrencyIdConvert; +use crate::evm::ExtendedAddressMapping; use primitives::constants::chain::CORE_ASSET_ID; impl Convert> for CurrencyIdConvert { @@ -306,8 +309,39 @@ pub type LocationToAccountId = ( SiblingParachainConvertsVia, // Straight up local `AccountId32` origins just alias directly to `AccountId`. AccountId32Aliases, + EvmAddressConversion, ); +/// Converts Account20 (ethereum) addresses to AccountId32 (substrate) addresses. +//TODO: do we want bitcoin too? +//TODO: do we care about network? We can maybe remove +pub struct EvmAddressConversion(PhantomData); +impl>> xcm_executor::traits::Convert + for EvmAddressConversion +{ + fn convert(location: MultiLocation) -> Result { + match location { + MultiLocation { + parents: 0, + interior: X1(AccountKey20 { network, key }), + } => { + let account_32 = ExtendedAddressMapping::into_account_id(H160::from(key)); + return Ok(account_32); + } + _ => Err(location), + } + } + + //TODO: fix this reverse + fn reverse(who: AccountId) -> Result { + Ok(AccountId32 { + id: who.into(), + network: Network::get(), + } + .into()) + } +} + parameter_types! { // The account which receives multi-currency tokens from failed attempts to deposit them pub Alternative: AccountId = PalletId(*b"xcm/alte").into_account_truncating(); From 504210eeb8e4af2beb5533bb4c58fa946d37b432 Mon Sep 17 00:00:00 2001 From: dmoka Date: Mon, 4 Dec 2023 13:42:51 +0100 Subject: [PATCH 02/34] fix integration test to send to eth address --- integration-tests/src/cross_chain_transfer.rs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/integration-tests/src/cross_chain_transfer.rs b/integration-tests/src/cross_chain_transfer.rs index 065bcfe3e..62f134cf5 100644 --- a/integration-tests/src/cross_chain_transfer.rs +++ b/integration-tests/src/cross_chain_transfer.rs @@ -173,12 +173,6 @@ fn hydra_should_receive_asset_when_transferred_from_acala_to_eth_address() { )); }); - //TODO: cotninue here, find a way to convert back from 32 to 20 - assert_eq!( - ExtendedAddressMapping::into_account_id(H160::from(hex!["222222ff7Be76052e023Ec1a306fCca8F9659D80"])), - AccountId::from(BOB) - ); - //let bob_evm = ExtendedAddressMapping::try_from_account(AccountId::from(BOB).borrow()).unwrap(); Acala::execute_with(|| { // Act assert_ok!(hydradx_runtime::XTokens::transfer( @@ -192,7 +186,7 @@ fn hydra_should_receive_asset_when_transferred_from_acala_to_eth_address() { Junction::Parachain(HYDRA_PARA_ID), Junction::AccountKey20 { network: None, - key: bob_evm_addr().into(), + key: evm_address().into(), } ) ) @@ -208,10 +202,10 @@ fn hydra_should_receive_asset_when_transferred_from_acala_to_eth_address() { ); }); - let fee = 321507225875; + let fee = 400641025641; Hydra::execute_with(|| { assert_eq!( - hydradx_runtime::Tokens::free_balance(ACA, &AccountId::from(BOB)), + hydradx_runtime::Tokens::free_balance(ACA, &AccountId::from(evm_account())), 30 * UNITS - fee ); assert_eq!( From f2e2481350140bc87080644927254e5af53ae426 Mon Sep 17 00:00:00 2001 From: dmoka Date: Mon, 4 Dec 2023 14:15:17 +0100 Subject: [PATCH 03/34] add check that the asset arrives when sent both eth and normal address --- integration-tests/src/cross_chain_transfer.rs | 32 ++++++++++++++++--- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/integration-tests/src/cross_chain_transfer.rs b/integration-tests/src/cross_chain_transfer.rs index 62f134cf5..c42df53a4 100644 --- a/integration-tests/src/cross_chain_transfer.rs +++ b/integration-tests/src/cross_chain_transfer.rs @@ -173,12 +173,13 @@ fn hydra_should_receive_asset_when_transferred_from_acala_to_eth_address() { )); }); + let amount = 30 * UNITS; Acala::execute_with(|| { - // Act + //We send toe ethereum address with Account20 assert_ok!(hydradx_runtime::XTokens::transfer( hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), 0, - 30 * UNITS, + amount, Box::new( MultiLocation::new( 1, @@ -195,10 +196,31 @@ fn hydra_should_receive_asset_when_transferred_from_acala_to_eth_address() { WeightLimit::Limited(Weight::from_parts(399_600_000_000, 0)) )); + //We send it again to the same address, but to normal Account32 + assert_ok!(hydradx_runtime::XTokens::transfer( + hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), + 0, + amount, + Box::new( + MultiLocation::new( + 1, + X2( + Junction::Parachain(HYDRA_PARA_ID), + Junction::AccountId32 { + id: evm_account().into(), + network: None + } + ) + ) + .into() + ), + WeightLimit::Limited(Weight::from_ref_time(399_600_000_000)) + )); + // Assert assert_eq!( hydradx_runtime::Balances::free_balance(&AccountId::from(ALICE)), - ALICE_INITIAL_NATIVE_BALANCE - 30 * UNITS + ALICE_INITIAL_NATIVE_BALANCE - 2 * amount ); }); @@ -206,11 +228,11 @@ fn hydra_should_receive_asset_when_transferred_from_acala_to_eth_address() { Hydra::execute_with(|| { assert_eq!( hydradx_runtime::Tokens::free_balance(ACA, &AccountId::from(evm_account())), - 30 * UNITS - fee + 2 * amount - 2 * fee ); assert_eq!( hydradx_runtime::Tokens::free_balance(ACA, &hydradx_runtime::Treasury::account_id()), - fee // fees should go to treasury + 2 * fee // fees should go to treasury ); }); } From ddd2c72178a83ef1b8acab23ec3612199fe060c1 Mon Sep 17 00:00:00 2001 From: dmoka Date: Mon, 4 Dec 2023 14:42:39 +0100 Subject: [PATCH 04/34] remove todos as they are not relevant --- runtime/hydradx/src/xcm.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/runtime/hydradx/src/xcm.rs b/runtime/hydradx/src/xcm.rs index aeab2ee20..46bda8d78 100644 --- a/runtime/hydradx/src/xcm.rs +++ b/runtime/hydradx/src/xcm.rs @@ -313,8 +313,6 @@ pub type LocationToAccountId = ( ); /// Converts Account20 (ethereum) addresses to AccountId32 (substrate) addresses. -//TODO: do we want bitcoin too? -//TODO: do we care about network? We can maybe remove pub struct EvmAddressConversion(PhantomData); impl>> xcm_executor::traits::Convert for EvmAddressConversion From 1b0ae4095e773703f87241f471a03557c4e03027 Mon Sep 17 00:00:00 2001 From: dmoka Date: Tue, 5 Dec 2023 15:38:40 +0100 Subject: [PATCH 05/34] bump versions --- integration-tests/Cargo.toml | 2 +- runtime/hydradx/Cargo.toml | 2 +- runtime/hydradx/src/lib.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index 0d1881a3a..3b27d4281 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "runtime-integration-tests" -version = "1.16.4" +version = "1.16.5" description = "Integration tests" authors = ["GalacticCouncil"] edition = "2021" diff --git a/runtime/hydradx/Cargo.toml b/runtime/hydradx/Cargo.toml index 24497f6fd..0d68e8352 100644 --- a/runtime/hydradx/Cargo.toml +++ b/runtime/hydradx/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hydradx-runtime" -version = "193.0.0" +version = "194.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 875b654c4..f2e73c961 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: 193, + spec_version: 194, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 1, From c831d42feb3c49d6a9d5d7658dd1d18f84dff43a Mon Sep 17 00:00:00 2001 From: dmoka Date: Tue, 5 Dec 2023 16:29:39 +0100 Subject: [PATCH 06/34] fix lock with latest versions --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6d1821306..9e2a63717 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4221,7 +4221,7 @@ dependencies = [ [[package]] name = "hydradx-runtime" -version = "193.0.0" +version = "194.0.0" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", @@ -10767,7 +10767,7 @@ dependencies = [ [[package]] name = "runtime-integration-tests" -version = "1.16.4" +version = "1.16.5" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", From c0bf508c0195fc5e74bbd0ad8996124f16b0bc42 Mon Sep 17 00:00:00 2001 From: dmoka Date: Tue, 5 Dec 2023 16:48:40 +0100 Subject: [PATCH 07/34] make clippy happy --- runtime/hydradx/src/xcm.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/hydradx/src/xcm.rs b/runtime/hydradx/src/xcm.rs index 46bda8d78..d1d1d3f3e 100644 --- a/runtime/hydradx/src/xcm.rs +++ b/runtime/hydradx/src/xcm.rs @@ -321,10 +321,10 @@ impl>> xcm_executor::traits::Convert { let account_32 = ExtendedAddressMapping::into_account_id(H160::from(key)); - return Ok(account_32); + Ok(account_32) } _ => Err(location), } From 4d4853ab9cb3fb0924b9e7e8bc778a715a96f061 Mon Sep 17 00:00:00 2001 From: Frederik Gartenmeister Date: Wed, 6 Dec 2023 13:21:48 +0100 Subject: [PATCH 08/34] feat: Enable ecosystem wide compatible account derivation --- primitives/src/lib.rs | 159 +++++++++++++++++++++++++++++++++++++ runtime/hydradx/src/xcm.rs | 2 + 2 files changed, 161 insertions(+) diff --git a/primitives/src/lib.rs b/primitives/src/lib.rs index 9fe493c72..cd6c2a70c 100644 --- a/primitives/src/lib.rs +++ b/primitives/src/lib.rs @@ -75,3 +75,162 @@ pub type Header = generic::Header; /// Block type. pub type Block = generic::Block; + + +pub mod xcm { + use codec::{Compact, Encode}; + use sp_io::hashing::blake2_256; + use sp_std::{borrow::Borrow, marker::PhantomData, vec::Vec}; + use xcm::prelude::{ + AccountId32, AccountKey20, Here, MultiLocation, PalletInstance, Parachain, X1, + }; + use xcm_executor::traits::Convert; + + /// NOTE: Copied from + /// + /// temporary struct that mimics the behavior of the upstream type that we + /// will move to once we update this repository to Polkadot 0.9.43+. + pub struct HashedDescriptionDescribeFamilyAllTerminal(PhantomData); + impl + Clone> HashedDescriptionDescribeFamilyAllTerminal { + fn describe_location_suffix(l: &MultiLocation) -> Result, ()> { + match (l.parents, &l.interior) { + (0, Here) => Ok(Vec::new()), + (0, X1(PalletInstance(i))) => { + Ok((b"Pallet", Compact::::from(*i as u32)).encode()) + } + (0, X1(AccountId32 { id, .. })) => Ok((b"AccountId32", id).encode()), + (0, X1(AccountKey20 { key, .. })) => Ok((b"AccountKey20", key).encode()), + _ => Err(()), + } + } + } + + impl + Clone> Convert + for HashedDescriptionDescribeFamilyAllTerminal + { + fn convert_ref(location: impl Borrow) -> Result { + let l = location.borrow(); + let to_hash = match (l.parents, l.interior.first()) { + (0, Some(Parachain(index))) => { + let tail = l.interior.split_first().0; + let interior = Self::describe_location_suffix(&tail.into())?; + (b"ChildChain", Compact::::from(*index), interior).encode() + } + (1, Some(Parachain(index))) => { + let tail = l.interior.split_first().0; + let interior = Self::describe_location_suffix(&tail.into())?; + (b"SiblingChain", Compact::::from(*index), interior).encode() + } + (1, _) => { + let tail = l.interior.into(); + let interior = Self::describe_location_suffix(&tail)?; + (b"ParentChain", interior).encode() + } + _ => return Err(()), + }; + Ok(blake2_256(&to_hash).into()) + } + + fn reverse_ref(_: impl Borrow) -> Result { + Err(()) + } + } + + #[test] + fn test_hashed_family_all_terminal_converter() { + use xcm::prelude::X2; + + type Converter = HashedDescriptionDescribeFamilyAllTerminal; + + assert_eq!( + [ + 129, 211, 14, 6, 146, 54, 225, 200, 135, 103, 248, 244, 125, 112, 53, 133, 91, 42, + 215, 236, 154, 199, 191, 208, 110, 148, 223, 55, 92, 216, 250, 34 + ], + Converter::<[u8; 32]>::convert(MultiLocation { + parents: 0, + interior: X2( + Parachain(1), + AccountId32 { + network: None, + id: [0u8; 32] + } + ), + }) + .unwrap() + ); + assert_eq!( + [ + 17, 142, 105, 253, 199, 34, 43, 136, 155, 48, 12, 137, 155, 219, 155, 110, 93, 181, + 93, 252, 124, 60, 250, 195, 229, 86, 31, 220, 121, 111, 254, 252 + ], + Converter::<[u8; 32]>::convert(MultiLocation { + parents: 1, + interior: X2( + Parachain(1), + AccountId32 { + network: None, + id: [0u8; 32] + } + ), + }) + .unwrap() + ); + assert_eq!( + [ + 237, 65, 190, 49, 53, 182, 196, 183, 151, 24, 214, 23, 72, 244, 235, 87, 187, 67, + 52, 122, 195, 192, 10, 58, 253, 49, 0, 112, 175, 224, 125, 66 + ], + Converter::<[u8; 32]>::convert(MultiLocation { + parents: 0, + interior: X2( + Parachain(1), + AccountKey20 { + network: None, + key: [0u8; 20] + } + ), + }) + .unwrap() + ); + assert_eq!( + [ + 226, 225, 225, 162, 254, 156, 113, 95, 68, 155, 160, 118, 126, 18, 166, 132, 144, + 19, 8, 204, 228, 112, 164, 189, 179, 124, 249, 1, 168, 110, 151, 50 + ], + Converter::<[u8; 32]>::convert(MultiLocation { + parents: 1, + interior: X2( + Parachain(1), + AccountKey20 { + network: None, + key: [0u8; 20] + } + ), + }) + .unwrap() + ); + assert_eq!( + [ + 254, 186, 179, 229, 13, 24, 84, 36, 84, 35, 64, 95, 114, 136, 62, 69, 247, 74, 215, + 104, 121, 114, 53, 6, 124, 46, 42, 245, 121, 197, 12, 208 + ], + Converter::<[u8; 32]>::convert(MultiLocation { + parents: 1, + interior: X2(Parachain(2), PalletInstance(3)), + }) + .unwrap() + ); + assert_eq!( + [ + 217, 56, 0, 36, 228, 154, 250, 26, 200, 156, 1, 39, 254, 162, 16, 187, 107, 67, 27, + 16, 218, 254, 250, 184, 6, 27, 216, 138, 194, 93, 23, 165 + ], + Converter::<[u8; 32]>::convert(MultiLocation { + parents: 1, + interior: Here, + }) + .unwrap() + ); + } +} diff --git a/runtime/hydradx/src/xcm.rs b/runtime/hydradx/src/xcm.rs index 9fd85919b..6555b731d 100644 --- a/runtime/hydradx/src/xcm.rs +++ b/runtime/hydradx/src/xcm.rs @@ -306,6 +306,8 @@ pub type LocationToAccountId = ( SiblingParachainConvertsVia, // Straight up local `AccountId32` origins just alias directly to `AccountId`. AccountId32Aliases, + // Generate remote accounts according to polkadot standards + primitives::xcm::HashedDescriptionDescribeFamilyAllTerminal, ); parameter_types! { From a4943bc5424870f91f393a8ff7e7d315971855f6 Mon Sep 17 00:00:00 2001 From: dmoka Date: Mon, 11 Dec 2023 09:04:48 +0100 Subject: [PATCH 09/34] remove unused functions --- integration-tests/src/cross_chain_transfer.rs | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/integration-tests/src/cross_chain_transfer.rs b/integration-tests/src/cross_chain_transfer.rs index c42df53a4..c746fb5ab 100644 --- a/integration-tests/src/cross_chain_transfer.rs +++ b/integration-tests/src/cross_chain_transfer.rs @@ -237,22 +237,6 @@ fn hydra_should_receive_asset_when_transferred_from_acala_to_eth_address() { }); } -//TODO: remove duplication of these functions -fn account_to_default_evm_address(account_id: &impl Encode) -> EvmAddress { - let payload = (b"evm:", account_id); - EvmAddress::from_slice(&payload.using_encoded(blake2_256)[0..20]) -} - -pub fn alice_evm_addr() -> H160 { - //H160::from(hex_literal::hex!("1000000000000000000000000000000000000001")) - account_to_default_evm_address(&ALICE) -} - -pub fn bob_evm_addr() -> H160 { - //H160::from(hex_literal::hex!("1000000000000000000000000000000000000001")) - account_to_default_evm_address(&BOB) -} - #[test] fn transfer_from_acala_should_fail_when_transferring_insufficient_amount() { TestNet::reset(); From fb7ca818fce5d08e63255edd8292ea02952442c8 Mon Sep 17 00:00:00 2001 From: dmoka Date: Mon, 11 Dec 2023 09:43:03 +0100 Subject: [PATCH 10/34] 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 afd6979ec..fc24f6e07 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4222,7 +4222,7 @@ dependencies = [ [[package]] name = "hydradx-runtime" -version = "194.0.0" +version = "195.0.0" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", diff --git a/runtime/hydradx/Cargo.toml b/runtime/hydradx/Cargo.toml index 0d68e8352..ad6abbe45 100644 --- a/runtime/hydradx/Cargo.toml +++ b/runtime/hydradx/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hydradx-runtime" -version = "194.0.0" +version = "195.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 f2e73c961..e30cc3940 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: 194, + spec_version: 195, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 1, From 6de13259c27f15322bd475218b87e14ac97a0e04 Mon Sep 17 00:00:00 2001 From: dmoka Date: Wed, 13 Dec 2023 08:25:34 +0100 Subject: [PATCH 11/34] temporarly remove the evm address conversion so we can merge "xcm-ecosystem-account-derivation" within guthub --- runtime/hydradx/src/xcm.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/hydradx/src/xcm.rs b/runtime/hydradx/src/xcm.rs index d1d1d3f3e..25d70cb12 100644 --- a/runtime/hydradx/src/xcm.rs +++ b/runtime/hydradx/src/xcm.rs @@ -309,9 +309,9 @@ pub type LocationToAccountId = ( SiblingParachainConvertsVia, // Straight up local `AccountId32` origins just alias directly to `AccountId`. AccountId32Aliases, - EvmAddressConversion, ); +// EvmAddressConversion, /// Converts Account20 (ethereum) addresses to AccountId32 (substrate) addresses. pub struct EvmAddressConversion(PhantomData); impl>> xcm_executor::traits::Convert From cbc1136cc9070f5e9a58f8ce4715631f29f000cc Mon Sep 17 00:00:00 2001 From: dmoka Date: Wed, 13 Dec 2023 13:18:40 +0100 Subject: [PATCH 12/34] WIP - add support for global remote location --- Cargo.lock | 1 + integration-tests/src/cross_chain_transfer.rs | 111 ++++++++++++ primitives/Cargo.toml | 1 + primitives/src/lib.rs | 159 ------------------ runtime/hydradx/Cargo.toml | 1 + runtime/hydradx/src/xcm.rs | 159 +++++++++++++++++- 6 files changed, 271 insertions(+), 161 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fc24f6e07..fd5bf8dce 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10002,6 +10002,7 @@ dependencies = [ "scale-info", "serde", "sp-core", + "sp-io", "sp-std", "static_assertions", ] diff --git a/integration-tests/src/cross_chain_transfer.rs b/integration-tests/src/cross_chain_transfer.rs index c746fb5ab..62f8662d7 100644 --- a/integration-tests/src/cross_chain_transfer.rs +++ b/integration-tests/src/cross_chain_transfer.rs @@ -173,6 +173,61 @@ fn hydra_should_receive_asset_when_transferred_from_acala_to_eth_address() { )); }); + let amount = 30 * UNITS; + Acala::execute_with(|| { + //We send toe ethereum address with Account20 + assert_ok!(hydradx_runtime::XTokens::transfer( + hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), + 0, + amount, + Box::new( + MultiLocation::new( + 1, + X2( + Junction::Parachain(HYDRA_PARA_ID), + Junction::AccountKey20 { + network: None, + key: evm_address().into(), + } + ) + ) + .into() + ), + WeightLimit::Limited(Weight::from_parts(399_600_000_000, 0)) + )); + // Assert + assert_eq!( + hydradx_runtime::Balances::free_balance(&AccountId::from(ALICE)), + ALICE_INITIAL_NATIVE_BALANCE - amount + ); + }); + + let fee = 400641025641; + Hydra::execute_with(|| { + assert_eq!( + hydradx_runtime::Tokens::free_balance(ACA, &AccountId::from(evm_account())), + amount - fee + ); + assert_eq!( + hydradx_runtime::Tokens::free_balance(ACA, &hydradx_runtime::Treasury::account_id()), + 1 * fee // fees should go to treasury + ); + }); +} + +#[test] +fn hydra_should_receive_asset_when_transferred_from_acala_to_same_address_represented_as_both_account32_and_20() { + // Arrange + TestNet::reset(); + + Hydra::execute_with(|| { + assert_ok!(hydradx_runtime::AssetRegistry::set_location( + hydradx_runtime::RuntimeOrigin::root(), + ACA, + hydradx_runtime::AssetLocation(MultiLocation::new(1, X2(Parachain(ACALA_PARA_ID), GeneralIndex(0)))) + )); + }); + let amount = 30 * UNITS; Acala::execute_with(|| { //We send toe ethereum address with Account20 @@ -237,6 +292,62 @@ fn hydra_should_receive_asset_when_transferred_from_acala_to_eth_address() { }); } +#[test] +fn asd() { + // Arrange + TestNet::reset(); + + Hydra::execute_with(|| { + assert_ok!(hydradx_runtime::AssetRegistry::set_location( + hydradx_runtime::RuntimeOrigin::root(), + ACA, + hydradx_runtime::AssetLocation(MultiLocation::new(1, X2(Parachain(ACALA_PARA_ID), GeneralIndex(0)))) + )); + }); + + let amount = 30 * UNITS; + Acala::execute_with(|| { + //We send toe ethereum address with Account20 + assert_ok!(hydradx_runtime::XTokens::transfer( + hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), + 0, + amount, + Box::new( + MultiLocation::new( + 1, + X2( + Junction::Parachain(ACALA_PARA_ID), + Junction::AccountKey20 { + network: None, + key: evm_address().into(), + } + ) + ) + .into() + ), + WeightLimit::Limited(Weight::from_parts(399_600_000_000, 0)) + )); + + // Assert + assert_eq!( + hydradx_runtime::Balances::free_balance(&AccountId::from(ALICE)), + ALICE_INITIAL_NATIVE_BALANCE - amount + ); + }); + + let fee = 400641025641; + Hydra::execute_with(|| { + assert_eq!( + hydradx_runtime::Tokens::free_balance(ACA, &AccountId::from(evm_account())), + amount - fee + ); + assert_eq!( + hydradx_runtime::Tokens::free_balance(ACA, &hydradx_runtime::Treasury::account_id()), + fee // fees should go to treasury + ); + }); +} + #[test] fn transfer_from_acala_should_fail_when_transferring_insufficient_amount() { TestNet::reset(); diff --git a/primitives/Cargo.toml b/primitives/Cargo.toml index 2edc5a180..2fb8fed8d 100644 --- a/primitives/Cargo.toml +++ b/primitives/Cargo.toml @@ -16,6 +16,7 @@ static_assertions = "1.1.0" frame-support = { workspace = true } sp-core = { workspace = true } sp-std = { workspace = true } +sp-io = { workspace = true } # Polkadot dependencies polkadot-primitives = { workspace = true } diff --git a/primitives/src/lib.rs b/primitives/src/lib.rs index cd6c2a70c..9fe493c72 100644 --- a/primitives/src/lib.rs +++ b/primitives/src/lib.rs @@ -75,162 +75,3 @@ pub type Header = generic::Header; /// Block type. pub type Block = generic::Block; - - -pub mod xcm { - use codec::{Compact, Encode}; - use sp_io::hashing::blake2_256; - use sp_std::{borrow::Borrow, marker::PhantomData, vec::Vec}; - use xcm::prelude::{ - AccountId32, AccountKey20, Here, MultiLocation, PalletInstance, Parachain, X1, - }; - use xcm_executor::traits::Convert; - - /// NOTE: Copied from - /// - /// temporary struct that mimics the behavior of the upstream type that we - /// will move to once we update this repository to Polkadot 0.9.43+. - pub struct HashedDescriptionDescribeFamilyAllTerminal(PhantomData); - impl + Clone> HashedDescriptionDescribeFamilyAllTerminal { - fn describe_location_suffix(l: &MultiLocation) -> Result, ()> { - match (l.parents, &l.interior) { - (0, Here) => Ok(Vec::new()), - (0, X1(PalletInstance(i))) => { - Ok((b"Pallet", Compact::::from(*i as u32)).encode()) - } - (0, X1(AccountId32 { id, .. })) => Ok((b"AccountId32", id).encode()), - (0, X1(AccountKey20 { key, .. })) => Ok((b"AccountKey20", key).encode()), - _ => Err(()), - } - } - } - - impl + Clone> Convert - for HashedDescriptionDescribeFamilyAllTerminal - { - fn convert_ref(location: impl Borrow) -> Result { - let l = location.borrow(); - let to_hash = match (l.parents, l.interior.first()) { - (0, Some(Parachain(index))) => { - let tail = l.interior.split_first().0; - let interior = Self::describe_location_suffix(&tail.into())?; - (b"ChildChain", Compact::::from(*index), interior).encode() - } - (1, Some(Parachain(index))) => { - let tail = l.interior.split_first().0; - let interior = Self::describe_location_suffix(&tail.into())?; - (b"SiblingChain", Compact::::from(*index), interior).encode() - } - (1, _) => { - let tail = l.interior.into(); - let interior = Self::describe_location_suffix(&tail)?; - (b"ParentChain", interior).encode() - } - _ => return Err(()), - }; - Ok(blake2_256(&to_hash).into()) - } - - fn reverse_ref(_: impl Borrow) -> Result { - Err(()) - } - } - - #[test] - fn test_hashed_family_all_terminal_converter() { - use xcm::prelude::X2; - - type Converter = HashedDescriptionDescribeFamilyAllTerminal; - - assert_eq!( - [ - 129, 211, 14, 6, 146, 54, 225, 200, 135, 103, 248, 244, 125, 112, 53, 133, 91, 42, - 215, 236, 154, 199, 191, 208, 110, 148, 223, 55, 92, 216, 250, 34 - ], - Converter::<[u8; 32]>::convert(MultiLocation { - parents: 0, - interior: X2( - Parachain(1), - AccountId32 { - network: None, - id: [0u8; 32] - } - ), - }) - .unwrap() - ); - assert_eq!( - [ - 17, 142, 105, 253, 199, 34, 43, 136, 155, 48, 12, 137, 155, 219, 155, 110, 93, 181, - 93, 252, 124, 60, 250, 195, 229, 86, 31, 220, 121, 111, 254, 252 - ], - Converter::<[u8; 32]>::convert(MultiLocation { - parents: 1, - interior: X2( - Parachain(1), - AccountId32 { - network: None, - id: [0u8; 32] - } - ), - }) - .unwrap() - ); - assert_eq!( - [ - 237, 65, 190, 49, 53, 182, 196, 183, 151, 24, 214, 23, 72, 244, 235, 87, 187, 67, - 52, 122, 195, 192, 10, 58, 253, 49, 0, 112, 175, 224, 125, 66 - ], - Converter::<[u8; 32]>::convert(MultiLocation { - parents: 0, - interior: X2( - Parachain(1), - AccountKey20 { - network: None, - key: [0u8; 20] - } - ), - }) - .unwrap() - ); - assert_eq!( - [ - 226, 225, 225, 162, 254, 156, 113, 95, 68, 155, 160, 118, 126, 18, 166, 132, 144, - 19, 8, 204, 228, 112, 164, 189, 179, 124, 249, 1, 168, 110, 151, 50 - ], - Converter::<[u8; 32]>::convert(MultiLocation { - parents: 1, - interior: X2( - Parachain(1), - AccountKey20 { - network: None, - key: [0u8; 20] - } - ), - }) - .unwrap() - ); - assert_eq!( - [ - 254, 186, 179, 229, 13, 24, 84, 36, 84, 35, 64, 95, 114, 136, 62, 69, 247, 74, 215, - 104, 121, 114, 53, 6, 124, 46, 42, 245, 121, 197, 12, 208 - ], - Converter::<[u8; 32]>::convert(MultiLocation { - parents: 1, - interior: X2(Parachain(2), PalletInstance(3)), - }) - .unwrap() - ); - assert_eq!( - [ - 217, 56, 0, 36, 228, 154, 250, 26, 200, 156, 1, 39, 254, 162, 16, 187, 107, 67, 27, - 16, 218, 254, 250, 184, 6, 27, 216, 138, 194, 93, 23, 165 - ], - Converter::<[u8; 32]>::convert(MultiLocation { - parents: 1, - interior: Here, - }) - .unwrap() - ); - } -} diff --git a/runtime/hydradx/Cargo.toml b/runtime/hydradx/Cargo.toml index ad6abbe45..77c0b6bb7 100644 --- a/runtime/hydradx/Cargo.toml +++ b/runtime/hydradx/Cargo.toml @@ -108,6 +108,7 @@ polkadot-xcm = { workspace = true } xcm-executor = { workspace = true } xcm-builder = { workspace = true } + # Substrate dependencies frame-benchmarking = { workspace = true, optional = true } frame-executive = { workspace = true } diff --git a/runtime/hydradx/src/xcm.rs b/runtime/hydradx/src/xcm.rs index e6458c677..750688175 100644 --- a/runtime/hydradx/src/xcm.rs +++ b/runtime/hydradx/src/xcm.rs @@ -309,11 +309,12 @@ pub type LocationToAccountId = ( SiblingParachainConvertsVia, // Straight up local `AccountId32` origins just alias directly to `AccountId`. AccountId32Aliases, + xcm_account_derivation::HashedDescriptionDescribeFamilyAllTerminal, + //EvmAddressConversion, // Generate remote accounts according to polkadot standards - primitives::xcm::HashedDescriptionDescribeFamilyAllTerminal, ); -// EvmAddressConversion, +// , /// Converts Account20 (ethereum) addresses to AccountId32 (substrate) addresses. pub struct EvmAddressConversion(PhantomData); impl>> xcm_executor::traits::Convert @@ -456,3 +457,157 @@ impl Contains for SafeCallFilter { ) } } +pub mod xcm_account_derivation { + use super::*; + use codec::{Compact, Encode}; + use sp_io::hashing::blake2_256; + use sp_std::{borrow::Borrow, marker::PhantomData, vec::Vec}; + //use xcm::prelude::{AccountId32, AccountKey20, Here, MultiLocation, PalletInstance, Parachain, X1}; + use xcm_executor::traits::Convert; + + /// NOTE: Copied from + /// + /// temporary struct that mimics the behavior of the upstream type that we + /// will move to once we update this repository to Polkadot 0.9.43+. + pub struct HashedDescriptionDescribeFamilyAllTerminal(PhantomData); + impl + Clone> HashedDescriptionDescribeFamilyAllTerminal { + fn describe_location_suffix(l: &MultiLocation) -> Result, ()> { + match (l.parents, &l.interior) { + (0, Here) => Ok(Vec::new()), + (0, X1(PalletInstance(i))) => Ok((b"Pallet", Compact::::from(*i as u32)).encode()), + (0, X1(AccountId32 { id, .. })) => Ok((b"AccountId32", id).encode()), + (0, X1(AccountKey20 { key, .. })) => Ok((b"AccountKey20", key).encode()), + _ => Err(()), + } + } + } + + impl + Clone> Convert + for HashedDescriptionDescribeFamilyAllTerminal + { + fn convert_ref(location: impl Borrow) -> Result { + let l = location.borrow(); + let to_hash = match (l.parents, l.interior.first()) { + (0, Some(Parachain(index))) => { + let tail = l.interior.split_first().0; + let interior = Self::describe_location_suffix(&tail.into())?; + (b"ChildChain", Compact::::from(*index), interior).encode() + } + (1, Some(Parachain(index))) => { + let tail = l.interior.split_first().0; + let interior = Self::describe_location_suffix(&tail.into())?; + (b"SiblingChain", Compact::::from(*index), interior).encode() + } + (1, _) => { + let tail = l.interior.into(); + let interior = Self::describe_location_suffix(&tail)?; + (b"ParentChain", interior).encode() + } + _ => return Err(()), + }; + Ok(blake2_256(&to_hash).into()) + } + + fn reverse_ref(_: impl Borrow) -> Result { + Err(()) + } + } + + #[test] + fn test_hashed_family_all_terminal_converter() { + use super::*; + + type Converter = HashedDescriptionDescribeFamilyAllTerminal; + + assert_eq!( + [ + 129, 211, 14, 6, 146, 54, 225, 200, 135, 103, 248, 244, 125, 112, 53, 133, 91, 42, 215, 236, 154, 199, + 191, 208, 110, 148, 223, 55, 92, 216, 250, 34 + ], + Converter::<[u8; 32]>::convert(MultiLocation { + parents: 0, + interior: X2( + Parachain(1), + AccountId32 { + network: None, + id: [0u8; 32] + } + ), + }) + .unwrap() + ); + assert_eq!( + [ + 17, 142, 105, 253, 199, 34, 43, 136, 155, 48, 12, 137, 155, 219, 155, 110, 93, 181, 93, 252, 124, 60, + 250, 195, 229, 86, 31, 220, 121, 111, 254, 252 + ], + Converter::<[u8; 32]>::convert(MultiLocation { + parents: 1, + interior: X2( + Parachain(1), + AccountId32 { + network: None, + id: [0u8; 32] + } + ), + }) + .unwrap() + ); + assert_eq!( + [ + 237, 65, 190, 49, 53, 182, 196, 183, 151, 24, 214, 23, 72, 244, 235, 87, 187, 67, 52, 122, 195, 192, + 10, 58, 253, 49, 0, 112, 175, 224, 125, 66 + ], + Converter::<[u8; 32]>::convert(MultiLocation { + parents: 0, + interior: X2( + Parachain(1), + AccountKey20 { + network: None, + key: [0u8; 20] + } + ), + }) + .unwrap() + ); + assert_eq!( + [ + 226, 225, 225, 162, 254, 156, 113, 95, 68, 155, 160, 118, 126, 18, 166, 132, 144, 19, 8, 204, 228, 112, + 164, 189, 179, 124, 249, 1, 168, 110, 151, 50 + ], + Converter::<[u8; 32]>::convert(MultiLocation { + parents: 1, + interior: X2( + Parachain(1), + AccountKey20 { + network: None, + key: [0u8; 20] + } + ), + }) + .unwrap() + ); + assert_eq!( + [ + 254, 186, 179, 229, 13, 24, 84, 36, 84, 35, 64, 95, 114, 136, 62, 69, 247, 74, 215, 104, 121, 114, 53, + 6, 124, 46, 42, 245, 121, 197, 12, 208 + ], + Converter::<[u8; 32]>::convert(MultiLocation { + parents: 1, + interior: X2(Parachain(2), PalletInstance(3)), + }) + .unwrap() + ); + assert_eq!( + [ + 217, 56, 0, 36, 228, 154, 250, 26, 200, 156, 1, 39, 254, 162, 16, 187, 107, 67, 27, 16, 218, 254, 250, + 184, 6, 27, 216, 138, 194, 93, 23, 165 + ], + Converter::<[u8; 32]>::convert(MultiLocation { + parents: 1, + interior: Here, + }) + .unwrap() + ); + } +} From 5fc205f7f2c5d39070f0b29416175badafec49c1 Mon Sep 17 00:00:00 2001 From: dmoka Date: Wed, 13 Dec 2023 15:09:50 +0100 Subject: [PATCH 13/34] fix evm tests by adding back evm address converter --- integration-tests/src/cross_chain_transfer.rs | 4 ++-- runtime/hydradx/src/xcm.rs | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/integration-tests/src/cross_chain_transfer.rs b/integration-tests/src/cross_chain_transfer.rs index 62f8662d7..c5f51fbc7 100644 --- a/integration-tests/src/cross_chain_transfer.rs +++ b/integration-tests/src/cross_chain_transfer.rs @@ -307,7 +307,6 @@ fn asd() { let amount = 30 * UNITS; Acala::execute_with(|| { - //We send toe ethereum address with Account20 assert_ok!(hydradx_runtime::XTokens::transfer( hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), 0, @@ -315,7 +314,8 @@ fn asd() { Box::new( MultiLocation::new( 1, - X2( + X3( + Junction::Parachain(HYDRA_PARA_ID), Junction::Parachain(ACALA_PARA_ID), Junction::AccountKey20 { network: None, diff --git a/runtime/hydradx/src/xcm.rs b/runtime/hydradx/src/xcm.rs index 750688175..eb89f31dd 100644 --- a/runtime/hydradx/src/xcm.rs +++ b/runtime/hydradx/src/xcm.rs @@ -309,9 +309,10 @@ pub type LocationToAccountId = ( SiblingParachainConvertsVia, // Straight up local `AccountId32` origins just alias directly to `AccountId`. AccountId32Aliases, - xcm_account_derivation::HashedDescriptionDescribeFamilyAllTerminal, - //EvmAddressConversion, // Generate remote accounts according to polkadot standards + xcm_account_derivation::HashedDescriptionDescribeFamilyAllTerminal, + // Convert ETH to local substrate account + EvmAddressConversion, ); // , From 54620c5c3da0fb42c40e731b24f4fee96a2fecac Mon Sep 17 00:00:00 2001 From: dmoka Date: Thu, 14 Dec 2023 16:29:22 +0100 Subject: [PATCH 14/34] remove invalid test --- integration-tests/src/cross_chain_transfer.rs | 56 ------------------- 1 file changed, 56 deletions(-) diff --git a/integration-tests/src/cross_chain_transfer.rs b/integration-tests/src/cross_chain_transfer.rs index c5f51fbc7..ea96cce20 100644 --- a/integration-tests/src/cross_chain_transfer.rs +++ b/integration-tests/src/cross_chain_transfer.rs @@ -292,62 +292,6 @@ fn hydra_should_receive_asset_when_transferred_from_acala_to_same_address_repres }); } -#[test] -fn asd() { - // Arrange - TestNet::reset(); - - Hydra::execute_with(|| { - assert_ok!(hydradx_runtime::AssetRegistry::set_location( - hydradx_runtime::RuntimeOrigin::root(), - ACA, - hydradx_runtime::AssetLocation(MultiLocation::new(1, X2(Parachain(ACALA_PARA_ID), GeneralIndex(0)))) - )); - }); - - let amount = 30 * UNITS; - Acala::execute_with(|| { - assert_ok!(hydradx_runtime::XTokens::transfer( - hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), - 0, - amount, - Box::new( - MultiLocation::new( - 1, - X3( - Junction::Parachain(HYDRA_PARA_ID), - Junction::Parachain(ACALA_PARA_ID), - Junction::AccountKey20 { - network: None, - key: evm_address().into(), - } - ) - ) - .into() - ), - WeightLimit::Limited(Weight::from_parts(399_600_000_000, 0)) - )); - - // Assert - assert_eq!( - hydradx_runtime::Balances::free_balance(&AccountId::from(ALICE)), - ALICE_INITIAL_NATIVE_BALANCE - amount - ); - }); - - let fee = 400641025641; - Hydra::execute_with(|| { - assert_eq!( - hydradx_runtime::Tokens::free_balance(ACA, &AccountId::from(evm_account())), - amount - fee - ); - assert_eq!( - hydradx_runtime::Tokens::free_balance(ACA, &hydradx_runtime::Treasury::account_id()), - fee // fees should go to treasury - ); - }); -} - #[test] fn transfer_from_acala_should_fail_when_transferring_insufficient_amount() { TestNet::reset(); From 26b4145a75cac9426587ada1175c1765be0de1dc Mon Sep 17 00:00:00 2001 From: dmoka Date: Thu, 14 Dec 2023 16:29:47 +0100 Subject: [PATCH 15/34] add test for verifying global account derivation --- integration-tests/src/transact_call_filter.rs | 122 ++++++++++++++++++ 1 file changed, 122 insertions(+) diff --git a/integration-tests/src/transact_call_filter.rs b/integration-tests/src/transact_call_filter.rs index eb346d770..ca5a8d877 100644 --- a/integration-tests/src/transact_call_filter.rs +++ b/integration-tests/src/transact_call_filter.rs @@ -241,3 +241,125 @@ fn safe_call_filter_should_respect_runtime_call_filter() { ))); }); } + +use hydradx_runtime::xcm_account_derivation::HashedDescriptionDescribeFamilyAllTerminal; +use orml_traits::MultiCurrency; +use xcm_executor::traits::Convert; +#[test] +fn asd() { + // Arrange + TestNet::reset(); + + let xcm_interior_at_acala = X1(Junction::AccountId32 { + network: None, + id: evm_account().into(), + }); + + let xcm_interior_at_hydra = X2( + Junction::Parachain(ACALA_PARA_ID), + Junction::AccountId32 { + network: None, + id: evm_account().into(), + }, + ); + + let xcm_origin_at_hydra = MultiLocation { + parents: 1, + interior: xcm_interior_at_hydra, + }; + + let acala_account_id_at_hydra: AccountId = + HashedDescriptionDescribeFamilyAllTerminal::convert_ref(xcm_origin_at_hydra).unwrap(); + + Hydra::execute_with(|| { + init_omnipool(); + + assert_ok!(hydradx_runtime::Balances::transfer( + hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), + acala_account_id_at_hydra.clone(), + 1_000 * UNITS, + )); + let dai_balance = + hydradx_runtime::Currencies::free_balance(DAI, &AccountId::from(acala_account_id_at_hydra.clone())); + assert_eq!(dai_balance, 0); + }); + + Acala::execute_with(|| { + // allowed by SafeCallFilter and the runtime call filter + let call = pallet_balances::Call::::transfer { + dest: BOB.into(), + value: UNITS, + }; + + let omni_sell = + hydradx_runtime::RuntimeCall::Omnipool(pallet_omnipool::Call::::sell { + asset_in: HDX, + asset_out: DAI, + amount: UNITS, + min_buy_amount: 0, + }); + + let message = Xcm(vec![ + WithdrawAsset( + ( + MultiLocation { + parents: 1, + interior: X2(Parachain(HYDRA_PARA_ID), GeneralIndex(0)), + }, + 900 * UNITS, + ) + .into(), + ), + BuyExecution { + fees: ( + MultiLocation { + parents: 1, + interior: X2(Parachain(HYDRA_PARA_ID), GeneralIndex(0)), + }, + 800 * UNITS, + ) + .into(), + weight_limit: Unlimited, + }, + Transact { + require_weight_at_most: Weight::from_parts(10_000_000_000, 0u64), + origin_kind: OriginKind::SovereignAccount, + call: omni_sell.encode().into(), + }, + ExpectTransactStatus(MaybeErrorCode::Success), + RefundSurplus, + DepositAsset { + assets: All.into(), + beneficiary: Junction::AccountId32 { + id: parachain_reserve_account().into(), + network: None, + } + .into(), + }, + ]); + + // Act + + assert_ok!(hydradx_runtime::PolkadotXcm::send_xcm( + xcm_interior_at_acala, + MultiLocation::new(1, X1(Parachain(HYDRA_PARA_ID))), + message + )); + }); + + Hydra::execute_with(|| { + // Assert + assert!(hydradx_runtime::System::events().iter().any(|r| matches!( + r.event, + hydradx_runtime::RuntimeEvent::XcmpQueue(cumulus_pallet_xcmp_queue::Event::Success { .. }) + ))); + /*assert_eq!( + hydradx_runtime::Balances::free_balance(&AccountId::from(acala_account_id_at_hydra)), + 1_000 * UNITS - UNITS + );*/ + + let dai_balance = hydradx_runtime::Currencies::free_balance(DAI, &AccountId::from(acala_account_id_at_hydra)); + assert!(dai_balance > 0); + assert_eq!(dai_balance, 26619890727267708); + }); +} From 10d68952601c4748a91af10472165642accb7fe8 Mon Sep 17 00:00:00 2001 From: dmoka Date: Thu, 14 Dec 2023 18:54:29 +0100 Subject: [PATCH 16/34] refactoring --- integration-tests/src/transact_call_filter.rs | 22 +++---------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/integration-tests/src/transact_call_filter.rs b/integration-tests/src/transact_call_filter.rs index ca5a8d877..8fcb92e65 100644 --- a/integration-tests/src/transact_call_filter.rs +++ b/integration-tests/src/transact_call_filter.rs @@ -245,8 +245,9 @@ fn safe_call_filter_should_respect_runtime_call_filter() { use hydradx_runtime::xcm_account_derivation::HashedDescriptionDescribeFamilyAllTerminal; use orml_traits::MultiCurrency; use xcm_executor::traits::Convert; + #[test] -fn asd() { +fn remove_account_should_work_on_hydra() { // Arrange TestNet::reset(); @@ -285,12 +286,6 @@ fn asd() { }); Acala::execute_with(|| { - // allowed by SafeCallFilter and the runtime call filter - let call = pallet_balances::Call::::transfer { - dest: BOB.into(), - value: UNITS, - }; - let omni_sell = hydradx_runtime::RuntimeCall::Omnipool(pallet_omnipool::Call::::sell { asset_in: HDX, @@ -326,20 +321,9 @@ fn asd() { origin_kind: OriginKind::SovereignAccount, call: omni_sell.encode().into(), }, - ExpectTransactStatus(MaybeErrorCode::Success), - RefundSurplus, - DepositAsset { - assets: All.into(), - beneficiary: Junction::AccountId32 { - id: parachain_reserve_account().into(), - network: None, - } - .into(), - }, ]); // Act - assert_ok!(hydradx_runtime::PolkadotXcm::send_xcm( xcm_interior_at_acala, MultiLocation::new(1, X1(Parachain(HYDRA_PARA_ID))), @@ -347,8 +331,8 @@ fn asd() { )); }); + // Assert Hydra::execute_with(|| { - // Assert assert!(hydradx_runtime::System::events().iter().any(|r| matches!( r.event, hydradx_runtime::RuntimeEvent::XcmpQueue(cumulus_pallet_xcmp_queue::Event::Success { .. }) From 6cae1d0ee35ded622f0562dfc2ab82d98372f7fb Mon Sep 17 00:00:00 2001 From: dmoka Date: Thu, 14 Dec 2023 18:59:32 +0100 Subject: [PATCH 17/34] adjust assertion --- integration-tests/src/transact_call_filter.rs | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/integration-tests/src/transact_call_filter.rs b/integration-tests/src/transact_call_filter.rs index 8fcb92e65..07dffd6fa 100644 --- a/integration-tests/src/transact_call_filter.rs +++ b/integration-tests/src/transact_call_filter.rs @@ -280,9 +280,11 @@ fn remove_account_should_work_on_hydra() { acala_account_id_at_hydra.clone(), 1_000 * UNITS, )); - let dai_balance = - hydradx_runtime::Currencies::free_balance(DAI, &AccountId::from(acala_account_id_at_hydra.clone())); - assert_eq!(dai_balance, 0); + + assert_eq!( + hydradx_runtime::Currencies::free_balance(DAI, &AccountId::from(acala_account_id_at_hydra.clone())), + 0 + ); }); Acala::execute_with(|| { @@ -321,6 +323,14 @@ fn remove_account_should_work_on_hydra() { origin_kind: OriginKind::SovereignAccount, call: omni_sell.encode().into(), }, + DepositAsset { + assets: All.into(), + beneficiary: Junction::AccountId32 { + id: acala_account_id_at_hydra.clone().into(), + network: None, + } + .into(), + }, ]); // Act @@ -337,13 +347,11 @@ fn remove_account_should_work_on_hydra() { r.event, hydradx_runtime::RuntimeEvent::XcmpQueue(cumulus_pallet_xcmp_queue::Event::Success { .. }) ))); - /*assert_eq!( - hydradx_runtime::Balances::free_balance(&AccountId::from(acala_account_id_at_hydra)), - 1_000 * UNITS - UNITS - );*/ let dai_balance = hydradx_runtime::Currencies::free_balance(DAI, &AccountId::from(acala_account_id_at_hydra)); - assert!(dai_balance > 0); - assert_eq!(dai_balance, 26619890727267708); + assert!( + dai_balance > 0, + "Omnipool sell swap failed as the user did not receive any DAI" + ); }); } From 370359d6747b8794faea96b4593740407cbed09c Mon Sep 17 00:00:00 2001 From: dmoka Date: Thu, 14 Dec 2023 19:02:59 +0100 Subject: [PATCH 18/34] rearrange tests --- integration-tests/src/cross_chain_transfer.rs | 7 +- .../src/global_account_derivation.rs | 121 ++++++++++++++++++ integration-tests/src/lib.rs | 1 + integration-tests/src/transact_call_filter.rs | 114 ----------------- 4 files changed, 123 insertions(+), 120 deletions(-) create mode 100644 integration-tests/src/global_account_derivation.rs diff --git a/integration-tests/src/cross_chain_transfer.rs b/integration-tests/src/cross_chain_transfer.rs index ea96cce20..96a5b6480 100644 --- a/integration-tests/src/cross_chain_transfer.rs +++ b/integration-tests/src/cross_chain_transfer.rs @@ -8,18 +8,13 @@ use polkadot_xcm::{latest::prelude::*, v3::WeightLimit, VersionedMultiAssets, Ve use cumulus_primitives_core::ParaId; use frame_support::weights::Weight; use hex_literal::hex; -use hydradx_runtime::evm::precompiles::EvmAddress; -use hydradx_runtime::evm::ExtendedAddressMapping; use orml_traits::currency::MultiCurrency; -use pallet_evm::AddressMapping; use pretty_assertions::assert_eq; use primitives::AccountId; -use sp_core::blake2_256; -use sp_core::Encode; -use sp_core::H160; use sp_core::H256; use sp_runtime::traits::{AccountIdConversion, BlakeTwo256, Hash}; use xcm_emulator::TestExt; + // Determine the hash for assets expected to be have been trapped. fn determine_hash(origin: &MultiLocation, assets: M) -> H256 where diff --git a/integration-tests/src/global_account_derivation.rs b/integration-tests/src/global_account_derivation.rs new file mode 100644 index 000000000..246972393 --- /dev/null +++ b/integration-tests/src/global_account_derivation.rs @@ -0,0 +1,121 @@ +#![cfg(test)] +use crate::polkadot_test_net::*; + +use frame_support::{assert_ok, weights::Weight}; +use sp_runtime::codec::Encode; + +use hydradx_runtime::xcm_account_derivation::HashedDescriptionDescribeFamilyAllTerminal; +use orml_traits::MultiCurrency; +use polkadot_xcm::latest::prelude::*; +use xcm_emulator::TestExt; +use xcm_executor::traits::Convert; + +#[test] +fn other_chain_remote_account_should_work_on_hydra() { + // Arrange + TestNet::reset(); + + let xcm_interior_at_acala = X1(Junction::AccountId32 { + network: None, + id: evm_account().into(), + }); + + let xcm_interior_at_hydra = X2( + Junction::Parachain(ACALA_PARA_ID), + Junction::AccountId32 { + network: None, + id: evm_account().into(), + }, + ); + + let xcm_origin_at_hydra = MultiLocation { + parents: 1, + interior: xcm_interior_at_hydra, + }; + + let acala_account_id_at_hydra: AccountId = + HashedDescriptionDescribeFamilyAllTerminal::convert_ref(xcm_origin_at_hydra).unwrap(); + + Hydra::execute_with(|| { + init_omnipool(); + + assert_ok!(hydradx_runtime::Balances::transfer( + hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), + acala_account_id_at_hydra.clone(), + 1_000 * UNITS, + )); + + assert_eq!( + hydradx_runtime::Currencies::free_balance(DAI, &AccountId::from(acala_account_id_at_hydra.clone())), + 0 + ); + }); + + Acala::execute_with(|| { + let omni_sell = + hydradx_runtime::RuntimeCall::Omnipool(pallet_omnipool::Call::::sell { + asset_in: HDX, + asset_out: DAI, + amount: UNITS, + min_buy_amount: 0, + }); + + let message = Xcm(vec![ + WithdrawAsset( + ( + MultiLocation { + parents: 1, + interior: X2(Parachain(HYDRA_PARA_ID), GeneralIndex(0)), + }, + 900 * UNITS, + ) + .into(), + ), + BuyExecution { + fees: ( + MultiLocation { + parents: 1, + interior: X2(Parachain(HYDRA_PARA_ID), GeneralIndex(0)), + }, + 800 * UNITS, + ) + .into(), + weight_limit: Unlimited, + }, + Transact { + require_weight_at_most: Weight::from_parts(10_000_000_000, 0u64), + origin_kind: OriginKind::SovereignAccount, + call: omni_sell.encode().into(), + }, + DepositAsset { + assets: All.into(), + beneficiary: Junction::AccountId32 { + id: acala_account_id_at_hydra.clone().into(), + network: None, + } + .into(), + }, + ]); + + // Act + assert_ok!(hydradx_runtime::PolkadotXcm::send_xcm( + xcm_interior_at_acala, + MultiLocation::new(1, X1(Parachain(HYDRA_PARA_ID))), + message + )); + }); + + // Assert + Hydra::execute_with(|| { + assert!(hydradx_runtime::System::events().iter().any(|r| matches!( + r.event, + hydradx_runtime::RuntimeEvent::XcmpQueue(cumulus_pallet_xcmp_queue::Event::Success { .. }) + ))); + + let dai_balance = hydradx_runtime::Currencies::free_balance(DAI, &AccountId::from(acala_account_id_at_hydra)); + assert!( + dai_balance > 0, + "Omnipool sell swap failed as the user did not receive any DAI" + ); + }); +} diff --git a/integration-tests/src/lib.rs b/integration-tests/src/lib.rs index 1dca8de52..d839468e1 100644 --- a/integration-tests/src/lib.rs +++ b/integration-tests/src/lib.rs @@ -10,6 +10,7 @@ mod dust_removal_whitelist; mod dynamic_fees; mod evm; mod exchange_asset; +mod global_account_derivation; mod non_native_fee; mod omnipool_init; mod omnipool_liquidity_mining; diff --git a/integration-tests/src/transact_call_filter.rs b/integration-tests/src/transact_call_filter.rs index 07dffd6fa..eb346d770 100644 --- a/integration-tests/src/transact_call_filter.rs +++ b/integration-tests/src/transact_call_filter.rs @@ -241,117 +241,3 @@ fn safe_call_filter_should_respect_runtime_call_filter() { ))); }); } - -use hydradx_runtime::xcm_account_derivation::HashedDescriptionDescribeFamilyAllTerminal; -use orml_traits::MultiCurrency; -use xcm_executor::traits::Convert; - -#[test] -fn remove_account_should_work_on_hydra() { - // Arrange - TestNet::reset(); - - let xcm_interior_at_acala = X1(Junction::AccountId32 { - network: None, - id: evm_account().into(), - }); - - let xcm_interior_at_hydra = X2( - Junction::Parachain(ACALA_PARA_ID), - Junction::AccountId32 { - network: None, - id: evm_account().into(), - }, - ); - - let xcm_origin_at_hydra = MultiLocation { - parents: 1, - interior: xcm_interior_at_hydra, - }; - - let acala_account_id_at_hydra: AccountId = - HashedDescriptionDescribeFamilyAllTerminal::convert_ref(xcm_origin_at_hydra).unwrap(); - - Hydra::execute_with(|| { - init_omnipool(); - - assert_ok!(hydradx_runtime::Balances::transfer( - hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), - acala_account_id_at_hydra.clone(), - 1_000 * UNITS, - )); - - assert_eq!( - hydradx_runtime::Currencies::free_balance(DAI, &AccountId::from(acala_account_id_at_hydra.clone())), - 0 - ); - }); - - Acala::execute_with(|| { - let omni_sell = - hydradx_runtime::RuntimeCall::Omnipool(pallet_omnipool::Call::::sell { - asset_in: HDX, - asset_out: DAI, - amount: UNITS, - min_buy_amount: 0, - }); - - let message = Xcm(vec![ - WithdrawAsset( - ( - MultiLocation { - parents: 1, - interior: X2(Parachain(HYDRA_PARA_ID), GeneralIndex(0)), - }, - 900 * UNITS, - ) - .into(), - ), - BuyExecution { - fees: ( - MultiLocation { - parents: 1, - interior: X2(Parachain(HYDRA_PARA_ID), GeneralIndex(0)), - }, - 800 * UNITS, - ) - .into(), - weight_limit: Unlimited, - }, - Transact { - require_weight_at_most: Weight::from_parts(10_000_000_000, 0u64), - origin_kind: OriginKind::SovereignAccount, - call: omni_sell.encode().into(), - }, - DepositAsset { - assets: All.into(), - beneficiary: Junction::AccountId32 { - id: acala_account_id_at_hydra.clone().into(), - network: None, - } - .into(), - }, - ]); - - // Act - assert_ok!(hydradx_runtime::PolkadotXcm::send_xcm( - xcm_interior_at_acala, - MultiLocation::new(1, X1(Parachain(HYDRA_PARA_ID))), - message - )); - }); - - // Assert - Hydra::execute_with(|| { - assert!(hydradx_runtime::System::events().iter().any(|r| matches!( - r.event, - hydradx_runtime::RuntimeEvent::XcmpQueue(cumulus_pallet_xcmp_queue::Event::Success { .. }) - ))); - - let dai_balance = hydradx_runtime::Currencies::free_balance(DAI, &AccountId::from(acala_account_id_at_hydra)); - assert!( - dai_balance > 0, - "Omnipool sell swap failed as the user did not receive any DAI" - ); - }); -} From 4c251ab71485253bf3cafdc04bc16a9edcfb374f Mon Sep 17 00:00:00 2001 From: dmoka Date: Thu, 14 Dec 2023 19:09:45 +0100 Subject: [PATCH 19/34] replace account derivation logic to adapters --- .../src/global_account_derivation.rs | 18 +- runtime/adapters/src/lib.rs | 1 + .../adapters/src/xcm_account_derivation.rs | 151 +++++++++++++++++ runtime/hydradx/src/xcm.rs | 156 +----------------- 4 files changed, 161 insertions(+), 165 deletions(-) create mode 100644 runtime/adapters/src/xcm_account_derivation.rs diff --git a/integration-tests/src/global_account_derivation.rs b/integration-tests/src/global_account_derivation.rs index 246972393..06a539eef 100644 --- a/integration-tests/src/global_account_derivation.rs +++ b/integration-tests/src/global_account_derivation.rs @@ -4,7 +4,7 @@ use crate::polkadot_test_net::*; use frame_support::{assert_ok, weights::Weight}; use sp_runtime::codec::Encode; -use hydradx_runtime::xcm_account_derivation::HashedDescriptionDescribeFamilyAllTerminal; +use hydradx_adapters::xcm_account_derivation::HashedDescriptionDescribeFamilyAllTerminal; use orml_traits::MultiCurrency; use polkadot_xcm::latest::prelude::*; use xcm_emulator::TestExt; @@ -20,17 +20,15 @@ fn other_chain_remote_account_should_work_on_hydra() { id: evm_account().into(), }); - let xcm_interior_at_hydra = X2( - Junction::Parachain(ACALA_PARA_ID), - Junction::AccountId32 { - network: None, - id: evm_account().into(), - }, - ); - let xcm_origin_at_hydra = MultiLocation { parents: 1, - interior: xcm_interior_at_hydra, + interior: X2( + Junction::Parachain(ACALA_PARA_ID), + Junction::AccountId32 { + network: None, + id: evm_account().into(), + }, + ), }; let acala_account_id_at_hydra: AccountId = diff --git a/runtime/adapters/src/lib.rs b/runtime/adapters/src/lib.rs index ae0d23ef4..9ca0550b6 100644 --- a/runtime/adapters/src/lib.rs +++ b/runtime/adapters/src/lib.rs @@ -61,6 +61,7 @@ use xcm_executor::{ }; pub mod inspect; +pub mod xcm_account_derivation; pub mod xcm_exchange; pub mod xcm_execute_filter; diff --git a/runtime/adapters/src/xcm_account_derivation.rs b/runtime/adapters/src/xcm_account_derivation.rs new file mode 100644 index 000000000..5dcce19c2 --- /dev/null +++ b/runtime/adapters/src/xcm_account_derivation.rs @@ -0,0 +1,151 @@ +use super::*; +use codec::{Compact, Encode}; +use sp_io::hashing::blake2_256; +use sp_std::{borrow::Borrow, marker::PhantomData, vec::Vec}; +use xcm_executor::traits::Convert; + +/// NOTE: Copied from +/// +/// temporary struct that mimics the behavior of the upstream type that we +/// will move to once we update this repository to Polkadot 0.9.43+. +pub struct HashedDescriptionDescribeFamilyAllTerminal(PhantomData); +impl + Clone> HashedDescriptionDescribeFamilyAllTerminal { + fn describe_location_suffix(l: &MultiLocation) -> Result, ()> { + match (l.parents, &l.interior) { + (0, Here) => Ok(Vec::new()), + (0, X1(PalletInstance(i))) => Ok((b"Pallet", Compact::::from(*i as u32)).encode()), + (0, X1(AccountId32 { id, .. })) => Ok((b"AccountId32", id).encode()), + (0, X1(AccountKey20 { key, .. })) => Ok((b"AccountKey20", key).encode()), + _ => Err(()), + } + } +} + +impl + Clone> Convert + for HashedDescriptionDescribeFamilyAllTerminal +{ + fn convert_ref(location: impl Borrow) -> Result { + let l = location.borrow(); + let to_hash = match (l.parents, l.interior.first()) { + (0, Some(Parachain(index))) => { + let tail = l.interior.split_first().0; + let interior = Self::describe_location_suffix(&tail.into())?; + (b"ChildChain", Compact::::from(*index), interior).encode() + } + (1, Some(Parachain(index))) => { + let tail = l.interior.split_first().0; + let interior = Self::describe_location_suffix(&tail.into())?; + (b"SiblingChain", Compact::::from(*index), interior).encode() + } + (1, _) => { + let tail = l.interior.into(); + let interior = Self::describe_location_suffix(&tail)?; + (b"ParentChain", interior).encode() + } + _ => return Err(()), + }; + Ok(blake2_256(&to_hash).into()) + } + + fn reverse_ref(_: impl Borrow) -> Result { + Err(()) + } +} + +#[test] +fn test_hashed_family_all_terminal_converter() { + use super::*; + + type Converter = HashedDescriptionDescribeFamilyAllTerminal; + + assert_eq!( + [ + 129, 211, 14, 6, 146, 54, 225, 200, 135, 103, 248, 244, 125, 112, 53, 133, 91, 42, 215, 236, 154, 199, 191, + 208, 110, 148, 223, 55, 92, 216, 250, 34 + ], + Converter::<[u8; 32]>::convert(MultiLocation { + parents: 0, + interior: X2( + Parachain(1), + AccountId32 { + network: None, + id: [0u8; 32] + } + ), + }) + .unwrap() + ); + assert_eq!( + [ + 17, 142, 105, 253, 199, 34, 43, 136, 155, 48, 12, 137, 155, 219, 155, 110, 93, 181, 93, 252, 124, 60, 250, + 195, 229, 86, 31, 220, 121, 111, 254, 252 + ], + Converter::<[u8; 32]>::convert(MultiLocation { + parents: 1, + interior: X2( + Parachain(1), + AccountId32 { + network: None, + id: [0u8; 32] + } + ), + }) + .unwrap() + ); + assert_eq!( + [ + 237, 65, 190, 49, 53, 182, 196, 183, 151, 24, 214, 23, 72, 244, 235, 87, 187, 67, 52, 122, 195, 192, 10, + 58, 253, 49, 0, 112, 175, 224, 125, 66 + ], + Converter::<[u8; 32]>::convert(MultiLocation { + parents: 0, + interior: X2( + Parachain(1), + AccountKey20 { + network: None, + key: [0u8; 20] + } + ), + }) + .unwrap() + ); + assert_eq!( + [ + 226, 225, 225, 162, 254, 156, 113, 95, 68, 155, 160, 118, 126, 18, 166, 132, 144, 19, 8, 204, 228, 112, + 164, 189, 179, 124, 249, 1, 168, 110, 151, 50 + ], + Converter::<[u8; 32]>::convert(MultiLocation { + parents: 1, + interior: X2( + Parachain(1), + AccountKey20 { + network: None, + key: [0u8; 20] + } + ), + }) + .unwrap() + ); + assert_eq!( + [ + 254, 186, 179, 229, 13, 24, 84, 36, 84, 35, 64, 95, 114, 136, 62, 69, 247, 74, 215, 104, 121, 114, 53, 6, + 124, 46, 42, 245, 121, 197, 12, 208 + ], + Converter::<[u8; 32]>::convert(MultiLocation { + parents: 1, + interior: X2(Parachain(2), PalletInstance(3)), + }) + .unwrap() + ); + assert_eq!( + [ + 217, 56, 0, 36, 228, 154, 250, 26, 200, 156, 1, 39, 254, 162, 16, 187, 107, 67, 27, 16, 218, 254, 250, 184, + 6, 27, 216, 138, 194, 93, 23, 165 + ], + Converter::<[u8; 32]>::convert(MultiLocation { + parents: 1, + interior: Here, + }) + .unwrap() + ); +} diff --git a/runtime/hydradx/src/xcm.rs b/runtime/hydradx/src/xcm.rs index eb89f31dd..ab5f7c8da 100644 --- a/runtime/hydradx/src/xcm.rs +++ b/runtime/hydradx/src/xcm.rs @@ -2,7 +2,7 @@ use super::*; use sp_std::marker::PhantomData; use codec::MaxEncodedLen; -use hydradx_adapters::RelayChainBlockNumberProvider; +use hydradx_adapters::{xcm_account_derivation, RelayChainBlockNumberProvider}; use hydradx_adapters::{MultiCurrencyTrader, ReroutingMultiCurrencyAdapter, ToFeeReceiver}; use pallet_transaction_multi_payment::DepositAll; use primitives::AssetId; // shadow glob import of polkadot_xcm::v3::prelude::AssetId @@ -458,157 +458,3 @@ impl Contains for SafeCallFilter { ) } } -pub mod xcm_account_derivation { - use super::*; - use codec::{Compact, Encode}; - use sp_io::hashing::blake2_256; - use sp_std::{borrow::Borrow, marker::PhantomData, vec::Vec}; - //use xcm::prelude::{AccountId32, AccountKey20, Here, MultiLocation, PalletInstance, Parachain, X1}; - use xcm_executor::traits::Convert; - - /// NOTE: Copied from - /// - /// temporary struct that mimics the behavior of the upstream type that we - /// will move to once we update this repository to Polkadot 0.9.43+. - pub struct HashedDescriptionDescribeFamilyAllTerminal(PhantomData); - impl + Clone> HashedDescriptionDescribeFamilyAllTerminal { - fn describe_location_suffix(l: &MultiLocation) -> Result, ()> { - match (l.parents, &l.interior) { - (0, Here) => Ok(Vec::new()), - (0, X1(PalletInstance(i))) => Ok((b"Pallet", Compact::::from(*i as u32)).encode()), - (0, X1(AccountId32 { id, .. })) => Ok((b"AccountId32", id).encode()), - (0, X1(AccountKey20 { key, .. })) => Ok((b"AccountKey20", key).encode()), - _ => Err(()), - } - } - } - - impl + Clone> Convert - for HashedDescriptionDescribeFamilyAllTerminal - { - fn convert_ref(location: impl Borrow) -> Result { - let l = location.borrow(); - let to_hash = match (l.parents, l.interior.first()) { - (0, Some(Parachain(index))) => { - let tail = l.interior.split_first().0; - let interior = Self::describe_location_suffix(&tail.into())?; - (b"ChildChain", Compact::::from(*index), interior).encode() - } - (1, Some(Parachain(index))) => { - let tail = l.interior.split_first().0; - let interior = Self::describe_location_suffix(&tail.into())?; - (b"SiblingChain", Compact::::from(*index), interior).encode() - } - (1, _) => { - let tail = l.interior.into(); - let interior = Self::describe_location_suffix(&tail)?; - (b"ParentChain", interior).encode() - } - _ => return Err(()), - }; - Ok(blake2_256(&to_hash).into()) - } - - fn reverse_ref(_: impl Borrow) -> Result { - Err(()) - } - } - - #[test] - fn test_hashed_family_all_terminal_converter() { - use super::*; - - type Converter = HashedDescriptionDescribeFamilyAllTerminal; - - assert_eq!( - [ - 129, 211, 14, 6, 146, 54, 225, 200, 135, 103, 248, 244, 125, 112, 53, 133, 91, 42, 215, 236, 154, 199, - 191, 208, 110, 148, 223, 55, 92, 216, 250, 34 - ], - Converter::<[u8; 32]>::convert(MultiLocation { - parents: 0, - interior: X2( - Parachain(1), - AccountId32 { - network: None, - id: [0u8; 32] - } - ), - }) - .unwrap() - ); - assert_eq!( - [ - 17, 142, 105, 253, 199, 34, 43, 136, 155, 48, 12, 137, 155, 219, 155, 110, 93, 181, 93, 252, 124, 60, - 250, 195, 229, 86, 31, 220, 121, 111, 254, 252 - ], - Converter::<[u8; 32]>::convert(MultiLocation { - parents: 1, - interior: X2( - Parachain(1), - AccountId32 { - network: None, - id: [0u8; 32] - } - ), - }) - .unwrap() - ); - assert_eq!( - [ - 237, 65, 190, 49, 53, 182, 196, 183, 151, 24, 214, 23, 72, 244, 235, 87, 187, 67, 52, 122, 195, 192, - 10, 58, 253, 49, 0, 112, 175, 224, 125, 66 - ], - Converter::<[u8; 32]>::convert(MultiLocation { - parents: 0, - interior: X2( - Parachain(1), - AccountKey20 { - network: None, - key: [0u8; 20] - } - ), - }) - .unwrap() - ); - assert_eq!( - [ - 226, 225, 225, 162, 254, 156, 113, 95, 68, 155, 160, 118, 126, 18, 166, 132, 144, 19, 8, 204, 228, 112, - 164, 189, 179, 124, 249, 1, 168, 110, 151, 50 - ], - Converter::<[u8; 32]>::convert(MultiLocation { - parents: 1, - interior: X2( - Parachain(1), - AccountKey20 { - network: None, - key: [0u8; 20] - } - ), - }) - .unwrap() - ); - assert_eq!( - [ - 254, 186, 179, 229, 13, 24, 84, 36, 84, 35, 64, 95, 114, 136, 62, 69, 247, 74, 215, 104, 121, 114, 53, - 6, 124, 46, 42, 245, 121, 197, 12, 208 - ], - Converter::<[u8; 32]>::convert(MultiLocation { - parents: 1, - interior: X2(Parachain(2), PalletInstance(3)), - }) - .unwrap() - ); - assert_eq!( - [ - 217, 56, 0, 36, 228, 154, 250, 26, 200, 156, 1, 39, 254, 162, 16, 187, 107, 67, 27, 16, 218, 254, 250, - 184, 6, 27, 216, 138, 194, 93, 23, 165 - ], - Converter::<[u8; 32]>::convert(MultiLocation { - parents: 1, - interior: Here, - }) - .unwrap() - ); - } -} From 313d5282c10cd27213852517abe734663de76675 Mon Sep 17 00:00:00 2001 From: dmoka Date: Thu, 14 Dec 2023 19:13:11 +0100 Subject: [PATCH 20/34] remove unused dependency --- primitives/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/primitives/Cargo.toml b/primitives/Cargo.toml index 2fb8fed8d..2edc5a180 100644 --- a/primitives/Cargo.toml +++ b/primitives/Cargo.toml @@ -16,7 +16,6 @@ static_assertions = "1.1.0" frame-support = { workspace = true } sp-core = { workspace = true } sp-std = { workspace = true } -sp-io = { workspace = true } # Polkadot dependencies polkadot-primitives = { workspace = true } From c93a16c026182737f9dcd44d824424169babeb87 Mon Sep 17 00:00:00 2001 From: dmoka Date: Fri, 15 Dec 2023 08:44:38 +0100 Subject: [PATCH 21/34] bump version --- Cargo.lock | 3 +-- runtime/adapters/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fd5bf8dce..ae24cf2b7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4176,7 +4176,7 @@ dependencies = [ [[package]] name = "hydradx-adapters" -version = "0.6.7" +version = "0.6.8" dependencies = [ "cumulus-pallet-parachain-system", "cumulus-primitives-core", @@ -10002,7 +10002,6 @@ dependencies = [ "scale-info", "serde", "sp-core", - "sp-io", "sp-std", "static_assertions", ] diff --git a/runtime/adapters/Cargo.toml b/runtime/adapters/Cargo.toml index 163b14ace..42c619673 100644 --- a/runtime/adapters/Cargo.toml +++ b/runtime/adapters/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hydradx-adapters" -version = "0.6.7" +version = "0.6.8" description = "Structs and other generic types for building runtimes." authors = ["GalacticCouncil"] edition = "2021" From 04b3998319619c430c12c5d239d7fd6ab1339389 Mon Sep 17 00:00:00 2001 From: dmoka Date: Fri, 15 Dec 2023 08:47:21 +0100 Subject: [PATCH 22/34] replace tests --- runtime/adapters/src/tests/mod.rs | 1 + .../src/tests/xcm_account_derivation.rs | 100 ++++++++++++++++++ .../adapters/src/xcm_account_derivation.rs | 98 ----------------- 3 files changed, 101 insertions(+), 98 deletions(-) create mode 100644 runtime/adapters/src/tests/xcm_account_derivation.rs diff --git a/runtime/adapters/src/tests/mod.rs b/runtime/adapters/src/tests/mod.rs index 504f68420..b4e321875 100644 --- a/runtime/adapters/src/tests/mod.rs +++ b/runtime/adapters/src/tests/mod.rs @@ -1,4 +1,5 @@ pub mod mock; pub mod trader; +pub mod xcm_account_derivation; pub mod xcm_exchange; pub mod xcm_execute_filter; diff --git a/runtime/adapters/src/tests/xcm_account_derivation.rs b/runtime/adapters/src/tests/xcm_account_derivation.rs new file mode 100644 index 000000000..8178bdb48 --- /dev/null +++ b/runtime/adapters/src/tests/xcm_account_derivation.rs @@ -0,0 +1,100 @@ +use crate::xcm_account_derivation::HashedDescriptionDescribeFamilyAllTerminal; +use polkadot_xcm::latest::prelude::*; +use pretty_assertions::assert_eq; +use xcm_executor::traits::Convert; + +#[test] +fn test_hashed_family_all_terminal_converter() { + type Converter = HashedDescriptionDescribeFamilyAllTerminal; + + assert_eq!( + [ + 129, 211, 14, 6, 146, 54, 225, 200, 135, 103, 248, 244, 125, 112, 53, 133, 91, 42, 215, 236, 154, 199, 191, + 208, 110, 148, 223, 55, 92, 216, 250, 34 + ], + Converter::<[u8; 32]>::convert(MultiLocation { + parents: 0, + interior: X2( + Parachain(1), + AccountId32 { + network: None, + id: [0u8; 32] + } + ), + }) + .unwrap() + ); + assert_eq!( + [ + 17, 142, 105, 253, 199, 34, 43, 136, 155, 48, 12, 137, 155, 219, 155, 110, 93, 181, 93, 252, 124, 60, 250, + 195, 229, 86, 31, 220, 121, 111, 254, 252 + ], + Converter::<[u8; 32]>::convert(MultiLocation { + parents: 1, + interior: X2( + Parachain(1), + AccountId32 { + network: None, + id: [0u8; 32] + } + ), + }) + .unwrap() + ); + assert_eq!( + [ + 237, 65, 190, 49, 53, 182, 196, 183, 151, 24, 214, 23, 72, 244, 235, 87, 187, 67, 52, 122, 195, 192, 10, + 58, 253, 49, 0, 112, 175, 224, 125, 66 + ], + Converter::<[u8; 32]>::convert(MultiLocation { + parents: 0, + interior: X2( + Parachain(1), + AccountKey20 { + network: None, + key: [0u8; 20] + } + ), + }) + .unwrap() + ); + assert_eq!( + [ + 226, 225, 225, 162, 254, 156, 113, 95, 68, 155, 160, 118, 126, 18, 166, 132, 144, 19, 8, 204, 228, 112, + 164, 189, 179, 124, 249, 1, 168, 110, 151, 50 + ], + Converter::<[u8; 32]>::convert(MultiLocation { + parents: 1, + interior: X2( + Parachain(1), + AccountKey20 { + network: None, + key: [0u8; 20] + } + ), + }) + .unwrap() + ); + assert_eq!( + [ + 254, 186, 179, 229, 13, 24, 84, 36, 84, 35, 64, 95, 114, 136, 62, 69, 247, 74, 215, 104, 121, 114, 53, 6, + 124, 46, 42, 245, 121, 197, 12, 208 + ], + Converter::<[u8; 32]>::convert(MultiLocation { + parents: 1, + interior: X2(Parachain(2), PalletInstance(3)), + }) + .unwrap() + ); + assert_eq!( + [ + 217, 56, 0, 36, 228, 154, 250, 26, 200, 156, 1, 39, 254, 162, 16, 187, 107, 67, 27, 16, 218, 254, 250, 184, + 6, 27, 216, 138, 194, 93, 23, 165 + ], + Converter::<[u8; 32]>::convert(MultiLocation { + parents: 1, + interior: Here, + }) + .unwrap() + ); +} diff --git a/runtime/adapters/src/xcm_account_derivation.rs b/runtime/adapters/src/xcm_account_derivation.rs index 5dcce19c2..e0d6746b1 100644 --- a/runtime/adapters/src/xcm_account_derivation.rs +++ b/runtime/adapters/src/xcm_account_derivation.rs @@ -51,101 +51,3 @@ impl + Clone> Convert Err(()) } } - -#[test] -fn test_hashed_family_all_terminal_converter() { - use super::*; - - type Converter = HashedDescriptionDescribeFamilyAllTerminal; - - assert_eq!( - [ - 129, 211, 14, 6, 146, 54, 225, 200, 135, 103, 248, 244, 125, 112, 53, 133, 91, 42, 215, 236, 154, 199, 191, - 208, 110, 148, 223, 55, 92, 216, 250, 34 - ], - Converter::<[u8; 32]>::convert(MultiLocation { - parents: 0, - interior: X2( - Parachain(1), - AccountId32 { - network: None, - id: [0u8; 32] - } - ), - }) - .unwrap() - ); - assert_eq!( - [ - 17, 142, 105, 253, 199, 34, 43, 136, 155, 48, 12, 137, 155, 219, 155, 110, 93, 181, 93, 252, 124, 60, 250, - 195, 229, 86, 31, 220, 121, 111, 254, 252 - ], - Converter::<[u8; 32]>::convert(MultiLocation { - parents: 1, - interior: X2( - Parachain(1), - AccountId32 { - network: None, - id: [0u8; 32] - } - ), - }) - .unwrap() - ); - assert_eq!( - [ - 237, 65, 190, 49, 53, 182, 196, 183, 151, 24, 214, 23, 72, 244, 235, 87, 187, 67, 52, 122, 195, 192, 10, - 58, 253, 49, 0, 112, 175, 224, 125, 66 - ], - Converter::<[u8; 32]>::convert(MultiLocation { - parents: 0, - interior: X2( - Parachain(1), - AccountKey20 { - network: None, - key: [0u8; 20] - } - ), - }) - .unwrap() - ); - assert_eq!( - [ - 226, 225, 225, 162, 254, 156, 113, 95, 68, 155, 160, 118, 126, 18, 166, 132, 144, 19, 8, 204, 228, 112, - 164, 189, 179, 124, 249, 1, 168, 110, 151, 50 - ], - Converter::<[u8; 32]>::convert(MultiLocation { - parents: 1, - interior: X2( - Parachain(1), - AccountKey20 { - network: None, - key: [0u8; 20] - } - ), - }) - .unwrap() - ); - assert_eq!( - [ - 254, 186, 179, 229, 13, 24, 84, 36, 84, 35, 64, 95, 114, 136, 62, 69, 247, 74, 215, 104, 121, 114, 53, 6, - 124, 46, 42, 245, 121, 197, 12, 208 - ], - Converter::<[u8; 32]>::convert(MultiLocation { - parents: 1, - interior: X2(Parachain(2), PalletInstance(3)), - }) - .unwrap() - ); - assert_eq!( - [ - 217, 56, 0, 36, 228, 154, 250, 26, 200, 156, 1, 39, 254, 162, 16, 187, 107, 67, 27, 16, 218, 254, 250, 184, - 6, 27, 216, 138, 194, 93, 23, 165 - ], - Converter::<[u8; 32]>::convert(MultiLocation { - parents: 1, - interior: Here, - }) - .unwrap() - ); -} From a32799c9e026f03cfc3adad205b2d179a69800e5 Mon Sep 17 00:00:00 2001 From: dmoka Date: Fri, 15 Dec 2023 09:06:07 +0100 Subject: [PATCH 23/34] fix typos in comments --- integration-tests/src/cross_chain_transfer.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/integration-tests/src/cross_chain_transfer.rs b/integration-tests/src/cross_chain_transfer.rs index 96a5b6480..89d78152a 100644 --- a/integration-tests/src/cross_chain_transfer.rs +++ b/integration-tests/src/cross_chain_transfer.rs @@ -170,7 +170,7 @@ fn hydra_should_receive_asset_when_transferred_from_acala_to_eth_address() { let amount = 30 * UNITS; Acala::execute_with(|| { - //We send toe ethereum address with Account20 + //We send to ethereum address with Account20 assert_ok!(hydradx_runtime::XTokens::transfer( hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), 0, @@ -225,7 +225,7 @@ fn hydra_should_receive_asset_when_transferred_from_acala_to_same_address_repres let amount = 30 * UNITS; Acala::execute_with(|| { - //We send toe ethereum address with Account20 + //We send to ethereum address with Account20 assert_ok!(hydradx_runtime::XTokens::transfer( hydradx_runtime::RuntimeOrigin::signed(ALICE.into()), 0, From 16d52ef522062e33a8f0cd10c56bffae5b2c349d Mon Sep 17 00:00:00 2001 From: dmoka Date: Fri, 15 Dec 2023 09:09:32 +0100 Subject: [PATCH 24/34] clean up --- integration-tests/src/global_account_derivation.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration-tests/src/global_account_derivation.rs b/integration-tests/src/global_account_derivation.rs index 06a539eef..0212ef273 100644 --- a/integration-tests/src/global_account_derivation.rs +++ b/integration-tests/src/global_account_derivation.rs @@ -49,6 +49,7 @@ fn other_chain_remote_account_should_work_on_hydra() { ); }); + // Act Acala::execute_with(|| { let omni_sell = hydradx_runtime::RuntimeCall::Omnipool(pallet_omnipool::Call::::sell { @@ -95,7 +96,6 @@ fn other_chain_remote_account_should_work_on_hydra() { }, ]); - // Act assert_ok!(hydradx_runtime::PolkadotXcm::send_xcm( xcm_interior_at_acala, MultiLocation::new(1, X1(Parachain(HYDRA_PARA_ID))), From 9b630c149acb6b8e827dc738c383d3bf530f8162 Mon Sep 17 00:00:00 2001 From: mrq Date: Thu, 22 Feb 2024 18:04:30 +0100 Subject: [PATCH 25/34] fmt --- runtime/adapters/src/lib.rs | 2 +- runtime/hydradx/src/xcm.rs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/runtime/adapters/src/lib.rs b/runtime/adapters/src/lib.rs index 8ecebeb23..65e347838 100644 --- a/runtime/adapters/src/lib.rs +++ b/runtime/adapters/src/lib.rs @@ -61,8 +61,8 @@ use xcm_executor::{ }; pub mod inspect; -pub mod xcm_account_derivation; pub mod price; +pub mod xcm_account_derivation; pub mod xcm_exchange; pub mod xcm_execute_filter; diff --git a/runtime/hydradx/src/xcm.rs b/runtime/hydradx/src/xcm.rs index f0a58271a..f1d327372 100644 --- a/runtime/hydradx/src/xcm.rs +++ b/runtime/hydradx/src/xcm.rs @@ -3,7 +3,8 @@ use sp_std::marker::PhantomData; use codec::MaxEncodedLen; use hydradx_adapters::{ - xcm_account_derivation, MultiCurrencyTrader, RelayChainBlockNumberProvider, ReroutingMultiCurrencyAdapter, ToFeeReceiver, + xcm_account_derivation, MultiCurrencyTrader, RelayChainBlockNumberProvider, ReroutingMultiCurrencyAdapter, + ToFeeReceiver, }; use pallet_transaction_multi_payment::DepositAll; use primitives::AssetId; // shadow glob import of polkadot_xcm::v3::prelude::AssetId From fd1be3e16250678d35532e2fc9f739d3e21c2dd0 Mon Sep 17 00:00:00 2001 From: dmoka Date: Tue, 27 Feb 2024 07:54:58 +0100 Subject: [PATCH 26/34] fix compilation error --- integration-tests/src/cross_chain_transfer.rs | 4 +-- .../src/global_account_derivation.rs | 7 +++-- .../adapters/src/xcm_account_derivation.rs | 20 +++++-------- runtime/hydradx/src/system.rs | 6 ++-- runtime/hydradx/src/xcm.rs | 28 +++++++------------ 5 files changed, 26 insertions(+), 39 deletions(-) diff --git a/integration-tests/src/cross_chain_transfer.rs b/integration-tests/src/cross_chain_transfer.rs index b68e02512..b73bf400c 100644 --- a/integration-tests/src/cross_chain_transfer.rs +++ b/integration-tests/src/cross_chain_transfer.rs @@ -162,7 +162,6 @@ fn hydra_should_receive_asset_when_transferred_from_acala_to_eth_address() { Hydra::execute_with(|| { assert_ok!(hydradx_runtime::AssetRegistry::set_location( - hydradx_runtime::RuntimeOrigin::root(), ACA, hydradx_runtime::AssetLocation(MultiLocation::new(1, X2(Parachain(ACALA_PARA_ID), GeneralIndex(0)))) )); @@ -217,7 +216,6 @@ fn hydra_should_receive_asset_when_transferred_from_acala_to_same_address_repres Hydra::execute_with(|| { assert_ok!(hydradx_runtime::AssetRegistry::set_location( - hydradx_runtime::RuntimeOrigin::root(), ACA, hydradx_runtime::AssetLocation(MultiLocation::new(1, X2(Parachain(ACALA_PARA_ID), GeneralIndex(0)))) )); @@ -264,7 +262,7 @@ fn hydra_should_receive_asset_when_transferred_from_acala_to_same_address_repres ) .into() ), - WeightLimit::Limited(Weight::from_ref_time(399_600_000_000)) + WeightLimit::Limited(Weight::from_parts(399_600_000_000, 0)) )); // Assert diff --git a/integration-tests/src/global_account_derivation.rs b/integration-tests/src/global_account_derivation.rs index 0212ef273..e240a40d1 100644 --- a/integration-tests/src/global_account_derivation.rs +++ b/integration-tests/src/global_account_derivation.rs @@ -8,8 +8,7 @@ use hydradx_adapters::xcm_account_derivation::HashedDescriptionDescribeFamilyAll use orml_traits::MultiCurrency; use polkadot_xcm::latest::prelude::*; use xcm_emulator::TestExt; -use xcm_executor::traits::Convert; - +use xcm_emulator::ConvertLocation; #[test] fn other_chain_remote_account_should_work_on_hydra() { // Arrange @@ -32,7 +31,7 @@ fn other_chain_remote_account_should_work_on_hydra() { }; let acala_account_id_at_hydra: AccountId = - HashedDescriptionDescribeFamilyAllTerminal::convert_ref(xcm_origin_at_hydra).unwrap(); + HashedDescriptionDescribeFamilyAllTerminal::convert_location(&xcm_origin_at_hydra).unwrap(); Hydra::execute_with(|| { init_omnipool(); @@ -86,6 +85,8 @@ fn other_chain_remote_account_should_work_on_hydra() { origin_kind: OriginKind::SovereignAccount, call: omni_sell.encode().into(), }, + ExpectTransactStatus(MaybeErrorCode::Success), + RefundSurplus, DepositAsset { assets: All.into(), beneficiary: Junction::AccountId32 { diff --git a/runtime/adapters/src/xcm_account_derivation.rs b/runtime/adapters/src/xcm_account_derivation.rs index e0d6746b1..378844822 100644 --- a/runtime/adapters/src/xcm_account_derivation.rs +++ b/runtime/adapters/src/xcm_account_derivation.rs @@ -2,8 +2,6 @@ use super::*; use codec::{Compact, Encode}; use sp_io::hashing::blake2_256; use sp_std::{borrow::Borrow, marker::PhantomData, vec::Vec}; -use xcm_executor::traits::Convert; - /// NOTE: Copied from /// /// temporary struct that mimics the behavior of the upstream type that we @@ -21,33 +19,29 @@ impl + Clone> HashedDescriptionDescribeFamilyAllTermin } } -impl + Clone> Convert +impl + Clone> ConvertLocation for HashedDescriptionDescribeFamilyAllTerminal { - fn convert_ref(location: impl Borrow) -> Result { + fn convert_location(location: &MultiLocation) -> Option { let l = location.borrow(); let to_hash = match (l.parents, l.interior.first()) { (0, Some(Parachain(index))) => { let tail = l.interior.split_first().0; - let interior = Self::describe_location_suffix(&tail.into())?; + let interior = Self::describe_location_suffix(&tail.into()).ok()?; (b"ChildChain", Compact::::from(*index), interior).encode() } (1, Some(Parachain(index))) => { let tail = l.interior.split_first().0; - let interior = Self::describe_location_suffix(&tail.into())?; + let interior = Self::describe_location_suffix(&tail.into()).ok()?; (b"SiblingChain", Compact::::from(*index), interior).encode() } (1, _) => { let tail = l.interior.into(); - let interior = Self::describe_location_suffix(&tail)?; + let interior = Self::describe_location_suffix(&tail).ok()?; (b"ParentChain", interior).encode() } - _ => return Err(()), + _ => return None, }; - Ok(blake2_256(&to_hash).into()) - } - - fn reverse_ref(_: impl Borrow) -> Result { - Err(()) + Some(blake2_256(&to_hash).into()) } } diff --git a/runtime/hydradx/src/system.rs b/runtime/hydradx/src/system.rs index d17300846..3853f9d00 100644 --- a/runtime/hydradx/src/system.rs +++ b/runtime/hydradx/src/system.rs @@ -93,7 +93,7 @@ impl Contains for CallFilter { } } - match call { + let m = match call { RuntimeCall::PolkadotXcm(pallet_xcm::Call::send { .. }) => true, // create and create2 are only allowed through RPC or Runtime API RuntimeCall::EVM(pallet_evm::Call::create { .. }) => false, @@ -101,7 +101,9 @@ impl Contains for CallFilter { RuntimeCall::PolkadotXcm(_) => false, RuntimeCall::OrmlXcm(_) => false, _ => true, - } + }; + let d = m.clone(); + m } } diff --git a/runtime/hydradx/src/xcm.rs b/runtime/hydradx/src/xcm.rs index f1d327372..de6c5c6c4 100644 --- a/runtime/hydradx/src/xcm.rs +++ b/runtime/hydradx/src/xcm.rs @@ -362,33 +362,22 @@ pub type LocationToAccountId = ( // Convert ETH to local substrate account EvmAddressConversion, ); +use xcm_executor::traits::ConvertLocation; -// , /// Converts Account20 (ethereum) addresses to AccountId32 (substrate) addresses. pub struct EvmAddressConversion(PhantomData); -impl>> xcm_executor::traits::Convert - for EvmAddressConversion -{ - fn convert(location: MultiLocation) -> Result { +impl>> ConvertLocation for EvmAddressConversion { + fn convert_location(location: &MultiLocation) -> Option { match location { MultiLocation { parents: 0, interior: X1(AccountKey20 { network: _, key }), } => { let account_32 = ExtendedAddressMapping::into_account_id(H160::from(key)); - Ok(account_32) + Some(account_32) } - _ => Err(location), - } - } - - //TODO: fix this reverse - fn reverse(who: AccountId) -> Result { - Ok(AccountId32 { - id: who.into(), - network: Network::get(), + _ => None, } - .into()) } } @@ -440,7 +429,7 @@ impl Contains for SafeCallFilter { return false; } - matches!( + let s = matches!( call, RuntimeCall::System(frame_system::Call::kill_prefix { .. } | frame_system::Call::set_heap_pages { .. }) | RuntimeCall::Timestamp(..) @@ -504,6 +493,9 @@ impl Contains for SafeCallFilter { | RuntimeCall::Currencies(..) | RuntimeCall::Tokens(..) | RuntimeCall::OrmlXcm(..) - ) + ); + let d = 3; + let k = s; + s } } From 91c091cb2024d4f4f404548b86a6878e9049a331 Mon Sep 17 00:00:00 2001 From: dmoka Date: Tue, 27 Feb 2024 07:56:45 +0100 Subject: [PATCH 27/34] revert temp variables --- runtime/hydradx/src/system.rs | 7 +++---- runtime/hydradx/src/xcm.rs | 7 ++----- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/runtime/hydradx/src/system.rs b/runtime/hydradx/src/system.rs index 3853f9d00..8be8d0291 100644 --- a/runtime/hydradx/src/system.rs +++ b/runtime/hydradx/src/system.rs @@ -93,7 +93,7 @@ impl Contains for CallFilter { } } - let m = match call { + match call { RuntimeCall::PolkadotXcm(pallet_xcm::Call::send { .. }) => true, // create and create2 are only allowed through RPC or Runtime API RuntimeCall::EVM(pallet_evm::Call::create { .. }) => false, @@ -101,9 +101,8 @@ impl Contains for CallFilter { RuntimeCall::PolkadotXcm(_) => false, RuntimeCall::OrmlXcm(_) => false, _ => true, - }; - let d = m.clone(); - m + } + } } diff --git a/runtime/hydradx/src/xcm.rs b/runtime/hydradx/src/xcm.rs index de6c5c6c4..e9cd544fa 100644 --- a/runtime/hydradx/src/xcm.rs +++ b/runtime/hydradx/src/xcm.rs @@ -429,7 +429,7 @@ impl Contains for SafeCallFilter { return false; } - let s = matches!( + matches!( call, RuntimeCall::System(frame_system::Call::kill_prefix { .. } | frame_system::Call::set_heap_pages { .. }) | RuntimeCall::Timestamp(..) @@ -493,9 +493,6 @@ impl Contains for SafeCallFilter { | RuntimeCall::Currencies(..) | RuntimeCall::Tokens(..) | RuntimeCall::OrmlXcm(..) - ); - let d = 3; - let k = s; - s + ) } } From 9ff1df6ed141301a05d90220a1eada579cc2b702 Mon Sep 17 00:00:00 2001 From: dmoka Date: Tue, 27 Feb 2024 08:26:23 +0100 Subject: [PATCH 28/34] fix compilation error in test --- .../adapters/src/tests/xcm_account_derivation.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/runtime/adapters/src/tests/xcm_account_derivation.rs b/runtime/adapters/src/tests/xcm_account_derivation.rs index 8178bdb48..7882defbe 100644 --- a/runtime/adapters/src/tests/xcm_account_derivation.rs +++ b/runtime/adapters/src/tests/xcm_account_derivation.rs @@ -1,7 +1,7 @@ use crate::xcm_account_derivation::HashedDescriptionDescribeFamilyAllTerminal; use polkadot_xcm::latest::prelude::*; use pretty_assertions::assert_eq; -use xcm_executor::traits::Convert; +use xcm_executor::traits::{ ConvertLocation}; #[test] fn test_hashed_family_all_terminal_converter() { @@ -12,7 +12,7 @@ fn test_hashed_family_all_terminal_converter() { 129, 211, 14, 6, 146, 54, 225, 200, 135, 103, 248, 244, 125, 112, 53, 133, 91, 42, 215, 236, 154, 199, 191, 208, 110, 148, 223, 55, 92, 216, 250, 34 ], - Converter::<[u8; 32]>::convert(MultiLocation { + Converter::<[u8; 32]>::convert_location(&MultiLocation { parents: 0, interior: X2( Parachain(1), @@ -29,7 +29,7 @@ fn test_hashed_family_all_terminal_converter() { 17, 142, 105, 253, 199, 34, 43, 136, 155, 48, 12, 137, 155, 219, 155, 110, 93, 181, 93, 252, 124, 60, 250, 195, 229, 86, 31, 220, 121, 111, 254, 252 ], - Converter::<[u8; 32]>::convert(MultiLocation { + Converter::<[u8; 32]>::convert_location(&MultiLocation { parents: 1, interior: X2( Parachain(1), @@ -46,7 +46,7 @@ fn test_hashed_family_all_terminal_converter() { 237, 65, 190, 49, 53, 182, 196, 183, 151, 24, 214, 23, 72, 244, 235, 87, 187, 67, 52, 122, 195, 192, 10, 58, 253, 49, 0, 112, 175, 224, 125, 66 ], - Converter::<[u8; 32]>::convert(MultiLocation { + Converter::<[u8; 32]>::convert_location(&MultiLocation { parents: 0, interior: X2( Parachain(1), @@ -63,7 +63,7 @@ fn test_hashed_family_all_terminal_converter() { 226, 225, 225, 162, 254, 156, 113, 95, 68, 155, 160, 118, 126, 18, 166, 132, 144, 19, 8, 204, 228, 112, 164, 189, 179, 124, 249, 1, 168, 110, 151, 50 ], - Converter::<[u8; 32]>::convert(MultiLocation { + Converter::<[u8; 32]>::convert_location(&MultiLocation { parents: 1, interior: X2( Parachain(1), @@ -80,7 +80,7 @@ fn test_hashed_family_all_terminal_converter() { 254, 186, 179, 229, 13, 24, 84, 36, 84, 35, 64, 95, 114, 136, 62, 69, 247, 74, 215, 104, 121, 114, 53, 6, 124, 46, 42, 245, 121, 197, 12, 208 ], - Converter::<[u8; 32]>::convert(MultiLocation { + Converter::<[u8; 32]>::convert_location(&MultiLocation { parents: 1, interior: X2(Parachain(2), PalletInstance(3)), }) @@ -91,7 +91,7 @@ fn test_hashed_family_all_terminal_converter() { 217, 56, 0, 36, 228, 154, 250, 26, 200, 156, 1, 39, 254, 162, 16, 187, 107, 67, 27, 16, 218, 254, 250, 184, 6, 27, 216, 138, 194, 93, 23, 165 ], - Converter::<[u8; 32]>::convert(MultiLocation { + Converter::<[u8; 32]>::convert_location(&MultiLocation { parents: 1, interior: Here, }) From f35e77aa4359c5705f75a3ca3819e80e63236eb6 Mon Sep 17 00:00:00 2001 From: dmoka Date: Tue, 27 Feb 2024 08:32:33 +0100 Subject: [PATCH 29/34] fix send xcm test --- integration-tests/src/global_account_derivation.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/integration-tests/src/global_account_derivation.rs b/integration-tests/src/global_account_derivation.rs index e240a40d1..2726a9844 100644 --- a/integration-tests/src/global_account_derivation.rs +++ b/integration-tests/src/global_account_derivation.rs @@ -9,6 +9,8 @@ use orml_traits::MultiCurrency; use polkadot_xcm::latest::prelude::*; use xcm_emulator::TestExt; use xcm_emulator::ConvertLocation; +use frame_support::dispatch::GetDispatchInfo; + #[test] fn other_chain_remote_account_should_work_on_hydra() { // Arrange @@ -81,7 +83,7 @@ fn other_chain_remote_account_should_work_on_hydra() { weight_limit: Unlimited, }, Transact { - require_weight_at_most: Weight::from_parts(10_000_000_000, 0u64), + require_weight_at_most: omni_sell.get_dispatch_info().weight, origin_kind: OriginKind::SovereignAccount, call: omni_sell.encode().into(), }, From 2ddde339bb8f23a65da581b617f7d1dcadfd5a2e Mon Sep 17 00:00:00 2001 From: dmoka Date: Tue, 27 Feb 2024 08:53:31 +0100 Subject: [PATCH 30/34] use imple of remote account handling from polkadot repo --- integration-tests/src/cross_chain_transfer.rs | 19 ++-- .../src/global_account_derivation.rs | 16 +-- runtime/adapters/src/lib.rs | 1 - runtime/adapters/src/tests/mod.rs | 1 - .../src/tests/xcm_account_derivation.rs | 100 ------------------ .../adapters/src/xcm_account_derivation.rs | 47 -------- runtime/hydradx/src/system.rs | 1 - runtime/hydradx/src/xcm.rs | 11 +- 8 files changed, 20 insertions(+), 176 deletions(-) delete mode 100644 runtime/adapters/src/tests/xcm_account_derivation.rs delete mode 100644 runtime/adapters/src/xcm_account_derivation.rs diff --git a/integration-tests/src/cross_chain_transfer.rs b/integration-tests/src/cross_chain_transfer.rs index b73bf400c..2a880163f 100644 --- a/integration-tests/src/cross_chain_transfer.rs +++ b/integration-tests/src/cross_chain_transfer.rs @@ -196,16 +196,12 @@ fn hydra_should_receive_asset_when_transferred_from_acala_to_eth_address() { ); }); - let fee = 400641025641; Hydra::execute_with(|| { + let fee = hydradx_runtime::Tokens::free_balance(ACA, &hydradx_runtime::Treasury::account_id()); + assert!(fee > 0, "fee should be greater than 0"); assert_eq!( hydradx_runtime::Tokens::free_balance(ACA, &AccountId::from(evm_account())), - amount - fee - ); - assert_eq!( - hydradx_runtime::Tokens::free_balance(ACA, &hydradx_runtime::Treasury::account_id()), - 1 * fee // fees should go to treasury - ); + amount - fee); }); } @@ -272,15 +268,12 @@ fn hydra_should_receive_asset_when_transferred_from_acala_to_same_address_repres ); }); - let fee = 400641025641; Hydra::execute_with(|| { + let fee_2x = hydradx_runtime::Tokens::free_balance(ACA, &hydradx_runtime::Treasury::account_id()); + assert!(fee_2x > 0, "fee should be greater than 0"); assert_eq!( hydradx_runtime::Tokens::free_balance(ACA, &AccountId::from(evm_account())), - 2 * amount - 2 * fee - ); - assert_eq!( - hydradx_runtime::Tokens::free_balance(ACA, &hydradx_runtime::Treasury::account_id()), - 2 * fee // fees should go to treasury + 2 * amount - fee_2x ); }); } diff --git a/integration-tests/src/global_account_derivation.rs b/integration-tests/src/global_account_derivation.rs index 2726a9844..5ac5fd1d1 100644 --- a/integration-tests/src/global_account_derivation.rs +++ b/integration-tests/src/global_account_derivation.rs @@ -1,16 +1,17 @@ #![cfg(test)] use crate::polkadot_test_net::*; -use frame_support::{assert_ok, weights::Weight}; +use frame_support::{assert_ok}; use sp_runtime::codec::Encode; -use hydradx_adapters::xcm_account_derivation::HashedDescriptionDescribeFamilyAllTerminal; +use frame_support::dispatch::GetDispatchInfo; use orml_traits::MultiCurrency; use polkadot_xcm::latest::prelude::*; -use xcm_emulator::TestExt; +use xcm_builder::DescribeAllTerminal; +use xcm_builder::DescribeFamily; +use xcm_builder::HashedDescription; use xcm_emulator::ConvertLocation; -use frame_support::dispatch::GetDispatchInfo; - +use xcm_emulator::TestExt; #[test] fn other_chain_remote_account_should_work_on_hydra() { // Arrange @@ -33,7 +34,8 @@ fn other_chain_remote_account_should_work_on_hydra() { }; let acala_account_id_at_hydra: AccountId = - HashedDescriptionDescribeFamilyAllTerminal::convert_location(&xcm_origin_at_hydra).unwrap(); + HashedDescription::>::convert_location(&xcm_origin_at_hydra) + .unwrap(); Hydra::execute_with(|| { init_omnipool(); @@ -83,7 +85,7 @@ fn other_chain_remote_account_should_work_on_hydra() { weight_limit: Unlimited, }, Transact { - require_weight_at_most: omni_sell.get_dispatch_info().weight, + require_weight_at_most: omni_sell.get_dispatch_info().weight, origin_kind: OriginKind::SovereignAccount, call: omni_sell.encode().into(), }, diff --git a/runtime/adapters/src/lib.rs b/runtime/adapters/src/lib.rs index 65e347838..02382533a 100644 --- a/runtime/adapters/src/lib.rs +++ b/runtime/adapters/src/lib.rs @@ -62,7 +62,6 @@ use xcm_executor::{ pub mod inspect; pub mod price; -pub mod xcm_account_derivation; pub mod xcm_exchange; pub mod xcm_execute_filter; diff --git a/runtime/adapters/src/tests/mod.rs b/runtime/adapters/src/tests/mod.rs index b4e321875..504f68420 100644 --- a/runtime/adapters/src/tests/mod.rs +++ b/runtime/adapters/src/tests/mod.rs @@ -1,5 +1,4 @@ pub mod mock; pub mod trader; -pub mod xcm_account_derivation; pub mod xcm_exchange; pub mod xcm_execute_filter; diff --git a/runtime/adapters/src/tests/xcm_account_derivation.rs b/runtime/adapters/src/tests/xcm_account_derivation.rs deleted file mode 100644 index 7882defbe..000000000 --- a/runtime/adapters/src/tests/xcm_account_derivation.rs +++ /dev/null @@ -1,100 +0,0 @@ -use crate::xcm_account_derivation::HashedDescriptionDescribeFamilyAllTerminal; -use polkadot_xcm::latest::prelude::*; -use pretty_assertions::assert_eq; -use xcm_executor::traits::{ ConvertLocation}; - -#[test] -fn test_hashed_family_all_terminal_converter() { - type Converter = HashedDescriptionDescribeFamilyAllTerminal; - - assert_eq!( - [ - 129, 211, 14, 6, 146, 54, 225, 200, 135, 103, 248, 244, 125, 112, 53, 133, 91, 42, 215, 236, 154, 199, 191, - 208, 110, 148, 223, 55, 92, 216, 250, 34 - ], - Converter::<[u8; 32]>::convert_location(&MultiLocation { - parents: 0, - interior: X2( - Parachain(1), - AccountId32 { - network: None, - id: [0u8; 32] - } - ), - }) - .unwrap() - ); - assert_eq!( - [ - 17, 142, 105, 253, 199, 34, 43, 136, 155, 48, 12, 137, 155, 219, 155, 110, 93, 181, 93, 252, 124, 60, 250, - 195, 229, 86, 31, 220, 121, 111, 254, 252 - ], - Converter::<[u8; 32]>::convert_location(&MultiLocation { - parents: 1, - interior: X2( - Parachain(1), - AccountId32 { - network: None, - id: [0u8; 32] - } - ), - }) - .unwrap() - ); - assert_eq!( - [ - 237, 65, 190, 49, 53, 182, 196, 183, 151, 24, 214, 23, 72, 244, 235, 87, 187, 67, 52, 122, 195, 192, 10, - 58, 253, 49, 0, 112, 175, 224, 125, 66 - ], - Converter::<[u8; 32]>::convert_location(&MultiLocation { - parents: 0, - interior: X2( - Parachain(1), - AccountKey20 { - network: None, - key: [0u8; 20] - } - ), - }) - .unwrap() - ); - assert_eq!( - [ - 226, 225, 225, 162, 254, 156, 113, 95, 68, 155, 160, 118, 126, 18, 166, 132, 144, 19, 8, 204, 228, 112, - 164, 189, 179, 124, 249, 1, 168, 110, 151, 50 - ], - Converter::<[u8; 32]>::convert_location(&MultiLocation { - parents: 1, - interior: X2( - Parachain(1), - AccountKey20 { - network: None, - key: [0u8; 20] - } - ), - }) - .unwrap() - ); - assert_eq!( - [ - 254, 186, 179, 229, 13, 24, 84, 36, 84, 35, 64, 95, 114, 136, 62, 69, 247, 74, 215, 104, 121, 114, 53, 6, - 124, 46, 42, 245, 121, 197, 12, 208 - ], - Converter::<[u8; 32]>::convert_location(&MultiLocation { - parents: 1, - interior: X2(Parachain(2), PalletInstance(3)), - }) - .unwrap() - ); - assert_eq!( - [ - 217, 56, 0, 36, 228, 154, 250, 26, 200, 156, 1, 39, 254, 162, 16, 187, 107, 67, 27, 16, 218, 254, 250, 184, - 6, 27, 216, 138, 194, 93, 23, 165 - ], - Converter::<[u8; 32]>::convert_location(&MultiLocation { - parents: 1, - interior: Here, - }) - .unwrap() - ); -} diff --git a/runtime/adapters/src/xcm_account_derivation.rs b/runtime/adapters/src/xcm_account_derivation.rs deleted file mode 100644 index 378844822..000000000 --- a/runtime/adapters/src/xcm_account_derivation.rs +++ /dev/null @@ -1,47 +0,0 @@ -use super::*; -use codec::{Compact, Encode}; -use sp_io::hashing::blake2_256; -use sp_std::{borrow::Borrow, marker::PhantomData, vec::Vec}; -/// NOTE: Copied from -/// -/// temporary struct that mimics the behavior of the upstream type that we -/// will move to once we update this repository to Polkadot 0.9.43+. -pub struct HashedDescriptionDescribeFamilyAllTerminal(PhantomData); -impl + Clone> HashedDescriptionDescribeFamilyAllTerminal { - fn describe_location_suffix(l: &MultiLocation) -> Result, ()> { - match (l.parents, &l.interior) { - (0, Here) => Ok(Vec::new()), - (0, X1(PalletInstance(i))) => Ok((b"Pallet", Compact::::from(*i as u32)).encode()), - (0, X1(AccountId32 { id, .. })) => Ok((b"AccountId32", id).encode()), - (0, X1(AccountKey20 { key, .. })) => Ok((b"AccountKey20", key).encode()), - _ => Err(()), - } - } -} - -impl + Clone> ConvertLocation - for HashedDescriptionDescribeFamilyAllTerminal -{ - fn convert_location(location: &MultiLocation) -> Option { - let l = location.borrow(); - let to_hash = match (l.parents, l.interior.first()) { - (0, Some(Parachain(index))) => { - let tail = l.interior.split_first().0; - let interior = Self::describe_location_suffix(&tail.into()).ok()?; - (b"ChildChain", Compact::::from(*index), interior).encode() - } - (1, Some(Parachain(index))) => { - let tail = l.interior.split_first().0; - let interior = Self::describe_location_suffix(&tail.into()).ok()?; - (b"SiblingChain", Compact::::from(*index), interior).encode() - } - (1, _) => { - let tail = l.interior.into(); - let interior = Self::describe_location_suffix(&tail).ok()?; - (b"ParentChain", interior).encode() - } - _ => return None, - }; - Some(blake2_256(&to_hash).into()) - } -} diff --git a/runtime/hydradx/src/system.rs b/runtime/hydradx/src/system.rs index 8be8d0291..d17300846 100644 --- a/runtime/hydradx/src/system.rs +++ b/runtime/hydradx/src/system.rs @@ -102,7 +102,6 @@ impl Contains for CallFilter { RuntimeCall::OrmlXcm(_) => false, _ => true, } - } } diff --git a/runtime/hydradx/src/xcm.rs b/runtime/hydradx/src/xcm.rs index e9cd544fa..f8f2caa2c 100644 --- a/runtime/hydradx/src/xcm.rs +++ b/runtime/hydradx/src/xcm.rs @@ -3,8 +3,7 @@ use sp_std::marker::PhantomData; use codec::MaxEncodedLen; use hydradx_adapters::{ - xcm_account_derivation, MultiCurrencyTrader, RelayChainBlockNumberProvider, ReroutingMultiCurrencyAdapter, - ToFeeReceiver, + MultiCurrencyTrader, RelayChainBlockNumberProvider, ReroutingMultiCurrencyAdapter, ToFeeReceiver, }; use pallet_transaction_multi_payment::DepositAll; use primitives::AssetId; // shadow glob import of polkadot_xcm::v3::prelude::AssetId @@ -27,9 +26,9 @@ use primitives::Price; use scale_info::TypeInfo; use xcm_builder::{ AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, - EnsureXcmOrigin, FixedWeightBounds, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, - SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, - TakeWeightCredit, WithComputedOrigin, + DescribeAllTerminal, DescribeFamily, EnsureXcmOrigin, FixedWeightBounds, HashedDescription, ParentIsPreset, + RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative, + SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, WithComputedOrigin, }; use xcm_executor::{Config, XcmExecutor}; @@ -358,7 +357,7 @@ pub type LocationToAccountId = ( // Straight up local `AccountId32` origins just alias directly to `AccountId`. AccountId32Aliases, // Generate remote accounts according to polkadot standards - xcm_account_derivation::HashedDescriptionDescribeFamilyAllTerminal, + HashedDescription>, // Convert ETH to local substrate account EvmAddressConversion, ); From 86d8958382e6e4d40ec3e5c160b554769ed36bf1 Mon Sep 17 00:00:00 2001 From: dmoka Date: Tue, 27 Feb 2024 08:54:17 +0100 Subject: [PATCH 31/34] bump versions --- Cargo.lock | 6 +++--- integration-tests/Cargo.toml | 2 +- runtime/adapters/Cargo.toml | 2 +- runtime/hydradx/Cargo.toml | 2 +- runtime/hydradx/src/lib.rs | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ac8f91865..0b1a5ec9f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4571,7 +4571,7 @@ dependencies = [ [[package]] name = "hydradx-adapters" -version = "1.2.1" +version = "1.2.2" dependencies = [ "cumulus-pallet-parachain-system", "cumulus-primitives-core", @@ -4621,7 +4621,7 @@ dependencies = [ [[package]] name = "hydradx-runtime" -version = "215.0.0" +version = "216.0.0" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", @@ -11333,7 +11333,7 @@ dependencies = [ [[package]] name = "runtime-integration-tests" -version = "1.19.1" +version = "1.19.2" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index c8bf8e541..5bf173328 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "runtime-integration-tests" -version = "1.19.1" +version = "1.19.2" description = "Integration tests" authors = ["GalacticCouncil"] edition = "2021" diff --git a/runtime/adapters/Cargo.toml b/runtime/adapters/Cargo.toml index 3debce6f5..cfd02822d 100644 --- a/runtime/adapters/Cargo.toml +++ b/runtime/adapters/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hydradx-adapters" -version = "1.2.1" +version = "1.2.2" description = "Structs and other generic types for building runtimes." authors = ["GalacticCouncil"] edition = "2021" diff --git a/runtime/hydradx/Cargo.toml b/runtime/hydradx/Cargo.toml index c417e8f25..d13dffcf4 100644 --- a/runtime/hydradx/Cargo.toml +++ b/runtime/hydradx/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hydradx-runtime" -version = "215.0.0" +version = "216.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 6e0c7d189..a0c67d3bf 100644 --- a/runtime/hydradx/src/lib.rs +++ b/runtime/hydradx/src/lib.rs @@ -107,7 +107,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("hydradx"), impl_name: create_runtime_str!("hydradx"), authoring_version: 1, - spec_version: 215, + spec_version: 216, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 1, From 00976d9e8e1fbf1b582365ec2964e53fcacce03e Mon Sep 17 00:00:00 2001 From: dmoka Date: Tue, 27 Feb 2024 08:57:23 +0100 Subject: [PATCH 32/34] formatting --- integration-tests/src/cross_chain_transfer.rs | 3 ++- integration-tests/src/global_account_derivation.rs | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/integration-tests/src/cross_chain_transfer.rs b/integration-tests/src/cross_chain_transfer.rs index 2a880163f..79cd13f79 100644 --- a/integration-tests/src/cross_chain_transfer.rs +++ b/integration-tests/src/cross_chain_transfer.rs @@ -201,7 +201,8 @@ fn hydra_should_receive_asset_when_transferred_from_acala_to_eth_address() { assert!(fee > 0, "fee should be greater than 0"); assert_eq!( hydradx_runtime::Tokens::free_balance(ACA, &AccountId::from(evm_account())), - amount - fee); + amount - fee + ); }); } diff --git a/integration-tests/src/global_account_derivation.rs b/integration-tests/src/global_account_derivation.rs index 5ac5fd1d1..954037063 100644 --- a/integration-tests/src/global_account_derivation.rs +++ b/integration-tests/src/global_account_derivation.rs @@ -1,7 +1,7 @@ #![cfg(test)] use crate::polkadot_test_net::*; -use frame_support::{assert_ok}; +use frame_support::assert_ok; use sp_runtime::codec::Encode; use frame_support::dispatch::GetDispatchInfo; From 72620742194f5b42ec8548221871991cc2a4c218 Mon Sep 17 00:00:00 2001 From: dmoka Date: Tue, 27 Feb 2024 11:12:00 +0100 Subject: [PATCH 33/34] bump versions --- Cargo.lock | 4 ++-- integration-tests/Cargo.toml | 2 +- runtime/hydradx/Cargo.toml | 2 +- runtime/hydradx/src/lib.rs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 351326245..44404ae08 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4621,7 +4621,7 @@ dependencies = [ [[package]] name = "hydradx-runtime" -version = "216.0.0" +version = "217.0.0" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", @@ -11361,7 +11361,7 @@ dependencies = [ [[package]] name = "runtime-integration-tests" -version = "1.19.2" +version = "1.19.3" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index 02046ce6a..ec378e6a4 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "runtime-integration-tests" -version = "1.19.2" +version = "1.19.3" description = "Integration tests" authors = ["GalacticCouncil"] edition = "2021" diff --git a/runtime/hydradx/Cargo.toml b/runtime/hydradx/Cargo.toml index d862f012a..11e27c8e0 100644 --- a/runtime/hydradx/Cargo.toml +++ b/runtime/hydradx/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hydradx-runtime" -version = "216.0.0" +version = "217.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 f27f0473f..9a7e7d81b 100644 --- a/runtime/hydradx/src/lib.rs +++ b/runtime/hydradx/src/lib.rs @@ -107,7 +107,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("hydradx"), impl_name: create_runtime_str!("hydradx"), authoring_version: 1, - spec_version: 216, + spec_version: 217, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 1, From 30cc57afa654911cd6ce7958c1c79a355f0fc3f4 Mon Sep 17 00:00:00 2001 From: dmoka Date: Tue, 27 Feb 2024 13:15:40 +0100 Subject: [PATCH 34/34] bump versions --- Cargo.lock | 4 ++-- integration-tests/Cargo.toml | 2 +- runtime/hydradx/Cargo.toml | 2 +- runtime/hydradx/src/lib.rs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 44404ae08..f5939f782 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4621,7 +4621,7 @@ dependencies = [ [[package]] name = "hydradx-runtime" -version = "217.0.0" +version = "218.0.0" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", @@ -11361,7 +11361,7 @@ dependencies = [ [[package]] name = "runtime-integration-tests" -version = "1.19.3" +version = "1.19.4" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index ec378e6a4..c0679008c 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "runtime-integration-tests" -version = "1.19.3" +version = "1.19.4" description = "Integration tests" authors = ["GalacticCouncil"] edition = "2021" diff --git a/runtime/hydradx/Cargo.toml b/runtime/hydradx/Cargo.toml index 11e27c8e0..5e8059e96 100644 --- a/runtime/hydradx/Cargo.toml +++ b/runtime/hydradx/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hydradx-runtime" -version = "217.0.0" +version = "218.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 9a7e7d81b..3947de413 100644 --- a/runtime/hydradx/src/lib.rs +++ b/runtime/hydradx/src/lib.rs @@ -107,7 +107,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("hydradx"), impl_name: create_runtime_str!("hydradx"), authoring_version: 1, - spec_version: 217, + spec_version: 218, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 1,