Skip to content

Commit

Permalink
feat: add management to initialize (#271)
Browse files Browse the repository at this point in the history
* feat: add management to initialize

* fix: ask for management on deploy
  • Loading branch information
Steffel authored Apr 12, 2021
1 parent 54bdc1b commit f97088d
Show file tree
Hide file tree
Showing 15 changed files with 92 additions and 38 deletions.
10 changes: 7 additions & 3 deletions contracts/Registry.vy
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface Vault:
token: address,
governance: address,
rewards: address,
management: address,
name: String[64],
symbol: String[32],
guardian: address,
Expand Down Expand Up @@ -154,6 +155,7 @@ def _newProxyVault(
token: address,
governance: address,
rewards: address,
management: address,
guardian: address,
name: String[64],
symbol: String[32],
Expand All @@ -164,7 +166,7 @@ def _newProxyVault(
vault: address = create_forwarder_to(release)

# NOTE: Must initialize the Vault atomically with deploying it
Vault(vault).initialize(token, governance, rewards, name, symbol, guardian)
Vault(vault).initialize(token, governance, rewards, management, name, symbol, guardian)

return vault

Expand Down Expand Up @@ -200,6 +202,7 @@ def newVault(
token: address,
guardian: address,
rewards: address,
management: address,
name: String[64],
symbol: String[32],
releaseDelta: uint256 = 0, # NOTE: Uses latest by default
Expand Down Expand Up @@ -227,7 +230,7 @@ def newVault(

# NOTE: Underflow if no releases created yet, or targeting prior to release history
releaseTarget: uint256 = self.numReleases - 1 - releaseDelta # dev: no releases
vault: address = self._newProxyVault(token, msg.sender, rewards, guardian, name, symbol, releaseTarget)
vault: address = self._newProxyVault(token, msg.sender, rewards, management, guardian, name, symbol, releaseTarget)

self._registerVault(token, vault)

Expand All @@ -240,6 +243,7 @@ def newExperimentalVault(
governance: address,
guardian: address,
rewards: address,
management: address,
name: String[64],
symbol: String[32],
releaseDelta: uint256 = 0, # NOTE: Uses latest by default
Expand All @@ -264,7 +268,7 @@ def newExperimentalVault(
# NOTE: Underflow if no releases created yet, or targeting prior to release history
releaseTarget: uint256 = self.numReleases - 1 - releaseDelta # dev: no releases
# NOTE: Anyone can call this method, as a convenience to Strategist' experiments
vault: address = self._newProxyVault(token, governance, rewards, guardian, name, symbol, releaseTarget)
vault: address = self._newProxyVault(token, governance, rewards, management, guardian, name, symbol, releaseTarget)

# NOTE: Not registered, so emit an "experiment" event here instead
log NewExperimentalVault(token, msg.sender, vault, Vault(vault).apiVersion())
Expand Down
5 changes: 3 additions & 2 deletions contracts/Vault.vy
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ def initialize(
token: address,
governance: address,
rewards: address,
management: address,
nameOverride: String[64],
symbolOverride: String[32],
guardian: address = msg.sender,
Expand Down Expand Up @@ -289,8 +290,8 @@ def initialize(

self.governance = governance
log UpdateGovernance(governance)
self.management = governance
log UpdateManagement(governance)
self.management = management
log UpdateManagement(management)
self.rewards = rewards
log UpdateRewards(rewards)
self.guardian = guardian
Expand Down
3 changes: 3 additions & 0 deletions scripts/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def main():

rewards = get_address("Rewards contract", default="treasury.ychad.eth")
guardian = get_address("Vault Guardian", default="dev.ychad.eth")
management = get_address("Vault Management", default="ychad.eth")
name = click.prompt(f"Set description", default=DEFAULT_VAULT_NAME(token))
symbol = click.prompt(f"Set symbol", default=DEFAULT_VAULT_SYMBOL(token))
target_release = Vault.at(registry.releases(target_release_index)).apiVersion()
Expand All @@ -107,6 +108,7 @@ def main():
token address: {token.address}
token symbol: {DEFAULT_VAULT_SYMBOL(token)}
governance: {gov}
management: {management}
rewards: {rewards}
guardian: {guardian}
name: '{name}'
Expand All @@ -119,6 +121,7 @@ def main():
token,
gov,
rewards,
management,
# NOTE: Empty string `""` means no override (don't use click default tho)
name if name != DEFAULT_VAULT_NAME(token) else "",
symbol if symbol != DEFAULT_VAULT_SYMBOL(token) else "",
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def create_vault(token=None, version=None, governance=gov):
if token is None:
token = create_token()
vault = patch_vault_version(version).deploy({"from": guardian})
vault.initialize(token, governance, rewards, "", "", guardian)
vault.initialize(token, governance, rewards, governance, "", "", guardian)
vault.setDepositLimit(2 ** 256 - 1, {"from": governance})
return vault

Expand Down
35 changes: 24 additions & 11 deletions tests/functional/registry/test_deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@


def test_deployment_management(
gov, guardian, rewards, registry, Vault, create_token, create_vault, rando
gov,
guardian,
rewards,
management,
registry,
Vault,
create_token,
create_vault,
rando,
):
v1_token = create_token()

# No deployments yet for token
with brownie.reverts():
registry.latestVault(v1_token)
Expand Down Expand Up @@ -35,7 +42,9 @@ def test_deployment_management(

# Can't deploy the same vault api version twice, proxy or not
with brownie.reverts():
registry.newVault(v1_token, guardian, rewards, "", "", {"from": gov})
registry.newVault(
v1_token, guardian, rewards, management, "", "", {"from": gov}
)

# New release overrides previous release
v2_vault = create_vault(version="2.0.0") # Uses different token
Expand All @@ -47,7 +56,7 @@ def test_deployment_management(
assert registry.numTokens() == 1
proxy_vault = Vault.at(
registry.newVault(
v1_token, guardian, rewards, "", "", {"from": gov}
v1_token, guardian, rewards, management, "", "", {"from": gov}
).return_value
)
assert proxy_vault.apiVersion() == v2_vault.apiVersion() == "2.0.0"
Expand All @@ -62,7 +71,7 @@ def test_deployment_management(
v2_token = create_token()
proxy_vault = Vault.at(
registry.newVault(
v2_token, guardian, rewards, "", "", 1, {"from": gov}
v2_token, guardian, rewards, management, "", "", 1, {"from": gov}
).return_value
)
assert proxy_vault.apiVersion() == v1_vault.apiVersion() == "1.0.0"
Expand All @@ -79,7 +88,9 @@ def test_deployment_management(

# Not just anyone can create a new endorsed Vault, only governance can!
with brownie.reverts():
registry.newVault(create_token(), guardian, rewards, "", "", {"from": rando})
registry.newVault(
create_token(), guardian, rewards, management, "", "", {"from": rando}
)


def test_experimental_deployments(
Expand All @@ -90,12 +101,14 @@ def test_experimental_deployments(

# Anyone can make an experiment
token = create_token()
registry.newExperimentalVault(token, rando, rando, rando, "", "", {"from": rando})
registry.newExperimentalVault(
token, rando, rando, rando, rando, "", "", {"from": rando}
)

# You can make as many experiments as you want with same api version
experimental_vault = Vault.at(
registry.newExperimentalVault(
token, rando, rando, rando, "", "", {"from": rando}
token, rando, rando, rando, rando, "", "", {"from": rando}
).return_value
)

Expand Down Expand Up @@ -127,7 +140,7 @@ def test_experimental_deployments(
# You can't endorse a vault if it would overwrite a current deployment
experimental_vault = Vault.at(
registry.newExperimentalVault(
token, gov, gov, gov, "", "", {"from": rando}
token, gov, gov, gov, gov, "", "", {"from": rando}
).return_value
)
with brownie.reverts():
Expand All @@ -139,7 +152,7 @@ def test_experimental_deployments(

experimental_vault = Vault.at(
registry.newExperimentalVault(
token, gov, gov, gov, "", "", {"from": rando}
token, gov, gov, gov, gov, "", "", {"from": rando}
).return_value
)
registry.endorseVault(experimental_vault, {"from": gov})
Expand All @@ -149,7 +162,7 @@ def test_experimental_deployments(
token = create_token()
experimental_vault = Vault.at(
registry.newExperimentalVault(
token, gov, gov, gov, "", "", 1, {"from": rando}
token, gov, gov, gov, gov, "", "", 1, {"from": rando}
).return_value
)
registry.endorseVault(experimental_vault, 1, {"from": gov})
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/strategy/test_clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def other_token(gov, Token):
@pytest.fixture
def other_vault(gov, Vault, other_token):
vault = gov.deploy(Vault)
vault.initialize(other_token, gov, gov, "", "", gov)
vault.initialize(other_token, gov, gov, gov, "", "", gov)
yield vault


Expand Down
2 changes: 1 addition & 1 deletion tests/functional/strategy/test_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def test_bad_migration(
):
different_vault = gov.deploy(Vault)
different_vault.initialize(
token, gov, gov, token.symbol() + " yVault", "yv" + token.symbol(), gov
token, gov, gov, gov, token.symbol() + " yVault", "yv" + token.symbol(), gov
)
different_vault.setDepositLimit(2 ** 256 - 1, {"from": gov})
new_strategy = strategist.deploy(TestStrategy, different_vault)
Expand Down
14 changes: 10 additions & 4 deletions tests/functional/vault/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ def test_vault_deployment(guardian, gov, rewards, token, Vault):
# Deploy the Vault without any name/symbol overrides
vault = guardian.deploy(Vault)
vault.initialize(
token, gov, rewards, token.symbol() + " yVault", "yv" + token.symbol(), guardian
token,
gov,
rewards,
gov,
token.symbol() + " yVault",
"yv" + token.symbol(),
guardian,
)
# Addresses
assert vault.governance() == gov
Expand All @@ -47,18 +53,18 @@ def test_vault_deployment(guardian, gov, rewards, token, Vault):
def test_vault_name_symbol_override(guardian, gov, rewards, token, Vault):
# Deploy the Vault with name/symbol overrides
vault = guardian.deploy(Vault)
vault.initialize(token, gov, rewards, "crvY yVault", "yvcrvY", guardian)
vault.initialize(token, gov, rewards, gov, "crvY yVault", "yvcrvY", guardian)
# Assert that the overrides worked
assert vault.name() == "crvY yVault"
assert vault.symbol() == "yvcrvY"


def test_vault_reinitialization(guardian, gov, rewards, token, Vault):
vault = guardian.deploy(Vault)
vault.initialize(token, gov, rewards, "crvY yVault", "yvcrvY", guardian)
vault.initialize(token, gov, rewards, gov, "crvY yVault", "yvcrvY", guardian)
# Can't reinitialize a vault
with brownie.reverts():
vault.initialize(token, gov, rewards, "crvY yVault", "yvcrvY", guardian)
vault.initialize(token, gov, rewards, gov, "crvY yVault", "yvcrvY", guardian)


@pytest.mark.parametrize(
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/vault/test_losses.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def vault(gov, token, Vault):
# NOTE: Because the fixture has tokens in it already
vault = gov.deploy(Vault)
vault.initialize(
token, gov, gov, token.symbol() + " yVault", "yv" + token.symbol(), gov
token, gov, gov, gov, token.symbol() + " yVault", "yv" + token.symbol(), gov
)
vault.setDepositLimit(2 ** 256 - 1, {"from": gov})
yield vault
Expand Down
12 changes: 6 additions & 6 deletions tests/functional/vault/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def vault(gov, management, token, Vault):
# NOTE: Because the fixture has tokens in it already
vault = gov.deploy(Vault)
vault.initialize(
token, gov, gov, token.symbol() + " yVault", "yv" + token.symbol(), gov
token, gov, gov, gov, token.symbol() + " yVault", "yv" + token.symbol(), gov
)
vault.setDepositLimit(MAX_UINT256, {"from": gov})
vault.setManagement(management, {"from": gov})
Expand All @@ -31,14 +31,14 @@ def vault(gov, management, token, Vault):
@pytest.fixture
def other_vault(gov, Vault, other_token):
vault = gov.deploy(Vault)
vault.initialize(other_token, gov, gov, "", "", gov)
vault.initialize(other_token, gov, gov, gov, "", "", gov)
yield vault


@pytest.fixture
def vault_with_false_returning_token(gov, Vault, token_false_return):
vault = gov.deploy(Vault)
vault.initialize(token_false_return, gov, gov, "", "", gov)
vault.initialize(token_false_return, gov, gov, gov, "", "", gov)
vault.setDepositLimit(MAX_UINT256, {"from": gov})
yield vault

Expand All @@ -48,7 +48,7 @@ def test_credit_available_minDebtPerHarvest_larger_than_available(
):
vault = gov.deploy(Vault)
vault.initialize(
token, gov, gov, token.symbol() + " yVault", "yv" + token.symbol(), gov
token, gov, gov, gov, token.symbol() + " yVault", "yv" + token.symbol(), gov
)
vault.setDepositLimit(MAX_UINT256, {"from": gov})
strategy = gov.deploy(TestStrategy, vault)
Expand Down Expand Up @@ -96,7 +96,7 @@ def test_credit_available_minDebtPerHarvest_larger_than_available(
def test_regular_available_deposit_limit(Vault, token, gov):
vault = gov.deploy(Vault)
vault.initialize(
token, gov, gov, token.symbol() + " yVault", "yv" + token.symbol(), gov
token, gov, gov, gov, token.symbol() + " yVault", "yv" + token.symbol(), gov
)
token.approve(vault, 100, {"from": gov})
vault.setDepositLimit(100)
Expand All @@ -111,7 +111,7 @@ def test_regular_available_deposit_limit(Vault, token, gov):
def test_negative_available_deposit_limit(Vault, token, gov):
vault = gov.deploy(Vault)
vault.initialize(
token, gov, gov, token.symbol() + " yVault", "yv" + token.symbol(), gov
token, gov, gov, gov, token.symbol() + " yVault", "yv" + token.symbol(), gov
)
token.approve(vault, 100, {"from": gov})
vault.setDepositLimit(100)
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/vault/test_shares.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def vault(gov, token, Vault):
# NOTE: Overriding the one in conftest because it has values already
vault = gov.deploy(Vault)
vault.initialize(
token, gov, gov, token.symbol() + " yVault", "yv" + token.symbol(), gov
token, gov, gov, gov, token.symbol() + " yVault", "yv" + token.symbol(), gov
)
vault.setDepositLimit(2 ** 256 - 1, {"from": gov})
yield vault
Expand Down
4 changes: 2 additions & 2 deletions tests/functional/vault/test_strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def vault(gov, management, token, Vault):
# NOTE: Because the fixture has tokens in it already
vault = gov.deploy(Vault)
vault.initialize(
token, gov, gov, token.symbol() + " yVault", "yv" + token.symbol(), gov
token, gov, gov, gov, token.symbol() + " yVault", "yv" + token.symbol(), gov
)
vault.setDepositLimit(2 ** 256 - 1, {"from": gov})
vault.setManagement(management, {"from": gov})
Expand Down Expand Up @@ -68,7 +68,7 @@ def test_liquidation_after_hack(chain, gov, vault, token, TestStrategy):
def strategy_with_wrong_vault(gov, token, vault, Vault, TestStrategy):
otherVault = gov.deploy(Vault)
otherVault.initialize(
token, gov, gov, token.symbol() + " yVault", "yv" + token.symbol(), gov,
token, gov, gov, gov, token.symbol() + " yVault", "yv" + token.symbol(), gov,
)
assert otherVault.token() == token
assert otherVault != vault
Expand Down
Loading

0 comments on commit f97088d

Please sign in to comment.