This method simultaneously creates a position and adds liquidity. The NFT, which represents the position, will be sent to the creator's address. All subsequent operations will require using the position ID (NFT).
Copy interface AddLiquidityOptions {
// pool object ID
pool: string;
// Operator address
address: string;
// Amount of coin A
amountA: string | number;
// Amount of coin B
amountB: string | number;
// Represents the index of the lower tick boundary
tickLower: number;
// Represents the index of the upper tick boundary
tickUpper: number;
// Acceptable wasted amount percentage. Range: [0, 100)
slippage: string | number;
// Expires timeout(ms), defaults 60_000
deadline?: number;
// Custom transaction handler
txb?: Transaction;
}
Copy const turbosSdk = new TurbosSdk(Network.testnet, {
url: 'https://fullnode.testnet.sui.io',
});
const signer = turbosSdk.account.getKeypairFromMnemonics("your mnemonic");
const poolId = '0x328572f9d3c99bdb0a2da46fa61ef7917e1d35e67ec9472d412aa82b4a5222b2';
const pool = await turbosSdk.pool.getPool(poolId);
const coinADecimals = 9;
const current_tick_index = turbosSdk.math.sqrtPriceX64ToTickIndex(
new BN(pool.sqrt_price),
);
const tickLower = turbosSdk.math.getPrevInitializableTickIndex(
current_tick_index,
pool.tick_spacing,
);
const tickUpper = turbosSdk.math.getNextInitializableTickIndex(
current_tick_index,
pool.tick_spacing,
);
const amountA = 1 * 10 ** coinADecimals;
const amounts = turbosSdk.pool.estimateAmountsFromOneAmount({
sqrtPrice: pool.sqrt_price,
tickLower,
tickUpper,
amount: amountA.toString(),
isAmountA: true,
});
const txb = await turbosSdk.pool.addLiquidity({
pool: poolId,
amountA: amounts[0],
amountB: amounts[1],
address: signer.toSuiAddress(),
slippage: 10, //10% slippage
tickLower,
tickUpper,
});
const result = await turbosSdk.provider.signAndExecuteTransaction({
transaction: txb,
signer,
});
console.log(result);