Telegram USD
WebsiteMiniapp
  • 👋Welcome
  • Getting Started
    • 🗽Introduction
    • 😢Ecosystem Challenges
      • Low Yield on TON
      • Limited Real-World Integration
      • High DeFi Barriers
    • 🤙A New Path Forward
  • How tgUSD Works
    • 🏠Architecture
      • ▶️Current Version
      • 🌴Core Components
        • Engine
        • Staking
      • 🔮Next Version
    • ⚖️Peg Stability
    • 💰Protocol Revenue
    • 🙋‍♀️Use Cases
      • DeFi
        • Yield Tokenization
        • Lending
        • Dex
        • Leverage Yield Farming
        • Derivatives
        • Arbitrage
      • Cross-Chain Expansion
        • TAC
        • Tycho
  • Rewards
    • 🌟Ambassador Program
    • ✴️What is Torch XP
  • Technical
    • 📖Telegram USD SDK
      • Setup
      • Mint tgUSD
      • Stake tgUSD
      • Unstake stgUSD
      • Get stgUSD Conversion Rate
        • On-chain method
        • Off-chain method
    • 🛠️Deployments
  • Security
    • ✳️Risks
    • 🛡️Audits
  • User Guide
    • How to Mint
    • How to Stake
    • How to Unstake
    • FAQ
  • Legal
    • Terms of Service
  • Privacy Policy
  • Other
    • 🎨Brand Kit
  • Links
    • Website
  • tgUSD Miniapp
  • Telegram Channel
  • X (Twitter)
Powered by GitBook
On this page
  • Step 1: Import modules & Initialize Staking Contract
  • Step2: Build Unstake Payload
  • Step 3: Claim tgUSD After Cooldown
  1. Technical
  2. Telegram USD SDK

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);
PreviousStake tgUSDNextGet stgUSD Conversion Rate

Last updated 13 days ago

📖