-
Notifications
You must be signed in to change notification settings - Fork 381
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:
pallet_unified_accounts
implementation (#1019)
* wip * feat: add initial implementation for `pallet_account` * feat: add test helpers and refactor * feat: setup mock and add tests for eip712 sig * feat: add `pallet_account` to local runtime * fix: runtime-benchmarks build * feat: add claim js script * feat: add tests for lookup and on kill * feat: add more tests * feat: add benchmarks * fix: build issues * feat: add to shibuya * feat: update xvm integration tests * feat: add intergration test for lookup * fix: formatting * fix: integration tests * feat: apply code review suggestions * feat: update pallet directory name * feat: expand tests * fix: benchmarks and weights * feat: use claim account in integration tests * feat: apply code suggestions * feat: remove `SignatureHelper` trait * feat: update claim script * feat: add check in default claim to manage collisions * fix: benchmarks * feat: inline `add_mappings()` method * feat: apply benchmarks weights & code suggestions * feat: re-run `pallet_balances` benchmarks
- Loading branch information
1 parent
ac29f4d
commit 51a1b84
Showing
26 changed files
with
3,159 additions
and
302 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
[package] | ||
name = "pallet-unified-accounts" | ||
version = "0.1.0" | ||
description = "Pallet for mapping VM accounts with native accounts" | ||
authors.workspace = true | ||
edition.workspace = true | ||
homepage.workspace = true | ||
repository.workspace = true | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
libsecp256k1 = { workspace = true, optional = true, features = ["hmac", "static-context"] } | ||
log = { workspace = true } | ||
parity-scale-codec = { workspace = true } | ||
scale-info = { workspace = true } | ||
|
||
frame-support = { workspace = true } | ||
frame-system = { workspace = true } | ||
sp-core = { workspace = true } | ||
sp-io = { workspace = true } | ||
sp-runtime = { workspace = true } | ||
sp-std = { workspace = true } | ||
|
||
# Benchmarks | ||
frame-benchmarking = { workspace = true, optional = true } | ||
|
||
precompile-utils = { workspace = true } | ||
|
||
# frontier | ||
pallet-evm = { workspace = true } | ||
|
||
# Astar | ||
astar-primitives = { workspace = true } | ||
|
||
[dev-dependencies] | ||
ethers = { workspace = true } | ||
hex = { workspace = true } | ||
pallet-balances = { workspace = true } | ||
pallet-ethereum = { workspace = true } | ||
pallet-evm = { workspace = true } | ||
pallet-timestamp = { workspace = true } | ||
|
||
[features] | ||
default = ["std"] | ||
std = [ | ||
"hex/std", | ||
"log/std", | ||
"libsecp256k1", | ||
"libsecp256k1/std", | ||
"parity-scale-codec/std", | ||
"scale-info/std", | ||
"sp-std/std", | ||
"sp-core/std", | ||
"sp-io/std", | ||
"sp-runtime/std", | ||
"frame-support/std", | ||
"frame-system/std", | ||
"astar-primitives/std", | ||
"precompile-utils/std", | ||
"pallet-evm/std", | ||
"pallet-balances/std", | ||
"pallet-timestamp/std", | ||
"pallet-ethereum/std", | ||
] | ||
runtime-benchmarks = [ | ||
"libsecp256k1/hmac", | ||
"frame-benchmarking", | ||
"frame-support/runtime-benchmarks", | ||
"frame-system/runtime-benchmarks", | ||
"sp-runtime/runtime-benchmarks", | ||
"astar-primitives/runtime-benchmarks", | ||
"pallet-ethereum/runtime-benchmarks", | ||
"pallet-evm/runtime-benchmarks", | ||
] | ||
try-runtime = ["frame-support/try-runtime", "pallet-evm/try-runtime"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// This file is part of Astar. | ||
|
||
// Copyright (C) 2019-2023 Stake Technologies Pte.Ltd. | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
// Astar 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. | ||
|
||
// Astar 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 Astar. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
#![cfg(feature = "runtime-benchmarks")] | ||
|
||
use super::*; | ||
use frame_benchmarking::v2::*; | ||
use frame_system::RawOrigin; | ||
|
||
/// Assert that the last event equals the provided one. | ||
fn assert_last_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) { | ||
frame_system::Pallet::<T>::assert_last_event(generic_event.into()); | ||
} | ||
|
||
#[benchmarks] | ||
mod benchmarks { | ||
use super::*; | ||
|
||
#[benchmark] | ||
fn claim_evm_address() { | ||
let caller: T::AccountId = whitelisted_caller(); | ||
let eth_secret_key = libsecp256k1::SecretKey::parse(&keccak_256(b"Alice")).unwrap(); | ||
let evm_address = Pallet::<T>::eth_address(ð_secret_key); | ||
let signature = Pallet::<T>::eth_sign_prehash( | ||
&Pallet::<T>::build_signing_payload(&caller), | ||
ð_secret_key, | ||
) | ||
.into(); | ||
|
||
let caller_clone = caller.clone(); | ||
|
||
#[extrinsic_call] | ||
_(RawOrigin::Signed(caller), evm_address, signature); | ||
|
||
assert_last_event::<T>( | ||
Event::<T>::AccountClaimed { | ||
account_id: caller_clone, | ||
evm_address, | ||
} | ||
.into(), | ||
); | ||
} | ||
|
||
#[benchmark] | ||
fn claim_default_evm_address() { | ||
let caller: T::AccountId = whitelisted_caller(); | ||
let caller_clone = caller.clone(); | ||
let evm_address = T::DefaultNativeToEvm::into_h160(caller.clone()); | ||
|
||
#[extrinsic_call] | ||
_(RawOrigin::Signed(caller)); | ||
|
||
assert_last_event::<T>( | ||
Event::<T>::AccountClaimed { | ||
account_id: caller_clone, | ||
evm_address, | ||
} | ||
.into(), | ||
); | ||
} | ||
} |
Oops, something went wrong.