@@ -109,6 +109,31 @@ contract G3MTest is Test {
109109 _;
110110 }
111111
112+ /// @dev Initializes a basic pool in dfmm.
113+ modifier deep () {
114+ vm.warp (0 );
115+ G3M.G3MParams memory params = G3M.G3MParams ({
116+ wX: 0.5 ether,
117+ wY: 0.5 ether,
118+ swapFee: TEST_SWAP_FEE,
119+ controller: address (0 )
120+ });
121+ uint256 init_p = 1 ether ;
122+ uint256 init_x = 1_000_000 ether ;
123+ bytes memory initData =
124+ solver.getInitialPoolData (init_x, init_p, params);
125+
126+ IDFMM.InitParams memory initParams = IDFMM.InitParams ({
127+ strategy: address (g3m),
128+ tokenX: tokenX,
129+ tokenY: tokenY,
130+ data: initData
131+ });
132+
133+ dfmm.init (initParams);
134+ _;
135+ }
136+
112137 function test_g3m_swap () public basic {
113138 uint256 amountIn = 10 ether ;
114139 uint256 poolId = dfmm.nonce () - 1 ;
@@ -228,6 +253,34 @@ contract G3MTest is Test {
228253 dfmm.swap (poolId, swapData);
229254 }
230255
256+ function test_g3m_swap_x_in_deep () public deep {
257+ bool xIn = true ;
258+ uint256 amountIn = 0.1 ether ;
259+ uint256 poolId = dfmm.nonce () - 1 ;
260+ (bool valid , uint256 amountOut , uint256 price , bytes memory swapData ) =
261+ solver.simulateSwap (poolId, xIn, amountIn);
262+
263+ console2.log ("Valid: " , valid);
264+ assert (valid);
265+
266+ console2.log ("AmountOut: " , amountOut);
267+ assertApproxEqRel (amountOut, 0.0997 ether, 1e11 );
268+
269+ (uint256 endReservesRx , uint256 endReservesRy , uint256 endReservesL ) =
270+ abi.decode (swapData, (uint256 , uint256 , uint256 ));
271+
272+ console2.log ("endReservesRx: " , endReservesRx);
273+ assertEq (endReservesRx, 1_000_000.1 ether);
274+
275+ console2.log ("endReservesRy: " , endReservesRy);
276+ assertApproxEqRel (endReservesRy, 999_999.9003 ether, 1e10 );
277+
278+ console2.log ("endReservesL: " , endReservesL);
279+ assertApproxEqRel (endReservesL, 1_000_000.00015 ether, 1e10 );
280+
281+ dfmm.swap (poolId, swapData);
282+ }
283+
231284 function test_diff_lower () public basic {
232285 uint256 poolId = dfmm.nonce () - 1 ;
233286 int256 diffLowered =
0 commit comments