From 25fbcb4e440005c2abf675332fed3e7e539db1de Mon Sep 17 00:00:00 2001 From: Minqi Wang Date: Thu, 20 Feb 2025 14:35:05 +0800 Subject: [PATCH 01/15] feat: add vesting precompile --- parachain/Cargo.lock | 25 +++++++++ parachain/Cargo.toml | 2 + parachain/precompiles/vesting/Cargo.toml | 51 +++++++++++++++++++ .../precompiles/vesting/VestingInterface.sol | 9 ++++ parachain/precompiles/vesting/src/lib.rs | 47 +++++++++++++++++ parachain/runtime/litentry/Cargo.toml | 2 + parachain/runtime/litentry/src/precompiles.rs | 7 +++ parachain/runtime/paseo/Cargo.toml | 2 + parachain/runtime/paseo/src/precompiles.rs | 7 +++ 9 files changed, 152 insertions(+) create mode 100644 parachain/precompiles/vesting/Cargo.toml create mode 100644 parachain/precompiles/vesting/VestingInterface.sol create mode 100644 parachain/precompiles/vesting/src/lib.rs diff --git a/parachain/Cargo.lock b/parachain/Cargo.lock index b4b5f05aae..a4d730a485 100644 --- a/parachain/Cargo.lock +++ b/parachain/Cargo.lock @@ -6007,6 +6007,7 @@ dependencies = [ "pallet-evm-precompile-score-staking", "pallet-evm-precompile-sha3fips", "pallet-evm-precompile-simple", + "pallet-evm-precompile-vesting", "pallet-extrinsic-filter", "pallet-group", "pallet-identity", @@ -8327,6 +8328,29 @@ dependencies = [ "sp-io", ] +[[package]] +name = "pallet-evm-precompile-vesting" +version = "0.1.0" +dependencies = [ + "derive_more 0.99.18", + "fp-evm", + "frame-support", + "frame-system", + "hex-literal", + "libsecp256k1", + "pallet-evm", + "pallet-timestamp", + "pallet-vesting", + "parity-scale-codec", + "precompile-utils", + "scale-info", + "serde", + "sha3", + "sp-core", + "sp-runtime", + "sp-std", +] + [[package]] name = "pallet-extrinsic-filter" version = "0.1.0" @@ -9533,6 +9557,7 @@ dependencies = [ "pallet-evm-precompile-score-staking", "pallet-evm-precompile-sha3fips", "pallet-evm-precompile-simple", + "pallet-evm-precompile-vesting", "pallet-extrinsic-filter", "pallet-group", "pallet-guardian", diff --git a/parachain/Cargo.toml b/parachain/Cargo.toml index 5630ed85fc..03eebf9f72 100644 --- a/parachain/Cargo.toml +++ b/parachain/Cargo.toml @@ -38,6 +38,7 @@ members = [ 'precompiles/omni-bridge', 'precompiles/parachain-staking', 'precompiles/score-staking', + 'precompiles/vesting', 'runtime/litentry', 'runtime/paseo', 'runtime/common', @@ -297,6 +298,7 @@ pallet-evm-precompile-bridge-transfer = { path = "precompiles/bridge-transfer", pallet-evm-precompile-omni-bridge = { path = "precompiles/omni-bridge", default-features = false } pallet-evm-precompile-parachain-staking = { path = "precompiles/parachain-staking", default-features = false } pallet-evm-precompile-score-staking = { path = "precompiles/score-staking", default-features = false } +pallet-evm-precompile-vesting = { path = "precompiles/vesting", default-features = false } pallet-evm-precompile-aiusd-convertor = { path = "precompiles/collab-ai/aiusd-convertor", default-features = false } pallet-evm-precompile-curator = { path = "precompiles/collab-ai/curator", default-features = false } diff --git a/parachain/precompiles/vesting/Cargo.toml b/parachain/precompiles/vesting/Cargo.toml new file mode 100644 index 0000000000..a8d64068dc --- /dev/null +++ b/parachain/precompiles/vesting/Cargo.toml @@ -0,0 +1,51 @@ +[package] +authors = ["Trust Computing GmbH "] +edition = '2021' +name = "pallet-evm-precompile-vesting" +version = '0.1.0' + +[dependencies] +precompile-utils = { workspace = true } + +frame-support = { workspace = true } +frame-system = { workspace = true } +pallet-vesting = { workspace = true } +parity-scale-codec = { workspace = true } +scale-info = { workspace = true, features = ["derive"] } +sp-core = { workspace = true } +sp-runtime = { workspace = true } +sp-std = { workspace = true } + +fp-evm = { workspace = true } +pallet-evm = { workspace = true } + +[dev-dependencies] +derive_more = { workspace = true } +hex-literal = { workspace = true } +libsecp256k1 = { workspace = true, features = ["std"] } +serde = { workspace = true } +sha3 = { workspace = true } +precompile-utils = { workspace = true, features = ["std", "testing"] } +pallet-timestamp = { workspace = true, features = ["std"] } +parity-scale-codec = { workspace = true, features = ["std"] } +sp-runtime = { workspace = true, features = ["std"] } + +[features] +default = ["std"] +std = [ + "fp-evm/std", + "frame-support/std", + "frame-system/std", + "libsecp256k1/std", + "pallet-vesting/std", + "pallet-evm/std", + "pallet-timestamp/std", + "parity-scale-codec/std", + "precompile-utils/std", + "scale-info/std", + "serde/std", + "sha3/std", + "sp-core/std", + "sp-runtime/std", + "sp-std/std", +] diff --git a/parachain/precompiles/vesting/VestingInterface.sol b/parachain/precompiles/vesting/VestingInterface.sol new file mode 100644 index 0000000000..603ac79190 --- /dev/null +++ b/parachain/precompiles/vesting/VestingInterface.sol @@ -0,0 +1,9 @@ +// SPDX-License-Identifier: GPL-3.0-only +pragma solidity >=0.8.3; + +interface IVesting { + /// @notice Used to unlock vest. + /// @custom:selector 0x458efde3 + /// vest() + function vest() external; +} \ No newline at end of file diff --git a/parachain/precompiles/vesting/src/lib.rs b/parachain/precompiles/vesting/src/lib.rs new file mode 100644 index 0000000000..9ccef56d45 --- /dev/null +++ b/parachain/precompiles/vesting/src/lib.rs @@ -0,0 +1,47 @@ +// Copyright 2020-2024 Trust Computing GmbH. +// This file is part of Litentry. +// +// Litentry is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Litentry is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Litentry. If not, see . +#![cfg_attr(not(feature = "std"), no_std)] + +use fp_evm::{PrecompileFailure, PrecompileHandle}; + +use frame_support::dispatch::{GetDispatchInfo, PostDispatchInfo}; +use pallet_evm::AddressMapping; +use precompile_utils::prelude::*; +use sp_runtime::traits::Dispatchable; + +use sp_core::U256; +use sp_std::{marker::PhantomData, vec::Vec}; + +pub struct VestingPrecompile(PhantomData); + +#[precompile_utils::precompile] +impl VestingPrecompile +where + Runtime: VestingPrecompile::Config + pallet_evm::Config, + Runtime::RuntimeCall: Dispatchable + GetDispatchInfo, + Runtime::RuntimeCall: From>, + ::RuntimeOrigin: From>, +{ + #[precompile::public("vest()")] + fn vest(handle: &mut impl PrecompileHandle) -> EvmResult { + let origin = Runtime::AddressMapping::into_account_id(handle.context().caller); + + let call = pallet_vesting::Call::::vest {}; + RuntimeHelper::::try_dispatch(handle, Some(origin).into(), call)?; + + Ok(()) + } +} diff --git a/parachain/runtime/litentry/Cargo.toml b/parachain/runtime/litentry/Cargo.toml index abe7a1a0ea..4d635f6847 100644 --- a/parachain/runtime/litentry/Cargo.toml +++ b/parachain/runtime/litentry/Cargo.toml @@ -116,6 +116,7 @@ pallet-evm-precompile-bridge-transfer = { workspace = true } pallet-evm-precompile-omni-bridge = { workspace = true } pallet-evm-precompile-parachain-staking = { workspace = true } pallet-evm-precompile-score-staking = { workspace = true } +pallet-evm-precompile-vesting = { workspace = true } moonbeam-evm-tracer = { workspace = true } moonbeam-rpc-primitives-debug = { workspace = true } @@ -249,6 +250,7 @@ std = [ "pallet-evm-precompile-score-staking/std", "pallet-evm-precompile-sha3fips/std", "pallet-evm-precompile-simple/std", + "pallet-evm-precompile-vesting/std", "pallet-evm/std", "pallet-extrinsic-filter/std", "pallet-group/std", diff --git a/parachain/runtime/litentry/src/precompiles.rs b/parachain/runtime/litentry/src/precompiles.rs index aa82c56ae4..2f71d45031 100644 --- a/parachain/runtime/litentry/src/precompiles.rs +++ b/parachain/runtime/litentry/src/precompiles.rs @@ -35,6 +35,7 @@ use pallet_evm_precompile_parachain_staking::ParachainStakingPrecompile; use pallet_evm_precompile_score_staking::ScoreStakingPrecompile; use pallet_evm_precompile_sha3fips::Sha3FIPS256; use pallet_evm_precompile_simple::{ECRecover, ECRecoverPublicKey, Identity, Ripemd160, Sha256}; +use pallet_evm_precompile_vesting::VestingPrecompile; use precompile_utils::precompile_set::*; use sp_std::fmt::Debug; @@ -118,6 +119,12 @@ pub type PrecompilesSetAt = ( PrecompileAt, ECRecoverPublicKey, (CallableByContract, CallableByPrecompile)>, PrecompileAt, Ed25519Verify, (CallableByContract, CallableByPrecompile)>, // Litentry precompiles (starts from 0x5000): + // ParachainStaking: pallet_parachain_staking = 15 + 20480 + PrecompileAt< + AddressU64<20495>, + VestingPrecompile, + (CallableByContract, CallableByPrecompile), + >, // ParachainStaking: pallet_parachain_staking = 45 + 20480 PrecompileAt< AddressU64<20525>, diff --git a/parachain/runtime/paseo/Cargo.toml b/parachain/runtime/paseo/Cargo.toml index b13ef2b44d..4fd60d8b87 100644 --- a/parachain/runtime/paseo/Cargo.toml +++ b/parachain/runtime/paseo/Cargo.toml @@ -127,6 +127,7 @@ pallet-evm-precompile-bridge-transfer = { workspace = true } pallet-evm-precompile-omni-bridge = { workspace = true } pallet-evm-precompile-parachain-staking = { workspace = true } pallet-evm-precompile-score-staking = { workspace = true } +pallet-evm-precompile-vesting = { workspace = true } pallet-evm-precompile-aiusd-convertor = { workspace = true } pallet-evm-precompile-curator = { workspace = true } @@ -280,6 +281,7 @@ std = [ "pallet-evm-precompile-score-staking/std", "pallet-evm-precompile-sha3fips/std", "pallet-evm-precompile-simple/std", + "pallet-evm-precompile-vesting/std", "pallet-evm/std", "pallet-extrinsic-filter/std", "pallet-group/std", diff --git a/parachain/runtime/paseo/src/precompiles.rs b/parachain/runtime/paseo/src/precompiles.rs index 47de4dd900..0525b12f7a 100644 --- a/parachain/runtime/paseo/src/precompiles.rs +++ b/parachain/runtime/paseo/src/precompiles.rs @@ -35,6 +35,7 @@ use pallet_evm_precompile_parachain_staking::ParachainStakingPrecompile; use pallet_evm_precompile_score_staking::ScoreStakingPrecompile; use pallet_evm_precompile_sha3fips::Sha3FIPS256; use pallet_evm_precompile_simple::{ECRecover, ECRecoverPublicKey, Identity, Ripemd160, Sha256}; +use pallet_evm_precompile_vesting::VestingPrecompile; use precompile_utils::precompile_set::*; use sp_std::fmt::Debug; @@ -125,6 +126,12 @@ pub type PrecompilesSetAt = ( PrecompileAt, ECRecoverPublicKey, (CallableByContract, CallableByPrecompile)>, PrecompileAt, Ed25519Verify, (CallableByContract, CallableByPrecompile)>, // Litentry precompiles (starts from 0x5000): + // ParachainStaking: pallet_parachain_staking = 15 + 20480 + PrecompileAt< + AddressU64<20495>, + VestingPrecompile, + (CallableByContract, CallableByPrecompile), + >, // ParachainStaking: pallet_parachain_staking = 45 + 20480 PrecompileAt< AddressU64<20525>, From 2ac0b8b9c1bf6c2b6921821ab7cb10772e004c1d Mon Sep 17 00:00:00 2001 From: Minqi Wang Date: Thu, 20 Feb 2025 14:37:12 +0800 Subject: [PATCH 02/15] chore: whitespace --- parachain/precompiles/vesting/VestingInterface.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/parachain/precompiles/vesting/VestingInterface.sol b/parachain/precompiles/vesting/VestingInterface.sol index 603ac79190..255b009a53 100644 --- a/parachain/precompiles/vesting/VestingInterface.sol +++ b/parachain/precompiles/vesting/VestingInterface.sol @@ -2,8 +2,8 @@ pragma solidity >=0.8.3; interface IVesting { - /// @notice Used to unlock vest. + /// @notice Used to unlock vest. /// @custom:selector 0x458efde3 - /// vest() + /// vest() function vest() external; } \ No newline at end of file From 80c0d21ed4dc97fe7047bbe47c76fdb9e1bab465 Mon Sep 17 00:00:00 2001 From: Minqi Wang Date: Thu, 20 Feb 2025 14:46:38 +0800 Subject: [PATCH 03/15] chore: fix --- parachain/precompiles/vesting/src/lib.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/parachain/precompiles/vesting/src/lib.rs b/parachain/precompiles/vesting/src/lib.rs index 9ccef56d45..02b3d33061 100644 --- a/parachain/precompiles/vesting/src/lib.rs +++ b/parachain/precompiles/vesting/src/lib.rs @@ -15,22 +15,21 @@ // along with Litentry. If not, see . #![cfg_attr(not(feature = "std"), no_std)] -use fp_evm::{PrecompileFailure, PrecompileHandle}; +use fp_evm::PrecompileHandle; use frame_support::dispatch::{GetDispatchInfo, PostDispatchInfo}; use pallet_evm::AddressMapping; use precompile_utils::prelude::*; use sp_runtime::traits::Dispatchable; -use sp_core::U256; -use sp_std::{marker::PhantomData, vec::Vec}; +use sp_std::marker::PhantomData; pub struct VestingPrecompile(PhantomData); #[precompile_utils::precompile] impl VestingPrecompile where - Runtime: VestingPrecompile::Config + pallet_evm::Config, + Runtime: pallet_vesting::Config + pallet_evm::Config, Runtime::RuntimeCall: Dispatchable + GetDispatchInfo, Runtime::RuntimeCall: From>, ::RuntimeOrigin: From>, From e9a0278b7bd8562abce5daf27f08d01e14cb15d0 Mon Sep 17 00:00:00 2001 From: Minqi Wang Date: Thu, 20 Feb 2025 15:00:53 +0800 Subject: [PATCH 04/15] chore: fix --- parachain/precompiles/vesting/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parachain/precompiles/vesting/src/lib.rs b/parachain/precompiles/vesting/src/lib.rs index 02b3d33061..646b0fe4b4 100644 --- a/parachain/precompiles/vesting/src/lib.rs +++ b/parachain/precompiles/vesting/src/lib.rs @@ -31,7 +31,7 @@ impl VestingPrecompile where Runtime: pallet_vesting::Config + pallet_evm::Config, Runtime::RuntimeCall: Dispatchable + GetDispatchInfo, - Runtime::RuntimeCall: From>, + Runtime::RuntimeCall: From>, ::RuntimeOrigin: From>, { #[precompile::public("vest()")] From 1f6ace90dc031db39f1f4251a94562bfee9b45f0 Mon Sep 17 00:00:00 2001 From: Minqi Wang Date: Thu, 20 Feb 2025 15:49:08 +0800 Subject: [PATCH 05/15] feat: add ts-test --- .../common/abi/precompile/Vesting.json | 9 ++++ .../precompile-contract.test.ts | 51 +++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 parachain/ts-tests/common/abi/precompile/Vesting.json diff --git a/parachain/ts-tests/common/abi/precompile/Vesting.json b/parachain/ts-tests/common/abi/precompile/Vesting.json new file mode 100644 index 0000000000..327622e492 --- /dev/null +++ b/parachain/ts-tests/common/abi/precompile/Vesting.json @@ -0,0 +1,9 @@ +[ + { + "inputs": [], + "name": "vest", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } +] \ No newline at end of file diff --git a/parachain/ts-tests/integration-tests/precompile-contract.test.ts b/parachain/ts-tests/integration-tests/precompile-contract.test.ts index 42d0e6db09..2e780df41a 100644 --- a/parachain/ts-tests/integration-tests/precompile-contract.test.ts +++ b/parachain/ts-tests/integration-tests/precompile-contract.test.ts @@ -11,6 +11,7 @@ import { import precompileStakingContractAbi from '../common/abi/precompile/Staking.json'; import precompileBridgeContractAbi from '../common/abi/precompile/Bridge.json'; import precompileOmniBridgeContractAbi from '../common/abi/precompile/OmniBridge.json'; +import precompileVestingContractAbi from '../common/abi/precompile/Vesting.json'; const BN = require('bn.js'); import { evmToAddress } from '@polkadot/util-crypto'; import { KeyringPair } from '@polkadot/keyring/types'; @@ -29,6 +30,7 @@ describeLitentry('Test Parachain Precompile Contract', ``, (context) => { const precompileStakingContractAddress = '0x000000000000000000000000000000000000502d'; const precompileBridgeContractAddress = '0x000000000000000000000000000000000000503d'; const precompileOmniBridgeContractAddress = '0x0000000000000000000000000000000000005055'; + const precompileVestingContractAddress = '0x000000000000000000000000000000000000500f'; const evmAccountRaw = { privateKey: '0x01ab6e801c06e59ca97a14fc0a1978b27fa366fc87450e0b65459dd3515b7391', address: '0xaaafB3972B05630fCceE866eC69CdADd9baC2771', @@ -58,6 +60,11 @@ describeLitentry('Test Parachain Precompile Contract', ``, (context) => { precompileOmniBridgeContractAbi, provider ); + const precompileVestingContract = new ethers.Contract( + precompileVestingContractAddress, + precompileVestingContractAbi, + provider + ); const executeTransaction = async (delegateTransaction: any, contractAddress: HexString, label = '') => { console.log(`=== Executing ${label} ===`); @@ -317,6 +324,50 @@ describeLitentry('Test Parachain Precompile Contract', ``, (context) => { console.timeEnd('Test precompile staking contract'); }); + step('Test precompile vesting contract', async function () { + console.time('Test precompile vesting contract'); + + let balance = (await context.api.query.system.account(evmAccountRaw.mappedAddress)).data; + printBalance('initial balance', balance); + + // top up LITs if insufficient amount for staking or they are not reserved (require: 50 LITs minimum) + // Add vesting balance + if ( + parseInt(balance.free.toString()) < parseInt('60000000000000000000') && + Number(balance.reserved.toString()) === 0 + ) { + console.log('transferring more tokens'); + + await transferTokens(context.alice, evmAccountRaw); + + balance = (await context.api.query.system.account(evmAccountRaw.mappedAddress)).data; + printBalance('balance after transferring', balance); + } + + // Add an immediate-unlocked vesting + const vestedTransferTx = context.api.tx.Vesting.vested_transfer(evmAccountRaw.mappedAddress, { locked: '60000000000000000000', per_block: '60000000000000000000', starting_block: 1}); + await signAndSend(vestedTransferTx, context.alice); + + + // Precompile vest + const vestTx = precompileVestingContract.interface.encodeFunctionData('vest', []); + + await executeTransaction(vestTx, precompileVestingContractAddress, 'vest'); + const eventsPromise = subscribeToEvents('vesting', 'VestingCompleted', context.api); + const events = (await eventsPromise).map(({ event }) => event); + + expect(events.length).to.eq(1); + const event_data = events[0].toHuman().data! as { + account: string; + }; + console.log(`Print Event data: ${JSON.stringify(event_data)}`); + + // VestingCompleted Event + expect(event_data.account).to.eq(evmAccountRaw.mappedAddress); + + console.timeEnd('Test precompile vesting contract'); + }); + step('Set ExtrinsicFilter mode to Normal', async function () { let extrinsic = await sudoWrapperTC(context.api, context.api.tx.extrinsicFilter.setMode('Normal')); await signAndSend(extrinsic, context.alice); From 42e70feb978a3ca9064b454e03193e2ab5be22d8 Mon Sep 17 00:00:00 2001 From: Minqi Wang Date: Thu, 20 Feb 2025 17:12:28 +0800 Subject: [PATCH 06/15] chore: fix --- .../ts-tests/integration-tests/precompile-contract.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parachain/ts-tests/integration-tests/precompile-contract.test.ts b/parachain/ts-tests/integration-tests/precompile-contract.test.ts index 2e780df41a..2f6d707cc3 100644 --- a/parachain/ts-tests/integration-tests/precompile-contract.test.ts +++ b/parachain/ts-tests/integration-tests/precompile-contract.test.ts @@ -345,7 +345,7 @@ describeLitentry('Test Parachain Precompile Contract', ``, (context) => { } // Add an immediate-unlocked vesting - const vestedTransferTx = context.api.tx.Vesting.vested_transfer(evmAccountRaw.mappedAddress, { locked: '60000000000000000000', per_block: '60000000000000000000', starting_block: 1}); + const vestedTransferTx = context.api.tx.Vesting.vestedTransfer(evmAccountRaw.mappedAddress, { locked: '60000000000000000000', per_block: '60000000000000000000', starting_block: 1}); await signAndSend(vestedTransferTx, context.alice); From 54f0c1366092aecb80ffeeec6443f2b5156dca4d Mon Sep 17 00:00:00 2001 From: Minqi Wang Date: Fri, 21 Feb 2025 10:07:25 +0800 Subject: [PATCH 07/15] chore: fix --- .../ts-tests/integration-tests/precompile-contract.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parachain/ts-tests/integration-tests/precompile-contract.test.ts b/parachain/ts-tests/integration-tests/precompile-contract.test.ts index 2f6d707cc3..053f847222 100644 --- a/parachain/ts-tests/integration-tests/precompile-contract.test.ts +++ b/parachain/ts-tests/integration-tests/precompile-contract.test.ts @@ -345,7 +345,7 @@ describeLitentry('Test Parachain Precompile Contract', ``, (context) => { } // Add an immediate-unlocked vesting - const vestedTransferTx = context.api.tx.Vesting.vestedTransfer(evmAccountRaw.mappedAddress, { locked: '60000000000000000000', per_block: '60000000000000000000', starting_block: 1}); + const vestedTransferTx = context.api.tx.vesting.vestedTransfer(evmAccountRaw.mappedAddress, { locked: '60000000000000000000', per_block: '60000000000000000000', starting_block: 1}); await signAndSend(vestedTransferTx, context.alice); From f3f54d0a43d47942bd9291890fef5923bb8fd2a6 Mon Sep 17 00:00:00 2001 From: Minqi Wang Date: Fri, 21 Feb 2025 13:02:33 +0800 Subject: [PATCH 08/15] chore: fix --- .../ts-tests/integration-tests/precompile-contract.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parachain/ts-tests/integration-tests/precompile-contract.test.ts b/parachain/ts-tests/integration-tests/precompile-contract.test.ts index 053f847222..433dffce46 100644 --- a/parachain/ts-tests/integration-tests/precompile-contract.test.ts +++ b/parachain/ts-tests/integration-tests/precompile-contract.test.ts @@ -345,7 +345,7 @@ describeLitentry('Test Parachain Precompile Contract', ``, (context) => { } // Add an immediate-unlocked vesting - const vestedTransferTx = context.api.tx.vesting.vestedTransfer(evmAccountRaw.mappedAddress, { locked: '60000000000000000000', per_block: '60000000000000000000', starting_block: 1}); + const vestedTransferTx = context.api.tx.vesting.vestedTransfer(evmAccountRaw.mappedAddress, { locked: '60000000000000000000', perBBlock: '60000000000000000000', startingBlock: 1}); await signAndSend(vestedTransferTx, context.alice); From 6b504091ede39e63353dd669cde10f44465598e0 Mon Sep 17 00:00:00 2001 From: Minqi Wang Date: Fri, 21 Feb 2025 14:09:42 +0800 Subject: [PATCH 09/15] chore: fix --- .../ts-tests/integration-tests/precompile-contract.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parachain/ts-tests/integration-tests/precompile-contract.test.ts b/parachain/ts-tests/integration-tests/precompile-contract.test.ts index 433dffce46..7fcafd4e95 100644 --- a/parachain/ts-tests/integration-tests/precompile-contract.test.ts +++ b/parachain/ts-tests/integration-tests/precompile-contract.test.ts @@ -345,7 +345,7 @@ describeLitentry('Test Parachain Precompile Contract', ``, (context) => { } // Add an immediate-unlocked vesting - const vestedTransferTx = context.api.tx.vesting.vestedTransfer(evmAccountRaw.mappedAddress, { locked: '60000000000000000000', perBBlock: '60000000000000000000', startingBlock: 1}); + const vestedTransferTx = context.api.tx.vesting.vestedTransfer(evmAccountRaw.mappedAddress, { locked: '60000000000000000000', perBlock: '60000000000000000000', startingBlock: 1}); await signAndSend(vestedTransferTx, context.alice); From 78daa01b389eb2b6f6329708388478c08e79efa9 Mon Sep 17 00:00:00 2001 From: Minqi Wang Date: Fri, 21 Feb 2025 16:06:34 +0800 Subject: [PATCH 10/15] chore: fix --- .../ts-tests/integration-tests/precompile-contract.test.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/parachain/ts-tests/integration-tests/precompile-contract.test.ts b/parachain/ts-tests/integration-tests/precompile-contract.test.ts index 7fcafd4e95..68f76dcad7 100644 --- a/parachain/ts-tests/integration-tests/precompile-contract.test.ts +++ b/parachain/ts-tests/integration-tests/precompile-contract.test.ts @@ -1,6 +1,7 @@ import { expect } from 'chai'; import { step } from 'mocha-steps'; import { + sleep, signAndSend, describeLitentry, loadConfig, @@ -344,10 +345,12 @@ describeLitentry('Test Parachain Precompile Contract', ``, (context) => { printBalance('balance after transferring', balance); } - // Add an immediate-unlocked vesting - const vestedTransferTx = context.api.tx.vesting.vestedTransfer(evmAccountRaw.mappedAddress, { locked: '60000000000000000000', perBlock: '60000000000000000000', startingBlock: 1}); + // Add an almost immediate-unlocked vesting + const vestedTransferTx = context.api.tx.vesting.vestedTransfer(evmAccountRaw.mappedAddress, { locked: '60000000000000000000', perBlock: '60000000000000000000', startingBlock: context.api.query.system.number() + 2}); await signAndSend(vestedTransferTx, context.alice); + // Set timeout to 60 seconds (5 blocks on parachain) + sleep(60); // Precompile vest const vestTx = precompileVestingContract.interface.encodeFunctionData('vest', []); From 6f73257a89858e40143feea325ee0c12a3a2d78e Mon Sep 17 00:00:00 2001 From: Minqi Wang Date: Fri, 21 Feb 2025 20:13:58 +0800 Subject: [PATCH 11/15] chore: fix --- parachain/runtime/litentry/src/precompiles.rs | 4 ++-- parachain/runtime/paseo/src/precompiles.rs | 4 ++-- .../ts-tests/integration-tests/precompile-contract.test.ts | 5 +++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/parachain/runtime/litentry/src/precompiles.rs b/parachain/runtime/litentry/src/precompiles.rs index 2f71d45031..f7538bb871 100644 --- a/parachain/runtime/litentry/src/precompiles.rs +++ b/parachain/runtime/litentry/src/precompiles.rs @@ -119,9 +119,9 @@ pub type PrecompilesSetAt = ( PrecompileAt, ECRecoverPublicKey, (CallableByContract, CallableByPrecompile)>, PrecompileAt, Ed25519Verify, (CallableByContract, CallableByPrecompile)>, // Litentry precompiles (starts from 0x5000): - // ParachainStaking: pallet_parachain_staking = 15 + 20480 + // Vesting: pallet_vesting = 11 + 20480 PrecompileAt< - AddressU64<20495>, + AddressU64<20491>, VestingPrecompile, (CallableByContract, CallableByPrecompile), >, diff --git a/parachain/runtime/paseo/src/precompiles.rs b/parachain/runtime/paseo/src/precompiles.rs index 0525b12f7a..e12c111131 100644 --- a/parachain/runtime/paseo/src/precompiles.rs +++ b/parachain/runtime/paseo/src/precompiles.rs @@ -126,9 +126,9 @@ pub type PrecompilesSetAt = ( PrecompileAt, ECRecoverPublicKey, (CallableByContract, CallableByPrecompile)>, PrecompileAt, Ed25519Verify, (CallableByContract, CallableByPrecompile)>, // Litentry precompiles (starts from 0x5000): - // ParachainStaking: pallet_parachain_staking = 15 + 20480 + // Vesting: pallet_vesting = 11 + 20480 PrecompileAt< - AddressU64<20495>, + AddressU64<20491>, VestingPrecompile, (CallableByContract, CallableByPrecompile), >, diff --git a/parachain/ts-tests/integration-tests/precompile-contract.test.ts b/parachain/ts-tests/integration-tests/precompile-contract.test.ts index 68f76dcad7..14ad0ca5be 100644 --- a/parachain/ts-tests/integration-tests/precompile-contract.test.ts +++ b/parachain/ts-tests/integration-tests/precompile-contract.test.ts @@ -31,7 +31,7 @@ describeLitentry('Test Parachain Precompile Contract', ``, (context) => { const precompileStakingContractAddress = '0x000000000000000000000000000000000000502d'; const precompileBridgeContractAddress = '0x000000000000000000000000000000000000503d'; const precompileOmniBridgeContractAddress = '0x0000000000000000000000000000000000005055'; - const precompileVestingContractAddress = '0x000000000000000000000000000000000000500f'; + const precompileVestingContractAddress = '0x000000000000000000000000000000000000500b'; const evmAccountRaw = { privateKey: '0x01ab6e801c06e59ca97a14fc0a1978b27fa366fc87450e0b65459dd3515b7391', address: '0xaaafB3972B05630fCceE866eC69CdADd9baC2771', @@ -346,7 +346,8 @@ describeLitentry('Test Parachain Precompile Contract', ``, (context) => { } // Add an almost immediate-unlocked vesting - const vestedTransferTx = context.api.tx.vesting.vestedTransfer(evmAccountRaw.mappedAddress, { locked: '60000000000000000000', perBlock: '60000000000000000000', startingBlock: context.api.query.system.number() + 2}); + const currentBlock = await context.api.query.system.number(); + const vestedTransferTx = context.api.tx.vesting.vestedTransfer(evmAccountRaw.mappedAddress, { locked: '60000000000000000000', perBlock: '60000000000000000000', startingBlock: currentBlock + 2}); await signAndSend(vestedTransferTx, context.alice); // Set timeout to 60 seconds (5 blocks on parachain) From 5e68f012d673ccbeed5fb43f55a036c69b2fbc46 Mon Sep 17 00:00:00 2001 From: Minqi Wang Date: Fri, 21 Feb 2025 20:20:35 +0800 Subject: [PATCH 12/15] chore: fix --- .../ts-tests/integration-tests/precompile-contract.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/parachain/ts-tests/integration-tests/precompile-contract.test.ts b/parachain/ts-tests/integration-tests/precompile-contract.test.ts index 14ad0ca5be..dd0bfd4d81 100644 --- a/parachain/ts-tests/integration-tests/precompile-contract.test.ts +++ b/parachain/ts-tests/integration-tests/precompile-contract.test.ts @@ -346,8 +346,8 @@ describeLitentry('Test Parachain Precompile Contract', ``, (context) => { } // Add an almost immediate-unlocked vesting - const currentBlock = await context.api.query.system.number(); - const vestedTransferTx = context.api.tx.vesting.vestedTransfer(evmAccountRaw.mappedAddress, { locked: '60000000000000000000', perBlock: '60000000000000000000', startingBlock: currentBlock + 2}); + const targetBlock = BigInt(await context.api.query.system.number()) + BigInt(2); + const vestedTransferTx = context.api.tx.vesting.vestedTransfer(evmAccountRaw.mappedAddress, { locked: '60000000000000000000', perBlock: '60000000000000000000', startingBlock: targetBlock.toString()}); await signAndSend(vestedTransferTx, context.alice); // Set timeout to 60 seconds (5 blocks on parachain) From e3b2f61108538342b8da5080ee47b940027e9dca Mon Sep 17 00:00:00 2001 From: Minqi Wang Date: Fri, 21 Feb 2025 21:31:51 +0800 Subject: [PATCH 13/15] chore: fix --- .../ts-tests/integration-tests/precompile-contract.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parachain/ts-tests/integration-tests/precompile-contract.test.ts b/parachain/ts-tests/integration-tests/precompile-contract.test.ts index dd0bfd4d81..db8f587488 100644 --- a/parachain/ts-tests/integration-tests/precompile-contract.test.ts +++ b/parachain/ts-tests/integration-tests/precompile-contract.test.ts @@ -346,7 +346,7 @@ describeLitentry('Test Parachain Precompile Contract', ``, (context) => { } // Add an almost immediate-unlocked vesting - const targetBlock = BigInt(await context.api.query.system.number()) + BigInt(2); + const targetBlock = parseInt((await context.api.query.system.number()).toString()) + 2; const vestedTransferTx = context.api.tx.vesting.vestedTransfer(evmAccountRaw.mappedAddress, { locked: '60000000000000000000', perBlock: '60000000000000000000', startingBlock: targetBlock.toString()}); await signAndSend(vestedTransferTx, context.alice); From f37684a950e443a994ee4e3cf72e9cdedcc87ef4 Mon Sep 17 00:00:00 2001 From: Minqi Wang Date: Fri, 21 Feb 2025 22:54:13 +0800 Subject: [PATCH 14/15] chore: account address format --- .../ts-tests/integration-tests/precompile-contract.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parachain/ts-tests/integration-tests/precompile-contract.test.ts b/parachain/ts-tests/integration-tests/precompile-contract.test.ts index db8f587488..76ca17aadf 100644 --- a/parachain/ts-tests/integration-tests/precompile-contract.test.ts +++ b/parachain/ts-tests/integration-tests/precompile-contract.test.ts @@ -367,7 +367,7 @@ describeLitentry('Test Parachain Precompile Contract', ``, (context) => { console.log(`Print Event data: ${JSON.stringify(event_data)}`); // VestingCompleted Event - expect(event_data.account).to.eq(evmAccountRaw.mappedAddress); + expect(event_data.account).to.eq(evmToAddress(evmAccountRaw.address, 42)); console.timeEnd('Test precompile vesting contract'); }); From 8a56ce0320973dcbd4bfb10377fd3b8c7ea6c8d8 Mon Sep 17 00:00:00 2001 From: Minqi Wang Date: Sat, 22 Feb 2025 00:23:51 +0800 Subject: [PATCH 15/15] chore: this time should work --- .../ts-tests/integration-tests/precompile-contract.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/parachain/ts-tests/integration-tests/precompile-contract.test.ts b/parachain/ts-tests/integration-tests/precompile-contract.test.ts index 76ca17aadf..a0ab0f7546 100644 --- a/parachain/ts-tests/integration-tests/precompile-contract.test.ts +++ b/parachain/ts-tests/integration-tests/precompile-contract.test.ts @@ -14,7 +14,7 @@ import precompileBridgeContractAbi from '../common/abi/precompile/Bridge.json'; import precompileOmniBridgeContractAbi from '../common/abi/precompile/OmniBridge.json'; import precompileVestingContractAbi from '../common/abi/precompile/Vesting.json'; const BN = require('bn.js'); -import { evmToAddress } from '@polkadot/util-crypto'; +import { encodeAddress, evmToAddress } from '@polkadot/util-crypto'; import { KeyringPair } from '@polkadot/keyring/types'; import { HexString } from '@polkadot/util/types'; import { ethers } from 'ethers'; @@ -367,7 +367,7 @@ describeLitentry('Test Parachain Precompile Contract', ``, (context) => { console.log(`Print Event data: ${JSON.stringify(event_data)}`); // VestingCompleted Event - expect(event_data.account).to.eq(evmToAddress(evmAccountRaw.address, 42)); + expect(encodeAddress(event_data.account, 42)).to.eq(evmToAddress(evmAccountRaw.address, 42)); console.timeEnd('Test precompile vesting contract'); });