update calculations to be like in up-to-date safe-contracts tests

This commit is contained in:
mmv 2019-05-22 19:36:46 +04:00
parent 755db44c17
commit c5bc2fa584
1 changed files with 9 additions and 11 deletions

View File

@ -40,21 +40,18 @@ export const estimateDataGas = (
// For signature array length and dataGasEstimate we already calculated // For signature array length and dataGasEstimate we already calculated
// the 0 bytes so we just add 64 for each non-zero byte // 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 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 const payload = safe.contract.methods
.execTransaction(to, valueInWei, data, operation, txGasEstimate, 0, gasPrice, gasToken, refundReceiver, sigs) .execTransaction(to, valueInWei, data, operation, txGasEstimate, 0, gasPrice, gasToken, refundReceiver, sigs)
.encodeABI() .encodeABI()
let dataGasEstimate = estimateDataGasCosts(payload) + signatureCost const dataGasEstimate = estimateDataGasCosts(payload) + signatureCost + (nonce > 0 ? 5000 : 20000) + 1500 // 1500 -> hash generation costs
console.log(dataGasEstimate, signatureCost)
if (dataGasEstimate > 65536) { return dataGasEstimate + 32000 // Add aditional gas costs (e.g. base tx costs, transfer costs)
dataGasEstimate += 64
} else {
dataGasEstimate += 128
}
return dataGasEstimate + 34000 // Add aditional gas costs (e.g. base tx costs, transfer costs)
} }
// eslint-disable-next-line // eslint-disable-next-line
@ -102,6 +99,7 @@ export const calculateTxFee = async (
if (!safeInstance) { if (!safeInstance) {
safeInstance = await getSafeEthereumInstance(safeAddress) safeInstance = await getSafeEthereumInstance(safeAddress)
} }
window.safeInstance = safeInstance
// Estimate safe transaction (need to be called with "from" set to the safe address) // Estimate safe transaction (need to be called with "from" set to the safe address)
const nonce = await safeInstance.nonce() const nonce = await safeInstance.nonce()
@ -145,7 +143,7 @@ export const calculateTxFee = async (
dataGasEstimate, dataGasEstimate,
0, 0,
'0x0000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000',
'0x0000000000000000000000000000000000000000', safeAddress,
sigs, sigs,
) )