baseLine fuzzing

This commit is contained in:
JulesCrown 2024-07-04 10:24:06 +02:00
parent aba495976d
commit aa67c0d798
3 changed files with 509 additions and 37 deletions

View file

@ -5,7 +5,7 @@ import "@uniswap-v3-periphery/libraries/PositionKey.sol";
import "@uniswap-v3-core/libraries/FixedPoint128.sol"; import "@uniswap-v3-core/libraries/FixedPoint128.sol";
import "@uniswap-v3-core/interfaces/IUniswapV3Pool.sol"; import "@uniswap-v3-core/interfaces/IUniswapV3Pool.sol";
import "@aperture/uni-v3-lib/TickMath.sol"; import "@aperture/uni-v3-lib/TickMath.sol";
import "@aperture/uni-v3-lib/LiquidityAmounts.sol"; import {LiquidityAmounts} from "@aperture/uni-v3-lib/LiquidityAmounts.sol";
import "@aperture/uni-v3-lib/PoolAddress.sol"; import "@aperture/uni-v3-lib/PoolAddress.sol";
import "@aperture/uni-v3-lib/CallbackValidation.sol"; import "@aperture/uni-v3-lib/CallbackValidation.sol";
import "@openzeppelin/token/ERC20/IERC20.sol"; import "@openzeppelin/token/ERC20/IERC20.sol";
@ -16,10 +16,13 @@ import {Harb} from "./Harb.sol";
/** /**
* @title LiquidityManager - A contract that supports the harb ecosystem. It * @title LiquidityManager - A contract that implements an automated market making strategy.
* protects the communities liquidity while allowing a manager role to * It maintains 3 positions:
* take strategic liqudity positions. * - The floor position guarantees the capacity needed to maintain a minimum price of the HARB token It is a very tight liquidity range with enough reserve assets to buy back the circulating supply.
*/ * - The anchor range provides liquidity around the current market price, ensuring liquid trading conditions for the token, regardless of the market environment.
* - The discovery range starts 500 ticks above the current market price and increases from there. It consists solely of unissued tokens, which are sold as the market price increases.
* The liquidity surplus obtained from selling tokens in the discovery range is directed back into the floor and anchor positions.
*/
contract BaseLineLP { contract BaseLineLP {
int24 constant TICK_SPACING = 200; int24 constant TICK_SPACING = 200;
int24 constant ANCHOR_SPACING = 5 * TICK_SPACING; int24 constant ANCHOR_SPACING = 5 * TICK_SPACING;
@ -244,8 +247,11 @@ contract BaseLineLP {
} }
// TODO: calculate liquidity correctly // TODO: calculate liquidity correctly
// or make sure that we don't have to pay more than we have // or make sure that we don't have to pay more than we have
tickLower = tickLower / TICK_SPACING * TICK_SPACING;
tickUpper = tickUpper / TICK_SPACING * TICK_SPACING;
_mint(Stage.ANCHOR, tickLower, tickUpper, anchorLiquidity * 2); _mint(Stage.ANCHOR, tickLower, tickUpper, anchorLiquidity * 2);
} }
currentTick = currentTick / TICK_SPACING * TICK_SPACING;
// ### set Floor position // ### set Floor position
{ {
@ -311,36 +317,6 @@ contract BaseLineLP {
harb.mint(harbInDiscovery); harb.mint(harbInDiscovery);
_mint(Stage.DISCOVERY, tickLower, tickUpper, liquidity); _mint(Stage.DISCOVERY, tickLower, tickUpper, liquidity);
harb.burn(harb.balanceOf(address(this))); harb.burn(harb.balanceOf(address(this)));
// // manage minting limits of harb here
// if (harbInDiscovery <= harb.balanceOf(address(this))) {
// _mint(tickLower, tickUpper, liquidity);
// harb.burn(harb.balanceOf(address(this)));
// } else {
// uint256 amount = availableMint(harbInDiscovery - harb.balanceOf(address(this)));
// harb.mint(amount);
// mintedToday += amount;
// amount = harb.balanceOf(address(this));
// if(amount < harbInDiscovery) {
// // calculate new ticks so that discovery liquidity is still
// // deeper than anchor, but less wide
// int24 tickWidth = int24(int256(11000 * amount / harbInDiscovery)) + ANCHOR_SPACING;
// tickWidth = tickWidth / TICK_SPACING * TICK_SPACING;
// tickWidth = (tickWidth <= ANCHOR_SPACING) ? tickWidth + TICK_SPACING : tickWidth;
// tickLower = token0isWeth ? currentTick - tickWidth : currentTick + ANCHOR_SPACING;
// tickUpper = token0isWeth ? currentTick - ANCHOR_SPACING : currentTick + tickWidth;
// sqrtRatioAX96 = TickMath.getSqrtRatioAtTick(tickLower);
// sqrtRatioBX96 = TickMath.getSqrtRatioAtTick(tickUpper);
// liquidity = LiquidityAmounts.getLiquidityForAmounts(
// sqrtPriceX96,
// sqrtRatioAX96,
// sqrtRatioBX96,
// token0isWeth ? 0 : amount,
// token0isWeth ? amount : 0
// );
// }
// _mint(tickLower, tickUpper, liquidity);
// }
} }
} }
@ -479,7 +455,7 @@ contract BaseLineLP {
// but cap anchor size at 10 % of total ETH // but cap anchor size at 10 % of total ETH
ethInNewAnchor = (ethInNewAnchor > ethBalance / 10) ? ethBalance / 10 : ethInNewAnchor; ethInNewAnchor = (ethInNewAnchor > ethBalance / 10) ? ethBalance / 10 : ethInNewAnchor;
currentTick = currentTick / TICK_SPACING * TICK_SPACING; //currentTick = currentTick / TICK_SPACING * TICK_SPACING;
_set(sqrtPriceX96, currentTick, ethInNewAnchor); _set(sqrtPriceX96, currentTick, ethInNewAnchor);
} }

View file

@ -22,7 +22,6 @@ contract Dummy {
} }
contract BaseLineLPTest is PoolSerializer { contract BaseLineLPTest is PoolSerializer {
uint256 mainnetFork;
IWETH9 weth; IWETH9 weth;
Harb harb; Harb harb;
IUniswapV3Factory factory; IUniswapV3Factory factory;

File diff suppressed because one or more lines are too long