Skip to content

Commit

Permalink
use ETH_RPC
Browse files Browse the repository at this point in the history
  • Loading branch information
bh2smith committed Apr 21, 2024
1 parent ed54697 commit baeb14b
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ DUNE_USER=
DUNE_PASSWORD=
DUNE_QUERY_ID=

GNOSIS_RPC=
ETH_RPC=

# Official Dune API
DUNE_API_KEY=

Expand Down
4 changes: 4 additions & 0 deletions src/constants.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from pathlib import Path


Expand All @@ -17,3 +18,6 @@
"type": "function",
}
]

ETH_RPC = os.environ.get("ETH_RPC", "https://rpc.ankr.com/eth")
GNOSIS_RPC = os.environ.get("ETH_RPC", "https://rpc.gnosischain.com")
3 changes: 2 additions & 1 deletion src/gas_saved.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from web3 import Web3
from web3.types import TxReceipt

from src.constants import ETH_RPC
from src.db.pg_client import pg_engine


Expand Down Expand Up @@ -34,7 +35,7 @@ def main(batch_tx_hash: str) -> int:
# Ref: https://github.com/cowprotocol/services/blob/fd5f7cf47a6afdff89b310b60b869dfc577ac7a7/crates/shared/src/price_estimation/gas.rs#L37
df_quotes["gas_amount"] = df_quotes["gas_amount"].apply(lambda x: x - 106391)
load_dotenv()
w3 = Web3(Web3.HTTPProvider("https://rpc.ankr.com/eth"))
w3 = Web3(Web3.HTTPProvider(ETH_RPC))
tx: TxReceipt = w3.eth.get_transaction_receipt(HexStr(batch_tx_hash))
gas_used = tx["gasUsed"]
print(
Expand Down
6 changes: 4 additions & 2 deletions src/missing_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

from web3 import Web3

from src.constants import ETH_RPC, GNOSIS_RPC


class Network(Enum):
"""
Expand All @@ -28,8 +30,8 @@ def as_dune_v2_repr(self) -> str:
def node_url(self) -> str:
"""Returns URL to Node for Network"""
return {
Network.MAINNET: "https://rpc.ankr.com/eth",
Network.GNOSIS: "https://rpc.gnosischain.com",
Network.MAINNET: ETH_RPC,
Network.GNOSIS: GNOSIS_RPC,
}[self]

@property
Expand Down
4 changes: 2 additions & 2 deletions src/subgraph/ens_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from dotenv import load_dotenv
from web3 import Web3

from src.constants import PUBLIC_RESOLVER_ABI
from src.constants import PUBLIC_RESOLVER_ABI, ETH_RPC
from src.subgraph.fetch import execute_subgraph_query
from src.utils import partition_array

Expand All @@ -23,7 +23,7 @@
}

load_dotenv()
w3 = Web3(Web3.HTTPProvider("https://rpc.ankr.com/eth"))
w3 = Web3(Web3.HTTPProvider(ETH_RPC))


def read_ens_text(resolver: str, node: str, key: str) -> str:
Expand Down
3 changes: 0 additions & 3 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ def test_network_class(self):
self.assertEqual(gnosis.chain_id, 100)
self.assertEqual(mainnet.chain_id, 1)

self.assertEqual(gnosis.node_url(), "https://rpc.gnosischain.com")
self.assertEqual(mainnet.node_url(), "https://rpc.ankr.com/eth")

self.assertEqual(gnosis.as_dune_v2_repr(), "gnosis")
self.assertEqual(mainnet.as_dune_v2_repr(), "ethereum")

Expand Down

0 comments on commit baeb14b

Please sign in to comment.