fix: a swap split across steps the user pays for shows every amount it spends (closes #625)
The swap's Amount line took only the first swap step's amount. Each later step the user pays for now adds what it takes of Token In, and what it takes of another token, or an amount the decoder cannot tell, gets lines of its own. A V4 step counts every SETTLE paid by the user and every SETTLE_ALL, with or without a swap action. A step that may take from the sender what the decoder did not read leaves no Amount figure and gets one line saying so. Only a permit to the router that the router does not let fail still covers later takes of its token. Model: opus-5-5
This commit is contained in:
@@ -1189,14 +1189,8 @@ number. They can read:
|
||||
`amountOut`, the exact amount it buys.
|
||||
- `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 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.
|
||||
whole open delta", so the calldata states no quantity. Transaction Decoding
|
||||
below gives the steps whose amounts the line shows.
|
||||
- `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
|
||||
@@ -2374,10 +2368,11 @@ view would leave a wallet one click from deletion.
|
||||
- Site origin (bold, scheme and port included) + "wants to send a
|
||||
transaction"
|
||||
- Decoded action (if calldata is recognized): action name, token details,
|
||||
amounts, what each `PERMIT2_TRANSFER_FROM` moves and where to, steps,
|
||||
deadline, and unless a swap pays only the From address, a `Paid to` line
|
||||
for each other address it pays, or saying that a token stays in the router
|
||||
or who it pays is unknown (see Transaction Decoding)
|
||||
amounts, what each swap step the user pays for spends of a token other
|
||||
than `Token In`, what each `PERMIT2_TRANSFER_FROM` moves and where to,
|
||||
steps, deadline, and unless a swap pays only the From address, a `Paid to`
|
||||
line for each other address it pays, or saying that a token stays in the
|
||||
router or who it pays is unknown (see Transaction Decoding)
|
||||
- From: color dot + full address + etherscan link
|
||||
- Contract: color dot + full address + etherscan link, token symbol label if
|
||||
known; for a contract creation, the same sentence as on WaitTx
|
||||
@@ -3085,37 +3080,40 @@ Currently supported:
|
||||
as a swap paid in ETH does, but only when that amount is not
|
||||
`CONTRACT_BALANCE` and the router held no WETH from an earlier step when the
|
||||
`WRAP_ETH` ran: after two `WRAP_ETH`s of 0.5 ETH into the router, a swap of 1
|
||||
WETH from it reads as leaving the WETH there. The router pays a `SETTLE` of
|
||||
`OPEN_DELTA` (zero) only what its step still owes of that token when the
|
||||
`SETTLE` runs, so one from the router counts as spending the amounts the
|
||||
step's swap actions state they spend of that token only when every action in
|
||||
the step could be read, every swap action names the token it spends and the
|
||||
token it buys (a swap action with an empty path swaps nothing), the `SETTLE`
|
||||
is the step's only `SETTLE` or `SETTLE_ALL` of that token and comes after
|
||||
every swap action, no swap action buys that token, and the swap actions that
|
||||
spend it state a quantity together; otherwise it counts as spending nothing.
|
||||
So the rest of a V4 `SETTLE` of more than its swap spends, taken to the
|
||||
router, the WETH of a `WRAP_ETH`, and a token a swap pays the router on the
|
||||
way to the output, each stays in the router when later steps do not spend all
|
||||
of it, where anyone can take it in a later transaction. The router sends ETH
|
||||
as written, so a `TRANSFER` of `CONTRACT_BALANCE` of ETH always reverts and
|
||||
pays out nothing. A step paying a token to the V2 pair that the very next step
|
||||
spends, as a V2 exact-in of that token whose `amountIn` is `ALREADY_PAID`
|
||||
(zero) or `CONTRACT_BALANCE`, is a hop, not a payout: Uniswap's mixed routes
|
||||
pay the next V2 pair directly, and the router enforces that swap's own
|
||||
minimum. The decoder checks that the address paid is that pair, deriving it
|
||||
from the V2 factory and pair init code hash the network's routers were
|
||||
deployed with and the first two tokens of that step's path; a payment to any
|
||||
other address is named. (Sepolia's `UniversalRouterV1_2_V2Support` was
|
||||
deployed with placeholders for both values, so no V2 swap step can succeed on
|
||||
that router.) Every other payment counts, in whichever step and of whatever
|
||||
token, a share of the output included: an interface fee paid to another
|
||||
address by `PAY_PORTION`, `TRANSFER` or `TAKE_PORTION` is named, and the
|
||||
minimum reads `Min. paid out`, because the swap's minimum includes the fee.
|
||||
The minimum reads `Min. received` only when some step pays the transaction's
|
||||
sender (the From address on TxApproval, the sender the explorer reports on
|
||||
TransactionDetail) and no `Paid to` line is shown. `Paid to` lines after
|
||||
`Token Out` name each other address paid; one reads
|
||||
WETH from it reads as leaving the WETH there. A `SETTLE` of `OPEN_DELTA`
|
||||
(zero), and a `SETTLE_ALL`, pay only what the step still owes of their token
|
||||
when they run. The decoder takes that to be the amounts the step's swap
|
||||
actions state they spend of that token only when every action in the step
|
||||
could be read, every swap action names the token it spends and the token it
|
||||
buys (a swap action with an empty path swaps nothing), the `SETTLE` or
|
||||
`SETTLE_ALL` is the step's only `SETTLE` or `SETTLE_ALL` of that token and
|
||||
comes after every swap action, no swap action buys that token, no `TAKE`,
|
||||
`TAKE_ALL` or `TAKE_PORTION` in the step takes it (a `TAKE` of a stated amount
|
||||
adds to what the step owes), and the swap actions that spend it state a
|
||||
quantity together; otherwise it does not know the amount, and such a `SETTLE`
|
||||
from the router counts as spending nothing. So the rest of a V4 `SETTLE` of
|
||||
more than its swap spends, taken to the router, the WETH of a `WRAP_ETH`, and
|
||||
a token a swap pays the router on the way to the output, each stays in the
|
||||
router when later steps do not spend all of it, where anyone can take it in a
|
||||
later transaction. The router sends ETH as written, so a `TRANSFER` of
|
||||
`CONTRACT_BALANCE` of ETH always reverts and pays out nothing. A step paying a
|
||||
token to the V2 pair that the very next step spends, as a V2 exact-in of that
|
||||
token whose `amountIn` is `ALREADY_PAID` (zero) or `CONTRACT_BALANCE`, is a
|
||||
hop, not a payout: Uniswap's mixed routes pay the next V2 pair directly, and
|
||||
the router enforces that swap's own minimum. The decoder checks that the
|
||||
address paid is that pair, deriving it from the V2 factory and pair init code
|
||||
hash the network's routers were deployed with and the first two tokens of that
|
||||
step's path; a payment to any other address is named. (Sepolia's
|
||||
`UniversalRouterV1_2_V2Support` was deployed with placeholders for both
|
||||
values, so no V2 swap step can succeed on that router.) Every other payment
|
||||
counts, in whichever step and of whatever token, a share of the output
|
||||
included: an interface fee paid to another address by `PAY_PORTION`,
|
||||
`TRANSFER` or `TAKE_PORTION` is named, and the minimum reads `Min. paid out`,
|
||||
because the swap's minimum includes the fee. The minimum reads `Min. received`
|
||||
only when some step pays the transaction's sender (the From address on
|
||||
TxApproval, the sender the explorer reports on TransactionDetail) and no
|
||||
`Paid to` line is shown. `Paid to` lines after `Token Out` name each other
|
||||
address paid; one reads
|
||||
`The bridge, which pays the deposit's recipient on another network` for a
|
||||
bridge deposit; one reads, for example,
|
||||
`The router, 2000.0000 USDT from the sender (later steps may not spend all of it)`
|
||||
@@ -3127,11 +3125,48 @@ Currently supported:
|
||||
name); and one more reads `Unknown (could not be decoded)` when a step that
|
||||
may pay an address went unread. When no step pays anyone, a single line reads
|
||||
`Unknown (not named in the calldata)`. Wherever there is a `Paid to` line, the
|
||||
minimum reads `Min. paid out`. After the `Amount` line (after `Token In` when
|
||||
there is none), each `PERMIT2_TRANSFER_FROM` but one into the router, in step
|
||||
order, gives three lines: `Moved from the sender`, the amount it moves, for
|
||||
example `1000000.0000 USDT`; `Token moved`, giving the token's address as the
|
||||
`Token In` line does; and `Moved to`, which reads
|
||||
minimum reads `Min. paid out`. The `Amount` line gives the 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 (see
|
||||
Display Consistency). A V2 exact-out step gives its `amountInMax`, and a V4
|
||||
swap step the `amountIn` of the swap action that spends its input currency.
|
||||
Each later V2 or V3 exact-in or V2 exact-out step whose `payerIsUser` is true
|
||||
also takes its amount, found in the same way, from the user's wallet. So does
|
||||
every V4 step but the one that sets the input side, with a swap action or
|
||||
without: it takes what its `SETTLE`s paid by the user (`payerIsUser` true) and
|
||||
its `SETTLE_ALL`s pay, for each token on its own. A `SETTLE` 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. What a step takes of
|
||||
`Token In` is added to the line's, unless a `PERMIT2_PERMIT` set the input
|
||||
side, whose amount the line keeps. A permit whose spender is the router and
|
||||
which the router does not let fail caps what the router may take of its token
|
||||
after it; any other permit caps nothing the router takes. So 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 either amount is not a quantity (a V4 open delta,
|
||||
`ALREADY_PAID`, or an amount the decoder does not know), the total is not
|
||||
known and there is no `Amount` line. A step paid from the router spends what
|
||||
the router holds and adds nothing, and so does a V2 exact-in whose `amountIn`
|
||||
is `ALREADY_PAID`, which takes nothing from the user. What a step takes of a
|
||||
token other than `Token In`, or of `Token In` when the decoder does not know
|
||||
the amount or when a permit that caps nothing set the input side, gives three
|
||||
lines after the `Amount` line (after `Token In` when there is none), in step
|
||||
order: `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 step may also take
|
||||
from the user's wallet what the decoder did not read: a V4 step, other than
|
||||
the one that sets the input side, 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 V2 exact-out step or a `PERMIT2_TRANSFER_FROM` whose input it cannot read;
|
||||
and every `PERMIT2_TRANSFER_FROM_BATCH`. Each such step gives one
|
||||
`Moved from the sender` line, among those lines in step order, reading
|
||||
`Unknown (could not be decoded)`, and there is then no `Amount` line, whose
|
||||
figure might be too low. Then each `PERMIT2_TRANSFER_FROM` but one into the
|
||||
router, in step order, gives three lines: `Moved from the sender`, the amount
|
||||
it moves, for example `1000000.0000 USDT`; `Token moved`, giving the token's
|
||||
address as the `Token In` line does; and `Moved to`, which reads
|
||||
`The V2 pair the next swap spends` for a hop and `The sender` for `address(1)`
|
||||
on every router but `UniversalRouterV1`, and otherwise gives the address. A
|
||||
move into the router needs none of them, because its `Paid to` line and
|
||||
|
||||
Reference in New Issue
Block a user