diff --git a/scripts/vote_2024_11_26.py b/scripts/vote_2024_11_26.py new file mode 100644 index 00000000..ef88875e --- /dev/null +++ b/scripts/vote_2024_11_26.py @@ -0,0 +1,168 @@ +""" +Voting 26/11/2024. + +I. Change the limits for ET on ATC & PML +1. ATC: increase from 1,5m per quarter to 7m USDC/USDT/DAI per quarter - set 7'000'000 limit on ATC registry `0xe07305F43B11F230EaA951002F6a55a16419B707` for 3 mos +2. PML: decrease from 6m per quarter to 4m USDC/USDT/DAI per quarter - set 4'000'000 limit on PML registry `0xDFfCD3BF14796a62a804c1B16F877Cf7120379dB` for 3 mos + +II. TMC limits update +3. Update TMC limit to 12,000 stETH on TMC registry `0x1a7cFA9EFB4D5BfFDE87B0FaEb1fC65d653868C0` for 6 mos +4. Reset the TMC amount spent on TMC registry `0x1a7cFA9EFB4D5BfFDE87B0FaEb1fC65d653868C0` + +III. Simply staking reward address change +5. Change staking reward address to `0x1EC3Cbe8fb1D8019092500CcA2111C158a35bC82` for node operator with id = 16 + +Vote passed & executed on XXX-XX-XXXX XX:XX:XX PM UTC, block #XXXXXXXX. +""" + +import time + +from typing import Dict, Tuple, Optional, List + +from brownie import interface +from brownie.network.transaction import TransactionReceipt +from utils.voting import bake_vote_items, confirm_vote_script, create_vote +from utils.easy_track import add_evmscript_factory, create_permissions +from utils.permission_parameters import Param, SpecialArgumentID, ArgumentValue, Op +from utils.ipfs import upload_vote_ipfs_description, calculate_vote_ipfs_description +from utils.node_operators import encode_set_node_operator_reward_address + +from utils.config import ( + get_deployer_account, + contracts, + get_is_live, + get_priority_fee, +) + +from utils.easy_track import ( + add_evmscript_factory, + create_permissions, + remove_evmscript_factory +) +from utils.allowed_recipients_registry import ( + set_limit_parameters, + update_spent_amount, + unsafe_set_spent_amount +) + +from utils.agent import agent_forward + +description = """ +I. Change the limits for ET on ATC & PML +1. ATC: increase from 1,5m per quarter to 7m USDC/USDT/DAI per quarter - set 7'000'000 limit on ATC registry `0xe07305F43B11F230EaA951002F6a55a16419B707` for 3 mos +2. PML: decrease from 6m per quarter to 4m USDC/USDT/DAI per quarter - set 4'000'000 limit on PML registry `0xDFfCD3BF14796a62a804c1B16F877Cf7120379dB` for 3 mos + +II. TMC limits update +3. Update TMC limit to 12,000 stETH on TMC registry `0x1a7cFA9EFB4D5BfFDE87B0FaEb1fC65d653868C0` for 6 mos +4. Reset the TMC amount spent on TMC registry `0x1a7cFA9EFB4D5BfFDE87B0FaEb1fC65d653868C0` + +III. Simply staking reward address change +5. Change staking reward address to `0x1EC3Cbe8fb1D8019092500CcA2111C158a35bC82` for node operator with id = 16 +""" + +def start_vote(tx_params: Dict[str, str], silent: bool) -> bool | list[int | TransactionReceipt | None]: + """Prepare and run voting.""" + + atc_registry = interface.AllowedRecipientRegistry("0xe07305F43B11F230EaA951002F6a55a16419B707") + pml_registry = interface.AllowedRecipientRegistry("0xDFfCD3BF14796a62a804c1B16F877Cf7120379dB") + + tmc_registry = interface.AllowedRecipientRegistry("0x1a7cFA9EFB4D5BfFDE87B0FaEb1fC65d653868C0") + + NO_registry = contracts.node_operators_registry + SimplyStaking_id = 16 + SimplyStaking_new_reward_address = "0x1EC3Cbe8fb1D8019092500CcA2111C158a35bC82" + + vote_desc_items, call_script_items = zip( + # + # I. Change the limits for ET on ATC & PML + # + ( + "1. Set 7'000'000 limit on ATC registry `0xe07305F43B11F230EaA951002F6a55a16419B707` for 3 mos", + agent_forward( + [ + set_limit_parameters( + registry_address=atc_registry, + limit=7_000_000 * 10 ** 18, + period_duration_months=3 + ), + ] + ), + ), + ( + "2. Set 4'000'000 limit on PML registry `0xDFfCD3BF14796a62a804c1B16F877Cf7120379dB` for 3 mos", + agent_forward( + [ + set_limit_parameters( + registry_address=pml_registry, + limit=4_000_000 * 10 ** 18, + period_duration_months=3 + ), + ] + ), + ), + # + # II. TMC limits update + # + ( + "3. Update TMC limit to 12,000 stETH on TMC registry `0x1a7cFA9EFB4D5BfFDE87B0FaEb1fC65d653868C0` for 6 mos", + agent_forward( + [ + set_limit_parameters( + registry_address=tmc_registry, + limit=12_000 * 10 ** 18, + period_duration_months=6 + ), + ] + ), + ), + ( + "4. Reset the TMC amount spent on TMC registry `0x1a7cFA9EFB4D5BfFDE87B0FaEb1fC65d653868C0`", + agent_forward( + [ + unsafe_set_spent_amount( + spent_amount=0, + registry_address=tmc_registry + ), + ] + ), + ), + # + # III. Simply staking reward address change + # + ( + "5. Change staking reward address to `0x1EC3Cbe8fb1D8019092500CcA2111C158a35bC82` for node operator with id = 16", + agent_forward( + [ + encode_set_node_operator_reward_address( + SimplyStaking_id, + SimplyStaking_new_reward_address, + NO_registry + ), + ] + ), + ), + ) + + 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 = {"from": get_deployer_account()} + + 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. \ No newline at end of file diff --git a/tests/test_2024_11_26.py b/tests/test_2024_11_26.py new file mode 100644 index 00000000..92c34a96 --- /dev/null +++ b/tests/test_2024_11_26.py @@ -0,0 +1,273 @@ +""" +Tests for voting 26/11/2024. +""" + +from scripts.vote_2024_11_26 import start_vote +from brownie import interface, reverts, accounts, ZERO_ADDRESS, chain, web3 +from utils.test.tx_tracing_helpers import * +from utils.config import contracts, LDO_HOLDER_ADDRESS_FOR_TESTS +from utils.config import contracts +from utils.test.easy_track_helpers import create_and_enact_payment_motion +from utils.test.event_validators.allowed_recipients_registry import ( + validate_set_limit_parameter_event, + validate_set_spent_amount_event, +) +from utils.test.event_validators.node_operators_registry import ( + validate_node_operator_reward_address_set_event, + NodeOperatorRewardAddressSetItem +) +from configs.config_mainnet import ( USDC_TOKEN ) + +STETH_TRANSFER_MAX_DELTA = 2 + +def test_vote(helpers, accounts, vote_ids_from_env, stranger): + + # misc + easy_track = interface.EasyTrack("0xF0211b7660680B49De1A7E9f25C65660F0a13Fea") + nor = contracts.node_operators_registry + prepare_agent_for_usdc_payment(15_000_000 * (10**6)) + prepare_agent_for_steth_payment(20_000 * 10**18) + + # Item 1 + atc_allowed_recipients_registry = interface.AllowedRecipientRegistry("0xe07305F43B11F230EaA951002F6a55a16419B707") + atc_multisig_acc = accounts.at("0x9B1cebF7616f2BC73b47D226f90b01a7c9F86956", force=True) + atc_trusted_caller_acc = atc_multisig_acc + atc_top_up_evm_script_factory = interface.TopUpAllowedRecipients("0x1843Bc35d1fD15AbE1913b9f72852a79457C42Ab") + atcBudgetLimitAfterExpected = 7_000_000 * 10**18 + atcSpendLimitAfterExpected = 5_500_000 * 10**18 + + # Item 2 + pml_allowed_recipients_registry = interface.AllowedRecipientRegistry("0xDFfCD3BF14796a62a804c1B16F877Cf7120379dB") + pml_multisig_acc = accounts.at("0x17F6b2C738a63a8D3A113a228cfd0b373244633D", force=True) + pml_trusted_caller_acc = pml_multisig_acc + pml_top_up_evm_script_factory = interface.TopUpAllowedRecipients("0x92a27C4e5e35cFEa112ACaB53851Ec70e2D99a8D") + pmlBudgetLimitAfterExpected = 4_000_000 * 10**18 + pmlSpendLimitAfterExpected = 3_000_000 * 10**18 + + # Item 3, 4 + tmc_allowed_recipients_registry = interface.AllowedRecipientRegistry("0x1a7cFA9EFB4D5BfFDE87B0FaEb1fC65d653868C0") + tmc_multisig = accounts.at("0xa02FC823cCE0D016bD7e17ac684c9abAb2d6D647", force=True) + tmc_trusted_caller = tmc_multisig + tmc_top_up_evm_script_factory = interface.TopUpAllowedRecipients("0x6e04aED774B7c89BB43721AcDD7D03C872a51B69") + stETH_token = interface.ERC20("0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84") + stonks_steth_contract = accounts.at("0x3e2D251275A92a8169A3B17A2C49016e2de492a7", force=True) + tmcBudgetAfterExpected = 12_000 * 10**18 + tmcNewSpentAmountExpected = 0 + + # Item 5 + # NO's data indexes + activeIndex = 0 + nameIndex = 1 + rewardAddressIndex = 2 + stakingLimitIndex = 3 + stoppedValidatorsIndex = 4 + # Simply Staking params + SimplyStakingId = 16 + SimplyStakingName = "Simply Staking" + SimplyStakingOldRewardAddress = "0xFEf3C7aa6956D03dbad8959c59155c4A465DCacd" + SimplyStakingNewRewardAddress = "0x1EC3Cbe8fb1D8019092500CcA2111C158a35bC82" + + + # Item 1 + atcBudgetLimitBefore, atcPeriodDurationMonthsBefore = interface.AllowedRecipientRegistry(atc_allowed_recipients_registry).getLimitParameters() + assert atcBudgetLimitBefore == 1_500_000 * 10 ** 18 + assert atcPeriodDurationMonthsBefore == 3 + assert 0 == interface.AllowedRecipientRegistry(atc_allowed_recipients_registry).spendableBalance() + + # Item 2 + pmlBudgetLimitBefore, pmlPeriodDurationMonthsBefore = interface.AllowedRecipientRegistry(pml_allowed_recipients_registry).getLimitParameters() + assert pmlBudgetLimitBefore == 6_000_000 * 10 ** 18 + assert pmlPeriodDurationMonthsBefore == 3 + assert 5_000_000 * 10**18 == interface.AllowedRecipientRegistry(pml_allowed_recipients_registry).spendableBalance() + + # Item 3 + tmcBudgetLimitBefore, tmcPeriodDurationMonthsBefore = interface.AllowedRecipientRegistry(tmc_allowed_recipients_registry).getLimitParameters() + assert tmcBudgetLimitBefore == 9_000 * 10 ** 18 + assert tmcPeriodDurationMonthsBefore == 6 + + # Item 4 + alreadySpentAmountBefore, spendableBalanceInPeriodBefore, periodStartTimestampBefore, periodEndTimestampBefore = tmc_allowed_recipients_registry.getPeriodState() + assert alreadySpentAmountBefore > 0 + + # Item 5 + SimplyStakingDataBefore = nor.getNodeOperator(SimplyStakingId, True) + assert SimplyStakingOldRewardAddress == SimplyStakingDataBefore[rewardAddressIndex] + assert SimplyStakingName == SimplyStakingDataBefore[nameIndex] + + + # START VOTE + if len(vote_ids_from_env) > 0: + (vote_id,) = vote_ids_from_env + else: + tx_params = {"from": LDO_HOLDER_ADDRESS_FOR_TESTS} + vote_id, _ = start_vote(tx_params, silent=True) + vote_tx = helpers.execute_vote(accounts, vote_id, contracts.voting) + print(f"voteId = {vote_id}, gasUsed = {vote_tx.gas_used}") + + + # Item 1 + atcBudgetLimitAfter, atcPeriodDurationMonthsAfter = interface.AllowedRecipientRegistry(atc_allowed_recipients_registry).getLimitParameters() + atc_spend_limit_after = interface.AllowedRecipientRegistry(atc_allowed_recipients_registry).getPeriodState()[1] + atcSpendableBalanceAfter = interface.AllowedRecipientRegistry(atc_allowed_recipients_registry).spendableBalance() + assert atcBudgetLimitAfter == atcBudgetLimitAfterExpected + assert atcPeriodDurationMonthsAfter == 3 + assert atc_spend_limit_after == atcSpendLimitAfterExpected + assert interface.AllowedRecipientRegistry(atc_allowed_recipients_registry).isUnderSpendableBalance(atcSpendableBalanceAfter, 3) + assert atcSpendableBalanceAfter == atcSpendLimitAfterExpected + limit_test(easy_track, + int(atcSpendableBalanceAfter / (10**18)) * 10**6, + atc_trusted_caller_acc, + atc_top_up_evm_script_factory, + atc_multisig_acc, + stranger, + interface.Usdc(USDC_TOKEN), + 2_000_000 * 10**6 + ) + + # Item 2 + pmlBudgetLimitAfter, pmlPeriodDurationMonthsAfter = interface.AllowedRecipientRegistry(pml_allowed_recipients_registry).getLimitParameters() + pml_spend_limit_after = interface.AllowedRecipientRegistry(pml_allowed_recipients_registry).getPeriodState()[1] + pmlSpendableBalanceAfter = interface.AllowedRecipientRegistry(pml_allowed_recipients_registry).spendableBalance() + assert pmlBudgetLimitAfter == pmlBudgetLimitAfterExpected + assert pmlPeriodDurationMonthsAfter == 3 + assert pml_spend_limit_after == pmlSpendLimitAfterExpected + assert interface.AllowedRecipientRegistry(pml_allowed_recipients_registry).isUnderSpendableBalance(pmlSpendableBalanceAfter, 3) + assert pmlSpendableBalanceAfter == pmlSpendLimitAfterExpected + limit_test(easy_track, + int(pmlSpendableBalanceAfter / (10**18)) * 10**6, + pml_trusted_caller_acc, + pml_top_up_evm_script_factory, + pml_multisig_acc, + stranger, + interface.Usdc(USDC_TOKEN), + 2_000_000 * 10**6 + ) + + # Item 3 + tmcBudgetLimitAfter, tmcPeriodDurationMonthsAfter = interface.AllowedRecipientRegistry(tmc_allowed_recipients_registry).getLimitParameters() + assert tmcBudgetLimitAfter == tmcBudgetAfterExpected + assert tmcPeriodDurationMonthsAfter == 6 + + # Item 4 + alreadySpentAmountAfter = tmc_allowed_recipients_registry.getPeriodState()[0] + assert alreadySpentAmountAfter == tmcNewSpentAmountExpected + tmcSpendableBalanceAfter = interface.AllowedRecipientRegistry(tmc_allowed_recipients_registry).spendableBalance() + assert tmcSpendableBalanceAfter == tmcBudgetAfterExpected + limit_test(easy_track, + tmcSpendableBalanceAfter, + tmc_trusted_caller, + tmc_top_up_evm_script_factory, + stonks_steth_contract, + stranger, + stETH_token, + 1_000 * 10 ** 18 + ) + + # Item 5 + SimplyStakingDataAfter = nor.getNodeOperator(SimplyStakingId, True) + assert SimplyStakingNewRewardAddress == SimplyStakingDataAfter[rewardAddressIndex] + assert SimplyStakingDataBefore[nameIndex] == SimplyStakingDataAfter[nameIndex] + assert SimplyStakingDataBefore[activeIndex] == SimplyStakingDataAfter[activeIndex] + assert SimplyStakingDataBefore[stakingLimitIndex] == SimplyStakingDataAfter[stakingLimitIndex] + assert SimplyStakingDataBefore[stoppedValidatorsIndex] == SimplyStakingDataAfter[stoppedValidatorsIndex] + + + # events + display_voting_events(vote_tx) + evs = group_voting_events(vote_tx) + + validate_set_limit_parameter_event( + evs[0], + limit=atcBudgetLimitAfterExpected, + period_duration_month=3, + period_start_timestamp=1727740800, + ) + validate_set_limit_parameter_event( + evs[1], + limit=pmlBudgetLimitAfterExpected, + period_duration_month=3, + period_start_timestamp=1727740800, + ) + validate_set_limit_parameter_event( + evs[2], + limit=tmcBudgetAfterExpected, + period_duration_month=6, + period_start_timestamp=1719792000, + ) + validate_set_spent_amount_event( + evs[3], + new_spent_amount=tmcNewSpentAmountExpected, + ) + validate_node_operator_reward_address_set_event( + evs[4], + NodeOperatorRewardAddressSetItem( + nodeOperatorId=SimplyStakingId, + reward_address=SimplyStakingNewRewardAddress + ) + ) + +def limit_test(easy_track, to_spend, trusted_caller_acc, top_up_evm_script_factory, multisig_acc, stranger, token, max_spend_at_once): + + chain.snapshot() + + # check that there is no way to spend more then expected + with reverts("SUM_EXCEEDS_SPENDABLE_BALANCE"): + create_and_enact_payment_motion( + easy_track, + trusted_caller_acc, + top_up_evm_script_factory, + token, + [multisig_acc], + [to_spend + 1], + stranger, + ) + + # spend all step by step + while to_spend > 0: + create_and_enact_payment_motion( + easy_track, + trusted_caller_acc, + top_up_evm_script_factory, + token, + [multisig_acc], + [min(max_spend_at_once, to_spend)], + stranger, + ) + to_spend -= min(max_spend_at_once, to_spend) + + # make sure there is nothing left so that you can't spend anymore + with reverts("SUM_EXCEEDS_SPENDABLE_BALANCE"): + create_and_enact_payment_motion( + easy_track, + trusted_caller_acc, + top_up_evm_script_factory, + token, + [multisig_acc], + [1], + stranger, + ) + + chain.revert() + +def prepare_agent_for_steth_payment(amount: int): + agent, steth = contracts.agent, contracts.lido + eth_whale = accounts.at("0x00000000219ab540356cBB839Cbe05303d7705Fa", force=True) + if steth.balanceOf(agent) < amount: + steth.submit(ZERO_ADDRESS, {"from": eth_whale, "value": amount + 2 * STETH_TRANSFER_MAX_DELTA}) + steth.transfer(agent, amount + STETH_TRANSFER_MAX_DELTA, {"from": eth_whale}) + assert steth.balanceOf(agent) >= amount, "Insufficient stETH balance" + +def prepare_agent_for_usdc_payment(amount: int): + agent, usdc = contracts.agent, interface.Usdc(USDC_TOKEN) + if usdc.balanceOf(agent) < amount: + usdc_minter = accounts.at("0x5B6122C109B78C6755486966148C1D70a50A47D7", force=True) + usdc_controller = accounts.at("0x79E0946e1C186E745f1352d7C21AB04700C99F71", force=True) + usdc_master_minter = interface.UsdcMasterMinter("0xE982615d461DD5cD06575BbeA87624fda4e3de17") + + web3.provider.make_request("evm_setAccountBalance", [usdc_controller.address, hex(100_000 * 10**18)]) + assert usdc_controller.balance() >= 100_000 * 10**18 + + usdc_master_minter.incrementMinterAllowance(amount, {"from": usdc_controller}) + usdc.mint(agent, amount, {"from": usdc_minter}) + + assert usdc.balanceOf(agent) >= amount, "Insufficient USDC balance" diff --git a/utils/allowed_recipients_registry.py b/utils/allowed_recipients_registry.py index 40b11d86..3d4c5576 100644 --- a/utils/allowed_recipients_registry.py +++ b/utils/allowed_recipients_registry.py @@ -14,6 +14,9 @@ def update_spent_amount(registry_address: str, spent_amount: int) -> Tuple[str, registry = interface.AllowedRecipientRegistry(registry_address) return (registry.address, registry.updateSpentAmount.encode_input(spent_amount)) +def unsafe_set_spent_amount(registry_address: str, spent_amount: int) -> Tuple[str, str]: + registry = interface.AllowedRecipientRegistry(registry_address) + return (registry.address, registry.unsafeSetSpentAmount.encode_input(spent_amount)) def create_top_up_allowed_recipient_permission(registry_address: str) -> str: return ( diff --git a/utils/test/event_validators/allowed_recipients_registry.py b/utils/test/event_validators/allowed_recipients_registry.py index 4c3b709a..f51c0d71 100644 --- a/utils/test/event_validators/allowed_recipients_registry.py +++ b/utils/test/event_validators/allowed_recipients_registry.py @@ -49,3 +49,16 @@ def validate_update_spent_amount_event( assert event["SpendableAmountChanged"]["_spendableBalance"] == spendable_balance_in_period assert event["SpendableAmountChanged"]["_periodStartTimestamp"] == period_start_timestamp assert event["SpendableAmountChanged"]["_periodEndTimestamp"] == period_end_timestamp + +def validate_set_spent_amount_event( + event: EventDict, + new_spent_amount: int, +): + _events_chain = ( + ["LogScriptCall", "LogScriptCall", "SpentAmountChanged", "ScriptResult"] + ) + + validate_events_chain([e.name for e in event], _events_chain) + + assert event.count("SpentAmountChanged") == 1 + assert event["SpentAmountChanged"]["_newSpentAmount"] == new_spent_amount diff --git a/utils/test/event_validators/node_operators_registry.py b/utils/test/event_validators/node_operators_registry.py index 9dfcdbce..43a4c3be 100644 --- a/utils/test/event_validators/node_operators_registry.py +++ b/utils/test/event_validators/node_operators_registry.py @@ -72,7 +72,7 @@ def validate_node_operator_name_set_event( def validate_node_operator_reward_address_set_event( event: EventDict, node_operator_reward_address_item: NodeOperatorRewardAddressSetItem ): - _events_chain = ["LogScriptCall", "KeysOpIndexSet", "NodeOperatorRewardAddressSet"] + _events_chain = ["LogScriptCall", "LogScriptCall", "NodeOperatorRewardAddressSet", "ScriptResult"] validate_events_chain([e.name for e in event], _events_chain)