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

Add pip #438

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ env/

out/
venv/

build/
solver_rewards.egg-info/
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Fill out your Dune credentials in the `.env` file.
Generate the solver-payouts with for the accounting period 7 days with today as end date).

```shell
python -m src.fetch.transfer_file
python -m solver_rewards.fetch.transfer_file
```

For more advanced usage of this payout script see below.
Expand Down Expand Up @@ -72,7 +72,7 @@ However, many IDEs can be configured to auto format on save.
looking at the script help menu can help provide a list of options!

```shell
$ python -m src.fetch.transfer_file --help
$ python -m solver_rewards.fetch.transfer_file --help

usage: Fetch Complete Reimbursement [-h] [--start START] [--post-tx POST_TX] [--consolidate-transfers CONSOLIDATE_TRANSFERS] [--dry-run DRY_RUN]
[--min-transfer-amount-wei MIN_TRANSFER_AMOUNT_WEI] [--min-transfer-amount-cow-atoms MIN_TRANSFER_AMOUNT_COW_ATOMS]
Expand Down Expand Up @@ -102,7 +102,7 @@ To generate the CSV Transfer file manually run the "quickstart" variant of the s
A more fine-tuned variant of the script execution could look like this:

```shell
python -m src.fetch.transfer_file --start 2023-03-14 --post-tx True
python -m solver_rewards.fetch.transfer_file --start 2023-03-14 --post-tx True
```

which would run for the accounting period March 14 - 21, 2023, using the Post CIP-20 reward scheme and post the payout
Expand Down Expand Up @@ -144,7 +144,7 @@ docker run --pull=always -it --rm \
--env-file .env \
-v $PWD:/app/out \
ghcr.io/cowprotocol/solver-rewards:main \
src.fetch.transfer_file \
solver_rewards.fetch.transfer_file \
--start 'YYYY-MM-DD'
```

Expand Down
4 changes: 4 additions & 0 deletions manifest.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include logging.conf
include requirements.txt
include solver_rewards/sql/**/*.sql
include solver_rewards/abis/**/*.json
8 changes: 4 additions & 4 deletions requirements.in
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
certifi>=2022.6.15
duneapi>=8.0.0
dune-client>=1.1.1
psycopg2-binary>=2.9.6
dune-client==1.7.4
psycopg2-binary>=2.9.3
python-dotenv>=0.20.0
coinpaprika>=0.1.0
requests>=2.28.1
safe-eth-py>=5.5.0
slackclient>=2.9.4
web3<7.0.0
SQLAlchemy<2.0.0
SQLAlchemy>=2.0,<3.0
sqlalchemy-stubs>=0.4
pandas==2.0.3
pandas==2.1.4
pandas-stubs==2.0.2.230605
numpy==1.26.4
pip-tools==7.4.1
Expand Down
26 changes: 6 additions & 20 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#
# This file is autogenerated by pip-compile with Python 3.10
# This file is autogenerated by pip-compile with Python 3.12
# by the following command:
#
# pip-compile
# pip-compile requirements.in
#
aiohappyeyeballs==2.4.0
# via aiohttp
Expand All @@ -15,8 +15,6 @@ aiosignal==1.3.1
# via aiohttp
astroid==3.2.4
# via pylint
async-timeout==4.0.3
# via aiohttp
attrs==24.2.0
# via
# aiohttp
Expand Down Expand Up @@ -59,7 +57,7 @@ deprecated==1.2.14
# duneapi
dill==0.3.8
# via pylint
dune-client==1.7.5
dune-client==1.7.4
# via -r requirements.in
duneapi==8.0.0
# via -r requirements.in
Expand Down Expand Up @@ -106,8 +104,6 @@ eth-utils==4.1.1
# rlp
# trie
# web3
exceptiongroup==1.2.2
# via pytest
frozenlist==1.4.1
# via
# aiohttp
Expand Down Expand Up @@ -167,7 +163,7 @@ packaging==24.1
# marshmallow
# pytest
# safe-eth-py
pandas==2.0.3
pandas==2.1.4
# via -r requirements.in
pandas-stubs==2.0.2.230605
# via -r requirements.in
Expand Down Expand Up @@ -249,18 +245,10 @@ slackclient==2.9.4
# via -r requirements.in
sortedcontainers==2.4.0
# via trie
sqlalchemy==1.4.53
sqlalchemy==2.0.36
# via -r requirements.in
sqlalchemy-stubs==0.4
# via -r requirements.in
tomli==2.0.1
# via
# black
# build
# mypy
# pip-tools
# pylint
# pytest
tomlkit==0.13.2
# via pylint
toolz==0.12.1
Expand All @@ -285,11 +273,9 @@ types-setuptools==73.0.0.20240822
# via dune-client
typing-extensions==4.12.2
# via
# astroid
# black
# eth-rlp
# eth-typing
# mypy
# sqlalchemy
# sqlalchemy-stubs
# typing-inspect
# web3
Expand Down
61 changes: 61 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import os
from setuptools import setup, find_packages

subpackages = find_packages("solver_rewards")
packages = ["solver_rewards"] + ["solver_rewards." + p for p in subpackages]


def read_requirements(filename):
with open(filename, "r") as f:
return [line.strip() for line in f.readlines() if line.strip()]


def get_files(directory: str, extension: str):
found_files = []
for root, _, files in os.walk(directory):
for file in files:
if file.endswith(extension):
found_files.append(
os.path.join(
"solver_rewards", os.path.relpath(os.path.join(root, file), start="solver_rewards")
)
)
return found_files


setup(
name="solver_rewards",
version="1.6.4",
packages=packages,
package_dir={"solver_rewards": "solver_rewards"},
include_package_data=True,
data_files=[
(
os.path.join(
"lib", "python{0}.{1}".format(*os.sys.version_info[:2]), "site-packages"
),
["logging.conf"],
),
(
os.path.join(
"lib",
"python{0}.{1}".format(*os.sys.version_info[:2]),
"site-packages",
"solver_rewards",
"sql",
),
get_files("solver_rewards/sql", ".sql"),
),
(
os.path.join(
"lib",
"python{0}.{1}".format(*os.sys.version_info[:2]),
"site-packages",
"solver_rewards",
"abis",
),
get_files("solver_rewards/abis", ".json"),
),
],
install_requires=read_requirements("requirements.txt"),
)
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions src/abis/load.py → solver_rewards/abis/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
# TODO - following this issue: https://github.com/ethereum/web3.py/issues/3017
from web3.contract import Contract # type: ignore

from src.config import IOConfig
from src.logger import set_log
from solver_rewards.config import IOConfig
from solver_rewards.logger import set_log

ABI_PATH = IOConfig.from_env().project_root_dir / Path("src/abis")
ABI_PATH = IOConfig.from_env().project_root_dir / Path("solver_rewards/abis")

log = set_log(__name__)

Expand Down
File renamed without changes.
12 changes: 11 additions & 1 deletion src/config.py → solver_rewards/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def from_env() -> IOConfig:
project_root_dir = Path(__file__).parent.parent
file_out_dir = project_root_dir / Path("out")
log_config_file = project_root_dir / Path("logging.conf")
query_dir = project_root_dir / Path("queries")
query_dir = IOConfig._get_query_directory(project_root_dir)
dashboard_dir = project_root_dir / Path("dashboards/solver-rewards-accounting")

return IOConfig(
Expand All @@ -259,6 +259,16 @@ def from_env() -> IOConfig:
slack_token=slack_token,
)

@staticmethod
def _get_query_directory(project_root_dir: Path) -> Path:
"""Determine the path to the queries directory"""
local_query_dir = project_root_dir / "queries"

if local_query_dir.exists():
return local_query_dir
else:
return Path(os.getenv("PYTHON_PACKAGE_DIR", "solver_rewards/queries"))


@dataclass(frozen=True)
class AccountingConfig:
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions src/fetch/dune.py → solver_rewards/fetch/dune.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
from dune_client.query import QueryBase
from dune_client.types import QueryParameter, DuneRecord

from src.logger import set_log, log_saver
from src.models.accounting_period import AccountingPeriod
from src.queries import QUERIES, QueryData
from src.utils.print_store import Category
from solver_rewards.logger import set_log, log_saver
from solver_rewards.models.accounting_period import AccountingPeriod
from solver_rewards.queries import QUERIES, QueryData
from solver_rewards.utils.print_store import Category

log = set_log(__name__)

Expand Down
20 changes: 10 additions & 10 deletions src/fetch/payouts.py → solver_rewards/fetch/payouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
from dune_client.types import Address
from pandas import DataFrame, Series

from src.config import AccountingConfig
from src.fetch.dune import DuneFetcher
from src.fetch.prices import exchange_rate_atoms
from src.logger import log_saver, set_log
from src.models.accounting_period import AccountingPeriod
from src.models.overdraft import Overdraft
from src.models.token import Token
from src.models.transfer import Transfer
from src.pg_client import MultiInstanceDBFetcher
from src.utils.print_store import Category
from solver_rewards.config import AccountingConfig
from solver_rewards.fetch.dune import DuneFetcher
from solver_rewards.fetch.prices import exchange_rate_atoms
from solver_rewards.logger import log_saver, set_log
from solver_rewards.models.accounting_period import AccountingPeriod
from solver_rewards.models.overdraft import Overdraft
from solver_rewards.models.token import Token
from solver_rewards.models.transfer import Transfer
from solver_rewards.pg_client import MultiInstanceDBFetcher
from solver_rewards.utils.print_store import Category

log = set_log(__name__)

Expand Down
2 changes: 1 addition & 1 deletion src/fetch/prices.py → solver_rewards/fetch/prices.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from coinpaprika import client as cp
from dune_client.types import Address

from src.logger import set_log
from solver_rewards.logger import set_log

log = set_log(__name__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@
from gnosis.eth.ethereum_client import EthereumClient
from slack.web.client import WebClient

from src.config import AccountingConfig, Network
from src.fetch.dune import DuneFetcher
from src.fetch.payouts import construct_payouts
from src.logger import log_saver, set_log
from src.models.accounting_period import AccountingPeriod
from src.models.transfer import Transfer, CSVTransfer
from src.multisend import post_multisend, prepend_unwrap_if_necessary
from src.pg_client import MultiInstanceDBFetcher
from src.slack_utils import post_to_slack
from src.utils.print_store import Category, PrintStore
from src.utils.script_args import generic_script_init
from solver_rewards.config import AccountingConfig, Network
from solver_rewards.fetch.dune import DuneFetcher
from solver_rewards.fetch.payouts import construct_payouts
from solver_rewards.logger import log_saver, set_log
from solver_rewards.models.accounting_period import AccountingPeriod
from solver_rewards.models.transfer import Transfer, CSVTransfer
from solver_rewards.multisend import post_multisend, prepend_unwrap_if_necessary
from solver_rewards.pg_client import MultiInstanceDBFetcher
from solver_rewards.slack_utils import post_to_slack
from solver_rewards.utils.print_store import Category, PrintStore
from solver_rewards.utils.script_args import generic_script_init

log = set_log(__name__)

Expand All @@ -34,7 +34,7 @@ def manual_propose(
transfers: list[Transfer],
period: AccountingPeriod,
config: AccountingConfig,
) -> None:
) -> str:
"""
Entry point to manual creation of rewards payout transaction.
This function generates the CSV transfer file to be pasted into the COW Safe app
Expand All @@ -48,8 +48,10 @@ def manual_propose(
csv_transfers, f"transfers-{period}.csv"
)

print(Transfer.summarize(transfers))
summary = Transfer.summarize(transfers)
print(summary)
print("Please cross check these results with the dashboard linked above.\n")
return summary


def auto_propose(
Expand Down Expand Up @@ -110,7 +112,7 @@ def auto_propose(
)


def main() -> None:
def main() -> None | str:
"""Generate transfers for an accounting period"""

args = generic_script_init(description="Fetch Complete Reimbursement")
Expand Down Expand Up @@ -169,7 +171,8 @@ def main() -> None:
config=config,
)
else:
manual_propose(transfers=payout_transfers, period=dune.period, config=config)
summary = manual_propose(transfers=payout_transfers, period=dune.period, config=config)
return summary


if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions src/logger.py → solver_rewards/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import logging.config
from logging import Logger

from src.config import IOConfig
from src.utils.print_store import PrintStore
from solver_rewards.config import IOConfig
from solver_rewards.utils.print_store import PrintStore

io_config = IOConfig.from_env()

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from dune_client.types import Address

from src.models.accounting_period import AccountingPeriod
from solver_rewards.models.accounting_period import AccountingPeriod


@dataclass
Expand Down
Loading
Loading