diff --git a/packages/0x.js/src/index.ts b/packages/0x.js/src/index.ts index 650e82a0ac..6951f36b48 100644 --- a/packages/0x.js/src/index.ts +++ b/packages/0x.js/src/index.ts @@ -37,7 +37,6 @@ export { OrderAndTraderInfo, TraderInfo, ValidateOrderFillableOpts, - DutchAuctionData, } from '@0x/contract-wrappers'; export { @@ -85,6 +84,7 @@ export { ExchangeContractErrs, Order, SignedOrder, + DutchAuctionData, ECSignature, OrderStateValid, OrderStateInvalid, diff --git a/packages/contract-wrappers/CHANGELOG.json b/packages/contract-wrappers/CHANGELOG.json index a10fdc48c6..fa8c87afce 100644 --- a/packages/contract-wrappers/CHANGELOG.json +++ b/packages/contract-wrappers/CHANGELOG.json @@ -1,4 +1,12 @@ [ + { + "version": "9.1.5", + "changes": [ + { + "note": "Use assetDataUtils for encoding and decoding DutchAuctionData" + } + ] + }, { "timestamp": 1558712885, "version": "9.1.4", diff --git a/packages/contract-wrappers/src/contract_wrappers/dutch_auction_wrapper.ts b/packages/contract-wrappers/src/contract_wrappers/dutch_auction_wrapper.ts index fc18e510c0..7cb6f74ba3 100644 --- a/packages/contract-wrappers/src/contract_wrappers/dutch_auction_wrapper.ts +++ b/packages/contract-wrappers/src/contract_wrappers/dutch_auction_wrapper.ts @@ -3,16 +3,15 @@ import { DutchAuction } from '@0x/contract-artifacts'; import { schemas } from '@0x/json-schemas'; import { assetDataUtils } from '@0x/order-utils'; import { DutchAuctionDetails, SignedOrder } from '@0x/types'; +import { DutchAuctionData } from '@0x/types'; import { BigNumber } from '@0x/utils'; import { Web3Wrapper } from '@0x/web3-wrapper'; import { ContractAbi } from 'ethereum-types'; -import * as ethAbi from 'ethereumjs-abi'; -import * as ethUtil from 'ethereumjs-util'; import * as _ from 'lodash'; import { orderTxOptsSchema } from '../schemas/order_tx_opts_schema'; import { txOptsSchema } from '../schemas/tx_opts_schema'; -import { DutchAuctionData, DutchAuctionWrapperError, OrderTransactionOpts } from '../types'; +import { DutchAuctionWrapperError, OrderTransactionOpts } from '../types'; import { assert } from '../utils/assert'; import { _getDefaultContractAddresses } from '../utils/contract_addresses'; @@ -36,14 +35,7 @@ export class DutchAuctionWrapper extends ContractWrapper { beginTimeSeconds: BigNumber, beginAmount: BigNumber, ): string { - const assetDataBuffer = ethUtil.toBuffer(assetData); - const abiEncodedAuctionData = (ethAbi as any).rawEncode( - ['uint256', 'uint256'], - [beginTimeSeconds.toString(), beginAmount.toString()], - ); - const abiEncodedAuctionDataBuffer = ethUtil.toBuffer(abiEncodedAuctionData); - const dutchAuctionDataBuffer = Buffer.concat([assetDataBuffer, abiEncodedAuctionDataBuffer]); - const dutchAuctionData = ethUtil.bufferToHex(dutchAuctionDataBuffer); + const dutchAuctionData = assetDataUtils.encodeDutchAuctionAssetData(assetData, beginTimeSeconds, beginAmount); return dutchAuctionData; } /** @@ -54,30 +46,8 @@ export class DutchAuctionWrapper extends ContractWrapper { * @return An object containing the auction asset, auction begin time and auction begin amount. */ public static decodeDutchAuctionData(dutchAuctionData: string): DutchAuctionData { - const dutchAuctionDataBuffer = ethUtil.toBuffer(dutchAuctionData); - // Decode asset data - const dutchAuctionDataLengthInBytes = 64; - const assetDataBuffer = dutchAuctionDataBuffer.slice( - 0, - dutchAuctionDataBuffer.byteLength - dutchAuctionDataLengthInBytes, - ); - const assetDataHex = ethUtil.bufferToHex(assetDataBuffer); - const assetData = assetDataUtils.decodeAssetDataOrThrow(assetDataHex); - // Decode auction details - const dutchAuctionDetailsBuffer = dutchAuctionDataBuffer.slice( - dutchAuctionDataBuffer.byteLength - dutchAuctionDataLengthInBytes, - ); - const [beginTimeSecondsAsBN, beginAmountAsBN] = ethAbi.rawDecode( - ['uint256', 'uint256'], - dutchAuctionDetailsBuffer, - ); - const beginTimeSeconds = new BigNumber(beginTimeSecondsAsBN.toString()); - const beginAmount = new BigNumber(beginAmountAsBN.toString()); - return { - assetData, - beginTimeSeconds, - beginAmount, - }; + const decoded = assetDataUtils.decodeDutchAuctionData(dutchAuctionData); + return decoded; } /** * Instantiate DutchAuctionWrapper diff --git a/packages/contract-wrappers/src/index.ts b/packages/contract-wrappers/src/index.ts index 5d4bdb2519..f179df21f9 100644 --- a/packages/contract-wrappers/src/index.ts +++ b/packages/contract-wrappers/src/index.ts @@ -58,7 +58,6 @@ export { OrderAndTraderInfo, TraderInfo, ValidateOrderFillableOpts, - DutchAuctionData, CoordinatorServerCancellationResponse, CoordinatorServerError, } from './types'; @@ -73,6 +72,7 @@ export { StaticCallAssetData, MultiAssetDataWithRecursiveDecoding, DutchAuctionDetails, + DutchAuctionData, Order, SignedOrder, AssetProxyId, diff --git a/packages/contract-wrappers/src/types.ts b/packages/contract-wrappers/src/types.ts index b0c510a157..de190c62d1 100644 --- a/packages/contract-wrappers/src/types.ts +++ b/packages/contract-wrappers/src/types.ts @@ -220,8 +220,6 @@ export enum DutchAuctionWrapperError { AssetDataMismatch = 'ASSET_DATA_MISMATCH', } -export { DutchAuctionData } from '@0x/types'; - export { CoordinatorServerCancellationResponse, CoordinatorServerError } from './utils/coordinator_server_types'; export interface CoordinatorTransaction { diff --git a/packages/order-utils/src/index.ts b/packages/order-utils/src/index.ts index 476a0f4e0b..4151dcb7a4 100644 --- a/packages/order-utils/src/index.ts +++ b/packages/order-utils/src/index.ts @@ -44,7 +44,9 @@ export { OrderRelevantState, OrderState, ECSignature, + AssetData, SingleAssetData, + DutchAuctionData, ERC20AssetData, ERC721AssetData, ERC1155AssetData,