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

Remove owner from migrations #1533

Merged
merged 4 commits into from
Jan 31, 2019
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
12 changes: 12 additions & 0 deletions packages/migrations/CHANGELOG.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@
{
"note": "Upgrade the bignumber.js to v8.0.2",
"pr": 1517
},
{
"note": "Removed `owner` in Migrations",
"pr": 1533
},
{
"note": "`txDefaults` parameter now requires the `from` field",
"pr": 1533
},
{
"note": "Convert `from` to lower case when passed in via cli",
"pr": 1533
}
]
},
Expand Down
3 changes: 2 additions & 1 deletion packages/migrations/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ const args = yargs
const provider = new Web3ProviderEngine();
provider.addProvider(rpcSubprovider);
provider.start();
const normalizedFromAddress = (args.from as string).toLowerCase();
const txDefaults = {
from: args.from,
from: normalizedFromAddress,
};
await runMigrationsAsync(provider, txDefaults);
process.exit(0);
Expand Down
54 changes: 17 additions & 37 deletions packages/migrations/src/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ import { erc20TokenInfo, erc721TokenInfo } from './utils/token_info';
* @param txDefaults Default transaction values to use when deploying contracts (e.g., specify the desired contract creator with the `from` parameter).
* @returns The addresses of the contracts that were deployed.
*/
export async function runMigrationsAsync(provider: Provider, txDefaults: Partial<TxData>): Promise<ContractAddresses> {
export async function runMigrationsAsync(provider: Provider, txDefaults: TxData): Promise<ContractAddresses> {
const web3Wrapper = new Web3Wrapper(provider);
const accounts: string[] = await web3Wrapper.getAvailableAddressesAsync();
const owner = accounts[0];

// Proxies
const erc20Proxy = await wrappers.ERC20ProxyContract.deployFrom0xArtifactAsync(
Expand Down Expand Up @@ -84,48 +82,38 @@ export async function runMigrationsAsync(provider: Provider, txDefaults: Partial
);

await web3Wrapper.awaitTransactionSuccessAsync(
await erc20Proxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, {
from: owner,
}),
await erc20Proxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, txDefaults),
);
await web3Wrapper.awaitTransactionSuccessAsync(
await erc721Proxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, {
from: owner,
}),
await erc721Proxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, txDefaults),
);
await web3Wrapper.awaitTransactionSuccessAsync(
await multiAssetProxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, {
from: owner,
}),
await multiAssetProxy.addAuthorizedAddress.sendTransactionAsync(exchange.address, txDefaults),
);

// MultiAssetProxy
await web3Wrapper.awaitTransactionSuccessAsync(
await erc20Proxy.addAuthorizedAddress.sendTransactionAsync(multiAssetProxy.address, {
from: owner,
}),
await erc20Proxy.addAuthorizedAddress.sendTransactionAsync(multiAssetProxy.address, txDefaults),
);
await web3Wrapper.awaitTransactionSuccessAsync(
await erc721Proxy.addAuthorizedAddress.sendTransactionAsync(multiAssetProxy.address, {
from: owner,
}),
await erc721Proxy.addAuthorizedAddress.sendTransactionAsync(multiAssetProxy.address, txDefaults),
);
await web3Wrapper.awaitTransactionSuccessAsync(
await multiAssetProxy.registerAssetProxy.sendTransactionAsync(erc20Proxy.address),
await multiAssetProxy.registerAssetProxy.sendTransactionAsync(erc20Proxy.address, txDefaults),
);
await web3Wrapper.awaitTransactionSuccessAsync(
await multiAssetProxy.registerAssetProxy.sendTransactionAsync(erc721Proxy.address),
await multiAssetProxy.registerAssetProxy.sendTransactionAsync(erc721Proxy.address, txDefaults),
);

// Register the Asset Proxies to the Exchange
await web3Wrapper.awaitTransactionSuccessAsync(
await exchange.registerAssetProxy.sendTransactionAsync(erc20Proxy.address),
await exchange.registerAssetProxy.sendTransactionAsync(erc20Proxy.address, txDefaults),
);
await web3Wrapper.awaitTransactionSuccessAsync(
await exchange.registerAssetProxy.sendTransactionAsync(erc721Proxy.address),
await exchange.registerAssetProxy.sendTransactionAsync(erc721Proxy.address, txDefaults),
);
await web3Wrapper.awaitTransactionSuccessAsync(
await exchange.registerAssetProxy.sendTransactionAsync(multiAssetProxy.address),
await exchange.registerAssetProxy.sendTransactionAsync(multiAssetProxy.address, txDefaults),
);

// Forwarder
Expand Down Expand Up @@ -156,7 +144,8 @@ export async function runMigrationsAsync(provider: Provider, txDefaults: Partial
);

// Multisigs
const owners = [accounts[0], accounts[1]];
const accounts: string[] = await web3Wrapper.getAvailableAddressesAsync();
const owners = _.uniq([accounts[0], accounts[1], txDefaults.from]);
const confirmationsRequired = new BigNumber(2);
const secondsRequired = new BigNumber(0);

Expand All @@ -173,19 +162,13 @@ export async function runMigrationsAsync(provider: Provider, txDefaults: Partial

// Transfer Ownership to the Asset Proxy Owner
await web3Wrapper.awaitTransactionSuccessAsync(
await erc20Proxy.transferOwnership.sendTransactionAsync(assetProxyOwner.address, {
from: owner,
}),
await erc20Proxy.transferOwnership.sendTransactionAsync(assetProxyOwner.address, txDefaults),
);
await web3Wrapper.awaitTransactionSuccessAsync(
await erc721Proxy.transferOwnership.sendTransactionAsync(assetProxyOwner.address, {
from: owner,
}),
await erc721Proxy.transferOwnership.sendTransactionAsync(assetProxyOwner.address, txDefaults),
);
await web3Wrapper.awaitTransactionSuccessAsync(
await multiAssetProxy.transferOwnership.sendTransactionAsync(assetProxyOwner.address, {
from: owner,
}),
await multiAssetProxy.transferOwnership.sendTransactionAsync(assetProxyOwner.address, txDefaults),
);

// Fund the Forwarder with ZRX
Expand Down Expand Up @@ -220,10 +203,7 @@ let _cachedContractAddresses: ContractAddresses;
* @param txDefaults Default transaction values to use when deploying contracts (e.g., specify the desired contract creator with the `from` parameter).
* @returns The addresses of the contracts that were deployed.
*/
export async function runMigrationsOnceAsync(
provider: Provider,
txDefaults: Partial<TxData>,
): Promise<ContractAddresses> {
export async function runMigrationsOnceAsync(provider: Provider, txDefaults: TxData): Promise<ContractAddresses> {
if (!_.isUndefined(_cachedContractAddresses)) {
return _cachedContractAddresses;
}
Expand Down