Skip to content

Commit

Permalink
Post deploy scripts (#66)
Browse files Browse the repository at this point in the history
- Add initial token allocation sequence
- Add sequence to transfer roles to Multisig
- Refactor deploy lib
- Remove some unnecessary tasks

---------

Co-authored-by: vrde <[email protected]>
  • Loading branch information
sirnicolaz and vrde authored May 16, 2023
1 parent 0fbcad6 commit 386d662
Show file tree
Hide file tree
Showing 15 changed files with 180 additions and 82 deletions.
5 changes: 5 additions & 0 deletions deployments/9000.network.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,10 @@
"address": "0x4296d7b37F7d23A8910BF849E1F6ff9a80F68242",
"blockNumber": 14023638,
"blockHash": "0x6903d980644bf1b65d851fd14546e1fbc1f6652bd59b6df3ebf8b8192117e35f"
},
"ProxyAdmin": {
"address": "0x7f1E2778dA4B6c9ce90cEb27835c29e5dF29b062",
"blockNumber": 14024376,
"blockHash": "0x63d209ead3e2b72ce4d6b7ae31fb6484a29d65111cde2420aef2c600372425e3"
}
}
1 change: 0 additions & 1 deletion deployments/9000.nextstep

This file was deleted.

5 changes: 5 additions & 0 deletions deployments/9001.network.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,10 @@
"address": "0xE5714C29b7acE2C6a3A80BE511ED7e5b92594204",
"blockNumber": 12936843,
"blockHash": "0xafbb572fbf16424c757c2c6afb6ae7bffa6f4c7f2c858186fd8be6483edadd6e"
},
"ProxyAdmin": {
"address": "0xd114ec88EDF928D703E0b379BF45c1B6e877C3cC",
"blockNumber": 12935345,
"blockHash": "0x129c942e03567684477a1941fd90973c0cd970c2f8c0ac0a9447b1372fb11214"
}
}
1 change: 0 additions & 1 deletion deployments/9001.nextstep

This file was deleted.

4 changes: 3 additions & 1 deletion lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { HardhatRuntimeEnvironment } from "hardhat/types";
import {
GovernanceToken__factory,
PriceOracle__factory,
ProxyAdmin__factory,
ResolutionManager__factory,
ShareholderRegistry__factory,
TokenMock__factory,
Expand Down Expand Up @@ -53,7 +54,8 @@ type ContractFactory =
| typeof GovernanceToken__factory
| typeof Voting__factory
| typeof TokenMock__factory
| typeof PriceOracle__factory;
| typeof PriceOracle__factory
| typeof ProxyAdmin__factory;

export async function loadContract<T extends ContractFactory>(
hre: HardhatRuntimeEnvironment,
Expand Down
4 changes: 4 additions & 0 deletions lib/environment/memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
InternalMarket,
NeokingdomToken,
PriceOracle,
ProxyAdmin,
RedemptionController,
ResolutionManager,
ShareholderRegistry,
Expand Down Expand Up @@ -95,6 +96,9 @@ export class NeokingdomDAOMemory extends NeokingdomDAO {
break;
case "Voting":
this.contracts.voting = contract as Voting;
break;
case "ProxyAdmin":
this.contracts.proxyAdmin = contract as ProxyAdmin;
}
}
}
6 changes: 1 addition & 5 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
export { generateDeployContext, DEPLOY_SEQUENCE } from "./sequence/deploy";
export {
generateSetupContext,
SETUP_SEQUENCE,
STAGING_SETUP_SEQUENCE,
} from "./sequence/setup";
export { SETUP_SEQUENCE, SETUP_SEQUENCE_TESTNET } from "./sequence/setup";

export { NeokingdomDAOHardhat } from "./environment/hardhat";

Expand Down
31 changes: 31 additions & 0 deletions lib/internal/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { TransactionResponse } from "@ethersproject/providers";
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
import { Wallet } from "ethers";
import { HardhatRuntimeEnvironment } from "hardhat/types";

import {
DAORoles,
Expand All @@ -11,6 +14,8 @@ import {
NeokingdomToken__factory,
PriceOracle,
PriceOracle__factory,
ProxyAdmin,
ProxyAdmin__factory,
RedemptionController,
RedemptionController__factory,
ResolutionManager,
Expand All @@ -35,6 +40,7 @@ export const FACTORIES = {
ShareholderRegistry: ShareholderRegistry__factory,
TokenMock: TokenMock__factory,
Voting: Voting__factory,
ProxyAdmin: ProxyAdmin__factory,
} as const;

export type ContractNames = keyof typeof FACTORIES;
Expand All @@ -61,6 +67,7 @@ export type NeokingdomContracts = {
shareholderRegistry: ShareholderRegistry;
tokenMock: TokenMock;
voting: Voting;
proxyAdmin: ProxyAdmin;
};

export type Context = {};
Expand Down Expand Up @@ -93,6 +100,7 @@ export const CONTRACT_NAMES = [
"shareholderRegistry",
"tokenMock",
"voting",
"proxyAdmin",
];

export function isNeokingdomContracts(
Expand All @@ -105,3 +113,26 @@ export function isNeokingdomContracts(
}
return true;
}

export type SetupContext = ContractContext & {
deployer: Wallet | SignerWithAddress;
contributors: Contributor[];
hre: HardhatRuntimeEnvironment;
};

export function generateSetupContext(
contributors: Contributor[],
hre: HardhatRuntimeEnvironment
) {
async function _generateSetupContext(n: NeokingdomDAO) {
const contracts = (await n.loadContractsPartial()) as NeokingdomContracts;
const context: SetupContext = {
...contracts,
contributors: contributors,
deployer: n.config.deployer,
hre: hre,
};
return context;
}
return _generateSetupContext;
}
2 changes: 1 addition & 1 deletion lib/sequence/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const DEPLOY_SEQUENCE: Sequence<DeployContext> = [
c.governanceToken.address,
c.voting.address,
]),

(c) => c.deploy("ProxyAdmin"),
(c) => c.priceOracle.relay(["EUR", "USD"], [1, 1], [1, 1]),
(c) => c.priceOracle.relay(["USDC", "USD"], [1, 1], [1, 1]),

Expand Down
66 changes: 66 additions & 0 deletions lib/sequence/post.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
import { Wallet } from "ethers";
import { parseEther } from "ethers/lib/utils";
import { HardhatRuntimeEnvironment } from "hardhat/types";

import { Sequence, SetupContext } from "../internal/types";
import { ROLES } from "../utils";

const BEN = "0x0a0c93d0f0553ebf7b7bea31be6fc65e38cc9b6e";
const TELEDISKO = "0xff2B49DeD1655bb2bde369cc56437793B6baA8e8";

/*
- NEOK and NEOS:
- https://ariregister.rik.ee/eng/company/16638166/Neokingdom-DAO-O%C3%9C?active_tab=register
- Ben 0x0a0c93d0f0553ebf7b7bea31be6fc65e38cc9b6e
- mint 30000 Governance NEOK
- mint 7999 NEOS
- TelediskoDAO 0xff2B49DeD1655bb2bde369cc56437793B6baA8e8
- mint 100000 NEOK
- mint 123700 Governance NEOK
- set status to `investor`
- mint 1 NEOS
- NeokingdomDAO 0x4706eD7a10064801F260BBf94743f241FCEf815e (ShareholderRegistry)
- mint 1987 NEOS
*/

export const SETUP_SEQUENCE_VIGODARZERE: Sequence<SetupContext> = [
(c) =>
// mint 30000 NEOKGOV
c.governanceToken.mint(BEN, parseEther("30000")),
(c) =>
// mint 7999 NEOKSHARE
c.shareholderRegistry.mint(BEN, parseEther("7999")),
// TelediskoDAO 0xff2B49DeD1655bb2bde369cc56437793B6baA8e8
(c) =>
// mint 1 NEOKSHARE
c.shareholderRegistry.mint(TELEDISKO, parseEther("1")),
(c) =>
// set status to `investor`
c.shareholderRegistry.setStatus(
c.shareholderRegistry.INVESTOR_STATUS(),
TELEDISKO
),
(c) =>
// mint 223700 NEOKGOV
c.governanceToken.mint(TELEDISKO, parseEther("223700")),
// NeokingdomDAO 0x4706eD7a10064801F260BBf94743f241FCEf815e (ShareholderRegistry)
(c) =>
// mint 1987 NEOKSHARE
c.shareholderRegistry.mint(
c.shareholderRegistry.address,
parseEther("1987")
),
];

export function finalizeACL(multisig: string): Sequence<SetupContext> {
return [
(c) => c.daoRoles.grantRole(ROLES.DEFAULT_ADMIN_ROLE, multisig),
(c) => c.daoRoles.grantRole(ROLES.OPERATOR_ROLE, multisig),
(c) => c.daoRoles.grantRole(ROLES.RESOLUTION_ROLE, multisig),
(c) => c.proxyAdmin.transferOwnership(multisig),
(c) => c.daoRoles.revokeRole(ROLES.RESOLUTION_ROLE, c.deployer.address),
(c) => c.daoRoles.revokeRole(ROLES.OPERATOR_ROLE, c.deployer.address),
(c) => c.daoRoles.revokeRole(ROLES.DEFAULT_ADMIN_ROLE, c.deployer.address),
];
}
28 changes: 3 additions & 25 deletions lib/sequence/setup.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,8 @@
import { BigNumber } from "ethers";
import { parseEther } from "ethers/lib/utils";

import { NeokingdomDAO, expandable } from "../internal/core";
import {
ContextGenerator,
ContractContext,
Contributor,
NeokingdomContracts,
Sequence,
} from "../internal/types";

export type SetupContext = ContractContext & {
contributors: Contributor[];
};

export function generateSetupContext(contributors: Contributor[]) {
async function _generateSetupContext(n: NeokingdomDAO) {
const contracts = (await n.loadContractsPartial()) as NeokingdomContracts;
const context: SetupContext = {
...contracts,
contributors: contributors,
};
return context;
}
return _generateSetupContext;
}
import { expandable } from "../internal/core";
import { Sequence, SetupContext } from "../internal/types";

export const SETUP_SEQUENCE: Sequence<SetupContext> = [
// Give each address one share
Expand Down Expand Up @@ -72,7 +50,7 @@ export const SETUP_SEQUENCE: Sequence<SetupContext> = [
),
];

export const STAGING_SETUP_SEQUENCE: Sequence<SetupContext> = [
export const SETUP_SEQUENCE_TESTNET: Sequence<SetupContext> = [
...SETUP_SEQUENCE,
// Add testing resolution type
(c) =>
Expand Down
13 changes: 13 additions & 0 deletions lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import { Contract, Wallet } from "ethers";
import { keccak256, parseEther, toUtf8Bytes } from "ethers/lib/utils";
import { readFile, writeFile } from "fs/promises";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import * as readline from "readline";

import {
DAORoles,
GovernanceToken,
InternalMarket,
NeokingdomToken,
PriceOracle,
ProxyAdmin,
RedemptionController,
ResolutionManager,
ShareholderRegistry,
Expand Down Expand Up @@ -214,6 +216,7 @@ export async function loadContracts(
),
tokenMock: await _loadContract<TokenMock>("TokenMock"),
voting: await _loadContract<Voting>("Voting"),
proxyAdmin: await _loadContract<ProxyAdmin>("ProxyAdmin"),
};
}

Expand Down Expand Up @@ -275,3 +278,13 @@ export async function getWallet(hre: HardhatRuntimeEnvironment) {
// Create the signer for the mnemonic, connected to the provider with hardcoded fee data
return new ethers.Wallet(privateKey).connect(provider);
}

const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});

export const question = (prompt: string) =>
new Promise<string>((resolve) => {
rl.question(prompt, resolve);
});
55 changes: 48 additions & 7 deletions tasks/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@ import {
DEPLOY_SEQUENCE,
NeokingdomDAOHardhat,
SETUP_SEQUENCE,
STAGING_SETUP_SEQUENCE,
generateDeployContext,
generateSetupContext,
} from "../lib";
import { generateSetupContext } from "../lib/internal/types";
import { SETUP_SEQUENCE_VIGODARZERE, finalizeACL } from "../lib/sequence/post";
import { SETUP_SEQUENCE_TESTNET } from "../lib/sequence/setup";
import { question } from "../lib/utils";

const MULTISIG_MAINNET = "0xd232121c41EF9ad4e4d0251BdCbe60b9F3D20758";
const MULTISIG_TESTNET = "0x7549fe2ED3c16240f97FE736146347409C6dD81D";

task("deploy", "Deploy DAO")
.addFlag("verify", "Verify contracts")
Expand All @@ -24,11 +29,11 @@ task("deploy", "Deploy DAO")
);

task("setup", "Set up the DAO")
.addFlag("prod", "Go to prod")
.setAction(async ({ prod }: { prod: boolean }, hre) => {
let sequence = STAGING_SETUP_SEQUENCE;
.addFlag("mainnet", "Go to Mainnet")
.setAction(async ({ mainnet }: { mainnet: boolean }, hre) => {
let sequence = SETUP_SEQUENCE_TESTNET;
let contributorsFile = "./dev-wallets.json";
if (prod) {
if (mainnet) {
sequence = SETUP_SEQUENCE;
contributorsFile = "./prod-wallets.json";
}
Expand All @@ -37,5 +42,41 @@ task("setup", "Set up the DAO")
const neokingdom = await NeokingdomDAOHardhat.initialize(hre, {
verbose: true,
});
await neokingdom.run(generateSetupContext(contributors), sequence);
await neokingdom.run(generateSetupContext(contributors, hre), sequence);
});

task("setup:vigodarzere", "Set up the DAO").setAction(async (_, hre) => {
let sequence = SETUP_SEQUENCE_VIGODARZERE;

const neokingdom = await NeokingdomDAOHardhat.initialize(hre, {
verbose: true,
});
await neokingdom.run(generateSetupContext([], hre), sequence);
});

task("setup:acl", "Set up ACL")
.addFlag("mainnet", "Go to mainnet")
.setAction(async ({ mainnet }: { mainnet: boolean }, hre) => {
let multisig = MULTISIG_TESTNET;
if (mainnet) {
multisig = MULTISIG_MAINNET;
}

console.log(
`Transferring rights and ProxyAdmin ownership to ${multisig} on ${
mainnet ? "Mainnet" : "Testnet"
}.`
);
const answer = await question(
"This action is irreversible. Please type 'GO' to continue.\n"
);

if (answer == "GO") {
let sequence = finalizeACL(multisig);

const neokingdom = await NeokingdomDAOHardhat.initialize(hre, {
verbose: true,
});
await neokingdom.run(generateSetupContext([], hre), sequence);
}
});
1 change: 0 additions & 1 deletion tasks/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import "./delegate";
import "./deploy";
import "./match";
import "./oracle";
import "./resolution";
import "./role";
Expand Down
Loading

0 comments on commit 386d662

Please sign in to comment.