Skip to content

Commit

Permalink
Refactor deposit data generation (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsudmi authored Dec 19, 2021
1 parent 0d10b80 commit ed2b01a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 41 deletions.
37 changes: 8 additions & 29 deletions operator_cli/commands/generate_proposal.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

from operator_cli.eth1 import check_operator_exists
from operator_cli.eth2 import (
FINALIZE_DEPOSIT_AMOUNT,
INITIALIZE_DEPOSIT_AMOUNT,
LANGUAGES,
VALIDATOR_DEPOSIT_AMOUNT,
create_new_mnemonic,
generate_merkle_deposit_datum,
generate_unused_validator_keys,
Expand Down Expand Up @@ -92,27 +91,17 @@ def generate_proposal(chain: str, existing_vault: bool) -> None:

# 2. Generate and save deposit data
chain_setting = get_chain_setting(chain)
(
initialize_merkle_root,
initialize_merkle_deposit_datum,
) = generate_merkle_deposit_datum(
(deposit_data_merkle_root, deposit_data,) = generate_merkle_deposit_datum(
chain_setting=chain_setting,
deposit_amount=INITIALIZE_DEPOSIT_AMOUNT,
loading_label="Creating initialize deposit data:\t\t",
validator_keypairs=keypairs,
)
finalize_merkle_root, finalize_merkle_deposit_datum = generate_merkle_deposit_datum(
chain_setting=chain_setting,
deposit_amount=FINALIZE_DEPOSIT_AMOUNT,
loading_label="Creating finalize deposit data:\t\t",
deposit_amount=VALIDATOR_DEPOSIT_AMOUNT,
loading_label="Creating deposit data:\t\t",
validator_keypairs=keypairs,
)

# TODO: Generate and save exit signatures

# 3. Upload deposit data to IPFS
initialize_ipfs_url = upload_deposit_datum(initialize_merkle_deposit_datum)
finalize_ipfs_url = upload_deposit_datum(finalize_merkle_deposit_datum)
ipfs_url = upload_deposit_datum(deposit_data)
click.clear()

# 4. Generate proposal specification part
Expand All @@ -127,10 +116,8 @@ def generate_proposal(chain: str, existing_vault: bool) -> None:
- DAO calls `addOperator` function of `PoolValidators` contract with the following parameters:
* operator: `{operator}`
* initializeMerkleRoot: `{initialize_merkle_root}`
* initializeMerkleProofs: `{initialize_ipfs_url}`
* finalizeMerkleRoot: `{finalize_merkle_root}`
* finalizeMerkleProofs: `{finalize_ipfs_url}`
* depositDataMerkleRoot: `{deposit_data_merkle_root}`
* depositDataMerkleProofs: `{ipfs_url}`
"""

stakewise_gql_client = get_stakewise_gql_client(chain)
Expand All @@ -149,15 +136,7 @@ def generate_proposal(chain: str, existing_vault: bool) -> None:
* revenueShare: `{share_percentage}`
"""

specification += """
- If the proposal will be approved, the operator must perform the following steps:
* Call `operator-cli sync-vault` with the same mnemonic as used for the proposal
* Create or update validators and make sure the new keys are added
* Call `commitOperator` from the `{operator}` address together with 1 ETH collateral
"""
else:
specification += f"""
specification += f"""
- If the proposal will be approved, the operator must perform the following steps:
* Call `operator-cli sync-vault` with the same mnemonic as used for generating the proposal
Expand Down
12 changes: 6 additions & 6 deletions operator_cli/eth1.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ def check_operator_exists(gql_client: GqlClient, operator: ChecksumAddress) -> b


@backoff.on_exception(backoff.expo, Exception, max_time=180)
def get_operators_init_merkle_proofs(
def get_operators_deposit_data_merkle_proofs(
gql_client: GqlClient,
) -> Dict[ChecksumAddress, str]:
"""Fetches initialize merkle proofs of the operators."""
"""Fetches deposit data merkle proofs of the operators."""
result: Dict = gql_client.execute(OPERATORS_QUERY)
operators = result["operators"]
init_merkle_proofs = {}
deposit_data_merkle_proofs = {}
for operator in operators:
proofs = operator["initializeMerkleProofs"]
proofs = operator["depositDataMerkleProofs"]
if proofs:
init_merkle_proofs[Web3.toChecksumAddress(operator["id"])] = proofs
deposit_data_merkle_proofs[Web3.toChecksumAddress(operator["id"])] = proofs

return init_merkle_proofs
return deposit_data_merkle_proofs


@backoff.on_exception(backoff.expo, Exception, max_time=180)
Expand Down
3 changes: 1 addition & 2 deletions operator_cli/eth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@
COIN_TYPE = "3600"

w3 = Web3()
INITIALIZE_DEPOSIT_AMOUNT: Wei = w3.toWei(1, "ether")
FINALIZE_DEPOSIT_AMOUNT: Wei = w3.toWei(31, "ether")
VALIDATOR_DEPOSIT_AMOUNT: Wei = w3.toWei(32, "ether")


class ValidatorStatus(Enum):
Expand Down
2 changes: 1 addition & 1 deletion operator_cli/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def get_stakewise_gql_client(chain: str) -> Client:
query getOperators {
operators {
id
initializeMerkleProofs
depositDataMerkleProofs
}
}
"""
Expand Down
8 changes: 5 additions & 3 deletions operator_cli/vault.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from web3.beacon import Beacon

from operator_cli.eth1 import (
get_operators_init_merkle_proofs,
get_operators_deposit_data_merkle_proofs,
get_validator_operator_address,
is_validator_registered,
)
Expand Down Expand Up @@ -120,10 +120,12 @@ def vault_current_state(self) -> VaultState:
@cached_property
def all_operators_deposit_data_public_keys(self) -> Dict[HexStr, ChecksumAddress]:
"""Fetches public keys and operators from deposit datum."""
init_merkle_proofs = get_operators_init_merkle_proofs(self.sw_gql_client)
deposit_data_merkle_proofs = get_operators_deposit_data_merkle_proofs(
self.sw_gql_client
)
result: Dict[HexStr, ChecksumAddress] = {}
with click.progressbar(
init_merkle_proofs.items(),
deposit_data_merkle_proofs.items(),
label="Fetching deposit datum\t\t",
show_percent=False,
show_pos=True,
Expand Down

0 comments on commit ed2b01a

Please sign in to comment.