Skip to content

Calculate rewards

Calculate rewards #109

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'
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"
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"
- 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: 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: 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 }}