From 34a9a3d4c837375e8fbd6dbbc66e17423c39a69b Mon Sep 17 00:00:00 2001 From: Felix Henneke Date: Thu, 7 Nov 2024 11:43:43 +0100 Subject: [PATCH] [Easy] Small rework of transfer_file initialization (#415) This PR changes the initialization step in the transfer_file script. It does not change the behavior of the code. The main change is to move the initialization of the dune fetcher into the main script and out of the parsing of arguments. This will make it easier to later explicitly pass config into initialization steps. It is also easier for me to understand, what individual steps in the script do. This change required adding a start argument to `ScriptArgs`. I also reordered the script a bit and to make it easier to consistently pass config objects as last argument of function calls. --- src/fetch/payouts.py | 2 +- src/fetch/transfer_file.py | 21 +++++++++++++++------ src/utils/script_args.py | 13 ++----------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/fetch/payouts.py b/src/fetch/payouts.py index 7cfd0276..6586f267 100644 --- a/src/fetch/payouts.py +++ b/src/fetch/payouts.py @@ -461,7 +461,7 @@ def construct_partner_fee_payments( def construct_payouts( - dune: DuneFetcher, ignore_slippage_flag: bool, orderbook: MultiInstanceDBFetcher + orderbook: MultiInstanceDBFetcher, dune: DuneFetcher, ignore_slippage_flag: bool ) -> list[Transfer]: """Workflow of solver reward payout logic post-CIP27""" # pylint: disable-msg=too-many-locals diff --git a/src/fetch/transfer_file.py b/src/fetch/transfer_file.py index 96aaf0c6..2a336d25 100644 --- a/src/fetch/transfer_file.py +++ b/src/fetch/transfer_file.py @@ -9,6 +9,7 @@ from dataclasses import asdict import certifi +from dune_client.client import DuneClient from dune_client.file.interface import FileIO from eth_typing import URI from gnosis.eth.ethereum_client import EthereumClient @@ -23,6 +24,7 @@ FILE_OUT_DIR, DOCS_URL, ) +from src.fetch.dune import DuneFetcher from src.fetch.payouts import construct_payouts from src.models.accounting_period import AccountingPeriod from src.models.transfer import Transfer, CSVTransfer @@ -103,19 +105,26 @@ def auto_propose( if __name__ == "__main__": args = generic_script_init(description="Fetch Complete Reimbursement") - dune = args.dune + + orderbook = MultiInstanceDBFetcher( + [os.environ["PROD_DB_URL"], os.environ["BARN_DB_URL"]] + ) + dune = DuneFetcher( + dune=DuneClient(os.environ["DUNE_API_KEY"]), + period=AccountingPeriod(args.start), + ) + dune.log_saver.print( f"The data aggregated can be visualized at\n{dune.period.dashboard_url()}", category=Category.GENERAL, ) payout_transfers_temp = construct_payouts( - args.dune, - args.ignore_slippage, - orderbook=MultiInstanceDBFetcher( - [os.environ["PROD_DB_URL"], os.environ["BARN_DB_URL"]] - ), + orderbook=orderbook, + dune=dune, + ignore_slippage_flag=args.ignore_slippage, ) + payout_transfers = [] for tr in payout_transfers_temp: if tr.token is None: diff --git a/src/utils/script_args.py b/src/utils/script_args.py index a00933af..7791a09a 100644 --- a/src/utils/script_args.py +++ b/src/utils/script_args.py @@ -1,21 +1,15 @@ """Common method for initializing setup for scripts""" import argparse -import os from datetime import date, timedelta from dataclasses import dataclass -from dune_client.client import DuneClient - -from src.fetch.dune import DuneFetcher -from src.models.accounting_period import AccountingPeriod - @dataclass class ScriptArgs: """A collection of common script arguments relevant to this project""" - dune: DuneFetcher + start: str post_tx: bool dry_run: bool min_transfer_amount_wei: int @@ -71,10 +65,7 @@ def generic_script_init(description: str) -> ScriptArgs: ) args = parser.parse_args() return ScriptArgs( - dune=DuneFetcher( - dune=DuneClient(os.environ["DUNE_API_KEY"]), - period=AccountingPeriod(args.start), - ), + start=args.start, post_tx=args.post_tx, dry_run=args.dry_run, min_transfer_amount_wei=args.min_transfer_amount_wei,