Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c9b6cebbf8 |
+55
-17
@@ -2197,24 +2197,31 @@ describe("uniswap decoder", () => {
|
||||
);
|
||||
|
||||
// https://git.eeqj.de/sneak/AutistMask/issues/655 — a
|
||||
// PERMIT2_TRANSFER_FROM before the permit moves the permit's token
|
||||
// under whatever allowance the router already had, so it may move
|
||||
// PERMIT2_TRANSFER_FROM of the permit's token before the permit moves
|
||||
// it under whatever allowance the router already had, so it may move
|
||||
// more than the permit's amount. The permit's amount then does not
|
||||
// stand, and the Amount line gives the total the steps take, as with
|
||||
// no permit. On next at f53b503 the Amount line read the permit's
|
||||
// 600.0000 USDT, and the permit got no lines of its own.
|
||||
// no permit. On next at f53b503 the first two rows read the permit's
|
||||
// 600.0000 USDT as the Amount figure, with no lines for the permit.
|
||||
// One after the permit, as in Uniswap's own V2 routes, moves no more
|
||||
// than the permit's amount, and one of another token before it moves
|
||||
// none of the permit's token, so in the last two rows the permit's
|
||||
// amount stands.
|
||||
const USDT_2000 = 2000000000n;
|
||||
// A PERMIT2_TRANSFER_FROM of `amount` of USDT to `recipient`.
|
||||
const permit2TransferFrom = (recipient, amount) =>
|
||||
// The V2 pair of WETH and USDC on Ethereum Mainnet.
|
||||
const WETH_USDC_PAIR = "0xB4e16d0168e52d35CaCD2c6185b44281Ec28C9Dc";
|
||||
// A PERMIT2_TRANSFER_FROM of `amount` of `token` to `recipient`.
|
||||
const permit2TransferFrom = (token, recipient, amount) =>
|
||||
coder.encode(
|
||||
["address", "address", "uint160"],
|
||||
[USDT_ADDR, recipient, amount],
|
||||
[token, recipient, amount],
|
||||
);
|
||||
test.each([
|
||||
{
|
||||
kind: "a PERMIT2_TRANSFER_FROM of 2,000 USDT into the router, then a PERMIT2_PERMIT of 600 USDT and a V3 exact-in of 2,000 USDT paid from the router,",
|
||||
kind: "a PERMIT2_TRANSFER_FROM of 2,000 USDT into the router, then a PERMIT2_PERMIT of 600 USDT and a V3 exact-in of 2,000 USDT paid from the router, shows the total the steps take and the permit's own lines",
|
||||
commands: [0x02, 0x0a, 0x00],
|
||||
inputs: [
|
||||
permit2TransferFrom(ROUTER_ADDR, USDT_2000),
|
||||
permit2TransferFrom(USDT_ADDR, ROUTER_ADDR, USDT_2000),
|
||||
encodePermit2(USDT_ADDR, USDT_600, ROUTER_ADDR),
|
||||
coder.encode(
|
||||
["address", "uint256", "uint256", "bytes", "bool"],
|
||||
@@ -2230,9 +2237,10 @@ describe("uniswap decoder", () => {
|
||||
lines: [["Amount", "2000.0000 USDT"], ...USDT_600_LINES],
|
||||
},
|
||||
{
|
||||
kind: "a PERMIT2_TRANSFER_FROM of 2,000 USDT to another address, then a PERMIT2_PERMIT of 600 USDT and a V3 exact-in of 600 USDT,",
|
||||
kind: "a PERMIT2_TRANSFER_FROM of 2,000 USDT to another address, then a PERMIT2_PERMIT of 600 USDT and a V3 exact-in of 600 USDT, shows the total the steps take and the permit's own lines",
|
||||
commands: [0x02, 0x0a, 0x00],
|
||||
inputs: [
|
||||
permit2TransferFrom(OTHER_ADDR, USDT_2000),
|
||||
permit2TransferFrom(USDT_ADDR, OTHER_ADDR, USDT_2000),
|
||||
encodePermit2(USDT_ADDR, USDT_600, ROUTER_ADDR),
|
||||
V3_600,
|
||||
],
|
||||
@@ -2244,13 +2252,43 @@ describe("uniswap decoder", () => {
|
||||
...USDT_600_LINES,
|
||||
],
|
||||
},
|
||||
])(
|
||||
"$kind shows the total the steps take and the permit's own lines",
|
||||
({ inputs, lines }) => {
|
||||
const result = decodeSteps([0x02, 0x0a, 0x00], inputs);
|
||||
expect(linesBetweenTokens(result)).toEqual(lines);
|
||||
{
|
||||
kind: "a PERMIT2_PERMIT of 1 WETH, then a PERMIT2_TRANSFER_FROM of 1 WETH to the V2 pair and a V2 exact-in of ALREADY_PAID, shows the permit's amount",
|
||||
commands: [0x0a, 0x02, 0x08],
|
||||
inputs: [
|
||||
encodePermit2(WETH_ADDR, ONE_WETH, ROUTER_ADDR),
|
||||
permit2TransferFrom(WETH_ADDR, WETH_USDC_PAIR, ONE_WETH),
|
||||
encodeV2SwapExactIn(USER_ADDR, 0n, 1990000000n, [
|
||||
WETH_ADDR,
|
||||
USDC_ADDR,
|
||||
]),
|
||||
],
|
||||
lines: [
|
||||
["Amount", "1.0000 WETH"],
|
||||
["Moved from the sender", "1.0000 WETH"],
|
||||
["Token moved", "WETH (" + WETH_ADDR + ")"],
|
||||
["Moved to", "The V2 pair the next swap spends"],
|
||||
],
|
||||
},
|
||||
);
|
||||
{
|
||||
kind: "a PERMIT2_TRANSFER_FROM of 400 DAI to another address, then a PERMIT2_PERMIT of 600 USDT and a V3 exact-in of 600 USDT, shows the permit's amount",
|
||||
commands: [0x02, 0x0a, 0x00],
|
||||
inputs: [
|
||||
permit2TransferFrom(DAI_ADDR, OTHER_ADDR, DAI_400),
|
||||
encodePermit2(USDT_ADDR, USDT_600, ROUTER_ADDR),
|
||||
V3_600,
|
||||
],
|
||||
lines: [
|
||||
["Amount", "600.0000 USDT"],
|
||||
["Moved from the sender", "400.0000 DAI"],
|
||||
["Token moved", "DAI (" + DAI_ADDR + ")"],
|
||||
["Moved to", OTHER_ADDR],
|
||||
],
|
||||
},
|
||||
])("$kind", ({ commands, inputs, lines }) => {
|
||||
const result = decodeSteps(commands, inputs);
|
||||
expect(linesBetweenTokens(result)).toEqual(lines);
|
||||
});
|
||||
|
||||
// A V3_SWAP_EXACT_OUT the user pays for, of at most `amountInMax`
|
||||
// USDT for USDC.
|
||||
|
||||
Reference in New Issue
Block a user