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

Serve Solver List I: Fetch & Store #15

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion dune_api_scripts/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
requests>=2.27.1
pylint==2.11.1
pytest==6.2.5
duneapi==3.0.3
duneapi==3.0.7
python-dotenv==0.20.0

62 changes: 62 additions & 0 deletions dune_api_scripts/store/solver_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"""Modifies and executed dune query for today's data"""
from __future__ import annotations

import dataclasses
import json
import os
from dataclasses import dataclass
bh2smith marked this conversation as resolved.
Show resolved Hide resolved
from typing import Any

from duneapi.api import DuneAPI
from duneapi.types import DuneQuery, Network
from duneapi.types import Address


class EnhancedJSONEncoder(json.JSONEncoder):
def default(self, o):
if dataclasses.is_dataclass(o):
return dataclasses.asdict(o)
return super().default(o)


@dataclass
class Solver:
address: str
environment: str
name: str
active: bool

@classmethod
def from_dict(cls, data: dict[str, Any]) -> Solver:
return cls(
address=Address(data["address"]).address,
environment=data["environment"],
name=data["name"],
active=data["active"],
)


def store_solver_list(dune: DuneAPI) -> list[Solver]:
# TODO - fetch for both networks and merge JSON content with chainID
# Waiting on https://github.com/duneanalytics/abstractions/pull/1268
raw_solver_list = dune.fetch(
DuneQuery.from_environment(
name="Solver List",
description="",
raw_sql="select * from gnosis_protocol_v2.view_solvers",
network=Network.MAINNET,
parameters=[],
)
)
solver_list = [Solver.from_dict(rec) for rec in raw_solver_list]

filename = os.path.join(os.environ["DUNE_DATA_FOLDER"], "solvers.json")
with open(filename, "w+", encoding="utf-8") as f:
json.dump(solver_list, f, ensure_ascii=False, indent=4, cls=EnhancedJSONEncoder)
bh2smith marked this conversation as resolved.
Show resolved Hide resolved

return solver_list


if __name__ == "__main__":

store_solver_list(dune=DuneAPI.new_from_environment())