From 9651941cce6246706c4ff5eff25470359629bce1 Mon Sep 17 00:00:00 2001 From: James Towle Date: Mon, 1 Jul 2019 17:28:12 -0500 Subject: [PATCH] Added getMatchOrdersResultsAsync and getBatchMatchOrdersResultsAsync --- contracts/dev-utils/compiler.json | 2 +- contracts/dev-utils/package.json | 2 +- contracts/dev-utils/src/artifacts.ts | 2 ++ contracts/dev-utils/src/wrappers.ts | 1 + contracts/dev-utils/tsconfig.json | 2 +- .../contracts/src/MixinMatchOrders.sol | 2 +- .../exchange/test/utils/exchange_wrapper.ts | 32 ++++++++++++++++++- contracts/test-utils/src/index.ts | 2 ++ contracts/test-utils/src/types.ts | 13 ++++++++ 9 files changed, 53 insertions(+), 5 deletions(-) diff --git a/contracts/dev-utils/compiler.json b/contracts/dev-utils/compiler.json index f3a3413f4a..2f174501e5 100644 --- a/contracts/dev-utils/compiler.json +++ b/contracts/dev-utils/compiler.json @@ -25,9 +25,9 @@ }, "contracts": [ "src/DevUtils.sol", + "src/EthBalanceChecker.sol", "src/LibAssetData.sol", "src/LibTransactionDecoder.sol", - "src/EthBalanceChecker.sol", "src/OrderTransferSimulationUtils.sol" ] } diff --git a/contracts/dev-utils/package.json b/contracts/dev-utils/package.json index e5a3699e20..eb89ade0b8 100644 --- a/contracts/dev-utils/package.json +++ b/contracts/dev-utils/package.json @@ -34,7 +34,7 @@ "lint-contracts": "solhint -c ../.solhint.json contracts/**/**/**/**/*.sol" }, "config": { - "abis": "./generated-artifacts/@(DevUtils|LibAssetData|LibTransactionDecoder|EthBalanceChecker|OrderTransferSimulationUtils).json", + "abis": "./generated-artifacts/@(DevUtils|EthBalanceChecker|LibAssetData|LibTransactionDecoder|OrderTransferSimulationUtils).json", "abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually." }, "repository": { diff --git a/contracts/dev-utils/src/artifacts.ts b/contracts/dev-utils/src/artifacts.ts index 8356ce7563..6a8002013c 100644 --- a/contracts/dev-utils/src/artifacts.ts +++ b/contracts/dev-utils/src/artifacts.ts @@ -6,6 +6,7 @@ import { ContractArtifact } from 'ethereum-types'; import * as DevUtils from '../generated-artifacts/DevUtils.json'; +import * as EthBalanceChecker from '../generated-artifacts/EthBalanceChecker.json'; import * as LibAssetData from '../generated-artifacts/LibAssetData.json'; import * as LibTransactionDecoder from '../generated-artifacts/LibTransactionDecoder.json'; import * as OrderTransferSimulationUtils from '../generated-artifacts/OrderTransferSimulationUtils.json'; @@ -13,5 +14,6 @@ export const artifacts = { DevUtils: DevUtils as ContractArtifact, LibAssetData: LibAssetData as ContractArtifact, LibTransactionDecoder: LibTransactionDecoder as ContractArtifact, + EthBalanceChecker: EthBalanceChecker as ContractArtifact, OrderTransferSimulationUtils: OrderTransferSimulationUtils as ContractArtifact, }; diff --git a/contracts/dev-utils/src/wrappers.ts b/contracts/dev-utils/src/wrappers.ts index 13c6397a9d..53bf08c126 100644 --- a/contracts/dev-utils/src/wrappers.ts +++ b/contracts/dev-utils/src/wrappers.ts @@ -4,6 +4,7 @@ * ----------------------------------------------------------------------------- */ export * from '../generated-wrappers/dev_utils'; +export * from '../generated-wrappers/eth_balance_checker'; export * from '../generated-wrappers/lib_asset_data'; export * from '../generated-wrappers/lib_transaction_decoder'; export * from '../generated-wrappers/order_transfer_simulation_utils'; diff --git a/contracts/dev-utils/tsconfig.json b/contracts/dev-utils/tsconfig.json index 97fefca01e..9918b06d4a 100644 --- a/contracts/dev-utils/tsconfig.json +++ b/contracts/dev-utils/tsconfig.json @@ -4,9 +4,9 @@ "include": ["./src/**/*", "./test/**/*", "./generated-wrappers/**/*"], "files": [ "generated-artifacts/DevUtils.json", + "generated-artifacts/EthBalanceChecker.json", "generated-artifacts/LibAssetData.json", "generated-artifacts/LibTransactionDecoder.json", - "generated-artifacts/EthBalanceChecker.json", "generated-artifacts/OrderTransferSimulationUtils.json" ], "exclude": ["./deploy/solc/solc_bin"] diff --git a/contracts/exchange/contracts/src/MixinMatchOrders.sol b/contracts/exchange/contracts/src/MixinMatchOrders.sol index 19d1eff3b1..ca8dbfa591 100644 --- a/contracts/exchange/contracts/src/MixinMatchOrders.sol +++ b/contracts/exchange/contracts/src/MixinMatchOrders.sol @@ -146,7 +146,7 @@ contract MixinMatchOrders is ) public nonReentrant - returns (LibFillResults.MatchedFillResults memory matchedFillResults) + returns (LibFillResults.MatchedFillResults memory) { return _matchOrders(leftOrder, rightOrder, leftSignature, rightSignature); } diff --git a/contracts/exchange/test/utils/exchange_wrapper.ts b/contracts/exchange/test/utils/exchange_wrapper.ts index 38850e56de..f836751462 100644 --- a/contracts/exchange/test/utils/exchange_wrapper.ts +++ b/contracts/exchange/test/utils/exchange_wrapper.ts @@ -1,7 +1,7 @@ import { artifacts as erc1155Artifacts } from '@0x/contracts-erc1155'; import { artifacts as erc20Artifacts } from '@0x/contracts-erc20'; import { artifacts as erc721Artifacts } from '@0x/contracts-erc721'; -import { FillResults, LogDecoder, OrderInfo, orderUtils, Web3ProviderEngine } from '@0x/contracts-test-utils'; +import { BatchMatchedFillResults, FillResults, LogDecoder, MatchedFillResults, OrderInfo, orderUtils, Web3ProviderEngine } from '@0x/contracts-test-utils'; import { SignedOrder, SignedZeroExTransaction } from '@0x/types'; import { AbiEncoder, BigNumber } from '@0x/utils'; import { Web3Wrapper } from '@0x/web3-wrapper'; @@ -282,6 +282,21 @@ export class ExchangeWrapper { const tx = await this._logDecoder.getTxWithDecodedLogsAsync(txHash); return tx; } + public async getBatchMatchOrdersResultsAsync( + signedOrdersLeft: SignedOrder[], + signedOrdersRight: SignedOrder[], + from: string, + ): Promise { + const params = orderUtils.createBatchMatchOrders(signedOrdersLeft, signedOrdersRight); + const batchMatchedFillResults = await this._exchange.batchMatchOrders.callAsync( + params.leftOrders, + params.rightOrders, + params.leftSignatures, + params.rightSignatures, + { from }, + ); + return batchMatchedFillResults; + } public async matchOrdersAsync( signedOrderLeft: SignedOrder, signedOrderRight: SignedOrder, @@ -298,6 +313,21 @@ export class ExchangeWrapper { const tx = await this._logDecoder.getTxWithDecodedLogsAsync(txHash); return tx; } + public async getMatchOrdersResultsAsync( + signedOrderLeft: SignedOrder, + signedOrderRight: SignedOrder, + from: string, + ): Promise { + const params = orderUtils.createMatchOrders(signedOrderLeft, signedOrderRight); + const matchedFillResults = await this._exchange.matchOrders.callAsync( + params.left, + params.right, + params.leftSignature, + params.rightSignature, + { from }, + ); + return matchedFillResults; + } public async getFillOrderResultsAsync( signedOrder: SignedOrder, from: string, diff --git a/contracts/test-utils/src/index.ts b/contracts/test-utils/src/index.ts index 44c101adcc..96850273cc 100644 --- a/contracts/test-utils/src/index.ts +++ b/contracts/test-utils/src/index.ts @@ -29,6 +29,7 @@ export { TransactionFactory } from './transaction_factory'; export { testWithReferenceFuncAsync } from './test_with_reference'; export { hexConcat } from './hex_utils'; export { + BatchMatchedFillResults, ContractName, ERC20BalancesByOwner, ERC1155FungibleHoldingsByOwner, @@ -38,6 +39,7 @@ export { FillResults, MarketBuyOrders, MarketSellOrders, + MatchedFillResults, OrderInfo, OrderStatus, Token, diff --git a/contracts/test-utils/src/types.ts b/contracts/test-utils/src/types.ts index b85f06a8b5..6560bdd1dc 100644 --- a/contracts/test-utils/src/types.ts +++ b/contracts/test-utils/src/types.ts @@ -150,3 +150,16 @@ export interface FillResults { makerFeePaid: BigNumber; takerFeePaid: BigNumber; } + +export interface MatchedFillResults { + left: FillResults; + right: FillResults; + leftMakerAssetSpreadAmount: BigNumber; +} + +export interface BatchMatchedFillResults { + left: FillResults[]; + right: FillResults[]; + profitInLeftMakerAsset: BigNumber; + profitInRightMakerAsset: BigNumber; +}