Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b57bf071a7 |
@@ -597,12 +597,14 @@ 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.
|
// of such a path are not the token it reads there. Both are checksummed, as
|
||||||
|
// 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 = "0x" + hex.slice(0, 40);
|
const first = getAddress("0x" + hex.slice(0, 40));
|
||||||
const last = "0x" + hex.slice(-40);
|
const last = getAddress("0x" + hex.slice(-40));
|
||||||
return { first, last };
|
return { first, last };
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2039,10 +2041,9 @@ 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, and a permit among
|
// or pay the user, before or after any other step. What the other
|
||||||
// them would name Token In. What the other steps state is
|
// steps state is then not the whole swap, so both sides are set
|
||||||
// then not the whole swap, so both sides are set unknown, with no
|
// unknown, with no figure, wherever the step stands.
|
||||||
// figure, wherever the step stands.
|
|
||||||
if (hasSubPlan) {
|
if (hasSubPlan) {
|
||||||
inputToken = null;
|
inputToken = null;
|
||||||
inputAmount = null;
|
inputAmount = null;
|
||||||
|
|||||||
+10
-18
@@ -696,12 +696,8 @@ 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(
|
expect(detail(result, "Token In").address).toBe(USDT_ADDR);
|
||||||
USDT_ADDR.toLowerCase(),
|
expect(detail(result, "Token Out").address).toBe(WETH_ADDR);
|
||||||
);
|
|
||||||
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");
|
||||||
@@ -735,9 +731,7 @@ 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(
|
expect(detail(result, "Token Out").address).toBe(USDC_ADDR);
|
||||||
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");
|
||||||
});
|
});
|
||||||
@@ -2373,9 +2367,11 @@ 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");
|
||||||
expect(
|
// The swap step names Token In, its address checksummed,
|
||||||
detail(result, "Token In").address.toLowerCase(),
|
// as on a permit's Allowance token line.
|
||||||
).toBe(USDT_ADDR.toLowerCase());
|
expect(detail(result, "Token In").value).toBe(
|
||||||
|
"USDT (" + USDT_ADDR + ")",
|
||||||
|
);
|
||||||
expect(linesBetweenTokens(result)).toEqual([
|
expect(linesBetweenTokens(result)).toEqual([
|
||||||
["Amount", "600.0000 USDT"],
|
["Amount", "600.0000 USDT"],
|
||||||
...lines,
|
...lines,
|
||||||
@@ -3284,9 +3280,7 @@ 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(
|
expect(detail(result, "Token In").address).toBe(USDT_ADDR);
|
||||||
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)",
|
||||||
@@ -3344,9 +3338,7 @@ 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(
|
expect(detail(result, "Token Out").address).toBe(USDT_ADDR);
|
||||||
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 in lowercase.
|
// its address written the same way.
|
||||||
const permitLines = [
|
const permitLines = [
|
||||||
"Permit2 allowance",
|
"Permit2 allowance",
|
||||||
"Allowance token",
|
"Allowance token",
|
||||||
@@ -2836,15 +2836,9 @@ describe("the allow-revert flag", () => {
|
|||||||
];
|
];
|
||||||
const swapLines = (r) =>
|
const swapLines = (r) =>
|
||||||
r.details.filter(
|
r.details.filter(
|
||||||
(d) =>
|
(d) => !["Steps", ...permitLines].includes(d.label),
|
||||||
!["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