diff --git a/Cargo.lock b/Cargo.lock index 4a6d32924..c12b78eba 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5268,6 +5268,7 @@ dependencies = [ "moonbeam-evm-tracer", "moonbeam-rpc-primitives-debug", "moonbeam-rpc-primitives-txpool", + "pallet-account", "pallet-assets", "pallet-aura", "pallet-balances", @@ -6434,6 +6435,24 @@ dependencies = [ "libm 0.1.4", ] +[[package]] +name = "pallet-account" +version = "0.1.0" +source = "git+https://github.com/AstarNetwork/astar-frame?branch=feature/pallet-account#ca3bddc43aa4e40bac153d8ad8394768848c011c" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "parity-scale-codec", + "scale-info", + "serde", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", +] + [[package]] name = "pallet-assets" version = "4.0.0-dev" @@ -11814,6 +11833,7 @@ dependencies = [ "moonbeam-evm-tracer", "moonbeam-rpc-primitives-debug", "moonbeam-rpc-primitives-txpool", + "pallet-account", "orml-traits", "orml-xcm-support", "orml-xtokens", diff --git a/Cargo.toml b/Cargo.toml index bc5746b6d..c4e6c3982 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -212,6 +212,7 @@ orml-xcm-support = { git = "https://github.com/open-web3-stack/open-runtime-modu # Astar pallets & modules # (wasm) +pallet-account = { git = "https://github.com/AstarNetwork/astar-frame", branch = "feature/pallet-account", default-features = false } pallet-block-reward = { git = "https://github.com/AstarNetwork/astar-frame", branch = "polkadot-v0.9.39", default-features = false } pallet-collator-selection = { git = "https://github.com/AstarNetwork/astar-frame", branch = "polkadot-v0.9.39", default-features = false } pallet-custom-signatures = { git = "https://github.com/AstarNetwork/astar-frame", branch = "polkadot-v0.9.39", default-features = false } diff --git a/runtime/local/Cargo.toml b/runtime/local/Cargo.toml index 286273822..310649368 100644 --- a/runtime/local/Cargo.toml +++ b/runtime/local/Cargo.toml @@ -17,6 +17,7 @@ fp-self-contained = { workspace = true } frame-executive = { workspace = true } frame-support = { workspace = true } frame-system = { workspace = true } +pallet-account = { workspace = true } pallet-assets = { workspace = true } pallet-aura = { workspace = true } pallet-balances = { workspace = true } @@ -103,6 +104,7 @@ std = [ "frame-support/std", "frame-system-rpc-runtime-api/std", "frame-system/std", + "pallet-account/std", "pallet-assets/std", "pallet-aura/std", "pallet-balances/std", diff --git a/runtime/local/src/lib.rs b/runtime/local/src/lib.rs index c75822be4..94f6cc462 100644 --- a/runtime/local/src/lib.rs +++ b/runtime/local/src/lib.rs @@ -528,12 +528,28 @@ parameter_types! { pub WeightPerGas: Weight = Weight::from_ref_time(WEIGHT_PER_GAS); } +/// Ensure that the origin is EVM compatible. +pub struct EnsureEvmOrigin; +impl pallet_evm::EnsureAddressOrigin for EnsureEvmOrigin +where + OuterOrigin: Into> + + From, +{ + type Success = (); + fn try_address_origin(address: &H160, origin: OuterOrigin) -> Result<(), OuterOrigin> { + origin.into().and_then(|o| match o { + pallet_account::NativeAndEVM::H160(a) if *address == a => Ok(()), + r => Err(OuterOrigin::from(r)), + }) + } +} + impl pallet_evm::Config for Runtime { type FeeCalculator = BaseFee; type GasWeightMapping = pallet_evm::FixedGasWeightMapping; type WeightPerGas = WeightPerGas; type BlockHashMapping = pallet_ethereum::EthereumBlockHashMapping; - type CallOrigin = pallet_evm::EnsureAddressRoot; + type CallOrigin = EnsureEvmOrigin; type WithdrawOrigin = pallet_evm::EnsureAddressTruncated; type AddressMapping = pallet_evm::HashedAddressMapping; type Currency = Balances; @@ -958,6 +974,15 @@ impl pallet_proxy::Config for Runtime { type AnnouncementDepositFactor = ConstU128<{ MILLIAST * 660 }>; } +impl pallet_account::Config for Runtime { + type CustomOrigin = pallet_account::NativeAndEVM; + type CustomOriginKind = pallet_account::NativeAndEVMKind; + type RuntimeOrigin = RuntimeOrigin; + type RuntimeEvent = RuntimeEvent; + type RuntimeCall = RuntimeCall; + type WeightInfo = (); +} + // TODO: remove this once https://github.com/paritytech/substrate/issues/12161 is resolved #[rustfmt::skip] construct_runtime!( @@ -991,6 +1016,7 @@ construct_runtime!( TechnicalCommittee: pallet_collective::, Treasury: pallet_treasury, Xvm: pallet_xvm, + Account: pallet_account, Proxy: pallet_proxy, Preimage: pallet_preimage, } diff --git a/runtime/shibuya/Cargo.toml b/runtime/shibuya/Cargo.toml index a1639e94e..4e3cedfab 100644 --- a/runtime/shibuya/Cargo.toml +++ b/runtime/shibuya/Cargo.toml @@ -37,6 +37,7 @@ frame-executive = { workspace = true } frame-support = { workspace = true } frame-system = { workspace = true } frame-system-rpc-runtime-api = { workspace = true } +pallet-account = { workspace = true } pallet-assets = { workspace = true } pallet-aura = { workspace = true } pallet-authorship = { workspace = true } @@ -157,6 +158,7 @@ std = [ "frame-executive/std", "frame-system/std", "frame-system-rpc-runtime-api/std", + "pallet-account/std", "pallet-authorship/std", "pallet-aura/std", "pallet-assets/std", diff --git a/runtime/shibuya/src/lib.rs b/runtime/shibuya/src/lib.rs index ccb966cd6..49f6dbefe 100644 --- a/runtime/shibuya/src/lib.rs +++ b/runtime/shibuya/src/lib.rs @@ -836,12 +836,28 @@ parameter_types! { pub WeightPerGas: Weight = Weight::from_ref_time(WEIGHT_PER_GAS); } +/// Ensure that the origin is EVM compatible. +pub struct EnsureEvmOrigin; +impl pallet_evm::EnsureAddressOrigin for EnsureEvmOrigin +where + OuterOrigin: Into> + + From, +{ + type Success = (); + fn try_address_origin(address: &H160, origin: OuterOrigin) -> Result<(), OuterOrigin> { + origin.into().and_then(|o| match o { + pallet_account::NativeAndEVM::H160(a) if *address == a => Ok(()), + r => Err(OuterOrigin::from(r)), + }) + } +} + impl pallet_evm::Config for Runtime { type FeeCalculator = BaseFee; type GasWeightMapping = pallet_evm::FixedGasWeightMapping; type WeightPerGas = WeightPerGas; type BlockHashMapping = pallet_ethereum::EthereumBlockHashMapping; - type CallOrigin = pallet_evm::EnsureAddressRoot; + type CallOrigin = EnsureEvmOrigin; type WithdrawOrigin = pallet_evm::EnsureAddressTruncated; type AddressMapping = pallet_evm::HashedAddressMapping; type Currency = Balances; @@ -1211,6 +1227,15 @@ impl pallet_xc_asset_config::Config for Runtime { type WeightInfo = pallet_xc_asset_config::weights::SubstrateWeight; } +impl pallet_account::Config for Runtime { + type CustomOrigin = pallet_account::NativeAndEVM; + type CustomOriginKind = pallet_account::NativeAndEVMKind; + type RuntimeOrigin = RuntimeOrigin; + type RuntimeEvent = RuntimeEvent; + type RuntimeCall = RuntimeCall; + type WeightInfo = (); +} + parameter_types! { // The deposit configuration for the singed migration. Specially if you want to allow any signed account to do the migration (see `SignedFilter`, these deposits should be high) pub const MigrationSignedDepositPerItem: Balance = 10 * MILLISBY; @@ -1286,6 +1311,7 @@ construct_runtime!( Preimage: pallet_preimage = 84, Xvm: pallet_xvm = 90, + Account: pallet_account= 91, Sudo: pallet_sudo = 99,