@@ -192,7 +192,7 @@ contract ReserveLiquidityStrategyTest is Test {
192192 uint256 stableReserveInPool = 1000e18 ; // S
193193 uint256 collateralReserveInPool = 1000e18 ; // C
194194 uint256 oraclePrice = 0.9e18 ; // P_oracle < 1e18 will make stable * (1-P) > 0
195- uint256 poolPrice = 1.02e18 ; // P_pool > P_oracle + threshold
195+ uint256 poolPrice = 1e18 ; // P_pool > P_oracle + threshold
196196 uint256 thresholdBps = 100 ; // 1%
197197
198198 mockPool.setReserves (stableReserveInPool, collateralReserveInPool);
@@ -203,11 +203,13 @@ contract ReserveLiquidityStrategyTest is Test {
203203 collateralToken.mint (address (mockPool), 1000e18 );
204204
205205 // Pre-calculate expected amounts with these values
206- // Using formula: numerator = C - P * S = 1000e18 - 1000e18*0.9 = 100e18
207- // collateralOut = numerator / 2 = 50e18
208- // stablesIn = (collateralOut * 1e18) / P = (50e18 * 1e18) / 0.9 = 55.555...e18
209- uint256 expectedCollateralOut = 50e18 ;
210- uint256 expectedStablesIn = 55555555555555555555 ; // 55.555...e18
206+ // Using formula:
207+ // numerator = C - P * S = 1000e18 - 1000e18*0.9 = 100e18
208+ // denominator = 1 + 1 - incentive = 2 - 0.1 = 1.9
209+ // collateralOut = numerator / denominator = 100e18 / 1.9 = 50.251256281407035175
210+ // stablesIn = (collateralOut * 1e18) / P = 55.834729201563372416
211+ uint256 expectedCollateralOut = 50251256281407035175 ;
212+ uint256 expectedStablesIn = 55834729201563372416 ; // 55.834...
211213 uint256 incentiveAmount = (expectedStablesIn * DEFAULT_INCENTIVE) / 10_000 ;
212214
213215 // Record balances before rebalance
@@ -274,7 +276,7 @@ contract ReserveLiquidityStrategyTest is Test {
274276 uint256 stableReserveInPool = 1000e18 ; // S
275277 uint256 collateralReserveInPool = 950e18 ; // C < P * S (1000e18)
276278 uint256 oraclePrice = 1e18 ; // P_oracle
277- uint256 poolPrice = 0.98e18 ; // P_pool < P_oracle - threshold
279+ uint256 poolPrice = 0.95e18 ; // P_pool < P_oracle - threshold
278280 uint256 thresholdBps = 100 ; // 1%
279281
280282 mockPool.setReserves (stableReserveInPool, collateralReserveInPool);
@@ -290,11 +292,13 @@ contract ReserveLiquidityStrategyTest is Test {
290292 uint256 reserveCollateralBefore = collateralToken.balanceOf (address (mockReserve));
291293
292294 // Calculate expected amounts
293- // Using formula: numerator = P * S - C = 1e18*1000e18 - 950e18 = 50e18
294- // collateralIn = numerator / 2 = 25e18
295- // stableOut = collateralIn * 1e18 / P = 25e18 / 1e18 = 25e18
296- uint256 expectedCollateralIn = 25e18 ;
297- uint256 expectedStableOut = 25e18 ;
295+ // Using formula:
296+ // numerator = P * S - C = 1000e18 - 950e18 = 50e18
297+ // denominator = P + P * (1 - incentive) = 1e18 + 1e18 * (1 - 0.01) = 1.99e18
298+ // stableOut = numerator / denominator = 50e18 / 1.99 = 25.125628140703517587
299+ // collateralIn = stableOut * 1e18 / P = 25.125628140703517587
300+ uint256 expectedCollateralIn = 25125628140703517587 ;
301+ uint256 expectedStableOut = 25125628140703517587 ;
298302 uint256 incentiveAmount = (expectedCollateralIn * DEFAULT_INCENTIVE) / 10_000 ;
299303
300304 // Expect RebalanceInitiated event with calculated amounts
@@ -372,8 +376,9 @@ contract ReserveLiquidityStrategyTest is Test {
372376
373377 // numerator = C_scaled - (P_oracle * S / 1e18)
374378 uint256 numerator = collateralReserveInPool_scaled - (oraclePrice * stableReserveInPool) / 1e18 ;
379+ uint256 denominator = 10_000 * 2 - DEFAULT_INCENTIVE;
375380
376- uint256 collateralOut_scaled = numerator / 2 ;
381+ uint256 collateralOut_scaled = ( numerator * 10_000 ) / denominator ;
377382 uint256 expectedCollateralOut = collateralOut_scaled / 1e12 ;
378383 uint256 expectedStablesIn = (collateralOut_scaled * 1e18 ) / oraclePrice;
379384 uint256 incentiveAmount = (expectedStablesIn * DEFAULT_INCENTIVE) / 10_000 ;
0 commit comments