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

Apply FeesTreasuryProportion to Substate-based txs tips and Ethereum-based transactions fees. #3043

Merged
merged 27 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b623e35
fix: FeesTreasuryProportion is only applied to substrate based tx only
TarekkMA Nov 12, 2024
28712c6
refactor: split test into 2 files
TarekkMA Nov 12, 2024
8d477f9
test: test 0% FeesTreasuryProportion
TarekkMA Nov 12, 2024
5e8f02b
fix
TarekkMA Nov 12, 2024
9b7c1f2
fix
TarekkMA Nov 12, 2024
99245d6
fix
TarekkMA Nov 12, 2024
6f1a121
fix
TarekkMA Nov 12, 2024
4c35eb6
Update test/suites/dev/moonbase/test-parameters/test-parameters-rando…
TarekkMA Nov 13, 2024
7f17edf
Update test/suites/dev/moonbase/test-parameters/test-parameters-rando…
TarekkMA Nov 13, 2024
2841fc9
add substrate based tests
TarekkMA Nov 13, 2024
a4493bf
fix
TarekkMA Nov 13, 2024
900f1f0
fix
TarekkMA Nov 13, 2024
07d1cde
test: test for different cases
TarekkMA Nov 13, 2024
536b329
test: add extra check
TarekkMA Nov 13, 2024
30b46cd
fix: test calculation
TarekkMA Nov 13, 2024
6eade28
fix: test calculation
TarekkMA Nov 14, 2024
ef2d73e
style: fix formatting
TarekkMA Nov 14, 2024
f63a803
fix: fix calculation for moonriver and moonbeam
TarekkMA Nov 14, 2024
0531166
Revert "fix: fix calculation for moonriver and moonbeam"
TarekkMA Nov 14, 2024
cf1276e
Revert "style: fix formatting"
TarekkMA Nov 14, 2024
6140e3c
Revert "fix: test calculation"
TarekkMA Nov 14, 2024
8c01ec5
fix: fix calculation
TarekkMA Nov 14, 2024
d549395
Merge branch 'master' into tarekkma/fix-fee-treasury-propotion
TarekkMA Nov 14, 2024
76f1e24
test: add with tip case
TarekkMA Nov 14, 2024
59ba104
test: fix calc
TarekkMA Nov 14, 2024
1c33c7a
test: fix calc
TarekkMA Nov 14, 2024
89591e6
test: fix calc
TarekkMA Nov 14, 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
12 changes: 8 additions & 4 deletions runtime/moonbase/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,9 @@ where
mut fees_then_tips: impl Iterator<Item = Credit<R::AccountId, pallet_balances::Pallet<R>>>,
) {
if let Some(fees) = fees_then_tips.next() {
let treasury_perbill =
let treasury_proportion =
runtime_params::dynamic_params::runtime_config::FeesTreasuryProportion::get();
let treasury_part = treasury_perbill.deconstruct();
let treasury_part = treasury_proportion.deconstruct();
let burn_part = Perbill::one().deconstruct() - treasury_part;
let (_, to_treasury) = fees.ration(burn_part, treasury_part);
// Balances pallet automatically burns dropped Credits by decreasing
Expand All @@ -378,7 +378,7 @@ where
// handle tip if there is one
if let Some(tip) = fees_then_tips.next() {
// for now we use the same burn/treasury strategy used for regular fees
let (_, to_treasury) = tip.ration(80, 20);
let (_, to_treasury) = tip.ration(burn_part, treasury_part);
ResolveTo::<TreasuryAccountId<R>, pallet_balances::Pallet<R>>::on_unbalanced(
to_treasury,
);
Expand All @@ -391,7 +391,11 @@ where
fn on_nonzero_unbalanced(amount: Credit<R::AccountId, pallet_balances::Pallet<R>>) {
// Balances pallet automatically burns dropped Credits by decreasing
// total_supply accordingly
let (_, to_treasury) = amount.ration(80, 20);
let treasury_proportion =
runtime_params::dynamic_params::runtime_config::FeesTreasuryProportion::get();
let treasury_part = treasury_proportion.deconstruct();
let burn_part = Perbill::one().deconstruct() - treasury_part;
let (_, to_treasury) = amount.ration(burn_part, treasury_part);
ResolveTo::<TreasuryAccountId<R>, pallet_balances::Pallet<R>>::on_unbalanced(to_treasury);
}
}
Expand Down
12 changes: 8 additions & 4 deletions runtime/moonbeam/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,9 @@ where
mut fees_then_tips: impl Iterator<Item = Credit<R::AccountId, pallet_balances::Pallet<R>>>,
) {
if let Some(fees) = fees_then_tips.next() {
let treasury_perbill =
let treasury_proportion =
runtime_params::dynamic_params::runtime_config::FeesTreasuryProportion::get();
let treasury_part = treasury_perbill.deconstruct();
let treasury_part = treasury_proportion.deconstruct();
let burn_part = Perbill::one().deconstruct() - treasury_part;
let (_, to_treasury) = fees.ration(burn_part, treasury_part);
// Balances pallet automatically burns dropped Credits by decreasing
Expand All @@ -366,7 +366,7 @@ where
// handle tip if there is one
if let Some(tip) = fees_then_tips.next() {
// for now we use the same burn/treasury strategy used for regular fees
let (_, to_treasury) = tip.ration(80, 20);
let (_, to_treasury) = tip.ration(burn_part, treasury_part);
ResolveTo::<TreasuryAccountId<R>, pallet_balances::Pallet<R>>::on_unbalanced(
to_treasury,
);
Expand All @@ -379,7 +379,11 @@ where
fn on_nonzero_unbalanced(amount: Credit<R::AccountId, pallet_balances::Pallet<R>>) {
// Balances pallet automatically burns dropped Credits by decreasing
// total_supply accordingly
let (_, to_treasury) = amount.ration(80, 20);
let treasury_proportion =
runtime_params::dynamic_params::runtime_config::FeesTreasuryProportion::get();
let treasury_part = treasury_proportion.deconstruct();
let burn_part = Perbill::one().deconstruct() - treasury_part;
let (_, to_treasury) = amount.ration(burn_part, treasury_part);
ResolveTo::<TreasuryAccountId<R>, pallet_balances::Pallet<R>>::on_unbalanced(to_treasury);
}
}
Expand Down
12 changes: 8 additions & 4 deletions runtime/moonriver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,9 @@ where
mut fees_then_tips: impl Iterator<Item = Credit<R::AccountId, pallet_balances::Pallet<R>>>,
) {
if let Some(fees) = fees_then_tips.next() {
let treasury_perbill =
let treasury_proportion =
runtime_params::dynamic_params::runtime_config::FeesTreasuryProportion::get();
let treasury_part = treasury_perbill.deconstruct();
let treasury_part = treasury_proportion.deconstruct();
let burn_part = Perbill::one().deconstruct() - treasury_part;
let (_, to_treasury) = fees.ration(burn_part, treasury_part);
// Balances pallet automatically burns dropped Credits by decreasing
Expand All @@ -368,7 +368,7 @@ where
// handle tip if there is one
if let Some(tip) = fees_then_tips.next() {
// for now we use the same burn/treasury strategy used for regular fees
let (_, to_treasury) = tip.ration(80, 20);
let (_, to_treasury) = tip.ration(burn_part, treasury_part);
ResolveTo::<TreasuryAccountId<R>, pallet_balances::Pallet<R>>::on_unbalanced(
to_treasury,
);
Expand All @@ -381,7 +381,11 @@ where
fn on_nonzero_unbalanced(amount: Credit<R::AccountId, pallet_balances::Pallet<R>>) {
// Balances pallet automatically burns dropped Credits by decreasing
// total_supply accordingly
let (_, to_treasury) = amount.ration(80, 20);
let treasury_proportion =
runtime_params::dynamic_params::runtime_config::FeesTreasuryProportion::get();
let treasury_part = treasury_proportion.deconstruct();
let burn_part = Perbill::one().deconstruct() - treasury_part;
let (_, to_treasury) = amount.ration(burn_part, treasury_part);
ResolveTo::<TreasuryAccountId<R>, pallet_balances::Pallet<R>>::on_unbalanced(to_treasury);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { describeSuite, expect } from "@moonwall/cli";
import { alith } from "@moonwall/util";
import { parameterType, UNIT } from "./test-parameters";

describeSuite({
id: "DTemp02",
title: "Parameters - Pallet Randomness",
foundationMethods: "dev",
testCases: ({ it, context, log }) => {
it({
id: `T01 - PalletRandomness - Deposit - CustomTests`,
title: "Deposit parameter should only be accepted in bounds",
test: async () => {
const MIN = 1n * UNIT;
const MAX = 1000n * UNIT;

// used as an acceptable value
const AVG = (MIN + MAX) / 2n;

const param1 = parameterType(context, "PalletRandomness", "Deposit", MIN - 1n);
try {
await context.createBlock(
context
.polkadotJs()
.tx.sudo.sudo(context.polkadotJs().tx.parameters.setParameter(param1.toU8a()))
.signAsync(alith),
{ allowFailures: false }
);
expect.fail("An extrinsic should not be created, since the parameter is invalid");
} catch (error) {
expect(error.toString().toLowerCase()).to.contain("value out of bounds");
}

const param2 = parameterType(context, "PalletRandomness", "Deposit", MAX + 1n);
try {
await context.createBlock(
context
.polkadotJs()
.tx.sudo.sudo(context.polkadotJs().tx.parameters.setParameter(param2.toU8a()))
.signAsync(alith),
{ allowFailures: false }
);
expect.fail("An extrinsic should not be created, since the parameter is invalid");
} catch (error) {
expect(error.toString().toLowerCase()).to.contain("value out of bounds");
}

const param3 = parameterType(context, "PalletRandomness", "Deposit", AVG);
const res3 = await context.createBlock(
context
.polkadotJs()
.tx.sudo.sudo(context.polkadotJs().tx.parameters.setParameter(param3.toU8a()))
.signAsync(alith),
{ allowFailures: false }
);
expect(
res3.result?.successful,
"An extrinsic should be created, since the parameter is valid"
).to.be.true;
},
});
},
});
Loading
Loading