Skip to content

Commit

Permalink
Merge pull request #749 from galacticcouncil/feat/adjust-fee
Browse files Browse the repository at this point in the history
feat: consistent transaction fees
  • Loading branch information
enthusiastmartin authored Feb 27, 2024
2 parents ea73330 + a87fc75 commit cb3441b
Show file tree
Hide file tree
Showing 38 changed files with 2,427 additions and 70 deletions.
34 changes: 32 additions & 2 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ members = [
'runtime/hydradx/src/evm/evm-utility/macro',
'pallets/referrals',
'pallets/evm-accounts',
'pallets/dynamic-evm-fee'
]

[workspace.dependencies]
Expand All @@ -62,6 +63,7 @@ pallet-currencies = { path = "pallets/currencies", default-features = false }
pallet-dca = { path = "pallets/dca", default-features = false }
pallet-duster = { path = "pallets/duster", default-features = false }
pallet-dynamic-fees = { path = "pallets/dynamic-fees", default-features = false }
pallet-dynamic-evm-fee = { path = "pallets/dynamic-evm-fee", default-features = false }
pallet-ema-oracle = { path = "pallets/ema-oracle", default-features = false }
pallet-genesis-history = { path = "pallets/genesis-history", default-features = false }
pallet-liquidity-mining = { path = "pallets/liquidity-mining", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ release: build checksum
all: clippy build-benchmarks test-benchmarks test build checksum

chopstics: release
npx @acala-network/chopsticks xcm --parachain=launch-configs/chopsticks/hydradx.yml --parachain=launch-configs/chopsticks/assethub.yml
npx @acala-network/chopsticks xcm --parachain=launch-configs/chopsticks/hydradx.yml --parachain=launch-configs/chopsticks/assethub.yml
7 changes: 5 additions & 2 deletions integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "runtime-integration-tests"
version = "1.19.1"
version = "1.19.2"
description = "Integration tests"
authors = ["GalacticCouncil"]
edition = "2021"
Expand Down Expand Up @@ -34,6 +34,7 @@ pallet-relaychain-info = { workspace = true }
pallet-route-executor = { workspace = true}
pallet-dca = { workspace = true}
pallet-dynamic-fees = { workspace = true }
pallet-dynamic-evm-fee = { workspace = true }
pallet-staking = { workspace = true}
pallet-lbp = { workspace = true}
pallet-xyk = { workspace = true}
Expand Down Expand Up @@ -127,8 +128,9 @@ polkadot-runtime = { workspace = true }

[dev-dependencies]
pretty_assertions = "1.2.1"
pallet-relaychain-info = { workspace = true }
xcm-emulator = { workspace = true }

test-utils = { workspace = true }
[features]
default = ["std"]
std = [
Expand Down Expand Up @@ -194,6 +196,7 @@ std = [
"hydradx-runtime/std",
"pallet-staking/std",
"scraper/std",
"pallet-dynamic-evm-fee/std"
]

# we don't include integration tests when benchmarking feature is enabled
Expand Down
19 changes: 7 additions & 12 deletions integration-tests/src/cross_chain_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,13 @@ fn hydra_should_receive_asset_when_transferred_from_polkadot_relay_chain() {
);
});

let fees = 401884032343;
Hydra::execute_with(|| {
let fee = hydradx_runtime::Tokens::free_balance(1, &hydradx_runtime::Treasury::account_id());
assert!(fee > 0, "Fees is not sent to treasury");

assert_eq!(
hydradx_runtime::Tokens::free_balance(1, &AccountId::from(BOB)),
BOB_INITIAL_NATIVE_BALANCE + 300 * UNITS - fees
);
assert_eq!(
hydradx_runtime::Tokens::free_balance(1, &hydradx_runtime::Treasury::account_id()),
fees
BOB_INITIAL_NATIVE_BALANCE + 300 * UNITS - fee
);
});
}
Expand Down Expand Up @@ -141,16 +139,13 @@ fn hydra_should_receive_asset_when_transferred_from_acala() {
);
});

let fee = 321507225875;
Hydra::execute_with(|| {
let fee = hydradx_runtime::Tokens::free_balance(ACA, &hydradx_runtime::Treasury::account_id());
assert!(fee > 0, "Fees is not sent to treasury");
assert_eq!(
hydradx_runtime::Tokens::free_balance(ACA, &AccountId::from(BOB)),
30 * UNITS - fee
);
assert_eq!(
hydradx_runtime::Tokens::free_balance(ACA, &hydradx_runtime::Treasury::account_id()),
fee // fees should go to treasury
);
});
}

Expand Down Expand Up @@ -331,7 +326,7 @@ fn claim_trapped_asset_should_work() {
Hydra::execute_with(|| {
assert_eq!(
hydradx_runtime::Tokens::free_balance(1, &AccountId::from(BOB)),
1000 * UNITS + 29_758_869_580_594
1_029_939_717_395_149 //1000 * UNITS + 30 * UNITS - fee
);

let origin = MultiLocation::new(1, X1(Parachain(ACALA_PARA_ID)));
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/src/dca.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ mod omnipool {
run_to_block(11, 40);

//Assert
assert_balance!(ALICE.into(), DAI, ALICE_INITIAL_DAI_BALANCE + 600 * UNITS);
assert_balance!(ALICE.into(), DAI, ALICE_INITIAL_DAI_BALANCE + 700 * UNITS);

//Because the last trade is not enough for a whole trade, it is returned to the user
let amount_in = 140_421_094_431_120;
Expand Down
29 changes: 17 additions & 12 deletions integration-tests/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use sp_runtime::{traits::SignedExtension, FixedU128, Permill};
use std::borrow::Cow;
use xcm_emulator::TestExt;

const TREASURY_ACCOUNT_INIT_BALANCE: Balance = 1000 * UNITS;
pub const TREASURY_ACCOUNT_INIT_BALANCE: Balance = 1000 * UNITS;

mod account_conversion {
use super::*;
Expand Down Expand Up @@ -244,8 +244,8 @@ mod account_conversion {
let fee_raw = hydradx_runtime::TransactionPayment::compute_fee_details(len, &info, 0);
let fee = fee_raw.final_fee();

// simple test that the fee is approximately 10 HDX
assert!(fee / UNITS == 10);
// simple test that the fee is approximately 10/4 HDX (it was originally 10 HDX, but we divided the fee by 4 in the config)
assert_eq!(fee / UNITS, 10 / 4);
});
}

Expand Down Expand Up @@ -1174,12 +1174,16 @@ fn dispatch_should_respect_call_filter() {
);
});
}

#[test]
fn compare_fee_between_evm_and_native_omnipool_calls() {
TestNet::reset();

Hydra::execute_with(|| {
//Set up to idle state where the chain is not utilized at all
pallet_transaction_payment::pallet::NextFeeMultiplier::<hydradx_runtime::Runtime>::put(
hydradx_runtime::MinimumMultiplier::get(),
);

//Set alice with as fee currency and fund it
assert_ok!(hydradx_runtime::MultiTransactionPayment::set_currency(
hydradx_runtime::RuntimeOrigin::signed(ALICE.into()),
Expand All @@ -1189,7 +1193,7 @@ fn compare_fee_between_evm_and_native_omnipool_calls() {
hydradx_runtime::RuntimeOrigin::root(),
ALICE.into(),
WETH,
100 * UNITS as i128,
1000000000 * UNITS as i128,
));

//Fund evm account with HDX to dispatch omnipool sell
Expand All @@ -1214,6 +1218,8 @@ fn compare_fee_between_evm_and_native_omnipool_calls() {
});

let gas_limit = 1000000;
let gas_price = hydradx_runtime::DynamicEvmFee::min_gas_price();

//Execute omnipool via EVM
assert_ok!(EVM::call(
evm_signed_origin(evm_address()),
Expand All @@ -1222,21 +1228,20 @@ fn compare_fee_between_evm_and_native_omnipool_calls() {
omni_sell.encode(),
U256::from(0),
gas_limit,
gas_price(),
gas_price.0 * 10,
None,
Some(U256::zero()),
[].into(),
));

//Pre dispatch the native omnipool call - so withdrawring only the fees for the execution
let info = omni_sell.get_dispatch_info();
let len: usize = 1;
assert_ok!(
pallet_transaction_payment::ChargeTransactionPayment::<hydradx_runtime::Runtime>::from(0).pre_dispatch(
&AccountId::from(ALICE),
&omni_sell,
&info,
len,
crate::fee_calculation::SWAP_ENCODED_LEN as usize,
)
);

Expand All @@ -1260,7 +1265,7 @@ fn compare_fee_between_evm_and_native_omnipool_calls() {
})
}

fn init_omnipool_with_oracle_for_block_10() {
pub fn init_omnipool_with_oracle_for_block_10() {
init_omnipol();
//do_trade_to_populate_oracle(DAI, HDX, UNITS);
set_relaychain_block_number(10);
Expand Down Expand Up @@ -1313,10 +1318,10 @@ pub fn init_omnipol() {

// TODO: test that we charge approximatelly same fee on evm as with extrinsics directly

const DISPATCH_ADDR: H160 = addr(1025);
pub const DISPATCH_ADDR: H160 = addr(1025);

fn gas_price() -> U256 {
U256::from(8 * 10_u128.pow(7))
pub fn gas_price() -> U256 {
U256::from(hydradx_runtime::evm::DEFAULT_BASE_FEE_PER_GAS)
}

fn create_dispatch_handle(data: Vec<u8>) -> MockHandle {
Expand Down
Loading

0 comments on commit cb3441b

Please sign in to comment.