Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: consistent transaction fees #749

Merged
merged 69 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from 47 commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
88aa891
add ddos scripts
dmoka Jan 12, 2024
882ce5a
fix init script to read the assets from good directory
dmoka Jan 12, 2024
7bdc1f2
remove invalid tx from init
dmoka Jan 12, 2024
87ff951
fix print out
dmoka Jan 12, 2024
8f74180
improve logging for ddos tx script
dmoka Jan 18, 2024
37f1dee
add tests for fees
dmoka Jan 18, 2024
3961f4b
reduce fee by 2/3 and make the fee growth faster in full chain conges…
dmoka Jan 23, 2024
0b413b7
change port for zombienet
dmoka Jan 23, 2024
50230b1
adjust fee tests
dmoka Jan 23, 2024
4828449
make transaction script run for ~1h
dmoka Jan 23, 2024
aad910e
change multiplers to have 500HDX as max fee and reaching in 1h
dmoka Jan 23, 2024
fda2c58
fix tests as fee has been decreased
dmoka Jan 23, 2024
ad0c5d6
merge master to feat/adjust-fee
dmoka Jan 24, 2024
639d7b0
adjust constants as weight changed due to polkadot v1.
dmoka Jan 24, 2024
df86c31
reduce evm fees by 2/3 just like we did for normal substrate extrinsics
dmoka Jan 24, 2024
272ee9d
add evm tests and base implementation od dynamic evm fee pallet
dmoka Feb 5, 2024
af188e8
fix evm fee calc by not using float as it is only good for std
dmoka Feb 5, 2024
1c6f334
remove done todo
dmoka Feb 5, 2024
19c02a0
readjust substrate and evm fees (based on current market prices) with…
dmoka Feb 6, 2024
feb02ac
cleaning up
dmoka Feb 6, 2024
b7fb154
refactoring
dmoka Feb 6, 2024
e5a0569
refactoring in tests
dmoka Feb 6, 2024
3bbf22b
add benchmarking for dynamic evm fee pallet
dmoka Feb 6, 2024
0524d92
removed done todo comment
dmoka Feb 6, 2024
1373db7
remove not needed comment
dmoka Feb 6, 2024
9e07d03
fix dca tests as fee were too low and had BelowMinimum issue wrt ed
dmoka Feb 6, 2024
eaba42d
cleaning up
dmoka Feb 7, 2024
16c2db3
fix warning message
dmoka Feb 7, 2024
941cf0f
add missing test
dmoka Feb 7, 2024
f3fb177
added scripts for evm hack
dmoka Feb 7, 2024
112acfb
remove duplication for call length
dmoka Feb 7, 2024
863312a
clean up in scripts
dmoka Feb 8, 2024
21ab100
clean up in tests
dmoka Feb 8, 2024
47cb09e
add documnetation for dynamic evm fee pallet
dmoka Feb 8, 2024
033a4f6
cleaning up
dmoka Feb 8, 2024
33dbdb1
merge master to feat/adjust-fee
dmoka Feb 8, 2024
4935c10
bump versions
dmoka Feb 8, 2024
db6c455
fix formatting in doc
dmoka Feb 8, 2024
19ebdf2
make clippy happy
dmoka Feb 9, 2024
6d35ebd
make clippy happy
dmoka Feb 9, 2024
71d6890
make checksum supports mac os
mrq1911 Feb 20, 2024
5ec1d49
refactor and suggestion
enthusiastmartin Feb 20, 2024
65b0254
fix tests as we corrected the price difference change calculation
dmoka Feb 21, 2024
be4709b
made unsafe operations safe
dmoka Feb 21, 2024
0fae3fd
renamings
dmoka Feb 21, 2024
2bc0aee
remove custom trait as we can solve it with a normat Get trait
dmoka Feb 21, 2024
ff6c4b5
renaming
dmoka Feb 21, 2024
43b8f76
Merge remote-tracking branch 'origin/master' into feat/adjust-fee
dmoka Feb 22, 2024
3f5d0eb
update cargo
dmoka Feb 22, 2024
6fcb43d
fix fee test for account binding as fee has been cut by 5/6
dmoka Feb 22, 2024
994b9be
update eth hdx price
dmoka Feb 22, 2024
20d2fce
bump main version
dmoka Feb 22, 2024
1027e14
Merge remote-tracking branch 'origin/master' into feat/adjust-fee
dmoka Feb 22, 2024
42a2a2f
update lock file
dmoka Feb 22, 2024
9c97b79
revert back makefile as we prolly made a mistake when merging
dmoka Feb 22, 2024
3d41fd6
retune fees as the price changed so we set a new reference
dmoka Feb 22, 2024
fd96ce0
add failing test for max evm fee - WIP as does not work yet
dmoka Feb 22, 2024
0a65440
fix and simplify evm scaling based on price
dmoka Feb 23, 2024
d76ae43
introduce configs for min and max base fee per gas so we can safely c…
dmoka Feb 23, 2024
4bd8fa8
make benchmark compile
dmoka Feb 23, 2024
59598ed
used checked for rational calc
dmoka Feb 23, 2024
37f585e
fix compilation
dmoka Feb 23, 2024
153924c
rebenchmark pallet
dmoka Feb 23, 2024
cc7af89
fix doc
dmoka Feb 23, 2024
d3bc8c5
make clippy happy
dmoka Feb 23, 2024
07c5fef
fix namings
dmoka Feb 26, 2024
bcd9425
adjust error message
dmoka Feb 26, 2024
d712716
merge master to feat/adjust-fee
dmoka Feb 26, 2024
a87fc75
bump runtime version
dmoka Feb 26, 2024
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
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 @@ -38,6 +38,7 @@ members = [
'pallets/democracy',
'runtime/hydradx/src/evm/evm-utility/macro',
'pallets/referrals',
'pallets/dynamic-evm-fee'
]

[workspace.dependencies]
Expand All @@ -60,6 +61,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
11 changes: 9 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
SHASUM = shasum -a 256
else
SHASUM = sha256sum
endif

.PHONY: build
build:
cargo build --release --locked
Expand Down Expand Up @@ -56,9 +63,9 @@ docker:
docker build -t hydra-dx .

checksum:
sha256sum target/release/hydradx > target/release/hydradx.sha256
$(SHASUM) target/release/hydradx > target/release/hydradx.sha256
cp target/release/wbuild/hydradx-runtime/hydradx_runtime.compact.compressed.wasm target/release/
sha256sum target/release/hydradx_runtime.compact.compressed.wasm > target/release/hydradx_runtime.compact.compressed.wasm.sha256
$(SHASUM) target/release/hydradx_runtime.compact.compressed.wasm > target/release/hydradx_runtime.compact.compressed.wasm.sha256

release: build checksum

Expand Down
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.17.2"
version = "1.17.3"
description = "Integration tests"
authors = ["GalacticCouncil"]
edition = "2021"
Expand Down Expand Up @@ -35,6 +35,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]
hex-literal = "0.4.1"
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
14 changes: 7 additions & 7 deletions integration-tests/src/cross_chain_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,16 @@ fn hydra_should_receive_asset_when_transferred_from_polkadot_relay_chain() {
);
});

let fees = 401884032343;
let fees = 66980672057;
Hydra::execute_with(|| {
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
);
assert_eq!(
hydradx_runtime::Tokens::free_balance(1, &AccountId::from(BOB)),
BOB_INITIAL_NATIVE_BALANCE + 300 * UNITS - fees
);
});
}

Expand Down Expand Up @@ -143,7 +143,7 @@ fn hydra_should_receive_asset_when_transferred_from_acala() {
);
});

let fee = 321507225875;
let fee = 53584537646;
Hydra::execute_with(|| {
assert_eq!(
hydradx_runtime::Tokens::free_balance(ACA, &AccountId::from(BOB)),
Expand Down Expand Up @@ -336,7 +336,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_959_811_596_766 //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 @@ -443,7 +443,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
25 changes: 15 additions & 10 deletions integration-tests/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,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 currency_precompile {
use super::*;
Expand Down Expand Up @@ -604,12 +604,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 @@ -619,7 +623,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 @@ -644,6 +648,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 @@ -652,21 +658,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 @@ -690,7 +695,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 @@ -743,10 +748,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
Loading