This project instantly calculates the required exact input amount and expected exact output amount in order to advance pool price of token 0 to targeted price of token 0.
There are some really tiny precision issues related to big integer logic but this project is open for any contributions for further improvements, so don't hesitate to open issues & PRs.
If you want me to share the exact input amount & exact output amount calculation logic on Uniswap V3 Liquidity Pools, you can click the button *star* right above to support me for this purpose.
- Bun v1.1.30 or higher
- An Ethereum Https provider URL
- Runtime: Bun - A fast all-in-one JavaScript runtime
- Ethereum Client: viem v2.23.6 - Type-safe Ethereum interactions
- Clone the repository:
git clone https://github.com/horizon-eth/uniswapv2-lp-optimal-input-output-calculation.git
cd uniswapv2-lp-optimal-input-output-calculation- Install dependencies:
bun install- Create a
.envfile based onexample.env:
cp .env.example .env- Configure your environment variables in
.env:
PROVIDER_HTTPS_URL="your_https_provider_url"bun start <targetToken0MarketPrice>example
bun start 2000The project uses TypeScript with strict type checking. Key files:
index.ts: Application entrypointsrc/config/config.ts: Application configssrc/config/client.ts: Client configssrc/pool/abi/abi.ts: Contract ABIssrc/pool/library/library.ts: Pool Function Library for Input & Output Calculation Logicsrc/utils/utils.ts: Pool Utility functions
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a new Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.