gas calculations wip
This commit is contained in:
parent
a984d08a3d
commit
c6325567ba
|
@ -48,6 +48,7 @@ export const estimateDataGas = (
|
|||
.encodeABI()
|
||||
|
||||
let dataGasEstimate = estimateDataGasCosts(payload) + signatureCost
|
||||
console.log(dataGasEstimate, signatureCost)
|
||||
if (dataGasEstimate > 65536) {
|
||||
dataGasEstimate += 64
|
||||
} else {
|
||||
|
@ -86,4 +87,47 @@ export const generateTxGasEstimateFrom = async (
|
|||
console.log('Error calculating tx gas estimation ' + error)
|
||||
return 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const calculateTxFee = async (
|
||||
safe: any,
|
||||
safeAddress: string,
|
||||
data: string,
|
||||
to: string,
|
||||
valueInWei: number,
|
||||
operation: number,
|
||||
) => {
|
||||
try {
|
||||
let safeInstance = safe
|
||||
if (!safeInstance) {
|
||||
safeInstance = await getSafeEthereumInstance(safeAddress)
|
||||
}
|
||||
|
||||
// Estimate safe transaction (need to be called with "from" set to the safe address)
|
||||
const nonce = await safeInstance.nonce()
|
||||
const threshold = await safeInstance.getThreshold()
|
||||
const txGasEstimate = await generateTxGasEstimateFrom(safeInstance, safeAddress, data, to, valueInWei, operation)
|
||||
const dataGasEstimate = await estimateDataGas(
|
||||
safeInstance,
|
||||
to,
|
||||
valueInWei,
|
||||
data,
|
||||
operation,
|
||||
txGasEstimate,
|
||||
'0x0000000000000000000000000000000000000000',
|
||||
nonce,
|
||||
Number(threshold),
|
||||
safeAddress,
|
||||
)
|
||||
const sigs = getSignaturesFrom(safeInstance.address, nonce)
|
||||
const estimate = await safeInstance.execTransaction.estimateGas(
|
||||
to, valueInWei, data, operation, txGasEstimate, dataGasEstimate, 0, '0x0000000000000000000000000000000000000000', safeAddress, sigs
|
||||
)
|
||||
|
||||
return estimate
|
||||
} catch (error) {
|
||||
// eslint-disable-next-line
|
||||
console.log('Error calculating tx gas estimation ' + error)
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ import {
|
|||
} from '~/components/forms/validator'
|
||||
import TokenSelectField from '~/routes/safe/components/Balances/SendModal/screens/SendFunds/TokenSelectField'
|
||||
import SafeInfo from '~/routes/safe/components/Balances/SendModal/screens/SendFunds/SafeInfo'
|
||||
import { generateTxGasEstimateFrom } from '~/logic/safe/safeTxSignerEIP712'
|
||||
import { calculateTxFee } from '~/logic/safe/transactions'
|
||||
import ArrowDown from './assets/arrow-down.svg'
|
||||
import { styles } from './style'
|
||||
|
||||
|
@ -89,7 +89,7 @@ const SendFunds = ({
|
|||
|
||||
const estimateFee = async () => {
|
||||
const valueInWei = web3.utils.toWei(amount, 'ether')
|
||||
const fee = await generateTxGasEstimateFrom(null, safeAddress, '0x', recipientAddress, valueInWei, 0)
|
||||
const fee = await calculateTxFee(null, safeAddress, '0x', recipientAddress, valueInWei, 0)
|
||||
setTxFee(fee)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue