Support arbitrary # of tokens in DeploymentManager
This commit is contained in:
parent
ce9f051d42
commit
f4cb8cfb7e
@ -1,3 +1,2 @@
|
|||||||
export * from './artifacts';
|
export * from './artifacts';
|
||||||
export * from './wrappers';
|
export * from './wrappers';
|
||||||
export * from './deployment_mananger';
|
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
import { Authorizable, Ownable } from '@0x/contracts-exchange';
|
import { Authorizable, Ownable } from '@0x/contracts-exchange';
|
||||||
import { constants as stakingConstants } from '@0x/contracts-staking';
|
import { constants as stakingConstants } from '@0x/contracts-staking';
|
||||||
import { blockchainTests, constants, expect } from '@0x/contracts-test-utils';
|
import { blockchainTests, expect } from '@0x/contracts-test-utils';
|
||||||
import { BigNumber } from '@0x/utils';
|
|
||||||
|
|
||||||
import { DeploymentManager } from '../src';
|
import { DeploymentManager } from './utils/deployment_mananger';
|
||||||
|
|
||||||
blockchainTests('Deployment Manager', env => {
|
blockchainTests('Deployment Manager', env => {
|
||||||
let owner: string;
|
let owner: string;
|
||||||
@ -11,7 +10,6 @@ blockchainTests('Deployment Manager', env => {
|
|||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
[owner] = await env.getAccountAddressesAsync();
|
[owner] = await env.getAccountAddressesAsync();
|
||||||
|
|
||||||
deploymentManager = await DeploymentManager.deployAsync(env);
|
deploymentManager = await DeploymentManager.deployAsync(env);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -6,9 +6,14 @@ import {
|
|||||||
MultiAssetProxyContract,
|
MultiAssetProxyContract,
|
||||||
StaticCallProxyContract,
|
StaticCallProxyContract,
|
||||||
} from '@0x/contracts-asset-proxy';
|
} from '@0x/contracts-asset-proxy';
|
||||||
import { artifacts as ERC1155Artifacts, ERC1155Contract } from '@0x/contracts-erc1155';
|
import { artifacts as ERC1155Artifacts, ERC1155MintableContract } from '@0x/contracts-erc1155';
|
||||||
import { artifacts as ERC20Artifacts, ERC20TokenContract, ZRXTokenContract, WETH9Contract } from '@0x/contracts-erc20';
|
import {
|
||||||
import { artifacts as ERC721Artifacts, ERC721TokenContract } from '@0x/contracts-erc721';
|
DummyERC20TokenContract,
|
||||||
|
artifacts as ERC20Artifacts,
|
||||||
|
ZRXTokenContract,
|
||||||
|
WETH9Contract,
|
||||||
|
} from '@0x/contracts-erc20';
|
||||||
|
import { artifacts as ERC721Artifacts, DummyERC721TokenContract } from '@0x/contracts-erc721';
|
||||||
import {
|
import {
|
||||||
artifacts as exchangeArtifacts,
|
artifacts as exchangeArtifacts,
|
||||||
AssetProxyDispatcher,
|
AssetProxyDispatcher,
|
||||||
@ -20,18 +25,15 @@ import { artifacts as multisigArtifacts, ZeroExGovernorContract } from '@0x/cont
|
|||||||
import {
|
import {
|
||||||
artifacts as stakingArtifacts,
|
artifacts as stakingArtifacts,
|
||||||
ReadOnlyProxyContract,
|
ReadOnlyProxyContract,
|
||||||
StakingContract,
|
|
||||||
StakingProxyContract,
|
StakingProxyContract,
|
||||||
|
TestStakingContract,
|
||||||
ZrxVaultContract,
|
ZrxVaultContract,
|
||||||
} from '@0x/contracts-staking';
|
} from '@0x/contracts-staking';
|
||||||
import { BlockchainTestsEnvironment, constants } from '@0x/contracts-test-utils';
|
import { BlockchainTestsEnvironment, constants } from '@0x/contracts-test-utils';
|
||||||
import { Web3ProviderEngine } from '@0x/subproviders';
|
|
||||||
import { BigNumber } from '@0x/utils';
|
import { BigNumber } from '@0x/utils';
|
||||||
import { TxData } from 'ethereum-types';
|
import { TxData } from 'ethereum-types';
|
||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
|
|
||||||
import { artifacts, TestStakingPlaceholderContract } from './';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a batch of authorities to a list of authorizable contracts.
|
* Adds a batch of authorities to a list of authorizable contracts.
|
||||||
* @param owner The owner of the authorizable contracts.
|
* @param owner The owner of the authorizable contracts.
|
||||||
@ -96,21 +98,29 @@ interface AssetProxyContracts {
|
|||||||
// Contract wrappers for all of the staking contracts
|
// Contract wrappers for all of the staking contracts
|
||||||
interface StakingContracts {
|
interface StakingContracts {
|
||||||
readOnlyProxy: ReadOnlyProxyContract;
|
readOnlyProxy: ReadOnlyProxyContract;
|
||||||
stakingLogic: TestStakingPlaceholderContract;
|
stakingLogic: TestStakingContract;
|
||||||
stakingProxy: StakingProxyContract;
|
stakingProxy: StakingProxyContract;
|
||||||
stakingWrapper: TestStakingPlaceholderContract;
|
stakingWrapper: TestStakingContract;
|
||||||
zrxVault: ZrxVaultContract;
|
zrxVault: ZrxVaultContract;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Contract wrappers for tokens.
|
// Contract wrappers for tokens.
|
||||||
interface TokenContracts {
|
interface TokenContracts {
|
||||||
erc1155: ERC1155Contract;
|
erc1155: ERC1155MintableContract[];
|
||||||
erc20: ERC20TokenContract;
|
erc20: DummyERC20TokenContract[];
|
||||||
erc721: ERC721TokenContract;
|
erc721: DummyERC721TokenContract[];
|
||||||
weth: WETH9Contract;
|
weth: WETH9Contract;
|
||||||
zrx: ZRXTokenContract;
|
zrx: ZRXTokenContract;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Options to be passed to `deployAsync`
|
||||||
|
export interface DeploymentOptions {
|
||||||
|
owner: string;
|
||||||
|
numErc1155TokensToDeploy: number;
|
||||||
|
numErc20TokensToDeploy: number;
|
||||||
|
numErc721TokensToDeploy: number;
|
||||||
|
}
|
||||||
|
|
||||||
export class DeploymentManager {
|
export class DeploymentManager {
|
||||||
public static protocolFeeMultiplier = new BigNumber(150000);
|
public static protocolFeeMultiplier = new BigNumber(150000);
|
||||||
|
|
||||||
@ -124,17 +134,21 @@ export class DeploymentManager {
|
|||||||
* Fully deploy the 0x exchange and staking contracts and configure the system with the
|
* Fully deploy the 0x exchange and staking contracts and configure the system with the
|
||||||
* asset proxy owner multisig.
|
* asset proxy owner multisig.
|
||||||
* @param environment A blockchain test environment to use for contracts deployment.
|
* @param environment A blockchain test environment to use for contracts deployment.
|
||||||
|
* @param options Specifies the owner address and number of tokens to deploy.
|
||||||
*/
|
*/
|
||||||
public static async deployAsync(environment: BlockchainTestsEnvironment): Promise<DeploymentManager> {
|
public static async deployAsync(
|
||||||
|
environment: BlockchainTestsEnvironment,
|
||||||
|
options: Partial<DeploymentOptions> = {},
|
||||||
|
): Promise<DeploymentManager> {
|
||||||
const chainId = await environment.getChainIdAsync();
|
const chainId = await environment.getChainIdAsync();
|
||||||
const [owner] = await environment.getAccountAddressesAsync();
|
const owner = options.owner || (await environment.getAccountAddressesAsync())[0];
|
||||||
const txDefaults = {
|
const txDefaults = {
|
||||||
...environment.txDefaults,
|
...environment.txDefaults,
|
||||||
from: owner,
|
from: owner,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Deploy the contracts using the same owner and environment.
|
// Deploy the contracts using the same owner and environment.
|
||||||
const assetProxies = await DeploymentManager._deployAssetProxyContractsAsync(environment, owner, txDefaults);
|
const assetProxies = await DeploymentManager._deployAssetProxyContractsAsync(environment, txDefaults);
|
||||||
const exchange = await ExchangeContract.deployFrom0xArtifactAsync(
|
const exchange = await ExchangeContract.deployFrom0xArtifactAsync(
|
||||||
exchangeArtifacts.Exchange,
|
exchangeArtifacts.Exchange,
|
||||||
environment.provider,
|
environment.provider,
|
||||||
@ -154,7 +168,7 @@ export class DeploymentManager {
|
|||||||
new BigNumber(1),
|
new BigNumber(1),
|
||||||
constants.ZERO_AMOUNT,
|
constants.ZERO_AMOUNT,
|
||||||
);
|
);
|
||||||
const tokens = await DeploymentManager._deployTokenContractsAsync(environment, txDefaults);
|
const tokens = await DeploymentManager._deployTokenContractsAsync(environment, txDefaults, options);
|
||||||
const staking = await DeploymentManager._deployStakingContractsAsync(
|
const staking = await DeploymentManager._deployStakingContractsAsync(
|
||||||
environment,
|
environment,
|
||||||
owner,
|
owner,
|
||||||
@ -273,12 +287,10 @@ export class DeploymentManager {
|
|||||||
/**
|
/**
|
||||||
* Deploy a set of asset proxy contracts.
|
* Deploy a set of asset proxy contracts.
|
||||||
* @param environment The blockchain environment to use.
|
* @param environment The blockchain environment to use.
|
||||||
* @param owner An owner address to use when configuring the asset proxies.
|
|
||||||
* @param txDefaults Defaults to use when deploying the asset proxies.
|
* @param txDefaults Defaults to use when deploying the asset proxies.
|
||||||
*/
|
*/
|
||||||
protected static async _deployAssetProxyContractsAsync(
|
protected static async _deployAssetProxyContractsAsync(
|
||||||
environment: BlockchainTestsEnvironment,
|
environment: BlockchainTestsEnvironment,
|
||||||
owner: string,
|
|
||||||
txDefaults: Partial<TxData>,
|
txDefaults: Partial<TxData>,
|
||||||
): Promise<AssetProxyContracts> {
|
): Promise<AssetProxyContracts> {
|
||||||
const erc20Proxy = await ERC20ProxyContract.deployFrom0xArtifactAsync(
|
const erc20Proxy = await ERC20ProxyContract.deployFrom0xArtifactAsync(
|
||||||
@ -349,8 +361,8 @@ export class DeploymentManager {
|
|||||||
txDefaults,
|
txDefaults,
|
||||||
stakingArtifacts,
|
stakingArtifacts,
|
||||||
);
|
);
|
||||||
const stakingLogic = await TestStakingPlaceholderContract.deployFrom0xArtifactAsync(
|
const stakingLogic = await TestStakingContract.deployFrom0xArtifactAsync(
|
||||||
artifacts.TestStakingPlaceholder,
|
stakingArtifacts.TestStaking,
|
||||||
environment.provider,
|
environment.provider,
|
||||||
txDefaults,
|
txDefaults,
|
||||||
stakingArtifacts,
|
stakingArtifacts,
|
||||||
@ -365,7 +377,7 @@ export class DeploymentManager {
|
|||||||
stakingLogic.address,
|
stakingLogic.address,
|
||||||
readOnlyProxy.address,
|
readOnlyProxy.address,
|
||||||
);
|
);
|
||||||
const stakingWrapper = new TestStakingPlaceholderContract(stakingProxy.address, environment.provider);
|
const stakingWrapper = new TestStakingContract(stakingProxy.address, environment.provider);
|
||||||
|
|
||||||
// Add the zrx vault and the weth contract to the staking proxy.
|
// Add the zrx vault and the weth contract to the staking proxy.
|
||||||
await stakingWrapper.setWethContract.awaitTransactionSuccessAsync(tokens.weth.address, { from: owner });
|
await stakingWrapper.setWethContract.awaitTransactionSuccessAsync(tokens.weth.address, { from: owner });
|
||||||
@ -392,30 +404,59 @@ export class DeploymentManager {
|
|||||||
* Deploy a set of token contracts.
|
* Deploy a set of token contracts.
|
||||||
* @param environment The blockchain environment to use.
|
* @param environment The blockchain environment to use.
|
||||||
* @param txDefaults Defaults to use when deploying the asset proxies.
|
* @param txDefaults Defaults to use when deploying the asset proxies.
|
||||||
|
* @param options Specifies how many tokens of each standard to deploy.
|
||||||
*/
|
*/
|
||||||
protected static async _deployTokenContractsAsync(
|
protected static async _deployTokenContractsAsync(
|
||||||
environment: BlockchainTestsEnvironment,
|
environment: BlockchainTestsEnvironment,
|
||||||
txDefaults: Partial<TxData>,
|
txDefaults: Partial<TxData>,
|
||||||
|
options: Partial<DeploymentOptions>,
|
||||||
): Promise<TokenContracts> {
|
): Promise<TokenContracts> {
|
||||||
const erc20 = await ERC20TokenContract.deployFrom0xArtifactAsync(
|
const numErc1155TokensToDeploy =
|
||||||
ERC20Artifacts.ERC20Token,
|
options.numErc1155TokensToDeploy || constants.NUM_DUMMY_ERC1155_CONTRACTS_TO_DEPLOY;
|
||||||
environment.provider,
|
const numErc20TokensToDeploy = options.numErc20TokensToDeploy || constants.NUM_DUMMY_ERC20_TO_DEPLOY;
|
||||||
txDefaults,
|
const numErc721TokensToDeploy = options.numErc721TokensToDeploy || constants.NUM_DUMMY_ERC721_TO_DEPLOY;
|
||||||
ERC20Artifacts,
|
|
||||||
);
|
|
||||||
|
|
||||||
const erc721 = await ERC721TokenContract.deployFrom0xArtifactAsync(
|
const erc1155 = await Promise.all(
|
||||||
ERC721Artifacts.ERC721Token,
|
_.times(
|
||||||
environment.provider,
|
numErc1155TokensToDeploy,
|
||||||
txDefaults,
|
async () =>
|
||||||
ERC721Artifacts,
|
await ERC1155MintableContract.deployFrom0xArtifactAsync(
|
||||||
);
|
ERC1155Artifacts.ERC1155Mintable,
|
||||||
|
|
||||||
const erc1155 = await ERC1155Contract.deployFrom0xArtifactAsync(
|
|
||||||
ERC1155Artifacts.ERC1155,
|
|
||||||
environment.provider,
|
environment.provider,
|
||||||
txDefaults,
|
txDefaults,
|
||||||
ERC1155Artifacts,
|
ERC1155Artifacts,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
const erc20 = await Promise.all(
|
||||||
|
_.times(
|
||||||
|
numErc20TokensToDeploy,
|
||||||
|
async () =>
|
||||||
|
await DummyERC20TokenContract.deployFrom0xArtifactAsync(
|
||||||
|
ERC20Artifacts.DummyERC20Token,
|
||||||
|
environment.provider,
|
||||||
|
txDefaults,
|
||||||
|
ERC20Artifacts,
|
||||||
|
constants.DUMMY_TOKEN_NAME,
|
||||||
|
constants.DUMMY_TOKEN_SYMBOL,
|
||||||
|
constants.DUMMY_TOKEN_DECIMALS,
|
||||||
|
constants.DUMMY_TOKEN_TOTAL_SUPPLY,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
const erc721 = await Promise.all(
|
||||||
|
_.times(
|
||||||
|
numErc721TokensToDeploy,
|
||||||
|
async () =>
|
||||||
|
await DummyERC721TokenContract.deployFrom0xArtifactAsync(
|
||||||
|
ERC721Artifacts.DummyERC721Token,
|
||||||
|
environment.provider,
|
||||||
|
txDefaults,
|
||||||
|
ERC721Artifacts,
|
||||||
|
constants.DUMMY_TOKEN_NAME,
|
||||||
|
constants.DUMMY_TOKEN_SYMBOL,
|
||||||
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
const weth = await WETH9Contract.deployFrom0xArtifactAsync(
|
const weth = await WETH9Contract.deployFrom0xArtifactAsync(
|
||||||
@ -424,7 +465,6 @@ export class DeploymentManager {
|
|||||||
txDefaults,
|
txDefaults,
|
||||||
ERC20Artifacts,
|
ERC20Artifacts,
|
||||||
);
|
);
|
||||||
|
|
||||||
const zrx = await ZRXTokenContract.deployFrom0xArtifactAsync(
|
const zrx = await ZRXTokenContract.deployFrom0xArtifactAsync(
|
||||||
ERC20Artifacts.ZRXToken,
|
ERC20Artifacts.ZRXToken,
|
||||||
environment.provider,
|
environment.provider,
|
||||||
@ -441,7 +481,7 @@ export class DeploymentManager {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private constructor(
|
constructor(
|
||||||
assetProxies: AssetProxyContracts,
|
assetProxies: AssetProxyContracts,
|
||||||
governor: ZeroExGovernorContract,
|
governor: ZeroExGovernorContract,
|
||||||
exchange: ExchangeContract,
|
exchange: ExchangeContract,
|
Loading…
x
Reference in New Issue
Block a user