Skip to content

Commit

Permalink
confirm tx fixed with 0 gas price
Browse files Browse the repository at this point in the history
  • Loading branch information
mikhaildobs committed Oct 18, 2019
1 parent f5413f9 commit c102595
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 48 deletions.
16 changes: 11 additions & 5 deletions packages/apps/wallet/data/store/saga/widget/every/confirm-tx.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
import { select, put } from 'redux-saga/effects'
import { ethers } from 'ethers'

const generator = function * ({ payload }) {
try {
const sdk = yield select(generator.selectors.sdk)
const { privateKey, contractAddress } = yield select(generator.selectors.userData)
const { privateKey } = yield select(generator.selectors.userData)
const txParams = yield select(generator.selectors.txParams)
const {
data,
to,
value
} = txParams

const message = {
from: contractAddress,
const owner = new ethers.Wallet(privateKey).address
const walletAddress = sdk.precomputeAddress({ owner })

const params = {
safe: walletAddress,
data: data || '0x0',
to: to || '0x0',
operationType: 0,
value: value || '0x0'
value: value || '0x0',
privateKey
}
const { txHash, success, errors } = yield sdk.execute(message, privateKey)

const { txHash, success, errors } = yield sdk.executeTx(params)
yield put({ type: '*WIDGET.CONFIRM', payload: { txHash, success, errors } })
} catch (e) {
console.error(e)
Expand Down
1 change: 1 addition & 0 deletions packages/apps/wallet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"cryptocompare": "^1.0.0",
"css-loader": "^0.28.0",
"eslint-config-standard": "^13.0.1",
"eth-sig-util": "2.4.4",
"ethereum-waffle": "^2.0.12",
"ethers": "^4.0.27",
"express": "^4.16.4",
Expand Down
50 changes: 26 additions & 24 deletions packages/sdk/src/estimateTxGas.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import assert from 'assert-js'
// import assert from 'assert-js'
import { ethers } from 'ethers'
import GnosisSafe from '@gnosis.pm/safe-contracts/build/contracts/GnosisSafe'
import { encodeParams } from './utils'
import BigNumber from 'bignumber.js'
import Web3 from 'web3'
import { signTx } from './signTx'
import { AddressZero } from 'ethers/constants'
// import { signTx } from './signTx'
// import { AddressZero } from 'ethers/constants'

const baseGasValue = hexValue => {
switch (hexValue) {
Expand Down Expand Up @@ -75,12 +75,12 @@ export const estimateGasCosts = async ({
}) => {
const provider = new ethers.providers.JsonRpcProvider(jsonRpcUrl)

let currentGasPriceGwei = await provider.getGasPrice()
currentGasPriceGwei = ethers.utils.formatUnits(
currentGasPriceGwei.toString(),
'gwei'
)
currentGasPriceGwei = parseInt(Math.ceil(currentGasPriceGwei))
// let currentGasPriceGwei = await provider.getGasPrice()
// currentGasPriceGwei = ethers.utils.formatUnits(
// currentGasPriceGwei.toString(),
// 'gwei'
// )
// currentGasPriceGwei = parseInt(Math.ceil(currentGasPriceGwei))

const web3 = new Web3(jsonRpcUrl)
const gnosisSafe = new web3.eth.Contract(GnosisSafe.abi, safe)
Expand All @@ -103,7 +103,7 @@ export const estimateGasCosts = async ({

let txGasEstimate = new BigNumber(estimateResponse.substring(138), 16)
// Add 10k else we will fail in case of nested calls
txGasEstimate = txGasEstimate.toNumber() + 10000
txGasEstimate = txGasEstimate.toNumber() + 100000

const gasCosts = []

Expand All @@ -125,14 +125,16 @@ export const estimateGasCosts = async ({
safeTxGas: txGasEstimate
})

for (
let gasPriceGwei = currentGasPriceGwei;
gasPriceGwei <= currentGasPriceGwei + 5;
gasPriceGwei++
) {
const gasPrice = ethers.utils
.parseUnits(gasPriceGwei.toString(), 'gwei')
.toNumber()
// for (
// let gasPriceGwei = currentGasPriceGwei;
// gasPriceGwei <= currentGasPriceGwei + 5;
// gasPriceGwei++
// ) {

let gasPriceGwei = 0
const gasPrice = ethers.utils
.parseUnits(gasPriceGwei.toString(), 'gwei')
.toNumber()

const baseGasEstimate = estimateBaseGas({
safe,
Expand All @@ -148,12 +150,12 @@ export const estimateGasCosts = async ({
nonce
})

gasCosts.push({
gasPrice,
baseGas: baseGasEstimate,
safeTxGas: txGasEstimate
})
}
gasCosts.push({
gasPrice,
baseGas: baseGasEstimate,
safeTxGas: txGasEstimate
})
// }

return gasCosts
}
8 changes: 4 additions & 4 deletions packages/sdk/src/executeTx.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const getGasSpectrum = async ({
const web3 = new Web3(jsonRpcUrl)
const gnosisSafe = new web3.eth.Contract(GnosisSafe.abi, safe)
const nonce = await gnosisSafe.methods.nonce().call()

const gasSpectrum = await estimateGasCosts({
jsonRpcUrl,
safe,
Expand All @@ -34,6 +34,7 @@ const getGasSpectrum = async ({
})

for (let i = 0; i < gasSpectrum.length; i++) {

gasSpectrum[i].signature = await signTx({
safe,
privateKey,
Expand Down Expand Up @@ -69,9 +70,8 @@ const getGasSpectrum = async ({
})

// Add the txGasEstimate and an additional 10k to the estimate to ensure that there is enough gas for the safe transaction
gasSpectrum[i].gasLimit = estimate + gasSpectrum[i].safeTxGas + 10000
gasSpectrum[i].gasLimit = estimate + gasSpectrum[i].safeTxGas + 100000
}
console.log('gasSpectrum: ', gasSpectrum)
return gasSpectrum
}

Expand Down Expand Up @@ -113,7 +113,7 @@ export const executeTx = async ({
assert.string(data, 'Data is required')
assert.string(gasToken, 'Gas token is required')
assert.string(refundReceiver, 'Refund receiver address is required')

const gasSpectrum = await getGasSpectrum({
jsonRpcUrl,
safe,
Expand Down
5 changes: 2 additions & 3 deletions packages/sdk/src/signTx.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const signTx = ({
}

privateKey = Buffer.from(privateKey, 'hex')

const typedData = getTypedData({
safe,
to,
Expand All @@ -62,13 +62,12 @@ export const signTx = ({
refundReceiver,
nonce
})

/**
r: new BigNumber(signature.slice(2, 66), 16).toString(10),
s: new BigNumber(signature.slice(66, 130), 16).toString(10),
v: new BigNumber(signature.slice(130, 132), 16).toString(10)
*/

return sigUtil.signTypedData(privateKey, {
data: typedData
})
Expand Down
7 changes: 5 additions & 2 deletions packages/server/src/services/transactionRelayService.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class TransactionRelayService {
gasSpectrum
}) {
try {
const i = 1
const i = 0

const gnosisSafe = new ethers.Contract(
safe,
Expand All @@ -25,6 +25,7 @@ class TransactionRelayService {
)

logger.debug('Submitting safe transaction...')

const tx = await gnosisSafe.execTransaction(
to,
value,
Expand All @@ -36,7 +37,9 @@ class TransactionRelayService {
gasToken,
refundReceiver,
gasSpectrum[i].signature,
{ gasPrice: gasSpectrum[i].gasPrice, gasLimit: gasSpectrum[i].gasLimit }
{
gasPrice: ethers.utils.parseUnits('10', 'gwei'), // gasSpectrum[i].gasPrice,
gasLimit: gasSpectrum[i].gasLimit }
)
logger.info(`Tx hash: ${tx.hash}`)
return { success: true, txHash: tx.hash }
Expand Down
19 changes: 9 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8466,15 +8466,7 @@ eth-sig-util@2.2.0:
tweetnacl "^1.0.0"
tweetnacl-util "^0.15.0"

eth-sig-util@^1.4.2:
version "1.4.2"
resolved "https://registry.yarnpkg.com/eth-sig-util/-/eth-sig-util-1.4.2.tgz#8d958202c7edbaae839707fba6f09ff327606210"
integrity sha1-jZWCAsftuq6Dlwf7pvCf8ydgYhA=
dependencies:
ethereumjs-abi "git+https://github.com/ethereumjs/ethereumjs-abi.git"
ethereumjs-util "^5.1.1"

eth-sig-util@^2.4.4:
eth-sig-util@2.4.4, eth-sig-util@^2.4.4:
version "2.4.4"
resolved "https://registry.yarnpkg.com/eth-sig-util/-/eth-sig-util-2.4.4.tgz#8804ead83de8648bcf81eadbfac1e3ccdd360aea"
integrity sha512-iWGqEJwsUMgtk8AqQQqIDTjMz+pW8s2Sq8gN640dh9U9HoEFQJO3m6ro96DgV6hMB2LYu8F5812LQyynOgCbEw==
Expand All @@ -8486,6 +8478,14 @@ eth-sig-util@^2.4.4:
tweetnacl "^1.0.0"
tweetnacl-util "^0.15.0"

eth-sig-util@^1.4.2:
version "1.4.2"
resolved "https://registry.yarnpkg.com/eth-sig-util/-/eth-sig-util-1.4.2.tgz#8d958202c7edbaae839707fba6f09ff327606210"
integrity sha1-jZWCAsftuq6Dlwf7pvCf8ydgYhA=
dependencies:
ethereumjs-abi "git+https://github.com/ethereumjs/ethereumjs-abi.git"
ethereumjs-util "^5.1.1"

eth-tx-summary@^3.1.2:
version "3.2.4"
resolved "https://registry.yarnpkg.com/eth-tx-summary/-/eth-tx-summary-3.2.4.tgz#e10eb95eb57cdfe549bf29f97f1e4f1db679035c"
Expand Down Expand Up @@ -21786,7 +21786,6 @@ websocket@1.0.29:
dependencies:
debug "^2.2.0"
es5-ext "^0.10.50"
gulp "^4.0.2"
nan "^2.14.0"
typedarray-to-buffer "^3.1.5"
yaeti "^0.0.6"
Expand Down

0 comments on commit c102595

Please sign in to comment.