Skip to content

Commit

Permalink
feat: iterate upgrade scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
rkolpakov committed Jan 21, 2025
1 parent 854790d commit f3514f8
Show file tree
Hide file tree
Showing 3 changed files with 181 additions and 18 deletions.
147 changes: 147 additions & 0 deletions scripts/dual_governance_downgrade_holesky.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
import time

from typing import Dict

from utils.agent import agent_forward, dual_governance_agent_forward
from utils.voting import bake_vote_items, confirm_vote_script, create_vote
from utils.ipfs import upload_vote_ipfs_description, calculate_vote_ipfs_description
from utils.config import (
contracts,
get_deployer_account,
get_is_live,
get_priority_fee,
)
from utils.permissions import (
encode_permission_set_manager,
encode_permission_create,
encode_permission_revoke,
encode_permission_grant,
)
from utils.mainnet_fork import pass_and_exec_dao_vote
from dual_governance_upgrade_holesky import dual_governance_contracts


try:
from brownie import interface
except ImportError:
print(
"You're probably running inside Brownie console. " "Please call:\n" "set_console_globals(interface=interface)"
)

description = "Holesky dual governance downgrade dry-run"

def start_vote(tx_params: Dict[str, str], silent: bool = False):
vote_desc_items, call_script_items = zip(
(
"Change permission manager for Lido STAKING_CONTROL_ROLE.",
agent_forward(
[
encode_permission_set_manager(contracts.lido, "STAKING_CONTROL_ROLE", contracts.voting)
]
)
),
(
"Revoke permission for STAKING_CONTROL_ROLE from Agent contract.",
encode_permission_revoke(
target_app=contracts.lido, permission_name="STAKING_CONTROL_ROLE", revoke_from=contracts.agent
),
),
(
"Grant permission for STAKING_CONTROL_ROLE to Voting contract.",
encode_permission_grant(
target_app=contracts.lido, permission_name="STAKING_CONTROL_ROLE", grant_to=contracts.voting
),
),
(
"Revoke WithdrawalQueue PAUSE_ROLE from Reseal Manager.",
(
agent_forward(
[
(
contracts.withdrawal_queue.address,
contracts.withdrawal_queue.revokeRole.encode_input(
contracts.withdrawal_queue.PAUSE_ROLE(), dual_governance_contracts["resealManager"]
),
)
]
)
),
),
(
"Revoke WithdrawalQueue RESUME_ROLE from Reseal Manager.",
(
agent_forward(
[
(
contracts.withdrawal_queue.address,
contracts.withdrawal_queue.revokeRole.encode_input(
contracts.withdrawal_queue.RESUME_ROLE(), dual_governance_contracts["resealManager"]
),
)
]
)
),
),
(
"Grant AllowedTokensRegistry DEFAULT_ADMIN_ROLE to Agent.",
(
contracts.allowed_tokens_registry.address,
contracts.allowed_tokens_registry.grantRole.encode_input(
contracts.allowed_tokens_registry.DEFAULT_ADMIN_ROLE(), contracts.agent
),
),
),
(
"Revoke AllowedTokensRegistry DEFAULT_ADMIN_ROLE from Voting.",
(
contracts.allowed_tokens_registry.address,
contracts.allowed_tokens_registry.revokeRole.encode_input(
contracts.allowed_tokens_registry.DEFAULT_ADMIN_ROLE(), contracts.voting
),
),
),
(
"Revoke permission for RUN_SCRIPT_ROLE from DG Executor contract.",
encode_permission_revoke(
target_app=contracts.agent,
permission_name="RUN_SCRIPT_ROLE",
revoke_from=contracts.dual_governance_admin_executor,
),
),
)

vote_items = bake_vote_items(list(vote_desc_items), list(call_script_items))

if silent:
desc_ipfs = calculate_vote_ipfs_description(description)
else:
desc_ipfs = upload_vote_ipfs_description(description)

return confirm_vote_script(vote_items, silent, desc_ipfs) and list(
create_vote(vote_items, tx_params, desc_ipfs=desc_ipfs)
)


def main():
tx_params: Dict[str, str] = {"from": get_deployer_account().address}
if get_is_live():
tx_params["priority_fee"] = get_priority_fee()

vote_id, _ = start_vote(tx_params=tx_params, silent=False)

vote_id >= 0 and print(f"Vote created: {vote_id}.")

time.sleep(5) # hack for waiting thread #2.


def start_and_execute_vote_on_fork():
if get_is_live():
raise Exception("This script is for local testing only.")

tx_params = {"from": get_deployer_account()}
vote_id, _ = start_vote(tx_params=tx_params, silent=True)

time.sleep(5) # hack for waiting thread #2.

print(f"Vote created: {vote_id}.")
pass_and_exec_dao_vote(int(vote_id))
24 changes: 15 additions & 9 deletions scripts/dual_governance_upgrade_holesky.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from typing import Dict

from utils.agent import agent_forward
from utils.agent import agent_forward, dual_governance_agent_forward
from utils.voting import bake_vote_items, confirm_vote_script, create_vote
from utils.ipfs import upload_vote_ipfs_description, calculate_vote_ipfs_description
from utils.config import (
Expand Down Expand Up @@ -46,7 +46,7 @@
}

def start_vote(tx_params: Dict[str, str], silent: bool = False):
foo_contract = interface.Foo("0x258C151254bB8C6673dEF05fB965D0dD8cB7eA89")
foo_contract = interface.Foo("0xC3fc22C7e0d20247B797fb6dc743BD3879217c81")

vote_desc_items, call_script_items = zip(
(
Expand Down Expand Up @@ -96,7 +96,7 @@ def start_vote(tx_params: Dict[str, str], silent: bool = False):
),
),
(
"Grant DEFAULT_ADMIN_ROLE to Voting.",
"Grant AllowedTokensRegistry DEFAULT_ADMIN_ROLE to Voting.",
(
agent_forward(
[
Expand All @@ -111,7 +111,7 @@ def start_vote(tx_params: Dict[str, str], silent: bool = False):
),
),
(
"Revoke DEFAULT_ADMIN_ROLE from Agent.",
"Revoke AllowedTokensRegistry DEFAULT_ADMIN_ROLE from Agent.",
(
contracts.allowed_tokens_registry.address,
contracts.allowed_tokens_registry.revokeRole.encode_input(
Expand All @@ -120,10 +120,10 @@ def start_vote(tx_params: Dict[str, str], silent: bool = False):
),
),
(
"Grant permission for EXECUTE_ROLE to DG Executor contract.",
"Grant permission for RUN_SCRIPT_ROLE to DG Executor contract.",
encode_permission_grant(
target_app=contracts.agent,
permission_name="EXECUTE_ROLE",
permission_name="RUN_SCRIPT_ROLE",
grant_to=contracts.dual_governance_admin_executor,
),
),
Expand All @@ -137,9 +137,15 @@ def start_vote(tx_params: Dict[str, str], silent: bool = False):
(
"Submit first dual governance proposal",
(
contracts.dual_governance.address,
contracts.dual_governance.submitProposal.encode_input(
[(foo_contract.address, 0, foo_contract.bar.encode_input())], "Test proposal"
dual_governance_agent_forward(
[(
foo_contract.address,
foo_contract.bar.encode_input()
),
(
contracts.time_constraints.address,
contracts.time_constraints.checkExecuteWithinDayTime.encode_input(28800, 72000)
)]
)
)
)
Expand Down
28 changes: 19 additions & 9 deletions tests/dual_governance_upgrade_holesky_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@
from utils.test.tx_tracing_helpers import *
from brownie.network.transaction import TransactionReceipt
from utils.config import contracts
from brownie.network.account import Account

try:
from brownie import interface
from brownie import interface, chain
except ImportError:
print(
"You're probably running inside Brownie console. " "Please call:\n" "set_console_globals(interface=interface)"
)

def test_vote(helpers, accounts, ldo_holder, vote_ids_from_env, bypass_events_decoding):
def test_vote(helpers, accounts, ldo_holder, vote_ids_from_env, bypass_events_decoding, stranger: Account):
dao_voting = contracts.voting
timelock = interface.EmergencyProtectedTimelock(contracts.dual_governance.TIMELOCK())

# Lido
assert contracts.acl.getPermissionManager(contracts.lido, contracts.lido.STAKING_CONTROL_ROLE()) == contracts.voting
Expand All @@ -27,8 +29,8 @@ def test_vote(helpers, accounts, ldo_holder, vote_ids_from_env, bypass_events_de
assert not contracts.allowed_tokens_registry.hasRole(contracts.allowed_tokens_registry.DEFAULT_ADMIN_ROLE(), contracts.voting)

# Agent
assert not contracts.acl.hasPermission(contracts.dual_governance_admin_executor, contracts.agent, contracts.agent.EXECUTE_ROLE())
assert contracts.acl.hasPermission(contracts.voting, contracts.agent, contracts.agent.EXECUTE_ROLE())
assert not contracts.acl.hasPermission(contracts.dual_governance_admin_executor, contracts.agent, contracts.agent.RUN_SCRIPT_ROLE())
assert contracts.acl.hasPermission(contracts.voting, contracts.agent, contracts.agent.RUN_SCRIPT_ROLE())

# Reseal manager
assert not contracts.withdrawal_queue.hasRole(contracts.withdrawal_queue.PAUSE_ROLE(), dual_governance_contracts["resealManager"])
Expand All @@ -51,13 +53,21 @@ def test_vote(helpers, accounts, ldo_holder, vote_ids_from_env, bypass_events_de
assert not contracts.allowed_tokens_registry.hasRole(contracts.allowed_tokens_registry.DEFAULT_ADMIN_ROLE(), contracts.agent)

# Agent
assert contracts.acl.hasPermission(contracts.dual_governance_admin_executor, contracts.agent, contracts.agent.EXECUTE_ROLE())
assert contracts.acl.hasPermission(contracts.voting, contracts.agent, contracts.agent.EXECUTE_ROLE())
assert contracts.acl.hasPermission(contracts.dual_governance_admin_executor, contracts.agent, contracts.agent.RUN_SCRIPT_ROLE())
assert contracts.acl.hasPermission(contracts.voting, contracts.agent, contracts.agent.RUN_SCRIPT_ROLE())

# Reseal manager
assert contracts.withdrawal_queue.hasRole(contracts.withdrawal_queue.PAUSE_ROLE(), dual_governance_contracts["resealManager"])
assert contracts.withdrawal_queue.hasRole(contracts.withdrawal_queue.RESUME_ROLE(), dual_governance_contracts["resealManager"])

# # Validate vote events
# if not bypass_events_decoding:
# assert count_vote_items_by_events(tx, dao_voting) == 2, "Incorrect voting items count"
proposal_id = timelock.getProposalsCount()

# while not contracts.dual_governance.canScheduleProposal(proposal_id):
chain.sleep(60 * 24)

contracts.dual_governance.scheduleProposal(proposal_id, {"from": stranger})

# while not timelock.canExecute(proposal_id):
chain.sleep(60 * 24)

timelock.execute(proposal_id, {"from": stranger})

0 comments on commit f3514f8

Please sign in to comment.