The `_estimateWithdrawalLp` function might return a very large value, result in users losing significant incentives or being unable to withdraw from the Dispatcher contract
The `_estimateWithdrawalLp` function might return a very large value, result in users losing significant incentives or being unable to withdraw from the Dispatcher contract\\nIn Dispatcher contract, `_estimateWithdrawalLp` function returns the value of shares amount based on the average of ratios `amount0 / reserve0` and `amount1 / reserve1`.\\n```\\nfunction _estimateWithdrawalLp(\\n    uint256 reserve0,\\n    uint256 reserve1,\\n    uint256 _totalSupply,\\n    uint256 amount0,\\n    uint256 amount1\\n) private pure returns (uint256 shareAmount) {\\n    shareAmount =\\n        ((amount0 * _totalSupply) / reserve0 + (amount1 * _totalSupply) / reserve1) /\\n        2;\\n}\\n```\\n\\nFrom `Dispatcher.withdraw` and `Dispatcher.deposit` function, amount0 and amount1 will be the accumulated fees of users\\n```\\nuint256 lpAmount;\\n{\\n    (uint256 fee0, uint256 fee1) = _calcFees(feesGrow, user);\\n    lpAmount = _estimateWithdrawalLp(reserve0, reserve1, _totalSupply, fee0, fee1);\\n}\\nuser.shares -= lpAmount;\\n_withdrawFee(pool, lpAmount, reserve0, reserve1, _totalSupply, deviationBP);\\n```\\n\\nHowever, it is important to note that the values of reserve0 and reserve1 can fluctuate significantly. This is because the positions of the Multipool in UniSwapV3 pools (concentrated) are unstable on-chain, and they can change substantially as the state of the pools changes. As a result, the `_estimateWithdrawalLp` function might return a large value even for a small fee amount. This could potentially lead to reverting due to underflow in the deposit function (in cases where lpAmount > user.shares), or it could result in withdrawing a larger amount of Multipool LP than initially expected.\\nScenario:\\nTotal supply of Multipool is 1e18, and Alice has 1e16 (1%) LP amounts which deposited into Dispatcher contract.\\nAlice accrued fees = 200 USDC and 100 USDT\\nThe reserves of Multipool are 100,000 USDC and 100,000 USDT, `_estimateWithdrawalLp` of Alice fees will be `(0.2% + 0.1%) / 2 * totalSupply` = `0.15% * totalSupply` = 1.5e15 LP amounts\\nHowever, in some cases, UniSwapV3 pools may experience fluctuations, reserves of Multipool are 10,000 USDC and 190,000 USDT, `_estimateWithdrawalLp` of Alice fees will be `(2% + 0.052%) / 2 * totalSupply` = `1.026% * totalSupply` = 1.026e16 LP amounts This result is greater than LP amounts of Alice (1e16), leading to reverting by underflow in deposit/withdraw function of Dispatcher contract.
Shouldn't use the average ratio for calculation in_estimateWithdrawalLp function
Users may face 2 potential issues when interacting with the Dispatcher contract.\\nThey might be unable to deposit/withdraw\\nSecondly, users could potentially lose significant incentives when depositing or withdrawing due to unexpected withdrawals of LP amounts for their fees.
```\\nfunction _estimateWithdrawalLp(\\n    uint256 reserve0,\\n    uint256 reserve1,\\n    uint256 _totalSupply,\\n    uint256 amount0,\\n    uint256 amount1\\n) private pure returns (uint256 shareAmount) {\\n    shareAmount =\\n        ((amount0 * _totalSupply) / reserve0 + (amount1 * _totalSupply) / reserve1) /\\n        2;\\n}\\n```\\n