Skip to content

Commit

Permalink
deployments scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
mobycrypt committed Sep 5, 2023
1 parent e973317 commit 77c3b16
Show file tree
Hide file tree
Showing 13 changed files with 93 additions and 96 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ typechain-types
cache
artifacts

deployments/
12 changes: 6 additions & 6 deletions contracts/dao/factory/DaoFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ import "../Dao.sol";

abstract contract DaoFactory {

mapping(bytes => Dao) private daos;
Dao[] private daos;

uint256 public defaultChallengePeriodSeconds = 7 days;
uint256 public nativeCollateral = 1 ether;

event DaoCreated(address daoAddress);

function createDao(bytes memory daoId, address tokenAddress, uint256 tokenCollateral) public {
require(address(daos[daoId]) == address(0), 'Dao already exists');
daos[daoId] = initializeDao(tokenAddress, tokenCollateral);
emit DaoCreated(address(daos[daoId]));
function createDao(address tokenAddress, uint256 tokenCollateral) public {
Dao dao = initializeDao(tokenAddress, tokenCollateral);
daos.push(dao);
emit DaoCreated(address(dao));
}

function initializeDao(address tokenAddress, uint256 tokenCollateral) public virtual returns (Dao);
function initializeDao(address tokenAddress, uint256 tokenCollateral) internal virtual returns (Dao);
}
2 changes: 1 addition & 1 deletion contracts/dao/factory/ERC20DaoFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "../ERC20Dao.sol";

contract ERC20DaoFactory is DaoFactory {

function initializeDao(address tokenAddress, uint256 tokenCollateral) override public returns (Dao) {
function initializeDao(address tokenAddress, uint256 tokenCollateral) override internal returns (Dao) {
return new ERC20Dao(tokenAddress, tokenCollateral, defaultChallengePeriodSeconds, nativeCollateral);
}
}
2 changes: 1 addition & 1 deletion contracts/dao/factory/NFTDaoFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "../NFTDao.sol";

contract NFTDaoFactory is DaoFactory {

function initializeDao(address tokenAddress, uint256 tokenCollateral) override public returns (Dao) {
function initializeDao(address tokenAddress, uint256 tokenCollateral) override internal returns (Dao) {
return new NFTDao(tokenAddress, tokenCollateral, defaultChallengePeriodSeconds, nativeCollateral);
}
}
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion info.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
1. `nvm use 18.10.0`
2. First run local node with `npx hardhat node` then deploy with `npx hardhat run scripts/deploy-dao-factory.ts --network local`
2. First run local node with `npx hardhat node` then deploy with `npx hardhat run scripts/deploy-dao-factories.ts --network local`
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"deploy-dao-factories-local": "npx hardhat run --network local scripts/deploy-dao-factories.ts",
"deploy-dev-tokens-local": "npx hardhat run --network local scripts/deploy-development-tokens.ts",
"send-tokens-to-dao-local": "npx hardhat run --network local scripts/send-to-dao.ts"
},
"keywords": [],
"author": "",
Expand Down
29 changes: 29 additions & 0 deletions scripts/deploy-dao-factories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { ethers, network } from 'hardhat';
import * as fs from 'fs';

async function main() {
const currentNetwork = network.name;

const erc20DaoFactory = await ethers.deployContract('ERC20DaoFactory', []);
await erc20DaoFactory.deployed();
const erc20DaoFactoryAddress = erc20DaoFactory.address;

const nftDaoFactory = await ethers.deployContract('NFTDaoFactory', []);
await nftDaoFactory.deployed();
const nftDaoFactoryAddress = nftDaoFactory.address;

if (!fs.existsSync('deployments')) {
fs.mkdirSync('deployments');
}
fs.writeFileSync(
`deployments/dao-factories-${currentNetwork}.json`,
JSON.stringify({
erc20DaoFactoryAddress: erc20DaoFactoryAddress,
nftDaoFactoryAddress: nftDaoFactoryAddress,
}, null, 2));
}

main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
64 changes: 0 additions & 64 deletions scripts/deploy-dao-factory.ts

This file was deleted.

30 changes: 30 additions & 0 deletions scripts/deploy-development-tokens.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { ethers, network } from 'hardhat';
import * as fs from 'fs';
import { parseUnits } from 'ethers/lib/utils';
import { BigNumber } from 'ethers';

async function main() {
const currentNetwork = network.name;

const erc20Development = await ethers.deployContract('ERC20Development', [
"My token","TOK", parseUnits("10000", 21),
]);
await erc20Development.deployed();

const erc721Development = await ethers.deployContract('ERC721Development', []);

if (!fs.existsSync('deployments')) {
fs.mkdirSync('deployments');
}
await erc721Development.deployed();
fs.writeFileSync(
`deployments/dev-tokens-${currentNetwork}.json`,
JSON.stringify({
erc20Address: erc20Development.address,
nftAddress: erc721Development.address,
}, null, 2));
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});
36 changes: 20 additions & 16 deletions scripts/send-to-dao.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
import { ethers } from 'hardhat';
import { Contract } from 'ethers';
import { readFileSync } from 'fs';

async function main() {
//TODO provide dao address
const daoAddress = '0xa8aFC8e510393213ea6c181c37bf273718e7C353';
const a = ['function transfer(address recipient, uint256 amount) external returns (bool)'];
//token address
//TODO provide token address
const contract = new Contract('0x9931e9395c7700F1b017Fd9CfC0D56c250000727', a, ethers.provider.getSigner());
// TODO provide dao address
const daoAddress = '0xA6FE3d32e2685E9A1Cb95a718b01160f1FF95e39';

await contract.transfer(daoAddress, ethers.utils.parseUnits('100', 21));
const abi = ['function transfer(address recipient, uint256 amount) external returns (bool)'];
const nftAbi = ['function createNFT(address,string) external returns (uint256)'];

console.log(`Transfer 100 tokens to DAO: ${daoAddress}`);
let file;
try {
file = JSON.parse(readFileSync('deployments/dev-tokens-local.json', 'utf8'));
} catch (e) {
console.log('No local deployment done! Deploy tokens first!');
return;
}
const contract = new Contract(file.erc20Address, abi, ethers.provider.getSigner());
await contract.transfer(daoAddress, ethers.utils.parseUnits('100', 18));
console.log(`Transferred 100 tokens to DAO: ${daoAddress}`);

const token = await ethers.deployContract('ERC721Development');
await token.deployed();

console.log(`NFT deployed to ${token.address}`);
const nft = new Contract(file.nftAddress, nftAbi, ethers.provider.getSigner());
const signer = (await ethers.getSigners())[0];
await token.createNFT(signer.address, 'https://arweave.net/gTzo012IdW-2nYxsWdX4y1jB4eC7ZljT4oBO9AFrJZ8\n');
console.log(`Created NFT for ${signer.address}`);
await token.createNFT(daoAddress, 'https://arweave.net/gTzo012IdW-2nYxsWdX4y1jB4eC7ZljT4oBO9AFrJZ8\n');
console.log(`Created NFT for ${daoAddress}`);
await nft.createNFT(signer.address, 'https://arweave.net/gTzo012IdW-2nYxsWdX4y1jB4eC7ZljT4oBO9AFrJZ8\n');
console.log(`Created NFT 0 for ${signer.address}`);
await nft.createNFT(daoAddress, 'https://arweave.net/gTzo012IdW-2nYxsWdX4y1jB4eC7ZljT4oBO9AFrJZ8\n');
console.log(`Created NFT 1 for DAO ${daoAddress}`);
}

main().catch((error) => {
Expand Down
6 changes: 0 additions & 6 deletions test/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ export async function deployNftToken(): Promise<ERC721> {

export async function deployErc20Dao(tokenAddress: string, challengePeriodSeconds: number): Promise<{ dao: ERC20Dao; ERC20DaoPool: ERC20DaoPool }> {
const dao = (await ethers.deployContract('ERC20Dao', [tokenAddress, TOKEN_COLLATERAL, challengePeriodSeconds, NATIVE_COLLATERAL])) as ERC20Dao;
dao.on('DaoPoolCreated', (poolAddress: string) => {
LOGGER.debug(`ERC20 DAO pool created at ${poolAddress}`);
});
await dao.deployed();
// @dev there was a problem with .on listener and it didn't work for multiple tests
const result = await dao.deployTransaction.wait();
Expand All @@ -45,9 +42,6 @@ export async function deployErc20Dao(tokenAddress: string, challengePeriodSecond

export async function deployNftDao(tokenAddress: string, challengePeriodSeconds: number): Promise<{ dao: NFTDao; NFTDaoPool: NFTDaoPool }> {
const dao = (await ethers.deployContract('NFTDao', [tokenAddress, TOKEN_NFT_COLLATERAL, challengePeriodSeconds, NATIVE_COLLATERAL])) as NFTDao;
dao.on('DaoPoolCreated', (poolAddress: string) => {
LOGGER.debug(`NFT DAO pool created at ${poolAddress}`);
});
await dao.deployed();
// @dev there was a problem with .on listener and it didn't work for multiple tests
const result = await dao.deployTransaction.wait();
Expand Down

0 comments on commit 77c3b16

Please sign in to comment.