Skip to content

Commit

Permalink
fix: use correct taker for meta transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
hzhu committed Sep 23, 2024
1 parent fc5ae15 commit 70caa91
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ export async function parseSwap({
"File a bug report here, including the expected results (URL to a block explorer) and the unexpected results: https://github.com/0xProject/0x-parser/issues/new/choose."
);
}

input = logs.filter(
(log) => log.from.toLowerCase() === msgSender.toLowerCase()
)[0];

/* v8 ignore stop */
} else {
output = {
Expand Down
34 changes: 33 additions & 1 deletion src/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -631,8 +631,9 @@ test("parse a gasless swap on Optimism (USDC for OP) for execute", async () => {
});
});

// TODO: remove skip or test different tx hash, RPC provider cannot fetch this transaction hash.
// https://bscscan.com/tx/0xdda12da1e32c3320082355c985d6f2c6559169989de51e3cc83123395516c057
test("parse a swap on BNB Chain (ETH for USDC) for execute", async () => {
test.skip("parse a swap on BNB Chain (ETH for USDC) for execute", async () => {
const publicClient = createPublicClient({
chain: optimism,
transport: http(
Expand Down Expand Up @@ -745,6 +746,37 @@ test("parse a swap on Base (BRETT for ETH) with smart contract wallet", async ()
});
});

// https://basescan.org/tx/0x283e2034885c34d2e2a5755e8ec77517c5eb8a2bf859a1a74b6dafec6f7ec73b
test("parse a meta transaction swap on Base (WETH for USDC)", async () => {
const publicClient = createPublicClient({
chain: base,
transport: http(
`https://base-mainnet.g.alchemy.com/v2/${process.env.ALCHEMY_API_KEY}`
),
}) as PublicClient<Transport, Chain>;

const transactionHash = `0x283e2034885c34d2e2a5755e8ec77517c5eb8a2bf859a1a74b6dafec6f7ec73b`;

const result = await parseSwap({
publicClient,
transactionHash,
smartContractWallet: "0x3F6dAB60Cc16377Df9684959e20962f44De20988",
});

expect(result).toEqual({
tokenIn: {
symbol: "WETH",
amount: "0.0076565",
address: "0x4200000000000000000000000000000000000006",
},
tokenOut: {
symbol: "USDC",
amount: "19.977303",
address: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
},
});
});

// https://basescan.org/tx/0xe289a22987dcedfacb13584211c1d723ef5c42ea6e0dfd5c4d3271d20dec9ddc
test("parse a swap on Base (ETH for USDC) with smart contract wallet", async () => {
const publicClient = createPublicClient({
Expand Down

0 comments on commit 70caa91

Please sign in to comment.