Skip to content

Commit

Permalink
Merge branch 'main' into issue/180
Browse files Browse the repository at this point in the history
  • Loading branch information
gosuto-inzasheru authored Mar 19, 2024
2 parents 389d983 + bea2990 commit 45f8621
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 11 deletions.
6 changes: 4 additions & 2 deletions bal_addresses/addresses.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from munch import Munch
from web3 import Web3

from .utils import to_checksum_address


GITHUB_MONOREPO_RAW = (
"https://raw.githubusercontent.com/balancer-labs/balancer-v2-monorepo/master"
Expand Down Expand Up @@ -318,7 +320,7 @@ def checksum_address_dict(addresses):
checksummed[k] = checksum_address_dict(v)
elif isinstance(v, str):
try:
checksummed[k] = Web3.toChecksumAddress(v)
checksummed[k] = to_checksum_address(v)
except:
checksummed[k] = v
else:
Expand Down Expand Up @@ -371,7 +373,7 @@ def checksum_address_dict(addresses):
checksummed[k] = checksum_address_dict(v)
elif isinstance(v, str):
try:
checksummed[k] = Web3.toChecksumAddress(v)
checksummed[k] = to_checksum_address(v)
except:
checksummed[k] = v
else:
Expand Down
9 changes: 4 additions & 5 deletions bal_addresses/pools_gauges.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from typing import Dict
import json
import requests
from web3 import Web3
from .utils import to_checksum_address

from bal_addresses.subgraph import Subgraph
from bal_addresses.errors import NoResultError
Expand Down Expand Up @@ -31,22 +30,22 @@ def get_bpt_balances(self, pool_id: str, block: int) -> Dict[str, int]:
results = {}
if "pool" in data and data["pool"]:
for share in data["pool"]["shares"]:
user_address = Web3.toChecksumAddress(share["userAddress"]["id"])
user_address = to_checksum_address(share["userAddress"]["id"])
results[user_address] = float(share["balance"])
return results

def get_gauge_deposit_shares(
self, gauge_address: str, block: int
) -> Dict[str, int]:
gauge_address = Web3.toChecksumAddress(gauge_address)
gauge_address = to_checksum_address(gauge_address)
variables = {"gaugeAddress": gauge_address, "block": int(block)}
data = self.subgraph.fetch_graphql_data(
self.subgraph.BALANCER_GAUGES_SHARES_QUERY, variables
)
results = {}
if "data" in data and "gaugeShares" in data["data"]:
for share in data["data"]["gaugeShares"]:
user_address = Web3.toChecksumAddress(share["user"]["id"])
user_address = to_checksum_address(share["user"]["id"])
results[user_address] = float(share["balance"])
return results

Expand Down
2 changes: 1 addition & 1 deletion bal_addresses/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pathlib>=1.0
requests
pandas
web3==5.31.3
web3
dotmap
munch==4.0.0
gql[requests]
14 changes: 14 additions & 0 deletions bal_addresses/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from web3 import Web3


### These functions are to deal with differing web3 versions and the need to use 5.x for legacy brownie code
def to_checksum_address(address: str):
if hasattr(Web3, 'toChecksumAddress'):
return Web3.toChecksumAddress(address)
if hasattr(Web3, "to_checksum_address"):
return Web3.to_checksum_address(address)
def is_address(address: str):
if hasattr(Web3, "isAddress"):
return Web3.isAddress(address)
if hasattr(Web3, "is_address"):
return Web3.isAddress(address)
3 changes: 2 additions & 1 deletion extras/arbitrum.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"Mike B": "0x81DE849AdB5883d089cdFd66bB399b4Af74a16bb",
"Danko": "0x2304488F0eddF15227C21b021739448B51E791C0",
"Dubstard": "0x01B894622C7aa890d758C8a0E8156480F0Fa5f6C",
"gosuto": "0xd411b886e96291b089273a5835D2BE4406700352"
"gosuto": "0xd411b886e96291b089273a5835D2BE4406700352",
"lipman": "0xB209a59A9F3CC7FA5A25dF152a01f9dF8B969A3a"
}
}
3 changes: 2 additions & 1 deletion extras/signers.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
}
},
"contributors": {
"json": "0xE2A4DE267cdD4fF5ED9Ba13552F5c624b12db9b2"
"json": "0xE2A4DE267cdD4fF5ED9Ba13552F5c624b12db9b2",
"lipman": "0x72658e9A5c55371A5e80559B8E07AbC14F212120"
}
}
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
long_description=LONG_DESCRIPTION,
packages=find_packages(),
url="https://github.com/BalancerMaxis/bal_addresses",
install_requires=["setuptools>=42", "wheel", "munch==4.0.0", "web3==5.31.*", "gql[requests]"], # add any additional packages that
install_requires=["setuptools>=42", "wheel", "munch==4.0.0", "web3", "gql[requests]"], # add any additional packages that
# needs to be installed along with your package. Eg: 'caer'

keywords=['python', 'first package'],
Expand Down

0 comments on commit 45f8621

Please sign in to comment.