fix: a permit on the zero address never reads as ETH (closes #660)
Permit2 has no allowance of ETH, but the swap decoder read a permit's zero-address token as ETH. Its Allowance token line read ETH. A permit of 1 wei of the zero address before a V4 step of 5 ETH also stood as the Amount figure, which then read 0.000000000000000001 ETH. Such a permit now never stands as the Amount figure. Its lines give the amount in base units and name the zero address, as for a token nothing knows. Model: opus-5-5
This commit is contained in:
@@ -3310,6 +3310,98 @@ describe("uniswap decoder", () => {
|
||||
|
||||
expect(detail(result, "Amount").value).toBe("Up to 1000.0000 USDT");
|
||||
});
|
||||
|
||||
// https://git.eeqj.de/sneak/AutistMask/issues/660 — Permit2 has no
|
||||
// allowance of ETH, so a permit on the zero address reads as one on a
|
||||
// token nothing knows. On next at 53551c6 such a permit's Allowance
|
||||
// token line read ETH. A permit of 1 wei of the zero address before a
|
||||
// V4 step of 5 ETH made the Amount line read 0.000000000000000001 ETH.
|
||||
describe("a permit on the zero address", () => {
|
||||
const FIVE_ETH = 5000000000000000000n;
|
||||
// The lines of a permit of `amount` base units of the zero
|
||||
// address for the router.
|
||||
const zeroAddressLines = (amount) => [
|
||||
[
|
||||
"Permit2 allowance",
|
||||
amount + " base units (decimals unknown)",
|
||||
],
|
||||
["Allowance token", ZERO_ADDR],
|
||||
["Allowance spender", getAddress(ROUTER_ADDR)],
|
||||
];
|
||||
|
||||
test("a PERMIT2_PERMIT on the zero address names the address", () => {
|
||||
const result = decodeSteps(
|
||||
[0x00, 0x0a],
|
||||
[
|
||||
V3_600,
|
||||
encodePermit2(
|
||||
ZERO_ADDR,
|
||||
1000000000000000000n,
|
||||
ROUTER_ADDR,
|
||||
),
|
||||
],
|
||||
);
|
||||
expect(linesBetweenTokens(result)).toEqual([
|
||||
["Amount", "600.0000 USDT"],
|
||||
...zeroAddressLines("1000000000000000000"),
|
||||
]);
|
||||
expect(detail(result, "Allowance token").address).toBe(
|
||||
ZERO_ADDR,
|
||||
);
|
||||
});
|
||||
|
||||
test("a PERMIT2_PERMIT_BATCH entry on the zero address names the address", () => {
|
||||
const result = decodeSteps(
|
||||
[0x03, 0x00],
|
||||
[
|
||||
encodePermit2Batch(
|
||||
[
|
||||
[USDT_ADDR, USDT_600],
|
||||
[ZERO_ADDR, 1000000000000000000n],
|
||||
],
|
||||
ROUTER_ADDR,
|
||||
),
|
||||
V3_600,
|
||||
],
|
||||
);
|
||||
expect(linesBetweenTokens(result)).toEqual([
|
||||
["Amount", "600.0000 USDT"],
|
||||
...USDT_600_LINES,
|
||||
...zeroAddressLines("1000000000000000000"),
|
||||
]);
|
||||
});
|
||||
|
||||
test("a PERMIT2_PERMIT of 1 wei of the zero address, then a V4 step of 5 ETH the user settles, shows the 5 ETH", () => {
|
||||
const result = decodeSteps(
|
||||
[0x0a, 0x10],
|
||||
[
|
||||
encodePermit2(ZERO_ADDR, 1n, ROUTER_ADDR),
|
||||
encodeV4Swap(
|
||||
new Uint8Array([
|
||||
V4_SWAP_EXACT_IN_SINGLE_ID,
|
||||
V4_SETTLE_ID,
|
||||
V4_TAKE_ALL_ID,
|
||||
]),
|
||||
[
|
||||
encodeV4ExactInSingle(
|
||||
ZERO_ADDR,
|
||||
USDC_ADDR,
|
||||
FIVE_ETH,
|
||||
1n,
|
||||
),
|
||||
settle(ZERO_ADDR, FIVE_ETH, true),
|
||||
encodeV4TakeAll(USDC_ADDR, 1n),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
expect(detail(result, "Token In").value).toBe("ETH (native)");
|
||||
expect(linesBetweenTokens(result)).toEqual([
|
||||
["Amount", "5.0000 ETH"],
|
||||
...zeroAddressLines("1"),
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// https://git.eeqj.de/sneak/AutistMask/issues/359 — the output half, in
|
||||
|
||||
Reference in New Issue
Block a user