|
| 1 | +import { ethers, network } from 'hardhat'; |
| 2 | +import { parseUnits } from '@ethersproject/units'; |
| 3 | +import { DeepSquare__factory } from '../typings'; |
| 4 | +import { Ballot__factory } from '../typings/factories/contracts/Ballot__factory'; |
| 5 | +import { VotingDelegation__factory } from '../typings/factories/contracts/VotingDelegation__factory'; |
| 6 | +import { BallotFactory__factory } from '../typings/factories/contracts/factories/BallotFactory__factory'; |
| 7 | + |
| 8 | +type NetworkName = 'hardhat' | 'mainnet' | 'fuji'; |
| 9 | +type ContractName = 'DeepSquare'; |
| 10 | + |
| 11 | +const addresses: Record<ContractName, Record<NetworkName, string>> = { |
| 12 | + DeepSquare: { |
| 13 | + hardhat: '0xf192cae2e7cd4048bea307368015e3647c49338e', |
| 14 | + mainnet: '0xf192cae2e7cd4048bea307368015e3647c49338e', |
| 15 | + fuji: '0x270D1399744874C72f95873eB9606172D155669D', |
| 16 | + }, |
| 17 | +}; |
| 18 | + |
| 19 | +async function main() { |
| 20 | + const networkName = network.name as NetworkName; |
| 21 | + const [deployer, ...accounts] = await ethers.getSigners(); |
| 22 | + |
| 23 | + const DeepSquareFactory = new DeepSquare__factory(deployer); |
| 24 | + const DeepSquare = DeepSquareFactory.attach(addresses.DeepSquare[networkName]); |
| 25 | + |
| 26 | + const gnosisAddress = await DeepSquare.owner(); |
| 27 | + |
| 28 | + console.log('deployer:', deployer.address); |
| 29 | + console.log('gnosis:', gnosisAddress); |
| 30 | + |
| 31 | + const votingDelegation = await new VotingDelegation__factory(deployer).deploy(DeepSquare.address); |
| 32 | + const ballotImplementation = await new Ballot__factory(deployer).deploy(DeepSquare.address, votingDelegation.address); |
| 33 | + const ballotFactory = await new BallotFactory__factory(deployer).deploy(ballotImplementation.address); |
| 34 | + |
| 35 | + if (networkName === 'fuji') { |
| 36 | + const ballotCreationTransaction = await ballotFactory.createBallot( |
| 37 | + 'Is this deployment functional ?', |
| 38 | + 'Deployment', |
| 39 | + ['Yes', 'No'], |
| 40 | + ); |
| 41 | + const cloneAddress: string = (await ballotCreationTransaction.wait()).events?.pop()?.args?.[0]; |
| 42 | + console.log('Voting clone deploy at: ', cloneAddress); |
| 43 | + const clone = new Ballot__factory(deployer).attach(cloneAddress); |
| 44 | + await DeepSquare.connect(gnosisAddress).transfer(deployer.address, parseUnits('50000', 18)); |
| 45 | + await clone.vote(0); |
| 46 | + await DeepSquare.connect(gnosisAddress).transfer(accounts[0].address, parseUnits('25000', 18)); |
| 47 | + await clone.connect(accounts[0].address).vote(0); |
| 48 | + await DeepSquare.connect(gnosisAddress).transfer(accounts[1].address, parseUnits('25000', 18)); |
| 49 | + await clone.connect(accounts[1].address).vote(1); |
| 50 | + |
| 51 | + await clone.close(); |
| 52 | + console.log('Vote results: '); |
| 53 | + const choices = await clone.getChoices(); |
| 54 | + for (const [index, result] of (await clone.getResults()).entries()) { |
| 55 | + console.log(`${choices[index]}: ${result.toString()}`); |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | + await votingDelegation.transferOwnership(gnosisAddress); |
| 60 | + await ballotImplementation.renounceOwnership(); |
| 61 | + await ballotFactory.transferOwnership(gnosisAddress); |
| 62 | +} |
| 63 | + |
| 64 | +main().catch((e) => { |
| 65 | + console.error(e); |
| 66 | + process.exit(1); |
| 67 | +}); |
0 commit comments