aboutsummaryrefslogtreecommitdiffstats
path: root/packages/asset-buyer/src/asset_buyer.ts
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-10-09 17:42:35 +0800
committerFabio Berger <me@fabioberger.com>2018-10-09 17:42:35 +0800
commit6c9f7839c3948e60f2987f474bb2ad6457588fa3 (patch)
tree5736c15290289124e24392bc81eb4f8426c468f1 /packages/asset-buyer/src/asset_buyer.ts
parent9654397b292ee03c503313e3fbb127ebb4b7d76b (diff)
parent3ac9dac4f0a6b3875b7ae0ea6dd1855743768ef2 (diff)
downloaddexon-sol-tools-6c9f7839c3948e60f2987f474bb2ad6457588fa3.tar
dexon-sol-tools-6c9f7839c3948e60f2987f474bb2ad6457588fa3.tar.gz
dexon-sol-tools-6c9f7839c3948e60f2987f474bb2ad6457588fa3.tar.bz2
dexon-sol-tools-6c9f7839c3948e60f2987f474bb2ad6457588fa3.tar.lz
dexon-sol-tools-6c9f7839c3948e60f2987f474bb2ad6457588fa3.tar.xz
dexon-sol-tools-6c9f7839c3948e60f2987f474bb2ad6457588fa3.tar.zst
dexon-sol-tools-6c9f7839c3948e60f2987f474bb2ad6457588fa3.zip
Merge branch 'development' into dev-section-redesign
* development: Clarifies use of schemas outside of Javascript/TypeScript. Fix typo Add asset-buyer to published packages section in README Publish Updated CHANGELOGS Update BuyQuote interface Add missing default options Remove unused constants Add fee order with a takerFee Add additional order factory methods and refactor test to use them Add comments about buy quote calculation Update CHANGELOG Fix linter Add additional test for slippage Add buy_quote_calculator_test
Diffstat (limited to 'packages/asset-buyer/src/asset_buyer.ts')
-rw-r--r--packages/asset-buyer/src/asset_buyer.ts24
1 files changed, 12 insertions, 12 deletions
diff --git a/packages/asset-buyer/src/asset_buyer.ts b/packages/asset-buyer/src/asset_buyer.ts
index 0bb757f52..7ec39e012 100644
--- a/packages/asset-buyer/src/asset_buyer.ts
+++ b/packages/asset-buyer/src/asset_buyer.ts
@@ -123,7 +123,7 @@ export class AssetBuyer {
public async getBuyQuoteAsync(
assetData: string,
assetBuyAmount: BigNumber,
- options: Partial<BuyQuoteRequestOpts>,
+ options: Partial<BuyQuoteRequestOpts> = {},
): Promise<BuyQuote> {
const { feePercentage, shouldForceOrderRefresh, slippagePercentage } = {
...constants.DEFAULT_BUY_QUOTE_REQUEST_OPTS,
@@ -164,7 +164,7 @@ export class AssetBuyer {
public async getBuyQuoteForERC20TokenAddressAsync(
tokenAddress: string,
assetBuyAmount: BigNumber,
- options: Partial<BuyQuoteRequestOpts>,
+ options: Partial<BuyQuoteRequestOpts> = {},
): Promise<BuyQuote> {
assert.isETHAddressHex('tokenAddress', tokenAddress);
assert.isBigNumber('assetBuyAmount', assetBuyAmount);
@@ -179,20 +179,23 @@ export class AssetBuyer {
*
* @return A promise of the txHash.
*/
- public async executeBuyQuoteAsync(buyQuote: BuyQuote, options: Partial<BuyQuoteExecutionOpts>): Promise<string> {
- const { rate, takerAddress, feeRecipient } = {
+ public async executeBuyQuoteAsync(
+ buyQuote: BuyQuote,
+ options: Partial<BuyQuoteExecutionOpts> = {},
+ ): Promise<string> {
+ const { ethAmount, takerAddress, feeRecipient } = {
...constants.DEFAULT_BUY_QUOTE_EXECUTION_OPTS,
...options,
};
assert.isValidBuyQuote('buyQuote', buyQuote);
- if (!_.isUndefined(rate)) {
- assert.isBigNumber('rate', rate);
+ if (!_.isUndefined(ethAmount)) {
+ assert.isBigNumber('ethAmount', ethAmount);
}
if (!_.isUndefined(takerAddress)) {
assert.isETHAddressHex('takerAddress', takerAddress);
}
assert.isETHAddressHex('feeRecipient', feeRecipient);
- const { orders, feeOrders, feePercentage, assetBuyAmount, maxRate } = buyQuote;
+ const { orders, feeOrders, feePercentage, assetBuyAmount, worstCaseQuoteInfo } = buyQuote;
// if no takerAddress is provided, try to get one from the provider
let finalTakerAddress;
if (!_.isUndefined(takerAddress)) {
@@ -207,15 +210,12 @@ export class AssetBuyer {
throw new Error(AssetBuyerError.NoAddressAvailable);
}
}
- // if no rate is provided, default to the maxRate from buyQuote
- const desiredRate = rate || maxRate;
- // calculate how much eth is required to buy assetBuyAmount at the desired rate
- const ethAmount = assetBuyAmount.dividedToIntegerBy(desiredRate);
+ // if no ethAmount is provided, default to the worst ethAmount from buyQuote
const txHash = await this._contractWrappers.forwarder.marketBuyOrdersWithEthAsync(
orders,
assetBuyAmount,
finalTakerAddress,
- ethAmount,
+ ethAmount || worstCaseQuoteInfo.totalEthAmount,
feeOrders,
feePercentage,
feeRecipient,