Python SDK for VoteMarket - campaign management, proofs, and analytics
Project description
VoteMarket Toolkit
Python SDK for VoteMarket - campaign management, proofs, and analytics.
Installation
pip install votemarket-toolkit
Development Prerequisites
For development, this project uses uv for fast, reliable dependency management.
Install uv:
# macOS/Linux
curl -LsSf https://astral.sh/uv/install.sh | sh
# Windows
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
# Alternative: via pip
pip install uv
Alternative: Traditional pip/venv workflow
If you prefer not to use uv, you can use standard Python tools:
# Create virtual environment
python -m venv .venv
# Activate virtual environment
source .venv/bin/activate # macOS/Linux
# OR
.venv\Scripts\activate # Windows
# Install package in editable mode
pip install -e ".[dev]"
# Run commands directly
python -m votemarket_toolkit.cli --help
Quick Start
from votemarket_toolkit.campaigns.service import CampaignService
from votemarket_toolkit.shared import registry
# Get platform address
curve_platform = registry.get_platform("curve", chain_id=42161)
# Fetch campaigns
service = CampaignService()
campaigns = await service.get_campaigns(
chain_id=42161,
platform_address=curve_platform,
campaign_id=97
)
Features
- Campaign Management: Fetch, create, and manage VoteMarket campaigns
- Proof Generation: Generate merkle proofs for reward claims
- Analytics: Analyze historical performance and optimize parameters
- Multi-chain: Supports Ethereum, Arbitrum, and other networks
- Registry: Built-in platform and gauge registries
Services
CampaignService
Fetch and manage campaign data, lifecycle status, and proof insertion.
from votemarket_toolkit.campaigns import CampaignService
service = CampaignService()
campaigns = await service.get_campaigns(chain_id=42161, platform_address="0x...")
AnalyticsService
Access historical performance metrics from the VoteMarket analytics repository.
from votemarket_toolkit.analytics import get_analytics_service
analytics = get_analytics_service()
history = await analytics.fetch_gauge_history("curve", "0x...")
CampaignOptimizer
Calculate optimal campaign parameters using market data and historical performance.
from votemarket_toolkit.analytics import get_campaign_optimizer
optimizer = get_campaign_optimizer()
result = await optimizer.calculate_optimal_campaign(
protocol="curve",
gauge="0x...",
reward_token="0x...",
chain_id=1,
total_reward_tokens=10000
)
VoteMarketProofs
Generate merkle proofs for user and gauge rewards.
from votemarket_toolkit.proofs import VoteMarketProofs
proofs = VoteMarketProofs(chain_id=1)
gauge_proof = proofs.get_gauge_proof("curve", "0x...", epoch, block_number)
user_proof = proofs.get_user_proof("curve", "0x...", "0x...", block_number)
Web3Service
Multi-chain Web3 connections with contract interaction utilities.
from votemarket_toolkit.shared.services import Web3Service
web3 = Web3Service.get_instance(chain_id=1)
contract = web3.get_contract(address, "vm_platform")
LaPosteService
Handle wrapped/native token conversions for cross-chain rewards.
from votemarket_toolkit.shared.services.laposte_service import laposte_service
native_tokens = await laposte_service.get_native_tokens(chain_id, ["0x..."])
token_info = await laposte_service.get_token_info(chain_id, "0x...")
VotesService
Fetch and cache voting data for gauges.
from votemarket_toolkit.votes.services import VotesService
votes = VotesService()
gauge_votes = await votes.get_gauge_votes("curve", "0x...", start_block, end_block)
Configuration
Create .env file with RPC endpoints:
# Required for all chains
ETHEREUM_MAINNET_RPC_URL=https://eth-mainnet.g.alchemy.com/v2/YOUR_KEY
ARBITRUM_MAINNET_RPC_URL=https://arb-mainnet.g.alchemy.com/v2/YOUR_KEY
OPTIMISM_MAINNET_RPC_URL=https://opt-mainnet.g.alchemy.com/v2/YOUR_KEY
BASE_MAINNET_RPC_URL=https://base-mainnet.g.alchemy.com/v2/YOUR_KEY
POLYGON_MAINNET_RPC_URL=https://polygon-mainnet.g.alchemy.com/v2/YOUR_KEY
BSC_MAINNET_RPC_URL=https://bsc-dataseed.binance.org/
Examples
See examples/python for complete usage examples:
campaigns/list_all.py– Fetch campaigns across protocols with periods and rewardsusers/check_status.py– Check user proof status (block data, gauge data, user votes)proofs/generate.py– Build gauge and user proofs for claimsdata/calculate_efficiency.py– Model optimalmax_reward_per_votevalues
Check User Eligibility
Check if a user has claimable rewards across all campaigns:
# Check eligibility for all campaigns in a protocol
make check-user-eligibility USER=0x... PROTOCOL=curve
# Filter by specific gauge
make check-user-eligibility USER=0x... PROTOCOL=curve GAUGE=0x...
# Filter by chain
make check-user-eligibility USER=0x... PROTOCOL=balancer CHAIN_ID=42161
# Show only active campaigns
make check-user-eligibility USER=0x... PROTOCOL=curve STATUS=active
This command checks pre-generated proof data from the VoteMarket API to determine which periods have claimable rewards.
Unified CLI
You can use the unified CLI instead of individual scripts.
Examples:
-
Generate a user proof uv run -m votemarket_toolkit.cli proofs-user --protocol curve --gauge-address 0x... --user-address 0x... --block-number 18500000 [--chain-id 1]
-
Generate a gauge proof uv run -m votemarket_toolkit.cli proofs-gauge --protocol curve --gauge-address 0x... --current-epoch 1699920000 --block-number 18500000 [--chain-id 1]
-
List active campaigns uv run -m votemarket_toolkit.cli campaigns-active --protocol curve --chain-id 42161 uv run -m votemarket_toolkit.cli campaigns-active --platform 0x... --chain-id 42161
-
Check a user’s eligibility uv run -m votemarket_toolkit.cli users-eligibility --user 0x... --protocol curve [--gauge 0x...] [--chain-id 42161] [--status active|closed|all]
When installed from PyPI, the CLI is available as votemarket:
- votemarket proofs-user --protocol curve --gauge-address 0x... --user-address 0x... --block-number 18500000
Development
# Clone repository
git clone https://github.com/stake-dao/votemarket-proof-toolkit
cd votemarket-proof-toolkit
# Install dependencies (requires uv - see below)
uv sync
# Run examples
uv run examples/python/data/calculate_efficiency.py
uv run examples/python/data/get_token_prices.py
# Format and lint
make format # Format all code
make format FILE=path # Format specific file
# Build and publish
make build # Build package
make test-build # Test build locally
make deploy # Deploy to PyPI
# Development commands (see Makefile for full list)
make list-campaigns CHAIN_ID=42161 PLATFORM=0x...
make get-active-campaigns PROTOCOL=curve
make check-user-eligibility USER=0x... PROTOCOL=curve [GAUGE=0x...] [CHAIN_ID=1] [STATUS=active]
License
AGPL-3.0 License - see LICENSE
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file votemarket_toolkit-2.0.0.tar.gz.
File metadata
- Download URL: votemarket_toolkit-2.0.0.tar.gz
- Upload date:
- Size: 105.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cbd1656a8d06b723eeb826196a305a2f1b2957b1e7b9c8a899af66f366e3cb64
|
|
| MD5 |
cdc16fc098906a13d39106fe77e4b358
|
|
| BLAKE2b-256 |
8c601a306dafe08d3dd9e4f718c1fec9833cad892815136c3a5bd61628734d9a
|
File details
Details for the file votemarket_toolkit-2.0.0-py3-none-any.whl.
File metadata
- Download URL: votemarket_toolkit-2.0.0-py3-none-any.whl
- Upload date:
- Size: 138.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
738724207d09c594c450ee7145052abcc6502388712880479859d05a060af443
|
|
| MD5 |
9d85f2536457e0f1d1f1747f339f43a9
|
|
| BLAKE2b-256 |
c69cb6ef29b2a6690d49e6506958e2c154caa2e29a097b6a199d2e942757472a
|