Skip to content

Commit

Permalink
Environment variables setup (#27)
Browse files Browse the repository at this point in the history
This changes the requirement from having to fetch secret keys from a
user-created `config.py` file, to fetching them from a .env file.
Keys in use are: `DUNE_KEY`, `ETHERSCAN_KEY`, `INFURA_KEY`
  • Loading branch information
shubhagarwal03 committed Apr 21, 2023
1 parent 2a594e3 commit d7841d6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 44 deletions.
6 changes: 5 additions & 1 deletion src/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@
the new end block. Daemon sleeps for 30 mins and continue checking.
"""
import time
import os
from typing import List, Optional
from dotenv import load_dotenv
from web3 import Web3
from config import INFURA_KEY
from src.off_chain.cow_endpoint_surplus import EBBOAnalysis
from src.off_chain.configuration import get_logger

load_dotenv()
INFURA_KEY = os.getenv("INFURA_KEY")


class DaemonEBBO:
"""
Expand Down
42 changes: 23 additions & 19 deletions src/off_chain/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
This file contains functions used by cow_endpoint_surplus.
"""
import logging
import os
from typing import Dict, List, Optional
from config import DUNE_KEY
from dotenv import load_dotenv
from dune_client.client import DuneClient
from dune_client.query import Query

load_dotenv()
DUNE_KEY = os.getenv("DUNE_KEY")


def get_solver_dict() -> Dict[str, List[int]]:
"""
Expand All @@ -17,25 +21,25 @@ def get_solver_dict() -> Dict[str, List[int]]:
name="Solver Dictionary",
query_id=1372857,
)
if DUNE_KEY is not None:
dune = DuneClient(DUNE_KEY)
results = dune.refresh(query)
solvers = results.get_rows()
for solver in solvers:
solver_dict[solver["name"]] = [0, 0]

# These names need to be updated since Dune and Orderbook Endpoint have different names.
# Example, "1Inch: [0, 0]" is a specific row, the first value is the number of solutions
# won, second value is number of solutions of that solver with higher surplus found.

dune = DuneClient(DUNE_KEY)
results = dune.refresh(query)
solvers = results.get_rows()
for solver in solvers:
solver_dict[solver["name"]] = [0, 0]

# These names need to be updated since Dune and Orderbook Endpoint have different names.
# Example, "1Inch: [0, 0]" is a specific row, the first value is the number of solutions
# won, second value is number of solutions of that solver with higher surplus found.

solver_dict["BaselineSolver"] = solver_dict.pop("Baseline")
solver_dict["1Inch"] = solver_dict.pop("Gnosis_1inch")
solver_dict["0x"] = solver_dict.pop("Gnosis_0x")
solver_dict["BalancerSOR"] = solver_dict.pop("Gnosis_BalancerSOR")
solver_dict["ParaSwap"] = solver_dict.pop("Gnosis_ParaSwap")
solver_dict["SeaSolver"] = solver_dict.pop("Seasolver")
solver_dict["CowDexAg"] = solver_dict.pop("DexCowAgg")
solver_dict["NaiveSolver"] = solver_dict.pop("Naive")
solver_dict["BaselineSolver"] = solver_dict.pop("Baseline")
solver_dict["1Inch"] = solver_dict.pop("Gnosis_1inch")
solver_dict["0x"] = solver_dict.pop("Gnosis_0x")
solver_dict["BalancerSOR"] = solver_dict.pop("Gnosis_BalancerSOR")
solver_dict["ParaSwap"] = solver_dict.pop("Gnosis_ParaSwap")
solver_dict["SeaSolver"] = solver_dict.pop("Seasolver")
solver_dict["CowDexAg"] = solver_dict.pop("DexCowAgg")
solver_dict["NaiveSolver"] = solver_dict.pop("Naive")

return solver_dict

Expand Down
6 changes: 5 additions & 1 deletion src/off_chain/cow_endpoint_surplus.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
Uses CoW Endpoint provided callData.
"""
import json
import os
from fractions import Fraction
from typing import List, Dict, Tuple, Any, Optional
from dotenv import load_dotenv
import requests
from config import ETHERSCAN_KEY
from src.off_chain.configuration import get_solver_dict, header, get_logger

load_dotenv()
ETHERSCAN_KEY = os.getenv("ETHERSCAN_KEY")


class EBBOAnalysis:
"""
Expand Down
23 changes: 0 additions & 23 deletions tests/unit/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,29 +64,6 @@ def test_surplus_difference(self) -> None:
) = get_surplus_difference(self.order_data, self.clearingPrices, self.order)
self.assertEqual(self.diff_surplus, -123572507, "Not equivalent!")

# def onchain_test_hash_input(self) -> None:
# """
# Test that function works with a hash
# """
# self.hash = "0xa5ee470bd261ba2d17394718e6c42b8230eea8d6f444f5ee609621936fe10bd5"
# self.file_name = str(self.hash)
# instance = EBBOAnalysis(self.file_name)
# self.assertIsNone(instance.get_surplus_by_input(settlement_hash=self.hash))

# def onchain_test_block_range_input(self) -> None:
# """
# Test that function works with a start and end block input
# """
# self.start_block = 16991373
# self.end_block = 16992833
# self.file_name = str(self.start_block) + "_surplusTo_" + str(self.end_block)
# instance = EBBOAnalysis(self.file_name)
# self.assertIsNone(
# instance.get_surplus_by_input(
# start_block=self.start_block, end_block=self.end_block
# )
# )


if __name__ == "__main__":
unittest.main()

0 comments on commit d7841d6

Please sign in to comment.