-
Notifications
You must be signed in to change notification settings - Fork 1
Governance additions (vote via legacy delegation, vote via liquid staking) #4
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
Merged
Merged
Changes from 14 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
d6d07b3
Prepare scripts for governance call (work in progress).
andreibancioiu 996c21b
Micro-refactor.
andreibancioiu 5714f85
Sketch functions for voting via legacy delegation.
andreibancioiu ac6ceb3
Sketch script for voting via legacy delegation.
andreibancioiu 66c4483
Improve voting (on-chain). A bit more robust.
andreibancioiu f5b3901
Fix voting for direct staking.
andreibancioiu 4973bb5
Improve vote via legacy delegation.
andreibancioiu 9678f67
Display previous votes etc.
andreibancioiu 86378bc
Refactor, adjust getting previous votes.
andreibancioiu 65c75b1
More robust flow.
andreibancioiu 44c7c45
Get on-chain delegated votes, apply some checks when voting via legac…
andreibancioiu 6f5feac
Simple report on governance (voting).
andreibancioiu c34aaab
Adjust readme.
andreibancioiu 2ec932e
Rename files, cleanup etc.
andreibancioiu c3f68ba
Fix gas limit.
andreibancioiu 9942b53
Add proofs for governance, for liquid staking (delegating votes).
andreibancioiu 0d7bb39
Vote via liquid staking (work in progress).
andreibancioiu 6b528f2
Adjust report etc. Refactoring.
andreibancioiu b907494
Fix function name.
andreibancioiu 8e8d364
Update proofs for governance.
andreibancioiu cb556aa
Fix logic around getting past votes.
andreibancioiu 420e6f3
Fix decoding.
andreibancioiu f3c391d
Fix getting timestamp etc.
andreibancioiu a4b2a58
Fix after self-review (refactoring).
andreibancioiu 165442d
Update governance proofs (Hatom).
andreibancioiu f169fd2
Fix after review.
andreibancioiu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| requests>=2.32.0,<3.0.0 | ||
| ledgercomm[hid] | ||
| rich==13.3.4 | ||
| multiversx-sdk[ledger]==2.1.0 | ||
| multiversx-sdk[ledger]==2.3.2 | ||
| pyotp==2.9.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| import sys | ||
| import traceback | ||
| from argparse import ArgumentParser | ||
| from pathlib import Path | ||
| from typing import List | ||
|
|
||
| from multiversx_sdk import VoteType | ||
| from multiversx_sdk.gas_estimator.errors import GasLimitEstimationError | ||
| from multiversx_sdk.smart_contracts.errors import SmartContractQueryError | ||
| from rich import print | ||
|
|
||
| from wizard import errors, ux | ||
| from wizard.accounts import load_accounts | ||
| from wizard.configuration import CONFIGURATIONS | ||
| from wizard.constants import DEFAULT_GAS_PRICE | ||
| from wizard.entrypoint import MyEntrypoint | ||
| from wizard.guardians import AuthApp | ||
| from wizard.transactions import TransactionWrapper | ||
| from wizard.utils import format_time | ||
|
|
||
|
|
||
| def get_vote_type_from_args(choice: str) -> VoteType: | ||
| return { | ||
| "yes": VoteType.YES, | ||
| "no": VoteType.NO, | ||
| "abstain": VoteType.ABSTAIN, | ||
| "veto": VoteType.VETO | ||
| }[choice] | ||
|
|
||
|
|
||
| def main(cli_args: list[str] = sys.argv[1:]): | ||
| try: | ||
| _do_main(cli_args) | ||
| except errors.KnownError as err: | ||
| ux.show_critical_error(traceback.format_exc()) | ||
| ux.show_critical_error(err.get_pretty()) | ||
| return 1 | ||
|
|
||
|
|
||
| def _do_main(cli_args: List[str]): | ||
| parser = ArgumentParser() | ||
| parser.add_argument("--network", choices=CONFIGURATIONS.keys(), required=True, help="network name") | ||
| parser.add_argument("--wallets", required=True, help="path to wallets configuration file") | ||
| parser.add_argument("--auth", required=True, help="auth registration file") | ||
| parser.add_argument("--gas-price", type=int, default=DEFAULT_GAS_PRICE, help="min gas price") | ||
| parser.add_argument("--proposal", type=int, required=True, help="proposal nonce / id") | ||
| parser.add_argument("--vote", choices=["yes", "no", "abstain", "veto"], required=True, help="vote choice") | ||
|
|
||
| args = parser.parse_args(cli_args) | ||
|
|
||
| network = args.network | ||
| configuration = CONFIGURATIONS[network] | ||
| entrypoint = MyEntrypoint( | ||
| configuration=configuration, | ||
| use_gas_estimator=True, | ||
| gas_limit_multiplier=1.1, | ||
| ) | ||
|
|
||
| accounts_wrappers = load_accounts(Path(args.wallets)) | ||
| auth_app = AuthApp.new_from_registration_file(Path(args.auth)) if args.auth else AuthApp([]) | ||
|
|
||
| entrypoint.recall_nonces(accounts_wrappers) | ||
| entrypoint.recall_guardians(accounts_wrappers) | ||
|
|
||
| transactions_wrappers: List[TransactionWrapper] = [] | ||
|
|
||
| proposal = args.proposal | ||
| vote = get_vote_type_from_args(args.vote) | ||
| gas_price = args.gas_price | ||
|
|
||
| ux.confirm_continuation( | ||
| f"Submit bulk votes on proposal [green]{proposal}[/green] with choice [green]{vote.value.upper()}[/green]?" | ||
| ) | ||
|
|
||
| for account_wrapper in accounts_wrappers: | ||
| address = account_wrapper.account.address | ||
|
|
||
| print(f"[yellow]{account_wrapper.wallet_name}[/yellow]", address.to_bech32()) | ||
|
|
||
| try: | ||
| voting_power = entrypoint.get_voting_power_on_onchain_governance(address) | ||
| if not voting_power: | ||
| print(f"\t[red]has no voting power[/red]") | ||
| continue | ||
|
|
||
| print(f"\t[blue]has voting power[/blue]", voting_power) | ||
|
|
||
| previous_votes = entrypoint.get_onchain_direct_votes(address, proposal) | ||
|
|
||
| for previous_vote in previous_votes: | ||
| print(f"\tprevious vote at {format_time(previous_vote.timestamp)}:", previous_vote.vote_type) | ||
|
|
||
| tx = entrypoint.vote_on_onchain_governance( | ||
| sender=account_wrapper, | ||
| proposal=proposal, | ||
| vote=vote, | ||
| gas_price=gas_price, | ||
| ) | ||
|
|
||
| transactions_wrappers.append(TransactionWrapper(tx, account_wrapper.wallet_name)) | ||
| except SmartContractQueryError as error: | ||
| print(f"\t[red]{error}[/red]") | ||
| except GasLimitEstimationError as error: | ||
| print(f"\t[red]{error.error}[/red]") | ||
|
|
||
| ux.confirm_continuation(f"Ready to send [green]{len(transactions_wrappers)}[/green] transaction(s)?") | ||
| entrypoint.send_multiple(auth_app, transactions_wrappers) | ||
| return 0 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| sys.exit(main(sys.argv[1:])) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If voted previously, should be skipped. The transaction is going to fail on a second vote on the same proposal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.