added csv serializer

This commit is contained in:
JulesCrown 2024-05-29 17:26:19 +02:00
parent 4b86637a40
commit 5d209e5e19
6 changed files with 325 additions and 171 deletions

View file

@ -2,29 +2,27 @@
pragma solidity ^0.8.19;
import "forge-std/Test.sol";
import "forge-std/console.sol";
import {TwabController} from "pt-v5-twab-controller/TwabController.sol";
import {PoolAddress, PoolKey} from "@aperture/uni-v3-lib/PoolAddress.sol";
import "@uniswap-v3-core/interfaces/IUniswapV3Factory.sol";
import "@uniswap-v3-core/interfaces/IUniswapV3Pool.sol";
import "@aperture/uni-v3-lib/TickMath.sol";
import "../src/interfaces/IWETH9.sol";
import {WETH} from "solmate/tokens/WETH.sol";
import "../src/Harb.sol";
import {BaseLineLP} from "../src/BaseLineLP.sol";
import {Stake, ExceededAvailableStake} from "../src/Stake.sol";
import "./helpers/PoolSerializer.sol";
address constant TAX_POOL = address(2);
// default fee of 1%
uint24 constant FEE = uint24(10_000);
contract BaseLineLPTest is Test {
contract BaseLineLPTest is PoolSerializer {
uint256 mainnetFork;
IWETH9 weth;
Harb harb;
IUniswapV3Factory factory;
Stake stake;
BaseLineLP liquidityManager;
BaseLineLP lm;
IUniswapV3Pool pool;
bool token0isWeth;
@ -83,32 +81,32 @@ contract BaseLineLPTest is Test {
stake = new Stake(address(harb));
harb.setStakingPool(address(stake));
liquidityManager = new BaseLineLP(factoryAddress, address(weth), address(harb));
harb.setLiquidityManager(address(liquidityManager));
lm = new BaseLineLP(factoryAddress, address(weth), address(harb));
harb.setLiquidityManager(address(lm));
createCSVHeader();
}
function testLP(address account) public {
vm.assume(account != address(0));
vm.assume(account != address(1)); // TWAB sponsorship address
vm.assume(account != address(2)); // tax pool address
vm.deal(account, 15 ether);
function test_LP() public {
address account = makeAddr("alice");
vm.deal(account, 20 ether);
vm.prank(account);
(bool sent, ) = address(liquidityManager).call{value: 10 ether}("");
(bool sent, ) = address(lm).call{value: 10 ether}("");
require(sent, "Failed to send Ether");
// Try to shift liquidity manager's state, expect failure due to initial state
vm.expectRevert();
liquidityManager.shift();
lm.shift();
// Setup of liquidity
liquidityManager.slide();
lm.slide();
appendPossitions(lm, pool, token0isWeth);
// Small buy into Anchor
vm.prank(account);
weth.deposit{value: 5 ether}();
weth.deposit{value: 10 ether}();
vm.prank(account);
weth.approve(address(this), 5 ether);
weth.approve(address(this), 10 ether);
pool.swap(
account, // Recipient of the output tokens
token0isWeth,
@ -117,7 +115,8 @@ contract BaseLineLPTest is Test {
abi.encode(account, int256(0.5 ether), true)
);
liquidityManager.shift();
lm.shift();
appendPossitions(lm, pool, token0isWeth);
// large buy into discovery
pool.swap(
@ -128,12 +127,13 @@ contract BaseLineLPTest is Test {
abi.encode(account, int256(3 ether), true)
);
liquidityManager.shift();
lm.shift();
appendPossitions(lm, pool, token0isWeth);
// sell into anchor
vm.prank(account);
harb.approve(address(this), 2000000 ether);
harb.approve(address(this), 12000000 ether);
pool.swap(
account, // Recipient of the output tokens
!token0isWeth,
@ -142,24 +142,29 @@ contract BaseLineLPTest is Test {
abi.encode(account, int256(300000 ether), false)
);
liquidityManager.slide();
lm.slide();
appendPossitions(lm, pool, token0isWeth);
// large sell into floor
harb.setLiquidityManager(address(account));
vm.prank(account);
harb.mint(900000 ether);
harb.setLiquidityManager(address(liquidityManager));
harb.mint(3600000 ether);
harb.setLiquidityManager(address(lm));
pool.swap(
account, // Recipient of the output tokens
!token0isWeth,
int256(900000 ether),
int256(3600000 ether),
!token0isWeth ? TickMath.MIN_SQRT_RATIO + 1 : TickMath.MAX_SQRT_RATIO - 1,
abi.encode(account, int256(900000 ether), false)
abi.encode(account, int256(3600000 ether), false)
);
// add to CSV
liquidityManager.slide();
lm.slide();
appendPossitions(lm, pool, token0isWeth);
writeCsv();
}
/*//////////////////////////////////////////////////////////////
CALLBACKS
//////////////////////////////////////////////////////////////*/