get methods

The following code shows how to use DEX contracts to get methods

import TonWeb from 'tonweb';
import { DEX } from '@ston-fi/sdk';

const USER_WALLET_ADDRESS = ''; // ! replace with your wallet address
const JETTON_0_ADDRESS = "EQA2kCVNwVsil2EM2mB0SkXytxCqQjS4mttjDpnXmwG9T6bO"; // STON
const JETTON_1_ADDRESS = "EQBX6K9aXVl3nXINCyPPL86C4ONVmQ8vK360u6dykFKXpHCa"; // GEMSTON

// create a router instance
const router = new DEX.v1.Router({
  tonApiClient: new TonWeb.HttpProvider('https://ton-api.ston.fi/jsonRPC')
});

// request and exam of the router data
const routerData = await router.getData();
console.log(`Router data:`, routerData);



// create a pool instance
const pool = await router.getPool({
  token0: JETTON_0_ADDRESS,
  token1: JETTON_1_ADDRESS,
});

if (!pool) {
  throw Error(`Pool for ${JETTON_0_ADDRESS}/${JETTON_1_ADDRESS} not found`);
}

const poolAddress = await pool.getAddress();
console.log(`Pool address:`, poolAddress.toString()); // EQCl-ax-5QC06ub096s2bqTbhYZWigZ1-FkJm2IVIMSazp7U

const poolData = await pool.getData();
console.log(`Pool data:`, poolData);

const expectedOutputsData = await pool.getExpectedOutputs({
  amount: new TonWeb.utils.BN("500000000"),
  jettonWallet: poolData.token0WalletAddress,
});
console.log(`expected results of the 5 STON swap:`, expectedOutputsData);

const expectedLpTokensAmount = await pool.getExpectedTokens({
  amount0: new TonWeb.utils.BN("500000000"),
  amount1: new TonWeb.utils.BN("200000000"),
});
console.log(`expected LP tokens amount after 5 STON, 2 GEMSTON deposit:`, expectedLpTokensAmount);

const expectedLiquidityData = await pool.getExpectedLiquidity({
  jettonAmount: new TonWeb.utils.BN("50000000"),
});
console.log(`expected assets return after 0.5 LP token burn:`, expectedLiquidityData);

const lpAccountAddress = await pool.getLpAccountAddress({
  ownerAddress: USER_WALLET_ADDRESS,
});
console.log(`Pool LP account for "${poolAddress.toString()}" & "${USER_WALLET_ADDRESS}"`, lpAccountAddress.toString());



// create a LP account instance for `USER_WALLET_ADDRESS`
const lpAccount = await pool.getLpAccount({
  ownerAddress: USER_WALLET_ADDRESS
});

if (!lpAccount) {
  throw Error(
    `LpAccount for ${USER_WALLET_ADDRESS} at ${JETTON_0_ADDRESS}/${JETTON_1_ADDRESS} pool not found`
  );
}

// request and exam of the LP account data
const lpAccountData = await lpAccount.getData();
console.log(`LP account data:`, lpAccountData);

Last updated