2021-06-06 19:31:32 +02:00
|
|
|
const { ethers } = require('hardhat')
|
|
|
|
|
2021-07-08 19:50:44 +02:00
|
|
|
const MERKLE_TREE_HEIGHT = 32
|
2021-06-06 19:31:32 +02:00
|
|
|
const MerkleTree = require('fixed-merkle-tree')
|
|
|
|
const { poseidon } = require('circomlib')
|
|
|
|
const poseidonHash = (items) => ethers.BigNumber.from(poseidon(items).toString())
|
|
|
|
const poseidonHash2 = (a, b) => poseidonHash([a, b])
|
|
|
|
|
|
|
|
const toFixedHex = (number, length = 32) =>
|
|
|
|
'0x' +
|
|
|
|
(number instanceof Buffer
|
|
|
|
? number.toString('hex')
|
|
|
|
: ethers.BigNumber.from(number).toHexString().slice(2)
|
|
|
|
).padStart(length * 2, '0')
|
|
|
|
|
|
|
|
async function main() {
|
2021-06-15 13:25:06 +02:00
|
|
|
const Verifier2 = await ethers.getContractFactory('Verifier2')
|
|
|
|
const verifier2 = await Verifier2.deploy()
|
|
|
|
await verifier2.deployed()
|
|
|
|
console.log(`verifier2: ${verifier2.address}`)
|
|
|
|
|
|
|
|
const Verifier16 = await ethers.getContractFactory('Verifier16')
|
|
|
|
const verifier16 = await Verifier16.deploy()
|
|
|
|
await verifier16.deployed()
|
|
|
|
console.log(`verifier16: ${verifier16.address}`)
|
2021-06-06 19:31:32 +02:00
|
|
|
|
|
|
|
const tree = new MerkleTree(MERKLE_TREE_HEIGHT, [], { hashFunction: poseidonHash2 })
|
|
|
|
const root = await tree.root()
|
|
|
|
|
|
|
|
const Pool = await ethers.getContractFactory('TornadoPool')
|
2021-06-15 13:25:06 +02:00
|
|
|
const tornado = await Pool.deploy(verifier2.address, verifier16.address, toFixedHex(root))
|
2021-06-16 02:31:31 +02:00
|
|
|
console.log(`TornadoPool address: ${tornado.address}`)
|
2021-06-06 19:31:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
main()
|
|
|
|
.then(() => process.exit(0))
|
|
|
|
.catch((error) => {
|
|
|
|
console.error(error)
|
|
|
|
process.exit(1)
|
|
|
|
})
|