Skip to content

Commit

Permalink
chore: use vault 304
Browse files Browse the repository at this point in the history
* chore: upgrade VaultV3 deployment

* fix: block num, supply
  • Loading branch information
heswithme authored Nov 1, 2024
1 parent 7871532 commit cb0217e
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 30 deletions.
62 changes: 37 additions & 25 deletions contracts/yearn/VaultV3.vy
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ event RoleSet:
role: indexed(Roles)

# STORAGE MANAGEMENT EVENTS
event UpdateFutureRoleManager:
future_role_manager: indexed(address)

event UpdateRoleManager:
role_manager: indexed(address)

Expand Down Expand Up @@ -861,7 +864,7 @@ def _redeem(

# NOTE: strategy's debt decreases by the full amount but the total idle increases
# by the actual amount only (as the difference is considered lost).
current_total_idle += (assets_to_withdraw - loss)
current_total_idle += (unsafe_sub(assets_to_withdraw, loss))
requested_assets -= loss
current_total_debt -= assets_to_withdraw

Expand Down Expand Up @@ -928,14 +931,11 @@ def _add_strategy(new_strategy: address, add_to_queue: bool):
@internal
def _revoke_strategy(strategy: address, force: bool=False):
assert self.strategies[strategy].activation != 0, "strategy not active"

# If force revoking a strategy, it will cause a loss.
loss: uint256 = 0

if self.strategies[strategy].current_debt != 0:
assert force, "strategy has debt"
# Vault realizes the full loss of outstanding debt.
loss = self.strategies[strategy].current_debt
loss: uint256 = self.strategies[strategy].current_debt
# Adjust total vault debt.
self.total_debt -= loss

Expand Down Expand Up @@ -1031,7 +1031,7 @@ def _update_debt(strategy: address, target_debt: uint256, max_loss: uint256) ->
# If we didn't get the amount we asked for and there is a max loss.
if withdrawn < assets_to_withdraw and max_loss < MAX_BPS:
# Make sure the loss is within the allowed range.
assert assets_to_withdraw - withdrawn <= assets_to_withdraw * max_loss / MAX_BPS, "too much loss"
assert unsafe_sub(assets_to_withdraw, withdrawn) <= assets_to_withdraw * max_loss / MAX_BPS, "too much loss"

# If we got too much make sure not to increase PPS.
elif withdrawn > assets_to_withdraw:
Expand Down Expand Up @@ -1257,16 +1257,20 @@ def _process_report(strategy: address) -> (uint256, uint256):
self.strategies[strategy].current_debt = current_debt
self.total_debt += gain
else:
self.total_idle = total_assets

# Add in any refunds since it is now idle.
current_debt = unsafe_add(current_debt, total_refunds)
self.total_idle = current_debt

# Or record any reported loss
elif loss > 0:
current_debt = unsafe_sub(current_debt, loss)
if strategy != self:
self.strategies[strategy].current_debt = current_debt
self.total_debt -= loss
else:
self.total_idle = total_assets
# Add in any refunds since it is now idle.
current_debt = unsafe_add(current_debt, total_refunds)
self.total_idle = current_debt

# Issue shares for fees that were calculated above if applicable.
if total_fees_shares > 0:
Expand Down Expand Up @@ -1537,30 +1541,32 @@ def set_role(account: address, role: Roles):
@external
def add_role(account: address, role: Roles):
"""
@notice Add a new role to an address.
@dev This will add a new role to the account
@notice Add a new role/s to an address.
@dev This will add a new role/s to the account
without effecting any of the previously held roles.
@param account The account to add a role to.
@param role The new role to add to account.
@param role The new role/s to add to account.
"""
assert msg.sender == self.role_manager
self.roles[account] = self.roles[account] | role
new_roles: Roles = self.roles[account] | role
self.roles[account] = new_roles

log RoleSet(account, self.roles[account])
log RoleSet(account, new_roles)

@external
def remove_role(account: address, role: Roles):
"""
@notice Remove a single role from an account.
@notice Remove a role/s from an account.
@dev This will leave all other roles for the
account unchanged.
@param account The account to remove a Role from.
@param role The Role to remove.
@param account The account to remove a Role/s from.
@param role The Role/s to remove.
"""
assert msg.sender == self.role_manager
self.roles[account] = self.roles[account] & ~role
new_roles: Roles = self.roles[account] & ~role
self.roles[account] = new_roles

log RoleSet(account, self.roles[account])
log RoleSet(account, new_roles)

@external
def transfer_role_manager(role_manager: address):
Expand All @@ -1574,6 +1580,8 @@ def transfer_role_manager(role_manager: address):
assert msg.sender == self.role_manager
self.future_role_manager = role_manager

log UpdateFutureRoleManager(role_manager)

@external
def accept_role_manager():
"""
Expand Down Expand Up @@ -1671,15 +1679,16 @@ def buy_debt(strategy: address, amount: uint256):

self._erc20_safe_transfer_from(self.asset, msg.sender, self, _amount)

# Lower strategy debt
self.strategies[strategy].current_debt -= _amount
# Lower strategy debt
new_debt: uint256 = unsafe_sub(current_debt, _amount)
self.strategies[strategy].current_debt = new_debt
# lower total debt
self.total_debt -= _amount
# Increase total idle
self.total_idle += _amount

# log debt change
log DebtUpdated(strategy, current_debt, current_debt - _amount)
log DebtUpdated(strategy, current_debt, new_debt)

# Transfer the strategies shares out.
self._erc20_safe_transfer(strategy, msg.sender, shares)
Expand Down Expand Up @@ -1746,7 +1755,7 @@ def update_debt(
@param strategy The strategy to update the debt for.
@param target_debt The target debt for the strategy.
@param max_loss Optional to check realized losses on debt decreases.
@return The amount of debt added or removed.
@return The new current debt of the strategy.
"""
self._enforce_role(msg.sender, Roles.DEBT_MANAGER)
return self._update_debt(strategy, target_debt, max_loss)
Expand All @@ -1772,7 +1781,10 @@ def shutdown_vault():
self.deposit_limit = 0
log UpdateDepositLimit(0)

self.roles[msg.sender] = self.roles[msg.sender] | Roles.DEBT_MANAGER
new_roles: Roles = self.roles[msg.sender] | Roles.DEBT_MANAGER
self.roles[msg.sender] = new_roles
log RoleSet(msg.sender, new_roles)

log Shutdown()


Expand Down Expand Up @@ -2099,7 +2111,7 @@ def FACTORY() -> address:
"""
return self.factory

@view
@pure
@external
def apiVersion() -> String[28]:
"""
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/address_book.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# yearn vaults 3.0.3 factory
yearn_vault_factory = "0x5577EdcB8A856582297CdBbB07055E6a6E38eb5f"
vault_original = "0xcA78AF7443f3F8FA0148b746Cb18FF67383CDF3f"
# yearn vaults 3.0.4 factory
yearn_vault_factory = "0x770D0d1Fb036483Ed4AbB6d53c1C88fb277D812F"
vault_original = "0xd8063123BBA3B480569244AE66BFE72B6c84b00d"

crvusd = "0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E"
crvusd_controller_factory = "0xC9332fdCB1C491Dcc683bAe86Fe3cb70360738BC"
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def rpc_url():

@pytest.fixture(autouse=True)
def forked_env(rpc_url):
block_to_fork = 21020069
block_to_fork = 21087700
with boa.swap_env(boa.Env()):
if BOA_CACHE:
boa.fork(url=rpc_url, block_identifier=block_to_fork)
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_stablecoin_lens.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
import boa

FORK_BLOCK_SUPPLY = 62247189465433688283786326
FORK_BLOCK_SUPPLY = 60516752788927113526145029


def test_circulating_supply(stablecoin_lens):
Expand Down

0 comments on commit cb0217e

Please sign in to comment.