diff --git a/packages/bitcore-wallet-service/src/lib/chain/eth/index.ts b/packages/bitcore-wallet-service/src/lib/chain/eth/index.ts index 11433b10f26..5c3837af085 100644 --- a/packages/bitcore-wallet-service/src/lib/chain/eth/index.ts +++ b/packages/bitcore-wallet-service/src/lib/chain/eth/index.ts @@ -183,7 +183,8 @@ export class EthChain implements IChain { let outputAddresses = []; // Parameter for MuliSend contract let outputAmounts = []; // Parameter for MuliSend contract let totalValue = toBN(0); // Parameter for MuliSend contract - + logger.info(`getFee for address ${from} on network ${network} and chain ${chain}`); + logger.info('getFee.opts: %o', { from, txType, priorityFeePercentile, gasLimitBuffer }); for (let output of opts.outputs) { if (opts.multiSendContractAddress) { outputAddresses.push(output.toAddress); @@ -227,7 +228,8 @@ export class EthChain implements IChain { gasLimit = inGasLimit || defaultGasLimit; fee += feePerKb * gasLimit; } - + logger.info(`[${from}] Add gas limit buffer?: ${!!gasLimitBuffer}`); + logger.info(`[${from}] Current gas limit: ${gasLimit}`); if (opts.multiSendContractAddress) { try { const data = this.encodeContractParameters( @@ -246,6 +248,7 @@ export class EthChain implements IChain { data, gasPrice }); + logger.info(`[${from}] Estimated gas limit: ${gasLimit}`); } catch (error) { logger.error('Error estimating gas for MultiSend contract: %o', error); } @@ -253,8 +256,10 @@ export class EthChain implements IChain { gasLimit = gasLimit ? gasLimit : inGasLimit; gasLimit += Math.ceil(gasLimit * buffer); // add gas limit buffer fee += feePerKb * gasLimit; + logger.info(`[${from}] Gas limit with buffer: ${gasLimit}`); } else if (gasLimitBuffer) { gasLimit += Math.ceil(gasLimit * (gasLimitBuffer / 100)); + logger.info(`[${from}] Gas limit with buffer: ${gasLimit}`); } if (Number(txType) === 2) { maxGasFee = await server.estimateFee({ network, chain: wallet.chain || coin, txType: 2 }); diff --git a/packages/bitcore-wallet-service/src/lib/server.ts b/packages/bitcore-wallet-service/src/lib/server.ts index 3b164fe6cc6..1659f85d848 100644 --- a/packages/bitcore-wallet-service/src/lib/server.ts +++ b/packages/bitcore-wallet-service/src/lib/server.ts @@ -2242,15 +2242,15 @@ export class WalletService implements IWalletService { } catch (addrErr) { return addrErr; } - + if (!checkRequired(output, ['toAddress', 'amount'])) { return new ClientError('Argument missing in output #' + (i + 1) + '.'); } - + if (!ChainService.checkValidTxAmount(wallet.chain, output)) { return new ClientError('Invalid amount'); } - + const error = ChainService.checkDust(wallet.chain, output, opts); if (error) return error; output.valid = true; @@ -2580,9 +2580,15 @@ export class WalletService implements IWalletService { return next(); }, async next => { + logger.info('Calculating fee for new tx: %o', { + from: opts.from, fee: opts.fee, input: opts.inputs?.length, gasLimit: opts.gasLimit, gasLimitBuffer: opts.gasLimitBuffer + }); if (!isNaN(opts.fee) && (opts.inputs || []).length > 0) return next(); try { ({ feePerKb, gasPrice, maxGasFee, priorityGasFee, gasLimit, fee } = await ChainService.getFee(this, wallet, opts)); + logger.info('ChainService.getFee return value %o', { + from: opts.from, feePerKb, gasPrice, maxGasFee, priorityGasFee, gasLimit, fee + }); } catch (error) { return next(error); } @@ -2702,7 +2708,7 @@ export class WalletService implements IWalletService { }, next => { if (!txp.multiSendContractAddress || !txp.tokenAddress) { - return next(); + return next(); } // Check that the multisend contract is approved in the token contract for the total amount const bc = this._getBlockchainExplorer(wallet.chain, wallet.network); @@ -6167,24 +6173,24 @@ export class WalletService implements IWalletService { 'x-api-key': API_KEY }; - let qs = []; - if (!checkRequired(req.body, ['sellAsset', 'buyAsset', 'sellAmount'])) { - return reject(new ClientError("Thorswap's request missing arguments")); - } - qs.push('sellAsset=' + req.body.sellAsset); - qs.push('buyAsset=' + req.body.buyAsset); - qs.push('sellAmount=' + req.body.sellAmount); - if (req.body.senderAddress) qs.push('senderAddress=' + req.body.senderAddress); - if (req.body.recipientAddress) qs.push('recipientAddress=' + req.body.recipientAddress); - if (req.body.slippage) qs.push('slippage=' + req.body.slippage); - if (req.body.limit) qs.push('limit=' + req.body.limit); - if (req.body.providers) qs.push('providers=' + req.body.providers); - if (req.body.subProviders) qs.push('subProviders=' + req.body.subProviders); - if (req.body.preferredProvider) qs.push('preferredProvider=' + req.body.preferredProvider); - if (req.body.affiliateAddress) qs.push('affiliateAddress=' + req.body.affiliateAddress); - if (req.body.affiliateBasisPoints) qs.push('affiliateBasisPoints=' + req.body.affiliateBasisPoints); - if (req.body.isAffiliateFeeFlat) qs.push('isAffiliateFeeFlat=' + req.body.isAffiliateFeeFlat); - if (req.body.allowSmartContractRecipient) qs.push('allowSmartContractRecipient=' + req.body.allowSmartContractRecipient); + let qs = []; + if (!checkRequired(req.body, ['sellAsset', 'buyAsset', 'sellAmount'])) { + return reject(new ClientError("Thorswap's request missing arguments")); + } + qs.push('sellAsset=' + req.body.sellAsset); + qs.push('buyAsset=' + req.body.buyAsset); + qs.push('sellAmount=' + req.body.sellAmount); + if (req.body.senderAddress) qs.push('senderAddress=' + req.body.senderAddress); + if (req.body.recipientAddress) qs.push('recipientAddress=' + req.body.recipientAddress); + if (req.body.slippage) qs.push('slippage=' + req.body.slippage); + if (req.body.limit) qs.push('limit=' + req.body.limit); + if (req.body.providers) qs.push('providers=' + req.body.providers); + if (req.body.subProviders) qs.push('subProviders=' + req.body.subProviders); + if (req.body.preferredProvider) qs.push('preferredProvider=' + req.body.preferredProvider); + if (req.body.affiliateAddress) qs.push('affiliateAddress=' + req.body.affiliateAddress); + if (req.body.affiliateBasisPoints) qs.push('affiliateBasisPoints=' + req.body.affiliateBasisPoints); + if (req.body.isAffiliateFeeFlat) qs.push('isAffiliateFeeFlat=' + req.body.isAffiliateFeeFlat); + if (req.body.allowSmartContractRecipient) qs.push('allowSmartContractRecipient=' + req.body.allowSmartContractRecipient); const URL: string = API + `/aggregator/tokens/quote?${qs.join('&')}`;