npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tonstakers-sdk

v0.0.14-development

Published

Tonstakers SDK

Downloads

511

Readme

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.