fix: send transaction

This commit is contained in:
Danil Kovtonyuk 2021-11-15 23:21:04 +10:00
parent 5035f4cc98
commit 4ef4cefa34
No known key found for this signature in database
GPG Key ID: E72A919BF08C3746
5 changed files with 74 additions and 64 deletions

View File

@ -14,7 +14,7 @@
"dependencies": {
"@mycrypto/gas-estimation": "^1.1.0",
"core-js": "^3.6.5",
"gas-price-oracle": "^0.4.0",
"gas-price-oracle": "^0.4.2",
"node-sass": "^4.14.1",
"nuxt": "^2.14.6",
"nuxt-buefy": "^0.4.4",

View File

@ -30,7 +30,7 @@ const mutations = {}
const actions = {
async deployContract(
{ state, dispatch, getters, rootGetters, commit, rootState },
{ dispatch, getters, rootGetters },
{ action, index, isL1 }
) {
try {
@ -53,9 +53,6 @@ const actions = {
}
const ethAccount = rootGetters['provider/getAccount']
const txGasParams = rootGetters['gasPrice/txGasParams']
console.log(txGasParams)
const isProxy = deployerContracts.includes(action.domain)
const deployerContract = getters.deployerContract(isProxy)
@ -66,7 +63,6 @@ const actions = {
const params = {
from: ethAccount,
to: deployerContract._address,
...txGasParams,
value: '0x0',
data,
}
@ -91,15 +87,13 @@ const actions = {
{ root: true }
)
const txHash = await dispatch(
'provider/sendRequest',
'provider/sendTransaction',
{
method: 'eth_sendTransaction',
params: [
{
...params,
gas: numberToHex(gasWithBuffer),
},
],
params: {
...params,
gas: numberToHex(gasWithBuffer),
},
},
{
root: true,

View File

@ -7,15 +7,10 @@ const { toHex, toWei } = require('web3-utils')
export const state = () => {
return {
params: {
1: {
maxFeePerGas: '0x25FF7A6000',
maxPriorityFeePerGas: '0x77359400',
},
},
prices: {
1: Object.assign(networkConfig.netId1.gasPrices),
100: Object.assign(networkConfig.netId100.gasPrices),
maxFeePerGas: '0x25FF7A6000',
maxPriorityFeePerGas: '0x77359400',
},
prices: Object.assign(networkConfig.netId1.gasPrices),
}
}
@ -31,36 +26,37 @@ export const getters = {
defaultFallbackGasPrices: gasPrices,
})
},
gasParams: (state) => (chainId) => {
return state.params[chainId]
isEip1559Supported: (state, getters, rootState, rootGetters) => {
const { isEip1559Supported } = rootGetters['provider/getNetwork']
return isEip1559Supported
},
gasPrice: (state) => (chainId) => {
const currentGas = state.prices[chainId]
return toHex(toWei(currentGas.fast.toString(), 'gwei'))
},
txGasParams: (state, getters, rootState, rootGetters) => {
const { id: chainId, isEip1559Supported } = rootGetters[
'provider/getNetwork'
]
if (isEip1559Supported) {
return getters.gasParams(chainId)
gasPrice: (state, getters) => {
if (getters.isEip1559Supported) {
return state.params.maxFeePerGas
}
return { gasPrice: getters.gasPrice(chainId) }
return toHex(toWei(state.prices.fast.toString(), 'gwei'))
},
txGasParams: (state, getters) => (isDisable = false) => {
if (!isDisable && getters.isEip1559Supported) {
return state.params
}
return { gasPrice: getters.gasPrice }
},
}
export const mutations = {
SAVE_GAS_PRICES(state, { chainId, ...gas }) {
this._vm.$set(state.prices, chainId, gas)
SAVE_GAS_PRICES(state, gas) {
this._vm.$set(state, 'prices', gas)
},
SET_GAS_PARAMS(state, { chainId, ...params }) {
this._vm.$set(state.params, chainId, params)
SET_GAS_PARAMS(state, params) {
this._vm.$set(state, 'params', params)
},
}
export const actions = {
async fetchGasParams({ getters, commit, dispatch, rootGetters, state }) {
const { pollInterval, id: chainId, isEip1559Supported } = rootGetters[
const { pollInterval, isEip1559Supported } = rootGetters[
'provider/getNetwork'
]
const rpcUrl = rootGetters['provider/getRpc']
@ -72,11 +68,10 @@ export const actions = {
commit('SET_GAS_PARAMS', {
maxFeePerGas: toHex(maxFeePerGas.toString()),
maxPriorityFeePerGas: toHex(maxPriorityFeePerGas.toString()),
chainId,
})
} else {
const gas = await getters.oracle.gasPrices()
commit('SAVE_GAS_PRICES', { chainId, ...gas })
commit('SAVE_GAS_PRICES', gas)
console.log(`Got fast gas price ${gas.fast}`)
}

View File

@ -146,4 +146,34 @@ export default {
})
}
},
async sendTransaction(
{ dispatch, rootGetters },
{ method, params, eipDisable = false }
) {
try {
const gasParams = rootGetters['gasPrice/txGasParams'](eipDisable)
const txHash = await dispatch('sendRequest', {
method,
params: [
{
...params,
...gasParams,
},
],
})
return txHash
} catch (err) {
if (err.message.includes('EIP-1559')) {
return await dispatch('sendTransaction', {
method,
params,
eipDisable: true,
})
}
throw new Error(err.message)
}
},
}

View File

@ -2300,12 +2300,12 @@ aws4@^1.8.0:
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.10.1.tgz#e1e82e4f3e999e2cfd61b161280d16a111f86428"
integrity sha512-zg7Hz2k5lI8kb7U32998pRRFin7zJlkfezGJjUc2heaD4Pw2wObakCDVzkKztTm/Ln7eiVvYsjqak0Ed4LkMDA==
axios@^0.19.2:
version "0.19.2"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.19.2.tgz#3ea36c5d8818d0d5f8a8a97a6d36b86cdc00cb27"
integrity sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA==
axios@^0.21.2:
version "0.21.4"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.4.tgz#c67b90dc0568e5c1cf2b0b858c43ba28e2eda575"
integrity sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==
dependencies:
follow-redirects "1.5.10"
follow-redirects "^1.14.0"
babel-eslint@^10.1.0:
version "10.1.0"
@ -3642,13 +3642,6 @@ debug@2.6.9, debug@^2.2.0, debug@^2.3.3, debug@^2.6.9:
dependencies:
ms "2.0.0"
debug@=3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/debug/-/debug-3.1.0.tgz#5bb5a0672628b64149566ba16819e61518c67261"
integrity sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==
dependencies:
ms "2.0.0"
debug@^4.0.1, debug@^4.1.0, debug@^4.1.1, debug@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/debug/-/debug-4.2.0.tgz#7f150f93920e94c58f5574c2fd01a3110effe7f1"
@ -4834,12 +4827,10 @@ flush-write-stream@^1.0.0:
inherits "^2.0.3"
readable-stream "^2.3.6"
follow-redirects@1.5.10:
version "1.5.10"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.5.10.tgz#7b7a9f9aea2fdff36786a94ff643ed07f4ff5e2a"
integrity sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==
dependencies:
debug "=3.1.0"
follow-redirects@^1.14.0:
version "1.14.5"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.5.tgz#f09a5848981d3c772b5392309778523f8d85c381"
integrity sha512-wtphSXy7d4/OR+MvIFbCVBDzZ5520qV8XfPklSN5QtxuMUJZ+b0Wnst1e1lCDocfzuCkHqj8k0FpZqO+UIaKNA==
for-in@^1.0.2:
version "1.0.2"
@ -4975,12 +4966,12 @@ functional-red-black-tree@^1.0.1:
resolved "https://registry.yarnpkg.com/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz#1b0ab3bd553b2a0d6399d29c0e3ea0b252078327"
integrity sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=
gas-price-oracle@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/gas-price-oracle/-/gas-price-oracle-0.4.0.tgz#1b8426bce92ebcff6cc98a0c5638769cb22417b1"
integrity sha512-5ct4VwTqTigD1V3EvUn513e41OIA+/Ubw0FITVfarw7AjVpg4LQSt9anRt+LcDU4+u+eMUEA3VP0VnvMN8nybA==
gas-price-oracle@^0.4.2:
version "0.4.2"
resolved "https://registry.yarnpkg.com/gas-price-oracle/-/gas-price-oracle-0.4.2.tgz#82dbc31c5f6d0ea23adbcb3d525e3e69dddca622"
integrity sha512-pAJ+g28htnEG7ji1Vv+BKZRkCk13DEyThHbumqQ+/PzDfarg951wSAx246FdodMl64FuXMUCqKImPIsMtMVYaA==
dependencies:
axios "^0.19.2"
axios "^0.21.2"
bignumber.js "^9.0.0"
gauge@~2.7.3: