Skip to content

Commit

Permalink
Merge pull request #99 from balancer/use_deployments_repo_json
Browse files Browse the repository at this point in the history
Move to using JSON file in new deployments repo
  • Loading branch information
mikemcdonald authored Jul 17, 2023
2 parents c725461 + f088807 commit 426e416
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 67 deletions.
88 changes: 46 additions & 42 deletions .github/python_actions/genContractLists.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,32 @@



def address_directory():
r = requests.get(ADDRESSBOOK_URL)
return r.json()
def address_directory(chain, status=None):
r = requests.get(f"https://raw.githubusercontent.com/balancer/balancer-deployments/master/addresses/{chain}.json")
r=r.json()
if isinstance(status, str):
return {k: v for k, v in r.items() if v['status'] == status}
else:
return r



def genFullTable(r, chain):
result = pd.DataFrame(columns=["Contract", "Address", "Deployment"])
r = r[chain] # go to chain
for deployment, contracts in r.items():
for contract in contracts.keys():
for deployment, depdata in r.items():
for contract in depdata['contracts']:
### Check if versioned
t = deployment.split("-")
t = t[len(t) - 1]
if bool(re.search(r'^v\d', t)):
contractText = f"{contract} ({t})"
contractText = f"{contract['name']} ({t})"
else:
contractText = contract
contractText = contract['name']
###

dl = f'{AddrBook.GITHUB_DEPLOYMENTS_NICE}/tasks/{deployment}'
al = f"{AddrBook.SCANNERS_BY_CHAIN[chain]}/address/{contracts[contract]}#code"
addressText = f'[{contracts[contract]}]({al})'
dl = f"{AddrBook.GITHUB_DEPLOYMENTS_NICE}/tasks/{deployment}"
al = f"{AddrBook.SCANNERS_BY_CHAIN[chain]}/address/{contract['address']}#code"
addressText = f"[{contract['address']}]({al})"
## TODO find github code links
result.loc[len(result)] = [contractText, addressText, f"[{deployment}]({dl})"]
result.sort_values(by=["Contract","Deployment"], inplace=True)
Expand All @@ -49,49 +53,47 @@ def genFullTable(r, chain):
def genPoolFactories(r, chain):
result = pd.DataFrame(columns=["Contract", "Address", "Deployment"])
print(f"Generating pools for {chain}")
r = r[chain] # go to chain
for deployment, contracts in r.items():
for deployment, depdata in r.items():
if "-pool" not in deployment:
continue
for contract, address in contracts.items():
if "Factory" in contract:
for contract in depdata['contracts']:
if "Factory" in contract['name']:
### Check if versioned
t = deployment.split("-")
t = t[len(t)-1]
if bool(re.search(r'^v\d', t)):
contractText = f"{contract} ({t})"
contractText = f"{contract['name']} ({t})"
else:
contractText = contract
contractText = contract['name']
###

dl = f"{AddrBook.GITHUB_DEPLOYMENTS_NICE}/tasks/{deployment}"
al = f"{AddrBook.SCANNERS_BY_CHAIN[chain]}/address/{contracts[contract]}#code"
result.loc[len(result)] = [contractText, f"[{contracts[contract]}]({al})", f"[{deployment}]({dl})"]
al = f"{AddrBook.SCANNERS_BY_CHAIN[chain]}/address/{contract['address']}#code"
result.loc[len(result)] = [contractText, f"[{contract['address']}]({al})", f"[{deployment}]({dl})"]
result.sort_values(by=["Contract","Deployment"], inplace=True)
return result

def genNotInContractList(r, chain, contractList):
result = pd.DataFrame(columns=["Contract", "Address", "Deployment"])
r = r[chain] # go to chain
for deployment, contracts in r.items():
for contract, address in contracts.items():
if contract in contractList:
for deployment, depdata in r.items():
for contract in depdata['contracts']:
if contract['name'] in contractList:
continue
if "-pool" in deployment:
if '-pool' in deployment:
continue

### Check if versioned
t = deployment.split("-")
t = t[len(t) - 1]
if bool(re.search(r'^v\d', t)):
contractText = f"{contract} ({t})"
contractText = f"{contract['name']} ({t})"
else:
contractText = contract
contractText = contract['name']
###

dl = f'{AddrBook.GITHUB_DEPLOYMENTS_NICE}/tasks/{deployment}'
al = f"{AddrBook.SCANNERS_BY_CHAIN[chain]}/address/{contracts[contract]}#code"
addressText = f'[{contracts[contract]}]({al})'
al = f"{AddrBook.SCANNERS_BY_CHAIN[chain]}/address/{contract['address']}#code"
addressText = f"[{contract['address']}]({al})"
## TODO find github code links
result.loc[len(result)] = [contractText, addressText, f"[{deployment}]({dl})"]
result.sort_values(by=["Contract","Deployment"], inplace=True)
Expand All @@ -101,24 +103,26 @@ def genNotInContractList(r, chain, contractList):

def genFromContractList(r, chain, contractList):
result = pd.DataFrame(columns=["Contract", "Address", "Deployment"])
r = r[chain] # go to chain
for deployment, contracts in r.items():
m = set(contracts.keys()) & set(contractList)
for contract in m:
for deployment, depdata in r.items():
for contract in depdata['contracts']:
### Check if in list
if contract['name'] not in contractList:
continue
### Check if versioned
t = deployment.split("-")
t = t[len(t) - 1]
if bool(re.search(r'^v\d', t)):
contractText = f"{contract} ({t})"
contractText = f"{contract['name']} ({t})"
else:
contractText = contract
contractText = contract['name']

###

dl = f'{AddrBook.GITHUB_DEPLOYMENTS_NICE}/tasks/{deployment}'
al = f"{AddrBook.SCANNERS_BY_CHAIN[chain]}/address/{contracts[contract]}#code"
addressText = f'[{contracts[contract]}]({al})'
dl = f"{AddrBook.GITHUB_DEPLOYMENTS_NICE}/tasks/{deployment}"
al = f"{AddrBook.SCANNERS_BY_CHAIN[chain]}/address/{contract['address']}#code"
addressText = f"[{contract['address']}]({al})"
## TODO find github code links
result.loc[len(result)] = [contract, addressText, f"[{deployment}]({dl})"]
result.loc[len(result)] = [contractText, addressText, f"[{deployment}]({dl})"]
result.sort_values(by=["Contract","Deployment"], inplace=True)
return result

Expand All @@ -137,7 +141,7 @@ def genChainMd(chain):
## Pool Factories
"""
r = address_directory()["active"]
r = address_directory(chain, status='ACTIVE')
output += genPoolFactories(r, chain).to_markdown(index=False)

for heading, contracts in CONTRACTS_BY_HEADING.items():
Expand All @@ -161,10 +165,10 @@ def genChainMd(chain):
"""
try:
r = address_directory()["old"]
r = address_directory(chain, status='DEPRECATED')
if r != {}:
output += genFullTable(r, chain).to_markdown(index=False)
except:
else:
output += "No deprecated contracts found\n"
output += """
Expand Down
Loading

1 comment on commit 426e416

@vercel
Copy link

@vercel vercel bot commented on 426e416 Jul 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.