Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 126 additions & 0 deletions .github/workflows/dispense-predictoor-usdc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
name: Dispense Predictoor USDC Rewards

on:
schedule:
- cron: "0 0 * * 1"
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
inputs:
amt_of_tokens:
description: "Amount of tokens to distribute"
required: true
default: "1"

jobs:
dispense-predictoor-usdc:
env:
BINANCE_API_URL: ${{secrets.BINANCE_API_URL}}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
permissions:
contents: "read"
id-token: "write"
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8]
#needs: run-tests
steps:
- id: df-py
uses: pozetroninc/github-action-get-latest-release@master
with:
owner: oceanprotocol
repo: df-py
excludes: prerelease, draft

- name: Set branch to checkout
id: set_branch
run: echo "BRANCH=${{ github.event_name == 'schedule' && steps.df-py.outputs.release || github.ref }}" >> $GITHUB_ENV

- uses: actions/checkout@v3
with:
ref: ${{ env.BRANCH }}

- name: Set up Python {{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
working-directory: ${{ github.workspace }}
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt --quiet

- name: Set up Openzeppelin
run: npm install @openzeppelin/contracts

- name: Set env variables
run: |
echo "DFTOOL_KEY=${{ secrets.DF_SAPPHIRE_ROSE_REWARDS_PK }}" >> $GITHUB_ENV
echo "ADDRESS_FILE=.github/workflows/data/address.json" >> $GITHUB_ENV
echo "WEB3_INFURA_PROJECT_ID=${{ secrets.WEB3_INFURA_PROJECT_ID }}" >> $GITHUB_ENV
echo "SECRET_SEED=${{ secrets.SECRET_SEED }}" >> $GITHUB_ENV
echo "date=$(date -d "last-thursday - 1 week" '+%Y-%m-%d')" >> $GITHUB_ENV
echo "now=$(date -d "last-thursday" '+%Y-%m-%d')" >> $GITHUB_ENV
echo "CSV_DIR=/tmp/csv" >> $GITHUB_ENV
echo "RETRY_TIMES=5" >> $GITHUB_ENV
echo "POLYGON_RPC_URL=https://polygon-mainnet.infura.io/v3/" >> $GITHUB_ENV
echo "MUMBAI_RPC_URL=https://polygon-mumbai.infura.io/v3/" >> $GITHUB_ENV
echo "MAINNET_RPC_URL=https://mainnet.infura.io/v3/" >> $GITHUB_ENV
echo "SAPPHIRE_MAINNET_RPC_URL=https://sapphire.oasis.io/" >> $GITHUB_ENV
echo "GOERLI_RPC_URL=https://rpc.ankr.com/eth_goerli" >> $GITHUB_ENV
echo "INFURA_NETWORKS=polygon,mumbai,mainnet" >> $GITHUB_ENV

- name: Make dftool executable
run: chmod +x dftool

- name: Run dftool predictoor_data
run: |
./dftool predictoor_data $date $now $CSV_DIR 23294 --RETRIES $RETRY_TIMES

- name: Run dftool calc rewards for predictoor_rose
run: |
./dftool calc predictoor_rose $CSV_DIR 500

- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: CSV Files
retention-days: 5
path: /tmp/csv

- name: Distribute Predictoor rewards
env:
USE_MULTISIG: false
if: github.event_name == 'schedule'
run: |
./dftool dispense_active $CSV_DIR 23294 --DFREWARDS_ADDR="0xc37F8341Ac6e4a94538302bCd4d49Cf0852D30C0" --TOKEN_ADDR="0x2c2E3812742Ab2DA53a728A09F5DE670Aba584b6" --PREDICTOOR_ROSE True

- name: Rename folder to round number
run: |
bash ./scripts/workflow_rename_folder.sh $now -USDC

- id: "auth"
uses: "google-github-actions/auth@v1"
with:
credentials_json: "${{ secrets.GC_SECRET }}"

- name: Set upload destination
run: |
if [[ "${{ github.event_name }}" == "schedule" ]]; then
echo "DESTINATION=df-historical-data" >> $GITHUB_ENV
else
echo "DESTINATION=df-historical-data-test" >> $GITHUB_ENV
fi

- name: Remove predictoor_data.csv
run: rm /tmp/csv/${{ env.DFWEEK }}/predictoor_data.csv

- id: "upload-folder"
uses: "google-github-actions/upload-cloud-storage@v1"
with:
path: "/tmp/csv/${{ env.DFWEEK }}/"
destination: "${{ env.DESTINATION }}"
31 changes: 31 additions & 0 deletions PREDICTOOR-DISPENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Predictoor Rewards Dispense

This document describes the process for dispensing Predictoor rewards.

## Process Overview

Predictoor rewards are dispensed weekly via a GitHub Action workflow.

- **Workflow:** [.github/workflows/dispense-predictoor-usdc.yaml](.github/workflows/dispense-predictoor-usdc.yaml)
- **Schedule:** Every Monday at 00:00 UTC.
- **Manual Trigger:** Can be triggered manually via `workflow_dispatch` with a custom amount of tokens.

## How it works

The workflow performs the following steps:

1. **Setup:** Installs dependencies and configures environment variables (RPC URLs, private keys).
2. **Data Retrieval:** Runs `dftool predictoor_data` to fetch predictoor performance data for the previous week.
3. **Reward Calculation:** Runs `dftool calc predictoor_rose` to calculate rewards based on the fetched data.
4. **Dispense:** Runs `dftool dispense_active` to send rewards to the `DFRewards` contract on Sapphire.
5. **Upload:** Renames the results folder (appending `-USDC` to the round number) and uploads the CSV files to Google Cloud Storage for historical tracking.

## Networks and Tokens

- **Chain:** Sapphire Mainnet (Chain ID 23294)
- **Token:** USDC (configured via `--TOKEN_ADDR` in the dispense step)
- **Reward Contract:** `DFRewards` contract address is specified in the dispense step.

## Manual Execution

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.
3 changes: 3 additions & 0 deletions README-crons-ops.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@ The server runs a cron job that calculates the allocations, vebalances, volumes,
## Weekly Rewards
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.

## Predictoor Rewards
Every Monday at 00:00 UTC, Github Actions calculates and dispenses rewards for Predictoors. [More info.](PREDICTOOR-DISPENSE.md)

## Contract Checkpoint
Every Thursday at 12:00 UTC, Github Actions checkpoints the `FeeDistributor` smart contract. This ensures that the `FeeEstimate` smart contract serves the correct data.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ Now, you can use those networks simply by specifying a different chainid in `dft
Happens via regularly-scheduled Github Actions:

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

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

Expand Down
11 changes: 7 additions & 4 deletions scripts/workflow_rename_folder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ else
now="$1"
fi

suffix="$2"

df_week=$(($(($(($(($(date -d "$now" +%s) - $(date -d "$count_start" +%s))) / 86400)) / 7)) + 4))
echo $df_week
df_foldersuffix="${df_week}${suffix}"
echo $df_foldersuffix

mkdir -p /tmp/csv/$df_week
cp /tmp/csv/*.csv /tmp/csv/$df_week
mkdir -p /tmp/csv/$df_foldersuffix
cp /tmp/csv/*.csv /tmp/csv/$df_foldersuffix

echo "DFWEEK=$df_week" >>$GITHUB_ENV
echo "DFWEEK=$df_foldersuffix" >>$GITHUB_ENV
Loading