diff --git a/harb-lib/package.json b/harb-lib/package.json index b880cf0..827cce3 100644 --- a/harb-lib/package.json +++ b/harb-lib/package.json @@ -1,6 +1,6 @@ { "name": "harb-lib", - "version": "0.1.1", + "version": "0.2.0", "description": "helper functions and snatch selection", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/onchain/src/BaseLineLP.sol b/onchain/src/BaseLineLP.sol index ad9a575..12ae181 100644 --- a/onchain/src/BaseLineLP.sol +++ b/onchain/src/BaseLineLP.sol @@ -50,6 +50,10 @@ contract BaseLineLP { uint256 feeGrowthInside1LastX128; } + // for minting limits + uint256 private lastDay; + uint256 private mintedToday; + mapping(Stage => TokenPosition) positions; modifier checkDeadline(uint256 deadline) { @@ -152,6 +156,10 @@ contract BaseLineLP { _outstanding = harb.totalSupply() - harb.balanceOf(address(pool)) - harb.balanceOf(address(this)); } + function spendingLimit() public view returns (uint256, uint256) { + return (lastDay, mintedToday); + } + function ethIn(Stage s) public view returns (uint256 _ethInPosition) { uint160 sqrtRatioAX96 = TickMath.getSqrtRatioAtTick(positions[s].tickLower); uint160 sqrtRatioBX96 = TickMath.getSqrtRatioAtTick(positions[s].tickUpper); @@ -212,6 +220,21 @@ contract BaseLineLP { }); } + /// @dev Returns if amount is within daily limit and resets spentToday after one day. + /// @param amount Amount to withdraw. + /// @return Returns if amount is under daily limit. + function availableMint(uint256 amount) internal returns (uint256) { + if (block.timestamp > lastDay + 24 hours) { + lastDay = block.timestamp; + mintedToday = 0; + } + uint256 mintLimit = harb.totalSupply() * 3 / 20; + if (mintedToday + amount > mintLimit) { + return mintLimit - mintedToday; + } + return amount; + } + function _set(uint160 sqrtPriceX96, int24 currentTick, uint256 ethInNewAnchor) internal { // ### set Anchor position uint128 anchorLiquidity; @@ -281,7 +304,33 @@ contract BaseLineLP { liquidity ); } - _mint(tickLower, tickUpper, liquidity); + // 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)) + 301; + tickLower = token0isWeth ? currentTick + 301 : currentTick - tickWidth; + tickUpper = token0isWeth ? currentTick + tickWidth : currentTick - 301; + sqrtRatioAX96 = TickMath.getSqrtRatioAtTick(tickLower); + sqrtRatioBX96 = TickMath.getSqrtRatioAtTick(tickUpper); + liquidity = LiquidityAmounts.getLiquidityForAmounts( + sqrtPriceX96, + sqrtRatioAX96, + sqrtRatioBX96, + token0isWeth ? 0 : amount, + token0isWeth ? amount: 0 + ); + } + _mint(tickLower, tickUpper, liquidity); + } } }