Skip to content

Commit

Permalink
fix: shares for amount calculation should use freeFunds (#425)
Browse files Browse the repository at this point in the history
* fix: shares for amount calculation should use freeFunds

* refactor: free funds

* fix: if check
  • Loading branch information
Steffel authored and steffel committed Jul 8, 2021
1 parent 7e86162 commit 377ee62
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions contracts/Vault.vy
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,11 @@ def _calculateLockedProfit() -> uint256:
else:
return 0

@view
@internal
def _freeFunds() -> uint256:
return self._totalAssets() - self._calculateLockedProfit()

@internal
def _issueSharesForAmount(to: address, amount: uint256) -> uint256:
# Issues `amount` Vault shares to `to`.
Expand All @@ -816,8 +821,7 @@ def _issueSharesForAmount(to: address, amount: uint256) -> uint256:
if totalSupply > 0:
# Mint amount of shares based on what the Vault is managing overall
# NOTE: if sqrt(token.totalSupply()) > 1e39, this could potentially revert
freeFunds: uint256 = self._totalAssets() - self._calculateLockedProfit()
shares = amount * totalSupply / freeFunds # dev: no free funds
shares = amount * totalSupply / self._freeFunds() # dev: no free funds
else:
# No existing shares, so mint 1:1
shares = amount
Expand Down Expand Up @@ -904,11 +908,10 @@ def _shareValue(shares: uint256) -> uint256:

# Determines the current value of `shares`.
# NOTE: if sqrt(Vault.totalAssets()) >>> 1e39, this could potentially revert
freeFunds: uint256 = self._totalAssets() - self._calculateLockedProfit()

return (
shares
* freeFunds
* self._freeFunds()
/ self.totalSupply
)

Expand All @@ -918,12 +921,13 @@ def _shareValue(shares: uint256) -> uint256:
def _sharesForAmount(amount: uint256) -> uint256:
# Determines how many shares `amount` of token would receive.
# See dev note on `deposit`.
if self._totalAssets() > 0:
_freeFunds: uint256 = self._freeFunds()
if _freeFunds > 0:
# NOTE: if sqrt(token.totalSupply()) > 1e37, this could potentially revert
return (
amount
* self.totalSupply
/ self._totalAssets()
/ _freeFunds
)
else:
return 0
Expand Down

0 comments on commit 377ee62

Please sign in to comment.