difftreelog
fix evm fees burn & test (#1079)
in: master
* fix evm fees burn & test * fix tips handling
3 files changed
js-packages/tests/creditFeesToTreasury.seqtest.tsdiffbeforeafterboth18import {ApiPromise} from '@polkadot/api';18import {ApiPromise} from '@polkadot/api';19import {usingPlaygrounds, expect, itSub} from '@unique/test-utils/util.js';19import {usingPlaygrounds, expect, itSub} from '@unique/test-utils/util.js';20import type {u32} from '@polkadot/types-codec';20import type {u32} from '@polkadot/types-codec';21import { itEth } from '@unique/test-utils/eth/util.js';22import { ITransactionResult } from '@unique-nft/playgrounds/types';212322const TREASURY = '5EYCAe5ijiYfyeZ2JJCGq56LmPyNRAKzpG4QkoQkkQNB5e6Z';24const TREASURY = '5EYCAe5ijiYfyeZ2JJCGq56LmPyNRAKzpG4QkoQkkQNB5e6Z';23const saneMinimumFee = 0.05;25const saneMinimumFee = 0.05;164 expect(Math.abs(fee - expectedTransferFee)).to.be.lessThan(tolerance);166 expect(Math.abs(fee - expectedTransferFee)).to.be.lessThan(tolerance);165 });167 });168 169 itEth('Evm Transactions send fees to Treasury', async ({helper}) => {170 const value = helper.balance.getOneTokenNominal();171 const gasPrice = await helper.getWeb3().eth.getGasPrice();172 let result = null;173 174 const lambda = async () => {175 result = await helper.executeExtrinsic(alice, 'api.tx.evm.call', [176 helper.address.substrateToEth(alice.address),177 helper.address.substrateToEth(bob.address),178 '0x',179 value,180 25_000,181 gasPrice,182 null,183 null,184 [],185 ]);186 };187 188 const totalPaid = await helper.arrange.calculcateFee({ Substrate: alice.address }, lambda);189 const evmFees = totalPaid - value;190 191 const treasuryDepoosited = (result as unknown as ITransactionResult).result.events192 .filter(({ event: { method, section } }) => section == 'treasury' && method == 'Deposit')193 .map(({ event: { data } }) => data[0].toJSON());194 195 const deposit = BigInt(treasuryDepoosited[0]);196 197 expect(deposit).to.be.equal(evmFees);198 });199 166});200});167201pallets/evm-transaction-payment/src/lib.rsdiffbeforeafterboth287 }287 }288288289 fn pay_priority_fee(tip: Self::LiquidityInfo) {289 fn pay_priority_fee(tip: Self::LiquidityInfo) {290 <pallet_evm::EVMCurrencyAdapter<C, OU> as OnChargeEVMTransaction<T>>::pay_priority_fee(291 tip.0,290 let Some(imbalance) = tip.0 else { return };292 )291 OU::on_unbalanced(imbalance)293 }292 }294}293}295294runtime/common/mod.rsdiffbeforeafterboth107107108type NegativeImbalance = <Balances as Currency<AccountId>>::NegativeImbalance;108type NegativeImbalance = <Balances as Currency<AccountId>>::NegativeImbalance;109109110pub struct DealWithFees;110pub(crate) type DealWithFees = Treasury;111impl OnUnbalanced<NegativeImbalance> for DealWithFees {112 fn on_unbalanceds<B>(mut fees_then_tips: impl Iterator<Item = NegativeImbalance>) {113 if let Some(fees) = fees_then_tips.next() {114 // for fees, 100% to treasury115 let mut split = fees.ration(100, 0);116 if let Some(tips) = fees_then_tips.next() {117 // for tips, if any, 100% to treasury118 tips.ration_merge_into(100, 0, &mut split);119 }120 Treasury::on_unbalanced(split.0);121 // Author::on_unbalanced(split.1);122 }123 }124}125111126pub struct RelayChainBlockNumberProvider<T>(sp_std::marker::PhantomData<T>);112pub struct RelayChainBlockNumberProvider<T>(sp_std::marker::PhantomData<T>);127113