Nevix
  • Protocol Overview
  • Protocol Architecture
  • Mathematical Foundation
  • Protocol Flow
  • Staking Process
  • Technical Implementation
    • Solana Program
    • Account Structure
    • Client Integration
  • Socials
    • X
  • Telegram
  • Website
Powered by GitBook
On this page
  1. Technical Implementation

Client Integration

// JavaScript client example

// Calculate reward for a stake
function getRewards(stake) {
  let timeElapsed = new Date().getTime() - stake.lastClaim;
  let base_hour_adjuster = getVaultBaseHour();
  const timeHours = timeElapsed / 1000 / 60 / 60;
  if (timeHours >= base_hour_adjuster) {
    let held_hours = Math.min(timeHours, 24);
    let remainder = held_hours % base_hour_adjuster;
    let multi = (held_hours - remainder) / base_hour_adjuster;
    let final_multi = multi * (getVaultRate() * 100) * getRawPoolMulti();
    let reward_tokens = stake.amount * (final_multi / 100.0);
    let actual_tokens = Math.floor(reward_tokens);
    return actual_tokens;
  }
  return 0;
};

// Stake tokens
async function stake(amount, stake_index) {
  const tx = await program.methods
      .deposit_eggs(new BN(amount), stake_index)
      .accounts({
          vault: vaultPDA,
          depositor: wallet,
          tokenAccount: userATA,
          tokenVault: tokenVaultPDA,
          mint: mint,
          userInteractions: userPDA,
          tokenProgram: tokenProgram,
          systemProgram: systemProgram
      })
      .rpc();
  
  return tx;
}

// Check if claim is available
function hasRewardsAvailable (stake: Stake) {
  if (stake.status === "active") {
    const lastClaimTime = stake.lastClaim || stake.timestamp;
    const elapsed = new Date().getTime() - lastClaimTime;
    const remaining = Math.max(stakeTimeMs - elapsed, 0);
    if (remaining === 0) {
      return true;
    }
  }
  return false;
};
PreviousAccount Structure

Last updated 27 days ago