npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@star-factory/sdk-staking

v0.2.0

Published

Staking SDK for the Star protocol

Readme

sdk-staking

Typed client for the on-chain staking program. It mirrors PDA seeds and instruction accounts, and adds read and convenience helpers.

  • Entry: sdk-staking/index.ts
  • Types: sdk-staking/types.ts
  • Peer deps: @coral-xyz/anchor, @solana/spl-token

Install

yarn add @coral-xyz/anchor @solana/spl-token

Quick start

import { AnchorProvider, BN } from '@coral-xyz/anchor';
import { PublicKey } from '@solana/web3.js';
import { StakingSDK } from '.';

const provider = AnchorProvider.env();
const sdk = await StakingSDK.create(provider); // or pass custom programId

// Initialize pool (authority must sign)
await sdk.initialize(new PublicKey('...accepted_mint...'));

// Stake
await sdk.stake(new BN(1_000_000));

// Unstake (starts 30-day unlock)
await sdk.unstake(new BN(500_000));

// Claim when eligible
if (await sdk.canClaimUnstake()) {
  await sdk.claimUnstake();
}

API

class StakingSDK {
  constructor(program: Program<StakeProgram>, provider: AnchorProvider);
  static create(provider: AnchorProvider, programId?: PublicKey): Promise<StakingSDK>;

  // PDAs
  getStakePoolPDA(): PDAWithBump;                    // [b"stake_pool"]
  getUserStakePDA(user: Address): PDAWithBump;       // [b"user_stake", user]
  getStakeVaultPDA(stakePool: Address): PDAWithBump; // [b"stake_vault", stake_pool]

  // Writes
  initialize(acceptedMint: Address, authority?: Address): Promise<TransactionSignature>;
  stake(amount: Amount, user?: Address): Promise<TransactionSignature>;
  unstake(amount: Amount, user?: Address): Promise<TransactionSignature>;
  claimUnstake(user?: Address): Promise<TransactionSignature>;

  // Reads
  getStakePool(): Promise<StakePoolAccount>;
  getUserStake(user?: Address): Promise<UserStakeAccount | null>;

  // Derived helpers
  getUserPoolShare(user?: Address): Promise<number>;         // percentage 0..100
  canClaimUnstake(user?: Address): Promise<boolean>;
  getTimeUntilClaim(user?: Address): Promise<number | null>; // seconds

  // Events
  onStakeEvent(cb: EventCallback<StakeEvent>): ListenerId;
  onUnstakeEvent(cb: EventCallback<UnstakeEvent>): ListenerId;
  onClaimUnstakeEvent(cb: EventCallback<ClaimUnstakeEvent>): ListenerId;
  removeEventListener(listenerId: ListenerId): Promise<void>;
}

Types (subset)

type Address = web3.PublicKey;
type Amount = BN;

interface StakePoolAccount { acceptedMint: Address; totalStaked: BN }
interface UserStakeAccount { stakedAmount: BN; pendingUnstake: BN; unlockTimestamp: BN }

Behavior notes

  • Loads IDL from ../target/idl/stake_program.json; use StakingSDK.create(provider, programId) to override address.
  • Uses .accountsPartial(...) (Anchor v0.29+). If needed, switch to .accounts(...).
  • getUserStake() returns null if the PDA is not initialized.
  • getUserPoolShare() computes (stakedAmount / totalStaked) * 100 with two-decimal precision.

Staker Snapshot Script

Creates a snapshot of all stakers for pro-rata reward distribution. Outputs CSV compatible with the airdrop script.

Usage

# From sdk-staking directory
yarn snapshot --supply <AMOUNT> [options]

# Options:
#   --supply <amount>   Total reward tokens to distribute (whole tokens)
#   --decimals <n>      Reward token decimals (default: 6 for USDC)
#   --output <path>     Output CSV path (default: ./staker-snapshot.csv)
#   --rpc <url>         RPC endpoint (default: $RPC_URL or localhost)

Examples

# Distribute 1M USDC (6 decimals) to stakers
yarn snapshot --supply 1000000 --decimals 6 --output ./usdc-rewards.csv

# Distribute 500K tokens with 9 decimals on mainnet
yarn snapshot --supply 500000 --decimals 9 --rpc https://api.mainnet-beta.solana.com

Output

Creates three files:

  • staker-snapshot.csv - wallet,amount format for airdrop script
  • staker-snapshot-detailed.csv - Full allocation details (staked amounts, percentages)
  • staker-snapshot-summary.json - Verification data and audit trail

Features

  • 100% integer arithmetic - No floating point for token amounts
  • Verified math - sum(distributed) + remainder = total_supply
  • Deterministic ordering - Sorted by wallet address for reproducibility
  • Randomized output - CSV is shuffled so whales aren't airdropped first

Programmatic Usage

import { StakingSDK } from '@star-vault/sdk-staking';

const sdk = await StakingSDK.create(provider);

// Get all stakers
const { stakers, totalStaked, activeStakers } = await sdk.getAllStakers();

// Each staker has:
// - wallet: PublicKey
// - stakedAmount: BN
// - pendingUnstake: BN
// - unlockTimestamp: BN