diff options
author | fragosti <francesco.agosti93@gmail.com> | 2018-09-19 06:57:05 +0800 |
---|---|---|
committer | fragosti <francesco.agosti93@gmail.com> | 2018-09-19 06:57:05 +0800 |
commit | 93f7e33f6a1d0a056198a9f22bcb10ef3e4f4f25 (patch) | |
tree | eb75ab7ab1a3a2e4b4c588e2f5eb3f976b9a1a68 | |
parent | fd4b4f8f8289d1e5a873ff5aa0aa9f7ac6a2ba08 (diff) | |
download | dexon-0x-contracts-93f7e33f6a1d0a056198a9f22bcb10ef3e4f4f25.tar.gz dexon-0x-contracts-93f7e33f6a1d0a056198a9f22bcb10ef3e4f4f25.tar.zst dexon-0x-contracts-93f7e33f6a1d0a056198a9f22bcb10ef3e4f4f25.zip |
Add isValidPercentage assert
-rw-r--r-- | packages/asset-buyer/src/asset_buyer.ts | 20 | ||||
-rw-r--r-- | packages/asset-buyer/src/utils/assert.ts | 7 |
2 files changed, 14 insertions, 13 deletions
diff --git a/packages/asset-buyer/src/asset_buyer.ts b/packages/asset-buyer/src/asset_buyer.ts index a2c0f37c9..7becb8285 100644 --- a/packages/asset-buyer/src/asset_buyer.ts +++ b/packages/asset-buyer/src/asset_buyer.ts @@ -159,15 +159,14 @@ export class AssetBuyer { * the next orderRefreshIntervalMs. Defaults to false. * @return An object that conforms to BuyQuote that satisfies the request. See type definition for more information. */ - public async getBuyQuoteAsync( - assetBuyAmount: BigNumber, - options: Partial<BuyQuoteRequestOpts>, - ): Promise<BuyQuote> { - const { feePercentage, forceOrderRefresh, slippagePercentage } = { ...options, ...constants.DEFAULT_BUY_QUOTE_REQUEST_OPTS }; + public async getBuyQuoteAsync(assetBuyAmount: BigNumber, options: Partial<BuyQuoteRequestOpts>): Promise<BuyQuote> { + const { feePercentage, forceOrderRefresh, slippagePercentage } = { + ...options, + ...constants.DEFAULT_BUY_QUOTE_REQUEST_OPTS, + }; assert.isBigNumber('assetBuyAmount', assetBuyAmount); - assert.isNumber('feePercentage', feePercentage); + assert.isValidPercentage('feePercentage', feePercentage); assert.isBoolean('forceOrderRefresh', forceOrderRefresh); - assert.isNumber('feePercentage', slippagePercentage); // we should refresh if: // we do not have any orders OR // we are forced to OR @@ -236,18 +235,13 @@ export class AssetBuyer { const desiredRate = rate || maxRate; // calculate how much eth is required to buy assetBuyAmount at the desired rate const ethAmount = assetBuyAmount.dividedToIntegerBy(desiredRate); - // TODO: critical - // update the forwarder wrapper to take in feePercentage as a number instead of a BigNumber, verify with Amir that this is being done correctly - const feePercentageBigNumber = !_.isUndefined(feePercentage) - ? Web3Wrapper.toBaseUnitAmount(new BigNumber(1), constants.ETHER_TOKEN_DECIMALS).mul(feePercentage) - : constants.ZERO_AMOUNT; const txHash = await this._contractWrappers.forwarder.marketBuyOrdersWithEthAsync( orders, assetBuyAmount, finalTakerAddress, ethAmount, feeOrders, - feePercentageBigNumber, + feePercentage, feeRecipient, ); return txHash; diff --git a/packages/asset-buyer/src/utils/assert.ts b/packages/asset-buyer/src/utils/assert.ts index edc90608c..745ba726f 100644 --- a/packages/asset-buyer/src/utils/assert.ts +++ b/packages/asset-buyer/src/utils/assert.ts @@ -41,4 +41,11 @@ export const assert = { `Expected all orders in ${variableName} to have the same makerAssetData and takerAssetData.`, ); }, + isValidPercentage(variableName: string, percentage: number): void { + assert.isNumber(variableName, percentage); + assert.assert( + percentage >= 0 && percentage <= 1, + `Expected ${variableName} to be between 0 and 1, but is ${percentage}`, + ); + }, }; |