Skip to content

Commit

Permalink
test: deep pool approxes
Browse files Browse the repository at this point in the history
  • Loading branch information
Autoparallel committed Feb 21, 2024
1 parent 4699489 commit 45bc289
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions src/test/G3M/G3MTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,31 @@ contract G3MTest is Test {
_;
}

/// @dev Initializes a basic pool in dfmm.
modifier deep() {
vm.warp(0);
G3M.G3MParams memory params = G3M.G3MParams({
wX: 0.5 ether,
wY: 0.5 ether,
swapFee: TEST_SWAP_FEE,
controller: address(0)
});
uint256 init_p = 1 ether;
uint256 init_x = 1_000_000 ether;
bytes memory initData =
solver.getInitialPoolData(init_x, init_p, params);

IDFMM.InitParams memory initParams = IDFMM.InitParams({
strategy: address(g3m),
tokenX: tokenX,
tokenY: tokenY,
data: initData
});

dfmm.init(initParams);
_;
}

function test_g3m_swap() public basic {
uint256 amountIn = 10 ether;
uint256 poolId = dfmm.nonce() - 1;
Expand Down Expand Up @@ -228,6 +253,34 @@ contract G3MTest is Test {
dfmm.swap(poolId, swapData);
}

function test_g3m_swap_x_in_deep() public deep {
bool xIn = true;
uint256 amountIn = 0.1 ether;
uint256 poolId = dfmm.nonce() - 1;
(bool valid, uint256 amountOut, uint256 price, bytes memory swapData) =
solver.simulateSwap(poolId, xIn, amountIn);

console2.log("Valid: ", valid);
assert(valid);

console2.log("AmountOut: ", amountOut);
assertApproxEqRel(amountOut, 0.0997 ether, 1e11);

(uint256 endReservesRx, uint256 endReservesRy, uint256 endReservesL) =
abi.decode(swapData, (uint256, uint256, uint256));

console2.log("endReservesRx: ", endReservesRx);
assertEq(endReservesRx, 1_000_000.1 ether);

console2.log("endReservesRy: ", endReservesRy);
assertApproxEqRel(endReservesRy, 999_999.9003 ether, 1e10);

console2.log("endReservesL: ", endReservesL);
assertApproxEqRel(endReservesL, 1_000_000.00015 ether, 1e10);

dfmm.swap(poolId, swapData);
}

function test_diff_lower() public basic {
uint256 poolId = dfmm.nonce() - 1;
int256 diffLowered =
Expand Down

0 comments on commit 45bc289

Please sign in to comment.