Skip to content

horizon-eth/UniswapV2_LP_Optimal_Input_Output_Calculation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

UniswapV2 Liquidity Pool Optimal Input & Output Calculation for Targeted Token 0 Price

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.

Prerequisites

  • Bun v1.1.30 or higher
  • An Ethereum Https provider URL

Tech Stack

  • Runtime: Bun - A fast all-in-one JavaScript runtime
  • Ethereum Client: viem v2.23.6 - Type-safe Ethereum interactions

Installation

  1. Clone the repository:
git clone https://github.com/horizon-eth/uniswapv2-lp-optimal-input-output-calculation.git
cd uniswapv2-lp-optimal-input-output-calculation
  1. Install dependencies:
bun install
  1. Create a .env file based on example.env:
cp .env.example .env
  1. Configure your environment variables in .env:
PROVIDER_HTTPS_URL="your_https_provider_url"

Usage

bun start <targetToken0MarketPrice>

example

bun start 2000

Development

The project uses TypeScript with strict type checking. Key files:

  • index.ts: Application entrypoint
  • src/config/config.ts: Application configs
  • src/config/client.ts: Client configs
  • src/pool/abi/abi.ts: Contract ABIs
  • src/pool/library/library.ts: Pool Function Library for Input & Output Calculation Logic
  • src/utils/utils.ts: Pool Utility functions

Contributing

  1. Fork the repository
  2. Create your feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a new Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors