@sodax/sdk 1.5.5-beta → 1.5.6-beta
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 +63 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.mjs +63 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -14968,6 +14968,19 @@ declare class ClService {
|
|
|
14968
14968
|
* @returns The required amount of token0
|
|
14969
14969
|
*/
|
|
14970
14970
|
static calculateAmount0FromAmount1(amount1: bigint, tickLower: bigint, tickUpper: bigint, currentTick: bigint): bigint;
|
|
14971
|
+
/**
|
|
14972
|
+
* Calculate amount0Max and amount1Max for a given liquidity and slippage tolerance.
|
|
14973
|
+
* For concentrated liquidity, a price drop increases the amount0 needed and a price rise increases the amount1 needed.
|
|
14974
|
+
* This calculates the worst-case amounts for each token independently.
|
|
14975
|
+
*/
|
|
14976
|
+
static calculateMaxAmountsForSlippage(liquidity: bigint, tickLower: bigint, tickUpper: bigint, currentTick: bigint, sqrtPriceX96: bigint, slippagePercent: number): {
|
|
14977
|
+
amount0Max: bigint;
|
|
14978
|
+
amount1Max: bigint;
|
|
14979
|
+
};
|
|
14980
|
+
/**
|
|
14981
|
+
* Integer square root via Newton's method. Returns floor(sqrt(n)).
|
|
14982
|
+
*/
|
|
14983
|
+
private static sqrtBigInt;
|
|
14971
14984
|
/**
|
|
14972
14985
|
* Helper: Convert price to nearest valid tick
|
|
14973
14986
|
* @param price - The price as a number
|
package/dist/index.d.ts
CHANGED
|
@@ -14968,6 +14968,19 @@ declare class ClService {
|
|
|
14968
14968
|
* @returns The required amount of token0
|
|
14969
14969
|
*/
|
|
14970
14970
|
static calculateAmount0FromAmount1(amount1: bigint, tickLower: bigint, tickUpper: bigint, currentTick: bigint): bigint;
|
|
14971
|
+
/**
|
|
14972
|
+
* Calculate amount0Max and amount1Max for a given liquidity and slippage tolerance.
|
|
14973
|
+
* For concentrated liquidity, a price drop increases the amount0 needed and a price rise increases the amount1 needed.
|
|
14974
|
+
* This calculates the worst-case amounts for each token independently.
|
|
14975
|
+
*/
|
|
14976
|
+
static calculateMaxAmountsForSlippage(liquidity: bigint, tickLower: bigint, tickUpper: bigint, currentTick: bigint, sqrtPriceX96: bigint, slippagePercent: number): {
|
|
14977
|
+
amount0Max: bigint;
|
|
14978
|
+
amount1Max: bigint;
|
|
14979
|
+
};
|
|
14980
|
+
/**
|
|
14981
|
+
* Integer square root via Newton's method. Returns floor(sqrt(n)).
|
|
14982
|
+
*/
|
|
14983
|
+
private static sqrtBigInt;
|
|
14971
14984
|
/**
|
|
14972
14985
|
* Helper: Convert price to nearest valid tick
|
|
14973
14986
|
* @param price - The price as a number
|
package/dist/index.mjs
CHANGED
|
@@ -35054,7 +35054,7 @@ var AssetService = class {
|
|
|
35054
35054
|
});
|
|
35055
35055
|
}
|
|
35056
35056
|
};
|
|
35057
|
-
var ClService = class {
|
|
35057
|
+
var ClService = class _ClService {
|
|
35058
35058
|
config;
|
|
35059
35059
|
relayerApiEndpoint;
|
|
35060
35060
|
hubProvider;
|
|
@@ -36072,6 +36072,68 @@ var ClService = class {
|
|
|
36072
36072
|
);
|
|
36073
36073
|
return amount0;
|
|
36074
36074
|
}
|
|
36075
|
+
/**
|
|
36076
|
+
* Calculate amount0Max and amount1Max for a given liquidity and slippage tolerance.
|
|
36077
|
+
* For concentrated liquidity, a price drop increases the amount0 needed and a price rise increases the amount1 needed.
|
|
36078
|
+
* This calculates the worst-case amounts for each token independently.
|
|
36079
|
+
*/
|
|
36080
|
+
static calculateMaxAmountsForSlippage(liquidity, tickLower, tickUpper, currentTick, sqrtPriceX96, slippagePercent) {
|
|
36081
|
+
const amount0AtCurrent = PositionMath.getToken0Amount(
|
|
36082
|
+
Number(currentTick),
|
|
36083
|
+
Number(tickLower),
|
|
36084
|
+
Number(tickUpper),
|
|
36085
|
+
sqrtPriceX96,
|
|
36086
|
+
liquidity
|
|
36087
|
+
);
|
|
36088
|
+
const amount1AtCurrent = PositionMath.getToken1Amount(
|
|
36089
|
+
Number(currentTick),
|
|
36090
|
+
Number(tickLower),
|
|
36091
|
+
Number(tickUpper),
|
|
36092
|
+
sqrtPriceX96,
|
|
36093
|
+
liquidity
|
|
36094
|
+
);
|
|
36095
|
+
const SLIPPAGE_SCALE = 1000000000n;
|
|
36096
|
+
const slippageScaled = BigInt(Math.round(slippagePercent * Number(SLIPPAGE_SCALE) / 100));
|
|
36097
|
+
const sqrtPriceX96Squared = sqrtPriceX96 * sqrtPriceX96;
|
|
36098
|
+
const sqrtPriceX96Down = _ClService.sqrtBigInt(
|
|
36099
|
+
sqrtPriceX96Squared * (SLIPPAGE_SCALE - slippageScaled) / SLIPPAGE_SCALE
|
|
36100
|
+
);
|
|
36101
|
+
const sqrtPriceX96Up = _ClService.sqrtBigInt(
|
|
36102
|
+
sqrtPriceX96Squared * (SLIPPAGE_SCALE + slippageScaled) / SLIPPAGE_SCALE
|
|
36103
|
+
);
|
|
36104
|
+
const tickDown = TickMath.getTickAtSqrtRatio(sqrtPriceX96Down);
|
|
36105
|
+
const tickUp = TickMath.getTickAtSqrtRatio(sqrtPriceX96Up);
|
|
36106
|
+
const amount0AtPriceDrop = PositionMath.getToken0Amount(
|
|
36107
|
+
tickDown,
|
|
36108
|
+
Number(tickLower),
|
|
36109
|
+
Number(tickUpper),
|
|
36110
|
+
sqrtPriceX96Down,
|
|
36111
|
+
liquidity
|
|
36112
|
+
);
|
|
36113
|
+
const amount1AtPriceRise = PositionMath.getToken1Amount(
|
|
36114
|
+
tickUp,
|
|
36115
|
+
Number(tickLower),
|
|
36116
|
+
Number(tickUpper),
|
|
36117
|
+
sqrtPriceX96Up,
|
|
36118
|
+
liquidity
|
|
36119
|
+
);
|
|
36120
|
+
const amount0Max = amount0AtPriceDrop > amount0AtCurrent ? amount0AtPriceDrop : amount0AtCurrent;
|
|
36121
|
+
const amount1Max = amount1AtPriceRise > amount1AtCurrent ? amount1AtPriceRise : amount1AtCurrent;
|
|
36122
|
+
return { amount0Max, amount1Max };
|
|
36123
|
+
}
|
|
36124
|
+
/**
|
|
36125
|
+
* Integer square root via Newton's method. Returns floor(sqrt(n)).
|
|
36126
|
+
*/
|
|
36127
|
+
static sqrtBigInt(n) {
|
|
36128
|
+
if (n < 0n) throw new Error("sqrtBigInt: negative input");
|
|
36129
|
+
if (n < 2n) return n;
|
|
36130
|
+
let x = 1n << (BigInt(n.toString(2).length) + 1n) / 2n;
|
|
36131
|
+
while (true) {
|
|
36132
|
+
const next = (x + n / x) / 2n;
|
|
36133
|
+
if (next >= x) return x;
|
|
36134
|
+
x = next;
|
|
36135
|
+
}
|
|
36136
|
+
}
|
|
36075
36137
|
/**
|
|
36076
36138
|
* Helper: Convert price to nearest valid tick
|
|
36077
36139
|
* @param price - The price as a number
|