-
Notifications
You must be signed in to change notification settings - Fork 466
[asset-swapper] clip native fill data #2565
Conversation
6996a30
to
77995b9
Compare
packages/asset-swapper/src/utils/market_operation_utils/fills.ts
Outdated
Show resolved
Hide resolved
packages/asset-swapper/src/utils/market_operation_utils/path_optimizer.ts
Outdated
Show resolved
Hide resolved
f9ce57d
to
bf626a0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really appreciate your swift PR
// targetInput can be less than the order size | ||
// whilst the penalty is constant, it affects the adjusted output | ||
// only up until the target has been exhausted. | ||
// A large order and an order at the exact target should be penalized |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should not be penalized the same?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
they should be penalized the same, since the cost is constant and the amount is constant. Where having a bigger order size is no advantage.
// the same. | ||
const clippedInput = BigNumber.min(targetInput, input); | ||
// scale the clipped output inline with the input | ||
const clippedOutput = clippedInput.dividedBy(input).times(output); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we be concerned about rounding errors with this operation? of does BigNumber prevent rounding issues?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These remain very precise, but I could go either way in having these as whole base units
which would lose precision but not necessarily have too much of an impact.
@@ -96,7 +96,7 @@ function clipFillAdjustedOutput(fill: Fill, remainingInput: BigNumber): BigNumbe | |||
return fill.adjustedOutput; | |||
} | |||
const penalty = fill.adjustedOutput.minus(fill.output); | |||
return fill.output.times(remainingInput.div(fill.input)).plus(penalty); | |||
return remainingInput.times(fill.rate).plus(penalty); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this function modified? based on my understanding, it should not impact nativeOrdersToPath
which is the core function that you changed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find it just easier to reason about. input * rate = output
, versus scaling the previous output by the proportion of remaining vs total.
Description
There is a scenario where perfectly sized Native orders were penalized more aggressively than they should have been.
The previous behaviour was as follows:
In the scenario where the user wishes to sell
2000
theSMALL_ORDER
should be penalized overBIG_ORDER
andBIG_ORDER
should be favoured.In the scenario where the user wishes to sell
200
bothSMALL_ORDER
andBIG_ORDER
are sufficient and either is acceptable to fill.We effectively bring large orders in line with small orders when they completely cover the requested amount.
Issue
The following behaviour caused perfectly sized orders to disappear:
adjustedRate
, then a subset of native orders are chosen (enough to fill the requested amount).rate
orders were dropped in 2), they would no longer be present when finding a path.