fix: the swap decoder names where a WRAP_ETH pays and shows a V4 step's ETH as a maximum when the router may hold ETH (closes #665)
check / check (push) Waiting to run
e2e / e2e-chrome (push) Waiting to run
e2e / e2e-firefox (push) Waiting to run

A `WRAP_ETH` that sets the input side and pays its WETH to anyone but
the router names that recipient on its `Moved to` line.

V4 pays a `SETTLE` of ETH from the router's own ETH, whichever payer it
names. When an earlier step may leave ETH in the router, the ETH that
the user pays a later V4 step gets lines of its own. Their
`Moved from the sender` line reads `Up to <amount>`, or
`Unknown (could not be decoded)` when the amount is not known. The
decoder never subtracts the router's ETH from that amount. Without such
an earlier step, the lines read as before.

Model: opus-5-5
This commit was merged in pull request #679.
This commit is contained in:
2026-11-03 03:02:10 +01:00
parent d89099d90a
commit ae0b86a8ac
3 changed files with 447 additions and 67 deletions
+56 -45
View File
@@ -1268,6 +1268,9 @@ see Transaction Decoding), do not always read as a number. They can read:
wording. When a V2 or V3 exact-out step sets `Min. received`, that line shows
its `amountOut`, the exact amount it buys. When earlier swap steps also pay
that token to the user, the line shows the sum (see Transaction Decoding).
When the router may hold ETH from an earlier step, the `Moved from the sender`
line of ETH that the user pays a V4 step also reads `Up to <amount>` (see
Transaction Decoding).
- `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. Transaction Decoding
@@ -3524,23 +3527,26 @@ Currently supported:
of any amount but `OPEN_DELTA` pays that amount, and a `SETTLE` of
`OPEN_DELTA` or a `SETTLE_ALL` pays what the step owes, as above. So a V4 step
that swaps 400 USDT, with a `SETTLE` of 5,000 USDT paid by the user and the
rest taken to another address, reads `5000.0000 USDT`. A later step that pays
an ERC-20 token from the router takes none of that token from the user's
wallet. A V2 exact-in whose `amountIn` is `ALREADY_PAID` takes nothing either.
A V4 `SETTLE` of ETH paid from the router still takes from the user's wallet,
since the router holds the transaction's value. When the decoder does not know
the amount of such a `SETTLE`, as for `CONTRACT_BALANCE`, that `SETTLE` counts
as a later step's take. When an earlier step left ETH in the router, that ETH
may pay part of a `SETTLE` of ETH paid from the router. That `SETTLE` then
gets lines of its own, with `Up to` before its amount. A later take of
`Token In` that only the user's wallet pays is added to the total while both
are quantities: a V3 exact-in of 600 USDT and a V2 exact-in of 400 USDT, both
paid by the user, read `1000.0000 USDT`. When the decoder does not know a
take's amount, the total is not known and there is no `Amount` line. A
`PERMIT2_PERMIT` names `Token In` only when its amount, `Unlimited` included,
stands as the `Amount` figure in place of the total, which it does only in the
plain shape of Uniswap's own routes: it comes before the step that sets the
input side, it is the only `PERMIT2_PERMIT` in the transaction and there is no
rest taken to another address, reads `5000.0000 USDT`. V4 pays a `SETTLE` of
ETH from the router's own ETH, whichever payer it names. So when the router
may hold ETH from an earlier step (see above), the ETH that the user pays a V4
step gets lines of its own (see below). A later step that pays an ERC-20 token
from the router takes none of that token from the user's wallet. A V2 exact-in
whose `amountIn` is `ALREADY_PAID` takes nothing either. A V4 `SETTLE` of ETH
paid from the router still takes from the user's wallet, since the router
holds the transaction's value. When the decoder does not know the amount of
such a `SETTLE`, as for `CONTRACT_BALANCE`, that `SETTLE` counts as a later
step's take. When an earlier step left ETH in the router, that ETH may pay
part of a `SETTLE` of ETH paid from the router. That `SETTLE` then gets lines
of its own, with `Up to` before its amount. A later take of `Token In` that
only the user's wallet pays is added to the total while both are quantities: a
V3 exact-in of 600 USDT and a V2 exact-in of 400 USDT, both paid by the user,
read `1000.0000 USDT`. When the decoder does not know a take's amount, the
total is not known and there is no `Amount` line. A `PERMIT2_PERMIT` names
`Token In` only when its amount, `Unlimited` included, stands as the `Amount`
figure in place of the total, which it does only in the plain shape of
Uniswap's own routes: it comes before the step that sets the input side, it is
the only `PERMIT2_PERMIT` in the transaction and there is no
`PERMIT2_PERMIT_BATCH`, its spender is the router, the router may not let it
fail, no step before it takes its token, a `PERMIT2_TRANSFER_FROM` of it
included, or a token the decoder does not know, and the decoder reads every
@@ -3570,34 +3576,39 @@ Currently supported:
that is not a quantity (a V4 open delta, `ALREADY_PAID`, which keep their
wording on the `Amount` line, or no stated amount, as of a V4 exact-out step);
an ETH take whose line reads `Up to` (see above); and one whose amount the
decoder does not know. When there is no `Amount` line, each take the total
counts gets them too, so that every amount the decoder reads is shown: the
amount the step that sets the input side states, when it is a quantity and the
user pays that step (a V2 or V3 step whose `payerIsUser` is true, a V4 step
the user pays some of its input token, or a `WRAP_ETH`, whose ETH comes from
the transaction's value), and each later take of `Token In` added to it. A
step that sets the input side gets none when the user pays it none of its
input token. A `PERMIT2_PERMIT` the decoder cannot read, then V3 exact-ins of
600 USDT and 400 DAI paid by the user, give lines for both amounts. When the
step that sets the input side states no amount, the user pays it some of its
input token, and there is no `Amount` line, that step gets them too whenever
another take's lines give a figure, or a `PERMIT2_TRANSFER_FROM` of its token
gives one, on the lines below or, into the router, on its `Paid to` line, so
that figure cannot read as all that leaves. When it states no amount and the
user pays it none of its input token, that step never gets them, with a permit
or without. They come in step order, except that the step that sets the input
side comes first when it has them, followed, when there is no `Amount` line,
by the other takes the total counts: `Moved from the sender`, its amount,
worded as the `Amount` line words one, or `Unknown (could not be decoded)`
when the decoder does not know it; `Token moved`, giving the token's address
as the `Token In` line does; and `Moved to`, which reads
`The swap step that spends it`. A token the decoder does not know gives the
`Moved from the sender` line alone. A step may also take from the user's
wallet what the decoder did not read: a V4 step whose input or one of whose
`SETTLE`s or `SETTLE_ALL`s it cannot read, which the router still runs; a V2
or V3 exact-in or exact-out step or a `PERMIT2_TRANSFER_FROM` whose input it
cannot read, such as a V3 step whose path is shorter than one token address or
has bytes after its last hop; every `PERMIT2_TRANSFER_FROM_BATCH`; every
decoder does not know. ETH that the user pays a V4 step when the router may
hold ETH gets these three lines too. When there is no `Amount` line, each take
the total counts gets them too, so that every amount the decoder reads is
shown: the amount the step that sets the input side states, when it is a
quantity and the user pays that step (a V2 or V3 step whose `payerIsUser` is
true, a V4 step the user pays some of its input token, or a `WRAP_ETH`, whose
ETH comes from the transaction's value), and each later take of `Token In`
added to it. A step that sets the input side gets none when the user pays it
none of its input token. A `PERMIT2_PERMIT` the decoder cannot read, then V3
exact-ins of 600 USDT and 400 DAI paid by the user, give lines for both
amounts. When the step that sets the input side states no amount, the user
pays it some of its input token, and there is no `Amount` line, that step gets
them too whenever another take's lines give a figure, or a
`PERMIT2_TRANSFER_FROM` of its token gives one, on the lines below or, into
the router, on its `Paid to` line, so that figure cannot read as all that
leaves. When it states no amount and the user pays it none of its input token,
that step never gets them, with a permit or without. They come in step order,
except that the step that sets the input side comes first when it has them,
followed, when there is no `Amount` line, by the other takes the total counts:
`Moved from the sender`, its amount, worded as the `Amount` line words one, or
`Unknown (could not be decoded)` when the decoder does not know it;
`Token moved`, giving the token's address as the `Token In` line does; and
`Moved to`, which reads `The swap step that spends it`. For ETH that the user
pays a V4 step when the router may hold ETH, `Moved from the sender` reads
`Up to <amount>` for a known amount. For a `WRAP_ETH` that pays its WETH to
anyone but the router, `Moved to` names that recipient instead: `The sender`
for `address(1)`, and otherwise the address. A token the decoder does not know
gives the `Moved from the sender` line alone. A step may also take from the
user's wallet what the decoder did not read: a V4 step whose input or one of
whose `SETTLE`s or `SETTLE_ALL`s it cannot read, which the router still runs;
a V2 or V3 exact-in or exact-out step or a `PERMIT2_TRANSFER_FROM` whose input
it cannot read, such as a V3 step whose path is shorter than one token address
or has bytes after its last hop; every `PERMIT2_TRANSFER_FROM_BATCH`; every
`EXECUTE_SUB_PLAN`, wherever it stands; and every step it fails on. Each such
step gives one `Moved from the sender` line among those, reading
`Unknown (could not be decoded)`. That line, or any line for a token the