Staking APIs
Getting Started

Getting Started

📋

This document is for Game Partners who need to integrate YGG Staking APIs into their systems. It provides a clear reference for accessing user staking data.

What You Need to Know

User Identification

We use Wallet Addresses on the Abstract Chain (abs.xyz (opens in a new tab)) to identify users across all partner games.

7-Day Average Calculation

YGG calculates a 7-day average staked amount for each user based on their minimum daily staked balance. This ensures fair reward distribution and prevents gaming the system.

Daily Snapshots

Staking snapshots are taken at 00:00 UTC daily. The minimum staked balance during each 24-hour period is used for the 7-day average calculation.

No Lock-in Period

Users can stake and unstake anytime. There is no cooldown or lock-in period, providing maximum flexibility.

Staking Mechanics

How Staking Works

  1. Users stake tokens on YGG Play Platform
  2. YGG records minimum balance every 24 hours (00:00 UTC)
  3. 7-day average is calculated using last 7 daily minimums
  4. Partners query staking data via API
  5. Partners reward users based on their staking tier

Calculation Example

Here's how the 7-day average is calculated:

// Daily minimum staked amounts for past 7 days
const dailyMinimums = [0, 100, 300, 150, 150, 650, 650]
 
// Calculate 7-day average
const sum = dailyMinimums.reduce((a, b) => a + b, 0)
const average = sum / 7
 
console.log(`7-Day Average: ${average} tokens`) // 285.71 tokens

Important Notes

Minimum Balance Period: The daily snapshot uses the minimum balance during the 24-hour period, not the balance at 00:00 UTC. This prevents users from temporarily staking large amounts just before the snapshot.

Integration Flow

Typical Implementation

  1. Player logs into game

    • Game calls YGG Staking API with player's wallet address
  2. Receive staking data

    • Get 7-day average staked amount
    • Get historical snapshots (optional)
  3. Determine player tier

    • Calculate tier based on 7-day average
    • Display tier in game UI
  4. Distribute rewards

    • Apply tier-based benefits
    • Grant in-game items/boosts
    • Enable special event perks

Example Integration

// When player logs in
async function handlePlayerLogin(walletAddress) {
  // Call YGG Staking API
  const stakingData = await getStakeSnapshots(walletAddress, 7)
  
  // Determine player's tier
  const tier = calculateTier(stakingData.averageStakedAmount)
  
  // Apply tier benefits
  await applyTierBenefits(player, tier)
  
  // Display in UI
  showPlayerTier(tier, stakingData.averageStakedAmount)
}
 
function calculateTier(averageAmount) {
  if (averageAmount >= 1000000) return 10 // Ultimate
  if (averageAmount >= 500000) return 9   // Grandmaster
  if (averageAmount >= 100000) return 8   // Master
  if (averageAmount >= 50000) return 7    // Champion
  if (averageAmount >= 10000) return 6    // Elite
  if (averageAmount >= 5000) return 5     // Legendary League
  if (averageAmount >= 1000) return 4     // MVP League
  if (averageAmount >= 500) return 3      // All-Star League
  if (averageAmount >= 100) return 2      // Pro League
  return 1                                // Rookie League
}
💡

Customize Your Tiers: Tier names, thresholds, and rewards should align with your game's economy and design.

Reward Distribution Strategies

Daily Rewards

  • Check staking tier at daily login
  • Grant daily rewards based on current tier
  • Rewards can vary by tier level

Weekly Rewards

  • Calculate total rewards for the week
  • Distribute at end of week
  • Bonus for maintaining high tier all week

Event-Based Rewards

  • Unlock special abilities during events
  • Access to exclusive event areas
  • Enhanced event rewards per tier

Progressive Unlocks

  • Higher tiers unlock new gameplay features
  • Access to premium game modes
  • Exclusive cosmetics or characters

Fair Play

  • Use 7-day average (not instant balance) for tier determination
  • Apply tier benefits fairly across all players
  • Communicate clearly about tier requirements

Error Handling

  • Default to lowest tier if API is unavailable

Next Steps

  1. Review Authentication requirements
  2. Explore the API Reference
  3. Test integration with YGG development team
  4. Implement tier logic in your game
  5. Go live with production endpoints
💬

Have questions? Contact our team for support during integration.