Skip to content

Commit

Permalink
chore: match gov abi (#213)
Browse files Browse the repository at this point in the history
  • Loading branch information
Schlagonia authored Sep 23, 2024
1 parent aff0b5a commit d268bbd
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 35 deletions.
30 changes: 17 additions & 13 deletions contracts/VaultFactory.vy
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,12 @@ event RemovedCustomProtocolFee:
event FactoryShutdown:
pass

event UpdateGovernance:
governance: indexed(address)
event GovernanceTransferred:
previousGovernance: indexed(address)
newGovernance: indexed(address)

event NewPendingGovernance:
pending_governance: indexed(address)
event UpdatePendingGovernance:
newPendingGovernance: indexed(address)


# Identifier for this version of the vault.
Expand All @@ -85,7 +86,7 @@ shutdown: public(bool)
# Address that can set or change the fee configs.
governance: public(address)
# Pending governance waiting to be accepted.
pending_governance: public(address)
pendingGovernance: public(address)

# Name for identification.
name: public(String[64])
Expand Down Expand Up @@ -272,7 +273,7 @@ def set_protocol_fee_recipient(new_protocol_fee_recipient: address):
assert new_protocol_fee_recipient != empty(address), "zero address"

default_fee_data: uint256 = self.default_protocol_fee_data

self.default_protocol_fee_data = self._pack_protocol_fee_data(
new_protocol_fee_recipient,
self._unpack_protocol_fee(default_fee_data),
Expand Down Expand Up @@ -339,23 +340,26 @@ def shutdown_factory():
log FactoryShutdown()

@external
def set_governance(new_governance: address):
def transferGovernance(new_governance: address):
"""
@notice Set the governance address
@param new_governance The new governance address
"""
assert msg.sender == self.governance, "not governance"
self.pending_governance = new_governance
self.pendingGovernance = new_governance

log NewPendingGovernance(new_governance)
log UpdatePendingGovernance(new_governance)

@external
def accept_governance():
def acceptGovernance():
"""
@notice Accept the governance address
"""
assert msg.sender == self.pending_governance, "not pending governance"
assert msg.sender == self.pendingGovernance, "not pending governance"

old_governance: address = self.governance

self.governance = msg.sender
self.pending_governance = empty(address)
self.pendingGovernance = empty(address)

log UpdateGovernance(msg.sender)
log GovernanceTransferred(old_governance, msg.sender)
2 changes: 1 addition & 1 deletion scripts/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def deploy_original_and_factory():
print(f"Deploying factory...")

factory_constructor = vault_factory.constructor.encode_input(
"Yearn v3.0.2 Vault Factory",
"Yearn v3.0.3 Vault Factory",
original_address,
"0x33333333D5eFb92f19a5F94a43456b3cec2797AE",
)
Expand Down
42 changes: 21 additions & 21 deletions tests/unit/factory/test_ownership.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,66 +5,66 @@

def test_gov_transfers_ownership(vault_factory, gov, strategist):
assert vault_factory.governance() == gov
assert vault_factory.pending_governance() == ZERO_ADDRESS
assert vault_factory.pendingGovernance() == ZERO_ADDRESS

vault_factory.set_governance(strategist, sender=gov)
vault_factory.transferGovernance(strategist, sender=gov)

assert vault_factory.governance() == gov
assert vault_factory.pending_governance() == strategist
assert vault_factory.pendingGovernance() == strategist

vault_factory.accept_governance(sender=strategist)
vault_factory.acceptGovernance(sender=strategist)

assert vault_factory.governance() == strategist
assert vault_factory.pending_governance() == ZERO_ADDRESS
assert vault_factory.pendingGovernance() == ZERO_ADDRESS


def test_gov_transfers_ownership__gov_cant_accept(vault_factory, gov, strategist):
assert vault_factory.governance() == gov
assert vault_factory.pending_governance() == ZERO_ADDRESS
assert vault_factory.pendingGovernance() == ZERO_ADDRESS

vault_factory.set_governance(strategist, sender=gov)
vault_factory.transferGovernance(strategist, sender=gov)

assert vault_factory.governance() == gov
assert vault_factory.pending_governance() == strategist
assert vault_factory.pendingGovernance() == strategist

with ape.reverts("not pending governance"):
vault_factory.accept_governance(sender=gov)
vault_factory.acceptGovernance(sender=gov)

assert vault_factory.governance() == gov
assert vault_factory.pending_governance() == strategist
assert vault_factory.pendingGovernance() == strategist


def test_random_transfers_ownership__fails(vault_factory, gov, strategist):
assert vault_factory.governance() == gov
assert vault_factory.pending_governance() == ZERO_ADDRESS
assert vault_factory.pendingGovernance() == ZERO_ADDRESS

with ape.reverts("not governance"):
vault_factory.set_governance(strategist, sender=strategist)
vault_factory.transferGovernance(strategist, sender=strategist)

assert vault_factory.governance() == gov
assert vault_factory.pending_governance() == ZERO_ADDRESS
assert vault_factory.pendingGovernance() == ZERO_ADDRESS


def test_gov_transfers_ownership__can_change_pending(
vault_factory, gov, bunny, strategist
):
assert vault_factory.governance() == gov
assert vault_factory.pending_governance() == ZERO_ADDRESS
assert vault_factory.pendingGovernance() == ZERO_ADDRESS

vault_factory.set_governance(strategist, sender=gov)
vault_factory.transferGovernance(strategist, sender=gov)

assert vault_factory.governance() == gov
assert vault_factory.pending_governance() == strategist
assert vault_factory.pendingGovernance() == strategist

vault_factory.set_governance(bunny, sender=gov)
vault_factory.transferGovernance(bunny, sender=gov)

assert vault_factory.governance() == gov
assert vault_factory.pending_governance() == bunny
assert vault_factory.pendingGovernance() == bunny

with ape.reverts("not pending governance"):
vault_factory.accept_governance(sender=strategist)
vault_factory.acceptGovernance(sender=strategist)

vault_factory.accept_governance(sender=bunny)
vault_factory.acceptGovernance(sender=bunny)

assert vault_factory.governance() == bunny
assert vault_factory.pending_governance() == ZERO_ADDRESS
assert vault_factory.pendingGovernance() == ZERO_ADDRESS

0 comments on commit d268bbd

Please sign in to comment.