diff --git a/Cargo.lock b/Cargo.lock index 127a77ec632..018886cd5e9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -486,7 +486,7 @@ dependencies = [ [[package]] name = "basilisk-runtime" -version = "53.0.0" +version = "54.0.0" dependencies = [ "common-runtime", "cumulus-pallet-aura-ext", @@ -506,6 +506,7 @@ dependencies = [ "frame-system-rpc-runtime-api", "frame-try-runtime", "hex-literal", + "hydradx-adapters", "hydradx-traits", "orml-benchmarking", "orml-currencies", @@ -3186,6 +3187,23 @@ dependencies = [ "sp-arithmetic", ] +[[package]] +name = "hydradx-adapters" +version = "0.1.0" +source = "git+https://github.com/galacticcouncil/warehouse?rev=7052eeab309742dccfe7e307c15fc4f780713553#7052eeab309742dccfe7e307c15fc4f780713553" +dependencies = [ + "frame-support", + "hydradx-traits", + "log", + "pallet-transaction-multi-payment", + "parity-scale-codec", + "sp-runtime", + "sp-std", + "xcm", + "xcm-builder", + "xcm-executor", +] + [[package]] name = "hydradx-traits" version = "0.6.0" @@ -8690,7 +8708,7 @@ dependencies = [ [[package]] name = "runtime-integration-tests" -version = "0.3.1" +version = "0.3.2" dependencies = [ "basilisk-runtime", "cumulus-pallet-aura-ext", @@ -11212,7 +11230,7 @@ dependencies = [ [[package]] name = "testing-basilisk-runtime" -version = "53.0.0" +version = "54.0.0" dependencies = [ "common-runtime", "cumulus-pallet-aura-ext", @@ -11232,6 +11250,7 @@ dependencies = [ "frame-system-rpc-runtime-api", "frame-try-runtime", "hex-literal", + "hydradx-adapters", "hydradx-traits", "orml-currencies", "orml-tokens", diff --git a/Cargo.toml b/Cargo.toml index 3a52cb48faf..5eed17555fe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -56,7 +56,7 @@ pallet-proxy = { git = "https://github.com/paritytech//substrate", rev = "22d40c pallet-recovery = { git = "https://github.com/paritytech//substrate", rev = "22d40c761a985482f93bbbea5ba4199bdba74f8e" } pallet-scheduler = { git = "https://github.com/paritytech//substrate", rev = "22d40c761a985482f93bbbea5ba4199bdba74f8e" } pallet-session = { git = "https://github.com/paritytech//substrate", rev = "22d40c761a985482f93bbbea5ba4199bdba74f8e" } -pallet-session-benchmarking = { git = "https://github.com/paritytech//substrate", rev = "22d40c761a985482f93bbbea5ba4199bdba74f8e" } +pallet-session-benchmarking = { git = "https://github.com/paritytech//substrate", rev = "22d40c761a985482f93bbbea5ba4199bdba74f8e" } pallet-society = { git = "https://github.com/paritytech//substrate", rev = "22d40c761a985482f93bbbea5ba4199bdba74f8e" } pallet-staking = { git = "https://github.com/paritytech//substrate", rev = "22d40c761a985482f93bbbea5ba4199bdba74f8e" } pallet-staking-reward-curve = { git = "https://github.com/paritytech//substrate", rev = "22d40c761a985482f93bbbea5ba4199bdba74f8e" } @@ -185,7 +185,7 @@ cumulus-client-network = { git = "https://github.com/paritytech//cumulus", rev = cumulus-client-service = { git = "https://github.com/paritytech//cumulus", rev = "76479e7fef3af7c8828a44647847b01afd5fefe5" } cumulus-pallet-aura-ext = { git = "https://github.com/paritytech//cumulus", rev = "76479e7fef3af7c8828a44647847b01afd5fefe5" } cumulus-pallet-dmp-queue = { git = "https://github.com/paritytech//cumulus", rev = "76479e7fef3af7c8828a44647847b01afd5fefe5" } -cumulus-pallet-parachain-system = { git = "https://github.com/paritytech//cumulus", rev = "76479e7fef3af7c8828a44647847b01afd5fefe5" } +cumulus-pallet-parachain-system = { git = "https://github.com/paritytech//cumulus", rev = "76479e7fef3af7c8828a44647847b01afd5fefe5" } cumulus-pallet-xcm = { git = "https://github.com/paritytech//cumulus", rev = "76479e7fef3af7c8828a44647847b01afd5fefe5" } cumulus-pallet-xcmp-queue = { git = "https://github.com/paritytech//cumulus", rev = "76479e7fef3af7c8828a44647847b01afd5fefe5" } cumulus-primitives-core = { git = "https://github.com/paritytech//cumulus", rev = "76479e7fef3af7c8828a44647847b01afd5fefe5" } @@ -193,7 +193,7 @@ cumulus-primitives-parachain-inherent = { git = "https://github.com/paritytech// cumulus-primitives-timestamp = { git = "https://github.com/paritytech//cumulus", rev = "76479e7fef3af7c8828a44647847b01afd5fefe5" } cumulus-primitives-utility = { git = "https://github.com/paritytech//cumulus", rev = "76479e7fef3af7c8828a44647847b01afd5fefe5" } cumulus-test-relay-sproof-builder = { git = "https://github.com/paritytech//cumulus", rev = "76479e7fef3af7c8828a44647847b01afd5fefe5" } -parachain-info = { git = "https://github.com/paritytech//cumulus", rev = "76479e7fef3af7c8828a44647847b01afd5fefe5" } +parachain-info = { git = "https://github.com/paritytech//cumulus", rev = "76479e7fef3af7c8828a44647847b01afd5fefe5" } cumulus-relay-chain-interface = { git = "https://github.com/paritytech//cumulus", rev = "76479e7fef3af7c8828a44647847b01afd5fefe5" } cumulus-relay-chain-local = { git = "https://github.com/paritytech//cumulus", rev = "76479e7fef3af7c8828a44647847b01afd5fefe5" } diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index 15e0a17c154..5afb404d165 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "runtime-integration-tests" -version = "0.3.1" +version = "0.3.2" description = "Integration tests" authors = ["GalacticCouncil"] edition = "2021" @@ -10,8 +10,8 @@ repository = "https://github.com/galacticcouncil/Basilisk-node" [dependencies] # local dependencies -pallet-transaction-multi-payment = { git = "https://github.com/galacticcouncil/warehouse", rev = "50c82ab02bb5baf99b263342dc5d4cc7e62c7e88", default-features = false} -pallet-price-oracle = { git = "https://github.com/galacticcouncil/warehouse", rev = "50c82ab02bb5baf99b263342dc5d4cc7e62c7e88", default-features = false} +pallet-transaction-multi-payment = { git = "https://github.com/galacticcouncil/warehouse", rev = "7052eeab309742dccfe7e307c15fc4f780713553", default-features = false} +pallet-price-oracle = { git = "https://github.com/galacticcouncil/warehouse", rev = "7052eeab309742dccfe7e307c15fc4f780713553", default-features = false} pallet-exchange = { path = "../pallets/exchange", default-features=false} pallet-exchange-benchmarking = { path = "../pallets/exchange/benchmarking", optional = true, default-features = false} @@ -65,8 +65,8 @@ xcm-executor = { git = "https://github.com/paritytech/polkadot", branch = "relea polkadot-xcm = { package = "xcm", git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.17", default-features = false } # HydraDX dependencies -pallet-asset-registry = { git = "https://github.com/galacticcouncil/warehouse", rev = "50c82ab02bb5baf99b263342dc5d4cc7e62c7e88", default-features = false } -hydradx-traits = { git = "https://github.com/galacticcouncil/warehouse", rev = "50c82ab02bb5baf99b263342dc5d4cc7e62c7e88", default-features = false } +pallet-asset-registry = { git = "https://github.com/galacticcouncil/warehouse", rev = "7052eeab309742dccfe7e307c15fc4f780713553", default-features = false } +hydradx-traits = { git = "https://github.com/galacticcouncil/warehouse", rev = "7052eeab309742dccfe7e307c15fc4f780713553", default-features = false } # Substrate dependencies frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.17", default-features = false, optional = true } diff --git a/integration-tests/src/cross_chain_transfer.rs b/integration-tests/src/cross_chain_transfer.rs index 596212e7753..f945461b203 100644 --- a/integration-tests/src/cross_chain_transfer.rs +++ b/integration-tests/src/cross_chain_transfer.rs @@ -44,7 +44,11 @@ fn transfer_from_relay_chain() { Basilisk::execute_with(|| { assert_eq!( basilisk_runtime::Tokens::free_balance(1, &AccountId::from(BOB)), - 1003 * BSX + 10028 * BSX / 10 // 3 BSX - fees + ); + assert_eq!( + basilisk_runtime::Tokens::free_balance(1, &basilisk_runtime::Treasury::account_id()), + 2 * BSX / 10 // fees should go to treasury ); }); } @@ -129,7 +133,11 @@ fn transfer_from_hydra() { Basilisk::execute_with(|| { assert_eq!( basilisk_runtime::Tokens::free_balance(1, &AccountId::from(BOB)), - 1003 * BSX + 10028 * BSX / 10 // 3 * BSX - fees + ); + assert_eq!( + basilisk_runtime::Tokens::free_balance(1, &basilisk_runtime::Treasury::account_id()), + 2 * BSX / 10 // fees should go to treasury ); }); } @@ -233,9 +241,14 @@ fn fee_currency_set_on_xcm_transfer() { }); Basilisk::execute_with(|| { + let fee_amount = 2 * BSX / 10; assert_eq!( basilisk_runtime::Tokens::free_balance(1, &AccountId::from(HITCHHIKER)), - transfer_amount + transfer_amount - fee_amount + ); + assert_eq!( + basilisk_runtime::Tokens::free_balance(1, &basilisk_runtime::Treasury::account_id()), + fee_amount // fees should go to treasury ); // fee currency is set after XCM transfer assert_eq!( diff --git a/integration-tests/src/kusama_test_net.rs b/integration-tests/src/kusama_test_net.rs index 159cbdbec6e..0fd9afb4056 100644 --- a/integration-tests/src/kusama_test_net.rs +++ b/integration-tests/src/kusama_test_net.rs @@ -164,7 +164,8 @@ pub fn hydra_ext() -> sp_io::TestExternalities { } pub fn basilisk_ext() -> sp_io::TestExternalities { - use basilisk_runtime::{NativeExistentialDeposit, Runtime, System}; + use basilisk_runtime::{MultiTransactionPayment, NativeExistentialDeposit, Runtime, System}; + use frame_support::traits::OnInitialize; let existential_deposit = NativeExistentialDeposit::get(); @@ -225,7 +226,11 @@ pub fn basilisk_ext() -> sp_io::TestExternalities { .unwrap(); let mut ext = sp_io::TestExternalities::new(t); - ext.execute_with(|| System::set_block_number(1)); + ext.execute_with(|| { + System::set_block_number(1); + // Make sure the prices are up-to-date. + MultiTransactionPayment::on_initialize(1); + }); ext } diff --git a/runtime/basilisk/Cargo.toml b/runtime/basilisk/Cargo.toml index 00fb3f3b473..7214d132ea5 100644 --- a/runtime/basilisk/Cargo.toml +++ b/runtime/basilisk/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "basilisk-runtime" -version = "53.0.0" +version = "54.0.0" authors = ["GalacticCouncil"] edition = "2021" homepage = "https://github.com/galacticcouncil/Basilisk-node" @@ -49,6 +49,7 @@ pallet-price-oracle = { git = "https://github.com/galacticcouncil/warehouse", re pallet-transaction-multi-payment = { git = "https://github.com/galacticcouncil/warehouse", rev = "7052eeab309742dccfe7e307c15fc4f780713553", default-features = false} pallet-relaychain-info = { git = "https://github.com/galacticcouncil/warehouse", rev = "7052eeab309742dccfe7e307c15fc4f780713553", default-features = false } pallet-asset-registry = { git = "https://github.com/galacticcouncil/warehouse", rev = "7052eeab309742dccfe7e307c15fc4f780713553", default-features = false } +hydradx-adapters = { git = "https://github.com/galacticcouncil/warehouse",rev = "7052eeab309742dccfe7e307c15fc4f780713553", default-features = false } # collator support pallet-collator-selection = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.17", default-features = false } @@ -202,6 +203,7 @@ std = [ "pallet-lbp/std", "pallet-price-oracle/std", "pallet-utility/std", + "hydradx-adapters/std", "hydradx-traits/std", "sp-api/std", "sp-block-builder/std", diff --git a/runtime/basilisk/src/lib.rs b/runtime/basilisk/src/lib.rs index d73ee1b1f17..508131e9a74 100644 --- a/runtime/basilisk/src/lib.rs +++ b/runtime/basilisk/src/lib.rs @@ -105,7 +105,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("basilisk"), impl_name: create_runtime_str!("basilisk"), authoring_version: 1, - spec_version: 53, + spec_version: 54, 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 e792b1033d4..626d8ab8763 100644 --- a/runtime/basilisk/src/xcm.rs +++ b/runtime/basilisk/src/xcm.rs @@ -5,12 +5,15 @@ use frame_support::{ traits::{Everything, Nothing}, PalletId, }; +use hydradx_adapters::{MultiCurrencyTrader, ToFeeReceiver}; pub use orml_xcm_support::{DepositToAlternative, IsNativeConcrete, MultiCurrencyAdapter, MultiNativeAsset}; use pallet_xcm::XcmPassthrough; use polkadot_parachain::primitives::Sibling; use polkadot_xcm::latest::prelude::*; use polkadot_xcm::latest::Error; +use primitives::Price; use sp_runtime::traits::Convert; + use xcm_builder::{ AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, AllowTopLevelPaidExecutionFrom, EnsureXcmOrigin, FixedWeightBounds, LocationInverter, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, @@ -96,7 +99,26 @@ impl Config for XcmConfig { type Barrier = Barrier; type Weigher = FixedWeightBounds; - type Trader = TradePassthrough; + // We calculate weight fees the same way as for regular extrinsics and use the prices and choice + // of accepted currencies of the transaction payment pallet. Fees go to the same fee receiver as + // configured in `MultiTransactionPayment`. + type Trader = MultiCurrencyTrader< + AssetId, + Balance, + Price, + WeightToFee, + MultiTransactionPayment, + CurrencyIdConvert, + ToFeeReceiver< + AccountId, + AssetId, + Balance, + Price, + CurrencyIdConvert, + DepositAll, + MultiTransactionPayment, + >, + >; type ResponseHandler = PolkadotXcm; type AssetTrap = PolkadotXcm; diff --git a/runtime/testing-basilisk/Cargo.toml b/runtime/testing-basilisk/Cargo.toml index bdf1e11b5b3..ce57f754f5f 100644 --- a/runtime/testing-basilisk/Cargo.toml +++ b/runtime/testing-basilisk/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "testing-basilisk-runtime" -version = "53.0.0" +version = "54.0.0" authors = ["GalacticCouncil"] edition = "2021" homepage = "https://github.com/galacticcouncil/Basilisk-node" @@ -49,6 +49,7 @@ pallet-price-oracle = { git = "https://github.com/galacticcouncil/warehouse", re pallet-relaychain-info = { git = "https://github.com/galacticcouncil/warehouse", rev = "7052eeab309742dccfe7e307c15fc4f780713553", default-features = false } pallet-transaction-multi-payment = { git = "https://github.com/galacticcouncil/warehouse", rev = "7052eeab309742dccfe7e307c15fc4f780713553", default-features = false} pallet-asset-registry = { git = "https://github.com/galacticcouncil/warehouse", rev = "7052eeab309742dccfe7e307c15fc4f780713553", default-features = false } +hydradx-adapters = { git = "https://github.com/galacticcouncil/warehouse",rev = "7052eeab309742dccfe7e307c15fc4f780713553", default-features = false } # collator support pallet-collator-selection = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.17", default-features = false } diff --git a/runtime/testing-basilisk/src/lib.rs b/runtime/testing-basilisk/src/lib.rs index 5ea5d8db6d6..eb214675316 100644 --- a/runtime/testing-basilisk/src/lib.rs +++ b/runtime/testing-basilisk/src/lib.rs @@ -113,7 +113,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("testing-basilisk"), impl_name: create_runtime_str!("testing-basilisk"), authoring_version: 1, - spec_version: 53, + spec_version: 54, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 1, diff --git a/runtime/testing-basilisk/src/xcm.rs b/runtime/testing-basilisk/src/xcm.rs index e792b1033d4..44dbd41bcba 100644 --- a/runtime/testing-basilisk/src/xcm.rs +++ b/runtime/testing-basilisk/src/xcm.rs @@ -5,6 +5,7 @@ use frame_support::{ traits::{Everything, Nothing}, PalletId, }; +use hydradx_adapters::{MultiCurrencyTrader, ToFeeReceiver}; pub use orml_xcm_support::{DepositToAlternative, IsNativeConcrete, MultiCurrencyAdapter, MultiNativeAsset}; use pallet_xcm::XcmPassthrough; use polkadot_parachain::primitives::Sibling; @@ -96,7 +97,26 @@ impl Config for XcmConfig { type Barrier = Barrier; type Weigher = FixedWeightBounds; - type Trader = TradePassthrough; + // We calculate weight fees the same way as for regular extrinsics and use the prices and choice + // of accepted currencies of the transaction payment pallet. Fees go to the same fee receiver as + // configured in `MultiTransactionPayment`. + type Trader = MultiCurrencyTrader< + AssetId, + Balance, + Price, + WeightToFee, + MultiTransactionPayment, + CurrencyIdConvert, + ToFeeReceiver< + AccountId, + AssetId, + Balance, + Price, + CurrencyIdConvert, + DepositAll, + MultiTransactionPayment, + >, + >; type ResponseHandler = PolkadotXcm; type AssetTrap = PolkadotXcm; @@ -167,6 +187,7 @@ impl pallet_xcm::Config for Runtime { pub struct CurrencyIdConvert; use primitives::constants::chain::CORE_ASSET_ID; +use primitives::Price; impl Convert> for CurrencyIdConvert { fn convert(id: AssetId) -> Option {