JavaScript Client SDK
Chaos Finance provided a JavaScript package for application developers, making the adoption fast and robust.
To add Chaos Finance Sonic LSD into your application, run this in the terminal from the root directory of the application.
Import functions and objects from SDK:
Settings Functions
register()
The first function developers should call is register() which initiates the REST endpoint, signing function and LSD contract's infos.
updatePublicKey()
Set new public key when account changes.
Mutating Functions
stakeSonic()
Developers should make sure that the stakeAmount is greater or equal to the userMinStakeAmount before sending the stake tx, otherwise it fails.
unstakeLstSonic()
All LST holders are eligible to call unstakeLstSonic
function to exchange their LST for SONIC.
withdrawSonic()
Call this function to withdraw the amount of claimableAmount
SONIC that the api getUserWithdrawInfo() returns.
Global Query Functions
getUserMinStakeAmount()
Query the minimum amount of SONIC that users can stake.
getLstApr()
Get the current Annual Percentage Rate (APR) for staking
getLstRate()
Get the lst rate how many SONIC does 1 LST worth.
Before staking users can pre calculate the amount of LST they will receive by:
The unstake amount of SONIC that users will receive can be calculated with:
getPlatformFeeCommission()
Get the platform's commission rate, expressed with 9 decimal places. For example, a value of 50,000,000 represents a commission rate of 5%.
getLsdTokenAddress()
Get the LSD Token mint address and SONIC token mint address.
getTotalStakedAmount()
Get the total amount of SONIC staked in the LSD network.
getTotalLstAmount()
Get the total amount of LSD tokens in the LSD network.
User Query Functions
getUserLstBalance()
When the stake tx get confirmed, call getUserLstBalance()
to get the amount of user's lstSonic.
getUserWithdrawInfo()
After unstake, developers should query withdrawal info. It returns:
- overallAmount: the total amount of SONIC the user can withdraw after the waiting period.
- claimableAmount: the amount of SONIC that user can currently withdraw.
- remainingTimeInSeconds: the number of seconds the user needs to wait before they can call
withdrawSonic
function.
getUserSolBalance()
Get SOL balance of the current wallet.
getUserSonicBalance()
Get SONIC balance of the current wallet.
getUserStakedAmount()
Get total amount of SONIC token the current user staked.