fix: a V4 step that spends some of its output currency shows no Min. received (closes #574)
A V4 step's Min. received was the sum of the minimums of the swap actions that buy its output currency, even when another swap action in the same step spends some of that currency. The user then receives less than that figure. decodeV4Swap() now gives no minimum when a swap action in the step also spends the output currency, as it already does for other minimums it cannot state. A multi-hop action counts only the currency it spends and the one it ends with, so a path through an intermediate currency is not read as spending it. Model: opus-5-5
This commit was merged in pull request #667.
This commit is contained in:
+10
-6
@@ -953,7 +953,9 @@ function totalAmount(amounts) {
|
||||
// 2. Amount is the amountIn of the swap action that spends Token In. If
|
||||
// several exact-in actions spend it, each with a stated amount, it is
|
||||
// their sum; in any other case there is none. Min. received is the same
|
||||
// for amountOutMin and the actions that buy Token Out.
|
||||
// for amountOutMin and the actions that buy Token Out, except that there
|
||||
// is none when a swap action in the step also spends Token Out: the step
|
||||
// then does not pay out all that those actions buy.
|
||||
// 3. If any swap action in the step cannot be read, only SETTLE, SETTLE_ALL,
|
||||
// TAKE and TAKE_ALL name the sides, and there is no Amount or Min.
|
||||
// received.
|
||||
@@ -1187,11 +1189,13 @@ function decodeV4Swap(input) {
|
||||
const boughtOnly = currenciesNotIn(bought, spent);
|
||||
if (present(takeToken) || boughtOnly.length === 1) {
|
||||
tokenOut = present(takeToken) ? takeToken : boughtOnly[0];
|
||||
amountOutMin = totalAmount(
|
||||
swaps
|
||||
.filter((s) => s.tokenOut === tokenOut)
|
||||
.map((s) => s.amountOutMin),
|
||||
);
|
||||
if (!spent.includes(tokenOut)) {
|
||||
amountOutMin = totalAmount(
|
||||
swaps
|
||||
.filter((s) => s.tokenOut === tokenOut)
|
||||
.map((s) => s.amountOutMin),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user