Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support eth address and remote accounts #709

Merged
merged 40 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
88c623b
WIP - add ethereum address conversion for multilocation
dmoka Dec 1, 2023
504210e
fix integration test to send to eth address
dmoka Dec 4, 2023
f2e2481
add check that the asset arrives when sent both eth and normal address
dmoka Dec 4, 2023
ddd2c72
remove todos as they are not relevant
dmoka Dec 4, 2023
1b0ae40
bump versions
dmoka Dec 5, 2023
c831d42
fix lock with latest versions
dmoka Dec 5, 2023
c0bf508
make clippy happy
dmoka Dec 5, 2023
4d4853a
feat: Enable ecosystem wide compatible account derivation
mustermeiszer Dec 6, 2023
a4943bc
remove unused functions
dmoka Dec 11, 2023
cfd2f24
merge master to feat/support-eth-address-in-xcm
dmoka Dec 11, 2023
fb7ca81
bump runtime version
dmoka Dec 11, 2023
6de1325
temporarly remove the evm address conversion so we can merge "xcm-eco…
dmoka Dec 13, 2023
842600e
Merge pull request #718 from centrifuge/feat/xcm-ecosystem-account-de…
dmoka Dec 13, 2023
cbc1136
WIP - add support for global remote location
dmoka Dec 13, 2023
5fc205f
fix evm tests by adding back evm address converter
dmoka Dec 13, 2023
54620c5
remove invalid test
dmoka Dec 14, 2023
26b4145
add test for verifying global account derivation
dmoka Dec 14, 2023
10d6895
refactoring
dmoka Dec 14, 2023
6cae1d0
adjust assertion
dmoka Dec 14, 2023
370359d
rearrange tests
dmoka Dec 14, 2023
4c251ab
replace account derivation logic to adapters
dmoka Dec 14, 2023
313d528
remove unused dependency
dmoka Dec 14, 2023
c93a16c
bump version
dmoka Dec 15, 2023
04b3998
replace tests
dmoka Dec 15, 2023
a32799c
fix typos in comments
dmoka Dec 15, 2023
16d52ef
clean up
dmoka Dec 15, 2023
1555bf7
Merge branch 'master' into feat/support-eth-address-in-xcm
mrq1911 Feb 22, 2024
9b630c1
fmt
mrq1911 Feb 22, 2024
878ec99
merge master to feat/support-eth-address-in-xcm
dmoka Feb 26, 2024
fd1be3e
fix compilation error
dmoka Feb 27, 2024
91c091c
revert temp variables
dmoka Feb 27, 2024
9ff1df6
fix compilation error in test
dmoka Feb 27, 2024
f35e77a
fix send xcm test
dmoka Feb 27, 2024
2ddde33
use imple of remote account handling from polkadot repo
dmoka Feb 27, 2024
86d8958
bump versions
dmoka Feb 27, 2024
00976d9
formatting
dmoka Feb 27, 2024
221bd52
Merge remote-tracking branch 'origin/master' into feat/support-eth-ad…
dmoka Feb 27, 2024
7262074
bump versions
dmoka Feb 27, 2024
e0aed7a
Merge branch 'master' into feat/support-eth-address-in-xcm
mrq1911 Feb 27, 2024
30cc57a
bump versions
dmoka Feb 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "runtime-integration-tests"
version = "1.19.3"
version = "1.19.4"
description = "Integration tests"
authors = ["GalacticCouncil"]
edition = "2021"
Expand Down
125 changes: 125 additions & 0 deletions integration-tests/src/cross_chain_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use hex_literal::hex;
use hydradx_traits::registry::Mutate;
use orml_traits::currency::MultiCurrency;
use pretty_assertions::assert_eq;
use primitives::AccountId;
use sp_core::H256;
use sp_runtime::traits::{AccountIdConversion, BlakeTwo256, Hash};
use xcm_emulator::TestExt;
Expand Down Expand Up @@ -149,6 +150,130 @@ 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(
ACA,
hydradx_runtime::AssetLocation(MultiLocation::new(1, X2(Parachain(ACALA_PARA_ID), GeneralIndex(0))))
));
});

let amount = 30 * UNITS;
Acala::execute_with(|| {
//We send to 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
);
});

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
);
});
}

#[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(
ACA,
hydradx_runtime::AssetLocation(MultiLocation::new(1, X2(Parachain(ACALA_PARA_ID), GeneralIndex(0))))
));
});

let amount = 30 * UNITS;
Acala::execute_with(|| {
//We send to 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))
));

//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_parts(399_600_000_000, 0))
));

// Assert
assert_eq!(
hydradx_runtime::Balances::free_balance(&AccountId::from(ALICE)),
ALICE_INITIAL_NATIVE_BALANCE - 2 * amount
);
});

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 - fee_2x
);
});
}

#[test]
fn transfer_from_acala_should_fail_when_transferring_insufficient_amount() {
TestNet::reset();
Expand Down
124 changes: 124 additions & 0 deletions integration-tests/src/global_account_derivation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#![cfg(test)]
use crate::polkadot_test_net::*;

use frame_support::assert_ok;
use sp_runtime::codec::Encode;

use frame_support::dispatch::GetDispatchInfo;
use orml_traits::MultiCurrency;
use polkadot_xcm::latest::prelude::*;
use xcm_builder::DescribeAllTerminal;
use xcm_builder::DescribeFamily;
use xcm_builder::HashedDescription;
use xcm_emulator::ConvertLocation;
use xcm_emulator::TestExt;
#[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_origin_at_hydra = MultiLocation {
parents: 1,
interior: X2(
Junction::Parachain(ACALA_PARA_ID),
Junction::AccountId32 {
network: None,
id: evm_account().into(),
},
),
};

let acala_account_id_at_hydra: AccountId =
HashedDescription::<AccountId, DescribeFamily<DescribeAllTerminal>>::convert_location(&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
);
});

// Act
Acala::execute_with(|| {
let omni_sell =
hydradx_runtime::RuntimeCall::Omnipool(pallet_omnipool::Call::<hydradx_runtime::Runtime>::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: omni_sell.get_dispatch_info().weight,
origin_kind: OriginKind::SovereignAccount,
call: omni_sell.encode().into(),
},
ExpectTransactStatus(MaybeErrorCode::Success),
RefundSurplus,
DepositAsset {
assets: All.into(),
beneficiary: Junction::AccountId32 {
id: acala_account_id_at_hydra.clone().into(),
network: None,
}
.into(),
},
]);

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"
);
});
}
1 change: 1 addition & 0 deletions integration-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ mod dynamic_fees;
mod evm;
mod exchange_asset;
mod fee_calculation;
mod global_account_derivation;
mod insufficient_assets_ed;
mod non_native_fee;
mod omnipool_init;
Expand Down
2 changes: 1 addition & 1 deletion runtime/adapters/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
3 changes: 2 additions & 1 deletion runtime/hydradx/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hydradx-runtime"
version = "217.0.0"
version = "218.0.0"
authors = ["GalacticCouncil"]
edition = "2021"
license = "Apache 2.0"
Expand Down Expand Up @@ -112,6 +112,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 }
Expand Down
2 changes: 1 addition & 1 deletion runtime/hydradx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading
Loading