Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cr_booster): add GHA workflow #660

Closed
wants to merge 2 commits into from
Closed
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
70 changes: 70 additions & 0 deletions .github/.scripts/boost.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { promises as fs } from 'fs'
import path from 'path'
//TODO: replace with actual implementation
;(async () => {
try {
// Define paths
const rootDir = process.cwd() // Assumes the script is run from the project root
const dataDir = path.join(rootDir, 'nft_boost_data')
const latestFilePath = path.join(dataDir, 'latest')
const jsonFileName = '0xDEADDEADDEADDEADDEADDEADDEADDEADDEADDEAD_666666.json'
const jsonFilePath = path.join(dataDir, jsonFileName)

// 1. Create folder nft_boost_data if it doesn't exist
try {
await fs.access(dataDir)
// Folder exists
} catch {
// Folder does not exist; create it
await fs.mkdir(dataDir)
console.log(`Directory created: ${dataDir}`)
}

// 2. Create file 'latest' in the nft_boost_data folder if it doesn't exist
try {
await fs.access(latestFilePath)
// File exists
} catch {
// File does not exist; create an empty file
await fs.writeFile(latestFilePath, '', 'utf8')
console.log(`File created: ${latestFilePath}`)
}

// 3. Create JSON file if it doesn't exist with the specified template
try {
await fs.access(jsonFilePath)
// File exists
} catch {
// File does not exist; create it with template content
const jsonData = {
nftContractAddress: '0xDEADDEADDEADDEADDEADDEADDEADDEADDEADDEAD_666666',
boostPercentage: 0,
calculationBlock: 0,
holders: {
// Example structure:
// "0xHolderAddress1": {
// estimatedRBTCRewards: 0,
// estimatedRIFRewards: 0,
// boostedRBTCRewards: 0,
// boostedRIFRewards: 0,
// tokenId: "0xTokenId"
// },
// "0xHolderAddress2": {
// estimatedRBTCRewards: 0,
// estimatedRIFRewards: 0,
// boostedRBTCRewards: 0,
// boostedRIFRewards: 0
// }
},
}
await fs.writeFile(jsonFilePath, JSON.stringify(jsonData, null, 2), 'utf8')
console.log(`JSON file created: ${jsonFilePath}`)
}

// 4. Make the latest file contain the JSON file name
await fs.writeFile(latestFilePath, jsonFileName, 'utf8')
console.log(`Latest file updated with content: ${jsonFileName}`)
} catch (error) {
console.error('Error:', error)
}
})()
61 changes: 61 additions & 0 deletions .github/workflows/booster.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Boost backers' rewards in an active NFT campaign

permissions:
contents: write

on:
workflow_dispatch:
inputs:
campaignId:
description: 'The ID of the active NFT campaign'
required: true
amount:
description: 'The amount of backers to boost'
required: true
nft:
description: 'The address of the NFT contract'
required: true

jobs:
boost:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
with:
persist-credentials: true

- name: Set up Node.js
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a
with:
node-version: '22'

- name: Install dependencies
run: npm install

- name: Switch to target branch for data
run: |
git fetch origin
git checkout -B boost-data

- name: Boost backers' rewards
run: |
npx tsx .github/.scripts/boost.ts \
--campaignId ${{ github.event.inputs.campaignId }} \
--amount ${{ github.event.inputs.amount }} \
--nft ${{ github.event.inputs.nft }}

- name: Commit and push changes
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global push.autoSetupRemote true

# Stage all changes
git add .

# Create a commit; if there are no changes, this command will fail, so we ignore that error.
git commit -m "Add files generated by boost script" || echo "No changes to commit"

# Push the commit back to the current branch
git push --force
Loading