WA-238 calculating gas and gasPrice when creating safe

This commit is contained in:
apanizo 2018-06-01 08:33:13 +02:00
parent 8da8071eeb
commit a759328f40
2 changed files with 11 additions and 5 deletions

View File

@ -5,7 +5,7 @@ import { promisify } from '~/utils/promisify'
// const MAINNET_NETWORK = 1
const calculateGasPrice = async () => {
export const calculateGasPrice = async () => {
/*
const web3 = getWeb3()
const { network } = web3.version
@ -26,16 +26,17 @@ const calculateGasPrice = async () => {
return new BigNumber(json.average).multipliedBy(1e8).toString()
}
const calculateGasOf = async (data: Object, from: string, to: string) => {
export const calculateGasOf = async (data: Object, from: string, to: string) => {
const web3 = getWeb3()
const gas = await promisify(cb => web3.eth.estimateGas({ data, from, to }, cb))
return promisify(cb => web3.eth.estimateGas({ data, from, to }, cb))
return gas * 2
}
const executeTransaction = async (data: Object, from: string, to: string) => {
const web3 = getWeb3()
const gas = await calculateGasOf(data, from, to) * 2
const gas = await calculateGasOf(data, from, to)
let gasPrice
try {

View File

@ -7,6 +7,7 @@ import GnosisSafeSol from '#/GnosisSafeTeamEdition.json'
import ProxyFactorySol from '#/ProxyFactory.json'
import CreateAndAddModules from '#/CreateAndAddModules.json'
import DailyLimitModule from '#/DailyLimitModule.json'
import { calculateGasOf, calculateGasPrice } from '~/wallets/ethTransactions'
let proxyFactoryMaster
let createAndAddModuleMaster
@ -129,5 +130,9 @@ export const deploySafeContract = async (
userAccount: string,
) => {
const gnosisSafeData = await getSafeDataBasedOn(safeAccounts, numConfirmations, dailyLimit)
return proxyFactoryMaster.createProxy(safeMaster.address, gnosisSafeData, { from: userAccount, gas: '5000000' })
const proxyFactoryData = proxyFactoryMaster.contract.createProxy.getData(safeMaster.address, gnosisSafeData)
const gas = await calculateGasOf(proxyFactoryData, userAccount, proxyFactoryMaster.address)
const gasPrice = await calculateGasPrice()
return proxyFactoryMaster.createProxy(safeMaster.address, gnosisSafeData, { from: userAccount, gas, gasPrice })
}