Add Exchange Proxy to Ganache snapshot (#2612)
* `@0x/contracts-zero-ex`: Expose migration tools. * `@0x/contract-addresses`: Update ganache snapshot Exchange Proxy addresses * `@0x/migrations`: Add Exchange Proxy migration
This commit is contained in:
@@ -1,4 +1,13 @@
|
||||
[
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Export migration tools",
|
||||
"pr": 2612
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1592969527,
|
||||
"version": "0.1.1",
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
"docs:json": "typedoc --excludePrivate --excludeExternals --excludeProtected --ignoreCompilerErrors --target ES5 --tsconfig typedoc-tsconfig.json --json $JSON_FILE_PATH $PROJECT_FILES"
|
||||
},
|
||||
"config": {
|
||||
"publicInterfaceContracts": "ZeroEx,FullMigration,InitialMigration,IFlashWallet,IAllowanceTarget,IERC20Transformer,IOwnable,ISimpleFunctionRegistry,ITokenSpender,ITransformERC20,FillQuoteTransformer,PayTakerTransformer,WethTransformer",
|
||||
"publicInterfaceContracts": "ZeroEx,FullMigration,InitialMigration,IFlashWallet,IAllowanceTarget,IERC20Transformer,IOwnable,ISimpleFunctionRegistry,ITokenSpender,ITransformERC20,FillQuoteTransformer,PayTakerTransformer,WethTransformer,Ownable,SimpleFunctionRegistry,TransformERC20,TokenSpender",
|
||||
"abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually.",
|
||||
"abis": "./test/generated-artifacts/@(AffiliateFeeTransformer|AllowanceTarget|Bootstrap|FillQuoteTransformer|FixinCommon|FlashWallet|FullMigration|IAllowanceTarget|IBootstrap|IERC20Transformer|IExchange|IFeature|IFlashWallet|IOwnable|ISimpleFunctionRegistry|ITestSimpleFunctionRegistryFeature|ITokenSpender|ITransformERC20|InitialMigration|LibBootstrap|LibCommonRichErrors|LibERC20Transformer|LibMigrate|LibOwnableRichErrors|LibOwnableStorage|LibProxyRichErrors|LibProxyStorage|LibSimpleFunctionRegistryRichErrors|LibSimpleFunctionRegistryStorage|LibSpenderRichErrors|LibStorage|LibTokenSpenderStorage|LibTransformERC20RichErrors|LibTransformERC20Storage|LibWalletRichErrors|Ownable|PayTakerTransformer|SimpleFunctionRegistry|TestCallTarget|TestDelegateCaller|TestFillQuoteTransformerExchange|TestFillQuoteTransformerHost|TestFullMigration|TestInitialMigration|TestMigrator|TestMintTokenERC20Transformer|TestMintableERC20Token|TestSimpleFunctionRegistryFeatureImpl1|TestSimpleFunctionRegistryFeatureImpl2|TestTokenSpender|TestTokenSpenderERC20Token|TestTransformERC20|TestTransformerBase|TestTransformerDeployerTransformer|TestTransformerHost|TestWeth|TestWethTransformerHost|TestZeroExFeature|TokenSpender|TransformERC20|Transformer|TransformerDeployer|WethTransformer|ZeroEx).json"
|
||||
},
|
||||
@@ -58,7 +58,6 @@
|
||||
"@0x/dev-utils": "^3.2.2",
|
||||
"@0x/order-utils": "^10.3.0",
|
||||
"@0x/sol-compiler": "^4.1.0",
|
||||
"@0x/subproviders": "^6.1.0",
|
||||
"@0x/ts-doc-gen": "^0.0.22",
|
||||
"@0x/tslint-config": "^4.0.0",
|
||||
"@types/lodash": "4.14.104",
|
||||
@@ -75,6 +74,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@0x/base-contract": "^6.2.2",
|
||||
"@0x/subproviders": "^6.1.0",
|
||||
"@0x/types": "^3.1.3",
|
||||
"@0x/typescript-typings": "^5.1.0",
|
||||
"@0x/utils": "^5.5.0",
|
||||
|
||||
@@ -15,7 +15,11 @@ import * as IOwnable from '../generated-artifacts/IOwnable.json';
|
||||
import * as ISimpleFunctionRegistry from '../generated-artifacts/ISimpleFunctionRegistry.json';
|
||||
import * as ITokenSpender from '../generated-artifacts/ITokenSpender.json';
|
||||
import * as ITransformERC20 from '../generated-artifacts/ITransformERC20.json';
|
||||
import * as Ownable from '../generated-artifacts/Ownable.json';
|
||||
import * as PayTakerTransformer from '../generated-artifacts/PayTakerTransformer.json';
|
||||
import * as SimpleFunctionRegistry from '../generated-artifacts/SimpleFunctionRegistry.json';
|
||||
import * as TokenSpender from '../generated-artifacts/TokenSpender.json';
|
||||
import * as TransformERC20 from '../generated-artifacts/TransformERC20.json';
|
||||
import * as WethTransformer from '../generated-artifacts/WethTransformer.json';
|
||||
import * as ZeroEx from '../generated-artifacts/ZeroEx.json';
|
||||
export const artifacts = {
|
||||
@@ -32,4 +36,8 @@ export const artifacts = {
|
||||
FillQuoteTransformer: FillQuoteTransformer as ContractArtifact,
|
||||
PayTakerTransformer: PayTakerTransformer as ContractArtifact,
|
||||
WethTransformer: WethTransformer as ContractArtifact,
|
||||
Ownable: Ownable as ContractArtifact,
|
||||
SimpleFunctionRegistry: SimpleFunctionRegistry as ContractArtifact,
|
||||
TransformERC20: TransformERC20 as ContractArtifact,
|
||||
TokenSpender: TokenSpender as ContractArtifact,
|
||||
};
|
||||
|
||||
@@ -41,3 +41,6 @@ export {
|
||||
TupleDataItem,
|
||||
StateMutability,
|
||||
} from 'ethereum-types';
|
||||
|
||||
export * from './nonce_utils';
|
||||
export * from './migration';
|
||||
|
||||
130
contracts/zero-ex/src/migration.ts
Normal file
130
contracts/zero-ex/src/migration.ts
Normal file
@@ -0,0 +1,130 @@
|
||||
import { BaseContract } from '@0x/base-contract';
|
||||
import { SupportedProvider } from '@0x/subproviders';
|
||||
import { TxData } from 'ethereum-types';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import { artifacts } from './artifacts';
|
||||
import {
|
||||
FullMigrationContract,
|
||||
InitialMigrationContract,
|
||||
OwnableContract,
|
||||
SimpleFunctionRegistryContract,
|
||||
TokenSpenderContract,
|
||||
TransformERC20Contract,
|
||||
ZeroExContract,
|
||||
} from './wrappers';
|
||||
|
||||
// tslint:disable: completed-docs
|
||||
|
||||
export interface BootstrapFeatures {
|
||||
registry: SimpleFunctionRegistryContract;
|
||||
ownable: OwnableContract;
|
||||
}
|
||||
|
||||
export async function deployBootstrapFeaturesAsync(
|
||||
provider: SupportedProvider,
|
||||
txDefaults: Partial<TxData>,
|
||||
features: Partial<BootstrapFeatures> = {},
|
||||
): Promise<BootstrapFeatures> {
|
||||
return {
|
||||
registry:
|
||||
features.registry ||
|
||||
(await SimpleFunctionRegistryContract.deployFrom0xArtifactAsync(
|
||||
artifacts.SimpleFunctionRegistry,
|
||||
provider,
|
||||
txDefaults,
|
||||
artifacts,
|
||||
)),
|
||||
ownable:
|
||||
features.ownable ||
|
||||
(await OwnableContract.deployFrom0xArtifactAsync(artifacts.Ownable, provider, txDefaults, artifacts)),
|
||||
};
|
||||
}
|
||||
|
||||
export async function initialMigrateAsync(
|
||||
owner: string,
|
||||
provider: SupportedProvider,
|
||||
txDefaults: Partial<TxData>,
|
||||
features: Partial<BootstrapFeatures> = {},
|
||||
): Promise<ZeroExContract> {
|
||||
const _features = await deployBootstrapFeaturesAsync(provider, txDefaults, features);
|
||||
const migrator = await InitialMigrationContract.deployFrom0xArtifactAsync(
|
||||
artifacts.InitialMigration,
|
||||
provider,
|
||||
txDefaults,
|
||||
artifacts,
|
||||
txDefaults.from as string,
|
||||
);
|
||||
const deployCall = migrator.deploy(owner, toFeatureAdddresses(_features));
|
||||
const zeroEx = new ZeroExContract(await deployCall.callAsync(), provider, {});
|
||||
await deployCall.awaitTransactionSuccessAsync();
|
||||
return zeroEx;
|
||||
}
|
||||
|
||||
export interface FullFeatures extends BootstrapFeatures {
|
||||
tokenSpender: TokenSpenderContract;
|
||||
transformERC20: TransformERC20Contract;
|
||||
}
|
||||
|
||||
export interface FullMigrationOpts {
|
||||
transformerDeployer: string;
|
||||
}
|
||||
|
||||
export async function deployFullFeaturesAsync(
|
||||
provider: SupportedProvider,
|
||||
txDefaults: Partial<TxData>,
|
||||
features: Partial<FullFeatures> = {},
|
||||
): Promise<FullFeatures> {
|
||||
return {
|
||||
...(await deployBootstrapFeaturesAsync(provider, txDefaults)),
|
||||
tokenSpender:
|
||||
features.tokenSpender ||
|
||||
(await TokenSpenderContract.deployFrom0xArtifactAsync(
|
||||
artifacts.TokenSpender,
|
||||
provider,
|
||||
txDefaults,
|
||||
artifacts,
|
||||
)),
|
||||
transformERC20:
|
||||
features.transformERC20 ||
|
||||
(await TransformERC20Contract.deployFrom0xArtifactAsync(
|
||||
artifacts.TransformERC20,
|
||||
provider,
|
||||
txDefaults,
|
||||
artifacts,
|
||||
)),
|
||||
};
|
||||
}
|
||||
|
||||
export async function fullMigrateAsync(
|
||||
owner: string,
|
||||
provider: SupportedProvider,
|
||||
txDefaults: Partial<TxData>,
|
||||
features: Partial<FullFeatures> = {},
|
||||
opts: Partial<FullMigrationOpts> = {},
|
||||
): Promise<ZeroExContract> {
|
||||
const _features = await deployFullFeaturesAsync(provider, txDefaults, features);
|
||||
const migrator = await FullMigrationContract.deployFrom0xArtifactAsync(
|
||||
artifacts.FullMigration,
|
||||
provider,
|
||||
txDefaults,
|
||||
artifacts,
|
||||
txDefaults.from as string,
|
||||
);
|
||||
const _opts = {
|
||||
transformerDeployer: txDefaults.from as string,
|
||||
...opts,
|
||||
};
|
||||
const deployCall = migrator.deploy(owner, toFeatureAdddresses(_features), _opts);
|
||||
const zeroEx = new ZeroExContract(await deployCall.callAsync(), provider, {});
|
||||
await deployCall.awaitTransactionSuccessAsync();
|
||||
return zeroEx;
|
||||
}
|
||||
|
||||
// tslint:disable:space-before-function-parent one-line
|
||||
export function toFeatureAdddresses<T extends BootstrapFeatures | FullFeatures | (BootstrapFeatures & FullFeatures)>(
|
||||
features: T,
|
||||
): { [name in keyof T]: string } {
|
||||
// TS can't figure this out.
|
||||
return _.mapValues(features, (c: BaseContract) => c.address) as any;
|
||||
}
|
||||
@@ -13,6 +13,10 @@ export * from '../generated-wrappers/i_simple_function_registry';
|
||||
export * from '../generated-wrappers/i_token_spender';
|
||||
export * from '../generated-wrappers/i_transform_erc20';
|
||||
export * from '../generated-wrappers/initial_migration';
|
||||
export * from '../generated-wrappers/ownable';
|
||||
export * from '../generated-wrappers/pay_taker_transformer';
|
||||
export * from '../generated-wrappers/simple_function_registry';
|
||||
export * from '../generated-wrappers/token_spender';
|
||||
export * from '../generated-wrappers/transform_erc20';
|
||||
export * from '../generated-wrappers/weth_transformer';
|
||||
export * from '../generated-wrappers/zero_ex';
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { blockchainTests, constants, expect, randomAddress, verifyEventsFromLogs } from '@0x/contracts-test-utils';
|
||||
import { BigNumber, hexUtils, OwnableRevertErrors, ZeroExRevertErrors } from '@0x/utils';
|
||||
|
||||
import { ZeroExContract } from '../../src/wrappers';
|
||||
import { artifacts } from '../artifacts';
|
||||
import { initialMigrateAsync } from '../utils/migration';
|
||||
import {
|
||||
@@ -9,7 +10,6 @@ import {
|
||||
ITestSimpleFunctionRegistryFeatureContract,
|
||||
TestSimpleFunctionRegistryFeatureImpl1Contract,
|
||||
TestSimpleFunctionRegistryFeatureImpl2Contract,
|
||||
ZeroExContract,
|
||||
} from '../wrappers';
|
||||
|
||||
blockchainTests.resets('SimpleFunctionRegistry feature', env => {
|
||||
|
||||
@@ -7,15 +7,11 @@ import {
|
||||
} from '@0x/contracts-test-utils';
|
||||
import { BigNumber, hexUtils, StringRevertError, ZeroExRevertErrors } from '@0x/utils';
|
||||
|
||||
import { TokenSpenderContract, ZeroExContract } from '../../src/wrappers';
|
||||
import { artifacts } from '../artifacts';
|
||||
import { abis } from '../utils/abis';
|
||||
import { fullMigrateAsync } from '../utils/migration';
|
||||
import {
|
||||
TestTokenSpenderERC20TokenContract,
|
||||
TestTokenSpenderERC20TokenEvents,
|
||||
TokenSpenderContract,
|
||||
ZeroExContract,
|
||||
} from '../wrappers';
|
||||
import { TestTokenSpenderERC20TokenContract, TestTokenSpenderERC20TokenEvents } from '../wrappers';
|
||||
|
||||
blockchainTests.resets('TokenSpender feature', env => {
|
||||
let zeroEx: ZeroExContract;
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
import { ETH_TOKEN_ADDRESS } from '@0x/order-utils';
|
||||
import { AbiEncoder, hexUtils, OwnableRevertErrors, ZeroExRevertErrors } from '@0x/utils';
|
||||
|
||||
import { TransformERC20Contract, ZeroExContract } from '../../src/wrappers';
|
||||
import { artifacts } from '../artifacts';
|
||||
import { abis } from '../utils/abis';
|
||||
import { fullMigrateAsync } from '../utils/migration';
|
||||
@@ -20,9 +21,7 @@ import {
|
||||
TestMintableERC20TokenContract,
|
||||
TestMintTokenERC20TransformerContract,
|
||||
TestMintTokenERC20TransformerEvents,
|
||||
TransformERC20Contract,
|
||||
TransformERC20Events,
|
||||
ZeroExContract,
|
||||
} from '../wrappers';
|
||||
|
||||
blockchainTests.resets('TransformERC20 feature', env => {
|
||||
|
||||
@@ -1,130 +1,10 @@
|
||||
import { BaseContract } from '@0x/base-contract';
|
||||
import { SupportedProvider } from '@0x/subproviders';
|
||||
import { TxData } from 'ethereum-types';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import { artifacts } from '../artifacts';
|
||||
import {
|
||||
FullMigrationContract,
|
||||
InitialMigrationContract,
|
||||
OwnableContract,
|
||||
SimpleFunctionRegistryContract,
|
||||
TokenSpenderContract,
|
||||
TransformERC20Contract,
|
||||
ZeroExContract,
|
||||
} from '../wrappers';
|
||||
|
||||
// tslint:disable: completed-docs
|
||||
|
||||
export interface BootstrapFeatures {
|
||||
registry: SimpleFunctionRegistryContract;
|
||||
ownable: OwnableContract;
|
||||
}
|
||||
|
||||
export async function deployBootstrapFeaturesAsync(
|
||||
provider: SupportedProvider,
|
||||
txDefaults: Partial<TxData>,
|
||||
features: Partial<BootstrapFeatures> = {},
|
||||
): Promise<BootstrapFeatures> {
|
||||
return {
|
||||
registry:
|
||||
features.registry ||
|
||||
(await SimpleFunctionRegistryContract.deployFrom0xArtifactAsync(
|
||||
artifacts.SimpleFunctionRegistry,
|
||||
provider,
|
||||
txDefaults,
|
||||
artifacts,
|
||||
)),
|
||||
ownable:
|
||||
features.ownable ||
|
||||
(await OwnableContract.deployFrom0xArtifactAsync(artifacts.Ownable, provider, txDefaults, artifacts)),
|
||||
};
|
||||
}
|
||||
|
||||
export async function initialMigrateAsync(
|
||||
owner: string,
|
||||
provider: SupportedProvider,
|
||||
txDefaults: Partial<TxData>,
|
||||
features: Partial<BootstrapFeatures> = {},
|
||||
): Promise<ZeroExContract> {
|
||||
const _features = await deployBootstrapFeaturesAsync(provider, txDefaults, features);
|
||||
const migrator = await InitialMigrationContract.deployFrom0xArtifactAsync(
|
||||
artifacts.InitialMigration,
|
||||
provider,
|
||||
txDefaults,
|
||||
artifacts,
|
||||
txDefaults.from as string,
|
||||
);
|
||||
const deployCall = migrator.deploy(owner, toFeatureAdddresses(_features));
|
||||
const zeroEx = new ZeroExContract(await deployCall.callAsync(), provider, {});
|
||||
await deployCall.awaitTransactionSuccessAsync();
|
||||
return zeroEx;
|
||||
}
|
||||
|
||||
export interface FullFeatures extends BootstrapFeatures {
|
||||
tokenSpender: TokenSpenderContract;
|
||||
transformERC20: TransformERC20Contract;
|
||||
}
|
||||
|
||||
export interface FullMigrationOpts {
|
||||
transformerDeployer: string;
|
||||
}
|
||||
|
||||
export async function deployFullFeaturesAsync(
|
||||
provider: SupportedProvider,
|
||||
txDefaults: Partial<TxData>,
|
||||
features: Partial<FullFeatures> = {},
|
||||
): Promise<FullFeatures> {
|
||||
return {
|
||||
...(await deployBootstrapFeaturesAsync(provider, txDefaults)),
|
||||
tokenSpender:
|
||||
features.tokenSpender ||
|
||||
(await TokenSpenderContract.deployFrom0xArtifactAsync(
|
||||
artifacts.TokenSpender,
|
||||
provider,
|
||||
txDefaults,
|
||||
artifacts,
|
||||
)),
|
||||
transformERC20:
|
||||
features.transformERC20 ||
|
||||
(await TransformERC20Contract.deployFrom0xArtifactAsync(
|
||||
artifacts.TransformERC20,
|
||||
provider,
|
||||
txDefaults,
|
||||
artifacts,
|
||||
)),
|
||||
};
|
||||
}
|
||||
|
||||
export async function fullMigrateAsync(
|
||||
owner: string,
|
||||
provider: SupportedProvider,
|
||||
txDefaults: Partial<TxData>,
|
||||
features: Partial<FullFeatures> = {},
|
||||
opts: Partial<FullMigrationOpts> = {},
|
||||
): Promise<ZeroExContract> {
|
||||
const _features = await deployFullFeaturesAsync(provider, txDefaults, features);
|
||||
const migrator = await FullMigrationContract.deployFrom0xArtifactAsync(
|
||||
artifacts.FullMigration,
|
||||
provider,
|
||||
txDefaults,
|
||||
artifacts,
|
||||
txDefaults.from as string,
|
||||
);
|
||||
const _opts = {
|
||||
transformerDeployer: txDefaults.from as string,
|
||||
...opts,
|
||||
};
|
||||
const deployCall = migrator.deploy(owner, toFeatureAdddresses(_features), _opts);
|
||||
const zeroEx = new ZeroExContract(await deployCall.callAsync(), provider, {});
|
||||
await deployCall.awaitTransactionSuccessAsync();
|
||||
return zeroEx;
|
||||
}
|
||||
|
||||
// tslint:disable:space-before-function-parent one-line
|
||||
export function toFeatureAdddresses<T extends BootstrapFeatures | FullFeatures | (BootstrapFeatures & FullFeatures)>(
|
||||
features: T,
|
||||
): { [name in keyof T]: string } {
|
||||
// TS can't figure this out.
|
||||
return _.mapValues(features, (c: BaseContract) => c.address) as any;
|
||||
}
|
||||
export {
|
||||
BootstrapFeatures,
|
||||
deployBootstrapFeaturesAsync,
|
||||
deployFullFeaturesAsync,
|
||||
initialMigrateAsync,
|
||||
fullMigrateAsync,
|
||||
toFeatureAdddresses,
|
||||
FullMigrationOpts,
|
||||
FullFeatures,
|
||||
} from '../../src/migration';
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { blockchainTests, constants, expect, verifyEventsFromLogs } from '@0x/contracts-test-utils';
|
||||
import { BigNumber, ZeroExRevertErrors } from '@0x/utils';
|
||||
|
||||
import { ZeroExContract } from '../src/wrappers';
|
||||
|
||||
import { artifacts } from './artifacts';
|
||||
import { initialMigrateAsync } from './utils/migration';
|
||||
import {
|
||||
@@ -9,7 +11,6 @@ import {
|
||||
ISimpleFunctionRegistryContract,
|
||||
TestZeroExFeatureContract,
|
||||
TestZeroExFeatureEvents,
|
||||
ZeroExContract,
|
||||
} from './wrappers';
|
||||
|
||||
blockchainTests.resets('ZeroEx contract', env => {
|
||||
|
||||
@@ -13,7 +13,11 @@
|
||||
"generated-artifacts/ITokenSpender.json",
|
||||
"generated-artifacts/ITransformERC20.json",
|
||||
"generated-artifacts/InitialMigration.json",
|
||||
"generated-artifacts/Ownable.json",
|
||||
"generated-artifacts/PayTakerTransformer.json",
|
||||
"generated-artifacts/SimpleFunctionRegistry.json",
|
||||
"generated-artifacts/TokenSpender.json",
|
||||
"generated-artifacts/TransformERC20.json",
|
||||
"generated-artifacts/WethTransformer.json",
|
||||
"generated-artifacts/ZeroEx.json",
|
||||
"test/generated-artifacts/AffiliateFeeTransformer.json",
|
||||
|
||||
Reference in New Issue
Block a user