A Slack bot that utilizes lockup smart contract queries to display information, monitor lockups and send periodic alerts.
-
Slack App Setup:
- Create a new Slack app at https://api.slack.com/apps
- Enable Socket Mode
- Add Bot Token Scopes:
chat:write,commands,app_mentions:read - Install the app to your workspace
- Get your Bot Token and App Token
-
Contract Information:
- Contract address of your deployed lockup contract
- RPC endpoint for the blockchain network
You can easily deploy the application by running:
./deploy.shCreate a .env file with the following variables:
# Slack Configuration
SLACK_BOT_TOKEN=your-bot-token-here
SLACK_APP_TOKEN=your-app-token-here
SLACK_CHANNEL=#alerts
# Contract Configuration
CONTRACT_ADDRESS=your-contract-address-here
RPC_ENDPOINT=https://rpc.c4e.io
CHAIN_ID=perun-1
# Monitoring Configuration
CHECK_TIME=09:00 # Time for daily checks (24-hour format)-
Create Slack App:
- Go to https://api.slack.com/apps
- Click "Create New App" -> "From scratch"
- Name your app
- Choose your workspace
-
Enable Socket Mode:
- Go to "Socket Mode" in your app settings
- Enable Socket Mode
- Generate an App-Level Token with
connections:writescope - This is your
SLACK_APP_TOKEN
-
Configure Bot:
- Go to "OAuth & Permissions"
- Add Bot Token Scopes:
chat:write- Send messagescommands- Use slash commandsapp_mentions:read- Respond to mentionsfiles:write- Upload files (for lockups export)
- Install app to workspace
- Copy the "Bot User OAuth Token" as your
SLACK_BOT_TOKEN
-
Add Slash Commands (Optional):
- Go to "Slash Commands"
- Create command
/check-contract - Description: "Check contract coin availability"
- Create command
/export-lockups - Description: "Export all lockups data as files"
-
Enable Events:
- Go to "Event Subscriptions"
- Enable Events
- Subscribe to
app_mentionbot event
The bot automatically runs daily checks at the configured time (CHECK_TIME). If coin availability is insufficient, it sends an alert like:
!! INSUFFICIENT COIN AVAILABILITY ALERT !!
Time: 2025-08-26 09:00:00
Contract: c4e.....
Status: Insufficient funds available for rewards
Available Rewards: 1000000 uc4e
Required Per Year: 2000000 uc4e
Active Lockups: 5
Total Principal: 10000000 uc4e
Action Required: Please deposit additional rewards.
-
Slash Command: Type
/check-contractin any channel where the bot is present -
Mention: Mention the bot with "check" or "status":
@Contract Monitor check status
Export all lockups data from the contract as downloadable files:
-
Slash Command: Type
/export-lockupsin any channel where the bot is present -
Mention: Mention the bot with "export" or "lockups":
@Contract Monitor export lockups
The bot will upload two files to the channel:
- JSON file: Raw lockups data in JSON format for programmatic use
- CSV file: Spreadsheet-friendly format for analysis in Excel/Google Sheets
Example export message:
All Lockups Export
Time: 2025-08-26 14:30:00
Contract: c4e.....
Format: JSON/CSV
The bot sends daily status updates showing:
- Current coin availability status
- Available reward funds
- Required rewards per year
- Number of active lockups
- Total principal locked
The bot uses these smart contract queries:
CheckCoinAvailability: Main query to check if sufficient funds are availableGetDepositedRewards: Get current available reward fundsGetAllRewards: Get total required rewards per yearGetSumLockupsAndDeposits: Get lockup statisticsGetAllLockups: Retrieve all lockups data for export functionality
Logs are written to logs/slack_monitor_bot.log and include:
- Daily check results
- Error messages
- Slack message sending status
- Contract query responses
To enable debug logging, modify the logging level in the script:
logging.basicConfig(level=logging.DEBUG, ...)The lockups export creates two file formats:
-
JSON Format: Contains the raw contract response data, preserving all nested structures and data types.
-
CSV Format: Flattened view of the data suitable for spreadsheet applications.
To check more frequently than daily, modify the schedule line:
# Check every hour
schedule.every().hour.do(daily_check)
# Check every 30 minutes
schedule.every(30).minutes.do(daily_check)