From eaa4cbf39349e22d165d69253884d4f9e1d58226 Mon Sep 17 00:00:00 2001 From: Gianfranco Tasteri Date: Wed, 3 Jan 2024 18:25:15 -0300 Subject: [PATCH] wip add custom update code, workaround for TakeFirstAsset trader --- runtime/amplitude/src/lib.rs | 7 ++- runtime/amplitude/src/xcm_config.rs | 85 +++++++++++++++++++++++++++- runtime/pendulum/src/xcm_config.rs | 86 +++++++++++++++++++++++++++-- 3 files changed, 169 insertions(+), 9 deletions(-) diff --git a/runtime/amplitude/src/lib.rs b/runtime/amplitude/src/lib.rs index da62ae2a1..95d7db851 100644 --- a/runtime/amplitude/src/lib.rs +++ b/runtime/amplitude/src/lib.rs @@ -147,14 +147,17 @@ pub type SignedPayload = generic::SignedPayload; pub type CheckedExtrinsic = generic::CheckedExtrinsic; use crate::sp_api_hidden_includes_construct_runtime::hidden_include::dispatch::GetStorageVersion; +use frame_support::pallet_prelude::StorageVersion; pub struct CustomOnRuntimeUpgrade; impl frame_support::traits::OnRuntimeUpgrade for CustomOnRuntimeUpgrade { fn on_runtime_upgrade() -> frame_support::weights::Weight { log::info!("Custom on-runtime-upgrade function"); if Contracts::on_chain_storage_version() == 0 { + log::info!{"version for pallet_xcm {:?}",StorageVersion::get::()}; + log::info!{"version for tx payment {:?}",StorageVersion::get::()}; log::info!("Upgrading pallet contract's storage version to 10"); - StorageVersion::new(0).put::(); + StorageVersion::new(10).put::(); } // not really a heavy operation frame_support::weights::Weight::zero() @@ -167,7 +170,7 @@ pub type Executive = frame_executive::Executive< frame_system::ChainContext, Runtime, AllPalletsWithSystem, - CustomOnRuntimeUpgrade + (CustomOnRuntimeUpgrade, pallet_xcm::migration::v1::MigrateToV1) >; pub struct AmplitudeDiaOracleKeyConverter; diff --git a/runtime/amplitude/src/xcm_config.rs b/runtime/amplitude/src/xcm_config.rs index 3ded549f5..604daa1a1 100644 --- a/runtime/amplitude/src/xcm_config.rs +++ b/runtime/amplitude/src/xcm_config.rs @@ -2,8 +2,9 @@ use core::marker::PhantomData; use frame_support::{ log, match_types, parameter_types, - traits::{ContainsPair, Everything, Nothing, ProcessMessageError}, + traits::{ContainsPair, Everything, Nothing, ProcessMessageError, tokens::fungibles}, weights::{Weight, WeightToFee as WeightToFeeTrait}, + pallet_prelude::DispatchError, }; use orml_traits::{ location::{RelativeReserveProvider, Reserve}, @@ -38,6 +39,7 @@ use crate::{ xcm_assets, }, ConstU32, + }; use super::{ @@ -305,7 +307,7 @@ pub type Barrier = ( ); pub struct ChargeWeightInFungiblesImplementation; -impl ChargeWeightInFungibles for ChargeWeightInFungiblesImplementation { +impl ChargeWeightInFungibles for ChargeWeightInFungiblesImplementation { fn charge_weight_in_fungibles( asset_id: CurrencyId, weight: Weight, @@ -324,16 +326,93 @@ impl ChargeWeightInFungibles for ChargeWeightInFungiblesImple } } +// Workarround for TakeFirstAssetTrader +use frame_support::traits::tokens::{Preservation, Fortitude, Provenance, WithdrawConsequence, DepositConsequence}; + +pub struct ConcreteAssets; +impl fungibles::Mutate for ConcreteAssets {} +impl fungibles::Balanced for ConcreteAssets { + type OnDropCredit = fungibles::DecreaseIssuance; + type OnDropDebt = fungibles::IncreaseIssuance; +} +impl fungibles::Inspect for ConcreteAssets { + type AssetId = >::AssetId; + type Balance = >::Balance; + + fn minimum_balance(id: Self::AssetId) -> Self::Balance { + Tokens::minimum_balance(id) + } + + fn total_issuance(asset_id: Self::AssetId) -> Self::Balance { + Tokens::total_issuance(asset_id) + } + + fn balance(asset_id: Self::AssetId, account_id: &AccountId) -> Self::Balance { + Tokens::balance(asset_id, account_id) + } + + fn total_balance(asset_id: Self::AssetId, account_id: &AccountId) -> Self::Balance { + Tokens::balance(asset_id, account_id) + } + + fn reducible_balance( + _: Self::AssetId, + _: &AccountId, + _: Preservation, + _: Fortitude, + ) -> Self::Balance { + todo!() + } + + fn can_deposit( + _: Self::AssetId, + _: &AccountId, + _: Self::Balance, + _: Provenance, + ) -> DepositConsequence { + todo!() + } + + fn can_withdraw( + _: Self::AssetId, + _: &AccountId, + _: Self::Balance, + ) -> WithdrawConsequence { + todo!() + } + + fn asset_exists(_: Self::AssetId) -> bool { + todo!() + } + +} +impl fungibles::Unbalanced for ConcreteAssets { + fn handle_dust(_: fungibles::Dust) { + todo!() + } + fn write_balance( + _: Self::AssetId, + _: &AccountId, + _: Self::Balance, + ) -> Result, DispatchError> { + todo!() + } + + fn set_total_issuance(_: Self::AssetId, _: Self::Balance) { + todo!() + } +} pub type Traders = ( TakeFirstAssetTrader< AccountId, ChargeWeightInFungiblesImplementation, ConvertedConcreteId, - Tokens, + ConcreteAssets, XcmFeesTo32ByteAccount, >, ); + pub struct XcmConfig; impl xcm_executor::Config for XcmConfig { type RuntimeCall = RuntimeCall; diff --git a/runtime/pendulum/src/xcm_config.rs b/runtime/pendulum/src/xcm_config.rs index fe12f7b00..4170f7aaf 100644 --- a/runtime/pendulum/src/xcm_config.rs +++ b/runtime/pendulum/src/xcm_config.rs @@ -5,8 +5,9 @@ use cumulus_primitives_utility::{ }; use frame_support::{ log, match_types, parameter_types, - traits::{ContainsPair, Everything, Nothing, ProcessMessageError}, + traits::{ContainsPair, Everything, Nothing, ProcessMessageError,tokens::fungibles}, weights::{Weight, WeightToFee as WeightToFeeTrait}, + pallet_prelude::DispatchError, }; use orml_traits::{ location::{RelativeReserveProvider, Reserve}, @@ -45,7 +46,7 @@ use crate::{ xcm_assets, }, ConstU32, -}; + }; use super::{ AccountId, Balance, Balances, Currencies, CurrencyId, ParachainInfo, ParachainSystem, @@ -321,7 +322,7 @@ pub type Barrier = ( ); pub struct ChargeWeightInFungiblesImplementation; -impl ChargeWeightInFungibles for ChargeWeightInFungiblesImplementation { +impl ChargeWeightInFungibles for ChargeWeightInFungiblesImplementation { fn charge_weight_in_fungibles( asset_id: CurrencyId, weight: Weight, @@ -355,12 +356,89 @@ type Transactor = MultiCurrencyAdapter< DepositToAlternative, >; +// Workarround for TakeFirstAssetTrader +use frame_support::traits::tokens::{Preservation, Fortitude, Provenance, WithdrawConsequence, DepositConsequence}; + +pub struct ConcreteAssets; +impl fungibles::Mutate for ConcreteAssets {} +impl fungibles::Balanced for ConcreteAssets { + type OnDropCredit = fungibles::DecreaseIssuance; + type OnDropDebt = fungibles::IncreaseIssuance; +} +impl fungibles::Inspect for ConcreteAssets { + type AssetId = >::AssetId; + type Balance = >::Balance; + + fn minimum_balance(id: Self::AssetId) -> Self::Balance { + Tokens::minimum_balance(id) + } + + fn total_issuance(asset_id: Self::AssetId) -> Self::Balance { + Tokens::total_issuance(asset_id) + } + + fn balance(asset_id: Self::AssetId, account_id: &AccountId) -> Self::Balance { + Tokens::balance(asset_id, account_id) + } + + fn total_balance(asset_id: Self::AssetId, account_id: &AccountId) -> Self::Balance { + Tokens::balance(asset_id, account_id) + } + + fn reducible_balance( + _: Self::AssetId, + _: &AccountId, + _: Preservation, + _: Fortitude, + ) -> Self::Balance { + todo!() + } + + fn can_deposit( + _: Self::AssetId, + _: &AccountId, + _: Self::Balance, + _: Provenance, + ) -> DepositConsequence { + todo!() + } + + fn can_withdraw( + _: Self::AssetId, + _: &AccountId, + _: Self::Balance, + ) -> WithdrawConsequence { + todo!() + } + + fn asset_exists(_: Self::AssetId) -> bool { + todo!() + } + +} +impl fungibles::Unbalanced for ConcreteAssets { + fn handle_dust(_: fungibles::Dust) { + todo!() + } + fn write_balance( + _: Self::AssetId, + _: &AccountId, + _: Self::Balance, + ) -> Result, DispatchError> { + todo!() + } + + fn set_total_issuance(_: Self::AssetId, _: Self::Balance) { + todo!() + } +} + pub type Traders = ( TakeFirstAssetTrader< AccountId, ChargeWeightInFungiblesImplementation, ConvertedConcreteId, - Tokens, + ConcreteAssets, XcmFeesTo32ByteAccount, >, );