Skip to content

Commit

Permalink
feat: remove loss from lockedProfit
Browse files Browse the repository at this point in the history
  • Loading branch information
steffel committed May 18, 2021
1 parent 56c46b1 commit fdf4bd8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
7 changes: 6 additions & 1 deletion contracts/Vault.vy
Original file line number Diff line number Diff line change
Expand Up @@ -1721,7 +1721,12 @@ def report(gain: uint256, loss: uint256, _debtPayment: uint256) -> uint256:

# Profit is locked and gradually released per block
# NOTE: compute current locked profit and replace with sum of current and new
self.lockedProfit = self._calculateLockedProfit() + gain - totalFees
lockedProfitBeforeLoss :uint256 = self._calculateLockedProfit() + gain - totalFees
if lockedProfitBeforeLoss > loss:
self.lockedProfit = lockedProfitBeforeLoss - loss
else:
self.lockedProfit = 0


# Update reporting time
self.strategies[msg.sender].lastReport = block.timestamp
Expand Down
21 changes: 21 additions & 0 deletions tests/functional/vault/test_losses.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,24 @@ def test_total_loss(chain, vault, strategy, gov, token):
assert params["totalLoss"] == 5000
assert params["totalDebt"] == 0
assert params["debtRatio"] == 0


def test_loss_should_be_removed_from_locked_profit(chain, vault, strategy, gov, token):
vault.setLockedProfitDegradation(1e10, {"from": gov})

vault.addStrategy(strategy, 1000, 0, 1000, 0, {"from": gov})
token.approve(vault, 2 ** 256 - 1, {"from": gov})
vault.deposit(5000, {"from": gov})
chain.sleep(1)
strategy.harvest({"from": gov})
assert token.balanceOf(strategy) == 500
token.transfer(strategy, 100, {"from": gov})
chain.sleep(1)
strategy.harvest({"from": gov})

assert vault.lockedProfit() == 90 # 100 - performance fees

token.transfer(token, 40, {"from": strategy})
chain.sleep(1)
strategy.harvest({"from": gov})
assert vault.lockedProfit() == 50

0 comments on commit fdf4bd8

Please sign in to comment.