Skip to content

Commit

Permalink
chore: remove decrease revert
Browse files Browse the repository at this point in the history
  • Loading branch information
Schlagonia committed Aug 22, 2024
1 parent ac4a496 commit 6588568
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions contracts/VaultV3.vy
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions tests/unit/vault/test_debt_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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(
Expand Down

0 comments on commit 6588568

Please sign in to comment.