A comprehensive TypeScript library for managing Smart Rewards campaign operations, including campaign data fetching, rewards calculation, on-chain claim execution, and automated campaign creation with wallet management.
- 🎯 Campaign Management: Fetch and manage campaigns with pagination support
- 💰 Rewards Calculation: Calculate claimable rewards with precision
- 🔗 On-chain Claims: Execute claims directly on blockchain
- 🚀 Campaign Creation: Create reward campaigns on Sonic and other EVM chains
- 🏷️ Token Enrichment: Fetch token metadata automatically
- ⚡ GraphQL Client: Efficient campaign data querying
- 🛡️ Error Handling: Comprehensive error handling and validation
- 📊 CLI Interface: Command-line interface for operations
- 🔐 Wallet Management: Secure encrypted wallet handling
# Install dependencies
yarn install
# Build the project
yarn build
# Start the application
yarn startimport { SmartRewardsClient, fetchCampaignsByChainId } from 'smart-rewards-campaign-ops';
// Simple campaign fetching
const campaigns = await fetchCampaignsByChainId(1); // Ethereum mainnet
console.log(`Found ${campaigns.totalCount} campaigns`);
// Advanced usage with Smart Rewards client
const client = new SmartRewardsClient();
const result = await client.processCampaign(userAddress, chainId, campaignId);
// Check claimable rewards
const canClaim = await client.canUserClaim(userAddress, chainId, campaignId);
if (canClaim.canClaim) {
console.log(`Can claim ${canClaim.remaining} ${canClaim.rewardTokenSymbol}`);
}# Run Smart Rewards CLI
yarn cli
# Create a campaign on Sonic
yarn create-campaign --config campaign-config.json
# Create campaign with environment variables
WALLET_PASSPHRASE=mypass yarn create-campaign --config config.json
# Development mode
yarn devCreate reward campaigns on Sonic and other EVM-compatible chains:
import { createSonicCampaign } from 'smart-rewards-campaign-ops';
// Create a campaign on Sonic
const result = await createSonicCampaign(
{
identityFile: 'wallets/identity.json',
passphrase: process.env.WALLET_PASSPHRASE!
},
{
poolAddress: '0xYourPoolAddress',
rewardTokenAddress: '0xYourTokenAddress',
escrowAmount: '5',
durationInDays: 7,
startDelayInHours: 1,
metadata: {
name: 'Boost liquidity',
description: 'Increase liquidity in vault',
protocol: 'ThickV2',
category: 'Liquidity Boost',
campaignType: 'token_balance_rewards',
execution_bundle: 'QmYourIPFSHash'
}
}
);
console.log('Campaign created:', result.transactionHash);
console.log('Campaign ID:', result.campaignId);For detailed campaign creation documentation, see CAMPAIGN_CREATION.md.
src/
├── index.ts # Main entry point and exports
├── types/ # Type definitions
│ └── index.ts # All TypeScript type definitions
├── clients/ # API and external service clients
│ ├── graphql-client.ts # GraphQL client for campaign queries
│ ├── smart-rewards-client.ts # Smart Rewards GraphQL operations
│ └── token-enrichment.ts # Token metadata fetching
├── core/ # Core business logic
│ ├── smart-rewards.ts # Main Smart Rewards orchestration
│ ├── calculations.ts # Reward calculation utilities
│ └── pagination.ts # Pagination utilities
├── blockchain/ # Blockchain-related functionality
│ ├── onchain-claim.ts # On-chain claim execution
│ └── campaign-creation.ts # Campaign creation on blockchain
├── abi/ # Smart contract ABIs
│ ├── ERC20.json # ERC20 token ABI
│ └── SmartRewardsTimestamp.json # SmartRewards contract ABI
├── utils/ # Utility functions
│ └── error-handler.ts # Error handling and validation
└── cli/ # Command-line interface
├── smart-rewards-cli.ts # Smart Rewards CLI
└── create-campaign.ts # Campaign creation CLI
# Development with watch mode
yarn build:watch
# Type checking
yarn type-check
# Linting
yarn lint
yarn lint:fix
# Testing
yarn test
yarn test:watchThe project uses TypeScript with strict mode enabled and includes:
- ESLint: Code linting with TypeScript rules
- Jest: Testing framework with TypeScript support
- Prettier: Code formatting (via ESLint)
- Build: TypeScript compilation with declarations
Main client for Smart Rewards operations:
processCampaign(user, chainId, campaignId): Complete campaign processinggetClaimProofs(user, chainId, campaignId): Get claim proofscalculateRewards(user, chainId, campaignId): Calculate rewardsexecuteClaim(chainId, proofs, decimals): Execute on-chain claim
Campaign data fetching:
fetchCampaignsByChainId(chainId, options): Fetch all campaignsfetchCampaignsPage(chainId, cursor, pageSize): Paginated fetchingprocessCampaignsInChunks(chainId, processor): Process in chunks
Campaign creation on blockchain:
loadWallet(walletConfig): Load encrypted walletapproveTokens(tokenAddress, amount): Approve token spendingcalculateCampaignTiming(startDelay, duration): Calculate timestampscreateCampaign(campaignParams): Create campaign on-chain
RewardCalculator: Reward calculations and unit conversionsTokenEnrichmentClient: Token metadata fetchingPaginationManager: Pagination handlingErrorHandler: Error handling and validationOnChainClaimClient: On-chain claim execution
MIT License - see LICENSE file for details.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
For issues and questions, please create an issue in the repository.