Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/alliance #252

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions scripts/vote_2024_10_01_holesky.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
"""
Voting 01/10/2024!
Add ET setup for Alliance in stETH
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why in stETH?

!! Holesky only
"""

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.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
)

description = """
1. **Add Alliance Ops stablecoins top up EVM script factory, as decided in the [Snapshot vote](https://snapshot.org/#/lido-snapshot.eth/proposal/0xa478fa5518769096eda2b7403a1d4104ca47de3102e8a9abab8640ef1b50650c).

"""

def start_vote(tx_params: Dict[str, str], silent: bool) -> bool | list[int | TransactionReceipt | None]:
"""Prepare and run voting."""

alliance_ops_topup_factory = interface.TopUpAllowedRecipients("0x343fa5f0c79277e2d27e440f40420d619f962a23")
alliance_ops_registry = interface.AllowedRecipientRegistry("0xe1ba8dee84a4df8e99e495419365d979cdb19991")

vote_desc_items, call_script_items = zip(
#
# I. Add Alliance Ops stablecoins top up EVM script factory
#
(
"1) Add Alliance Ops stablecoins top up EVM script factory 0x343fa5f0c79277e2d27e440f40420d619f962a23",
add_evmscript_factory(
factory=alliance_ops_topup_factory,
permissions=create_permissions(contracts.finance, "newImmediatePayment")
+ create_permissions(alliance_ops_registry, "updateSpentAmount")[2:],
),
),
)

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.

226 changes: 226 additions & 0 deletions tests/test_2024_10_01_holesky.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
"""
Tests for voting 01/10/2024
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

08/10


"""

from scripts.vote_2024_10_01_holesky import start_vote
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10_08

from brownie import interface, ZERO_ADDRESS, reverts, web3, accounts, convert
from utils.test.tx_tracing_helpers import *
from utils.voting import find_metadata_by_vote_id
from utils.ipfs import get_lido_vote_cid_from_str
from utils.config import contracts, LDO_HOLDER_ADDRESS_FOR_TESTS, network_name
from utils.easy_track import create_permissions
from configs.config_mainnet import (
DAI_TOKEN,
USDC_TOKEN,
USDT_TOKEN,
)
from utils.test.easy_track_helpers import create_and_enact_payment_motion, check_add_and_remove_recipient_with_voting
from utils.test.event_validators.easy_track import (
validate_evmscript_factory_added_event,
EVMScriptFactoryAdded,
validate_evmscript_factory_removed_event,
)
_
# STETH_TRANSFER_MAX_DELTA = 2

def test_vote(helpers, accounts, vote_ids_from_env, stranger, ldo_holder, bypass_events_decoding):
steth = contracts.lido
easy_track = contracts.easy_track
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's better to use addresses in tests than to use contracts


evm_script_factories_before = easy_track.getEVMScriptFactories()

alliance_ops_top_up_evm_script_factory_new = "0x343fa5f0c79277e2d27e440f40420d619f962a23" # TopUpAllowedRecipients
assert alliance_ops_top_up_evm_script_factory_new not in evm_script_factories_before

alliance_multisig_acc = accounts.at("xd4090CA1134F8dE1450B8246916F73d212efdEf6", force=True) # Testnet DAO Multisigs
alliance_dai_usdc_contract = accounts.at("0x2eb8e9198e647f80ccf62a5e291bcd4a5a3ca68c", force=True) # Testnet Stablecoins
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's rudiments from the previous launch connected with swaps.
We can't use these addresses here. you have to use alliance_multisig_acc as a receiver

alliance_usdc_dai_contract = accounts.at("0x9715b2786f1053294fc8952df923b95cab9aac42", force=True)
alliance_usdt_dai_contract = accounts.at("0x86f6c353a0965eb069cd7f4f91c1afef8c725551", force=True)

# 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}")

evm_script_factories_after = easy_track.getEVMScriptFactories()

# 1. Add TMC stETH top up EVM script factory address TBA (AllowedRecipientsRegistry address TBA)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

steth ;)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and also please replace all TBA with addresses

assert alliance_ops_top_up_evm_script_factory_new in evm_script_factories_after

'''
create_and_enact_payment_motion(
easy_track,
trusted_caller=alliance_multisig_acc,
factory=alliance_ops_top_up_evm_script_factory_new,
token=steth,
recievers=[alliance_steth_contract],
transfer_amounts=[10 * 10**18],
stranger=stranger,
)
'''

'''
tmc_steth_allowed_recipients_registry = interface.AllowedRecipientRegistry(
"0x1a7cFA9EFB4D5BfFDE87B0FaEb1fC65d653868C0"
)
check_add_and_remove_recipient_with_voting(
registry=tmc_steth_allowed_recipients_registry,
helpers=helpers,
ldo_holder=ldo_holder,
dao_voting=contracts.voting,
)
'''
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please, remove all commented sections



dai_transfer_amount = 1_000 * 10**18
'''
prepare_agent_for_steth_payment(4 * dai_transfer_amount)
'''

usdc_transfer_amount = 1_000 * 10**6
'''
prepare_agent_for_usdc_payment(4 * usdc_transfer_amount)
'''

usdt_transfer_amount = 1_000 * 10**6
'''
prepare_agent_for_usdt_payment(4 * usdt_transfer_amount)
'''

# 2. Add TMC stables top up EVM script factory address TBA (AllowedRecipientsRegistry address TBA, AllowedTokensRegistry address TBA)
assert alliance_ops_top_up_evm_script_factory_new in evm_script_factories_after
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we really need to check it twice?


create_and_enact_payment_motion(
easy_track,
trusted_caller=alliance_multisig_acc,
factory=alliance_ops_top_up_evm_script_factory_new,
token=interface.Dai(DAI_TOKEN),
recievers=[alliance_dai_usdc_contract],
transfer_amounts=[dai_transfer_amount],
stranger=stranger,
)

create_and_enact_payment_motion(
easy_track,
trusted_caller=alliance_multisig_acc,
factory=alliance_ops_top_up_evm_script_factory_new,
token=interface.Usdc(USDC_TOKEN),
recievers=[alliance_usdc_dai_contract],
transfer_amounts=[usdc_transfer_amount],
stranger=stranger,
)

create_and_enact_payment_motion(
easy_track,
trusted_caller=alliance_multisig_acc,
factory=alliance_ops_top_up_evm_script_factory_new,
token=interface.Usdt(USDT_TOKEN),
recievers=[alliance_usdt_dai_contract],
transfer_amounts=[usdt_transfer_amount],
stranger=stranger,
)

with reverts("TOKEN_NOT_ALLOWED"):
create_and_enact_payment_motion(
easy_track,
trusted_caller=alliance_multisig_acc,
factory=alliance_ops_top_up_evm_script_factory_new,
token=steth,
recievers=[alliance_dai_usdc_contract],
transfer_amounts=[1],
stranger=stranger,
)


alliance_ops_allowed_recipients_registry = interface.AllowedRecipientRegistry(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's better to declare variables in the beginning of tests

"0xe1ba8dee84a4df8e99e495419365d979cdb19991"
)

check_add_and_remove_recipient_with_voting(
registry=alliance_ops_allowed_recipients_registry,
helpers=helpers,
ldo_holder=ldo_holder,
dao_voting=contracts.voting,
)

# validate vote events
assert count_vote_items_by_events(vote_tx, contracts.voting) == 1, "Incorrect voting items count"

metadata = find_metadata_by_vote_id(vote_id)

assert get_lido_vote_cid_from_str(metadata) == "bafkreibbrlprupitulahcrl57uda4nkzrbfajtrhhsaa3cbx5of4t2huoa" # todo: поменять адрес после тестовой публикации голоосвания на форке

display_voting_events(vote_tx)
'''
if bypass_events_decoding or network_name() in ("goerli", "goerli-fork"):
return
'''

evs = group_voting_events(vote_tx)

'''
validate_evmscript_factory_added_event(
evs[0],
EVMScriptFactoryAdded(
factory_addr=alliance_ops_top_up_evm_script_factory_new,
permissions=create_permissions(contracts.finance, "newImmediatePayment")
+ create_permissions(alliance_ops_allowed_recipients_registry, "updateSpentAmount")[2:],
),
)
'''
validate_evmscript_factory_added_event(
evs[0],
EVMScriptFactoryAdded(
factory_addr=alliance_ops_top_up_evm_script_factory_new,
permissions=create_permissions(contracts.finance, "newImmediatePayment")
+ create_permissions(alliance_ops_allowed_recipients_registry, "updateSpentAmount")[2:],
),
)

'''
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_dai_payment(amount: int):
agent, dai = contracts.agent, interface.Dai(DAI_TOKEN)
if dai.balanceOf(agent) < amount:
dai_ward_impersonated = accounts.at("0x9759A6Ac90977b93B58547b4A71c78317f391A28", force=True)
dai.mint(agent, amount, {"from": dai_ward_impersonated})

assert dai.balanceOf(agent) >= amount, f"Insufficient DAI 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")
usdc_master_minter.incrementMinterAllowance(amount, {"from": usdc_controller})
usdc.mint(agent, amount, {"from": usdc_minter})

assert usdc.balanceOf(agent) >= amount, "Insufficient USDC balance"


def prepare_agent_for_usdt_payment(amount: int):
agent, usdt = contracts.agent, interface.Usdt(USDT_TOKEN)
if usdt.balanceOf(agent) < amount:
usdt_owner = accounts.at("0xC6CDE7C39eB2f0F0095F41570af89eFC2C1Ea828", force=True)
usdt.issue(amount, {"from": usdt_owner})
usdt.transfer(agent, amount, {"from": usdt_owner})

assert usdt.balanceOf(agent) >= amount, "Insufficient USDT balance"
'''
Loading