Skip to content

Commit d143428

Browse files
authored
Merge pull request #23 from Giveth/staging
Fix the fee estimation difference
2 parents 21a2d3b + 577aff1 commit d143428

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

src/config/production.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ export const productionConfig: AppConfig = {
2727
givgarden: 5, // 5% for GIVgarden
2828
projects: 92, // 92% for projects
2929
},
30-
distributionBalanceThreshold: 100, // Balance threshold for 100% distribution
31-
distributionPercentage: 5, // Percentage for standard distribution
30+
distributionBalanceThreshold: 10, // Balance threshold for 100% distribution
31+
distributionPercentage: 1, // Percentage for standard distribution
3232
minBalanceForDistribution: 0.1, // Minimum balance for distribution
3333
},
3434
feeRefiller: {

src/services/donation-handler.service.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ export class DonationHandlerService {
230230
gasLimit: gasLimit,
231231
};
232232

233+
console.log(`Sending single donation transaction with gas limit: ${gasLimit.toString()}`);
233234
const result = await this.transactionService.sendTransaction(transactionRequest, walletInfo.hdPath);
234235

235236
console.log(`✅ Single donation transaction successful: ${result.transactionHash}`);
@@ -359,6 +360,7 @@ export class DonationHandlerService {
359360
gasLimit: gasLimit,
360361
};
361362

363+
console.log(`Sending batch donation transaction with gas limit: ${gasLimit.toString()}`);
362364
const result = await this.transactionService.sendTransaction(transactionRequest, walletInfo.hdPath);
363365

364366
console.log(`✅ Batch donation transaction successful: ${result.transactionHash}`);

src/services/transaction.service.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,21 @@ export class TransactionService {
117117

118118
console.log(`Estimated transaction fee: ${feeEstimate.estimatedFeeInPOL} POL`);
119119

120-
// Ensure wallet has sufficient balance for fees
120+
// Determine the actual gas limit that will be used
121+
const actualGasLimit = request.gasLimit || feeEstimate.gasLimit;
122+
123+
// If a custom gas limit is provided, recalculate the fee using the actual gas limit
124+
let actualTotalFee = feeEstimate.totalFee;
125+
if (request.gasLimit && request.gasLimit !== feeEstimate.gasLimit) {
126+
// Recalculate fee with the actual gas limit that will be used
127+
actualTotalFee = actualGasLimit * feeEstimate.gasPrice;
128+
console.log(`Custom gas limit provided. Recalculated fee: ${ethers.formatEther(actualTotalFee)} POL (Gas: ${actualGasLimit.toString()}, Price: ${ethers.formatUnits(feeEstimate.gasPrice, 'gwei')} gwei)`);
129+
}
130+
131+
// Ensure wallet has sufficient balance for fees using the actual fee
121132
const refillResult = await this.feeRefillerService.ensureSufficientBalance(
122133
request.from,
123-
feeEstimate.totalFee
134+
actualTotalFee
124135
);
125136

126137
if (!refillResult.success) {
@@ -132,7 +143,7 @@ export class TransactionService {
132143
to: request.to as `0x${string}`,
133144
data: request.data as `0x${string}`,
134145
value: request.value ? ethers.parseEther(request.value) : 0n,
135-
gasLimit: request.gasLimit || feeEstimate.gasLimit, // Use custom gas limit if provided
146+
gasLimit: actualGasLimit,
136147
gasPrice: feeEstimate.gasPrice,
137148
nonce: nonce // Explicit nonce to prevent conflicts
138149
};

0 commit comments

Comments
 (0)