From a6e361c524c18049db42766cd14f497c86e21dd0 Mon Sep 17 00:00:00 2001 From: Schlag <89420541+Schlagonia@users.noreply.github.com> Date: Sun, 7 Jan 2024 10:10:51 -0700 Subject: [PATCH] chore: removals (#189) * chore: remove increase and decrease allowances * chore: remove open roles --- contracts/VaultV3.vy | 76 +- tests/unit/vault/test_erc20.py | 37 - .../vault/test_role_permissioned_access.py | 909 ------------------ 3 files changed, 7 insertions(+), 1015 deletions(-) delete mode 100644 tests/unit/vault/test_role_permissioned_access.py diff --git a/contracts/VaultV3.vy b/contracts/VaultV3.vy index 6c52e7f0..791d21cc 100644 --- a/contracts/VaultV3.vy +++ b/contracts/VaultV3.vy @@ -111,10 +111,6 @@ event RoleSet: account: indexed(address) role: indexed(Roles) -event RoleStatusChanged: - role: indexed(Roles) - status: indexed(RoleStatusChange) - # STORAGE MANAGEMENT EVENTS event UpdateRoleManager: role_manager: indexed(address) @@ -204,10 +200,6 @@ enum Rounding: ROUND_DOWN ROUND_UP -enum RoleStatusChange: - OPENED - CLOSED - # IMMUTABLE # # Underlying token used by the vault. ASSET: immutable(ERC20) @@ -224,6 +216,7 @@ default_queue: public(DynArray[address, MAX_QUEUE]) # Should the vault use the default_queue regardless whats passed in. use_default_queue: public(bool) +### ACCOUNTING ### # ERC20 - amount of shares per account balance_of: HashMap[address, uint256] # ERC20 - owner -> (spender -> amount) @@ -231,7 +224,6 @@ allowance: public(HashMap[address, HashMap[address, uint256]]) # Total amount of shares that are currently minted including those locked. # NOTE: To get the ERC20 compliant version user totalSupply(). total_supply: public(uint256) - # Total amount of assets that has been deposited in strategies. total_debt: uint256 # Current assets held in the vault contract. Replacing balanceOf(this) to avoid price_per_share manipulation. @@ -240,16 +232,18 @@ total_idle: uint256 minimum_total_idle: public(uint256) # Maximum amount of tokens that the vault can accept. If totalAssets > deposit_limit, deposits will revert. deposit_limit: public(uint256) + +### PERIPHERY ### # Contract that charges fees and can give refunds. accountant: public(address) # Contract to control the deposit limit. deposit_limit_module: public(address) # Contract to control the withdraw limit. withdraw_limit_module: public(address) + +### ROLES ### # HashMap mapping addresses to their roles roles: public(HashMap[address, Roles]) -# HashMap mapping roles to their permissioned state. If false, the role is not open to the public. -open_roles: public(HashMap[Roles, bool]) # Address that can add and remove roles to addresses. role_manager: public(address) # Temporary variable to store the address of the next role_manager until the role is accepted. @@ -343,20 +337,6 @@ def _approve(owner: address, spender: address, amount: uint256) -> bool: log Approval(owner, spender, amount) return True -@internal -def _increase_allowance(owner: address, spender: address, amount: uint256) -> bool: - new_allowance: uint256 = self.allowance[owner][spender] + amount - self.allowance[owner][spender] = new_allowance - log Approval(owner, spender, new_allowance) - return True - -@internal -def _decrease_allowance(owner: address, spender: address, amount: uint256) -> bool: - new_allowance: uint256 = self.allowance[owner][spender] - amount - self.allowance[owner][spender] = new_allowance - log Approval(owner, spender, new_allowance) - return True - @internal def _permit( owner: address, @@ -1471,8 +1451,8 @@ def setProfitMaxUnlockTime(new_profit_max_unlock_time: uint256): # ROLE MANAGEMENT # @internal def _enforce_role(account: address, role: Roles): - # Make sure the sender either holds the role or it has been opened. - assert role in self.roles[account] or self.open_roles[role], "not allowed" + # Make sure the sender holds the role. + assert role in self.roles[account], "not allowed" @external def set_role(account: address, role: Roles): @@ -1515,28 +1495,6 @@ def remove_role(account: address, role: Roles): self.roles[account] = self.roles[account] & ~role log RoleSet(account, self.roles[account]) - -@external -def set_open_role(role: Roles): - """ - @notice Set a role to be open. - @param role The role to set. - """ - assert msg.sender == self.role_manager - self.open_roles[role] = True - - log RoleStatusChanged(role, RoleStatusChange.OPENED) - -@external -def close_open_role(role: Roles): - """ - @notice Close a opened role. - @param role The role to close. - """ - assert msg.sender == self.role_manager - self.open_roles[role] = False - - log RoleStatusChanged(role, RoleStatusChange.CLOSED) @external def transfer_role_manager(role_manager: address): @@ -1852,26 +1810,6 @@ def transferFrom(sender: address, receiver: address, amount: uint256) -> bool: return self._transfer_from(sender, receiver, amount) ## ERC20+4626 compatibility -@external -def increaseAllowance(spender: address, amount: uint256) -> bool: - """ - @notice Increase the allowance for a spender. - @param spender The address to increase the allowance for. - @param amount The amount to increase the allowance by. - @return True if the increase was successful. - """ - return self._increase_allowance(msg.sender, spender, amount) - -@external -def decreaseAllowance(spender: address, amount: uint256) -> bool: - """ - @notice Decrease the allowance for a spender. - @param spender The address to decrease the allowance for. - @param amount The amount to decrease the allowance by. - @return True if the decrease was successful. - """ - return self._decrease_allowance(msg.sender, spender, amount) - @external def permit( owner: address, diff --git a/tests/unit/vault/test_erc20.py b/tests/unit/vault/test_erc20.py index 676950c0..264e4bf8 100644 --- a/tests/unit/vault/test_erc20.py +++ b/tests/unit/vault/test_erc20.py @@ -55,43 +55,6 @@ def test_approve__with_amount__approve(fish, fish_amount, bunny, asset, create_v assert vault.allowance(fish, bunny) == fish_amount -def test_increase_allowance__with_amount__approve( - fish, fish_amount, bunny, asset, create_vault -): - vault = create_vault(asset) - - tx = vault.increaseAllowance(bunny.address, fish_amount, sender=fish) - event = list(tx.decode_logs(vault.Approval)) - - assert len(event) == 1 - assert event[0].owner == fish - assert event[0].spender == bunny - assert event[0].value == fish_amount - - assert vault.allowance(fish, bunny) == fish_amount - - -def test_decrease_allowance__with_amount__approve( - fish, fish_amount, bunny, asset, create_vault -): - vault = create_vault(asset) - decrease_amount = fish_amount // 2 - final_allowance = fish_amount - decrease_amount - - vault.approve(bunny.address, fish_amount, sender=fish) - assert vault.allowance(fish, bunny) == fish_amount - - tx = vault.decreaseAllowance(bunny.address, decrease_amount, sender=fish) - event = list(tx.decode_logs(vault.Approval)) - - assert len(event) == 1 - assert event[0].owner == fish - assert event[0].spender == bunny - assert event[0].value == final_allowance - - assert vault.allowance(fish, bunny) == final_allowance - - def test_transfer_from__with_approval__transfer( fish, fish_amount, bunny, doggie, asset, create_vault, user_deposit ): diff --git a/tests/unit/vault/test_role_permissioned_access.py b/tests/unit/vault/test_role_permissioned_access.py deleted file mode 100644 index 2d0c1971..00000000 --- a/tests/unit/vault/test_role_permissioned_access.py +++ /dev/null @@ -1,909 +0,0 @@ -import ape -from utils.constants import ( - ROLES, - WEEK, - StrategyChangeType, - RoleStatusChange, - ZERO_ADDRESS, -) -from utils.utils import from_units - - -def test_set_open_role__by_random_account__reverts(vault, bunny): - with ape.reverts(): - vault.set_open_role(ROLES.ADD_STRATEGY_MANAGER, sender=bunny) - - -def test_close_open_role__by_random_account__reverts(vault, gov, bunny): - tx = vault.set_open_role(ROLES.ADD_STRATEGY_MANAGER, sender=gov) - - event = list(tx.decode_logs(vault.RoleStatusChanged)) - assert len(event) == 1 - assert event[0].role == ROLES.ADD_STRATEGY_MANAGER - assert event[0].status == RoleStatusChange.OPENED - - assert vault.open_roles(ROLES.ADD_STRATEGY_MANAGER) == True - with ape.reverts(): - vault.close_open_role(ROLES.ADD_STRATEGY_MANAGER, sender=bunny) - - -# STRATEGY MANAGEMENT - - -def test_add_strategy__add_strategy_role_closed__reverts(vault, create_strategy, bunny): - new_strategy = create_strategy(vault) - with ape.reverts("not allowed"): - vault.add_strategy(new_strategy, sender=bunny) - - -def test_revoke_strategy__revoke_strategy_role_closed__reverts( - vault, create_strategy, bunny, gov -): - new_strategy = create_strategy(vault) - vault.add_strategy(new_strategy, sender=gov) - with ape.reverts("not allowed"): - vault.revoke_strategy(new_strategy, sender=bunny) - - -def test_force_revoke_strategy__revoke_strategy_role_closed__reverts( - vault, create_strategy, bunny, gov -): - new_strategy = create_strategy(vault) - - vault.add_strategy(new_strategy, sender=gov) - with ape.reverts("not allowed"): - vault.force_revoke_strategy(new_strategy, sender=bunny) - - -def test_add_strategy__set_add_strategy_role_open(vault, create_strategy, bunny, gov): - new_strategy = create_strategy(vault) - tx = vault.set_open_role(ROLES.ADD_STRATEGY_MANAGER, sender=gov) - - event = list(tx.decode_logs(vault.RoleStatusChanged)) - assert len(event) == 1 - assert event[0].role == ROLES.ADD_STRATEGY_MANAGER - assert event[0].status == RoleStatusChange.OPENED - - tx = vault.add_strategy(new_strategy, sender=bunny) - event = list(tx.decode_logs(vault.StrategyChanged)) - assert len(event) == 1 - assert event[0].strategy == new_strategy.address - assert event[0].change_type == StrategyChangeType.ADDED - - -def test_revoke_strategy__set_revoke_strategy_role_open( - vault, create_strategy, bunny, gov -): - new_strategy = create_strategy(vault) - vault.add_strategy(new_strategy, sender=gov) - tx = vault.set_open_role(ROLES.REVOKE_STRATEGY_MANAGER, sender=gov) - - event = list(tx.decode_logs(vault.RoleStatusChanged)) - assert len(event) == 1 - assert event[0].role == ROLES.REVOKE_STRATEGY_MANAGER - assert event[0].status == RoleStatusChange.OPENED - - tx = vault.revoke_strategy(new_strategy, sender=bunny) - event = list(tx.decode_logs(vault.StrategyChanged)) - assert len(event) == 1 - assert event[0].strategy == new_strategy.address - assert event[0].change_type == StrategyChangeType.REVOKED - - -def test_force_revoke_strategy__set_revoke_strategy_role_open( - vault, create_strategy, bunny, gov -): - new_strategy = create_strategy(vault) - - vault.add_strategy(new_strategy, sender=gov) - tx = vault.set_open_role(ROLES.FORCE_REVOKE_MANAGER, sender=gov) - - event = list(tx.decode_logs(vault.RoleStatusChanged)) - assert len(event) == 1 - assert event[0].role == ROLES.FORCE_REVOKE_MANAGER - assert event[0].status == RoleStatusChange.OPENED - - tx = vault.force_revoke_strategy(new_strategy, sender=bunny) - event = list(tx.decode_logs(vault.StrategyChanged)) - assert len(event) == 1 - assert event[0].strategy == new_strategy.address - assert event[0].change_type == StrategyChangeType.REVOKED - - -def test_add_strategy__set_add_strategy_role_open_then_close__reverts( - vault, create_strategy, bunny, gov -): - new_strategy = create_strategy(vault) - tx = vault.set_open_role(ROLES.ADD_STRATEGY_MANAGER, sender=gov) - - event = list(tx.decode_logs(vault.RoleStatusChanged)) - assert len(event) == 1 - assert event[0].role == ROLES.ADD_STRATEGY_MANAGER - assert event[0].status == RoleStatusChange.OPENED - - tx = vault.add_strategy(new_strategy, sender=bunny) - event = list(tx.decode_logs(vault.StrategyChanged)) - assert len(event) == 1 - assert event[0].strategy == new_strategy.address - assert event[0].change_type == StrategyChangeType.ADDED - # close the role - tx = vault.close_open_role(ROLES.ADD_STRATEGY_MANAGER, sender=gov) - - event = list(tx.decode_logs(vault.RoleStatusChanged)) - assert len(event) == 1 - assert event[0].role == ROLES.ADD_STRATEGY_MANAGER - assert event[0].status == RoleStatusChange.CLOSED - - with ape.reverts("not allowed"): - vault.add_strategy(new_strategy, sender=bunny) - - -def test_revoke_strategy__set_revoke_strategy_role_open_then_close__reverts( - vault, create_strategy, bunny, gov -): - new_strategy = create_strategy(vault) - vault.add_strategy(new_strategy, sender=gov) - tx = vault.set_open_role(ROLES.REVOKE_STRATEGY_MANAGER, sender=gov) - - event = list(tx.decode_logs(vault.RoleStatusChanged)) - assert len(event) == 1 - assert event[0].role == ROLES.REVOKE_STRATEGY_MANAGER - assert event[0].status == RoleStatusChange.OPENED - - tx = vault.revoke_strategy(new_strategy, sender=bunny) - event = list(tx.decode_logs(vault.StrategyChanged)) - assert len(event) == 1 - assert event[0].strategy == new_strategy.address - assert event[0].change_type == StrategyChangeType.REVOKED - - # close the role - tx = vault.close_open_role(ROLES.REVOKE_STRATEGY_MANAGER, sender=gov) - - event = list(tx.decode_logs(vault.RoleStatusChanged)) - assert len(event) == 1 - assert event[0].role == ROLES.REVOKE_STRATEGY_MANAGER - assert event[0].status == RoleStatusChange.CLOSED - - with ape.reverts("not allowed"): - vault.revoke_strategy(new_strategy, sender=bunny) - - -def test_force_revoke_strategy__set_revoke_strategy_role_open( - vault, create_strategy, bunny, gov -): - new_strategy = create_strategy(vault) - - vault.add_strategy(new_strategy, sender=gov) - tx = vault.set_open_role(ROLES.FORCE_REVOKE_MANAGER, sender=gov) - - event = list(tx.decode_logs(vault.RoleStatusChanged)) - assert len(event) == 1 - assert event[0].role == ROLES.FORCE_REVOKE_MANAGER - assert event[0].status == RoleStatusChange.OPENED - - tx = vault.force_revoke_strategy(new_strategy, sender=bunny) - event = list(tx.decode_logs(vault.StrategyChanged)) - assert len(event) == 1 - assert event[0].strategy == new_strategy.address - assert event[0].change_type == StrategyChangeType.REVOKED - other_strategy = create_strategy(vault) - vault.add_strategy(other_strategy, sender=gov) - - tx = vault.close_open_role(ROLES.FORCE_REVOKE_MANAGER, sender=gov) - - event = list(tx.decode_logs(vault.RoleStatusChanged)) - assert len(event) == 1 - assert event[0].role == ROLES.FORCE_REVOKE_MANAGER - assert event[0].status == RoleStatusChange.CLOSED - - with ape.reverts("not allowed"): - vault.force_revoke_strategy(other_strategy, sender=bunny) - - -# REPORTING_MANAGER - - -def test_process_report__reporting_role_closed__reverts( - vault, create_strategy, bunny, gov -): - new_strategy = create_strategy(vault) - vault.add_strategy(new_strategy, sender=gov) - with ape.reverts("not allowed"): - vault.process_report(new_strategy, sender=bunny) - - -def test_process_report__set_reporting_role_open( - vault, - create_strategy, - asset, - fish_amount, - user_deposit, - add_strategy_to_vault, - add_debt_to_strategy, - bunny, - gov, -): - asset.mint(bunny, fish_amount, sender=gov) - user_deposit(bunny, vault, asset, fish_amount) - new_strategy = create_strategy(vault) - add_strategy_to_vault(gov, new_strategy, vault) - add_debt_to_strategy(gov, new_strategy, vault, fish_amount) - tx = vault.set_open_role(ROLES.REPORTING_MANAGER, sender=gov) - - event = list(tx.decode_logs(vault.RoleStatusChanged)) - assert len(event) == 1 - assert event[0].role == ROLES.REPORTING_MANAGER - assert event[0].status == RoleStatusChange.OPENED - - asset.mint(new_strategy, fish_amount, sender=gov) - new_strategy.report(sender=gov) - - tx = vault.process_report(new_strategy, sender=bunny) - event = list(tx.decode_logs(vault.StrategyReported)) - assert len(event) == 1 - assert event[0].strategy == new_strategy.address and event[0].gain == fish_amount - - -def test_process_report__set_reporting_role_open_then_close__reverts( - vault, - create_strategy, - asset, - fish_amount, - user_deposit, - add_strategy_to_vault, - add_debt_to_strategy, - bunny, - gov, -): - asset.mint(bunny, fish_amount, sender=gov) - user_deposit(bunny, vault, asset, fish_amount) - new_strategy = create_strategy(vault) - add_strategy_to_vault(gov, new_strategy, vault) - add_debt_to_strategy(gov, new_strategy, vault, fish_amount) - - tx = vault.set_open_role(ROLES.REPORTING_MANAGER, sender=gov) - - event = list(tx.decode_logs(vault.RoleStatusChanged)) - assert len(event) == 1 - assert event[0].role == ROLES.REPORTING_MANAGER - assert event[0].status == RoleStatusChange.OPENED - - asset.mint(new_strategy, fish_amount, sender=gov) - new_strategy.report(sender=gov) - - tx = vault.process_report(new_strategy, sender=bunny) - event = list(tx.decode_logs(vault.StrategyReported)) - assert len(event) == 1 - assert event[0].strategy == new_strategy.address and event[0].gain == fish_amount - - # close role - tx = vault.close_open_role(ROLES.REPORTING_MANAGER, sender=gov) - - event = list(tx.decode_logs(vault.RoleStatusChanged)) - assert len(event) == 1 - assert event[0].role == ROLES.REPORTING_MANAGER - assert event[0].status == RoleStatusChange.CLOSED - - with ape.reverts("not allowed"): - vault.process_report(new_strategy, sender=bunny) - - -# PROFIT UNLOCK MANGAGER - - -def test_update_profit_unlock__profit_unlock_role_closed__reverts(vault, bunny): - with ape.reverts(): - vault.setProfitMaxUnlockTime(WEEK * 2, sender=bunny) - - -def test_update_profit_unlock__set_profit_unlock_role_role_open(vault, bunny, gov): - tx = vault.set_open_role(ROLES.PROFIT_UNLOCK_MANAGER, sender=gov) - - event = list(tx.decode_logs(vault.RoleStatusChanged)) - assert len(event) == 1 - assert event[0].role == ROLES.PROFIT_UNLOCK_MANAGER - assert event[0].status == RoleStatusChange.OPENED - - tx = vault.setProfitMaxUnlockTime(WEEK * 2, sender=bunny) - event = list(tx.decode_logs(vault.UpdateProfitMaxUnlockTime)) - assert len(event) == 1 - assert event[0].profit_max_unlock_time == WEEK * 2 - vault.profitMaxUnlockTime() == WEEK * 2 - - -def test_update_profit_unlock__set_profit_unlock_role_role_open_then_close__reverts( - vault, bunny, gov -): - tx = vault.set_open_role(ROLES.PROFIT_UNLOCK_MANAGER, sender=gov) - - event = list(tx.decode_logs(vault.RoleStatusChanged)) - assert len(event) == 1 - assert event[0].role == ROLES.PROFIT_UNLOCK_MANAGER - assert event[0].status == RoleStatusChange.OPENED - - tx = vault.setProfitMaxUnlockTime(WEEK * 2, sender=bunny) - event = list(tx.decode_logs(vault.UpdateProfitMaxUnlockTime)) - assert len(event) == 1 - assert event[0].profit_max_unlock_time == WEEK * 2 - assert vault.profitMaxUnlockTime() == WEEK * 2 - tx = vault.close_open_role(ROLES.PROFIT_UNLOCK_MANAGER, sender=gov) - - event = list(tx.decode_logs(vault.RoleStatusChanged)) - assert len(event) == 1 - assert event[0].role == ROLES.PROFIT_UNLOCK_MANAGER - assert event[0].status == RoleStatusChange.CLOSED - - with ape.reverts(): - vault.setProfitMaxUnlockTime(WEEK, sender=bunny) - - -# ACCOUNTING MANAGEMENT - - -def test_set_minimum_total_idle__minimum_idle_role_closed__reverts(vault, bunny): - with ape.reverts("not allowed"): - vault.set_minimum_total_idle(0, sender=bunny) - - -def test_set_deposit_limit__deposit_limit_role_closed__reverts(vault, bunny): - with ape.reverts("not allowed"): - vault.set_deposit_limit(0, sender=bunny) - - -def test_set_deposit_limit_module__deposit_limit_role_closed__reverts(vault, bunny): - with ape.reverts("not allowed"): - vault.set_deposit_limit_module(bunny, sender=bunny) - - -def test_set_withdraw_limit_module__withdraw_limit_role_closed__reverts(vault, bunny): - with ape.reverts("not allowed"): - vault.set_withdraw_limit_module(bunny, sender=bunny) - - -def test_update_max_debt_for_strategy__max_debt_role_closed__reverts( - vault, create_strategy, bunny, gov -): - new_strategy = create_strategy(vault) - vault.add_strategy(new_strategy, sender=gov) - with ape.reverts("not allowed"): - vault.update_max_debt_for_strategy(new_strategy, 0, sender=bunny) - - -def test_set_minimum_total_idle__set_minimum_idle_role_open(vault, bunny, gov): - tx = vault.set_open_role(ROLES.MINIMUM_IDLE_MANAGER, sender=gov) - - event = list(tx.decode_logs(vault.RoleStatusChanged)) - assert len(event) == 1 - assert event[0].role == ROLES.MINIMUM_IDLE_MANAGER - assert event[0].status == RoleStatusChange.OPENED - - tx = vault.set_minimum_total_idle(0, sender=bunny) - event = list(tx.decode_logs(vault.UpdateMinimumTotalIdle)) - assert len(event) == 1 - assert event[0].minimum_total_idle == 0 - - -def test_set_deposit_limit__set_deposit_limit_role_open(vault, bunny, gov): - tx = vault.set_open_role(ROLES.DEPOSIT_LIMIT_MANAGER, sender=gov) - - event = list(tx.decode_logs(vault.RoleStatusChanged)) - assert len(event) == 1 - assert event[0].role == ROLES.DEPOSIT_LIMIT_MANAGER - assert event[0].status == RoleStatusChange.OPENED - - tx = vault.set_deposit_limit(0, sender=bunny) - event = list(tx.decode_logs(vault.UpdateDepositLimit)) - assert len(event) == 1 - assert event[0].deposit_limit == 0 - - -def test_set_deposit_limit_module__set_deposit_limit_role_open(vault, bunny, gov): - tx = vault.set_open_role(ROLES.DEPOSIT_LIMIT_MANAGER, sender=gov) - - event = list(tx.decode_logs(vault.RoleStatusChanged)) - assert len(event) == 1 - assert event[0].role == ROLES.DEPOSIT_LIMIT_MANAGER - assert event[0].status == RoleStatusChange.OPENED - - tx = vault.set_deposit_limit_module(bunny, sender=bunny) - event = list(tx.decode_logs(vault.UpdateDepositLimitModule)) - assert len(event) == 1 - assert event[0].deposit_limit_module == bunny.address - assert vault.deposit_limit_module() == bunny.address - - -def test_set_withdraw_limit_module__set_withdraw_limit_role_open(vault, bunny, gov): - tx = vault.set_open_role(ROLES.WITHDRAW_LIMIT_MANAGER, sender=gov) - - event = list(tx.decode_logs(vault.RoleStatusChanged)) - assert len(event) == 1 - assert event[0].role == ROLES.WITHDRAW_LIMIT_MANAGER - assert event[0].status == RoleStatusChange.OPENED - - tx = vault.set_withdraw_limit_module(bunny, sender=bunny) - event = list(tx.decode_logs(vault.UpdateWithdrawLimitModule)) - assert len(event) == 1 - assert event[0].withdraw_limit_module == bunny.address - assert vault.withdraw_limit_module() == bunny.address - - -def test_update_max_debt_for_strategy__max_debt_limit_role_open( - vault, create_strategy, bunny, gov -): - tx = vault.set_open_role(ROLES.MAX_DEBT_MANAGER, sender=gov) - - event = list(tx.decode_logs(vault.RoleStatusChanged)) - assert len(event) == 1 - assert event[0].role == ROLES.MAX_DEBT_MANAGER - assert event[0].status == RoleStatusChange.OPENED - - new_strategy = create_strategy(vault) - vault.add_strategy(new_strategy, sender=gov) - tx = vault.update_max_debt_for_strategy(new_strategy, 420, sender=bunny) - event = list(tx.decode_logs(vault.UpdatedMaxDebtForStrategy)) - assert len(event) == 1 - assert ( - event[0].sender == bunny.address and event[0].strategy == new_strategy.address - ) - assert event[0].new_debt == 420 - - -def test_set_minimum_total_idle__set_minimum_idle_role_open_then_close__reverts( - vault, bunny, gov -): - tx = vault.set_open_role(ROLES.MINIMUM_IDLE_MANAGER, sender=gov) - - event = list(tx.decode_logs(vault.RoleStatusChanged)) - assert len(event) == 1 - assert event[0].role == ROLES.MINIMUM_IDLE_MANAGER - assert event[0].status == RoleStatusChange.OPENED - - tx = vault.set_minimum_total_idle(0, sender=bunny) - event = list(tx.decode_logs(vault.UpdateMinimumTotalIdle)) - assert len(event) == 1 - assert event[0].minimum_total_idle == 0 - # close role - tx = vault.close_open_role(ROLES.MINIMUM_IDLE_MANAGER, sender=gov) - - event = list(tx.decode_logs(vault.RoleStatusChanged)) - assert len(event) == 1 - assert event[0].role == ROLES.MINIMUM_IDLE_MANAGER - assert event[0].status == RoleStatusChange.CLOSED - - with ape.reverts("not allowed"): - vault.set_minimum_total_idle(0, sender=bunny) - - -def test_set_deposit_limit__set_deposit_limit_role_open(vault, bunny, gov): - tx = vault.set_open_role(ROLES.DEPOSIT_LIMIT_MANAGER, sender=gov) - - event = list(tx.decode_logs(vault.RoleStatusChanged)) - assert len(event) == 1 - assert event[0].role == ROLES.DEPOSIT_LIMIT_MANAGER - assert event[0].status == RoleStatusChange.OPENED - - tx = vault.set_deposit_limit(0, sender=bunny) - event = list(tx.decode_logs(vault.UpdateDepositLimit)) - assert len(event) == 1 - assert event[0].deposit_limit == 0 - # close role - tx = vault.close_open_role(ROLES.DEPOSIT_LIMIT_MANAGER, sender=gov) - - event = list(tx.decode_logs(vault.RoleStatusChanged)) - assert len(event) == 1 - assert event[0].role == ROLES.DEPOSIT_LIMIT_MANAGER - assert event[0].status == RoleStatusChange.CLOSED - - with ape.reverts("not allowed"): - vault.set_deposit_limit(0, sender=bunny) - - -def test_set_deposit_limit_module__set_deposit_limit_role_open(vault, bunny, gov): - tx = vault.set_open_role(ROLES.DEPOSIT_LIMIT_MANAGER, sender=gov) - - event = list(tx.decode_logs(vault.RoleStatusChanged)) - assert len(event) == 1 - assert event[0].role == ROLES.DEPOSIT_LIMIT_MANAGER - assert event[0].status == RoleStatusChange.OPENED - - tx = vault.set_deposit_limit_module(bunny, sender=bunny) - event = list(tx.decode_logs(vault.UpdateDepositLimitModule)) - assert len(event) == 1 - assert event[0].deposit_limit_module == bunny.address - assert vault.deposit_limit_module() == bunny.address - - # close role - tx = vault.close_open_role(ROLES.DEPOSIT_LIMIT_MANAGER, sender=gov) - - event = list(tx.decode_logs(vault.RoleStatusChanged)) - assert len(event) == 1 - assert event[0].role == ROLES.DEPOSIT_LIMIT_MANAGER - assert event[0].status == RoleStatusChange.CLOSED - - with ape.reverts("not allowed"): - vault.set_deposit_limit_module(ZERO_ADDRESS, sender=bunny) - - -def test_set_withdraw_limit_module__set_withdraw_limit_role_open(vault, bunny, gov): - tx = vault.set_open_role(ROLES.WITHDRAW_LIMIT_MANAGER, sender=gov) - - event = list(tx.decode_logs(vault.RoleStatusChanged)) - assert len(event) == 1 - assert event[0].role == ROLES.WITHDRAW_LIMIT_MANAGER - assert event[0].status == RoleStatusChange.OPENED - - tx = vault.set_withdraw_limit_module(bunny, sender=bunny) - event = list(tx.decode_logs(vault.UpdateWithdrawLimitModule)) - assert len(event) == 1 - assert event[0].withdraw_limit_module == bunny.address - assert vault.withdraw_limit_module() == bunny.address - - # close role - tx = vault.close_open_role(ROLES.WITHDRAW_LIMIT_MANAGER, sender=gov) - - event = list(tx.decode_logs(vault.RoleStatusChanged)) - assert len(event) == 1 - assert event[0].role == ROLES.WITHDRAW_LIMIT_MANAGER - assert event[0].status == RoleStatusChange.CLOSED - - with ape.reverts("not allowed"): - vault.set_withdraw_limit_module(ZERO_ADDRESS, sender=bunny) - - -def test_update_max_debt_for_strategy__set_max_debt_role_open_then_close__reverts( - vault, create_strategy, bunny, gov -): - tx = vault.set_open_role(ROLES.MAX_DEBT_MANAGER, sender=gov) - - event = list(tx.decode_logs(vault.RoleStatusChanged)) - assert len(event) == 1 - assert event[0].role == ROLES.MAX_DEBT_MANAGER - assert event[0].status == RoleStatusChange.OPENED - - new_strategy = create_strategy(vault) - vault.add_strategy(new_strategy, sender=gov) - tx = vault.update_max_debt_for_strategy(new_strategy, 420, sender=bunny) - event = list(tx.decode_logs(vault.UpdatedMaxDebtForStrategy)) - assert len(event) == 1 - assert ( - event[0].sender == bunny.address and event[0].strategy == new_strategy.address - ) - assert event[0].new_debt == 420 - # close role - tx = vault.close_open_role(ROLES.MAX_DEBT_MANAGER, sender=gov) - - event = list(tx.decode_logs(vault.RoleStatusChanged)) - assert len(event) == 1 - assert event[0].role == ROLES.MAX_DEBT_MANAGER - assert event[0].status == RoleStatusChange.CLOSED - - with ape.reverts("not allowed"): - vault.update_max_debt_for_strategy(new_strategy, 420, sender=bunny) - - -# DEBT_PURCHASER - - -def test_buy_debt__debt_purchaser_role_closed__reverts(vault, strategy, bunny): - with ape.reverts("not allowed"): - vault.buy_debt(strategy.address, 0, sender=bunny) - - -def test_buy_debt__set_debt_purchaser_role_open( - vault, - strategy, - mint_and_deposit_into_vault, - add_debt_to_strategy, - fish_amount, - asset, - bunny, - gov, -): - amount = fish_amount - - mint_and_deposit_into_vault(vault, gov, amount) - add_debt_to_strategy(gov, strategy, vault, amount) - - # Approve vault to pull funds. - asset.mint(bunny.address, amount, sender=gov) - asset.approve(vault.address, amount, sender=bunny) - - tx = vault.set_open_role(ROLES.DEBT_PURCHASER, sender=gov) - - event = list(tx.decode_logs(vault.RoleStatusChanged)) - assert len(event) == 1 - assert event[0].role == ROLES.DEBT_PURCHASER - assert event[0].status == RoleStatusChange.OPENED - - tx = vault.buy_debt(strategy.address, amount, sender=bunny) - event = list(tx.decode_logs(vault.DebtPurchased)) - - assert len(event) == 1 - assert event[0].strategy == strategy.address - assert event[0].amount == amount - - event = list(tx.decode_logs(vault.DebtUpdated)) - - assert len(event) == 1 - assert event[0].strategy == strategy.address - assert event[0].current_debt == amount - assert event[0].new_debt == 0 - - -def test_buy_debt__set_debt_purchaser_role_open_then_close__reverts( - vault, - strategy, - mint_and_deposit_into_vault, - add_debt_to_strategy, - fish_amount, - asset, - bunny, - gov, -): - amount = fish_amount - - mint_and_deposit_into_vault(vault, gov, amount) - add_debt_to_strategy(gov, strategy, vault, amount) - - # Approve vault to pull funds. - asset.mint(bunny.address, amount, sender=gov) - asset.approve(vault.address, amount, sender=bunny) - - vault.set_open_role(ROLES.DEBT_PURCHASER, sender=gov) - tx = vault.buy_debt(strategy.address, amount // 2, sender=bunny) - event = list(tx.decode_logs(vault.DebtPurchased)) - - assert len(event) == 1 - assert event[0].strategy == strategy.address - assert event[0].amount == amount // 2 - - event = list(tx.decode_logs(vault.DebtUpdated)) - - assert len(event) == 1 - assert event[0].strategy == strategy.address - assert event[0].current_debt == amount - assert event[0].new_debt == amount // 2 - # close role - - tx = vault.close_open_role(ROLES.DEBT_PURCHASER, sender=gov) - - event = list(tx.decode_logs(vault.RoleStatusChanged)) - assert len(event) == 1 - assert event[0].role == ROLES.DEBT_PURCHASER - assert event[0].status == RoleStatusChange.CLOSED - - with ape.reverts("not allowed"): - vault.buy_debt(strategy.address, amount // 2, sender=bunny) - - -# DEBT_MANAGER - - -def test_update_debt__debt_role_closed__reverts(vault, create_strategy, bunny, gov): - new_strategy = create_strategy(vault) - vault.add_strategy(new_strategy, sender=gov) - with ape.reverts("not allowed"): - vault.update_debt(new_strategy, 0, sender=bunny) - - -def test_update_debt__set_debt_role_open( - vault, create_strategy, bunny, gov, mint_and_deposit_into_vault -): - new_strategy = create_strategy(vault) - vault.add_strategy(new_strategy, sender=gov) - vault.update_max_debt_for_strategy(new_strategy, 1338, sender=gov) - mint_and_deposit_into_vault(vault) - tx = vault.set_open_role(ROLES.DEBT_MANAGER, sender=gov) - - event = list(tx.decode_logs(vault.RoleStatusChanged)) - assert len(event) == 1 - assert event[0].role == ROLES.DEBT_MANAGER - assert event[0].status == RoleStatusChange.OPENED - - tx = vault.update_debt(new_strategy, 1337, sender=bunny) - event = list(tx.decode_logs(vault.DebtUpdated)) - assert len(event) == 1 - assert event[0].strategy == new_strategy.address and event[0].new_debt == 1337 - - -def test_update_debt__set_debt_role_open_then_close__reverts( - vault, create_strategy, bunny, gov, mint_and_deposit_into_vault -): - new_strategy = create_strategy(vault) - vault.add_strategy(new_strategy, sender=gov) - vault.update_max_debt_for_strategy(new_strategy, 1338, sender=gov) - mint_and_deposit_into_vault(vault) - tx = vault.set_open_role(ROLES.DEBT_MANAGER, sender=gov) - - event = list(tx.decode_logs(vault.RoleStatusChanged)) - assert len(event) == 1 - assert event[0].role == ROLES.DEBT_MANAGER - assert event[0].status == RoleStatusChange.OPENED - - tx = vault.update_debt(new_strategy, 1337, sender=bunny) - event = list(tx.decode_logs(vault.DebtUpdated)) - assert len(event) == 1 - assert event[0].strategy == new_strategy.address and event[0].new_debt == 1337 - # close role - tx = vault.close_open_role(ROLES.DEBT_MANAGER, sender=gov) - - event = list(tx.decode_logs(vault.RoleStatusChanged)) - assert len(event) == 1 - assert event[0].role == ROLES.DEBT_MANAGER - assert event[0].status == RoleStatusChange.CLOSED - - with ape.reverts("not allowed"): - vault.update_debt(new_strategy, 1337, sender=bunny) - - -# ACCOUNTANT_MANAGER - - -def test_set_accountant__accountant_manager_closed__reverts(bunny, vault): - with ape.reverts("not allowed"): - vault.set_accountant(bunny, sender=bunny) - - -def test_set_accountant__accountant_manager_open(gov, vault, bunny): - # We temporarily give bunny the role of DEBT_MANAGER - tx = vault.set_open_role(ROLES.ACCOUNTANT_MANAGER, sender=gov) - - event = list(tx.decode_logs(vault.RoleStatusChanged)) - assert len(event) == 1 - assert event[0].role == ROLES.ACCOUNTANT_MANAGER - assert event[0].status == RoleStatusChange.OPENED - - assert vault.accountant() != bunny - vault.set_accountant(bunny, sender=bunny) - assert vault.accountant() == bunny - - -def test_set_accountant__accountant_manager_open_then_close__reverts( - gov, vault, bunny, fish -): - # We temporarily give bunny the role of DEBT_MANAGER - tx = vault.set_open_role(ROLES.ACCOUNTANT_MANAGER, sender=gov) - - event = list(tx.decode_logs(vault.RoleStatusChanged)) - assert len(event) == 1 - assert event[0].role == ROLES.ACCOUNTANT_MANAGER - assert event[0].status == RoleStatusChange.OPENED - - assert vault.accountant() != bunny - vault.set_accountant(bunny, sender=bunny) - assert vault.accountant() == bunny - - tx = vault.close_open_role(ROLES.ACCOUNTANT_MANAGER, sender=gov) - - event = list(tx.decode_logs(vault.RoleStatusChanged)) - assert len(event) == 1 - assert event[0].role == ROLES.ACCOUNTANT_MANAGER - assert event[0].status == RoleStatusChange.CLOSED - - with ape.reverts("not allowed"): - vault.set_accountant(fish, sender=fish) - - -# EMERGENCY_MANAGER - - -def test_shutdown_vault__emergency_role_closed__reverts(vault, bunny): - with ape.reverts("not allowed"): - vault.shutdown_vault(sender=bunny) - - -def test_shutdown_vault__set_emergency_role_open(vault, bunny, gov): - with ape.reverts(): - vault.shutdown_vault(sender=bunny) - - tx = vault.set_open_role(ROLES.EMERGENCY_MANAGER, sender=gov) - - event = list(tx.decode_logs(vault.RoleStatusChanged)) - assert len(event) == 1 - assert event[0].role == ROLES.EMERGENCY_MANAGER - assert event[0].status == RoleStatusChange.OPENED - - tx = vault.shutdown_vault(sender=bunny) - event = list(tx.decode_logs(vault.Shutdown)) - assert len(event) == 1 - - -# QUEUE MANAGER - - -def test_set_default_queue__queue_manager_closed__reverts(bunny, vault): - with ape.reverts("not allowed"): - vault.set_default_queue([], sender=bunny) - - -def test_set_use_default_queue__queue_manager_closed__reverts(bunny, vault): - with ape.reverts("not allowed"): - vault.set_use_default_queue(True, sender=bunny) - - -def test_set_default_queue__queue_manager_open(gov, vault, strategy, bunny): - # We temporarily give bunny the role of DEBT_MANAGER - tx = vault.set_open_role(ROLES.QUEUE_MANAGER, sender=gov) - - event = list(tx.decode_logs(vault.RoleStatusChanged)) - assert len(event) == 1 - assert event[0].role == ROLES.QUEUE_MANAGER - assert event[0].status == RoleStatusChange.OPENED - - assert vault.get_default_queue() != [] - vault.set_default_queue([], sender=bunny) - assert vault.get_default_queue() == [] - - -def test_set_use_default_queue__queue_manager_open(gov, vault, strategy, bunny): - # We temporarily give bunny the role of DEBT_MANAGER - tx = vault.set_open_role(ROLES.QUEUE_MANAGER, sender=gov) - - event = list(tx.decode_logs(vault.RoleStatusChanged)) - assert len(event) == 1 - assert event[0].role == ROLES.QUEUE_MANAGER - assert event[0].status == RoleStatusChange.OPENED - - assert vault.use_default_queue() == False - tx = vault.set_use_default_queue(True, sender=bunny) - - event = list(tx.decode_logs(vault.UpdateUseDefaultQueue)) - assert len(event) == 1 - assert event[0].use_default_queue == True - assert vault.use_default_queue() == True - - -def test_set_default_queue__queue_manager_open_then_close__reverts( - gov, vault, strategy, bunny, fish -): - # We temporarily give bunny the role of DEBT_MANAGER - tx = vault.set_open_role(ROLES.QUEUE_MANAGER, sender=gov) - - event = list(tx.decode_logs(vault.RoleStatusChanged)) - assert len(event) == 1 - assert event[0].role == ROLES.QUEUE_MANAGER - assert event[0].status == RoleStatusChange.OPENED - - assert vault.get_default_queue() != [] - vault.set_default_queue([], sender=bunny) - assert vault.get_default_queue() == [] - - tx = vault.close_open_role(ROLES.QUEUE_MANAGER, sender=gov) - - event = list(tx.decode_logs(vault.RoleStatusChanged)) - assert len(event) == 1 - assert event[0].role == ROLES.QUEUE_MANAGER - assert event[0].status == RoleStatusChange.CLOSED - - with ape.reverts("not allowed"): - vault.set_default_queue([], sender=fish) - - -def test_set_use_default_queue__queue_manager_open_then_close__reverts( - gov, vault, strategy, bunny, fish -): - # We temporarily give bunny the role of DEBT_MANAGER - tx = vault.set_open_role(ROLES.QUEUE_MANAGER, sender=gov) - - event = list(tx.decode_logs(vault.RoleStatusChanged)) - assert len(event) == 1 - assert event[0].role == ROLES.QUEUE_MANAGER - assert event[0].status == RoleStatusChange.OPENED - - assert vault.use_default_queue() == False - tx = vault.set_use_default_queue(True, sender=bunny) - - event = list(tx.decode_logs(vault.UpdateUseDefaultQueue)) - assert len(event) == 1 - assert event[0].use_default_queue == True - assert vault.use_default_queue() == True - - tx = vault.close_open_role(ROLES.QUEUE_MANAGER, sender=gov) - - event = list(tx.decode_logs(vault.RoleStatusChanged)) - assert len(event) == 1 - assert event[0].role == ROLES.QUEUE_MANAGER - assert event[0].status == RoleStatusChange.CLOSED - - with ape.reverts("not allowed"): - vault.set_use_default_queue(False, sender=fish)