better revert messages

This commit is contained in:
JulesCrown 2024-09-18 07:59:07 +02:00
parent f738daff96
commit 938d1eba79
2 changed files with 16 additions and 16 deletions

View file

@ -61,7 +61,7 @@ contract Harberg is ERC20, ERC20Permit {
// Modifier to restrict access to the liquidity manager
modifier onlyLiquidityManager() {
require(msg.sender == address(liquidityManager), "Harberg/only-lm");
require(msg.sender == address(liquidityManager), "only liquidity manager");
_;
}

View file

@ -79,13 +79,13 @@ contract LiquidityManager {
// the minimum share of ETH that will be put into the anchor
uint256 public anchorLiquidityShare;
// the higher the inefficiency, the more conservative the positioning of floor
uint256 public capitalInfefficiency;
uint256 public capitalInefficiency;
error ZeroAddressInSetter();
error AddressAlreadySet();
event EthScarcity(int24 currentTick, uint256 ethBalance, uint256 outstandingSupply, uint256 vwap, uint256 capitalInfefficiency, uint256 anchorLiquidityShare, int24 vwapTick);
event EthAbundance(int24 currentTick, uint256 ethBalance, uint256 outstandingSupply, uint256 vwap, uint256 capitalInfefficiency, uint256 anchorLiquidityShare, int24 vwapTick);
event EthScarcity(int24 currentTick, uint256 ethBalance, uint256 outstandingSupply, uint256 vwap, uint256 capitalInefficiency, uint256 anchorLiquidityShare, int24 vwapTick);
event EthAbundance(int24 currentTick, uint256 ethBalance, uint256 outstandingSupply, uint256 vwap, uint256 capitalInefficiency, uint256 anchorLiquidityShare, int24 vwapTick);
/// @dev Function modifier to ensure that the caller is the feeDestination
modifier onlyFeeDestination() {
@ -106,7 +106,7 @@ contract LiquidityManager {
harb = Harberg(_harb);
token0isWeth = _WETH9 < _harb;
anchorLiquidityShare = MAX_ANCHOR_LIQ_SHARE;
capitalInfefficiency = MIN_CAPITAL_INEFFICIENCY; // starting at 95% fuzzer passes tests
capitalInefficiency = MIN_CAPITAL_INEFFICIENCY; // starting at 95% fuzzer passes tests
}
/// @notice Callback function that Uniswap V3 calls for liquidity actions requiring minting or burning of tokens.
@ -138,15 +138,15 @@ contract LiquidityManager {
}
function setAnchorLiquidityShare(uint256 anchorLiquidityShare_) external onlyFeeDestination {
require(anchorLiquidityShare_ >= MIN_ANCHOR_LIQ_SHARE, "");
require(anchorLiquidityShare_ <= MAX_ANCHOR_LIQ_SHARE, "");
require(anchorLiquidityShare_ >= MIN_ANCHOR_LIQ_SHARE, "anchor liquidity share too low.");
require(anchorLiquidityShare_ <= MAX_ANCHOR_LIQ_SHARE, "anchor liquidity share too high.");
anchorLiquidityShare = anchorLiquidityShare_;
}
function setCapitalInfefficiency(uint256 capitalInfefficiency_) external onlyFeeDestination {
require(capitalInfefficiency_ >= MIN_CAPITAL_INEFFICIENCY, "");
require(capitalInfefficiency_ <= MAX_CAPITAL_INEFFICIENCY, "");
capitalInfefficiency = capitalInfefficiency_;
function setCapitalInfefficiency(uint256 capitalInefficiency_) external onlyFeeDestination {
require(capitalInefficiency_ >= MIN_CAPITAL_INEFFICIENCY, "capital inefficiency is too low.");
require(capitalInefficiency_ <= MAX_CAPITAL_INEFFICIENCY, "capital inefficiency is too high.");
capitalInefficiency = capitalInefficiency_;
}
function setMinStakeSupplyFraction(uint256 mssf_) external onlyFeeDestination {
@ -239,7 +239,7 @@ contract LiquidityManager {
uint256 ethBalance = (address(this).balance + weth.balanceOf(address(this)));
uint256 floorEthBalance = ethBalance * (100 - anchorLiquidityShare) / 100;
if (outstandingSupply > 0) {
vwapTick = tickAtPrice(token0isWeth, outstandingSupply * capitalInfefficiency / 100 , floorEthBalance);
vwapTick = tickAtPrice(token0isWeth, outstandingSupply * capitalInefficiency / 100 , floorEthBalance);
} else {
vwapTick = token0isWeth ? currentTick + ANCHOR_SPACING : currentTick - ANCHOR_SPACING;
}
@ -311,15 +311,15 @@ contract LiquidityManager {
uint256 vwapX96 = 0;
uint256 requiredEthForBuyback = 0;
if (cumulativeVolume > 0) {
vwapX96 = cumulativeVolumeWeightedPriceX96 * capitalInfefficiency / 100 / cumulativeVolume; // in harb/eth
vwapX96 = cumulativeVolumeWeightedPriceX96 * capitalInefficiency / 100 / cumulativeVolume; // in harb/eth
requiredEthForBuyback = outstandingSupply.mulDiv(vwapX96, (1 << 96));
}
// make a new calculation of the vwapTick, having updated outstandingSupply
if (floorEthBalance < requiredEthForBuyback) {
// not enough ETH, find a lower price
requiredEthForBuyback = floorEthBalance;
vwapTick = tickAtPrice(token0isWeth, outstandingSupply * capitalInfefficiency / 100 , requiredEthForBuyback);
emit EthScarcity(currentTick, ethBalance, outstandingSupply, vwapX96, capitalInfefficiency, anchorLiquidityShare, vwapTick);
vwapTick = tickAtPrice(token0isWeth, outstandingSupply * capitalInefficiency / 100 , requiredEthForBuyback);
emit EthScarcity(currentTick, ethBalance, outstandingSupply, vwapX96, capitalInefficiency, anchorLiquidityShare, vwapTick);
} else if (vwapX96 == 0) {
requiredEthForBuyback = floorEthBalance;
vwapTick = currentTick;
@ -328,7 +328,7 @@ contract LiquidityManager {
vwapTick = tickAtPriceRatio(int128(int256(vwapX96 >> 32)));
// convert to pool tick
vwapTick = token0isWeth ? -vwapTick : vwapTick;
emit EthAbundance(currentTick, ethBalance, outstandingSupply, vwapX96, capitalInfefficiency, anchorLiquidityShare, vwapTick);
emit EthAbundance(currentTick, ethBalance, outstandingSupply, vwapX96, capitalInefficiency, anchorLiquidityShare, vwapTick);
}
// move floor below anchor, if needed
if (token0isWeth) {