add migration

This commit is contained in:
Roman Storm 2021-02-02 14:32:44 -08:00
parent 5fe2429b89
commit 72133bfba6
No known key found for this signature in database
GPG Key ID: 522F2A785F34E71F
4 changed files with 33 additions and 8 deletions

2
.env.example Normal file
View File

@ -0,0 +1,2 @@
PRIVATE_KEY=0x
INFURA_TOKEN=

1
.gitignore vendored
View File

@ -3,3 +3,4 @@ node_modules
#Hardhat files
cache
artifacts
.env

View File

@ -1,6 +1,6 @@
/* global task, ethers */
require('@nomiclabs/hardhat-waffle')
require('dotenv').config()
// This is a sample Hardhat task. To learn how to create your own go to
// https://hardhat.org/guides/create-task.html
task('accounts', 'Prints the list of accounts', async () => {
@ -19,4 +19,10 @@ task('accounts', 'Prints the list of accounts', async () => {
*/
module.exports = {
solidity: '0.6.12',
networks: {
goerli: {
url: `https://goerli.infura.io/v3/${process.env.INFURA_TOKEN}`,
accounts: [process.env.PRIVATE_KEY],
},
},
}

View File

@ -4,6 +4,9 @@
// When running the script with `hardhat run <script>` you'll find the Hardhat
// Runtime Environment's members available in the global scope.
const hre = require('hardhat')
const { toFixedHex, poseidonHash2 } = require('../src/utils')
const toEns = (addr) => toFixedHex(addr, 20).padEnd(66, '0')
const MerkleTree = require('fixed-merkle-tree')
async function main() {
// Hardhat always runs the compile task when running scripts with its command
@ -13,13 +16,26 @@ async function main() {
// manually to make sure everything is compiled
// await hre.run('compile');
// We get the contract to deploy
const Greeter = await hre.ethers.getContractFactory('Greeter')
const greeter = await Greeter.deploy('Hello, Hardhat!')
await greeter.deployed()
console.log('Greeter deployed to:', greeter.address)
const BatchTreeUpdateVerifier = await hre.ethers.getContractFactory('BatchTreeUpdateVerifier')
const verifier = await BatchTreeUpdateVerifier.deploy()
await verifier.deployed()
const TornadoTrees = await hre.ethers.getContractFactory('TornadoTrees')
// bytes32 _governance,
// bytes32 _tornadoProxy,
// bytes32 _treeUpdateVerifier,
// bytes32 _depositRoot,
// bytes32 _withdrawalRoot
const levels = 20
const tree = new MerkleTree(levels, [], { hashFunction: poseidonHash2 })
const tornadoTrees = await TornadoTrees.deploy(
toEns('0x5efda50f22d34F262c29268506C5Fa42cB56A1Ce'),
toEns('0x905b63Fff465B9fFBF41DeA908CEb12478ec7601'),
toEns(verifier.address),
toFixedHex(tree.root()),
toFixedHex(tree.root()),
)
await tornadoTrees.deployed()
console.log('tornadoTrees deployed to:', tornadoTrees.address)
}
// We recommend this pattern to be able to use async/await everywhere