Skip to main content

Overview

This example demonstrates how to integrate ZKScore contracts with a DeFi protocol to track user activity, calculate DeFi scores, and reward protocol participation.

DeFi Integration Example

class DeFiProtocolIntegration {
  constructor(protocolContract, zkScoreContracts) {
    this.protocol = protocolContract;
    this.zkScore = zkScoreContracts;
  }
  
  async trackLiquidityProvision(user, amount) {
    // Update protocol activity
    await this.protocol.provideLiquidity(user, amount);
    
    // Update ZKScore
    await this.zkScore.scoreCalculator.updateCategoryScore(user, 0, amount / 1000);
    
    // Check achievements
    const liquidityAchievements = [100, 101, 102]; // Different tiers
    for (const id of liquidityAchievements) {
      const canClaim = await this.zkScore.achievementRegistry.canClaim(user, id);
      if (canClaim) {
        await this.zkScore.achievementRegistry.claimAchievement(id, '0x');
      }
    }
  }
}

Best Practices

  1. Real-time Updates: Update scores as activities occur
  2. Achievement Tracking: Auto-claim eligible achievements
  3. Event Integration: Sync protocol events with ZKScore
  4. Gas Optimization: Batch updates when possible