API Reference

Complete API documentation for @tetherto/wdk-protocol-swap-stonfi-ton

Table of Contents

Class
Description
Methods

Main class for swapping tokens on StonFi DEX on TON blockchain. Extends SwapProtocol from @tetherto/wdk-wallet/protocols.

Constructor - Creates swap service swap(options, config?) - Swaps tokens on StonFi DEX quoteSwap(options, config?) - Gets the cost of a swap operation without doing it

StonFiProtocolTon

The main class for swapping tokens on StonFi DEX on TON blockchain. Extends SwapProtocol from @tetherto/wdk-wallet/protocols.

Constructor

new StonFiProtocolTon(account, config?)

Parameters:

  • account (WalletAccountTon | WalletAccountTonGasless | WalletAccountReadOnlyTon | WalletAccountReadOnlyTonGasless): The wallet account to use for swap operations

  • config (SwapProtocolConfig, optional): Configuration object

    • swapMaxFee (bigint, optional): Maximum total swap cost in nanotons

Example:

import StonFiProtocolTon from '@tetherto/wdk-protocol-swap-stonfi-ton'
import { WalletAccountTon } from '@tetherto/wdk-wallet-ton'

const account = new WalletAccountTon(seedPhrase, {
  tonApiKey: 'YOUR_TON_API_KEY',
  tonApiEndpoint: 'YOUR_TON_API_ENDPOINT'
})

const swapProtocol = new StonFiProtocolTon(account, {
  swapMaxFee: 1000000000n // Maximum swap fee in nanotons
})

Methods

Method
Description
Returns
Throws

swap(options, config?)

Swaps tokens on StonFi DEX

Promise<SwapResult>

If no TON connection or fee exceeds max

quoteSwap(options, config?)

Gets the cost of a swap operation

Promise<Omit<SwapResult, 'hash'>>

If no TON connection

swap(options, config?)

Swaps tokens on StonFi DEX using the StonFi protocol.

Parameters:

  • options (StonFiSwapOptions): Swap operation options

    • tokenIn (string): Token to sell (use 'ton' for native TON or jetton address)

    • tokenOut (string): Token to buy (use 'ton' for native TON or jetton address)

    • tokenInAmount (bigint, optional): Amount to sell in token base units

    • tokenOutAmount (bigint, optional): Exact amount to buy in token base units

    • slippageTolerance (number, optional): Max price change allowed (default: 0.0001 = 0.01%)

    • to (string, optional): Address to send bought tokens (default: your address)

  • config (Pick<TonGaslessWalletConfig, 'paymasterToken'> & Pick<SwapProtocolConfig, 'swapMaxFee'>, optional): Override settings for gasless accounts

    • paymasterToken (string, optional): Token to use for paying fees

    • swapMaxFee (bigint, optional): Override maximum swap fee

Returns: Promise<SwapResult> - Swap operation result

Throws:

  • Error if account is read-only

  • Error if no TON connection is set up

  • Error if swap fee goes over maximum allowed

  • Error if no liquidity pool found for token pair

  • Error if gasless account tries to swap native TON

Example:

quoteSwap(options, config?)

Gets the cost of a swap operation without doing it.

Parameters:

  • options (StonFiSwapOptions): Swap operation options (same as swap method)

  • config (Pick<TonGaslessWalletConfig, 'paymasterToken'>, optional): Override settings for gasless accounts

    • paymasterToken (string, optional): Token to use for paying fees

Returns: Promise<Omit<SwapResult, 'hash'>> - Swap cost estimate

Throws: Error if no TON connection is set up

Example:

Types

StonFiSwapOptions

SwapResult

SwapProtocolConfig

TonGaslessWalletConfig

Supported Network

The swap service supports TON blockchain:

Source and Target Network:

  • 'ton' - TON blockchain with StonFi DEX

Token Support:

  • Native TON (use 'ton' string)

  • All jetton tokens available on StonFi DEX

  • Token addresses are TON jetton contract addresses

Note: Gasless accounts can only swap jetton-to-jetton pairs. TON-to-jetton and jetton-to-TON swaps need standard accounts.

Error Handling

The swap service throws specific errors for different problems:

Usage Examples

Basic Swap Operation

Multiple Token Swaps

Gasless Swap


Need Help?