Skip to content
This repository has been archived by the owner on Jan 18, 2023. It is now read-only.

Commit

Permalink
Fix deployment script, add error checking and UX improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
kermankohli committed Feb 28, 2019
1 parent 7ca7b2d commit 9abf16c
Show file tree
Hide file tree
Showing 20 changed files with 422 additions and 233 deletions.
10 changes: 5 additions & 5 deletions deployments/README.md 100644 → 100755
Expand Up @@ -3,12 +3,12 @@
Before getting started, make sure you have the following `env` variables set:

```
// Private key to deploy with
// Private key to deploy with. Must be prepended with '0x'
DEPLOYMENT_PRIVATE_KEY="0xA..."
// The network name set here will use constants from `network-constants.ts`
// Examples of networks include `main`, `kovan`, `development`
DEPLOYMENT_NETWORK_NAME="development"
// The variable set here will use constants from `network-constants.ts`
// Examples of networks include `production`, `staging`, `development`
DEPLOYMENT_CONSTANT="production"
// Network id will indicate which chain to run on
// Main-net = 1, Kovan = 42, Test_RPC = 50
Expand All @@ -23,6 +23,6 @@ To deploy, simply run `yarn deploy`. Test are automatically run at the end.

## Tests

In order to run tests the outputs file should contain addresses for the contracts you would like to test against and the `.env` file should have the same `DEPLOYMENT_NETWORK_NAME` and `DEPLOYMENT_NETWORK_ID`.
In order to run tests the outputs file should contain addresses for the contracts you would like to test against and the `.env` file should have the same `DEPLOYMENT_CONSTANT` and `DEPLOYMENT_NETWORK_ID`.

Then run `yarn test-development`
Empty file modified deployments/constants.ts 100644 → 100755
Empty file.
5 changes: 5 additions & 0 deletions deployments/dependencies.ts 100644 → 100755
Expand Up @@ -54,5 +54,10 @@ export default {
1: 'https://mainnet.infura.io',
42: 'https://kovan.infura.io',
},
HUMAN_FRIENDLY_NAMES: {
1: 'main-net',
42: 'kovan',
50: 'test-rpc'
}
};

Empty file modified deployments/deploy.ts 100644 → 100755
Empty file.
89 changes: 50 additions & 39 deletions deployments/manager.ts 100644 → 100755
Expand Up @@ -7,20 +7,23 @@ import { RebalancingStage } from './stages/5_rebalancing';
import { AuthorizationStage } from './stages/4_authorization';

import { asyncForEach } from '../utils/array';
import { getWeb3Instance } from './utils/blockchain';
import { getWeb3Instance, getInfuraKey } from './utils/blockchain';

import {
getNetworkName,
getNetworkConstant,
getNetworkId,
returnOutputs,
writeStateToOutputs,
removeNetwork,
getContractCode
getContractCode,
getPrivateKey,
isCorrectNetworkId,
getLastDeploymentStage,
sortOutputs
} from './utils/output-helper';

export class Manager {

private _networkName: string;
private _networkConstant: string;
private _networkId: number;

private _stages: { [id: number]: DeploymentStageInterface } = {
Expand All @@ -32,70 +35,78 @@ export class Manager {
};

constructor() {
this._networkName = getNetworkName();
this._networkConstant = getNetworkConstant();
this._networkId = getNetworkId();
}

async deploy() {
await this.configureIfDevelopment();
await this.checkInputParameters()

let toDeploy = await this.getDeploymentStages();
let web3 = await getWeb3Instance();
let correctNetworkId = await this.isCorrectNetworkId();

if (!correctNetworkId) {
throw Error('ENV variable `DEPLOYMENT_NETWORK_ID` does not match `network_id` in outputs.json');
}

await asyncForEach(toDeploy, async stage => {
console.log(`Stage: ${stage}/${Object.keys(this._stages).length}`);

const currentStage = this._stages[stage];

await currentStage.deploy(web3);
await writeStateToOutputs(this._networkName, 'last_deployment_stage', parseInt(stage));
await writeStateToOutputs('last_deployment_stage', parseInt(stage));
});
}

async getDeploymentStages() {
const lastStage = await this.getLastDeploymentStage();
const stageKeys = Object.keys(this._stages);
return stageKeys.filter(value => parseInt(value) > lastStage).sort();
await sortOutputs();
}

async getLastDeploymentStage(): Promise<number> {
try {
const output = await returnOutputs();
return output[this._networkName]['state']['last_deployment_stage'] || 0;
} catch {
return 0;
async checkInputParameters() {
await this.configureIfDevelopment();

const correctNetworkId = await isCorrectNetworkId();
const infuraKey = getInfuraKey() || '';
const privateKey = getPrivateKey() || '';
const networkId = getNetworkId() || 0;
const networkConstant = getNetworkConstant() || '';

if (!privateKey) {
throw Error('.env variable DEPLOYMENT_PRIVATE_KEY is missing');
}
}

async isCorrectNetworkId(): Promise<boolean> {
try {
const output = await returnOutputs();
const existingId = output[this._networkName]['state']['network_id'];
if (!existingId) {
await writeStateToOutputs(this._networkName, 'network_id', this._networkId);
return true;
}
return existingId == this._networkId;
} catch {
return true;
if (!networkId) {
throw Error('.env variable DEPLOYMENT_NETWORK_ID is missing');
}

if (!networkConstant) {
throw Error('.env variable DEPLOYMENT_CONSTANT is missing');
}

if (!correctNetworkId) {
throw Error('.env variable DEPLOYMENT_NETWORK_ID does not match `network_id` in outputs.json');
}

if (privateKey.substring(0,2) != '0x') {
throw Error('Please make sure the private key is appended with 0x');
}

if ((!infuraKey || infuraKey.length == 0) && (networkId != 50)) {
throw Error('.env variable INFURA_KEY is missing');
}
}

async getDeploymentStages() {
const lastStage = await getLastDeploymentStage();
const stageKeys = Object.keys(this._stages);
return stageKeys.filter(value => parseInt(value) > lastStage).sort();
}

async configureIfDevelopment() {
try {
const web3 = await getWeb3Instance();
const code = await getContractCode('Core', web3);
if (this._networkId == 50 && code.length <= 3) {
console.log(`\n*** Clearing all addresses for ${this._networkName} ***\n`);
await removeNetwork(this._networkName);
console.log(`\n*** Clearing all addresses for ${this._networkConstant} ***\n`);
await removeNetwork(this._networkConstant);
}
} catch (error) {
console.log(error);
console.log('*** No addresses to wipe *** ');
}
}
}
68 changes: 34 additions & 34 deletions deployments/network-constants.ts 100644 → 100755
Expand Up @@ -2,88 +2,88 @@ import constants from './constants';

export default {
minimumRebalanceInterval: {
main: constants.ONE_DAY_IN_SECONDS,
kovan: constants.ONE_MINUTE_IN_SECONDS,
production: constants.ONE_DAY_IN_SECONDS,
staging: constants.ONE_MINUTE_IN_SECONDS,
development: constants.ONE_MINUTE_IN_SECONDS,
},
minimumRebalanceProposalPeriod: {
main: constants.ONE_DAY_IN_SECONDS,
kovan: constants.ONE_MINUTE_IN_SECONDS,
production: constants.ONE_DAY_IN_SECONDS,
staging: constants.ONE_MINUTE_IN_SECONDS,
development: constants.ONE_MINUTE_IN_SECONDS,
},
minimumRebalanceTimeToPivot: {
main: (constants.ONE_DAY_IN_SECONDS / 4),
kovan: 0,
production: (constants.ONE_DAY_IN_SECONDS / 4),
staging: 0,
development: 0,
},
maximumRebalanceTimeToPivot: {
main: (constants.ONE_DAY_IN_SECONDS * 3),
kovan: (constants.ONE_DAY_IN_SECONDS * 3),
production: (constants.ONE_DAY_IN_SECONDS * 3),
staging: (constants.ONE_DAY_IN_SECONDS * 3),
development: (constants.ONE_DAY_IN_SECONDS * 3),
},
bitEthProposalPeriod: {
main: constants.ONE_DAY_IN_SECONDS,
kovan: constants.THIRTY_MINUTES_IN_SECONDS,
production: constants.ONE_DAY_IN_SECONDS,
staging: constants.THIRTY_MINUTES_IN_SECONDS,
development: constants.ONE_DAY_IN_SECONDS,
},
bitEthRebalanceInterval: {
main: constants.THIRTY_DAYS_IN_SECONDS,
kovan: constants.THIRTY_MINUTES_IN_SECONDS,
production: constants.THIRTY_DAYS_IN_SECONDS,
staging: constants.THIRTY_MINUTES_IN_SECONDS,
development: constants.ONE_DAY_IN_SECONDS,
},
bitEthRebalanceManagerAuctionTimeToPivot: {
main: constants.ONE_DAY_IN_SECONDS,
kovan: constants.ONE_HOUR_IN_SECONDS,
production: constants.ONE_DAY_IN_SECONDS,
staging: constants.ONE_HOUR_IN_SECONDS,
development: constants.ONE_DAY_IN_SECONDS,
},
bitEthRebalanceManagerAllocationUpperBound: {
main: 52,
kovan: 50,
production: 52,
staging: 50,
development: 50,
},
bitEthRebalanceManagerAllocationLowerBound: {
main: 48,
kovan: 50,
production: 48,
staging: 50,
development: 50,
},
ethDaiProposalPeriod: {
main: constants.ONE_DAY_IN_SECONDS,
kovan: constants.THIRTY_MINUTES_IN_SECONDS,
production: constants.ONE_DAY_IN_SECONDS,
staging: constants.THIRTY_MINUTES_IN_SECONDS,
development: constants.ONE_DAY_IN_SECONDS,
},
ethDaiRebalanceInterval: {
main: constants.THIRTY_DAYS_IN_SECONDS,
kovan: constants.THIRTY_MINUTES_IN_SECONDS,
production: constants.THIRTY_DAYS_IN_SECONDS,
staging: constants.THIRTY_MINUTES_IN_SECONDS,
development: constants.ONE_DAY_IN_SECONDS,
},
ethDaiRebalanceManagerAuctionTimeToPivot: {
main: constants.ONE_DAY_IN_SECONDS,
kovan: constants.ONE_HOUR_IN_SECONDS,
production: constants.ONE_DAY_IN_SECONDS,
staging: constants.ONE_HOUR_IN_SECONDS,
development: constants.ONE_DAY_IN_SECONDS,
},
ethDaiRebalanceManagerAllocationUpperBound: {
main: 60,
kovan: 50,
production: 60,
staging: 50,
development: 50,
},
ethDaiRebalanceManagerAllocationLowerBound: {
main: 40,
kovan: 50,
production: 40,
staging: 50,
development: 50,
},
timeLockPeriod: {
main: 0,
kovan: 0,
production: 0,
staging: 0,
development: 0,
},
linearAuctionPriceCurve: {
main: true,
kovan: true,
production: true,
staging: true,
development: true,
},
constantsAuctionPriceCurve: {
main: false,
kovan: true,
production: false,
staging: true,
development: true,
},
};
63 changes: 32 additions & 31 deletions deployments/outputs.json 100644 → 100755
@@ -1,39 +1,40 @@
{
"kovan": {
"42-staging": {
"human_friendly_name": "kovan-staging",
"addresses": {
"Vault": "0x1f66Aa3d97Fb94b931bC83060fEeCB20DBc04536",
"TransferProxy": "0x04a1F0E1C03B69BbA6E9aFB7B02EBa94328613c6",
"Core": "0xf9d7b625F95b7F73736f1F95C4EB54D109344750",
"SetTokenFactory": "0x69Bba2231afCDa0225F67FA4B49065cc4bFAB52E",
"WhiteList": "0xaD78e5570f24A268687C6CC0F73966e9978568A7",
"RebalancingSetTokenFactory": "0x88E76a3cDFb58bD04b3F3d9914EB65a94d5dEC9C",
"EIP712Library": "0x421C9A9dD08f2f0BE6E85e46F0E30775b4d57C95",
"ERC20Wrapper": "0x90b242eDd278E636E02C2054C861Fd46A7B96271",
"ExchangeIssueLibrary": "0xf6EA83409627Ed05349A10A86c36348063F9faB3",
"OrderLibrary": "0x98e1C92d666C83fdaafA1b55F7E60B15FE0181AB",
"RebalancingHelperLibrary": "0xAe284f5c545d554833dc8Aa45772f62FFD8525Fe",
"StandardProposeLibrary": "0xCE1b0a43f410652Cda8E55394c0e5223F56143a3",
"StandardStartRebalanceLibrary": "0xbBD58feba6c85D3fdf4F046073a6Bc508E07c2a1",
"StandardPlaceBidLibrary": "0xE72fce2A41E3e1f49e2A6D9FaE3ac3943ee50A26",
"StandardSettleRebalanceLibrary": "0x438071B6E7CcDeCeBe7a9407348CbBF5a5A5Fa1C",
"StandardFailAuctionLibrary": "0xCaAd13362B7DcE580Bcb875654DA75250925d977",
"RebalanceAuctionModule": "0x02CC43cDD5E8183092E5184b7e02de98D030e4D5",
"IssuanceOrderModule": "0xcEDA8318522D348f1d1aca48B24629b8FbF09020",
"ExchangeIssueModule": "0x0cA24B8Ce996ea8b50786b991E41Eab97c9A3BA7",
"TakerWalletWrapper": "0x8292D26925a537541b56e00D5F90e48dcA511F37",
"RebalancingTokenIssuanceModule": "0x9015254B65AfeC5DCF0bB6657414843C7616dA61",
"ZeroExExchangeWrapper": "0xe8f04c0A0404260f5340aed7b276a9aD72937A87",
"PayableExchangeIssue": "0xb633b5d605Eb6148C531307E7840b5fB4B6539f9",
"KyberNetworkWrapper": "0x56dB0438B1341e81e4C6E62F875fC3607FD1b911",
"LinearAuctionPriceCurve": "0x73C29F323f1D192B139c4a128b0aC9652F2Da490",
"ConstantAuctionPriceCurve": "0x75834f8929EcE6b7a0D09E7200FDE14E5b4C1F65",
"InitialCollateralSet": "0xC8655Dd4AE34f61Ce2eA28E7069707fdc8E1fdfb",
"BitEthRebalanceManager": "0xad0E4a2bD56Cf01bB3D4A68600700c2cd955Af81",
"BitEthRebalancingSetToken": "0x38aE0ac4bf28eb9A7EbC45f78C5400E4db718E73"
"ERC20Wrapper": "0x8053dA394E13D93182F6164353Ab70eC65a54654",
"IssuanceLibrary": "0x7C184aeac95c10D77Af569F929A10D74bC83cfB0",
"ExchangeIssueLibrary": "0x3636800c9e9e91d1577b0D101896FaecD351F624",
"RebalancingHelperLibrary": "0x3ae5c14edA44ce3c78a8B899E6d785a27Cfa412b",
"StandardProposeLibrary": "0x6D80de17e4FDF356d069D3F84aE77754BDd666Cf",
"StandardSettleRebalanceLibrary": "0xfFC878607f52898AA0A25e9EA61D9d157C773FC8",
"StandardStartRebalanceLibrary": "0xE32C79c563722C715b273cc3b70C21F705f74686",
"StandardPlaceBidLibrary": "0xC765AC5eFA6Dca87a1BA71C1717486A1B594ceCB",
"StandardFailAuctionLibrary": "0x58811b442e9Af2f2aa0F6BeEAA42853f78661789",
"Vault": "0x507f159854F864fAbF79CCfa7347bab408B79e6B",
"TransferProxy": "0x6DB97388577183c4F54486fcfdd468d251662759",
"Core": "0xB118b0682f6f60ef1Cb6d1373353Ea12FF931b3e",
"SetTokenFactory": "0xc9A21b66c25BCc3C9E78949862352aAFe73a126C",
"WhiteList": "0x3fA333AbB0c49322E0925C3EA428585AfC98847E",
"RebalancingSetTokenFactory": "0x4C0e820eaf06f8a74677C4A437B8BCe595B9daAA",
"ExchangeIssueModule": "0x2398C41113BDF47EA09Ed613728Ef36C618D7c3b",
"RebalanceAuctionModule": "0xb5c0F3e8e71e712247eb25EcdBC0cdB6ecE5c644",
"RebalancingTokenIssuanceModule": "0x9E1A3a2466c782F91a813E42cd90043a79feA9Db",
"PayableExchangeIssue": "0x41B87AfCeA96f0A5D2C4ff6A98B2516B07d75F6a",
"KyberNetworkWrapper": "0x12499f5a0a615b30F862A144398853734Fddc1B4",
"ZeroExExchangeWrapper": "0x3241E7Dc11B5A5810DA505532DcA13CAC0C0BA53",
"LinearAuctionPriceCurve": "0xc4D4e3af0ccc59b02a33a1adf4c4108652e63DF0",
"ConstantAuctionPriceCurve": "0x0A1217680e53146C064F9798F84d2AEF150B6Cc6",
"BitEthRebalanceManager": "0x95cF6Af6569B1d529eDE9a179b11731A3735673e",
"BitEthInitialCollateralSet": "0x4C061B54C3e5AfAA56a2eB84D44831398A12699a",
"BitEthRebalancingSetToken": "0x4c8Da1a6604b2Ff4308992Ce53909052f03693A0",
"ETHDaiRebalanceManager": "0x18766fA4Ec62A4c020a6D2bf9ACc590e2557D608",
"ETHDaiInitialCollateralSet": "0xDd6d57868d4398458900Bf5A1c403D6653E149a3",
"ETHDaiRebalancingSetToken": "0xcB9eC401174F5D2EdaE991Cc923313EC3d2E68A8"
},
"state": {
"last_deployment_stage": 5,
"network_id": 42
}
}
}
}

0 comments on commit 9abf16c

Please sign in to comment.