CronJob - Arbitrum Sepolia #10
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CronJob Arbitrum Sepolia | |
on: | |
schedule: | |
- cron: "*/90 * * * *" # ie. 4:00pm, 5:30pm, 7:00pm, etc. | |
push: | |
env: | |
CHAIN_ID: 421614 | |
PRIZE_POOL_ADDRESS: "0xdBBC646D78Ca1752F2DB6EA76DC467F740f9f816" | |
VAULT_ACCOUNTS_DIRECTORY_NAME: "vaultAccounts" | |
OUTPUT_DIRECTORY_NAME: "winners" | |
CLI_VERSION: "1.1.5" | |
FWC_RPC_URL: ${{ secrets.ARBITRUM_SEPOLIA_RPC_URL }} | |
ARBITRUM_SEPOLIA_RPC_URL: ${{ secrets.ARBITRUM_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' | |
# -------------------------------------------------------- # | |
# Arbitrum 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: Arbitrum Sepolia Vault Accounts | |
id: vaultAccountsArbitrumSepolia | |
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 Arbitrum Sepolia | |
if: steps.vaultAccountsArbitrumSepolia.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 Arbitrum Sepolia draw #${{ steps.vaultAccountsArbitrumSepolia.outputs.drawId }}" | |
# 8. Push | |
- name: Push changes (if required) | |
uses: ad-m/github-push-action@master | |
if: steps.vaultAccountsArbitrumSepolia.outputs.runStatus == 'true' | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
branch: ${{ github.ref }} | |
force: true | |
# Optionally: | |
- name: Comment Error | |
id: commentError | |
if: steps.vaultAccountsArbitrumSepolia.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.vaultAccountsArbitrumSepolia.outputs.drawId }} Winner Calc Failed: Exit Code 1` | |
}) |