StakeVoteSDK README
Installation
npm i @terminusbet/stake-vote-sdk
Notice (for front-end developers)
If you encounter an error regarding the crypto
module when building a front-end project with frameworks such as React, Vue, or Next.js, consider installing a polyfill (for example, the node-polyfills plugin) or adding a crypto-browserify alias to your build configuration.
For example:
import { nodePolyfills } from 'vite-plugin-node-polyfills'
plugins: [
nodePolyfills({
include: ['crypto'],
}),
],
OR
resolve: {
alias: {
crypto: 'crypto-browserify',
}
},
StakeVoteSDK transaction
Get StakeVoteSDK transaction-related methods.
getStakeTransactions
async getStakeTransactions(
user: PublicKey,
stakePoolState: PublicKey,
amount: BN
): Promise<Transaction>
- Stake to get voting rights
- Parameters:
user
: The public key of the user.stakePoolState
: Staking pool public key corresponding to different staking periods.amount
: Amount of mint to stake.
- Returns: A promise that resolves to a
Transaction
.
getStakeAddTransactions
async getStakeAddTransactions(
user: PublicKey,
stakePoolState: PublicKey,
amount: BN,
addType: number
): Promise<Transaction>
- Increase the stake to get more voting rights
- Parameters:
user
: The public key of the user.stakePoolState
: Staking pool public key corresponding to different staking periods.amount
: Amount of mint to stake.addType
: Mint amount OR time.
- Returns: A promise that resolves to a
Transaction
.
getStakeWithdrawTransactions
async getStakeWithdrawTransactions(
user: PublicKey,
stakePoolState: PublicKey,
amount: BN
): Promise<Transaction>
- Withdraw staked tokens
- Parameters:
user
: The public key of the user.stakePoolState
: Staking pool public key corresponding to different staking periods.amount
: Amount of mint to withdraw.
- Returns: A promise that resolves to a
Transaction
.
getAutoVoteTransactions
async getAutoVoteTransactions(
user: PublicKey,
ballotBoxState: PublicKey,
amount: bigint,
slippage = 500n
): Promise<Transaction>
- Voting by custom amount
- Parameters:
user
: The public key of the user.ballotBoxState
: The public key of the ballot box.amount
: Amount of mint to vote.slippage
: Minimum number of voting rights to be accepted.
- Returns: A promise that resolves to a
Transaction
.
getAutoWholeVoteTransactions
async getAutoWholeVoteTransactions(
user: PublicKey,
ballotBoxState: PublicKey
): Promise<Transaction>
- The program automatically casts all votes
- Parameters:
user
: The public key of the user.ballotBoxState
: The public key of the ballot box.
- Returns: A promise that resolves to a
Transaction
.
getRewardReceiveTransactions
async getRewardReceiveTransactions(
user: PublicKey,
rewardUseBallotBox: PublicKey
): Promise<Transaction>
- Get Rewards
- Parameters:
user
: The public key of the user.rewardUseBallotBox
: The public key of the ballot box.
- Returns: A promise that resolves to a
Transaction
.
getBatchRewardReceiveTransactions
async getBatchRewardReceiveTransactions(
user: PublicKey,
rewardUseBallotBoxs: PublicKey
): Promise<Transaction>
- Get rewards from multiple voting boxes in batches
- Parameters:
user
: The public key of the user.rewardUseBallotBoxs
: The public key of the ballot boxes.
- Returns: A promise that resolves to a
Transaction
.
Some preview methods for account
// Get the staking pool list
async getStakePoolStates(): : Promise<ProgramAccount<{
stakePeriod: BN;
rewardGrowBy: BN;
growReduceBy: BN;
decimal: number;
rewardGrowMinBy: BN;
}>[]>
// Get all the user's voting rights
async getUserVouchers(user: PublicKey): Promise<{
userVouchers: bigint;
decimal: number;
}>
// Get users can receive rewards
async getUserRewards(ballotBoxState: PublicKey, user: PublicKey): Promise<{
userRewards: bigint;
rewardMint: PublicKey;
}>
// Get the staking pool config
async getStakePoolStateAccount(
stakePoolState: PublicKey
): Promise<StakePoolState | null>
// Get user voting information
async getUserVoteStateAccount(
ballotBoxState: PublicKey,
user: PublicKey,
commitment: Commitment = DEFAULT_COMMITMENT
): Promise<UserVoteState | null>
// Get the voting details of a user in a staking pool
async getUserStakeVoteStateAccount(
stakePoolState: PublicKey,
user: PublicKey,
commitment: Commitment = DEFAULT_COMMITMENT
): Promise<UserStakeVoteState | null>
// Get the user's received reward data
async getUserRewardStateAccount(
stakePoolState: PublicKey,
user: PublicKey,
commitment: Commitment = DEFAULT_COMMITMENT
): Promise<UserRewardState | null>
// Get ballot box information
async getBallotBotStateAccount(
ballotBot: PublicKey,
commitment: Commitment = DEFAULT_COMMITMENT
): Promise<BallotBotState | null>
// Get ballot box reward information
async getVoteRewardStateAccount(
ballotBoxState: PublicKey,
commitment: Commitment = DEFAULT_COMMITMENT
): Promise<VoteRewardState | null>
// Get user's active ballot boxes
async getUserActiveBallotBoxStateAccount(
stakePoolState: PublicKey,
user: PublicKey,
commitment: Commitment = DEFAULT_COMMITMENT
): Promise<UserActiveBallotBoxState | null>
// Get global active ballot boxes
async getActiveBallotBoxStateAccount(
commitment: Commitment = DEFAULT_COMMITMENT
): Promise<ActiveBallotBoxState | null>
// Get user's active ballot boxes
async getUserActiveBallotBoxStateAccount(
stakePoolState: PublicKey,
user: PublicKey,
commitment: Commitment = DEFAULT_COMMITMENT
): Promise<UserActiveBallotBoxState | null>
// Get the lock amount for the staked pool
async lockedAmount(
stakePoolState: PublicKey,
user: PublicKey
): Promise<BN>
StakeVoteSDK Class
The StakeVoteSDK
class provides methods for interacting with the Bet protocol. Below are the method signatures and descriptions.
stake
async stake(
user: Keypair,
stakePoolState: PublicKey,
amount: BN,
priorityFees?: PriorityFee,
commitment: Commitment = DEFAULT_COMMITMENT,
finality: Finality = DEFAULT_FINALITY
): Promise<TransactionResult>
- Parameters:
user
: The Keypair of the user.stakePoolState
: Staking pool public key corresponding to different staking periods.amount
: Amount of mint to stake.priorityFees
: Priority fees (optional).commitment
: Commitment level (default: DEFAULT_COMMITMENT).finality
: Finality level (default: DEFAULT_FINALITY).
- Returns: A promise that resolves to a
TransactionResult
.
stakeAdd
async stakeAdd(
user: Keypair,
stakePoolState: PublicKey,
amount: BN,
addType: number,
priorityFees?: PriorityFee,
commitment: Commitment = DEFAULT_COMMITMENT,
finality: Finality = DEFAULT_FINALITY
): Promise<TransactionResult>
- Parameters:
user
: The Keypair of the user.stakePoolState
: Staking pool public key corresponding to different staking periods.amount
: Amount of mint to stake.addType
: Mint amount OR time.priorityFees
: Priority fees (optional).commitment
: Commitment level (default: DEFAULT_COMMITMENT).finality
: Finality level (default: DEFAULT_FINALITY).
- Returns: A promise that resolves to a
TransactionResult
.
stakeWithdraw
async stakeWithdraw(
user: Keypair,
stakePoolState: PublicKey,
amount: BN,
priorityFees?: PriorityFee,
commitment: Commitment = DEFAULT_COMMITMENT,
finality: Finality = DEFAULT_FINALITY
): Promise<TransactionResult>
- Parameters:
user
: The Keypair of the user.stakePoolState
: Staking pool public key corresponding to different staking periods.amount
: Amount of mint to withdraw.priorityFees
: Priority fees (optional).commitment
: Commitment level (default: DEFAULT_COMMITMENT).finality
: Finality level (default: DEFAULT_FINALITY).
- Returns: A promise that resolves to a
TransactionResult
.
vote
async vote(
user: Keypair,
ballotBoxState: PublicKey,
amount: bigint,
slippage: bigint,
priorityFees?: PriorityFee,
commitment: Commitment = DEFAULT_COMMITMENT,
finality: Finality = DEFAULT_FINALITY
): Promise<TransactionResult>
- Parameters:
user
: The Keypair of the user.ballotBoxState
: The public key of the ballot box.amount
: Amount of mint to vote.slippage
: The slippage of voting rights to be accepted.priorityFees
: Priority fees (optional).commitment
: Commitment level (default: DEFAULT_COMMITMENT).finality
: Finality level (default: DEFAULT_FINALITY).
- Returns: A promise that resolves to a
TransactionResult
.
voteWhole
async voteWhole(
user: Keypair,
ballotBoxState: PublicKey,
priorityFees?: PriorityFee,
commitment: Commitment = DEFAULT_COMMITMENT,
finality: Finality = DEFAULT_FINALITY
): Promise<TransactionResult>
- Parameters:
user
: The Keypair of the user.ballotBoxState
: The public key of the ballot box.isWhole
: Whether to invest all holdings.priorityFees
: Priority fees (optional).commitment
: Commitment level (default: DEFAULT_COMMITMENT).finality
: Finality level (default: DEFAULT_FINALITY).
- Returns: A promise that resolves to a
TransactionResult
.
rewardReceive
async rewardReceive(
user: Keypair,
rewardUseBallotBox: PublicKey,
priorityFees?: PriorityFee,
commitment: Commitment = DEFAULT_COMMITMENT,
finality: Finality = DEFAULT_FINALITY
): Promise<TransactionResult>
- Parameters:
user
: The Keypair of the user.rewardUseBallotBox
: The public key of the reward ballot box.priorityFees
: Priority fees (optional).commitment
: Commitment level (default: DEFAULT_COMMITMENT).finality
: Finality level (default: DEFAULT_FINALITY).
- Returns: A promise that resolves to a
TransactionResult
.