Skip to content

Commit

Permalink
ci: add action
Browse files Browse the repository at this point in the history
  • Loading branch information
madlabman committed Jul 6, 2024
1 parent 68f312d commit e2e77f9
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 3 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/_update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
name: Update CSM rewards tree

on:
workflow_call:
inputs:
branch:
description: branch to commit the changes
required: true
type: string
distributor:
description: CSFeeDistributor address
required: true
type: string

permissions:
contents: write

jobs:
script:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.branch }}

- name: Set up Python 3.12
uses: actions/setup-python@v4
with:
python-version: "3.12"

- name: Setup poetry
run: >
curl -sSL https://install.python-poetry.org | python - &&
echo "$POETRY_HOME/bin" >> "$GITHUB_PATH"
env:
POETRY_HOME: "/opt/poetry"
POETRY_VERSION: 1.8.3

- name: Install dependencies
run: poetry install --no-interaction

- name: Generate types
run: poetry run wake up pytypes

- name: Run script
run: poetry run wake run main.py
id: script
env:
RPC_URL: ${{ inputs.branch == 'testnet' && secrets.RPC_URL_HOLESKY || secrets.RPC_URL_MAINNET }}
GW3_ACCESS_KEY: ${{ secrets.GW3_ACCESS_KEY }}
GW3_SECRET_KEY: ${{ secrets.GW3_SECRET_KEY }}
DISTRIBUTOR_ADDRESS: ${{ inputs.distributor }}

- name: Commit new artifacts
if: ${{ steps.script.outputs.updated == 'True' }}
run: |
git config --global user.name "madlabman"
git config --global user.email "[email protected]"
git add "*.json"
git commit -m "chore: update tree and proofs" -m "CID: ${{ steps.script.outputs.cid }}"
git fetch origin
git rebase --strategy-option=ours "origin/${{ inputs.branch }}"
git push
18 changes: 18 additions & 0 deletions .github/workflows/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
name: Automated update

on:
schedule:
- cron: "0 */1 * * *"
workflow_dispatch:

permissions:
contents: write

jobs:
testnet:
uses: ./.github/workflows/_update.yml
with:
branch: testnet
distributor: "0xD7ba648C8F72669C6aE649648B516ec03D07c8ED"
secrets: inherit
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
**Latest [proofs](./proofs.json)**
If you're a Node Operator in CSM, you get staking rewards as a part of Lido
protocol fees.

**Latest [tree](./tree.json)**
The allocation of rewards for CSM operators using a Merkle tree is provided by
CSM Performance Oracle once in a frame, making a new portion of the rewards
available for claim.

Here you can find the latest [rewards tree](./tree.json) as well as the
pre-generated [proofs](./proofs.json) for your convenience.
20 changes: 19 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import os
import subprocess
import sys

from wake.deployment import Address, default_chain, print
Expand Down Expand Up @@ -37,7 +38,7 @@ def main():

proofs = {
f"CSM Operator {v["value"][0]}": {
"leaf": tree.leaf(v["value"]),
"cumulativeFeeShares": v["value"][1],
"proof": list(tree.get_proof(v["treeIndex"])),
}
for v in dump["values"]
Expand All @@ -46,6 +47,23 @@ def main():
with open("proofs.json", "w", encoding="utf-8") as fp:
json.dump(proofs, fp, indent=2, default=default)

github_output = os.getenv("GITHUB_OUTPUT", None)
if not github_output:
return

git_diff = subprocess.run(["git", "diff", "--exit-code", "--quiet", "tree.json"])

with open(github_output, "a", encoding="utf-8") as fp:
fp.write(
"\n".join(
[
"",
f"cid={cid}",
f"updated={git_diff.returncode != 0}",
]
)
)


def default(o):
if isinstance(o, bytes):
Expand Down
1 change: 1 addition & 0 deletions proofs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions tree.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}

0 comments on commit e2e77f9

Please sign in to comment.