@flaunch/sdk 0.9.13 → 0.9.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -28793,7 +28793,8 @@ class ReadWriteFlaunchSDK extends ReadFlaunchSDK {
28793
28793
  const amount0 = poolKey.currency0 === coinAddress ? coinAmount : flethAmount;
28794
28794
  const amount1 = poolKey.currency0 === coinAddress ? flethAmount : coinAmount;
28795
28795
  // Calculate and constrain liquidity using shared method
28796
- const { finalLiquidity, finalAmount0, finalAmount1 } = this.calculateConstrainedLiquidity(currentTick, tickLower, tickUpper, amount0, amount1);
28796
+ const slippagePercent = params.slippagePercent;
28797
+ const { finalLiquidity, finalAmount0, finalAmount1 } = this.calculateConstrainedLiquidity(currentTick, tickLower, tickUpper, amount0, amount1, slippagePercent);
28797
28798
  // 6. Add liquidity
28798
28799
  calls.push(this.createLiquidityCall(poolKey, tickLower, tickUpper, finalLiquidity, finalAmount0, finalAmount1, userAddress));
28799
28800
  return calls;
@@ -28850,8 +28851,9 @@ class ReadWriteFlaunchSDK extends ReadFlaunchSDK {
28850
28851
  currentTick = poolState.tick;
28851
28852
  // If the current sqrtPriceX96 of the pool is zero, and the initial marketcap or price is provided,
28852
28853
  // we can use this to determine the current tick.
28853
- if (poolState.sqrtPriceX96 === 0n && (("initialMarketCapUSD" in params && params.initialMarketCapUSD) ||
28854
- ("initialPriceUSD" in params && params.initialPriceUSD))) {
28854
+ if (poolState.sqrtPriceX96 === 0n &&
28855
+ (("initialMarketCapUSD" in params && params.initialMarketCapUSD) ||
28856
+ ("initialPriceUSD" in params && params.initialPriceUSD))) {
28855
28857
  let { decimals: coinDecimals, formattedTotalSupplyInDecimals } = await this.getCoinInfo(coinAddress);
28856
28858
  // If we have a tokenSupply set, then overwrite the value
28857
28859
  if ("tokenSupply" in params && params.tokenSupply !== undefined) {
@@ -28983,7 +28985,8 @@ class ReadWriteFlaunchSDK extends ReadFlaunchSDK {
28983
28985
  const amount0 = poolKey.currency0 === coinAddress ? coinAmount : flethAmount;
28984
28986
  const amount1 = poolKey.currency0 === coinAddress ? flethAmount : coinAmount;
28985
28987
  // Calculate and constrain liquidity using shared method
28986
- const { finalLiquidity, finalAmount0, finalAmount1 } = this.calculateConstrainedLiquidity(currentTick, tickLower, tickUpper, amount0, amount1);
28988
+ const slippagePercent = params.slippagePercent;
28989
+ const { finalLiquidity, finalAmount0, finalAmount1 } = this.calculateConstrainedLiquidity(currentTick, tickLower, tickUpper, amount0, amount1, slippagePercent);
28987
28990
  // 3. Add liquidity
28988
28991
  calls.push(this.createLiquidityCall(poolKey, tickLower, tickUpper, finalLiquidity, finalAmount0, finalAmount1, userAddress));
28989
28992
  return calls;
@@ -29064,7 +29067,8 @@ class ReadWriteFlaunchSDK extends ReadFlaunchSDK {
29064
29067
  * @param amount1 - Amount of currency1
29065
29068
  * @returns Final liquidity and amounts
29066
29069
  */
29067
- calculateConstrainedLiquidity(currentTick, tickLower, tickUpper, amount0, amount1) {
29070
+ calculateConstrainedLiquidity(currentTick, tickLower, tickUpper, amount0, amount1, slippagePercent = 0.05 // Default to 0.05%
29071
+ ) {
29068
29072
  // Calculate liquidity first using user's input amounts
29069
29073
  const initialLiquidity = getLiquidityFromAmounts({
29070
29074
  currentTick,
@@ -29118,8 +29122,11 @@ class ReadWriteFlaunchSDK extends ReadFlaunchSDK {
29118
29122
  finalAmount1 = constrainedAmounts.amount1;
29119
29123
  }
29120
29124
  // IMPORTANT: Add conservative buffer to account for contract rounding differences
29121
- // Reduce liquidity by 0.05% to ensure contract calculations stay within user bounds
29122
- const liquidityBuffer = finalLiquidity / 2000n; // 0.05%
29125
+ // Reduce liquidity by slippagePercent to ensure contract calculations stay within user bounds
29126
+ // slippagePercent is passed as decimal percentage (e.g., 0.05 for 0.05%), convert to decimal
29127
+ const slippageAsDecimal = slippagePercent / 100;
29128
+ const slippageMultiplier = BigInt(Math.floor(1 / slippageAsDecimal));
29129
+ const liquidityBuffer = finalLiquidity / slippageMultiplier;
29123
29130
  const conservativeLiquidity = finalLiquidity - (liquidityBuffer > 1n ? liquidityBuffer : 1n);
29124
29131
  // Use conservative liquidity but keep user's original amounts as maximums
29125
29132
  // The conservative liquidity ensures the contract won't need more than user provided