Skip to content

Commit

Permalink
perf: optimize code (yearn#379)
Browse files Browse the repository at this point in the history
  • Loading branch information
zgfzgf authored and sambacha committed Sep 7, 2021
1 parent 7f8c9fc commit 69b90e6
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions contracts/Vault.vy
Original file line number Diff line number Diff line change
Expand Up @@ -963,19 +963,18 @@ def _reportLoss(strategy: address, loss: uint256):
assert totalDebt >= loss

# Also, make sure we reduce our trust with the strategy by the amount of loss
ratio_change: uint256 = 0
if self.debtRatio != 0: # if vault with single strategy that is set to EmergencyOne
ratio_change = min(
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,
self.strategies[strategy].debtRatio,
)
self.strategies[strategy].debtRatio -= ratio_change
self.debtRatio -= ratio_change
# Finally, adjust our strategy's parameters by the loss
self.strategies[strategy].totalLoss += loss
self.strategies[strategy].totalDebt = totalDebt - loss
self.totalDebt -= loss
self.strategies[strategy].debtRatio -= ratio_change
self.debtRatio -= ratio_change


@external
Expand Down

0 comments on commit 69b90e6

Please sign in to comment.