Skip to content

Commit

Permalink
wip add custom update code, workaround for TakeFirstAsset trader
Browse files Browse the repository at this point in the history
  • Loading branch information
gianfra-t committed Jan 3, 2024
1 parent 9dc0dd7 commit eaa4cbf
Show file tree
Hide file tree
Showing 3 changed files with 169 additions and 9 deletions.
7 changes: 5 additions & 2 deletions runtime/amplitude/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,17 @@ pub type SignedPayload = generic::SignedPayload<RuntimeCall, SignedExtra>;
pub type CheckedExtrinsic = generic::CheckedExtrinsic<AccountId, RuntimeCall, SignedExtra>;

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::<PolkadotXcm>()};
log::info!{"version for tx payment {:?}",StorageVersion::get::<TransactionPayment>()};
log::info!("Upgrading pallet contract's storage version to 10");
StorageVersion::new(0).put::<Contracts>();
StorageVersion::new(10).put::<Contracts>();
}
// not really a heavy operation
frame_support::weights::Weight::zero()
Expand All @@ -167,7 +170,7 @@ pub type Executive = frame_executive::Executive<
frame_system::ChainContext<Runtime>,
Runtime,
AllPalletsWithSystem,
CustomOnRuntimeUpgrade
(CustomOnRuntimeUpgrade, pallet_xcm::migration::v1::MigrateToV1<Runtime>)
>;

pub struct AmplitudeDiaOracleKeyConverter;
Expand Down
85 changes: 82 additions & 3 deletions runtime/amplitude/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -38,6 +39,7 @@ use crate::{
xcm_assets,
},
ConstU32,

};

use super::{
Expand Down Expand Up @@ -305,7 +307,7 @@ pub type Barrier = (
);

pub struct ChargeWeightInFungiblesImplementation;
impl ChargeWeightInFungibles<AccountId, Tokens> for ChargeWeightInFungiblesImplementation {
impl ChargeWeightInFungibles<AccountId, ConcreteAssets> for ChargeWeightInFungiblesImplementation {
fn charge_weight_in_fungibles(
asset_id: CurrencyId,
weight: Weight,
Expand All @@ -324,16 +326,93 @@ impl ChargeWeightInFungibles<AccountId, Tokens> for ChargeWeightInFungiblesImple
}
}

// Workarround for TakeFirstAssetTrader
use frame_support::traits::tokens::{Preservation, Fortitude, Provenance, WithdrawConsequence, DepositConsequence};

pub struct ConcreteAssets;
impl fungibles::Mutate<AccountId> for ConcreteAssets {}
impl fungibles::Balanced<AccountId> for ConcreteAssets {
type OnDropCredit = fungibles::DecreaseIssuance<AccountId, Self>;
type OnDropDebt = fungibles::IncreaseIssuance<AccountId, Self>;
}
impl fungibles::Inspect<AccountId> for ConcreteAssets {
type AssetId = <Tokens as fungibles::Inspect<AccountId>>::AssetId;
type Balance = <Tokens as fungibles::Inspect<AccountId>>::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<Self::Balance> {
todo!()
}

fn asset_exists(_: Self::AssetId) -> bool {
todo!()
}

}
impl fungibles::Unbalanced<AccountId> for ConcreteAssets {
fn handle_dust(_: fungibles::Dust<AccountId, Self>) {
todo!()
}
fn write_balance(
_: Self::AssetId,
_: &AccountId,
_: Self::Balance,
) -> Result<Option<Self::Balance>, DispatchError> {
todo!()
}

fn set_total_issuance(_: Self::AssetId, _: Self::Balance) {
todo!()
}
}
pub type Traders = (
TakeFirstAssetTrader<
AccountId,
ChargeWeightInFungiblesImplementation,
ConvertedConcreteId<CurrencyId, Balance, CurrencyIdConvert, JustTry>,
Tokens,
ConcreteAssets,
XcmFeesTo32ByteAccount<LocalAssetTransactor, AccountId, AmplitudeTreasuryAccount>,
>,
);


pub struct XcmConfig;
impl xcm_executor::Config for XcmConfig {
type RuntimeCall = RuntimeCall;
Expand Down
86 changes: 82 additions & 4 deletions runtime/pendulum/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -45,7 +46,7 @@ use crate::{
xcm_assets,
},
ConstU32,
};
};

use super::{
AccountId, Balance, Balances, Currencies, CurrencyId, ParachainInfo, ParachainSystem,
Expand Down Expand Up @@ -321,7 +322,7 @@ pub type Barrier = (
);

pub struct ChargeWeightInFungiblesImplementation;
impl ChargeWeightInFungibles<AccountId, Tokens> for ChargeWeightInFungiblesImplementation {
impl ChargeWeightInFungibles<AccountId, ConcreteAssets> for ChargeWeightInFungiblesImplementation {
fn charge_weight_in_fungibles(
asset_id: CurrencyId,
weight: Weight,
Expand Down Expand Up @@ -355,12 +356,89 @@ type Transactor = MultiCurrencyAdapter<
DepositToAlternative<PendulumTreasuryAccount, Currencies, CurrencyId, AccountId, Balance>,
>;

// Workarround for TakeFirstAssetTrader
use frame_support::traits::tokens::{Preservation, Fortitude, Provenance, WithdrawConsequence, DepositConsequence};

pub struct ConcreteAssets;
impl fungibles::Mutate<AccountId> for ConcreteAssets {}
impl fungibles::Balanced<AccountId> for ConcreteAssets {
type OnDropCredit = fungibles::DecreaseIssuance<AccountId, Self>;
type OnDropDebt = fungibles::IncreaseIssuance<AccountId, Self>;
}
impl fungibles::Inspect<AccountId> for ConcreteAssets {
type AssetId = <Tokens as fungibles::Inspect<AccountId>>::AssetId;
type Balance = <Tokens as fungibles::Inspect<AccountId>>::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<Self::Balance> {
todo!()
}

fn asset_exists(_: Self::AssetId) -> bool {
todo!()
}

}
impl fungibles::Unbalanced<AccountId> for ConcreteAssets {
fn handle_dust(_: fungibles::Dust<AccountId, Self>) {
todo!()
}
fn write_balance(
_: Self::AssetId,
_: &AccountId,
_: Self::Balance,
) -> Result<Option<Self::Balance>, DispatchError> {
todo!()
}

fn set_total_issuance(_: Self::AssetId, _: Self::Balance) {
todo!()
}
}

pub type Traders = (
TakeFirstAssetTrader<
AccountId,
ChargeWeightInFungiblesImplementation,
ConvertedConcreteId<CurrencyId, Balance, CurrencyIdConvert, JustTry>,
Tokens,
ConcreteAssets,
XcmFeesTo32ByteAccount<Transactor, AccountId, PendulumTreasuryAccount>,
>,
);
Expand Down

0 comments on commit eaa4cbf

Please sign in to comment.