gas price

This commit is contained in:
Alexey 2020-12-29 20:44:37 -05:00
parent 9718f80775
commit e3ddfc06a6
5 changed files with 29 additions and 3 deletions

View File

@ -11,3 +11,6 @@ INSERT_BATCH_SIZE=60
# should not be more often than CONFIRMATION_BLOCKS time. e.g every 3 minutes # should not be more often than CONFIRMATION_BLOCKS time. e.g every 3 minutes
CRON_EXPRESSION="0 */3 * * * *" CRON_EXPRESSION="0 */3 * * * *"
CONFIRMATION_BLOCKS=3 CONFIRMATION_BLOCKS=3
# one of "low", "standard", "fast", "instant" or a number in Gwei
GAS_PRICE=fast

View File

@ -16,11 +16,12 @@
"dotenv": "^8.2.0", "dotenv": "^8.2.0",
"eth-ens-namehash": "^2.0.8", "eth-ens-namehash": "^2.0.8",
"fixed-merkle-tree": "^0.3.4", "fixed-merkle-tree": "^0.3.4",
"gas-price-oracle": "^0.2.2",
"ioredis": "^4.17.3", "ioredis": "^4.17.3",
"snarkjs": "git+https://github.com/tornadocash/snarkjs.git#869181cfaf7526fe8972073d31655493a04326d5", "snarkjs": "git+https://github.com/tornadocash/snarkjs.git#869181cfaf7526fe8972073d31655493a04326d5",
"torn-token": "^1.0.0",
"tx-manager": "^0.2.9", "tx-manager": "^0.2.9",
"web3": "^1.2.11", "web3": "^1.2.11"
"torn-token": "^1.0.0"
}, },
"devDependencies": { "devDependencies": {
"babel-eslint": "^10.1.0", "babel-eslint": "^10.1.0",

View File

@ -1,8 +1,10 @@
require('dotenv').config() require('dotenv').config()
const cron = require('cron') const cron = require('cron')
const { web3, redis, getTornadoTrees, txManager } = require('./singletons') const { web3, redis, getTornadoTrees, txManager, gasOracle } = require('./singletons')
const config = require('torn-token') const config = require('torn-token')
const { getTornadoEvents, getRegisteredEvents } = require('./events') const { getTornadoEvents, getRegisteredEvents } = require('./events')
const GAS_PRICE_VALUES = ['low', 'standard', 'fast', 'instant']
const { toWei, toHex } = require('web3-utils')
const STARTING_BLOCK = process.env.STARTING_BLOCK || 0 const STARTING_BLOCK = process.env.STARTING_BLOCK || 0
const prefix = { const prefix = {
@ -47,10 +49,19 @@ async function main(isRetry = false) {
console.log( console.log(
`Submitting tree update with ${chunks['deposit'].length} deposits and ${chunks['withdrawal'].length} withdrawals`, `Submitting tree update with ${chunks['deposit'].length} deposits and ${chunks['withdrawal'].length} withdrawals`,
) )
let gasPrice
if (GAS_PRICE_VALUES.includes(process.env.GAS_PRICE)) {
const gasPrices = await gasOracle.gasPrices()
gasPrice = gasPrices[process.env.GAS_PRICE]
} else {
gasPrice = Number(process.env.GAS_PRICE)
}
const data = tornadoTrees.methods.updateRoots(chunks['deposit'], chunks['withdrawal']).encodeABI() const data = tornadoTrees.methods.updateRoots(chunks['deposit'], chunks['withdrawal']).encodeABI()
const tx = txManager.createTx({ const tx = txManager.createTx({
to: tornadoTrees._address, to: tornadoTrees._address,
data, data,
gasPrice: toHex(toWei(gasPrice.toString(), 'Gwei')),
}) })
try { try {

View File

@ -5,6 +5,8 @@ const tornadoTreesAbi = require('../abi/tornadoTrees.json')
const Redis = require('ioredis') const Redis = require('ioredis')
const ENSResolver = require('./resolver') const ENSResolver = require('./resolver')
const resolver = new ENSResolver() const resolver = new ENSResolver()
const { GasPriceOracle } = require('gas-price-oracle')
const gasOracle = new GasPriceOracle({ defaultRpc: process.env.RPC_URL })
const redis = new Redis(process.env.REDIS_URL) const redis = new Redis(process.env.REDIS_URL)
const config = require('torn-token') const config = require('torn-token')
let tornadoTrees let tornadoTrees
@ -34,4 +36,5 @@ module.exports = {
redis, redis,
getTornadoTrees, getTornadoTrees,
txManager, txManager,
gasOracle,
} }

View File

@ -2133,6 +2133,14 @@ gas-price-oracle@^0.2.0:
axios "^0.19.2" axios "^0.19.2"
bignumber.js "^9.0.0" bignumber.js "^9.0.0"
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"
get-caller-file@^1.0.1: get-caller-file@^1.0.1:
version "1.0.3" version "1.0.3"
resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-1.0.3.tgz#f978fa4c90d1dfe7ff2d6beda2a515e713bdcf4a" resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-1.0.3.tgz#f978fa4c90d1dfe7ff2d6beda2a515e713bdcf4a"