> For the complete documentation index, see [llms.txt](https://agent-precision.gitbook.io/skor-ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://agent-precision.gitbook.io/skor-ai/4-skor-ai-agent-staking-project.md).

# 4️⃣ SKOR AI Agent Staking Project

## 1. Overview <a href="#id-1.-overview" id="id-1.-overview"></a>

We're also bringing DeFi into the gaming world with Solana-based staking. Users can stake their $SKOR tokens to earn rewards through a structured tier and duration model — directly integrated into our platform. This creates a self-sustaining ecosystem where gamers grow both in skill and value.

## 2. Staking Model & Tokenomics <a href="#id-2.-staking-model-and-tokenomics" id="id-2.-staking-model-and-tokenomics"></a>

**Total Supply:** 1,000,000,000 tokens                                                                                                                  &#x20;

### **Staking Reward Pool**

* **Total:** 300,000,000 tokens distributed over 60 months
* **Monthly Cap:** Maximum of 5,000,000 tokens distributed per month

### **Staking Structure**

* **Tiers:**
  * **Bronze:** 100  -  99,999
  * **Silver:** 100,000  -  299,999
  * **Gold:** 300,000 + tokens
* **Staking Durations:**
  * Options: 60, 90, 180, 365 days
  * *Note:* Early withdrawals are not allowed.
* **Rewards:**
  * Flat rewards paid at the end of the lock period
  * Annualized APYs, pro-rated for shorter durations

### **APY Table (Annualized Rates, Pro-Rated for Duration)**

| Tier   | 60 Days | 90 Days | 180 Days | 365 Days |
| ------ | ------- | ------- | -------- | -------- |
| Bronze | 8 %     | 12 %    | 16 %     | 20 %     |
| Silver | 12 %    | 18 %    | 24 %     | 30 %     |
| Gold   | 16 %    | 24 %    | 32 %     | 40 %     |

{% hint style="info" %}

Limited Time Offer ( Upto an additional 40% APY )
{% endhint %}

### **Example Calculation:**

For a Silver-tier user staking 100,000  tokens for 90 days:

* **Duration:** 90 days (¼ year)
* **APY:** 18 % annualized → Pro-rated APY = 18% / 4 = 4.5 %
* **Reward:** 100,000 × 4.5 % = 4,500 tokens
* **Maturity Amount:** 100,000 + 4,500 = 104,500 token

## 3. Backend Architecture & Components <a href="#id-3.-backend-architecture-and-components" id="id-3.-backend-architecture-and-components"></a>

### **A. Blockchain Integration (Solana)**

* **Smart Contracts:** Written in Rust using the Solana program library.
* **On-Chain Storage:** State is maintained on Solana, holding staking records and token balances.
* **Communication: Okto Smart** Wallet integration and Paymaster for front-end interactions.

### **B. Off-Chain Services**

* **Calculation Engine:** Handles reward computations and staking simulations.
* **APIs:** Expose endpoints for staking, checking rewards, and user account management.

## 4. Reward Calculation Logic <a href="#id-4.-reward-calculation-logic" id="id-4.-reward-calculation-logic"></a>

Reward calculations are based on the annualized APY, the staking tier, and the chosen lock duration. The reward is prorated for shorter terms.

### **Calculation Formula:**

For a given stake:

* **Reward = Staked Tokens × (APY ÷ (365 / Duration in Days))**

For example, using the Silver-tier for 90 days:

* Reward = 20,000 tokens × (11% / 4) = 550 tokens

### **Code Example (Rust)**

Below is a simplified Rust function that performs the calculation. This code would be part of your on-chain program or a simulation module.

```rust
/// Returns the reward for a given stake, APY (annualized in percentage),
/// and duration (in days). Reward is calculated as:
/// Reward = stake * ((apy/100) / (365 / duration))
pub fn calculate_reward(stake: u64, apy: f64, duration_days: u64) -> u64 {
    let annual_fraction = duration_days as f64 / 365.0;
    let reward = (stake as f64) * (apy / 100.0) * annual_fraction;
    reward.round() as u64
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_calculate_reward_90_days_silver() {
        // Silver Tier, 90 days APY of 11%, stake of 20,000 tokens.
        let stake = 20_000;
        let apy = 11.0;
        let duration = 90;
        // Expected reward = 20,000 * (11/100) * (90/365) ≈ 20,000 * 0.11 * 0.2466 = 543 tokens (approx)
        let reward = calculate_reward(stake, apy, duration);
        assert!((reward as i64 - 543).abs() <= 1, "Expected reward around 543 tokens, got {}", reward);
    }

    #[test]
    fn test_calculate_reward_365_days_gold() {
        // Gold Tier, 365 days APY of 20%, stake of 100,000 tokens.
        let stake = 100_000;
        let apy = 20.0;
        let duration = 365;
        // Expected reward = 50,000 * 0.20 * (365/365) = 10,000 tokens
        let reward = calculate_reward(stake, apy, duration);
        assert_eq!(reward, 10_000);
    }
}
```

### **Explanation:**

* **Function:** `calculate_reward` computes rewards based on the input parameters.
* **Testing:** Unit tests (using Rust’s built-in framework) verify that the reward calculations meet expected values.
* **TDD Note:** By writing tests first, then developing logic to pass these tests, you ensure that your calculation engine meets the business rules.

## 5. Test Driven Development (TDD) Strategy <a href="#id-5.-test-driven-development-tdd-strategy" id="id-5.-test-driven-development-tdd-strategy"></a>

TDD will be our guiding development methodology. The process is as follows:

1. **Write Tests:** For every new feature or bug fix, write a failing test.
2. **Implement Code:** Develop the code necessary to pass the test.
3. **Refactor:** Clean up the code, ensuring tests continue to pass.
4. **Repeat:** Iterate for every new piece of functionality.

### **Additional TDD Practices:**

* **Integration Tests:** Simulate entire staking flows, including token transfers, locking periods, and reward payouts.
* **Simulation Scripts:** Use off-chain simulations to model monthly reward budgets under different staking scenarios.

### **Example Simulation (Pseudocode in JavaScript)**

For further testing outside the on-chain environment, you might want a simulation script written in JavaScript using a framework like Mocha:

Copy

```javascript
// calculateReward.js
function calculateReward(stake, apy, durationDays) {
  const annualFraction = durationDays / 365;
  return Math.round(stake * (apy / 100) * annualFraction);
}

module.exports = { calculateReward };
```

Copy

```javascript
// test/calculateReward.test.js
const assert = require('assert');
const { calculateReward } = require('../calculateReward');

describe('calculateReward function', function() {
  it('should calculate reward for 90 days stake (Silver Tier)', function() {
    const stake = 20000;
    const apy = 11;
    const durationDays = 90;
    // Expected reward ≈ 543 tokens
    const reward = calculateReward(stake, apy, durationDays);
    assert(Math.abs(reward - 543) <= 1);
  });
  
  it('should calculate reward for 365 days stake (Gold Tier)', function() {
    const stake = 50000;
    const apy = 20;
    const durationDays = 365;
    // Expected reward = 10,000 tokens
    const reward = calculateReward(stake, apy, durationDays);
    assert.strictEqual(reward, 10000);
  });
});
```

### **Running Tests**

* **Rust Tests:** Run with `cargo test` to ensure all unit tests in your Solana program pass.
* **JavaScript Tests:** Run `npm test` (assuming you set up Mocha/Chai) to validate off-chain simulation logic.

## 6. Simulations and Monthly Reward Budget <a href="#id-6.-simulations-and-monthly-reward-budget" id="id-6.-simulations-and-monthly-reward-budget"></a>

The following are simulations that validate monthly reward distributions:

### **Simulation Scenarios**

1. **10% of Supply Staked (100M tokens)**
   * **Breakdown Example:**
     * Bronze: 50M tokens at 9.5% APY → Annual Reward: 4.75M tokens
     * Silver: 35M tokens at 12% APY → Annual Reward: 4.2M tokens
     * Gold: 15M tokens at 16% APY → Annual Reward: 2.4M tokens
   * **Monthly Reward:** Approximately 0.95M tokens
2. **20% of Supply Staked (200M tokens)** ...
3. **30% of Supply Staked (300M tokens)**
4. **40% of Supply Staked (400M tokens)**
5. **50% of Supply Staked (500M tokens)**

Each simulation confirms that the reward distribution is within the monthly cap, ensuring a 2M token buffer under the maximum monthly distribution of 5M tokens.
