This commit is contained in:
JulesCrown 2024-07-13 14:56:13 +02:00
parent 969d78247c
commit ba298cfd50
4 changed files with 38 additions and 47 deletions

View file

@ -70,7 +70,7 @@ contract BaseLineLP2Test is Test {
} else {
// Token (valued at 1 USD cent) as token0, ETH as token1
// We invert the logic to represent the price of 1 token in terms of ETH
price = uint256(10**16) / 3700; // Adjust for 18 decimal places
price = uint256(10**16) / 3000; // Adjust for 18 decimal places
}
uint160 sqrtPriceX96 = uint160(sqrt(price) * 2**96 / 10**9); // Adjust sqrt value to 96-bit precision
@ -131,7 +131,7 @@ contract BaseLineLP2Test is Test {
createCSVHeader();
}
function slide() internal {
function slide(bool last) internal {
// have some time pass to record prices in uni oracle
uint256 timeBefore = block.timestamp;
vm.warp(timeBefore + (60 * 60 * 5));
@ -148,7 +148,9 @@ contract BaseLineLP2Test is Test {
if (keccak256(abi.encodePacked(reason)) == keccak256(abi.encodePacked("amplitude not reached, diamond hands!"))) {
console.log("slide failed on amplitude");
} else {
revert(reason); // Rethrow the error if it's not the expected message
if (!last) {
revert(reason); // Rethrow the error if it's not the expected message
}
}
}
}
@ -158,7 +160,7 @@ contract BaseLineLP2Test is Test {
uint256 timeBefore = block.timestamp;
vm.warp(timeBefore + (60 * 60 * 5));
lm.shift();
//lm.shift();
try lm.shift() {
// Check liquidity positions after shift
(uint256 ethFloor, uint256 ethAnchor, uint256 ethDiscovery, uint256 harbFloor, uint256 harbAnchor, uint256 harbDiscovery) = checkLiquidityPositionsAfter("shift");
@ -240,15 +242,12 @@ contract BaseLineLP2Test is Test {
return x >= 0 ? uint(x) : uint(-x);
}
event DEBUG(uint256 a, bool);
function buy(uint256 amountEth) internal {
emit DEBUG(amountEth, true);
performSwap(amountEth, true);
checkLiquidityPositionsAfter(string.concat("buy ", uintToStr(amountEth)));
}
function sell(uint256 amountHarb) internal {
emit DEBUG(amountHarb, false);
performSwap(amountHarb, false);
checkLiquidityPositionsAfter(string.concat("sell ", uintToStr(amountHarb)));
}
@ -434,15 +433,17 @@ contract BaseLineLP2Test is Test {
// uint256 traderBalanceBefore = weth.balanceOf(account);
// // Setup initial liquidity
// slide();
// slide(false);
// buy(100 ether);
// buy(200 ether);
// shift();
// //revert();
// sell(harb.balanceOf(account));
// slide();
// slide(true);
// writeCsv();
@ -461,7 +462,7 @@ contract BaseLineLP2Test is Test {
// uint256 traderBalanceBefore = weth.balanceOf(account);
// // Setup initial liquidity
// slide();
// slide(false);
// buy(2 ether);
@ -477,7 +478,7 @@ contract BaseLineLP2Test is Test {
// sell(harb.balanceOf(account));
// slide();
// slide(true);
// writeCsv();
// uint256 traderBalanceAfter = weth.balanceOf(account);
@ -486,28 +487,26 @@ contract BaseLineLP2Test is Test {
// assertGt(traderBalanceBefore, traderBalanceAfter, "trader should not have made profit");
// }
event DEBUG2(int24 a, int24 b);
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(true);
setUpCustomToken0(numActions % 2 == 0 ? true : false);
vm.deal(account, 100 ether);
vm.prank(account);
weth.deposit{value: 100 ether}();
// Setup initial liquidity
slide();
slide(false);
uint256 traderBalanceBefore = weth.balanceOf(account);
uint8 f = 0;
for (uint i = 0; i < numActions; i++) {
uint256 amount = (uint256(amounts[i]) * 1 ether) + 1 ether;
uint256 harbBal = harb.balanceOf(account);
emit DEBUG(i, true);
if (harbBal == 0) {
amount = amount % (weth.balanceOf(account) / 2);
amount = amount == 0 ? weth.balanceOf(account) : amount;
@ -528,14 +527,12 @@ contract BaseLineLP2Test is Test {
(, int24 currentTick, , , , , ) = pool.slot0();
(, int24 tickLower, int24 tickUpper) = lm.positions(BaseLineLP.Stage.ANCHOR);
int24 midTick = token0isWeth ? tickLower + ANCHOR_SPACING : tickUpper - ANCHOR_SPACING;
emit DEBUG2(tickLower, tickUpper);
emit DEBUG2(currentTick, midTick);
if (currentTick < midTick) {
// Current tick is below the midpoint, so call slide()
token0isWeth ? shift(): slide();
token0isWeth ? shift(): slide(false);
} else if (currentTick > midTick) {
// Current tick is above the midpoint, so call shift()
token0isWeth ? slide(): shift();
token0isWeth ? slide(false): shift();
}
f = 0;
} else {
@ -546,7 +543,7 @@ contract BaseLineLP2Test is Test {
// Simulate large sell to push price down to floor
sell(harb.balanceOf(account));
slide();
slide(true);
uint256 traderBalanceAfter = weth.balanceOf(account);