Skip to content

Commit 51ace8b

Browse files
authored
Add workflow for dispensing Predictoor USDC rewards (#840)
* Add workflow for dispensing Predictoor USDC rewards * Update README to include details on Predictoor rewards schedule * Add documentation for Predictoor rewards dispense process * Add link to Predictoor dispense documentation in README * Update workflow to append '-USDC' to folder names and adjust documentation accordingly
1 parent 9917bc4 commit 51ace8b

5 files changed

Lines changed: 168 additions & 4 deletions

File tree

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
name: Dispense Predictoor USDC Rewards
2+
3+
on:
4+
schedule:
5+
- cron: "0 0 * * 1"
6+
push:
7+
branches: [main]
8+
pull_request:
9+
branches: [main]
10+
workflow_dispatch:
11+
inputs:
12+
amt_of_tokens:
13+
description: "Amount of tokens to distribute"
14+
required: true
15+
default: "1"
16+
17+
jobs:
18+
dispense-predictoor-usdc:
19+
env:
20+
BINANCE_API_URL: ${{secrets.BINANCE_API_URL}}
21+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
22+
permissions:
23+
contents: "read"
24+
id-token: "write"
25+
runs-on: ubuntu-latest
26+
strategy:
27+
matrix:
28+
python-version: [3.8]
29+
#needs: run-tests
30+
steps:
31+
- id: df-py
32+
uses: pozetroninc/github-action-get-latest-release@master
33+
with:
34+
owner: oceanprotocol
35+
repo: df-py
36+
excludes: prerelease, draft
37+
38+
- name: Set branch to checkout
39+
id: set_branch
40+
run: echo "BRANCH=${{ github.event_name == 'schedule' && steps.df-py.outputs.release || github.ref }}" >> $GITHUB_ENV
41+
42+
- uses: actions/checkout@v3
43+
with:
44+
ref: ${{ env.BRANCH }}
45+
46+
- name: Set up Python {{ matrix.python-version }}
47+
uses: actions/setup-python@v2
48+
with:
49+
python-version: ${{ matrix.python-version }}
50+
51+
- name: Install dependencies
52+
working-directory: ${{ github.workspace }}
53+
run: |
54+
python -m pip install --upgrade pip
55+
pip install -r requirements.txt --quiet
56+
57+
- name: Set up Openzeppelin
58+
run: npm install @openzeppelin/contracts
59+
60+
- name: Set env variables
61+
run: |
62+
echo "DFTOOL_KEY=${{ secrets.DF_SAPPHIRE_ROSE_REWARDS_PK }}" >> $GITHUB_ENV
63+
echo "ADDRESS_FILE=.github/workflows/data/address.json" >> $GITHUB_ENV
64+
echo "WEB3_INFURA_PROJECT_ID=${{ secrets.WEB3_INFURA_PROJECT_ID }}" >> $GITHUB_ENV
65+
echo "SECRET_SEED=${{ secrets.SECRET_SEED }}" >> $GITHUB_ENV
66+
echo "date=$(date -d "last-thursday - 1 week" '+%Y-%m-%d')" >> $GITHUB_ENV
67+
echo "now=$(date -d "last-thursday" '+%Y-%m-%d')" >> $GITHUB_ENV
68+
echo "CSV_DIR=/tmp/csv" >> $GITHUB_ENV
69+
echo "RETRY_TIMES=5" >> $GITHUB_ENV
70+
echo "POLYGON_RPC_URL=https://polygon-mainnet.infura.io/v3/" >> $GITHUB_ENV
71+
echo "MUMBAI_RPC_URL=https://polygon-mumbai.infura.io/v3/" >> $GITHUB_ENV
72+
echo "MAINNET_RPC_URL=https://mainnet.infura.io/v3/" >> $GITHUB_ENV
73+
echo "SAPPHIRE_MAINNET_RPC_URL=https://sapphire.oasis.io/" >> $GITHUB_ENV
74+
echo "GOERLI_RPC_URL=https://rpc.ankr.com/eth_goerli" >> $GITHUB_ENV
75+
echo "INFURA_NETWORKS=polygon,mumbai,mainnet" >> $GITHUB_ENV
76+
77+
- name: Make dftool executable
78+
run: chmod +x dftool
79+
80+
- name: Run dftool predictoor_data
81+
run: |
82+
./dftool predictoor_data $date $now $CSV_DIR 23294 --RETRIES $RETRY_TIMES
83+
84+
- name: Run dftool calc rewards for predictoor_rose
85+
run: |
86+
./dftool calc predictoor_rose $CSV_DIR 500
87+
88+
- name: Upload artifacts
89+
uses: actions/upload-artifact@v4
90+
with:
91+
name: CSV Files
92+
retention-days: 5
93+
path: /tmp/csv
94+
95+
- name: Distribute Predictoor rewards
96+
env:
97+
USE_MULTISIG: false
98+
if: github.event_name == 'schedule'
99+
run: |
100+
./dftool dispense_active $CSV_DIR 23294 --DFREWARDS_ADDR="0xc37F8341Ac6e4a94538302bCd4d49Cf0852D30C0" --TOKEN_ADDR="0x2c2E3812742Ab2DA53a728A09F5DE670Aba584b6" --PREDICTOOR_ROSE True
101+
102+
- name: Rename folder to round number
103+
run: |
104+
bash ./scripts/workflow_rename_folder.sh $now -USDC
105+
106+
- id: "auth"
107+
uses: "google-github-actions/auth@v1"
108+
with:
109+
credentials_json: "${{ secrets.GC_SECRET }}"
110+
111+
- name: Set upload destination
112+
run: |
113+
if [[ "${{ github.event_name }}" == "schedule" ]]; then
114+
echo "DESTINATION=df-historical-data" >> $GITHUB_ENV
115+
else
116+
echo "DESTINATION=df-historical-data-test" >> $GITHUB_ENV
117+
fi
118+
119+
- name: Remove predictoor_data.csv
120+
run: rm /tmp/csv/${{ env.DFWEEK }}/predictoor_data.csv
121+
122+
- id: "upload-folder"
123+
uses: "google-github-actions/upload-cloud-storage@v1"
124+
with:
125+
path: "/tmp/csv/${{ env.DFWEEK }}/"
126+
destination: "${{ env.DESTINATION }}"

PREDICTOOR-DISPENSE.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Predictoor Rewards Dispense
2+
3+
This document describes the process for dispensing Predictoor rewards.
4+
5+
## Process Overview
6+
7+
Predictoor rewards are dispensed weekly via a GitHub Action workflow.
8+
9+
- **Workflow:** [.github/workflows/dispense-predictoor-usdc.yaml](.github/workflows/dispense-predictoor-usdc.yaml)
10+
- **Schedule:** Every Monday at 00:00 UTC.
11+
- **Manual Trigger:** Can be triggered manually via `workflow_dispatch` with a custom amount of tokens.
12+
13+
## How it works
14+
15+
The workflow performs the following steps:
16+
17+
1. **Setup:** Installs dependencies and configures environment variables (RPC URLs, private keys).
18+
2. **Data Retrieval:** Runs `dftool predictoor_data` to fetch predictoor performance data for the previous week.
19+
3. **Reward Calculation:** Runs `dftool calc predictoor_rose` to calculate rewards based on the fetched data.
20+
4. **Dispense:** Runs `dftool dispense_active` to send rewards to the `DFRewards` contract on Sapphire.
21+
5. **Upload:** Renames the results folder (appending `-USDC` to the round number) and uploads the CSV files to Google Cloud Storage for historical tracking.
22+
23+
## Networks and Tokens
24+
25+
- **Chain:** Sapphire Mainnet (Chain ID 23294)
26+
- **Token:** USDC (configured via `--TOKEN_ADDR` in the dispense step)
27+
- **Reward Contract:** `DFRewards` contract address is specified in the dispense step.
28+
29+
## Manual Execution
30+
31+
Go to the "Actions" tab in GitHub, select "Dispense Predictoor USDC Rewards", and click "Run workflow". You can specify the `amt_of_tokens` to distribute.

README-crons-ops.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,8 @@ The server runs a cron job that calculates the allocations, vebalances, volumes,
1313
## Weekly Rewards
1414
Every Thursday at 12:00 UTC, Github Actions calculates the weekly rewards for the previous week. The results are then uploaded as an artifact to the Github Actions.
1515

16+
## Predictoor Rewards
17+
Every Monday at 00:00 UTC, Github Actions calculates and dispenses rewards for Predictoors. [More info.](PREDICTOOR-DISPENSE.md)
18+
1619
## Contract Checkpoint
1720
Every Thursday at 12:00 UTC, Github Actions checkpoints the `FeeDistributor` smart contract. This ensures that the `FeeEstimate` smart contract serves the correct data.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ Now, you can use those networks simply by specifying a different chainid in `dft
141141
Happens via regularly-scheduled Github Actions:
142142

143143
- Active: [flow.yml](.github/workflows/flow.yml)
144+
- Predictoor: [PREDICTOOR-DISPENSE.md](PREDICTOOR-DISPENSE.md)
144145

145146
More info: [README-crons-ops.md](README-crons-ops.md)
146147

scripts/workflow_rename_folder.sh

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@ else
1010
now="$1"
1111
fi
1212

13+
suffix="$2"
14+
1315
df_week=$(($(($(($(($(date -d "$now" +%s) - $(date -d "$count_start" +%s))) / 86400)) / 7)) + 4))
14-
echo $df_week
16+
df_foldersuffix="${df_week}${suffix}"
17+
echo $df_foldersuffix
1518

16-
mkdir -p /tmp/csv/$df_week
17-
cp /tmp/csv/*.csv /tmp/csv/$df_week
19+
mkdir -p /tmp/csv/$df_foldersuffix
20+
cp /tmp/csv/*.csv /tmp/csv/$df_foldersuffix
1821

19-
echo "DFWEEK=$df_week" >>$GITHUB_ENV
22+
echo "DFWEEK=$df_foldersuffix" >>$GITHUB_ENV

0 commit comments

Comments
 (0)