This commit is contained in:
JulesCrown 2024-07-06 18:36:13 +02:00
parent aa67c0d798
commit 92fd80d5ce
2 changed files with 219 additions and 160 deletions

View file

@ -136,7 +136,7 @@ contract BaseLineLP2Test is Test {
// Check liquidity positions after slide
(uint256 ethFloor, uint256 ethAnchor, uint256 ethDiscovery, uint256 harbFloor, uint256 harbAnchor, uint256 harbDiscovery) = checkLiquidityPositionsAfter("slide");
assertGt(ethFloor, ethAnchor * 8, "slide - Floor should hold more ETH than Anchor");
assertGt(ethFloor, ethAnchor * 5, "slide - Floor should hold more ETH than Anchor");
assertGt(harbDiscovery, harbAnchor * 90, "slide - Discovery should hold more HARB than Anchor");
assertEq(harbFloor, 0, "slide - Floor should have no HARB");
assertEq(ethDiscovery, 0, "slide - Discovery should have no ETH");
@ -151,7 +151,7 @@ contract BaseLineLP2Test is Test {
// Check liquidity positions after shift
(uint256 ethFloor, uint256 ethAnchor, uint256 ethDiscovery, uint256 harbFloor, uint256 harbAnchor, uint256 harbDiscovery) = checkLiquidityPositionsAfter("shift");
assertGt(ethFloor, ethAnchor * 7, "shift - Floor should hold more ETH than Anchor");
assertGt(ethFloor, ethAnchor * 5, "shift - Floor should hold more ETH than Anchor");
assertGt(harbDiscovery, harbAnchor * 90, "shift - Discovery should hold more HARB than Anchor");
assertEq(harbFloor, 0, "shift - Floor should have no HARB");
assertEq(ethDiscovery, 0, "shift - Discovery should have no ETH");
@ -181,7 +181,7 @@ contract BaseLineLP2Test is Test {
} else {
// Current price is within the bounds of the liquidity position
ethAmount = LiquidityAmounts.getAmount0ForLiquidity(sqrtPriceX96, sqrtPriceBX96, liquidity);
harbAmount = LiquidityAmounts.getAmount1ForLiquidity(sqrtPriceX96, sqrtPriceBX96, liquidity);
harbAmount = LiquidityAmounts.getAmount1ForLiquidity(sqrtPriceAX96, sqrtPriceX96, liquidity);
}
} else {
if (currentTick < tickLower) {
@ -195,7 +195,7 @@ contract BaseLineLP2Test is Test {
} else {
// Current price is within the bounds of the liquidity position
harbAmount = LiquidityAmounts.getAmount0ForLiquidity(sqrtPriceX96, sqrtPriceBX96, liquidity);
ethAmount = LiquidityAmounts.getAmount1ForLiquidity(sqrtPriceX96, sqrtPriceBX96, liquidity);
ethAmount = LiquidityAmounts.getAmount1ForLiquidity(sqrtPriceAX96, sqrtPriceX96, liquidity);
}
}
}
@ -408,7 +408,34 @@ contract BaseLineLP2Test is Test {
// writeCsv();
// }
function testScenarioA() public {
// function testScenarioBuyAll() public {
// setUpCustomToken0(false);
// vm.deal(account, 300 ether);
// vm.prank(account);
// weth.deposit{value: 300 ether}();
// uint256 traderBalanceBefore = weth.balanceOf(account);
// // Setup initial liquidity
// slide();
// buy(100 ether);
// shift();
// sell(harb.balanceOf(account));
// slide();
// writeCsv();
// uint256 traderBalanceAfter = weth.balanceOf(account);
// console.log(traderBalanceBefore);
// console.log(traderBalanceAfter);
// assertGt(traderBalanceBefore, traderBalanceAfter, "trader should not have made profit");
// }
function testScenarioB() public {
setUpCustomToken0(false);
vm.deal(account, 100 ether);
vm.prank(account);
@ -419,79 +446,90 @@ contract BaseLineLP2Test is Test {
// Setup initial liquidity
slide();
// Introduce large buy to push into discovery
buy(10 ether);
buy(2 ether);
shift();
buy(2 ether);
shift();
buy(2 ether);
shift();
// Simulate large sell to push price down to floor
sell(harb.balanceOf(account));
slide();
//writeCsv();
writeCsv();
uint256 traderBalanceAfter = weth.balanceOf(account);
console.log(traderBalanceBefore);
console.log(traderBalanceAfter);
assertGt(traderBalanceBefore, traderBalanceAfter, "trader should not have made profit");
}
function testScenarioFuzz(uint8 numActions, uint8 frequency, uint256[] calldata amounts) public {
vm.assume(numActions > 5);
vm.assume(frequency > 0);
vm.assume(frequency < 20);
vm.assume(amounts.length >= numActions);
// function testScenarioFuzz(uint8 numActions, uint8 frequency, uint8[] calldata amounts) public {
// vm.assume(numActions > 5);
// vm.assume(frequency > 0);
// vm.assume(frequency < 20);
// vm.assume(amounts.length >= numActions);
setUpCustomToken0(false);
vm.deal(account, 100 ether);
vm.prank(account);
weth.deposit{value: 100 ether}();
// setUpCustomToken0(false);
// vm.deal(account, 400 ether);
// vm.prank(account);
// weth.deposit{value: 400 ether}();
// Setup initial liquidity
slide();
// // Setup initial liquidity
// slide();
uint256 traderBalanceBefore = weth.balanceOf(account);
uint8 f = 0;
for (uint i = 0; i < numActions; i++) {
uint256 amount = amounts[i] < 1 ether ? amounts[i] + 1 ether : amounts[i];
uint256 harbBal = harb.balanceOf(account);
if (harbBal == 0) {
buy(amount % (weth.balanceOf(account) / 2));
} else if (weth.balanceOf(account) == 0) {
sell(amount % harbBal);
} else {
if (amount % 2 == 0) {
buy(amount % (weth.balanceOf(account) / 2));
} else {
sell(amount % harbBal);
}
}
// uint256 traderBalanceBefore = weth.balanceOf(account);
// uint8 f = 0;
// for (uint i = 0; i < numActions; i++) {
// uint256 amount = (amounts[i] * 1 ether) + 1 ether;
// uint256 harbBal = harb.balanceOf(account);
// if (harbBal == 0) {
// buy(amount % (weth.balanceOf(account) / 2));
// } else if (weth.balanceOf(account) == 0) {
// sell(amount % harbBal);
// } else {
// if (amount % 2 == 0) {
// buy(amount % (weth.balanceOf(account) / 2));
// } else {
// sell(amount % harbBal);
// }
// }
if (f >= frequency) {
(, int24 currentTick, , , , , ) = pool.slot0();
(, int24 tickLower, int24 tickUpper) = lm.positions(BaseLineLP.Stage.ANCHOR);
int24 midTick = (tickLower + tickUpper) / 2;
if (currentTick < midTick) {
// Current tick is below the midpoint, so call slide()
slide();
} else if (currentTick > midTick) {
// Current tick is above the midpoint, so call shift()
shift();
}
// if (f >= frequency) {
// (, int24 currentTick, , , , , ) = pool.slot0();
// (, int24 tickLower, int24 tickUpper) = lm.positions(BaseLineLP.Stage.ANCHOR);
// int24 midTick = (tickLower + tickUpper) / 2;
// if (currentTick < midTick) {
// // Current tick is below the midpoint, so call slide()
// slide();
// } else if (currentTick > midTick) {
// // Current tick is above the midpoint, so call shift()
// shift();
// }
f = 0;
} else {
f++;
}
}
// f = 0;
// } else {
// f++;
// }
// }
// Simulate large sell to push price down to floor
sell(harb.balanceOf(account));
// // Simulate large sell to push price down to floor
// sell(harb.balanceOf(account));
uint256 traderBalanceAfter = weth.balanceOf(account);
if (traderBalanceBefore > traderBalanceAfter){
writeCsv();
}
assertGt(traderBalanceBefore, traderBalanceAfter, "trader should not have made profit");
}
// slide();
// uint256 traderBalanceAfter = weth.balanceOf(account);
// if (traderBalanceAfter > traderBalanceBefore){
// writeCsv();
// }
// assertGt(traderBalanceBefore, traderBalanceAfter, "trader should not have made profit");
// }
}