added csv serializer
This commit is contained in:
parent
4b86637a40
commit
5d209e5e19
6 changed files with 325 additions and 171 deletions
|
|
@ -57,7 +57,7 @@ contract BaseLineLP {
|
|||
uint256 private lastDay;
|
||||
uint256 private mintedToday;
|
||||
|
||||
mapping(Stage => TokenPosition) positions;
|
||||
mapping(Stage => TokenPosition) public positions;
|
||||
|
||||
modifier checkDeadline(uint256 deadline) {
|
||||
require(block.timestamp <= deadline, "Transaction too old");
|
||||
|
|
@ -103,27 +103,6 @@ contract BaseLineLP {
|
|||
|
||||
}
|
||||
|
||||
function createPosition(Stage positionIndex, int24 tickLower, int24 tickUpper, uint256 amount) internal {
|
||||
uint160 sqrtRatioAX96 = TickMath.getSqrtRatioAtTick(tickLower);
|
||||
uint160 sqrtRatioBX96 = TickMath.getSqrtRatioAtTick(tickUpper);
|
||||
uint128 liquidity = LiquidityAmounts.getLiquidityForAmount1(
|
||||
sqrtRatioAX96, sqrtRatioBX96, amount
|
||||
);
|
||||
pool.mint(address(this), tickLower, tickUpper, liquidity, abi.encode(poolKey));
|
||||
// TODO: check slippage
|
||||
// read position and start tracking in storage
|
||||
bytes32 positionKey = PositionKey.compute(address(this), tickLower, tickUpper);
|
||||
(, uint256 feeGrowthInside0LastX128, uint256 feeGrowthInside1LastX128,,) = pool.positions(positionKey);
|
||||
positions[positionIndex] = TokenPosition({
|
||||
liquidity: liquidity,
|
||||
tickLower: tickLower,
|
||||
tickUpper: tickUpper,
|
||||
feeGrowthInside0LastX128: feeGrowthInside0LastX128,
|
||||
feeGrowthInside1LastX128: feeGrowthInside1LastX128
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function outstanding() public view returns (uint256 _outstanding) {
|
||||
_outstanding = harb.totalSupply() - harb.balanceOf(address(pool)) - harb.balanceOf(address(this));
|
||||
}
|
||||
|
|
@ -133,17 +112,47 @@ contract BaseLineLP {
|
|||
}
|
||||
|
||||
|
||||
function ethIn(Stage s) public view returns (uint256 _ethInPosition) {
|
||||
function tokensIn(Stage s) public view returns (uint256 _ethInPosition, uint256 _harbInPosition) {
|
||||
uint160 sqrtRatioAX96 = TickMath.getSqrtRatioAtTick(positions[s].tickLower);
|
||||
uint160 sqrtRatioBX96 = TickMath.getSqrtRatioAtTick(positions[s].tickUpper);
|
||||
if (token0isWeth) {
|
||||
_ethInPosition = LiquidityAmounts.getAmount0ForLiquidity(
|
||||
sqrtRatioAX96, sqrtRatioBX96, positions[s].liquidity / 2
|
||||
);
|
||||
if (s == Stage.FLOOR) {
|
||||
_ethInPosition = LiquidityAmounts.getAmount0ForLiquidity(
|
||||
sqrtRatioAX96, sqrtRatioBX96, positions[s].liquidity
|
||||
);
|
||||
_harbInPosition = 0;
|
||||
} else if (s == Stage.ANCHOR) {
|
||||
_ethInPosition = LiquidityAmounts.getAmount0ForLiquidity(
|
||||
sqrtRatioAX96, sqrtRatioBX96, positions[s].liquidity / 2
|
||||
);
|
||||
_harbInPosition = LiquidityAmounts.getAmount1ForLiquidity(
|
||||
sqrtRatioAX96, sqrtRatioBX96, positions[s].liquidity / 2
|
||||
);
|
||||
} else {
|
||||
_ethInPosition = 0;
|
||||
_harbInPosition = LiquidityAmounts.getAmount1ForLiquidity(
|
||||
sqrtRatioAX96, sqrtRatioBX96, positions[s].liquidity
|
||||
);
|
||||
}
|
||||
} else {
|
||||
_ethInPosition = LiquidityAmounts.getAmount1ForLiquidity(
|
||||
sqrtRatioAX96, sqrtRatioBX96, positions[s].liquidity / 2
|
||||
);
|
||||
if (s == Stage.FLOOR) {
|
||||
_ethInPosition = LiquidityAmounts.getAmount1ForLiquidity(
|
||||
sqrtRatioAX96, sqrtRatioBX96, positions[s].liquidity
|
||||
);
|
||||
_harbInPosition = 0;
|
||||
} else if (s == Stage.ANCHOR) {
|
||||
_ethInPosition = LiquidityAmounts.getAmount1ForLiquidity(
|
||||
sqrtRatioAX96, sqrtRatioBX96, positions[s].liquidity / 2
|
||||
);
|
||||
_harbInPosition = LiquidityAmounts.getAmount0ForLiquidity(
|
||||
sqrtRatioAX96, sqrtRatioBX96, positions[s].liquidity / 2
|
||||
);
|
||||
} else {
|
||||
_ethInPosition = 0;
|
||||
_harbInPosition = LiquidityAmounts.getAmount0ForLiquidity(
|
||||
sqrtRatioAX96, sqrtRatioBX96, positions[s].liquidity
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -382,7 +391,7 @@ contract BaseLineLP {
|
|||
|
||||
// ## set new positions
|
||||
// reduce Anchor by 10% of new ETH. It will be moved into Floor
|
||||
uint256 initialEthInAnchor = ethIn(Stage.ANCHOR);
|
||||
(uint256 initialEthInAnchor,) = tokensIn(Stage.ANCHOR);
|
||||
ethInAnchor -= (ethInAnchor - initialEthInAnchor) * 10 / LIQUIDITY_RATIO_DIVISOR;
|
||||
|
||||
|
||||
|
|
@ -440,8 +449,8 @@ contract BaseLineLP {
|
|||
// TODO: set only discovery
|
||||
return;
|
||||
}
|
||||
uint256 ethInAnchor = ethIn(Stage.ANCHOR);
|
||||
uint256 ethInFloor = ethIn(Stage.FLOOR);
|
||||
(uint256 ethInAnchor,) = tokensIn(Stage.ANCHOR);
|
||||
(uint256 ethInFloor,) = tokensIn(Stage.FLOOR);
|
||||
|
||||
// use previous ration of Floor to Anchor
|
||||
uint256 ethInNewAnchor = ethBalance / 10;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue