Skip to content

The Liquidity-Share-Value-Calculator is a simple project that calculates the liquidity share value using the UniswapV2Pair contract, Library contract, and Factory contract.

License

Notifications You must be signed in to change notification settings

dodger213/Liquidity-Share-Value-Calculator

Repository files navigation

Liquidity-Share-Value-Calculator

A Solidity smart contract for calculating liquidity share values in Uniswap V2 pairs.

Overview

The LiquidityValueCalculator contract provides functionality to compute the value of liquidity shares in terms of both tokens in a Uniswap V2 pair. This is particularly useful for liquidity providers who want to know the underlying value of their LP tokens.

Features

  • Calculate the exact amount of both tokens represented by LP tokens
  • Compatible with any Uniswap V2 pair
  • Gas-efficient calculations
  • View functions that don't modify state

Contract Details

Constructor

  • Takes a Uniswap V2 factory address as parameter
  • Stores the factory address for pair calculations

Main Functions

computeLiquidityShareValue

function computeLiquidityShareValue(
    uint liquidity,
    address tokenA,
    address tokenB
) external view returns (uint tokenAAmount, uint tokenBAmount)
  • Input: Liquidity amount and addresses of both tokens
  • Output: Equivalent amounts of tokenA and tokenB
  • Uses current reserves and total supply for accurate calculations

pairInfo (Internal)

function pairInfo(
    address tokenA,
    address tokenB
) internal view returns (uint reserveA, uint reserveB, uint totalLiquidity)
  • Retrieves current reserves and total supply from the pair
  • Handles token ordering based on addresses
  • Returns reserveA, reserveB, and total liquidity

Dependencies

  • Uniswap V2 Core
  • Uniswap V2 Periphery
  • Solidity ^0.8.27

License

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

About

The Liquidity-Share-Value-Calculator is a simple project that calculates the liquidity share value using the UniswapV2Pair contract, Library contract, and Factory contract.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published