From 1f57931e9237780758d21a0237a3064b2c7397c6 Mon Sep 17 00:00:00 2001 From: 4meta5 Date: Wed, 29 May 2024 12:52:16 -0400 Subject: [PATCH] save config progress but blocked by pallet impl now which must be changed for security reasons --- evm-template/runtime/src/defi.rs | 73 +++++++++++++++++++++++++------- 1 file changed, 57 insertions(+), 16 deletions(-) diff --git a/evm-template/runtime/src/defi.rs b/evm-template/runtime/src/defi.rs index c75eec17..4d83d30b 100644 --- a/evm-template/runtime/src/defi.rs +++ b/evm-template/runtime/src/defi.rs @@ -4,7 +4,8 @@ use frame_system::EnsureRoot; use orml_traits::parameter_type_with_key; use super::{ - Balance, Balances, BlockNumber, Currencies, Runtime, RuntimeEvent, Tokens, WeightToFee, + AccountId, Balance, Balances, BlockNumber, Currencies, Runtime, RuntimeEvent, Tokens, + WeightToFee, }; pub type Amount = i128; @@ -16,7 +17,7 @@ parameter_types! { } parameter_type_with_key! { - pub ExistentialDeposits: |currency_id: AssetId| -> Balance { + pub ExistentialDeposits: |_currency_id: AssetId| -> Balance { Balance::default() }; } @@ -36,35 +37,75 @@ impl orml_tokens::Config for Runtime { } parameter_types! { - pub const GetNativeCurrencyId: AssetId = 0u32; + // TODO: enforce everywhere, including XCM execution + pub const NativeAssetId: AssetId = 0u32; + // NOTE: the underlying impl of `reset_payment_currency` extrinsic assumes that this is not NativeAssetId + // even if we want to use pallet-balances for managing the EVM Asset + // TODO: set `EvmAssetId = NativeAssetId` without violating the assumptions of `reset_payment_currency` extrinsic + // ISSUE #5575 + pub const EvmAssetId: AssetId = 1u32; } impl orml_currencies::Config for Runtime { - type GetNativeCurrencyId = GetNativeCurrencyId; + type GetNativeCurrencyId = NativeAssetId; type MultiCurrency = Tokens; type NativeCurrency = orml_currencies::BasicCurrencyAdapter; type WeightInfo = (); // TODO: generate weights } +// TODO: upstream for all EVM chains that use native 20 byte accounts +pub struct AllEvmAccounts; +impl InspectEvmAccounts for AllEvmAccounts { + /// Returns `True` if the account is EVM truncated account. + fn is_evm_account(account_id: AccountId) -> bool { + true + } + + /// get the EVM address from the substrate address. + fn evm_address(account_id: &impl AsRef<[u8; 32]>) -> EvmAddress { + // unused in pallet-tx-multi-payment + [0u8; 20] + } + + /// Get the truncated address from the EVM address. + fn truncated_account_id(evm_address: AccountId) -> AccountId { + evm_address + } + + /// Return the Substrate address bound to the EVM account. If not bound, returns `None`. + fn bound_account_id(evm_address: AccountId) -> Option { + Some(evm_address) + } + + /// Get the Substrate address from the EVM address. + /// Returns the truncated version of the address if the address wasn't bind. + fn account_id(evm_address: AccountId) -> AccountId { + evm_address + } + + /// Returns `True` if the address is allowed to deploy smart contracts. + fn can_deploy_contracts(evm_address: AccountId) -> bool { + true + } +} + impl pallet_transaction_multi_payment::Config for Runtime { - type AcceptedCurrencyOrigin = EnsureRoot; + type AcceptedCurrencyOrigin = EnsureRoot; type Currencies = Currencies; - // TODO: ensure matches EVM used in `pallet_evm` - type EvmAssetId = evm::WethAssetId; - type EvmPermit = evm::permit::EvmPermitHandler; - // TODO: impl InspectEVMAccounts by Runtime in separate folder - // because we do not require pallet-evm-accounts config - type InspectEvmAccounts = (); - //EVMAccounts - type NativeAssetId = GetNativeCurrencyId; + // ISSUE #5575 + type EvmAssetId = NativeAssetId; + // NOTE: impl EvmPermit for () returns false positive results + // TODO1: replace this impl with dummy patch that returns true negative results + // TODO2: impl EvmPermit and its precompile in a follow up because the precompile written by HydraDX-node assumes we use their 32 byte keys (which we do not) + type EvmPermit = (); + type InspectEvmAccounts = AllEvmAccounts; + type NativeAssetId = NativeAssetId; type OraclePriceProvider = (); - //OraclePriceProvider; type RouteProvider = (); - //Router; type RuntimeEvent = RuntimeEvent; type TryCallCurrency<'a> = pallet_transaction_multi_payment::TryCallCurrency; + // TODO: update weights type WeightInfo = (); - //TODO: run weights in context of this runtime, first add to benchmarking runtime config type WeightToFee = WeightToFee; }