Fast Khaki Raccoon
Medium
_swapForRewards
wrongly calculates the new amounts using an outdated value, which would cause the admin to receive a higher fee
depositFromPairedLpToken
would first reduce _adminAmt
, then use it to calculate _amountOut
.
uint256 _adminAmt = _getAdminFeeFromAmount(_amountTkn);
_amountTkn -= _adminAmt;
// ...
uint256 _amountOut = _token0 == PAIRED_LP_TOKEN
? (_rewardsPriceX96 * _amountTkn) / FixedPoint96.Q96
: (_amountTkn * FixedPoint96.Q96) / _rewardsPriceX96;
_swapForRewards(_amountTkn, _amountOut, _adminAmt);
Later it would use the same reduced amount to calculate the new amounts if _rewardsSwapAmountInOverride > 0
, not knowing that _amountOut (converted back into _amountIn ) + _adminAmt > _amountIn
, which would result in _adminAmt
+ _amountIn (needed for _amountOut)
to be bigger than _rewardsSwapAmountInOverride
function _swapForRewards(uint256 _amountIn, uint256 _amountOut, uint256 _adminAmt) internal {
if (_rewardsSwapAmountInOverride > 0) {
_adminAmt = (_adminAmt * _rewardsSwapAmountInOverride) / _amountIn;
_amountOut = (_amountOut * _rewardsSwapAmountInOverride) / _amountIn;
_amountIn = _rewardsSwapAmountInOverride;
}
No response
No response
- 1k for swap, fee 10%, price - 2 USD
- Admin fee = 1k * 10% = 100 fee
- Out = 900 / 2 = 450
results: in = 900, fee = 100, out = 450
_rewardsSwapAmountInOverride
= 50- admin = 100 * 50 / 900 = 5.55
- out = 450 * 50 / 900 = 25
- in = 50
As we can see out _rewardsSwapAmountInOverride
is 50, however we need 50 for the 25 out (as price is 2 USD), and out fee is 5.5, which is outside this 50, and not 10% of it, but 11%, which is a 10% increase in fee.
Admin receives a higher fee
Math is wrong
Fee is outside the prev. _rewardsSwapAmountInOverride
value, resulting in a bigger swap and a higher fee.
No response
Add the _adminAmt
to _amountIn
when in the if:
if (_rewardsSwapAmountInOverride > 0) {
_amountIn += _adminAmt;
_adminAmt = (_adminAmt * _rewardsSwapAmountInOverride) / _amountIn;
_amountOut = (_amountOut * _rewardsSwapAmountInOverride) / _amountIn;
_amountIn = _rewardsSwapAmountInOverride;
}