diff --git a/contracts/badger-sett/strategies/digg/StabilizeStrategyDiggV1.sol b/contracts/badger-sett/strategies/digg/StabilizeStrategyDiggV1.sol index cbdbfd35..7c87cd40 100644 --- a/contracts/badger-sett/strategies/digg/StabilizeStrategyDiggV1.sol +++ b/contracts/badger-sett/strategies/digg/StabilizeStrategyDiggV1.sol @@ -54,14 +54,14 @@ contract StabilizeStrategyDiggV1 is BaseStrategyMultiSwapper { bool public diggInExpansion; uint256 public lastDiggTotalSupply; // The last recorded total supply of the digg token uint256 public lastDiggPrice; // The price of Digg at last trade in BTC units - uint256 public diggSupplyChangeFactor = 50000; // This is a factor used by the strategy to determine how much digg to sell in expansion - uint256 public wbtcSupplyChangeFactor = 20000; // This is a factor used by the strategy to determine how much wbtc to sell in contraction - uint256 public wbtcSellAmplificationFactor = 2; // The higher this number the more aggressive the buyback in contraction - uint256 public maxGainedDiggSellPercent = 100000; // The maximum percent of sellable Digg gains through rebase - uint256 public maxWBTCSellPercent = 50000; // The maximum percent of sellable wBTC; - uint256 public tradeBatchSize = 10e18; // The normalized size of the trade batches, can be adjusted - uint256 public tradeAmountLeft = 0; // The amount left to trade - uint256 private _maxOracleLag = 24 hours; // Maximum amount of lag the oracle can have before reverting the price + uint256 public diggSupplyChangeFactor; // This is a factor used by the strategy to determine how much digg to sell in expansion + uint256 public wbtcSupplyChangeFactor; // This is a factor used by the strategy to determine how much wbtc to sell in contraction + uint256 public wbtcSellAmplificationFactor; // The higher this number the more aggressive the buyback in contraction + uint256 public maxGainedDiggSellPercent; // The maximum percent of sellable Digg gains through rebase + uint256 public maxWBTCSellPercent; // The maximum percent of sellable wBTC; + uint256 public tradeBatchSize; // The normalized size of the trade batches, can be adjusted + uint256 public tradeAmountLeft; // The amount left to trade + uint256 public maxOracleLag; // Maximum amount of lag the oracle can have before reverting the price // Constants uint256 constant DIVISION_FACTOR = 100000; @@ -112,6 +112,15 @@ contract StabilizeStrategyDiggV1 is BaseStrategyMultiSwapper { stabilizeFee = _feeConfig[3]; strategyLockedUntil = _lockedUntil; // Deployer can optionally lock strategy from withdrawing until a certain blocknumber + diggSupplyChangeFactor = 50000; + wbtcSupplyChangeFactor = 20000; + wbtcSellAmplificationFactor = 2; + maxGainedDiggSellPercent = 100000; + maxWBTCSellPercent = 50000; + tradeBatchSize = 10e18; + tradeAmountLeft = 0; + maxOracleLag = 56 hours; + setupTradeTokens(); lastDiggPrice = getDiggPrice(); lastDiggTotalSupply = tokenList[0].token.totalSupply(); // The supply only changes at rebase @@ -151,11 +160,11 @@ contract StabilizeStrategyDiggV1 is BaseStrategyMultiSwapper { function getDiggUSDPrice() public view returns (uint256) { AggregatorV3Interface priceOracle = AggregatorV3Interface(DIGG_ORACLE_ADDRESS); (, int256 intPrice, , uint256 lastUpdateTime, ) = priceOracle.latestRoundData(); // We only want the answer - require(block.timestamp.sub(lastUpdateTime) < _maxOracleLag, "Price data is too old to use"); + require(block.timestamp.sub(lastUpdateTime) < maxOracleLag, "Price data is too old to use"); uint256 usdPrice = uint256(intPrice); priceOracle = AggregatorV3Interface(BTC_ORACLE_ADDRESS); (, intPrice, , lastUpdateTime, ) = priceOracle.latestRoundData(); // We only want the answer - require(block.timestamp.sub(lastUpdateTime) < _maxOracleLag, "Price data is too old to use"); + require(block.timestamp.sub(lastUpdateTime) < maxOracleLag, "Price data is too old to use"); usdPrice = usdPrice.mul(uint256(intPrice)).mul(10**2); return usdPrice; // Digg Price in USD } @@ -163,14 +172,14 @@ contract StabilizeStrategyDiggV1 is BaseStrategyMultiSwapper { function getDiggPrice() public view returns (uint256) { AggregatorV3Interface priceOracle = AggregatorV3Interface(DIGG_ORACLE_ADDRESS); (, int256 intPrice, , uint256 lastUpdateTime, ) = priceOracle.latestRoundData(); // We only want the answer - require(block.timestamp.sub(lastUpdateTime) < _maxOracleLag, "Price data is too old to use"); + require(block.timestamp.sub(lastUpdateTime) < maxOracleLag, "Price data is too old to use"); return uint256(intPrice).mul(10**10); } function getWBTCUSDPrice() public view returns (uint256) { AggregatorV3Interface priceOracle = AggregatorV3Interface(BTC_ORACLE_ADDRESS); (, int256 intPrice, , uint256 lastUpdateTime, ) = priceOracle.latestRoundData(); // We only want the answer - require(block.timestamp.sub(lastUpdateTime) < _maxOracleLag, "Price data is too old to use"); + require(block.timestamp.sub(lastUpdateTime) < maxOracleLag, "Price data is too old to use"); return uint256(intPrice).mul(10**10); } @@ -305,7 +314,7 @@ contract StabilizeStrategyDiggV1 is BaseStrategyMultiSwapper { function setOracleLagTime(uint256 _time) external { _onlyAnyAuthorizedParties(); - _maxOracleLag = _time; + maxOracleLag = _time; } function setStabilizeFee(uint256 _fee) external { diff --git a/helpers/sett/DiggSnapshotManager.py b/helpers/sett/DiggSnapshotManager.py index c9a5c913..dfffa750 100644 --- a/helpers/sett/DiggSnapshotManager.py +++ b/helpers/sett/DiggSnapshotManager.py @@ -29,7 +29,7 @@ def rebase(self, value, overrides, confirm=True): # as the rebase logic checks if block ts w/in rebase window. self._shift_into_next_rebase_window(digg, value) - digg.orchestrator.rebase({"from": digg.owner},) + digg.orchestrator.rebase({"from": digg.owner}) after = self.snap(trackedUsers) if confirm: diff --git a/helpers/sett/DiggStabilizerSnapshotManager.py b/helpers/sett/DiggStabilizerSnapshotManager.py deleted file mode 100644 index 0a08e607..00000000 --- a/helpers/sett/DiggStabilizerSnapshotManager.py +++ /dev/null @@ -1,17 +0,0 @@ -from brownie import chain -from rich.console import Console - -from config.badger_config import digg_config -from .SnapshotManager import SnapshotManager - -console = Console() - -class DiggStabilizerSnapshotManager(SnapshotManager): - def rebalance(self, overrides, confirm=True): - user = overrides["from"].address - trackedUsers = {"user": user} - before = self.snap(trackedUsers) - tx = self.strategy.rebalance(overrides) - after = self.snap(trackedUsers) - if confirm: - self.resolver.confirm_rebalance(before, after, tx) diff --git a/helpers/sett/resolvers/StabilizeStrategyDiggV1Resolver.py b/helpers/sett/resolvers/StabilizeStrategyDiggV1Resolver.py index 037c3db6..763554fe 100644 --- a/helpers/sett/resolvers/StabilizeStrategyDiggV1Resolver.py +++ b/helpers/sett/resolvers/StabilizeStrategyDiggV1Resolver.py @@ -25,7 +25,7 @@ def confirm_rebalance_events(self, before, after, tx): ] for key in keys: assert key in event - console.print("[blue]== Convex Strat rebalance() NoTrade State ==[/blue]") + console.print("[blue]== rebalance() NoTrade State ==[/blue]") self.printState(event, keys) key = "TradeState" @@ -42,7 +42,7 @@ def confirm_rebalance_events(self, before, after, tx): ] for key in keys: assert key in event - console.print("[blue]== Convex Strat rebalance() TradeState State ==[/blue]") + console.print("[blue]== rebalance() TradeState State ==[/blue]") self.printState(event, keys) key = "Approval" @@ -57,7 +57,7 @@ def confirm_rebalance_events(self, before, after, tx): assert key in event console.print( - "[blue]== Convex Strat rebalance() Approval State ==[/blue]" + "[blue]== rebalance() Approval State ==[/blue]" ) self.printState(event, keys) @@ -100,9 +100,9 @@ def confirm_rebalance(self, before, after, tx): newSupply = event["newSupply"] # Sold Digg - if event["diggInExpansion"]: + if event["diggInExpansion"]: rebasePercentage = (newSupply - oldSupply) / oldSupply - changedDigg = before.balances("want", "strategy") * rebasePercentage + changedDigg = before.balances("want", "strategy") - (before.balances("want", "strategy")/(1 + rebasePercentage)) assert approx( changedDigg * (soldPercent/100000), before.balances("want", "strategy") - after.balances("want", "strategy"), @@ -291,7 +291,6 @@ def add_balances_snap(self, calls, entities): diggSLP = interface.IERC20("0x9a13867048e01c663ce8Ce2fE0cDAE69Ff9F35E3") diggUniLP = interface.IERC20("0xE86204c4eDDd2f70eE00EAd6805f917671F56c52") wbtc = interface.IERC20("0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599") - digg = interface.IERC20("0x798D1bE841a82a273720CE31c822C61a67a601C3") calls = self.add_entity_balances_for_tokens(calls, "diggSLP", diggSLP, entities) diff --git a/tests/sett/test_digg_stabilize_flow.py b/tests/sett/test_digg_stabilize_flow.py index f17a9877..c558515e 100644 --- a/tests/sett/test_digg_stabilize_flow.py +++ b/tests/sett/test_digg_stabilize_flow.py @@ -68,14 +68,16 @@ def test_single_user_rebalance_flow(settConfig): chain.mine() # Rebase - # Push/rebase on an exchange rate of 1.2 + # Push/rebase on an exchange rate of 1. + print("TotalSupply before:", want.totalSupply()) snap.rebase(1.2 * 10 ** 18, {"from": deployer}) + print("TotalSupply after:", want.totalSupply()) print("Time After First Rebase: ", chain.time()) print(diggOracle.latestRoundData()) # Rebalance - snap.rebalance({"from": settKeeper}) + snap.rebalance({"from": strategyKeeper}) chain.sleep(hours(0.25)) chain.mine() @@ -88,13 +90,15 @@ def test_single_user_rebalance_flow(settConfig): # Rebase # Push/rebase on an exchange rate of 0.6 - snap.rebase(0.6 * 10 ** 18, {"from": deployer}) + print("TotalSupply before:", want.totalSupply()) + snap.rebase(0.4 * 10 ** 18, {"from": deployer}) + print("TotalSupply after:", want.totalSupply()) print("Time After First Rebase: ", chain.time()) print(diggOracle.latestRoundData()) # Rebalance - snap.rebalance({"from": settKeeper}) + snap.rebalance({"from": strategyKeeper}) chain.sleep(hours(0.25)) chain.mine() @@ -103,7 +107,6 @@ def test_single_user_rebalance_flow(settConfig): amount = sett.balanceOf(randomUser.address) snap.settWithdraw(amount // 2, {"from": randomUser}) - assert False def rebase(badger: BadgerSystem, account): digg = badger.digg