tonstakers-sdk
TypeScript icon, indicating that this package has built-in type declarations

0.0.14-development • Public • Published

Tonstakers SDK

The Tonstakers SDK offers an advanced set of tools for developers aiming to incorporate staking functionalities into their applications on the TON blockchain. This updated version introduces a more extensive interaction with the TON ecosystem, including staking operations, balance inquiries, and much more, enhancing your application's capabilities.

Features

  • Simplified staking and unstaking operations, including options for maximum stake, instant unstake, and best rate unstake.
  • Retrieval of staked, available, TVL (Total Value Locked), and stakers count balances.
  • Fetching current and historical APY (Annual Percentage Yield) for staked assets.
  • Enhanced API key configuration for improved access limits to the tonapi.
  • Event-driven architecture for initialization and deinitialization notifications.

Installation

Tonstakers SDK can be easily installed using npm or yarn, or integrated directly into your HTML pages.

Using npm or yarn

npm install tonstakers-sdk
# or
yarn add tonstakers-sdk

Using a <script> tag

For direct HTML integration:

<script src="path/to/tonstakers-sdk.min.js"></script>

Replace "path/to/tonstakers-sdk.min.js" with the actual SDK path.

Usage

In a Module Environment

Initialize the SDK with your wallet connector (usually, a TonConnect instance) and optional parameters:

import { Tonstakers } from "tonstakers-sdk";

// this is an example connector
import { TonConnectUI } from "@tonconnect/ui";
export const tonConnectUI = new TonConnectUI({
  manifestUrl: MANIFEST_URL,
});

const tonstakers = new Tonstakers({
  connector: yourWalletConnector, // Your wallet connector
  partnerCode: 123456, // Optional partner code
  tonApiKey: "YOUR_API_KEY", // Optional API key for tonapi
});

In a Browser Environment

Direct HTML file initialization:

<script src="path/to/tonstakers-sdk.min.js"></script>
<script>
  const { Tonstakers } = TonstakersSDK;

  const tonstakers = new Tonstakers({
    connector: yourWalletConnector,
    partnerCode: 123456,
    tonApiKey: "YOUR_API_KEY",
  });
</script>

Event Listeners

tonstakers.addEventListener("initialized", () => {
  console.log("Tonstakers SDK initialized successfully.");
});

tonstakers.addEventListener("deinitialized", () => {
  console.log("Tonstakers SDK has been deinitialized.");
});

Performing Operations

Stake and unstake with new methods:

await tonstakers.stake(1); // Stake 1 TON
await tonstakers.unstake(1); // Unstake 1 tsTON
await tonstakers.stakeMax(); // Stake the maximum available balance
await tonstakers.unstakeInstant(1); // Instant unstake 1 tsTON
await tonstakers.unstakeBestRate(1); // Unstake 1 tsTON at the best available rate

Retrieve information:

const stakedBalance = await tonstakers.getStakedBalance();
console.log(`Current staked balance: ${stakedBalance}`);

const tonBalance = await tonstakers.getBalance();
console.log(`Current user ton balance: ${tonBalance}`);

const availableBalance = await tonstakers.getAvailableBalance();
console.log(`Available balance for staking: ${availableBalance}`);

const currentApy = await tonstakers.getCurrentApy();
console.log(`Current APY: ${currentApy}%`);

const historicalApy = await tonstakers.getHistoricalApy();
console.log(`Historical APY data: ${historicalApy}`);

const tvl = await tonstakers.getTvl();
console.log(`Total Value Locked (TVL): ${tvl}`);

const stakersCount = await tonstakers.getStakersCount();
console.log(`Current number of stakers: ${stakersCount}`);

const rates = await tonstakers.getRates();
console.log(`1 TON = ${rates.TONUSD} USD`);
console.log(`1 tsTON = ${rates.tsTONTON} TON`);
console.log(`Projected 1 tsTON = ${rates.tsTONTONProjected} TON`);

const [cycleStart, cycleEnd] = await tonstakers.getRoundTimestamps();
console.log(`Cycle start: ${cycleStart}, Cycle end: ${cycleEnd}`);

const activeWithdrawals = await tonstakers.getActiveWithdrawalNFTs();
console.log(`Active withdrawal NFTs: ${JSON.stringify(activeWithdrawals)}`);

const instantLiquidity = await tonstakers.getInstantLiquidity();
console.log(`Instant liquidity: ${instantLiquidity}`);

Clear storage data:

await tonstakers.clearStorageData(); // Clear all cached data
await tonstakers.clearStorageUserData(); // Clear cached user-specific data

Demo

A demo HTML page is included with the SDK to demonstrate integration into web applications, showcasing wallet connection, staking/unstaking operations, and balance updates.

Readme

Keywords

Package Sidebar

Install

npm i tonstakers-sdk

Weekly Downloads

155

Version

0.0.14-development

License

MIT

Unpacked Size

362 kB

Total Files

9

Last publish

Collaborators

  • tonstakersdev