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: xcm exchange asset #714

Merged
merged 12 commits into from
Feb 27, 2024
4 changes: 2 additions & 2 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.17.3"
version = "1.17.4"
description = "Integration tests"
authors = ["GalacticCouncil"]
edition = "2021"
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/src/cross_chain_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ fn claim_asset(asset: MultiAsset, recipient: [u8; 32]) {
}

#[test]
fn polkadot_xcm_execute_extrinsic_should_not_be_allowed() {
fn polkadot_xcm_execute_extrinsic_should_be_allowed() {
TestNet::reset();

Hydra::execute_with(|| {
Expand Down
6 changes: 0 additions & 6 deletions integration-tests/src/exchange_asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ pub const ACA: u32 = 1234;
pub const GLMR: u32 = 4567;
pub const IBTC: u32 = 7890;

//TODO: Unignore these tests when we have the AssetExchange feature configured in hydra.
//For now they are ignored as first we want to try out AssetExchange in basilisk

#[ignore]
#[test]
fn hydra_should_swap_assets_when_receiving_from_acala_with_sell() {
//Arrange
Expand Down Expand Up @@ -96,7 +92,6 @@ fn hydra_should_swap_assets_when_receiving_from_acala_with_sell() {
});
}

#[ignore]
#[test]
fn hydra_should_swap_assets_when_receiving_from_acala_with_buy() {
//Arrange
Expand Down Expand Up @@ -169,7 +164,6 @@ fn hydra_should_swap_assets_when_receiving_from_acala_with_buy() {
}

//We swap GLMR for iBTC, sent from ACALA and executed on Hydradx, resultin in 4 hops
#[ignore]
#[test]
fn transfer_and_swap_should_work_with_4_hops() {
//Arrange
Expand Down
2 changes: 1 addition & 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 = "207.0.0"
version = "208.0.0"
authors = ["GalacticCouncil"]
edition = "2021"
license = "Apache 2.0"
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: 207,
spec_version: 208,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down
10 changes: 8 additions & 2 deletions runtime/hydradx/src/xcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ use frame_support::{
PalletId,
};
use frame_system::EnsureRoot;
use hydradx_adapters::xcm_exchange::XcmAssetExchanger;
use hydradx_adapters::xcm_execute_filter::AllowTransferAndSwap;
use orml_traits::{location::AbsoluteReserveProvider, parameter_type_with_key};
use orml_xcm_support::{DepositToAlternative, IsNativeConcrete, MultiNativeAsset};
use pallet_xcm::XcmPassthrough;
Expand Down Expand Up @@ -90,6 +92,10 @@ parameter_types! {
pub const MaxInstructions: u32 = 100;
pub const MaxAssetsForTransfer: usize = 2;

pub TempAccountForXcmAssetExchange: AccountId = [42; 32].into();
pub const MaxXcmDepth: u16 = 5;
pub const MaxNumberOfInstructions: u16 = 100;

pub UniversalLocation: InteriorMultiLocation = X2(GlobalConsensus(RelayNetwork::get()), Parachain(ParachainInfo::parachain_id().into()));
}

Expand Down Expand Up @@ -123,7 +129,7 @@ impl Config for XcmConfig {
type ResponseHandler = PolkadotXcm;
type AssetTrap = PolkadotXcm;
type AssetLocker = ();
type AssetExchanger = ();
type AssetExchanger = XcmAssetExchanger<Runtime, TempAccountForXcmAssetExchange, CurrencyIdConvert, Currencies>;
type AssetClaims = PolkadotXcm;
type SubscriptionService = PolkadotXcm;
type PalletInstancesInfo = AllPalletsWithSystem;
Expand Down Expand Up @@ -221,7 +227,7 @@ impl pallet_xcm::Config for Runtime {
type SendXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
type XcmRouter = XcmRouter;
type ExecuteXcmOrigin = EnsureXcmOrigin<RuntimeOrigin, LocalOriginToLocation>;
type XcmExecuteFilter = Nothing;
type XcmExecuteFilter = AllowTransferAndSwap<MaxXcmDepth, MaxNumberOfInstructions, RuntimeCall>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this change necessary? i dont think we are planning to execute xcm messages locally and xcm::execute extrinsic is call filtered anyway currently

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want it in combination with changing the call filter to allow UIs to interact with the chain through pallet_xcm::execute. This is part of the XCM exchange asset stuff.
Concretely you could imagine our UI swapping tokens on Hydra and then sending them to the destination in one extrinsic/with one XCM.

type XcmExecutor = XcmExecutor<XcmConfig>;
type XcmTeleportFilter = Nothing;
type XcmReserveTransferFilter = Everything;
Expand Down
Loading