Skip to content

Commit

Permalink
fix: revert changes on debt outstanding (yearn#381)
Browse files Browse the repository at this point in the history
* fix: do not use totalDebt to calculate debtLimit

* feat: test failure

* docs: add comment

* refactor: move test

Co-authored-by: Poolpi Tako <poolpitako@protonmail.com>
  • Loading branch information
Steffel and poolpitako authored May 27, 2021
1 parent 41e2eeb commit 2a0ba02
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
7 changes: 5 additions & 2 deletions contracts/Vault.vy
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,8 @@ def _reportLoss(strategy: address, loss: uint256):

# Also, make sure we reduce our trust with the strategy by the amount of loss
if self.debtRatio != 0: # if vault with single strategy that is set to EmergencyOne
# NOTE: The context to this calculation is different than the calculation in `_reportLoss`,
# this calculation intentionally approximates via `totalDebt` to avoid manipulatable results
ratio_change: uint256 = min(
# NOTE: This calculation isn't 100% precise, the adjustment is ~10%-20% more severe due to EVM math
loss * self.debtRatio / self.totalDebt,
Expand Down Expand Up @@ -1437,10 +1439,11 @@ def _debtOutstanding(strategy: address) -> uint256:
# See note on `debtOutstanding()`.
if self.debtRatio == 0:
return self.strategies[strategy].totalDebt

strategy_debtLimit: uint256 = (
self.strategies[strategy].debtRatio
* self.totalDebt
/ self.debtRatio
* self._totalAssets()
/ MAX_BPS
)
strategy_totalDebt: uint256 = self.strategies[strategy].totalDebt

Expand Down
10 changes: 10 additions & 0 deletions tests/functional/strategy/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,13 @@ def test_set_metadataURI(gov, strategy, strategist, rando):
assert strategy.metadataURI() == "ipfs://test3"
with brownie.reverts("!authorized"):
strategy.setMetadataURI("ipfs://fake", {"from": rando})


def test_reduce_debt_ratio(strategy, vault, gov, chain):
chain.sleep(1)
strategy.harvest({"from": gov})
assert vault.strategies(strategy).dict()["totalDebt"] > 0
old_debt_ratio = vault.strategies(strategy).dict()["debtRatio"]
vault.updateStrategyDebtRatio(strategy, old_debt_ratio // 2, {"from": gov})

assert vault.debtOutstanding(strategy) > 0

0 comments on commit 2a0ba02

Please sign in to comment.