LP Tokens always valued at 3 PTs
LP Tokens are always valued at 3 PTs. As a result, users of the AMM pool might receive fewer assets/PTs than expected. The AMM pool might be unfairly arbitraged, resulting in a loss for the pool's LPs.\\nThe Napier AMM pool facilitates trade between underlying assets and PTs. The PTs in the pool are represented by the Curve's Base LP Token of the Curve's pool that holds the PTs. The Napier AMM pool and Router math assumes that the Base LP Token is equivalent to 3 times the amount of PTs, as shown below. When the pool is initially deployed, it is correct that the LP token is equivalent to 3 times the amount of PT.\\n```\\nFile: PoolMath.sol\\n    int256 internal constant N_COINS = 3;\\n..SNIP..\\n    function swapExactBaseLpTokenForUnderlying(PoolState memory pool, uint256 exactBaseLptIn)\\n        internal\\n..SNIP..\\n            // Note: Here we are multiplying by N_COINS because the swap formula is defined in terms of the amount of PT being swapped.\\n            // BaseLpt is equivalent to 3 times the amount of PT due to the initial deposit of 1:1:1:1=pt1:pt2:pt3:Lp share in Curve pool.\\n            exactBaseLptIn.neg() * N_COINS\\n..SNIP..\\n    function swapUnderlyingForExactBaseLpToken(PoolState memory pool, uint256 exactBaseLptOut)\\n..SNIP..\\n        (int256 _netUnderlyingToAccount18, int256 _netUnderlyingFee18, int256 _netUnderlyingToProtocol18) = executeSwap(\\n            pool,\\n            // Note: sign is defined from the perspective of the swapper.\\n            // positive because the swapper is buying pt\\n            exactBaseLptOut.toInt256() * N_COINS\\n```\\n\\n```\\nFile: NapierPool.sol\\n    /// @dev Number of coins in the BasePool\\n    uint256 internal constant N_COINS = 3;\\n..SNIP..\\n                    totalBaseLptTimesN: baseLptUsed * N_COINS,\\n..SNIP..\\n            totalBaseLptTimesN: totalBaseLpt * N_COINS,\\n```\\n\\nIn Curve, LP tokens are generally priced by computing the underlying tokens per share, hence dividing the total underlying token amounts by the total supply of the LP token. Given that the underlying assets in Curve's stable swap are pegged to each other, the invariant's $D$ value can be computed to estimate the total value of the underlying tokens.\\nCurve itself provides a function `get_virtual_price` that computes the price of the LP token by dividing $D$ with the total supply.\\nNote that for LP tokens, the ratio of the total underlying value and the total supply will grow (fee mechanism) over time. Thus, the virtual price's value will increase over time.\\nThis means the LP token will be worth more than 3 PTs in the Curve Pool over time. However, the Naiper AMM pool still values its LP token at a constant value of 3 PTs. This discrepancy between the value of the LP tokens in the Napier AMM pool and Curve pool might result in various issues, such as the following:\\nInvestors brought LP tokens at the price of 3.X PT from the market. The LP tokens are deposited into or swap into the Napier AMM pool. The Naiper Pool will always assume that the price of the LP token is 3 PTs, thus shortchanging the number of assets or PTs returned to users.\\nPotential arbitrage opportunity where malicious users obtain the LP token from the Naiper AMM pool at a value of 3 PT and redeem the LP token at a value higher than 3 PTs, pocketing the differences.
Naiper and Pendle share the same core math for their AMM pool.\\nIn Pendle, the AMM stores the PTs and SY (Standard Yield Token). When performing any operation (e.g., deposit, swap), the SY will be converted to the underlying assets based on SY's current rate before performing any math operation. If it is a SY (wstETH), the SY's rate will be the current exchange rate for wstETH to stETH/ETH. One could also think the AMM's reserve is PTs and Underlying Assets under the hood.\\nIn Napier, the AMM stores the PTs and Curve's LP tokens. When performing any operation, the math will always convert the LP token to underlying assets using a static exchange rate of 3. However, this is incorrect, as the value of an LP token will grow over time. The AMM should value the LP tokens based on their current value. The virtual price of the LP token and other information can be leveraged to derive the current value of the LP tokens to facilitate the math operation within the pool.
Users of the AMM pool might receive fewer assets/PTs than expected. The AMM pool might be unfairly arbitraged, resulting in a loss for the pool's LPs.
```\\nFile: PoolMath.sol\\n    int256 internal constant N_COINS = 3;\\n..SNIP..\\n    function swapExactBaseLpTokenForUnderlying(PoolState memory pool, uint256 exactBaseLptIn)\\n        internal\\n..SNIP..\\n            // Note: Here we are multiplying by N_COINS because the swap formula is defined in terms of the amount of PT being swapped.\\n            // BaseLpt is equivalent to 3 times the amount of PT due to the initial deposit of 1:1:1:1=pt1:pt2:pt3:Lp share in Curve pool.\\n            exactBaseLptIn.neg() * N_COINS\\n..SNIP..\\n    function swapUnderlyingForExactBaseLpToken(PoolState memory pool, uint256 exactBaseLptOut)\\n..SNIP..\\n        (int256 _netUnderlyingToAccount18, int256 _netUnderlyingFee18, int256 _netUnderlyingToProtocol18) = executeSwap(\\n            pool,\\n            // Note: sign is defined from the perspective of the swapper.\\n            // positive because the swapper is buying pt\\n            exactBaseLptOut.toInt256() * N_COINS\\n```\\n