multicall

This commit is contained in:
Alexey 2021-03-22 21:36:37 +04:00
parent 10170b2155
commit a87436e6d5
3 changed files with 188 additions and 18 deletions

View File

@ -4,6 +4,13 @@ const ethers = require('ethers')
const tornadoTreesAbi = require('./abi/tornadoTrees.json')
const tornadoAbi = require('./abi/tornado.json')
const fs = require('fs')
const { aggregate } = require('@makerdao/multicall')
const { BigNumber } = ethers
const config = {
rpcUrl: process.env.RPC_URL,
multicallAddress: '0xeefba1e63905ef1d7acba5a8513c70307c1ce441',
}
const abi = new ethers.utils.AbiCoder()
const provider = new ethers.providers.JsonRpcProvider(process.env.RPC_URL)
@ -13,17 +20,20 @@ const tornadoTreesV1 = new ethers.Contract(
provider,
)
const instances = process.env.NET_ID === '1' ? [
'0x12D66f87A04A9E220743712cE6d9bB1B5616B8Fc',
'0x47CE0C6eD5B0Ce3d3A51fdb1C52DC66a7c3c2936',
'0x910Cbd523D972eb0a6f4cAe4618aD62622b39DbF',
'0xA160cdAB225685dA1d56aa342Ad8841c3b53f291',
] : [
'0x3aac1cC67c2ec5Db4eA850957b967Ba153aD6279',
'0x723B78e67497E85279CB204544566F4dC5d2acA0',
'0x0E3A09dDA6B20aFbB34aC7cD4A6881493f3E7bf7',
'0x6Bf694a291DF3FeC1f7e69701E3ab6c592435Ae7',
]
const instances =
process.env.NET_ID === '1'
? [
'0x12D66f87A04A9E220743712cE6d9bB1B5616B8Fc',
'0x47CE0C6eD5B0Ce3d3A51fdb1C52DC66a7c3c2936',
'0x910Cbd523D972eb0a6f4cAe4618aD62622b39DbF',
'0xA160cdAB225685dA1d56aa342Ad8841c3b53f291',
]
: [
'0x3aac1cC67c2ec5Db4eA850957b967Ba153aD6279',
'0x723B78e67497E85279CB204544566F4dC5d2acA0',
'0x0E3A09dDA6B20aFbB34aC7cD4A6881493f3E7bf7',
'0x6Bf694a291DF3FeC1f7e69701E3ab6c592435Ae7',
]
const tornadoTreesDeploymentBlock = process.env.NET_ID === '1' ? 11474714 : 3945174
@ -97,8 +107,40 @@ async function getPendingDeposits() {
fs.writeFileSync('./cache/allEvents.json', JSON.stringify(tornadoEvents, null, 2))
// const tornadoEvents = require('./cache/allEvents.json')
const registeredDeposits = await tornadoTreesV1.getRegisteredDeposits({ gasLimit: 500e6 })
let lastProcessedDepositLeaf = (await tornadoTreesV1.lastProcessedDepositLeaf()).toNumber()
const depositsLength = BigNumber.from(await provider.getStorageAt(tornadoTreesV1.address, 0)).toNumber()
console.log('depositsLength', depositsLength)
let registeredDeposits = []
let nextBatchIndex = lastProcessedDepositLeaf
while (nextBatchIndex <= depositsLength) {
const calls = []
const batchSize = 300
const nextBatchEnd = Math.min(nextBatchIndex + batchSize, depositsLength)
for (let i = nextBatchIndex; i < nextBatchEnd; i++) {
calls.push({
target: tornadoTreesV1.address,
call: ['deposits(uint256)(bytes32)', i],
returns: [[`deposit-${i}`]],
})
}
try {
const { results } = await aggregate(calls, config)
// console.log('results', results)
registeredDeposits = registeredDeposits.concat(Object.values(results.original))
console.log('registeredDeposits', registeredDeposits.length)
if (nextBatchIndex === depositsLength) {
break
}
nextBatchIndex = nextBatchEnd
} catch (e) {
break
}
}
// fs.writeFileSync('./cache/tempRegisteredDeposits.json', JSON.stringify(registeredDeposits, null, 2))
const cachedEvents = registeredDeposits.map((hash) => {
const leaf = tornadoEvents[hash]
if (!leaf) {
@ -141,8 +183,38 @@ async function getPendingWithdrawals() {
fs.writeFileSync('./cache/allEvents.json', JSON.stringify(tornadoEvents, null, 2))
// const tornadoEvents = require('./cache/allEvents.json')
const registeredWithdrawals = await tornadoTreesV1.getRegisteredWithdrawals({ gasLimit: 500e6 })
let lastProcessedWithdrawalLeaf = (await tornadoTreesV1.lastProcessedWithdrawalLeaf()).toNumber()
const withdrawalsLength = BigNumber.from(await provider.getStorageAt(tornadoTreesV1.address, 2)).toNumber()
console.log('withdrawalsLength', withdrawalsLength)
let registeredWithdrawals = []
let nextBatchIndex = lastProcessedWithdrawalLeaf
while (nextBatchIndex <= withdrawalsLength) {
const calls = []
const batchSize = 400
const nextBatchEnd = Math.min(nextBatchIndex + batchSize, withdrawalsLength)
for (let i = nextBatchIndex; i < nextBatchEnd; i++) {
calls.push({
target: tornadoTreesV1.address,
call: ['withdrawals(uint256)(bytes32)', i],
returns: [[`withdrawal-${i}`]],
})
}
try {
const { results } = await aggregate(calls, config)
registeredWithdrawals = registeredWithdrawals.concat(Object.values(results.original))
console.log('registeredWithdrawals', registeredWithdrawals.length)
if (nextBatchIndex === withdrawalsLength) {
break
}
nextBatchIndex = nextBatchEnd
} catch (e) {
console.log('e', e)
break
}
}
const cachedEvents = registeredWithdrawals.map((hash) => {
const leaf = tornadoEvents[hash]
if (!leaf) {
@ -189,8 +261,8 @@ async function getCommittedWithdrawals() {
fs.writeFileSync('./cache/committedWithdrawals.json', JSON.stringify(events, null, 2))
}
getCommittedDeposits()
getCommittedWithdrawals()
// getCommittedDeposits()
// getCommittedWithdrawals()
getPendingDeposits()
// getPendingDeposits()
getPendingWithdrawals()

View File

@ -11,6 +11,7 @@
"author": "Roman Semenov <semenov.roma@gmail.com>",
"license": "ISC",
"dependencies": {
"@makerdao/multicall": "^0.12.0",
"circomlib": "git+https://github.com/tornadocash/circomlib.git#d20d53411d1bef61f38c99a8b36d5d0cc4836aa1",
"cron": "^1.8.2",
"dotenv": "^8.2.0",

101
yarn.lock
View File

@ -60,6 +60,13 @@
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.11.3.tgz#9e1eae46738bcd08e23e867bab43e7b95299a8f9"
integrity sha512-REo8xv7+sDxkKvoxEywIdsNFiZLybwdI7hcT5uEPyQrSMB4YQ973BfC9OOrD/81MaIjh6UxdulIQXkjmiH3PcA==
"@babel/runtime@^7.7.4":
version "7.13.10"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.13.10.tgz#47d42a57b6095f4468da440388fdbad8bebf0d7d"
integrity sha512-4QPkjJq6Ns3V/RgpEahRk+AGfL0eO6RHHtTWoNNr5mO49G6B5+X6d6THgWEAvTrznU5xYpbAlVKRYcsCgh/Akw==
dependencies:
regenerator-runtime "^0.13.4"
"@babel/template@^7.10.4":
version "7.10.4"
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.10.4.tgz#3251996c4200ebc71d1a8fc405fba940f36ba278"
@ -901,6 +908,20 @@
fastfile "0.0.19"
ffjavascript "^0.2.30"
"@makerdao/multicall@^0.12.0":
version "0.12.0"
resolved "https://registry.yarnpkg.com/@makerdao/multicall/-/multicall-0.12.0.tgz#490cb2698c8748b132bfdf59c79d7ef2598880b1"
integrity sha512-ARyv5EFqiaRegm1axPcDsOboBv8nCV6wDbPk9ODk5I1vM9IIcDOhw2DgPyW4i1+3ahrDTyuxPPy36Jm8My+LdA==
dependencies:
"@babel/runtime" "^7.7.4"
cross-fetch "^3.0.4"
debug "^4.1.1"
ethers "^4.0.27"
invariant "^2.2.4"
isomorphic-ws "^4.0.1"
lodash "^4.17.11"
ws "^7.2.0"
"@openzeppelin/contracts@^3.1.0":
version "3.2.0"
resolved "https://registry.yarnpkg.com/@openzeppelin/contracts/-/contracts-3.2.0.tgz#3e6b3a7662d8ed64271ade96ef42655db983fd9d"
@ -1770,6 +1791,13 @@ cron@^1.8.2:
dependencies:
moment-timezone "^0.5.x"
cross-fetch@^3.0.4:
version "3.1.2"
resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-3.1.2.tgz#ee0c2f18844c4fde36150c2a4ddc068d20c1bc41"
integrity sha512-+JhD65rDNqLbGmB3Gzs3HrEKC0aQnD+XA3SY6RjgkF88jV2q5cTc5+CwxlS3sdmLk98gpPt5CF9XRnPdlxZe6w==
dependencies:
node-fetch "2.6.1"
cross-spawn@^6.0.0, cross-spawn@^6.0.5:
version "6.0.5"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-6.0.5.tgz#4a5ec7c64dfae22c3a14124dbacdee846d80cbc4"
@ -1829,7 +1857,7 @@ debug@2.6.9, debug@^2.2.0:
dependencies:
ms "2.0.0"
debug@4.3.1:
debug@4.3.1, debug@^4.1.1:
version "4.3.1"
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.1.tgz#f0d229c505e0c6d8c49ac553d1b13dc183f6b2ee"
integrity sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ==
@ -2384,6 +2412,21 @@ ethereumjs-util@^7.0.3:
ethjs-util "0.1.6"
rlp "^2.2.4"
ethers@^4.0.27:
version "4.0.48"
resolved "https://registry.yarnpkg.com/ethers/-/ethers-4.0.48.tgz#330c65b8133e112b0613156e57e92d9009d8fbbe"
integrity sha512-sZD5K8H28dOrcidzx9f8KYh8083n5BexIO3+SbE4jK83L85FxtpXZBCQdXb8gkg+7sBqomcLhhkU7UHL+F7I2g==
dependencies:
aes-js "3.0.0"
bn.js "^4.4.0"
elliptic "6.5.3"
hash.js "1.1.3"
js-sha3 "0.5.7"
scrypt-js "2.0.4"
setimmediate "1.0.4"
uuid "2.0.1"
xmlhttprequest "1.8.0"
ethers@^5.0.17:
version "5.0.18"
resolved "https://registry.yarnpkg.com/ethers/-/ethers-5.0.18.tgz#2ccf382d32b9712e6967d0b14303cb0fe8056c7a"
@ -3151,6 +3194,13 @@ inquirer@^6.2.2:
strip-ansi "^5.1.0"
through "^2.3.6"
invariant@^2.2.4:
version "2.2.4"
resolved "https://registry.yarnpkg.com/invariant/-/invariant-2.2.4.tgz#610f3c92c9359ce1db616e538008d23ff35158e6"
integrity sha512-phJfQVBuaJM5raOpJjSfkiD6BpbCE4Ns//LaXl6wGYtUBY83nWS6Rf9tXm2e8VaK60JEjYldbPif/A2B1C2gNA==
dependencies:
loose-envify "^1.0.0"
invert-kv@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/invert-kv/-/invert-kv-2.0.0.tgz#7393f5afa59ec9ff5f67a27620d11c226e3eec02"
@ -3247,6 +3297,11 @@ isexe@^2.0.0:
resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10"
integrity sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=
isomorphic-ws@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/isomorphic-ws/-/isomorphic-ws-4.0.1.tgz#55fd4cd6c5e6491e76dc125938dd863f5cd4f2dc"
integrity sha512-BhBvN2MBpWTaSHdWRb/bwdZJ1WaehQ2L1KngkCkfLUGF0mAWAT1sQUQacEmQ0jXkFw/czDXPNQSL5u2/Krsz1w==
isstream@~0.1.2:
version "0.1.2"
resolved "https://registry.yarnpkg.com/isstream/-/isstream-0.1.2.tgz#47e63f7af55afa6f92e1500e690eb8b8529c099a"
@ -3280,7 +3335,7 @@ js-sha3@^0.8.0:
resolved "https://registry.yarnpkg.com/js-sha3/-/js-sha3-0.8.0.tgz#b9b7a5da73afad7dedd0f8c463954cbde6818840"
integrity sha512-gF1cRrHhIzNfToc802P800N8PpXS+evLLXfsVpowqmAFR9uwbi89WvXg2QspOmXL8QL86J4T1EpFu+yUkwJY3Q==
js-tokens@^4.0.0:
"js-tokens@^3.0.0 || ^4.0.0", js-tokens@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
integrity sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==
@ -3444,6 +3499,13 @@ logplease@^1.2.15:
resolved "https://registry.yarnpkg.com/logplease/-/logplease-1.2.15.tgz#3da442e93751a5992cc19010a826b08d0293c48a"
integrity sha512-jLlHnlsPSJjpwUfcNyUxXCl33AYg2cHhIf9QhGL2T4iPT0XPB+xP1LRKFPgIg1M/sg9kAJvy94w9CzBNrfnstA==
loose-envify@^1.0.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf"
integrity sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==
dependencies:
js-tokens "^3.0.0 || ^4.0.0"
lowercase-keys@^1.0.0, lowercase-keys@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/lowercase-keys/-/lowercase-keys-1.0.1.tgz#6f9e30b47084d971a7c820ff15a6c5167b74c26f"
@ -3755,6 +3817,11 @@ node-addon-api@^2.0.0:
resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-2.0.2.tgz#432cfa82962ce494b132e9d72a15b29f71ff5d32"
integrity sha512-Ntyt4AIXyaLIuMHF6IOoTakB3K+RWxwtsHNRxllEoA6vPwP9o4866g6YWDLUdnucilZhmkxiHwHr11gAENw+QA==
node-fetch@2.6.1:
version "2.6.1"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052"
integrity sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==
node-gyp-build@^4.2.0:
version "4.2.3"
resolved "https://registry.yarnpkg.com/node-gyp-build/-/node-gyp-build-4.2.3.tgz#ce6277f853835f718829efb47db20f3e4d9c4739"
@ -4189,6 +4256,11 @@ readdirp@~3.5.0:
dependencies:
picomatch "^2.2.1"
regenerator-runtime@^0.13.4:
version "0.13.7"
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.13.7.tgz#cac2dacc8a1ea675feaabaeb8ae833898ae46f55"
integrity sha512-a54FxoJDIr27pgf7IgeQGxmqUNYrcV338lf/6gH456HZ/PhX+5BcwHXG9ajESmwe6WRO0tAzRUrRmNONWgkrew==
regexpp@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/regexpp/-/regexpp-2.0.1.tgz#8d19d31cf632482b589049f8281f93dbcba4d07f"
@ -4330,6 +4402,11 @@ safe-buffer@^5.0.1, safe-buffer@^5.1.0, safe-buffer@^5.1.1, safe-buffer@^5.1.2,
resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a"
integrity sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==
scrypt-js@2.0.4:
version "2.0.4"
resolved "https://registry.yarnpkg.com/scrypt-js/-/scrypt-js-2.0.4.tgz#32f8c5149f0797672e551c07e230f834b6af5f16"
integrity sha512-4KsaGcPnuhtCZQCxFxN3GVYIhKFPTdLd8PLC552XwbMndtD0cjRFAhDuuydXQ0h08ZfPgzqe6EKHozpuH74iDw==
scrypt-js@3.0.1, scrypt-js@^3.0.0, scrypt-js@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/scrypt-js/-/scrypt-js-3.0.1.tgz#d314a57c2aef69d1ad98a138a21fe9eafa9ee312"
@ -4406,6 +4483,11 @@ set-blocking@^2.0.0:
resolved "https://registry.yarnpkg.com/set-blocking/-/set-blocking-2.0.0.tgz#045f9782d011ae9a6803ddd382b24392b3d890f7"
integrity sha1-BF+XgtARrppoA93TgrJDkrPYkPc=
setimmediate@1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/setimmediate/-/setimmediate-1.0.4.tgz#20e81de622d4a02588ce0c8da8973cbcf1d3138f"
integrity sha1-IOgd5iLUoCWIzgyNqJc8vPHTE48=
setimmediate@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/setimmediate/-/setimmediate-1.0.5.tgz#290cbb232e306942d7d7ea9b83732ab7856f8285"
@ -4951,6 +5033,11 @@ utils-merge@1.0.1:
resolved "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.1.tgz#9f95710f50a267947b2ccc124741c1028427e713"
integrity sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM=
uuid@2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-2.0.1.tgz#c2a30dedb3e535d72ccf82e343941a50ba8533ac"
integrity sha1-wqMN7bPlNdcsz4LjQ5QaULqFM6w=
uuid@3.3.2:
version "3.3.2"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.3.2.tgz#1b4af4955eb3077c501c23872fc6513811587131"
@ -5371,6 +5458,11 @@ ws@^3.0.0:
safe-buffer "~5.1.0"
ultron "~1.1.0"
ws@^7.2.0:
version "7.4.4"
resolved "https://registry.yarnpkg.com/ws/-/ws-7.4.4.tgz#383bc9742cb202292c9077ceab6f6047b17f2d59"
integrity sha512-Qm8k8ojNQIMx7S+Zp8u/uHOx7Qazv3Yv4q68MiWWWOJhiwG5W3x7iqmRtJo8xxrciZUY4vRxUTJCKuRnF28ZZw==
xhr-request-promise@^0.1.2:
version "0.1.3"
resolved "https://registry.yarnpkg.com/xhr-request-promise/-/xhr-request-promise-0.1.3.tgz#2d5f4b16d8c6c893be97f1a62b0ed4cf3ca5f96c"
@ -5408,6 +5500,11 @@ xhr@^2.0.4, xhr@^2.3.3:
parse-headers "^2.0.0"
xtend "^4.0.0"
xmlhttprequest@1.8.0:
version "1.8.0"
resolved "https://registry.yarnpkg.com/xmlhttprequest/-/xmlhttprequest-1.8.0.tgz#67fe075c5c24fef39f9d65f5f7b7fe75171968fc"
integrity sha1-Z/4HXFwk/vOfnWX197f+dRcZaPw=
xtend@^4.0.0:
version "4.0.2"
resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.2.tgz#bb72779f5fa465186b1f438f674fa347fdb5db54"