Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
abandeali1 committed Nov 18, 2019
1 parent daef4cf commit 638c4ca
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 205 deletions.
23 changes: 13 additions & 10 deletions packages/migrations/src/test_contract_configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,19 @@ import { getTimelockRegistrationsAsync } from './utils/timelocks';
const INFURA_PROJECT_ID = '';

const networkIdToRpcUrl = {
1: `https://mainnet.infura.io/v3/${INFURA_PROJECT_ID}`,
1: `http://localhost:8545`,
3: `https://ropsten.infura.io/v3/${INFURA_PROJECT_ID}`,
4: `https://rinkeby.infura.io/v3/${INFURA_PROJECT_ID}`,
42: `https://kovan.infura.io/v3/${INFURA_PROJECT_ID}`,
};

// tslint:disable:custom-no-magic-numbers
async function testContractConfigsAsync(provider: SupportedProvider): Promise<void> {
export async function testContractConfigsAsync(provider: SupportedProvider): Promise<void> {
const web3Wrapper = new Web3Wrapper(provider);
const chainId = await web3Wrapper.getChainIdAsync();
let chainId = await web3Wrapper.getChainIdAsync();
if (chainId === 1337) {
chainId = 1;
}
const addresses = getContractAddressesForChainOrThrow(chainId);
const configs = getConfigsByChainId(chainId);

Expand Down Expand Up @@ -382,13 +385,13 @@ async function testContractConfigsAsync(provider: SupportedProvider): Promise<vo
}

(async () => {
for (const rpcUrl of Object.values(networkIdToRpcUrl)) {
const provider = new Web3ProviderEngine();
provider.addProvider(new EmptyWalletSubprovider());
provider.addProvider(new RPCSubprovider(rpcUrl));
providerUtils.startProviderEngine(provider);
await testContractConfigsAsync(provider);
}
// for (const rpcUrl of Object.values(networkIdToRpcUrl)) {
// const provider = new Web3ProviderEngine();
// provider.addProvider(new EmptyWalletSubprovider());
// provider.addProvider(new RPCSubprovider(rpcUrl));
// providerUtils.startProviderEngine(provider);
// await testContractConfigsAsync(provider);
// }
})().catch(err => {
logUtils.log(err);
process.exit(1);
Expand Down
228 changes: 33 additions & 195 deletions packages/migrations/src/testnet_migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ import {
ZrxVaultContract,
} from '@0x/contracts-staking';
import { IAuthorizableContract, IOwnableContract } from '@0x/contracts-utils';
import { EmptyWalletSubprovider, RPCSubprovider, Web3ProviderEngine } from '@0x/subproviders';
import { AbiEncoder, BigNumber, logUtils, providerUtils } from '@0x/utils';
import { Web3Wrapper } from '@0x/web3-wrapper';
import { LogWithDecodedArgs, SupportedProvider, TxData } from 'ethereum-types';

import { testContractConfigsAsync } from './test_contract_configs';
import { getConfigsByChainId } from './utils/configs_by_chain';
import { constants } from './utils/constants';
import { providerFactory } from './utils/provider_factory';
Expand Down Expand Up @@ -51,210 +54,45 @@ async function submitAndExecuteTransactionAsync(
*/
export async function runMigrationsAsync(supportedProvider: SupportedProvider, txDefaults: TxData): Promise<void> {
const provider = providerUtils.standardizeOrThrow(supportedProvider);
const chainId = new BigNumber(await providerUtils.getChainIdAsync(provider));
const deployedAddresses = getContractAddressesForChainOrThrow(chainId.toNumber());
const configs = getConfigsByChainId(chainId.toNumber());
const web3Wrapper = new Web3Wrapper(provider);
let chainId = await web3Wrapper.getChainIdAsync();
if (chainId === 1337) {
chainId = 1;
}

// NOTE: This must be deployed before running these migrations, since its address is hard coded in the
// staking logic contract.
const zrxVault = new ZrxVaultContract(deployedAddresses.zrxVault, provider, txDefaults);

const stakingLogic = await StakingContract.deployFrom0xArtifactAsync(
stakingArtifacts.Staking,
provider,
txDefaults,
stakingArtifacts,
);

const exchange = await ExchangeContract.deployFrom0xArtifactAsync(
exchangeArtifacts.Exchange,
provider,
txDefaults,
exchangeArtifacts,
chainId,
);

const stakingProxy = await StakingProxyContract.deployFrom0xArtifactAsync(
stakingArtifacts.StakingProxy,
provider,
txDefaults,
stakingArtifacts,
stakingLogic.address,
);

const erc20BridgeProxy = await ERC20BridgeProxyContract.deployFrom0xArtifactAsync(
assetProxyArtifacts.ERC20BridgeProxy,
provider,
txDefaults,
assetProxyArtifacts,
);
const deployedAddresses = getContractAddressesForChainOrThrow(chainId);

await UniswapBridgeContract.deployFrom0xArtifactAsync(
assetProxyArtifacts.UniswapBridge,
provider,
txDefaults,
assetProxyArtifacts,
);
await web3Wrapper.increaseTimeAsync(15 * 24 * 60 * 60);
await web3Wrapper.mineBlockAsync();

await Eth2DaiBridgeContract.deployFrom0xArtifactAsync(
assetProxyArtifacts.Eth2DaiBridge,
provider,
txDefaults,
assetProxyArtifacts,
);

const authorizableInterface = new IAuthorizableContract(constants.NULL_ADDRESS, provider, txDefaults);
const ownableInterface = new IOwnableContract(constants.NULL_ADDRESS, provider, txDefaults);

const customTimeLocks = await getTimelockRegistrationsAsync(provider);

const governor = await ZeroExGovernorContract.deployFrom0xArtifactAsync(
multisigArtifacts.ZeroExGovernor,
provider,
txDefaults,
multisigArtifacts,
customTimeLocks.map(timeLockInfo => timeLockInfo.functionSelector),
customTimeLocks.map(timeLockInfo => timeLockInfo.destination),
customTimeLocks.map(timeLockInfo => timeLockInfo.secondsTimeLocked),
configs.zeroExGovernor.owners,
configs.zeroExGovernor.required,
configs.zeroExGovernor.secondsTimeLocked,
);

logUtils.log('Configuring Exchange...');
await exchange.setProtocolFeeCollectorAddress(stakingProxy.address).awaitTransactionSuccessAsync();
await exchange.setProtocolFeeMultiplier(new BigNumber(150000)).awaitTransactionSuccessAsync();
await exchange.registerAssetProxy(deployedAddresses.erc20Proxy).awaitTransactionSuccessAsync();
await exchange.registerAssetProxy(deployedAddresses.erc721Proxy).awaitTransactionSuccessAsync();
await exchange.registerAssetProxy(deployedAddresses.erc1155Proxy).awaitTransactionSuccessAsync();
await exchange.registerAssetProxy(deployedAddresses.multiAssetProxy).awaitTransactionSuccessAsync();
await exchange.registerAssetProxy(deployedAddresses.staticCallProxy).awaitTransactionSuccessAsync();
await exchange.registerAssetProxy(erc20BridgeProxy.address).awaitTransactionSuccessAsync();
const apo = new ZeroExGovernorContract(deployedAddresses.assetProxyOwner, provider, txDefaults);
const governor = new ZeroExGovernorContract(deployedAddresses.zeroExGovernor, provider, txDefaults);
const zrxVault = new ZrxVaultContract(deployedAddresses.zrxVault, provider, txDefaults);
const exchange = new ExchangeContract(deployedAddresses.exchange, provider, txDefaults);
const stakingProxy = new StakingProxyContract(deployedAddresses.stakingProxy, provider, txDefaults);

await apo.executeTransaction(new BigNumber(6)).awaitTransactionSuccessAsync();
await apo.executeTransaction(new BigNumber(7)).awaitTransactionSuccessAsync();
await apo.executeTransaction(new BigNumber(8)).awaitTransactionSuccessAsync();
await apo.executeTransaction(new BigNumber(9)).awaitTransactionSuccessAsync();
await apo.executeTransaction(new BigNumber(10)).awaitTransactionSuccessAsync();
await exchange.transferOwnership(governor.address).awaitTransactionSuccessAsync();
logUtils.log('Exchange configured!');

logUtils.log('Configuring ERC20BridgeProxy...');
await erc20BridgeProxy.addAuthorizedAddress(exchange.address).awaitTransactionSuccessAsync();
await erc20BridgeProxy.addAuthorizedAddress(deployedAddresses.multiAssetProxy).awaitTransactionSuccessAsync();
await erc20BridgeProxy.transferOwnership(governor.address).awaitTransactionSuccessAsync();
logUtils.log('ERC20BridgeProxy configured!');

logUtils.log('Configuring ZrxVault...');
await zrxVault.addAuthorizedAddress(txDefaults.from).awaitTransactionSuccessAsync();
await zrxVault.setStakingProxy(stakingProxy.address).awaitTransactionSuccessAsync();
await zrxVault.removeAuthorizedAddress(txDefaults.from).awaitTransactionSuccessAsync();
await zrxVault.addAuthorizedAddress(governor.address).awaitTransactionSuccessAsync();
await zrxVault.transferOwnership(governor.address).awaitTransactionSuccessAsync();
logUtils.log('ZrxVault configured!');

logUtils.log('Configuring StakingProxy...');
await stakingProxy.addAuthorizedAddress(txDefaults.from).awaitTransactionSuccessAsync();
const staking = new StakingContract(stakingProxy.address, provider, txDefaults);
await staking.addExchangeAddress(exchange.address).awaitTransactionSuccessAsync();
await stakingProxy.removeAuthorizedAddress(txDefaults.from).awaitTransactionSuccessAsync();
await stakingProxy.addAuthorizedAddress(governor.address).awaitTransactionSuccessAsync();
await stakingProxy.transferOwnership(governor.address).awaitTransactionSuccessAsync();
logUtils.log('StakingProxy configured!');

logUtils.log('Transfering ownership of 2.0 contracts...');
const oldAssetProxyOwner = new ZeroExGovernorContract(deployedAddresses.assetProxyOwner, provider, txDefaults);
await submitAndExecuteTransactionAsync(
oldAssetProxyOwner,
deployedAddresses.exchangeV2, // Exchange 2.1 address
ownableInterface.transferOwnership(governor.address).getABIEncodedTransactionData(),
);
await submitAndExecuteTransactionAsync(
oldAssetProxyOwner,
deployedAddresses.erc20Proxy,
ownableInterface.transferOwnership(governor.address).getABIEncodedTransactionData(),
);
await submitAndExecuteTransactionAsync(
oldAssetProxyOwner,
deployedAddresses.erc721Proxy,
ownableInterface.transferOwnership(governor.address).getABIEncodedTransactionData(),
);
await submitAndExecuteTransactionAsync(
oldAssetProxyOwner,
deployedAddresses.erc1155Proxy,
ownableInterface.transferOwnership(governor.address).getABIEncodedTransactionData(),
);
await submitAndExecuteTransactionAsync(
oldAssetProxyOwner,
deployedAddresses.multiAssetProxy,
ownableInterface.transferOwnership(governor.address).getABIEncodedTransactionData(),
);
logUtils.log('Ownership transferred!');

const functionCalls = [
// AssetProxy configs
{
destination: deployedAddresses.erc20Proxy,
data: authorizableInterface.addAuthorizedAddress(exchange.address).getABIEncodedTransactionData(),
},
{
destination: deployedAddresses.erc20Proxy,
data: authorizableInterface.addAuthorizedAddress(zrxVault.address).getABIEncodedTransactionData(),
},
{
destination: deployedAddresses.erc721Proxy,
data: authorizableInterface.addAuthorizedAddress(exchange.address).getABIEncodedTransactionData(),
},
{
destination: deployedAddresses.erc1155Proxy,
data: authorizableInterface.addAuthorizedAddress(exchange.address).getABIEncodedTransactionData(),
},
{
destination: deployedAddresses.multiAssetProxy,
data: authorizableInterface.addAuthorizedAddress(exchange.address).getABIEncodedTransactionData(),
},
{
destination: deployedAddresses.multiAssetProxy,
data: exchange.registerAssetProxy(erc20BridgeProxy.address).getABIEncodedTransactionData(),
},
];

const batchTransactionEncoder = AbiEncoder.create('(bytes[],address[],uint256[])');
const batchTransactionData = batchTransactionEncoder.encode([
functionCalls.map(item => item.data),
functionCalls.map(item => item.destination),
functionCalls.map(() => constants.ZERO_AMOUNT),
]);
await submitAndExecuteTransactionAsync(governor, governor.address, batchTransactionData);

const devUtils = await DevUtilsContract.deployFrom0xArtifactAsync(
devUtilsArtifacts.DevUtils,
provider,
txDefaults,
devUtilsArtifacts,
exchange.address,
);

await CoordinatorContract.deployFrom0xArtifactAsync(
coordinatorArtifacts.Coordinator,
provider,
txDefaults,
coordinatorArtifacts,
exchange.address,
chainId,
);
await zrxVault.transferOwnership(governor.address).awaitTransactionSuccessAsync();
await governor.executeTransaction(new BigNumber(3)).awaitTransactionSuccessAsync();

const wethAssetData = await devUtils.encodeERC20AssetData(deployedAddresses.etherToken).callAsync();
const forwarder = await ForwarderContract.deployFrom0xArtifactAsync(
forwarderArtifacts.Forwarder,
provider,
txDefaults,
forwarderArtifacts,
exchange.address,
wethAssetData,
);
await forwarder.approveMakerAssetProxy(deployedAddresses.etherToken).awaitTransactionSuccessAsync();
await testContractConfigsAsync(provider);
}

(async () => {
const networkId = 1;
const rpcUrl = 'https://mainnet.infura.io/v3/';
const provider = await providerFactory.getLedgerProviderAsync(networkId, rpcUrl);
await runMigrationsAsync(provider, { from: '0x3b39078f2a3e1512eecc8d6792fdc7f33e1cd2cf', gasPrice: 10000000001 });
const provider = new Web3ProviderEngine();
provider.addProvider(new RPCSubprovider('http://127.0.0.1:8545', 600000));
providerUtils.startProviderEngine(provider);
await runMigrationsAsync(provider, {
from: '0x3b39078f2a3e1512eecc8d6792fdc7f33e1cd2cf',
gasPrice: 20000000000,
gas: 2000000,
});
})().catch(err => {
logUtils.log(err);
process.exit(1);
Expand Down

0 comments on commit 638c4ca

Please sign in to comment.