Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
edfd01014d |
@@ -1260,8 +1260,9 @@ user WETH, then an unwrap, shows WETH with the second swap's minimum. The
|
||||
minimum reads in ETH when that step paid all its WETH to the router. When it
|
||||
paid only part of it to the router, as a V4 step does that `TAKE`s some of its
|
||||
WETH to the user and the rest to the router, or paid the router WETH beside a
|
||||
payout the decoder cannot read, the swap shows ETH with no minimum, since the
|
||||
calldata states none for the ETH. A later step that sets the output side sets it
|
||||
payout the decoder cannot read, the swap shows ETH with no minimum: the decoder
|
||||
does not count how much of that step's minimum reaches the router, nor read the
|
||||
`UNWRAP_WETH`'s own minimum. A later step that sets the output side sets it
|
||||
anew. 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
|
||||
|
||||
@@ -1224,9 +1224,10 @@ function decode(data, toAddress, chainId, sources, fromAddress) {
|
||||
// again.
|
||||
let outputUnwrapped = false;
|
||||
// Where the step that set the output side paid its output: the
|
||||
// recipient of a swap step, as written, or of each TAKE and
|
||||
// TAKE_PORTION of it in a V4 step, with null for a payout of that
|
||||
// step this decoder did not read. A BALANCE_CHECK_ERC20 pays nobody.
|
||||
// recipient of a swap step, as written, or of each TAKE, TAKE_ALL and
|
||||
// TAKE_PORTION of it in a V4 step, a TAKE_ALL as paid to the sender,
|
||||
// with null for a payout of that step this decoder did not read. A
|
||||
// BALANCE_CHECK_ERC20 pays nobody.
|
||||
let outputRecipients = [];
|
||||
let hasV2OrV3ExactOut = false;
|
||||
let swapUndecoded = false;
|
||||
@@ -1800,9 +1801,10 @@ function decode(data, toAddress, chainId, sources, fromAddress) {
|
||||
// that step paid to the user, or to anyone else, stays
|
||||
// WETH, so when that step also paid some of its output
|
||||
// elsewhere, or made a payout this decoder did not read,
|
||||
// only part of it may be unwrapped. The calldata then
|
||||
// states no minimum for the ETH, and the output side keeps
|
||||
// no figure.
|
||||
// only part of it may be unwrapped. This decoder does not
|
||||
// count how much of that step's minimum then reaches the
|
||||
// router, nor read the UNWRAP_WETH's own minimum, so the
|
||||
// output side keeps no figure.
|
||||
const toRouter = (r) => present(r) && isRouter(r);
|
||||
if (
|
||||
present(outputToken) &&
|
||||
|
||||
@@ -603,6 +603,20 @@ describe("an UNWRAP_WETH makes the output ETH only when the router holds it", ()
|
||||
expect(detail(result, "Min. received").value).toBe("1.0000 ETH");
|
||||
});
|
||||
|
||||
// The SWEEP pays the user all the WETH the router holds, so the
|
||||
// UNWRAP_WETH finds none of it.
|
||||
test("a swap paying its WETH to the router, then a SWEEP of it to the user, then an UNWRAP_WETH, reads as WETH", () => {
|
||||
const result = decode(
|
||||
execute(
|
||||
swapToWeth(ADDRESS_THIS),
|
||||
sweep(WETH, MSG_SENDER),
|
||||
unwrapWeth(MSG_SENDER),
|
||||
),
|
||||
);
|
||||
expect(result.name).toBe("Swap USDT → WETH");
|
||||
expect(detail(result, "Min. received").value).toBe("1.0000 WETH");
|
||||
});
|
||||
|
||||
// The user receives the first step's WETH as WETH and the second's as
|
||||
// ETH. The second step sets the output side and pays its WETH to the
|
||||
// router, so the output reads as ETH with the second step's minimum.
|
||||
@@ -641,8 +655,9 @@ describe("an UNWRAP_WETH makes the output ETH only when the router holds it", ()
|
||||
});
|
||||
|
||||
// One V4 step buys at least 1 WETH and TAKEs 0.6 WETH to the user and the
|
||||
// rest to the router. The user receives 0.6 WETH and the rest as ETH, so
|
||||
// neither minimum is shown: the calldata states none for the ETH.
|
||||
// rest to the router. The user receives 0.6 WETH and the rest as ETH.
|
||||
// Neither minimum is shown: the decoder does not count how much of the
|
||||
// step's minimum reaches the router, nor read the UNWRAP_WETH's own.
|
||||
test("one V4 step paying part of its WETH to the user and the rest to the router, then an UNWRAP_WETH, reads as ETH with no minimum", () => {
|
||||
const result = decode(
|
||||
execute(
|
||||
@@ -699,6 +714,35 @@ describe("an UNWRAP_WETH makes the output ETH only when the router holds it", ()
|
||||
expect(result.name).toBe("Swap USDT → WETH");
|
||||
expect(detail(result, "Min. received").value).toBe("0.5000 WETH");
|
||||
});
|
||||
|
||||
// The EXECUTE_SUB_PLAN's own steps, which the decoder does not read, buy
|
||||
// the user USDC as well, so Token Out is not named.
|
||||
test("a swap paying its WETH to the router, then an UNWRAP_WETH, then an EXECUTE_SUB_PLAN, names no Token Out", () => {
|
||||
const subPlan = [
|
||||
0x21,
|
||||
coder.encode(
|
||||
["bytes", "bytes[]"],
|
||||
[
|
||||
"0x00",
|
||||
[
|
||||
v3SwapExactIn(
|
||||
MSG_SENDER,
|
||||
USDT_2000,
|
||||
USDC_1990,
|
||||
USDT,
|
||||
USDC,
|
||||
)[1],
|
||||
],
|
||||
],
|
||||
),
|
||||
];
|
||||
const result = decode(
|
||||
execute(swapToWeth(ADDRESS_THIS), unwrapWeth(MSG_SENDER), subPlan),
|
||||
);
|
||||
expect(result.name).toBe("Uniswap Swap");
|
||||
expect(detail(result, "Token Out").value).toBe(UNDECODED);
|
||||
expect(detail(result, "Min. received")).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
// https://git.eeqj.de/sneak/AutistMask/issues/606: any token a step pays the
|
||||
|
||||
Reference in New Issue
Block a user