Skip to content

Commit

Permalink
feat: strategy reporing tests, wip
Browse files Browse the repository at this point in the history
  • Loading branch information
heswithme committed Oct 7, 2024
1 parent b8b75a9 commit ff74075
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 35 deletions.
16 changes: 11 additions & 5 deletions contracts/RewardsHandler.vy
Original file line number Diff line number Diff line change
Expand Up @@ -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



################################################################
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)


################################################################
Expand Down
14 changes: 14 additions & 0 deletions contracts/interfaces/IStrategy.vyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# pragma version ~=0.4

@external
def report() -> (uint256, uint256):
...

@external
def setKeeper(_keeper: address):
...

@view
@external
def management() -> address:
...
4 changes: 4 additions & 0 deletions contracts/interfaces/IVault.vyi
Original file line number Diff line number Diff line change
Expand Up @@ -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:
...
2 changes: 1 addition & 1 deletion scripts/debug_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
56 changes: 36 additions & 20 deletions tests/unitary/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def curve_dao():


@pytest.fixture(scope="module")
def deployer():
def dev_address():
return boa.env.generate_address()


Expand Down Expand Up @@ -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)
Expand All @@ -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


Expand Down Expand Up @@ -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

Expand All @@ -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
8 changes: 4 additions & 4 deletions tests/unitary/rewards_handler/test_set_twa_frequency.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
8 changes: 4 additions & 4 deletions tests/unitary/rewards_handler/test_set_twa_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion tests/unitary/yearn/test_deposit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ff74075

Please sign in to comment.