Merge pull request #2500 from 0xProject/fix/asset-swapper/native-order-prune

[asset-swapper] Fix native fill prune
This commit is contained in:
Lawrence Forman
2020-02-27 13:38:49 -05:00
committed by GitHub
2 changed files with 11 additions and 1 deletions

View File

@@ -1,4 +1,13 @@
[ [
{
"version": "4.3.2",
"changes": [
{
"note": "Fix order native pruning by fill amount",
"pr": 2500
}
]
},
{ {
"timestamp": 1582677073, "timestamp": 1582677073,
"version": "4.3.1", "version": "4.3.1",

View File

@@ -386,8 +386,8 @@ function createBuyPathFromNativeOrders(
function pruneNativeFills(fills: Fill[], fillAmount: BigNumber, dustFractionThreshold: number): Fill[] { function pruneNativeFills(fills: Fill[], fillAmount: BigNumber, dustFractionThreshold: number): Fill[] {
const minInput = fillAmount.times(dustFractionThreshold); const minInput = fillAmount.times(dustFractionThreshold);
const totalInput = ZERO_AMOUNT;
const pruned = []; const pruned = [];
let totalInput = ZERO_AMOUNT;
for (const fill of fills) { for (const fill of fills) {
if (totalInput.gte(fillAmount)) { if (totalInput.gte(fillAmount)) {
break; break;
@@ -395,6 +395,7 @@ function pruneNativeFills(fills: Fill[], fillAmount: BigNumber, dustFractionThre
if (fill.input.lt(minInput)) { if (fill.input.lt(minInput)) {
continue; continue;
} }
totalInput = totalInput.plus(fill.input);
pruned.push(fill); pruned.push(fill);
} }
return pruned; return pruned;