fix: the swap decoder shows the ETH of a WRAP_ETH that does not set the input side (closes #721)
A later WRAP_ETH of a stated amount now counts as a take from the sender. When it pays anyone but the router, it gets its own Moved from the sender lines, with the recipient on Moved to. When it pays the router, it joins the Amount line if Token In is ETH, and otherwise gets those lines too. When the router may already hold ETH, the amount reads Up to. A WRAP_ETH whose input this decoder cannot read gets a line saying the amount could not be decoded. A WRAP_ETH of CONTRACT_BALANCE states no amount and reads as before, so Uniswap's own routes do not change. Model: opus-5-5
This commit was merged in pull request #725.
This commit is contained in:
@@ -370,7 +370,8 @@ const PAID_ELSEWHERE = [
|
||||
"Steps",
|
||||
"Deadline",
|
||||
];
|
||||
// `lines` with the lines of one PERMIT2_TRANSFER_FROM after Amount.
|
||||
// `lines` with the lines of one PERMIT2_TRANSFER_FROM or later WRAP_ETH after
|
||||
// Amount.
|
||||
const withMove = (lines) =>
|
||||
lines.flatMap((l) =>
|
||||
l === "Amount"
|
||||
@@ -985,7 +986,7 @@ describe("what reaches the UNWRAP_WETH of the swap's WETH", () => {
|
||||
);
|
||||
|
||||
// The SWEEP pays the user the swap's WETH, so the UNWRAP_WETH unwraps the
|
||||
// WRAP_ETH's.
|
||||
// WRAP_ETH's. The WRAP_ETH's 1 ETH gets lines of its own.
|
||||
test("a SWEEP of the swap's WETH to the user, then a WRAP_ETH into the router, reads as ETH with no minimum", () => {
|
||||
const result = decode(
|
||||
execute(
|
||||
@@ -996,7 +997,10 @@ describe("what reaches the UNWRAP_WETH of the swap's WETH", () => {
|
||||
),
|
||||
);
|
||||
expect(result.name).toBe("Swap USDT → ETH");
|
||||
expect(labels(result)).toEqual(NO_MINIMUM_TO_USER);
|
||||
expect(labels(result)).toEqual(withMove(NO_MINIMUM_TO_USER));
|
||||
expect(detail(result, "Moved from the sender").value).toBe(
|
||||
"1.0000 ETH",
|
||||
);
|
||||
});
|
||||
|
||||
test("an UNWRAP_WETH into the router, then a WRAP_ETH of all its ETH to the user, reads as WETH with no minimum", () => {
|
||||
@@ -1097,7 +1101,9 @@ describe("what reaches the UNWRAP_WETH of the swap's WETH", () => {
|
||||
},
|
||||
);
|
||||
|
||||
// The user receives 0.5 WETH and the rest of the swap's output as ETH.
|
||||
// The user receives 0.5 WETH and the rest of the swap's output as ETH. The
|
||||
// router holds ETH when the WRAP_ETH runs, so the sender pays at most its
|
||||
// 0.5 ETH.
|
||||
test("an UNWRAP_WETH into the router, then a WRAP_ETH of 0.5 ETH to the user, reads as WETH with no minimum", () => {
|
||||
const result = decode(
|
||||
execute(
|
||||
@@ -1108,7 +1114,11 @@ describe("what reaches the UNWRAP_WETH of the swap's WETH", () => {
|
||||
),
|
||||
);
|
||||
expect(result.name).toBe("Swap USDT → WETH");
|
||||
expect(labels(result)).toEqual(NO_MINIMUM_TO_USER);
|
||||
expect(labels(result)).toEqual(withMove(NO_MINIMUM_TO_USER));
|
||||
expect(detail(result, "Moved from the sender").value).toBe(
|
||||
"Up to 0.5000 ETH",
|
||||
);
|
||||
expect(detail(result, "Moved to").value).toBe("The sender");
|
||||
});
|
||||
|
||||
// The UNWRAP_WETH pays the user the swap's WETH as ETH; the WRAP_ETH wraps
|
||||
@@ -1348,6 +1358,7 @@ describe("any token left in the router is not received", () => {
|
||||
),
|
||||
),
|
||||
left: tokenLine(WETH, "WETH"),
|
||||
spent: "1.0000 ETH",
|
||||
},
|
||||
// A SETTLE of OPEN_DELTA from the router pays only what the step
|
||||
// still owes of its currency when it runs.
|
||||
@@ -1516,8 +1527,8 @@ describe("any token left in the router is not received", () => {
|
||||
"Moved from the sender",
|
||||
]
|
||||
: ["Amount"]),
|
||||
// A later swap step the user pays for spends `spent` of a token
|
||||
// other than Token In.
|
||||
// A later swap step or WRAP_ETH the user pays for spends `spent`
|
||||
// of a token other than Token In.
|
||||
...(spent
|
||||
? ["Moved from the sender", "Token moved", "Moved to"]
|
||||
: []),
|
||||
|
||||
Reference in New Issue
Block a user