Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
de01cd3
Use pallet-currency-swap as template
dmitrylavrenov Feb 19, 2025
5f39289
Minimal design implementation
dmitrylavrenov Feb 19, 2025
3940e57
Add etheruem execution logic
dmitrylavrenov Feb 19, 2025
e1d1ee7
Use ValidatedTransaction apply instead of execute
dmitrylavrenov Feb 19, 2025
96d6174
Fix deposited balance type
dmitrylavrenov Feb 19, 2025
f1a5082
Fix features
dmitrylavrenov Feb 19, 2025
0cc5c34
Fix features-snapshot
dmitrylavrenov Feb 19, 2025
e770e54
Fix cargo machete
dmitrylavrenov Feb 19, 2025
8e98914
Fix typo
dmitrylavrenov Feb 19, 2025
001d9c4
Some naming improvements
dmitrylavrenov Feb 19, 2025
e4da0c4
Add the corresponding transaction hash executed in evm to BalancesSwa…
dmitrylavrenov Feb 20, 2025
719bff1
Use zero as max fee per gas
dmitrylavrenov Feb 20, 2025
8075ab6
Handle dispatch result with post info
dmitrylavrenov Feb 20, 2025
a997f19
Rename evm_trx_hash to evm_transaction_hash
dmitrylavrenov Feb 20, 2025
211f506
Rename bridge pots account types
dmitrylavrenov Feb 20, 2025
343ca7c
Remove currency from pallet name
dmitrylavrenov Feb 20, 2025
23c1ae5
Remove unused required interfaces
dmitrylavrenov Feb 20, 2025
316d5e9
Use gas_limit as gas_transaction_call value from evm config
dmitrylavrenov Feb 20, 2025
3ee261d
Use token terminology instead of currency
dmitrylavrenov Feb 20, 2025
47e35c4
Uppercase for evm
dmitrylavrenov Feb 20, 2025
50b81d5
Add debug assert on resulted post_info ethereum transaction
dmitrylavrenov Feb 21, 2025
40f6777
Move ethereum transfer logic to separate function
dmitrylavrenov Feb 21, 2025
50459ae
Rename to pallet-evm-swap
dmitrylavrenov Feb 24, 2025
d75599f
Introduce precompile to execute swap from evm to native
dmitrylavrenov Feb 24, 2025
f9cc338
Implement helper function to execute balanced transfer
dmitrylavrenov Feb 24, 2025
eec8566
Implement a helper function to process dispatch error
dmitrylavrenov Feb 24, 2025
58b4dc2
Fix pallet docs
dmitrylavrenov Feb 24, 2025
824e740
Implement mock testing environment with basic setup works test
dmitrylavrenov Feb 25, 2025
aa7dd74
Introduce a helper function to prepare simple ethereum transfer trans…
dmitrylavrenov Feb 25, 2025
b97d646
Add basic swap works for native to evm case
dmitrylavrenov Feb 25, 2025
7be9fc3
Add evm to native basic swap works test
dmitrylavrenov Feb 25, 2025
ea1acf6
Add logs builder at precompile
dmitrylavrenov Feb 25, 2025
44843f9
Leave just alice accounts
dmitrylavrenov Feb 25, 2025
27d3958
Add more ethereum checks for evm to native swap tests
dmitrylavrenov Feb 25, 2025
4cf4600
Implement swap_works_almost_full_balance test for evm to native flow
dmitrylavrenov Feb 25, 2025
088e8a9
Add swap_fail_no_funds test for evm to native flow
dmitrylavrenov Feb 25, 2025
c657794
Add swap_fail_below_ed test for evm to native flow
dmitrylavrenov Feb 25, 2025
ea22f0f
Add swap_works_full_balance test for evm to native flow
dmitrylavrenov Feb 25, 2025
e799577
Add swap_fail_bad_selector test
dmitrylavrenov Feb 25, 2025
ac7c943
Add swap_fail_value_overflow test for evm to native flow
dmitrylavrenov Feb 25, 2025
070d29c
Add swap_fail_no_arguments test for evm to native flow
dmitrylavrenov Feb 25, 2025
8c1b4a5
Add swap_fail_short_argument for evm to native flow
dmitrylavrenov Feb 25, 2025
7e0749a
Add swap_fail_trailing_junk test for evm to native flow
dmitrylavrenov Feb 25, 2025
983b436
Some refactoring of evm_to_native tests
dmitrylavrenov Feb 25, 2025
413f49b
Use more elegant way to build precompiles at mock
dmitrylavrenov Feb 25, 2025
0310534
Fix typo
dmitrylavrenov Feb 25, 2025
9c1d157
Add a helper to run succeeded test for native to evm flow
dmitrylavrenov Feb 25, 2025
a2da3d9
Add swap_works_kill_origin for native to evm flow
dmitrylavrenov Feb 25, 2025
b2ff08b
Add swap_keep_alive_works test
dmitrylavrenov Feb 25, 2025
27cf98e
Add some swap failed tests
dmitrylavrenov Feb 25, 2025
383802b
Add swap_keep_alive_fails test
dmitrylavrenov Feb 25, 2025
f2f9afd
Switch to mutate fungible interface
dmitrylavrenov Feb 25, 2025
8c2bda3
Some renaming
dmitrylavrenov Feb 27, 2025
446b736
Add mode details into process_dispatch_error
dmitrylavrenov Feb 27, 2025
d0cb02c
Redesign evm to native tests
dmitrylavrenov Feb 27, 2025
7d544db
Add swap_fail_target_balance_overflow test
dmitrylavrenov Feb 27, 2025
c47063a
Redesign run_succeeded_test_and_assert for native to evm tests
dmitrylavrenov Feb 27, 2025
98f9dea
Prevent bridge account killing at precompile logic
dmitrylavrenov Feb 27, 2025
3dfb075
Prevent killing bridge pot evm account at evm to native flow
dmitrylavrenov Feb 27, 2025
21a744b
Add swap_fail_bridge_evm_overflow test
dmitrylavrenov Feb 27, 2025
3cc5c6a
Add swap_fail_bridge_native_killed test
dmitrylavrenov Feb 27, 2025
50e6d9c
Improve process_dispatch_error handler
dmitrylavrenov Feb 27, 2025
51b3e90
e2e: swap: nativeToEvm implementation
dmitrylavrenov Feb 28, 2025
1b249cc
Add ewmSwap precompile abi
dmitrylavrenov Feb 28, 2025
9ab94b5
Implement evm to native tokens swap e2e test
dmitrylavrenov Feb 28, 2025
d14852e
Remove description of the interface from abi
dmitrylavrenov Feb 28, 2025
24eeba5
Integrate CallOrCreateInfo usage
dmitrylavrenov Feb 28, 2025
1ee7d0d
Add swap_both_fails_bridge_evm_no_funds test
dmitrylavrenov Feb 28, 2025
0bc056f
Add swap_both_fails_bridge_native_overflow test
dmitrylavrenov Feb 28, 2025
65bb7e8
Check alice, bridgePotEvm, evmSwapPrecompile balances at evmToNative …
dmitrylavrenov Feb 28, 2025
efe156f
Add native related balances checks at evm to native e2e test
dmitrylavrenov Mar 3, 2025
256a006
Move getNativeBalance to swap utils
dmitrylavrenov Mar 3, 2025
c210dcc
Add native balances checks at native to evm e2e test
dmitrylavrenov Mar 3, 2025
0a1572f
Add evm balances checks at native to evm e2e test
dmitrylavrenov Mar 3, 2025
7a003d8
Some e2e renaimings
dmitrylavrenov Mar 3, 2025
a3c6114
Move getNativeBalance to substrate lib
dmitrylavrenov Mar 3, 2025
55f249e
Add evm swap tests at humanode-runtime
dmitrylavrenov Mar 3, 2025
85782b4
Use runner at evm to native unit tests at pallet-evm-swap
dmitrylavrenov Mar 3, 2025
4ffef33
Edit balance type at fee calculation at humanode-runtime tests
dmitrylavrenov Mar 3, 2025
c938fdb
Add EVM_SWAP to precompiles_constants
dmitrylavrenov Mar 4, 2025
be29fd9
Deprecate precompile-currency-swap usage at humanode-runtime
dmitrylavrenov Mar 4, 2025
e7fbf1a
Introduce precompile-evm-swap
dmitrylavrenov Mar 5, 2025
41d63af
Remove precompile-currency-swap crate
dmitrylavrenov Mar 5, 2025
d334f3f
Move precompile logic to own crate
dmitrylavrenov Mar 5, 2025
d4e4460
Rename currency_swap mod to evm_swap at humanode-runtime
dmitrylavrenov Mar 5, 2025
1a2aa98
Fix typos
dmitrylavrenov Mar 5, 2025
2408617
Fix machete
dmitrylavrenov Mar 5, 2025
66d43e6
Fix features snapshot
dmitrylavrenov Mar 5, 2025
2c0d205
Minor improvments
dmitrylavrenov Mar 5, 2025
b71246b
Add event description to swap precompile interface
dmitrylavrenov Mar 5, 2025
2546256
Rename precompile and pallet crates
dmitrylavrenov Mar 5, 2025
3a84067
Fix typos
dmitrylavrenov Mar 5, 2025
5ca3164
Add feesPot balance check at e2e tests
dmitrylavrenov Mar 5, 2025
154e03c
Pass more gas for failed tests in precompile
dmitrylavrenov Mar 7, 2025
6a56dbb
Minor improvements for e2e tests
dmitrylavrenov Mar 7, 2025
f0be229
Use fully qualified path for precompile_evm_to_native_swap
dmitrylavrenov Mar 13, 2025
c9456c3
Add ethereum execution checks for nativeToEvm e2e test
dmitrylavrenov Mar 13, 2025
8b7fc35
Add some comment
dmitrylavrenov Mar 13, 2025
f68e074
Improve the way of checking expected events for nativeToEvm e2e test
dmitrylavrenov Mar 14, 2025
13d59b9
Use assert_noop at precompile tests where fee is not spent
dmitrylavrenov Mar 24, 2025
38b15ed
Explicitly convert to number from primitive
dmitrylavrenov Mar 24, 2025
01643bd
Use as string | number for primitive
dmitrylavrenov Mar 24, 2025
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
55 changes: 39 additions & 16 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ fc-mapping-sync = { git = "https://github.com/humanode-network/frontier", tag =
fc-rpc = { git = "https://github.com/humanode-network/frontier", tag = "locked/polkadot-v0.9.43-2025-03-22", default-features = false }
fc-rpc-core = { git = "https://github.com/humanode-network/frontier", tag = "locked/polkadot-v0.9.43-2025-03-22", default-features = false }
fc-storage = { git = "https://github.com/humanode-network/frontier", tag = "locked/polkadot-v0.9.43-2025-03-22", default-features = false }
fp-ethereum = { git = "https://github.com/humanode-network/frontier", tag = "locked/polkadot-v0.9.43-2025-03-22", default-features = false }
fp-evm = { git = "https://github.com/humanode-network/frontier", tag = "locked/polkadot-v0.9.43-2025-03-22", default-features = false }
fp-rpc = { git = "https://github.com/humanode-network/frontier", tag = "locked/polkadot-v0.9.43-2025-03-22", default-features = false }
fp-self-contained = { git = "https://github.com/humanode-network/frontier", tag = "locked/polkadot-v0.9.43-2025-03-22", default-features = false }
Expand Down
8 changes: 6 additions & 2 deletions crates/humanode-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ pallet-evm-balances = { path = "../pallet-evm-balances", default-features = fals
pallet-evm-system = { path = "../pallet-evm-system", default-features = false }
pallet-humanode-offences = { path = "../pallet-humanode-offences", default-features = false }
pallet-humanode-session = { path = "../pallet-humanode-session", default-features = false }
pallet-native-to-evm-swap = { path = "../pallet-native-to-evm-swap", default-features = false }
pallet-pot = { path = "../pallet-pot", default-features = false }
pallet-token-claims = { path = "../pallet-token-claims", default-features = false }
pallet-vesting = { path = "../pallet-vesting", default-features = false }
precompile-bioauth = { path = "../precompile-bioauth", default-features = false }
precompile-bls12381 = { path = "../precompile-bls12381", default-features = false }
precompile-currency-swap = { path = "../precompile-currency-swap", default-features = false }
precompile-evm-accounts-mapping = { path = "../precompile-evm-accounts-mapping", default-features = false }
precompile-evm-to-native-swap = { path = "../precompile-evm-to-native-swap", default-features = false }
precompile-native-currency = { path = "../precompile-native-currency", default-features = false }
precompile-utils = { path = "../precompile-utils", default-features = false }
primitives-auth-ticket = { path = "../primitives-auth-ticket", default-features = false }
Expand Down Expand Up @@ -131,6 +132,7 @@ runtime-benchmarks = [
"pallet-humanode-session/runtime-benchmarks",
"pallet-im-online/runtime-benchmarks",
"pallet-multisig/runtime-benchmarks",
"pallet-native-to-evm-swap/runtime-benchmarks",
"pallet-sudo/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
"pallet-token-claims/runtime-benchmarks",
Expand Down Expand Up @@ -190,6 +192,7 @@ std = [
"pallet-humanode-session/std",
"pallet-im-online/std",
"pallet-multisig/std",
"pallet-native-to-evm-swap/std",
"pallet-pot/std",
"pallet-session/std",
"pallet-sudo/std",
Expand All @@ -201,8 +204,8 @@ std = [
"pallet-vesting/std",
"precompile-bioauth/std",
"precompile-bls12381/std",
"precompile-currency-swap/std",
"precompile-evm-accounts-mapping/std",
"precompile-evm-to-native-swap/std",
"precompile-native-currency/std",
"precompile-utils/std",
"primitives-auth-ticket/std",
Expand Down Expand Up @@ -261,6 +264,7 @@ try-runtime = [
"pallet-humanode-session/try-runtime",
"pallet-im-online/try-runtime",
"pallet-multisig/try-runtime",
"pallet-native-to-evm-swap/try-runtime",
"pallet-pot/try-runtime",
"pallet-session/try-runtime",
"pallet-sudo/try-runtime",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ parameter_types! {
pub EvmToNativeSwapBridgePotAccountId: EvmAccountId = EvmToNativeSwapBridgePot::account_id();
}

pub struct EvmToNativeSwapConfig;

impl precompile_evm_to_native_swap::Config for EvmToNativeSwapConfig {
type AccountId = AccountId;
type EvmAccountId = EvmAccountId;
type NativeToken = Balances;
type EvmToken = EvmBalances;
type BalanceConverterEvmToNative = Identity;
type BridgePotNative = NativeToEvmSwapBridgePotAccountId;
type BridgePotEvm = EvmToNativeSwapBridgePotAccountId;
}

pub type NativeToEvmOneToOne =
bridge_pot_currency_swap::CurrencySwap<NativeToEvmOneToOneConfig, ExistenceRequired>;

Expand Down
24 changes: 10 additions & 14 deletions crates/humanode-runtime/src/frontier_precompiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ use precompile_bls12381::{
Bls12381G1Add, Bls12381G1Mul, Bls12381G1MultiExp, Bls12381G2Add, Bls12381G2Mul,
Bls12381G2MultiExp, Bls12381MapG1, Bls12381MapG2, Bls12381Pairing,
};
use precompile_currency_swap::CurrencySwap;
use precompile_evm_accounts_mapping::EvmAccountsMapping;
use precompile_evm_to_native_swap::EvmToNativeSwap;
use precompile_native_currency::NativeCurrency;
use precompile_utils::EvmData;
use sp_core::{H160, U256};
use sp_std::marker::PhantomData;

use crate::{currency_swap, AccountId, ConstU64, EvmAccountId};
use crate::{evm_swap, ConstU64};

/// A set of constant values used to indicate precompiles.
pub mod precompiles_constants {
Expand Down Expand Up @@ -74,8 +74,8 @@ pub mod precompiles_constants {
pub const EVM_ACCOUNTS_MAPPING: u64 = 2049;
/// `NativeCurrency` precompile constant.
pub const NATIVE_CURRENCY: u64 = 2050;
/// `CurrencySwap` precompile constant.
pub const CURRENCY_SWAP: u64 = 2304;
/// `EvmToNativeSwap` precompile constant.
pub const EVM_TO_NATIVE_SWAP: u64 = 2304;
}

use precompiles_constants::*;
Expand Down Expand Up @@ -117,7 +117,7 @@ where
BIOAUTH,
EVM_ACCOUNTS_MAPPING,
NATIVE_CURRENCY,
CURRENCY_SWAP
EVM_TO_NATIVE_SWAP,
]
.into_iter()
.map(hash)
Expand Down Expand Up @@ -172,15 +172,11 @@ where
a if a == hash(NATIVE_CURRENCY) => {
Some(NativeCurrency::<R, ConstU64<200>>::execute(handle))
}
a if a == hash(CURRENCY_SWAP) => {
Some(CurrencySwap::<
currency_swap::EvmToNativeOneToOne,
EvmAccountId,
AccountId,
// TODO(#697): implement proper dynamic gas cost estimation.
ConstU64<200>,
>::execute(handle))
}
a if a == hash(EVM_TO_NATIVE_SWAP) => Some(EvmToNativeSwap::<
evm_swap::EvmToNativeSwapConfig,
// TODO(#697): implement proper dynamic gas cost estimation.
ConstU64<200>,
>::execute(handle)),
// Fallback
_ => None,
}
Expand Down
22 changes: 17 additions & 5 deletions crates/humanode-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ use frontier_precompiles::{precompiles_constants, FrontierPrecompiles};
#[cfg(feature = "runtime-benchmarks")]
mod benchmarking;
pub mod constants;
mod currency_swap;
mod deauthentication_reason;
#[cfg(test)]
mod dev_utils;
mod display_moment;
pub mod eth_sig;
mod evm_swap;
mod find_author;
mod fixed_supply;
pub mod robonode;
Expand Down Expand Up @@ -625,13 +625,24 @@ impl pallet_evm_balances::Config for Runtime {
type Balance = Balance;
type ExistentialDeposit = ConstU128<1>;
type AccountStore = EvmSystem;
type DustRemoval = currency_swap::TreasuryPotProxy;
type DustRemoval = evm_swap::TreasuryPotProxy;
}

impl pallet_currency_swap::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type AccountIdTo = EvmAccountId;
type CurrencySwap = currency_swap::NativeToEvmOneToOne;
type CurrencySwap = evm_swap::NativeToEvmOneToOne;
type WeightInfo = ();
}

impl pallet_native_to_evm_swap::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type EvmAccountId = EvmAccountId;
type NativeToken = Balances;
type EvmToken = EvmBalances;
type BalanceConverterNativeToEvm = Identity;
type BridgePotNative = NativeToEvmSwapBridgePotAccountId;
type BridgePotEvm = EvmToNativeSwapBridgePotAccountId;
type WeightInfo = ();
}

Expand Down Expand Up @@ -661,7 +672,7 @@ impl pallet_evm::Config for Runtime {
type ChainId = EthereumChainId;
type BlockGasLimit = BlockGasLimit;
type OnChargeTransaction =
fixed_supply::EvmTransactionCharger<EvmBalances, currency_swap::FeesPotProxy>;
fixed_supply::EvmTransactionCharger<EvmBalances, evm_swap::FeesPotProxy>;
type OnCreate = ();
type FindAuthor = find_author::FindAuthorTruncated<
find_author::FindAuthorFromSession<find_author::FindAuthorBabe, BabeId>,
Expand Down Expand Up @@ -787,7 +798,7 @@ frame_support::parameter_types! {
frontier_precompiles::hash(precompiles_constants::BIOAUTH),
frontier_precompiles::hash(precompiles_constants::EVM_ACCOUNTS_MAPPING),
frontier_precompiles::hash(precompiles_constants::NATIVE_CURRENCY),
frontier_precompiles::hash(precompiles_constants::CURRENCY_SWAP),
frontier_precompiles::hash(precompiles_constants::EVM_TO_NATIVE_SWAP),
];
}

Expand Down Expand Up @@ -842,6 +853,7 @@ construct_runtime!(
EvmBalancesErc20Support: pallet_erc20_support = 37,
DummyPrecompilesCode: pallet_dummy_precompiles_code = 38,
HumanodeOffences: pallet_humanode_offences = 39,
NativeToEvmSwap: pallet_native_to_evm_swap = 40,
}
);

Expand Down
83 changes: 0 additions & 83 deletions crates/humanode-runtime/src/tests/currency_swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,86 +164,3 @@ fn currency_swap_native_call_works() {
);
})
}

/// This test verifies that the swap precompile call works in the happy path.
#[test]
fn currency_swap_precompile_call_works() {
// Build the state from the config.
new_test_ext_with().execute_with(move || {
let alice_balance_before = Balances::total_balance(&account_id("Alice"));
let native_to_evm_swap_bridge_pot_before =
Balances::total_balance(&NativeToEvmSwapBridgePot::account_id());
let alice_evm_balance_before = EvmBalances::total_balance(&evm_account_id("EvmAlice"));
let evm_to_native_swap_bridge_pot_before =
EvmBalances::total_balance(&EvmToNativeSwapBridgePot::account_id());
let fees_pot_balance_before = Balances::total_balance(&FeesPot::account_id());
let swap_balance: Balance = 1000;

// Prepare EVM call.
let input = EvmDataWriter::new_with_selector(precompile_currency_swap::Action::Swap)
.write(H256::from(account_id("Alice").as_ref()))
.build();

let expected_gas_usage: u64 = 21216 + 560;
let expected_fee: Balance =
u128::from(expected_gas_usage) * u128::try_from(*GAS_PRICE).unwrap();

// Invoke the function under test.
let config = <Runtime as pallet_evm::Config>::config();
let execinfo = <Runtime as pallet_evm::Config>::Runner::call(
evm_account_id("EvmAlice"),
*PRECOMPILE_ADDRESS,
input,
swap_balance.into(),
50_000, // a reasonable upper bound for tests
Some(*GAS_PRICE),
Some(*GAS_PRICE),
None,
Vec::new(),
true,
true,
None,
None,
config,
)
.unwrap();
assert_eq!(
execinfo.exit_reason,
fp_evm::ExitReason::Succeed(fp_evm::ExitSucceed::Returned)
);
assert_eq!(execinfo.used_gas.standard, expected_gas_usage.into());
assert_eq!(execinfo.value, EvmDataWriter::new().write(true).build());
assert_eq!(
execinfo.logs,
vec![LogsBuilder::new(*PRECOMPILE_ADDRESS).log3(
precompile_currency_swap::SELECTOR_LOG_SWAP,
evm_account_id("EvmAlice"),
H256::from(account_id("Alice").as_ref()),
EvmDataWriter::new().write(swap_balance).build(),
)]
);

// Assert state changes.
assert!(BalancedCurrencySwapBridgesInitializer::is_balanced().unwrap());
assert_eq!(
Balances::total_balance(&FeesPot::account_id()),
fees_pot_balance_before + expected_fee
);
assert_eq!(
Balances::total_balance(&account_id("Alice")),
alice_balance_before + swap_balance
);
assert_eq!(
Balances::total_balance(&NativeToEvmSwapBridgePot::account_id()),
native_to_evm_swap_bridge_pot_before - swap_balance - expected_fee
);
assert_eq!(
EvmBalances::total_balance(&evm_account_id("EvmAlice")),
alice_evm_balance_before - swap_balance - expected_fee
);
assert_eq!(
EvmBalances::total_balance(&EvmToNativeSwapBridgePot::account_id()),
evm_to_native_swap_bridge_pot_before + swap_balance + expected_fee
);
})
}
Loading
Loading