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

Pangolin ahUSDT #1236

Merged
merged 22 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 1 addition & 24 deletions runtime/common/src/xcm_configs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use frame_support::{
};
use sp_core::Get;
use sp_io::hashing::blake2_256;
use sp_runtime::traits::{Hash, SaturatedConversion, Saturating, Zero};
use sp_runtime::traits::{SaturatedConversion, Saturating, Zero};
use sp_std::{borrow::Borrow, prelude::*, result::Result};

/// Base balance required for the XCM unit weight.
Expand Down Expand Up @@ -214,26 +214,3 @@ pub struct AssetRegistrarMetadata {
pub decimals: u8,
pub is_frozen: bool,
}

// Our AssetType. For now we only handle Xcm Assets
#[derive(Clone, Eq, Debug, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo)]
pub enum AssetType {
Xcm(MultiLocation),
}
impl Default for AssetType {
fn default() -> Self {
Self::Xcm(MultiLocation::here())
}
}
impl From<MultiLocation> for AssetType {
fn from(location: MultiLocation) -> Self {
Self::Xcm(location)
}
}
impl Into<Option<MultiLocation>> for AssetType {
fn into(self) -> Option<MultiLocation> {
match self {
Self::Xcm(location) => Some(location),
}
}
}
jiguantong marked this conversation as resolved.
Show resolved Hide resolved
28 changes: 27 additions & 1 deletion runtime/pangolin/src/pallets/asset_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ use crate::*;
// substrate
use frame_support::{dispatch::GetDispatchInfo, pallet_prelude::*, transactional};
use frame_system::EnsureNever;
use sp_runtime::traits::Hash;
// polkadot
use xcm::latest::prelude::*;

// We instruct how to register the Assets
// In this case, we tell it to create an Asset in pallet-assets
Expand Down Expand Up @@ -91,6 +94,29 @@ frame_support::parameter_types! {
);
}

// Our AssetType. For now we only handle Xcm Assets
#[derive(Clone, Eq, Debug, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo)]
pub enum AssetType {
Xcm(MultiLocation),
}
impl Default for AssetType {
fn default() -> Self {
Self::Xcm(MultiLocation::here())
}
}
impl From<MultiLocation> for AssetType {
fn from(location: MultiLocation) -> Self {
Self::Xcm(location)
}
}
impl Into<Option<MultiLocation>> for AssetType {
fn into(self) -> Option<MultiLocation> {
match self {
Self::Xcm(location) => Some(location),
}
}
}

// Implementation on how to retrieve the AssetId from an AssetType
// We simply hash the AssetType and take the lowest 128 bits
impl From<AssetType> for crate::AssetId {
Expand All @@ -116,7 +142,7 @@ impl pallet_asset_manager::Config for Runtime {
type Balance = Balance;
type Currency = Balances;
type ForeignAssetModifierOrigin = Root;
type ForeignAssetType = xcm_configs::AssetType;
type ForeignAssetType = AssetType;
type LocalAssetDeposit = ConstU128<0>;
type LocalAssetIdCreator = LocalAssetIdCreator;
type LocalAssetModifierOrigin = EnsureNever<AccountId>;
Expand Down
6 changes: 5 additions & 1 deletion runtime/pangolin/src/pallets/orml_xtokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ impl orml_xtokens::Config for Runtime {
type BaseXcmWeight = BaseXcmWeight;
type CurrencyId = CurrencyId;
type CurrencyIdConvert = CurrencyIdtoMultiLocation<
xcm_primitives::AsAssetType<crate::AssetId, xcm_configs::AssetType, AssetManager>,
xcm_primitives::AsAssetType<
crate::AssetId,
pallets::asset_manager::AssetType,
AssetManager,
>,
>;
type MaxAssetsForTransfer = MaxAssetsForTransfer;
// We don't have this case: fee_reserve != non_fee_reserve
Expand Down
18 changes: 15 additions & 3 deletions runtime/pangolin/src/pallets/polkadot_xcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ pub type ForeignFungiblesTransactor = xcm_builder::FungiblesAdapter<
xcm_builder::ConvertedConcreteId<
crate::AssetId,
Balance,
xcm_primitives::AsAssetType<crate::AssetId, xcm_configs::AssetType, AssetManager>,
xcm_primitives::AsAssetType<
crate::AssetId,
pallets::asset_manager::AssetType,
AssetManager,
>,
xcm_executor::traits::JustTry,
>,
),
Expand Down Expand Up @@ -201,7 +205,11 @@ pub type XcmFeesToAccount = xcm_primitives::XcmFeesToAccount<
xcm_builder::ConvertedConcreteId<
crate::AssetId,
Balance,
xcm_primitives::AsAssetType<crate::AssetId, xcm_configs::AssetType, AssetManager>,
xcm_primitives::AsAssetType<
crate::AssetId,
pallets::asset_manager::AssetType,
AssetManager,
>,
xcm_executor::traits::JustTry,
>,
),
Expand Down Expand Up @@ -246,7 +254,11 @@ impl xcm_executor::Config for XcmExecutorConfig {
DealWithFees<Runtime>,
ToTreasury,
>,
xcm_primitives::FirstAssetTrader<xcm_configs::AssetType, AssetManager, XcmFeesToAccount>,
xcm_primitives::FirstAssetTrader<
pallets::asset_manager::AssetType,
AssetManager,
XcmFeesToAccount,
>,
);
type UniversalAliases = frame_support::traits::Nothing;
// Teleporting is disabled.
Expand Down