GithubHelp home page GithubHelp logo

pvp-staking's Introduction

PVP Staking: A Contract for Unlocked and Locked Staking

Overview

pvp_staking utilizes the Anchor framework to facilitate staking operations on the Solana network, offering both standard and locked staking options with reward enhancements through multipliers.

Modules

  • context: Defines the context data structures for transaction instructions.
  • error: Custom error codes for handling exceptions in contract operations.
  • state: Manages stateful components of the staking pools and user stakes.
  • utils: Utility functions to support various operations like state updates and calculations.

Functions

List of all the functions used to interact with the program

Admin Operations

  • initialize: Sets up a new staking pool with required parameters like reward rate and initializes time tracking.
  • initialize_locked: Configures locked staking pools with specified serving periods and associated multipliers.
  • update_admin: Allows updating the administrator of the staking pool.
  • update_reward_rate: Changes the reward rate per second for the pool.
  • add_multiplier: Adds multiplier settings to a specified locked pool period.

User Operations

  • deposit: Allows users to deposit tokens into the staking pool and updates the internal accounting to reflect the new state.
  • deposit_locked: Similar to deposit, but for locked pools with specified multipliers affecting the staked amount.
  • withdraw: Withdraw tokens from the staking pool, adjusting the internal state accordingly.
  • withdraw_locked: Withdraw tokens from a locked pool assuming the locking period has passed.
  • claim_reward: Allows users to claim their accumulated rewards based on their staked tokens.

Error Codes

The contract uses custom error codes defined in the error::ErrorCodes module to manage exceptions related to invalid operations and authorization issues.

State Management

The contract maintains the state of the staking pools and user stakes using the following structs

  • Pool: Tracks the main staking pool details.
  • PoolLocked: Manages settings for locked pools with multipliers.
  • StakeAccount: Records individual user stakes in the flexible pool.
  • StakeLocked: Manages individual locked stakes for users.

Setup

Note - It is assumed that you have solana/rust/anchor installed already, otherwise Install Anchor

  • Change wallet: Change the username in the Anchor.toml's wallet field to your username.
  • Configure the cluster: Change the cluster in the Anchor.toml to Mainnet, Testnet, Devnet or Localnet.

Run on local

  1. Anchor localnet - Start the localnet.
  2. Anchor build - Build the program
  3. Anchor keys list - Get the program address after build, then change the address in Anchor.toml and declare_id! of lib.rs.
  4. Anchor build - Rebuild the program with updated program id.
  5. Anchor deploy - Deploy the program.
  6. Anchor run test - Test the testing scripts with the updated program.

pvp-staking's People

Contributors

crypt0xg avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.