const LIQUID_STAKING_INFO = {
id: "0x15eda7330c8f99c30e430b4d82fd7ab2af3ead4ae17046fcb224aa9bad394f6b",
type: "0x83556891f4a0f233ce7b05cfe7f957d4020492a34f5405b2cb9377d060bef4bf::spring_sui::SPRING_SUI",
weightHookId:
"0xbbafcb2d7399c0846f8185da3f273ad5b26b3b35993050affa44cfa890f1f144",
};
const client = new SuiClient({ url: RPC_URL });
const lstClient = await LstClient.initialize(client, LIQUID_STAKING_INFO);
const tx = new Transaction();
const [sui] = tx.splitCoins(tx.gas, [BigInt(options.amount)]);
const sSui = lstClient.mint(tx, sui);
tx.transferObjects([sSui], keypair.toSuiAddress());
const txResponse = await client.signAndExecuteTransaction({
transaction: tx,
signer: keypair,
options: {
showEvents: true,
showEffects: true,
showObjectChanges: true,
},
});
const LIQUID_STAKING_INFO = {
id: "0x15eda7330c8f99c30e430b4d82fd7ab2af3ead4ae17046fcb224aa9bad394f6b",
type: "0x83556891f4a0f233ce7b05cfe7f957d4020492a34f5405b2cb9377d060bef4bf::spring_sui::SPRING_SUI",
weightHookId:
"0xbbafcb2d7399c0846f8185da3f273ad5b26b3b35993050affa44cfa890f1f144",
};
const client = new SuiClient({ url: RPC_URL });
const lstCoins = await client.getCoins({
owner: keypair.toSuiAddress(),
coinType: LIQUID_STAKING_INFO.type,
limit: 1000,
});
const tx = new Transaction();
const lstClient = await LstClient.initialize(client, LIQUID_STAKING_INFO);
if (lstCoins.data.length > 1) {
tx.mergeCoins(
lstCoins.data[0].coinObjectId,
lstCoins.data.slice(1).map((c) => c.coinObjectId),
);
}
const [lst] = tx.splitCoins(lstCoins.data[0].coinObjectId, [
BigInt(options.amount),
]);
const sui = lstClient.redeemLst(tx, lst);
tx.transferObjects([sui], keypair.toSuiAddress());
const txResponse = await client.signAndExecuteTransaction({
transaction: tx,
signer: keypair,
options: {
showEvents: true,
showEffects: true,
showObjectChanges: true,
},
});
Get the exchange rate of sSUI/SUI offchain (using the SDK)
import { fetchLiquidStakingInfo } from "@suilend/springsui-sdk";
import BigNumber from "bignumber.js";
const LIQUID_STAKING_INFO = {
id: "0x15eda7330c8f99c30e430b4d82fd7ab2af3ead4ae17046fcb224aa9bad394f6b",
type: "0x83556891f4a0f233ce7b05cfe7f957d4020492a34f5405b2cb9377d060bef4bf::spring_sui::SPRING_SUI",
weightHookId:
"0xbbafcb2d7399c0846f8185da3f273ad5b26b3b35993050affa44cfa890f1f144",
};
const SUI_DECIMALS = 9;
const SSUI_DECIMALS = 9;
const rawLiquidStakingInfo = await fetchLiquidStakingInfo(
LIQUID_STAKING_INFO,
suiClient,
);
const totalSuiSupply = new BigNumber(
rawLiquidStakingInfo.storage.totalSuiSupply.toString(),
).div(10 ** SUI_DECIMALS);
const totalLstSupply = new BigNumber(
rawLiquidStakingInfo.lstTreasuryCap.totalSupply.value.toString(),
).div(10 ** SSUI_DECIMALS);
const suiToLstExchangeRate = !totalSuiSupply.eq(0)
? totalLstSupply.div(totalSuiSupply)
: new BigNumber(0);