Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aea693a761 |
@@ -597,14 +597,12 @@ function decodeV2SwapExactOut(input) {
|
|||||||
// token(20) ...), or null when it is not one token followed by whole hops of
|
// token(20) ...), or null when it is not one token followed by whole hops of
|
||||||
// a fee and a token (40 hex digits, then 46 per hop). The router reads only
|
// a fee and a token (40 hex digits, then 46 per hop). The router reads only
|
||||||
// whole hops and ignores any bytes after the last one, so the last 20 bytes
|
// whole hops and ignores any bytes after the last one, so the last 20 bytes
|
||||||
// of such a path are not the token it reads there. Both are checksummed, as
|
// of such a path are not the token it reads there.
|
||||||
// the ABI decoder gives every other address, so a token reads the same on
|
|
||||||
// every line.
|
|
||||||
function decodeV3Path(pathHex) {
|
function decodeV3Path(pathHex) {
|
||||||
const hex = pathHex.startsWith("0x") ? pathHex.slice(2) : pathHex;
|
const hex = pathHex.startsWith("0x") ? pathHex.slice(2) : pathHex;
|
||||||
if (hex.length < 40 || (hex.length - 40) % 46 !== 0) return null;
|
if (hex.length < 40 || (hex.length - 40) % 46 !== 0) return null;
|
||||||
const first = getAddress("0x" + hex.slice(0, 40));
|
const first = "0x" + hex.slice(0, 40);
|
||||||
const last = getAddress("0x" + hex.slice(-40));
|
const last = "0x" + hex.slice(-40);
|
||||||
return { first, last };
|
return { first, last };
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2041,9 +2039,10 @@ function decode(data, toAddress, chainId, sources, fromAddress) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// The commands of an EXECUTE_SUB_PLAN step may spend the user's tokens
|
// The commands of an EXECUTE_SUB_PLAN step may spend the user's tokens
|
||||||
// or pay the user, before or after any other step. What the other
|
// or pay the user, before or after any other step, and a permit among
|
||||||
// steps state is then not the whole swap, so both sides are set
|
// them would name Token In. What the other steps state is
|
||||||
// unknown, with no figure, wherever the step stands.
|
// then not the whole swap, so both sides are set unknown, with no
|
||||||
|
// figure, wherever the step stands.
|
||||||
if (hasSubPlan) {
|
if (hasSubPlan) {
|
||||||
inputToken = null;
|
inputToken = null;
|
||||||
inputAmount = null;
|
inputAmount = null;
|
||||||
|
|||||||
+18
-10
@@ -696,8 +696,12 @@ describe("uniswap decoder", () => {
|
|||||||
USER_ADDR,
|
USER_ADDR,
|
||||||
);
|
);
|
||||||
expect(result.name).toBe("Swap USDT → WETH");
|
expect(result.name).toBe("Swap USDT → WETH");
|
||||||
expect(detail(result, "Token In").address).toBe(USDT_ADDR);
|
expect(detail(result, "Token In").address).toBe(
|
||||||
expect(detail(result, "Token Out").address).toBe(WETH_ADDR);
|
USDT_ADDR.toLowerCase(),
|
||||||
|
);
|
||||||
|
expect(detail(result, "Token Out").address).toBe(
|
||||||
|
WETH_ADDR.toLowerCase(),
|
||||||
|
);
|
||||||
|
|
||||||
const amount = detail(result, "Amount");
|
const amount = detail(result, "Amount");
|
||||||
expect(amount.value).toBe("Up to 2000.0000 USDT");
|
expect(amount.value).toBe("Up to 2000.0000 USDT");
|
||||||
@@ -731,7 +735,9 @@ describe("uniswap decoder", () => {
|
|||||||
expect(result.name).toBe("Swap ETH → USDC");
|
expect(result.name).toBe("Swap ETH → USDC");
|
||||||
expect(detail(result, "Amount").value).toBe("Up to 0.5000 ETH");
|
expect(detail(result, "Amount").value).toBe("Up to 0.5000 ETH");
|
||||||
expect(detail(result, "Moved from the sender")).toBeUndefined();
|
expect(detail(result, "Moved from the sender")).toBeUndefined();
|
||||||
expect(detail(result, "Token Out").address).toBe(USDC_ADDR);
|
expect(detail(result, "Token Out").address).toBe(
|
||||||
|
USDC_ADDR.toLowerCase(),
|
||||||
|
);
|
||||||
expect(detail(result, "Paid to")).toBeUndefined();
|
expect(detail(result, "Paid to")).toBeUndefined();
|
||||||
expect(detail(result, "Min. received").value).toBe("1500.0000 USDC");
|
expect(detail(result, "Min. received").value).toBe("1500.0000 USDC");
|
||||||
});
|
});
|
||||||
@@ -2367,11 +2373,9 @@ describe("uniswap decoder", () => {
|
|||||||
({ commands, inputs, lines }) => {
|
({ commands, inputs, lines }) => {
|
||||||
const result = decodeSteps(commands, inputs);
|
const result = decodeSteps(commands, inputs);
|
||||||
expect(result.name).toBe("Swap USDT → USDC");
|
expect(result.name).toBe("Swap USDT → USDC");
|
||||||
// The swap step names Token In, its address checksummed,
|
expect(
|
||||||
// as on a permit's Allowance token line.
|
detail(result, "Token In").address.toLowerCase(),
|
||||||
expect(detail(result, "Token In").value).toBe(
|
).toBe(USDT_ADDR.toLowerCase());
|
||||||
"USDT (" + USDT_ADDR + ")",
|
|
||||||
);
|
|
||||||
expect(linesBetweenTokens(result)).toEqual([
|
expect(linesBetweenTokens(result)).toEqual([
|
||||||
["Amount", "600.0000 USDT"],
|
["Amount", "600.0000 USDT"],
|
||||||
...lines,
|
...lines,
|
||||||
@@ -3280,7 +3284,9 @@ describe("uniswap decoder", () => {
|
|||||||
);
|
);
|
||||||
const result = uniswap.decode(data, ROUTER_ADDR, "0x1", {}, USER_ADDR);
|
const result = uniswap.decode(data, ROUTER_ADDR, "0x1", {}, USER_ADDR);
|
||||||
expect(result.name).toBe("Uniswap Swap");
|
expect(result.name).toBe("Uniswap Swap");
|
||||||
expect(detail(result, "Token In").address).toBe(USDT_ADDR);
|
expect(detail(result, "Token In").address).toBe(
|
||||||
|
USDT_ADDR.toLowerCase(),
|
||||||
|
);
|
||||||
expect(detail(result, "Amount").value).toBe("1000.0000 USDT");
|
expect(detail(result, "Amount").value).toBe("1000.0000 USDT");
|
||||||
expect(detail(result, "Token Out").value).toBe(
|
expect(detail(result, "Token Out").value).toBe(
|
||||||
"Unknown (not named in the calldata)",
|
"Unknown (not named in the calldata)",
|
||||||
@@ -3338,7 +3344,9 @@ describe("uniswap decoder", () => {
|
|||||||
"Unknown (not named in the calldata)",
|
"Unknown (not named in the calldata)",
|
||||||
);
|
);
|
||||||
expect(detail(result, "Amount")).toBeUndefined();
|
expect(detail(result, "Amount")).toBeUndefined();
|
||||||
expect(detail(result, "Token Out").address).toBe(USDT_ADDR);
|
expect(detail(result, "Token Out").address).toBe(
|
||||||
|
USDT_ADDR.toLowerCase(),
|
||||||
|
);
|
||||||
expect(detail(result, "Min. received").value).toBe("990.0000 USDT");
|
expect(detail(result, "Min. received").value).toBe("990.0000 USDT");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -2828,7 +2828,7 @@ describe("the allow-revert flag", () => {
|
|||||||
// amount stands as the Amount figure only there, and only without
|
// amount stands as the Amount figure only there, and only without
|
||||||
// the flag. With the flag it stands on no router and gets lines
|
// the flag. With the flag it stands on no router and gets lines
|
||||||
// of its own, and the swap step names Token In: the same token,
|
// of its own, and the swap step names Token In: the same token,
|
||||||
// its address written the same way.
|
// its address in lowercase.
|
||||||
const permitLines = [
|
const permitLines = [
|
||||||
"Permit2 allowance",
|
"Permit2 allowance",
|
||||||
"Allowance token",
|
"Allowance token",
|
||||||
@@ -2836,9 +2836,15 @@ describe("the allow-revert flag", () => {
|
|||||||
];
|
];
|
||||||
const swapLines = (r) =>
|
const swapLines = (r) =>
|
||||||
r.details.filter(
|
r.details.filter(
|
||||||
(d) => !["Steps", ...permitLines].includes(d.label),
|
(d) =>
|
||||||
|
!["Steps", "Token In", ...permitLines].includes(
|
||||||
|
d.label,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
expect(swapLines(withFlag)).toEqual(swapLines(plain));
|
expect(swapLines(withFlag)).toEqual(swapLines(plain));
|
||||||
|
expect(detail(withFlag, "Token In").address.toLowerCase()).toBe(
|
||||||
|
detail(plain, "Token In").address.toLowerCase(),
|
||||||
|
);
|
||||||
expect(
|
expect(
|
||||||
labels(withFlag).filter((l) => permitLines.includes(l)),
|
labels(withFlag).filter((l) => permitLines.includes(l)),
|
||||||
).toEqual(permitLines);
|
).toEqual(permitLines);
|
||||||
|
|||||||
Reference in New Issue
Block a user