Submitted by cmichel
The IndexPool.constructor function already mints INIT_POOL_SUPPLY = 100 * 1e18 = 1e20 LP tokens to the zero address.
When trying to use the pool, someone has to provide the actual initial reserve tokens in mint.
On the first mint, the pool reserves are zero and the token amount required to mint is just this ratio itself: uint120 amountIn = reserve != 0 ? uint120(_mul(ratio, reserve)) : ratio;
Note that the amountIn is independent of the token which does not make much sense.
This implies that all tokens must be provided in equal raw amounts, regardless of their decimals and value.
Imagine I want to create a DAI/WBTC pool.
If I want to initialize the pool with 100$ of DAI, amountIn = ratio needs to be 100*1e18=1e20 as DAI has 18 decimals.
However, I now also need to supply 1e20 of WBTC (which has 8 decimals) and Id need to pay 1e20/1e8 * priceOfBTC, over a quadrillion dollars to match it with the 100$ of DAI.
Even in a pool where all tokens have the same decimals and the same value, like USDC <> USDT, it leads to issues:
Its unclear why its assumed that the pools tokens are all in equal value - this is not a StableSwap-like pool.
Any pool that uses tokens that dont have the same value and share the same decimals cannot be used because initial liquidity cannot be provided in an economically justifiable way.
It also leads to issues where the second LP supplier has to pay less tokens to receive the exact same amount of LP tokens that the initial minter receives. They can steal from the initial LP provider by burning these tokens again.
Do not mint the initial token supply to the zero address in the constructor.
Do it like Uniswap/Balancer and let the first liquidity provider provide arbitrary token amounts, then mint the initial pool supply.
If reserve == 0, amountIn should just take the pool balances that were transferred to this account.
In case the initial mint to the zero address in the constructor was done to prevent the Uniswap-attack where the price of a single wei of LP token can be very high and price out LPs, send a small fraction of this initial LP supply (~1000) to the zero address after it was minted to the first supplier in mint.
maxsam4 (Sushi) confirmed
