diff options
author | Fabio Berger <me@fabioberger.com> | 2018-11-16 21:52:20 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-11-16 21:52:20 +0800 |
commit | 25d0b1e6e58987d0f00a5034158c2c514cf476d6 (patch) | |
tree | 412ef07e713fd928b856aca2fc603e182adcd1d3 /packages/asset-buyer/src/utils | |
parent | e36fc4e6aef414c5d3507c59d82e03e92fbc93fb (diff) | |
parent | cabb7432b9a6d4a5bb8da6fc7fe4522d24e4ece5 (diff) | |
download | dexon-sol-tools-25d0b1e6e58987d0f00a5034158c2c514cf476d6.tar dexon-sol-tools-25d0b1e6e58987d0f00a5034158c2c514cf476d6.tar.gz dexon-sol-tools-25d0b1e6e58987d0f00a5034158c2c514cf476d6.tar.bz2 dexon-sol-tools-25d0b1e6e58987d0f00a5034158c2c514cf476d6.tar.lz dexon-sol-tools-25d0b1e6e58987d0f00a5034158c2c514cf476d6.tar.xz dexon-sol-tools-25d0b1e6e58987d0f00a5034158c2c514cf476d6.tar.zst dexon-sol-tools-25d0b1e6e58987d0f00a5034158c2c514cf476d6.zip |
Merge branch 'development' into launchKitLanding
* development: (110 commits)
fix: fix exceeds block gas limit error
chore(instant): fix lint error
fix: remove unused vars
Send in affiliate info as option
Have heartbeat update not trigger errors
fix: remove redundant handler
feat: make onUnlockWalletClick different based on ON
chore: remove wallet panel content for mobile
feat: use blue for wallet prompt on mobile
feat: use stable version of bowser
fix: add http to external url string
feat: make onUnlockWalletClick different based on ON
chore: remove wallet panel content for mobile
feat: use blue for wallet prompt on mobile
feat: use stable version of bowser
feat: expose webpack-dev-server content to local network
fix(website): remove node env definition from webpack
fix(website): currentProvider called on undefined
chore: update yarn lock
feat: use capital values for enums
...
Diffstat (limited to 'packages/asset-buyer/src/utils')
-rw-r--r-- | packages/asset-buyer/src/utils/assert.ts | 2 | ||||
-rw-r--r-- | packages/asset-buyer/src/utils/buy_quote_calculator.ts | 28 | ||||
-rw-r--r-- | packages/asset-buyer/src/utils/order_provider_response_processor.ts | 29 |
3 files changed, 32 insertions, 27 deletions
diff --git a/packages/asset-buyer/src/utils/assert.ts b/packages/asset-buyer/src/utils/assert.ts index 2466f53a4..fcf9b0d0e 100644 --- a/packages/asset-buyer/src/utils/assert.ts +++ b/packages/asset-buyer/src/utils/assert.ts @@ -18,7 +18,7 @@ export const assert = { } }, isValidBuyQuoteInfo(variableName: string, buyQuoteInfo: BuyQuoteInfo): void { - sharedAssert.isBigNumber(`${variableName}.ethPerAssetPrice`, buyQuoteInfo.ethPerAssetPrice); + sharedAssert.isBigNumber(`${variableName}.assetEthAmount`, buyQuoteInfo.assetEthAmount); sharedAssert.isBigNumber(`${variableName}.feeEthAmount`, buyQuoteInfo.feeEthAmount); sharedAssert.isBigNumber(`${variableName}.totalEthAmount`, buyQuoteInfo.totalEthAmount); }, diff --git a/packages/asset-buyer/src/utils/buy_quote_calculator.ts b/packages/asset-buyer/src/utils/buy_quote_calculator.ts index 6a67ed1ed..b15b880c2 100644 --- a/packages/asset-buyer/src/utils/buy_quote_calculator.ts +++ b/packages/asset-buyer/src/utils/buy_quote_calculator.ts @@ -106,28 +106,28 @@ function calculateQuoteInfo( isMakerAssetZrxToken: boolean, ): BuyQuoteInfo { // find the total eth and zrx needed to buy assetAmount from the resultOrders from left to right - let ethAmountToBuyAsset = constants.ZERO_AMOUNT; - let ethAmountToBuyZrx = constants.ZERO_AMOUNT; + let assetEthAmount = constants.ZERO_AMOUNT; + let zrxEthAmount = constants.ZERO_AMOUNT; if (isMakerAssetZrxToken) { - ethAmountToBuyAsset = findEthAmountNeededToBuyZrx(ordersAndFillableAmounts, assetBuyAmount); + assetEthAmount = findEthAmountNeededToBuyZrx(ordersAndFillableAmounts, assetBuyAmount); } else { // find eth and zrx amounts needed to buy const ethAndZrxAmountToBuyAsset = findEthAndZrxAmountNeededToBuyAsset(ordersAndFillableAmounts, assetBuyAmount); - ethAmountToBuyAsset = ethAndZrxAmountToBuyAsset[0]; + assetEthAmount = ethAndZrxAmountToBuyAsset[0]; const zrxAmountToBuyAsset = ethAndZrxAmountToBuyAsset[1]; // find eth amount needed to buy zrx - ethAmountToBuyZrx = findEthAmountNeededToBuyZrx(feeOrdersAndFillableAmounts, zrxAmountToBuyAsset); + zrxEthAmount = findEthAmountNeededToBuyZrx(feeOrdersAndFillableAmounts, zrxAmountToBuyAsset); } - /// find the eth amount needed to buy the affiliate fee - const ethAmountToBuyAffiliateFee = ethAmountToBuyAsset.mul(feePercentage).ceil(); - const totalEthAmountWithoutAffiliateFee = ethAmountToBuyAsset.plus(ethAmountToBuyZrx); - const ethAmountTotal = totalEthAmountWithoutAffiliateFee.plus(ethAmountToBuyAffiliateFee); - // divide into the assetBuyAmount in order to find rate of makerAsset / WETH - const ethPerAssetPrice = totalEthAmountWithoutAffiliateFee.div(assetBuyAmount); + // eth amount needed to buy the affiliate fee + const affiliateFeeEthAmount = assetEthAmount.mul(feePercentage).ceil(); + // eth amount needed for fees is the sum of affiliate fee and zrx fee + const feeEthAmount = affiliateFeeEthAmount.plus(zrxEthAmount); + // eth amount needed in total is the sum of the amount needed for the asset and the amount needed for fees + const totalEthAmount = assetEthAmount.plus(feeEthAmount); return { - totalEthAmount: ethAmountTotal, - feeEthAmount: ethAmountToBuyAffiliateFee, - ethPerAssetPrice, + assetEthAmount, + feeEthAmount, + totalEthAmount, }; } diff --git a/packages/asset-buyer/src/utils/order_provider_response_processor.ts b/packages/asset-buyer/src/utils/order_provider_response_processor.ts index 28f684f3c..25e85b2cc 100644 --- a/packages/asset-buyer/src/utils/order_provider_response_processor.ts +++ b/packages/asset-buyer/src/utils/order_provider_response_processor.ts @@ -44,19 +44,24 @@ export const orderProviderResponseProcessor = { let unsortedOrders = filteredOrders; // if an orderValidator is provided, use on chain information to calculate remaining fillable makerAsset amounts if (!_.isUndefined(orderValidator)) { - // TODO(bmillman): improvement - // try/catch this request and throw a more domain specific error const takerAddresses = _.map(filteredOrders, () => constants.NULL_ADDRESS); - const ordersAndTradersInfo = await orderValidator.getOrdersAndTradersInfoAsync( - filteredOrders, - takerAddresses, - ); - // take orders + on chain information and find the valid orders and remaining fillable maker asset amounts - unsortedOrders = getValidOrdersWithRemainingFillableMakerAssetAmountsFromOnChain( - filteredOrders, - ordersAndTradersInfo, - isMakerAssetZrxToken, - ); + try { + const ordersAndTradersInfo = await orderValidator.getOrdersAndTradersInfoAsync( + filteredOrders, + takerAddresses, + ); + // take orders + on chain information and find the valid orders and remaining fillable maker asset amounts + unsortedOrders = getValidOrdersWithRemainingFillableMakerAssetAmountsFromOnChain( + filteredOrders, + ordersAndTradersInfo, + isMakerAssetZrxToken, + ); + } catch (err) { + // Sometimes we observe this call to orderValidator fail with response `0x` + // Because of differences in Parity / Geth implementations, its very hard to tell if this response is a "system error" + // or a revert. In this case we just swallow these errors and fallback to partial fill information from the SRA. + // TODO(bmillman): report these errors so we have an idea of how often we're getting these failures. + } } // sort orders by rate // TODO(bmillman): optimization |