Submitted by rvierdiiev
In case position has grown, then protocol receives performance fee.
https://github.com/code-423n4/2024-05-bakerfi/blob/main/contracts/core/Vault.sol#L153-L158
We will check how shares amount is calculated and why its less than it should be.
Suppose that totalSupply() == 100000 and _totalAssets(maxPriceAge) == 100100, so we earned 100 eth as additional profit. balanceChange == 100 and performance fee is 10%, which is 10 eth.
sharesToMint = 10 * 100000 / 100100 = 9.99001
This means that with 9.990001 shares protocol should be able to grab 10 eth fee, which is indeed like that if we convert 9.99001 * 100100 / 100000 = 10.
The problem is that minting is done later, which means that totalSupply() will increase with 9.99001 shares. So if we calculate fees amount now we will get a smaller amount: 9.99001 * 100100 / 100009.99001 = 9.999001
Protocol receives smaller amount of fees.
VsCode
The formula should be adjusted to count increase of total supply.
hvasconcelos (BakerFi) acknowledged
