From 405234133b784bf563a4220cc6380d25c901e453 Mon Sep 17 00:00:00 2001 From: fragosti Date: Fri, 5 Oct 2018 13:40:26 -0700 Subject: Fix order expiration calc bug and expose gas options to executeBuyQuote --- packages/asset-buyer/src/asset_buyer.ts | 6 +++++- packages/asset-buyer/src/types.ts | 2 ++ packages/asset-buyer/src/utils/order_utils.ts | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) (limited to 'packages/asset-buyer/src') diff --git a/packages/asset-buyer/src/asset_buyer.ts b/packages/asset-buyer/src/asset_buyer.ts index 7ec39e012..50343efde 100644 --- a/packages/asset-buyer/src/asset_buyer.ts +++ b/packages/asset-buyer/src/asset_buyer.ts @@ -183,7 +183,7 @@ export class AssetBuyer { buyQuote: BuyQuote, options: Partial = {}, ): Promise { - const { ethAmount, takerAddress, feeRecipient } = { + const { ethAmount, takerAddress, feeRecipient, gasLimit, gasPrice } = { ...constants.DEFAULT_BUY_QUOTE_EXECUTION_OPTS, ...options, }; @@ -219,6 +219,10 @@ export class AssetBuyer { feeOrders, feePercentage, feeRecipient, + { + gasLimit, + gasPrice, + }, ); return txHash; } diff --git a/packages/asset-buyer/src/types.ts b/packages/asset-buyer/src/types.ts index b96795bb6..f779d123f 100644 --- a/packages/asset-buyer/src/types.ts +++ b/packages/asset-buyer/src/types.ts @@ -82,6 +82,8 @@ export interface BuyQuoteRequestOpts { export interface BuyQuoteExecutionOpts { ethAmount?: BigNumber; takerAddress?: string; + gasLimit?: number; + gasPrice?: BigNumber; feeRecipient: string; } diff --git a/packages/asset-buyer/src/utils/order_utils.ts b/packages/asset-buyer/src/utils/order_utils.ts index 62166eb76..cfc13a8a1 100644 --- a/packages/asset-buyer/src/utils/order_utils.ts +++ b/packages/asset-buyer/src/utils/order_utils.ts @@ -10,7 +10,7 @@ export const orderUtils = { willOrderExpire(order: SignedOrder, secondsFromNow: number): boolean { const millisecondsInSecond = 1000; const currentUnixTimestampSec = new BigNumber(Date.now() / millisecondsInSecond).round(); - return order.expirationTimeSeconds.lessThan(currentUnixTimestampSec.minus(secondsFromNow)); + return order.expirationTimeSeconds.lessThan(currentUnixTimestampSec.plus(secondsFromNow)); }, calculateRemainingMakerAssetAmount(order: SignedOrder, remainingTakerAssetAmount: BigNumber): BigNumber { if (remainingTakerAssetAmount.eq(0)) { -- cgit v1.2.3 From 9ba00a1077ba53f00e7b75f650289dfc3aff47ff Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Fri, 5 Oct 2018 15:24:11 -0700 Subject: Add comments for gasPrice and gasLimit --- packages/asset-buyer/src/types.ts | 2 ++ 1 file changed, 2 insertions(+) (limited to 'packages/asset-buyer/src') diff --git a/packages/asset-buyer/src/types.ts b/packages/asset-buyer/src/types.ts index f779d123f..90502ac69 100644 --- a/packages/asset-buyer/src/types.ts +++ b/packages/asset-buyer/src/types.ts @@ -77,6 +77,8 @@ export interface BuyQuoteRequestOpts { /** * ethAmount: The desired amount of eth to spend. Defaults to buyQuote.worstCaseQuoteInfo.totalEthAmount. * takerAddress: The address to perform the buy. Defaults to the first available address from the provider. + * gasLimit: The amount of gas to send with a transaction (in Gwei). Defaults to an eth_estimateGas rpc call. + * gasPrice: Gas price in Wei to use for a transaction * feeRecipient: The address where affiliate fees are sent. Defaults to null address (0x000...000). */ export interface BuyQuoteExecutionOpts { -- cgit v1.2.3 From cb1311ecc5889a0fd81b61f3ab7b66605d75960f Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Fri, 5 Oct 2018 15:25:54 -0700 Subject: Increase default expiryBufferSeconds from 15 to 300 (5 minutes) --- packages/asset-buyer/src/constants.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/asset-buyer/src') diff --git a/packages/asset-buyer/src/constants.ts b/packages/asset-buyer/src/constants.ts index e1056e39b..bc168e462 100644 --- a/packages/asset-buyer/src/constants.ts +++ b/packages/asset-buyer/src/constants.ts @@ -8,7 +8,7 @@ const MAINNET_NETWORK_ID = 1; const DEFAULT_ASSET_BUYER_OPTS: AssetBuyerOpts = { networkId: MAINNET_NETWORK_ID, orderRefreshIntervalMs: 10000, // 10 seconds - expiryBufferSeconds: 15, + expiryBufferSeconds: 300, }; const DEFAULT_BUY_QUOTE_REQUEST_OPTS: BuyQuoteRequestOpts = { -- cgit v1.2.3 From f9f8e06c1c8ac5b254dfae08e216ea199a77ff02 Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Fri, 5 Oct 2018 15:42:19 -0700 Subject: Fix incorrect affiliate fee calculations and associated tests --- packages/asset-buyer/src/utils/buy_quote_calculator.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'packages/asset-buyer/src') diff --git a/packages/asset-buyer/src/utils/buy_quote_calculator.ts b/packages/asset-buyer/src/utils/buy_quote_calculator.ts index cb0fd128c..a1d334eef 100644 --- a/packages/asset-buyer/src/utils/buy_quote_calculator.ts +++ b/packages/asset-buyer/src/utils/buy_quote_calculator.ts @@ -72,7 +72,6 @@ export const buyQuoteCalculator = { assetBuyAmount, feePercentage, ); - return { assetData, orders: resultOrders, @@ -98,13 +97,14 @@ function calculateQuoteInfo( ); // find the total eth needed to buy fees const ethAmountToBuyFees = findEthAmountNeededToBuyFees(feeOrdersAndFillableAmounts, zrxAmountToBuyAsset); - const ethAmountBeforeAffiliateFee = ethAmountToBuyAsset.plus(ethAmountToBuyFees); - const totalEthAmount = ethAmountBeforeAffiliateFee.mul(feePercentage + 1); + const affiliateFeeEthAmount = ethAmountToBuyAsset.mul(feePercentage); + const totalEthAmountWithoutAffiliateFee = ethAmountToBuyAsset.plus(ethAmountToBuyFees); + const totalEthAmount = totalEthAmountWithoutAffiliateFee.plus(affiliateFeeEthAmount); // divide into the assetBuyAmount in order to find rate of makerAsset / WETH - const ethPerAssetPrice = ethAmountBeforeAffiliateFee.div(assetBuyAmount); + const ethPerAssetPrice = totalEthAmountWithoutAffiliateFee.div(assetBuyAmount); return { totalEthAmount, - feeEthAmount: totalEthAmount.minus(ethAmountBeforeAffiliateFee), + feeEthAmount: affiliateFeeEthAmount, ethPerAssetPrice, }; } -- cgit v1.2.3 From f2fdb6e47dd07a034d5be4fc3e0edca863e38aaa Mon Sep 17 00:00:00 2001 From: Brandon Millman Date: Tue, 9 Oct 2018 14:28:54 -0700 Subject: Add comments for expiryBuffer --- packages/asset-buyer/src/constants.ts | 2 +- packages/asset-buyer/src/types.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'packages/asset-buyer/src') diff --git a/packages/asset-buyer/src/constants.ts b/packages/asset-buyer/src/constants.ts index bc168e462..e095dee06 100644 --- a/packages/asset-buyer/src/constants.ts +++ b/packages/asset-buyer/src/constants.ts @@ -8,7 +8,7 @@ const MAINNET_NETWORK_ID = 1; const DEFAULT_ASSET_BUYER_OPTS: AssetBuyerOpts = { networkId: MAINNET_NETWORK_ID, orderRefreshIntervalMs: 10000, // 10 seconds - expiryBufferSeconds: 300, + expiryBufferSeconds: 300, // 5 minutes }; const DEFAULT_BUY_QUOTE_REQUEST_OPTS: BuyQuoteRequestOpts = { diff --git a/packages/asset-buyer/src/types.ts b/packages/asset-buyer/src/types.ts index 90502ac69..6218f4ba4 100644 --- a/packages/asset-buyer/src/types.ts +++ b/packages/asset-buyer/src/types.ts @@ -92,7 +92,7 @@ export interface BuyQuoteExecutionOpts { /** * networkId: The ethereum network id. Defaults to 1 (mainnet). * orderRefreshIntervalMs: The interval in ms that getBuyQuoteAsync should trigger an refresh of orders and order states. Defaults to 10000ms (10s). - * expiryBufferSeconds: The number of seconds to add when calculating whether an order is expired or not. Defaults to 15s. + * expiryBufferSeconds: The number of seconds to add when calculating whether an order is expired or not. Defaults to 300s (5m). */ export interface AssetBuyerOpts { networkId: number; -- cgit v1.2.3