Skip to content

Commit

Permalink
Test USDT ID
Browse files Browse the repository at this point in the history
  • Loading branch information
jiguantong committed Aug 25, 2023
1 parent d8ed5e8 commit a9b3b6a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
29 changes: 0 additions & 29 deletions runtime/common/src/xcm_configs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,32 +237,3 @@ impl Into<Option<MultiLocation>> for AssetType {
}
}
}

frame_support::parameter_types! {
/// 1000 is AssetHub paraId.
/// 50 is pallet-assets index on AssetHub.
/// 1984 is the id of Tether USD on AssetHub.
/// Refer to
pub UsdtLocation: MultiLocation = MultiLocation::new(
1,
X3(Parachain(1000), PalletInstance(50), GeneralIndex(1984))
);
}

// 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 {
fn from(asset: AssetType) -> crate::AssetId {
match asset {
AssetType::Xcm(id) =>
if id == UsdtLocation::get() {
1027
} else {
let mut result: [u8; 8] = [0u8; 8];
let hash: sp_core::H256 = id.using_encoded(dc_primitives::Hashing::hash);
result.copy_from_slice(&hash.as_fixed_bytes()[0..8]);
u64::from_le_bytes(result)
},
}
}
}
29 changes: 29 additions & 0 deletions runtime/pangolin/src/pallets/asset_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,35 @@ impl pallet_asset_manager::LocalAssetIdCreator<Runtime> for LocalAssetIdCreator
}
}

frame_support::parameter_types! {
/// 1000 is AssetHub paraId.
/// 50 is pallet-assets index on AssetHub.
/// 1984 is the id of Tether USD on AssetHub.
/// 7777 is the id of Test USD on AssetHub(Rococo).
pub UsdtLocation: MultiLocation = MultiLocation::new(
1,
X3(Parachain(1000), PalletInstance(50), GeneralIndex(7777))
);
}

// 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 {
fn from(asset: AssetType) -> crate::AssetId {
match asset {
AssetType::Xcm(id) =>
if id == UsdtLocation::get() {
1027
} else {
let mut result: [u8; 8] = [0u8; 8];
let hash: sp_core::H256 = id.using_encoded(dc_primitives::Hashing::hash);
result.copy_from_slice(&hash.as_fixed_bytes()[0..8]);
u64::from_le_bytes(result)
},
}
}
}

impl pallet_asset_manager::Config for Runtime {
type AssetId = crate::AssetId;
type AssetRegistrar = AssetRegistrar;
Expand Down

0 comments on commit a9b3b6a

Please sign in to comment.