From c5bc2fa584b3bf2e132a575419189a99d477e636 Mon Sep 17 00:00:00 2001 From: mmv Date: Wed, 22 May 2019 19:36:46 +0400 Subject: [PATCH] update calculations to be like in up-to-date safe-contracts tests --- src/logic/safe/transactions/gas.js | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/logic/safe/transactions/gas.js b/src/logic/safe/transactions/gas.js index 6af60ce0..b3beda81 100644 --- a/src/logic/safe/transactions/gas.js +++ b/src/logic/safe/transactions/gas.js @@ -40,21 +40,18 @@ export const estimateDataGas = ( // For signature array length and dataGasEstimate we already calculated // the 0 bytes so we just add 64 for each non-zero byte const gasPrice = 0 // no need to get refund when we submit txs to metamask - const signatureCost = signatureCount * (68 + 2176 + 2176) // array count (3 -> r, s, v) * signature count + const signatureCost = signatureCount * (68 + 2176 + 2176 + 6000) // array count (3 -> r, s, v) * signature count - const sigs = getSignaturesFrom(safe.address, nonce) + const sigs = `0x000000000000000000000000${ + '0xbc2BB26a6d821e69A38016f3858561a1D80d4182'.replace('0x', '') + }0000000000000000000000000000000000000000000000000000000000000000` const payload = safe.contract.methods .execTransaction(to, valueInWei, data, operation, txGasEstimate, 0, gasPrice, gasToken, refundReceiver, sigs) .encodeABI() - let dataGasEstimate = estimateDataGasCosts(payload) + signatureCost - console.log(dataGasEstimate, signatureCost) - if (dataGasEstimate > 65536) { - dataGasEstimate += 64 - } else { - dataGasEstimate += 128 - } - return dataGasEstimate + 34000 // Add aditional gas costs (e.g. base tx costs, transfer costs) + const dataGasEstimate = estimateDataGasCosts(payload) + signatureCost + (nonce > 0 ? 5000 : 20000) + 1500 // 1500 -> hash generation costs + + return dataGasEstimate + 32000 // Add aditional gas costs (e.g. base tx costs, transfer costs) } // eslint-disable-next-line @@ -102,6 +99,7 @@ export const calculateTxFee = async ( if (!safeInstance) { safeInstance = await getSafeEthereumInstance(safeAddress) } + window.safeInstance = safeInstance // Estimate safe transaction (need to be called with "from" set to the safe address) const nonce = await safeInstance.nonce() @@ -145,7 +143,7 @@ export const calculateTxFee = async ( dataGasEstimate, 0, '0x0000000000000000000000000000000000000000', - '0x0000000000000000000000000000000000000000', + safeAddress, sigs, )