Skip to content

Commit d5c94d6

Browse files
committed
fix: account for msgSender for metaTxn is used with multicall
1 parent c692dbb commit d5c94d6

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,16 @@ export async function parseSwap({
127127
const takerForGaslessApprovalSwap =
128128
settlerArgs[0].recipient.toLowerCase() as Address;
129129

130+
const msgSender = settlerArgs[3];
131+
130132
const nativeAmountToTaker = calculateNativeTransfer(trace, {
131133
recipient: takerForGaslessApprovalSwap,
132134
});
133135

134136
if (nativeAmountToTaker === "0") {
135-
output = output = logs[logs.length - 1];
137+
[output] = logs.filter(
138+
(log) => log.to.toLowerCase() === msgSender.toLowerCase()
139+
);
136140
} else {
137141
output = {
138142
symbol: NATIVE_SYMBOL_BY_CHAIN_ID[chainId],

src/tests/index.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,37 @@ test("parse a gasless swap on Base (DAI for USDC)", async () => {
329329
});
330330
});
331331

332+
// https://basescan.org/tx/0xb1ac9977d28e750add3b1a1ebdc95e56a51a9af7fc3d66fa7c011686eac455e6
333+
test("parse a gasless swap on Base (USDC for BRETT) via metaTxn multicall", async () => {
334+
const publicClient = createPublicClient({
335+
chain: base,
336+
transport: http(
337+
`https://base-mainnet.g.alchemy.com/v2/${process.env.ALCHEMY_API_KEY}`
338+
),
339+
}) as PublicClient<Transport, Chain>;
340+
341+
const transactionHash =
342+
"0xb1ac9977d28e750add3b1a1ebdc95e56a51a9af7fc3d66fa7c011686eac455e6";
343+
344+
const result = await parseSwap({
345+
publicClient,
346+
transactionHash,
347+
});
348+
349+
expect(result).toEqual({
350+
tokenIn: {
351+
symbol: "USDC",
352+
amount: "1000",
353+
address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
354+
},
355+
tokenOut: {
356+
symbol: "BRETT",
357+
amount: "18260.873189681406728218",
358+
address: "0x532f27101965dd16442E59d40670FaF5eBB142E4",
359+
},
360+
});
361+
});
362+
332363
// https://basescan.org/tx/0xa09cb1606e30c3aed8a842723fd6c23cecd838a59f750ab3dbc5ef2c7486e696
333364
test("parse a swap on Base (USDC for DAI)", async () => {
334365
const publicClient = createPublicClient({

0 commit comments

Comments
 (0)