fix: a V4 step of chained swap actions shows what the user receives (closes #563)
A V4 step's input side is what SETTLE or SETTLE_ALL names, else the one currency its swap actions spend and never buy; its output side is what TAKE or TAKE_ALL names, else the one they buy and never spend. Amount and Min. received come from those actions, summed where several state one. An unread swap action leaves the sides to SETTLE, SETTLE_ALL, TAKE and TAKE_ALL, with no figure. A step with a swap action always sets the output side, sets the input side only when no earlier step set it, and sets a side its rules leave unknown as unknown with no figure. SWAP_EXACT_OUT is now read as spending its first path entry, not its last. Model: opus-5-5
This commit is contained in:
@@ -1168,11 +1168,13 @@ read:
|
||||
- `All available (V4 open delta)`: the swap's `Amount` line, when the amount it
|
||||
shows is a V4 exact-in `amountIn` of zero. V4 reads that zero as "use the
|
||||
whole open delta", so the calldata states no quantity. The line shows the
|
||||
amount of one step that names an input token or amount: the last
|
||||
`PERMIT2_PERMIT` step if there is one, otherwise the first V2 or V3 exact-in,
|
||||
V2 exact-out, `WRAP_ETH` or V4 swap step. A V2 exact-out step gives its
|
||||
`amountInMax`, and a V4 swap step the `amountIn` of its first readable
|
||||
exact-in action.
|
||||
amount of the step that sets the input side: the last `PERMIT2_PERMIT` step if
|
||||
there is one, otherwise the first V2 or V3 exact-in, V2 exact-out, `WRAP_ETH`
|
||||
or V4 swap step that names an input token or amount. A V4 step with a swap
|
||||
action sets the input side when no earlier step set it, even when it names
|
||||
neither, as described below. A V2 exact-out step gives its `amountInMax`, and
|
||||
a V4 swap step the `amountIn` of the swap action that spends its input
|
||||
currency.
|
||||
- `Whatever an earlier step sent to the pair (V2 already paid)`: the swap's
|
||||
`Amount` line, when the amount it shows is a V2 exact-in `amountIn` of zero.
|
||||
The router reads that zero as "the pair already holds the input tokens": the
|
||||
@@ -1194,16 +1196,38 @@ The swap's `Token In` and `Token Out` lines name a currency, not an amount; each
|
||||
reads `Unknown (not named in the calldata)` when the decoder found no token for
|
||||
that side, or `Unknown (could not be decoded)` instead when a V4 swap action in
|
||||
the transaction could not be read (see Transaction Decoding below). A V4 step
|
||||
whose swap action could not be read still sets each side as a swap step does,
|
||||
and a side its `SETTLE` or `TAKE` did not name is then unknown: no other step's
|
||||
token or figure is shown for it. An `UNWRAP_WETH` step makes `Token Out` ETH
|
||||
only when the output side is WETH, on mainnet or Sepolia, or when no step set
|
||||
the output side; a WETH `Min. received` figure then reads in ETH. Otherwise
|
||||
`Token Out` and `Min. received` keep the output side's own token and figure,
|
||||
whether the swap was paid in ETH or in a token: a V2 exact-out swap that buys
|
||||
USDC and then unwraps the WETH it did not spend shows USDC. The token permission
|
||||
warning on the signature screen has its own amount wording, including `Unknown`;
|
||||
the SignApproval section below describes it.
|
||||
with a swap action always sets the output side, and sets the input side only
|
||||
when no earlier step set it. It finds each side by three rules:
|
||||
|
||||
1. Its input side is the currency its `SETTLE` or `SETTLE_ALL` names, or else
|
||||
the one currency that some swap action in the step spends and none buys. Its
|
||||
output side is the currency its `TAKE` or `TAKE_ALL` names, or else the one
|
||||
currency that some swap action buys and none spends. If there is not exactly
|
||||
one such currency, that side is unknown, and the step sets it as unknown with
|
||||
no figure. A step that buys WETH with USDT and USDC with that WETH, with
|
||||
nothing naming its sides, reads `Swap USDT → USDC`.
|
||||
2. Its `Amount` is the `amountIn` of the swap action that spends the input
|
||||
currency. If several exact-in actions spend it, each with a stated amount, it
|
||||
is their sum; in any other case the step gives no `Amount`. The decoder reads
|
||||
no amount from an exact-out action, and an open delta is not a stated amount.
|
||||
Its `Min. received` is found the same way, from the `amountOutMin` of the
|
||||
actions that buy the output currency.
|
||||
3. If any swap action in the step could not be read, only `SETTLE`,
|
||||
`SETTLE_ALL`, `TAKE` and `TAKE_ALL` name its sides, and the step gives no
|
||||
`Amount` or `Min. received`. A side they did not name is unknown, and the
|
||||
step sets it as unknown with no figure.
|
||||
|
||||
A V4 step with no swap action sets only the sides its `SETTLE`, `SETTLE_ALL`,
|
||||
`TAKE` or `TAKE_ALL` names.
|
||||
|
||||
An `UNWRAP_WETH` step makes `Token Out` ETH only when the output side is WETH,
|
||||
on mainnet or Sepolia, or when no step set the output side; a WETH
|
||||
`Min. received` figure then reads in ETH. Otherwise `Token Out` and
|
||||
`Min. received` keep the output side's own token and figure, whether the swap
|
||||
was paid in ETH or in a token: a V2 exact-out swap that buys USDC and then
|
||||
unwraps the WETH it did not spend shows USDC. The token permission warning on
|
||||
the signature screen has its own amount wording, including `Unknown`; the
|
||||
SignApproval section below describes it.
|
||||
|
||||
The swap's `Deadline` line is the router's deadline as a UTC date and time, e.g.
|
||||
`2026-02-27 08:25:51`. A JavaScript date reaches only to 275760-09-13 00:00:00
|
||||
|
||||
Reference in New Issue
Block a user