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

simulate actions of vote.py in review_votes.py #1531

Merged
merged 9 commits into from
Dec 5, 2024
23 changes: 22 additions & 1 deletion tools/python/aura_snapshot_voting/review_votes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
from pathlib import Path
from bal_addresses.utils import to_checksum_address
import requests
from vote import (
prepare_vote_data,
create_vote_payload,
hash_eip712_message,
_get_prop_and_determine_date_range,
)


def find_project_root(current_path=None):
Expand Down Expand Up @@ -55,6 +61,19 @@ def review_votes(week_string):
total_allocation = vote_df["Allocation %"].str.rstrip("%").astype(float).sum()
allocation_check = abs(total_allocation - 100) < 0.0001

try:
prop, _, _ = _get_prop_and_determine_date_range()
vote_df, vote_choices = prepare_vote_data(vote_df, prop)
data = create_vote_payload(vote_choices, prop)
hash = hash_eip712_message(data)
vote_prep = f"\n### Vote Preparation\nSuccessfully simulated vote preparation ✅\nMessage hash: `0x{hash.hex()}`"
vote_check = True
except Exception as e:
vote_prep = (
f"\n### Vote Preparation\n❌ Error simulating vote preparation: {str(e)}"
)
vote_check = False

report = f"""## vLAURA Votes Review

CSV file: `{os.path.relpath(csv_file, project_root)}`
Expand All @@ -68,11 +87,13 @@ def review_votes(week_string):
{f"- Missing labels for {len(missing_labels)} gauge(s):" if not snapshot_label_check else ""}
{missing_labels[["Chain", "Label", "Gauge Address"]].to_string(index=False) if not snapshot_label_check else ""}

{vote_prep}

### Vote Summary

{vote_df[["Chain", "Label", "Gauge Address", "Allocation %"]].to_markdown(index=False)}

{"### ✅ All checks passed" if (allocation_check and snapshot_label_check) else "### ❌ Some checks failed"}
{"### ✅ All checks passed!" if (allocation_check and snapshot_label_check and vote_check) else "### ❌ Some checks failed - please review the issues above"}
"""

with open("review_output.md", "w") as f:
Expand Down
54 changes: 34 additions & 20 deletions tools/python/aura_snapshot_voting/vote.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,26 +116,8 @@ def create_voting_dirs_for_year(base_path, year, week):
f.write("")


if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Vote processing script")
parser.add_argument(
"--week-string",
type=str,
help="Date that votes are are being posted. should be YYYY-W##",
)
year, week = parser.parse_args().week_string.split("-")

project_root = find_project_root()
base_path = project_root / "MaxiOps/vlaura_voting"
voting_dir = base_path / str(year) / str(week)
input_dir = voting_dir / "input"
output_dir = voting_dir / "output"

create_voting_dirs_for_year(base_path, year, week)

vote_df = pd.read_csv(glob.glob(f"{input_dir}/*.csv")[0])

prop, _, _ = _get_prop_and_determine_date_range()
def prepare_vote_data(vote_df, prop):
"""Prepares and validates vote data, returning the structured payload"""
choices = prop["choices"]
gauge_labels = fetch_json_from_url(GAUGE_MAPPING_URL)
gauge_labels = {to_checksum_address(x["address"]): x["label"] for x in gauge_labels}
Expand All @@ -156,6 +138,12 @@ def create_voting_dirs_for_year(base_path, year, week):

vote_choices = dict(zip(vote_df["snapshot_index"], vote_df["share"]))

return vote_df, vote_choices


def create_vote_payload(vote_choices, prop):
"""Creates the EIP712 structured data payload"""
project_root = find_project_root()
template_path = project_root / "tools/python/aura_snapshot_voting"
with open(f"{template_path}/eip712_template.json", "r") as f:
data = json.load(f)
Expand All @@ -165,6 +153,32 @@ def create_voting_dirs_for_year(base_path, year, week):
data["message"]["proposal"] = bytes.fromhex(prop["id"][2:])
data["message"]["choice"] = format_choices(vote_choices)

return data


if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Vote processing script")
parser.add_argument(
"--week-string",
type=str,
help="Date that votes are are being posted. should be YYYY-W##",
)
year, week = parser.parse_args().week_string.split("-")

project_root = find_project_root()
base_path = project_root / "MaxiOps/vlaura_voting"
voting_dir = base_path / str(year) / str(week)
input_dir = voting_dir / "input"
output_dir = voting_dir / "output"

create_voting_dirs_for_year(base_path, year, week)

vote_df = pd.read_csv(glob.glob(f"{input_dir}/*.csv")[0])

prop, _, _ = _get_prop_and_determine_date_range()

vote_df, vote_choices = prepare_vote_data(vote_df, prop)
data = create_vote_payload(vote_choices, prop)
hash = hash_eip712_message(data)

print(f"voting for: \n{vote_df[['Chain', 'snapshot_label', 'share']]}")
Expand Down