Skip to content

Commit 58ace8b

Browse files
committed
Fix gas fee calculation
1 parent 9ab5191 commit 58ace8b

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

.vscode/settings.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"editor.defaultFormatter": "esbenp.prettier-vscode",
33
"editor.formatOnSave": true,
44
"editor.tabSize": 2,
5-
"typescript.tsdk": "node_modules/typescript/lib",
65
"[typescript]": {
76
"editor.defaultFormatter": "esbenp.prettier-vscode"
87
}

packages/sdk/src/sdkBase.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,14 @@ export class NxtpSdkBase {
580580
relayerFee,
581581
});
582582

583+
this.logger.info("Calculated fees", requestContext, methodContext, {
584+
receiverAmount,
585+
totalFee,
586+
metaTxRelayerFee,
587+
routerFee,
588+
gasFee,
589+
});
590+
583591
if (BigNumber.from(receiverAmount).lt(0)) {
584592
throw new NotEnoughAmount({ receiverAmount, totalFee, routerFee, gasFee, relayerFee: metaTxRelayerFee });
585593
}

packages/txservice/src/chainreader.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,15 @@ export class ChainReader {
298298
requestContext,
299299
),
300300
]);
301+
const total = senderFulfillGasFee.add(receiverPrepareGasFee);
301302

302-
return senderFulfillGasFee.add(receiverPrepareGasFee);
303+
this.logger.info("Calculated fees", requestContext, methodContext, {
304+
senderFulfillGasFee: senderFulfillGasFee.toString(),
305+
receiverPrepareGasFee: receiverPrepareGasFee.toString(),
306+
total: total.toString(),
307+
});
308+
309+
return total;
303310
}
304311

305312
/**
@@ -456,9 +463,12 @@ export class ChainReader {
456463
// Use Gelato Oracle if it's configured and available for the chain id
457464
let gelatoEstimatedFee: BigNumber | undefined;
458465
if (this.config[chainIdForTokenPrice] && this.config[chainIdForTokenPrice].gelatoOracle) {
466+
const inputDecimals = await this.getDecimalsForAsset(chainId, assetId);
459467
gelatoEstimatedFee = await this.calculateGelatoFee(chainIdForGasPrice, assetId, gasLimit.toNumber());
460468
gelatoEstimatedFee = gelatoEstimatedFee
461-
? gelatoEstimatedFee.div(BigNumber.from(10).pow(18 - decimals))
469+
? decimals > inputDecimals
470+
? gelatoEstimatedFee.mul(BigNumber.from(10).pow(decimals - inputDecimals))
471+
: gelatoEstimatedFee.div(BigNumber.from(10).pow(inputDecimals - decimals))
462472
: undefined;
463473
}
464474

0 commit comments

Comments
 (0)