diff --git a/package-lock.json b/package-lock.json index 2602a55b3f..01d7a0752b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -81,7 +81,7 @@ "geoip-lite2": "^2.2.7", "graphql": "^16.11.0", "graphql-request": "^6.1.0", - "handlebars": "^4.7.8", + "handlebars": "^4.7.9", "helmet": "^6.2.0", "ibantools": "^4.5.1", "jszip": "^3.10.1", @@ -17493,9 +17493,9 @@ } }, "node_modules/handlebars": { - "version": "4.7.8", - "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.7.8.tgz", - "integrity": "sha512-vafaFqs8MZkRrSX7sFVUdo3ap/eNiLnb4IakshzvP56X5Nr1iGKAIqdX6tMlm6HcNRIkr6AxO5jFEoJzzpT8aQ==", + "version": "4.7.9", + "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.7.9.tgz", + "integrity": "sha512-4E71E0rpOaQuJR2A3xDZ+GM1HyWYv1clR58tC8emQNeQe3RH7MAzSbat+V0wG78LQBo6m6bzSG/L4pBuCsgnUQ==", "license": "MIT", "dependencies": { "minimist": "^1.2.5", diff --git a/package.json b/package.json index 2c1ea32ccf..f02316dcf9 100644 --- a/package.json +++ b/package.json @@ -98,7 +98,7 @@ "geoip-lite2": "^2.2.7", "graphql": "^16.11.0", "graphql-request": "^6.1.0", - "handlebars": "^4.7.8", + "handlebars": "^4.7.9", "helmet": "^6.2.0", "ibantools": "^4.5.1", "jszip": "^3.10.1", diff --git a/src/subdomains/supporting/payin/services/base/payin-evm.service.ts b/src/subdomains/supporting/payin/services/base/payin-evm.service.ts index cc140a553d..43da7769c0 100644 --- a/src/subdomains/supporting/payin/services/base/payin-evm.service.ts +++ b/src/subdomains/supporting/payin/services/base/payin-evm.service.ts @@ -23,6 +23,10 @@ export abstract class PayInEvmService { return this.#client.sendTokenFromAccount(account, addressTo, tokenName, amount); } + async getGasCostForCoinTransaction(): Promise { + return this.#client.getCurrentGasCostForCoinTransaction(); + } + async checkTransactionCompletion(txHash: string, minConfirmations: number): Promise { return this.#client.isTxComplete(txHash, minConfirmations); } diff --git a/src/subdomains/supporting/payin/strategies/send/impl/base/evm-coin.strategy.ts b/src/subdomains/supporting/payin/strategies/send/impl/base/evm-coin.strategy.ts index 30b2766b0c..9674b0b453 100644 --- a/src/subdomains/supporting/payin/strategies/send/impl/base/evm-coin.strategy.ts +++ b/src/subdomains/supporting/payin/strategies/send/impl/base/evm-coin.strategy.ts @@ -41,12 +41,14 @@ export abstract class EvmCoinStrategy extends EvmStrategy { payInGroup.status = PayInStatus.PREPARED; } - protected dispatchSend(payInGroup: SendGroup, type: SendType, estimatedNativeFee: number): Promise { + protected async dispatchSend(payInGroup: SendGroup, type: SendType, estimatedNativeFee: number): Promise { const { account, destinationAddress } = payInGroup; const groupAmount = this.getTotalGroupAmount(payInGroup, type); - // subtract fee for forwarding - const amount = type === SendType.FORWARD ? Util.round(groupAmount - estimatedNativeFee * 1.00001, 12) : groupAmount; + // use fresh gas cost (not cached estimate) to avoid value + gas > balance + const freshGasCost = await this.payInEvmService.getGasCostForCoinTransaction(); + const gasCost = Math.max(freshGasCost, estimatedNativeFee); + const amount = Util.round(groupAmount - gasCost * 1.05, 12); return this.payInEvmService.sendNativeCoin(account, destinationAddress, amount); }