diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index 07110367..9f2c89d4 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -28,10 +28,10 @@ jobs: with: fetch-depth: 1 - - name: Set up python 3.8 + - name: Set up python 3.9 uses: actions/setup-python@v2 with: - python-version: 3.10 + python-version: 3.9 - name: Set pip cache directory path id: pip-cache-dir-path diff --git a/contracts/VaultV3.vy b/contracts/VaultV3.vy index a6f70575..7a711934 100644 --- a/contracts/VaultV3.vy +++ b/contracts/VaultV3.vy @@ -1061,12 +1061,14 @@ def _update_debt(strategy: address, target_debt: uint256, max_loss: uint256) -> withdrawable: uint256 = IStrategy(strategy).convertToAssets( IStrategy(strategy).maxRedeem(self) ) - assert withdrawable != 0, "nothing to withdraw" # If insufficient withdrawable, withdraw what we can. if withdrawable < assets_to_withdraw: assets_to_withdraw = withdrawable + if assets_to_withdraw == 0: + return current_debt + # If there are unrealised losses we don't let the vault reduce its debt until there is a new report unrealised_losses_share: uint256 = self._assess_share_of_unrealised_losses(strategy, assets_to_withdraw) assert unrealised_losses_share == 0, "strategy has unrealised losses" @@ -1101,7 +1103,7 @@ def _update_debt(strategy: address, target_debt: uint256, max_loss: uint256) -> else: # We are increasing the strategies debt - # Respect the maximum amount allowed. TODO: Should this just check if max uint? + # Respect the maximum amount allowed. max_debt: uint256 = self.strategies[strategy].max_debt if new_debt > max_debt: new_debt = max_debt diff --git a/tests/unit/vault/test_debt_management.py b/tests/unit/vault/test_debt_management.py index 2b7f2d31..4679bfc5 100644 --- a/tests/unit/vault/test_debt_management.py +++ b/tests/unit/vault/test_debt_management.py @@ -96,7 +96,7 @@ def test_update_debt__with_current_debt_equal_to_new_debt__reverts( vault.update_debt(strategy.address, new_debt, sender=gov) -def test_update_debt__with_current_debt_greater_than_new_debt_and_zero_withdrawable__reverts( +def test_update_debt__with_current_debt_greater_than_new_debt_and_zero_withdrawable( gov, asset, vault, locked_strategy, add_debt_to_strategy ): vault_balance = asset.balanceOf(vault) @@ -109,8 +109,9 @@ def test_update_debt__with_current_debt_greater_than_new_debt_and_zero_withdrawa # reduce debt in strategy vault.update_max_debt_for_strategy(locked_strategy.address, new_debt, sender=gov) - with ape.reverts("nothing to withdraw"): - vault.update_debt(locked_strategy.address, new_debt, sender=gov) + tx = vault.update_debt(locked_strategy.address, new_debt, sender=gov) + + assert tx.return_value == current_debt def test_update_debt__with_current_debt_greater_than_new_debt_and_strategy_has_losses__reverts(