Unstake stgUSD

This guide demonstrates how to unstake stgUSD to get tgUSD (principal + accrued rewards)

Step 1: Import modules & Initialize Staking Contract

import { Address, TonClient4 } from "@ton/ton";
import { tgUSDStaking } from "@torch-finance/tgusd-sdk";

const tonClient = new TonClient4({
  endpoint: 'https://mainnet-v4.tonhubapi.com',
});

// Staking Contract
const stakingAddress = Address.parse("EQDsRxOvYyhOAi-zHBSN2NkHcjwFB1aaMSnqJG7Chm14x02P")
const tgUSDJettonMaster = Address.parse("EQCJ7ASxOkI6Ws5Bh8J74XZbRX8861jFgTZT42DXv71-UISf")
const stgUSDJettonMaster = Address.parse("EQC2OdSIRyDofBjKYtR-ZN-Xk3eHN9gEujY7deoHNRBdZ5QG")
const staking = tonClient.open(tgUSDStaking.createFromAddress(stakingAddress, tgUSDJettonMaster, stgUSDJettonMaster));

Step2: Build Unstake Payload

// Prepare Unstake params
// Staker Address
const stakerAddress = Address.parse("stake-address");

// Burn 0.1 stgUSD to get tgUSD
// Your stgUSD will be burned and converted to tgUSD based on the conversion rate in the staking contract.
const burnAmount = 100000n;
const unstakePayload = await staking.getUnstakePayload(stakerAddress, burnAmount);

After calling Unstake, a 7-day cooldown period is required. You can only claim your tgUSD after the cooldown period ends.

Step 3: Claim tgUSD After Cooldown

// Remember to import RedeemAccount from the SDK.
import { RedeemAccount } from '@torch-finance/tgusd-sdk';

// Unstaker Address
const unstakerAddress = Address.parse("unstaker-address");

// Get the address of the associated unstake account
const unstakeAccountAddress = await staking.getUnstakeAccountAddress(unstakerAddress);

// Initialize the unstake account contract
const unstakeAccount = tonClient.open(
  RedeemAccount.createFromAddress(unstakeAccountAddress)
);

// Build claim payload for redeeming tgUSD
const claimPayload = await unstakeAccount.getClaimPayload(unstakerAddress);

Last updated