Skip to content

bifrost-io/update_referendum

Repository files navigation

Script for Updating Referendum

A NestJS service that automatically updates vToken voting results based on the target chain's referendum outcomes.

The service can be triggered in two ways:

  1. Scheduled Task: Automatically runs at configured intervals (default: every Monday 9:00 AM)
  2. Manual Trigger: Can be triggered via HTTP endpoint anytime

1. Features

  • Monitors referendums on Polkadot, Kusama, and Bifrost chains
  • Automatically updates vToken voting results when target chain referendums conclude
  • Supports manual trigger via API endpoint
  • Configurable execution schedule via CRON expression

2. Quick Start

  1. Clone the repository:
git clone https://github.com/bifrost-finance/update_referendum.git
cd update_referendum
  1. Install dependencies:
yarn install
  1. Configure environment:
cp .env.example .env
# Edit .env with your settings
  1. Start the service:
yarn start
  1. Trigger manually:
curl -X POST http://localhost:8888/manual/update

3. Configuration

Create a .env file in the root directory:

# Required endpoints
BIFROST_ENDPOINT=wss://bifrost-polkadot-rpc.dwellir.com
POLKADOT_ENDPOINT=wss://rpc.polkadot.io
KUSAMA_ENDPOINT=wss://kusama-rpc.polkadot.io

# Vault configuration
# If VAULT_ADDR is not configured or NODE_ENV=development, will use test account //Alice
VAULT_ADDR=http://127.0.0.1:8200
VAULT_TOKEN=your_vault_token
KEY_NAME=your_key_name
VAULT_GOV_SECRET=your_gov_secret

# Environment
# development: use test account //Alice
# production: use account configured in Vault
NODE_ENV=development

# Schedule configuration (format: second minute hour day month weekday)
# Examples:
# "0 0 9 * * 1" - Execute every Monday at 9:00 AM
# "*/5 * * * * *" - Execute every 5 seconds
CRON_EXPRESSION="0 0 9 * * 1"

# Manual trigger:
# curl -X POST http://localhost:8888/manual/update

4. Testing

Unit Tests

Run unit tests:

yarn test

E2E Tests

Run E2E tests:

yarn test:e2e

Note: E2E tests use Chopsticks to simulate a local blockchain environment. Make sure you:

  1. Have a stable internet connection (for initial chain state download)
  2. Allow the tests enough time to complete (they may take several minutes)
  3. Ignore connection closure warnings after successful tests

Test Coverage

Generate test coverage report:

yarn test:cov

5. Architecture

  1. Query Task

    • Connects to all chains
    • Retrieves ongoing referendums from Bifrost vtokenVoting
    • Checks target chain referendum status
    • Returns referendums that need updating
  2. Construct Task

    • Constructs update transactions for each referendum
    • Batches transactions if multiple updates needed
    • Prepares governance proposal
  3. Governance Task

    • Submits governance proposal through Fellowship Bot
    • Handles preimage and proposal submission

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published