Skip to content

Commit

Permalink
gnosis things
Browse files Browse the repository at this point in the history
  • Loading branch information
nginnever committed Jul 1, 2021
1 parent c07b11f commit f3c42a3
Show file tree
Hide file tree
Showing 5 changed files with 242 additions and 37 deletions.
12 changes: 11 additions & 1 deletion hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
require("@nomiclabs/hardhat-waffle");
import '@openzeppelin/hardhat-upgrades';
/**
* @type import('hardhat/config').HardhatUserConfig
*/
module.exports = {
solidity: "0.8.0",
solidity: {
version: "0.8.0",
allowUnlimitedContractSize: true,
settings: {
optimizer: {
enabled: true,
runs: 200
}
}
}
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"@gnosis.pm/safe-contracts": "^1.3.0",
"@nomiclabs/hardhat-ethers": "^2.0.2",
"@nomiclabs/hardhat-waffle": "^2.0.1",
"@openzeppelin/hardhat-upgrades": "^1.9.0",
"@openzeppelin/test-environment": "^0.1.9",
"@types/chai": "^4.2.18",
"@types/mocha": "^8.2.2",
Expand Down
45 changes: 45 additions & 0 deletions test/safeTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/dist/src/signer-with-address'
import { expect } from 'chai'
import { BigNumber, Contract } from 'ethers'
import { ethers, network } from 'hardhat'
import { DAOFixture, getFixtureWithParams } from './shared/fixtures'
import { keccak256 } from 'ethereumjs-util'
import { defaultSender, provider, web3, contract } from '@openzeppelin/test-environment';

const zero = ethers.BigNumber.from(0)
const MaxUint256 = ethers.constants.MaxUint256

let daoFixture: DAOFixture
let wallet: SignerWithAddress

// TODOs:
// - figure out how to inspect nested mappings
// - figure out how to get expect reverts working

describe('houseDAOnft:', () => {
// async function createToken(totalSupply: BigNumber) {
// const { artToken } = tokenFixture
// }

beforeEach(async function () {
wallet = (await ethers.getSigners())[0]
daoFixture = await getFixtureWithParams(wallet, true)
})

it.only('house dao is initialized', async () => {
let wallet_1 = (await ethers.getSigners())[0]
const { safe } = daoFixture

// expect(await houseDAONFT.totalProposalCount()).to.equal(0)
// expect(await houseDAONFT.memberCount()).to.equal(1)
// expect(await houseDAONFT.proposalTime()).to.equal(86400)
// expect(await houseDAONFT.gracePeriod()).to.equal(259200)
// expect(await houseDAONFT.balance()).to.equal(0)
// expect(await houseDAONFT.threshold()).to.equal(5)
// expect(await houseDAONFT.nftPrice()).to.equal(ethers.utils.parseEther('0.5'))
// expect(await houseDAONFT.issuanceSupply()).to.equal(0)
// expect(await houseDAONFT.minimumProposalAmount()).to.equal(1)
// expect(await houseDAONFT.ERC721Address()).to.equal(multiNFT.address)
// expect(await houseDAONFT.WETH()).to.equal(weth.address)
})
})
108 changes: 74 additions & 34 deletions test/shared/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import GovernanceToken from '../../artifacts/contracts/common/GovernanceToken.so
import HouseDAOGov from '../../artifacts/contracts/HouseDAOGovernance.sol/HouseDAOGovernance.json'
import HouseDAONFT from '../../artifacts/contracts/HouseDAONFT.sol/HouseDAONFT.json'
import MultiNFT from '../../artifacts/contracts/test/NFT.sol/MultiArtToken.json'
import Safe from '../../artifacts/contracts/test/SafeFixture.sol/SafeFixture.json'
import ProxyFactory from '../../artifacts/contracts/test/safe/proxies/GnosisSafeProxyFactory.sol/GnosisSafeProxyFactory.json'

import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/dist/src/signer-with-address'
import "@nomiclabs/hardhat-ethers";
import { ethers } from 'hardhat'
import { ethers, upgrades } from 'hardhat'
import { deployContract } from 'ethereum-waffle'
import { Contract } from 'ethers'

Expand All @@ -15,7 +17,9 @@ export interface DAOFixture {
houseDAOGov: Contract,
houseDAONFT: Contract,
multiNFT: Contract,
govToken: Contract
govToken: Contract,
safe: Contract,
proxy: Contract
}

export async function getFixtureWithParams(
Expand All @@ -26,59 +30,95 @@ export async function getFixtureWithParams(
const wethContract = await ethers.getContractFactory("WETH9")
// deploy tokens
const weth = await wethContract.deploy()
console.log(weth.deployTransaction.gasLimit.toString())
console.log('deployed weth: ', weth.address)

const govTokenContract = await ethers.getContractFactory("GovernanceToken")
const govToken = await govTokenContract.deploy("GovToken", "GT", ethers.BigNumber.from('100000000000000000000000'))
console.log(govToken.deployTransaction.gasLimit.toString())
console.log("deployed governance token: ", govToken.address)

const multiArtToken = await ethers.getContractFactory("MultiArtToken")
const multiNFT = await multiArtToken.deploy("Walk", "TWT")
const multiNFT = await multiArtToken.deploy("Walk", "TWT")
console.log(multiNFT.deployTransaction.gasLimit.toString())
console.log('deployed TokenWalk Domain: ', multiNFT.address)
await multiNFT.mintEdition(['https://gateway.ipfs.io/ipfs/QmZuwWhEGkUKZgC2GzNrfCRKcrKbxYxskjSnTgpMQY9Dy2/metadata/'], 1, wallet.address, {gasLimit:12450000})
await multiNFT.mintEdition(['https://gateway.ipfs.io/ipfs/QmZuwWhEGkUKZgC2GzNrfCRKcrKbxYxskjSnTgpMQY9Dy2/metadata/'], 1, wallet.address, {gasLimit:12450000})
await multiNFT.mintEdition(['https://gateway.ipfs.io/ipfs/QmZuwWhEGkUKZgC2GzNrfCRKcrKbxYxskjSnTgpMQY9Dy2/metadata/'], 1, wallet.address, {gasLimit:12450000})
await multiNFT.mintEdition(['https://gateway.ipfs.io/ipfs/QmZuwWhEGkUKZgC2GzNrfCRKcrKbxYxskjSnTgpMQY9Dy2/metadata/'], 1, wallet.address, {gasLimit:12450000})

const houseGovContract = await ethers.getContractFactory("HouseDAOGovernance")
const houseDAOGov = await houseGovContract.deploy(
[wallet.address], // head of house
govToken.address, // gov token addres
//ethers.BigNumber.from(1000000), // min entry fee in gov tokens
ethers.BigNumber.from(1), // number of days proposals are active
ethers.BigNumber.from('50000000000000000000000'), // total gov tokens supplied to contract
ethers.BigNumber.from('1000000000000000000'), // number of votes wieghted to pass
ethers.BigNumber.from('10000'), // min proposal gov token amt
//ethers.BigNumber.from('1000000000000000000'), // reward for entry in gov token
weth.address
)
console.log('deployed House ERC20 DAO: ', houseDAOGov.address)
await govToken.approve(houseDAOGov.address, ethers.BigNumber.from('50000000000000000000000'))
await houseDAOGov.init()
// const houseGovContract = await ethers.getContractFactory("HouseDAOGovernance")
const houseDAOGov = await wethContract.deploy()
// const houseDAOGov = await houseGovContract.deploy(
// [wallet.address], // head of house
// govToken.address, // gov token addres
// //ethers.BigNumber.from(1000000), // min entry fee in gov tokens
// ethers.BigNumber.from(1), // number of days proposals are active
// ethers.BigNumber.from('50000000000000000000000'), // total gov tokens supplied to contract
// ethers.BigNumber.from('1000000000000000000'), // number of votes wieghted to pass
// ethers.BigNumber.from('10000'), // min proposal gov token amt
// //ethers.BigNumber.from('1000000000000000000'), // reward for entry in gov token
// weth.address
// )
// console.log('deployed House ERC20 DAO: ', houseDAOGov.address)
// await govToken.approve(houseDAOGov.address, ethers.BigNumber.from('50000000000000000000000'))
// await houseDAOGov.init()

// const houseNFTContract = await ethers.getContractFactory("HouseDAONFT")
const houseDAONFT = await wethContract.deploy()
// const houseDAONFT = await houseNFTContract.deploy(
// [wallet.address], // head of house
// multiNFT.address, // gov token addres
// //wallet.address, // nft vault address
// //ethers.BigNumber.from(1), // start index of gov tokens
// ethers.BigNumber.from(1), // number of days proposals are active
// ethers.BigNumber.from(5), // number of votes wieghted to pass
// ethers.BigNumber.from(1), // min proposal gov token amt
// //ethers.BigNumber.from(75), // issuance supply
// weth.address,
// ethers.utils.parseEther('0.5'), // price of gov token
// )
// console.log('deployed House NFT DAO: ', houseDAOGov.address)
// await multiNFT.setDAOAddress(houseDAONFT.address)
// //await multiNFT.setApprovalForAll(houseDAONFT.address, true)
// console.log('house nft dao is initialized')


const houseNFTContract = await ethers.getContractFactory("HouseDAONFT")
const houseDAONFT = await houseNFTContract.deploy(
[wallet.address], // head of house
multiNFT.address, // gov token addres
//wallet.address, // nft vault address
//ethers.BigNumber.from(1), // start index of gov tokens
ethers.BigNumber.from(1), // number of days proposals are active
ethers.BigNumber.from(5), // number of votes wieghted to pass
ethers.BigNumber.from(1), // min proposal gov token amt
//ethers.BigNumber.from(75), // issuance supply
weth.address,
ethers.utils.parseEther('0.5'), // price of gov token
const safeContract = await ethers.getContractFactory("SafeFixture")
const FactoryContract = await ethers.getContractFactory("GnosisSafeProxyFactory")
const ProxyContract = await ethers.getContractFactory("GnosisSafeProxy")
const factory = await FactoryContract.deploy()
//const safe = await safeContract.deploy()
const safeABI = ["function setup(address[] _owners, uint256 _threshold, address to, bytes data, address fallbackHandler, address paymentToken, uint256 payment, address paymentReceiver)"]
const iface = new ethers.utils.Interface(safeABI);

let owner1SafeData = await iface.encodeFunctionData(
"setup",
[[wallet.address], 1, wallet.address, "0x", wallet.address, wallet.address, 0, wallet.address]
)
console.log('deployed House NFT DAO: ', houseDAOGov.address)
await multiNFT.setDAOAddress(houseDAONFT.address)
//await multiNFT.setApprovalForAll(houseDAONFT.address, true)
console.log('house nft dao is initialized')

const safe = await upgrades.deployProxy(safeContract, [owner1SafeData], {initializer: 'setup'})

let tx = await factory.createProxy(safe.address, owner1SafeData)
let receipt = await tx.wait()
let event = receipt.events?.filter((x: any) => {return x.event == "ProxyCreation"})
let proxyAddress = event[0].args[0]
console.log(proxyAddress)
const proxy = await ProxyContract.attach(proxyAddress)
console.log(safe.deployTransaction.gasLimit.toString())
console.log('deployed Gnosis Safe: ', safe.address)
console.log(proxy)
let ownerCount = await proxy.nonce()
console.log(ownerCount)
console.log("Gnosis Safe is setup")

return {
weth,
houseDAOGov,
houseDAONFT,
multiNFT,
govToken,
safe,
proxy
}
}
Loading

0 comments on commit f3c42a3

Please sign in to comment.