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

Commit

Permalink
Alex/update migration script (#349)
Browse files Browse the repository at this point in the history
* Update migration script

* Update migration script

* Add time lock updates to vault and transfer proxy
  • Loading branch information
asoong committed Jan 15, 2019
1 parent 0a0d899 commit 8eadb0c
Show file tree
Hide file tree
Showing 3 changed files with 280 additions and 53 deletions.
40 changes: 40 additions & 0 deletions migrations/2_token_whitelist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const WhiteList = artifacts.require("WhiteList")

const TOKEN_WHITELIST_MAINNET = [
'0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', // WETH
'0x2260fac5e5542a773aa44fbcfedf7c193bc2c599' // WBTC
];
const TOKEN_WHITELIST_ROPSTEN = [];
const TOKEN_WHITELIST_KOVAN = [];
const TOKEN_WHITELIST_DEVELOPMENT = [];


module.exports = function(deployer, network, accounts) {
if (network == "development" || network == "coverage") {
console.log("Exiting - Network is development");
return;
}

deployer.then(() => deployWhitelist(deployer, network));
};

async function deployWhitelist(deployer, network) {
let initialTokenWhiteList;
switch(network) {
case 'kovan':
case 'kovan-fork':
initialTokenWhiteList = TOKEN_WHITELIST_KOVAN;
break;

case 'ropsten':
case 'ropsten-fork':
initialTokenWhiteList = TOKEN_WHITELIST_ROPSTEN;
break;

case 'development':
initialTokenWhiteList = TOKEN_WHITELIST_DEVELOPMENT;
break;
}

await deployer.deploy(WhiteList, initialTokenWhiteList);
}
109 changes: 56 additions & 53 deletions migrations/2_core.js → migrations/3_core.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,15 @@ const LinearAuctionPriceCurve = artifacts.require('LinearAuctionPriceCurve');
const OrderLibrary = artifacts.require("OrderLibrary");
const RebalanceAuctionModule = artifacts.require("RebalanceAuctionModule");
const RebalancingSetTokenFactory = artifacts.require('RebalancingSetTokenFactory');
const RebalancingTokenIssuanceModule = artifacts.require('RebalancingTokenIssuanceModule');
const SetTokenFactory = artifacts.require("SetTokenFactory");
const SignatureValidator = artifacts.require("SignatureValidator");
const TakerWalletWrapper = artifacts.require("TakerWalletWrapper");
const TransferProxy = artifacts.require("TransferProxy");
const Vault = artifacts.require("Vault");
const WhiteList = artifacts.require("WhiteList")
const ZeroExExchangeWrapper = artifacts.require("ZeroExExchangeWrapper");

const EXCHANGES = {
ZERO_EX: 1,
KYBER: 2,
TAKER_WALLET: 3,
}
const ZERO_EX_EXCHANGE_ADDRESS_KOVAN = '0x35dd2932454449b14cee11a94d3674a936d5d7b2';
const ZERO_EX_ERC20_PROXY_ADDRESS_KOVAN = '0xf1ec01d6236d3cd881a0bf0130ea25fe4234003e';
const ZERO_EX_ZRX_ADDRESS_KOVAN = '0x2002d3812f58e35f0ea1ffbf80a75a38c32175fa';
Expand Down Expand Up @@ -50,9 +47,11 @@ module.exports = function(deployer, network, accounts) {
};

async function deployContracts(deployer, network) {
// Link external libraries that are dependencies of our contracts
await deployAndLinkLibraries(deployer, network);

// Deploy Core contracts and its authorized dependents
await deployCoreContracts(deployer, network);
await addAuthorizations(deployer, network);
};

async function deployAndLinkLibraries(deployer, network) {
Expand All @@ -70,19 +69,27 @@ async function deployAndLinkLibraries(deployer, network) {
await deployer.deploy(OrderLibrary);
await Core.link('OrderLibrary', OrderLibrary.address);
await IssuanceOrderModule.link('OrderLibrary', OrderLibrary.address);

await deployer.deploy(SignatureValidator);
};

async function deployCoreContracts(deployer, network) {
// Deploy Vault, TransferProxy, and Signature Validator
// Deploy Vault and TransferProxy
await deployer.deploy(Vault);
await deployer.deploy(TransferProxy);
await deployer.deploy(SignatureValidator);

// Deploy Core
await deployer.deploy(Core, TransferProxy.address, Vault.address, SignatureValidator.address);
await deployer.deploy(
Core,
TransferProxy.address,
Vault.address
);

// Deploy SetToken Factory
await deployer.deploy(SetTokenFactory, Core.address);
await deployer.deploy(
SetTokenFactory,
Core.address
);

// Deploy RebalancingSetToken Factory
let minimumReblanaceInterval;
Expand All @@ -102,7 +109,14 @@ async function deployCoreContracts(deployer, network) {
minimumProposalPeriod = ONE_MINUTE_IN_SECONDS;
break;
}
await deployer.deploy(RebalancingSetTokenFactory, Core.address, minimumReblanaceInterval, minimumProposalPeriod);

await deployer.deploy(
RebalancingSetTokenFactory,
Core.address,
WhiteList.address,
minimumReblanaceInterval,
minimumProposalPeriod
);

// Deploy Exchange Wrappers
let zeroExExchangeAddress;
Expand Down Expand Up @@ -133,16 +147,43 @@ async function deployCoreContracts(deployer, network) {
}

// Deploy Exchange Issue Module
await deployer.deploy(ExchangeIssueModule, Core.address, TransferProxy.address, Vault.address);
await deployer.deploy(
ExchangeIssueModule,
Core.address,
TransferProxy.address,
Vault.address
);

// Deploy Issuance Order Module
await deployer.deploy(IssuanceOrderModule, Core.address, TransferProxy.address, Vault.address);
await deployer.deploy(
IssuanceOrderModule,
Core.address,
TransferProxy.address,
Vault.address,
SignatureValidator.address
);

// Deploy Rebalancing Auction Module
await deployer.deploy(RebalanceAuctionModule, Core.address, Vault.address);
await deployer.deploy(
RebalanceAuctionModule,
Core.address,
Vault.address
);

// Deploy Rebalancing Token Issuance Module
await deployer.deploy(
RebalancingTokenIssuanceModule,
Core.address,
TransferProxy.address,
Vault.address
);

// Taker Wallet Wrapper
await deployer.deploy(TakerWalletWrapper, Core.address, TransferProxy.address);
await deployer.deploy(
TakerWalletWrapper,
Core.address,
TransferProxy.address
);

// Kyber Wrapper
if (kyberNetworkProxyAddress) {
Expand Down Expand Up @@ -170,41 +211,3 @@ async function deployCoreContracts(deployer, network) {
await deployer.deploy(ConstantAuctionPriceCurve, DEFAULT_AUCTION_PRICE_NUMERATOR, DEFAULT_AUCTION_PRICE_DENOMINATOR);
await deployer.deploy(LinearAuctionPriceCurve, DEFAULT_AUCTION_PRICE_DENOMINATOR);
};

async function addAuthorizations(deployer, network) {
// Approve Core to Vault
const vault = await Vault.deployed();
await vault.addAuthorizedAddress(Core.address);
await vault.addAuthorizedAddress(ExchangeIssueModule.address);
await vault.addAuthorizedAddress(IssuanceOrderModule.address);
await vault.addAuthorizedAddress(RebalanceAuctionModule.address);

// Approve Core and Vault to TransferProxy
const transferProxy = await TransferProxy.deployed();
await transferProxy.addAuthorizedAddress(Core.address);
await transferProxy.addAuthorizedAddress(TakerWalletWrapper.address);
await transferProxy.addAuthorizedAddress(ExchangeIssueModule.address);
await transferProxy.addAuthorizedAddress(IssuanceOrderModule.address);
await transferProxy.addAuthorizedAddress(RebalanceAuctionModule.address);

// Register Factories
const core = await Core.deployed();
await core.addFactory(SetTokenFactory.address);
await core.addFactory(RebalancingSetTokenFactory.address);

// Register Modules
await core.addModule(ExchangeIssueModule.address);
await core.addModule(IssuanceOrderModule.address);
await core.addModule(RebalanceAuctionModule.address);

// Register Exchanges
if (network === 'kovan' || network === 'kovan-fork' || network === 'development') {
await core.addExchange(EXCHANGES.ZERO_EX, ZeroExExchangeWrapper.address);
};
await core.addExchange(EXCHANGES.KYBER, KyberNetworkWrapper.address);
await core.addExchange(EXCHANGES.TAKER_WALLET, TakerWalletWrapper.address);

// Register Price Libraries
await core.addPriceLibrary(ConstantAuctionPriceCurve.address);
await core.addPriceLibrary(LinearAuctionPriceCurve.address);
};
184 changes: 184 additions & 0 deletions migrations/4_authorizations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
const ConstantAuctionPriceCurve = artifacts.require('ConstantAuctionPriceCurve');
const Core = artifacts.require("Core");
const ExchangeIssueModule = artifacts.require('ExchangeIssueModule');
const IssuanceOrderModule = artifacts.require('IssuanceOrderModule');
const KyberNetworkWrapper = artifacts.require('KyberNetworkWrapper');
const LinearAuctionPriceCurve = artifacts.require('LinearAuctionPriceCurve');
const RebalanceAuctionModule = artifacts.require("RebalanceAuctionModule");
const RebalancingSetTokenFactory = artifacts.require('RebalancingSetTokenFactory');
const RebalancingTokenIssuanceModule = artifacts.require('RebalancingTokenIssuanceModule');
const SetTokenFactory = artifacts.require("SetTokenFactory");
const TakerWalletWrapper = artifacts.require("TakerWalletWrapper");
const TransferProxy = artifacts.require("TransferProxy");
const Vault = artifacts.require("Vault");
const WhiteList = artifacts.require("WhiteList")
const ZeroExExchangeWrapper = artifacts.require("ZeroExExchangeWrapper");

const EXCHANGES = {
ZERO_EX: 1,
KYBER: 2,
TAKER_WALLET: 3,
}

const TIMELOCK_PERIOD_DEPLOYMENT = 0;
const TIMELOCK_PERIOD_MAINNET = 604800;
const TIMELOCK_PERIOD_TESTNET = 60;
const TIMELOCK_PERIOD_DEVELOPMENT = 60;


module.exports = function(deployer, network, accounts) {
if (network == "development" || network == "coverage") {
console.log("Exiting - Network is development");
return;
}

deployer.then(() => addAuthorizations(deployer, network));
};

async function addAuthorizations(deployer, network) {
// Set timelock period to 0 for adding initial deployment authorizations
await setTimeLockPeriodForDeployment(deployer, network);

// Add authorizations, factories, modules, exchange wrappers, and price libraries
await addAuthorizations(deployer, network);

// Enable timelock period
await enableTimeLockMinimumTime(deployer, network);
};

/*
* This is provided purely for transparency to show that the initial timelock period is 0 to allow the system
* to be deployed without having to wait the time lock period. After `addAuthorizations` adds the factories, modules,
* exchange wrappers, and price libraries, the timelock is set to TIMELOCK_PERIOD_MAINNET in `enableTimeLockMinimumTime`
*
*/
async function setTimeLockPeriodForDeployment(deployer, network) {
await updateTimeLockOnRequiredContracts(TIMELOCK_PERIOD_DEPLOYMENT);
};

async function addAuthorizations(deployer, network) {
// Add authorized addresses to Vault
console.log('Adding authorized addresses to \'Vault\': ', Vault.address)
const vault = await Vault.deployed();
await addAuthorizedAddressToContract(vault, 'Core', Core.address);
await addAuthorizedAddressToContract(vault, 'ExchangeIssueModule', ExchangeIssueModule.address);
await addAuthorizedAddressToContract(vault, 'IssuanceOrderModule', IssuanceOrderModule.address);
await addAuthorizedAddressToContract(vault, 'RebalanceAuctionModule', RebalanceAuctionModule.address);
await addAuthorizedAddressToContract(vault, 'RebalancingTokenIssuanceModule', RebalancingTokenIssuanceModule.address);
console.log('Successfully added authorized addresses to \'Vault\'\n');

// Add authorized addresses to TransferProxy
console.log('Adding authorized addresses to \'TransferProxy\': ', TransferProxy.address)
const transferProxy = await TransferProxy.deployed();
await addAuthorizedAddressToContract(transferProxy, 'Core', Core.address);
await addAuthorizedAddressToContract(transferProxy, 'TakerWalletWrapper', TakerWalletWrapper.address);
await addAuthorizedAddressToContract(transferProxy, 'ExchangeIssueModule', ExchangeIssueModule.address);
await addAuthorizedAddressToContract(transferProxy, 'IssuanceOrderModule', IssuanceOrderModule.address);
await addAuthorizedAddressToContract(transferProxy, 'RebalanceAuctionModule', RebalanceAuctionModule.address);
await addAuthorizedAddressToContract(transferProxy, 'RebalancingTokenIssuanceModule', RebalancingTokenIssuanceModule.address);
console.log('Successfully added authorized addresses to \'TransferProxy\'\n');

// Register Factories
console.log('Adding factories to \'Core\': ', Core.address)
await addFactoryToCore('SetTokenFactory', SetTokenFactory.address);
await addFactoryToCore('RebalancingSetTokenFactory', RebalancingSetTokenFactory.address);
console.log('Successfully added factories to \'Core\'\n');

// Register Modules
console.log('Adding modules to \'Core\': ', Core.address)
await addModuleToCore('ExchangeIssueModule', ExchangeIssueModule.address);
await addModuleToCore('IssuanceOrderModule', IssuanceOrderModule.address);
await addModuleToCore('RebalanceAuctionModule', RebalanceAuctionModule.address);
await addModuleToCore('RebalancingTokenIssuanceModule', RebalancingTokenIssuanceModule.address);
console.log('Successfully added modules to \'Core\'\n');

// Register Exchanges
console.log('Adding exchange wrappers to \'Core\': ', Core.address)
if (network === 'kovan' || network === 'kovan-fork' || network === 'development') {
await addExchangeWrapperToCore('ZeroExExchangeWrapper', EXCHANGES.ZERO_EX, ZeroExExchangeWrapper.address);
};
await addExchangeWrapperToCore('KyberNetworkWrapper', EXCHANGES.KYBER, KyberNetworkWrapper.address);
await addExchangeWrapperToCore('TakerWalletWrapper', EXCHANGES.TAKER_WALLET, TakerWalletWrapper.address);
console.log('Successfully added exchange wrappers to \'Core\'\n');

// Register Price Libraries
console.log('Adding price libraries to \'Core\': ', Core.address)
await addPriceLibraryToCore('ConstantAuctionPriceCurve', ConstantAuctionPriceCurve.address);
await addPriceLibraryToCore('LinearAuctionPriceCurve', LinearAuctionPriceCurve.address);
console.log('Successfully added price libraries to \'Core\'\n');
};

async function enableTimeLockMinimumTime(deployer, network) {
let timeLockPeriod;
switch(network) {
case 'main':
timeLockPeriod = TIMELOCK_PERIOD_MAINNET;
break;

case 'kovan':
case 'kovan-fork':
case 'ropsten':
case 'ropsten-fork':
timeLockPeriod = TIMELOCK_PERIOD_TESTNET;
break;

case 'development':
timeLockPeriod = TIMELOCK_PERIOD_DEVELOPMENT;
break;
}

await updateTimeLockOnRequiredContracts(timeLockPeriod);
};

/* ============ Helpers ============ */

async function addAuthorizedAddressToContract(contract, contractName, contractAddress) {
console.log(`Authorizing \'${contractName}\': ${contractAddress}`)

await contract.addAuthorizedAddress(contractAddress);
}

async function addFactoryToCore(contractName, contractAddress) {
console.log(`Adding \'${contractName}\': ${contractAddress}`)

const core = await Core.deployed();
await core.addFactory(contractAddress);
}

async function addModuleToCore(contractName, contractAddress) {
console.log(`Adding \'${contractName}\': ${contractAddress}`)

const core = await Core.deployed();
await core.addModule(contractAddress);
}

async function addExchangeWrapperToCore(contractName, exchangeWrapperKey, contractAddress) {
console.log(`Adding \'${contractName}\': ${contractAddress}`)

const core = await Core.deployed();
await core.addExchange(exchangeWrapperKey, contractAddress);
}

async function addPriceLibraryToCore(contractName, contractAddress) {
console.log(`Adding \'${contractName}\': ${contractAddress}`)

const core = await Core.deployed();
await core.addPriceLibrary(contractAddress);
}

async function updateTimeLockOnRequiredContracts(timeLockPeriod) {
const core = await Core.deployed();
await core.setTimeLockPeriod(timeLockPeriod);

const transferProxy = await TransferProxy.deployed();
await transferProxy.setTimeLockPeriod(timeLockPeriod);

const vault = await Vault.deployed();
await vault.setTimeLockPeriod(timeLockPeriod);

const whitelist = await WhiteList.deployed();
await whitelist.setTimeLockPeriod(timeLockPeriod);

const issuanceOrderModule = await IssuanceOrderModule.deployed();
await issuanceOrderModule.setTimeLockPeriod(timeLockPeriod);
}

0 comments on commit 8eadb0c

Please sign in to comment.