While Calculating the value for availableLiquidity we need to subtract the holdAmount as it is not part of Liquidity yet.
Summary
While Calculating the Liquidity for stableToken we did not care about holdAmount , holdAmount is not part of Current Liquidity.In case of baseToken we subtract holdAmount from availableLiquidity
Vulnerability Detail
The getPoolAvailableLiquidity function is used to check for available liquidity in terms of baseTokens.
The if condition only check for tokenBalance.amount.toInt256() + tokenBalance.unsettledAmount<tokenBalance.lossAmount.toInt256() which means that all the token balance in amount and unsettled is available for liquidity which is not correct we also holdAmount from these balances. We do not subtract the holdAmount from Liquidity in case of stableToken while in baseToken case we do.
Impact
The amount calculated for AvailableLiquidity in stableCoin is not correct it will impact the case where we subtract from available liquidity.
aman
High
While Calculating the value for availableLiquidity we need to subtract the holdAmount as it is not part of Liquidity yet.
Summary
While Calculating the Liquidity for
stableToken
we did not care aboutholdAmount
,holdAmount
is not part of Current Liquidity.In case ofbaseToken
we subtractholdAmount
fromavailableLiquidity
Vulnerability Detail
The
getPoolAvailableLiquidity
function is used to check for available liquidity in terms ofbaseTokens
.The if condition only check for
tokenBalance.amount.toInt256() + tokenBalance.unsettledAmount<tokenBalance.lossAmount.toInt256()
which means that all the token balance in amount and unsettled is available for liquidity which is not correct we alsoholdAmount
from these balances. We do not subtract theholdAmount
from Liquidity in case ofstableToken
while inbaseToken
case we do.Impact
The amount calculated for AvailableLiquidity in stableCoin is not correct it will impact the case where we subtract from available liquidity.
Code Snippet
https://github.com/sherlock-audit/2024-05-elfi-protocol/blob/main/elfi-perp-contracts/contracts/process/LpPoolQueryProcess.sol#L151-L191
Tool used
Manual Review
Recommendation
Also handle the
holdAmount
in case ofstableToken
balances.