Skip to content

Commit

Permalink
feat: pallet_unified_accounts implementation (#1019)
Browse files Browse the repository at this point in the history
* 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
ashutoshvarma authored Sep 27, 2023
1 parent ac29f4d commit 51a1b84
Show file tree
Hide file tree
Showing 26 changed files with 3,159 additions and 302 deletions.
914 changes: 830 additions & 84 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,14 @@ rlp = "0.5"
tracing = "0.1.34"
similar-asserts = { version = "1.1.0" }
assert_matches = "1.3.0"
libsecp256k1 = "0.7.0"
libsecp256k1 = { version = "0.7.0", default-features = false }
impl-trait-for-tuples = "0.2.2"
slices = "0.2.0"
derive_more = { version = "0.99" }
proc-macro2 = "1.0"
quote = "1.0"
syn = { version = "1.0" }
ethers = { version = "2.0.9", default_features = false }

# Substrate
# (wasm)
Expand Down Expand Up @@ -277,6 +278,7 @@ pallet-xc-asset-config = { path = "./pallets/xc-asset-config", default-features
pallet-xvm = { path = "./pallets/xvm", default-features = false }
pallet-xcm = { path = "./pallets/pallet-xcm", default-features = false }
pallet-ethereum-checked = { path = "./pallets/ethereum-checked", default-features = false }
pallet-unified-accounts = { path = "./pallets/unified-accounts", default-features = false }

astar-primitives = { path = "./primitives", default-features = false }

Expand Down
76 changes: 76 additions & 0 deletions pallets/unified-accounts/Cargo.toml
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"]
76 changes: 76 additions & 0 deletions pallets/unified-accounts/src/benchmarking.rs
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(&eth_secret_key);
let signature = Pallet::<T>::eth_sign_prehash(
&Pallet::<T>::build_signing_payload(&caller),
&eth_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(),
);
}
}
Loading

0 comments on commit 51a1b84

Please sign in to comment.