Skip to content

CronJob - Base Sepolia #53

CronJob - Base Sepolia

CronJob - Base Sepolia #53

name: CronJob - Base Sepolia
on:
schedule:
- cron: "*/90 * * * *" # ie. 4:00pm, 5:30pm, 7:00pm, etc.
push:
env:
CHAIN_ID: 84532
PRIZE_POOL_ADDRESS: "0xc90625047f206f525a811a54bbec05c23e08b58b"
VAULT_ACCOUNTS_DIRECTORY_NAME: "vaultAccounts"
OUTPUT_DIRECTORY_NAME: "winners"
CLI_VERSION: "1.1.7"
FWC_RPC_URL: ${{ secrets.BASE_SEPOLIA_RPC_URL }}
JSON_RPC_URL: ${{ secrets.BASE_SEPOLIA_RPC_URL }}
NODE_OPTIONS: "--max_old_space_size=32768"
permissions: write-all
jobs:
runCLI:
name: Winners Compute
runs-on: ${{ matrix.os }}
strategy:
max-parallel: 1
matrix:
node: ["20.11.1"]
os: [ubuntu-latest]
steps:
- name: Checkout repo
uses: actions/checkout@v3
with:
submodules: recursive
- name: Use Node ${{ matrix.node }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
- name: Clone foundry-winner-calc repo
uses: actions/checkout@master
with:
repository: GenerationSoftware/foundry-winner-calc
path: './foundry-winner-calc'
# -------------------------------------------------------- #
# Base Sepolia
# -------------------------------------------------------- #
# 1. Install
- name: Install PoolTogether V5 CLI
run: |
npm install -g @generationsoftware/pt-v5-cli@${{ env.CLI_VERSION }}
echo "$(npm -g bin)" >> $GITHUB_PATH
# 2. Compute JSON input files (vault accounts)
- name: Base Sepolia Vault Accounts
id: vaultAccountsBaseSepolia
uses: chuckbergeron/executable-wrapper@f94b435740d6b958c2d7eb76c77657e761819cfe
continue-on-error: true
with:
working-directory: ./foundry-winner-calc
run_command: ptv5 utils vaultAccounts -o ./${{ env.VAULT_ACCOUNTS_DIRECTORY_NAME }} -p ${{ env.PRIZE_POOL_ADDRESS }} -c ${{ env.CHAIN_ID }}
# 3. Install package deps, build contracts
- name: Install deps and compile
run: |
cd ./foundry-winner-calc
npm install
npm run build
cd sol
forge install
forge build
cd ..
# 4. Store list of input JSON files in variable
- name: Finding files
working-directory: ./foundry-winner-calc
run: |
{
echo 'FILELIST<<EOF'
find ./${{ env.VAULT_ACCOUNTS_DIRECTORY_NAME }} -type f -name '0x*.json' -print
echo EOF
} >> "$GITHUB_ENV"
# 5. Loop through vault input files, compute winners
- name: Iterate vaults
id: processVaults
working-directory: ./foundry-winner-calc
run: |
for i in $FILELIST; do
echo "Processing: ${i}"
node index.js ${i} ../${{ env.OUTPUT_DIRECTORY_NAME }}/${i}
done
# 6. Concat winner output files into 1 winners.json file
- name: Concat Winner Files
uses: chuckbergeron/executable-wrapper@f94b435740d6b958c2d7eb76c77657e761819cfe
continue-on-error: true
with:
working-directory: ./${{ env.OUTPUT_DIRECTORY_NAME }}
run_command: ptv5 utils concatWinners -o ./${{ env.VAULT_ACCOUNTS_DIRECTORY_NAME }} -p ${{ env.PRIZE_POOL_ADDRESS }} -c ${{ env.CHAIN_ID }}
# 7. Commit
- name: Commit Base Sepolia
if: steps.vaultAccountsBaseSepolia.outputs.runStatus == 'true'
continue-on-error: true
run: |
git config pull.rebase false
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git pull
git add ./${{ env.OUTPUT_DIRECTORY_NAME }}
git commit -m "Add testnet winner results for Base Sepolia draw #${{ steps.vaultAccountsBaseSepolia.outputs.drawId }}"
# 8. Push
- name: Push changes (if required)
uses: ad-m/github-push-action@master
if: steps.vaultAccountsBaseSepolia.outputs.runStatus == 'true'
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref }}
force: true
# Optionally:
- name: Comment Error
id: commentError
if: steps.vaultAccountsBaseSepolia.outputs.exitcode == 1
uses: actions/github-script@v5
continue-on-error: true
with:
script: |
await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: `Draw #${{ steps.vaultAccountsBaseSepolia.outputs.drawId }} Winner Calc Failed: Exit Code 1`
})