@sodax/sdk 1.5.5-beta → 1.5.7-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 +95 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +15 -2
- package/dist/index.d.ts +15 -2
- package/dist/index.mjs +95 -12
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -14958,7 +14958,7 @@ declare class ClService {
|
|
|
14958
14958
|
* @param currentTick - Current pool tick
|
|
14959
14959
|
* @returns The required amount of token1
|
|
14960
14960
|
*/
|
|
14961
|
-
static calculateAmount1FromAmount0(amount0: bigint, tickLower: bigint, tickUpper: bigint, currentTick: bigint): bigint;
|
|
14961
|
+
static calculateAmount1FromAmount0(amount0: bigint, tickLower: bigint, tickUpper: bigint, currentTick: bigint, sqrtPriceX96: bigint): bigint;
|
|
14962
14962
|
/**
|
|
14963
14963
|
* Helper: Calculate token0 amount needed given token1 amount and price range
|
|
14964
14964
|
* @param amount1 - Amount of token1
|
|
@@ -14967,7 +14967,20 @@ declare class ClService {
|
|
|
14967
14967
|
* @param currentTick - Current pool tick
|
|
14968
14968
|
* @returns The required amount of token0
|
|
14969
14969
|
*/
|
|
14970
|
-
static calculateAmount0FromAmount1(amount1: bigint, tickLower: bigint, tickUpper: bigint, currentTick: bigint): bigint;
|
|
14970
|
+
static calculateAmount0FromAmount1(amount1: bigint, tickLower: bigint, tickUpper: bigint, currentTick: bigint, sqrtPriceX96: 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
|
@@ -14958,7 +14958,7 @@ declare class ClService {
|
|
|
14958
14958
|
* @param currentTick - Current pool tick
|
|
14959
14959
|
* @returns The required amount of token1
|
|
14960
14960
|
*/
|
|
14961
|
-
static calculateAmount1FromAmount0(amount0: bigint, tickLower: bigint, tickUpper: bigint, currentTick: bigint): bigint;
|
|
14961
|
+
static calculateAmount1FromAmount0(amount0: bigint, tickLower: bigint, tickUpper: bigint, currentTick: bigint, sqrtPriceX96: bigint): bigint;
|
|
14962
14962
|
/**
|
|
14963
14963
|
* Helper: Calculate token0 amount needed given token1 amount and price range
|
|
14964
14964
|
* @param amount1 - Amount of token1
|
|
@@ -14967,7 +14967,20 @@ declare class ClService {
|
|
|
14967
14967
|
* @param currentTick - Current pool tick
|
|
14968
14968
|
* @returns The required amount of token0
|
|
14969
14969
|
*/
|
|
14970
|
-
static calculateAmount0FromAmount1(amount1: bigint, tickLower: bigint, tickUpper: bigint, currentTick: bigint): bigint;
|
|
14970
|
+
static calculateAmount0FromAmount1(amount1: bigint, tickLower: bigint, tickUpper: bigint, currentTick: bigint, sqrtPriceX96: 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 = 41;
|
|
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";
|
|
@@ -8940,7 +8940,8 @@ var HubVaultSymbols = [
|
|
|
8940
8940
|
"sodaNEAR",
|
|
8941
8941
|
"sodaKAIA",
|
|
8942
8942
|
"sodaSTX",
|
|
8943
|
-
"sodaUSDS"
|
|
8943
|
+
"sodaUSDS",
|
|
8944
|
+
"sodaUSDat"
|
|
8944
8945
|
];
|
|
8945
8946
|
var SodaTokens = {
|
|
8946
8947
|
sodaBNB: {
|
|
@@ -9110,6 +9111,13 @@ var SodaTokens = {
|
|
|
9110
9111
|
decimals: 18,
|
|
9111
9112
|
address: "0x243b0c26c8b38793908d7C64e8510f21B19B4613",
|
|
9112
9113
|
xChainId: SONIC_MAINNET_CHAIN_ID
|
|
9114
|
+
},
|
|
9115
|
+
sodaUSDat: {
|
|
9116
|
+
symbol: "sodaUSDat",
|
|
9117
|
+
name: "Soda USDat",
|
|
9118
|
+
decimals: 18,
|
|
9119
|
+
address: "0x67f45e9815c17ec690950d0fd7f6a7cdcceb46d0",
|
|
9120
|
+
xChainId: SONIC_MAINNET_CHAIN_ID
|
|
9113
9121
|
}
|
|
9114
9122
|
};
|
|
9115
9123
|
var SodaTokensAsHubAssets = Object.values(SodaTokens).reduce((acc, token) => {
|
|
@@ -10246,6 +10254,13 @@ var spokeChainConfig = {
|
|
|
10246
10254
|
decimals: 8,
|
|
10247
10255
|
address: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
|
|
10248
10256
|
xChainId: ETHEREUM_MAINNET_CHAIN_ID
|
|
10257
|
+
},
|
|
10258
|
+
sUSDat: {
|
|
10259
|
+
symbol: "sUSDat",
|
|
10260
|
+
name: "Staked USDat",
|
|
10261
|
+
decimals: 18,
|
|
10262
|
+
address: "0xD166337499E176bbC38a1FBd113Ab144e5bd2Df7",
|
|
10263
|
+
xChainId: ETHEREUM_MAINNET_CHAIN_ID
|
|
10249
10264
|
}
|
|
10250
10265
|
}
|
|
10251
10266
|
},
|
|
@@ -11337,6 +11352,13 @@ var hubAssets = {
|
|
|
11337
11352
|
symbol: "WBTC",
|
|
11338
11353
|
name: "Wrapped Bitcoin",
|
|
11339
11354
|
vault: SodaTokens.sodaBTC.address
|
|
11355
|
+
},
|
|
11356
|
+
[spokeChainConfig[ETHEREUM_MAINNET_CHAIN_ID].supportedTokens.sUSDat.address]: {
|
|
11357
|
+
asset: "0x67f45e9815c17ec690950d0fd7f6a7cdcceb46d0",
|
|
11358
|
+
decimal: 18,
|
|
11359
|
+
symbol: "sUSDat",
|
|
11360
|
+
name: "Staked USDat",
|
|
11361
|
+
vault: SodaTokens.sodaUSDat.address
|
|
11340
11362
|
}
|
|
11341
11363
|
},
|
|
11342
11364
|
[KAIA_MAINNET_CHAIN_ID]: {
|
|
@@ -11682,7 +11704,8 @@ var swapSupportedTokens = {
|
|
|
11682
11704
|
spokeChainConfig[ETHEREUM_MAINNET_CHAIN_ID].supportedTokens.USDC,
|
|
11683
11705
|
spokeChainConfig[ETHEREUM_MAINNET_CHAIN_ID].supportedTokens.USDT,
|
|
11684
11706
|
spokeChainConfig[ETHEREUM_MAINNET_CHAIN_ID].supportedTokens.SODA,
|
|
11685
|
-
spokeChainConfig[ETHEREUM_MAINNET_CHAIN_ID].supportedTokens.LL
|
|
11707
|
+
spokeChainConfig[ETHEREUM_MAINNET_CHAIN_ID].supportedTokens.LL,
|
|
11708
|
+
spokeChainConfig[ETHEREUM_MAINNET_CHAIN_ID].supportedTokens.sUSDat
|
|
11686
11709
|
],
|
|
11687
11710
|
[REDBELLY_MAINNET_CHAIN_ID]: [
|
|
11688
11711
|
spokeChainConfig[REDBELLY_MAINNET_CHAIN_ID].supportedTokens.RBNT,
|
|
@@ -35054,7 +35077,7 @@ var AssetService = class {
|
|
|
35054
35077
|
});
|
|
35055
35078
|
}
|
|
35056
35079
|
};
|
|
35057
|
-
var ClService = class {
|
|
35080
|
+
var ClService = class _ClService {
|
|
35058
35081
|
config;
|
|
35059
35082
|
relayerApiEndpoint;
|
|
35060
35083
|
hubProvider;
|
|
@@ -36018,13 +36041,12 @@ var ClService = class {
|
|
|
36018
36041
|
* @param currentTick - Current pool tick
|
|
36019
36042
|
* @returns The required amount of token1
|
|
36020
36043
|
*/
|
|
36021
|
-
static calculateAmount1FromAmount0(amount0, tickLower, tickUpper, currentTick) {
|
|
36044
|
+
static calculateAmount1FromAmount0(amount0, tickLower, tickUpper, currentTick, sqrtPriceX96) {
|
|
36022
36045
|
if (amount0 === 0n) return 0n;
|
|
36023
36046
|
const sqrtRatioX96Lower = TickMath.getSqrtRatioAtTick(Number(tickLower));
|
|
36024
36047
|
const sqrtRatioX96Upper = TickMath.getSqrtRatioAtTick(Number(tickUpper));
|
|
36025
|
-
const sqrtRatioX96Current = TickMath.getSqrtRatioAtTick(Number(currentTick));
|
|
36026
36048
|
const liquidity = maxLiquidityForAmounts(
|
|
36027
|
-
|
|
36049
|
+
sqrtPriceX96,
|
|
36028
36050
|
sqrtRatioX96Lower,
|
|
36029
36051
|
sqrtRatioX96Upper,
|
|
36030
36052
|
amount0,
|
|
@@ -36036,7 +36058,7 @@ var ClService = class {
|
|
|
36036
36058
|
Number(currentTick),
|
|
36037
36059
|
Number(tickLower),
|
|
36038
36060
|
Number(tickUpper),
|
|
36039
|
-
|
|
36061
|
+
sqrtPriceX96,
|
|
36040
36062
|
liquidity
|
|
36041
36063
|
);
|
|
36042
36064
|
return amount1;
|
|
@@ -36049,13 +36071,12 @@ var ClService = class {
|
|
|
36049
36071
|
* @param currentTick - Current pool tick
|
|
36050
36072
|
* @returns The required amount of token0
|
|
36051
36073
|
*/
|
|
36052
|
-
static calculateAmount0FromAmount1(amount1, tickLower, tickUpper, currentTick) {
|
|
36074
|
+
static calculateAmount0FromAmount1(amount1, tickLower, tickUpper, currentTick, sqrtPriceX96) {
|
|
36053
36075
|
if (amount1 === 0n) return 0n;
|
|
36054
36076
|
const sqrtRatioX96Lower = TickMath.getSqrtRatioAtTick(Number(tickLower));
|
|
36055
36077
|
const sqrtRatioX96Upper = TickMath.getSqrtRatioAtTick(Number(tickUpper));
|
|
36056
|
-
const sqrtRatioX96Current = TickMath.getSqrtRatioAtTick(Number(currentTick));
|
|
36057
36078
|
const liquidity = maxLiquidityForAmounts(
|
|
36058
|
-
|
|
36079
|
+
sqrtPriceX96,
|
|
36059
36080
|
sqrtRatioX96Lower,
|
|
36060
36081
|
sqrtRatioX96Upper,
|
|
36061
36082
|
BigInt("0xffffffffffffffffffffffffffffffff"),
|
|
@@ -36067,11 +36088,73 @@ var ClService = class {
|
|
|
36067
36088
|
Number(currentTick),
|
|
36068
36089
|
Number(tickLower),
|
|
36069
36090
|
Number(tickUpper),
|
|
36070
|
-
|
|
36091
|
+
sqrtPriceX96,
|
|
36071
36092
|
liquidity
|
|
36072
36093
|
);
|
|
36073
36094
|
return amount0;
|
|
36074
36095
|
}
|
|
36096
|
+
/**
|
|
36097
|
+
* Calculate amount0Max and amount1Max for a given liquidity and slippage tolerance.
|
|
36098
|
+
* For concentrated liquidity, a price drop increases the amount0 needed and a price rise increases the amount1 needed.
|
|
36099
|
+
* This calculates the worst-case amounts for each token independently.
|
|
36100
|
+
*/
|
|
36101
|
+
static calculateMaxAmountsForSlippage(liquidity, tickLower, tickUpper, currentTick, sqrtPriceX96, slippagePercent) {
|
|
36102
|
+
const amount0AtCurrent = PositionMath.getToken0Amount(
|
|
36103
|
+
Number(currentTick),
|
|
36104
|
+
Number(tickLower),
|
|
36105
|
+
Number(tickUpper),
|
|
36106
|
+
sqrtPriceX96,
|
|
36107
|
+
liquidity
|
|
36108
|
+
);
|
|
36109
|
+
const amount1AtCurrent = PositionMath.getToken1Amount(
|
|
36110
|
+
Number(currentTick),
|
|
36111
|
+
Number(tickLower),
|
|
36112
|
+
Number(tickUpper),
|
|
36113
|
+
sqrtPriceX96,
|
|
36114
|
+
liquidity
|
|
36115
|
+
);
|
|
36116
|
+
const SLIPPAGE_SCALE = 1000000000n;
|
|
36117
|
+
const slippageScaled = BigInt(Math.round(slippagePercent * Number(SLIPPAGE_SCALE) / 100));
|
|
36118
|
+
const sqrtPriceX96Squared = sqrtPriceX96 * sqrtPriceX96;
|
|
36119
|
+
const sqrtPriceX96Down = _ClService.sqrtBigInt(
|
|
36120
|
+
sqrtPriceX96Squared * (SLIPPAGE_SCALE - slippageScaled) / SLIPPAGE_SCALE
|
|
36121
|
+
);
|
|
36122
|
+
const sqrtPriceX96Up = _ClService.sqrtBigInt(
|
|
36123
|
+
sqrtPriceX96Squared * (SLIPPAGE_SCALE + slippageScaled) / SLIPPAGE_SCALE
|
|
36124
|
+
);
|
|
36125
|
+
const tickDown = TickMath.getTickAtSqrtRatio(sqrtPriceX96Down);
|
|
36126
|
+
const tickUp = TickMath.getTickAtSqrtRatio(sqrtPriceX96Up);
|
|
36127
|
+
const amount0AtPriceDrop = PositionMath.getToken0Amount(
|
|
36128
|
+
tickDown,
|
|
36129
|
+
Number(tickLower),
|
|
36130
|
+
Number(tickUpper),
|
|
36131
|
+
sqrtPriceX96Down,
|
|
36132
|
+
liquidity
|
|
36133
|
+
);
|
|
36134
|
+
const amount1AtPriceRise = PositionMath.getToken1Amount(
|
|
36135
|
+
tickUp,
|
|
36136
|
+
Number(tickLower),
|
|
36137
|
+
Number(tickUpper),
|
|
36138
|
+
sqrtPriceX96Up,
|
|
36139
|
+
liquidity
|
|
36140
|
+
);
|
|
36141
|
+
const amount0Max = amount0AtPriceDrop > amount0AtCurrent ? amount0AtPriceDrop : amount0AtCurrent;
|
|
36142
|
+
const amount1Max = amount1AtPriceRise > amount1AtCurrent ? amount1AtPriceRise : amount1AtCurrent;
|
|
36143
|
+
return { amount0Max, amount1Max };
|
|
36144
|
+
}
|
|
36145
|
+
/**
|
|
36146
|
+
* Integer square root via Newton's method. Returns floor(sqrt(n)).
|
|
36147
|
+
*/
|
|
36148
|
+
static sqrtBigInt(n) {
|
|
36149
|
+
if (n < 0n) throw new Error("sqrtBigInt: negative input");
|
|
36150
|
+
if (n < 2n) return n;
|
|
36151
|
+
let x = 1n << (BigInt(n.toString(2).length) + 1n) / 2n;
|
|
36152
|
+
while (true) {
|
|
36153
|
+
const next = (x + n / x) / 2n;
|
|
36154
|
+
if (next >= x) return x;
|
|
36155
|
+
x = next;
|
|
36156
|
+
}
|
|
36157
|
+
}
|
|
36075
36158
|
/**
|
|
36076
36159
|
* Helper: Convert price to nearest valid tick
|
|
36077
36160
|
* @param price - The price as a number
|