Skip to content

Commit

Permalink
save config progress but blocked by pallet impl now which must be cha…
Browse files Browse the repository at this point in the history
…nged for security reasons
  • Loading branch information
4meta5 committed May 29, 2024
1 parent 4b2388c commit 1f57931
Showing 1 changed file with 57 additions and 16 deletions.
73 changes: 57 additions & 16 deletions evm-template/runtime/src/defi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -16,7 +17,7 @@ parameter_types! {
}

parameter_type_with_key! {
pub ExistentialDeposits: |currency_id: AssetId| -> Balance {
pub ExistentialDeposits: |_currency_id: AssetId| -> Balance {
Balance::default()
};
}
Expand All @@ -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<Runtime, Balances, Amount, BlockNumber>;
type WeightInfo = (); // TODO: generate weights
}

// TODO: upstream for all EVM chains that use native 20 byte accounts
pub struct AllEvmAccounts;
impl<T> InspectEvmAccounts<AccountId, AccountId> 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<AccountId> {
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<AccountId>;
type AcceptedCurrencyOrigin = EnsureRoot<Self::AccountId>;
type Currencies = Currencies;
// TODO: ensure matches EVM used in `pallet_evm`
type EvmAssetId = evm::WethAssetId;
type EvmPermit = evm::permit::EvmPermitHandler<Runtime>;
// 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<AssetId, EmaOracle, LRNA>;
type RouteProvider = ();
//Router;
type RuntimeEvent = RuntimeEvent;
type TryCallCurrency<'a> = pallet_transaction_multi_payment::TryCallCurrency<Runtime>;
// TODO: update weights
type WeightInfo = ();
//TODO: run weights in context of this runtime, first add to benchmarking runtime config
type WeightToFee = WeightToFee;
}

0 comments on commit 1f57931

Please sign in to comment.