diff --git a/contracts/RewardsHandler.vy b/contracts/RewardsHandler.vy index 967cba2..3ef5535 100644 --- a/contracts/RewardsHandler.vy +++ b/contracts/RewardsHandler.vy @@ -34,8 +34,10 @@ from contracts.interfaces import IDynamicWeight implements: IDynamicWeight -# yearn vault's interface +# yearn interfaces from interfaces import IVault +from interfaces import IStrategy + ################################################################ @@ -154,7 +156,7 @@ def __init__( self._set_minimum_weight(minimum_weight) self._set_scaling_factor(scaling_factor) - + self.distribution_time = WEEK stablecoin = _stablecoin vault = _vault @@ -210,11 +212,15 @@ def process_rewards(): # stakers in the vault. available_balance: uint256 = staticcall stablecoin.balanceOf(self) + # strategy to work with + strategy: IStrategy = IStrategy(staticcall vault.default_queue(0)) # we distribute funds in 2 steps: # 1. transfer the actual funds - extcall stablecoin.transfer(vault.address, available_balance) - # 2. start streaming the rewards to users - extcall vault.process_report(vault.address) + extcall stablecoin.transfer(strategy.address, available_balance) + # 2. report on strategy + extcall strategy.report() + # 3. start streaming the rewards to users + extcall vault.process_report(strategy.address) ################################################################ diff --git a/contracts/interfaces/IStrategy.vyi b/contracts/interfaces/IStrategy.vyi new file mode 100644 index 0000000..6ec7115 --- /dev/null +++ b/contracts/interfaces/IStrategy.vyi @@ -0,0 +1,14 @@ +# pragma version ~=0.4 + +@external +def report() -> (uint256, uint256): + ... + +@external +def setKeeper(_keeper: address): + ... + +@view +@external +def management() -> address: + ... diff --git a/contracts/interfaces/IVault.vyi b/contracts/interfaces/IVault.vyi index b3b1864..e559717 100644 --- a/contracts/interfaces/IVault.vyi +++ b/contracts/interfaces/IVault.vyi @@ -14,3 +14,7 @@ def process_report(strategy: address) -> (uint256, uint256): @external def default_queue(index: uint256) -> address: ... + +@external +def update_debt(strategy: address, target_debt: uint256) -> uint256: + ... diff --git a/scripts/debug_tests.py b/scripts/debug_tests.py index 8e25db3..76ba18b 100644 --- a/scripts/debug_tests.py +++ b/scripts/debug_tests.py @@ -11,7 +11,7 @@ def main(): # Pytest arguments pytest_args = [ "-s", # Do not capture output, allowing you to see print statements and debug info - "tests/unitary/twa", # Specific test to run + "tests/unitary/yearn/test_rewards.py", # Specific test to run # '--maxfail=1', # Stop after the firstD failure "--tb=short", # Shorter traceback for easier reading "-rA", # Show extra test summary info diff --git a/tests/unitary/conftest.py b/tests/unitary/conftest.py index 9bb787d..126fd34 100644 --- a/tests/unitary/conftest.py +++ b/tests/unitary/conftest.py @@ -16,7 +16,7 @@ def curve_dao(): @pytest.fixture(scope="module") -def deployer(): +def dev_address(): return boa.env.generate_address() @@ -46,7 +46,7 @@ def role_manager(): @pytest.fixture(scope="module") -def vault(vault_factory, crvusd, role_manager, accrual_strategy): +def vault(vault_factory, crvusd, role_manager, accrual_strategy, dev_address): vault_deployer = boa.load_partial("contracts/yearn/Vault.vy") address = vault_factory.deploy_new_vault(crvusd, "Staked crvUSD", "st-crvUSD", role_manager, 0) @@ -59,7 +59,14 @@ def vault(vault_factory, crvusd, role_manager, accrual_strategy): vault.set_role(_god, int("11111111111111", 2), sender=role_manager) vault.add_strategy(accrual_strategy, sender=_god) # TODO figure out queue - + boa.deal(crvusd, dev_address, 1 * 10**18) + with boa.env.prank(dev_address): + crvusd.approve(vault, 1 * 10**18) + vault.set_deposit_limit(10_000_000 * 10**18, sender=_god) + vault.deposit(1 * 10**18, dev_address) + + vault.update_max_debt_for_strategy(accrual_strategy, 1 * 10**18, sender=_god) + vault.update_debt(accrual_strategy, 1 * 10**18, sender=_god) return vault @@ -114,19 +121,24 @@ def mock_peg_keeper(): @pytest.fixture(scope="module") def rewards_handler( - vault, crvusd, role_manager, minimum_weight, scaling_factor, mock_controller_factory, curve_dao + vault, + crvusd, + role_manager, + minimum_weight, + scaling_factor, + mock_controller_factory, + curve_dao, + dev_address, ): print(crvusd, vault, minimum_weight, scaling_factor, mock_controller_factory, curve_dao) - rh = boa.load( - "contracts/RewardsHandler.vy", - crvusd, - vault, - minimum_weight, - scaling_factor, - mock_controller_factory, - curve_dao, - ) - vault.set_role(rh, 2**11 | 2**5 | 2**0, sender=role_manager) + rewards_handler_deployer = boa.load_partial("contracts/RewardsHandler.vy") + + with boa.env.prank(dev_address): + rh = rewards_handler_deployer( + crvusd, vault, minimum_weight, scaling_factor, mock_controller_factory, curve_dao + ) + + vault.set_role(rh, 2**11 | 2**6 | 2**5 | 2**0, sender=role_manager) return rh @@ -140,16 +152,20 @@ def solc_args(): @pytest.fixture(scope="module") -def tokenized_strategy(solc_args, vault_factory): +def tokenized_strategy(solc_args, vault_factory, dev_address): deployer = boa.load_partial_solc( "contracts/yearn/TokenizedStrategy.sol", compiler_args=solc_args ) - return deployer.deploy( - vault_factory.address, override_address="0x2e234DAe75C793f67A35089C9d99245E1C58470b" - ) + with boa.env.prank(dev_address): + tokenized_strategy = deployer.deploy( + vault_factory.address, override_address="0x2e234DAe75C793f67A35089C9d99245E1C58470b" + ) + return tokenized_strategy @pytest.fixture(scope="module") -def accrual_strategy(solc_args, crvusd, tokenized_strategy): +def accrual_strategy(solc_args, crvusd, tokenized_strategy, dev_address): deployer = boa.load_partial_solc("contracts/yearn/AccrualStrategy.sol", compiler_args=solc_args) - return deployer.deploy(crvusd.address, "dummy") + with boa.env.prank(dev_address): + strategy = deployer.deploy(crvusd.address, "AccrualStrategy") + return strategy diff --git a/tests/unitary/rewards_handler/test_set_twa_frequency.py b/tests/unitary/rewards_handler/test_set_twa_frequency.py index 0a13655..d164214 100644 --- a/tests/unitary/rewards_handler/test_set_twa_frequency.py +++ b/tests/unitary/rewards_handler/test_set_twa_frequency.py @@ -10,9 +10,9 @@ def test_default_behavior(rewards_handler, curve_dao): assert updated_twa_dt == new_twa_dt -def test_role_access(rewards_handler, curve_dao, deployer): - # validate that deployer can't change twa parameters +def test_role_access(rewards_handler, curve_dao, dev_address): + # validate that dev_address can't change twa parameters with boa.reverts("access_control: account is missing role"): - rewards_handler.set_twa_window(1, sender=deployer) + rewards_handler.set_twa_window(1, sender=dev_address) with boa.reverts("access_control: account is missing role"): - rewards_handler.set_twa_snapshot_dt(1, sender=deployer) + rewards_handler.set_twa_snapshot_dt(1, sender=dev_address) diff --git a/tests/unitary/rewards_handler/test_set_twa_window.py b/tests/unitary/rewards_handler/test_set_twa_window.py index 3b35a3b..dd6f522 100644 --- a/tests/unitary/rewards_handler/test_set_twa_window.py +++ b/tests/unitary/rewards_handler/test_set_twa_window.py @@ -13,9 +13,9 @@ def test_default_behavior(rewards_handler, curve_dao): assert updated_twa_window == new_twa_window -def test_role_access(rewards_handler, curve_dao, deployer): - # validate that deployer can't change twa parameters +def test_role_access(rewards_handler, curve_dao, dev_address): + # validate that dev_address can't change twa parameters with boa.reverts("access_control: account is missing role"): - rewards_handler.set_twa_window(1, sender=deployer) + rewards_handler.set_twa_window(1, sender=dev_address) with boa.reverts("access_control: account is missing role"): - rewards_handler.set_twa_snapshot_dt(1, sender=deployer) + rewards_handler.set_twa_snapshot_dt(1, sender=dev_address) diff --git a/tests/unitary/yearn/test_deposit.py b/tests/unitary/yearn/test_deposit.py index aca3c40..1e1a4e8 100644 --- a/tests/unitary/yearn/test_deposit.py +++ b/tests/unitary/yearn/test_deposit.py @@ -5,7 +5,7 @@ def test_deposit(vault, crvusd, role_manager, vault_god): alice = boa.env.generate_address() boa.deal(crvusd, alice, 10_000 * 10**18) - vault.set_deposit_limit(10_000 * 10**18, sender=vault_god) + vault.set_deposit_limit(10_000_000 * 10**18, sender=vault_god) with boa.env.prank(alice): crvusd.approve(vault, 10_000 * 10**18)