@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.cjs.js CHANGED
@@ -28801,7 +28801,8 @@ class ReadWriteFlaunchSDK extends ReadFlaunchSDK {
28801
28801
  const amount0 = poolKey.currency0 === coinAddress ? coinAmount : flethAmount;
28802
28802
  const amount1 = poolKey.currency0 === coinAddress ? flethAmount : coinAmount;
28803
28803
  // Calculate and constrain liquidity using shared method
28804
- const { finalLiquidity, finalAmount0, finalAmount1 } = this.calculateConstrainedLiquidity(currentTick, tickLower, tickUpper, amount0, amount1);
28804
+ const slippagePercent = params.slippagePercent;
28805
+ const { finalLiquidity, finalAmount0, finalAmount1 } = this.calculateConstrainedLiquidity(currentTick, tickLower, tickUpper, amount0, amount1, slippagePercent);
28805
28806
  // 6. Add liquidity
28806
28807
  calls.push(this.createLiquidityCall(poolKey, tickLower, tickUpper, finalLiquidity, finalAmount0, finalAmount1, userAddress));
28807
28808
  return calls;
@@ -28858,8 +28859,9 @@ class ReadWriteFlaunchSDK extends ReadFlaunchSDK {
28858
28859
  currentTick = poolState.tick;
28859
28860
  // If the current sqrtPriceX96 of the pool is zero, and the initial marketcap or price is provided,
28860
28861
  // we can use this to determine the current tick.
28861
- if (poolState.sqrtPriceX96 === 0n && (("initialMarketCapUSD" in params && params.initialMarketCapUSD) ||
28862
- ("initialPriceUSD" in params && params.initialPriceUSD))) {
28862
+ if (poolState.sqrtPriceX96 === 0n &&
28863
+ (("initialMarketCapUSD" in params && params.initialMarketCapUSD) ||
28864
+ ("initialPriceUSD" in params && params.initialPriceUSD))) {
28863
28865
  let { decimals: coinDecimals, formattedTotalSupplyInDecimals } = await this.getCoinInfo(coinAddress);
28864
28866
  // If we have a tokenSupply set, then overwrite the value
28865
28867
  if ("tokenSupply" in params && params.tokenSupply !== undefined) {
@@ -28991,7 +28993,8 @@ class ReadWriteFlaunchSDK extends ReadFlaunchSDK {
28991
28993
  const amount0 = poolKey.currency0 === coinAddress ? coinAmount : flethAmount;
28992
28994
  const amount1 = poolKey.currency0 === coinAddress ? flethAmount : coinAmount;
28993
28995
  // Calculate and constrain liquidity using shared method
28994
- const { finalLiquidity, finalAmount0, finalAmount1 } = this.calculateConstrainedLiquidity(currentTick, tickLower, tickUpper, amount0, amount1);
28996
+ const slippagePercent = params.slippagePercent;
28997
+ const { finalLiquidity, finalAmount0, finalAmount1 } = this.calculateConstrainedLiquidity(currentTick, tickLower, tickUpper, amount0, amount1, slippagePercent);
28995
28998
  // 3. Add liquidity
28996
28999
  calls.push(this.createLiquidityCall(poolKey, tickLower, tickUpper, finalLiquidity, finalAmount0, finalAmount1, userAddress));
28997
29000
  return calls;
@@ -29072,7 +29075,8 @@ class ReadWriteFlaunchSDK extends ReadFlaunchSDK {
29072
29075
  * @param amount1 - Amount of currency1
29073
29076
  * @returns Final liquidity and amounts
29074
29077
  */
29075
- calculateConstrainedLiquidity(currentTick, tickLower, tickUpper, amount0, amount1) {
29078
+ calculateConstrainedLiquidity(currentTick, tickLower, tickUpper, amount0, amount1, slippagePercent = 0.05 // Default to 0.05%
29079
+ ) {
29076
29080
  // Calculate liquidity first using user's input amounts
29077
29081
  const initialLiquidity = getLiquidityFromAmounts({
29078
29082
  currentTick,
@@ -29126,8 +29130,11 @@ class ReadWriteFlaunchSDK extends ReadFlaunchSDK {
29126
29130
  finalAmount1 = constrainedAmounts.amount1;
29127
29131
  }
29128
29132
  // IMPORTANT: Add conservative buffer to account for contract rounding differences
29129
- // Reduce liquidity by 0.05% to ensure contract calculations stay within user bounds
29130
- const liquidityBuffer = finalLiquidity / 2000n; // 0.05%
29133
+ // Reduce liquidity by slippagePercent to ensure contract calculations stay within user bounds
29134
+ // slippagePercent is passed as decimal percentage (e.g., 0.05 for 0.05%), convert to decimal
29135
+ const slippageAsDecimal = slippagePercent / 100;
29136
+ const slippageMultiplier = BigInt(Math.floor(1 / slippageAsDecimal));
29137
+ const liquidityBuffer = finalLiquidity / slippageMultiplier;
29131
29138
  const conservativeLiquidity = finalLiquidity - (liquidityBuffer > 1n ? liquidityBuffer : 1n);
29132
29139
  // Use conservative liquidity but keep user's original amounts as maximums
29133
29140
  // The conservative liquidity ensures the contract won't need more than user provided