to create(ming) lp token
(address to) ⇒ (uint liquidity)
This is a combination of some functions
to[pair(USDC/WETH)] = 0xB4e16d0168e52d35CaCD2c6185b44281Ec28C9Dc
- I’m using some values from quote🌟 amount0(WETH) :1000 amount1(USDC) : 974721890337 reserve0: 43086702975516 reserve1: 41997552572672937696884 totalSupply: 786985207163076840
amount0.mul(_totalSupply) / _reserve0 = 1000*786985207163076840/43086702975516 = 18265152.653
amount1.mul(_totalSupply) / _reserve1 = 974721890337 * 786985207163076840/41997552572672937696884 = 18265152.653
liquidity = 18265152.653 //
※ In fact, the amountA and B is decided the following code so, it is not happend the mentioned above.
function mint(address to) external lock returns (uint liquidity) {
(uint112 _reserve0, uint112 _reserve1,) = getReserves(); // gas savings
uint balance0 = IERC20(token0).balanceOf(address(this));
uint balance1 = IERC20(token1).balanceOf(address(this));
uint amount0 = balance0.sub(_reserve0);
uint amount1 = balance1.sub(_reserve1);
bool feeOn = _mintFee(_reserve0, _reserve1);
uint _totalSupply = totalSupply; // gas savings, must be defined here since totalSupply can update in _mintFee
if (_totalSupply == 0) {
liquidity = Math.sqrt(amount0.mul(amount1)).sub(MINIMUM_LIQUIDITY);
_mint(address(0), MINIif(A >B) returns B, if(A<B) returns AMUM_LIQUIDITY); // permanently lock the first MINIMUM_LIQUIDITY tokens
} else {
// min(A,B) => if(A >B) returns B, if(A<B) returns A
// get a smaller one
liquidity = Math.min(amount0.mul(_totalSupply) / _reserve0, amount1.mul(_totalSupply) / _reserve1);
}
require(liquidity > 0, 'UniswapV2: INSUFFICIENT_LIQUIDITY_MINTED');
_mint(to, liquidity);
_update(balance0, balance1, _reserve0, _reserve1);
if (feeOn) kLast = uint(reserve0).mul(reserve1); // reserve0 and reserve1 are up-to-date
emit Mint(msg.sender, amount0, amount1);
}
https://github.com/Uniswap/v2-core/blob/master/contracts/UniswapV2Pair.sol#L110