Skip to content

Commit

Permalink
perf: save gas in func withdraw (#383)
Browse files Browse the repository at this point in the history
* perf: save gas in func withdraw

* perf: rollback assert
  • Loading branch information
zgfzgf authored May 29, 2021
1 parent f5a576b commit 25b4c29
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions contracts/Vault.vy
Original file line number Diff line number Diff line change
Expand Up @@ -1047,8 +1047,8 @@ def withdraw(
# See @dev note, above.
value: uint256 = self._shareValue(shares)

totalLoss: uint256 = 0
if value > self.token.balanceOf(self):
totalLoss: uint256 = 0
# We need to go get some from our strategies in the withdrawal queue
# NOTE: This performs forced withdrawals from each Strategy. During
# forced withdrawal, a Strategy may realize a loss. That loss
Expand Down Expand Up @@ -1100,9 +1100,9 @@ def withdraw(
# including the losses that were incurred above during withdrawals
shares = self._sharesForAmount(value + totalLoss)

# NOTE: This loss protection is put in place to revert if losses from
# withdrawing are more than what is considered acceptable.
assert totalLoss <= maxLoss * (value + totalLoss) / MAX_BPS
# NOTE: This loss protection is put in place to revert if losses from
# withdrawing are more than what is considered acceptable.
assert totalLoss <= maxLoss * (value + totalLoss) / MAX_BPS

# Burn shares (full value of what is being withdrawn)
self.totalSupply -= shares
Expand Down

0 comments on commit 25b4c29

Please sign in to comment.