Skip to content
This repository was archived by the owner on Jan 18, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .env.default
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
INFURAKEY=""
MNEMONIC=""
PRIVATE_KEY=""

DEPLOYMENT_PRIVATE_KEY=""
DEPLOYMENT_NETWORK_NAME="development"
DEPLOYMENT_NETWORK_ID=50;
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ yarn-error.log*

# Snapshot
blockchain/

# Ouputs
deployments/outputs.ts
28 changes: 28 additions & 0 deletions deployments/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Getting Started

Before getting started, make sure you have the following `env` variables set:

```
// Private key to deploy with
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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's detail which networks you can deploy to. kovan, main etc.


// Network id will indicate which chain to run on
// Main-net = 1, Kovan = 42, Test_RPC = 50
DEPLOYMENT_NETWORK_ID=50;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which network corresponds to what? Would be helpful

```

## Deploying

The deployment script will output all addresses to `outputs.json`.

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`.

Then run `yarn test-development`
30 changes: 30 additions & 0 deletions deployments/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import BigNumber from 'bignumber.js';

export default {
EXCHANGES: {
ZERO_EX: 1,
KYBER: 2,
TAKER_WALLET: 3,
},
WBTC_PRICE: new BigNumber(3711),
WBTC_FULL_TOKEN_UNITS: new BigNumber(10 ** 8),
WBTC_MULTIPLIER: new BigNumber(1),
DEFAULT_WBTC_UNIT: new BigNumber(1),
WETH_FULL_TOKEN_UNITS: new BigNumber(10 ** 18),
WETH_PRICE: new BigNumber(128),
WETH_MULTIPLIER: new BigNumber(1),
WETH_DOMINANT_REBALANCING_NATURAL_UNIT: new BigNumber(10 ** 12),
PRICE_PRECISION: new BigNumber(100),
DEFAULT_REBALANCING_NATURAL_UNIT: new BigNumber(10 ** 10),
REBALANCING_SET_USD_PRICE: new BigNumber(100),
DEFAULT_AUCTION_PRICE_NUMERATOR: 1374,
DEFAULT_AUCTION_PRICE_DENOMINATOR: 1000,
SET_FULL_TOKEN_UNITS: new BigNumber(10 ** 18),
ONE_MINUTE_IN_SECONDS: 60,
THIRTY_MINUTES_IN_SECONDS: 1800,
ONE_HOUR_IN_SECONDS: 3600,
ONE_DAY_IN_SECONDS: 86400,
THIRTY_DAYS_IN_SECONDS: 2592000,
MINIMUM_REBALANCING_NATURAL_UNIT: 10000,
MAXIMUM_REBALANCING_NATURAL_UNIT: 100000000000000
};
54 changes: 54 additions & 0 deletions deployments/dependencies.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
*
* The keys are numerical network ids to avoid confusion between multiple contract
* staging environments on the same Ethereum network (main-staging, main-production)
*
* 1 = main net
* 3 = ropsten
* 42 = kovan
* 531 = Set's test-rpc (5 = S, 3 = E, 1 = T)
*
*/

export default {
WBTC: {
1: '0x2260fac5e5542a773aa44fbcfedf7c193bc2c599',
42: '0x595f8DaB94b9c718cbf5c693cD539Fd00b286D3d',
},
WETH: {
1: '0x2260fac5e5542a773aa44fbcfedf7c193bc2c599',
42: '0x4C5E0CAbAA6B376D565cF2be865a03F43E361770',
},
ZERO_EX_EXCHANGE: {
42: '0x35dD2932454449b14Cee11A94d3674a936d5d7b2',
50: '0x48BaCB9266a570d521063EF5dD96e61686DbE788',
},
ZERO_EX_PROXY: {
42: '0xF1eC01d6236D3CD881a0bF0130eA25fe4234003E',
50: '0x1dC4c1cEFEF38a777b15aA20260a54E584b16C48',
},
ZERO_EX_ZRX: {
42: '0x2002D3812F58e35F0EA1fFbf80A75a38c32175fA',
50: '0x871DD7C2B4b25E1Aa18728e9D5f2Af4C4e431f5c',
},
KYBER_PROXY: {
42: '0x7e6b8b9510d71bf8ef0f893902ebb9c865eef4df',
3: '0x818e6fecd516ecc3849daf6845e3ec868087b755',
50: '0x371b13d97f4bF77d724E78c16B7dC74099f40e84',
},
WBTC_MEDIANIZER: {
1: '',
42: '0x02186378d8e723e11643b4cd520E31655be3B0E9',
50: '0x2002d3812F58E35F0ea1fFbF80A75a38C32173Fa',
},
WETH_MEDIANIZER: {
1: '',
42: '0x9Fe0D478D0E290d50EF8DFc08760C4ad9D2C7AE9',
50: '0x2002d3812f58E35f0EA1Ffbf80a75A38c32174fA',
},
INFURA_SUBDOMAIN: {
1: 'https://mainnet.infura.io',
42: 'https://kovan.infura.io',
},
};

14 changes: 14 additions & 0 deletions deployments/deploy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Manager } from './manager';

async function start() {
const newManager = new Manager();

try {
await newManager.deploy();
} catch (error) {
console.log(error);
}
}

start();

101 changes: 101 additions & 0 deletions deployments/manager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import { DeploymentStageInterface } from '../types/deployment_stage_interface';

import { LibrariesStage } from './stages/1_libraries';
import { CoreStage } from './stages/2_core';
import { ModulesStage } from './stages/3_modules';
import { RebalancingStage } from './stages/5_rebalancing';
import { AuthorizationStage } from './stages/4_authorization';

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

import {
getNetworkName,
getNetworkId,
returnOutputs,
writeStateToOutputs,
removeNetwork,
getContractCode
} from './utils/output-helper';

export class Manager {

private _networkName: string;
private _networkId: number;

private _stages: { [id: number]: DeploymentStageInterface } = {
1: new LibrariesStage(),
2: new CoreStage(),
3: new ModulesStage(),
4: new AuthorizationStage(),
5: new RebalancingStage(),
};

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

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

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));
});
}

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

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

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;
}
}

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);
}
} catch (error) {
console.log(error);
}
}
}
64 changes: 64 additions & 0 deletions deployments/network-constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import constants from './constants';

export default {
minimumRebalanceInterval: {
main: constants.ONE_DAY_IN_SECONDS,
kovan: constants.ONE_MINUTE_IN_SECONDS,
development: constants.ONE_MINUTE_IN_SECONDS,
},
minimumRebalanceProposalPeriod: {
main: constants.ONE_DAY_IN_SECONDS,
kovan: constants.ONE_MINUTE_IN_SECONDS,
development: constants.ONE_MINUTE_IN_SECONDS,
},
minimumRebalanceTimeToPivot: {
main: (constants.ONE_DAY_IN_SECONDS / 4),
kovan: 0,
development: 0,
},
maximumRebalanceTimeToPivot: {
main: (constants.ONE_DAY_IN_SECONDS * 3),
kovan: (constants.ONE_DAY_IN_SECONDS * 3),
development: (constants.ONE_DAY_IN_SECONDS * 3),
},
bitEthRebalanceManagerProposalPeriod: {
main: constants.ONE_DAY_IN_SECONDS,
kovan: constants.THIRTY_MINUTES_IN_SECONDS,
development: constants.ONE_DAY_IN_SECONDS,
},
bitEthRebalanceManagerRebalanceInterval: {
main: constants.THIRTY_DAYS_IN_SECONDS,
kovan: constants.THIRTY_MINUTES_IN_SECONDS,
development: constants.ONE_DAY_IN_SECONDS,
},
bitEthRebalanceManagerAuctionTimeToPivot: {
main: constants.ONE_DAY_IN_SECONDS,
kovan: constants.ONE_HOUR_IN_SECONDS,
development: constants.ONE_DAY_IN_SECONDS,
},
bitEthRebalanceManagerAllocationUpperBound: {
main: 52,
kovan: 50,
development: 50,
},
bitEthRebalanceManagerAllocationLowerBound: {
main: 48,
kovan: 50,
development: 50,
},
timeLockPeriod: {
main: 0,
kovan: 0,
development: 0,
},
linearAuctionPriceCurve: {
main: true,
kovan: true,
development: true,
},
constantsAuctionPriceCurve: {
main: false,
kovan: true,
development: true,
},
};
73 changes: 73 additions & 0 deletions deployments/outputs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"kovan": {
"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"
},
"state": {
"last_deployment_stage": 5,
"network_id": 1
}
},
"development": {
"addresses": {
"ERC20Wrapper": "0x6975548516e60ce4d005Aa42De1e96DddD9d23eD",
"ExchangeIssueLibrary": "0x57b7aB09008dD5eda262b160A7b0f0d17c8754B4",
"RebalancingHelperLibrary": "0x9Ac5A7B338d90A85c6201D2691983Cc37F81AD2d",
"StandardProposeLibrary": "0x1590311C922a283024f0363777478C6b8c3d8c6c",
"StandardSettleRebalanceLibrary": "0x751D5E793577B2fd5dF9356729f8ddabF0800F20",
"StandardStartRebalanceLibrary": "0xa9a65D631f8c8577f543B64B35909030C84676A2",
"StandardPlaceBidLibrary": "0x038C860fd0d598B3DF5577B466c8b0a074867f56",
"StandardFailAuctionLibrary": "0x16C057c0494A0d7FB83974356Ce44323793BcFb2",
"WBTC": "0xdEf2bdc320e6EB892FEF7F406ff8C4BaB0735379",
"WETH": "0x58787E5441be9548440086495EA8583394e3427f",
"Vault": "0x841789fe96a433b49450E37E8CB513117712F63F",
"TransferProxy": "0x56D919871bDb3009590392fb05060e625276041d",
"Core": "0x4A86aD5f263260f24483Df2B1B3a23ea4788B6AB",
"SetTokenFactory": "0x0221652D4306F6b3CB7B23E43C3e25D8F9a142Ca",
"WhiteList": "0x4F4DB3fBEeAb70E6425c72E8f103fcbefDBDE2FE",
"RebalancingSetTokenFactory": "0xC307C1ecb7d3C546357598b9D4c6434481A18308",
"ExchangeIssueModule": "0x5578Dd96d5179Aa78d56EDbA9eBEf1Cb98077cfA",
"RebalanceAuctionModule": "0xe6244DDc4E21660308989DB20b6a5c10931c1B35",
"RebalancingTokenIssuanceModule": "0x6AC7189BD267c81c55d7d7d0321f9B23639cB9db",
"PayableExchangeIssue": "0x3E809c563c15a295E832e37053798DdC8d6C8dab",
"KyberNetworkWrapper": "0x8E1fF02637Cb5E39f2fA36c14706aa348B065B09",
"ZeroExExchangeWrapper": "0x2727E688B8fD40b198cd5Fe6E408e00494a06F07",
"LinearAuctionPriceCurve": "0x22ebc052F43A88Efa06379426120718170F2204e",
"ConstantAuctionPriceCurve": "0x1dA52d1D3a3AcFa0A1836b737393b4e9931268Fc",
"BitEthRebalanceManager": "0xc51B43db0Cea40E36207993F0aB1883E7A865417",
"InitialCollateralSet": "0x7E71f21a7ef0EbC24b0865D17DFF03fD874C5cFf",
"BitEthRebalancingSetToken": "0x4ae4BD9B4A5600Db8f28e9a01EE73094Eb4814A7"
},
"state": {
"last_deployment_stage": 5
}
}
}
Loading