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

Support PINK #1416

Merged
merged 4 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 10 additions & 1 deletion runtime/darwinia/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ impl frame_support::traits::OnRuntimeUpgrade for CustomOnRuntimeUpgrade {
fn migrate() -> frame_support::weights::Weight {
// substrate
use pallet_balances::Locks;
use sp_core::H160;
use sp_std::str::FromStr;

[
("0xabcf7060a68f62624f7569ada9d78b5a5db0782a", b"phrelect"),
Expand All @@ -63,6 +65,13 @@ fn migrate() -> frame_support::weights::Weight {
}
});

const REVERT_BYTECODE: [u8; 5] = [0x60, 0x00, 0x60, 0x00, 0xFD];
// PINK equals to the 0x404 in the pallet-evm runtime.
const ADDRESS: &str = "0x0000000000000000000000000000000000000404";
if let Ok(addr) = H160::from_str(ADDRESS) {
EVM::create_account(addr, REVERT_BYTECODE.to_vec());
}

// frame_support::weights::Weight::zero()
<Runtime as frame_system::Config>::DbWeight::get().reads_writes(0, 16)
RuntimeBlockWeights::get().max_block
}
28 changes: 16 additions & 12 deletions runtime/darwinia/src/pallets/asset_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,20 +102,18 @@ impl From<MultiLocation> for AssetType {
// We simply hash the `AssetType` and take the lowest 128 bits.
impl From<AssetType> for crate::AssetId {
fn from(asset: AssetType) -> crate::AssetId {
use sp_runtime::traits::Hash;

match asset {
AssetType::Xcm(id) =>
if id == UsdtLocation::get() {
1027
} else {
let mut result: [u8; 8] = [0_u8; 8];
let hash: sp_core::H256 = id.using_encoded(dc_primitives::Hashing::hash);
AssetType::Xcm(id) if id == UsdtLocation::get() => 1027,
AssetType::Xcm(id) if id == PinkLocation::get() => 1028,
AssetType::Xcm(id) => {
use sp_runtime::traits::Hash;

result.copy_from_slice(&hash.as_fixed_bytes()[0..8]);
let mut result: [u8; 8] = [0_u8; 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)
},
u64::from_le_bytes(result)
},
}
}
}
Expand All @@ -131,11 +129,17 @@ 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 Test USDT on AssetHub(Polkadot).
/// 1984 is the id of USDT on AssetHub(Polkadot).
pub UsdtLocation: MultiLocation = MultiLocation::new(
1,
X3(Parachain(1000), PalletInstance(50), GeneralIndex(1984))
);

/// 23 is the id of PINK on AssetHub(Polkadot).
pub PinkLocation: MultiLocation = MultiLocation::new(
1,
X3(Parachain(1000), PalletInstance(50), GeneralIndex(23))
);
}

impl pallet_asset_manager::Config for Runtime {
Expand Down
3 changes: 2 additions & 1 deletion runtime/darwinia/src/pallets/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ where
Self(Default::default())
}

pub fn used_addresses() -> [sp_core::H160; 17] {
pub fn used_addresses() -> [sp_core::H160; 18] {
[
addr(0x01),
addr(0x02),
Expand All @@ -63,6 +63,7 @@ where
addr(0x401),
addr(0x402), // For KTON asset.
addr(0x403), // For Tether USDT.
addr(0x404), // For PINK.
addr(0x600),
addr(0x601),
addr(0x602),
Expand Down