Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,11 @@
# Create an Alchemy API key: https://docs.alchemy.com/docs/alchemy-quickstart-guide
# Or even better, run a local node: https://ethereum.org/en/run-a-node and use it's RPC URL.
ETH_MAINNET_RPC="https://eth-mainnet.g.alchemy.com/v2/<your-api-key>"
ALCHEMY_API_KEY="your-alchemy-api-key-here"


# Required: QuickNode API keys for specific chain tests
# Sign up at https://quicknode.com for free trial with debug method support
QUICKNODE_BNB_CHAIN_API_KEY="your-quicknode-bnb-key"
QUICKNODE_MANTLE_API_KEY="your-quicknode-mantle-key"
QUICKNODE_MODE_API_KEY="your-quicknode-mode-key"
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<br>Mantle
</div>
</td>
<td style="width:100px; text-align:center;">
<td style="width:100px; text-align:center;">
<div align="center">
<img alt="mantle" src="https://raw.githubusercontent.com/rainbow-me/assets/master/blockchains/monad/info/logo.png" width="22"/>
<br>Monad
Expand All @@ -84,14 +84,14 @@
<br>Scroll
</div>
</td>
</tr>
<tr>
<td style="width:100px; text-align:center;">
<div align="center">
<img alt="coming soon" src="https://raw.githubusercontent.com/rainbow-me/assets/master/blockchains/mode/info/logo.png" width="22"/>
<br>Mode
</div>
</td>
</tr>
<tr>
<td style="width:100px; text-align:center;">
<div align="center">
<img alt="Worldchain" src="https://cdn.prod.website-files.com/6503306c491d20f69e484470/6718ce22ee5879d832765fd6_66ced64f18a10922ffcff77d_65d8bce782514cfb6c149b7a_1VQdZPHJ_400x400.webp" width="22"/>
Expand Down Expand Up @@ -121,15 +121,15 @@
<img alt="coming soon" src="https://i.imgur.com/CexTjqF.png" width="22"/>
<br>🔜
</div>
</td>
</td>
</tr>
<tr>
<td style="width:100px; text-align:center;">
<div align="center">
<img alt="coming soon" src="https://cdn.prod.website-files.com/63692bf32544bee8b1836ea6/637b01428c7bd8e16af26756_favicon-32.png" width="22"/>
<br>🔜
</div>
</td>
</tr>
<tr>
</td>
<td style="width:100px; text-align:center;">
<div align="center">
<img alt="coming soon" src="https://i.imgur.com/OPA8A9u.png" width="22"/>
Expand Down
25 changes: 17 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,23 @@ export async function parseSwap({
};
}

/* v8 ignore start */
if (!output) {
console.error(
"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."
);
return null;
}
/* v8 ignore stop */
if (!output) {
if (!logs.length) /* v8 ignore next */ return null;
const firstTransfer = logs[0];
const lastTransfer = logs[logs.length - 1];
return {
tokenIn: {
symbol: firstTransfer.symbol,
address: firstTransfer.address.toLowerCase(),
amount: firstTransfer.amount
},
tokenOut: {
symbol: lastTransfer.symbol,
address: lastTransfer.address.toLowerCase(),
amount: lastTransfer.amount
}
};
}

return {
tokenIn: {
Expand Down
54 changes: 54 additions & 0 deletions src/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1455,3 +1455,57 @@ test("logs a warning for reverted transactions)", async () => {

warnSpy.mockRestore();
});

//https://etherscan.io/tx/0x7eea91c5c715ef4bb1e39ddf4c7832113693e87c18392740353d5ae669406a46
test("parse a swap on Ethereum (USDC for WMON) with SettlerIntent", async () => {
const transactionHash = "0x7eea91c5c715ef4bb1e39ddf4c7832113693e87c18392740353d5ae669406a46";

const result = await parseSwap({
publicClient: publicClient,
transactionHash,
});

expect(result).toEqual({
tokenIn: {
symbol: "USDC",
amount: "1000.080833",
address: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
},
tokenOut: {
symbol: "WMON",
amount: "22204.573291811240325155",
address: "0x6917037f8944201b2648198a89906edf863b9517",
},
});
});

// https://optimistic.etherscan.io/tx/0xdee6f4fea0250f297ed9663c4ca4479e8a253c62e16faa60759e25832cd1f34f
test("parse a swap on Optimism (wstETH for ETH) via Balancer pool", async () => {
const publicClient = createPublicClient({
chain: optimism,
transport: http(
`https://opt-mainnet.g.alchemy.com/v2/${process.env.ALCHEMY_API_KEY}`
),
}) as PublicClient<Transport, Chain>;

const transactionHash =
"0xdee6f4fea0250f297ed9663c4ca4479e8a253c62e16faa60759e25832cd1f34f";

const result = await parseSwap({
publicClient,
transactionHash,
});

expect(result).toEqual({
tokenIn: {
symbol: "wstETH",
amount: "0.008868",
address: "0x1f32b1c2345538c0c6f582fcb022739c4a194ebb",
},
tokenOut: {
symbol: "WETH",
amount: "0.010698199301849867",
address: "0x4200000000000000000000000000000000000006",
},
});
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a new line here? 🙏

Suggested change
});
});