Skip to content
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

feat: pallet_unified_accounts implementation #1019

Merged
merged 30 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
bd16dfd
wip
ashutoshvarma Aug 23, 2023
d5e60cd
feat: add initial implementation for `pallet_account`
ashutoshvarma Aug 30, 2023
cff5b2a
feat: add test helpers and refactor
ashutoshvarma Aug 31, 2023
28a53aa
feat: setup mock and add tests for eip712 sig
ashutoshvarma Aug 31, 2023
1a6b8b0
feat: add `pallet_account` to local runtime
ashutoshvarma Aug 31, 2023
570cd51
fix: runtime-benchmarks build
ashutoshvarma Sep 1, 2023
d8826ac
feat: add claim js script
ashutoshvarma Sep 1, 2023
cf86aba
feat: add tests for lookup and on kill
ashutoshvarma Sep 8, 2023
51e00b7
feat: add more tests
ashutoshvarma Sep 11, 2023
9cfb429
feat: add benchmarks
ashutoshvarma Sep 11, 2023
cb5bef7
fix: build issues
ashutoshvarma Sep 11, 2023
dbffa3a
feat: add to shibuya
ashutoshvarma Sep 13, 2023
19dbd0a
feat: update xvm integration tests
ashutoshvarma Sep 13, 2023
10dfa24
feat: add intergration test for lookup
ashutoshvarma Sep 13, 2023
b738fb0
fix: formatting
ashutoshvarma Sep 13, 2023
1de5d16
fix: integration tests
ashutoshvarma Sep 14, 2023
2dbc09b
feat: apply code review suggestions
ashutoshvarma Sep 21, 2023
f9014ed
feat: update pallet directory name
ashutoshvarma Sep 21, 2023
97bd0e1
feat: expand tests
ashutoshvarma Sep 21, 2023
27ecc4c
fix: benchmarks and weights
ashutoshvarma Sep 25, 2023
434e940
feat: use claim account in integration tests
ashutoshvarma Sep 25, 2023
775f1b8
feat: apply code suggestions
ashutoshvarma Sep 25, 2023
a29f284
Merge branch 'master' into feat/account-unification
ashutoshvarma Sep 25, 2023
74e83da
feat: remove `SignatureHelper` trait
ashutoshvarma Sep 26, 2023
5e9a0b8
feat: update claim script
ashutoshvarma Sep 26, 2023
aa587d0
feat: add check in default claim to manage collisions
ashutoshvarma Sep 26, 2023
2609aec
fix: benchmarks
ashutoshvarma Sep 26, 2023
037028a
feat: inline `add_mappings()` method
ashutoshvarma Sep 26, 2023
9fcc5a6
feat: apply benchmarks weights & code suggestions
ashutoshvarma Sep 26, 2023
817ea7e
feat: re-run `pallet_balances` benchmarks
ashutoshvarma Sep 26, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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::DefaultAccountMapping::into_h160(caller.clone());

#[extrinsic_call]
_(RawOrigin::Signed(caller));

assert_last_event::<T>(
Event::<T>::AccountClaimed {
account_id: caller_clone,
evm_address,
}
.into(),
);
}
}
Loading
Loading