Merge pull request #2212 from 0xProject/refactor/no-domain-in-order
Remove domain from Order and remove OrderWithoutDomain type
This commit is contained in:
@@ -111,10 +111,8 @@ describe('Coordinator tests', () => {
|
||||
takerAssetData: assetDataUtils.encodeERC20AssetData(erc20TokenB.address),
|
||||
makerFeeAssetData: assetDataUtils.encodeERC20AssetData(makerFeeToken.address),
|
||||
takerFeeAssetData: assetDataUtils.encodeERC20AssetData(makerFeeToken.address),
|
||||
domain: {
|
||||
verifyingContract: exchange.address,
|
||||
chainId,
|
||||
},
|
||||
exchangeAddress: exchange.address,
|
||||
chainId,
|
||||
};
|
||||
const makerPrivateKey = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(makerAddress)];
|
||||
const takerPrivateKey = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(takerAddress)];
|
||||
|
@@ -12,7 +12,7 @@ import {
|
||||
} from '@0x/contracts-test-utils';
|
||||
import { BlockchainLifecycle } from '@0x/dev-utils';
|
||||
import { transactionHashUtils } from '@0x/order-utils';
|
||||
import { EIP712DomainWithDefaultSchema, RevertReason, SignatureType, SignedOrder } from '@0x/types';
|
||||
import { RevertReason, SignatureType, SignedOrder } from '@0x/types';
|
||||
import { BigNumber, LibBytesRevertErrors, providerUtils } from '@0x/utils';
|
||||
import * as chai from 'chai';
|
||||
import * as ethUtil from 'ethereumjs-util';
|
||||
@@ -34,7 +34,6 @@ describe('Mixins tests', () => {
|
||||
let approvalFactory2: ApprovalFactory;
|
||||
let defaultOrder: SignedOrder;
|
||||
const exchangeAddress = randomAddress();
|
||||
let exchangeDomain: EIP712DomainWithDefaultSchema;
|
||||
|
||||
before(async () => {
|
||||
await blockchainLifecycle.startAsync();
|
||||
@@ -54,10 +53,6 @@ describe('Mixins tests', () => {
|
||||
);
|
||||
const accounts = await web3Wrapper.getAvailableAddressesAsync();
|
||||
[transactionSignerAddress, approvalSignerAddress1, approvalSignerAddress2] = accounts.slice(0, 3);
|
||||
exchangeDomain = {
|
||||
verifyingContract: constants.NULL_ADDRESS,
|
||||
chainId,
|
||||
};
|
||||
defaultOrder = {
|
||||
makerAddress: constants.NULL_ADDRESS,
|
||||
takerAddress: constants.NULL_ADDRESS,
|
||||
@@ -74,7 +69,8 @@ describe('Mixins tests', () => {
|
||||
expirationTimeSeconds: constants.ZERO_AMOUNT,
|
||||
salt: constants.ZERO_AMOUNT,
|
||||
signature: constants.NULL_BYTES,
|
||||
domain: exchangeDomain,
|
||||
exchangeAddress: constants.NULL_ADDRESS,
|
||||
chainId,
|
||||
};
|
||||
const transactionSignerPrivateKey = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(transactionSignerAddress)];
|
||||
const approvalSignerPrivateKey1 = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(approvalSignerAddress1)];
|
||||
@@ -152,7 +148,8 @@ describe('Mixins tests', () => {
|
||||
const decodedSignedOrders = decodedOrders.map(order => ({
|
||||
...order,
|
||||
signature: constants.NULL_BYTES,
|
||||
domain: exchangeDomain,
|
||||
exchangeAddress: constants.NULL_ADDRESS,
|
||||
chainId,
|
||||
}));
|
||||
expect(orders).to.deep.eq(decodedSignedOrders);
|
||||
});
|
||||
@@ -165,7 +162,8 @@ describe('Mixins tests', () => {
|
||||
const decodedSignedOrders = decodedOrders.map(order => ({
|
||||
...order,
|
||||
signature: constants.NULL_BYTES,
|
||||
domain: exchangeDomain,
|
||||
exchangeAddress: constants.NULL_ADDRESS,
|
||||
chainId,
|
||||
}));
|
||||
expect(orders).to.deep.eq(decodedSignedOrders);
|
||||
});
|
||||
@@ -178,7 +176,8 @@ describe('Mixins tests', () => {
|
||||
const decodedSignedOrders = decodedOrders.map(order => ({
|
||||
...order,
|
||||
signature: constants.NULL_BYTES,
|
||||
domain: exchangeDomain,
|
||||
exchangeAddress: constants.NULL_ADDRESS,
|
||||
chainId,
|
||||
}));
|
||||
expect(orders).to.deep.eq(decodedSignedOrders);
|
||||
});
|
||||
|
@@ -120,10 +120,8 @@ describe('OrderValidationUtils/OrderTransferSimulatorUtils', () => {
|
||||
takerAssetData: erc20AssetData2,
|
||||
makerFeeAssetData: feeAssetData,
|
||||
takerFeeAssetData: feeAssetData,
|
||||
domain: {
|
||||
verifyingContract: exchange.address,
|
||||
chainId,
|
||||
},
|
||||
exchangeAddress: exchange.address,
|
||||
chainId,
|
||||
};
|
||||
const privateKey = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(makerAddress)];
|
||||
orderFactory = new OrderFactory(privateKey, defaultOrderParams);
|
||||
|
@@ -120,10 +120,8 @@ blockchainTests(ContractName.Forwarder, env => {
|
||||
takerFeeAssetData: assetDataUtils.encodeERC20AssetData(defaultMakerAssetAddress),
|
||||
makerFee: Web3Wrapper.toBaseUnitAmount(0, DECIMALS_DEFAULT),
|
||||
takerFee: Web3Wrapper.toBaseUnitAmount(0, DECIMALS_DEFAULT),
|
||||
domain: {
|
||||
verifyingContract: exchangeInstance.address,
|
||||
chainId,
|
||||
},
|
||||
exchangeAddress: exchangeInstance.address,
|
||||
chainId,
|
||||
};
|
||||
const privateKey = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(makerAddress)];
|
||||
orderFactory = new OrderFactory(privateKey, defaultOrderParams);
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import { ReferenceFunctions } from '@0x/contracts-utils';
|
||||
import { LibMathRevertErrors } from '@0x/order-utils';
|
||||
import { FillResults, OrderWithoutDomain } from '@0x/types';
|
||||
import { FillResults, Order } from '@0x/types';
|
||||
import { BigNumber } from '@0x/utils';
|
||||
|
||||
const { safeAdd, safeSub, safeMul, safeDiv } = ReferenceFunctions;
|
||||
@@ -94,7 +94,7 @@ export function addFillResults(a: FillResults, b: FillResults): FillResults {
|
||||
* Calculates amounts filled and fees paid by maker and taker.
|
||||
*/
|
||||
export function calculateFillResults(
|
||||
order: OrderWithoutDomain,
|
||||
order: Order,
|
||||
takerAssetFilledAmount: BigNumber,
|
||||
protocolFeeMultiplier: BigNumber,
|
||||
gasPrice: BigNumber,
|
||||
|
@@ -8,7 +8,7 @@ import {
|
||||
uint256Values,
|
||||
} from '@0x/contracts-test-utils';
|
||||
import { LibMathRevertErrors } from '@0x/order-utils';
|
||||
import { FillResults, MatchedFillResults, OrderWithoutDomain as Order } from '@0x/types';
|
||||
import { FillResults, MatchedFillResults, Order } from '@0x/types';
|
||||
import { BigNumber, SafeMathRevertErrors } from '@0x/utils';
|
||||
import { Web3Wrapper } from '@0x/web3-wrapper';
|
||||
import * as _ from 'lodash';
|
||||
@@ -39,6 +39,8 @@ blockchainTests('LibFillResults', env => {
|
||||
salt: constants.ZERO_AMOUNT,
|
||||
feeRecipientAddress: constants.NULL_ADDRESS,
|
||||
expirationTimeSeconds: constants.ZERO_AMOUNT,
|
||||
chainId: 1,
|
||||
exchangeAddress: constants.NULL_ADDRESS,
|
||||
};
|
||||
|
||||
const randomAddress = () => hexRandom(constants.ADDRESS_LENGTH);
|
||||
@@ -536,10 +538,8 @@ blockchainTests('LibFillResults', env => {
|
||||
feeRecipientAddress: randomAddress(),
|
||||
expirationTimeSeconds: randomUint256(),
|
||||
salt: randomUint256(),
|
||||
domain: {
|
||||
verifyingContract: constants.NULL_ADDRESS,
|
||||
chainId: 1337, // The chain id for the isolated exchange
|
||||
},
|
||||
exchangeAddress: constants.NULL_ADDRESS,
|
||||
chainId: 1337, // The chain id for the isolated exchange
|
||||
};
|
||||
|
||||
function makeOrder(details?: Partial<Order>): Order {
|
||||
@@ -547,7 +547,7 @@ blockchainTests('LibFillResults', env => {
|
||||
}
|
||||
|
||||
before(async () => {
|
||||
ORDER_DEFAULTS.domain.verifyingContract = libsContract.address;
|
||||
ORDER_DEFAULTS.exchangeAddress = libsContract.address;
|
||||
});
|
||||
|
||||
it('should correctly calculate the results when only the right order is fully filled', async () => {
|
||||
@@ -1209,10 +1209,8 @@ blockchainTests('LibFillResults', env => {
|
||||
feeRecipientAddress: randomAddress(),
|
||||
expirationTimeSeconds: randomUint256(),
|
||||
salt: randomUint256(),
|
||||
domain: {
|
||||
verifyingContract: constants.NULL_ADDRESS,
|
||||
chainId: 1337, // The chain id for the isolated exchange
|
||||
},
|
||||
exchangeAddress: constants.NULL_ADDRESS,
|
||||
chainId: 1337, // The chain id for the isolated exchange
|
||||
};
|
||||
|
||||
function makeOrder(details?: Partial<Order>): Order {
|
||||
@@ -1220,7 +1218,7 @@ blockchainTests('LibFillResults', env => {
|
||||
}
|
||||
|
||||
before(async () => {
|
||||
ORDER_DEFAULTS.domain.verifyingContract = libsContract.address;
|
||||
ORDER_DEFAULTS.exchangeAddress = libsContract.address;
|
||||
});
|
||||
|
||||
it('should transfer correct amounts when right order is fully filled', async () => {
|
||||
|
@@ -16,10 +16,8 @@ blockchainTests('LibOrder', env => {
|
||||
const randomAssetData = () => hexRandom(36);
|
||||
|
||||
const EMPTY_ORDER: Order = {
|
||||
domain: {
|
||||
verifyingContract: constants.NULL_ADDRESS,
|
||||
chainId: 0,
|
||||
},
|
||||
exchangeAddress: constants.NULL_ADDRESS,
|
||||
chainId: 0,
|
||||
senderAddress: constants.NULL_ADDRESS,
|
||||
makerAddress: constants.NULL_ADDRESS,
|
||||
takerAddress: constants.NULL_ADDRESS,
|
||||
@@ -52,7 +50,8 @@ blockchainTests('LibOrder', env => {
|
||||
const expectedHash = orderHashUtils.getOrderHashHex(order);
|
||||
const domainHash = ethUtil.bufferToHex(
|
||||
signTypedDataUtils.generateDomainHash({
|
||||
...order.domain,
|
||||
chainId: order.chainId,
|
||||
verifyingContract: order.exchangeAddress,
|
||||
name: constants.EIP712_DOMAIN_NAME,
|
||||
version: constants.EIP712_DOMAIN_VERSION,
|
||||
}),
|
||||
@@ -65,19 +64,14 @@ blockchainTests('LibOrder', env => {
|
||||
it('should correctly hash an empty order', async () => {
|
||||
await testGetTypedDataHashAsync({
|
||||
...EMPTY_ORDER,
|
||||
domain: {
|
||||
...EMPTY_ORDER.domain,
|
||||
verifyingContract: libOrderContract.address,
|
||||
},
|
||||
exchangeAddress: libOrderContract.address,
|
||||
});
|
||||
});
|
||||
|
||||
it('should correctly hash a non-empty order', async () => {
|
||||
await testGetTypedDataHashAsync({
|
||||
domain: {
|
||||
verifyingContract: libOrderContract.address,
|
||||
chainId: 1337,
|
||||
},
|
||||
exchangeAddress: libOrderContract.address,
|
||||
chainId: 1337,
|
||||
senderAddress: randomAddress(),
|
||||
makerAddress: randomAddress(),
|
||||
takerAddress: randomAddress(),
|
||||
@@ -98,14 +92,15 @@ blockchainTests('LibOrder', env => {
|
||||
it('orderHash should differ if the domain hash is different', async () => {
|
||||
const domainHash1 = ethUtil.bufferToHex(
|
||||
signTypedDataUtils.generateDomainHash({
|
||||
...EMPTY_ORDER.domain,
|
||||
chainId: EMPTY_ORDER.chainId,
|
||||
verifyingContract: EMPTY_ORDER.exchangeAddress,
|
||||
name: constants.EIP712_DOMAIN_NAME,
|
||||
version: constants.EIP712_DOMAIN_VERSION,
|
||||
}),
|
||||
);
|
||||
const domainHash2 = ethUtil.bufferToHex(
|
||||
signTypedDataUtils.generateDomainHash({
|
||||
...EMPTY_ORDER.domain,
|
||||
verifyingContract: EMPTY_ORDER.exchangeAddress,
|
||||
name: constants.EIP712_DOMAIN_NAME,
|
||||
version: constants.EIP712_DOMAIN_VERSION,
|
||||
chainId: 1337,
|
||||
@@ -135,10 +130,8 @@ blockchainTests('LibOrder', env => {
|
||||
it('should correctly hash a non-empty order', async () => {
|
||||
await testGetStructHashAsync({
|
||||
// The domain is not used in this test, so it's okay if it is left empty.
|
||||
domain: {
|
||||
verifyingContract: constants.NULL_ADDRESS,
|
||||
chainId: 0,
|
||||
},
|
||||
exchangeAddress: constants.NULL_ADDRESS,
|
||||
chainId: 0,
|
||||
senderAddress: randomAddress(),
|
||||
makerAddress: randomAddress(),
|
||||
takerAddress: randomAddress(),
|
||||
|
@@ -217,10 +217,8 @@ blockchainTests.resets('Exchange core', () => {
|
||||
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultTakerAssetAddress),
|
||||
makerFeeAssetData: assetDataUtils.encodeERC20AssetData(defaultFeeAssetAddress),
|
||||
takerFeeAssetData: assetDataUtils.encodeERC20AssetData(defaultFeeAssetAddress),
|
||||
domain: {
|
||||
verifyingContract: exchange.address,
|
||||
chainId,
|
||||
},
|
||||
exchangeAddress: exchange.address,
|
||||
chainId,
|
||||
};
|
||||
const privateKey = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(makerAddress)];
|
||||
orderFactory = new OrderFactory(privateKey, defaultOrderParams);
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import { ReferenceFunctions as LibReferenceFunctions } from '@0x/contracts-exchange-libs';
|
||||
import { blockchainTests, constants, expect, hexRandom, LogDecoder } from '@0x/contracts-test-utils';
|
||||
import { ExchangeRevertErrors, orderHashUtils } from '@0x/order-utils';
|
||||
import { Order, OrderWithoutDomain } from '@0x/types';
|
||||
import { Order } from '@0x/types';
|
||||
import { BigNumber, SafeMathRevertErrors } from '@0x/utils';
|
||||
import { Web3Wrapper } from '@0x/web3-wrapper';
|
||||
import { LogWithDecodedArgs } from 'ethereum-types';
|
||||
@@ -56,10 +56,8 @@ blockchainTests('Exchange core internal functions', env => {
|
||||
salt: new BigNumber(_.random(0, 1e8)),
|
||||
feeRecipientAddress: randomAddress(),
|
||||
expirationTimeSeconds: new BigNumber(_.random(0, 1e8)),
|
||||
domain: {
|
||||
verifyingContract: constants.NULL_ADDRESS,
|
||||
chainId: 1337, // The chain id for the isolated exchange
|
||||
},
|
||||
exchangeAddress: constants.NULL_ADDRESS,
|
||||
chainId: 1337, // The chain id for the isolated exchange
|
||||
};
|
||||
|
||||
function makeOrder(details?: Partial<Order>): Order {
|
||||
@@ -67,7 +65,7 @@ blockchainTests('Exchange core internal functions', env => {
|
||||
}
|
||||
|
||||
before(async () => {
|
||||
ORDER_DEFAULTS.domain.verifyingContract = testExchange.address;
|
||||
ORDER_DEFAULTS.exchangeAddress = testExchange.address;
|
||||
});
|
||||
|
||||
it('should revert if the maker asset multiplication should overflow', async () => {
|
||||
@@ -160,14 +158,16 @@ blockchainTests('Exchange core internal functions', env => {
|
||||
salt: new BigNumber(_.random(0, 1e8)),
|
||||
feeRecipientAddress: randomAddress(),
|
||||
expirationTimeSeconds: new BigNumber(_.random(0, 1e8)),
|
||||
chainId: 1337,
|
||||
exchangeAddress: constants.NULL_ADDRESS,
|
||||
};
|
||||
|
||||
function makeOrder(details?: Partial<OrderWithoutDomain>): OrderWithoutDomain {
|
||||
function makeOrder(details?: Partial<Order>): Order {
|
||||
return _.assign({}, ORDER_DEFAULTS, details);
|
||||
}
|
||||
|
||||
async function testUpdateFilledStateAsync(
|
||||
order: OrderWithoutDomain,
|
||||
order: Order,
|
||||
orderTakerAssetFilledAmount: BigNumber,
|
||||
takerAddress: string,
|
||||
takerAssetFillAmount: BigNumber,
|
||||
|
@@ -36,6 +36,8 @@ blockchainTests('Isolated fillOrder() tests', env => {
|
||||
takerAssetData: createGoodAssetData(),
|
||||
makerFeeAssetData: createGoodAssetData(),
|
||||
takerFeeAssetData: createGoodAssetData(),
|
||||
exchangeAddress: constants.NULL_ADDRESS,
|
||||
chainId: 1,
|
||||
};
|
||||
const DEFAULT_GAS_PRICE = new BigNumber(20000);
|
||||
const DEFAULT_PROTOCOL_FEE_MULTIPLIER = new BigNumber(15000);
|
||||
|
@@ -198,10 +198,7 @@ describe('matchOrders', () => {
|
||||
defaultFeeTokenAddress = erc20Tokens[2].address;
|
||||
defaultERC721AssetAddress = erc721Token.address;
|
||||
defaultERC1155AssetAddress = erc1155Token.address;
|
||||
const domain = {
|
||||
verifyingContract: exchange.address,
|
||||
chainId,
|
||||
};
|
||||
|
||||
// Create default order parameters
|
||||
const defaultOrderParamsLeft = {
|
||||
...constants.STATIC_ORDER_PARAMS,
|
||||
@@ -211,7 +208,8 @@ describe('matchOrders', () => {
|
||||
makerFeeAssetData: assetDataUtils.encodeERC20AssetData(defaultFeeTokenAddress),
|
||||
takerFeeAssetData: assetDataUtils.encodeERC20AssetData(defaultFeeTokenAddress),
|
||||
feeRecipientAddress: feeRecipientAddressLeft,
|
||||
domain,
|
||||
exchangeAddress: exchange.address,
|
||||
chainId,
|
||||
};
|
||||
const defaultOrderParamsRight = {
|
||||
...constants.STATIC_ORDER_PARAMS,
|
||||
@@ -221,7 +219,8 @@ describe('matchOrders', () => {
|
||||
makerFeeAssetData: assetDataUtils.encodeERC20AssetData(defaultFeeTokenAddress),
|
||||
takerFeeAssetData: assetDataUtils.encodeERC20AssetData(defaultFeeTokenAddress),
|
||||
feeRecipientAddress: feeRecipientAddressRight,
|
||||
domain,
|
||||
exchangeAddress: exchange.address,
|
||||
chainId,
|
||||
};
|
||||
const privateKeyLeft = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(makerAddressLeft)];
|
||||
orderFactoryLeft = new OrderFactory(privateKeyLeft, defaultOrderParamsLeft);
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import { ReferenceFunctions as LibReferenceFunctions } from '@0x/contracts-exchange-libs';
|
||||
import { constants, describe, expect } from '@0x/contracts-test-utils';
|
||||
import { LibMathRevertErrors } from '@0x/order-utils';
|
||||
import { OrderWithoutDomain as Order } from '@0x/types';
|
||||
import { Order } from '@0x/types';
|
||||
import { BigNumber, SafeMathRevertErrors } from '@0x/utils';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
@@ -24,6 +24,8 @@ describe('Reference functions', () => {
|
||||
salt: constants.ZERO_AMOUNT,
|
||||
feeRecipientAddress: constants.NULL_ADDRESS,
|
||||
expirationTimeSeconds: constants.ZERO_AMOUNT,
|
||||
chainId: 1,
|
||||
exchangeAddress: constants.NULL_ADDRESS,
|
||||
};
|
||||
|
||||
describe('calculateFillResults', () => {
|
||||
|
@@ -435,10 +435,8 @@ blockchainTests.resets('MixinSignatureValidator', env => {
|
||||
takerFeeAssetData: assetDataUtils.encodeERC20AssetData(randomAddress()),
|
||||
makerFee: constants.ZERO_AMOUNT,
|
||||
takerFee: constants.ZERO_AMOUNT,
|
||||
domain: {
|
||||
verifyingContract: signatureValidator.address,
|
||||
chainId,
|
||||
},
|
||||
exchangeAddress: signatureValidator.address,
|
||||
chainId,
|
||||
};
|
||||
orderFactory = new OrderFactory(signerPrivateKey, defaultOrderParams);
|
||||
});
|
||||
|
@@ -11,7 +11,7 @@ import {
|
||||
TransactionFactory,
|
||||
} from '@0x/contracts-test-utils';
|
||||
import { assetDataUtils, ExchangeRevertErrors, orderHashUtils, transactionHashUtils } from '@0x/order-utils';
|
||||
import { EIP712DomainWithDefaultSchema, FillResults, OrderStatus } from '@0x/types';
|
||||
import { FillResults, OrderStatus } from '@0x/types';
|
||||
import { AbiEncoder, BigNumber } from '@0x/utils';
|
||||
import { LogWithDecodedArgs, MethodAbi } from 'ethereum-types';
|
||||
import * as ethUtil from 'ethereumjs-util';
|
||||
@@ -51,7 +51,6 @@ blockchainTests.resets('Exchange transactions', env => {
|
||||
let exchangeInstance: ExchangeContract;
|
||||
let erc20Proxy: ERC20ProxyContract;
|
||||
|
||||
let domain: EIP712DomainWithDefaultSchema;
|
||||
let orderFactory: OrderFactory;
|
||||
let makerTransactionFactory: TransactionFactory;
|
||||
let takerTransactionFactory: TransactionFactory;
|
||||
@@ -107,11 +106,6 @@ blockchainTests.resets('Exchange transactions', env => {
|
||||
defaultMakerFeeTokenAddress = makerFeeToken.address;
|
||||
defaultTakerFeeTokenAddress = takerFeeToken.address;
|
||||
|
||||
domain = {
|
||||
verifyingContract: exchangeInstance.address,
|
||||
chainId,
|
||||
};
|
||||
|
||||
const defaultOrderParams = {
|
||||
...constants.STATIC_ORDER_PARAMS,
|
||||
makerAddress,
|
||||
@@ -120,7 +114,8 @@ blockchainTests.resets('Exchange transactions', env => {
|
||||
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultTakerTokenAddress),
|
||||
makerFeeAssetData: assetDataUtils.encodeERC20AssetData(defaultMakerFeeTokenAddress),
|
||||
takerFeeAssetData: assetDataUtils.encodeERC20AssetData(defaultTakerFeeTokenAddress),
|
||||
domain,
|
||||
exchangeAddress: exchangeInstance.address,
|
||||
chainId,
|
||||
};
|
||||
makerPrivateKey = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(makerAddress)];
|
||||
takerPrivateKey = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(takerAddress)];
|
||||
|
@@ -6,7 +6,7 @@ import {
|
||||
txDefaults as testTxDefaults,
|
||||
} from '@0x/contracts-test-utils';
|
||||
import { orderHashUtils } from '@0x/order-utils';
|
||||
import { FillResults, OrderInfo, OrderWithoutDomain, SignatureType } from '@0x/types';
|
||||
import { FillResults, Order, OrderInfo, SignatureType } from '@0x/types';
|
||||
import { BigNumber } from '@0x/utils';
|
||||
import { TxData, Web3Wrapper } from '@0x/web3-wrapper';
|
||||
import * as crypto from 'crypto';
|
||||
@@ -28,7 +28,7 @@ export interface IsolatedExchangeEvents {
|
||||
transferFromCalls: DispatchTransferFromCallArgs[];
|
||||
}
|
||||
|
||||
export type Order = OrderWithoutDomain;
|
||||
export type Order = Order;
|
||||
export type Numberish = string | number | BigNumber;
|
||||
|
||||
export const DEFAULT_GOOD_SIGNATURE = createGoodSignature();
|
||||
@@ -101,11 +101,11 @@ export class IsolatedExchangeWrapper {
|
||||
}
|
||||
|
||||
public getOrderHash(order: Order): string {
|
||||
const domain = {
|
||||
verifyingContract: this.instance.address,
|
||||
const domainInfo = {
|
||||
exchangeAddress: this.instance.address,
|
||||
chainId: IsolatedExchangeWrapper.CHAIN_ID,
|
||||
};
|
||||
return orderHashUtils.getOrderHashHex({ ...order, domain });
|
||||
return orderHashUtils.getOrderHashHex({ ...order, ...domainInfo });
|
||||
}
|
||||
|
||||
public async getOrderInfoAsync(order: Order): Promise<OrderInfo> {
|
||||
|
@@ -430,10 +430,8 @@ export class OrderFactoryFromScenario {
|
||||
salt: generatePseudoRandomSalt(),
|
||||
feeRecipientAddress,
|
||||
expirationTimeSeconds,
|
||||
domain: {
|
||||
verifyingContract: this._exchangeAddress,
|
||||
chainId: this._chainId,
|
||||
},
|
||||
exchangeAddress: this._exchangeAddress,
|
||||
chainId: this._chainId,
|
||||
};
|
||||
|
||||
return order;
|
||||
|
@@ -97,10 +97,8 @@ blockchainTests.resets('Exchange wrappers', env => {
|
||||
takerAssetData: assetDataUtils.encodeERC20AssetData(defaultTakerAssetAddress),
|
||||
makerFeeAssetData: assetDataUtils.encodeERC20AssetData(defaultFeeAssetAddress),
|
||||
takerFeeAssetData: assetDataUtils.encodeERC20AssetData(defaultFeeAssetAddress),
|
||||
domain: {
|
||||
verifyingContract: exchange.address,
|
||||
chainId,
|
||||
},
|
||||
exchangeAddress: exchange.address,
|
||||
chainId,
|
||||
};
|
||||
const privateKey = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(makerAddress)];
|
||||
orderFactory = new OrderFactory(privateKey, defaultOrderParams);
|
||||
|
@@ -10,7 +10,7 @@ import {
|
||||
} from '@0x/contracts-test-utils';
|
||||
import { ReferenceFunctions as UtilReferenceFunctions } from '@0x/contracts-utils';
|
||||
import { ExchangeRevertErrors, orderHashUtils } from '@0x/order-utils';
|
||||
import { FillResults, OrderWithoutDomain as Order } from '@0x/types';
|
||||
import { FillResults, Order } from '@0x/types';
|
||||
import { AnyRevertError, BigNumber, SafeMathRevertErrors, StringRevertError } from '@0x/utils';
|
||||
import { LogEntry, LogWithDecodedArgs } from 'ethereum-types';
|
||||
import * as ethjs from 'ethereumjs-util';
|
||||
@@ -83,20 +83,12 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
takerAssetData: randomAssetData(),
|
||||
makerFeeAssetData: randomAssetData(),
|
||||
takerFeeAssetData: randomAssetData(),
|
||||
exchangeAddress: constants.NULL_ADDRESS,
|
||||
chainId: CHAIN_ID,
|
||||
...(fields || {}),
|
||||
};
|
||||
}
|
||||
|
||||
function getExpectedOrderHash(order: Order): string {
|
||||
return orderHashUtils.getOrderHashHex({
|
||||
...order,
|
||||
domain: {
|
||||
verifyingContract: testContract.address,
|
||||
chainId: CHAIN_ID,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// Computes the expected (fake) fill results from `TestWrapperFunctions` `_fillOrder` implementation.
|
||||
function getExpectedFillResults(order: Order, signature: string): FillResults {
|
||||
if (order.salt === ALWAYS_FAILING_SALT) {
|
||||
@@ -114,7 +106,7 @@ blockchainTests('Exchange wrapper functions unit tests.', env => {
|
||||
// Creates a deterministic order signature, even though no signature validation
|
||||
// actually occurs in the test contract.
|
||||
function createOrderSignature(order: Order): string {
|
||||
return ethjs.bufferToHex(ethjs.sha3(ethjs.toBuffer(getExpectedOrderHash(order))));
|
||||
return ethjs.bufferToHex(ethjs.sha3(ethjs.toBuffer(orderHashUtils.getOrderHashHex(order))));
|
||||
}
|
||||
|
||||
// Asserts that `_fillOrder()` was called in the same order and with the same
|
||||
|
@@ -177,10 +177,8 @@ describe(ContractName.BalanceThresholdFilter, () => {
|
||||
makerFee: Web3Wrapper.toBaseUnitAmount(new BigNumber(100), DECIMALS_DEFAULT),
|
||||
takerFee: Web3Wrapper.toBaseUnitAmount(new BigNumber(150), DECIMALS_DEFAULT),
|
||||
senderAddress: erc721BalanceThresholdFilterInstance.address,
|
||||
domain: {
|
||||
verifyingContract: exchangeInstance.address,
|
||||
chainId,
|
||||
},
|
||||
exchangeAddress: exchangeInstance.address,
|
||||
chainId,
|
||||
};
|
||||
// Create two order factories with valid makers (who meet the threshold balance), and
|
||||
// one factory for an invalid address (that does not meet the threshold balance)
|
||||
|
@@ -163,10 +163,8 @@ describe(ContractName.DutchAuction, () => {
|
||||
expirationTimeSeconds: auctionEndTimeSeconds,
|
||||
makerFee: constants.ZERO_AMOUNT,
|
||||
takerFee: constants.ZERO_AMOUNT,
|
||||
domain: {
|
||||
verifyingContract: exchangeInstance.address,
|
||||
chainId,
|
||||
},
|
||||
exchangeAddress: exchangeInstance.address,
|
||||
chainId,
|
||||
};
|
||||
// Default buy order is for the auction begin price
|
||||
const buyerDefaultOrderParams = {
|
||||
|
@@ -166,11 +166,6 @@ describe('OrderMatcher', () => {
|
||||
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||
);
|
||||
|
||||
const domain = {
|
||||
verifyingContract: exchange.address,
|
||||
chainId,
|
||||
};
|
||||
|
||||
// Create default order parameters
|
||||
const defaultOrderParamsLeft = {
|
||||
...constants.STATIC_ORDER_PARAMS,
|
||||
@@ -180,7 +175,8 @@ describe('OrderMatcher', () => {
|
||||
feeRecipientAddress: feeRecipientAddressLeft,
|
||||
makerFee: constants.ZERO_AMOUNT,
|
||||
takerFee: constants.ZERO_AMOUNT,
|
||||
domain,
|
||||
exchangeAddress: exchange.address,
|
||||
chainId,
|
||||
};
|
||||
const defaultOrderParamsRight = {
|
||||
...constants.STATIC_ORDER_PARAMS,
|
||||
@@ -190,7 +186,8 @@ describe('OrderMatcher', () => {
|
||||
feeRecipientAddress: feeRecipientAddressRight,
|
||||
makerFee: constants.ZERO_AMOUNT,
|
||||
takerFee: constants.ZERO_AMOUNT,
|
||||
domain,
|
||||
exchangeAddress: exchange.address,
|
||||
chainId,
|
||||
};
|
||||
const privateKeyLeft = constants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(makerAddressLeft)];
|
||||
orderFactoryLeft = new OrderFactory(privateKeyLeft, defaultOrderParamsLeft);
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import { generatePseudoRandomSalt } from '@0x/order-utils';
|
||||
import { crypto } from '@0x/order-utils/lib/src/crypto';
|
||||
import { OrderWithoutDomain, SignedOrder } from '@0x/types';
|
||||
import { Order, SignedOrder } from '@0x/types';
|
||||
import { BigNumber } from '@0x/utils';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
@@ -17,7 +17,7 @@ export const orderUtils = {
|
||||
},
|
||||
createFill: (signedOrder: SignedOrder, takerAssetFillAmount?: BigNumber) => {
|
||||
const fill = {
|
||||
order: orderUtils.getOrderWithoutDomain(signedOrder),
|
||||
order: signedOrder,
|
||||
takerAssetFillAmount: takerAssetFillAmount || signedOrder.takerAssetAmount,
|
||||
signature: signedOrder.signature,
|
||||
};
|
||||
@@ -25,19 +25,19 @@ export const orderUtils = {
|
||||
},
|
||||
createCancel(signedOrder: SignedOrder, takerAssetCancelAmount?: BigNumber): CancelOrder {
|
||||
const cancel = {
|
||||
order: orderUtils.getOrderWithoutDomain(signedOrder),
|
||||
order: signedOrder,
|
||||
takerAssetCancelAmount: takerAssetCancelAmount || signedOrder.takerAssetAmount,
|
||||
};
|
||||
return cancel;
|
||||
},
|
||||
getOrderWithoutDomain(signedOrder: SignedOrder): OrderWithoutDomain {
|
||||
return _.omit(signedOrder, ['signature', 'domain']) as OrderWithoutDomain;
|
||||
createOrderWithoutSignature(signedOrder: SignedOrder): Order {
|
||||
return _.omit(signedOrder, ['signature']) as Order;
|
||||
},
|
||||
createBatchMatchOrders(signedOrdersLeft: SignedOrder[], signedOrdersRight: SignedOrder[]): BatchMatchOrder {
|
||||
return {
|
||||
leftOrders: signedOrdersLeft.map(order => orderUtils.getOrderWithoutDomain(order)),
|
||||
leftOrders: signedOrdersLeft.map(order => orderUtils.createOrderWithoutSignature(order)),
|
||||
rightOrders: signedOrdersRight.map(order => {
|
||||
const right = orderUtils.getOrderWithoutDomain(order);
|
||||
const right = orderUtils.createOrderWithoutSignature(order);
|
||||
right.makerAssetData = constants.NULL_BYTES;
|
||||
right.takerAssetData = constants.NULL_BYTES;
|
||||
return right;
|
||||
@@ -48,8 +48,8 @@ export const orderUtils = {
|
||||
},
|
||||
createMatchOrders(signedOrderLeft: SignedOrder, signedOrderRight: SignedOrder): MatchOrder {
|
||||
const fill = {
|
||||
left: orderUtils.getOrderWithoutDomain(signedOrderLeft),
|
||||
right: orderUtils.getOrderWithoutDomain(signedOrderRight),
|
||||
left: orderUtils.createOrderWithoutSignature(signedOrderLeft),
|
||||
right: orderUtils.createOrderWithoutSignature(signedOrderRight),
|
||||
leftSignature: signedOrderLeft.signature,
|
||||
rightSignature: signedOrderRight.signature,
|
||||
};
|
||||
|
@@ -1,4 +1,4 @@
|
||||
import { OrderWithoutDomain } from '@0x/types';
|
||||
import { Order } from '@0x/types';
|
||||
import { BigNumber } from '@0x/utils';
|
||||
import { AbiDefinition } from 'ethereum-types';
|
||||
|
||||
@@ -42,25 +42,25 @@ export interface SubmissionContractEventArgs {
|
||||
}
|
||||
|
||||
export interface BatchFillOrders {
|
||||
orders: OrderWithoutDomain[];
|
||||
orders: Order[];
|
||||
signatures: string[];
|
||||
takerAssetFillAmounts: BigNumber[];
|
||||
}
|
||||
|
||||
export interface MarketSellOrders {
|
||||
orders: OrderWithoutDomain[];
|
||||
orders: Order[];
|
||||
signatures: string[];
|
||||
takerAssetFillAmount: BigNumber;
|
||||
}
|
||||
|
||||
export interface MarketBuyOrders {
|
||||
orders: OrderWithoutDomain[];
|
||||
orders: Order[];
|
||||
signatures: string[];
|
||||
makerAssetFillAmount: BigNumber;
|
||||
}
|
||||
|
||||
export interface BatchCancelOrders {
|
||||
orders: OrderWithoutDomain[];
|
||||
orders: Order[];
|
||||
}
|
||||
|
||||
export interface CancelOrdersBefore {
|
||||
@@ -120,20 +120,20 @@ export enum ContractName {
|
||||
}
|
||||
|
||||
export interface CancelOrder {
|
||||
order: OrderWithoutDomain;
|
||||
order: Order;
|
||||
takerAssetCancelAmount: BigNumber;
|
||||
}
|
||||
|
||||
export interface BatchMatchOrder {
|
||||
leftOrders: OrderWithoutDomain[];
|
||||
rightOrders: OrderWithoutDomain[];
|
||||
leftOrders: Order[];
|
||||
rightOrders: Order[];
|
||||
leftSignatures: string[];
|
||||
rightSignatures: string[];
|
||||
}
|
||||
|
||||
export interface MatchOrder {
|
||||
left: OrderWithoutDomain;
|
||||
right: OrderWithoutDomain;
|
||||
left: Order;
|
||||
right: Order;
|
||||
leftSignature: string;
|
||||
rightSignature: string;
|
||||
}
|
||||
|
Reference in New Issue
Block a user