Skip to content

Commit

Permalink
Update deployment scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
bill-clippy committed Jul 12, 2023
1 parent a480c29 commit 7c60353
Show file tree
Hide file tree
Showing 13 changed files with 492 additions and 457 deletions.
7 changes: 2 additions & 5 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,5 @@ GOVERNANCE_TIMELOCK_DELAY=86400
# Launch date (YYYY-MM-DD). It must be a Thursday.
GOVERNANCE_LAUNCH_DATE=1970-01-01

# Anyswap Router address
ANYSWAP_ROUTER=0x0000000000000000000000000000000000000000;

# AnyCall proxy address
ANY_CALL_PROXY=0x0000000000000000000000000000000000000000;
# LayerZero endpoint.
LZ_ENDPOINT=0x0000000000000000000000000000000000000000;
3 changes: 1 addition & 2 deletions config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,5 @@ export const GOVERNANCE_CONFIG = {
LAUNCH_TIMESTAMP: endOfWeek(
new Date(process.env.GOVERNANCE_LAUNCH_DATE ?? "1970-01-01").getTime() / 1000
),
ANYSWAP_ROUTER: process.env.ANYSWAP_ROUTER,
ANY_CALL_PROXY: process.env.ANY_CALL_PROXY,
LZ_ENDPOINT: process.env.LZ_ENDPOINT,
};
4 changes: 2 additions & 2 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "@nomiclabs/hardhat-etherscan";
import "solidity-coverage";
import "./tasks/accounts";
import "./tasks/deploy_address_whitelist";
import "./tasks/deploy_anyswap_chess_pool";
import "./tasks/deploy_chess_pool";
import "./tasks/deploy_bsc_apr_oracle";
import "./tasks/deploy_bsc_staking_strategy";
import "./tasks/deploy_chess_controller_impl";
Expand All @@ -27,7 +27,7 @@ import "./tasks/deploy_sub_governance";
import "./tasks/deploy_swap_router";
import "./tasks/deploy_flash_swap_router";
import "./tasks/deploy_data_aggregator";
import "./tasks/dev_deploy_anyswap";
import "./tasks/dev_deploy_lz";
import "./tasks/dev_deploy_curve";
import "./tasks/dev_deploy_deposit_contract";
import "./tasks/dev_deploy_token_hub";
Expand Down
33 changes: 0 additions & 33 deletions tasks/deploy_anyswap_chess_pool.ts

This file was deleted.

32 changes: 32 additions & 0 deletions tasks/deploy_chess_pool.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { task } from "hardhat/config";
import { GOVERNANCE_CONFIG } from "../config";
import { Addresses, loadAddressFile, newAddresses, saveAddressFile } from "./address_file";
import type { GovernanceAddresses } from "./deploy_governance";
import { updateHreSigner } from "./signers";

export interface ChessPoolAddresses extends Addresses {
chessPool: string;
}

task("deploy_chess_pool", "Deploy LzChessPool")
.addOptionalParam("chess", "Chess contract address", "")
.setAction(async function (args, hre) {
await updateHreSigner(hre);
const { ethers } = hre;
await hre.run("compile");

const chessAddress =
args.chess || loadAddressFile<GovernanceAddresses>(hre, "governance").chess;

const ChessPool = await ethers.getContractFactory("ProxyOFTPool");
const chessPool = await ChessPool.deploy(GOVERNANCE_CONFIG.LZ_ENDPOINT, chessAddress);
console.log(`ChessPool: ${chessPool.address}`);

await chessPool.setUseCustomAdapterParams(true);

const addresses: ChessPoolAddresses = {
...newAddresses(hre),
chessPool: chessPool.address,
};
saveAddressFile(hre, `chess_pool`, addresses);
});
17 changes: 9 additions & 8 deletions tasks/deploy_chess_schedule_relayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface ChessScheduleRelayerAddresses extends Addresses {

task("deploy_chess_schedule_relayer", "Deploy ChessScheduleRelayer")
.addFlag("dry", "Get contract address without deploying it")
.addParam("chainId", "Sub chain ID")
.addParam("lzChainId", "LayerZero sub chain ID")
.addParam("subSchedule", "Address of ChessSubSchedule on the sub chain")
.setAction(async function (args, hre) {
await updateHreSigner(hre);
Expand All @@ -28,25 +28,26 @@ task("deploy_chess_schedule_relayer", "Deploy ChessScheduleRelayer")
return;
}

const chainId = parseInt(args.chainId);
assert.ok(chainId > 0 && chainId < 1e9, "Invalid sub chain ID");
const lzChainId = parseInt(args.lzChainId);
assert.ok(lzChainId > 0 && lzChainId < 1e9, "Invalid sub chain ID");
const subSchedule = args.subSchedule;
const governanceAddresses = loadAddressFile<GovernanceAddresses>(hre, "governance");

const ChessScheduleRelayer = await ethers.getContractFactory("ChessScheduleRelayer");
const relayer = await ChessScheduleRelayer.deploy(
chainId,
subSchedule,
lzChainId,
governanceAddresses.chessSchedule,
governanceAddresses.chessController,
governanceAddresses.anyswapChessPool,
GOVERNANCE_CONFIG.ANY_CALL_PROXY
governanceAddresses.chessPool,
GOVERNANCE_CONFIG.LZ_ENDPOINT
);
console.log(`ChessScheduleRelayer: ${relayer.address}`);

await relayer.setTrustedRemoteAddress(lzChainId, subSchedule);

const addresses: ChessScheduleRelayerAddresses = {
...newAddresses(hre),
relayer: relayer.address,
};
saveAddressFile(hre, `chess_schedule_relayer_${chainId}`, addresses);
saveAddressFile(hre, `chess_schedule_relayer_${lzChainId}`, addresses);
});
18 changes: 4 additions & 14 deletions tasks/deploy_data_aggregator.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { strict as assert } from "assert";
import { task } from "hardhat/config";
import { Addresses, saveAddressFile, loadAddressFile, newAddresses } from "./address_file";
import { Addresses, loadAddressFile, newAddresses, saveAddressFile } from "./address_file";
import type { FlashSwapRouterAddresses } from "./deploy_flash_swap_router";
import type { GovernanceAddresses } from "./deploy_governance";
import type { StableSwapAddresses } from "./deploy_stable_swap";
import type { SwapRouterAddresses } from "./deploy_swap_router";
import type { FlashSwapRouterAddresses } from "./deploy_flash_swap_router";
import { GOVERNANCE_CONFIG } from "../config";
import { updateHreSigner } from "./signers";

export interface DataAggregatorAddresses extends Addresses {
Expand All @@ -14,20 +12,12 @@ export interface DataAggregatorAddresses extends Addresses {

task("deploy_data_aggregator", "Deploy data aggregator")
.addParam("firstUnderlyingSymbol", "Fund0 underlying symbols")
.addParam("otherChainIds", "Comma-separated chain IDs")
.setAction(async function (args, hre) {
await updateHreSigner(hre);
const { ethers } = hre;
await hre.run("compile");

const firstUnderlyingSymbol = args.firstUnderlyingSymbol;
const otherChainIds: number[] = args.otherChainIds
.split(",")
.filter(Boolean)
.map((x: string) => parseInt(x));
for (const chainId of otherChainIds) {
assert.ok(chainId > 0 && chainId < 1e9, "Invalid chain ID");
}

const governanceAddresses = loadAddressFile<GovernanceAddresses>(hre, "governance");
const swapRouterAddresses = loadAddressFile<SwapRouterAddresses>(hre, "swap_router");
Expand All @@ -49,8 +39,8 @@ task("deploy_data_aggregator", "Deploy data aggregator")
swapRouterAddresses.swapRouter,
flashSwapRouterAddresses.flashSwapRouter,
bishopStableSwapAddress.quote,
GOVERNANCE_CONFIG.ANY_CALL_PROXY,
otherChainIds
ethers.constants.AddressZero,
[]
);
console.log(`Data Aggregator: ${dataAggregator.address}`);

Expand Down
30 changes: 14 additions & 16 deletions tasks/deploy_governance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import type { ChessScheduleImplAddresses } from "./deploy_chess_schedule_impl";
import type { VotingEscrowImplAddresses } from "./deploy_voting_escrow_impl";
import type { ControllerBallotAddresses } from "./deploy_controller_ballot";
import type { ChessControllerImplAddresses } from "./deploy_chess_controller_impl";
import type { AnyswapChessPoolAddresses } from "./deploy_anyswap_chess_pool";
import type { ChessPoolAddresses } from "./deploy_chess_pool";
import { GOVERNANCE_CONFIG } from "../config";
import { updateHreSigner } from "./signers";

export interface GovernanceAddresses extends Addresses {
timelockController: string;
proxyAdmin: string;
chess: string;
anyswapChessPool: string;
chessPool: string;
chessScheduleImpl: string;
chessSchedule: string;
votingEscrowImpl: string;
Expand Down Expand Up @@ -79,24 +79,24 @@ task("deploy_governance", "Deploy governance contracts", async function (_args,
const chessSchedule = ChessSchedule.attach(chessScheduleProxy.address);
console.log(`ChessSchedule: ${chessSchedule.address}`);

await hre.run("deploy_anyswap_chess_pool", {
await hre.run("deploy_chess_pool", {
chess: chess.address,
});
const anyswapChessPool = await ethers.getContractAt(
"AnyswapChessPool",
loadAddressFile<AnyswapChessPoolAddresses>(hre, "anyswap_chess_pool").anyswapChessPool
const chessPool = await ethers.getContractAt(
"ProxyOFTPool",
loadAddressFile<ChessPoolAddresses>(hre, "chess_pool").chessPool
);
console.log(`AnyswapChessPool: ${anyswapChessPool.address}`);
console.log(`ChessPool: ${chessPool.address}`);

await hre.run("deploy_voting_escrow_impl", {
chess: chess.address,
anyswapChess: anyswapChessPool.address,
chessPool: chessPool.address,
});
const votingEscrowImplAddresses = loadAddressFile<VotingEscrowImplAddresses>(
hre,
"voting_escrow_v3_impl"
"voting_escrow_v4_impl"
);
const VotingEscrow = await ethers.getContractFactory("VotingEscrowV3");
const VotingEscrow = await ethers.getContractFactory("VotingEscrowV4");
const votingEscrowImpl = VotingEscrow.attach(votingEscrowImplAddresses.votingEscrowImpl);

const votingEscrowInitTx = await votingEscrowImpl.populateTransaction.initialize(
Expand Down Expand Up @@ -155,22 +155,20 @@ task("deploy_governance", "Deploy governance contracts", async function (_args,
const chessController = ChessController.attach(chessControllerProxy.address);
console.log(`ChessController: ${chessController.address}`);

console.log("Set VotingEscrow and AnyswapRouter to be CHESS minters");
await anyswapChessPool.addMinter(votingEscrow.address);
await anyswapChessPool.addMinter(GOVERNANCE_CONFIG.ANYSWAP_ROUTER);
// TODO transfer owner
console.log("Set VotingEscrow to be CHESS minters");
await chessPool.addMinter(votingEscrow.address);

console.log("Transfering ownership to TimelockController");
await proxyAdmin.transferOwnership(timelockController.address);
await anyswapChessPool.transferOwnership(timelockController.address);
await chessPool.transferOwnership(timelockController.address);
await votingEscrow.transferOwnership(timelockController.address);

const addresses: GovernanceAddresses = {
...newAddresses(hre),
timelockController: timelockController.address,
proxyAdmin: proxyAdmin.address,
chess: chess.address,
anyswapChessPool: anyswapChessPool.address,
chessPool: chessPool.address,
chessScheduleImpl: chessScheduleImpl.address,
chessSchedule: chessSchedule.address,
votingEscrowImpl: votingEscrowImpl.address,
Expand Down
45 changes: 23 additions & 22 deletions tasks/deploy_sub_governance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import type { GovernanceAddresses } from "./deploy_governance";
import type { VotingEscrowImplAddresses } from "./deploy_voting_escrow_impl";
import type { ControllerBallotAddresses } from "./deploy_controller_ballot";
import type { ChessControllerImplAddresses } from "./deploy_chess_controller_impl";
import type { AnyswapChessPoolAddresses } from "./deploy_anyswap_chess_pool";
import type { ChessPoolAddresses } from "./deploy_chess_pool";
import { GOVERNANCE_CONFIG } from "../config";
import { updateHreSigner } from "./signers";

task("deploy_sub_governance", "Deploy sub chain governance contracts")
.addParam("mainChainId", "Main chain ID")
.addParam("mainLzChainId", "Main LayerZero chain ID")
.addParam("mainChainRelayer", "ChessScheduleRelayer address on the main chain")
.setAction(async function (args, hre) {
await updateHreSigner(hre);
Expand All @@ -18,7 +18,7 @@ task("deploy_sub_governance", "Deploy sub chain governance contracts")
await hre.run("compile");
const [deployer] = await ethers.getSigners();

const mainChainId = parseInt(args.mainChainId);
const mainLzChainId = parseInt(args.mainLzChainId);
const mainChainRelayer = args.mainChainRelayer;

const TimelockController = await ethers.getContractFactory("TimelockController");
Expand All @@ -44,24 +44,24 @@ task("deploy_sub_governance", "Deploy sub chain governance contracts")
);
console.log(`Chess: ${chess.address}`);

await hre.run("deploy_anyswap_chess_pool", {
await hre.run("deploy_chess_pool", {
chess: chess.address,
});
const anyswapChessPool = await ethers.getContractAt(
"AnyswapChessPool",
loadAddressFile<AnyswapChessPoolAddresses>(hre, "anyswap_chess_pool").anyswapChessPool
const chessPool = await ethers.getContractAt(
"ProxyOFTPool",
loadAddressFile<ChessPoolAddresses>(hre, "chess_pool").chessPool
);
console.log(`AnyswapChessPool: ${anyswapChessPool.address}`);
console.log(`ChessPool: ${chessPool.address}`);

await hre.run("deploy_voting_escrow_impl", {
chess: chess.address,
anyswapChess: chess.address,
chessPool: chessPool.address,
});
const votingEscrowImplAddresses = loadAddressFile<VotingEscrowImplAddresses>(
hre,
"voting_escrow_v3_impl"
"voting_escrow_v4_impl"
);
const VotingEscrow = await ethers.getContractFactory("VotingEscrowV3");
const VotingEscrow = await ethers.getContractFactory("VotingEscrowV4");
const votingEscrowImpl = VotingEscrow.attach(votingEscrowImplAddresses.votingEscrowImpl);

const votingEscrowInitTx = await votingEscrowImpl.populateTransaction.initialize(
Expand Down Expand Up @@ -125,11 +125,10 @@ task("deploy_sub_governance", "Deploy sub chain governance contracts")

const ChessSubSchedule = await ethers.getContractFactory("ChessSubSchedule");
const chessSubScheduleImpl = await ChessSubSchedule.deploy(
mainChainId,
mainChainRelayer,
mainLzChainId,
controllerBallot.address,
chess.address,
GOVERNANCE_CONFIG.ANY_CALL_PROXY
chessPool.address,
GOVERNANCE_CONFIG.LZ_ENDPOINT
);
console.log(`ChessSubSchedule implementation: ${chessSubScheduleImpl.address}`);

Expand All @@ -143,25 +142,27 @@ task("deploy_sub_governance", "Deploy sub chain governance contracts")
const chessSubSchedule = ChessSubSchedule.attach(chessSubScheduleProxy.address);
console.log(`ChessSubSchedule: ${chessSubSchedule.address}`);

console.log("Set VotingEscrow, ChessSubSchedule and AnyswapRouter to be CHESS minters");
await chess.addMinter(votingEscrow.address);
await chess.addMinter(chessSubSchedule.address);
console.log("Set ChessSubSchedule's trusted remote address");
await chessSubSchedule.setTrustedRemoteAddress(mainLzChainId, mainChainRelayer);

console.log("Set VotingEscrow, ChessSubSchedule to be CHESS minters");
await chessPool.addMinter(votingEscrow.address);
await chessPool.addMinter(chessSubSchedule.address);
await chess.addMinter(timelockController.address);
await anyswapChessPool.addMinter(GOVERNANCE_CONFIG.ANYSWAP_ROUTER);
await anyswapChessPool.addMinter(timelockController.address);
await chessPool.addMinter(timelockController.address);

console.log("Transfering ownership to TimelockController");
await chess.transferOwnership(timelockController.address);
await proxyAdmin.transferOwnership(timelockController.address);
await anyswapChessPool.transferOwnership(timelockController.address);
await chessPool.transferOwnership(timelockController.address);
await votingEscrow.transferOwnership(timelockController.address);

const addresses: GovernanceAddresses = {
...newAddresses(hre),
timelockController: timelockController.address,
proxyAdmin: proxyAdmin.address,
chess: chess.address,
anyswapChessPool: anyswapChessPool.address,
chessPool: chessPool.address,
chessScheduleImpl: chessSubScheduleImpl.address,
chessSchedule: chessSubSchedule.address,
votingEscrowImpl: votingEscrowImpl.address,
Expand Down
Loading

0 comments on commit 7c60353

Please sign in to comment.