Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Solana Token Staking Protocol with rewards

alaadotsol/stake-oxe

Repository files navigation

OXE - Solana Token Staking Protocol

OXE is a Solana-based token staking/locking protocol built using the Anchor framework. It enables users to create staking pools for tokens, deposit them for a specified lock period, and potentially earn rewards.

Features

  • Pool Creation: Create token staking pools with configurable parameters
  • Flexible Lock Periods: Configure minimum and maximum lock durations
  • Optional Rewards: Pools can optionally provide rewards in a different token
  • Secure Vault Storage: All deposited tokens are stored in secure program-derived vaults
  • Permissionless: Anyone can create pools and users can freely participate

Architecture

The protocol follows a modular design with the following key components:

State

  • Pool: Central state account that stores:

    • Creator's public key
    • Minimum and maximum lock durations (in seconds)
    • Optional reward mint
    • Bump seed for PDA derivation
  • Ticket: (Planned) Represents a user's deposit into a pool, including:

    • Amount of tokens deposited
    • Lock end time
    • User information
  • Reward: (Planned) Represents reward distribution parameters and tracking

Instructions

  1. Initialize

    • Creates a new staking pool with configured parameters
    • Sets up token vaults for deposits and optional rewards
    • Allows creators to fund the reward vault during creation
  2. Deposit (Planned)

    • Allows users to deposit tokens into a pool
    • Creates a ticket representing the user's stake
    • Calculates lock period and expected rewards
  3. Withdraw (Planned)

    • Allows users to withdraw their tokens after the lock period
    • Distributes earned rewards
    • Closes the ticket account

Account Structure

The protocol uses Solana's Program Derived Addresses (PDAs) to create and manage various accounts:

  • Pool Account: ["pool", creator, mint]
  • Pool Vault: Stores the staked tokens
  • Reward Vault: Stores tokens for rewards (if enabled)
  • Ticket Account: (Planned) ["ticket", pool, owner]

Getting Started

Prerequisites

  • Solana CLI
  • Anchor Framework
  • Node.js and Yarn/npm
  • Solana wallet with SOL for deployment and testing

Installation

  1. Clone the repository:

    git clone https://github.com/yourusername/oxe.git
    cd oxe
  2. Install dependencies:

    yarn install
    # or
    bun install
  3. Build the program:

    anchor build

Deployment

  1. Deploy to localnet for testing:

    anchor deploy
  2. Run tests:

    anchor test
    # or
    bun run test
  3. For mainnet deployment, update your Anchor.toml with the appropriate cluster and wallet.

Usage

Creating a Staking Pool

const tx = await program.methods.initialize({
  rewardAmount: new BN(1000000), // Optional, omit if no rewards
  minDuration: new BN(86400),    // 1 day in seconds
  maxDuration: new BN(2592000),  // 30 days in seconds
})
.accounts({
  creator: wallet.publicKey,
  mint: tokenMint,
  rewardMint: rewardTokenMint, // Optional
  // Other accounts will be derived by the program
})
.rpc();

Depositing Tokens (Planned)

// Coming soon

Withdrawing Tokens (Planned)

// Coming soon

Security Considerations

  • The protocol uses Solana's PDA mechanism for secure account derivation
  • Token accounts are properly validated to prevent unauthorized access
  • Amount validation ensures reasonable reward parameters

Development Roadmap

  • Pool creation and initialization
  • Ticket creation and deposit functionality
  • Withdrawal and reward distribution
  • Enhanced reward mechanisms
  • DAO governance integration
  • UI/Dashboard for easy interaction

License

ISC

Built With


Note: This project is under active development. Deposit and withdrawal features are planned but not yet implemented.

About

Solana Token Staking Protocol with rewards

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published