-
Notifications
You must be signed in to change notification settings - Fork 19
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
Add vesting precompile #3263
Add vesting precompile #3263
Changes from 11 commits
25fbcb4
2ac0b8b
80c0d21
e9a0278
1f6ace9
42e70fe
54f0c13
f3f54d0
6b50409
78daa01
8c0e6d9
6f73257
29e7848
5e68f01
e3b2f61
f37684a
8a56ce0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
[package] | ||
authors = ["Trust Computing GmbH <info@litentry.com>"] | ||
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", | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// 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 <https://www.gnu.org/licenses/>. | ||
#![cfg_attr(not(feature = "std"), no_std)] | ||
|
||
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_std::marker::PhantomData; | ||
|
||
pub struct VestingPrecompile<Runtime>(PhantomData<Runtime>); | ||
|
||
#[precompile_utils::precompile] | ||
impl<Runtime> VestingPrecompile<Runtime> | ||
where | ||
Runtime: pallet_vesting::Config + pallet_evm::Config, | ||
Runtime::RuntimeCall: Dispatchable<PostInfo = PostDispatchInfo> + GetDispatchInfo, | ||
Runtime::RuntimeCall: From<pallet_vesting::Call<Runtime>>, | ||
<Runtime::RuntimeCall as Dispatchable>::RuntimeOrigin: From<Option<Runtime::AccountId>>, | ||
{ | ||
#[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::<Runtime>::vest {}; | ||
RuntimeHelper::<Runtime>::try_dispatch(handle, Some(origin).into(), call)?; | ||
|
||
Ok(()) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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<R> = ( | |
PrecompileAt<AddressU64<1026>, ECRecoverPublicKey, (CallableByContract, CallableByPrecompile)>, | ||
PrecompileAt<AddressU64<1027>, Ed25519Verify, (CallableByContract, CallableByPrecompile)>, | ||
// Litentry precompiles (starts from 0x5000): | ||
// ParachainStaking: pallet_parachain_staking = 15 + 20480 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, why not 11 + 20480 to make it consistent? 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. corrected |
||
PrecompileAt< | ||
AddressU64<20495>, | ||
VestingPrecompile<R>, | ||
(CallableByContract, CallableByPrecompile), | ||
>, | ||
// ParachainStaking: pallet_parachain_staking = 45 + 20480 | ||
PrecompileAt< | ||
AddressU64<20525>, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[ | ||
{ | ||
"inputs": [], | ||
"name": "vest", | ||
"outputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
} | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to add a test case in parachain ts-tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. I will add one.