UNPKG

@dydxfoundation/governance

Version:
127 lines (126 loc) 6.12 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.deployPhase1 = void 0; const types_1 = require("../../types"); const deploy_config_1 = require("../deploy-config"); const get_deployer_address_1 = require("../deploy-config/get-deployer-address"); const constants_1 = require("../lib/constants"); const logging_1 = require("../lib/logging"); const util_1 = require("../lib/util"); const deploy_executor_1 = require("./helpers/deploy-executor"); const transfer_tokens_1 = require("./helpers/transfer-tokens"); async function deployPhase1({ startStep = 0, dydxTokenAddress, governorAddress, longTimelockAddress, shortTimelockAddress, merklePauserTimelockAddress, } = {}) { (0, logging_1.log)('Beginning phase 1 deployment\n'); const deployConfig = (0, deploy_config_1.getDeployConfig)(); const deployer = await (0, get_deployer_address_1.getDeployerSigner)(); const deployerAddress = deployer.address; (0, logging_1.log)(`Beginning deployment with deployer ${deployerAddress}\n`); // Phase 1 deployed contracts. let dydxToken; let governor; let longTimelock; let shortTimelock; let merklePauserTimelock; if (startStep <= 1) { (0, logging_1.log)('Step 1. Deploy DYDX token'); dydxToken = await new types_1.DydxToken__factory(deployer).deploy(deployerAddress, deployConfig.TRANSFERS_RESTRICTED_BEFORE, deployConfig.TRANSFER_RESTRICTION_LIFTED_NO_LATER_THAN, deployConfig.MINTING_RESTRICTED_BEFORE, deployConfig.MINT_MAX_PERCENT); await (0, util_1.waitForTx)(dydxToken.deployTransaction); dydxTokenAddress = dydxToken.address; } else { if (!dydxTokenAddress) { throw new Error('Expected parameter dydxTokenAddress to be specified.'); } dydxToken = new types_1.DydxToken__factory(deployer).attach(dydxTokenAddress); } if (startStep <= 2) { (0, logging_1.log)('Step 2. Deploy governor'); governor = await new types_1.DydxGovernor__factory(deployer).deploy( // Phase 1 does not include the incentives contracts, including the safety module, so we // can't deploy the governance strategy yet. constants_1.ZERO_ADDRESS, deployConfig.VOTING_DELAY_BLOCKS, deployerAddress); await (0, util_1.waitForTx)(governor.deployTransaction); governorAddress = governor.address; } else { if (!governorAddress) { throw new Error('Expected parameter governorAddress to be specified.'); } governor = new types_1.DydxGovernor__factory(deployer).attach(governorAddress); } if (startStep <= 3) { (0, logging_1.log)('Step 3. Deploy long timelock'); longTimelock = await (0, deploy_executor_1.deployExecutor)(deployer, governorAddress, deployConfig.LONG_TIMELOCK_CONFIG); longTimelockAddress = longTimelock.address; } else { if (!longTimelockAddress) { throw new Error('Expected parameter longTimelockAddress to be specified.'); } longTimelock = new types_1.Executor__factory(deployer).attach(longTimelockAddress); } if (startStep <= 4) { (0, logging_1.log)('Step 4. Deploy short timelock'); shortTimelock = await (0, deploy_executor_1.deployExecutor)(deployer, governorAddress, deployConfig.SHORT_TIMELOCK_CONFIG); shortTimelockAddress = shortTimelock.address; } else { if (!shortTimelockAddress) { throw new Error('Expected parameter shortTimelockAddress to be specified.'); } shortTimelock = new types_1.Executor__factory(deployer).attach(shortTimelockAddress); } if (startStep <= 5) { (0, logging_1.log)('Step 5. Deploy merkle timelock'); merklePauserTimelock = await (0, deploy_executor_1.deployExecutor)(deployer, governorAddress, deployConfig.MERKLE_PAUSER_TIMELOCK_CONFIG); merklePauserTimelockAddress = merklePauserTimelock.address; } else { if (!merklePauserTimelockAddress) { throw new Error('Expected parameter merklePauserTimelockAddress to be specified.'); } merklePauserTimelock = new types_1.Executor__factory(deployer).attach(merklePauserTimelockAddress); } if (startStep <= 6) { (0, logging_1.log)('Step 6. Authorize timelocks on governance contract'); await (0, util_1.waitForTx)(await governor.authorizeExecutors([longTimelockAddress, shortTimelockAddress, merklePauserTimelockAddress])); } if (startStep <= 7) { (0, logging_1.log)('Step 7. Add deployer to token transfer allowlist'); await (0, util_1.waitForTx)(await dydxToken.addToTokenTransferAllowlist([deployerAddress])); } if (startStep <= 8) { (0, logging_1.log)('Step 8. Add test addresses to token transfer allowlist'); await (0, util_1.waitForTx)(await dydxToken.addToTokenTransferAllowlist(deployConfig.TOKEN_TEST_ADDRESSES)); } if (startStep <= 9) { (0, logging_1.log)('Step 9. Send test tokens.'); const testAllocations = [ deployConfig.TOKEN_ALLOCATIONS.TEST_TOKENS_1, deployConfig.TOKEN_ALLOCATIONS.TEST_TOKENS_2, deployConfig.TOKEN_ALLOCATIONS.TEST_TOKENS_3, deployConfig.TOKEN_ALLOCATIONS.TEST_TOKENS_4, ]; for (const allocation of testAllocations) { await (0, transfer_tokens_1.transferWithPrompt)(dydxToken, allocation.ADDRESS, allocation.AMOUNT); } } (0, logging_1.log)('\n=== PHASE 1 DEPLOYMENT COMPLETE ===\n'); const contracts = [ ['DydxToken', dydxTokenAddress], ['Governor', governorAddress], ['ShortTimelock', shortTimelockAddress], ['LongTimelock', longTimelockAddress], ['MerkleTimelock', merklePauserTimelockAddress], ['Distributor EOA', deployerAddress], ]; contracts.forEach(data => (0, logging_1.log)(`${data[0]} at ${data[1]}`)); return { dydxToken, governor, shortTimelock, longTimelock, merklePauserTimelock, }; } exports.deployPhase1 = deployPhase1;