aboutsummaryrefslogtreecommitdiffstats
path: root/packages/asset-buyer/src
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-10-11 20:23:45 +0800
committerFabio Berger <me@fabioberger.com>2018-10-11 20:23:45 +0800
commit1cfcc82ea9869e14c1a1b78e1376c89fdbeb91f4 (patch)
tree48ef8716485c1b961b2494071f5a64f60ff42f29 /packages/asset-buyer/src
parent6c9f7839c3948e60f2987f474bb2ad6457588fa3 (diff)
parent8941b6cee5b56fab6d3b89ac8a899f21d5c86350 (diff)
downloaddexon-sol-tools-1cfcc82ea9869e14c1a1b78e1376c89fdbeb91f4.tar
dexon-sol-tools-1cfcc82ea9869e14c1a1b78e1376c89fdbeb91f4.tar.gz
dexon-sol-tools-1cfcc82ea9869e14c1a1b78e1376c89fdbeb91f4.tar.bz2
dexon-sol-tools-1cfcc82ea9869e14c1a1b78e1376c89fdbeb91f4.tar.lz
dexon-sol-tools-1cfcc82ea9869e14c1a1b78e1376c89fdbeb91f4.tar.xz
dexon-sol-tools-1cfcc82ea9869e14c1a1b78e1376c89fdbeb91f4.tar.zst
dexon-sol-tools-1cfcc82ea9869e14c1a1b78e1376c89fdbeb91f4.zip
Merge branch 'development' into dev-section-redesign
* development: (62 commits) Fix linter error Upgrade ethereum-types Lint and update deps Be more explicit with falsiness Add type to cssRuleIfExists Fix issue where we throw if non-numeric characters are used in input Upgrade to more recent types, fix yarn.lock [fix]: [testnet-faucet] Exit 1 on build fail Explains tools we want them to use Add note about button Add dev-tools-pages bundles to gitignore Improve README Fix button and center Increase max bundle size for instant Add stuff Initial project scaffolding Change tslint config to remove conflicts with prettier fix: [testnet-faucet] Signing of orders Update the CHANGELOG Add comments for expiryBuffer ...
Diffstat (limited to 'packages/asset-buyer/src')
-rw-r--r--packages/asset-buyer/src/asset_buyer.ts6
-rw-r--r--packages/asset-buyer/src/constants.ts2
-rw-r--r--packages/asset-buyer/src/types.ts6
-rw-r--r--packages/asset-buyer/src/utils/buy_quote_calculator.ts10
-rw-r--r--packages/asset-buyer/src/utils/order_utils.ts2
5 files changed, 17 insertions, 9 deletions
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<BuyQuoteExecutionOpts> = {},
): Promise<string> {
- 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/constants.ts b/packages/asset-buyer/src/constants.ts
index e1056e39b..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: 15,
+ 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 b96795bb6..6218f4ba4 100644
--- a/packages/asset-buyer/src/types.ts
+++ b/packages/asset-buyer/src/types.ts
@@ -77,18 +77,22 @@ 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 {
ethAmount?: BigNumber;
takerAddress?: string;
+ gasLimit?: number;
+ gasPrice?: BigNumber;
feeRecipient: string;
}
/**
* 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;
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,
};
}
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)) {