git.delta.rocks / unique-network / refs/commits / 347f218123fd

difftreelog

fix evm fees burn & test (#1079)

Pavel Orlov2024-06-24parent: #1e1dae4.patch.diff
in: master
* fix evm fees burn & test

* fix tips handling

3 files changed

modifiedjs-packages/tests/creditFeesToTreasury.seqtest.tsdiffbeforeafterboth
--- a/js-packages/tests/creditFeesToTreasury.seqtest.ts
+++ b/js-packages/tests/creditFeesToTreasury.seqtest.ts
@@ -18,6 +18,8 @@
 import {ApiPromise} from '@polkadot/api';
 import {usingPlaygrounds, expect, itSub} from '@unique/test-utils/util.js';
 import type {u32} from '@polkadot/types-codec';
+import { itEth } from '@unique/test-utils/eth/util.js';
+import { ITransactionResult } from '@unique-nft/playgrounds/types';
 
 const TREASURY = '5EYCAe5ijiYfyeZ2JJCGq56LmPyNRAKzpG4QkoQkkQNB5e6Z';
 const saneMinimumFee = 0.05;
@@ -163,4 +165,36 @@
 
     expect(Math.abs(fee - expectedTransferFee)).to.be.lessThan(tolerance);
   });
+   
+  itEth('Evm Transactions send fees to Treasury', async ({helper}) => {
+    const value = helper.balance.getOneTokenNominal();
+    const gasPrice = await helper.getWeb3().eth.getGasPrice();
+    let result = null;
+    
+    const lambda = async () => {
+      result = await helper.executeExtrinsic(alice, 'api.tx.evm.call', [
+        helper.address.substrateToEth(alice.address),
+        helper.address.substrateToEth(bob.address),
+        '0x',
+        value,
+        25_000,
+        gasPrice,
+        null,
+        null,
+        [],
+      ]);
+    };
+    
+    const totalPaid = await helper.arrange.calculcateFee({ Substrate: alice.address }, lambda);
+    const evmFees = totalPaid - value;
+    
+    const treasuryDepoosited = (result as unknown as ITransactionResult).result.events
+      .filter(({ event: { method, section } }) => section == 'treasury' && method == 'Deposit')
+      .map(({ event: { data } }) => data[0].toJSON());
+    
+    const deposit = BigInt(treasuryDepoosited[0]);
+  
+    expect(deposit).to.be.equal(evmFees);
+  });
+  
 });
modifiedpallets/evm-transaction-payment/src/lib.rsdiffbeforeafterboth
--- a/pallets/evm-transaction-payment/src/lib.rs
+++ b/pallets/evm-transaction-payment/src/lib.rs
@@ -287,8 +287,7 @@
 	}
 
 	fn pay_priority_fee(tip: Self::LiquidityInfo) {
-		<pallet_evm::EVMCurrencyAdapter<C, OU> as OnChargeEVMTransaction<T>>::pay_priority_fee(
-			tip.0,
-		)
+		let Some(imbalance) = tip.0 else { return };
+		OU::on_unbalanced(imbalance)
 	}
 }
modifiedruntime/common/mod.rsdiffbeforeafterboth
107107
108type NegativeImbalance = <Balances as Currency<AccountId>>::NegativeImbalance;108type NegativeImbalance = <Balances as Currency<AccountId>>::NegativeImbalance;
109109
110pub 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 treasury
115 let mut split = fees.ration(100, 0);
116 if let Some(tips) = fees_then_tips.next() {
117 // for tips, if any, 100% to treasury
118 tips.ration_merge_into(100, 0, &mut split);
119 }
120 Treasury::on_unbalanced(split.0);
121 // Author::on_unbalanced(split.1);
122 }
123 }
124}
125111
126pub struct RelayChainBlockNumberProvider<T>(sp_std::marker::PhantomData<T>);112pub struct RelayChainBlockNumberProvider<T>(sp_std::marker::PhantomData<T>);
127113