An automated solution for maintaining target APY rates in Active Staking Rewards (ASR) pools on Solana by intelligently calculating and executing token top-ups based on current pool metrics and funding periods.
This script monitors Solana staking pools and automatically transfers tokens to reward pools when needed to maintain target Annual Percentage Yield (APY) rates. It supports multiple pools with different APY targets and funding intervals, with built-in safety checks, webhook notifications, and dry-run capabilities.
- π― Automated APY Management: Maintains target APY rates across multiple staking pools
- β° Flexible Scheduling: Configurable funding periods (hourly, daily, etc.)
- π Smart Notifications: Webhook alerts for low balances, errors, and important events
- π§ͺ Dry Run Mode: Test configurations without executing transactions
- π CSV Reporting: Detailed transaction logs and pool metrics
- π‘οΈ Safety Checks: Balance validation and transaction cost estimation
- β‘ Rate Limiting: Built-in throttling to prevent network overload
- Node.js: Version 21 or higher (v22 recommended)
- pnpm: Package manager
- Solana Wallet: Private key(s) for funding wallet(s)
- RPC Access: Solana RPC endpoint URL
# Use the correct Node.js version
nvm use
# Install dependencies
pnpm installCreate a .env file in the project root:
# Required Settings
# Solana Network
RPC_URL=https://api.mainnet-beta.solana.com
# Pool Configuration (JSON string - see example below)
POOL_CONFIGS=[{"id":"1","name":"Example Pool",...}]
# Execution Settings
PERIOD_IN_MINUTES=60
# Optional Settings
DRY_RUN=0
DEBUG_LOG=false
WEBHOOK_URL=https://your-webhook-endpoint.com/notify
SOL_BALANCE_WARNING_THRESHOLD=5000000The POOL_CONFIGS should be a JSON string containing an array of pool configurations:
[
{
"id": "1",
"name": "Pool 1",
"stakePoolAddress": "YourStakePoolAddressHere",
"privateKey": "your-base58-private-key-or-uint8array-string",
"targetAPY": 5,
"fundingPeriodMinutes": 60,
"feeValue": "YourPDAFromStreamflowHere",
"isToken2022": true
},
{
"id": "2",
"name": "Pool 2",
"stakePoolAddress": "YourStakePoolAddressHere",
"privateKey": "your-base58-private-key-or-uint8array-string",
"targetAPY": 8,
"fundingPeriodMinutes": 360,
"feeValue": "YourPDAFromStreamflowHere",
"isToken2022": false
}
]| Variable | Required | Description | Example |
|---|---|---|---|
RPC_URL |
β | Solana RPC endpoint | https://api.mainnet-beta.solana.com |
POOL_CONFIGS |
β | JSON array of pool configurations | See example above |
PERIOD_IN_MINUTES |
β | Funding period to process (filters pools) | 60, 360, 1440, etc |
DRY_RUN |
β | Run without executing transactions | 0 or 1 |
DEBUG_LOG |
β | Enable verbose logging | true or false |
WEBHOOK_URL |
β | Endpoint for notifications | https://discord.com/api/webhooks/... |
SOL_BALANCE_WARNING_THRESHOLD |
β | Low balance alert threshold (lamports) | 5000000 |
# Production run
pnpm run start
# Dry run (no transactions executed)
DRY_RUN=1 pnpm run start
# With debug logging
DEBUG_LOG=true pnpm run startpnpm run testpnpm run format- Pool Filtering: Script filters configured pools by
PERIOD_IN_MINUTES - Balance Checks: Validates SOL and token balances in funding wallets
- APY Calculation: Determines required tokens to maintain target APY
- Safety Validation: Estimates transaction costs and checks balances
- Execution: Transfers tokens to reward pools (unless in dry-run mode)
- Reporting: Logs results and writes CSV output to
/tmp/result.csv - Notifications: Sends alerts for errors, low balances, or important events
This script supports automated execution via GitHub Actions. The .github/workflows directory contains example workflow files for different intervals.
To set up automated execution:
- Copy an example workflow file
- Modify the cron schedule using Crontab Guru
- Configure repository secrets for environment variables
- Enable GitHub Actions in your repository
# Run every hour
schedule:
- cron: '0 * * * *'
# Run every 6 hours
schedule:
- cron: '0 */6 * * *'
# Run daily at 12:00 UTC
schedule:
- cron: '0 12 * * *'- Store private keys securely using GitHub Secrets
- Use dedicated funding wallets with minimal required balances
"RPC_URL is required" Error
- Ensure
RPC_URLis set in your environment variables - Verify the RPC endpoint is accessible and responsive
"Not enough SOL balance" Warning
- Check your funding wallet SOL balance
- Adjust
SOL_BALANCE_WARNING_THRESHOLDif needed - Add more SOL to the funding wallet
"POOL_CONFIGS are required" Error
- Verify
POOL_CONFIGSis valid JSON - Check that all required fields are present in each pool config
No Pools Processed
- Ensure
PERIOD_IN_MINUTESmatches at least one pool'sfundingPeriodMinutes - Check that pools are configured correctly
Enable debug logging for detailed execution information:
DEBUG_LOG=true pnpm run startThe script generates:
- Console logs: Real-time execution status and results
- CSV file: Detailed results written to
/tmp/result.csv - Webhook notifications: Alerts sent to configured endpoint (if configured)
| Timestamp | Pool ID | Pool Name | Staked Amount | Funder Token Account Balance | Total Top-up Amount | Tx Signature |
|---|
Apache 2.0