Skip to content
Merged
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
150 changes: 75 additions & 75 deletions .github/workflows/scheduled-commit.yaml
Original file line number Diff line number Diff line change
@@ -1,87 +1,87 @@
name: "Calculate rewards"
# name: "Calculate rewards"

on:
schedule:
- cron: '30 7 * * 1' # Every Monday at 07:30 UCT
- cron: '30 19 * * 4' # Every Thursday at 19:30 UCT
workflow_dispatch:
inputs:
first_reward_epoch:
description: "Reward epoch (Last epoch if of-four)"
type: number
reward_amount_epoch_wei:
description: "Reward amount (in wei)"
type: number
trigger_generate_report_workflow:
description: "Run github pages deployment workflow"
type: string
required: true
default: 'true'
# on:
# # schedule:
# # - cron: '30 7 * * 1' # Every Monday at 07:30 UCT
# # - cron: '30 19 * * 4' # Every Thursday at 19:30 UCT
# workflow_dispatch:
# inputs:
# first_reward_epoch:
# description: "Reward epoch (Last epoch if of-four)"
# type: number
# reward_amount_epoch_wei:
# description: "Reward amount (in wei)"
# type: number
# trigger_generate_report_workflow:
# description: "Run github pages deployment workflow"
# type: string
# required: true
# default: 'true'


permissions:
contents: write
actions: write
# permissions:
# contents: write
# actions: write

jobs:
process-staking-rewards:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: 20
- name: Install jq
run: sudo apt update -y && sudo apt install jq moreutils -y
- name: Install node modules
run: yarn install --frozen-lockfile
- name: Calculate epoch vars
run: |
export REWARD_EPOCH_DEFINED="${{ github.event.inputs.first_reward_epoch }}"
export REWARD_EPOCH_CALCULATED="$(node .github/workflows/get-current-reward-epoch.js)"
export USE_REWARD_EPOCH="${REWARD_EPOCH_DEFINED:-$REWARD_EPOCH_CALCULATED}"
echo "USE_REWARD_EPOCH=$USE_REWARD_EPOCH" >> "$GITHUB_ENV"
# jobs:
# process-staking-rewards:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v4
# - uses: actions/setup-node@v3
# with:
# node-version: 20
# - name: Install jq
# run: sudo apt update -y && sudo apt install jq moreutils -y
# - name: Install node modules
# run: yarn install --frozen-lockfile
# - name: Calculate epoch vars
# run: |
# export REWARD_EPOCH_DEFINED="${{ github.event.inputs.first_reward_epoch }}"
# export REWARD_EPOCH_CALCULATED="$(node .github/workflows/get-current-reward-epoch.js)"
# export USE_REWARD_EPOCH="${REWARD_EPOCH_DEFINED:-$REWARD_EPOCH_CALCULATED}"
# echo "USE_REWARD_EPOCH=$USE_REWARD_EPOCH" >> "$GITHUB_ENV"

export USE_FIRST_REWARD_EPOCH="$((${USE_REWARD_EPOCH} - 3))"
echo "USE_FIRST_REWARD_EPOCH=${USE_FIRST_REWARD_EPOCH}" >> "$GITHUB_ENV"
# export USE_FIRST_REWARD_EPOCH="$((${USE_REWARD_EPOCH} - 3))"
# echo "USE_FIRST_REWARD_EPOCH=${USE_FIRST_REWARD_EPOCH}" >> "$GITHUB_ENV"

echo "EPOCH_OF4_if0=$(( $(( $USE_REWARD_EPOCH - 1 )) % 4 ))" >> "$GITHUB_ENV"
# echo "EPOCH_OF4_if0=$(( $(( $USE_REWARD_EPOCH - 1 )) % 4 ))" >> "$GITHUB_ENV"

- name: Set reward amount wei overwrite
if: github.event.inputs.reward_amount_epoch_wei != ''
run: jq --raw-output --monochrome-output --argjson amount "${{ github.event.inputs.reward_amount_epoch_wei }}" '.REWARD_AMOUNT_EPOCH_WEI = $amunt' configs/networks/flare.json | sponge configs/networks/flare.json
# - name: Set reward amount wei overwrite
# if: github.event.inputs.reward_amount_epoch_wei != ''
# run: jq --raw-output --monochrome-output --argjson amount "${{ github.event.inputs.reward_amount_epoch_wei }}" '.REWARD_AMOUNT_EPOCH_WEI = $amunt' configs/networks/flare.json | sponge configs/networks/flare.json

- name: Process staking rewards for ${{ env.USE_REWARD_EPOCH }}
run: |
jq --raw-output --monochrome-output '.NUM_EPOCHS = 1' configs/networks/flare.json | sponge configs/networks/flare.json
jq --raw-output --monochrome-output --argjson epoch "$USE_REWARD_EPOCH" '.REWARD_EPOCH = $epoch' configs/networks/flare.json | sponge configs/networks/flare.json
yarn run process-staking-rewards
# - name: Process staking rewards for ${{ env.USE_REWARD_EPOCH }}
# run: |
# jq --raw-output --monochrome-output '.NUM_EPOCHS = 1' configs/networks/flare.json | sponge configs/networks/flare.json
# jq --raw-output --monochrome-output --argjson epoch "$USE_REWARD_EPOCH" '.REWARD_EPOCH = $epoch' configs/networks/flare.json | sponge configs/networks/flare.json
# yarn run process-staking-rewards

- name: Combine rewards for [epoch ${{ env.USE_FIRST_REWARD_EPOCH }}-${{ env.USE_REWARD_EPOCH }}]
if: env.EPOCH_OF4_if0 == 0
run: |
jq --raw-output --monochrome-output '.NUM_EPOCHS = 4' configs/networks/flare.json | sponge configs/networks/flare.json
jq --raw-output --monochrome-output --argjson epoch "$USE_REWARD_EPOCH" '.REWARD_EPOCH = $epoch' configs/networks/flare.json | sponge configs/networks/flare.json
yarn sum-staking-rewards
# - name: Combine rewards for [epoch ${{ env.USE_FIRST_REWARD_EPOCH }}-${{ env.USE_REWARD_EPOCH }}]
# if: env.EPOCH_OF4_if0 == 0
# run: |
# jq --raw-output --monochrome-output '.NUM_EPOCHS = 4' configs/networks/flare.json | sponge configs/networks/flare.json
# jq --raw-output --monochrome-output --argjson epoch "$USE_REWARD_EPOCH" '.REWARD_EPOCH = $epoch' configs/networks/flare.json | sponge configs/networks/flare.json
# yarn sum-staking-rewards

- name: Commit generated-files
run: |
git config --global user.name 'Reward scripts automation'
git config --global user.email 'flare-foundation-reward-scripts-automation@users.noreply.github.com'
git add generated-files/reward-epoch-${{ env.USE_REWARD_EPOCH }}
if [ "$EPOCH_OF4_if0" -eq 0 ]; then git add generated-files/validator-rewards/epochs-${{ env.USE_FIRST_REWARD_EPOCH }}-${{ env.USE_REWARD_EPOCH }}.json; fi
git commit -m "Processed staking rewards for epoch ${{ env.USE_REWARD_EPOCH }}" && git push || echo "No changes were present, failed to commit, proceeding..."
# - name: Commit generated-files
# run: |
# git config --global user.name 'Reward scripts automation'
# git config --global user.email 'flare-foundation-reward-scripts-automation@users.noreply.github.com'
# git add generated-files/reward-epoch-${{ env.USE_REWARD_EPOCH }}
# if [ "$EPOCH_OF4_if0" -eq 0 ]; then git add generated-files/validator-rewards/epochs-${{ env.USE_FIRST_REWARD_EPOCH }}-${{ env.USE_REWARD_EPOCH }}.json; fi
# git commit -m "Processed staking rewards for epoch ${{ env.USE_REWARD_EPOCH }}" && git push || echo "No changes were present, failed to commit, proceeding..."

- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: staking-rewards
path: |
generated-files/reward-epoch-${{ env.USE_REWARD_EPOCH }}
generated-files/validator-rewards/epochs-${{ env.USE_FIRST_REWARD_EPOCH }}-${{ env.USE_REWARD_EPOCH }}.json
# - name: Upload artifacts
# uses: actions/upload-artifact@v3
# with:
# name: staking-rewards
# path: |
# generated-files/reward-epoch-${{ env.USE_REWARD_EPOCH }}
# generated-files/validator-rewards/epochs-${{ env.USE_FIRST_REWARD_EPOCH }}-${{ env.USE_REWARD_EPOCH }}.json

- name: Trigger "generate report" workflow
if: github.event.inputs.trigger_generate_report_workflow == 'true' || github.event.inputs.trigger_generate_report_workflow == ''
env:
GH_TOKEN: ${{ github.token }}
run: gh workflow run "Generate report" -f first_reward_epoch=${{ env.USE_REWARD_EPOCH }}
# - name: Trigger "generate report" workflow
# if: github.event.inputs.trigger_generate_report_workflow == 'true' || github.event.inputs.trigger_generate_report_workflow == ''
# env:
# GH_TOKEN: ${{ github.token }}
# run: gh workflow run "Generate report" -f first_reward_epoch=${{ env.USE_REWARD_EPOCH }}
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ You can also run it with optional parameters from [file](./src/processProviders.

For each run output of the process is in folder `generated-files/reward-epochs-<REWARD_EPOCH>`.

### Verifying the results
To verify the official results posted in this repository one needs to update its configuration file with values from the `configFileData` object of a `data.json` file for some reward epoch.
To verify the results for the reward epochs from 126 to 243 inclusive one needs to use branch `version-1`.

### Data for distributing rewards
Rewards will be distributed every four reward epochs, which means that every 14 days reward amounts from the past four reward epochs will be summed. This is achieved by running the process
Expand Down
Loading