From 0fba0b1a1bbe1192802ebcf4b88437b94d6a1c18 Mon Sep 17 00:00:00 2001 From: Amir Bandeali Date: Wed, 2 Jan 2019 14:08:21 -0800 Subject: feat: Add balance and allowance checks for MultiAssetProxy --- .../asset_balance_and_proxy_allowance_fetcher.ts | 132 ++++++++++++++------- 1 file changed, 87 insertions(+), 45 deletions(-) (limited to 'packages/contract-wrappers') diff --git a/packages/contract-wrappers/src/fetchers/asset_balance_and_proxy_allowance_fetcher.ts b/packages/contract-wrappers/src/fetchers/asset_balance_and_proxy_allowance_fetcher.ts index d10cffe57..376004f52 100644 --- a/packages/contract-wrappers/src/fetchers/asset_balance_and_proxy_allowance_fetcher.ts +++ b/packages/contract-wrappers/src/fetchers/asset_balance_and_proxy_allowance_fetcher.ts @@ -1,8 +1,9 @@ // tslint:disable:no-unnecessary-type-assertion import { AbstractBalanceAndProxyAllowanceFetcher, assetDataUtils } from '@0x/order-utils'; -import { AssetProxyId, ERC20AssetData, ERC721AssetData } from '@0x/types'; +import { AssetProxyId, ERC20AssetData, ERC721AssetData, MultiAssetData } from '@0x/types'; import { BigNumber } from '@0x/utils'; import { BlockParamLiteral } from 'ethereum-types'; +import * as _ from 'lodash'; import { ERC20TokenWrapper } from '../contract_wrappers/erc20_token_wrapper'; import { ERC721TokenWrapper } from '../contract_wrappers/erc721_token_wrapper'; @@ -18,60 +19,101 @@ export class AssetBalanceAndProxyAllowanceFetcher implements AbstractBalanceAndP } public async getBalanceAsync(assetData: string, userAddress: string): Promise { const decodedAssetData = assetDataUtils.decodeAssetDataOrThrow(assetData); - if (decodedAssetData.assetProxyId === AssetProxyId.ERC20) { - const decodedERC20AssetData = decodedAssetData as ERC20AssetData; - const balance = await this._erc20Token.getBalanceAsync(decodedERC20AssetData.tokenAddress, userAddress, { - defaultBlock: this._stateLayer, - }); - return balance; - } else { - const decodedERC721AssetData = decodedAssetData as ERC721AssetData; - const tokenOwner = await this._erc721Token.getOwnerOfAsync( - decodedERC721AssetData.tokenAddress, - decodedERC721AssetData.tokenId, - { + let balance: BigNumber | undefined; + switch (decodedAssetData.assetProxyId) { + case AssetProxyId.ERC20: + const decodedERC20AssetData = decodedAssetData as ERC20AssetData; + balance = await this._erc20Token.getBalanceAsync(decodedERC20AssetData.tokenAddress, userAddress, { defaultBlock: this._stateLayer, - }, - ); - const balance = tokenOwner === userAddress ? new BigNumber(1) : new BigNumber(0); - return balance; + }); + break; + case AssetProxyId.ERC721: + const decodedERC721AssetData = decodedAssetData as ERC721AssetData; + const tokenOwner = await this._erc721Token.getOwnerOfAsync( + decodedERC721AssetData.tokenAddress, + decodedERC721AssetData.tokenId, + { + defaultBlock: this._stateLayer, + }, + ); + balance = tokenOwner === userAddress ? new BigNumber(1) : new BigNumber(0); + break; + case AssetProxyId.MultiAsset: + // The `balance` for MultiAssetData is the total units of the entire `assetData` that are held by the `userAddress`. + for (const [ + index, + nestedAssetDataElement, + ] of (decodedAssetData as MultiAssetData).nestedAssetData.entries()) { + const nestedAmountElement = (decodedAssetData as MultiAssetData).amounts[index]; + const nestedAssetBalance = (await this.getBalanceAsync( + nestedAssetDataElement, + userAddress, + )).dividedToIntegerBy(nestedAmountElement); + if (_.isUndefined(balance) || nestedAssetBalance.lessThan(balance)) { + balance = nestedAssetBalance; + } + } + break; + default: + throw new Error(`Proxy with id ${decodedAssetData.assetProxyId} not supported`); } + return balance as BigNumber; } public async getProxyAllowanceAsync(assetData: string, userAddress: string): Promise { const decodedAssetData = assetDataUtils.decodeAssetDataOrThrow(assetData); - if (decodedAssetData.assetProxyId === AssetProxyId.ERC20) { - const decodedERC20AssetData = decodedAssetData as ERC20AssetData; - const proxyAllowance = await this._erc20Token.getProxyAllowanceAsync( - decodedERC20AssetData.tokenAddress, - userAddress, - { - defaultBlock: this._stateLayer, - }, - ); - return proxyAllowance; - } else { - const decodedERC721AssetData = decodedAssetData as ERC721AssetData; - - const isApprovedForAll = await this._erc721Token.isProxyApprovedForAllAsync( - decodedERC721AssetData.tokenAddress, - userAddress, - { - defaultBlock: this._stateLayer, - }, - ); - if (isApprovedForAll) { - return new BigNumber(this._erc20Token.UNLIMITED_ALLOWANCE_IN_BASE_UNITS); - } else { - const isApproved = await this._erc721Token.isProxyApprovedAsync( + let proxyAllowance: BigNumber | undefined; + switch (decodedAssetData.assetProxyId) { + case AssetProxyId.ERC20: + const decodedERC20AssetData = decodedAssetData as ERC20AssetData; + proxyAllowance = await this._erc20Token.getProxyAllowanceAsync( + decodedERC20AssetData.tokenAddress, + userAddress, + { + defaultBlock: this._stateLayer, + }, + ); + break; + case AssetProxyId.ERC721: + const decodedERC721AssetData = decodedAssetData as ERC721AssetData; + const isApprovedForAll = await this._erc721Token.isProxyApprovedForAllAsync( decodedERC721AssetData.tokenAddress, - decodedERC721AssetData.tokenId, + userAddress, { defaultBlock: this._stateLayer, }, ); - const proxyAllowance = isApproved ? new BigNumber(1) : new BigNumber(0); - return proxyAllowance; - } + if (isApprovedForAll) { + return new BigNumber(this._erc20Token.UNLIMITED_ALLOWANCE_IN_BASE_UNITS); + } else { + const isApproved = await this._erc721Token.isProxyApprovedAsync( + decodedERC721AssetData.tokenAddress, + decodedERC721AssetData.tokenId, + { + defaultBlock: this._stateLayer, + }, + ); + proxyAllowance = isApproved ? new BigNumber(1) : new BigNumber(0); + } + break; + case AssetProxyId.MultiAsset: + // The `proxyAllowance` for MultiAssetData is the total units of the entire `assetData` that the proxies have been approved to spend by the `userAddress`. + for (const [ + index, + nestedAssetDataElement, + ] of (decodedAssetData as MultiAssetData).nestedAssetData.entries()) { + const nestedAmountElement = (decodedAssetData as MultiAssetData).amounts[index]; + const nestedAssetAllowance = (await this.getProxyAllowanceAsync( + nestedAssetDataElement, + userAddress, + )).dividedToIntegerBy(nestedAmountElement); + if (_.isUndefined(proxyAllowance) || nestedAssetAllowance.lessThan(proxyAllowance)) { + proxyAllowance = nestedAssetAllowance; + } + } + break; + default: + throw new Error(`Proxy with id ${decodedAssetData.assetProxyId} not supported`); } + return proxyAllowance as BigNumber; } } -- cgit v1.2.3 From 70508f52a1dd6bfcc891f145c3a06f1e66c3cda5 Mon Sep 17 00:00:00 2001 From: Amir Bandeali Date: Wed, 2 Jan 2019 17:17:40 -0800 Subject: Update CHANGELOGs --- packages/contract-wrappers/CHANGELOG.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'packages/contract-wrappers') diff --git a/packages/contract-wrappers/CHANGELOG.json b/packages/contract-wrappers/CHANGELOG.json index d39027797..a8c74fa24 100644 --- a/packages/contract-wrappers/CHANGELOG.json +++ b/packages/contract-wrappers/CHANGELOG.json @@ -1,9 +1,13 @@ [ { - "version": "4.1.4", + "version": "4.2.0", "changes": [ { "note": "Add support for Trust Wallet signature denial error" + }, + { + "note": "Add balance and allowance queries for MultiAssetProxy", + "pr": 1363 } ] }, -- cgit v1.2.3 From 24564b986daa703f66e54f85abf4782d99a40f94 Mon Sep 17 00:00:00 2001 From: Amir Bandeali Date: Fri, 4 Jan 2019 14:31:25 -0800 Subject: Minimize unnecessary type assertions --- .../asset_balance_and_proxy_allowance_fetcher.ts | 132 ++++++++------------- 1 file changed, 52 insertions(+), 80 deletions(-) (limited to 'packages/contract-wrappers') diff --git a/packages/contract-wrappers/src/fetchers/asset_balance_and_proxy_allowance_fetcher.ts b/packages/contract-wrappers/src/fetchers/asset_balance_and_proxy_allowance_fetcher.ts index 376004f52..1ff130a48 100644 --- a/packages/contract-wrappers/src/fetchers/asset_balance_and_proxy_allowance_fetcher.ts +++ b/packages/contract-wrappers/src/fetchers/asset_balance_and_proxy_allowance_fetcher.ts @@ -1,6 +1,4 @@ -// tslint:disable:no-unnecessary-type-assertion import { AbstractBalanceAndProxyAllowanceFetcher, assetDataUtils } from '@0x/order-utils'; -import { AssetProxyId, ERC20AssetData, ERC721AssetData, MultiAssetData } from '@0x/types'; import { BigNumber } from '@0x/utils'; import { BlockParamLiteral } from 'ethereum-types'; import * as _ from 'lodash'; @@ -20,99 +18,73 @@ export class AssetBalanceAndProxyAllowanceFetcher implements AbstractBalanceAndP public async getBalanceAsync(assetData: string, userAddress: string): Promise { const decodedAssetData = assetDataUtils.decodeAssetDataOrThrow(assetData); let balance: BigNumber | undefined; - switch (decodedAssetData.assetProxyId) { - case AssetProxyId.ERC20: - const decodedERC20AssetData = decodedAssetData as ERC20AssetData; - balance = await this._erc20Token.getBalanceAsync(decodedERC20AssetData.tokenAddress, userAddress, { + if (assetDataUtils.isERC20AssetData(decodedAssetData)) { + balance = await this._erc20Token.getBalanceAsync(decodedAssetData.tokenAddress, userAddress, { + defaultBlock: this._stateLayer, + }); + } else if (assetDataUtils.isERC721AssetData(decodedAssetData)) { + const tokenOwner = await this._erc721Token.getOwnerOfAsync( + decodedAssetData.tokenAddress, + decodedAssetData.tokenId, + { defaultBlock: this._stateLayer, - }); - break; - case AssetProxyId.ERC721: - const decodedERC721AssetData = decodedAssetData as ERC721AssetData; - const tokenOwner = await this._erc721Token.getOwnerOfAsync( - decodedERC721AssetData.tokenAddress, - decodedERC721AssetData.tokenId, - { - defaultBlock: this._stateLayer, - }, - ); - balance = tokenOwner === userAddress ? new BigNumber(1) : new BigNumber(0); - break; - case AssetProxyId.MultiAsset: - // The `balance` for MultiAssetData is the total units of the entire `assetData` that are held by the `userAddress`. - for (const [ - index, + }, + ); + balance = tokenOwner === userAddress ? new BigNumber(1) : new BigNumber(0); + } else if (assetDataUtils.isMultiAssetData(decodedAssetData)) { + // The `balance` for MultiAssetData is the total units of the entire `assetData` that are held by the `userAddress`. + for (const [index, nestedAssetDataElement] of decodedAssetData.nestedAssetData.entries()) { + const nestedAmountElement = decodedAssetData.amounts[index]; + const nestedAssetBalance = (await this.getBalanceAsync( nestedAssetDataElement, - ] of (decodedAssetData as MultiAssetData).nestedAssetData.entries()) { - const nestedAmountElement = (decodedAssetData as MultiAssetData).amounts[index]; - const nestedAssetBalance = (await this.getBalanceAsync( - nestedAssetDataElement, - userAddress, - )).dividedToIntegerBy(nestedAmountElement); - if (_.isUndefined(balance) || nestedAssetBalance.lessThan(balance)) { - balance = nestedAssetBalance; - } + userAddress, + )).dividedToIntegerBy(nestedAmountElement); + if (_.isUndefined(balance) || nestedAssetBalance.lessThan(balance)) { + balance = nestedAssetBalance; } - break; - default: - throw new Error(`Proxy with id ${decodedAssetData.assetProxyId} not supported`); + } } return balance as BigNumber; } public async getProxyAllowanceAsync(assetData: string, userAddress: string): Promise { const decodedAssetData = assetDataUtils.decodeAssetDataOrThrow(assetData); let proxyAllowance: BigNumber | undefined; - switch (decodedAssetData.assetProxyId) { - case AssetProxyId.ERC20: - const decodedERC20AssetData = decodedAssetData as ERC20AssetData; - proxyAllowance = await this._erc20Token.getProxyAllowanceAsync( - decodedERC20AssetData.tokenAddress, - userAddress, - { - defaultBlock: this._stateLayer, - }, - ); - break; - case AssetProxyId.ERC721: - const decodedERC721AssetData = decodedAssetData as ERC721AssetData; - const isApprovedForAll = await this._erc721Token.isProxyApprovedForAllAsync( - decodedERC721AssetData.tokenAddress, - userAddress, + if (assetDataUtils.isERC20AssetData(decodedAssetData)) { + proxyAllowance = await this._erc20Token.getProxyAllowanceAsync(decodedAssetData.tokenAddress, userAddress, { + defaultBlock: this._stateLayer, + }); + } else if (assetDataUtils.isERC721AssetData(decodedAssetData)) { + const isApprovedForAll = await this._erc721Token.isProxyApprovedForAllAsync( + decodedAssetData.tokenAddress, + userAddress, + { + defaultBlock: this._stateLayer, + }, + ); + if (isApprovedForAll) { + return new BigNumber(this._erc20Token.UNLIMITED_ALLOWANCE_IN_BASE_UNITS); + } else { + const isApproved = await this._erc721Token.isProxyApprovedAsync( + decodedAssetData.tokenAddress, + decodedAssetData.tokenId, { defaultBlock: this._stateLayer, }, ); - if (isApprovedForAll) { - return new BigNumber(this._erc20Token.UNLIMITED_ALLOWANCE_IN_BASE_UNITS); - } else { - const isApproved = await this._erc721Token.isProxyApprovedAsync( - decodedERC721AssetData.tokenAddress, - decodedERC721AssetData.tokenId, - { - defaultBlock: this._stateLayer, - }, - ); - proxyAllowance = isApproved ? new BigNumber(1) : new BigNumber(0); - } - break; - case AssetProxyId.MultiAsset: - // The `proxyAllowance` for MultiAssetData is the total units of the entire `assetData` that the proxies have been approved to spend by the `userAddress`. - for (const [ - index, + proxyAllowance = isApproved ? new BigNumber(1) : new BigNumber(0); + } + } else if (assetDataUtils.isMultiAssetData(decodedAssetData)) { + // The `proxyAllowance` for MultiAssetData is the total units of the entire `assetData` that the proxies have been approved to spend by the `userAddress`. + for (const [index, nestedAssetDataElement] of decodedAssetData.nestedAssetData.entries()) { + const nestedAmountElement = decodedAssetData.amounts[index]; + const nestedAssetAllowance = (await this.getProxyAllowanceAsync( nestedAssetDataElement, - ] of (decodedAssetData as MultiAssetData).nestedAssetData.entries()) { - const nestedAmountElement = (decodedAssetData as MultiAssetData).amounts[index]; - const nestedAssetAllowance = (await this.getProxyAllowanceAsync( - nestedAssetDataElement, - userAddress, - )).dividedToIntegerBy(nestedAmountElement); - if (_.isUndefined(proxyAllowance) || nestedAssetAllowance.lessThan(proxyAllowance)) { - proxyAllowance = nestedAssetAllowance; - } + userAddress, + )).dividedToIntegerBy(nestedAmountElement); + if (_.isUndefined(proxyAllowance) || nestedAssetAllowance.lessThan(proxyAllowance)) { + proxyAllowance = nestedAssetAllowance; } - break; - default: - throw new Error(`Proxy with id ${decodedAssetData.assetProxyId} not supported`); + } } return proxyAllowance as BigNumber; } -- cgit v1.2.3 From fd37e88bdbdcc821e4aa734aed6ad1f499b2b3e4 Mon Sep 17 00:00:00 2001 From: Amir Bandeali Date: Mon, 7 Jan 2019 11:11:19 -0800 Subject: Use enums in pipeline --- packages/contract-wrappers/CHANGELOG.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/contract-wrappers') diff --git a/packages/contract-wrappers/CHANGELOG.json b/packages/contract-wrappers/CHANGELOG.json index a8c74fa24..581fbdee1 100644 --- a/packages/contract-wrappers/CHANGELOG.json +++ b/packages/contract-wrappers/CHANGELOG.json @@ -6,7 +6,7 @@ "note": "Add support for Trust Wallet signature denial error" }, { - "note": "Add balance and allowance queries for MultiAssetProxy", + "note": "Add balance and allowance queries for `MultiAssetProxy`", "pr": 1363 } ] -- cgit v1.2.3 From 43b648e7dc1ea49aff3ab1e6883aa6e069fae72f Mon Sep 17 00:00:00 2001 From: Greg Hysen Date: Thu, 20 Dec 2018 15:39:19 -0800 Subject: Dutch wrapper --- .../contract-wrappers/src/contract_wrappers.ts | 10 ++ .../src/contract_wrappers/dutch_auction_wrapper.ts | 151 ++++++++++++++++++++ packages/contract-wrappers/src/index.ts | 1 + .../test/dutch_auction_wrapper_test.ts | 156 +++++++++++++++++++++ 4 files changed, 318 insertions(+) create mode 100644 packages/contract-wrappers/src/contract_wrappers/dutch_auction_wrapper.ts create mode 100644 packages/contract-wrappers/test/dutch_auction_wrapper_test.ts (limited to 'packages/contract-wrappers') diff --git a/packages/contract-wrappers/src/contract_wrappers.ts b/packages/contract-wrappers/src/contract_wrappers.ts index 0c535bd5c..396505866 100644 --- a/packages/contract-wrappers/src/contract_wrappers.ts +++ b/packages/contract-wrappers/src/contract_wrappers.ts @@ -20,6 +20,7 @@ import { EtherTokenWrapper } from './contract_wrappers/ether_token_wrapper'; import { ExchangeWrapper } from './contract_wrappers/exchange_wrapper'; import { ForwarderWrapper } from './contract_wrappers/forwarder_wrapper'; import { OrderValidatorWrapper } from './contract_wrappers/order_validator_wrapper'; +import { DutchAuctionWrapper } from './contract_wrappers/dutch_auction_wrapper'; import { ContractWrappersConfigSchema } from './schemas/contract_wrappers_config_schema'; import { ContractWrappersConfig } from './types'; import { assert } from './utils/assert'; @@ -65,6 +66,10 @@ export class ContractWrappers { * An instance of the OrderValidatorWrapper class containing methods for interacting with any OrderValidator smart contract. */ public orderValidator: OrderValidatorWrapper; + /** + * An instance of the DutchAuctionWrapper class containing methods for interacting with any DutchAuction smart contract. + */ + public dutchAuction: DutchAuctionWrapper; private readonly _web3Wrapper: Web3Wrapper; /** @@ -141,6 +146,11 @@ export class ContractWrappers { config.networkId, contractAddresses.orderValidator, ); + this.dutchAuction = new DutchAuctionWrapper( + this._web3Wrapper, + config.networkId, + contractAddresses.orderValidator, + ); } /** * Unsubscribes from all subscriptions for all contracts. diff --git a/packages/contract-wrappers/src/contract_wrappers/dutch_auction_wrapper.ts b/packages/contract-wrappers/src/contract_wrappers/dutch_auction_wrapper.ts new file mode 100644 index 000000000..500e7a63d --- /dev/null +++ b/packages/contract-wrappers/src/contract_wrappers/dutch_auction_wrapper.ts @@ -0,0 +1,151 @@ +import { artifacts as protocolArtifacts } from '@0x/contracts-protocol'; +import { DutchAuctionContract } from '@0x/abi-gen-wrappers'; +import { DutchAuction } from '@0x/contract-artifacts'; +import { LogDecoder } from '@0x/contracts-test-utils'; +import { artifacts as tokensArtifacts } from '@0x/contracts-tokens'; +import { _getDefaultContractAddresses } from '../utils/contract_addresses'; +import { DutchAuctionDetails, SignedOrder } from '@0x/types'; +import { ContractAbi } from 'ethereum-types'; +import { Web3Wrapper } from '@0x/web3-wrapper'; +import { BigNumber } from '@0x/utils'; +import { Provider, TransactionReceiptWithDecodedLogs } from 'ethereum-types'; +import * as _ from 'lodash'; +import ethAbi = require('ethereumjs-abi'); +import { schemas } from '@0x/json-schemas'; +import { assert } from '../utils/assert'; +import ethUtil = require('ethereumjs-util'); + +import { orderTxOptsSchema } from '../schemas/order_tx_opts_schema'; +import { txOptsSchema } from '../schemas/tx_opts_schema'; +import { OrderTransactionOpts } from '../types'; +import { ContractWrapper } from './contract_wrapper'; +import { ExchangeWrapperError } from '../types'; + +export class DutchAuctionWrapper extends ContractWrapper { + public abi: ContractAbi = DutchAuction.compilerOutput.abi; + public address: string; + private _dutchAuctionContractIfExists?: DutchAuctionContract; + /** + * Instantiate DutchAuctionWrapper + * @param web3Wrapper Web3Wrapper instance to use. + * @param networkId Desired networkId. + * @param address The address of the Dutch Auction contract. If undefined, will + * default to the known address corresponding to the networkId. + */ + constructor( + web3Wrapper: Web3Wrapper, + networkId: number, + address: string, + ) { + super(web3Wrapper, networkId); + this.address = address; + } + /** + * Matches the buy and sell orders at an amount given the following: the current block time, the auction + * start time and the auction begin amount. The sell order is a an order at the lowest amount + * at the end of the auction. Excess from the match is transferred to the seller. + * Over time the price moves from beginAmount to endAmount given the current block.timestamp. + * @param buyOrder The Buyer's order. This order is for the current expected price of the auction. + * @param sellOrder The Seller's order. This order is for the lowest amount (at the end of the auction). + * @param from Address the transaction is being sent from. + * @return Transaction receipt with decoded logs. + */ + public async matchOrdersAsync( + buyOrder: SignedOrder, + sellOrder: SignedOrder, + takerAddress: string, + orderTransactionOpts: OrderTransactionOpts = { shouldValidate: true }, + ): Promise { + // type assertions + assert.doesConformToSchema('buyOrder', buyOrder, schemas.signedOrderSchema); + assert.doesConformToSchema('sellOrder', sellOrder, schemas.signedOrderSchema); + await assert.isSenderAddressAsync('takerAddress', takerAddress, this._web3Wrapper); + assert.doesConformToSchema('orderTransactionOpts', orderTransactionOpts, orderTxOptsSchema, [txOptsSchema]); + const normalizedTakerAddress = takerAddress.toLowerCase(); + // other assertions + if ( + sellOrder.makerAssetData !== buyOrder.takerAssetData || + sellOrder.takerAssetData !== buyOrder.makerAssetData + ) { + throw new Error(ExchangeWrapperError.AssetDataMismatch); + } + // get contract + const dutchAuctionInstance = await this._getDutchAuctionContractAsync(); + // validate transaction + if (orderTransactionOpts.shouldValidate) { + await dutchAuctionInstance.matchOrders.callAsync( + buyOrder, + sellOrder, + buyOrder.signature, + sellOrder.signature, + { + from: normalizedTakerAddress, + gas: orderTransactionOpts.gasLimit, + gasPrice: orderTransactionOpts.gasPrice, + nonce: orderTransactionOpts.nonce, + }, + ); + } + // send transaction + const txHash = await dutchAuctionInstance.matchOrders.sendTransactionAsync( + buyOrder, + sellOrder, + buyOrder.signature, + sellOrder.signature, + { + from: normalizedTakerAddress, + gas: orderTransactionOpts.gasLimit, + gasPrice: orderTransactionOpts.gasPrice, + nonce: orderTransactionOpts.nonce, + }, + ); + return txHash; + } + /** + * Calculates the Auction Details for the given order + * @param sellOrder The Seller's order. This order is for the lowest amount (at the end of the auction). + * @return The dutch auction details. + */ + public async getAuctionDetailsAsync(sellOrder: SignedOrder): Promise { + // type assertions + assert.doesConformToSchema('sellOrder', sellOrder, schemas.signedOrderSchema); + // get contract + const dutchAuctionInstance = await this._getDutchAuctionContractAsync(); + // call contract + const afterAuctionDetails = await dutchAuctionInstance.getAuctionDetails.callAsync(sellOrder); + return afterAuctionDetails; + } + private async _getDutchAuctionContractAsync(): Promise { + if (!_.isUndefined(this._dutchAuctionContractIfExists)) { + return this._dutchAuctionContractIfExists; + } + const contractInstance = new DutchAuctionContract( + this.abi, + this.address, + this._web3Wrapper.getProvider(), + this._web3Wrapper.getContractDefaults(), + ); + this._dutchAuctionContractIfExists = contractInstance; + return this._dutchAuctionContractIfExists; + } + /** + * Dutch auction details are encoded with the asset data for a 0x order. This function produces a hex + * encoded assetData string, containing information both about the asset being traded and the + * dutch auction; which is usable in the makerAssetData or takerAssetData fields in a 0x order. + * @param assetData Hex encoded assetData string for the asset being auctioned. + * @param beginTimeSeconds Begin time of the dutch auction. + * @param beginAmount Starting amount being sold in the dutch auction. + * @return The hex encoded assetData string. + */ + public static encodeDutchAuctionAssetData(assetData: string, 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); + return dutchAuctionData; + }; +} diff --git a/packages/contract-wrappers/src/index.ts b/packages/contract-wrappers/src/index.ts index d66ff5c9c..5c64dbbc6 100644 --- a/packages/contract-wrappers/src/index.ts +++ b/packages/contract-wrappers/src/index.ts @@ -34,6 +34,7 @@ export { ERC20ProxyWrapper } from './contract_wrappers/erc20_proxy_wrapper'; export { ERC721ProxyWrapper } from './contract_wrappers/erc721_proxy_wrapper'; export { ForwarderWrapper } from './contract_wrappers/forwarder_wrapper'; export { OrderValidatorWrapper } from './contract_wrappers/order_validator_wrapper'; +export { DutchAuctionWrapper } from './contract_wrappers/dutch_auction_wrapper'; export { TransactionEncoder } from './utils/transaction_encoder'; diff --git a/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts b/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts new file mode 100644 index 000000000..ad8b3bd31 --- /dev/null +++ b/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts @@ -0,0 +1,156 @@ +import { BlockchainLifecycle } from '@0x/dev-utils'; +import { FillScenarios } from '@0x/fill-scenarios'; +import { assetDataUtils } from '@0x/order-utils'; +import { SignedOrder } from '@0x/types'; +import { BigNumber } from '@0x/utils'; +import * as chai from 'chai'; +import 'mocha'; + +import { ContractWrappers, OrderStatus } from '../src'; + +import { chaiSetup } from './utils/chai_setup'; +import { constants } from './utils/constants'; +import { migrateOnceAsync } from './utils/migrate'; +import { tokenUtils } from './utils/token_utils'; +import { provider, web3Wrapper } from './utils/web3_wrapper'; +import { getLatestBlockTimestampAsync } from '@0x/contracts-test-utils'; +import { DutchAuction } from '@0x/contract-artifacts'; +import { DutchAuctionWrapper } from '../src/contract_wrappers/dutch_auction_wrapper'; + +chaiSetup.configure(); +const expect = chai.expect; +const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); + +// tslint:disable:custom-no-magic-numbers +describe.only('DutchAuctionWrapper', () => { + const fillableAmount = new BigNumber(5); + const tenMinutesInSeconds = 10 * 60; + let contractWrappers: ContractWrappers; + let fillScenarios: FillScenarios; + let exchangeContractAddress: string; + let zrxTokenAddress: string; + let userAddresses: string[]; + let makerAddress: string; + let takerAddress: string; + let makerTokenAddress: string; + let takerTokenAddress: string; + let makerAssetData: string; + let takerAssetData: string; + let buyOrder: SignedOrder; + let sellOrder: SignedOrder; + let makerTokenAssetData: string; + let takerTokenAssetData: string; + before(async () => { + console.log(`BEOGIN DEPLOYINH`); + const contractAddresses = await migrateOnceAsync(); + await blockchainLifecycle.startAsync(); + const config = { + networkId: constants.TESTRPC_NETWORK_ID, + contractAddresses, + blockPollingIntervalMs: 10, + }; + + contractWrappers = new ContractWrappers(provider, config); + console.log(`DEPLOYINH`); + exchangeContractAddress = contractWrappers.exchange.address; + userAddresses = await web3Wrapper.getAvailableAddressesAsync(); + zrxTokenAddress = contractWrappers.exchange.zrxTokenAddress; + fillScenarios = new FillScenarios( + provider, + userAddresses, + zrxTokenAddress, + exchangeContractAddress, + contractWrappers.erc20Proxy.address, + contractWrappers.erc721Proxy.address, + ); + [, makerAddress, takerAddress] = userAddresses; + [makerTokenAddress] = tokenUtils.getDummyERC20TokenAddresses(); + takerTokenAddress = contractWrappers.forwarder.etherTokenAddress; + // construct asset data for tokens being swapped + [makerTokenAssetData, takerTokenAssetData] = [ + assetDataUtils.encodeERC20AssetData(makerTokenAddress), + assetDataUtils.encodeERC20AssetData(takerTokenAddress), + ]; + // encode auction details in maker asset data + const auctionBeginAmount = fillableAmount; + const currentBlockTimestamp = await getLatestBlockTimestampAsync(); + const auctionBeginTimeSeconds = new BigNumber(currentBlockTimestamp - tenMinutesInSeconds); + makerAssetData = DutchAuctionWrapper.encodeDutchAuctionAssetData( + makerTokenAssetData, + auctionBeginTimeSeconds, + auctionBeginAmount + ); + takerAssetData = takerTokenAssetData; + // create sell / buy orders for auction + // note that the maker/taker asset datas are swapped in the `buyOrder` + sellOrder = await fillScenarios.createFillableSignedOrderAsync( + makerAssetData, + takerAssetData, + makerAddress, + constants.NULL_ADDRESS, + fillableAmount, + ); + buyOrder = await fillScenarios.createFillableSignedOrderAsync( + takerAssetData, + makerAssetData, + makerAddress, + constants.NULL_ADDRESS, + fillableAmount, + ); + }); + after(async () => { + await blockchainLifecycle.revertAsync(); + }); + beforeEach(async () => { + await blockchainLifecycle.startAsync(); + }); + afterEach(async () => { + await blockchainLifecycle.revertAsync(); + }); + describe('#matchOrdersAsync', () => { + it('should match two orders', async () => { + const txHash = await contractWrappers.dutchAuction.matchOrdersAsync(buyOrder, sellOrder, takerAddress); + await web3Wrapper.awaitTransactionSuccessAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS); + }); + it('should throw when invalid transaction and shouldValidate is true', async () => { + // request match with bad buy/sell orders + const badSellOrder = buyOrder; + const badBuyOrder = sellOrder; + return expect( + await contractWrappers.dutchAuction.matchOrdersAsync( + badBuyOrder, + badSellOrder, + takerAddress, + { + shouldValidate: true, + }, + ), + ).to.be.rejectedWith('COMPLETE_FILL_FAILED'); + }); + }); + + describe('#getAuctionDetailsAsync', () => { + it('should be worth the begin price at the begining of the auction', async () => { + // setup auction details + const auctionBeginAmount = fillableAmount; + const currentBlockTimestamp = await getLatestBlockTimestampAsync(); + const auctionBeginTimeSeconds = new BigNumber(currentBlockTimestamp + tenMinutesInSeconds); + const makerAssetData = DutchAuctionWrapper.encodeDutchAuctionAssetData( + makerTokenAssetData, + auctionBeginTimeSeconds, + auctionBeginAmount + ); + const order = await fillScenarios.createFillableSignedOrderAsync( + makerAssetData, + takerAssetData, + makerAddress, + constants.NULL_ADDRESS, + fillableAmount, + ); + const auctionDetails = await contractWrappers.dutchAuction.getAuctionDetailsAsync(order); + expect(auctionDetails.currentTimeSeconds).to.be.bignumber.lte(auctionBeginTimeSeconds); + expect(auctionDetails.currentAmount).to.be.bignumber.equal(auctionBeginAmount); + expect(auctionDetails.beginAmount).to.be.bignumber.equal(auctionBeginAmount); + }); + }); +}); -- cgit v1.2.3 From 5da748a062043b46133a2dbce248a756bbefce12 Mon Sep 17 00:00:00 2001 From: Greg Hysen Date: Thu, 20 Dec 2018 19:40:16 -0800 Subject: Progress on dutch auction wrapper. Need to add auction data decoding to it. --- .../contract-wrappers/src/contract_wrappers.ts | 2 +- .../src/contract_wrappers/dutch_auction_wrapper.ts | 74 +++++++++++++++++++++- .../test/dutch_auction_wrapper_test.ts | 46 ++++++++------ 3 files changed, 99 insertions(+), 23 deletions(-) (limited to 'packages/contract-wrappers') diff --git a/packages/contract-wrappers/src/contract_wrappers.ts b/packages/contract-wrappers/src/contract_wrappers.ts index 396505866..3728d58d3 100644 --- a/packages/contract-wrappers/src/contract_wrappers.ts +++ b/packages/contract-wrappers/src/contract_wrappers.ts @@ -149,7 +149,7 @@ export class ContractWrappers { this.dutchAuction = new DutchAuctionWrapper( this._web3Wrapper, config.networkId, - contractAddresses.orderValidator, + contractAddresses.dutchAuction, ); } /** 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 500e7a63d..fee543c3b 100644 --- a/packages/contract-wrappers/src/contract_wrappers/dutch_auction_wrapper.ts +++ b/packages/contract-wrappers/src/contract_wrappers/dutch_auction_wrapper.ts @@ -21,9 +21,13 @@ import { OrderTransactionOpts } from '../types'; import { ContractWrapper } from './contract_wrapper'; import { ExchangeWrapperError } from '../types'; +import { orderFactory } from '@0x/order-utils/lib/src/order_factory'; +import { constants } from 'zlib'; + export class DutchAuctionWrapper extends ContractWrapper { public abi: ContractAbi = DutchAuction.compilerOutput.abi; public address: string; + private _exchangeAddress: string; private _dutchAuctionContractIfExists?: DutchAuctionContract; /** * Instantiate DutchAuctionWrapper @@ -35,10 +39,12 @@ export class DutchAuctionWrapper extends ContractWrapper { constructor( web3Wrapper: Web3Wrapper, networkId: number, - address: string, + address?: string, + exchangeAddress?: string, ) { super(web3Wrapper, networkId); - this.address = address; + this.address = this.address = _.isUndefined(address) ? _getDefaultContractAddresses(networkId).dutchAuction : address; + this._exchangeAddress = _.isUndefined(exchangeAddress) ? _getDefaultContractAddresses(networkId).exchange : exchangeAddress; } /** * Matches the buy and sell orders at an amount given the following: the current block time, the auction @@ -110,6 +116,8 @@ export class DutchAuctionWrapper extends ContractWrapper { // type assertions assert.doesConformToSchema('sellOrder', sellOrder, schemas.signedOrderSchema); // get contract + console.log(sellOrder); + console.log(await this._getDutchAuctionContractAsync()); const dutchAuctionInstance = await this._getDutchAuctionContractAsync(); // call contract const afterAuctionDetails = await dutchAuctionInstance.getAuctionDetails.callAsync(sellOrder); @@ -128,6 +136,66 @@ export class DutchAuctionWrapper extends ContractWrapper { this._dutchAuctionContractIfExists = contractInstance; return this._dutchAuctionContractIfExists; } + + public async createSignedSellOrderAsync( + auctionBeginTimeSections: BigNumber, + auctionBeginAmount: BigNumber, + auctionEndAmount: BigNumber, + acutionEndTime: BigNumber, + makerAssetData: string, + takerAssetData: string, + makerAddress: string, + takerAddress: string, + takerFillableAmount: BigNumber, + senderAddress?: string, + makerFee?: BigNumber, + takerFee?: BigNumber, + feeRecipientAddress?: string, + ): Promise { + console.log(`asdasd`); + const makerAssetAmount = auctionEndAmount; + const makerAssetDataWithAuctionDetails = DutchAuctionWrapper.encodeDutchAuctionAssetData(makerAssetData, auctionBeginTimeSections, auctionBeginAmount); + const signedOrder = await orderFactory.createSignedOrderAsync( + this._web3Wrapper.getProvider(), + makerAddress, + makerAssetAmount, + makerAssetDataWithAuctionDetails, + takerFillableAmount, + takerAssetData, + this._exchangeAddress, + { + takerAddress, + senderAddress, + makerFee, + takerFee, + feeRecipientAddress, + expirationTimeSeconds: acutionEndTime, + }, + ); + //console.log(signedOrder); + return signedOrder; + } + + public async createSignedBuyOrderAsync(sellOrder: SignedOrder, buyerAddress: string, senderAddress?: string, makerFee?: BigNumber, takerFee?: BigNumber, feeRecipientAddress?: string): Promise { + const signedOrder = await orderFactory.createSignedOrderAsync( + this._web3Wrapper.getProvider(), + buyerAddress, + sellOrder.takerAssetAmount.times(2), // change this to decode value from auction @TODO -- add decode above for this. + sellOrder.takerAssetData, + sellOrder.makerAssetAmount, + sellOrder.makerAssetData, + sellOrder.exchangeAddress, + { + senderAddress, + makerFee, + takerFee, + feeRecipientAddress, + expirationTimeSeconds: sellOrder.expirationTimeSeconds, + }, + ); + // console.log(signedOrder); + return signedOrder; + } /** * Dutch auction details are encoded with the asset data for a 0x order. This function produces a hex * encoded assetData string, containing information both about the asset being traded and the @@ -138,6 +206,7 @@ export class DutchAuctionWrapper extends ContractWrapper { * @return The hex encoded assetData string. */ public static encodeDutchAuctionAssetData(assetData: string, beginTimeSeconds: BigNumber, beginAmount: BigNumber): string { + // console.log(`yoooo`, assetData); const assetDataBuffer = ethUtil.toBuffer(assetData); const abiEncodedAuctionData = (ethAbi as any).rawEncode( ['uint256', 'uint256'], @@ -145,6 +214,7 @@ export class DutchAuctionWrapper extends ContractWrapper { ); const abiEncodedAuctionDataBuffer = ethUtil.toBuffer(abiEncodedAuctionData); const dutchAuctionDataBuffer = Buffer.concat([assetDataBuffer, abiEncodedAuctionDataBuffer]); + // console.log(`GREFG --- `, abiEncodedAuctionData); const dutchAuctionData = ethUtil.bufferToHex(dutchAuctionDataBuffer); return dutchAuctionData; }; diff --git a/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts b/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts index ad8b3bd31..bfc4e0a58 100644 --- a/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts +++ b/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts @@ -16,6 +16,7 @@ import { provider, web3Wrapper } from './utils/web3_wrapper'; import { getLatestBlockTimestampAsync } from '@0x/contracts-test-utils'; import { DutchAuction } from '@0x/contract-artifacts'; import { DutchAuctionWrapper } from '../src/contract_wrappers/dutch_auction_wrapper'; +import { Web3Wrapper } from '@0x/web3-wrapper'; chaiSetup.configure(); const expect = chai.expect; @@ -23,7 +24,7 @@ const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); // tslint:disable:custom-no-magic-numbers describe.only('DutchAuctionWrapper', () => { - const fillableAmount = new BigNumber(5); + const fillableAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(50), 18); const tenMinutesInSeconds = 10 * 60; let contractWrappers: ContractWrappers; let fillScenarios: FillScenarios; @@ -32,10 +33,9 @@ describe.only('DutchAuctionWrapper', () => { let userAddresses: string[]; let makerAddress: string; let takerAddress: string; + let buyerAddress: string; let makerTokenAddress: string; let takerTokenAddress: string; - let makerAssetData: string; - let takerAssetData: string; let buyOrder: SignedOrder; let sellOrder: SignedOrder; let makerTokenAssetData: string; @@ -63,40 +63,44 @@ describe.only('DutchAuctionWrapper', () => { contractWrappers.erc20Proxy.address, contractWrappers.erc721Proxy.address, ); - [, makerAddress, takerAddress] = userAddresses; + [, makerAddress, takerAddress, buyerAddress] = userAddresses; [makerTokenAddress] = tokenUtils.getDummyERC20TokenAddresses(); takerTokenAddress = contractWrappers.forwarder.etherTokenAddress; + console.log(`B`); // construct asset data for tokens being swapped [makerTokenAssetData, takerTokenAssetData] = [ assetDataUtils.encodeERC20AssetData(makerTokenAddress), assetDataUtils.encodeERC20AssetData(takerTokenAddress), ]; + console.log(`C`); // encode auction details in maker asset data const auctionBeginAmount = fillableAmount; const currentBlockTimestamp = await getLatestBlockTimestampAsync(); const auctionBeginTimeSeconds = new BigNumber(currentBlockTimestamp - tenMinutesInSeconds); - makerAssetData = DutchAuctionWrapper.encodeDutchAuctionAssetData( + /* makerAssetData = DutchAuctionWrapper.encodeDutchAuctionAssetData( makerTokenAssetData, auctionBeginTimeSeconds, auctionBeginAmount - ); - takerAssetData = takerTokenAssetData; + );*/ + console.log(`C2`); // create sell / buy orders for auction // note that the maker/taker asset datas are swapped in the `buyOrder` - sellOrder = await fillScenarios.createFillableSignedOrderAsync( - makerAssetData, - takerAssetData, - makerAddress, - constants.NULL_ADDRESS, + sellOrder = await contractWrappers.dutchAuction.createSignedSellOrderAsync( + auctionBeginTimeSeconds, + fillableAmount.times(2), fillableAmount, - ); - buyOrder = await fillScenarios.createFillableSignedOrderAsync( - takerAssetData, - makerAssetData, + new BigNumber(currentBlockTimestamp + tenMinutesInSeconds), + makerTokenAssetData, + takerTokenAssetData, makerAddress, constants.NULL_ADDRESS, fillableAmount, ); + buyOrder = await contractWrappers.dutchAuction.createSignedBuyOrderAsync( + sellOrder, + buyerAddress, + ); + console.log(`CD`); }); after(async () => { await blockchainLifecycle.revertAsync(); @@ -109,8 +113,10 @@ describe.only('DutchAuctionWrapper', () => { }); describe('#matchOrdersAsync', () => { it('should match two orders', async () => { - const txHash = await contractWrappers.dutchAuction.matchOrdersAsync(buyOrder, sellOrder, takerAddress); - await web3Wrapper.awaitTransactionSuccessAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS); + console.log(await contractWrappers.dutchAuction.getAuctionDetailsAsync(sellOrder)); + + // const txHash = await contractWrappers.dutchAuction.matchOrdersAsync(buyOrder, sellOrder, takerAddress, {gasLimit: 1000000}); + //await web3Wrapper.awaitTransactionSuccessAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS); }); it('should throw when invalid transaction and shouldValidate is true', async () => { // request match with bad buy/sell orders @@ -130,7 +136,7 @@ describe.only('DutchAuctionWrapper', () => { }); describe('#getAuctionDetailsAsync', () => { - it('should be worth the begin price at the begining of the auction', async () => { + /*it('should be worth the begin price at the begining of the auction', async () => { // setup auction details const auctionBeginAmount = fillableAmount; const currentBlockTimestamp = await getLatestBlockTimestampAsync(); @@ -151,6 +157,6 @@ describe.only('DutchAuctionWrapper', () => { expect(auctionDetails.currentTimeSeconds).to.be.bignumber.lte(auctionBeginTimeSeconds); expect(auctionDetails.currentAmount).to.be.bignumber.equal(auctionBeginAmount); expect(auctionDetails.beginAmount).to.be.bignumber.equal(auctionBeginAmount); - }); + });*/ }); }); -- cgit v1.2.3 From 7203ca90cf9bff2f7accf5fe2ee7da5764d0dac3 Mon Sep 17 00:00:00 2001 From: Greg Hysen Date: Fri, 21 Dec 2018 16:11:59 -0800 Subject: all dutchie wrapper tests passing --- .../src/contract_wrappers/dutch_auction_wrapper.ts | 94 +++++++--------------- .../test/dutch_auction_wrapper_test.ts | 90 +++++++++++---------- 2 files changed, 76 insertions(+), 108 deletions(-) (limited to 'packages/contract-wrappers') 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 fee543c3b..5896617fc 100644 --- a/packages/contract-wrappers/src/contract_wrappers/dutch_auction_wrapper.ts +++ b/packages/contract-wrappers/src/contract_wrappers/dutch_auction_wrapper.ts @@ -7,7 +7,7 @@ import { _getDefaultContractAddresses } from '../utils/contract_addresses'; import { DutchAuctionDetails, SignedOrder } from '@0x/types'; import { ContractAbi } from 'ethereum-types'; import { Web3Wrapper } from '@0x/web3-wrapper'; -import { BigNumber } from '@0x/utils'; +import { BigNumber, abiUtils } from '@0x/utils'; import { Provider, TransactionReceiptWithDecodedLogs } from 'ethereum-types'; import * as _ from 'lodash'; import ethAbi = require('ethereumjs-abi'); @@ -21,8 +21,7 @@ import { OrderTransactionOpts } from '../types'; import { ContractWrapper } from './contract_wrapper'; import { ExchangeWrapperError } from '../types'; -import { orderFactory } from '@0x/order-utils/lib/src/order_factory'; -import { constants } from 'zlib'; +import { assetDataUtils, AssetData } from '@0x/order-utils'; export class DutchAuctionWrapper extends ContractWrapper { public abi: ContractAbi = DutchAuction.compilerOutput.abi; @@ -74,6 +73,10 @@ export class DutchAuctionWrapper extends ContractWrapper { sellOrder.takerAssetData !== buyOrder.makerAssetData ) { throw new Error(ExchangeWrapperError.AssetDataMismatch); + } else { + // Smart contracts assigns the asset data from the left order to the right one so we can save gas on reducing the size of call data + //rightSignedOrder.makerAssetData = '0x'; + // rightSignedOrder.takerAssetData = '0x'; } // get contract const dutchAuctionInstance = await this._getDutchAuctionContractAsync(); @@ -136,66 +139,6 @@ export class DutchAuctionWrapper extends ContractWrapper { this._dutchAuctionContractIfExists = contractInstance; return this._dutchAuctionContractIfExists; } - - public async createSignedSellOrderAsync( - auctionBeginTimeSections: BigNumber, - auctionBeginAmount: BigNumber, - auctionEndAmount: BigNumber, - acutionEndTime: BigNumber, - makerAssetData: string, - takerAssetData: string, - makerAddress: string, - takerAddress: string, - takerFillableAmount: BigNumber, - senderAddress?: string, - makerFee?: BigNumber, - takerFee?: BigNumber, - feeRecipientAddress?: string, - ): Promise { - console.log(`asdasd`); - const makerAssetAmount = auctionEndAmount; - const makerAssetDataWithAuctionDetails = DutchAuctionWrapper.encodeDutchAuctionAssetData(makerAssetData, auctionBeginTimeSections, auctionBeginAmount); - const signedOrder = await orderFactory.createSignedOrderAsync( - this._web3Wrapper.getProvider(), - makerAddress, - makerAssetAmount, - makerAssetDataWithAuctionDetails, - takerFillableAmount, - takerAssetData, - this._exchangeAddress, - { - takerAddress, - senderAddress, - makerFee, - takerFee, - feeRecipientAddress, - expirationTimeSeconds: acutionEndTime, - }, - ); - //console.log(signedOrder); - return signedOrder; - } - - public async createSignedBuyOrderAsync(sellOrder: SignedOrder, buyerAddress: string, senderAddress?: string, makerFee?: BigNumber, takerFee?: BigNumber, feeRecipientAddress?: string): Promise { - const signedOrder = await orderFactory.createSignedOrderAsync( - this._web3Wrapper.getProvider(), - buyerAddress, - sellOrder.takerAssetAmount.times(2), // change this to decode value from auction @TODO -- add decode above for this. - sellOrder.takerAssetData, - sellOrder.makerAssetAmount, - sellOrder.makerAssetData, - sellOrder.exchangeAddress, - { - senderAddress, - makerFee, - takerFee, - feeRecipientAddress, - expirationTimeSeconds: sellOrder.expirationTimeSeconds, - }, - ); - // console.log(signedOrder); - return signedOrder; - } /** * Dutch auction details are encoded with the asset data for a 0x order. This function produces a hex * encoded assetData string, containing information both about the asset being traded and the @@ -206,7 +149,6 @@ export class DutchAuctionWrapper extends ContractWrapper { * @return The hex encoded assetData string. */ public static encodeDutchAuctionAssetData(assetData: string, beginTimeSeconds: BigNumber, beginAmount: BigNumber): string { - // console.log(`yoooo`, assetData); const assetDataBuffer = ethUtil.toBuffer(assetData); const abiEncodedAuctionData = (ethAbi as any).rawEncode( ['uint256', 'uint256'], @@ -218,4 +160,28 @@ export class DutchAuctionWrapper extends ContractWrapper { const dutchAuctionData = ethUtil.bufferToHex(dutchAuctionDataBuffer); return dutchAuctionData; }; + /** + * Dutch auction details are encoded with the asset data for a 0x order. This function produces a hex + * encoded assetData string, containing information both about the asset being traded and the + * dutch auction; which is usable in the makerAssetData or takerAssetData fields in a 0x order. + * @param dutchAuctionData Hex encoded assetData string for the asset being auctioned. + * @return + */ + public static decodeDutchAuctionData(dutchAuctionData: string): [AssetData, BigNumber, BigNumber] { + const dutchAuctionDataBuffer = ethUtil.toBuffer(dutchAuctionData); + // Decode asset data + const assetDataBuffer = dutchAuctionDataBuffer.slice(0, dutchAuctionDataBuffer.byteLength - 64); + const assetDataHex = ethUtil.bufferToHex(assetDataBuffer); + const assetData = assetDataUtils.decodeAssetDataOrThrow(assetDataHex); + // Decode auction details + const dutchAuctionDetailsBuffer = dutchAuctionDataBuffer.slice(dutchAuctionDataBuffer.byteLength - 64); + const [beginTimeSecondsAsBN, beginAmountAsBN] = ethAbi.rawDecode( + ['uint256', 'uint256'], + dutchAuctionDetailsBuffer + ); + const beginTimeSeconds = new BigNumber(`0x${beginTimeSecondsAsBN.toString()}`); + const beginAmount = new BigNumber(`0x${beginAmountAsBN.toString()}`); + console.log(beginAmount); + return [assetData, beginTimeSeconds, beginAmount]; + }; } diff --git a/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts b/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts index bfc4e0a58..f548e3ff8 100644 --- a/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts +++ b/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts @@ -1,7 +1,7 @@ import { BlockchainLifecycle } from '@0x/dev-utils'; import { FillScenarios } from '@0x/fill-scenarios'; import { assetDataUtils } from '@0x/order-utils'; -import { SignedOrder } from '@0x/types'; +import { RevertReason, SignedOrder } from '@0x/types'; import { BigNumber } from '@0x/utils'; import * as chai from 'chai'; import 'mocha'; @@ -18,13 +18,19 @@ import { DutchAuction } from '@0x/contract-artifacts'; import { DutchAuctionWrapper } from '../src/contract_wrappers/dutch_auction_wrapper'; import { Web3Wrapper } from '@0x/web3-wrapper'; +import { DutchAuctionUtils } from './utils/dutch_auction_utils'; + +import { + expectTransactionFailedAsync, +} from '@0x/contracts-test-utils'; + chaiSetup.configure(); const expect = chai.expect; const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); // tslint:disable:custom-no-magic-numbers describe.only('DutchAuctionWrapper', () => { - const fillableAmount = Web3Wrapper.toBaseUnitAmount(new BigNumber(50), 18); + const fillableAmount = new BigNumber(2);//Web3Wrapper.toBaseUnitAmount(new BigNumber(50), 18); const tenMinutesInSeconds = 10 * 60; let contractWrappers: ContractWrappers; let fillScenarios: FillScenarios; @@ -33,13 +39,16 @@ describe.only('DutchAuctionWrapper', () => { let userAddresses: string[]; let makerAddress: string; let takerAddress: string; - let buyerAddress: string; let makerTokenAddress: string; let takerTokenAddress: string; let buyOrder: SignedOrder; let sellOrder: SignedOrder; let makerTokenAssetData: string; let takerTokenAssetData: string; + let auctionBeginTimeSeconds: BigNumber; + let auctionBeginAmount: BigNumber; + let auctionEndTimeSeconds: BigNumber; + let auctionEndAmount: BigNumber; before(async () => { console.log(`BEOGIN DEPLOYINH`); const contractAddresses = await migrateOnceAsync(); @@ -63,9 +72,8 @@ describe.only('DutchAuctionWrapper', () => { contractWrappers.erc20Proxy.address, contractWrappers.erc721Proxy.address, ); - [, makerAddress, takerAddress, buyerAddress] = userAddresses; - [makerTokenAddress] = tokenUtils.getDummyERC20TokenAddresses(); - takerTokenAddress = contractWrappers.forwarder.etherTokenAddress; + [, makerAddress, takerAddress] = userAddresses; + [makerTokenAddress, takerTokenAddress] = tokenUtils.getDummyERC20TokenAddresses(); console.log(`B`); // construct asset data for tokens being swapped [makerTokenAssetData, takerTokenAssetData] = [ @@ -74,31 +82,40 @@ describe.only('DutchAuctionWrapper', () => { ]; console.log(`C`); // encode auction details in maker asset data - const auctionBeginAmount = fillableAmount; + auctionEndAmount = fillableAmount; + auctionBeginAmount = auctionEndAmount.times(2); const currentBlockTimestamp = await getLatestBlockTimestampAsync(); - const auctionBeginTimeSeconds = new BigNumber(currentBlockTimestamp - tenMinutesInSeconds); + auctionBeginTimeSeconds = new BigNumber(currentBlockTimestamp - tenMinutesInSeconds); + auctionEndTimeSeconds = new BigNumber(currentBlockTimestamp + tenMinutesInSeconds); /* makerAssetData = DutchAuctionWrapper.encodeDutchAuctionAssetData( makerTokenAssetData, auctionBeginTimeSeconds, auctionBeginAmount );*/ console.log(`C2`); + // Create template orders from + + // create sell / buy orders for auction // note that the maker/taker asset datas are swapped in the `buyOrder` - sellOrder = await contractWrappers.dutchAuction.createSignedSellOrderAsync( + + const coinbase = userAddresses[0]; + const dutchAuctionUtils = new DutchAuctionUtils(web3Wrapper, coinbase, exchangeContractAddress, contractWrappers.erc20Proxy.address); + sellOrder = await dutchAuctionUtils.createSignedSellOrderAsync( auctionBeginTimeSeconds, - fillableAmount.times(2), - fillableAmount, - new BigNumber(currentBlockTimestamp + tenMinutesInSeconds), + auctionBeginAmount, + auctionEndAmount, + auctionEndTimeSeconds, makerTokenAssetData, takerTokenAssetData, makerAddress, constants.NULL_ADDRESS, - fillableAmount, + auctionEndAmount, ); - buyOrder = await contractWrappers.dutchAuction.createSignedBuyOrderAsync( + console.log(`ASDS`); + buyOrder = await dutchAuctionUtils.createSignedBuyOrderAsync( sellOrder, - buyerAddress, + takerAddress, ); console.log(`CD`); }); @@ -113,17 +130,15 @@ describe.only('DutchAuctionWrapper', () => { }); describe('#matchOrdersAsync', () => { it('should match two orders', async () => { - console.log(await contractWrappers.dutchAuction.getAuctionDetailsAsync(sellOrder)); - - // const txHash = await contractWrappers.dutchAuction.matchOrdersAsync(buyOrder, sellOrder, takerAddress, {gasLimit: 1000000}); - //await web3Wrapper.awaitTransactionSuccessAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS); + const txHash = await contractWrappers.dutchAuction.matchOrdersAsync(buyOrder, sellOrder, takerAddress); + await web3Wrapper.awaitTransactionSuccessAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS); }); it('should throw when invalid transaction and shouldValidate is true', async () => { // request match with bad buy/sell orders const badSellOrder = buyOrder; const badBuyOrder = sellOrder; - return expect( - await contractWrappers.dutchAuction.matchOrdersAsync( + return expectTransactionFailedAsync( + contractWrappers.dutchAuction.matchOrdersAsync( badBuyOrder, badSellOrder, takerAddress, @@ -131,32 +146,19 @@ describe.only('DutchAuctionWrapper', () => { shouldValidate: true, }, ), - ).to.be.rejectedWith('COMPLETE_FILL_FAILED'); + RevertReason.InvalidAssetData + ); }); }); describe('#getAuctionDetailsAsync', () => { - /*it('should be worth the begin price at the begining of the auction', async () => { - // setup auction details - const auctionBeginAmount = fillableAmount; - const currentBlockTimestamp = await getLatestBlockTimestampAsync(); - const auctionBeginTimeSeconds = new BigNumber(currentBlockTimestamp + tenMinutesInSeconds); - const makerAssetData = DutchAuctionWrapper.encodeDutchAuctionAssetData( - makerTokenAssetData, - auctionBeginTimeSeconds, - auctionBeginAmount - ); - const order = await fillScenarios.createFillableSignedOrderAsync( - makerAssetData, - takerAssetData, - makerAddress, - constants.NULL_ADDRESS, - fillableAmount, - ); - const auctionDetails = await contractWrappers.dutchAuction.getAuctionDetailsAsync(order); - expect(auctionDetails.currentTimeSeconds).to.be.bignumber.lte(auctionBeginTimeSeconds); - expect(auctionDetails.currentAmount).to.be.bignumber.equal(auctionBeginAmount); - expect(auctionDetails.beginAmount).to.be.bignumber.equal(auctionBeginAmount); - });*/ + it('should be worth the begin price at the begining of the auction', async () => { + // get auction details + const auctionDetails = await contractWrappers.dutchAuction.getAuctionDetailsAsync(sellOrder); + // run some basic sanity checks on the return value + expect(auctionDetails.beginTimeSeconds, 'auctionDetails.beginTimeSeconds').to.be.bignumber.equal(auctionBeginTimeSeconds); + expect(auctionDetails.beginAmount, 'auctionDetails.beginAmount').to.be.bignumber.equal(auctionBeginAmount); + expect(auctionDetails.endTimeSeconds, 'auctionDetails.endTimeSeconds').to.be.bignumber.equal(auctionEndTimeSeconds); + }); }); }); -- cgit v1.2.3 From 0432212a346aa761c54b5a9159a7e61e0c2f9b9a Mon Sep 17 00:00:00 2001 From: Greg Hysen Date: Fri, 21 Dec 2018 16:40:07 -0800 Subject: dutch wrapper tests working --- .../src/contract_wrappers/dutch_auction_wrapper.ts | 24 +++++------- packages/contract-wrappers/src/types.ts | 12 ++++++ .../test/dutch_auction_wrapper_test.ts | 43 +++------------------- 3 files changed, 27 insertions(+), 52 deletions(-) (limited to 'packages/contract-wrappers') 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 5896617fc..dea759962 100644 --- a/packages/contract-wrappers/src/contract_wrappers/dutch_auction_wrapper.ts +++ b/packages/contract-wrappers/src/contract_wrappers/dutch_auction_wrapper.ts @@ -19,9 +19,9 @@ import { orderTxOptsSchema } from '../schemas/order_tx_opts_schema'; import { txOptsSchema } from '../schemas/tx_opts_schema'; import { OrderTransactionOpts } from '../types'; import { ContractWrapper } from './contract_wrapper'; -import { ExchangeWrapperError } from '../types'; +import { DutchAuctionWrapperError, DutchAuctionData } from '../types'; -import { assetDataUtils, AssetData } from '@0x/order-utils'; +import { assetDataUtils } from '@0x/order-utils'; export class DutchAuctionWrapper extends ContractWrapper { public abi: ContractAbi = DutchAuction.compilerOutput.abi; @@ -72,11 +72,7 @@ export class DutchAuctionWrapper extends ContractWrapper { sellOrder.makerAssetData !== buyOrder.takerAssetData || sellOrder.takerAssetData !== buyOrder.makerAssetData ) { - throw new Error(ExchangeWrapperError.AssetDataMismatch); - } else { - // Smart contracts assigns the asset data from the left order to the right one so we can save gas on reducing the size of call data - //rightSignedOrder.makerAssetData = '0x'; - // rightSignedOrder.takerAssetData = '0x'; + throw new Error(DutchAuctionWrapperError.AssetDataMismatch); } // get contract const dutchAuctionInstance = await this._getDutchAuctionContractAsync(); @@ -119,8 +115,6 @@ export class DutchAuctionWrapper extends ContractWrapper { // type assertions assert.doesConformToSchema('sellOrder', sellOrder, schemas.signedOrderSchema); // get contract - console.log(sellOrder); - console.log(await this._getDutchAuctionContractAsync()); const dutchAuctionInstance = await this._getDutchAuctionContractAsync(); // call contract const afterAuctionDetails = await dutchAuctionInstance.getAuctionDetails.callAsync(sellOrder); @@ -156,7 +150,6 @@ export class DutchAuctionWrapper extends ContractWrapper { ); const abiEncodedAuctionDataBuffer = ethUtil.toBuffer(abiEncodedAuctionData); const dutchAuctionDataBuffer = Buffer.concat([assetDataBuffer, abiEncodedAuctionDataBuffer]); - // console.log(`GREFG --- `, abiEncodedAuctionData); const dutchAuctionData = ethUtil.bufferToHex(dutchAuctionDataBuffer); return dutchAuctionData; }; @@ -165,9 +158,9 @@ export class DutchAuctionWrapper extends ContractWrapper { * encoded assetData string, containing information both about the asset being traded and the * dutch auction; which is usable in the makerAssetData or takerAssetData fields in a 0x order. * @param dutchAuctionData Hex encoded assetData string for the asset being auctioned. - * @return + * @return An object containing the auction asset, auction begin time and auction begin amount. */ - public static decodeDutchAuctionData(dutchAuctionData: string): [AssetData, BigNumber, BigNumber] { + public static decodeDutchAuctionData(dutchAuctionData: string): DutchAuctionData { const dutchAuctionDataBuffer = ethUtil.toBuffer(dutchAuctionData); // Decode asset data const assetDataBuffer = dutchAuctionDataBuffer.slice(0, dutchAuctionDataBuffer.byteLength - 64); @@ -181,7 +174,10 @@ export class DutchAuctionWrapper extends ContractWrapper { ); const beginTimeSeconds = new BigNumber(`0x${beginTimeSecondsAsBN.toString()}`); const beginAmount = new BigNumber(`0x${beginAmountAsBN.toString()}`); - console.log(beginAmount); - return [assetData, beginTimeSeconds, beginAmount]; + return { + assetData, + beginTimeSeconds, + beginAmount + }; }; } diff --git a/packages/contract-wrappers/src/types.ts b/packages/contract-wrappers/src/types.ts index 14d4649ae..f23587c20 100644 --- a/packages/contract-wrappers/src/types.ts +++ b/packages/contract-wrappers/src/types.ts @@ -14,6 +14,8 @@ import { BigNumber } from '@0x/utils'; import { BlockParam, ContractEventArg, DecodedLogArgs, LogEntryEvent, LogWithDecodedArgs } from 'ethereum-types'; +import { AssetData } from '@0x/order-utils'; + export enum ExchangeWrapperError { AssetDataMismatch = 'ASSET_DATA_MISMATCH', } @@ -206,3 +208,13 @@ export interface BalanceAndAllowance { balance: BigNumber; allowance: BigNumber; } + +export enum DutchAuctionWrapperError { + AssetDataMismatch = 'ASSET_DATA_MISMATCH', +} + +export interface DutchAuctionData { + assetData: AssetData; + beginTimeSeconds: BigNumber; + beginAmount: BigNumber; +} diff --git a/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts b/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts index f548e3ff8..697554dd1 100644 --- a/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts +++ b/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts @@ -1,12 +1,11 @@ import { BlockchainLifecycle } from '@0x/dev-utils'; -import { FillScenarios } from '@0x/fill-scenarios'; import { assetDataUtils } from '@0x/order-utils'; import { RevertReason, SignedOrder } from '@0x/types'; import { BigNumber } from '@0x/utils'; import * as chai from 'chai'; import 'mocha'; -import { ContractWrappers, OrderStatus } from '../src'; +import { ContractWrappers } from '../src'; import { chaiSetup } from './utils/chai_setup'; import { constants } from './utils/constants'; @@ -14,10 +13,6 @@ import { migrateOnceAsync } from './utils/migrate'; import { tokenUtils } from './utils/token_utils'; import { provider, web3Wrapper } from './utils/web3_wrapper'; import { getLatestBlockTimestampAsync } from '@0x/contracts-test-utils'; -import { DutchAuction } from '@0x/contract-artifacts'; -import { DutchAuctionWrapper } from '../src/contract_wrappers/dutch_auction_wrapper'; -import { Web3Wrapper } from '@0x/web3-wrapper'; - import { DutchAuctionUtils } from './utils/dutch_auction_utils'; import { @@ -33,9 +28,7 @@ describe.only('DutchAuctionWrapper', () => { const fillableAmount = new BigNumber(2);//Web3Wrapper.toBaseUnitAmount(new BigNumber(50), 18); const tenMinutesInSeconds = 10 * 60; let contractWrappers: ContractWrappers; - let fillScenarios: FillScenarios; let exchangeContractAddress: string; - let zrxTokenAddress: string; let userAddresses: string[]; let makerAddress: string; let takerAddress: string; @@ -50,7 +43,7 @@ describe.only('DutchAuctionWrapper', () => { let auctionEndTimeSeconds: BigNumber; let auctionEndAmount: BigNumber; before(async () => { - console.log(`BEOGIN DEPLOYINH`); + // setup contract wrappers & addresses const contractAddresses = await migrateOnceAsync(); await blockchainLifecycle.startAsync(); const config = { @@ -58,47 +51,23 @@ describe.only('DutchAuctionWrapper', () => { contractAddresses, blockPollingIntervalMs: 10, }; - contractWrappers = new ContractWrappers(provider, config); - console.log(`DEPLOYINH`); exchangeContractAddress = contractWrappers.exchange.address; userAddresses = await web3Wrapper.getAvailableAddressesAsync(); - zrxTokenAddress = contractWrappers.exchange.zrxTokenAddress; - fillScenarios = new FillScenarios( - provider, - userAddresses, - zrxTokenAddress, - exchangeContractAddress, - contractWrappers.erc20Proxy.address, - contractWrappers.erc721Proxy.address, - ); [, makerAddress, takerAddress] = userAddresses; [makerTokenAddress, takerTokenAddress] = tokenUtils.getDummyERC20TokenAddresses(); - console.log(`B`); // construct asset data for tokens being swapped [makerTokenAssetData, takerTokenAssetData] = [ assetDataUtils.encodeERC20AssetData(makerTokenAddress), assetDataUtils.encodeERC20AssetData(takerTokenAddress), ]; - console.log(`C`); - // encode auction details in maker asset data + // setup auction details in maker asset data auctionEndAmount = fillableAmount; auctionBeginAmount = auctionEndAmount.times(2); const currentBlockTimestamp = await getLatestBlockTimestampAsync(); auctionBeginTimeSeconds = new BigNumber(currentBlockTimestamp - tenMinutesInSeconds); auctionEndTimeSeconds = new BigNumber(currentBlockTimestamp + tenMinutesInSeconds); - /* makerAssetData = DutchAuctionWrapper.encodeDutchAuctionAssetData( - makerTokenAssetData, - auctionBeginTimeSeconds, - auctionBeginAmount - );*/ - console.log(`C2`); - // Create template orders from - - - // create sell / buy orders for auction - // note that the maker/taker asset datas are swapped in the `buyOrder` - + // create auction orders const coinbase = userAddresses[0]; const dutchAuctionUtils = new DutchAuctionUtils(web3Wrapper, coinbase, exchangeContractAddress, contractWrappers.erc20Proxy.address); sellOrder = await dutchAuctionUtils.createSignedSellOrderAsync( @@ -112,12 +81,10 @@ describe.only('DutchAuctionWrapper', () => { constants.NULL_ADDRESS, auctionEndAmount, ); - console.log(`ASDS`); buyOrder = await dutchAuctionUtils.createSignedBuyOrderAsync( sellOrder, takerAddress, ); - console.log(`CD`); }); after(async () => { await blockchainLifecycle.revertAsync(); @@ -152,7 +119,7 @@ describe.only('DutchAuctionWrapper', () => { }); describe('#getAuctionDetailsAsync', () => { - it('should be worth the begin price at the begining of the auction', async () => { + it('should get auction details', async () => { // get auction details const auctionDetails = await contractWrappers.dutchAuction.getAuctionDetailsAsync(sellOrder); // run some basic sanity checks on the return value -- cgit v1.2.3 From b249a50d8f0054328a901525af6316133ed64023 Mon Sep 17 00:00:00 2001 From: Greg Hysen Date: Fri, 21 Dec 2018 16:40:11 -0800 Subject: ran prettier --- .../src/contract_wrappers/dutch_auction_wrapper.ts | 33 +++++++++--------- .../test/dutch_auction_wrapper_test.ts | 39 +++++++++++----------- 2 files changed, 35 insertions(+), 37 deletions(-) (limited to 'packages/contract-wrappers') 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 dea759962..b7cdff670 100644 --- a/packages/contract-wrappers/src/contract_wrappers/dutch_auction_wrapper.ts +++ b/packages/contract-wrappers/src/contract_wrappers/dutch_auction_wrapper.ts @@ -1,14 +1,10 @@ -import { artifacts as protocolArtifacts } from '@0x/contracts-protocol'; import { DutchAuctionContract } from '@0x/abi-gen-wrappers'; import { DutchAuction } from '@0x/contract-artifacts'; -import { LogDecoder } from '@0x/contracts-test-utils'; -import { artifacts as tokensArtifacts } from '@0x/contracts-tokens'; import { _getDefaultContractAddresses } from '../utils/contract_addresses'; import { DutchAuctionDetails, SignedOrder } from '@0x/types'; import { ContractAbi } from 'ethereum-types'; import { Web3Wrapper } from '@0x/web3-wrapper'; import { BigNumber, abiUtils } from '@0x/utils'; -import { Provider, TransactionReceiptWithDecodedLogs } from 'ethereum-types'; import * as _ from 'lodash'; import ethAbi = require('ethereumjs-abi'); import { schemas } from '@0x/json-schemas'; @@ -35,15 +31,14 @@ export class DutchAuctionWrapper extends ContractWrapper { * @param address The address of the Dutch Auction contract. If undefined, will * default to the known address corresponding to the networkId. */ - constructor( - web3Wrapper: Web3Wrapper, - networkId: number, - address?: string, - exchangeAddress?: string, - ) { + constructor(web3Wrapper: Web3Wrapper, networkId: number, address?: string, exchangeAddress?: string) { super(web3Wrapper, networkId); - this.address = this.address = _.isUndefined(address) ? _getDefaultContractAddresses(networkId).dutchAuction : address; - this._exchangeAddress = _.isUndefined(exchangeAddress) ? _getDefaultContractAddresses(networkId).exchange : exchangeAddress; + this.address = this.address = _.isUndefined(address) + ? _getDefaultContractAddresses(networkId).dutchAuction + : address; + this._exchangeAddress = _.isUndefined(exchangeAddress) + ? _getDefaultContractAddresses(networkId).exchange + : exchangeAddress; } /** * Matches the buy and sell orders at an amount given the following: the current block time, the auction @@ -142,7 +137,11 @@ export class DutchAuctionWrapper extends ContractWrapper { * @param beginAmount Starting amount being sold in the dutch auction. * @return The hex encoded assetData string. */ - public static encodeDutchAuctionAssetData(assetData: string, beginTimeSeconds: BigNumber, beginAmount: BigNumber): string { + public static encodeDutchAuctionAssetData( + assetData: string, + beginTimeSeconds: BigNumber, + beginAmount: BigNumber, + ): string { const assetDataBuffer = ethUtil.toBuffer(assetData); const abiEncodedAuctionData = (ethAbi as any).rawEncode( ['uint256', 'uint256'], @@ -152,7 +151,7 @@ export class DutchAuctionWrapper extends ContractWrapper { const dutchAuctionDataBuffer = Buffer.concat([assetDataBuffer, abiEncodedAuctionDataBuffer]); const dutchAuctionData = ethUtil.bufferToHex(dutchAuctionDataBuffer); return dutchAuctionData; - }; + } /** * Dutch auction details are encoded with the asset data for a 0x order. This function produces a hex * encoded assetData string, containing information both about the asset being traded and the @@ -170,14 +169,14 @@ export class DutchAuctionWrapper extends ContractWrapper { const dutchAuctionDetailsBuffer = dutchAuctionDataBuffer.slice(dutchAuctionDataBuffer.byteLength - 64); const [beginTimeSecondsAsBN, beginAmountAsBN] = ethAbi.rawDecode( ['uint256', 'uint256'], - dutchAuctionDetailsBuffer + dutchAuctionDetailsBuffer, ); const beginTimeSeconds = new BigNumber(`0x${beginTimeSecondsAsBN.toString()}`); const beginAmount = new BigNumber(`0x${beginAmountAsBN.toString()}`); return { assetData, beginTimeSeconds, - beginAmount + beginAmount, }; - }; + } } diff --git a/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts b/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts index 697554dd1..fa5ef41fd 100644 --- a/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts +++ b/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts @@ -15,9 +15,7 @@ import { provider, web3Wrapper } from './utils/web3_wrapper'; import { getLatestBlockTimestampAsync } from '@0x/contracts-test-utils'; import { DutchAuctionUtils } from './utils/dutch_auction_utils'; -import { - expectTransactionFailedAsync, -} from '@0x/contracts-test-utils'; +import { expectTransactionFailedAsync } from '@0x/contracts-test-utils'; chaiSetup.configure(); const expect = chai.expect; @@ -25,7 +23,7 @@ const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); // tslint:disable:custom-no-magic-numbers describe.only('DutchAuctionWrapper', () => { - const fillableAmount = new BigNumber(2);//Web3Wrapper.toBaseUnitAmount(new BigNumber(50), 18); + const fillableAmount = new BigNumber(2); //Web3Wrapper.toBaseUnitAmount(new BigNumber(50), 18); const tenMinutesInSeconds = 10 * 60; let contractWrappers: ContractWrappers; let exchangeContractAddress: string; @@ -69,7 +67,12 @@ describe.only('DutchAuctionWrapper', () => { auctionEndTimeSeconds = new BigNumber(currentBlockTimestamp + tenMinutesInSeconds); // create auction orders const coinbase = userAddresses[0]; - const dutchAuctionUtils = new DutchAuctionUtils(web3Wrapper, coinbase, exchangeContractAddress, contractWrappers.erc20Proxy.address); + const dutchAuctionUtils = new DutchAuctionUtils( + web3Wrapper, + coinbase, + exchangeContractAddress, + contractWrappers.erc20Proxy.address, + ); sellOrder = await dutchAuctionUtils.createSignedSellOrderAsync( auctionBeginTimeSeconds, auctionBeginAmount, @@ -81,10 +84,7 @@ describe.only('DutchAuctionWrapper', () => { constants.NULL_ADDRESS, auctionEndAmount, ); - buyOrder = await dutchAuctionUtils.createSignedBuyOrderAsync( - sellOrder, - takerAddress, - ); + buyOrder = await dutchAuctionUtils.createSignedBuyOrderAsync(sellOrder, takerAddress); }); after(async () => { await blockchainLifecycle.revertAsync(); @@ -105,15 +105,10 @@ describe.only('DutchAuctionWrapper', () => { const badSellOrder = buyOrder; const badBuyOrder = sellOrder; return expectTransactionFailedAsync( - contractWrappers.dutchAuction.matchOrdersAsync( - badBuyOrder, - badSellOrder, - takerAddress, - { - shouldValidate: true, - }, - ), - RevertReason.InvalidAssetData + contractWrappers.dutchAuction.matchOrdersAsync(badBuyOrder, badSellOrder, takerAddress, { + shouldValidate: true, + }), + RevertReason.InvalidAssetData, ); }); }); @@ -123,9 +118,13 @@ describe.only('DutchAuctionWrapper', () => { // get auction details const auctionDetails = await contractWrappers.dutchAuction.getAuctionDetailsAsync(sellOrder); // run some basic sanity checks on the return value - expect(auctionDetails.beginTimeSeconds, 'auctionDetails.beginTimeSeconds').to.be.bignumber.equal(auctionBeginTimeSeconds); + expect(auctionDetails.beginTimeSeconds, 'auctionDetails.beginTimeSeconds').to.be.bignumber.equal( + auctionBeginTimeSeconds, + ); expect(auctionDetails.beginAmount, 'auctionDetails.beginAmount').to.be.bignumber.equal(auctionBeginAmount); - expect(auctionDetails.endTimeSeconds, 'auctionDetails.endTimeSeconds').to.be.bignumber.equal(auctionEndTimeSeconds); + expect(auctionDetails.endTimeSeconds, 'auctionDetails.endTimeSeconds').to.be.bignumber.equal( + auctionEndTimeSeconds, + ); }); }); }); -- cgit v1.2.3 From cb1bfa0f9790706bf9ce08aad0bf8fd9e2621ce9 Mon Sep 17 00:00:00 2001 From: Greg Hysen Date: Fri, 21 Dec 2018 17:04:17 -0800 Subject: ran prettier + added changelog entry for contract wrappers --- packages/contract-wrappers/CHANGELOG.json | 10 ++++++++++ .../src/contract_wrappers/dutch_auction_wrapper.ts | 8 ++------ 2 files changed, 12 insertions(+), 6 deletions(-) (limited to 'packages/contract-wrappers') diff --git a/packages/contract-wrappers/CHANGELOG.json b/packages/contract-wrappers/CHANGELOG.json index 581fbdee1..dadba6190 100644 --- a/packages/contract-wrappers/CHANGELOG.json +++ b/packages/contract-wrappers/CHANGELOG.json @@ -1,6 +1,16 @@ [ { "version": "4.2.0", + "changes": [ + { + "note": + "Added Dutch Auction wrapper", + "pr": 1465 + } + ] + }, + { + "version": "4.1.4", "changes": [ { "note": "Add support for Trust Wallet signature denial error" 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 b7cdff670..bb1e89555 100644 --- a/packages/contract-wrappers/src/contract_wrappers/dutch_auction_wrapper.ts +++ b/packages/contract-wrappers/src/contract_wrappers/dutch_auction_wrapper.ts @@ -4,7 +4,7 @@ import { _getDefaultContractAddresses } from '../utils/contract_addresses'; import { DutchAuctionDetails, SignedOrder } from '@0x/types'; import { ContractAbi } from 'ethereum-types'; import { Web3Wrapper } from '@0x/web3-wrapper'; -import { BigNumber, abiUtils } from '@0x/utils'; +import { BigNumber } from '@0x/utils'; import * as _ from 'lodash'; import ethAbi = require('ethereumjs-abi'); import { schemas } from '@0x/json-schemas'; @@ -22,7 +22,6 @@ import { assetDataUtils } from '@0x/order-utils'; export class DutchAuctionWrapper extends ContractWrapper { public abi: ContractAbi = DutchAuction.compilerOutput.abi; public address: string; - private _exchangeAddress: string; private _dutchAuctionContractIfExists?: DutchAuctionContract; /** * Instantiate DutchAuctionWrapper @@ -31,14 +30,11 @@ export class DutchAuctionWrapper extends ContractWrapper { * @param address The address of the Dutch Auction contract. If undefined, will * default to the known address corresponding to the networkId. */ - constructor(web3Wrapper: Web3Wrapper, networkId: number, address?: string, exchangeAddress?: string) { + constructor(web3Wrapper: Web3Wrapper, networkId: number, address?: string) { super(web3Wrapper, networkId); this.address = this.address = _.isUndefined(address) ? _getDefaultContractAddresses(networkId).dutchAuction : address; - this._exchangeAddress = _.isUndefined(exchangeAddress) - ? _getDefaultContractAddresses(networkId).exchange - : exchangeAddress; } /** * Matches the buy and sell orders at an amount given the following: the current block time, the auction -- cgit v1.2.3 From 06139cbfe59a1a00524de097b7e7fe5364c8d1c0 Mon Sep 17 00:00:00 2001 From: Greg Hysen Date: Fri, 21 Dec 2018 17:05:47 -0800 Subject: Added dutch auction utils to contract-wrappers --- .../test/utils/dutch_auction_utils.ts | 144 +++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 packages/contract-wrappers/test/utils/dutch_auction_utils.ts (limited to 'packages/contract-wrappers') diff --git a/packages/contract-wrappers/test/utils/dutch_auction_utils.ts b/packages/contract-wrappers/test/utils/dutch_auction_utils.ts new file mode 100644 index 000000000..9cff1930d --- /dev/null +++ b/packages/contract-wrappers/test/utils/dutch_auction_utils.ts @@ -0,0 +1,144 @@ +import { DummyERC20TokenContract, DummyERC721TokenContract, ExchangeContract } from '@0x/abi-gen-wrappers'; +import { SignedOrder } from '@0x/types'; +import * as artifacts from '@0x/contract-artifacts'; +import { BigNumber } from '@0x/utils'; +import { Web3Wrapper } from '@0x/web3-wrapper'; +import { orderFactory } from '@0x/order-utils/lib/src/order_factory'; + +import { DutchAuctionWrapper } from '../../src/contract_wrappers/dutch_auction_wrapper'; +import { constants } from './constants'; +import { assetDataUtils } from '@0x/order-utils'; + +export class DutchAuctionUtils { + private _web3Wrapper: Web3Wrapper; + private _coinbase: string; + private _exchangeAddress: string; + private _erc20ProxyAddress: string; + + constructor(web3Wrapper: Web3Wrapper, coinbase: string, exchangeAddress: string, erc20ProxyAddress: string) { + this._web3Wrapper = web3Wrapper; + this._coinbase = coinbase; + this._exchangeAddress = exchangeAddress; + this._erc20ProxyAddress = erc20ProxyAddress; + } + public async createSignedSellOrderAsync( + auctionBeginTimeSections: BigNumber, + auctionBeginAmount: BigNumber, + auctionEndAmount: BigNumber, + acutionEndTime: BigNumber, + makerAssetData: string, + takerAssetData: string, + makerAddress: string, + takerAddress: string, + takerFillableAmount: BigNumber, + senderAddress?: string, + makerFee?: BigNumber, + takerFee?: BigNumber, + feeRecipientAddress?: string, + ): Promise { + console.log(`asdasd`); + const makerAssetAmount = auctionEndAmount; + const makerAssetDataWithAuctionDetails = DutchAuctionWrapper.encodeDutchAuctionAssetData( + makerAssetData, + auctionBeginTimeSections, + auctionBeginAmount, + ); + const signedOrder = await orderFactory.createSignedOrderAsync( + this._web3Wrapper.getProvider(), + makerAddress, + makerAssetAmount, + makerAssetDataWithAuctionDetails, + takerFillableAmount, + takerAssetData, + this._exchangeAddress, + { + takerAddress, + senderAddress, + makerFee, + takerFee, + feeRecipientAddress, + expirationTimeSeconds: acutionEndTime, + }, + ); + const erc20AssetData = assetDataUtils.decodeERC20AssetData(makerAssetData); + await this._increaseERC20BalanceAndAllowanceAsync(erc20AssetData.tokenAddress, makerAddress, makerAssetAmount); + return signedOrder; + } + public async createSignedBuyOrderAsync( + sellOrder: SignedOrder, + buyerAddress: string, + senderAddress?: string, + makerFee?: BigNumber, + takerFee?: BigNumber, + feeRecipientAddress?: string, + ): Promise { + const dutchAuctionData = DutchAuctionWrapper.decodeDutchAuctionData(sellOrder.makerAssetData); + const signedOrder = await orderFactory.createSignedOrderAsync( + this._web3Wrapper.getProvider(), + buyerAddress, + dutchAuctionData.beginAmount, + sellOrder.takerAssetData, + sellOrder.makerAssetAmount, + sellOrder.makerAssetData, + sellOrder.exchangeAddress, + { + senderAddress, + makerFee, + takerFee, + feeRecipientAddress, + expirationTimeSeconds: sellOrder.expirationTimeSeconds, + }, + ); + const buyerERC20AssetData = assetDataUtils.decodeERC20AssetData(sellOrder.takerAssetData); + await this._increaseERC20BalanceAndAllowanceAsync( + buyerERC20AssetData.tokenAddress, + buyerAddress, + dutchAuctionData.beginAmount, + ); + return signedOrder; + } + private async _increaseERC20BalanceAndAllowanceAsync( + tokenAddress: string, + address: string, + amount: BigNumber, + ): Promise { + if (amount.isZero() || address === constants.NULL_ADDRESS) { + return; // noop + } + await Promise.all([ + this._increaseERC20BalanceAsync(tokenAddress, address, amount), + this._increaseERC20AllowanceAsync(tokenAddress, address, amount), + ]); + } + private async _increaseERC20BalanceAsync(tokenAddress: string, address: string, amount: BigNumber): Promise { + const erc20Token = new DummyERC20TokenContract( + artifacts.DummyERC20Token.compilerOutput.abi, + tokenAddress, + this._web3Wrapper.getProvider(), + this._web3Wrapper.getContractDefaults(), + ); + const txHash = await erc20Token.transfer.sendTransactionAsync(address, amount, { + from: this._coinbase, + }); + await this._web3Wrapper.awaitTransactionSuccessAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS); + } + private async _increaseERC20AllowanceAsync( + tokenAddress: string, + address: string, + amount: BigNumber, + ): Promise { + const erc20Token = new DummyERC20TokenContract( + artifacts.DummyERC20Token.compilerOutput.abi, + tokenAddress, + this._web3Wrapper.getProvider(), + this._web3Wrapper.getContractDefaults(), + ); + const oldMakerAllowance = await erc20Token.allowance.callAsync(address, this._erc20ProxyAddress); + const newMakerAllowance = oldMakerAllowance.plus(amount); + + const txHash = await erc20Token.approve.sendTransactionAsync(this._erc20ProxyAddress, newMakerAllowance, { + from: address, + }); + await this._web3Wrapper.awaitTransactionSuccessAsync(txHash, constants.AWAIT_TRANSACTION_MINED_MS); + } +} -- cgit v1.2.3 From 6de3a33f365bc73d9c592e96b0d17c7940297613 Mon Sep 17 00:00:00 2001 From: Greg Hysen Date: Fri, 21 Dec 2018 17:15:43 -0800 Subject: updated relevant changelogs --- packages/contract-wrappers/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/contract-wrappers') diff --git a/packages/contract-wrappers/package.json b/packages/contract-wrappers/package.json index f3f7301fd..c6921d70b 100644 --- a/packages/contract-wrappers/package.json +++ b/packages/contract-wrappers/package.json @@ -1,6 +1,6 @@ { "name": "@0x/contract-wrappers", - "version": "4.1.3", + "version": "4.2.0", "description": "Smart TS wrappers for 0x smart contracts", "keywords": [ "0xproject", -- cgit v1.2.3 From bbd48283407540b630a42f7155e97adc4b825e1b Mon Sep 17 00:00:00 2001 From: Greg Hysen Date: Fri, 21 Dec 2018 17:21:14 -0800 Subject: removed .only --- packages/contract-wrappers/test/dutch_auction_wrapper_test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/contract-wrappers') diff --git a/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts b/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts index fa5ef41fd..16d370cb6 100644 --- a/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts +++ b/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts @@ -22,7 +22,7 @@ const expect = chai.expect; const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); // tslint:disable:custom-no-magic-numbers -describe.only('DutchAuctionWrapper', () => { +describe('DutchAuctionWrapper', () => { const fillableAmount = new BigNumber(2); //Web3Wrapper.toBaseUnitAmount(new BigNumber(50), 18); const tenMinutesInSeconds = 10 * 60; let contractWrappers: ContractWrappers; -- cgit v1.2.3 From 0893614859c9f8c20c295aad162c2e0b7853c415 Mon Sep 17 00:00:00 2001 From: Greg Hysen Date: Fri, 21 Dec 2018 17:33:16 -0800 Subject: removed needless newline on contract-wrappers changelog --- packages/contract-wrappers/CHANGELOG.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'packages/contract-wrappers') diff --git a/packages/contract-wrappers/CHANGELOG.json b/packages/contract-wrappers/CHANGELOG.json index dadba6190..c01e35dcf 100644 --- a/packages/contract-wrappers/CHANGELOG.json +++ b/packages/contract-wrappers/CHANGELOG.json @@ -3,8 +3,7 @@ "version": "4.2.0", "changes": [ { - "note": - "Added Dutch Auction wrapper", + "note": "Added Dutch Auction wrapper", "pr": 1465 } ] -- cgit v1.2.3 From d6467d707fdc1797eba4a445e805ccadc1f47872 Mon Sep 17 00:00:00 2001 From: Greg Hysen Date: Fri, 21 Dec 2018 22:23:21 -0800 Subject: Removed redundant assignment --- .../contract-wrappers/src/contract_wrappers/dutch_auction_wrapper.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/contract-wrappers') 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 bb1e89555..f243d55d9 100644 --- a/packages/contract-wrappers/src/contract_wrappers/dutch_auction_wrapper.ts +++ b/packages/contract-wrappers/src/contract_wrappers/dutch_auction_wrapper.ts @@ -32,7 +32,7 @@ export class DutchAuctionWrapper extends ContractWrapper { */ constructor(web3Wrapper: Web3Wrapper, networkId: number, address?: string) { super(web3Wrapper, networkId); - this.address = this.address = _.isUndefined(address) + this.address = _.isUndefined(address) ? _getDefaultContractAddresses(networkId).dutchAuction : address; } -- cgit v1.2.3 From c6ab380685098dbf3a0a6ee5fae137e816839c2d Mon Sep 17 00:00:00 2001 From: Greg Hysen Date: Sat, 22 Dec 2018 12:56:52 -0800 Subject: Ran prettier & linter --- packages/contract-wrappers/CHANGELOG.json | 2 +- packages/contract-wrappers/package.json | 2 + .../contract-wrappers/src/contract_wrappers.ts | 2 +- .../src/contract_wrappers/dutch_auction_wrapper.ts | 135 +++++++++++---------- .../test/dutch_auction_wrapper_test.ts | 10 +- .../test/utils/dutch_auction_utils.ts | 18 +-- 6 files changed, 86 insertions(+), 83 deletions(-) (limited to 'packages/contract-wrappers') diff --git a/packages/contract-wrappers/CHANGELOG.json b/packages/contract-wrappers/CHANGELOG.json index c01e35dcf..677292030 100644 --- a/packages/contract-wrappers/CHANGELOG.json +++ b/packages/contract-wrappers/CHANGELOG.json @@ -4,7 +4,7 @@ "changes": [ { "note": "Added Dutch Auction wrapper", - "pr": 1465 + "pr": 1465 } ] }, diff --git a/packages/contract-wrappers/package.json b/packages/contract-wrappers/package.json index c6921d70b..222cfa622 100644 --- a/packages/contract-wrappers/package.json +++ b/packages/contract-wrappers/package.json @@ -69,6 +69,7 @@ "@0x/assert": "^1.0.20", "@0x/contract-addresses": "^2.0.0", "@0x/contract-artifacts": "^1.1.2", + "@0x/contracts-test-utils": "^1.0.2", "@0x/fill-scenarios": "^1.0.16", "@0x/json-schemas": "^2.1.4", "@0x/order-utils": "^3.0.7", @@ -76,6 +77,7 @@ "@0x/typescript-typings": "^3.0.6", "@0x/utils": "^2.0.8", "@0x/web3-wrapper": "^3.2.1", + "ethereumjs-abi": "0.6.5", "ethereum-types": "^1.1.4", "ethereumjs-blockstream": "6.0.0", "ethereumjs-util": "^5.1.1", diff --git a/packages/contract-wrappers/src/contract_wrappers.ts b/packages/contract-wrappers/src/contract_wrappers.ts index 3728d58d3..4e594593e 100644 --- a/packages/contract-wrappers/src/contract_wrappers.ts +++ b/packages/contract-wrappers/src/contract_wrappers.ts @@ -12,6 +12,7 @@ import { Web3Wrapper } from '@0x/web3-wrapper'; import { Provider } from 'ethereum-types'; import * as _ from 'lodash'; +import { DutchAuctionWrapper } from './contract_wrappers/dutch_auction_wrapper'; import { ERC20ProxyWrapper } from './contract_wrappers/erc20_proxy_wrapper'; import { ERC20TokenWrapper } from './contract_wrappers/erc20_token_wrapper'; import { ERC721ProxyWrapper } from './contract_wrappers/erc721_proxy_wrapper'; @@ -20,7 +21,6 @@ import { EtherTokenWrapper } from './contract_wrappers/ether_token_wrapper'; import { ExchangeWrapper } from './contract_wrappers/exchange_wrapper'; import { ForwarderWrapper } from './contract_wrappers/forwarder_wrapper'; import { OrderValidatorWrapper } from './contract_wrappers/order_validator_wrapper'; -import { DutchAuctionWrapper } from './contract_wrappers/dutch_auction_wrapper'; import { ContractWrappersConfigSchema } from './schemas/contract_wrappers_config_schema'; import { ContractWrappersConfig } from './types'; import { assert } from './utils/assert'; 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 f243d55d9..cb0c10187 100644 --- a/packages/contract-wrappers/src/contract_wrappers/dutch_auction_wrapper.ts +++ b/packages/contract-wrappers/src/contract_wrappers/dutch_auction_wrapper.ts @@ -1,28 +1,84 @@ import { DutchAuctionContract } from '@0x/abi-gen-wrappers'; import { DutchAuction } from '@0x/contract-artifacts'; -import { _getDefaultContractAddresses } from '../utils/contract_addresses'; +import { schemas } from '@0x/json-schemas'; +import { assetDataUtils } from '@0x/order-utils'; import { DutchAuctionDetails, SignedOrder } from '@0x/types'; -import { ContractAbi } from 'ethereum-types'; -import { Web3Wrapper } from '@0x/web3-wrapper'; 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 ethAbi = require('ethereumjs-abi'); -import { schemas } from '@0x/json-schemas'; -import { assert } from '../utils/assert'; -import ethUtil = require('ethereumjs-util'); import { orderTxOptsSchema } from '../schemas/order_tx_opts_schema'; import { txOptsSchema } from '../schemas/tx_opts_schema'; -import { OrderTransactionOpts } from '../types'; -import { ContractWrapper } from './contract_wrapper'; -import { DutchAuctionWrapperError, DutchAuctionData } from '../types'; +import { DutchAuctionData, DutchAuctionWrapperError, OrderTransactionOpts } from '../types'; +import { assert } from '../utils/assert'; +import { _getDefaultContractAddresses } from '../utils/contract_addresses'; -import { assetDataUtils } from '@0x/order-utils'; +import { ContractWrapper } from './contract_wrapper'; export class DutchAuctionWrapper extends ContractWrapper { public abi: ContractAbi = DutchAuction.compilerOutput.abi; public address: string; private _dutchAuctionContractIfExists?: DutchAuctionContract; + /** + * Dutch auction details are encoded with the asset data for a 0x order. This function produces a hex + * encoded assetData string, containing information both about the asset being traded and the + * dutch auction; which is usable in the makerAssetData or takerAssetData fields in a 0x order. + * @param assetData Hex encoded assetData string for the asset being auctioned. + * @param beginTimeSeconds Begin time of the dutch auction. + * @param beginAmount Starting amount being sold in the dutch auction. + * @return The hex encoded assetData string. + */ + public static encodeDutchAuctionAssetData( + assetData: string, + 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); + return dutchAuctionData; + } + /** + * Dutch auction details are encoded with the asset data for a 0x order. This function produces a hex + * encoded assetData string, containing information both about the asset being traded and the + * dutch auction; which is usable in the makerAssetData or takerAssetData fields in a 0x order. + * @param dutchAuctionData Hex encoded assetData string for the asset being auctioned. + * @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(`0x${beginTimeSecondsAsBN.toString()}`); + const beginAmount = new BigNumber(`0x${beginAmountAsBN.toString()}`); + return { + assetData, + beginTimeSeconds, + beginAmount, + }; + } /** * Instantiate DutchAuctionWrapper * @param web3Wrapper Web3Wrapper instance to use. @@ -30,11 +86,9 @@ export class DutchAuctionWrapper extends ContractWrapper { * @param address The address of the Dutch Auction contract. If undefined, will * default to the known address corresponding to the networkId. */ - constructor(web3Wrapper: Web3Wrapper, networkId: number, address?: string) { + public constructor(web3Wrapper: Web3Wrapper, networkId: number, address?: string) { super(web3Wrapper, networkId); - this.address = _.isUndefined(address) - ? _getDefaultContractAddresses(networkId).dutchAuction - : address; + this.address = _.isUndefined(address) ? _getDefaultContractAddresses(networkId).dutchAuction : address; } /** * Matches the buy and sell orders at an amount given the following: the current block time, the auction @@ -124,55 +178,4 @@ export class DutchAuctionWrapper extends ContractWrapper { this._dutchAuctionContractIfExists = contractInstance; return this._dutchAuctionContractIfExists; } - /** - * Dutch auction details are encoded with the asset data for a 0x order. This function produces a hex - * encoded assetData string, containing information both about the asset being traded and the - * dutch auction; which is usable in the makerAssetData or takerAssetData fields in a 0x order. - * @param assetData Hex encoded assetData string for the asset being auctioned. - * @param beginTimeSeconds Begin time of the dutch auction. - * @param beginAmount Starting amount being sold in the dutch auction. - * @return The hex encoded assetData string. - */ - public static encodeDutchAuctionAssetData( - assetData: string, - 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); - return dutchAuctionData; - } - /** - * Dutch auction details are encoded with the asset data for a 0x order. This function produces a hex - * encoded assetData string, containing information both about the asset being traded and the - * dutch auction; which is usable in the makerAssetData or takerAssetData fields in a 0x order. - * @param dutchAuctionData Hex encoded assetData string for the asset being auctioned. - * @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 assetDataBuffer = dutchAuctionDataBuffer.slice(0, dutchAuctionDataBuffer.byteLength - 64); - const assetDataHex = ethUtil.bufferToHex(assetDataBuffer); - const assetData = assetDataUtils.decodeAssetDataOrThrow(assetDataHex); - // Decode auction details - const dutchAuctionDetailsBuffer = dutchAuctionDataBuffer.slice(dutchAuctionDataBuffer.byteLength - 64); - const [beginTimeSecondsAsBN, beginAmountAsBN] = ethAbi.rawDecode( - ['uint256', 'uint256'], - dutchAuctionDetailsBuffer, - ); - const beginTimeSeconds = new BigNumber(`0x${beginTimeSecondsAsBN.toString()}`); - const beginAmount = new BigNumber(`0x${beginAmountAsBN.toString()}`); - return { - assetData, - beginTimeSeconds, - beginAmount, - }; - } } diff --git a/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts b/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts index 16d370cb6..4e6ad44e9 100644 --- a/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts +++ b/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts @@ -1,3 +1,4 @@ +import { expectTransactionFailedAsync, getLatestBlockTimestampAsync } from '@0x/contracts-test-utils'; import { BlockchainLifecycle } from '@0x/dev-utils'; import { assetDataUtils } from '@0x/order-utils'; import { RevertReason, SignedOrder } from '@0x/types'; @@ -9,13 +10,10 @@ import { ContractWrappers } from '../src'; import { chaiSetup } from './utils/chai_setup'; import { constants } from './utils/constants'; +import { DutchAuctionUtils } from './utils/dutch_auction_utils'; import { migrateOnceAsync } from './utils/migrate'; import { tokenUtils } from './utils/token_utils'; import { provider, web3Wrapper } from './utils/web3_wrapper'; -import { getLatestBlockTimestampAsync } from '@0x/contracts-test-utils'; -import { DutchAuctionUtils } from './utils/dutch_auction_utils'; - -import { expectTransactionFailedAsync } from '@0x/contracts-test-utils'; chaiSetup.configure(); const expect = chai.expect; @@ -23,7 +21,7 @@ const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); // tslint:disable:custom-no-magic-numbers describe('DutchAuctionWrapper', () => { - const fillableAmount = new BigNumber(2); //Web3Wrapper.toBaseUnitAmount(new BigNumber(50), 18); + const fillableAmount = new BigNumber(2); const tenMinutesInSeconds = 10 * 60; let contractWrappers: ContractWrappers; let exchangeContractAddress: string; @@ -62,7 +60,7 @@ describe('DutchAuctionWrapper', () => { // setup auction details in maker asset data auctionEndAmount = fillableAmount; auctionBeginAmount = auctionEndAmount.times(2); - const currentBlockTimestamp = await getLatestBlockTimestampAsync(); + const currentBlockTimestamp: number = await getLatestBlockTimestampAsync(); auctionBeginTimeSeconds = new BigNumber(currentBlockTimestamp - tenMinutesInSeconds); auctionEndTimeSeconds = new BigNumber(currentBlockTimestamp + tenMinutesInSeconds); // create auction orders diff --git a/packages/contract-wrappers/test/utils/dutch_auction_utils.ts b/packages/contract-wrappers/test/utils/dutch_auction_utils.ts index 9cff1930d..766fc373a 100644 --- a/packages/contract-wrappers/test/utils/dutch_auction_utils.ts +++ b/packages/contract-wrappers/test/utils/dutch_auction_utils.ts @@ -1,19 +1,20 @@ -import { DummyERC20TokenContract, DummyERC721TokenContract, ExchangeContract } from '@0x/abi-gen-wrappers'; -import { SignedOrder } from '@0x/types'; +import { DummyERC20TokenContract } from '@0x/abi-gen-wrappers'; import * as artifacts from '@0x/contract-artifacts'; +import { assetDataUtils } from '@0x/order-utils'; +import { orderFactory } from '@0x/order-utils/lib/src/order_factory'; +import { SignedOrder } from '@0x/types'; import { BigNumber } from '@0x/utils'; import { Web3Wrapper } from '@0x/web3-wrapper'; -import { orderFactory } from '@0x/order-utils/lib/src/order_factory'; import { DutchAuctionWrapper } from '../../src/contract_wrappers/dutch_auction_wrapper'; + import { constants } from './constants'; -import { assetDataUtils } from '@0x/order-utils'; export class DutchAuctionUtils { - private _web3Wrapper: Web3Wrapper; - private _coinbase: string; - private _exchangeAddress: string; - private _erc20ProxyAddress: string; + private readonly _web3Wrapper: Web3Wrapper; + private readonly _coinbase: string; + private readonly _exchangeAddress: string; + private readonly _erc20ProxyAddress: string; constructor(web3Wrapper: Web3Wrapper, coinbase: string, exchangeAddress: string, erc20ProxyAddress: string) { this._web3Wrapper = web3Wrapper; @@ -36,7 +37,6 @@ export class DutchAuctionUtils { takerFee?: BigNumber, feeRecipientAddress?: string, ): Promise { - console.log(`asdasd`); const makerAssetAmount = auctionEndAmount; const makerAssetDataWithAuctionDetails = DutchAuctionWrapper.encodeDutchAuctionAssetData( makerAssetData, -- cgit v1.2.3 From 61a33688264d31be063cd11260d9f37f3774975b Mon Sep 17 00:00:00 2001 From: Greg Hysen Date: Sat, 22 Dec 2018 13:11:14 -0800 Subject: `afterAuctionDetails` -> `auctionDetails` --- .../contract-wrappers/src/contract_wrappers/dutch_auction_wrapper.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'packages/contract-wrappers') 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 cb0c10187..f9eb3c771 100644 --- a/packages/contract-wrappers/src/contract_wrappers/dutch_auction_wrapper.ts +++ b/packages/contract-wrappers/src/contract_wrappers/dutch_auction_wrapper.ts @@ -162,8 +162,8 @@ export class DutchAuctionWrapper extends ContractWrapper { // get contract const dutchAuctionInstance = await this._getDutchAuctionContractAsync(); // call contract - const afterAuctionDetails = await dutchAuctionInstance.getAuctionDetails.callAsync(sellOrder); - return afterAuctionDetails; + const auctionDetails = await dutchAuctionInstance.getAuctionDetails.callAsync(sellOrder); + return auctionDetails; } private async _getDutchAuctionContractAsync(): Promise { if (!_.isUndefined(this._dutchAuctionContractIfExists)) { -- cgit v1.2.3 From 77a2ca1ddc9a7dd444822ca3cb38b3679dbd4085 Mon Sep 17 00:00:00 2001 From: Greg Hysen Date: Sat, 22 Dec 2018 13:54:57 -0800 Subject: Minor documentation updates to dutch auction wrapper --- .../src/contract_wrappers/dutch_auction_wrapper.ts | 15 +++++------ .../test/dutch_auction_wrapper_test.ts | 16 ++++++------ .../test/utils/dutch_auction_utils.ts | 29 ++++++++++++++-------- 3 files changed, 34 insertions(+), 26 deletions(-) (limited to 'packages/contract-wrappers') 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 f9eb3c771..c1aceff47 100644 --- a/packages/contract-wrappers/src/contract_wrappers/dutch_auction_wrapper.ts +++ b/packages/contract-wrappers/src/contract_wrappers/dutch_auction_wrapper.ts @@ -47,9 +47,9 @@ export class DutchAuctionWrapper extends ContractWrapper { return dutchAuctionData; } /** - * Dutch auction details are encoded with the asset data for a 0x order. This function produces a hex + * Dutch auction details are encoded with the asset data for a 0x order. This function decodes a hex * encoded assetData string, containing information both about the asset being traded and the - * dutch auction; which is usable in the makerAssetData or takerAssetData fields in a 0x order. + * dutch auction. * @param dutchAuctionData Hex encoded assetData string for the asset being auctioned. * @return An object containing the auction asset, auction begin time and auction begin amount. */ @@ -95,10 +95,11 @@ export class DutchAuctionWrapper extends ContractWrapper { * start time and the auction begin amount. The sell order is a an order at the lowest amount * at the end of the auction. Excess from the match is transferred to the seller. * Over time the price moves from beginAmount to endAmount given the current block.timestamp. - * @param buyOrder The Buyer's order. This order is for the current expected price of the auction. - * @param sellOrder The Seller's order. This order is for the lowest amount (at the end of the auction). - * @param from Address the transaction is being sent from. - * @return Transaction receipt with decoded logs. + * @param buyOrder The Buyer's order. This order is for the current expected price of the auction. + * @param sellOrder The Seller's order. This order is for the lowest amount (at the end of the auction). + * @param takerAddress The user Ethereum address who would like to fill this order. Must be available via the supplied + * Provider provided at instantiation. + * @return Transaction hash. */ public async matchOrdersAsync( buyOrder: SignedOrder, @@ -152,7 +153,7 @@ export class DutchAuctionWrapper extends ContractWrapper { return txHash; } /** - * Calculates the Auction Details for the given order + * Fetches the Auction Details for the given order * @param sellOrder The Seller's order. This order is for the lowest amount (at the end of the auction). * @return The dutch auction details. */ diff --git a/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts b/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts index 4e6ad44e9..fb4eb10b4 100644 --- a/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts +++ b/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts @@ -21,7 +21,9 @@ const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); // tslint:disable:custom-no-magic-numbers describe('DutchAuctionWrapper', () => { - const fillableAmount = new BigNumber(2); + const makerAssetAmount = new BigNumber(5); + const auctionEndTakerAmount = new BigNumber(10); + const auctionBeginTakerAmount = auctionEndTakerAmount.times(2); const tenMinutesInSeconds = 10 * 60; let contractWrappers: ContractWrappers; let exchangeContractAddress: string; @@ -35,9 +37,7 @@ describe('DutchAuctionWrapper', () => { let makerTokenAssetData: string; let takerTokenAssetData: string; let auctionBeginTimeSeconds: BigNumber; - let auctionBeginAmount: BigNumber; let auctionEndTimeSeconds: BigNumber; - let auctionEndAmount: BigNumber; before(async () => { // setup contract wrappers & addresses const contractAddresses = await migrateOnceAsync(); @@ -58,8 +58,6 @@ describe('DutchAuctionWrapper', () => { assetDataUtils.encodeERC20AssetData(takerTokenAddress), ]; // setup auction details in maker asset data - auctionEndAmount = fillableAmount; - auctionBeginAmount = auctionEndAmount.times(2); const currentBlockTimestamp: number = await getLatestBlockTimestampAsync(); auctionBeginTimeSeconds = new BigNumber(currentBlockTimestamp - tenMinutesInSeconds); auctionEndTimeSeconds = new BigNumber(currentBlockTimestamp + tenMinutesInSeconds); @@ -73,14 +71,14 @@ describe('DutchAuctionWrapper', () => { ); sellOrder = await dutchAuctionUtils.createSignedSellOrderAsync( auctionBeginTimeSeconds, - auctionBeginAmount, - auctionEndAmount, auctionEndTimeSeconds, + auctionBeginTakerAmount, + auctionEndTakerAmount, + makerAssetAmount, makerTokenAssetData, takerTokenAssetData, makerAddress, constants.NULL_ADDRESS, - auctionEndAmount, ); buyOrder = await dutchAuctionUtils.createSignedBuyOrderAsync(sellOrder, takerAddress); }); @@ -119,7 +117,7 @@ describe('DutchAuctionWrapper', () => { expect(auctionDetails.beginTimeSeconds, 'auctionDetails.beginTimeSeconds').to.be.bignumber.equal( auctionBeginTimeSeconds, ); - expect(auctionDetails.beginAmount, 'auctionDetails.beginAmount').to.be.bignumber.equal(auctionBeginAmount); + expect(auctionDetails.beginAmount, 'auctionDetails.beginAmount').to.be.bignumber.equal(auctionBeginTakerAmount); expect(auctionDetails.endTimeSeconds, 'auctionDetails.endTimeSeconds').to.be.bignumber.equal( auctionEndTimeSeconds, ); diff --git a/packages/contract-wrappers/test/utils/dutch_auction_utils.ts b/packages/contract-wrappers/test/utils/dutch_auction_utils.ts index 766fc373a..380d0588c 100644 --- a/packages/contract-wrappers/test/utils/dutch_auction_utils.ts +++ b/packages/contract-wrappers/test/utils/dutch_auction_utils.ts @@ -24,31 +24,34 @@ export class DutchAuctionUtils { } public async createSignedSellOrderAsync( auctionBeginTimeSections: BigNumber, - auctionBeginAmount: BigNumber, - auctionEndAmount: BigNumber, - acutionEndTime: BigNumber, + acutionEndTimeSeconds: BigNumber, + auctionBeginTakerAssetAmount: BigNumber, + auctionEndTakerAssetAmount: BigNumber, + makerAssetAmount: BigNumber, makerAssetData: string, takerAssetData: string, makerAddress: string, takerAddress: string, - takerFillableAmount: BigNumber, senderAddress?: string, makerFee?: BigNumber, takerFee?: BigNumber, feeRecipientAddress?: string, ): Promise { - const makerAssetAmount = auctionEndAmount; + // Notes on sell order: + // - The `takerAssetAmount` is set to the `auctionEndTakerAssetAmount`, which is the lowest amount the + // the seller can expect to receive + // - The `makerAssetData` is overloaded to include the auction begin time and begin taker asset amount const makerAssetDataWithAuctionDetails = DutchAuctionWrapper.encodeDutchAuctionAssetData( makerAssetData, auctionBeginTimeSections, - auctionBeginAmount, + auctionBeginTakerAssetAmount, ); const signedOrder = await orderFactory.createSignedOrderAsync( this._web3Wrapper.getProvider(), makerAddress, makerAssetAmount, makerAssetDataWithAuctionDetails, - takerFillableAmount, + auctionEndTakerAssetAmount, takerAssetData, this._exchangeAddress, { @@ -57,7 +60,7 @@ export class DutchAuctionUtils { makerFee, takerFee, feeRecipientAddress, - expirationTimeSeconds: acutionEndTime, + expirationTimeSeconds: acutionEndTimeSeconds, }, ); const erc20AssetData = assetDataUtils.decodeERC20AssetData(makerAssetData); @@ -71,8 +74,15 @@ export class DutchAuctionUtils { makerFee?: BigNumber, takerFee?: BigNumber, feeRecipientAddress?: string, + expirationTimeSeconds?: BigNumber, ): Promise { const dutchAuctionData = DutchAuctionWrapper.decodeDutchAuctionData(sellOrder.makerAssetData); + // Notes on buy order: + // - The `makerAssetAmount` is set to `dutchAuctionData.beginAmount`, which is + // the highest amount the buyer would have to pay out at any point during the auction. + // - The `takerAssetAmount` is set to the seller's `makerAssetAmount`, as the buyer + // receives the entire amount being sold by the seller. + // - The `makerAssetData`/`takerAssetData` are reversed from the sell order const signedOrder = await orderFactory.createSignedOrderAsync( this._web3Wrapper.getProvider(), buyerAddress, @@ -86,7 +96,7 @@ export class DutchAuctionUtils { makerFee, takerFee, feeRecipientAddress, - expirationTimeSeconds: sellOrder.expirationTimeSeconds, + expirationTimeSeconds, }, ); const buyerERC20AssetData = assetDataUtils.decodeERC20AssetData(sellOrder.takerAssetData); @@ -135,7 +145,6 @@ export class DutchAuctionUtils { ); const oldMakerAllowance = await erc20Token.allowance.callAsync(address, this._erc20ProxyAddress); const newMakerAllowance = oldMakerAllowance.plus(amount); - const txHash = await erc20Token.approve.sendTransactionAsync(this._erc20ProxyAddress, newMakerAllowance, { from: address, }); -- cgit v1.2.3 From a00e416a19a5aa7a6d1a615c4886f9d30339c8f6 Mon Sep 17 00:00:00 2001 From: Greg Hysen Date: Sat, 22 Dec 2018 14:50:24 -0800 Subject: ran prettier --- packages/contract-wrappers/test/dutch_auction_wrapper_test.ts | 4 +++- packages/contract-wrappers/test/utils/dutch_auction_utils.ts | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'packages/contract-wrappers') diff --git a/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts b/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts index fb4eb10b4..d7a6ca015 100644 --- a/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts +++ b/packages/contract-wrappers/test/dutch_auction_wrapper_test.ts @@ -117,7 +117,9 @@ describe('DutchAuctionWrapper', () => { expect(auctionDetails.beginTimeSeconds, 'auctionDetails.beginTimeSeconds').to.be.bignumber.equal( auctionBeginTimeSeconds, ); - expect(auctionDetails.beginAmount, 'auctionDetails.beginAmount').to.be.bignumber.equal(auctionBeginTakerAmount); + expect(auctionDetails.beginAmount, 'auctionDetails.beginAmount').to.be.bignumber.equal( + auctionBeginTakerAmount, + ); expect(auctionDetails.endTimeSeconds, 'auctionDetails.endTimeSeconds').to.be.bignumber.equal( auctionEndTimeSeconds, ); diff --git a/packages/contract-wrappers/test/utils/dutch_auction_utils.ts b/packages/contract-wrappers/test/utils/dutch_auction_utils.ts index 380d0588c..8e2aef217 100644 --- a/packages/contract-wrappers/test/utils/dutch_auction_utils.ts +++ b/packages/contract-wrappers/test/utils/dutch_auction_utils.ts @@ -38,7 +38,7 @@ export class DutchAuctionUtils { feeRecipientAddress?: string, ): Promise { // Notes on sell order: - // - The `takerAssetAmount` is set to the `auctionEndTakerAssetAmount`, which is the lowest amount the + // - The `takerAssetAmount` is set to the `auctionEndTakerAssetAmount`, which is the lowest amount the // the seller can expect to receive // - The `makerAssetData` is overloaded to include the auction begin time and begin taker asset amount const makerAssetDataWithAuctionDetails = DutchAuctionWrapper.encodeDutchAuctionAssetData( @@ -78,7 +78,7 @@ export class DutchAuctionUtils { ): Promise { const dutchAuctionData = DutchAuctionWrapper.decodeDutchAuctionData(sellOrder.makerAssetData); // Notes on buy order: - // - The `makerAssetAmount` is set to `dutchAuctionData.beginAmount`, which is + // - The `makerAssetAmount` is set to `dutchAuctionData.beginAmount`, which is // the highest amount the buyer would have to pay out at any point during the auction. // - The `takerAssetAmount` is set to the seller's `makerAssetAmount`, as the buyer // receives the entire amount being sold by the seller. -- cgit v1.2.3 From edb989fbf381201752309a1e2aa5dcf6837b67d0 Mon Sep 17 00:00:00 2001 From: Greg Hysen Date: Sun, 23 Dec 2018 16:04:09 -0800 Subject: export dutch auction wrapper types from 0x.js --- packages/contract-wrappers/src/index.ts | 1 + 1 file changed, 1 insertion(+) (limited to 'packages/contract-wrappers') diff --git a/packages/contract-wrappers/src/index.ts b/packages/contract-wrappers/src/index.ts index 5c64dbbc6..cf0ec405f 100644 --- a/packages/contract-wrappers/src/index.ts +++ b/packages/contract-wrappers/src/index.ts @@ -55,6 +55,7 @@ export { OrderAndTraderInfo, TraderInfo, ValidateOrderFillableOpts, + DutchAuctionData, } from './types'; export { Order, SignedOrder, AssetProxyId } from '@0x/types'; -- cgit v1.2.3 From 5f2a7cb78fd8b937bcecf962071d59a08e46dec5 Mon Sep 17 00:00:00 2001 From: Greg Hysen Date: Sun, 23 Dec 2018 16:13:43 -0800 Subject: removed manual updte of package.json version --- packages/contract-wrappers/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/contract-wrappers') diff --git a/packages/contract-wrappers/package.json b/packages/contract-wrappers/package.json index 222cfa622..e4de75ab2 100644 --- a/packages/contract-wrappers/package.json +++ b/packages/contract-wrappers/package.json @@ -1,6 +1,6 @@ { "name": "@0x/contract-wrappers", - "version": "4.2.0", + "version": "4.1.3", "description": "Smart TS wrappers for 0x smart contracts", "keywords": [ "0xproject", -- cgit v1.2.3 From d0a0673694f26a2e9f8e562d335a34cdc1e9c8b2 Mon Sep 17 00:00:00 2001 From: Greg Hysen Date: Sun, 23 Dec 2018 17:14:34 -0800 Subject: Doc generation working for changes by dutch auction wrapper --- packages/contract-wrappers/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/contract-wrappers') diff --git a/packages/contract-wrappers/src/index.ts b/packages/contract-wrappers/src/index.ts index cf0ec405f..bf9c27018 100644 --- a/packages/contract-wrappers/src/index.ts +++ b/packages/contract-wrappers/src/index.ts @@ -58,7 +58,7 @@ export { DutchAuctionData, } from './types'; -export { Order, SignedOrder, AssetProxyId } from '@0x/types'; +export { AssetData, DutchAuctionDetails, ERC20AssetData, ERC721AssetData, Order, SignedOrder, AssetProxyId } from '@0x/types'; export { BlockParamLiteral, -- cgit v1.2.3 From e39ae0350b744227bca73001c90101f0b8613193 Mon Sep 17 00:00:00 2001 From: Greg Hysen Date: Sun, 23 Dec 2018 17:29:12 -0800 Subject: Ran prettier --- packages/contract-wrappers/src/index.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'packages/contract-wrappers') diff --git a/packages/contract-wrappers/src/index.ts b/packages/contract-wrappers/src/index.ts index bf9c27018..853194d6f 100644 --- a/packages/contract-wrappers/src/index.ts +++ b/packages/contract-wrappers/src/index.ts @@ -58,7 +58,15 @@ export { DutchAuctionData, } from './types'; -export { AssetData, DutchAuctionDetails, ERC20AssetData, ERC721AssetData, Order, SignedOrder, AssetProxyId } from '@0x/types'; +export { + AssetData, + DutchAuctionDetails, + ERC20AssetData, + ERC721AssetData, + Order, + SignedOrder, + AssetProxyId, +} from '@0x/types'; export { BlockParamLiteral, -- cgit v1.2.3 From 04db7f0fae02ef29795d0f65deb71e64b5552233 Mon Sep 17 00:00:00 2001 From: Greg Hysen Date: Mon, 7 Jan 2019 13:08:44 -0800 Subject: Fixed merge conflict from development --- packages/contract-wrappers/src/index.ts | 5 ++++- packages/contract-wrappers/src/types.ts | 4 +--- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'packages/contract-wrappers') diff --git a/packages/contract-wrappers/src/index.ts b/packages/contract-wrappers/src/index.ts index 853194d6f..69bbe3c91 100644 --- a/packages/contract-wrappers/src/index.ts +++ b/packages/contract-wrappers/src/index.ts @@ -60,9 +60,12 @@ export { export { AssetData, - DutchAuctionDetails, ERC20AssetData, ERC721AssetData, + SingleAssetData, + MultiAssetData, + MultiAssetDataWithRecursiveDecoding, + DutchAuctionDetails, Order, SignedOrder, AssetProxyId, diff --git a/packages/contract-wrappers/src/types.ts b/packages/contract-wrappers/src/types.ts index f23587c20..945ca88cd 100644 --- a/packages/contract-wrappers/src/types.ts +++ b/packages/contract-wrappers/src/types.ts @@ -9,13 +9,11 @@ import { WETH9Events, } from '@0x/abi-gen-wrappers'; import { ContractAddresses } from '@0x/contract-addresses'; -import { OrderState, SignedOrder } from '@0x/types'; +import { AssetData, OrderState, SignedOrder } from '@0x/types'; import { BigNumber } from '@0x/utils'; import { BlockParam, ContractEventArg, DecodedLogArgs, LogEntryEvent, LogWithDecodedArgs } from 'ethereum-types'; -import { AssetData } from '@0x/order-utils'; - export enum ExchangeWrapperError { AssetDataMismatch = 'ASSET_DATA_MISMATCH', } -- cgit v1.2.3 From 0a6ead90d9ef4823f00f9afbc2426a274df11181 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Wed, 9 Jan 2019 14:44:03 +0100 Subject: Updated CHANGELOGS --- packages/contract-wrappers/CHANGELOG.json | 3 ++- packages/contract-wrappers/CHANGELOG.md | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'packages/contract-wrappers') diff --git a/packages/contract-wrappers/CHANGELOG.json b/packages/contract-wrappers/CHANGELOG.json index 677292030..fd8dfa427 100644 --- a/packages/contract-wrappers/CHANGELOG.json +++ b/packages/contract-wrappers/CHANGELOG.json @@ -6,7 +6,8 @@ "note": "Added Dutch Auction wrapper", "pr": 1465 } - ] + ], + "timestamp": 1547040760 }, { "version": "4.1.4", diff --git a/packages/contract-wrappers/CHANGELOG.md b/packages/contract-wrappers/CHANGELOG.md index 595fbcc31..fe7bb7b81 100644 --- a/packages/contract-wrappers/CHANGELOG.md +++ b/packages/contract-wrappers/CHANGELOG.md @@ -5,6 +5,15 @@ Edit the package's CHANGELOG.json file only. CHANGELOG +## v4.2.0 - _January 9, 2019_ + + * Added Dutch Auction wrapper (#1465) + +## v4.1.4 - _Invalid date_ + + * Add support for Trust Wallet signature denial error + * Add balance and allowance queries for `MultiAssetProxy` (#1363) + ## v4.1.3 - _December 13, 2018_ * Dependencies updated -- cgit v1.2.3 From 5b7eff217e9c8d09d64ff8721d7a16e1df8a7c58 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Wed, 9 Jan 2019 14:44:17 +0100 Subject: Publish - 0x.js@3.0.0 - @0x/abi-gen@1.0.20 - @0x/abi-gen-wrappers@2.1.0 - @0x/assert@1.0.21 - @0x/asset-buyer@3.0.5 - @0x/base-contract@3.0.11 - @0x/connect@3.0.11 - @0x/contract-addresses@2.1.0 - @0x/contract-artifacts@1.2.0 - @0x/contract-wrappers@4.2.0 - @0x/dev-tools-pages@0.0.11 - @0x/dev-utils@1.0.22 - @0x/fill-scenarios@1.1.0 - @0x/instant@1.0.5 - @0x/json-schemas@2.1.5 - @0x/metacoin@0.0.33 - @0x/migrations@2.3.0 - @0x/monorepo-scripts@1.0.16 - @0x/order-utils@3.1.0 - @0x/order-watcher@2.4.0 - @0x/pipeline@1.0.3 - @0x/react-docs@1.0.23 - @0x/react-shared@1.1.0 - @0x/sol-compiler@2.0.0 - @0x/sol-cov@2.1.17 - @0x/sol-doc@1.0.12 - @0x/sol-resolver@1.2.1 - @0x/sra-spec@1.0.14 - @0x/subproviders@2.1.9 - @0x/testnet-faucets@1.0.61 - @0x/types@1.5.0 - @0x/utils@2.1.1 - @0x/web3-wrapper@3.2.2 - @0x/website@0.0.64 - @0x/contracts-examples@1.0.3 - @0x/contracts-extensions@1.2.0 - @0x/contracts-interfaces@1.0.3 - @0x/contracts-libs@1.0.3 - @0x/contracts-multisig@1.0.3 - @0x/contracts-protocol@2.2.0 - @0x/contracts-test-utils@1.0.3 - @0x/contracts-tokens@1.0.3 - @0x/contracts-utils@1.0.3 --- packages/contract-wrappers/package.json | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'packages/contract-wrappers') diff --git a/packages/contract-wrappers/package.json b/packages/contract-wrappers/package.json index e4de75ab2..708b4249a 100644 --- a/packages/contract-wrappers/package.json +++ b/packages/contract-wrappers/package.json @@ -1,6 +1,6 @@ { "name": "@0x/contract-wrappers", - "version": "4.1.3", + "version": "4.2.0", "description": "Smart TS wrappers for 0x smart contracts", "keywords": [ "0xproject", @@ -37,9 +37,9 @@ "node": ">=6.0.0" }, "devDependencies": { - "@0x/dev-utils": "^1.0.21", - "@0x/migrations": "^2.2.2", - "@0x/subproviders": "^2.1.8", + "@0x/dev-utils": "^1.0.22", + "@0x/migrations": "^2.3.0", + "@0x/subproviders": "^2.1.9", "@0x/tslint-config": "^2.0.0", "@types/lodash": "4.14.104", "@types/mocha": "^2.2.42", @@ -65,20 +65,20 @@ "web3-provider-engine": "14.0.6" }, "dependencies": { - "@0x/abi-gen-wrappers": "^2.0.2", - "@0x/assert": "^1.0.20", - "@0x/contract-addresses": "^2.0.0", - "@0x/contract-artifacts": "^1.1.2", - "@0x/contracts-test-utils": "^1.0.2", - "@0x/fill-scenarios": "^1.0.16", - "@0x/json-schemas": "^2.1.4", - "@0x/order-utils": "^3.0.7", - "@0x/types": "^1.4.1", + "@0x/abi-gen-wrappers": "^2.1.0", + "@0x/assert": "^1.0.21", + "@0x/contract-addresses": "^2.1.0", + "@0x/contract-artifacts": "^1.2.0", + "@0x/contracts-test-utils": "^1.0.3", + "@0x/fill-scenarios": "^1.1.0", + "@0x/json-schemas": "^2.1.5", + "@0x/order-utils": "^3.1.0", + "@0x/types": "^1.5.0", "@0x/typescript-typings": "^3.0.6", - "@0x/utils": "^2.0.8", - "@0x/web3-wrapper": "^3.2.1", - "ethereumjs-abi": "0.6.5", + "@0x/utils": "^2.1.1", + "@0x/web3-wrapper": "^3.2.2", "ethereum-types": "^1.1.4", + "ethereumjs-abi": "0.6.5", "ethereumjs-blockstream": "6.0.0", "ethereumjs-util": "^5.1.1", "ethers": "~4.0.4", -- cgit v1.2.3