Kodiak Finance
  • OVERVIEW
    • 🐻‍❄️Introducing Kodiak
    • 🐻Kodiak x Berachain
    • ✉️Contact Us
    • 🍯Kodiak Contracts
  • 🅱️Kodiak-Boyco
  • PROTOCOL
    • 🔃DEX
      • Swaps
      • Liquidity Provision
      • Trading Fees
    • 🏝️Islands
      • Island Liquidity Provision
      • Sweetened Islands
      • Island Mechanics
        • Auto-BGT
        • Real-time Security
        • Rebalancing
        • Strategies
    • 🐼Panda Factory
  • 🪙Tokenomics
    • Kodiak Pre-TGE Rewards
  • 🧠User Guide
    • Launch a Token Launch on Panda Factory
    • Trading on Panda Factory
    • Swap
    • Create a V2 Position
    • Create a V3 Position
    • Add/Stake Islands Liquidity
    • Migrating to a Reward Vault
    • Deploying new Permissonless Islands
    • Deploying and Configuring a Kodiak Farm
    • Add your token
  • Add Your Project to the Ecosystem
  • 👨‍💻Developers
    • 🐼Panda
      • Technical Integration Guide
      • Subgraph
        • Entity Reference
        • Query Guide
        • Advanced Usage Guide
      • Smart Contract Reference
        • Panda Factory
        • Panda Pool
        • Panda Token
      • Api
    • Farms
      • Technical Integration Guide
      • Smart Contract Reference
    • 🌴Kodiak Islands
      • Technical Integration Guide
        • Understanding Token Deposit Ratio
      • Subgraph
        • Entity Reference
        • Query Guide
        • Advanced Usage Guide
      • Smart Contract Reference
        • Kodiak Island Factory
        • Kodiak Island
        • Kodiak Island Router
      • Api
    • 💰Pricing with Subgraph
    • 💱Quotes
    • Backend
  • 🛡️SECURITY
    • 🔍Audits
    • Page
  • ℹ️Informational
    • 📜Terms of Use
    • 🔏Privacy Policy
    • TradingView Advanced License
Powered by GitBook
On this page
  1. Developers
  2. Farms

Technical Integration Guide

Overview

KodiakFarm is an advanced staking protocol that implements a dynamic reward system with time-locked staking mechanisms. The protocol enables users to stake ERC20 tokens and earn multiple reward types simultaneously, with rewards amplified through a duration-based multiplier system. This implementation focuses on flexibility, security, and capital efficiency through its sophisticated architecture:

  • Dynamic Multi-Token Reward System: Supports multiple reward tokens that can be added or modified post-deployment

  • Time-Weighted Multipliers: Rewards scale with lock duration, incentivizing longer-term commitment

  • Advanced Security Architecture: Multi-layered access control system with distinct roles and permissions

  • Adaptive Reward Management: Intelligent reward rate adjustment based on token availability and distribution metrics

  • Risk Mitigation Features: Comprehensive safety controls including emergency withdrawals, staking caps, and granular pause mechanisms

  • Capital Efficiency: Optimized reward distribution with configurability for different token economics models

Technical Details

Initialization and Setup

  1. Deployment Flow

    • Deploy the contract through the FarmFactory

    • Initialize with owner, staking token, reward tokens, managers, and rates

    • Fund the contract with reward tokens

    • Call startFarm() to begin operations

  2. Reward Configuration

    struct RewardConfig {
        address token;
        address manager;
        uint256 rate;
    }
    • Multiple reward tokens can be configured

    • Each token has its own manager and rate

    • Additional reward tokens can be added post-deployment

  3. Staking Mechanism

    struct LockedStake {
        bytes32 kek_id;
        uint256 start_timestamp;
        uint256 liquidity;
        uint256 ending_timestamp;
        uint256 lock_multiplier;
    }
    • Users lock tokens for a specified duration

    • Lock duration affects reward multiplier

    • Multiplier ranges from 1x to 3x (configurable)

Integration Steps

  1. Contract Setup

    const farm = await KodiakFarm.deploy();
    await farm.initialize(
        owner,
        stakingToken,
        rewardTokens,
        rewardManagers,
        rewardRates
    );
  2. Token Approvals

    // Approve staking token
    await stakingToken.approve(farmAddress, amount);
    // Approve reward tokens (for managers)
    await rewardToken.approve(farmAddress, rewardAmount);
  3. Staking Integration

    // Lock tokens
    await farm.stakeLocked(amount, lockDuration);
    
    // Withdraw tokens
    await farm.withdrawLocked(kekId);
    
    // Claim rewards
    await farm.getReward();
  4. Event Handling

    farm.on('StakeLocked', (user, amount, secs, kekId) => {
        // Handle stake locked event
    });
    
    farm.on('RewardPaid', (user, reward, tokenAddress) => {
        // Handle reward payment
    });

Best Practices

  1. Security Considerations

    • Always verify reward token balances before setting rates

    • Implement frontend checks for lock duration limits

    • Monitor total staked amounts against cap

    • Handle emergency scenarios through proper channels

  2. Gas Optimization

    • Batch withdrawals using withdrawLockedMultiple

    • Use withdrawLockedAll for mass withdrawals

    • Consider gas costs when setting reward periods

  3. Error Handling

    • Implement proper error handling for failed transactions

    • Monitor for paused states (staking, withdrawals, rewards)

    • Handle grey-listed address scenarios

PreviousFarmsNextSmart Contract Reference

Last updated 2 months ago

👨‍💻