Skip to content

Commit

Permalink
Support $PINK (#1416)
Browse files Browse the repository at this point in the history
      * Support PINK

* Update precompile

* Add contract code migration

* Rewrite match pattern

---------

Co-authored-by: bear <boundless.forest@outlook.com>
  • Loading branch information
jiguantong and boundless-forest committed Feb 28, 2024
1 parent 06440ea commit 1b0cf3b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
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

0 comments on commit 1b0cf3b

Please sign in to comment.