-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
release-as: 0.0.5
- Loading branch information
0 parents
commit 5add299
Showing
40 changed files
with
15,453 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
RPC_TEST_URL="https://rpc.flashbots.net" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Contributing Guide | ||
|
||
Thanks for your interest in contributing. Please review this guide prior to submitting a pull request. | ||
|
||
## Development | ||
|
||
Start by [forking](https://docs.github.com/en/get-started/quickstart/fork-a-repo) and cloning the repository onto your computer. Afterwards, you can start development by installing the dependencies and running the tests. | ||
|
||
1. Install dependencies | ||
|
||
``` | ||
npm install | ||
``` | ||
|
||
2. Run tests | ||
|
||
``` | ||
npm test | ||
``` | ||
|
||
Once you have completed your changes, you can create a [pull request from the fork](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request-from-a-fork). Project maintainers may create pull requests in the repository without a fork. | ||
|
||
## Pull requests | ||
|
||
For large or impactful change, please open an [issue](https://github.com/hzhu/eth-balances/issues/new) or [discussion](https://github.com/hzhu/eth-balances/discussions/new?category=q-a) prior to submitting a pull request. This allows the project maintainers and contributors to discuss alternatives and solutions prior to implementation. | ||
|
||
### Workflow | ||
|
||
1. Open an issue | ||
1. Fork the repo and create a branch | ||
1. Add new commits | ||
1. Commits should be [concise, descriptive, and well formatted](https://cbea.ms/git-commit/#seven-rules) | ||
1. Commits should follow the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) specification and use the [standard headings](https://github.com/googleapis/release-please/blob/cb0f936e598c5bfb8d3e0a9c0eeb57ae59a35140/src/changelog-notes.ts#L43-L54) | ||
1. This repo has a linear git history and merge commits are not allowed | ||
1. Open a new pull request on GitHub | ||
1. [Link](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue) the issue you created earlier with the pull request | ||
|
||
### Dependabot | ||
|
||
This repository uses [Dependabot](https://docs.github.com/en/code-security/dependabot) to help [secure](https://docs.github.com/en/code-security/dependabot/dependabot-security-updates/configuring-dependabot-security-updates) and [update](https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuring-dependabot-version-updates#about-version-updates-for-dependencies) project dependencies. It does this by automatically opening pull requests to update package dependencies. Project maintainers are responsible for reviewing, testing, approving, and merging Dependabot pull requests. | ||
|
||
## Release | ||
|
||
Project maintainers can publish releases. Releases are automated with Google's [release-please](https://github.com/googleapis/release-please) GitHub action. Simply merge the release pull request ([release PR](https://github.com/googleapis/release-please#whats-a-release-pr)) to publish a release 🚀. | ||
|
||
The GitHub action parses [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) to help automate releases. It creates a release PR that is kept up-to-date as additional commits are merged. The release PR can be merged once maintainers are ready to publish the release. Merging the release PR triggers the action to: | ||
|
||
1. Update the `CHANGELOG.md` and `package.json` | ||
2. Tag the commit with the [version](https://semver.org/) | ||
3. Create a GitHub release based on the tag | ||
4. Publish [the package](https://www.npmjs.com/package/@0x/0x-parser) to npm | ||
|
||
## Versioning | ||
|
||
This project follows [Semantic Versioning 2.0](https://semver.org/) and the release tooling automatically parses the semantic version based on the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
on: | ||
push: | ||
branches: | ||
- main | ||
name: release-please | ||
jobs: | ||
release-please: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: google-github-actions/release-please-action@v3 | ||
id: release | ||
with: | ||
release-type: node | ||
package-name: test-release-please | ||
# The logic below handles the npm publication: | ||
- uses: actions/checkout@v3 | ||
# these if statements ensure that a publication only occurs when | ||
# a new release is created: | ||
if: ${{ steps.release.outputs.release_created }} | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18 | ||
registry-url: "https://registry.npmjs.org" | ||
if: ${{ steps.release.outputs.release_created }} | ||
- run: npm ci | ||
if: ${{ steps.release.outputs.release_created }} | ||
- run: npm run build | ||
if: ${{ steps.release.outputs.release_created }} | ||
- run: npm publish --access public | ||
env: | ||
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} | ||
if: ${{ steps.release.outputs.release_created }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name: Build & Test | ||
on: [push] | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18.x | ||
- uses: actions/checkout@v3 | ||
- run: npm ci | ||
- run: npm run build | ||
- run: npm test --coverage | ||
env: | ||
RPC_TEST_URL: "https://rpc.flashbots.net" | ||
- uses: codecov/codecov-action@v3 | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
directory: ./coverage/ | ||
fail_ci_if_error: true | ||
flags: unittests | ||
verbose: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# dependencies | ||
node_modules | ||
|
||
# artifacts | ||
dist | ||
|
||
# example artifacts | ||
examples/web/index.esm.js | ||
examples/node/index.cjs.js | ||
|
||
# coverage files | ||
coverage | ||
|
||
# hardhat cache | ||
cache | ||
|
||
# environment variables | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) [2023] 0x | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# 0x-parser | ||
|
||
[](https://www.npmjs.com/package/@0x/0x-parser) | ||
[](https://github.com/0xproject/0x-parser/actions/workflows/test.yml) | ||
[](https://codecov.io/gh/0xproject/0x-parser) | ||
|
||
Designed for [0x integrators](https://0x.org/docs/introduction/introduction-to-0x), this library offers a solution to parse swap amounts from 0x transactions, a task that becomes complex when trades involve Automated Market Makers (AMMs). Given the potential for [slippage](https://0x.org/post/what-is-slippage) in these trades, the final swap amounts cannot be anticipated before trade execution. This library addresses this challenge by accepting a transaction hash as input, then parsing through the event logs to identify the exact swap amounts. | ||
|
||
## Installation | ||
|
||
``` | ||
npm install @0x/0x-parser | ||
``` | ||
|
||
## Usage | ||
|
||
```javascript | ||
import { parseSwap } from '@0x/0x-parser'; | ||
|
||
async function main() { | ||
const { getAddress, JsonRpcProvider, Contract } = ethers; | ||
const EXCHANGE_PROXY = "0xDef1C0ded9bec7F1a1670819833240f027b25EfF"; | ||
const transactionHash = "0xf705df9127065ae8a8da3c1939d7096011ea13c81e4a2ed8c59ea1b039f7565d"; | ||
const abiUrl = "https://raw.githubusercontent.com/0xProject/protocol/development/packages/contract-artifacts/artifacts/IZeroEx.json"; | ||
const response = await fetch(abiUrl); | ||
const IZeroEx = await response.json(); | ||
const { interface } = new Contract(EXCHANGE_PROXY, IZeroEx.compilerOutput.abi); | ||
const provider = new JsonRpcProvider("https://eth.llamarpc.com"); | ||
const [tx, txReceipt] = await Promise.all([ | ||
provider.getTransaction(transactionHash), | ||
provider.getTransactionReceipt(transactionHash), | ||
]); | ||
const txDescription = interface.parseTransaction(tx); | ||
const data = await parseSwap({ rpcUrl: "https://eth.llamarpc.com", txReceipt, txDescription }); | ||
|
||
console.log(JSON.stringify(data); | ||
} | ||
|
||
main(); | ||
``` | ||
## Live demo | ||
Try a demo app that uses 0x-parser [here](https://0x-parser-demo.vercel.app/). | ||
<img src="https://raw.githubusercontent.com/hzhu/yo/main/react-demo.png" alt="0x parser React demo app" width="650"/> | ||
## Examples | ||
This repository includes an example you can execute locally using the `npm run web:example` command. Additionally, there's another repository that showcases how to use this package within a simple React app, which you can find [here](https://github.com/hzhu/0x-parser-demo). | ||
## Contributing | ||
Contributions are welcomed! Please follow the [contributing guidelines](./.github/.CONTRIBUTING.md). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Ethereum Balances</title> | ||
<script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script> | ||
<script type="module"> | ||
import { ethers } from "https://cdnjs.cloudflare.com/ajax/libs/ethers/6.2.2/ethers.min.js"; | ||
import { parseSwap } from "./index.esm.js"; | ||
window.ethers = ethers; | ||
window.parseSwap = parseSwap; | ||
</script> | ||
<script | ||
crossorigin | ||
src="https://unpkg.com/react@18/umd/react.development.js" | ||
></script> | ||
<script | ||
crossorigin | ||
src="https://unpkg.com/react-dom@18/umd/react-dom.development.js" | ||
></script> | ||
<script type="text/babel"> | ||
const transactions = { | ||
ethereum: { | ||
permitAndCall: | ||
"0x5eac379185f24ddeba7fcd4414779df77ecfd1102da6ebf6dacf25b01a14b241", | ||
fillLimitOrder: | ||
"0xbe734b761ccd45cc60a5b4828eb83da96405d663567a46041b049627dddf347d", | ||
multiplexBatchSellEthForToken: | ||
"0xe59ff84284d7e2ad87f1a6de55d5d6600b0b721242110687847e57b52a045b7d", | ||
multiplexBatchSellTokenForEth: | ||
"0x0caebae93af96f83c4d2434816d079d1b43e9061dcaca8627bd9e2c0917a3b63", | ||
multiplexMultiHopSellTokenForEth: | ||
"0xba3a89b2164e5f169bc81e90a13f8946d110dffe2b53393953ea2a4fede8e81e", | ||
sellToLiquidityProvider: | ||
"0x2a4379d531695dd4f142730edb7720bb9d06dfb405322e0e16acbfd8ba4fcb98", | ||
multiplexMultiHopSellEthForToken: | ||
"0x00b191d47269265cfbbc94c77a114281ee939463b7a922e8bfbf7de8bc150c5c", | ||
multiplexBatchSellTokenForToken: | ||
"0xb2c5a697a3126af96d2aa20ba6dcd0daaf9ec6baa49de2a76682dfe4258d2e56", | ||
multiplexMultiHopSellTokenForToken: | ||
"0xf705df9127065ae8a8da3c1939d7096011ea13c81e4a2ed8c59ea1b039f7565d", | ||
transformERC20: | ||
"0x4db5b7168686cdfb1469b47a67f03fb6199aa81f3d2a26c4a05835b8752d152d", | ||
sellToUniswap: | ||
"0xd6a7aeda4a2978c80b03700e3136c6895b48d08cd9c8d4c88dfd19dee0a12795", | ||
sellEthForTokenToUniswapV3: | ||
"0xc552e83ef96c5d523f69494ae61b7235a6304ab439e127eb0121d33bbcdaa1ff", | ||
sellTokenForTokenToUniswapV3: | ||
"0x90dbdd630287a0412f88cbc98b0d751bc81c613bb285898dac461b523cd07a5a", | ||
sellTokenForEthToUniswapV3: | ||
"0x822d38c0746b19544cedddd9a1ebaacadd3e5da55dc293738ae135fc595e269b", | ||
fillOtcOrder: | ||
"0xc9579b9e3cddebd3d48ccb0a719456d7c46869b2c3a536509ea88685c7a5efbb", | ||
fillTakerSignedOtcOrderForEth: | ||
"0x5f0ed4396f68e0321e48d50611cc6663af68bf7cbee6bc8e74ff5c63d90f3b68", | ||
fillTakerSignedOtcOrder: | ||
"0x7f31ba7cacfda809ea24d4b9f87c44fb4114608666c7dd1c6553986ce88dc92b", | ||
executeMetaTransaction: | ||
"0xbfc411b0fd658c0a502d9830359835869c8f5614b7e0992bed4e1c2c35305450", | ||
fillOtcOrderForEth: | ||
"0x2c4cee137659650ef486fb46b657ec37c1b4fe18489956a5e058cf5585328fa7", | ||
fillOtcOrderWithEth: | ||
"0x68608bec5c30750a6a358b14eb937a07f10f72c84428bdf6eae80f52c27faf53", | ||
}, | ||
optimism: { | ||
transformERC20: | ||
"0xfa5282d42d3e3ab01c23557ad8ab923c9ecee380b8fae5165852e088f2e4f4ce", | ||
}, | ||
arbitrum: { | ||
transformERC20: | ||
"0xa13071a809c4ff587cd0af724c7e73cae89f492eba891c9112adda8e57559580", | ||
}, | ||
bsc: { | ||
sellToPancakeSwap: | ||
"0x2076af859a54f5f0c7d4e1cd13b3906169a5e3697d8762b59062052d53466e94", | ||
}, | ||
polygon: { | ||
executeMetaTransaction: | ||
"0x0c537cdfb9d1d23d16f775b49e8004a5dea6ce6bdd287bd1f6320c4f813ead9a", | ||
transformERC20: | ||
"0xa53a3b8e7335ba2707b478d786cfb4dc251bdd3b2678e9717d9585031d1db9cf", | ||
fillLimitOrder: | ||
"0x2324387b691ea78b31135fa1f031d133e88cd3a7c7625c02293e943ec7090c36", | ||
}, | ||
}; | ||
|
||
const rpcUrls = { | ||
bsc: "https://bscrpc.com", | ||
arbitrum: "https://1rpc.io/arb", | ||
polygon: "https://polygon-rpc.com", | ||
ethereum: "https://eth.llamarpc.com", | ||
optimism: "https://endpoints.omniatech.io/v1/op/mainnet/public", | ||
}; | ||
|
||
async function example() { | ||
const { getAddress, JsonRpcProvider, Contract } = ethers; | ||
const EXCHANGE_PROXY = "0xDef1C0ded9bec7F1a1670819833240f027b25EfF"; | ||
const abiUrl = | ||
"https://raw.githubusercontent.com/0xProject/protocol/development/packages/contract-artifacts/artifacts/IZeroEx.json"; | ||
const response = await fetch(abiUrl); | ||
const IZeroEx = await response.json(); | ||
const contract = new Contract( | ||
EXCHANGE_PROXY, | ||
IZeroEx.compilerOutput.abi | ||
); | ||
const provider = new JsonRpcProvider(rpcUrls.ethereum); | ||
const [tx, txReceipt] = await Promise.all([ | ||
provider.getTransaction(transactions.ethereum.transformERC20), | ||
provider.getTransactionReceipt(transactions.ethereum.transformERC20), | ||
]); | ||
const txDescription = contract.interface.parseTransaction(tx); | ||
const data = await parseSwap({ | ||
rpcUrl: rpcUrls.ethereum, | ||
txReceipt, | ||
txDescription, | ||
}); | ||
console.log(JSON.stringify(data, null, 4)); | ||
} | ||
|
||
example(); | ||
</script> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
</body> | ||
</html> |
Oops, something went wrong.