@@ -84,13 +84,150 @@ contract G3MTest is Test {
8484 _;
8585 }
8686
87+ /// @dev Initializes a basic pool in dfmm with 0 swapFee.
88+ modifier basic_feeless () {
89+ vm.warp (0 );
90+ G3M.G3MParams memory params = G3M.G3MParams ({
91+ wX: 0.5 ether,
92+ wY: 0.5 ether,
93+ swapFee: 0 ,
94+ controller: address (0 )
95+ });
96+ uint256 init_p = 1 ether ;
97+ uint256 init_x = 1 ether ;
98+ bytes memory initData =
99+ solver.getInitialPoolData (init_x, init_p, params);
100+
101+ IDFMM.InitParams memory initParams = IDFMM.InitParams ({
102+ strategy: address (g3m),
103+ tokenX: tokenX,
104+ tokenY: tokenY,
105+ data: initData
106+ });
107+
108+ dfmm.init (initParams);
109+ _;
110+ }
111+
87112 function test_g3m_swap () public basic {
88113 uint256 amountIn = 10 ether ;
89114 uint256 poolId = dfmm.nonce () - 1 ;
90115 (bool valid , uint256 amountOut , uint256 price , bytes memory swapData ) =
91116 solver.simulateSwap (poolId, true , amountIn);
92117 }
93118
119+ function test_g3m_swap_x_in_no_fee () public basic_feeless {
120+ bool xIn = true ;
121+ uint256 amountIn = 0.1 ether ;
122+ uint256 poolId = dfmm.nonce () - 1 ;
123+ (bool valid , uint256 amountOut , uint256 price , bytes memory swapData ) =
124+ solver.simulateSwap (poolId, xIn, amountIn);
125+
126+ console2.log ("Valid: " , valid);
127+ assert (valid);
128+
129+ console2.log ("AmountOut: " , amountOut);
130+ assertEq (amountOut, 90_909_090_909_090_907 );
131+
132+ (uint256 endReservesRx , uint256 endReservesRy , uint256 endReservesL ) =
133+ abi.decode (swapData, (uint256 , uint256 , uint256 ));
134+
135+ console2.log ("endReservesRx: " , endReservesRx);
136+ assertEq (endReservesRx, 1.1 ether);
137+
138+ console2.log ("endReservesRy: " , endReservesRy);
139+ assertEq (endReservesRy, 909_090_909_090_909_093 );
140+
141+ console2.log ("endReservesL: " , endReservesL);
142+ assertEq (endReservesL, 1 ether);
143+
144+ dfmm.swap (poolId, swapData);
145+ }
146+
147+ function test_g3m_swap_y_in_no_fee () public basic_feeless {
148+ bool xIn = false ;
149+ uint256 amountIn = 0.1 ether ;
150+ uint256 poolId = dfmm.nonce () - 1 ;
151+ (bool valid , uint256 amountOut , uint256 price , bytes memory swapData ) =
152+ solver.simulateSwap (poolId, xIn, amountIn);
153+
154+ console2.log ("Valid: " , valid);
155+ assert (valid);
156+
157+ console2.log ("AmountOut: " , amountOut);
158+ assertEq (amountOut, 90_909_090_909_090_907 );
159+
160+ (uint256 endReservesRx , uint256 endReservesRy , uint256 endReservesL ) =
161+ abi.decode (swapData, (uint256 , uint256 , uint256 ));
162+
163+ console2.log ("endReservesRx: " , endReservesRx);
164+ assertEq (endReservesRx, 909_090_909_090_909_093 );
165+
166+ console2.log ("endReservesRy: " , endReservesRy);
167+ assertEq (endReservesRy, 1.1 ether);
168+
169+ console2.log ("endReservesL: " , endReservesL);
170+ assertEq (endReservesL, 1 ether);
171+
172+ dfmm.swap (poolId, swapData);
173+ }
174+
175+ function test_g3m_swap_x_in_with_fee () public basic {
176+ bool xIn = true ;
177+ uint256 amountIn = 0.1 ether ;
178+ uint256 poolId = dfmm.nonce () - 1 ;
179+ (bool valid , uint256 amountOut , uint256 price , bytes memory swapData ) =
180+ solver.simulateSwap (poolId, xIn, amountIn);
181+
182+ console2.log ("Valid: " , valid);
183+ assert (valid);
184+
185+ console2.log ("AmountOut: " , amountOut);
186+ assertEq (amountOut, 90_636_343_181_818_178 );
187+
188+ (uint256 endReservesRx , uint256 endReservesRy , uint256 endReservesL ) =
189+ abi.decode (swapData, (uint256 , uint256 , uint256 ));
190+
191+ console2.log ("endReservesRx: " , endReservesRx);
192+ assertEq (endReservesRx, 1.1 ether);
193+
194+ console2.log ("endReservesRy: " , endReservesRy);
195+ assertEq (endReservesRy, 909_363_656_818_181_822 );
196+
197+ console2.log ("endReservesL: " , endReservesL);
198+ assertEq (endReservesL, 1.00015 ether);
199+
200+ dfmm.swap (poolId, swapData);
201+ }
202+
203+ function test_g3m_swap_y_in_with_fee () public basic {
204+ bool xIn = false ;
205+ uint256 amountIn = 0.1 ether ;
206+ uint256 poolId = dfmm.nonce () - 1 ;
207+ (bool valid , uint256 amountOut , uint256 price , bytes memory swapData ) =
208+ solver.simulateSwap (poolId, xIn, amountIn);
209+
210+ console2.log ("Valid: " , valid);
211+ assert (valid);
212+
213+ console2.log ("AmountOut: " , amountOut);
214+ assertEq (amountOut, 90_636_343_181_818_178 );
215+
216+ (uint256 endReservesRx , uint256 endReservesRy , uint256 endReservesL ) =
217+ abi.decode (swapData, (uint256 , uint256 , uint256 ));
218+
219+ console2.log ("endReservesRx: " , endReservesRx);
220+ assertEq (endReservesRx, 909_363_656_818_181_822 );
221+
222+ console2.log ("endReservesRy: " , endReservesRy);
223+ assertEq (endReservesRy, 1.1 ether);
224+
225+ console2.log ("endReservesL: " , endReservesL);
226+ assertEq (endReservesL, 1.00015 ether);
227+
228+ dfmm.swap (poolId, swapData);
229+ }
230+
94231 function test_diff_lower () public basic {
95232 uint256 poolId = dfmm.nonce () - 1 ;
96233 int256 diffLowered =
0 commit comments