how to swap
1
Find the Pool
import { Asset, Factory, PoolV1 } from "@utyablabs/sdk";
const factory = client.open(Factory.createFromAddress(Factory.FACTORY_ADDRESS));
const tokenAddress = Address.parse("EQAw63ZqLmnwRA77PW07CWIEngwg-eIiysaqZ8IWpUL0nP7a")
const poolAddress = await factory.getPoolAddress({
asset0: Asset.native(),
asset1: Asset.token(tokenAddress)
});
const pool = client.open(PoolV1.createFromAddress(poolAddress));
2
3
Swap
TON -> Token
// Swap 1 TON
await pool.sendNativeSwap(sender, {
amount: toNano("1"), // Swap 1 TON
minOut: 0n, // Minimum amount of tokens to receive
sender: userAddress,
referral: null, // Referral address
});
Swap Token -> TON
import { JettonMaster } from "@ton/ton";
// Get the wallet address
const master = client.open(JettonMaster.create(tokenAddress));
const walletAddress = await master.getWalletAddress(userAddress);
// Swap 1000 tokens
await pool.sendTokenSwap(sender, {
sender: userAddress,
walletAddress: walletAddress,
jetton_amount: toNano("1000"),
minOut: 0n,
referral: null,
assetIn: Asset.token(tokenAddress),
assetOut: Asset.native(),
});
Last updated