@0x/0x-parser
Advanced tools
Comparing version 0.5.0 to 0.5.1
{ | ||
"name": "@0x/0x-parser", | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"description": "🧾 Designed for 0x integrators: This library parses 0x transactions on EVM blockchains into a format that is both user-friendly and easy to understand.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -16,6 +16,6 @@ # 0x-parser | ||
This library is specifically designed for [0x integrators](https://0x.org/docs/introduction/introduction-to-0x), and it simplifies the complex task of parsing [0x transactions](https://etherscan.io/address/0xdef1c0ded9bec7f1a1670819833240f027b25eff) into a format that is both user-friendly and easy to understand. One of the challenges in these trades is that they can experience [slippage](https://0x.org/post/what-is-slippage) through [Automated Market Makers](<[AMMs](https://0x.org/post/what-is-an-automated-market-maker-amm)>) (AMMs), making the final swap amounts difficult to predict prior to executing the trade. However, this library overcomes that challenge by accepting a transaction hash as input and parsing the receipt and event logs to accurately identify the final swap amounts. Try the demo [here](https://0x-parser-demo.vercel.app). | ||
This library is designed for [0x integrators](https://0x.org/docs/introduction/introduction-to-0x), and it simplifies the complex task of parsing [0x transactions](https://etherscan.io/address/0xdef1c0ded9bec7f1a1670819833240f027b25eff) into a format that is both user-friendly and easy to understand. One of the challenges when swapping tokens is that the trade can experience [slippage](https://0x.org/post/what-is-slippage) through [Automated Market Makers](<[AMMs](https://0x.org/post/what-is-an-automated-market-maker-amm)>) (AMMs), making the final swap amounts difficult to predict prior to executing the trade. However, this library overcomes that challenge by parsing the transaction receipt and event logs to accurately identify the final swap amounts. Try the demo [here](https://0x-parser-demo.vercel.app). | ||
<p align="center"> | ||
<img style="" src="https://raw.githubusercontent.com/hzhu/yo/main/react-demo.png" alt="React demo app for 0x-parser" width="650"/> | ||
<img src="https://raw.githubusercontent.com/hzhu/yo/main/react-demo.png" alt="Screenshot of demo app using 0x-parser" width="650"/> | ||
</p> | ||
@@ -22,0 +22,0 @@ |
@@ -151,3 +151,5 @@ import { formatUnits } from "ethers"; | ||
export function sellToUniswap({ txReceipt }: { txReceipt: EnrichedTxReceipt }) { | ||
const [inputLog, outputLog] = txReceipt.logs; | ||
const { logs } = txReceipt; | ||
const inputLog = logs[0]; | ||
const outputLog = logs[logs.length - 1]; | ||
@@ -154,0 +156,0 @@ return extractTokenInfo(inputLog, outputLog); |
@@ -14,3 +14,3 @@ import { it, expect } from "vitest"; | ||
// https://etherscan.io/tx/0xd6a7aeda4a2978c80b03700e3136c6895b48d08cd9c8d4c88dfd19dee0a12795 | ||
it("parses swap from sellToUniswap", async () => { | ||
it("parses a single hop swap from sellToUniswap", async () => { | ||
const data = await parseSwap({ | ||
@@ -36,1 +36,24 @@ transactionHash: | ||
}); | ||
// https://etherscan.io/tx/0x380eebed81807391a70aac7f02cc852d441ccf0b7cf6538f7a472750e551720b | ||
it("parses a multihop swap from sellToUniswap", async () => { | ||
const data = await parseSwap({ | ||
transactionHash: | ||
"0x380eebed81807391a70aac7f02cc852d441ccf0b7cf6538f7a472750e551720b", | ||
exchangeProxyAbi: EXCHANGE_PROXY_ABI.compilerOutput.abi, | ||
rpcUrl: ETH_MAINNET_RPC, | ||
}); | ||
expect(data).toEqual({ | ||
tokenIn: { | ||
symbol: "USDC", | ||
amount: "1000", | ||
address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", | ||
}, | ||
tokenOut: { | ||
symbol: "SOLANA", | ||
amount: "497767771055.529611406221129532", | ||
address: "0x3D806324b6Df5AF3c1a81aCbA14A8A62Fe6D643F", | ||
}, | ||
}); | ||
}); |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
1186426
13749