@sodax/sdk 1.5.4-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 +69 -7
- 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 +69 -7
- 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
|
@@ -8713,7 +8713,7 @@ var universalRouterAbi = [
|
|
|
8713
8713
|
];
|
|
8714
8714
|
|
|
8715
8715
|
// ../types/dist/constants/index.js
|
|
8716
|
-
var CONFIG_VERSION =
|
|
8716
|
+
var CONFIG_VERSION = 40;
|
|
8717
8717
|
var AVALANCHE_MAINNET_CHAIN_ID = "0xa86a.avax";
|
|
8718
8718
|
var ARBITRUM_MAINNET_CHAIN_ID = "0xa4b1.arbitrum";
|
|
8719
8719
|
var BASE_MAINNET_CHAIN_ID = "0x2105.base";
|
|
@@ -9854,7 +9854,7 @@ var spokeChainConfig = {
|
|
|
9854
9854
|
},
|
|
9855
9855
|
[BITCOIN_MAINNET_CHAIN_ID]: {
|
|
9856
9856
|
addresses: {
|
|
9857
|
-
assetManager: "
|
|
9857
|
+
assetManager: "bc1pcz4pyrfgv7v6tx8a404mafyvt73cnm80yuv8tqwrywxmqxpja8ys4pjyl5"
|
|
9858
9858
|
},
|
|
9859
9859
|
chain: baseChainInfo[BITCOIN_MAINNET_CHAIN_ID],
|
|
9860
9860
|
bnUSD: "no",
|
|
@@ -11660,10 +11660,10 @@ var swapSupportedTokens = {
|
|
|
11660
11660
|
spokeChainConfig[SUI_MAINNET_CHAIN_ID].supportedTokens.WAL
|
|
11661
11661
|
],
|
|
11662
11662
|
[INJECTIVE_MAINNET_CHAIN_ID]: [
|
|
11663
|
-
|
|
11664
|
-
|
|
11665
|
-
|
|
11666
|
-
spokeChainConfig[INJECTIVE_MAINNET_CHAIN_ID].supportedTokens.SODA
|
|
11663
|
+
spokeChainConfig[INJECTIVE_MAINNET_CHAIN_ID].supportedTokens.INJ,
|
|
11664
|
+
spokeChainConfig[INJECTIVE_MAINNET_CHAIN_ID].supportedTokens.bnUSD,
|
|
11665
|
+
spokeChainConfig[INJECTIVE_MAINNET_CHAIN_ID].supportedTokens.USDC
|
|
11666
|
+
// spokeChainConfig[INJECTIVE_MAINNET_CHAIN_ID].supportedTokens.SODA, // NOTE: not in solver wiki
|
|
11667
11667
|
],
|
|
11668
11668
|
[NEAR_MAINNET_CHAIN_ID]: [
|
|
11669
11669
|
spokeChainConfig[NEAR_MAINNET_CHAIN_ID].supportedTokens.NEAR,
|
|
@@ -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
|