Staking Vault JS SDK
The Chaos Finance Staking Vault JavaScript SDK provides a comprehensive interface for integrating Liquid Staking Derivatives (LSD) functionality into your SONIC applications. This SDK enables developers to easily implement staking, unstaking, and withdrawal operations with built-in error handling and transaction management.
Installation
To add Chaos Finance Staking Vault LSD into your application, run this in the terminal from the root directory of the application:
Quick Start
1. Initialize the SDK
The first step developers should do is register REST endpoint, lsd program configs and wallet related functions.
There are three functions involved: register
, registerChain
and registerWallet
The register function is equivalent to executing both registerChain
and registerWallet
.
The registerChain
function doesn't require a connected wallet, but both register
and registerWallet
do.
Therefore, if your app needs to retrieve on-chain status before connecting wallet, you may call registerChain
,
then you are able to query global infos, such as lst apr, min stake amount, platform fee commission etc.
If you got the wallet connected, you can call register
or registerWallet
to finish the process,
so that you can call staking functions: stake, unstake, withdraw or user information functions.
register()
registerChain()
registerWallet()
updatePublicKey()
Set new public key when account changes.
2. Define Program IDs
Set up your program configuration:
3. Staking Operations
Stake Tokens
Unstake LST Tokens
Withdraw Tokens
Query Functions
User Query Functions
getUserSolBalance()
Returns the user's SOL balance.
getUserStakingTokenBalance()
Returns the user's staking token balance.
getUserLstBalance()
Returns the user's LST token balance.
getUserStakedAmount()
Returns the user's total staked amount in base tokens.
getUserWithdrawInfo()
Returns information about user's pending withdrawals.
Returns: WithdrawInfo object
Global Query Functions
getTotalLstAmount()
Returns the total LST amount in the pool.
getTotalStakedAmount()
Returns the total staked amount in the pool.
getLstRate()
Returns the current LST exchange rate.
Before staking users can pre calculate the amount of LST they will receive by:
The unstake amount of staking token that users will receive can be calculated with:
getLstApr()
Returns the current APR (Annual Percentage Rate).
getUserMinStakeAmount()
Returns the minimum stake amount required.
getUnbondingDuration()
Returns the unbonding duration in seconds.
getTokenProgramIds()
Returns the token program ID for a given mint address.