Submitted by GalloDaSballo, also found by GalloDaSballo
MagnetarHelper.getFractionForAmount is used to determine the fraction (shares) that will be received when an amount is deposited. The code needs to compute the totalShares and then determine what the fraction is going to be.
The logic is used in Singularity._removeAsset and since its tied to a withdrawal, the rounding will be down. However, in MagnetarHelper the round is up.
https://github.com/Tapioca-DAO/tapioca-periph/blob/2ddbcb1cde03b548e13421b2dba66435d2ac8eb5/contracts/Magnetar/MagnetarHelper.sol#L208-L219
See the actual implementation in Singularity:
https://github.com/Tapioca-DAO/Tapioca-bar/blob/c2031ac2e2667ac8f9ac48eaedae3dd52abef559/contracts/markets/singularity/SGLCommon.sol#L199-L216
This will cause issues when calculating how much fraction to withdraw based on the amount required by the withdrawer.
Change the rounding direction:
Math
cryptotechmaker (Tapioca) confirmed and commented:
