Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dodger213/liquidity-share-value-calculator
The Liquidity-Share-Value-Calculator is a simple project that calculates the liquidity share value using the UniswapV2Pair contract, Library contract, and Factory contract.
https://github.com/dodger213/liquidity-share-value-calculator
factory library liquidity-pool pair solidity typescript uniswap
Last synced: about 1 month ago
JSON representation
The Liquidity-Share-Value-Calculator is a simple project that calculates the liquidity share value using the UniswapV2Pair contract, Library contract, and Factory contract.
- Host: GitHub
- URL: https://github.com/dodger213/liquidity-share-value-calculator
- Owner: dodger213
- License: mit
- Created: 2024-10-28T02:26:59.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2024-11-06T08:48:52.000Z (3 months ago)
- Last Synced: 2024-11-06T09:33:24.460Z (3 months ago)
- Topics: factory, library, liquidity-pool, pair, solidity, typescript, uniswap
- Language: TypeScript
- Homepage:
- Size: 102 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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
```solidity
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)
```solidity
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](./LICENSE) file for details.