Skip to content

Commit

Permalink
P 975 litentry evm (#2967)
Browse files Browse the repository at this point in the history
* feat: add litentry evm, precompile, score_staking

* feat: archive migration

* chore: enable litentry evm ts-test

* chore: lock file

* chore

* chore

* chore

* debug: missing declare of score staking

* chore: update node

* chore

* chore

* chore: rename folder

* chore

* chore: add more ts-test hint

* chore

* chore

* chore

* chore

* chore

* chore

* chore: remove migration part

* chore: modify alice starting balance

* chore

* chore: update ts-test parameter

---------

Signed-off-by: WMQ <46511820+wangminqi@users.noreply.github.com>
  • Loading branch information
wangminqi committed Aug 12, 2024
1 parent 66cfb56 commit 2df6398
Show file tree
Hide file tree
Showing 15 changed files with 802 additions and 111 deletions.
15 changes: 15 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ test-cargo-all-benchmarks:

.PHONY: test-ts-docker-litentry ## Run litentry ts tests with docker without clean-up
test-ts-docker-litentry: launch-docker-litentry launch-docker-bridge
@./scripts/run-ts-test.sh litentry bridge no_evm
@./scripts/run-ts-test.sh litentry bridge evm

.PHONY: test-ts-docker-litmus ## Run litmus ts tests with docker without clean-up
test-ts-docker-litmus: launch-docker-litmus launch-docker-bridge
Expand All @@ -136,7 +136,7 @@ test-ts-docker-rococo: launch-docker-rococo launch-docker-bridge

.PHONY: test-ts-binary-litentry ## Run litentry ts tests with binary without clean-up
test-ts-binary-litentry: launch-binary-litentry
@./scripts/run-ts-test.sh litentry no_bridge no_evm
@./scripts/run-ts-test.sh litentry no_bridge evm

.PHONY: test-ts-binary-litmus ## Run litmus ts tests with binary without clean-up
test-ts-binary-litmus: launch-binary-litmus
Expand Down
8 changes: 6 additions & 2 deletions node/src/chain_specs/litentry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub fn get_chain_spec_dev() -> ChainSpec {
vec![
(
get_account_id_from_seed::<sr25519::Public>("Alice"),
DEFAULT_ENDOWED_ACCOUNT_BALANCE,
6 * DEFAULT_ENDOWED_ACCOUNT_BALANCE,
),
(
get_account_id_from_seed::<sr25519::Public>("Bob"),
Expand Down Expand Up @@ -196,7 +196,8 @@ fn generate_genesis(
balances: BalancesConfig { balances: endowed_accounts },
parachain_info: ParachainInfoConfig { parachain_id: id },
parachain_staking: ParachainStakingConfig {
candidates: invulnerables.iter().cloned().map(|(acc, _)| (acc, 50 * UNIT)).collect(),
// Should be enough for both Litentry and rococo
candidates: invulnerables.iter().cloned().map(|(acc, _)| (acc, 5000 * UNIT)).collect(),
..Default::default()
},
session: SessionConfig {
Expand Down Expand Up @@ -231,11 +232,14 @@ fn generate_genesis(
polkadot_xcm: PolkadotXcmConfig { safe_xcm_version: Some(SAFE_XCM_VERSION) },
transaction_payment: Default::default(),
assets: Default::default(),
ethereum: Default::default(),
evm: Default::default(),
teebag: TeebagConfig {
allow_sgx_debug_mode: true,
admin: None,
mode: TeebagOperationalMode::Development,
},
bitacross: BitacrossConfig { admin: None },
score_staking: Default::default(),
}
}
32 changes: 32 additions & 0 deletions runtime/litentry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ version = '0.1.0'
hex = { workspace = true, optional = true }
hex-literal = { workspace = true }
log = { workspace = true }
num_enum = { workspace = true }
parity-scale-codec = { workspace = true }
scale-info = { workspace = true }

Expand Down Expand Up @@ -84,17 +85,32 @@ pallet-bridge = { workspace = true }
pallet-bridge-transfer = { workspace = true }
pallet-extrinsic-filter = { workspace = true }
pallet-parachain-staking = { workspace = true }
pallet-score-staking = { workspace = true }
pallet-teebag = { workspace = true }
runtime-common = { workspace = true }

fp-evm = { workspace = true }
fp-rpc = { workspace = true }
fp-self-contained = { workspace = true }
pallet-ethereum = { workspace = true }
pallet-evm = { workspace = true }
pallet-evm-precompile-assets-erc20 = { workspace = true }
pallet-evm-precompile-blake2 = { workspace = true }
pallet-evm-precompile-bn128 = { workspace = true }
pallet-evm-precompile-dispatch = { workspace = true }
pallet-evm-precompile-ed25519 = { workspace = true }
pallet-evm-precompile-modexp = { workspace = true }
pallet-evm-precompile-sha3fips = { workspace = true }
pallet-evm-precompile-simple = { workspace = true }

pallet-evm-precompile-bridge-transfer = { workspace = true }
pallet-evm-precompile-parachain-staking = { workspace = true }
pallet-evm-precompile-score-staking = { workspace = true }

moonbeam-evm-tracer = { workspace = true }
moonbeam-rpc-primitives-debug = { workspace = true }
moonbeam-rpc-primitives-txpool = { workspace = true }
precompile-utils = { workspace = true }

[dev-dependencies]
cumulus-primitives-parachain-inherent = { workspace = true, features = ["std"] }
Expand Down Expand Up @@ -144,6 +160,7 @@ runtime-benchmarks = [
"pallet-bridge-transfer/runtime-benchmarks",
"pallet-extrinsic-filter/runtime-benchmarks",
"cumulus-pallet-xcmp-queue/runtime-benchmarks",
"pallet-score-staking/runtime-benchmarks",
]
std = [
"parity-scale-codec/std",
Expand Down Expand Up @@ -179,6 +196,17 @@ std = [
"pallet-democracy/std",
"pallet-ethereum/std",
"pallet-evm/std",
"pallet-evm-precompile-assets-erc20/std",
"pallet-evm-precompile-blake2/std",
"pallet-evm-precompile-simple/std",
"pallet-evm-precompile-bn128/std",
"pallet-evm-precompile-dispatch/std",
"pallet-evm-precompile-ed25519/std",
"pallet-evm-precompile-modexp/std",
"pallet-evm-precompile-sha3fips/std",
"pallet-evm-precompile-bridge-transfer/std",
"pallet-evm-precompile-parachain-staking/std",
"pallet-evm-precompile-score-staking/std",
"pallet-identity/std",
"pallet-membership/std",
"pallet-multisig/std",
Expand Down Expand Up @@ -208,6 +236,7 @@ std = [
"xcm/std",
"xcm-builder/std",
"xcm-executor/std",
"fp-evm/std",
"fp-rpc/std",
"fp-self-contained/std",
"frame-benchmarking?/std",
Expand All @@ -217,10 +246,12 @@ std = [
"pallet-bridge-transfer/std",
"pallet-extrinsic-filter/std",
"pallet-bitacross/std",
"pallet-score-staking/std",
"pallet-teebag/std",
"moonbeam-evm-tracer/std",
"moonbeam-rpc-primitives-debug/std",
"moonbeam-rpc-primitives-txpool/std",
"precompile-utils/std",
]
try-runtime = [
"hex",
Expand Down Expand Up @@ -268,4 +299,5 @@ try-runtime = [
"pallet-vesting/try-runtime",
"pallet-xcm/try-runtime",
"parachain-info/try-runtime",
"pallet-score-staking/try-runtime",
]
25 changes: 23 additions & 2 deletions runtime/litentry/src/asset_config.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
use super::{
weights, AccountId, AssetId, Balance, Balances, Runtime, RuntimeEvent, TreasuryPalletId,
};
use crate::constants::currency::deposit;
use crate::{constants::currency::deposit, precompiles::ASSET_PRECOMPILE_ADDRESS_PREFIX};
use frame_support::{
parameter_types,
traits::{AsEnsureOriginWithArg, ConstU32, NeverEnsureOrigin},
};
use frame_system::EnsureRoot;
use pallet_evm_precompile_assets_erc20::AddressToAssetId;
use parity_scale_codec::Compact;
use runtime_common::{
currency::{DOLLARS, EXISTENTIAL_DEPOSIT},
xcm_impl::CurrencyId,
EnsureRootOrHalfCouncil,
};
use sp_core::ConstU128;
use sp_core::{ConstU128, H160};
use sp_runtime::traits::AccountIdConversion;
use sp_std::prelude::*;

Expand All @@ -36,6 +37,26 @@ parameter_types! {
pub const AssetAccountDeposit: Balance = deposit(1, 18);
}

impl AddressToAssetId<AssetId> for Runtime {
fn address_to_asset_id(address: H160) -> Option<AssetId> {
let mut data = [0u8; 16];
let address_bytes: [u8; 20] = address.into();
if ASSET_PRECOMPILE_ADDRESS_PREFIX.eq(&address_bytes[0..4]) {
data.copy_from_slice(&address_bytes[4..20]);
Some(u128::from_be_bytes(data))
} else {
None
}
}

fn asset_id_to_address(asset_id: AssetId) -> H160 {
let mut data = [0u8; 20];
data[0..4].copy_from_slice(ASSET_PRECOMPILE_ADDRESS_PREFIX);
data[4..20].copy_from_slice(&asset_id.to_be_bytes());
H160::from(data)
}
}

pub struct AssetsBenchmarkHelper;
#[cfg(feature = "runtime-benchmarks")]
impl<AssetIdParameter: From<u128>> pallet_assets::BenchmarkHelper<AssetIdParameter>
Expand Down
Loading

0 comments on commit 2df6398

Please sign in to comment.