diff options
author | Brandon Millman <brandon.millman@gmail.com> | 2018-10-04 05:50:59 +0800 |
---|---|---|
committer | Brandon Millman <brandon.millman@gmail.com> | 2018-10-04 05:51:24 +0800 |
commit | 260db053fe45ae8d5973207b43d762d905b28cd8 (patch) | |
tree | c3e602501e895d39a31f0ee6879b415fcf95ff46 /packages/asset-buyer/src | |
parent | 57b4396193b731d97f73f4e3648a8dbdc1f589ac (diff) | |
download | dexon-sol-tools-260db053fe45ae8d5973207b43d762d905b28cd8.tar dexon-sol-tools-260db053fe45ae8d5973207b43d762d905b28cd8.tar.gz dexon-sol-tools-260db053fe45ae8d5973207b43d762d905b28cd8.tar.bz2 dexon-sol-tools-260db053fe45ae8d5973207b43d762d905b28cd8.tar.lz dexon-sol-tools-260db053fe45ae8d5973207b43d762d905b28cd8.tar.xz dexon-sol-tools-260db053fe45ae8d5973207b43d762d905b28cd8.tar.zst dexon-sol-tools-260db053fe45ae8d5973207b43d762d905b28cd8.zip |
Add additional test for slippage
Diffstat (limited to 'packages/asset-buyer/src')
-rw-r--r-- | packages/asset-buyer/src/utils/buy_quote_calculator.ts | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/packages/asset-buyer/src/utils/buy_quote_calculator.ts b/packages/asset-buyer/src/utils/buy_quote_calculator.ts index 53f2228e9..5a531e000 100644 --- a/packages/asset-buyer/src/utils/buy_quote_calculator.ts +++ b/packages/asset-buyer/src/utils/buy_quote_calculator.ts @@ -92,16 +92,16 @@ function calculateRate( assetBuyAmount: BigNumber, feePercentage: number, ): BigNumber { - // find the total eth and zrx needed to buy assetAmount from the resultOrders from left to right (best rate to worst rate) - const [minEthAmountToBuyAsset, minZrxAmountToBuyAsset] = findEthAndZrxAmountNeededToBuyAsset( + // find the total eth and zrx needed to buy assetAmount from the resultOrders from left to right + const [ethAmountToBuyAsset, zrxAmountToBuyAsset] = findEthAndZrxAmountNeededToBuyAsset( ordersAndFillableAmounts, assetBuyAmount, ); // find the total eth needed to buy fees - const minEthAmountToBuyFees = findEthAmountNeededToBuyFees(feeOrdersAndFillableAmounts, minZrxAmountToBuyAsset); - const finalMinEthAmount = minEthAmountToBuyAsset.plus(minEthAmountToBuyFees).mul(feePercentage + 1); + const ethAmountToBuyFees = findEthAmountNeededToBuyFees(feeOrdersAndFillableAmounts, zrxAmountToBuyAsset); + const ethAmount = ethAmountToBuyAsset.plus(ethAmountToBuyFees).mul(feePercentage + 1); // divide into the assetBuyAmount in order to find rate of makerAsset / WETH - const result = assetBuyAmount.div(finalMinEthAmount); + const result = assetBuyAmount.div(ethAmount); return result; } @@ -156,7 +156,7 @@ function findEthAndZrxAmountNeededToBuyAsset( const zrxAmountForThisOrder = amountToFill.mul(order.takerFee).dividedToIntegerBy(order.makerAssetAmount); return { ethAmount: acc.ethAmount.plus(ethAmountForThisOrder), - zrxAmount: acc.ethAmount.plus(zrxAmountForThisOrder), + zrxAmount: acc.zrxAmount.plus(zrxAmountForThisOrder), remainingAssetBuyAmount: BigNumber.max( constants.ZERO_AMOUNT, acc.remainingAssetBuyAmount.minus(amountToFill), |