@magmaprotocol/magma-clmm-sdk 0.5.38 → 0.5.39

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.js CHANGED
@@ -92,7 +92,6 @@ __export(src_exports, {
92
92
  SUI_SYSTEM_STATE_OBJECT_ID: () => SUI_SYSTEM_STATE_OBJECT_ID,
93
93
  SplitSwap: () => SplitSwap,
94
94
  SplitUnit: () => SplitUnit,
95
- StrategyType: () => StrategyType,
96
95
  SwapDirection: () => SwapDirection,
97
96
  SwapModule: () => SwapModule,
98
97
  SwapUtils: () => SwapUtils,
@@ -114,10 +113,6 @@ __export(src_exports, {
114
113
  adjustForSlippage: () => adjustForSlippage,
115
114
  asIntN: () => asIntN,
116
115
  asUintN: () => asUintN,
117
- autoFillXByStrategy: () => autoFillXByStrategy,
118
- autoFillXByWeight: () => autoFillXByWeight,
119
- autoFillYByStrategy: () => autoFillYByStrategy,
120
- autoFillYByWeight: () => autoFillYByWeight,
121
116
  bufferToHex: () => bufferToHex,
122
117
  buildClmmPositionName: () => buildClmmPositionName,
123
118
  buildNFT: () => buildNFT,
@@ -156,14 +151,12 @@ __export(src_exports, {
156
151
  getAmountUnfixedDelta: () => getAmountUnfixedDelta,
157
152
  getCoinAFromLiquidity: () => getCoinAFromLiquidity,
158
153
  getCoinBFromLiquidity: () => getCoinBFromLiquidity,
159
- getCoinXYForLiquidity: () => getCoinXYForLiquidity,
160
154
  getDefaultSuiInputType: () => getDefaultSuiInputType,
161
155
  getDeltaA: () => getDeltaA,
162
156
  getDeltaB: () => getDeltaB,
163
157
  getDeltaDownFromOutput: () => getDeltaDownFromOutput,
164
158
  getDeltaUpFromInput: () => getDeltaUpFromInput,
165
159
  getFutureTime: () => getFutureTime,
166
- getLiquidityAndCoinYByCoinX: () => getLiquidityAndCoinYByCoinX,
167
160
  getLiquidityFromCoinA: () => getLiquidityFromCoinA,
168
161
  getLiquidityFromCoinB: () => getLiquidityFromCoinB,
169
162
  getLowerSqrtPriceFromCoinA: () => getLowerSqrtPriceFromCoinA,
@@ -187,7 +180,6 @@ __export(src_exports, {
187
180
  getObjectType: () => getObjectType,
188
181
  getObjectVersion: () => getObjectVersion,
189
182
  getPackagerConfigs: () => getPackagerConfigs,
190
- getPriceOfBinByBinId: () => getPriceOfBinByBinId,
191
183
  getRewardInTickRange: () => getRewardInTickRange,
192
184
  getSuiObjectData: () => getSuiObjectData,
193
185
  getTickDataFromUrlData: () => getTickDataFromUrlData,
@@ -211,16 +203,11 @@ __export(src_exports, {
211
203
  shortAddress: () => shortAddress,
212
204
  shortString: () => shortString,
213
205
  tickScore: () => tickScore,
214
- toAmountAskSide: () => toAmountAskSide,
215
- toAmountBidSide: () => toAmountBidSide,
216
- toAmountBothSide: () => toAmountBothSide,
217
- toAmountsBothSideByStrategy: () => toAmountsBothSideByStrategy,
218
206
  toBuffer: () => toBuffer,
219
207
  toCoinAmount: () => toCoinAmount,
220
208
  toDecimalsAmount: () => toDecimalsAmount,
221
209
  transClmmpoolDataWithoutTicks: () => transClmmpoolDataWithoutTicks,
222
- utf8to16: () => utf8to16,
223
- withLiquiditySlippage: () => withLiquiditySlippage
210
+ utf8to16: () => utf8to16
224
211
  });
225
212
  module.exports = __toCommonJS(src_exports);
226
213
 
@@ -256,7 +243,7 @@ var CachedContent = class {
256
243
  };
257
244
 
258
245
  // src/utils/common.ts
259
- var import_bn13 = __toESM(require("bn.js"));
246
+ var import_bn11 = __toESM(require("bn.js"));
260
247
  var import_bcs = require("@mysten/bcs");
261
248
  var import_ed25519 = require("@mysten/sui/keypairs/ed25519");
262
249
  var import_secp256k1 = require("@mysten/sui/keypairs/secp256k1");
@@ -1811,660 +1798,8 @@ function collectFeesQuote(param) {
1811
1798
  return updateFees(param.position, fee_growth_inside_a, fee_growth_inside_b);
1812
1799
  }
1813
1800
 
1814
- // src/math/dlmmStrategy.ts
1815
- var import_bn10 = __toESM(require("bn.js"));
1816
-
1817
- // src/math/dlmmWeightToAmounts.ts
1818
- var import_bn9 = __toESM(require("bn.js"));
1819
- var import_decimal6 = __toESM(require("decimal.js"));
1820
- var import_calc_dlmm = require("@magmaprotocol/calc_dlmm");
1821
- function getPriceOfBinByBinId(binId, binStep) {
1822
- const twoDec = new import_decimal6.default(2);
1823
- const price = new import_decimal6.default((0, import_calc_dlmm.get_price_from_real_id)(binId, binStep));
1824
- return price.div(twoDec.pow(128));
1825
- }
1826
- function autoFillYByWeight(activeId, binStep, amountX, amountXInActiveBin, amountYInActiveBin, distributions) {
1827
- const activeBins = distributions.filter((element) => {
1828
- return element.binId === activeId;
1829
- });
1830
- if (activeBins.length === 1) {
1831
- const p0 = getPriceOfBinByBinId(activeId, binStep);
1832
- let wx0 = new import_decimal6.default(0);
1833
- let wy0 = new import_decimal6.default(0);
1834
- const activeBin = activeBins[0];
1835
- if (amountXInActiveBin.isZero() && amountYInActiveBin.isZero()) {
1836
- wx0 = new import_decimal6.default(activeBin.weight).div(p0.mul(new import_decimal6.default(2)));
1837
- wy0 = new import_decimal6.default(activeBin.weight).div(new import_decimal6.default(2));
1838
- } else {
1839
- const amountXInActiveBinDec = new import_decimal6.default(amountXInActiveBin.toString());
1840
- const amountYInActiveBinDec = new import_decimal6.default(amountYInActiveBin.toString());
1841
- if (!amountXInActiveBin.isZero()) {
1842
- wx0 = new import_decimal6.default(activeBin.weight).div(p0.add(amountYInActiveBinDec.div(amountXInActiveBinDec)));
1843
- }
1844
- if (!amountYInActiveBin.isZero()) {
1845
- wy0 = new import_decimal6.default(activeBin.weight).div(new import_decimal6.default(1).add(p0.mul(amountXInActiveBinDec).div(amountYInActiveBinDec)));
1846
- }
1847
- }
1848
- let totalWeightX2 = wx0;
1849
- let totalWeightY2 = wy0;
1850
- distributions.forEach((element) => {
1851
- if (element.binId < activeId) {
1852
- totalWeightY2 = totalWeightY2.add(new import_decimal6.default(element.weight));
1853
- }
1854
- if (element.binId > activeId) {
1855
- const price = getPriceOfBinByBinId(element.binId, binStep);
1856
- const weighPerPrice = new import_decimal6.default(element.weight).div(price);
1857
- totalWeightX2 = totalWeightX2.add(weighPerPrice);
1858
- }
1859
- });
1860
- const kx2 = totalWeightX2.isZero() ? new import_decimal6.default(1) : new import_decimal6.default(amountX.toString()).div(totalWeightX2);
1861
- const amountY2 = kx2.mul(totalWeightY2);
1862
- return new import_bn9.default(amountY2.floor().toString());
1863
- }
1864
- let totalWeightX = new import_decimal6.default(0);
1865
- let totalWeightY = new import_decimal6.default(0);
1866
- distributions.forEach((element) => {
1867
- if (element.binId < activeId) {
1868
- totalWeightY = totalWeightY.add(new import_decimal6.default(element.weight));
1869
- } else {
1870
- const price = getPriceOfBinByBinId(element.binId, binStep);
1871
- const weighPerPrice = new import_decimal6.default(element.weight).div(price);
1872
- totalWeightX = totalWeightX.add(weighPerPrice);
1873
- }
1874
- });
1875
- const kx = totalWeightX.isZero() ? new import_decimal6.default(1) : new import_decimal6.default(amountX.toString()).div(totalWeightX);
1876
- const amountY = kx.mul(totalWeightY);
1877
- return new import_bn9.default(amountY.floor().toString());
1878
- }
1879
- function autoFillXByWeight(activeId, binStep, amountY, amountXInActiveBin, amountYInActiveBin, distributions) {
1880
- const activeBins = distributions.filter((element) => {
1881
- return element.binId === activeId;
1882
- });
1883
- if (activeBins.length === 1) {
1884
- const p0 = getPriceOfBinByBinId(activeId, binStep);
1885
- let wx0 = new import_decimal6.default(0);
1886
- let wy0 = new import_decimal6.default(0);
1887
- const activeBin = activeBins[0];
1888
- if (amountXInActiveBin.isZero() && amountYInActiveBin.isZero()) {
1889
- wx0 = new import_decimal6.default(activeBin.weight).div(p0.mul(new import_decimal6.default(2)));
1890
- wy0 = new import_decimal6.default(activeBin.weight).div(new import_decimal6.default(2));
1891
- } else {
1892
- const amountXInActiveBinDec = new import_decimal6.default(amountXInActiveBin.toString());
1893
- const amountYInActiveBinDec = new import_decimal6.default(amountYInActiveBin.toString());
1894
- if (!amountXInActiveBin.isZero()) {
1895
- wx0 = new import_decimal6.default(activeBin.weight).div(p0.add(amountYInActiveBinDec.div(amountXInActiveBinDec)));
1896
- }
1897
- if (!amountYInActiveBin.isZero()) {
1898
- wy0 = new import_decimal6.default(activeBin.weight).div(new import_decimal6.default(1).add(p0.mul(amountXInActiveBinDec).div(amountYInActiveBinDec)));
1899
- }
1900
- }
1901
- let totalWeightX2 = wx0;
1902
- let totalWeightY2 = wy0;
1903
- distributions.forEach((element) => {
1904
- if (element.binId < activeId) {
1905
- totalWeightY2 = totalWeightY2.add(new import_decimal6.default(element.weight));
1906
- }
1907
- if (element.binId > activeId) {
1908
- const price = getPriceOfBinByBinId(element.binId, binStep);
1909
- const weighPerPrice = new import_decimal6.default(element.weight).div(price);
1910
- totalWeightX2 = totalWeightX2.add(weighPerPrice);
1911
- }
1912
- });
1913
- const ky2 = totalWeightY2.isZero() ? new import_decimal6.default(1) : new import_decimal6.default(amountY.toString()).div(totalWeightY2);
1914
- const amountX2 = ky2.mul(totalWeightX2);
1915
- return new import_bn9.default(amountX2.floor().toString());
1916
- }
1917
- let totalWeightX = new import_decimal6.default(0);
1918
- let totalWeightY = new import_decimal6.default(0);
1919
- distributions.forEach((element) => {
1920
- if (element.binId < activeId) {
1921
- totalWeightY = totalWeightY.add(new import_decimal6.default(element.weight));
1922
- } else {
1923
- const price = getPriceOfBinByBinId(element.binId, binStep);
1924
- const weighPerPrice = new import_decimal6.default(element.weight).div(price);
1925
- totalWeightX = totalWeightX.add(weighPerPrice);
1926
- }
1927
- });
1928
- const ky = totalWeightY.isZero() ? new import_decimal6.default(1) : new import_decimal6.default(amountY.toString()).div(totalWeightY);
1929
- const amountX = ky.mul(totalWeightX);
1930
- return new import_bn9.default(amountX.floor().toString());
1931
- }
1932
- function toAmountBidSide(activeId, totalAmount, distributions) {
1933
- const totalWeight = distributions.reduce((sum, el) => {
1934
- return el.binId > activeId ? sum : sum.add(el.weight);
1935
- }, new import_decimal6.default(0));
1936
- if (totalWeight.cmp(new import_decimal6.default(0)) !== 1) {
1937
- throw Error("Invalid parameteres");
1938
- }
1939
- return distributions.map((bin) => {
1940
- if (bin.binId > activeId) {
1941
- return {
1942
- binId: bin.binId,
1943
- amount: new import_bn9.default(0)
1944
- };
1945
- }
1946
- return {
1947
- binId: bin.binId,
1948
- amount: new import_bn9.default(new import_decimal6.default(totalAmount.toString()).mul(new import_decimal6.default(bin.weight).div(totalWeight)).floor().toString())
1949
- };
1950
- });
1951
- }
1952
- function toAmountAskSide(activeId, binStep, totalAmount, distributions) {
1953
- const totalWeight = distributions.reduce((sum, el) => {
1954
- if (el.binId < activeId) {
1955
- return sum;
1956
- }
1957
- const price = getPriceOfBinByBinId(el.binId, binStep);
1958
- const weightPerPrice = new import_decimal6.default(el.weight).div(price);
1959
- return sum.add(weightPerPrice);
1960
- }, new import_decimal6.default(0));
1961
- if (totalWeight.cmp(new import_decimal6.default(0)) !== 1) {
1962
- throw Error("Invalid parameteres");
1963
- }
1964
- return distributions.map((bin) => {
1965
- if (bin.binId < activeId) {
1966
- return {
1967
- binId: bin.binId,
1968
- amount: new import_bn9.default(0)
1969
- };
1970
- }
1971
- const price = getPriceOfBinByBinId(bin.binId, binStep);
1972
- const weightPerPrice = new import_decimal6.default(bin.weight).div(price);
1973
- return {
1974
- binId: bin.binId,
1975
- amount: new import_bn9.default(new import_decimal6.default(totalAmount.toString()).mul(weightPerPrice).div(totalWeight).floor().toString())
1976
- };
1977
- });
1978
- }
1979
- function toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, distributions) {
1980
- if (activeId > distributions[distributions.length - 1].binId) {
1981
- const amounts = toAmountBidSide(activeId, amountY, distributions);
1982
- return amounts.map((bin) => {
1983
- return {
1984
- binId: bin.binId,
1985
- amountX: new import_bn9.default(0),
1986
- amountY: bin.amount
1987
- };
1988
- });
1989
- }
1990
- if (activeId < distributions[0].binId) {
1991
- const amounts = toAmountAskSide(activeId, binStep, amountX, distributions);
1992
- return amounts.map((bin) => {
1993
- return {
1994
- binId: bin.binId,
1995
- amountX: bin.amount,
1996
- amountY: new import_bn9.default(0)
1997
- };
1998
- });
1999
- }
2000
- const activeBins = distributions.filter((element) => {
2001
- return element.binId === activeId;
2002
- });
2003
- if (activeBins.length === 1) {
2004
- const p0 = getPriceOfBinByBinId(activeId, binStep);
2005
- let wx0 = new import_decimal6.default(0);
2006
- let wy0 = new import_decimal6.default(0);
2007
- const activeBin = activeBins[0];
2008
- if (amountXInActiveBin.isZero() && amountYInActiveBin.isZero()) {
2009
- wx0 = new import_decimal6.default(activeBin.weight).div(p0.mul(new import_decimal6.default(2)));
2010
- wy0 = new import_decimal6.default(activeBin.weight).div(new import_decimal6.default(2));
2011
- } else {
2012
- const amountXInActiveBinDec = new import_decimal6.default(amountXInActiveBin.toString());
2013
- const amountYInActiveBinDec = new import_decimal6.default(amountYInActiveBin.toString());
2014
- if (!amountXInActiveBin.isZero()) {
2015
- wx0 = new import_decimal6.default(activeBin.weight).div(p0.add(amountYInActiveBinDec.div(amountXInActiveBinDec)));
2016
- }
2017
- if (!amountYInActiveBin.isZero()) {
2018
- wy0 = new import_decimal6.default(activeBin.weight).div(new import_decimal6.default(1).add(p0.mul(amountXInActiveBinDec).div(amountYInActiveBinDec)));
2019
- }
2020
- }
2021
- let totalWeightX2 = wx0;
2022
- let totalWeightY2 = wy0;
2023
- distributions.forEach((element) => {
2024
- if (element.binId < activeId) {
2025
- totalWeightY2 = totalWeightY2.add(new import_decimal6.default(element.weight));
2026
- }
2027
- if (element.binId > activeId) {
2028
- const price = getPriceOfBinByBinId(element.binId, binStep);
2029
- const weighPerPrice = new import_decimal6.default(element.weight).div(price);
2030
- totalWeightX2 = totalWeightX2.add(weighPerPrice);
2031
- }
2032
- });
2033
- const kx2 = new import_decimal6.default(amountX.toString()).div(totalWeightX2);
2034
- const ky2 = new import_decimal6.default(amountY.toString()).div(totalWeightY2);
2035
- const k2 = kx2.lessThan(ky2) ? kx2 : ky2;
2036
- return distributions.map((bin) => {
2037
- if (bin.binId < activeId) {
2038
- const amount = k2.mul(new import_decimal6.default(bin.weight));
2039
- return {
2040
- binId: bin.binId,
2041
- amountX: new import_bn9.default(0),
2042
- amountY: new import_bn9.default(amount.floor().toString())
2043
- };
2044
- }
2045
- if (bin.binId > activeId) {
2046
- const price = getPriceOfBinByBinId(bin.binId, binStep);
2047
- const weighPerPrice = new import_decimal6.default(bin.weight).div(price);
2048
- const amount = k2.mul(weighPerPrice);
2049
- return {
2050
- binId: bin.binId,
2051
- amountX: new import_bn9.default(amount.floor().toString()),
2052
- amountY: new import_bn9.default(0)
2053
- };
2054
- }
2055
- const amountXActiveBin = k2.mul(wx0);
2056
- const amountYActiveBin = k2.mul(wy0);
2057
- return {
2058
- binId: bin.binId,
2059
- amountX: new import_bn9.default(amountXActiveBin.floor().toString()),
2060
- amountY: new import_bn9.default(amountYActiveBin.floor().toString())
2061
- };
2062
- });
2063
- }
2064
- let totalWeightX = new import_decimal6.default(0);
2065
- let totalWeightY = new import_decimal6.default(0);
2066
- distributions.forEach((element) => {
2067
- if (element.binId < activeId) {
2068
- totalWeightY = totalWeightY.add(new import_decimal6.default(element.weight));
2069
- } else {
2070
- const price = getPriceOfBinByBinId(element.binId, binStep);
2071
- const weighPerPrice = new import_decimal6.default(element.weight).div(price);
2072
- totalWeightX = totalWeightX.add(weighPerPrice);
2073
- }
2074
- });
2075
- const kx = new import_decimal6.default(amountX.toString()).div(totalWeightX);
2076
- const ky = new import_decimal6.default(amountY.toString()).div(totalWeightY);
2077
- const k = kx.lessThan(ky) ? kx : ky;
2078
- return distributions.map((bin) => {
2079
- if (bin.binId < activeId) {
2080
- const amount2 = k.mul(new import_decimal6.default(bin.weight));
2081
- return {
2082
- binId: bin.binId,
2083
- amountX: new import_bn9.default(0),
2084
- amountY: new import_bn9.default(amount2.floor().toString())
2085
- };
2086
- }
2087
- const price = getPriceOfBinByBinId(bin.binId, binStep);
2088
- const weighPerPrice = new import_decimal6.default(bin.weight).div(price);
2089
- const amount = k.mul(weighPerPrice);
2090
- return {
2091
- binId: bin.binId,
2092
- amountX: new import_bn9.default(amount.floor().toString()),
2093
- amountY: new import_bn9.default(0)
2094
- };
2095
- });
2096
- }
2097
-
2098
- // src/math/dlmmStrategy.ts
2099
- var StrategyType = /* @__PURE__ */ ((StrategyType2) => {
2100
- StrategyType2[StrategyType2["Spot"] = 0] = "Spot";
2101
- StrategyType2[StrategyType2["Curve"] = 1] = "Curve";
2102
- StrategyType2[StrategyType2["BidAsk"] = 2] = "BidAsk";
2103
- return StrategyType2;
2104
- })(StrategyType || {});
2105
- function toWeightDecendingOrder(minBinId, maxBinId) {
2106
- const distributions = [];
2107
- for (let i = minBinId; i <= maxBinId; i++) {
2108
- distributions.push({
2109
- binId: i,
2110
- weight: maxBinId - i + 1
2111
- });
2112
- }
2113
- return distributions;
2114
- }
2115
- function toWeightAscendingOrder(minBinId, maxBinId) {
2116
- const distributions = [];
2117
- for (let i = minBinId; i <= maxBinId; i++) {
2118
- distributions.push({
2119
- binId: i,
2120
- weight: i - minBinId + 1
2121
- });
2122
- }
2123
- return distributions;
2124
- }
2125
- function toWeightSpotBalanced(minBinId, maxBinId) {
2126
- const distributions = [];
2127
- for (let i = minBinId; i <= maxBinId; i++) {
2128
- distributions.push({
2129
- binId: i,
2130
- weight: 1
2131
- });
2132
- }
2133
- return distributions;
2134
- }
2135
- var DEFAULT_MAX_WEIGHT = 2e3;
2136
- var DEFAULT_MIN_WEIGHT = 200;
2137
- function toWeightCurve(minBinId, maxBinId, activeId) {
2138
- if (activeId < minBinId || activeId > maxBinId) {
2139
- throw new ClmmpoolsError("Invalid strategy params", "InvalidParams" /* InvalidParams */);
2140
- }
2141
- const maxWeight = DEFAULT_MAX_WEIGHT;
2142
- const minWeight = DEFAULT_MIN_WEIGHT;
2143
- const diffWeight = maxWeight - minWeight;
2144
- const diffMinWeight = activeId > minBinId ? Math.floor(diffWeight / (activeId - minBinId)) : 0;
2145
- const diffMaxWeight = maxBinId > activeId ? Math.floor(diffWeight / (maxBinId - activeId)) : 0;
2146
- const distributions = [];
2147
- for (let i = minBinId; i <= maxBinId; i++) {
2148
- if (i < activeId) {
2149
- distributions.push({
2150
- binId: i,
2151
- weight: maxWeight - (activeId - i) * diffMinWeight
2152
- });
2153
- } else if (i > activeId) {
2154
- distributions.push({
2155
- binId: i,
2156
- weight: maxWeight - (i - activeId) * diffMaxWeight
2157
- });
2158
- } else {
2159
- distributions.push({
2160
- binId: i,
2161
- weight: maxWeight
2162
- });
2163
- }
2164
- }
2165
- return distributions;
2166
- }
2167
- function toWeightBidAsk(minBinId, maxBinId, activeId) {
2168
- if (activeId < minBinId || activeId > maxBinId) {
2169
- throw new ClmmpoolsError("Invalid strategy params", "InvalidParams" /* InvalidParams */);
2170
- }
2171
- const maxWeight = DEFAULT_MAX_WEIGHT;
2172
- const minWeight = DEFAULT_MIN_WEIGHT;
2173
- const diffWeight = maxWeight - minWeight;
2174
- const diffMinWeight = activeId > minBinId ? Math.floor(diffWeight / (activeId - minBinId)) : 0;
2175
- const diffMaxWeight = maxBinId > activeId ? Math.floor(diffWeight / (maxBinId - activeId)) : 0;
2176
- const distributions = [];
2177
- for (let i = minBinId; i <= maxBinId; i++) {
2178
- if (i < activeId) {
2179
- distributions.push({
2180
- binId: i,
2181
- weight: minWeight + (activeId - i) * diffMinWeight
2182
- });
2183
- } else if (i > activeId) {
2184
- distributions.push({
2185
- binId: i,
2186
- weight: minWeight + (i - activeId) * diffMaxWeight
2187
- });
2188
- } else {
2189
- distributions.push({
2190
- binId: i,
2191
- weight: minWeight
2192
- });
2193
- }
2194
- }
2195
- return distributions;
2196
- }
2197
- function autoFillYByStrategy(activeId, binStep, amountX, amountXInActiveBin, amountYInActiveBin, minBinId, maxBinId, strategyType) {
2198
- switch (strategyType) {
2199
- case 0 /* Spot */: {
2200
- const weights = toWeightSpotBalanced(minBinId, maxBinId);
2201
- return autoFillYByWeight(activeId, binStep, amountX, amountXInActiveBin, amountYInActiveBin, weights);
2202
- }
2203
- case 1 /* Curve */: {
2204
- const weights = toWeightCurve(minBinId, maxBinId, activeId);
2205
- return autoFillYByWeight(activeId, binStep, amountX, amountXInActiveBin, amountYInActiveBin, weights);
2206
- }
2207
- case 2 /* BidAsk */: {
2208
- const weights = toWeightBidAsk(minBinId, maxBinId, activeId);
2209
- return autoFillYByWeight(activeId, binStep, amountX, amountXInActiveBin, amountYInActiveBin, weights);
2210
- }
2211
- default:
2212
- throw new Error(`Unsupported strategy type: ${strategyType}`);
2213
- }
2214
- }
2215
- function autoFillXByStrategy(activeId, binStep, amountY, amountXInActiveBin, amountYInActiveBin, minBinId, maxBinId, strategyType) {
2216
- switch (strategyType) {
2217
- case 0 /* Spot */: {
2218
- const weights = toWeightSpotBalanced(minBinId, maxBinId);
2219
- return autoFillXByWeight(activeId, binStep, amountY, amountXInActiveBin, amountYInActiveBin, weights);
2220
- }
2221
- case 1 /* Curve */: {
2222
- const weights = toWeightCurve(minBinId, maxBinId, activeId);
2223
- return autoFillXByWeight(activeId, binStep, amountY, amountXInActiveBin, amountYInActiveBin, weights);
2224
- }
2225
- case 2 /* BidAsk */: {
2226
- const weights = toWeightBidAsk(minBinId, maxBinId, activeId);
2227
- return autoFillXByWeight(activeId, binStep, amountY, amountXInActiveBin, amountYInActiveBin, weights);
2228
- }
2229
- default:
2230
- throw new Error(`Unsupported strategy type: ${strategyType}`);
2231
- }
2232
- }
2233
- function toAmountsBothSideByStrategy(activeId, binStep, minBinId, maxBinId, amountX, amountY, amountXInActiveBin, amountYInActiveBin, strategyType) {
2234
- const isSingleSideX = amountY.isZero();
2235
- switch (strategyType) {
2236
- case 0 /* Spot */: {
2237
- if (activeId < minBinId || activeId > maxBinId) {
2238
- const weights = toWeightSpotBalanced(minBinId, maxBinId);
2239
- return toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights);
2240
- }
2241
- const amountsInBin = [];
2242
- if (!isSingleSideX) {
2243
- if (minBinId <= activeId) {
2244
- const weights = toWeightSpotBalanced(minBinId, activeId);
2245
- const amounts = toAmountBidSide(activeId, amountY, weights);
2246
- for (const bin of amounts) {
2247
- amountsInBin.push({
2248
- binId: bin.binId,
2249
- amountX: new import_bn10.default(0),
2250
- amountY: bin.amount
2251
- });
2252
- }
2253
- }
2254
- if (activeId < maxBinId) {
2255
- const weights = toWeightSpotBalanced(activeId + 1, maxBinId);
2256
- const amounts = toAmountAskSide(activeId, binStep, amountX, weights);
2257
- for (const bin of amounts) {
2258
- amountsInBin.push({
2259
- binId: bin.binId,
2260
- amountX: bin.amount,
2261
- amountY: new import_bn10.default(0)
2262
- });
2263
- }
2264
- }
2265
- } else {
2266
- if (minBinId < activeId) {
2267
- const weights = toWeightSpotBalanced(minBinId, activeId - 1);
2268
- const amountsIntoBidSide = toAmountBidSide(activeId, amountY, weights);
2269
- for (const bin of amountsIntoBidSide) {
2270
- amountsInBin.push({
2271
- binId: bin.binId,
2272
- amountX: new import_bn10.default(0),
2273
- amountY: bin.amount
2274
- });
2275
- }
2276
- }
2277
- if (activeId <= maxBinId) {
2278
- const weights = toWeightSpotBalanced(activeId, maxBinId);
2279
- const amountsIntoAskSide = toAmountAskSide(activeId, binStep, amountX, weights);
2280
- for (const bin of amountsIntoAskSide) {
2281
- amountsInBin.push({
2282
- binId: bin.binId,
2283
- amountX: bin.amount,
2284
- amountY: new import_bn10.default(0)
2285
- });
2286
- }
2287
- }
2288
- }
2289
- return amountsInBin;
2290
- }
2291
- case 1 /* Curve */: {
2292
- if (activeId < minBinId) {
2293
- const weights = toWeightDecendingOrder(minBinId, maxBinId);
2294
- return toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights);
2295
- }
2296
- if (activeId > maxBinId) {
2297
- const weights = toWeightAscendingOrder(minBinId, maxBinId);
2298
- return toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights);
2299
- }
2300
- const amountsInBin = [];
2301
- if (!isSingleSideX) {
2302
- if (minBinId <= activeId) {
2303
- const weights = toWeightAscendingOrder(minBinId, activeId);
2304
- const amounts = toAmountBidSide(activeId, amountY, weights);
2305
- for (const bin of amounts) {
2306
- amountsInBin.push({
2307
- binId: bin.binId,
2308
- amountX: new import_bn10.default(0),
2309
- amountY: bin.amount
2310
- });
2311
- }
2312
- }
2313
- if (activeId < maxBinId) {
2314
- const weights = toWeightDecendingOrder(activeId + 1, maxBinId);
2315
- const amounts = toAmountAskSide(activeId, binStep, amountX, weights);
2316
- for (const bin of amounts) {
2317
- amountsInBin.push({
2318
- binId: bin.binId,
2319
- amountX: bin.amount,
2320
- amountY: new import_bn10.default(0)
2321
- });
2322
- }
2323
- }
2324
- } else {
2325
- if (minBinId < activeId) {
2326
- const weights = toWeightAscendingOrder(minBinId, activeId - 1);
2327
- const amountsIntoBidSide = toAmountBidSide(activeId, amountY, weights);
2328
- for (const bin of amountsIntoBidSide) {
2329
- amountsInBin.push({
2330
- binId: bin.binId,
2331
- amountX: new import_bn10.default(0),
2332
- amountY: bin.amount
2333
- });
2334
- }
2335
- }
2336
- if (activeId <= maxBinId) {
2337
- const weights = toWeightDecendingOrder(activeId, maxBinId);
2338
- const amountsIntoAskSide = toAmountAskSide(activeId, binStep, amountX, weights);
2339
- for (const bin of amountsIntoAskSide) {
2340
- amountsInBin.push({
2341
- binId: bin.binId,
2342
- amountX: bin.amount,
2343
- amountY: new import_bn10.default(0)
2344
- });
2345
- }
2346
- }
2347
- }
2348
- return amountsInBin;
2349
- }
2350
- case 2 /* BidAsk */: {
2351
- if (activeId < minBinId) {
2352
- const weights = toWeightAscendingOrder(minBinId, maxBinId);
2353
- return toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights);
2354
- }
2355
- if (activeId > maxBinId) {
2356
- const weights = toWeightDecendingOrder(minBinId, maxBinId);
2357
- return toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights);
2358
- }
2359
- const amountsInBin = [];
2360
- if (!isSingleSideX) {
2361
- if (minBinId <= activeId) {
2362
- const weights = toWeightDecendingOrder(minBinId, activeId);
2363
- const amounts = toAmountBidSide(activeId, amountY, weights);
2364
- for (const bin of amounts) {
2365
- amountsInBin.push({
2366
- binId: bin.binId,
2367
- amountX: new import_bn10.default(0),
2368
- amountY: bin.amount
2369
- });
2370
- }
2371
- }
2372
- if (activeId < maxBinId) {
2373
- const weights = toWeightAscendingOrder(activeId + 1, maxBinId);
2374
- const amounts = toAmountAskSide(activeId, binStep, amountX, weights);
2375
- for (const bin of amounts) {
2376
- amountsInBin.push({
2377
- binId: bin.binId,
2378
- amountX: bin.amount,
2379
- amountY: new import_bn10.default(0)
2380
- });
2381
- }
2382
- }
2383
- } else {
2384
- if (minBinId < activeId) {
2385
- const weights = toWeightDecendingOrder(minBinId, activeId - 1);
2386
- const amountsIntoBidSide = toAmountBidSide(activeId, amountY, weights);
2387
- for (const bin of amountsIntoBidSide) {
2388
- amountsInBin.push({
2389
- binId: bin.binId,
2390
- amountX: new import_bn10.default(0),
2391
- amountY: bin.amount
2392
- });
2393
- }
2394
- }
2395
- if (activeId <= maxBinId) {
2396
- const weights = toWeightAscendingOrder(activeId, maxBinId);
2397
- const amountsIntoAskSide = toAmountAskSide(activeId, binStep, amountX, weights);
2398
- for (const bin of amountsIntoAskSide) {
2399
- amountsInBin.push({
2400
- binId: bin.binId,
2401
- amountX: bin.amount,
2402
- amountY: new import_bn10.default(0)
2403
- });
2404
- }
2405
- }
2406
- }
2407
- return amountsInBin;
2408
- }
2409
- default:
2410
- throw new Error(`Unsupported strategy type: ${strategyType}`);
2411
- }
2412
- }
2413
-
2414
- // src/math/LiquidityHelper.ts
2415
- var import_decimal8 = __toESM(require("decimal.js"));
2416
-
2417
- // src/utils/numbers.ts
2418
- var import_decimal7 = __toESM(require("decimal.js"));
2419
- function d(value) {
2420
- if (import_decimal7.default.isDecimal(value)) {
2421
- return value;
2422
- }
2423
- return new import_decimal7.default(value === void 0 ? 0 : value);
2424
- }
2425
- function decimalsMultiplier(decimals) {
2426
- return d(10).pow(d(decimals).abs());
2427
- }
2428
-
2429
- // src/math/LiquidityHelper.ts
2430
- function withLiquiditySlippage(value, slippage, mode) {
2431
- return d(value)[mode](d(value).mul(slippage)).toDP(0);
2432
- }
2433
- function getLiquidityAndCoinYByCoinX(coinInVal, reserveInSize, reserveOutSize, lpSupply) {
2434
- if (coinInVal.lessThanOrEqualTo(0)) {
2435
- throw new ClmmpoolsError("coinInVal is less than zero", "InvalidCoinAmount" /* InvalidCoinAmount */);
2436
- }
2437
- if (reserveInSize.lessThanOrEqualTo(0) || reserveOutSize.lessThanOrEqualTo(0)) {
2438
- return -1;
2439
- }
2440
- const coinYAmount = coinInVal.mul(reserveOutSize).div(reserveInSize);
2441
- const sqrtSupply = lpSupply;
2442
- const lpX = coinInVal.div(reserveInSize).mul(sqrtSupply);
2443
- const lpY = coinYAmount.div(reserveOutSize).mul(sqrtSupply);
2444
- const lpAmount = import_decimal8.default.min(lpX, lpY);
2445
- return {
2446
- coinYAmount,
2447
- lpAmount
2448
- };
2449
- }
2450
- function getCoinXYForLiquidity(liquidity, reserveInSize, reserveOutSize, lpSuply) {
2451
- if (liquidity.lessThanOrEqualTo(0)) {
2452
- throw new ClmmpoolsError("liquidity can't be equal or less than zero", "InvalidLiquidityAmount" /* InvalidLiquidityAmount */);
2453
- }
2454
- if (reserveInSize.lessThanOrEqualTo(0) || reserveOutSize.lessThanOrEqualTo(0)) {
2455
- throw new ClmmpoolsError("reserveInSize or reserveOutSize can not be equal or less than zero", "InvalidReserveAmount" /* InvalidReserveAmount */);
2456
- }
2457
- const sqrtSupply = lpSuply;
2458
- const coinXAmount = liquidity.div(sqrtSupply).mul(reserveInSize);
2459
- const coinYAmount = liquidity.div(sqrtSupply).mul(reserveOutSize);
2460
- return {
2461
- coinXAmount,
2462
- coinYAmount
2463
- };
2464
- }
2465
-
2466
1801
  // src/math/percentage.ts
2467
- var import_bn11 = __toESM(require("bn.js"));
1802
+ var import_bn9 = __toESM(require("bn.js"));
2468
1803
  var Percentage = class {
2469
1804
  numerator;
2470
1805
  denominator;
@@ -2492,8 +1827,8 @@ var Percentage = class {
2492
1827
  * @returns
2493
1828
  */
2494
1829
  static fromFraction(numerator, denominator) {
2495
- const num = typeof numerator === "number" ? new import_bn11.default(numerator.toString()) : numerator;
2496
- const denom = typeof denominator === "number" ? new import_bn11.default(denominator.toString()) : denominator;
1830
+ const num = typeof numerator === "number" ? new import_bn9.default(numerator.toString()) : numerator;
1831
+ const denom = typeof denominator === "number" ? new import_bn9.default(denominator.toString()) : denominator;
2497
1832
  return new Percentage(num, denom);
2498
1833
  }
2499
1834
  };
@@ -2593,7 +1928,7 @@ function adjustForCoinSlippage(tokenAmount, slippage, adjustUp) {
2593
1928
  }
2594
1929
 
2595
1930
  // src/math/SplitSwap.ts
2596
- var import_bn12 = __toESM(require("bn.js"));
1931
+ var import_bn10 = __toESM(require("bn.js"));
2597
1932
  var SplitUnit = /* @__PURE__ */ ((SplitUnit2) => {
2598
1933
  SplitUnit2[SplitUnit2["FIVE"] = 5] = "FIVE";
2599
1934
  SplitUnit2[SplitUnit2["TEN"] = 10] = "TEN";
@@ -2651,7 +1986,7 @@ function updateSplitSwapResult(maxIndex, currentIndex, splitSwapResult, stepResu
2651
1986
  return splitSwapResult;
2652
1987
  }
2653
1988
  function computeSplitSwap(a2b, byAmountIn, amounts, poolData, swapTicks) {
2654
- let currentLiquidity = new import_bn12.default(poolData.liquidity);
1989
+ let currentLiquidity = new import_bn10.default(poolData.liquidity);
2655
1990
  let { currentSqrtPrice } = poolData;
2656
1991
  let splitSwapResult = {
2657
1992
  amountInArray: [],
@@ -2714,7 +2049,7 @@ function computeSplitSwap(a2b, byAmountIn, amounts, poolData, swapTicks) {
2714
2049
  targetSqrtPrice,
2715
2050
  currentLiquidity,
2716
2051
  remainerAmount,
2717
- new import_bn12.default(poolData.feeRate),
2052
+ new import_bn10.default(poolData.feeRate),
2718
2053
  byAmountIn
2719
2054
  );
2720
2055
  tempStepResult = stepResult;
@@ -2726,7 +2061,7 @@ function computeSplitSwap(a2b, byAmountIn, amounts, poolData, swapTicks) {
2726
2061
  splitSwapResult.amountOutArray[i] = splitSwapResult.amountOutArray[i].add(stepResult.amountOut);
2727
2062
  splitSwapResult.feeAmountArray[i] = splitSwapResult.feeAmountArray[i].add(stepResult.feeAmount);
2728
2063
  if (stepResult.nextSqrtPrice.eq(tick.sqrtPrice)) {
2729
- signedLiquidityChange = a2b ? tick.liquidityNet.mul(new import_bn12.default(-1)) : tick.liquidityNet;
2064
+ signedLiquidityChange = a2b ? tick.liquidityNet.mul(new import_bn10.default(-1)) : tick.liquidityNet;
2730
2065
  currentLiquidity = signedLiquidityChange.gt(ZERO) ? currentLiquidity.add(signedLiquidityChange) : currentLiquidity.sub(signedLiquidityChange.abs());
2731
2066
  currentSqrtPrice = tick.sqrtPrice;
2732
2067
  } else {
@@ -2751,7 +2086,7 @@ function computeSplitSwap(a2b, byAmountIn, amounts, poolData, swapTicks) {
2751
2086
  break;
2752
2087
  }
2753
2088
  if (tempStepResult.nextSqrtPrice.eq(tick.sqrtPrice)) {
2754
- signedLiquidityChange = a2b ? tick.liquidityNet.mul(new import_bn12.default(-1)) : tick.liquidityNet;
2089
+ signedLiquidityChange = a2b ? tick.liquidityNet.mul(new import_bn10.default(-1)) : tick.liquidityNet;
2755
2090
  currentLiquidity = signedLiquidityChange.gt(ZERO) ? currentLiquidity.add(signedLiquidityChange) : currentLiquidity.sub(signedLiquidityChange.abs());
2756
2091
  currentSqrtPrice = tick.sqrtPrice;
2757
2092
  } else {
@@ -2806,6 +2141,18 @@ var SplitSwap = class {
2806
2141
  }
2807
2142
  };
2808
2143
 
2144
+ // src/utils/numbers.ts
2145
+ var import_decimal6 = __toESM(require("decimal.js"));
2146
+ function d(value) {
2147
+ if (import_decimal6.default.isDecimal(value)) {
2148
+ return value;
2149
+ }
2150
+ return new import_decimal6.default(value === void 0 ? 0 : value);
2151
+ }
2152
+ function decimalsMultiplier(decimals) {
2153
+ return d(10).pow(d(decimals).abs());
2154
+ }
2155
+
2809
2156
  // src/utils/objects.ts
2810
2157
  function getSuiObjectData(resp) {
2811
2158
  return resp.data;
@@ -2959,7 +2306,7 @@ function buildPool(objects) {
2959
2306
  const rewarders = [];
2960
2307
  fields.rewarder_manager.fields.rewarders.forEach((item) => {
2961
2308
  const { emissions_per_second } = item.fields;
2962
- const emissionSeconds = MathUtil.fromX64(new import_bn13.default(emissions_per_second));
2309
+ const emissionSeconds = MathUtil.fromX64(new import_bn11.default(emissions_per_second));
2963
2310
  const emissionsEveryDay = Math.floor(emissionSeconds.toNumber() * 60 * 60 * 24);
2964
2311
  rewarders.push({
2965
2312
  emissions_per_second,
@@ -3151,11 +2498,11 @@ function buildTickData(objects) {
3151
2498
  const possition = {
3152
2499
  objectId: getObjectId(objects),
3153
2500
  index: asIntN(BigInt(valueItem.index.fields.bits)),
3154
- sqrtPrice: new import_bn13.default(valueItem.sqrt_price),
3155
- liquidityNet: new import_bn13.default(valueItem.liquidity_net.fields.bits),
3156
- liquidityGross: new import_bn13.default(valueItem.liquidity_gross),
3157
- feeGrowthOutsideA: new import_bn13.default(valueItem.fee_growth_outside_a),
3158
- feeGrowthOutsideB: new import_bn13.default(valueItem.fee_growth_outside_b),
2501
+ sqrtPrice: new import_bn11.default(valueItem.sqrt_price),
2502
+ liquidityNet: new import_bn11.default(valueItem.liquidity_net.fields.bits),
2503
+ liquidityGross: new import_bn11.default(valueItem.liquidity_gross),
2504
+ feeGrowthOutsideA: new import_bn11.default(valueItem.fee_growth_outside_a),
2505
+ feeGrowthOutsideB: new import_bn11.default(valueItem.fee_growth_outside_b),
3159
2506
  rewardersGrowthOutside: valueItem.rewards_growth_outside
3160
2507
  };
3161
2508
  return possition;
@@ -3165,11 +2512,11 @@ function buildTickDataByEvent(fields) {
3165
2512
  throw new ClmmpoolsError(`Invalid tick fields.`, "InvalidTickFields" /* InvalidTickFields */);
3166
2513
  }
3167
2514
  const index = asIntN(BigInt(fields.index.bits));
3168
- const sqrtPrice = new import_bn13.default(fields.sqrt_price);
3169
- const liquidityNet = new import_bn13.default(fields.liquidity_net.bits);
3170
- const liquidityGross = new import_bn13.default(fields.liquidity_gross);
3171
- const feeGrowthOutsideA = new import_bn13.default(fields.fee_growth_outside_a);
3172
- const feeGrowthOutsideB = new import_bn13.default(fields.fee_growth_outside_b);
2515
+ const sqrtPrice = new import_bn11.default(fields.sqrt_price);
2516
+ const liquidityNet = new import_bn11.default(fields.liquidity_net.bits);
2517
+ const liquidityGross = new import_bn11.default(fields.liquidity_gross);
2518
+ const feeGrowthOutsideA = new import_bn11.default(fields.fee_growth_outside_a);
2519
+ const feeGrowthOutsideB = new import_bn11.default(fields.fee_growth_outside_b);
3173
2520
  const rewardersGrowthOutside = fields.rewards_growth_outside || [];
3174
2521
  const tick = {
3175
2522
  objectId: "",
@@ -3188,7 +2535,7 @@ function buildClmmPositionName(pool_index, position_index) {
3188
2535
  }
3189
2536
 
3190
2537
  // src/utils/tick.ts
3191
- var import_bn14 = __toESM(require("bn.js"));
2538
+ var import_bn12 = __toESM(require("bn.js"));
3192
2539
  var TickUtil = class {
3193
2540
  /**
3194
2541
  * Get min tick index.
@@ -3228,22 +2575,22 @@ function getRewardInTickRange(pool, tickLower, tickUpper, tickLowerIndex, tickUp
3228
2575
  let rewarder_growth_below = growthGlobal[i];
3229
2576
  if (tickLower !== null) {
3230
2577
  if (pool.current_tick_index < tickLowerIndex) {
3231
- rewarder_growth_below = growthGlobal[i].sub(new import_bn14.default(tickLower.rewardersGrowthOutside[i]));
2578
+ rewarder_growth_below = growthGlobal[i].sub(new import_bn12.default(tickLower.rewardersGrowthOutside[i]));
3232
2579
  } else {
3233
2580
  rewarder_growth_below = tickLower.rewardersGrowthOutside[i];
3234
2581
  }
3235
2582
  }
3236
- let rewarder_growth_above = new import_bn14.default(0);
2583
+ let rewarder_growth_above = new import_bn12.default(0);
3237
2584
  if (tickUpper !== null) {
3238
2585
  if (pool.current_tick_index >= tickUpperIndex) {
3239
- rewarder_growth_above = growthGlobal[i].sub(new import_bn14.default(tickUpper.rewardersGrowthOutside[i]));
2586
+ rewarder_growth_above = growthGlobal[i].sub(new import_bn12.default(tickUpper.rewardersGrowthOutside[i]));
3240
2587
  } else {
3241
2588
  rewarder_growth_above = tickUpper.rewardersGrowthOutside[i];
3242
2589
  }
3243
2590
  }
3244
2591
  const rewGrowthInside = MathUtil.subUnderflowU128(
3245
- MathUtil.subUnderflowU128(new import_bn14.default(growthGlobal[i]), new import_bn14.default(rewarder_growth_below)),
3246
- new import_bn14.default(rewarder_growth_above)
2592
+ MathUtil.subUnderflowU128(new import_bn12.default(growthGlobal[i]), new import_bn12.default(rewarder_growth_below)),
2593
+ new import_bn12.default(rewarder_growth_above)
3247
2594
  );
3248
2595
  rewarderGrowthInside.push(rewGrowthInside);
3249
2596
  }
@@ -3251,8 +2598,8 @@ function getRewardInTickRange(pool, tickLower, tickUpper, tickLowerIndex, tickUp
3251
2598
  }
3252
2599
 
3253
2600
  // src/utils/transaction-util.ts
3254
- var import_bn15 = __toESM(require("bn.js"));
3255
- var import_decimal9 = __toESM(require("decimal.js"));
2601
+ var import_bn13 = __toESM(require("bn.js"));
2602
+ var import_decimal7 = __toESM(require("decimal.js"));
3256
2603
  var import_transactions = require("@mysten/sui/transactions");
3257
2604
  function findAdjustCoin(coinPair) {
3258
2605
  const isAdjustCoinA = CoinAssist.isSuiCoin(coinPair.coinTypeA);
@@ -3260,7 +2607,7 @@ function findAdjustCoin(coinPair) {
3260
2607
  return { isAdjustCoinA, isAdjustCoinB };
3261
2608
  }
3262
2609
  function reverSlippageAmount(slippageAmount, slippage) {
3263
- return import_decimal9.default.ceil(d(slippageAmount).div(1 + slippage)).toString();
2610
+ return import_decimal7.default.ceil(d(slippageAmount).div(1 + slippage)).toString();
3264
2611
  }
3265
2612
  async function printTransaction(tx, isPrint = true) {
3266
2613
  console.log(`inputs`, tx.blockData.inputs);
@@ -3560,7 +2907,7 @@ var _TransactionUtil = class {
3560
2907
  const liquidityInput = ClmmPoolUtil.estLiquidityAndcoinAmountFromOneAmounts(
3561
2908
  Number(params.tick_lower),
3562
2909
  Number(params.tick_upper),
3563
- new import_bn15.default(coinAmount),
2910
+ new import_bn13.default(coinAmount),
3564
2911
  params.fix_amount_a,
3565
2912
  true,
3566
2913
  slippage,
@@ -3634,12 +2981,12 @@ var _TransactionUtil = class {
3634
2981
  max_amount_a = params.amount_a;
3635
2982
  min_amount_a = params.amount_a;
3636
2983
  max_amount_b = params.amount_b;
3637
- min_amount_b = new import_decimal9.default(params.amount_b).div(new import_decimal9.default(1).plus(new import_decimal9.default(params.slippage))).mul(new import_decimal9.default(1).minus(new import_decimal9.default(params.slippage))).toDecimalPlaces(0).toNumber();
2984
+ min_amount_b = new import_decimal7.default(params.amount_b).div(new import_decimal7.default(1).plus(new import_decimal7.default(params.slippage))).mul(new import_decimal7.default(1).minus(new import_decimal7.default(params.slippage))).toDecimalPlaces(0).toNumber();
3638
2985
  } else {
3639
2986
  max_amount_b = params.amount_b;
3640
2987
  min_amount_b = params.amount_b;
3641
2988
  max_amount_a = params.amount_a;
3642
- min_amount_a = new import_decimal9.default(params.amount_a).div(new import_decimal9.default(1).plus(new import_decimal9.default(params.slippage))).mul(new import_decimal9.default(1).minus(new import_decimal9.default(params.slippage))).toDecimalPlaces(0).toNumber();
2989
+ min_amount_a = new import_decimal7.default(params.amount_a).div(new import_decimal7.default(1).plus(new import_decimal7.default(params.slippage))).mul(new import_decimal7.default(1).minus(new import_decimal7.default(params.slippage))).toDecimalPlaces(0).toNumber();
3643
2990
  }
3644
2991
  const args = params.is_open ? [
3645
2992
  tx.object(clmmConfig.global_config_id),
@@ -4628,7 +3975,7 @@ var _TransactionUtil = class {
4628
3975
  const basePath = splitPath.basePaths[i];
4629
3976
  a2b.push(basePath.direction);
4630
3977
  poolAddress.push(basePath.poolAddress);
4631
- rawAmountLimit.push(new import_bn15.default(basePath.inputAmount.toString()));
3978
+ rawAmountLimit.push(new import_bn13.default(basePath.inputAmount.toString()));
4632
3979
  if (i === 0) {
4633
3980
  coinType.push(basePath.fromCoin, basePath.toCoin);
4634
3981
  } else {
@@ -4636,8 +3983,8 @@ var _TransactionUtil = class {
4636
3983
  }
4637
3984
  }
4638
3985
  const onePath = {
4639
- amountIn: new import_bn15.default(splitPath.inputAmount.toString()),
4640
- amountOut: new import_bn15.default(splitPath.outputAmount.toString()),
3986
+ amountIn: new import_bn13.default(splitPath.inputAmount.toString()),
3987
+ amountOut: new import_bn13.default(splitPath.outputAmount.toString()),
4641
3988
  poolAddress,
4642
3989
  a2b,
4643
3990
  rawAmountLimit,
@@ -4994,9 +4341,9 @@ var TxBlock = class {
4994
4341
  };
4995
4342
 
4996
4343
  // src/utils/deepbook-utils.ts
4997
- var import_bn16 = __toESM(require("bn.js"));
4344
+ var import_bn14 = __toESM(require("bn.js"));
4998
4345
  var import_transactions3 = require("@mysten/sui/transactions");
4999
- var FLOAT_SCALING = new import_bn16.default(1e9);
4346
+ var FLOAT_SCALING = new import_bn14.default(1e9);
5000
4347
  var DeepbookUtils = class {
5001
4348
  static createAccountCap(senderAddress, sdkOptions, tx, isTransfer = false) {
5002
4349
  if (senderAddress.length === 0) {
@@ -5142,9 +4489,9 @@ var DeepbookUtils = class {
5142
4489
  static async preSwap(sdk, pool, a2b, amountIn) {
5143
4490
  let isExceed = false;
5144
4491
  let amountOut = ZERO;
5145
- let remainAmount = new import_bn16.default(amountIn);
4492
+ let remainAmount = new import_bn14.default(amountIn);
5146
4493
  let feeAmount = ZERO;
5147
- const initAmountIn = new import_bn16.default(amountIn);
4494
+ const initAmountIn = new import_bn14.default(amountIn);
5148
4495
  if (a2b) {
5149
4496
  let bids = await this.getPoolBids(sdk, pool.poolID, pool.baseAsset, pool.quoteAsset);
5150
4497
  if (bids === null) {
@@ -5154,16 +4501,16 @@ var DeepbookUtils = class {
5154
4501
  return b.price - a.price;
5155
4502
  });
5156
4503
  for (let i = 0; i < bids.length; i += 1) {
5157
- const curBidAmount = new import_bn16.default(bids[i].quantity);
5158
- const curBidPrice = new import_bn16.default(bids[i].price);
5159
- const fee = curBidAmount.mul(new import_bn16.default(curBidPrice)).mul(new import_bn16.default(pool.takerFeeRate)).div(FLOAT_SCALING).div(FLOAT_SCALING);
4504
+ const curBidAmount = new import_bn14.default(bids[i].quantity);
4505
+ const curBidPrice = new import_bn14.default(bids[i].price);
4506
+ const fee = curBidAmount.mul(new import_bn14.default(curBidPrice)).mul(new import_bn14.default(pool.takerFeeRate)).div(FLOAT_SCALING).div(FLOAT_SCALING);
5160
4507
  if (remainAmount.gt(curBidAmount)) {
5161
4508
  remainAmount = remainAmount.sub(curBidAmount);
5162
4509
  amountOut = amountOut.add(curBidAmount.mul(curBidPrice).div(FLOAT_SCALING).sub(fee));
5163
4510
  feeAmount = feeAmount.add(fee);
5164
4511
  } else {
5165
- const curOut = remainAmount.mul(new import_bn16.default(bids[i].price)).div(FLOAT_SCALING);
5166
- const curFee = curOut.mul(new import_bn16.default(pool.takerFeeRate)).div(FLOAT_SCALING);
4512
+ const curOut = remainAmount.mul(new import_bn14.default(bids[i].price)).div(FLOAT_SCALING);
4513
+ const curFee = curOut.mul(new import_bn14.default(pool.takerFeeRate)).div(FLOAT_SCALING);
5167
4514
  amountOut = amountOut.add(curOut.sub(curFee));
5168
4515
  remainAmount = remainAmount.sub(remainAmount);
5169
4516
  feeAmount = feeAmount.add(curFee);
@@ -5178,15 +4525,15 @@ var DeepbookUtils = class {
5178
4525
  isExceed = true;
5179
4526
  }
5180
4527
  for (let i = 0; i < asks.length; i += 1) {
5181
- const curAskAmount = new import_bn16.default(asks[i].price).mul(new import_bn16.default(asks[i].quantity)).div(new import_bn16.default(1e9));
5182
- const fee = curAskAmount.mul(new import_bn16.default(pool.takerFeeRate)).div(FLOAT_SCALING);
4528
+ const curAskAmount = new import_bn14.default(asks[i].price).mul(new import_bn14.default(asks[i].quantity)).div(new import_bn14.default(1e9));
4529
+ const fee = curAskAmount.mul(new import_bn14.default(pool.takerFeeRate)).div(FLOAT_SCALING);
5183
4530
  const curAskAmountWithFee = curAskAmount.add(fee);
5184
4531
  if (remainAmount.gt(curAskAmount)) {
5185
- amountOut = amountOut.add(new import_bn16.default(asks[i].quantity));
4532
+ amountOut = amountOut.add(new import_bn14.default(asks[i].quantity));
5186
4533
  remainAmount = remainAmount.sub(curAskAmountWithFee);
5187
4534
  feeAmount = feeAmount.add(fee);
5188
4535
  } else {
5189
- const splitNums = new import_bn16.default(asks[i].quantity).div(new import_bn16.default(pool.lotSize));
4536
+ const splitNums = new import_bn14.default(asks[i].quantity).div(new import_bn14.default(pool.lotSize));
5190
4537
  const splitAmount = curAskAmountWithFee.div(splitNums);
5191
4538
  const swapSplitNum = remainAmount.div(splitAmount);
5192
4539
  amountOut = amountOut.add(swapSplitNum.muln(pool.lotSize));
@@ -6047,7 +5394,7 @@ var PoolModule = class {
6047
5394
  };
6048
5395
 
6049
5396
  // src/modules/positionModule.ts
6050
- var import_bn17 = __toESM(require("bn.js"));
5397
+ var import_bn15 = __toESM(require("bn.js"));
6051
5398
  var import_transactions5 = require("@mysten/sui/transactions");
6052
5399
  var import_utils15 = require("@mysten/sui/utils");
6053
5400
  var PositionModule = class {
@@ -6269,8 +5616,8 @@ var PositionModule = class {
6269
5616
  for (let i = 0; i < valueData.length; i += 1) {
6270
5617
  const { parsedJson } = valueData[i];
6271
5618
  const posRrewarderResult = {
6272
- feeOwedA: new import_bn17.default(parsedJson.fee_owned_a),
6273
- feeOwedB: new import_bn17.default(parsedJson.fee_owned_b),
5619
+ feeOwedA: new import_bn15.default(parsedJson.fee_owned_a),
5620
+ feeOwedB: new import_bn15.default(parsedJson.fee_owned_b),
6274
5621
  position_id: parsedJson.position_id
6275
5622
  };
6276
5623
  result.push(posRrewarderResult);
@@ -6646,7 +5993,7 @@ var PositionModule = class {
6646
5993
  };
6647
5994
 
6648
5995
  // src/modules/rewarderModule.ts
6649
- var import_bn18 = __toESM(require("bn.js"));
5996
+ var import_bn16 = __toESM(require("bn.js"));
6650
5997
  var import_transactions6 = require("@mysten/sui/transactions");
6651
5998
  var RewarderModule = class {
6652
5999
  _sdk;
@@ -6672,7 +6019,7 @@ var RewarderModule = class {
6672
6019
  }
6673
6020
  const emissionsEveryDay = [];
6674
6021
  for (const rewarderInfo of rewarderInfos) {
6675
- const emissionSeconds = MathUtil.fromX64(new import_bn18.default(rewarderInfo.emissions_per_second));
6022
+ const emissionSeconds = MathUtil.fromX64(new import_bn16.default(rewarderInfo.emissions_per_second));
6676
6023
  emissionsEveryDay.push({
6677
6024
  emissions: Math.floor(emissionSeconds.toNumber() * 60 * 60 * 24),
6678
6025
  coin_address: rewarderInfo.coinAddress
@@ -6691,20 +6038,20 @@ var RewarderModule = class {
6691
6038
  const currentPool = await this.sdk.Pool.getPool(poolID);
6692
6039
  const lastTime = currentPool.rewarder_last_updated_time;
6693
6040
  currentPool.rewarder_last_updated_time = currentTime.toString();
6694
- if (Number(currentPool.liquidity) === 0 || currentTime.eq(new import_bn18.default(lastTime))) {
6041
+ if (Number(currentPool.liquidity) === 0 || currentTime.eq(new import_bn16.default(lastTime))) {
6695
6042
  return currentPool;
6696
6043
  }
6697
- const timeDelta = currentTime.div(new import_bn18.default(1e3)).sub(new import_bn18.default(lastTime)).add(new import_bn18.default(15));
6044
+ const timeDelta = currentTime.div(new import_bn16.default(1e3)).sub(new import_bn16.default(lastTime)).add(new import_bn16.default(15));
6698
6045
  const rewarderInfos = currentPool.rewarder_infos;
6699
6046
  for (let i = 0; i < rewarderInfos.length; i += 1) {
6700
6047
  const rewarderInfo = rewarderInfos[i];
6701
6048
  const rewarderGrowthDelta = MathUtil.checkMulDivFloor(
6702
6049
  timeDelta,
6703
- new import_bn18.default(rewarderInfo.emissions_per_second),
6704
- new import_bn18.default(currentPool.liquidity),
6050
+ new import_bn16.default(rewarderInfo.emissions_per_second),
6051
+ new import_bn16.default(currentPool.liquidity),
6705
6052
  128
6706
6053
  );
6707
- this.growthGlobal[i] = new import_bn18.default(rewarderInfo.growth_global).add(new import_bn18.default(rewarderGrowthDelta));
6054
+ this.growthGlobal[i] = new import_bn16.default(rewarderInfo.growth_global).add(new import_bn16.default(rewarderGrowthDelta));
6708
6055
  }
6709
6056
  return currentPool;
6710
6057
  }
@@ -6719,7 +6066,7 @@ var RewarderModule = class {
6719
6066
  */
6720
6067
  async posRewardersAmount(poolID, positionHandle, positionID) {
6721
6068
  const currentTime = Date.parse((/* @__PURE__ */ new Date()).toString());
6722
- const pool = await this.updatePoolRewarder(poolID, new import_bn18.default(currentTime));
6069
+ const pool = await this.updatePoolRewarder(poolID, new import_bn16.default(currentTime));
6723
6070
  const position = await this.sdk.Position.getPositionRewarders(positionHandle, positionID);
6724
6071
  if (position === void 0) {
6725
6072
  return [];
@@ -6740,7 +6087,7 @@ var RewarderModule = class {
6740
6087
  */
6741
6088
  async poolRewardersAmount(accountAddress, poolID) {
6742
6089
  const currentTime = Date.parse((/* @__PURE__ */ new Date()).toString());
6743
- const pool = await this.updatePoolRewarder(poolID, new import_bn18.default(currentTime));
6090
+ const pool = await this.updatePoolRewarder(poolID, new import_bn16.default(currentTime));
6744
6091
  const positions = await this.sdk.Position.getPositionList(accountAddress, [poolID]);
6745
6092
  const tickDatas = await this.getPoolLowerAndUpperTicks(pool.ticks_handle, positions);
6746
6093
  const rewarderAmount = [ZERO, ZERO, ZERO];
@@ -6767,38 +6114,38 @@ var RewarderModule = class {
6767
6114
  const growthInside = [];
6768
6115
  const AmountOwed = [];
6769
6116
  if (rewardersInside.length > 0) {
6770
- let growthDelta0 = MathUtil.subUnderflowU128(rewardersInside[0], new import_bn18.default(position.reward_growth_inside_0));
6771
- if (growthDelta0.gt(new import_bn18.default("3402823669209384634633745948738404"))) {
6117
+ let growthDelta0 = MathUtil.subUnderflowU128(rewardersInside[0], new import_bn16.default(position.reward_growth_inside_0));
6118
+ if (growthDelta0.gt(new import_bn16.default("3402823669209384634633745948738404"))) {
6772
6119
  growthDelta0 = ONE;
6773
6120
  }
6774
- const amountOwed_0 = MathUtil.checkMulShiftRight(new import_bn18.default(position.liquidity), growthDelta0, 64, 128);
6121
+ const amountOwed_0 = MathUtil.checkMulShiftRight(new import_bn16.default(position.liquidity), growthDelta0, 64, 128);
6775
6122
  growthInside.push(rewardersInside[0]);
6776
6123
  AmountOwed.push({
6777
- amount_owed: new import_bn18.default(position.reward_amount_owed_0).add(amountOwed_0),
6124
+ amount_owed: new import_bn16.default(position.reward_amount_owed_0).add(amountOwed_0),
6778
6125
  coin_address: pool.rewarder_infos[0].coinAddress
6779
6126
  });
6780
6127
  }
6781
6128
  if (rewardersInside.length > 1) {
6782
- let growthDelta_1 = MathUtil.subUnderflowU128(rewardersInside[1], new import_bn18.default(position.reward_growth_inside_1));
6783
- if (growthDelta_1.gt(new import_bn18.default("3402823669209384634633745948738404"))) {
6129
+ let growthDelta_1 = MathUtil.subUnderflowU128(rewardersInside[1], new import_bn16.default(position.reward_growth_inside_1));
6130
+ if (growthDelta_1.gt(new import_bn16.default("3402823669209384634633745948738404"))) {
6784
6131
  growthDelta_1 = ONE;
6785
6132
  }
6786
- const amountOwed_1 = MathUtil.checkMulShiftRight(new import_bn18.default(position.liquidity), growthDelta_1, 64, 128);
6133
+ const amountOwed_1 = MathUtil.checkMulShiftRight(new import_bn16.default(position.liquidity), growthDelta_1, 64, 128);
6787
6134
  growthInside.push(rewardersInside[1]);
6788
6135
  AmountOwed.push({
6789
- amount_owed: new import_bn18.default(position.reward_amount_owed_1).add(amountOwed_1),
6136
+ amount_owed: new import_bn16.default(position.reward_amount_owed_1).add(amountOwed_1),
6790
6137
  coin_address: pool.rewarder_infos[1].coinAddress
6791
6138
  });
6792
6139
  }
6793
6140
  if (rewardersInside.length > 2) {
6794
- let growthDelta_2 = MathUtil.subUnderflowU128(rewardersInside[2], new import_bn18.default(position.reward_growth_inside_2));
6795
- if (growthDelta_2.gt(new import_bn18.default("3402823669209384634633745948738404"))) {
6141
+ let growthDelta_2 = MathUtil.subUnderflowU128(rewardersInside[2], new import_bn16.default(position.reward_growth_inside_2));
6142
+ if (growthDelta_2.gt(new import_bn16.default("3402823669209384634633745948738404"))) {
6796
6143
  growthDelta_2 = ONE;
6797
6144
  }
6798
- const amountOwed_2 = MathUtil.checkMulShiftRight(new import_bn18.default(position.liquidity), growthDelta_2, 64, 128);
6145
+ const amountOwed_2 = MathUtil.checkMulShiftRight(new import_bn16.default(position.liquidity), growthDelta_2, 64, 128);
6799
6146
  growthInside.push(rewardersInside[2]);
6800
6147
  AmountOwed.push({
6801
- amount_owed: new import_bn18.default(position.reward_amount_owed_2).add(amountOwed_2),
6148
+ amount_owed: new import_bn16.default(position.reward_amount_owed_2).add(amountOwed_2),
6802
6149
  coin_address: pool.rewarder_infos[2].coinAddress
6803
6150
  });
6804
6151
  }
@@ -6912,8 +6259,8 @@ var RewarderModule = class {
6912
6259
  for (let i = 0; i < valueData.length; i += 1) {
6913
6260
  const { parsedJson } = valueData[i];
6914
6261
  const posRrewarderResult = {
6915
- feeOwedA: new import_bn18.default(parsedJson.fee_owned_a),
6916
- feeOwedB: new import_bn18.default(parsedJson.fee_owned_b),
6262
+ feeOwedA: new import_bn16.default(parsedJson.fee_owned_a),
6263
+ feeOwedB: new import_bn16.default(parsedJson.fee_owned_b),
6917
6264
  position_id: parsedJson.position_id
6918
6265
  };
6919
6266
  result.push(posRrewarderResult);
@@ -6976,7 +6323,7 @@ var RewarderModule = class {
6976
6323
  };
6977
6324
  for (let j = 0; j < params[i].rewarderInfo.length; j += 1) {
6978
6325
  posRrewarderResult.rewarderAmountOwed.push({
6979
- amount_owed: new import_bn18.default(valueData[i].parsedJson.data[j]),
6326
+ amount_owed: new import_bn16.default(valueData[i].parsedJson.data[j]),
6980
6327
  coin_address: params[i].rewarderInfo[j].coinAddress
6981
6328
  });
6982
6329
  }
@@ -7165,7 +6512,7 @@ var RewarderModule = class {
7165
6512
  };
7166
6513
 
7167
6514
  // src/modules/routerModule.ts
7168
- var import_bn19 = __toESM(require("bn.js"));
6515
+ var import_bn17 = __toESM(require("bn.js"));
7169
6516
  var import_cc_graph = require("@syntsugar/cc-graph");
7170
6517
  var import_transactions7 = require("@mysten/sui/transactions");
7171
6518
  function _pairSymbol(base, quote) {
@@ -7447,8 +6794,8 @@ var RouterModule = class {
7447
6794
  if (swapWithMultiPoolParams != null) {
7448
6795
  const preSwapResult2 = await this.sdk.Swap.preSwapWithMultiPool(swapWithMultiPoolParams);
7449
6796
  const onePath2 = {
7450
- amountIn: new import_bn19.default(preSwapResult2.estimatedAmountIn),
7451
- amountOut: new import_bn19.default(preSwapResult2.estimatedAmountOut),
6797
+ amountIn: new import_bn17.default(preSwapResult2.estimatedAmountIn),
6798
+ amountOut: new import_bn17.default(preSwapResult2.estimatedAmountOut),
7452
6799
  poolAddress: [preSwapResult2.poolAddress],
7453
6800
  a2b: [preSwapResult2.aToB],
7454
6801
  rawAmountLimit: byAmountIn ? [preSwapResult2.estimatedAmountOut] : [preSwapResult2.estimatedAmountIn],
@@ -7461,8 +6808,8 @@ var RouterModule = class {
7461
6808
  priceSlippagePoint
7462
6809
  };
7463
6810
  const result2 = {
7464
- amountIn: new import_bn19.default(preSwapResult2.estimatedAmountIn),
7465
- amountOut: new import_bn19.default(preSwapResult2.estimatedAmountOut),
6811
+ amountIn: new import_bn17.default(preSwapResult2.estimatedAmountIn),
6812
+ amountOut: new import_bn17.default(preSwapResult2.estimatedAmountOut),
7466
6813
  paths: [onePath2],
7467
6814
  a2b: preSwapResult2.aToB,
7468
6815
  b2c: void 0,
@@ -7484,8 +6831,8 @@ var RouterModule = class {
7484
6831
  if (swapWithMultiPoolParams != null) {
7485
6832
  const preSwapResult2 = await this.sdk.Swap.preSwapWithMultiPool(swapWithMultiPoolParams);
7486
6833
  const onePath2 = {
7487
- amountIn: new import_bn19.default(preSwapResult2.estimatedAmountIn),
7488
- amountOut: new import_bn19.default(preSwapResult2.estimatedAmountOut),
6834
+ amountIn: new import_bn17.default(preSwapResult2.estimatedAmountIn),
6835
+ amountOut: new import_bn17.default(preSwapResult2.estimatedAmountOut),
7489
6836
  poolAddress: [preSwapResult2.poolAddress],
7490
6837
  a2b: [preSwapResult2.aToB],
7491
6838
  rawAmountLimit: byAmountIn ? [preSwapResult2.estimatedAmountOut] : [preSwapResult2.estimatedAmountIn],
@@ -7498,8 +6845,8 @@ var RouterModule = class {
7498
6845
  priceSlippagePoint
7499
6846
  };
7500
6847
  const result3 = {
7501
- amountIn: new import_bn19.default(preSwapResult2.estimatedAmountIn),
7502
- amountOut: new import_bn19.default(preSwapResult2.estimatedAmountOut),
6848
+ amountIn: new import_bn17.default(preSwapResult2.estimatedAmountIn),
6849
+ amountOut: new import_bn17.default(preSwapResult2.estimatedAmountOut),
7503
6850
  paths: [onePath2],
7504
6851
  a2b: preSwapResult2.aToB,
7505
6852
  b2c: void 0,
@@ -7580,8 +6927,8 @@ var RouterModule = class {
7580
6927
  if (swapWithMultiPoolParams != null) {
7581
6928
  const preSwapResult = await this.sdk.Swap.preSwapWithMultiPool(swapWithMultiPoolParams);
7582
6929
  const onePath = {
7583
- amountIn: new import_bn19.default(preSwapResult.estimatedAmountIn),
7584
- amountOut: new import_bn19.default(preSwapResult.estimatedAmountOut),
6930
+ amountIn: new import_bn17.default(preSwapResult.estimatedAmountIn),
6931
+ amountOut: new import_bn17.default(preSwapResult.estimatedAmountOut),
7585
6932
  poolAddress: [preSwapResult.poolAddress],
7586
6933
  a2b: [preSwapResult.aToB],
7587
6934
  rawAmountLimit: byAmountIn ? [preSwapResult.estimatedAmountOut] : [preSwapResult.estimatedAmountIn],
@@ -7594,8 +6941,8 @@ var RouterModule = class {
7594
6941
  priceSlippagePoint
7595
6942
  };
7596
6943
  const result = {
7597
- amountIn: new import_bn19.default(preSwapResult.estimatedAmountIn),
7598
- amountOut: new import_bn19.default(preSwapResult.estimatedAmountOut),
6944
+ amountIn: new import_bn17.default(preSwapResult.estimatedAmountIn),
6945
+ amountOut: new import_bn17.default(preSwapResult.estimatedAmountOut),
7599
6946
  paths: [onePath],
7600
6947
  a2b: preSwapResult.aToB,
7601
6948
  b2c: void 0,
@@ -7679,13 +7026,13 @@ var RouterModule = class {
7679
7026
  continue;
7680
7027
  }
7681
7028
  if (params[0].byAmountIn) {
7682
- const amount = new import_bn19.default(valueData[i].parsedJson.data.amount_out);
7029
+ const amount = new import_bn17.default(valueData[i].parsedJson.data.amount_out);
7683
7030
  if (amount.gt(tempMaxAmount)) {
7684
7031
  tempIndex = i;
7685
7032
  tempMaxAmount = amount;
7686
7033
  }
7687
7034
  } else {
7688
- const amount = params[i].stepNums > 1 ? new import_bn19.default(valueData[i].parsedJson.data.amount_in) : new import_bn19.default(valueData[i].parsedJson.data.amount_in).add(new import_bn19.default(valueData[i].parsedJson.data.fee_amount));
7035
+ const amount = params[i].stepNums > 1 ? new import_bn17.default(valueData[i].parsedJson.data.amount_in) : new import_bn17.default(valueData[i].parsedJson.data.amount_in).add(new import_bn17.default(valueData[i].parsedJson.data.fee_amount));
7689
7036
  if (amount.lt(tempMaxAmount)) {
7690
7037
  tempIndex = i;
7691
7038
  tempMaxAmount = amount;
@@ -7755,8 +7102,8 @@ var RouterModule = class {
7755
7102
  };
7756
7103
 
7757
7104
  // src/modules/swapModule.ts
7758
- var import_bn20 = __toESM(require("bn.js"));
7759
- var import_decimal10 = __toESM(require("decimal.js"));
7105
+ var import_bn18 = __toESM(require("bn.js"));
7106
+ var import_decimal8 = __toESM(require("decimal.js"));
7760
7107
  var import_transactions8 = require("@mysten/sui/transactions");
7761
7108
  var AMM_SWAP_MODULE = "amm_swap";
7762
7109
  var POOL_STRUCT = "Pool";
@@ -7774,14 +7121,14 @@ var SwapModule = class {
7774
7121
  const pathCount = item.basePaths.length;
7775
7122
  if (pathCount > 0) {
7776
7123
  const path = item.basePaths[0];
7777
- const feeRate = path.label === "Magma" ? new import_decimal10.default(path.feeRate).div(10 ** 6) : new import_decimal10.default(path.feeRate).div(10 ** 9);
7124
+ const feeRate = path.label === "Magma" ? new import_decimal8.default(path.feeRate).div(10 ** 6) : new import_decimal8.default(path.feeRate).div(10 ** 9);
7778
7125
  const feeAmount = d(path.inputAmount).div(10 ** path.fromDecimal).mul(feeRate);
7779
7126
  fee = fee.add(feeAmount);
7780
7127
  if (pathCount > 1) {
7781
7128
  const path2 = item.basePaths[1];
7782
- const price1 = path.direction ? path.currentPrice : new import_decimal10.default(1).div(path.currentPrice);
7783
- const price2 = path2.direction ? path2.currentPrice : new import_decimal10.default(1).div(path2.currentPrice);
7784
- const feeRate2 = path2.label === "Magma" ? new import_decimal10.default(path2.feeRate).div(10 ** 6) : new import_decimal10.default(path2.feeRate).div(10 ** 9);
7129
+ const price1 = path.direction ? path.currentPrice : new import_decimal8.default(1).div(path.currentPrice);
7130
+ const price2 = path2.direction ? path2.currentPrice : new import_decimal8.default(1).div(path2.currentPrice);
7131
+ const feeRate2 = path2.label === "Magma" ? new import_decimal8.default(path2.feeRate).div(10 ** 6) : new import_decimal8.default(path2.feeRate).div(10 ** 9);
7785
7132
  const feeAmount2 = d(path2.outputAmount).div(10 ** path2.toDecimal).mul(feeRate2);
7786
7133
  const fee2 = feeAmount2.div(price1.mul(price2));
7787
7134
  fee = fee.add(fee2);
@@ -7799,17 +7146,17 @@ var SwapModule = class {
7799
7146
  const outputAmount = d(path.outputAmount).div(10 ** path.toDecimal);
7800
7147
  const inputAmount = d(path.inputAmount).div(10 ** path.fromDecimal);
7801
7148
  const rate = outputAmount.div(inputAmount);
7802
- const cprice = path.direction ? new import_decimal10.default(path.currentPrice) : new import_decimal10.default(1).div(path.currentPrice);
7149
+ const cprice = path.direction ? new import_decimal8.default(path.currentPrice) : new import_decimal8.default(1).div(path.currentPrice);
7803
7150
  impactValue = impactValue.add(this.calculateSingleImpact(rate, cprice));
7804
7151
  }
7805
7152
  if (pathCount === 2) {
7806
7153
  const path = item.basePaths[0];
7807
7154
  const path2 = item.basePaths[1];
7808
- const cprice1 = path.direction ? new import_decimal10.default(path.currentPrice) : new import_decimal10.default(1).div(path.currentPrice);
7809
- const cprice2 = path2.direction ? new import_decimal10.default(path2.currentPrice) : new import_decimal10.default(1).div(path2.currentPrice);
7155
+ const cprice1 = path.direction ? new import_decimal8.default(path.currentPrice) : new import_decimal8.default(1).div(path.currentPrice);
7156
+ const cprice2 = path2.direction ? new import_decimal8.default(path2.currentPrice) : new import_decimal8.default(1).div(path2.currentPrice);
7810
7157
  const cprice = cprice1.mul(cprice2);
7811
- const outputAmount = new import_decimal10.default(path2.outputAmount).div(10 ** path2.toDecimal);
7812
- const inputAmount = new import_decimal10.default(path.inputAmount).div(10 ** path.fromDecimal);
7158
+ const outputAmount = new import_decimal8.default(path2.outputAmount).div(10 ** path2.toDecimal);
7159
+ const inputAmount = new import_decimal8.default(path.inputAmount).div(10 ** path.fromDecimal);
7813
7160
  const rate = outputAmount.div(inputAmount);
7814
7161
  impactValue = impactValue.add(this.calculateSingleImpact(rate, cprice));
7815
7162
  }
@@ -7871,13 +7218,13 @@ var SwapModule = class {
7871
7218
  continue;
7872
7219
  }
7873
7220
  if (params.byAmountIn) {
7874
- const amount = new import_bn20.default(valueData[i].parsedJson.data.amount_out);
7221
+ const amount = new import_bn18.default(valueData[i].parsedJson.data.amount_out);
7875
7222
  if (amount.gt(tempMaxAmount)) {
7876
7223
  tempIndex = i;
7877
7224
  tempMaxAmount = amount;
7878
7225
  }
7879
7226
  } else {
7880
- const amount = new import_bn20.default(valueData[i].parsedJson.data.amount_out);
7227
+ const amount = new import_bn18.default(valueData[i].parsedJson.data.amount_out);
7881
7228
  if (amount.lt(tempMaxAmount)) {
7882
7229
  tempIndex = i;
7883
7230
  tempMaxAmount = amount;
@@ -7941,7 +7288,7 @@ var SwapModule = class {
7941
7288
  return this.transformSwapData(params, valueData[0].parsedJson.data);
7942
7289
  }
7943
7290
  transformSwapData(params, data) {
7944
- const estimatedAmountIn = data.amount_in && data.fee_amount ? new import_bn20.default(data.amount_in).add(new import_bn20.default(data.fee_amount)).toString() : "";
7291
+ const estimatedAmountIn = data.amount_in && data.fee_amount ? new import_bn18.default(data.amount_in).add(new import_bn18.default(data.fee_amount)).toString() : "";
7945
7292
  return {
7946
7293
  poolAddress: params.pool.poolAddress,
7947
7294
  currentSqrtPrice: params.currentSqrtPrice,
@@ -7958,7 +7305,7 @@ var SwapModule = class {
7958
7305
  transformSwapWithMultiPoolData(params, jsonData) {
7959
7306
  const { data } = jsonData;
7960
7307
  console.log("json data. ", data);
7961
- const estimatedAmountIn = data.amount_in && data.fee_amount ? new import_bn20.default(data.amount_in).add(new import_bn20.default(data.fee_amount)).toString() : "";
7308
+ const estimatedAmountIn = data.amount_in && data.fee_amount ? new import_bn18.default(data.amount_in).add(new import_bn18.default(data.fee_amount)).toString() : "";
7962
7309
  return {
7963
7310
  poolAddress: params.poolAddress,
7964
7311
  estimatedAmountIn,
@@ -9471,8 +8818,8 @@ var TokenModule = class {
9471
8818
  };
9472
8819
 
9473
8820
  // src/modules/routerModuleV2.ts
9474
- var import_bn21 = __toESM(require("bn.js"));
9475
- var import_decimal11 = __toESM(require("decimal.js"));
8821
+ var import_bn19 = __toESM(require("bn.js"));
8822
+ var import_decimal9 = __toESM(require("decimal.js"));
9476
8823
  var import_uuid = require("uuid");
9477
8824
  var import_axios = __toESM(require("axios"));
9478
8825
  var RouterModuleV2 = class {
@@ -9489,7 +8836,7 @@ var RouterModuleV2 = class {
9489
8836
  if (label === "Magma") {
9490
8837
  return TickMath.sqrtPriceX64ToPrice(currentSqrtPrice, decimalA, decimalB);
9491
8838
  }
9492
- return new import_decimal11.default(currentSqrtPrice.toString()).div(new import_decimal11.default(10).pow(new import_decimal11.default(decimalB + 9 - decimalA)));
8839
+ return new import_decimal9.default(currentSqrtPrice.toString()).div(new import_decimal9.default(10).pow(new import_decimal9.default(decimalB + 9 - decimalA)));
9493
8840
  }
9494
8841
  parseJsonResult(data) {
9495
8842
  const result = {
@@ -9515,12 +8862,12 @@ var RouterModuleV2 = class {
9515
8862
  outputAmount: basePath.output_amount,
9516
8863
  inputAmount: basePath.input_amount,
9517
8864
  feeRate: basePath.fee_rate,
9518
- currentSqrtPrice: new import_bn21.default(basePath.current_sqrt_price.toString()),
9519
- afterSqrtPrice: basePath.label === "Magma" ? new import_bn21.default(basePath.after_sqrt_price.toString()) : ZERO,
8865
+ currentSqrtPrice: new import_bn19.default(basePath.current_sqrt_price.toString()),
8866
+ afterSqrtPrice: basePath.label === "Magma" ? new import_bn19.default(basePath.after_sqrt_price.toString()) : ZERO,
9520
8867
  fromDecimal: basePath.from_decimal,
9521
8868
  toDecimal: basePath.to_decimal,
9522
8869
  currentPrice: this.calculatePrice(
9523
- new import_bn21.default(basePath.current_sqrt_price.toString()),
8870
+ new import_bn19.default(basePath.current_sqrt_price.toString()),
9524
8871
  basePath.from_decimal,
9525
8872
  basePath.to_decimal,
9526
8873
  basePath.direction,
@@ -9603,7 +8950,7 @@ var RouterModuleV2 = class {
9603
8950
  const priceResult = await this.sdk.Router.priceUseV1(
9604
8951
  from,
9605
8952
  to,
9606
- new import_bn21.default(amount),
8953
+ new import_bn19.default(amount),
9607
8954
  byAmountIn,
9608
8955
  priceSplitPoint,
9609
8956
  partner,
@@ -9615,7 +8962,7 @@ var RouterModuleV2 = class {
9615
8962
  if (path.poolAddress.length > 1) {
9616
8963
  const fromDecimal0 = this.sdk.Router.tokenInfo(path.coinType[0]).decimals;
9617
8964
  const toDecimal0 = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
9618
- const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new import_bn21.default(priceResult.currentSqrtPrice[0]), fromDecimal0, toDecimal0) : TickMath.sqrtPriceX64ToPrice(new import_bn21.default(priceResult.currentSqrtPrice[0]), toDecimal0, fromDecimal0);
8965
+ const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new import_bn19.default(priceResult.currentSqrtPrice[0]), fromDecimal0, toDecimal0) : TickMath.sqrtPriceX64ToPrice(new import_bn19.default(priceResult.currentSqrtPrice[0]), toDecimal0, fromDecimal0);
9619
8966
  const path0 = {
9620
8967
  direction: path.a2b[0],
9621
8968
  label: "Magma",
@@ -9632,7 +8979,7 @@ var RouterModuleV2 = class {
9632
8979
  };
9633
8980
  const fromDecimal1 = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
9634
8981
  const toDecimal1 = this.sdk.Router.tokenInfo(path.coinType[2]).decimals;
9635
- const currentPrice1 = path.a2b[1] ? TickMath.sqrtPriceX64ToPrice(new import_bn21.default(priceResult.currentSqrtPrice[1]), fromDecimal1, toDecimal1) : TickMath.sqrtPriceX64ToPrice(new import_bn21.default(priceResult.currentSqrtPrice[1]), toDecimal1, fromDecimal1);
8982
+ const currentPrice1 = path.a2b[1] ? TickMath.sqrtPriceX64ToPrice(new import_bn19.default(priceResult.currentSqrtPrice[1]), fromDecimal1, toDecimal1) : TickMath.sqrtPriceX64ToPrice(new import_bn19.default(priceResult.currentSqrtPrice[1]), toDecimal1, fromDecimal1);
9636
8983
  const path1 = {
9637
8984
  direction: path.a2b[1],
9638
8985
  label: "Magma",
@@ -9651,7 +8998,7 @@ var RouterModuleV2 = class {
9651
8998
  } else {
9652
8999
  const fromDecimal = this.sdk.Router.tokenInfo(path.coinType[0]).decimals;
9653
9000
  const toDecimal = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
9654
- const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new import_bn21.default(priceResult.currentSqrtPrice[0]), fromDecimal, toDecimal) : TickMath.sqrtPriceX64ToPrice(new import_bn21.default(priceResult.currentSqrtPrice[0]), toDecimal, fromDecimal);
9001
+ const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new import_bn19.default(priceResult.currentSqrtPrice[0]), fromDecimal, toDecimal) : TickMath.sqrtPriceX64ToPrice(new import_bn19.default(priceResult.currentSqrtPrice[0]), toDecimal, fromDecimal);
9655
9002
  const path0 = {
9656
9003
  direction: path.a2b[0],
9657
9004
  label: "Magma",
@@ -9736,7 +9083,7 @@ var RouterModuleV2 = class {
9736
9083
  const priceResult = await this.sdk.Router.priceUseV1(
9737
9084
  from,
9738
9085
  to,
9739
- new import_bn21.default(amount),
9086
+ new import_bn19.default(amount),
9740
9087
  byAmountIn,
9741
9088
  priceSplitPoint,
9742
9089
  partner,
@@ -9748,7 +9095,7 @@ var RouterModuleV2 = class {
9748
9095
  if (path.poolAddress.length > 1) {
9749
9096
  const fromDecimal0 = this.sdk.Router.tokenInfo(path.coinType[0]).decimals;
9750
9097
  const toDecimal0 = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
9751
- const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new import_bn21.default(priceResult.currentSqrtPrice[0]), fromDecimal0, toDecimal0) : TickMath.sqrtPriceX64ToPrice(new import_bn21.default(priceResult.currentSqrtPrice[0]), toDecimal0, fromDecimal0);
9098
+ const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new import_bn19.default(priceResult.currentSqrtPrice[0]), fromDecimal0, toDecimal0) : TickMath.sqrtPriceX64ToPrice(new import_bn19.default(priceResult.currentSqrtPrice[0]), toDecimal0, fromDecimal0);
9752
9099
  const path0 = {
9753
9100
  direction: path.a2b[0],
9754
9101
  label: "Magma",
@@ -9765,7 +9112,7 @@ var RouterModuleV2 = class {
9765
9112
  };
9766
9113
  const fromDecimal1 = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
9767
9114
  const toDecimal1 = this.sdk.Router.tokenInfo(path.coinType[2]).decimals;
9768
- const currentPrice1 = path.a2b[1] ? TickMath.sqrtPriceX64ToPrice(new import_bn21.default(priceResult.currentSqrtPrice[1]), fromDecimal1, toDecimal1) : TickMath.sqrtPriceX64ToPrice(new import_bn21.default(priceResult.currentSqrtPrice[1]), toDecimal1, fromDecimal1);
9115
+ const currentPrice1 = path.a2b[1] ? TickMath.sqrtPriceX64ToPrice(new import_bn19.default(priceResult.currentSqrtPrice[1]), fromDecimal1, toDecimal1) : TickMath.sqrtPriceX64ToPrice(new import_bn19.default(priceResult.currentSqrtPrice[1]), toDecimal1, fromDecimal1);
9769
9116
  const path1 = {
9770
9117
  direction: path.a2b[1],
9771
9118
  label: "Magma",
@@ -9784,7 +9131,7 @@ var RouterModuleV2 = class {
9784
9131
  } else {
9785
9132
  const fromDecimal = this.sdk.Router.tokenInfo(path.coinType[0]).decimals;
9786
9133
  const toDecimal = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
9787
- const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new import_bn21.default(priceResult.currentSqrtPrice[0]), fromDecimal, toDecimal) : TickMath.sqrtPriceX64ToPrice(new import_bn21.default(priceResult.currentSqrtPrice[0]), toDecimal, fromDecimal);
9134
+ const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new import_bn19.default(priceResult.currentSqrtPrice[0]), fromDecimal, toDecimal) : TickMath.sqrtPriceX64ToPrice(new import_bn19.default(priceResult.currentSqrtPrice[0]), toDecimal, fromDecimal);
9788
9135
  const path0 = {
9789
9136
  direction: path.a2b[0],
9790
9137
  label: "Magma",
@@ -10706,8 +10053,8 @@ var GaugeModule = class {
10706
10053
 
10707
10054
  // src/modules/dlmm.ts
10708
10055
  var import_transactions12 = require("@mysten/sui/transactions");
10709
- var import_decimal12 = __toESM(require("decimal.js"));
10710
- var import_calc_dlmm2 = require("@magmaprotocol/calc_dlmm");
10056
+ var import_decimal10 = __toESM(require("decimal.js"));
10057
+ var import_calc_dlmm = require("@magmaprotocol/calc_dlmm");
10711
10058
  var DlmmModule = class {
10712
10059
  _sdk;
10713
10060
  constructor(sdk) {
@@ -10779,12 +10126,12 @@ var DlmmModule = class {
10779
10126
  }
10780
10127
  // params price: input (b/(10^b_decimal))/(a/(10^a_decimal))
10781
10128
  price_to_storage_id(price, bin_step, tokenADecimal, tokenBDecimal) {
10782
- const priceDec = new import_decimal12.default(price);
10783
- const tenDec = new import_decimal12.default(10);
10784
- const twoDec = new import_decimal12.default(2);
10129
+ const priceDec = new import_decimal10.default(price);
10130
+ const tenDec = new import_decimal10.default(10);
10131
+ const twoDec = new import_decimal10.default(2);
10785
10132
  const price_x128 = priceDec.mul(tenDec.pow(tokenBDecimal)).div(tenDec.pow(tokenADecimal)).mul(twoDec.pow(128));
10786
- const active_id = (0, import_calc_dlmm2.get_real_id_from_price)(price_x128.toFixed(0).toString(), bin_step);
10787
- return (0, import_calc_dlmm2.get_storage_id_from_real_id)(active_id);
10133
+ const active_id = (0, import_calc_dlmm.get_real_id_from_price)(price_x128.toFixed(0).toString(), bin_step);
10134
+ return (0, import_calc_dlmm.get_storage_id_from_real_id)(active_id);
10788
10135
  }
10789
10136
  // NOTE: x, y should be sorted
10790
10137
  async createPairPayload(params) {
@@ -11495,7 +10842,6 @@ var src_default = MagmaClmmSDK;
11495
10842
  SUI_SYSTEM_STATE_OBJECT_ID,
11496
10843
  SplitSwap,
11497
10844
  SplitUnit,
11498
- StrategyType,
11499
10845
  SwapDirection,
11500
10846
  SwapModule,
11501
10847
  SwapUtils,
@@ -11517,10 +10863,6 @@ var src_default = MagmaClmmSDK;
11517
10863
  adjustForSlippage,
11518
10864
  asIntN,
11519
10865
  asUintN,
11520
- autoFillXByStrategy,
11521
- autoFillXByWeight,
11522
- autoFillYByStrategy,
11523
- autoFillYByWeight,
11524
10866
  bufferToHex,
11525
10867
  buildClmmPositionName,
11526
10868
  buildNFT,
@@ -11558,14 +10900,12 @@ var src_default = MagmaClmmSDK;
11558
10900
  getAmountUnfixedDelta,
11559
10901
  getCoinAFromLiquidity,
11560
10902
  getCoinBFromLiquidity,
11561
- getCoinXYForLiquidity,
11562
10903
  getDefaultSuiInputType,
11563
10904
  getDeltaA,
11564
10905
  getDeltaB,
11565
10906
  getDeltaDownFromOutput,
11566
10907
  getDeltaUpFromInput,
11567
10908
  getFutureTime,
11568
- getLiquidityAndCoinYByCoinX,
11569
10909
  getLiquidityFromCoinA,
11570
10910
  getLiquidityFromCoinB,
11571
10911
  getLowerSqrtPriceFromCoinA,
@@ -11589,7 +10929,6 @@ var src_default = MagmaClmmSDK;
11589
10929
  getObjectType,
11590
10930
  getObjectVersion,
11591
10931
  getPackagerConfigs,
11592
- getPriceOfBinByBinId,
11593
10932
  getRewardInTickRange,
11594
10933
  getSuiObjectData,
11595
10934
  getTickDataFromUrlData,
@@ -11613,15 +10952,10 @@ var src_default = MagmaClmmSDK;
11613
10952
  shortAddress,
11614
10953
  shortString,
11615
10954
  tickScore,
11616
- toAmountAskSide,
11617
- toAmountBidSide,
11618
- toAmountBothSide,
11619
- toAmountsBothSideByStrategy,
11620
10955
  toBuffer,
11621
10956
  toCoinAmount,
11622
10957
  toDecimalsAmount,
11623
10958
  transClmmpoolDataWithoutTicks,
11624
- utf8to16,
11625
- withLiquiditySlippage
10959
+ utf8to16
11626
10960
  });
11627
10961
  //# sourceMappingURL=index.js.map