EP Native Orders (#27)
* `@0x/contracts-zero-ex`: add limit orders feature `@0x/contracts-utils`: add `uint128` functions to `LibSafeMathV06` * `@0x/contract-addresses`: Update ganache snapshot addresses * `@0x/contracts-zero-ex`: Mask EIP712 struct hash values. * `@0x/contracts-zero-ex`: Add more limit order tests * `@0x/contracts-zero-ex`: Fix typos * `@0x/contracts-zero-ex`: Compute fee collector address after protocol fee zero check. * `@0x/contracts-zero-ex`: Remove WETH payment logic from fee collector fixin * `@0x/contracts-zero-ex`: Convert all ETH to WETH in `FeeCollector`. * `@0x/contracts-zero-ex`: Address review feedback * `@0x/contracts-zero-ex`: Export more utils * `@0x/contracts-zero-ex`: Rename `LimitOrdersFeatures`, `LibLimitOrders`, etc. into `*NativeOrders*`. `@0x/contracts-zero-ex`: Emit `protocolFeePaid` in native order fill events. `@0x/contracts-zero-ex`: Refactor to get around stack limits. `@0x/contracts-zero-ex`: Use different storage mappings for RFQ and limit order pair cancellations. * `@0x/contracts-zero-ex`: Add `getProtocolFeeMultiplier()` and `transferProtocolFeesForPools()` to `NativeOrdersFeature`. * `@0x/contracts-zero-ex`: Fix broken tests * update orders docs * `@0x/contracts-zero-ex`: Add more tests to `NativeOrdersFeature` * rebuild after rebase * `@0x/contract-addresses`: Fix changelog booboo * `@0x/contracts-zero-ex`: Add method selectors output to generated artifacts * `@0x/contracts-zero-ex`: Add maker address to order cancel events. `@0x/contracts-zreo-ex`: Remove `UpTo` suffix from order pair cancellation functions. `@0x/contracts-zreo-ex`: Address misc review comments. * `@0x/contracts-zero-ex`: More SafeMath in native orders * update orders docs Co-authored-by: Lawrence Forman <me@merklejerk.com>
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import { SupportedProvider } from '@0x/subproviders';
|
||||
import { SimpleContractArtifact } from '@0x/types';
|
||||
import { NULL_ADDRESS } from '@0x/utils';
|
||||
import { TxData } from 'ethereum-types';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
@@ -8,6 +10,7 @@ import {
|
||||
InitialMigrationContract,
|
||||
IZeroExContract,
|
||||
MetaTransactionsFeatureContract,
|
||||
NativeOrdersFeatureContract,
|
||||
OwnableFeatureContract,
|
||||
SignatureValidatorFeatureContract,
|
||||
SimpleFunctionRegistryFeatureContract,
|
||||
@@ -26,6 +29,19 @@ export interface BootstrapFeatures {
|
||||
ownable: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Artifacts to use when deploying bootstrap features.
|
||||
*/
|
||||
export interface BootstrapFeatureArtifacts {
|
||||
registry: SimpleContractArtifact;
|
||||
ownable: SimpleContractArtifact;
|
||||
}
|
||||
|
||||
const DEFAULT_BOOTSTRAP_FEATURE_ARTIFACTS = {
|
||||
registry: artifacts.SimpleFunctionRegistryFeature,
|
||||
ownable: artifacts.OwnableFeature,
|
||||
};
|
||||
|
||||
/**
|
||||
* Deploy the minimum features of the Exchange Proxy.
|
||||
*/
|
||||
@@ -33,12 +49,17 @@ export async function deployBootstrapFeaturesAsync(
|
||||
provider: SupportedProvider,
|
||||
txDefaults: Partial<TxData>,
|
||||
features: Partial<BootstrapFeatures> = {},
|
||||
featureArtifacts: Partial<BootstrapFeatureArtifacts> = {},
|
||||
): Promise<BootstrapFeatures> {
|
||||
const _featureArtifacts = {
|
||||
...DEFAULT_BOOTSTRAP_FEATURE_ARTIFACTS,
|
||||
...featureArtifacts,
|
||||
};
|
||||
return {
|
||||
registry:
|
||||
features.registry ||
|
||||
(await SimpleFunctionRegistryFeatureContract.deployFrom0xArtifactAsync(
|
||||
artifacts.SimpleFunctionRegistryFeature,
|
||||
_featureArtifacts.registry,
|
||||
provider,
|
||||
txDefaults,
|
||||
artifacts,
|
||||
@@ -46,7 +67,7 @@ export async function deployBootstrapFeaturesAsync(
|
||||
ownable:
|
||||
features.ownable ||
|
||||
(await OwnableFeatureContract.deployFrom0xArtifactAsync(
|
||||
artifacts.OwnableFeature,
|
||||
_featureArtifacts.ownable,
|
||||
provider,
|
||||
txDefaults,
|
||||
artifacts,
|
||||
@@ -90,30 +111,73 @@ export interface FullFeatures extends BootstrapFeatures {
|
||||
transformERC20: string;
|
||||
signatureValidator: string;
|
||||
metaTransactions: string;
|
||||
nativeOrders: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extra configuration options for a full migration of the Exchange Proxy.
|
||||
* Artifacts to use when deploying full features.
|
||||
*/
|
||||
export interface FullMigrationOpts {
|
||||
transformerDeployer: string;
|
||||
export interface FullFeatureArtifacts extends BootstrapFeatureArtifacts {
|
||||
tokenSpender: SimpleContractArtifact;
|
||||
transformERC20: SimpleContractArtifact;
|
||||
signatureValidator: SimpleContractArtifact;
|
||||
metaTransactions: SimpleContractArtifact;
|
||||
nativeOrders: SimpleContractArtifact;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configuration for deploying full features..
|
||||
*/
|
||||
export interface FullFeaturesDeployConfig {
|
||||
zeroExAddress: string;
|
||||
wethAddress: string;
|
||||
stakingAddress: string;
|
||||
protocolFeeMultiplier: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configuration options for a full migration of the Exchange Proxy.
|
||||
*/
|
||||
export interface FullMigrationConfig extends FullFeaturesDeployConfig {
|
||||
transformerDeployer?: string;
|
||||
}
|
||||
|
||||
const DEFAULT_FULL_FEATURES_DEPLOY_CONFIG = {
|
||||
zeroExAddress: NULL_ADDRESS,
|
||||
wethAddress: NULL_ADDRESS,
|
||||
stakingAddress: NULL_ADDRESS,
|
||||
protocolFeeMultiplier: 70e3,
|
||||
};
|
||||
|
||||
const DEFAULT_FULL_FEATURES_ARTIFACTS = {
|
||||
tokenSpender: artifacts.TokenSpenderFeature,
|
||||
transformERC20: artifacts.TransformERC20Feature,
|
||||
signatureValidator: artifacts.SignatureValidatorFeature,
|
||||
metaTransactions: artifacts.MetaTransactionsFeature,
|
||||
nativeOrders: artifacts.NativeOrdersFeature,
|
||||
};
|
||||
|
||||
/**
|
||||
* Deploy all the features for a full Exchange Proxy.
|
||||
*/
|
||||
export async function deployFullFeaturesAsync(
|
||||
provider: SupportedProvider,
|
||||
txDefaults: Partial<TxData>,
|
||||
zeroExAddress: string,
|
||||
config: Partial<FullFeaturesDeployConfig> = {},
|
||||
features: Partial<FullFeatures> = {},
|
||||
featureArtifacts: Partial<FullFeatureArtifacts> = {},
|
||||
): Promise<FullFeatures> {
|
||||
const _config = { ...DEFAULT_FULL_FEATURES_DEPLOY_CONFIG, ...config };
|
||||
const _featureArtifacts = {
|
||||
...DEFAULT_FULL_FEATURES_ARTIFACTS,
|
||||
...featureArtifacts,
|
||||
};
|
||||
return {
|
||||
...(await deployBootstrapFeaturesAsync(provider, txDefaults)),
|
||||
tokenSpender:
|
||||
features.tokenSpender ||
|
||||
(await TokenSpenderFeatureContract.deployFrom0xArtifactAsync(
|
||||
artifacts.TokenSpenderFeature,
|
||||
_featureArtifacts.tokenSpender,
|
||||
provider,
|
||||
txDefaults,
|
||||
artifacts,
|
||||
@@ -121,7 +185,7 @@ export async function deployFullFeaturesAsync(
|
||||
transformERC20:
|
||||
features.transformERC20 ||
|
||||
(await TransformERC20FeatureContract.deployFrom0xArtifactAsync(
|
||||
artifacts.TransformERC20Feature,
|
||||
_featureArtifacts.transformERC20,
|
||||
provider,
|
||||
txDefaults,
|
||||
artifacts,
|
||||
@@ -129,7 +193,7 @@ export async function deployFullFeaturesAsync(
|
||||
signatureValidator:
|
||||
features.signatureValidator ||
|
||||
(await SignatureValidatorFeatureContract.deployFrom0xArtifactAsync(
|
||||
artifacts.SignatureValidatorFeature,
|
||||
_featureArtifacts.signatureValidator,
|
||||
provider,
|
||||
txDefaults,
|
||||
artifacts,
|
||||
@@ -137,11 +201,23 @@ export async function deployFullFeaturesAsync(
|
||||
metaTransactions:
|
||||
features.metaTransactions ||
|
||||
(await MetaTransactionsFeatureContract.deployFrom0xArtifactAsync(
|
||||
artifacts.MetaTransactionsFeature,
|
||||
_featureArtifacts.metaTransactions,
|
||||
provider,
|
||||
txDefaults,
|
||||
artifacts,
|
||||
zeroExAddress,
|
||||
_config.zeroExAddress,
|
||||
)).address,
|
||||
nativeOrders:
|
||||
features.nativeOrders ||
|
||||
(await NativeOrdersFeatureContract.deployFrom0xArtifactAsync(
|
||||
_featureArtifacts.nativeOrders,
|
||||
provider,
|
||||
txDefaults,
|
||||
artifacts,
|
||||
_config.zeroExAddress,
|
||||
_config.wethAddress,
|
||||
_config.stakingAddress,
|
||||
_config.protocolFeeMultiplier,
|
||||
)).address,
|
||||
};
|
||||
}
|
||||
@@ -154,7 +230,8 @@ export async function fullMigrateAsync(
|
||||
provider: SupportedProvider,
|
||||
txDefaults: Partial<TxData>,
|
||||
features: Partial<FullFeatures> = {},
|
||||
opts: Partial<FullMigrationOpts> = {},
|
||||
config: Partial<FullMigrationConfig> = {},
|
||||
featureArtifacts: Partial<FullFeatureArtifacts> = {},
|
||||
): Promise<IZeroExContract> {
|
||||
const migrator = await FullMigrationContract.deployFrom0xArtifactAsync(
|
||||
artifacts.FullMigration,
|
||||
@@ -170,11 +247,12 @@ export async function fullMigrateAsync(
|
||||
artifacts,
|
||||
await migrator.getBootstrapper().callAsync(),
|
||||
);
|
||||
const _features = await deployFullFeaturesAsync(provider, txDefaults, zeroEx.address, features);
|
||||
const _opts = {
|
||||
const _config = { ...config, zeroExAddress: zeroEx.address };
|
||||
const _features = await deployFullFeaturesAsync(provider, txDefaults, _config, features, featureArtifacts);
|
||||
const migrateOpts = {
|
||||
transformerDeployer: txDefaults.from as string,
|
||||
...opts,
|
||||
..._config,
|
||||
};
|
||||
await migrator.initializeZeroEx(owner, zeroEx.address, _features, _opts).awaitTransactionSuccessAsync();
|
||||
await migrator.migrateZeroEx(owner, zeroEx.address, _features, migrateOpts).awaitTransactionSuccessAsync();
|
||||
return new IZeroExContract(zeroEx.address, provider, txDefaults);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user