From bebf717e002ce8aac66c39f8888db4ed15846414 Mon Sep 17 00:00:00 2001 From: Guantong Date: Tue, 27 Feb 2024 16:16:44 +0800 Subject: [PATCH 1/4] Support PINK --- runtime/darwinia/src/pallets/asset_manager.rs | 10 +++++++++- runtime/darwinia/src/pallets/evm.rs | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/runtime/darwinia/src/pallets/asset_manager.rs b/runtime/darwinia/src/pallets/asset_manager.rs index 347ea88f0..3f4f4785b 100644 --- a/runtime/darwinia/src/pallets/asset_manager.rs +++ b/runtime/darwinia/src/pallets/asset_manager.rs @@ -108,6 +108,8 @@ impl From for crate::AssetId { AssetType::Xcm(id) => if id == UsdtLocation::get() { 1027 + } else if id == PinkLocation::get() { + 1028 } else { let mut result: [u8; 8] = [0_u8; 8]; let hash: sp_core::H256 = id.using_encoded(dc_primitives::Hashing::hash); @@ -131,11 +133,17 @@ impl Into> 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 { diff --git a/runtime/darwinia/src/pallets/evm.rs b/runtime/darwinia/src/pallets/evm.rs index 93530fe38..cdab7918f 100644 --- a/runtime/darwinia/src/pallets/evm.rs +++ b/runtime/darwinia/src/pallets/evm.rs @@ -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), From 4e1431a9a06d04e755e784a3b8e60c9a4d49ed42 Mon Sep 17 00:00:00 2001 From: Guantong Date: Tue, 27 Feb 2024 16:30:21 +0800 Subject: [PATCH 2/4] Update precompile --- runtime/darwinia/src/pallets/evm.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/darwinia/src/pallets/evm.rs b/runtime/darwinia/src/pallets/evm.rs index cdab7918f..1b64ae3fd 100644 --- a/runtime/darwinia/src/pallets/evm.rs +++ b/runtime/darwinia/src/pallets/evm.rs @@ -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), From 842333c5fcb51114fd708c0844b2d752705d8ac6 Mon Sep 17 00:00:00 2001 From: bear Date: Wed, 28 Feb 2024 13:41:36 +0800 Subject: [PATCH 3/4] Add contract code migration --- runtime/darwinia/src/migration.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/runtime/darwinia/src/migration.rs b/runtime/darwinia/src/migration.rs index 0ade34422..41643c08a 100644 --- a/runtime/darwinia/src/migration.rs +++ b/runtime/darwinia/src/migration.rs @@ -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"), @@ -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() - ::DbWeight::get().reads_writes(0, 16) + RuntimeBlockWeights::get().max_block } From 73b632f09b3558073b4d5d53835c30c4ac30e7d4 Mon Sep 17 00:00:00 2001 From: bear Date: Wed, 28 Feb 2024 14:01:14 +0800 Subject: [PATCH 4/4] Rewrite match pattern --- runtime/darwinia/src/pallets/asset_manager.rs | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/runtime/darwinia/src/pallets/asset_manager.rs b/runtime/darwinia/src/pallets/asset_manager.rs index 3f4f4785b..0cfbc4a86 100644 --- a/runtime/darwinia/src/pallets/asset_manager.rs +++ b/runtime/darwinia/src/pallets/asset_manager.rs @@ -102,22 +102,18 @@ impl From for AssetType { // We simply hash the `AssetType` and take the lowest 128 bits. impl From 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 if id == PinkLocation::get() { - 1028 - } 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) + }, } } }