Skip to content

Commit 27286d2

Browse files
committed
test: deep pool approxes
1 parent 4699489 commit 27286d2

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed

src/test/G3M/G3MTest.t.sol

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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,62 @@ 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+
284+
function test_g3m_swap_y_in_deep() public deep {
285+
bool xIn = false;
286+
uint256 amountIn = 0.1 ether;
287+
uint256 poolId = dfmm.nonce() - 1;
288+
(bool valid, uint256 amountOut, uint256 price, bytes memory swapData) =
289+
solver.simulateSwap(poolId, xIn, amountIn);
290+
291+
console2.log("Valid: ", valid);
292+
assert(valid);
293+
294+
console2.log("AmountOut: ", amountOut);
295+
assertApproxEqRel(amountOut, 0.0997 ether, 1e11);
296+
297+
(uint256 endReservesRx, uint256 endReservesRy, uint256 endReservesL) =
298+
abi.decode(swapData, (uint256, uint256, uint256));
299+
300+
console2.log("endReservesRx: ", endReservesRx);
301+
assertApproxEqRel(endReservesRx, 999_999.9003 ether, 1e10);
302+
303+
console2.log("endReservesRy: ", endReservesRy);
304+
assertEq(endReservesRy, 1_000_000.1 ether);
305+
306+
console2.log("endReservesL: ", endReservesL);
307+
assertApproxEqRel(endReservesL, 1_000_000.00015 ether, 1e10);
308+
309+
dfmm.swap(poolId, swapData);
310+
}
311+
231312
function test_diff_lower() public basic {
232313
uint256 poolId = dfmm.nonce() - 1;
233314
int256 diffLowered =

0 commit comments

Comments
 (0)