mirror of
https://github.com/tornadocash/tornado-initiation-ui.git
synced 2025-02-14 13:10:29 +01:00
add gas price oracle
This commit is contained in:
parent
e5a40d65a6
commit
70c5487ba2
@ -32,18 +32,18 @@ export default {
|
||||
|
||||
const result = localStorage.getItem('provider')
|
||||
if (result && result.name) {
|
||||
this.$store.dispatch(
|
||||
'provider/initProvider',
|
||||
{
|
||||
name: result.name,
|
||||
network: result.network,
|
||||
},
|
||||
{ root: true }
|
||||
)
|
||||
this.initProvider({
|
||||
name: result.name,
|
||||
network: result.network,
|
||||
})
|
||||
}
|
||||
|
||||
this.fetchGasPrice()
|
||||
},
|
||||
methods: {
|
||||
...mapActions('provider', ['initProvider']),
|
||||
...mapActions('steps', ['fetchDeploymentStatus']),
|
||||
...mapActions('gasPrice', ['fetchGasPrice']),
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
@ -12,6 +12,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"core-js": "^3.6.5",
|
||||
"gas-price-oracle": "^0.2.2",
|
||||
"node-sass": "^4.14.1",
|
||||
"nuxt": "^2.14.6",
|
||||
"nuxt-buefy": "^0.4.3",
|
||||
|
@ -49,6 +49,9 @@ const actions = {
|
||||
)
|
||||
throw new Error('Already deployed')
|
||||
}
|
||||
|
||||
const gasPrice = rootGetters['gasPrice/fastGasPrice']
|
||||
|
||||
const data = getters.deployerContract.methods
|
||||
.deploy(bytecode, salt)
|
||||
.encodeABI()
|
||||
@ -60,7 +63,7 @@ const actions = {
|
||||
from: ethAccount,
|
||||
to: getters.deployerContract._address,
|
||||
gas: numberToHex(6e6),
|
||||
gasPrice: '0x100000000',
|
||||
gasPrice,
|
||||
value: 0,
|
||||
data,
|
||||
},
|
||||
|
55
store/gasPrice.js
Normal file
55
store/gasPrice.js
Normal file
@ -0,0 +1,55 @@
|
||||
/* eslint-disable no-console */
|
||||
import { GasPriceOracle } from 'gas-price-oracle'
|
||||
import networkConfig from '@/networkConfig'
|
||||
const { toHex, toWei } = require('web3-utils')
|
||||
|
||||
export const state = () => {
|
||||
return {
|
||||
instant: networkConfig.netId1.gasPrices.instant,
|
||||
fast: networkConfig.netId1.gasPrices.fast,
|
||||
standard: networkConfig.netId1.gasPrices.standard,
|
||||
low: networkConfig.netId1.gasPrices.low,
|
||||
custom: null,
|
||||
}
|
||||
}
|
||||
|
||||
export const getters = {
|
||||
oracle: (state, getters, rootState, rootGetters) => {
|
||||
const currentRpc = rootGetters['provider/getNetwork'].rpcUrls.Infura.url
|
||||
console.log('currentRpc', currentRpc)
|
||||
return new GasPriceOracle({ defaultRpc: currentRpc })
|
||||
},
|
||||
fastGasPrice: (state) => {
|
||||
return toHex(toWei(state.fast.toString(), 'gwei'))
|
||||
},
|
||||
lowGasPrice: (state) => {
|
||||
return toHex(toWei(state.standard.toString(), 'gwei'))
|
||||
},
|
||||
}
|
||||
|
||||
export const mutations = {
|
||||
SAVE_GAS_PRICES(state, { instant, fast, standard, low }) {
|
||||
this._vm.$set(state, 'instant', instant)
|
||||
this._vm.$set(state, 'fast', fast)
|
||||
this._vm.$set(state, 'standard', standard)
|
||||
this._vm.$set(state, 'low', low)
|
||||
},
|
||||
SAVE_CUSTOM_GAS_PRICE(state, { custom }) {
|
||||
this._vm.$set(state, 'custom', custom)
|
||||
},
|
||||
}
|
||||
|
||||
export const actions = {
|
||||
async fetchGasPrice({ getters, commit, dispatch, rootGetters, state }) {
|
||||
const { pollInterval } = rootGetters['provider/getNetwork']
|
||||
try {
|
||||
const gas = await getters.oracle.gasPrices(state)
|
||||
commit('SAVE_GAS_PRICES', gas)
|
||||
console.log(`Got fast gas price ${state.fast}`)
|
||||
setTimeout(() => dispatch('fetchGasPrice'), 1000 * pollInterval)
|
||||
} catch (e) {
|
||||
console.error('fetchGasPrice', e)
|
||||
setTimeout(() => dispatch('fetchGasPrice'), 1000 * pollInterval)
|
||||
}
|
||||
},
|
||||
}
|
34
yarn.lock
34
yarn.lock
@ -1999,6 +1999,13 @@ 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==
|
||||
dependencies:
|
||||
follow-redirects "1.5.10"
|
||||
|
||||
babel-eslint@^10.1.0:
|
||||
version "10.1.0"
|
||||
resolved "https://registry.yarnpkg.com/babel-eslint/-/babel-eslint-10.1.0.tgz#6968e568a910b78fb3779cdd8b6ac2f479943232"
|
||||
@ -2081,6 +2088,11 @@ big.js@^5.2.2:
|
||||
resolved "https://registry.yarnpkg.com/big.js/-/big.js-5.2.2.tgz#65f0af382f578bcdc742bd9c281e9cb2d7768328"
|
||||
integrity sha512-vyL2OymJxmarO8gxMr0mhChsO9QGwhynfuu4+MHTAW6czfq9humCB7rKpUjDd9YUiDPU4mzpyupFSvOClAwbmQ==
|
||||
|
||||
bignumber.js@^9.0.0:
|
||||
version "9.0.1"
|
||||
resolved "https://registry.yarnpkg.com/bignumber.js/-/bignumber.js-9.0.1.tgz#8d7ba124c882bfd8e43260c67475518d0689e4e5"
|
||||
integrity sha512-IdZR9mh6ahOBv/hYGiXyVuyCetmGJhtYkqLBpTStdhEGjegpPlUawydyaF3pbIOFynJTpllEs+NP+CS9jKFLjA==
|
||||
|
||||
binary-extensions@^1.0.0:
|
||||
version "1.13.1"
|
||||
resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-1.13.1.tgz#598afe54755b2868a5330d2aff9d4ebb53209b65"
|
||||
@ -3307,6 +3319,13 @@ 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"
|
||||
@ -4608,6 +4627,13 @@ 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"
|
||||
|
||||
for-in@^1.0.2:
|
||||
version "1.0.2"
|
||||
resolved "https://registry.yarnpkg.com/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80"
|
||||
@ -4747,6 +4773,14 @@ 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.2.2:
|
||||
version "0.2.2"
|
||||
resolved "https://registry.yarnpkg.com/gas-price-oracle/-/gas-price-oracle-0.2.2.tgz#32c57a9aa6bc69152be96812880232efebfecbc6"
|
||||
integrity sha512-I4+rLbc7C1vgYXV+cYY0MKeqdZVna2hXpNfD2fcIvf/wIgvtIYmG9gsmhiaYGSgOE2RSPUs2xf/W4K2nJOoNuQ==
|
||||
dependencies:
|
||||
axios "^0.19.2"
|
||||
bignumber.js "^9.0.0"
|
||||
|
||||
gauge@~2.7.3:
|
||||
version "2.7.4"
|
||||
resolved "https://registry.yarnpkg.com/gauge/-/gauge-2.7.4.tgz#2c03405c7538c39d7eb37b317022e325fb018bf7"
|
||||
|
Loading…
x
Reference in New Issue
Block a user