Skip to content
This repository was archived by the owner on Feb 8, 2025. It is now read-only.

Commit 5ff6b9e

Browse files
committed
fix(api): use max paymaster eth fees when calculatiing max fees
1 parent a1fe860 commit 5ff6b9e

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

api/src/features/paymasters/paymasters.service.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ export class PaymastersService {
8181
maxPaymasterEthFees,
8282
true,
8383
);
84-
8584
const maxPaymasterEthFee = totalPaymasterEthFees(maxPaymasterEthFees);
85+
const maxEthFees = maxNetworkEthFee.plus(maxPaymasterEthFee).minus(ethDiscount);
86+
8687
const signedData: PaymasterSignedData = {
8788
// User signs the maxPaymasterEthFee so can't be changed; (maxPaymasteEthFee - paymasterEthFee) is included in the discount
8889
paymasterFee: asFp(maxPaymasterEthFee, ETH),
@@ -101,9 +102,6 @@ export class PaymastersService {
101102
),
102103
);
103104

104-
const paymasterEthFee = totalPaymasterEthFees(paymasterEthFees);
105-
const maxEthFees = maxNetworkEthFee.plus(paymasterEthFee).minus(ethDiscount);
106-
107105
const tokenPrice = await this.prices.price(asUAddress(feeToken, chain));
108106
const maxTokenFees = maxEthFees.div(tokenPrice.eth);
109107
await this.prices.updatePriceFeedsIfNecessary(chain, [ETH.pythUsdPriceId, tokenPrice.id]);
@@ -200,7 +198,10 @@ export class PaymastersService {
200198
);
201199

202200
// Provide a discount if currentPaymasterEthFee < maxPaymasterEthFee; ensuring the user benefits in case of feeToken:eth price change etc.
203-
const paymasterEthFees = await this.finalPaymasterEthFees(maxPaymasterEthFees, { account });
201+
const paymasterEthFees = await this.finalPaymasterEthFees(maxPaymasterEthFees, {
202+
account,
203+
use,
204+
});
204205
const paymasterEthFee = totalPaymasterEthFees(paymasterEthFees);
205206
const paymasterEthFeeDiscount =
206207
totalPaymasterEthFees(maxPaymasterEthFees).minus(paymasterEthFee);
@@ -238,9 +239,9 @@ export class PaymastersService {
238239

239240
private async finalPaymasterEthFees(
240241
max: PaymasterFeeParts,
241-
params: Omit<PaymasterEthFeeParams, 'use'>,
242+
params: PaymasterEthFeeParams,
242243
): Promise<PaymasterFeeParts> {
243-
const current = await this.paymasterEthFees({ ...params, use: true });
244+
const current = await this.paymasterEthFees(params);
244245

245246
return {
246247
activation: Decimal.min(max.activation, current.activation),

0 commit comments

Comments
 (0)