Skip to content

Commit

Permalink
first commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
BIP Bot committed Feb 9, 2024
0 parents commit eae8c33
Show file tree
Hide file tree
Showing 8 changed files with 310 additions and 0 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/ecosystem_deposits_single_pool.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Get ecosystem deposits by user csv for a single pool (mainnet only for now)

on:
workflow_dispatch:
inputs:
POOL_ID:
description: "The PoolID of the pool to query"
required: true
GAUGE:
description: "The address gauge for the pool above"
required: true
BLOCK:
description: "The block number to measure at"
required: true


jobs:
generate-csv:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Cache Compiler Installations
uses: actions/cache@v2
with:
path: |
~/.solcx
~/.vvm
key: compiler-cache

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.9

- name: Generate CSV
env:
POOL_ID: ${{ github.event.inputs.POOL_ID }}
GAUGE: ${{ github.event.inputs.GAUGE }}
BLOCK: ${{ github.event.inputs.BLOCK }}
run: |
pip3 install -r requirements.txt
python ./ecosystem_deposits_for_1_pool.py
- name: Create PR
id: cpr
uses: peter-evans/create-pull-request@v5
with:
commit-message: "CSV generated"
title: "Action Generated CSV"
branch: gha-csv-merge
delete-branch: true
labels: "Automatic Run"
branch-suffix: timestamp

run_reports:
needs: merge_jsons
uses: "BalancerMaxis/multisig-ops/.github/workflows/run_reports_reusable.yaml@main"
secrets: inherit
with:
pr_number: ${{ needs.merge_jsons.outputs.pull-request-number }}
checkout_ref: "gha-balances-csv"
162 changes: 162 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
### Python template
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Ecosystem Balances
This repo is a demonstration of how to use an API in development to generate user balances across the Balancer ecosystem.
###### Note that BPT refers to Balancer Pool Token, or the deposit token that comes from depositing in a gauge

#### The following positions are considered:

- BPTs in a users wallet
- BPTs staked in the Balancer Gauge
- BPTs deposited into Aura

### How to run it:
There are 3 inputs. A pool_id, a gauge address and a block number to count at. The easiest way to get all of this at once is to find the pool on Aura, here is an example for [ezETH/WETH](https://app.aura.finance/#/1/pool/189).

Go to the info tab and turn `Dev Mode` on. Now you can see the `Balancer Pool Id` and `Balancer Gauge`. A recent block at the time of this writing is `19192586`.


![img.png](img.png)


With this data at hand, here is how you would run at the command line using this file:
```shell
export POOL_ID=0x596192bb6e41802428ac943d2f1476c1af25cc0e000000000000000000000659
export GAUGE=0xa8b309a75f0d64ed632d45a003c68a30e59a1d8b
export BLOCK=19192586
pip3 install -r requirements.txt
python3 ecosystem_deposits_for_1_pool.py
```

You should get some results like this. You can ignore the preferential gauge messages

```shell
Warning: 12526.432768559198 BPTs were found in the deposited in a bal gauge and zeroed out, but 12526.43276855921 of 'em where counted as gauge deposits.
Warning: 89.60338546450836 BPTs were found in the aura proxy and zeroed out, but 89.60338546450835 of 'em where counted as Aura deposits.
Found 13376.424484124613 of which 12526.432768559198 where staked by an address in a bal gauge and 89.60338546450836 where deposited on aura at block 19192586
CSV file generated successfully: output.json
```

Check that the program completes and that the warnings are about very smol rounding errors you can accept.

A file named `output.csv` has been created that has BPT balances per user.

to understand user balances of one component of the pool, you'll need to multiply those BPT balances by the amount of the a specific that was in each BPT on that block.
33 changes: 33 additions & 0 deletions ecosystem_deposits_for_1_pool.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from bal_addresses import Ecosystem
import csv
import os

### Example Run for ezETH/rETH
# export POOL_ID=0x05ff47afada98a98982113758878f9a8b9fdda0a000000000000000000000645
# export GAUGE=0xc859bf9d7b8c557bbd229565124c2c09269f3aef
# export BLOCK=19192051
# pip3 install -r requirements.txt
# python3 tools/ecosystem_deposits_for_pool.py

def main(
chain="mainnet",
output_filename="output.csv"
):
pool_id = os.environ["POOL_ID"]
gauge_address = os.environ["GAUGE"]
block = os.environ["BLOCK"]
eco = Ecosystem(chain)
csv_file = output_filename
user_balances =eco.get_ecosystem_balances(pool_id, gauge_address, block)
with open(csv_file, 'w') as f:
writer = csv.writer(f)

writer.writerow(["depositor_address", "total_pool_tokens"])
for depositor, amount in user_balances.items():
writer.writerow([depositor, amount])
print("CSV file generated successfully: ", csv_file)



if __name__ == "__main__":
main()
Binary file added img.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file added main.py
Empty file.
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
git+https://github.com/BalancerMaxis/bal_addresses@ecosystem-balances-poc

0 comments on commit eae8c33

Please sign in to comment.