From 8117f26908325587f1965f3e719f96691566c6f3 Mon Sep 17 00:00:00 2001 From: dmoka Date: Wed, 19 Jul 2023 15:00:29 +0200 Subject: [PATCH 1/6] config xcm asset exchange for runtime --- Cargo.lock | 54 +++++++++++++++++++++---------------- Cargo.toml | 34 +++++++++++------------ runtime/basilisk/Cargo.toml | 3 ++- runtime/basilisk/src/lib.rs | 2 +- runtime/basilisk/src/xcm.rs | 20 +++++++++++--- 5 files changed, 67 insertions(+), 46 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b59c9e8b77..dfb83c9638 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -612,7 +612,7 @@ dependencies = [ [[package]] name = "basilisk-runtime" -version = "104.0.0" +version = "105.0.0" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", @@ -3743,7 +3743,7 @@ dependencies = [ [[package]] name = "hydra-dx-math" version = "7.4.3" -source = "git+https://github.com/galacticcouncil/HydraDX-node?rev=38958214930d3156bbaa973c5ace67e823cbdaeb#38958214930d3156bbaa973c5ace67e823cbdaeb" +source = "git+https://github.com/galacticcouncil/HydraDX-node?rev=b59c0379b312e9b3df365f407aa48b43bc4ca833#b59c0379b312e9b3df365f407aa48b43bc4ca833" dependencies = [ "fixed", "num-traits", @@ -3757,8 +3757,8 @@ dependencies = [ [[package]] name = "hydradx-adapters" -version = "0.4.1" -source = "git+https://github.com/galacticcouncil/HydraDX-node?rev=38958214930d3156bbaa973c5ace67e823cbdaeb#38958214930d3156bbaa973c5ace67e823cbdaeb" +version = "0.4.2" +source = "git+https://github.com/galacticcouncil/HydraDX-node?rev=b59c0379b312e9b3df365f407aa48b43bc4ca833#b59c0379b312e9b3df365f407aa48b43bc4ca833" dependencies = [ "cumulus-pallet-parachain-system", "cumulus-primitives-core", @@ -3767,19 +3767,27 @@ dependencies = [ "hydra-dx-math", "hydradx-traits", "log", + "orml-tokens", "orml-traits", + "orml-utilities", "orml-xcm-support", + "pallet-balances", "pallet-circuit-breaker", + "pallet-currencies", "pallet-dynamic-fees", "pallet-ema-oracle", "pallet-liquidity-mining", "pallet-omnipool", "pallet-omnipool-liquidity-mining", + "pallet-route-executor", "pallet-transaction-multi-payment", "parity-scale-codec", "polkadot-parachain", "primitive-types 0.12.1", "primitives 5.8.2", + "scale-info", + "sp-core", + "sp-io", "sp-runtime", "sp-std", "xcm", @@ -3790,7 +3798,7 @@ dependencies = [ [[package]] name = "hydradx-traits" version = "2.4.0" -source = "git+https://github.com/galacticcouncil/HydraDX-node?rev=38958214930d3156bbaa973c5ace67e823cbdaeb#38958214930d3156bbaa973c5ace67e823cbdaeb" +source = "git+https://github.com/galacticcouncil/HydraDX-node?rev=b59c0379b312e9b3df365f407aa48b43bc4ca833#b59c0379b312e9b3df365f407aa48b43bc4ca833" dependencies = [ "frame-support", "impl-trait-for-tuples", @@ -5964,7 +5972,7 @@ dependencies = [ [[package]] name = "pallet-asset-registry" version = "2.2.2" -source = "git+https://github.com/galacticcouncil/HydraDX-node?rev=38958214930d3156bbaa973c5ace67e823cbdaeb#38958214930d3156bbaa973c5ace67e823cbdaeb" +source = "git+https://github.com/galacticcouncil/HydraDX-node?rev=b59c0379b312e9b3df365f407aa48b43bc4ca833#b59c0379b312e9b3df365f407aa48b43bc4ca833" dependencies = [ "frame-benchmarking", "frame-support", @@ -6167,7 +6175,7 @@ dependencies = [ [[package]] name = "pallet-circuit-breaker" version = "1.1.14" -source = "git+https://github.com/galacticcouncil/HydraDX-node?rev=38958214930d3156bbaa973c5ace67e823cbdaeb#38958214930d3156bbaa973c5ace67e823cbdaeb" +source = "git+https://github.com/galacticcouncil/HydraDX-node?rev=b59c0379b312e9b3df365f407aa48b43bc4ca833#b59c0379b312e9b3df365f407aa48b43bc4ca833" dependencies = [ "frame-support", "frame-system", @@ -6183,7 +6191,7 @@ dependencies = [ [[package]] name = "pallet-collator-rewards" version = "1.0.4" -source = "git+https://github.com/galacticcouncil/HydraDX-node?rev=38958214930d3156bbaa973c5ace67e823cbdaeb#38958214930d3156bbaa973c5ace67e823cbdaeb" +source = "git+https://github.com/galacticcouncil/HydraDX-node?rev=b59c0379b312e9b3df365f407aa48b43bc4ca833#b59c0379b312e9b3df365f407aa48b43bc4ca833" dependencies = [ "frame-support", "frame-system", @@ -6255,7 +6263,7 @@ dependencies = [ [[package]] name = "pallet-currencies" version = "1.2.1" -source = "git+https://github.com/galacticcouncil/HydraDX-node?rev=38958214930d3156bbaa973c5ace67e823cbdaeb#38958214930d3156bbaa973c5ace67e823cbdaeb" +source = "git+https://github.com/galacticcouncil/HydraDX-node?rev=b59c0379b312e9b3df365f407aa48b43bc4ca833#b59c0379b312e9b3df365f407aa48b43bc4ca833" dependencies = [ "frame-support", "frame-system", @@ -6290,7 +6298,7 @@ dependencies = [ [[package]] name = "pallet-duster" version = "3.2.3" -source = "git+https://github.com/galacticcouncil/HydraDX-node?rev=38958214930d3156bbaa973c5ace67e823cbdaeb#38958214930d3156bbaa973c5ace67e823cbdaeb" +source = "git+https://github.com/galacticcouncil/HydraDX-node?rev=b59c0379b312e9b3df365f407aa48b43bc4ca833#b59c0379b312e9b3df365f407aa48b43bc4ca833" dependencies = [ "frame-benchmarking", "frame-support", @@ -6307,7 +6315,7 @@ dependencies = [ [[package]] name = "pallet-dynamic-fees" version = "1.0.1" -source = "git+https://github.com/galacticcouncil/HydraDX-node?rev=38958214930d3156bbaa973c5ace67e823cbdaeb#38958214930d3156bbaa973c5ace67e823cbdaeb" +source = "git+https://github.com/galacticcouncil/HydraDX-node?rev=b59c0379b312e9b3df365f407aa48b43bc4ca833#b59c0379b312e9b3df365f407aa48b43bc4ca833" dependencies = [ "frame-support", "frame-system", @@ -6391,7 +6399,7 @@ dependencies = [ [[package]] name = "pallet-ema-oracle" version = "1.1.0" -source = "git+https://github.com/galacticcouncil/HydraDX-node?rev=38958214930d3156bbaa973c5ace67e823cbdaeb#38958214930d3156bbaa973c5ace67e823cbdaeb" +source = "git+https://github.com/galacticcouncil/HydraDX-node?rev=b59c0379b312e9b3df365f407aa48b43bc4ca833#b59c0379b312e9b3df365f407aa48b43bc4ca833" dependencies = [ "frame-benchmarking", "frame-support", @@ -6529,7 +6537,7 @@ dependencies = [ [[package]] name = "pallet-liquidity-mining" version = "4.2.3" -source = "git+https://github.com/galacticcouncil/HydraDX-node?rev=38958214930d3156bbaa973c5ace67e823cbdaeb#38958214930d3156bbaa973c5ace67e823cbdaeb" +source = "git+https://github.com/galacticcouncil/HydraDX-node?rev=b59c0379b312e9b3df365f407aa48b43bc4ca833#b59c0379b312e9b3df365f407aa48b43bc4ca833" dependencies = [ "frame-support", "frame-system", @@ -6619,7 +6627,7 @@ dependencies = [ [[package]] name = "pallet-nft" version = "7.1.1" -source = "git+https://github.com/galacticcouncil/HydraDX-node?rev=38958214930d3156bbaa973c5ace67e823cbdaeb#38958214930d3156bbaa973c5ace67e823cbdaeb" +source = "git+https://github.com/galacticcouncil/HydraDX-node?rev=b59c0379b312e9b3df365f407aa48b43bc4ca833#b59c0379b312e9b3df365f407aa48b43bc4ca833" dependencies = [ "frame-benchmarking", "frame-support", @@ -6742,7 +6750,7 @@ dependencies = [ [[package]] name = "pallet-omnipool" version = "3.1.0" -source = "git+https://github.com/galacticcouncil/HydraDX-node?rev=38958214930d3156bbaa973c5ace67e823cbdaeb#38958214930d3156bbaa973c5ace67e823cbdaeb" +source = "git+https://github.com/galacticcouncil/HydraDX-node?rev=b59c0379b312e9b3df365f407aa48b43bc4ca833#b59c0379b312e9b3df365f407aa48b43bc4ca833" dependencies = [ "bitflags", "frame-support", @@ -6762,7 +6770,7 @@ dependencies = [ [[package]] name = "pallet-omnipool-liquidity-mining" version = "2.0.10" -source = "git+https://github.com/galacticcouncil/HydraDX-node?rev=38958214930d3156bbaa973c5ace67e823cbdaeb#38958214930d3156bbaa973c5ace67e823cbdaeb" +source = "git+https://github.com/galacticcouncil/HydraDX-node?rev=b59c0379b312e9b3df365f407aa48b43bc4ca833#b59c0379b312e9b3df365f407aa48b43bc4ca833" dependencies = [ "bitflags", "frame-support", @@ -6868,7 +6876,7 @@ dependencies = [ [[package]] name = "pallet-relaychain-info" version = "0.3.3" -source = "git+https://github.com/galacticcouncil/HydraDX-node?rev=38958214930d3156bbaa973c5ace67e823cbdaeb#38958214930d3156bbaa973c5ace67e823cbdaeb" +source = "git+https://github.com/galacticcouncil/HydraDX-node?rev=b59c0379b312e9b3df365f407aa48b43bc4ca833#b59c0379b312e9b3df365f407aa48b43bc4ca833" dependencies = [ "cumulus-pallet-parachain-system", "cumulus-primitives-core", @@ -6883,7 +6891,7 @@ dependencies = [ [[package]] name = "pallet-route-executor" version = "1.0.5" -source = "git+https://github.com/galacticcouncil/HydraDX-node?rev=38958214930d3156bbaa973c5ace67e823cbdaeb#38958214930d3156bbaa973c5ace67e823cbdaeb" +source = "git+https://github.com/galacticcouncil/HydraDX-node?rev=b59c0379b312e9b3df365f407aa48b43bc4ca833#b59c0379b312e9b3df365f407aa48b43bc4ca833" dependencies = [ "frame-support", "frame-system", @@ -7078,7 +7086,7 @@ dependencies = [ [[package]] name = "pallet-transaction-multi-payment" version = "9.0.1" -source = "git+https://github.com/galacticcouncil/HydraDX-node?rev=38958214930d3156bbaa973c5ace67e823cbdaeb#38958214930d3156bbaa973c5ace67e823cbdaeb" +source = "git+https://github.com/galacticcouncil/HydraDX-node?rev=b59c0379b312e9b3df365f407aa48b43bc4ca833#b59c0379b312e9b3df365f407aa48b43bc4ca833" dependencies = [ "frame-support", "frame-system", @@ -7096,7 +7104,7 @@ dependencies = [ [[package]] name = "pallet-transaction-pause" version = "0.1.3" -source = "git+https://github.com/galacticcouncil/HydraDX-node?rev=38958214930d3156bbaa973c5ace67e823cbdaeb#38958214930d3156bbaa973c5ace67e823cbdaeb" +source = "git+https://github.com/galacticcouncil/HydraDX-node?rev=b59c0379b312e9b3df365f407aa48b43bc4ca833#b59c0379b312e9b3df365f407aa48b43bc4ca833" dependencies = [ "frame-benchmarking", "frame-support", @@ -7271,7 +7279,7 @@ dependencies = [ [[package]] name = "pallet-xcm-rate-limiter" version = "0.1.0" -source = "git+https://github.com/galacticcouncil/HydraDX-node?rev=38958214930d3156bbaa973c5ace67e823cbdaeb#38958214930d3156bbaa973c5ace67e823cbdaeb" +source = "git+https://github.com/galacticcouncil/HydraDX-node?rev=b59c0379b312e9b3df365f407aa48b43bc4ca833#b59c0379b312e9b3df365f407aa48b43bc4ca833" dependencies = [ "cumulus-pallet-xcmp-queue", "frame-benchmarking", @@ -9113,7 +9121,7 @@ dependencies = [ [[package]] name = "primitives" version = "5.8.2" -source = "git+https://github.com/galacticcouncil/HydraDX-node?rev=38958214930d3156bbaa973c5ace67e823cbdaeb#38958214930d3156bbaa973c5ace67e823cbdaeb" +source = "git+https://github.com/galacticcouncil/HydraDX-node?rev=b59c0379b312e9b3df365f407aa48b43bc4ca833#b59c0379b312e9b3df365f407aa48b43bc4ca833" dependencies = [ "frame-support", "hex-literal 0.3.4", @@ -12754,7 +12762,7 @@ dependencies = [ [[package]] name = "test-utils" version = "1.1.1" -source = "git+https://github.com/galacticcouncil/HydraDX-node?rev=38958214930d3156bbaa973c5ace67e823cbdaeb#38958214930d3156bbaa973c5ace67e823cbdaeb" +source = "git+https://github.com/galacticcouncil/HydraDX-node?rev=b59c0379b312e9b3df365f407aa48b43bc4ca833#b59c0379b312e9b3df365f407aa48b43bc4ca833" dependencies = [ "frame-system", "pretty_assertions", diff --git a/Cargo.toml b/Cargo.toml index 62eca0c184..ee50cb34a6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,23 +12,23 @@ members = [ ] [workspace.dependencies] -hydra-dx-math = { git = "https://github.com/galacticcouncil/HydraDX-node", rev = "38958214930d3156bbaa973c5ace67e823cbdaeb", default-features = false } -hydradx-traits = { git = "https://github.com/galacticcouncil/HydraDX-node", rev = "38958214930d3156bbaa973c5ace67e823cbdaeb", default-features = false } -hydradx-adapters = { git = "https://github.com/galacticcouncil/HydraDX-node", rev = "38958214930d3156bbaa973c5ace67e823cbdaeb", default-features = false } -pallet-relaychain-info = { git = "https://github.com/galacticcouncil/HydraDX-node", rev = "38958214930d3156bbaa973c5ace67e823cbdaeb", default-features = false } -pallet-transaction-multi-payment = { git = "https://github.com/galacticcouncil/HydraDX-node", rev = "38958214930d3156bbaa973c5ace67e823cbdaeb", default-features = false } -pallet-asset-registry = { git = "https://github.com/galacticcouncil/HydraDX-node", rev = "38958214930d3156bbaa973c5ace67e823cbdaeb", default-features = false } -pallet-nft = { git = "https://github.com/galacticcouncil/HydraDX-node", rev = "38958214930d3156bbaa973c5ace67e823cbdaeb", default-features = false } -pallet-currencies = { git = "https://github.com/galacticcouncil/HydraDX-node", rev = "38958214930d3156bbaa973c5ace67e823cbdaeb", default-features = false } -pallet-transaction-pause = { git = "https://github.com/galacticcouncil/HydraDX-node", rev = "38958214930d3156bbaa973c5ace67e823cbdaeb", default-features = false } -pallet-route-executor = { git = "https://github.com/galacticcouncil/HydraDX-node", rev = "38958214930d3156bbaa973c5ace67e823cbdaeb", default-features = false } -pallet-liquidity-mining = { git = "https://github.com/galacticcouncil/HydraDX-node", rev = "38958214930d3156bbaa973c5ace67e823cbdaeb", default-features = false } -warehouse-liquidity-mining = { package="pallet-liquidity-mining", git = "https://github.com/galacticcouncil/HydraDX-node", rev = "38958214930d3156bbaa973c5ace67e823cbdaeb", default-features = false } -pallet-ema-oracle = { git = "https://github.com/galacticcouncil/HydraDX-node", rev = "38958214930d3156bbaa973c5ace67e823cbdaeb", default-features = false } -pallet-duster = { git = "https://github.com/galacticcouncil/HydraDX-node", rev = "38958214930d3156bbaa973c5ace67e823cbdaeb", default-features = false } -pallet-collator-rewards = { git = "https://github.com/galacticcouncil/HydraDX-node", rev = "38958214930d3156bbaa973c5ace67e823cbdaeb", default-features = false } -test-utils = { git = "https://github.com/galacticcouncil/HydraDX-node", rev = "38958214930d3156bbaa973c5ace67e823cbdaeb", default-features = false } -pallet-xcm-rate-limiter = { git = "https://github.com/galacticcouncil/HydraDX-node", rev = "38958214930d3156bbaa973c5ace67e823cbdaeb", default-features = false } +hydra-dx-math = { git = "https://github.com/galacticcouncil/HydraDX-node", rev = "b59c0379b312e9b3df365f407aa48b43bc4ca833", default-features = false } +hydradx-traits = { git = "https://github.com/galacticcouncil/HydraDX-node", rev = "b59c0379b312e9b3df365f407aa48b43bc4ca833", default-features = false } +hydradx-adapters = { git = "https://github.com/galacticcouncil/HydraDX-node", rev = "b59c0379b312e9b3df365f407aa48b43bc4ca833", default-features = false } +pallet-relaychain-info = { git = "https://github.com/galacticcouncil/HydraDX-node", rev = "b59c0379b312e9b3df365f407aa48b43bc4ca833", default-features = false } +pallet-transaction-multi-payment = { git = "https://github.com/galacticcouncil/HydraDX-node", rev = "b59c0379b312e9b3df365f407aa48b43bc4ca833", default-features = false } +pallet-asset-registry = { git = "https://github.com/galacticcouncil/HydraDX-node", rev = "b59c0379b312e9b3df365f407aa48b43bc4ca833", default-features = false } +pallet-nft = { git = "https://github.com/galacticcouncil/HydraDX-node", rev = "b59c0379b312e9b3df365f407aa48b43bc4ca833", default-features = false } +pallet-currencies = { git = "https://github.com/galacticcouncil/HydraDX-node", rev = "b59c0379b312e9b3df365f407aa48b43bc4ca833", default-features = false } +pallet-transaction-pause = { git = "https://github.com/galacticcouncil/HydraDX-node", rev = "b59c0379b312e9b3df365f407aa48b43bc4ca833", default-features = false } +pallet-route-executor = { git = "https://github.com/galacticcouncil/HydraDX-node", rev = "b59c0379b312e9b3df365f407aa48b43bc4ca833", default-features = false } +pallet-liquidity-mining = { git = "https://github.com/galacticcouncil/HydraDX-node", rev = "b59c0379b312e9b3df365f407aa48b43bc4ca833", default-features = false } +warehouse-liquidity-mining = { package="pallet-liquidity-mining", git = "https://github.com/galacticcouncil/HydraDX-node", rev = "b59c0379b312e9b3df365f407aa48b43bc4ca833", default-features = false } +pallet-ema-oracle = { git = "https://github.com/galacticcouncil/HydraDX-node", rev = "b59c0379b312e9b3df365f407aa48b43bc4ca833", default-features = false } +pallet-duster = { git = "https://github.com/galacticcouncil/HydraDX-node", rev = "b59c0379b312e9b3df365f407aa48b43bc4ca833", default-features = false } +pallet-collator-rewards = { git = "https://github.com/galacticcouncil/HydraDX-node", rev = "b59c0379b312e9b3df365f407aa48b43bc4ca833", default-features = false } +test-utils = { git = "https://github.com/galacticcouncil/HydraDX-node", rev = "b59c0379b312e9b3df365f407aa48b43bc4ca833", default-features = false } +pallet-xcm-rate-limiter = { git = "https://github.com/galacticcouncil/HydraDX-node", rev = "b59c0379b312e9b3df365f407aa48b43bc4ca833", default-features = false } [patch."https://github.com/paritytech/substrate"] frame-benchmarking = { git = "https://github.com/paritytech//substrate", branch = "polkadot-v0.9.38" } diff --git a/runtime/basilisk/Cargo.toml b/runtime/basilisk/Cargo.toml index ee18d3e307..303b084436 100644 --- a/runtime/basilisk/Cargo.toml +++ b/runtime/basilisk/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "basilisk-runtime" -version = "104.0.0" +version = "105.0.0" authors = ["GalacticCouncil"] edition = "2021" homepage = "https://github.com/galacticcouncil/Basilisk-node" @@ -208,6 +208,7 @@ std = [ "pallet-utility/std", "pallet-xyk-liquidity-mining/std", "hydradx-traits/std", + "hydradx-adapters/std", "sp-api/std", "sp-block-builder/std", "sp-consensus-aura/std", diff --git a/runtime/basilisk/src/lib.rs b/runtime/basilisk/src/lib.rs index fcb48bf9e8..8c17edf4cb 100644 --- a/runtime/basilisk/src/lib.rs +++ b/runtime/basilisk/src/lib.rs @@ -94,7 +94,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("basilisk"), impl_name: create_runtime_str!("basilisk"), authoring_version: 1, - spec_version: 104, + spec_version: 105, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 1, diff --git a/runtime/basilisk/src/xcm.rs b/runtime/basilisk/src/xcm.rs index ddaff4c5d0..22056f71d4 100644 --- a/runtime/basilisk/src/xcm.rs +++ b/runtime/basilisk/src/xcm.rs @@ -19,6 +19,7 @@ use super::*; use crate::governance::{MajorityTechCommitteeOrRoot, SuperMajorityCouncilOrRoot, TreasuryAccount}; use crate::system::WeightToFee; +use codec::{Decode, Encode, MaxEncodedLen}; use cumulus_primitives_core::ParaId; use frame_support::{ parameter_types, @@ -27,7 +28,10 @@ use frame_support::{ PalletId, }; use frame_system::EnsureRoot; +use hydradx_adapters::xcm_exchange::XcmAssetExchanger; +use hydradx_adapters::xcm_execute_filter::AllowTransferAndSwap; use hydradx_adapters::{MultiCurrencyTrader, ToFeeReceiver}; +use hydradx_traits::router::PoolType; use orml_traits::{location::AbsoluteReserveProvider, parameter_type_with_key}; pub use orml_xcm_support::{DepositToAlternative, IsNativeConcrete, MultiCurrencyAdapter, MultiNativeAsset}; use pallet_transaction_multi_payment::DepositAll; @@ -36,8 +40,6 @@ use polkadot_parachain::primitives::RelayChainBlockNumber; use polkadot_parachain::primitives::Sibling; use polkadot_xcm::v3::{prelude::*, Error, MultiLocation, Weight as XcmWeight}; use primitives::AssetId; - -use codec::{Decode, Encode, MaxEncodedLen}; use scale_info::TypeInfo; use xcm_builder::{ AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, @@ -158,7 +160,7 @@ impl Config for XcmConfig { type ResponseHandler = PolkadotXcm; type AssetTrap = PolkadotXcm; type AssetLocker = (); - type AssetExchanger = (); + type AssetExchanger = XcmAssetExchanger; type AssetClaims = PolkadotXcm; type SubscriptionService = PolkadotXcm; type PalletInstancesInfo = AllPalletsWithSystem; @@ -234,6 +236,16 @@ parameter_types! { pub ReachableDest: Option = Some(Parent.into()); } +parameter_types! { + //Xcm asset exchange + pub DefaultPoolType: PoolType = PoolType::XYK; + pub TempAccount: AccountId = [42; 32].into(); + + //Xcm executor filter + pub const MaxXcmDepth: u16 = 5; + pub const MaxNumberOfInstructions: u16 = 100; +} + impl pallet_xcm::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Currency = Balances; @@ -241,7 +253,7 @@ impl pallet_xcm::Config for Runtime { type SendXcmOrigin = EnsureXcmOrigin; type XcmRouter = XcmRouter; type ExecuteXcmOrigin = EnsureXcmOrigin; - type XcmExecuteFilter = Everything; + type XcmExecuteFilter = AllowTransferAndSwap; type XcmExecutor = XcmExecutor; type XcmTeleportFilter = Nothing; type XcmReserveTransferFilter = Everything; From c2eba58864df127339162acd741e5d87f6068739 Mon Sep 17 00:00:00 2001 From: dmoka Date: Wed, 19 Jul 2023 16:10:55 +0200 Subject: [PATCH 2/6] add integration tests for exchange asset --- integration-tests/src/exchange_asset.rs | 261 +++++++++++++++++++++++ integration-tests/src/kusama_test_net.rs | 3 +- integration-tests/src/lib.rs | 1 + 3 files changed, 264 insertions(+), 1 deletion(-) create mode 100644 integration-tests/src/exchange_asset.rs diff --git a/integration-tests/src/exchange_asset.rs b/integration-tests/src/exchange_asset.rs new file mode 100644 index 0000000000..dcb139299f --- /dev/null +++ b/integration-tests/src/exchange_asset.rs @@ -0,0 +1,261 @@ +#![cfg(test)] + +use crate::kusama_test_net::*; +use basilisk_runtime::RuntimeOrigin; +use basilisk_runtime::XYK; +use frame_support::dispatch::GetDispatchInfo; +use frame_support::weights::Weight; +use frame_support::{assert_ok, pallet_prelude::*}; +use orml_traits::currency::MultiCurrency; +use polkadot_xcm::{latest::prelude::*, VersionedXcm}; +use pretty_assertions::assert_eq; +use primitives::constants::chain::CORE_ASSET_ID; +use sp_runtime::FixedU128; +use xcm_emulator::TestExt; + +pub const SELL: bool = true; +pub const BUY: bool = false; + +#[test] +fn basilisk_should_swap_assets_when_receiving_from_otherchain_with_sell() { + //Arrange + TestNet::reset(); + + Basilisk::execute_with(|| { + register_kar(); + add_currency_price(KAR, FixedU128::from(1)); + + assert_ok!(basilisk_runtime::Tokens::deposit(KAR, &CHARLIE.into(), 3000 * UNITS)); + create_xyk_pool(KAR, BSX); + }); + + OtherParachain::execute_with(|| { + let xcm = craft_exchange_asset_xcm::<_, parachain_runtime_mock::RuntimeCall>( + MultiAsset::from((GeneralIndex(0), 5 * UNITS)), + MultiAsset::from((GeneralIndex(CORE_ASSET_ID.into()), 2 * UNITS)), + SELL, + ); + //Act + let res = parachain_runtime_mock::PolkadotXcm::execute( + parachain_runtime_mock::RuntimeOrigin::signed(ALICE.into()), + Box::new(xcm), + Weight::from_ref_time(399_600_000_000), + ); + assert_ok!(res); + + //Assert + assert_eq!( + parachain_runtime_mock::Balances::free_balance(AccountId::from(ALICE)), + ALICE_INITIAL_NATIVE_BALANCE_ON_OTHER_PARACHAIN - 100 * UNITS + ); + + assert!(matches!( + last_other_para_events(2).first(), + Some(parachain_runtime_mock::RuntimeEvent::XcmpQueue( + cumulus_pallet_xcmp_queue::Event::XcmpMessageSent { .. } + )) + )); + }); + + let fees = 27_500_000_000_000; + Basilisk::execute_with(|| { + assert_eq!( + basilisk_runtime::Tokens::free_balance(KAR, &AccountId::from(BOB)), + 95000000000000 - fees + ); + let received = BOB_INITIAL_BSX_BALANCE + 2373809523812; + assert_eq!( + basilisk_runtime::Balances::free_balance(&AccountId::from(BOB)), + received + ); + assert_eq!( + basilisk_runtime::Tokens::free_balance(KAR, &basilisk_runtime::Treasury::account_id()), + fees + ); + }); +} + +#[test] +fn basilisk_should_swap_assets_when_receiving_from_otherchain_with_buy() { + //Arrange + TestNet::reset(); + + Basilisk::execute_with(|| { + register_kar(); + add_currency_price(KAR, FixedU128::from(1)); + + assert_ok!(basilisk_runtime::Tokens::deposit(KAR, &CHARLIE.into(), 3000 * UNITS)); + assert_ok!(basilisk_runtime::Tokens::deposit(BSX, &CHARLIE.into(), 3000 * UNITS)); + assert_ok!(XYK::create_pool( + RuntimeOrigin::signed(CHARLIE.into()), + KAR, + 1000 * UNITS, + BSX, + 500 * UNITS, + )); + }); + + let amount_out = 20 * UNITS; + OtherParachain::execute_with(|| { + let xcm = craft_exchange_asset_xcm::<_, parachain_runtime_mock::RuntimeCall>( + MultiAsset::from((GeneralIndex(0), 70 * UNITS)), + MultiAsset::from((GeneralIndex(CORE_ASSET_ID.into()), amount_out)), + BUY, + ); + //Act + let res = parachain_runtime_mock::PolkadotXcm::execute( + parachain_runtime_mock::RuntimeOrigin::signed(ALICE.into()), + Box::new(xcm), + Weight::from_ref_time(399_600_000_000), + ); + assert_ok!(res); + + //Assert + assert_eq!( + parachain_runtime_mock::Balances::free_balance(AccountId::from(ALICE)), + ALICE_INITIAL_NATIVE_BALANCE_ON_OTHER_PARACHAIN - 100 * UNITS + ); + + assert!(matches!( + last_other_para_events(2).first(), + Some(parachain_runtime_mock::RuntimeEvent::XcmpQueue( + cumulus_pallet_xcmp_queue::Event::XcmpMessageSent { .. } + )) + )); + }); + + let fees = 27_500_000_000_000; + let amount_in = 41_791_666_666_665; + + Basilisk::execute_with(|| { + assert_eq!( + basilisk_runtime::Tokens::free_balance(KAR, &AccountId::from(BOB)), + 100 * UNITS - amount_in - fees + ); + + assert_eq!( + basilisk_runtime::Balances::free_balance(&AccountId::from(BOB)), + BOB_INITIAL_BSX_BALANCE + amount_out + ); + assert_eq!( + basilisk_runtime::Tokens::free_balance(KAR, &basilisk_runtime::Treasury::account_id()), + fees + ); + }); +} + +fn register_kar() { + assert_ok!(basilisk_runtime::AssetRegistry::register( + basilisk_runtime::RuntimeOrigin::root(), + b"KAR".to_vec(), + pallet_asset_registry::AssetType::Token, + 1_000_000, + Some(KAR), + None, + Some(basilisk_runtime::AssetLocation(MultiLocation::new( + 1, + X2(Parachain(OTHER_PARA_ID), GeneralIndex(0)) + ))), + None + )); +} + +fn add_currency_price(asset_id: u32, price: FixedU128) { + assert_ok!(basilisk_runtime::MultiTransactionPayment::add_currency( + basilisk_runtime::RuntimeOrigin::root(), + asset_id, + price, + )); + + // make sure the price is propagated + basilisk_runtime::MultiTransactionPayment::on_initialize(basilisk_runtime::System::block_number()); +} + +fn craft_exchange_asset_xcm, RC: Decode + GetDispatchInfo>( + give: MultiAsset, + want: M, + is_sell: bool, +) -> VersionedXcm { + use kusama_runtime::xcm_config::BaseXcmWeight; + use xcm_builder::FixedWeightBounds; + use xcm_executor::traits::WeightBounds; + + type Weigher = FixedWeightBounds>; + + let dest = MultiLocation::new(1, Parachain(BASILISK_PARA_ID)); + let beneficiary = Junction::AccountId32 { id: BOB, network: None }.into(); + let assets: MultiAssets = MultiAsset::from((GeneralIndex(0), 100 * UNITS)).into(); // hardcoded + let max_assets = assets.len() as u32 + 1; + let context = X2(GlobalConsensus(NetworkId::Polkadot), Parachain(OTHER_PARA_ID)); + let fees = assets + .get(0) + .expect("should have at least 1 asset") + .clone() + .reanchored(&dest, context) + .expect("should reanchor"); + let give = give.reanchored(&dest, context).expect("should reanchor give"); + let give: MultiAssetFilter = Definite(give.into()); + let want = want.into(); + let weight_limit = { + let fees = fees.clone(); + let mut remote_message = Xcm(vec![ + ReserveAssetDeposited::(assets.clone()), + ClearOrigin, + BuyExecution { + fees, + weight_limit: Limited(Weight::zero()), + }, + ExchangeAsset { + give: give.clone(), + want: want.clone(), + maximal: is_sell, + }, + DepositAsset { + assets: Wild(AllCounted(max_assets)), + beneficiary, + }, + ]); + // use local weight for remote message and hope for the best. + let remote_weight = Weigher::weight(&mut remote_message).expect("weighing should not fail"); + Limited(remote_weight) + }; + // executed on remote (on hydra) + let xcm = Xcm(vec![ + BuyExecution { fees, weight_limit }, + ExchangeAsset { + give, + want, + maximal: is_sell, + }, + DepositAsset { + assets: Wild(AllCounted(max_assets)), + beneficiary, + }, + ]); + // executed on local (acala) + let message = Xcm(vec![ + SetFeesMode { jit_withdraw: true }, + TransferReserveAsset { assets, dest, xcm }, + ]); + VersionedXcm::V3(message) +} + +pub fn last_other_para_events(n: usize) -> Vec { + frame_system::Pallet::::events() + .into_iter() + .rev() + .take(n) + .rev() + .map(|e| e.event) + .collect() +} + +fn create_xyk_pool(asset_a: u32, asset_b: u32) { + assert_ok!(XYK::create_pool( + RuntimeOrigin::signed(CHARLIE.into()), + asset_a, + 100 * UNITS, + asset_b, + 50 * UNITS, + )); +} diff --git a/integration-tests/src/kusama_test_net.rs b/integration-tests/src/kusama_test_net.rs index 40a44a4736..fc1eb34490 100644 --- a/integration-tests/src/kusama_test_net.rs +++ b/integration-tests/src/kusama_test_net.rs @@ -18,6 +18,7 @@ pub const AUSD: AssetId = 1; pub const MOVR: AssetId = 2; pub const KSM: AssetId = 3; pub const NEW_BOOTSTRAPPED_TOKEN: AssetId = 4; +pub const KAR: AssetId = 5; pub const ALICE_INITIAL_BSX_BALANCE: u128 = 1_000 * UNITS; pub const BOB_INITIAL_BSX_BALANCE: u128 = 1000 * UNITS; @@ -277,7 +278,7 @@ pub fn other_parachain_ext() -> sp_io::TestExternalities { pallet_asset_registry::GenesisConfig:: { registered_assets: vec![(b"AUSD".to_vec(), 1_000_000u128, Some(AUSD))], - native_asset_name: b"BSX".to_vec(), + native_asset_name: b"KAR".to_vec(), native_existential_deposit: existential_deposit, } .assimilate_storage(&mut t) diff --git a/integration-tests/src/lib.rs b/integration-tests/src/lib.rs index 3841e8fafe..c6c0e54b49 100644 --- a/integration-tests/src/lib.rs +++ b/integration-tests/src/lib.rs @@ -11,3 +11,4 @@ mod transact_call_filter; mod vesting; mod xcm_rate_limiter; mod xyk; +mod exchange_asset; From 794912d9f8a2c253be2cead9abf65c174b98124d Mon Sep 17 00:00:00 2001 From: dmoka Date: Thu, 20 Jul 2023 10:25:08 +0200 Subject: [PATCH 3/6] bump version --- integration-tests/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index 45a5d174cd..27693b61a0 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "runtime-integration-tests" -version = "0.9.13" +version = "0.9.14" description = "Integration tests" authors = ["GalacticCouncil"] edition = "2021" From a504b1f3092209f62fb6cf74ba55736d9bba45ea Mon Sep 17 00:00:00 2001 From: dmoka Date: Thu, 20 Jul 2023 10:25:33 +0200 Subject: [PATCH 4/6] formatting --- integration-tests/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration-tests/src/lib.rs b/integration-tests/src/lib.rs index c6c0e54b49..64ab0f6adc 100644 --- a/integration-tests/src/lib.rs +++ b/integration-tests/src/lib.rs @@ -1,5 +1,6 @@ mod call_filter; mod cross_chain_transfer; +mod exchange_asset; mod fees; mod kusama_test_net; mod nft; @@ -11,4 +12,3 @@ mod transact_call_filter; mod vesting; mod xcm_rate_limiter; mod xyk; -mod exchange_asset; From 17eaf53f8df2e23d4c1f71a70ac2730df198cbff Mon Sep 17 00:00:00 2001 From: dmoka Date: Thu, 20 Jul 2023 10:28:11 +0200 Subject: [PATCH 5/6] update lock file --- Cargo.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index dfb83c9638..2cee7e36f5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9869,7 +9869,7 @@ dependencies = [ [[package]] name = "runtime-integration-tests" -version = "0.9.13" +version = "0.9.14" dependencies = [ "basilisk-runtime", "cumulus-pallet-aura-ext", From 7c29c038a2d362d71cae46518db0ccec610c6583 Mon Sep 17 00:00:00 2001 From: dmoka Date: Tue, 25 Jul 2023 14:43:39 +0200 Subject: [PATCH 6/6] install proto before rust tool chain installation because it complains for that --- .github/workflows/workflow.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 6d8f8417fa..264b5590f8 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -22,6 +22,8 @@ jobs: - run: git describe --tags --abbrev=0 --always - name: Setup cmake uses: jwlawson/actions-setup-cmake@v1.12 + - name: Install misc dependencies + run: sudo rm /var/lib/dpkg/lock-frontend && sudo rm /var/lib/dpkg/lock && sudo apt-get install -y protobuf-compiler m4 - name: Install Rust uses: codota/toolchain@00a8bf2bdcfe93aefd70422d3dec07337959d3a4 with: