Skip to content

Commit

Permalink
check that K updates for next swap
Browse files Browse the repository at this point in the history
  • Loading branch information
kinrezC committed Apr 22, 2024
1 parent 063c249 commit 55418b8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
5 changes: 3 additions & 2 deletions test/SYCoveredCall/unit/SetUp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ contract SYCoveredCallSetUp is SetUp {
uint256 defaultReserveXMil = 1_000_000 ether;
uint256 defaultReserveXDeep = ONE * 10_000_000;

uint256 defaultPrice = ONE;
uint256 defaultPrice;
uint256 defaultPricePoint9Rate = 0.84167999326 ether;

address public constant wstETH = 0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0; //real wsteth
Expand Down Expand Up @@ -105,6 +105,8 @@ contract SYCoveredCallSetUp is SetUp {
YT: YT
});

defaultPrice = uint256(pendleRateAnchor);

bytes memory initialPoolData = solver.getInitialPoolDataGivenX(
defaultReserveX, defaultPrice, defaultParams
);
Expand All @@ -118,7 +120,6 @@ contract SYCoveredCallSetUp is SetUp {
feeCollector: address(0),
controllerFee: 0
});
console2.log("timestamp", block.timestamp);

(POOL_ID,,) = dfmm.init(defaultInitParams);

Expand Down
31 changes: 31 additions & 0 deletions test/SYCoveredCall/unit/Swap.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,37 @@ contract SYCoveredCallSwapTest is SYCoveredCallSetUp {
);
}

function test_SYCoveredCall_swap_SwapsXforY_Warp2DaysUpdatesK()
public
init
{
vm.warp(block.timestamp + 2 days);

(uint256[] memory reserves, uint256 L) =
solver.getReservesAndLiquidity(POOL_ID);
SYCoveredCallParams memory params = solver.getPoolParams(POOL_ID);
uint256 initialK = computeKGivenLastPrice(reserves[0], L, params);
uint256 amountIn = 0.1 ether;
bool swapXForY = true;
console2.log("initialK", initialK);

(bool valid, uint256 amountOut,, bytes memory payload) =
solver.simulateSwap(POOL_ID, swapXForY, amountIn, block.timestamp);
assertEq(valid, true);

console2.log("out", amountOut);

(,, uint256 inputAmount, uint256 outputAmount) =
dfmm.swap(POOL_ID, address(this), payload, "");

(uint256[] memory nextReserves, uint256 nextL) =
solver.getReservesAndLiquidity(POOL_ID);
SYCoveredCallParams memory nextParams = solver.getPoolParams(POOL_ID);

uint256 k = computeKGivenLastPrice(nextReserves[0], nextL, nextParams);
console2.log("k", k);
}

function test_SYCoveredCall_swap_SwapsYforX() public init {
uint256 preDfmmBalanceX = tokenX.balanceOf(address(dfmm));
uint256 preDfmmBalanceY = tokenY.balanceOf(address(dfmm));
Expand Down

0 comments on commit 55418b8

Please sign in to comment.