Skip to content

Commit

Permalink
Merge branch 'main' into beets_vestooor
Browse files Browse the repository at this point in the history
  • Loading branch information
Tritium-VLK authored Apr 21, 2024
2 parents 23e593b + 4396ca6 commit e9384c4
Show file tree
Hide file tree
Showing 70 changed files with 2,869 additions and 477 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/black.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Lint

on: [push, pull_request]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/[email protected]

- name: Black
uses: psf/black@stable
with:
options: "--verbose"
version: "24.4.0"

- name: Auto commit
uses: stefanzweifel/[email protected]
with:
commit_message: "style: ci lint with `black`"
13 changes: 6 additions & 7 deletions .github/workflows/generate_addressbooks.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
name: Generate Addressbooks
name: Generate Addressbooks Deployments

on:
schedule:
- cron: "0 0 * * 3"
workflow_dispatch:

jobs:
refersh_books:
refresh_books:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.9"

Expand All @@ -24,15 +24,14 @@ jobs:
git clone https://github.com/balancer/balancer-deployments.git
export DEPLOYMENTS_REPO_ROOT_URL=`pwd`/balancer-deployments
pip3 install -r bal_addresses/requirements.txt
python3 gen_core_pools.py
python3 gen_pools_and_gauges.py
python3 transform-deployments.py
python3 gen_mono_addressbook.py
python3 gen_addresses.py
rm -rf balancer-deployments
git add -A
- name: pull-request
uses: peter-evans/create-pull-request@v5
uses: peter-evans/create-pull-request@v6
with:
commit-message: "Scheduled update from changes to monorepo"
title: "Scheduled update from changes to monorepo"
Expand Down
36 changes: 36 additions & 0 deletions .github/workflows/generate_core_pools.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Generate Core Pools JSON

on:
schedule:
- cron: "0 0 * * 3"
workflow_dispatch:

jobs:
refersh_books:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install Python
uses: actions/setup-python@v5
with:
python-version: "3.9"

- name: Update Files
id: update
run: |
pip3 install -r bal_addresses/requirements.txt
python3 gen_core_pools.py
git add -A
- name: pull-request
uses: peter-evans/create-pull-request@v6
with:
commit-message: "Scheduled update from changes to monorepo"
title: "Scheduled update from changes to monorepo"
branch: "gha-addressbook"
reviewers: "Tritum-VLK"
assignees: "Tritum-VLK"
labels: "Automatic"
8 changes: 3 additions & 5 deletions .github/workflows/generate_permissions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:
ALCHEMY_KEY: ${{ secrets.ALCHEMY_KEY }}
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.9"

Expand All @@ -25,12 +25,10 @@ jobs:
run: |
pip3 install -r bal_addresses/requirements.txt
python3 generate_current_permissions.py
python3 gen_addresses.py
rm -rf balancer-deployments
git add -A
- name: pull-request
uses: peter-evans/create-pull-request@v5
uses: peter-evans/create-pull-request@v6
with:
commit-message: "Scheduled update from changes to monorepo"
title: "Scheduled update from changes to monorepo"
Expand Down
17 changes: 15 additions & 2 deletions bal_addresses/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
from .addresses import AddrBook, GITHUB_DEPLOYMENTS_RAW, GITHUB_DEPLOYMENTS_NICE, GITHUB_RAW_OUTPUTS, GITHUB_RAW_EXTRAS
from .addresses import (
AddrBook,
GITHUB_DEPLOYMENTS_RAW,
GITHUB_DEPLOYMENTS_NICE,
GITHUB_RAW_OUTPUTS,
GITHUB_RAW_EXTRAS,
)
from .permissions import BalPermissions
from .errors import MultipleMatchesError, NoResultError
from .errors import (
MultipleMatchesError,
NoResultError,
ChecksumError,
UnexpectedListLengthError,
)
from .subgraph import Subgraph
from .pools_gauges import BalPoolsGauges
72 changes: 60 additions & 12 deletions bal_addresses/addresses.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import os.path
from .errors import MultipleMatchesError, NoResultError
from typing import Dict
from typing import Optional
Expand All @@ -7,6 +8,9 @@
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 All @@ -26,16 +30,21 @@

class AddrBook:
chains = Munch.fromDict(
requests.get(
json.load(open("extras/chains.json"))
if os.path.exists("extras/chains.json")
else requests.get(
"https://raw.githubusercontent.com/BalancerMaxis/bal_addresses/main/extras/chains.json"
).json()
)
fx_description_by_name = Munch.fromDict(
requests.get(
json.load(open("extras/func_desc_by_name.json"))
if os.path.exists("extras/func_desc_by_name.json")
else requests.get(
"https://raw.githubusercontent.com/BalancerMaxis/bal_addresses/main/extras/func_desc_by_name.json"
).json()
)
chain_ids_by_name = chains.CHAIN_IDS_BY_NAME
chain_names_by_id = {v: k for k, v in chain_ids_by_name.items()}

def __init__(self, chain, jsonfile=False):
self.jsonfile = jsonfile
Expand All @@ -62,6 +71,7 @@ def __init__(self, chain, jsonfile=False):
self._eoas = None
self._pools = None
self._gauges = None
self._root_gauges = None

@property
def deployments(self) -> Optional[Munch]:
Expand Down Expand Up @@ -129,6 +139,17 @@ def gauges(self) -> Optional[Munch]:
self.populate_gauges()
return self._gauges

@property
def root_gauges(self) -> Optional[Munch]:
"""
Get the root gauges for all chains in a form of a Munch object
"""
if self._root_gauges is not None:
return self._root_gauges
else:
self.populate_root_gauges()
return self._root_gauges

def populate_deployments(self) -> None:
chain_deployments = requests.get(
f"{GITHUB_DEPLOYMENTS_RAW}/addresses/{self.chain}.json"
Expand Down Expand Up @@ -197,23 +218,48 @@ def populate_multisigs(self) -> None:
self._multisigs = Munch.fromDict({})

def populate_pools(self) -> None:
with open("extras/pools.json", "r") as f:
msigs = json.load(f)
if msigs.get(self.chain):
self._pools = Munch.fromDict(self.checksum_address_dict(msigs[self.chain]))
pools = (
json.load(open("outputs/pools.json"))
if os.path.exists("outputs/pools.json")
else requests.get(f"{GITHUB_RAW_OUTPUTS}/pools.json").json()
)
if pools.get(self.chain):
self._pools = Munch.fromDict(self.checksum_address_dict(pools[self.chain]))
else:
print(f"Warning: No pools for chain {self.chain}")
self._pools = Munch.fromDict({})

def populate_gauges(self) -> None:
with open("extras/gauges.json", "r") as f:
msigs = json.load(f)
if msigs.get(self.chain):
self._gauges = Munch.fromDict(self.checksum_address_dict(msigs[self.chain]))
gauges = (
json.load(open("outputs/gauges.json"))
if os.path.exists("outputs/gauges.json")
else requests.get(f"{GITHUB_RAW_OUTPUTS}/gauges.json").json()
)
if gauges.get(self.chain):
self._gauges = Munch.fromDict(
self.checksum_address_dict(gauges[self.chain])
)
else:
print(f"Warning: No gauges for chain {self.chain}")
self._gauges = Munch.fromDict({})

def populate_root_gauges(self) -> None:
if self.chain == "mainnet":
root_gauges = (
json.load(open("outputs/root_gauges.json"))
if os.path.exists("outputs/root_gauges.json")
else requests.get(f"{GITHUB_RAW_OUTPUTS}/root_gauges.json").json()
)
if root_gauges.get(self.chain):
self._root_gauges = Munch.fromDict(
self.checksum_address_dict(root_gauges[self.chain])
)
else:
print(f"Warning: No root gauges for chain {self.chain}")
self._root_gauges = Munch.fromDict({})
else:
self._root_gauges = Munch.fromDict({})

def search_unique(self, substr):
results = [s for s in self.flatbook.keys() if substr in s]
if len(results) > 1:
Expand Down Expand Up @@ -274,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 All @@ -300,11 +346,13 @@ def generate_flatbook(self):
self.populate_multisigs()
self.populate_pools()
self.populate_gauges()
self.populate_root_gauges()
self.populate_extras()
# write pools and gauges first, so they get overwritten by deployments later
# deployment label should take precedence over pool/gauge label
flatbook["pools"] = self.flatten_dict(self.pools)
flatbook["gauges"] = self.flatten_dict(self.gauges)
flatbook["root_gauges"] = self.flatten_dict(self.root_gauges)
for deployment, ddata in self.deployments.items():
for contract, infodict in ddata["contracts"].items():
flatbook[infodict.path] = infodict.address
Expand All @@ -325,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
16 changes: 14 additions & 2 deletions bal_addresses/errors.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@

class MultipleMatchesError(Exception):
pass


class NoResultError(Exception):
pass
pass


class ChecksumError(Exception):
pass


class GraphQLRequestError(Exception):
pass


class UnexpectedListLengthError(Exception):
pass
11 changes: 11 additions & 0 deletions bal_addresses/graphql/blocks/first_block_after_ts.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
query FirstBlockAfterTimestamp($timestamp: BigInt) {
blocks(
first: 1
orderBy: number
orderDirection: asc
where: { timestamp_gt: $timestamp }
) {
number
timestamp
}
}
15 changes: 15 additions & 0 deletions bal_addresses/graphql/core/fetch_gauge_shares.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
query FetchGaugeShares($gaugeAddress: String!, $block: Int) {
gaugeShares(
block: { number: $block }
where: { gauge_contains_nocase: $gaugeAddress, balance_gt: "0" }
orderBy: balance
orderDirection: desc
first: 1000
) {
balance
id
user {
id
}
}
}
10 changes: 10 additions & 0 deletions bal_addresses/graphql/core/get_aura_gauge_mappings.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
query getAuraGaugeMappings {
gauges(first: 1000) {
pool {
id
gauge {
id
}
}
}
}
10 changes: 10 additions & 0 deletions bal_addresses/graphql/core/get_user_pool_balances.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
query GetUserPoolBalances($poolId: ID!, $block: Int) {
pool(id: $poolId, block: { number: $block }) {
shares(where: { balance_gt: "0" }, orderBy: balance, orderDirection: desc) {
userAddress {
id
}
balance
}
}
}
15 changes: 15 additions & 0 deletions bal_addresses/graphql/core/last_join_exit.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
query LastJoinExit($poolId: String!) {
joinExits(first: 1, orderBy: timestamp, orderDirection: desc, where: {pool: $poolId}) {
amounts
valueUSD
id
sender
timestamp
tx
type
pool {
id
tokensList
}
}
}
Loading

0 comments on commit e9384c4

Please sign in to comment.