@magmaprotocol/magma-clmm-sdk 0.5.77 → 0.5.79

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
@@ -37,6 +37,7 @@ var src_exports = {};
37
37
  __export(src_exports, {
38
38
  AMM_SWAP_MODULE: () => AMM_SWAP_MODULE,
39
39
  AmountSpecified: () => AmountSpecified,
40
+ BinMath: () => BinMath,
40
41
  CLOCK_ADDRESS: () => CLOCK_ADDRESS,
41
42
  CachedContent: () => CachedContent,
42
43
  ClmmExpectSwapModule: () => ClmmExpectSwapModule,
@@ -64,6 +65,7 @@ __export(src_exports, {
64
65
  DeepbookCustodianV2Moudle: () => DeepbookCustodianV2Moudle,
65
66
  DeepbookEndpointsV2Moudle: () => DeepbookEndpointsV2Moudle,
66
67
  DeepbookUtils: () => DeepbookUtils,
68
+ DlmmScript: () => DlmmScript,
67
69
  FEE_RATE_DENOMINATOR: () => FEE_RATE_DENOMINATOR,
68
70
  GAS_SYMBOL: () => GAS_SYMBOL,
69
71
  GAS_TYPE_ARG: () => GAS_TYPE_ARG,
@@ -91,6 +93,7 @@ __export(src_exports, {
91
93
  SUI_SYSTEM_STATE_OBJECT_ID: () => SUI_SYSTEM_STATE_OBJECT_ID,
92
94
  SplitSwap: () => SplitSwap,
93
95
  SplitUnit: () => SplitUnit,
96
+ StrategyType: () => StrategyType,
94
97
  SwapDirection: () => SwapDirection,
95
98
  SwapModule: () => SwapModule,
96
99
  SwapUtils: () => SwapUtils,
@@ -112,6 +115,10 @@ __export(src_exports, {
112
115
  adjustForSlippage: () => adjustForSlippage,
113
116
  asIntN: () => asIntN,
114
117
  asUintN: () => asUintN,
118
+ autoFillXByStrategy: () => autoFillXByStrategy,
119
+ autoFillXByWeight: () => autoFillXByWeight,
120
+ autoFillYByStrategy: () => autoFillYByStrategy,
121
+ autoFillYByWeight: () => autoFillYByWeight,
115
122
  bufferToHex: () => bufferToHex,
116
123
  buildClmmPositionName: () => buildClmmPositionName,
117
124
  buildNFT: () => buildNFT,
@@ -150,12 +157,14 @@ __export(src_exports, {
150
157
  getAmountUnfixedDelta: () => getAmountUnfixedDelta,
151
158
  getCoinAFromLiquidity: () => getCoinAFromLiquidity,
152
159
  getCoinBFromLiquidity: () => getCoinBFromLiquidity,
160
+ getCoinXYForLiquidity: () => getCoinXYForLiquidity,
153
161
  getDefaultSuiInputType: () => getDefaultSuiInputType,
154
162
  getDeltaA: () => getDeltaA,
155
163
  getDeltaB: () => getDeltaB,
156
164
  getDeltaDownFromOutput: () => getDeltaDownFromOutput,
157
165
  getDeltaUpFromInput: () => getDeltaUpFromInput,
158
166
  getFutureTime: () => getFutureTime,
167
+ getLiquidityAndCoinYByCoinX: () => getLiquidityAndCoinYByCoinX,
159
168
  getLiquidityFromCoinA: () => getLiquidityFromCoinA,
160
169
  getLiquidityFromCoinB: () => getLiquidityFromCoinB,
161
170
  getLowerSqrtPriceFromCoinA: () => getLowerSqrtPriceFromCoinA,
@@ -179,6 +188,7 @@ __export(src_exports, {
179
188
  getObjectType: () => getObjectType,
180
189
  getObjectVersion: () => getObjectVersion,
181
190
  getPackagerConfigs: () => getPackagerConfigs,
191
+ getPriceOfBinByBinId: () => getPriceOfBinByBinId,
182
192
  getRewardInTickRange: () => getRewardInTickRange,
183
193
  getSuiObjectData: () => getSuiObjectData,
184
194
  getTickDataFromUrlData: () => getTickDataFromUrlData,
@@ -202,11 +212,16 @@ __export(src_exports, {
202
212
  shortAddress: () => shortAddress,
203
213
  shortString: () => shortString,
204
214
  tickScore: () => tickScore,
215
+ toAmountAskSide: () => toAmountAskSide,
216
+ toAmountBidSide: () => toAmountBidSide,
217
+ toAmountBothSide: () => toAmountBothSide,
218
+ toAmountsBothSideByStrategy: () => toAmountsBothSideByStrategy,
205
219
  toBuffer: () => toBuffer,
206
220
  toCoinAmount: () => toCoinAmount,
207
221
  toDecimalsAmount: () => toDecimalsAmount,
208
222
  transClmmpoolDataWithoutTicks: () => transClmmpoolDataWithoutTicks,
209
- utf8to16: () => utf8to16
223
+ utf8to16: () => utf8to16,
224
+ withLiquiditySlippage: () => withLiquiditySlippage
210
225
  });
211
226
  module.exports = __toCommonJS(src_exports);
212
227
 
@@ -242,7 +257,7 @@ var CachedContent = class {
242
257
  };
243
258
 
244
259
  // src/utils/common.ts
245
- var import_bn11 = __toESM(require("bn.js"));
260
+ var import_bn12 = __toESM(require("bn.js"));
246
261
  var import_bcs = require("@mysten/bcs");
247
262
  var import_ed25519 = require("@mysten/sui/keypairs/ed25519");
248
263
  var import_secp256k1 = require("@mysten/sui/keypairs/secp256k1");
@@ -508,6 +523,7 @@ var Voter = "voter";
508
523
  var RewardDistributor = "reward_distributor";
509
524
  var Gauge = "gauge";
510
525
  var Minter = "minter";
526
+ var DlmmScript = "dlmm_script";
511
527
  var CoinInfoAddress = "0x1::coin::CoinInfo";
512
528
  var CoinStoreAddress = "0x1::coin::CoinStore";
513
529
  var DeepbookCustodianV2Moudle = "custodian_v2";
@@ -1796,8 +1812,512 @@ function collectFeesQuote(param) {
1796
1812
  return updateFees(param.position, fee_growth_inside_a, fee_growth_inside_b);
1797
1813
  }
1798
1814
 
1799
- // src/math/percentage.ts
1815
+ // src/math/dlmmWeightToAmounts.ts
1800
1816
  var import_bn9 = __toESM(require("bn.js"));
1817
+ var import_decimal6 = __toESM(require("decimal.js"));
1818
+ var import_calc_dlmm = require("@magmaprotocol/calc_dlmm");
1819
+ function getPriceOfBinByBinId(binId, binStep) {
1820
+ const twoDec = new import_decimal6.default(2);
1821
+ const price = new import_decimal6.default((0, import_calc_dlmm.get_price_x128_from_real_id)(binId, binStep));
1822
+ return price.div(twoDec.pow(128));
1823
+ }
1824
+ function autoFillYByWeight(activeId, binStep, amountX, amountXInActiveBin, amountYInActiveBin, distributions) {
1825
+ const activeBins = distributions.filter((element) => {
1826
+ return element.binId === activeId;
1827
+ });
1828
+ if (activeBins.length === 1) {
1829
+ const p0 = getPriceOfBinByBinId(activeId, binStep);
1830
+ let wx0 = new import_decimal6.default(0);
1831
+ let wy0 = new import_decimal6.default(0);
1832
+ const activeBin = activeBins[0];
1833
+ if (amountXInActiveBin.isZero() && amountYInActiveBin.isZero()) {
1834
+ wx0 = new import_decimal6.default(activeBin.weight).div(p0.mul(new import_decimal6.default(2)));
1835
+ wy0 = new import_decimal6.default(activeBin.weight).div(new import_decimal6.default(2));
1836
+ } else {
1837
+ const amountXInActiveBinDec = new import_decimal6.default(amountXInActiveBin.toString());
1838
+ const amountYInActiveBinDec = new import_decimal6.default(amountYInActiveBin.toString());
1839
+ if (!amountXInActiveBin.isZero()) {
1840
+ wx0 = new import_decimal6.default(activeBin.weight).div(p0.add(amountYInActiveBinDec.div(amountXInActiveBinDec)));
1841
+ }
1842
+ if (!amountYInActiveBin.isZero()) {
1843
+ wy0 = new import_decimal6.default(activeBin.weight).div(new import_decimal6.default(1).add(p0.mul(amountXInActiveBinDec).div(amountYInActiveBinDec)));
1844
+ }
1845
+ }
1846
+ let totalWeightX2 = wx0;
1847
+ let totalWeightY2 = wy0;
1848
+ distributions.forEach((element) => {
1849
+ if (element.binId < activeId) {
1850
+ totalWeightY2 = totalWeightY2.add(new import_decimal6.default(element.weight));
1851
+ }
1852
+ if (element.binId > activeId) {
1853
+ const price = getPriceOfBinByBinId(element.binId, binStep);
1854
+ const weighPerPrice = new import_decimal6.default(element.weight).div(price);
1855
+ totalWeightX2 = totalWeightX2.add(weighPerPrice);
1856
+ }
1857
+ });
1858
+ const kx2 = totalWeightX2.isZero() ? new import_decimal6.default(1) : new import_decimal6.default(amountX.toString()).div(totalWeightX2);
1859
+ const amountY2 = kx2.mul(totalWeightY2);
1860
+ return new import_bn9.default(amountY2.floor().toString());
1861
+ }
1862
+ let totalWeightX = new import_decimal6.default(0);
1863
+ let totalWeightY = new import_decimal6.default(0);
1864
+ distributions.forEach((element) => {
1865
+ if (element.binId < activeId) {
1866
+ totalWeightY = totalWeightY.add(new import_decimal6.default(element.weight));
1867
+ } else {
1868
+ const price = getPriceOfBinByBinId(element.binId, binStep);
1869
+ const weighPerPrice = new import_decimal6.default(element.weight).div(price);
1870
+ totalWeightX = totalWeightX.add(weighPerPrice);
1871
+ }
1872
+ });
1873
+ const kx = totalWeightX.isZero() ? new import_decimal6.default(1) : new import_decimal6.default(amountX.toString()).div(totalWeightX);
1874
+ const amountY = kx.mul(totalWeightY);
1875
+ return new import_bn9.default(amountY.floor().toString());
1876
+ }
1877
+ function autoFillXByWeight(activeId, binStep, amountY, amountXInActiveBin, amountYInActiveBin, distributions) {
1878
+ const activeBins = distributions.filter((element) => {
1879
+ return element.binId === activeId;
1880
+ });
1881
+ if (activeBins.length === 1) {
1882
+ const p0 = getPriceOfBinByBinId(activeId, binStep);
1883
+ let wx0 = new import_decimal6.default(0);
1884
+ let wy0 = new import_decimal6.default(0);
1885
+ const activeBin = activeBins[0];
1886
+ if (amountXInActiveBin.isZero() && amountYInActiveBin.isZero()) {
1887
+ wx0 = new import_decimal6.default(activeBin.weight).div(p0.mul(new import_decimal6.default(2)));
1888
+ wy0 = new import_decimal6.default(activeBin.weight).div(new import_decimal6.default(2));
1889
+ } else {
1890
+ const amountXInActiveBinDec = new import_decimal6.default(amountXInActiveBin.toString());
1891
+ const amountYInActiveBinDec = new import_decimal6.default(amountYInActiveBin.toString());
1892
+ if (!amountXInActiveBin.isZero()) {
1893
+ wx0 = new import_decimal6.default(activeBin.weight).div(p0.add(amountYInActiveBinDec.div(amountXInActiveBinDec)));
1894
+ }
1895
+ if (!amountYInActiveBin.isZero()) {
1896
+ wy0 = new import_decimal6.default(activeBin.weight).div(new import_decimal6.default(1).add(p0.mul(amountXInActiveBinDec).div(amountYInActiveBinDec)));
1897
+ }
1898
+ }
1899
+ let totalWeightX2 = wx0;
1900
+ let totalWeightY2 = wy0;
1901
+ distributions.forEach((element) => {
1902
+ if (element.binId < activeId) {
1903
+ totalWeightY2 = totalWeightY2.add(new import_decimal6.default(element.weight));
1904
+ }
1905
+ if (element.binId > activeId) {
1906
+ const price = getPriceOfBinByBinId(element.binId, binStep);
1907
+ const weighPerPrice = new import_decimal6.default(element.weight).div(price);
1908
+ totalWeightX2 = totalWeightX2.add(weighPerPrice);
1909
+ }
1910
+ });
1911
+ const ky2 = totalWeightY2.isZero() ? new import_decimal6.default(1) : new import_decimal6.default(amountY.toString()).div(totalWeightY2);
1912
+ const amountX2 = ky2.mul(totalWeightX2);
1913
+ return new import_bn9.default(amountX2.floor().toString());
1914
+ }
1915
+ let totalWeightX = new import_decimal6.default(0);
1916
+ let totalWeightY = new import_decimal6.default(0);
1917
+ distributions.forEach((element) => {
1918
+ if (element.binId < activeId) {
1919
+ totalWeightY = totalWeightY.add(new import_decimal6.default(element.weight));
1920
+ } else {
1921
+ const price = getPriceOfBinByBinId(element.binId, binStep);
1922
+ const weighPerPrice = new import_decimal6.default(element.weight).div(price);
1923
+ totalWeightX = totalWeightX.add(weighPerPrice);
1924
+ }
1925
+ });
1926
+ const ky = totalWeightY.isZero() ? new import_decimal6.default(1) : new import_decimal6.default(amountY.toString()).div(totalWeightY);
1927
+ const amountX = ky.mul(totalWeightX);
1928
+ return new import_bn9.default(amountX.floor().toString());
1929
+ }
1930
+ function toAmountBidSide(activeId, totalAmount, distributions) {
1931
+ const totalWeight = distributions.reduce((sum, el) => {
1932
+ return el.binId > activeId ? sum : sum.add(el.weight);
1933
+ }, new import_decimal6.default(0));
1934
+ if (totalWeight.cmp(new import_decimal6.default(0)) !== 1) {
1935
+ throw Error("Invalid parameteres");
1936
+ }
1937
+ return distributions.map((bin) => {
1938
+ if (bin.binId > activeId) {
1939
+ return {
1940
+ binId: bin.binId,
1941
+ amount: new import_bn9.default(0)
1942
+ };
1943
+ }
1944
+ return {
1945
+ binId: bin.binId,
1946
+ amount: new import_bn9.default(new import_decimal6.default(totalAmount.toString()).mul(new import_decimal6.default(bin.weight).div(totalWeight)).floor().toString())
1947
+ };
1948
+ });
1949
+ }
1950
+ function toAmountAskSide(activeId, binStep, totalAmount, distributions) {
1951
+ const totalWeight = distributions.reduce((sum, el) => {
1952
+ if (el.binId < activeId) {
1953
+ return sum;
1954
+ }
1955
+ const price = getPriceOfBinByBinId(el.binId, binStep);
1956
+ const weightPerPrice = new import_decimal6.default(el.weight).div(price);
1957
+ return sum.add(weightPerPrice);
1958
+ }, new import_decimal6.default(0));
1959
+ if (totalWeight.cmp(new import_decimal6.default(0)) !== 1) {
1960
+ throw Error("Invalid parameteres");
1961
+ }
1962
+ return distributions.map((bin) => {
1963
+ if (bin.binId < activeId) {
1964
+ return {
1965
+ binId: bin.binId,
1966
+ amount: new import_bn9.default(0)
1967
+ };
1968
+ }
1969
+ const price = getPriceOfBinByBinId(bin.binId, binStep);
1970
+ const weightPerPrice = new import_decimal6.default(bin.weight).div(price);
1971
+ return {
1972
+ binId: bin.binId,
1973
+ amount: new import_bn9.default(new import_decimal6.default(totalAmount.toString()).mul(weightPerPrice).div(totalWeight).floor().toString())
1974
+ };
1975
+ });
1976
+ }
1977
+ function toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, distributions) {
1978
+ if (activeId > distributions[distributions.length - 1].binId || amountX.isZero()) {
1979
+ const amounts = toAmountBidSide(activeId, amountY, distributions);
1980
+ return amounts.map((bin) => {
1981
+ return {
1982
+ binId: bin.binId,
1983
+ amountX: new import_bn9.default(0),
1984
+ amountY: bin.amount
1985
+ };
1986
+ });
1987
+ }
1988
+ if (activeId < distributions[0].binId || amountY.isZero()) {
1989
+ const amounts = toAmountAskSide(activeId, binStep, amountX, distributions);
1990
+ return amounts.map((bin) => {
1991
+ return {
1992
+ binId: bin.binId,
1993
+ amountX: bin.amount,
1994
+ amountY: new import_bn9.default(0)
1995
+ };
1996
+ });
1997
+ }
1998
+ const activeBins = distributions.filter((element) => {
1999
+ return element.binId === activeId;
2000
+ });
2001
+ if (activeBins.length === 1) {
2002
+ const p0 = getPriceOfBinByBinId(activeId, binStep);
2003
+ let wx0 = new import_decimal6.default(0);
2004
+ let wy0 = new import_decimal6.default(0);
2005
+ const activeBin = activeBins[0];
2006
+ if (amountXInActiveBin.isZero() && amountYInActiveBin.isZero()) {
2007
+ wx0 = new import_decimal6.default(activeBin.weight).div(p0.mul(new import_decimal6.default(2)));
2008
+ wy0 = new import_decimal6.default(activeBin.weight).div(new import_decimal6.default(2));
2009
+ } else {
2010
+ const amountXInActiveBinDec = new import_decimal6.default(amountXInActiveBin.toString());
2011
+ const amountYInActiveBinDec = new import_decimal6.default(amountYInActiveBin.toString());
2012
+ if (!amountXInActiveBin.isZero()) {
2013
+ wx0 = new import_decimal6.default(activeBin.weight).div(p0.add(amountYInActiveBinDec.div(amountXInActiveBinDec)));
2014
+ }
2015
+ if (!amountYInActiveBin.isZero()) {
2016
+ wy0 = new import_decimal6.default(activeBin.weight).div(new import_decimal6.default(1).add(p0.mul(amountXInActiveBinDec).div(amountYInActiveBinDec)));
2017
+ }
2018
+ }
2019
+ let totalWeightX2 = wx0;
2020
+ let totalWeightY2 = wy0;
2021
+ distributions.forEach((element) => {
2022
+ if (element.binId < activeId) {
2023
+ totalWeightY2 = totalWeightY2.add(new import_decimal6.default(element.weight));
2024
+ }
2025
+ if (element.binId > activeId) {
2026
+ const price = getPriceOfBinByBinId(element.binId, binStep);
2027
+ const weighPerPrice = new import_decimal6.default(element.weight).div(price);
2028
+ totalWeightX2 = totalWeightX2.add(weighPerPrice);
2029
+ }
2030
+ });
2031
+ const kx2 = new import_decimal6.default(amountX.toString()).div(totalWeightX2);
2032
+ const ky2 = new import_decimal6.default(amountY.toString()).div(totalWeightY2);
2033
+ const k2 = kx2.lessThan(ky2) ? kx2 : ky2;
2034
+ return distributions.map((bin) => {
2035
+ if (bin.binId < activeId) {
2036
+ const amount = k2.mul(new import_decimal6.default(bin.weight));
2037
+ return {
2038
+ binId: bin.binId,
2039
+ amountX: new import_bn9.default(0),
2040
+ amountY: new import_bn9.default(amount.floor().toString())
2041
+ };
2042
+ }
2043
+ if (bin.binId > activeId) {
2044
+ const price = getPriceOfBinByBinId(bin.binId, binStep);
2045
+ const weighPerPrice = new import_decimal6.default(bin.weight).div(price);
2046
+ const amount = k2.mul(weighPerPrice);
2047
+ return {
2048
+ binId: bin.binId,
2049
+ amountX: new import_bn9.default(amount.floor().toString()),
2050
+ amountY: new import_bn9.default(0)
2051
+ };
2052
+ }
2053
+ const amountXActiveBin = k2.mul(wx0);
2054
+ const amountYActiveBin = k2.mul(wy0);
2055
+ return {
2056
+ binId: bin.binId,
2057
+ amountX: new import_bn9.default(amountXActiveBin.floor().toString()),
2058
+ amountY: new import_bn9.default(amountYActiveBin.floor().toString())
2059
+ };
2060
+ });
2061
+ }
2062
+ let totalWeightX = new import_decimal6.default(0);
2063
+ let totalWeightY = new import_decimal6.default(0);
2064
+ distributions.forEach((element) => {
2065
+ if (element.binId < activeId) {
2066
+ totalWeightY = totalWeightY.add(new import_decimal6.default(element.weight));
2067
+ } else {
2068
+ const price = getPriceOfBinByBinId(element.binId, binStep);
2069
+ const weighPerPrice = new import_decimal6.default(element.weight).div(price);
2070
+ totalWeightX = totalWeightX.add(weighPerPrice);
2071
+ }
2072
+ });
2073
+ const kx = new import_decimal6.default(amountX.toString()).div(totalWeightX);
2074
+ const ky = new import_decimal6.default(amountY.toString()).div(totalWeightY);
2075
+ const k = kx.lessThan(ky) ? kx : ky;
2076
+ return distributions.map((bin) => {
2077
+ if (bin.binId < activeId) {
2078
+ const amount2 = k.mul(new import_decimal6.default(bin.weight));
2079
+ return {
2080
+ binId: bin.binId,
2081
+ amountX: new import_bn9.default(0),
2082
+ amountY: new import_bn9.default(amount2.floor().toString())
2083
+ };
2084
+ }
2085
+ const price = getPriceOfBinByBinId(bin.binId, binStep);
2086
+ const weighPerPrice = new import_decimal6.default(bin.weight).div(price);
2087
+ const amount = k.mul(weighPerPrice);
2088
+ return {
2089
+ binId: bin.binId,
2090
+ amountX: new import_bn9.default(amount.floor().toString()),
2091
+ amountY: new import_bn9.default(0)
2092
+ };
2093
+ });
2094
+ }
2095
+
2096
+ // src/math/dlmmStrategy.ts
2097
+ var StrategyType = /* @__PURE__ */ ((StrategyType2) => {
2098
+ StrategyType2[StrategyType2["Spot"] = 1] = "Spot";
2099
+ StrategyType2[StrategyType2["Curve"] = 2] = "Curve";
2100
+ StrategyType2[StrategyType2["BidAsk"] = 3] = "BidAsk";
2101
+ return StrategyType2;
2102
+ })(StrategyType || {});
2103
+ function toWeightDecendingOrder(minBinId, maxBinId) {
2104
+ const distributions = [];
2105
+ for (let i = minBinId; i <= maxBinId; i++) {
2106
+ distributions.push({
2107
+ binId: i,
2108
+ weight: maxBinId - i + 1
2109
+ });
2110
+ }
2111
+ return distributions;
2112
+ }
2113
+ function toWeightAscendingOrder(minBinId, maxBinId) {
2114
+ const distributions = [];
2115
+ for (let i = minBinId; i <= maxBinId; i++) {
2116
+ distributions.push({
2117
+ binId: i,
2118
+ weight: i - minBinId + 1
2119
+ });
2120
+ }
2121
+ return distributions;
2122
+ }
2123
+ function toWeightSpotBalanced(minBinId, maxBinId) {
2124
+ const distributions = [];
2125
+ for (let i = minBinId; i <= maxBinId; i++) {
2126
+ distributions.push({
2127
+ binId: i,
2128
+ weight: 1
2129
+ });
2130
+ }
2131
+ return distributions;
2132
+ }
2133
+ var DEFAULT_MAX_WEIGHT = 2e3;
2134
+ var DEFAULT_MIN_WEIGHT = 200;
2135
+ function toWeightCurve(minBinId, maxBinId, activeId) {
2136
+ if (activeId < minBinId || activeId > maxBinId) {
2137
+ throw new ClmmpoolsError("Invalid strategy params", "InvalidParams" /* InvalidParams */);
2138
+ }
2139
+ const maxWeight = DEFAULT_MAX_WEIGHT;
2140
+ const minWeight = DEFAULT_MIN_WEIGHT;
2141
+ const diffWeight = maxWeight - minWeight;
2142
+ const diffMinWeight = activeId > minBinId ? Math.floor(diffWeight / (activeId - minBinId)) : 0;
2143
+ const diffMaxWeight = maxBinId > activeId ? Math.floor(diffWeight / (maxBinId - activeId)) : 0;
2144
+ const distributions = [];
2145
+ for (let i = minBinId; i <= maxBinId; i++) {
2146
+ if (i < activeId) {
2147
+ distributions.push({
2148
+ binId: i,
2149
+ weight: maxWeight - (activeId - i) * diffMinWeight
2150
+ });
2151
+ } else if (i > activeId) {
2152
+ distributions.push({
2153
+ binId: i,
2154
+ weight: maxWeight - (i - activeId) * diffMaxWeight
2155
+ });
2156
+ } else {
2157
+ distributions.push({
2158
+ binId: i,
2159
+ weight: maxWeight
2160
+ });
2161
+ }
2162
+ }
2163
+ return distributions;
2164
+ }
2165
+ function toWeightBidAsk(minBinId, maxBinId, activeId) {
2166
+ if (activeId < minBinId || activeId > maxBinId) {
2167
+ throw new ClmmpoolsError("Invalid strategy params", "InvalidParams" /* InvalidParams */);
2168
+ }
2169
+ const maxWeight = DEFAULT_MAX_WEIGHT;
2170
+ const minWeight = DEFAULT_MIN_WEIGHT;
2171
+ const diffWeight = maxWeight - minWeight;
2172
+ const diffMinWeight = activeId > minBinId ? Math.floor(diffWeight / (activeId - minBinId)) : 0;
2173
+ const diffMaxWeight = maxBinId > activeId ? Math.floor(diffWeight / (maxBinId - activeId)) : 0;
2174
+ const distributions = [];
2175
+ for (let i = minBinId; i <= maxBinId; i++) {
2176
+ if (i < activeId) {
2177
+ distributions.push({
2178
+ binId: i,
2179
+ weight: minWeight + (activeId - i) * diffMinWeight
2180
+ });
2181
+ } else if (i > activeId) {
2182
+ distributions.push({
2183
+ binId: i,
2184
+ weight: minWeight + (i - activeId) * diffMaxWeight
2185
+ });
2186
+ } else {
2187
+ distributions.push({
2188
+ binId: i,
2189
+ weight: minWeight
2190
+ });
2191
+ }
2192
+ }
2193
+ return distributions;
2194
+ }
2195
+ function autoFillYByStrategy(activeId, binStep, amountX, amountXInActiveBin, amountYInActiveBin, minBinId, maxBinId, strategyType) {
2196
+ switch (strategyType) {
2197
+ case 1 /* Spot */: {
2198
+ const weights = toWeightSpotBalanced(minBinId, maxBinId);
2199
+ return autoFillYByWeight(activeId, binStep, amountX, amountXInActiveBin, amountYInActiveBin, weights);
2200
+ }
2201
+ case 2 /* Curve */: {
2202
+ const weights = toWeightCurve(minBinId, maxBinId, activeId);
2203
+ return autoFillYByWeight(activeId, binStep, amountX, amountXInActiveBin, amountYInActiveBin, weights);
2204
+ }
2205
+ case 3 /* BidAsk */: {
2206
+ const weights = toWeightBidAsk(minBinId, maxBinId, activeId);
2207
+ return autoFillYByWeight(activeId, binStep, amountX, amountXInActiveBin, amountYInActiveBin, weights);
2208
+ }
2209
+ default:
2210
+ throw new Error(`Unsupported strategy type: ${strategyType}`);
2211
+ }
2212
+ }
2213
+ function autoFillXByStrategy(activeId, binStep, amountY, amountXInActiveBin, amountYInActiveBin, minBinId, maxBinId, strategyType) {
2214
+ switch (strategyType) {
2215
+ case 1 /* Spot */: {
2216
+ const weights = toWeightSpotBalanced(minBinId, maxBinId);
2217
+ return autoFillXByWeight(activeId, binStep, amountY, amountXInActiveBin, amountYInActiveBin, weights);
2218
+ }
2219
+ case 2 /* Curve */: {
2220
+ const weights = toWeightCurve(minBinId, maxBinId, activeId);
2221
+ return autoFillXByWeight(activeId, binStep, amountY, amountXInActiveBin, amountYInActiveBin, weights);
2222
+ }
2223
+ case 3 /* BidAsk */: {
2224
+ const weights = toWeightBidAsk(minBinId, maxBinId, activeId);
2225
+ return autoFillXByWeight(activeId, binStep, amountY, amountXInActiveBin, amountYInActiveBin, weights);
2226
+ }
2227
+ default:
2228
+ throw new Error(`Unsupported strategy type: ${strategyType}`);
2229
+ }
2230
+ }
2231
+ function toAmountsBothSideByStrategy(activeId, binStep, minBinId, maxBinId, amountX, amountY, amountXInActiveBin, amountYInActiveBin, strategyType) {
2232
+ const isSingleSideX = amountY.isZero();
2233
+ switch (strategyType) {
2234
+ case 1 /* Spot */: {
2235
+ const weights = toWeightSpotBalanced(minBinId, maxBinId);
2236
+ return toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights);
2237
+ }
2238
+ case 2 /* Curve */: {
2239
+ if (activeId < minBinId) {
2240
+ const weights2 = toWeightDecendingOrder(minBinId, maxBinId);
2241
+ return toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights2);
2242
+ }
2243
+ if (activeId > maxBinId) {
2244
+ const weights2 = toWeightAscendingOrder(minBinId, maxBinId);
2245
+ return toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights2);
2246
+ }
2247
+ const weights = toWeightCurve(minBinId, maxBinId, activeId);
2248
+ return toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights);
2249
+ }
2250
+ case 3 /* BidAsk */: {
2251
+ if (activeId < minBinId) {
2252
+ const weights2 = toWeightAscendingOrder(minBinId, maxBinId);
2253
+ return toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights2);
2254
+ }
2255
+ if (activeId > maxBinId) {
2256
+ const weights2 = toWeightDecendingOrder(minBinId, maxBinId);
2257
+ return toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights2);
2258
+ }
2259
+ const weights = toWeightBidAsk(minBinId, maxBinId, activeId);
2260
+ return toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights);
2261
+ }
2262
+ default:
2263
+ throw new Error(`Unsupported strategy type: ${strategyType}`);
2264
+ }
2265
+ }
2266
+
2267
+ // src/math/LiquidityHelper.ts
2268
+ var import_decimal8 = __toESM(require("decimal.js"));
2269
+
2270
+ // src/utils/numbers.ts
2271
+ var import_decimal7 = __toESM(require("decimal.js"));
2272
+ function d(value) {
2273
+ if (import_decimal7.default.isDecimal(value)) {
2274
+ return value;
2275
+ }
2276
+ return new import_decimal7.default(value === void 0 ? 0 : value);
2277
+ }
2278
+ function decimalsMultiplier(decimals) {
2279
+ return d(10).pow(d(decimals).abs());
2280
+ }
2281
+
2282
+ // src/math/LiquidityHelper.ts
2283
+ function withLiquiditySlippage(value, slippage, mode) {
2284
+ return d(value)[mode](d(value).mul(slippage)).toDP(0);
2285
+ }
2286
+ function getLiquidityAndCoinYByCoinX(coinInVal, reserveInSize, reserveOutSize, lpSupply) {
2287
+ if (coinInVal.lessThanOrEqualTo(0)) {
2288
+ throw new ClmmpoolsError("coinInVal is less than zero", "InvalidCoinAmount" /* InvalidCoinAmount */);
2289
+ }
2290
+ if (reserveInSize.lessThanOrEqualTo(0) || reserveOutSize.lessThanOrEqualTo(0)) {
2291
+ return -1;
2292
+ }
2293
+ const coinYAmount = coinInVal.mul(reserveOutSize).div(reserveInSize);
2294
+ const sqrtSupply = lpSupply;
2295
+ const lpX = coinInVal.div(reserveInSize).mul(sqrtSupply);
2296
+ const lpY = coinYAmount.div(reserveOutSize).mul(sqrtSupply);
2297
+ const lpAmount = import_decimal8.default.min(lpX, lpY);
2298
+ return {
2299
+ coinYAmount,
2300
+ lpAmount
2301
+ };
2302
+ }
2303
+ function getCoinXYForLiquidity(liquidity, reserveInSize, reserveOutSize, lpSuply) {
2304
+ if (liquidity.lessThanOrEqualTo(0)) {
2305
+ throw new ClmmpoolsError("liquidity can't be equal or less than zero", "InvalidLiquidityAmount" /* InvalidLiquidityAmount */);
2306
+ }
2307
+ if (reserveInSize.lessThanOrEqualTo(0) || reserveOutSize.lessThanOrEqualTo(0)) {
2308
+ throw new ClmmpoolsError("reserveInSize or reserveOutSize can not be equal or less than zero", "InvalidReserveAmount" /* InvalidReserveAmount */);
2309
+ }
2310
+ const sqrtSupply = lpSuply;
2311
+ const coinXAmount = liquidity.div(sqrtSupply).mul(reserveInSize);
2312
+ const coinYAmount = liquidity.div(sqrtSupply).mul(reserveOutSize);
2313
+ return {
2314
+ coinXAmount,
2315
+ coinYAmount
2316
+ };
2317
+ }
2318
+
2319
+ // src/math/percentage.ts
2320
+ var import_bn10 = __toESM(require("bn.js"));
1801
2321
  var Percentage = class {
1802
2322
  numerator;
1803
2323
  denominator;
@@ -1825,8 +2345,8 @@ var Percentage = class {
1825
2345
  * @returns
1826
2346
  */
1827
2347
  static fromFraction(numerator, denominator) {
1828
- const num = typeof numerator === "number" ? new import_bn9.default(numerator.toString()) : numerator;
1829
- const denom = typeof denominator === "number" ? new import_bn9.default(denominator.toString()) : denominator;
2348
+ const num = typeof numerator === "number" ? new import_bn10.default(numerator.toString()) : numerator;
2349
+ const denom = typeof denominator === "number" ? new import_bn10.default(denominator.toString()) : denominator;
1830
2350
  return new Percentage(num, denom);
1831
2351
  }
1832
2352
  };
@@ -1926,7 +2446,7 @@ function adjustForCoinSlippage(tokenAmount, slippage, adjustUp) {
1926
2446
  }
1927
2447
 
1928
2448
  // src/math/SplitSwap.ts
1929
- var import_bn10 = __toESM(require("bn.js"));
2449
+ var import_bn11 = __toESM(require("bn.js"));
1930
2450
  var SplitUnit = /* @__PURE__ */ ((SplitUnit2) => {
1931
2451
  SplitUnit2[SplitUnit2["FIVE"] = 5] = "FIVE";
1932
2452
  SplitUnit2[SplitUnit2["TEN"] = 10] = "TEN";
@@ -1984,7 +2504,7 @@ function updateSplitSwapResult(maxIndex, currentIndex, splitSwapResult, stepResu
1984
2504
  return splitSwapResult;
1985
2505
  }
1986
2506
  function computeSplitSwap(a2b, byAmountIn, amounts, poolData, swapTicks) {
1987
- let currentLiquidity = new import_bn10.default(poolData.liquidity);
2507
+ let currentLiquidity = new import_bn11.default(poolData.liquidity);
1988
2508
  let { currentSqrtPrice } = poolData;
1989
2509
  let splitSwapResult = {
1990
2510
  amountInArray: [],
@@ -2047,7 +2567,7 @@ function computeSplitSwap(a2b, byAmountIn, amounts, poolData, swapTicks) {
2047
2567
  targetSqrtPrice,
2048
2568
  currentLiquidity,
2049
2569
  remainerAmount,
2050
- new import_bn10.default(poolData.feeRate),
2570
+ new import_bn11.default(poolData.feeRate),
2051
2571
  byAmountIn
2052
2572
  );
2053
2573
  tempStepResult = stepResult;
@@ -2059,7 +2579,7 @@ function computeSplitSwap(a2b, byAmountIn, amounts, poolData, swapTicks) {
2059
2579
  splitSwapResult.amountOutArray[i] = splitSwapResult.amountOutArray[i].add(stepResult.amountOut);
2060
2580
  splitSwapResult.feeAmountArray[i] = splitSwapResult.feeAmountArray[i].add(stepResult.feeAmount);
2061
2581
  if (stepResult.nextSqrtPrice.eq(tick.sqrtPrice)) {
2062
- signedLiquidityChange = a2b ? tick.liquidityNet.mul(new import_bn10.default(-1)) : tick.liquidityNet;
2582
+ signedLiquidityChange = a2b ? tick.liquidityNet.mul(new import_bn11.default(-1)) : tick.liquidityNet;
2063
2583
  currentLiquidity = signedLiquidityChange.gt(ZERO) ? currentLiquidity.add(signedLiquidityChange) : currentLiquidity.sub(signedLiquidityChange.abs());
2064
2584
  currentSqrtPrice = tick.sqrtPrice;
2065
2585
  } else {
@@ -2084,7 +2604,7 @@ function computeSplitSwap(a2b, byAmountIn, amounts, poolData, swapTicks) {
2084
2604
  break;
2085
2605
  }
2086
2606
  if (tempStepResult.nextSqrtPrice.eq(tick.sqrtPrice)) {
2087
- signedLiquidityChange = a2b ? tick.liquidityNet.mul(new import_bn10.default(-1)) : tick.liquidityNet;
2607
+ signedLiquidityChange = a2b ? tick.liquidityNet.mul(new import_bn11.default(-1)) : tick.liquidityNet;
2088
2608
  currentLiquidity = signedLiquidityChange.gt(ZERO) ? currentLiquidity.add(signedLiquidityChange) : currentLiquidity.sub(signedLiquidityChange.abs());
2089
2609
  currentSqrtPrice = tick.sqrtPrice;
2090
2610
  } else {
@@ -2139,17 +2659,22 @@ var SplitSwap = class {
2139
2659
  }
2140
2660
  };
2141
2661
 
2142
- // src/utils/numbers.ts
2143
- var import_decimal6 = __toESM(require("decimal.js"));
2144
- function d(value) {
2145
- if (import_decimal6.default.isDecimal(value)) {
2146
- return value;
2662
+ // src/math/bin.ts
2663
+ var import_decimal9 = __toESM(require("decimal.js"));
2664
+ var import_calc_dlmm2 = require("@magmaprotocol/calc_dlmm");
2665
+ var BinMath = class {
2666
+ static getPriceOfBinByBinId(binId, binStep, decimalsA, decimalsB) {
2667
+ const twoDec = new import_decimal9.default(2);
2668
+ const price = new import_decimal9.default((0, import_calc_dlmm2.get_price_x128_from_real_id)(binId, binStep));
2669
+ return price.div(twoDec.pow(128)).mul(import_decimal9.default.pow(10, decimalsA - decimalsB));
2670
+ }
2671
+ static getBinIdFromPrice(price, binStep, decimalsA, decimalsB) {
2672
+ const twoDec = new import_decimal9.default(2);
2673
+ const tenDec = new import_decimal9.default(10);
2674
+ const realid = (0, import_calc_dlmm2.get_real_id_from_price_x128)(new import_decimal9.default(price).mul(tenDec.pow(decimalsB - decimalsA)).mul(twoDec.pow(128)).toDecimalPlaces(0).toString(), binStep);
2675
+ return realid;
2147
2676
  }
2148
- return new import_decimal6.default(value === void 0 ? 0 : value);
2149
- }
2150
- function decimalsMultiplier(decimals) {
2151
- return d(10).pow(d(decimals).abs());
2152
- }
2677
+ };
2153
2678
 
2154
2679
  // src/utils/objects.ts
2155
2680
  function getSuiObjectData(resp) {
@@ -2304,7 +2829,7 @@ function buildPool(objects) {
2304
2829
  const rewarders = [];
2305
2830
  fields.rewarder_manager.fields.rewarders.forEach((item) => {
2306
2831
  const { emissions_per_second } = item.fields;
2307
- const emissionSeconds = MathUtil.fromX64(new import_bn11.default(emissions_per_second));
2832
+ const emissionSeconds = MathUtil.fromX64(new import_bn12.default(emissions_per_second));
2308
2833
  const emissionsEveryDay = Math.floor(emissionSeconds.toNumber() * 60 * 60 * 24);
2309
2834
  rewarders.push({
2310
2835
  emissions_per_second,
@@ -2496,11 +3021,11 @@ function buildTickData(objects) {
2496
3021
  const possition = {
2497
3022
  objectId: getObjectId(objects),
2498
3023
  index: asIntN(BigInt(valueItem.index.fields.bits)),
2499
- sqrtPrice: new import_bn11.default(valueItem.sqrt_price),
2500
- liquidityNet: new import_bn11.default(valueItem.liquidity_net.fields.bits),
2501
- liquidityGross: new import_bn11.default(valueItem.liquidity_gross),
2502
- feeGrowthOutsideA: new import_bn11.default(valueItem.fee_growth_outside_a),
2503
- feeGrowthOutsideB: new import_bn11.default(valueItem.fee_growth_outside_b),
3024
+ sqrtPrice: new import_bn12.default(valueItem.sqrt_price),
3025
+ liquidityNet: new import_bn12.default(valueItem.liquidity_net.fields.bits),
3026
+ liquidityGross: new import_bn12.default(valueItem.liquidity_gross),
3027
+ feeGrowthOutsideA: new import_bn12.default(valueItem.fee_growth_outside_a),
3028
+ feeGrowthOutsideB: new import_bn12.default(valueItem.fee_growth_outside_b),
2504
3029
  rewardersGrowthOutside: valueItem.rewards_growth_outside
2505
3030
  };
2506
3031
  return possition;
@@ -2510,11 +3035,11 @@ function buildTickDataByEvent(fields) {
2510
3035
  throw new ClmmpoolsError(`Invalid tick fields.`, "InvalidTickFields" /* InvalidTickFields */);
2511
3036
  }
2512
3037
  const index = asIntN(BigInt(fields.index.bits));
2513
- const sqrtPrice = new import_bn11.default(fields.sqrt_price);
2514
- const liquidityNet = new import_bn11.default(fields.liquidity_net.bits);
2515
- const liquidityGross = new import_bn11.default(fields.liquidity_gross);
2516
- const feeGrowthOutsideA = new import_bn11.default(fields.fee_growth_outside_a);
2517
- const feeGrowthOutsideB = new import_bn11.default(fields.fee_growth_outside_b);
3038
+ const sqrtPrice = new import_bn12.default(fields.sqrt_price);
3039
+ const liquidityNet = new import_bn12.default(fields.liquidity_net.bits);
3040
+ const liquidityGross = new import_bn12.default(fields.liquidity_gross);
3041
+ const feeGrowthOutsideA = new import_bn12.default(fields.fee_growth_outside_a);
3042
+ const feeGrowthOutsideB = new import_bn12.default(fields.fee_growth_outside_b);
2518
3043
  const rewardersGrowthOutside = fields.rewards_growth_outside || [];
2519
3044
  const tick = {
2520
3045
  objectId: "",
@@ -2533,7 +3058,7 @@ function buildClmmPositionName(pool_index, position_index) {
2533
3058
  }
2534
3059
 
2535
3060
  // src/utils/tick.ts
2536
- var import_bn12 = __toESM(require("bn.js"));
3061
+ var import_bn13 = __toESM(require("bn.js"));
2537
3062
  var TickUtil = class {
2538
3063
  /**
2539
3064
  * Get min tick index.
@@ -2573,22 +3098,22 @@ function getRewardInTickRange(pool, tickLower, tickUpper, tickLowerIndex, tickUp
2573
3098
  let rewarder_growth_below = growthGlobal[i];
2574
3099
  if (tickLower !== null) {
2575
3100
  if (pool.current_tick_index < tickLowerIndex) {
2576
- rewarder_growth_below = growthGlobal[i].sub(new import_bn12.default(tickLower.rewardersGrowthOutside[i]));
3101
+ rewarder_growth_below = growthGlobal[i].sub(new import_bn13.default(tickLower.rewardersGrowthOutside[i]));
2577
3102
  } else {
2578
3103
  rewarder_growth_below = tickLower.rewardersGrowthOutside[i];
2579
3104
  }
2580
3105
  }
2581
- let rewarder_growth_above = new import_bn12.default(0);
3106
+ let rewarder_growth_above = new import_bn13.default(0);
2582
3107
  if (tickUpper !== null) {
2583
3108
  if (pool.current_tick_index >= tickUpperIndex) {
2584
- rewarder_growth_above = growthGlobal[i].sub(new import_bn12.default(tickUpper.rewardersGrowthOutside[i]));
3109
+ rewarder_growth_above = growthGlobal[i].sub(new import_bn13.default(tickUpper.rewardersGrowthOutside[i]));
2585
3110
  } else {
2586
3111
  rewarder_growth_above = tickUpper.rewardersGrowthOutside[i];
2587
3112
  }
2588
3113
  }
2589
3114
  const rewGrowthInside = MathUtil.subUnderflowU128(
2590
- MathUtil.subUnderflowU128(new import_bn12.default(growthGlobal[i]), new import_bn12.default(rewarder_growth_below)),
2591
- new import_bn12.default(rewarder_growth_above)
3115
+ MathUtil.subUnderflowU128(new import_bn13.default(growthGlobal[i]), new import_bn13.default(rewarder_growth_below)),
3116
+ new import_bn13.default(rewarder_growth_above)
2592
3117
  );
2593
3118
  rewarderGrowthInside.push(rewGrowthInside);
2594
3119
  }
@@ -2596,8 +3121,8 @@ function getRewardInTickRange(pool, tickLower, tickUpper, tickLowerIndex, tickUp
2596
3121
  }
2597
3122
 
2598
3123
  // src/utils/transaction-util.ts
2599
- var import_bn13 = __toESM(require("bn.js"));
2600
- var import_decimal7 = __toESM(require("decimal.js"));
3124
+ var import_bn14 = __toESM(require("bn.js"));
3125
+ var import_decimal10 = __toESM(require("decimal.js"));
2601
3126
  var import_transactions = require("@mysten/sui/transactions");
2602
3127
  function findAdjustCoin(coinPair) {
2603
3128
  const isAdjustCoinA = CoinAssist.isSuiCoin(coinPair.coinTypeA);
@@ -2605,7 +3130,7 @@ function findAdjustCoin(coinPair) {
2605
3130
  return { isAdjustCoinA, isAdjustCoinB };
2606
3131
  }
2607
3132
  function reverSlippageAmount(slippageAmount, slippage) {
2608
- return import_decimal7.default.ceil(d(slippageAmount).div(1 + slippage)).toString();
3133
+ return import_decimal10.default.ceil(d(slippageAmount).div(1 + slippage)).toString();
2609
3134
  }
2610
3135
  async function printTransaction(tx, isPrint = true) {
2611
3136
  console.log(`inputs`, tx.blockData.inputs);
@@ -2905,7 +3430,7 @@ var _TransactionUtil = class {
2905
3430
  const liquidityInput = ClmmPoolUtil.estLiquidityAndcoinAmountFromOneAmounts(
2906
3431
  Number(params.tick_lower),
2907
3432
  Number(params.tick_upper),
2908
- new import_bn13.default(coinAmount),
3433
+ new import_bn14.default(coinAmount),
2909
3434
  params.fix_amount_a,
2910
3435
  true,
2911
3436
  slippage,
@@ -2979,12 +3504,12 @@ var _TransactionUtil = class {
2979
3504
  max_amount_a = params.amount_a;
2980
3505
  min_amount_a = params.amount_a;
2981
3506
  max_amount_b = params.amount_b;
2982
- 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();
3507
+ min_amount_b = new import_decimal10.default(params.amount_b).div(new import_decimal10.default(1).plus(new import_decimal10.default(params.slippage))).mul(new import_decimal10.default(1).minus(new import_decimal10.default(params.slippage))).toDecimalPlaces(0).toNumber();
2983
3508
  } else {
2984
3509
  max_amount_b = params.amount_b;
2985
3510
  min_amount_b = params.amount_b;
2986
3511
  max_amount_a = params.amount_a;
2987
- 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();
3512
+ min_amount_a = new import_decimal10.default(params.amount_a).div(new import_decimal10.default(1).plus(new import_decimal10.default(params.slippage))).mul(new import_decimal10.default(1).minus(new import_decimal10.default(params.slippage))).toDecimalPlaces(0).toNumber();
2988
3513
  }
2989
3514
  const args = params.is_open ? [
2990
3515
  tx.object(clmmConfig.global_config_id),
@@ -3973,7 +4498,7 @@ var _TransactionUtil = class {
3973
4498
  const basePath = splitPath.basePaths[i];
3974
4499
  a2b.push(basePath.direction);
3975
4500
  poolAddress.push(basePath.poolAddress);
3976
- rawAmountLimit.push(new import_bn13.default(basePath.inputAmount.toString()));
4501
+ rawAmountLimit.push(new import_bn14.default(basePath.inputAmount.toString()));
3977
4502
  if (i === 0) {
3978
4503
  coinType.push(basePath.fromCoin, basePath.toCoin);
3979
4504
  } else {
@@ -3981,8 +4506,8 @@ var _TransactionUtil = class {
3981
4506
  }
3982
4507
  }
3983
4508
  const onePath = {
3984
- amountIn: new import_bn13.default(splitPath.inputAmount.toString()),
3985
- amountOut: new import_bn13.default(splitPath.outputAmount.toString()),
4509
+ amountIn: new import_bn14.default(splitPath.inputAmount.toString()),
4510
+ amountOut: new import_bn14.default(splitPath.outputAmount.toString()),
3986
4511
  poolAddress,
3987
4512
  a2b,
3988
4513
  rawAmountLimit,
@@ -4339,9 +4864,9 @@ var TxBlock = class {
4339
4864
  };
4340
4865
 
4341
4866
  // src/utils/deepbook-utils.ts
4342
- var import_bn14 = __toESM(require("bn.js"));
4867
+ var import_bn15 = __toESM(require("bn.js"));
4343
4868
  var import_transactions3 = require("@mysten/sui/transactions");
4344
- var FLOAT_SCALING = new import_bn14.default(1e9);
4869
+ var FLOAT_SCALING = new import_bn15.default(1e9);
4345
4870
  var DeepbookUtils = class {
4346
4871
  static createAccountCap(senderAddress, sdkOptions, tx, isTransfer = false) {
4347
4872
  if (senderAddress.length === 0) {
@@ -4487,9 +5012,9 @@ var DeepbookUtils = class {
4487
5012
  static async preSwap(sdk, pool, a2b, amountIn) {
4488
5013
  let isExceed = false;
4489
5014
  let amountOut = ZERO;
4490
- let remainAmount = new import_bn14.default(amountIn);
5015
+ let remainAmount = new import_bn15.default(amountIn);
4491
5016
  let feeAmount = ZERO;
4492
- const initAmountIn = new import_bn14.default(amountIn);
5017
+ const initAmountIn = new import_bn15.default(amountIn);
4493
5018
  if (a2b) {
4494
5019
  let bids = await this.getPoolBids(sdk, pool.poolID, pool.baseAsset, pool.quoteAsset);
4495
5020
  if (bids === null) {
@@ -4499,16 +5024,16 @@ var DeepbookUtils = class {
4499
5024
  return b.price - a.price;
4500
5025
  });
4501
5026
  for (let i = 0; i < bids.length; i += 1) {
4502
- const curBidAmount = new import_bn14.default(bids[i].quantity);
4503
- const curBidPrice = new import_bn14.default(bids[i].price);
4504
- const fee = curBidAmount.mul(new import_bn14.default(curBidPrice)).mul(new import_bn14.default(pool.takerFeeRate)).div(FLOAT_SCALING).div(FLOAT_SCALING);
5027
+ const curBidAmount = new import_bn15.default(bids[i].quantity);
5028
+ const curBidPrice = new import_bn15.default(bids[i].price);
5029
+ const fee = curBidAmount.mul(new import_bn15.default(curBidPrice)).mul(new import_bn15.default(pool.takerFeeRate)).div(FLOAT_SCALING).div(FLOAT_SCALING);
4505
5030
  if (remainAmount.gt(curBidAmount)) {
4506
5031
  remainAmount = remainAmount.sub(curBidAmount);
4507
5032
  amountOut = amountOut.add(curBidAmount.mul(curBidPrice).div(FLOAT_SCALING).sub(fee));
4508
5033
  feeAmount = feeAmount.add(fee);
4509
5034
  } else {
4510
- const curOut = remainAmount.mul(new import_bn14.default(bids[i].price)).div(FLOAT_SCALING);
4511
- const curFee = curOut.mul(new import_bn14.default(pool.takerFeeRate)).div(FLOAT_SCALING);
5035
+ const curOut = remainAmount.mul(new import_bn15.default(bids[i].price)).div(FLOAT_SCALING);
5036
+ const curFee = curOut.mul(new import_bn15.default(pool.takerFeeRate)).div(FLOAT_SCALING);
4512
5037
  amountOut = amountOut.add(curOut.sub(curFee));
4513
5038
  remainAmount = remainAmount.sub(remainAmount);
4514
5039
  feeAmount = feeAmount.add(curFee);
@@ -4523,15 +5048,15 @@ var DeepbookUtils = class {
4523
5048
  isExceed = true;
4524
5049
  }
4525
5050
  for (let i = 0; i < asks.length; i += 1) {
4526
- const curAskAmount = new import_bn14.default(asks[i].price).mul(new import_bn14.default(asks[i].quantity)).div(new import_bn14.default(1e9));
4527
- const fee = curAskAmount.mul(new import_bn14.default(pool.takerFeeRate)).div(FLOAT_SCALING);
5051
+ const curAskAmount = new import_bn15.default(asks[i].price).mul(new import_bn15.default(asks[i].quantity)).div(new import_bn15.default(1e9));
5052
+ const fee = curAskAmount.mul(new import_bn15.default(pool.takerFeeRate)).div(FLOAT_SCALING);
4528
5053
  const curAskAmountWithFee = curAskAmount.add(fee);
4529
5054
  if (remainAmount.gt(curAskAmount)) {
4530
- amountOut = amountOut.add(new import_bn14.default(asks[i].quantity));
5055
+ amountOut = amountOut.add(new import_bn15.default(asks[i].quantity));
4531
5056
  remainAmount = remainAmount.sub(curAskAmountWithFee);
4532
5057
  feeAmount = feeAmount.add(fee);
4533
5058
  } else {
4534
- const splitNums = new import_bn14.default(asks[i].quantity).div(new import_bn14.default(pool.lotSize));
5059
+ const splitNums = new import_bn15.default(asks[i].quantity).div(new import_bn15.default(pool.lotSize));
4535
5060
  const splitAmount = curAskAmountWithFee.div(splitNums);
4536
5061
  const swapSplitNum = remainAmount.div(splitAmount);
4537
5062
  amountOut = amountOut.add(swapSplitNum.muln(pool.lotSize));
@@ -5392,7 +5917,7 @@ var PoolModule = class {
5392
5917
  };
5393
5918
 
5394
5919
  // src/modules/positionModule.ts
5395
- var import_bn15 = __toESM(require("bn.js"));
5920
+ var import_bn16 = __toESM(require("bn.js"));
5396
5921
  var import_transactions5 = require("@mysten/sui/transactions");
5397
5922
  var import_utils15 = require("@mysten/sui/utils");
5398
5923
  var PositionModule = class {
@@ -5614,8 +6139,8 @@ var PositionModule = class {
5614
6139
  for (let i = 0; i < valueData.length; i += 1) {
5615
6140
  const { parsedJson } = valueData[i];
5616
6141
  const posRrewarderResult = {
5617
- feeOwedA: new import_bn15.default(parsedJson.fee_owned_a),
5618
- feeOwedB: new import_bn15.default(parsedJson.fee_owned_b),
6142
+ feeOwedA: new import_bn16.default(parsedJson.fee_owned_a),
6143
+ feeOwedB: new import_bn16.default(parsedJson.fee_owned_b),
5619
6144
  position_id: parsedJson.position_id
5620
6145
  };
5621
6146
  result.push(posRrewarderResult);
@@ -5991,7 +6516,7 @@ var PositionModule = class {
5991
6516
  };
5992
6517
 
5993
6518
  // src/modules/rewarderModule.ts
5994
- var import_bn16 = __toESM(require("bn.js"));
6519
+ var import_bn17 = __toESM(require("bn.js"));
5995
6520
  var import_transactions6 = require("@mysten/sui/transactions");
5996
6521
  var RewarderModule = class {
5997
6522
  _sdk;
@@ -6017,7 +6542,7 @@ var RewarderModule = class {
6017
6542
  }
6018
6543
  const emissionsEveryDay = [];
6019
6544
  for (const rewarderInfo of rewarderInfos) {
6020
- const emissionSeconds = MathUtil.fromX64(new import_bn16.default(rewarderInfo.emissions_per_second));
6545
+ const emissionSeconds = MathUtil.fromX64(new import_bn17.default(rewarderInfo.emissions_per_second));
6021
6546
  emissionsEveryDay.push({
6022
6547
  emissions: Math.floor(emissionSeconds.toNumber() * 60 * 60 * 24),
6023
6548
  coin_address: rewarderInfo.coinAddress
@@ -6036,20 +6561,20 @@ var RewarderModule = class {
6036
6561
  const currentPool = await this.sdk.Pool.getPool(poolID);
6037
6562
  const lastTime = currentPool.rewarder_last_updated_time;
6038
6563
  currentPool.rewarder_last_updated_time = currentTime.toString();
6039
- if (Number(currentPool.liquidity) === 0 || currentTime.eq(new import_bn16.default(lastTime))) {
6564
+ if (Number(currentPool.liquidity) === 0 || currentTime.eq(new import_bn17.default(lastTime))) {
6040
6565
  return currentPool;
6041
6566
  }
6042
- const timeDelta = currentTime.div(new import_bn16.default(1e3)).sub(new import_bn16.default(lastTime)).add(new import_bn16.default(15));
6567
+ const timeDelta = currentTime.div(new import_bn17.default(1e3)).sub(new import_bn17.default(lastTime)).add(new import_bn17.default(15));
6043
6568
  const rewarderInfos = currentPool.rewarder_infos;
6044
6569
  for (let i = 0; i < rewarderInfos.length; i += 1) {
6045
6570
  const rewarderInfo = rewarderInfos[i];
6046
6571
  const rewarderGrowthDelta = MathUtil.checkMulDivFloor(
6047
6572
  timeDelta,
6048
- new import_bn16.default(rewarderInfo.emissions_per_second),
6049
- new import_bn16.default(currentPool.liquidity),
6573
+ new import_bn17.default(rewarderInfo.emissions_per_second),
6574
+ new import_bn17.default(currentPool.liquidity),
6050
6575
  128
6051
6576
  );
6052
- this.growthGlobal[i] = new import_bn16.default(rewarderInfo.growth_global).add(new import_bn16.default(rewarderGrowthDelta));
6577
+ this.growthGlobal[i] = new import_bn17.default(rewarderInfo.growth_global).add(new import_bn17.default(rewarderGrowthDelta));
6053
6578
  }
6054
6579
  return currentPool;
6055
6580
  }
@@ -6064,7 +6589,7 @@ var RewarderModule = class {
6064
6589
  */
6065
6590
  async posRewardersAmount(poolID, positionHandle, positionID) {
6066
6591
  const currentTime = Date.parse((/* @__PURE__ */ new Date()).toString());
6067
- const pool = await this.updatePoolRewarder(poolID, new import_bn16.default(currentTime));
6592
+ const pool = await this.updatePoolRewarder(poolID, new import_bn17.default(currentTime));
6068
6593
  const position = await this.sdk.Position.getPositionRewarders(positionHandle, positionID);
6069
6594
  if (position === void 0) {
6070
6595
  return [];
@@ -6085,7 +6610,7 @@ var RewarderModule = class {
6085
6610
  */
6086
6611
  async poolRewardersAmount(accountAddress, poolID) {
6087
6612
  const currentTime = Date.parse((/* @__PURE__ */ new Date()).toString());
6088
- const pool = await this.updatePoolRewarder(poolID, new import_bn16.default(currentTime));
6613
+ const pool = await this.updatePoolRewarder(poolID, new import_bn17.default(currentTime));
6089
6614
  const positions = await this.sdk.Position.getPositionList(accountAddress, [poolID]);
6090
6615
  const tickDatas = await this.getPoolLowerAndUpperTicks(pool.ticks_handle, positions);
6091
6616
  const rewarderAmount = [ZERO, ZERO, ZERO];
@@ -6112,38 +6637,38 @@ var RewarderModule = class {
6112
6637
  const growthInside = [];
6113
6638
  const AmountOwed = [];
6114
6639
  if (rewardersInside.length > 0) {
6115
- let growthDelta0 = MathUtil.subUnderflowU128(rewardersInside[0], new import_bn16.default(position.reward_growth_inside_0));
6116
- if (growthDelta0.gt(new import_bn16.default("3402823669209384634633745948738404"))) {
6640
+ let growthDelta0 = MathUtil.subUnderflowU128(rewardersInside[0], new import_bn17.default(position.reward_growth_inside_0));
6641
+ if (growthDelta0.gt(new import_bn17.default("3402823669209384634633745948738404"))) {
6117
6642
  growthDelta0 = ONE;
6118
6643
  }
6119
- const amountOwed_0 = MathUtil.checkMulShiftRight(new import_bn16.default(position.liquidity), growthDelta0, 64, 128);
6644
+ const amountOwed_0 = MathUtil.checkMulShiftRight(new import_bn17.default(position.liquidity), growthDelta0, 64, 128);
6120
6645
  growthInside.push(rewardersInside[0]);
6121
6646
  AmountOwed.push({
6122
- amount_owed: new import_bn16.default(position.reward_amount_owed_0).add(amountOwed_0),
6647
+ amount_owed: new import_bn17.default(position.reward_amount_owed_0).add(amountOwed_0),
6123
6648
  coin_address: pool.rewarder_infos[0].coinAddress
6124
6649
  });
6125
6650
  }
6126
6651
  if (rewardersInside.length > 1) {
6127
- let growthDelta_1 = MathUtil.subUnderflowU128(rewardersInside[1], new import_bn16.default(position.reward_growth_inside_1));
6128
- if (growthDelta_1.gt(new import_bn16.default("3402823669209384634633745948738404"))) {
6652
+ let growthDelta_1 = MathUtil.subUnderflowU128(rewardersInside[1], new import_bn17.default(position.reward_growth_inside_1));
6653
+ if (growthDelta_1.gt(new import_bn17.default("3402823669209384634633745948738404"))) {
6129
6654
  growthDelta_1 = ONE;
6130
6655
  }
6131
- const amountOwed_1 = MathUtil.checkMulShiftRight(new import_bn16.default(position.liquidity), growthDelta_1, 64, 128);
6656
+ const amountOwed_1 = MathUtil.checkMulShiftRight(new import_bn17.default(position.liquidity), growthDelta_1, 64, 128);
6132
6657
  growthInside.push(rewardersInside[1]);
6133
6658
  AmountOwed.push({
6134
- amount_owed: new import_bn16.default(position.reward_amount_owed_1).add(amountOwed_1),
6659
+ amount_owed: new import_bn17.default(position.reward_amount_owed_1).add(amountOwed_1),
6135
6660
  coin_address: pool.rewarder_infos[1].coinAddress
6136
6661
  });
6137
6662
  }
6138
6663
  if (rewardersInside.length > 2) {
6139
- let growthDelta_2 = MathUtil.subUnderflowU128(rewardersInside[2], new import_bn16.default(position.reward_growth_inside_2));
6140
- if (growthDelta_2.gt(new import_bn16.default("3402823669209384634633745948738404"))) {
6664
+ let growthDelta_2 = MathUtil.subUnderflowU128(rewardersInside[2], new import_bn17.default(position.reward_growth_inside_2));
6665
+ if (growthDelta_2.gt(new import_bn17.default("3402823669209384634633745948738404"))) {
6141
6666
  growthDelta_2 = ONE;
6142
6667
  }
6143
- const amountOwed_2 = MathUtil.checkMulShiftRight(new import_bn16.default(position.liquidity), growthDelta_2, 64, 128);
6668
+ const amountOwed_2 = MathUtil.checkMulShiftRight(new import_bn17.default(position.liquidity), growthDelta_2, 64, 128);
6144
6669
  growthInside.push(rewardersInside[2]);
6145
6670
  AmountOwed.push({
6146
- amount_owed: new import_bn16.default(position.reward_amount_owed_2).add(amountOwed_2),
6671
+ amount_owed: new import_bn17.default(position.reward_amount_owed_2).add(amountOwed_2),
6147
6672
  coin_address: pool.rewarder_infos[2].coinAddress
6148
6673
  });
6149
6674
  }
@@ -6257,8 +6782,8 @@ var RewarderModule = class {
6257
6782
  for (let i = 0; i < valueData.length; i += 1) {
6258
6783
  const { parsedJson } = valueData[i];
6259
6784
  const posRrewarderResult = {
6260
- feeOwedA: new import_bn16.default(parsedJson.fee_owned_a),
6261
- feeOwedB: new import_bn16.default(parsedJson.fee_owned_b),
6785
+ feeOwedA: new import_bn17.default(parsedJson.fee_owned_a),
6786
+ feeOwedB: new import_bn17.default(parsedJson.fee_owned_b),
6262
6787
  position_id: parsedJson.position_id
6263
6788
  };
6264
6789
  result.push(posRrewarderResult);
@@ -6321,7 +6846,7 @@ var RewarderModule = class {
6321
6846
  };
6322
6847
  for (let j = 0; j < params[i].rewarderInfo.length; j += 1) {
6323
6848
  posRrewarderResult.rewarderAmountOwed.push({
6324
- amount_owed: new import_bn16.default(valueData[i].parsedJson.data[j]),
6849
+ amount_owed: new import_bn17.default(valueData[i].parsedJson.data[j]),
6325
6850
  coin_address: params[i].rewarderInfo[j].coinAddress
6326
6851
  });
6327
6852
  }
@@ -6480,7 +7005,7 @@ var RewarderModule = class {
6480
7005
  };
6481
7006
 
6482
7007
  // src/modules/routerModule.ts
6483
- var import_bn17 = __toESM(require("bn.js"));
7008
+ var import_bn18 = __toESM(require("bn.js"));
6484
7009
  var import_cc_graph = require("@syntsugar/cc-graph");
6485
7010
  var import_transactions7 = require("@mysten/sui/transactions");
6486
7011
  function _pairSymbol(base, quote) {
@@ -6762,8 +7287,8 @@ var RouterModule = class {
6762
7287
  if (swapWithMultiPoolParams != null) {
6763
7288
  const preSwapResult2 = await this.sdk.Swap.preSwapWithMultiPool(swapWithMultiPoolParams);
6764
7289
  const onePath2 = {
6765
- amountIn: new import_bn17.default(preSwapResult2.estimatedAmountIn),
6766
- amountOut: new import_bn17.default(preSwapResult2.estimatedAmountOut),
7290
+ amountIn: new import_bn18.default(preSwapResult2.estimatedAmountIn),
7291
+ amountOut: new import_bn18.default(preSwapResult2.estimatedAmountOut),
6767
7292
  poolAddress: [preSwapResult2.poolAddress],
6768
7293
  a2b: [preSwapResult2.aToB],
6769
7294
  rawAmountLimit: byAmountIn ? [preSwapResult2.estimatedAmountOut] : [preSwapResult2.estimatedAmountIn],
@@ -6776,8 +7301,8 @@ var RouterModule = class {
6776
7301
  priceSlippagePoint
6777
7302
  };
6778
7303
  const result2 = {
6779
- amountIn: new import_bn17.default(preSwapResult2.estimatedAmountIn),
6780
- amountOut: new import_bn17.default(preSwapResult2.estimatedAmountOut),
7304
+ amountIn: new import_bn18.default(preSwapResult2.estimatedAmountIn),
7305
+ amountOut: new import_bn18.default(preSwapResult2.estimatedAmountOut),
6781
7306
  paths: [onePath2],
6782
7307
  a2b: preSwapResult2.aToB,
6783
7308
  b2c: void 0,
@@ -6799,8 +7324,8 @@ var RouterModule = class {
6799
7324
  if (swapWithMultiPoolParams != null) {
6800
7325
  const preSwapResult2 = await this.sdk.Swap.preSwapWithMultiPool(swapWithMultiPoolParams);
6801
7326
  const onePath2 = {
6802
- amountIn: new import_bn17.default(preSwapResult2.estimatedAmountIn),
6803
- amountOut: new import_bn17.default(preSwapResult2.estimatedAmountOut),
7327
+ amountIn: new import_bn18.default(preSwapResult2.estimatedAmountIn),
7328
+ amountOut: new import_bn18.default(preSwapResult2.estimatedAmountOut),
6804
7329
  poolAddress: [preSwapResult2.poolAddress],
6805
7330
  a2b: [preSwapResult2.aToB],
6806
7331
  rawAmountLimit: byAmountIn ? [preSwapResult2.estimatedAmountOut] : [preSwapResult2.estimatedAmountIn],
@@ -6813,8 +7338,8 @@ var RouterModule = class {
6813
7338
  priceSlippagePoint
6814
7339
  };
6815
7340
  const result3 = {
6816
- amountIn: new import_bn17.default(preSwapResult2.estimatedAmountIn),
6817
- amountOut: new import_bn17.default(preSwapResult2.estimatedAmountOut),
7341
+ amountIn: new import_bn18.default(preSwapResult2.estimatedAmountIn),
7342
+ amountOut: new import_bn18.default(preSwapResult2.estimatedAmountOut),
6818
7343
  paths: [onePath2],
6819
7344
  a2b: preSwapResult2.aToB,
6820
7345
  b2c: void 0,
@@ -6895,8 +7420,8 @@ var RouterModule = class {
6895
7420
  if (swapWithMultiPoolParams != null) {
6896
7421
  const preSwapResult = await this.sdk.Swap.preSwapWithMultiPool(swapWithMultiPoolParams);
6897
7422
  const onePath = {
6898
- amountIn: new import_bn17.default(preSwapResult.estimatedAmountIn),
6899
- amountOut: new import_bn17.default(preSwapResult.estimatedAmountOut),
7423
+ amountIn: new import_bn18.default(preSwapResult.estimatedAmountIn),
7424
+ amountOut: new import_bn18.default(preSwapResult.estimatedAmountOut),
6900
7425
  poolAddress: [preSwapResult.poolAddress],
6901
7426
  a2b: [preSwapResult.aToB],
6902
7427
  rawAmountLimit: byAmountIn ? [preSwapResult.estimatedAmountOut] : [preSwapResult.estimatedAmountIn],
@@ -6909,8 +7434,8 @@ var RouterModule = class {
6909
7434
  priceSlippagePoint
6910
7435
  };
6911
7436
  const result = {
6912
- amountIn: new import_bn17.default(preSwapResult.estimatedAmountIn),
6913
- amountOut: new import_bn17.default(preSwapResult.estimatedAmountOut),
7437
+ amountIn: new import_bn18.default(preSwapResult.estimatedAmountIn),
7438
+ amountOut: new import_bn18.default(preSwapResult.estimatedAmountOut),
6914
7439
  paths: [onePath],
6915
7440
  a2b: preSwapResult.aToB,
6916
7441
  b2c: void 0,
@@ -6994,13 +7519,13 @@ var RouterModule = class {
6994
7519
  continue;
6995
7520
  }
6996
7521
  if (params[0].byAmountIn) {
6997
- const amount = new import_bn17.default(valueData[i].parsedJson.data.amount_out);
7522
+ const amount = new import_bn18.default(valueData[i].parsedJson.data.amount_out);
6998
7523
  if (amount.gt(tempMaxAmount)) {
6999
7524
  tempIndex = i;
7000
7525
  tempMaxAmount = amount;
7001
7526
  }
7002
7527
  } else {
7003
- 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));
7528
+ const amount = params[i].stepNums > 1 ? new import_bn18.default(valueData[i].parsedJson.data.amount_in) : new import_bn18.default(valueData[i].parsedJson.data.amount_in).add(new import_bn18.default(valueData[i].parsedJson.data.fee_amount));
7004
7529
  if (amount.lt(tempMaxAmount)) {
7005
7530
  tempIndex = i;
7006
7531
  tempMaxAmount = amount;
@@ -7070,8 +7595,8 @@ var RouterModule = class {
7070
7595
  };
7071
7596
 
7072
7597
  // src/modules/swapModule.ts
7073
- var import_bn18 = __toESM(require("bn.js"));
7074
- var import_decimal8 = __toESM(require("decimal.js"));
7598
+ var import_bn19 = __toESM(require("bn.js"));
7599
+ var import_decimal11 = __toESM(require("decimal.js"));
7075
7600
  var import_transactions8 = require("@mysten/sui/transactions");
7076
7601
  var AMM_SWAP_MODULE = "amm_swap";
7077
7602
  var POOL_STRUCT = "Pool";
@@ -7089,14 +7614,14 @@ var SwapModule = class {
7089
7614
  const pathCount = item.basePaths.length;
7090
7615
  if (pathCount > 0) {
7091
7616
  const path = item.basePaths[0];
7092
- const feeRate = path.label === "Magma" ? new import_decimal8.default(path.feeRate).div(10 ** 6) : new import_decimal8.default(path.feeRate).div(10 ** 9);
7617
+ const feeRate = path.label === "Magma" ? new import_decimal11.default(path.feeRate).div(10 ** 6) : new import_decimal11.default(path.feeRate).div(10 ** 9);
7093
7618
  const feeAmount = d(path.inputAmount).div(10 ** path.fromDecimal).mul(feeRate);
7094
7619
  fee = fee.add(feeAmount);
7095
7620
  if (pathCount > 1) {
7096
7621
  const path2 = item.basePaths[1];
7097
- const price1 = path.direction ? path.currentPrice : new import_decimal8.default(1).div(path.currentPrice);
7098
- const price2 = path2.direction ? path2.currentPrice : new import_decimal8.default(1).div(path2.currentPrice);
7099
- const feeRate2 = path2.label === "Magma" ? new import_decimal8.default(path2.feeRate).div(10 ** 6) : new import_decimal8.default(path2.feeRate).div(10 ** 9);
7622
+ const price1 = path.direction ? path.currentPrice : new import_decimal11.default(1).div(path.currentPrice);
7623
+ const price2 = path2.direction ? path2.currentPrice : new import_decimal11.default(1).div(path2.currentPrice);
7624
+ const feeRate2 = path2.label === "Magma" ? new import_decimal11.default(path2.feeRate).div(10 ** 6) : new import_decimal11.default(path2.feeRate).div(10 ** 9);
7100
7625
  const feeAmount2 = d(path2.outputAmount).div(10 ** path2.toDecimal).mul(feeRate2);
7101
7626
  const fee2 = feeAmount2.div(price1.mul(price2));
7102
7627
  fee = fee.add(fee2);
@@ -7114,17 +7639,17 @@ var SwapModule = class {
7114
7639
  const outputAmount = d(path.outputAmount).div(10 ** path.toDecimal);
7115
7640
  const inputAmount = d(path.inputAmount).div(10 ** path.fromDecimal);
7116
7641
  const rate = outputAmount.div(inputAmount);
7117
- const cprice = path.direction ? new import_decimal8.default(path.currentPrice) : new import_decimal8.default(1).div(path.currentPrice);
7642
+ const cprice = path.direction ? new import_decimal11.default(path.currentPrice) : new import_decimal11.default(1).div(path.currentPrice);
7118
7643
  impactValue = impactValue.add(this.calculateSingleImpact(rate, cprice));
7119
7644
  }
7120
7645
  if (pathCount === 2) {
7121
7646
  const path = item.basePaths[0];
7122
7647
  const path2 = item.basePaths[1];
7123
- const cprice1 = path.direction ? new import_decimal8.default(path.currentPrice) : new import_decimal8.default(1).div(path.currentPrice);
7124
- const cprice2 = path2.direction ? new import_decimal8.default(path2.currentPrice) : new import_decimal8.default(1).div(path2.currentPrice);
7648
+ const cprice1 = path.direction ? new import_decimal11.default(path.currentPrice) : new import_decimal11.default(1).div(path.currentPrice);
7649
+ const cprice2 = path2.direction ? new import_decimal11.default(path2.currentPrice) : new import_decimal11.default(1).div(path2.currentPrice);
7125
7650
  const cprice = cprice1.mul(cprice2);
7126
- const outputAmount = new import_decimal8.default(path2.outputAmount).div(10 ** path2.toDecimal);
7127
- const inputAmount = new import_decimal8.default(path.inputAmount).div(10 ** path.fromDecimal);
7651
+ const outputAmount = new import_decimal11.default(path2.outputAmount).div(10 ** path2.toDecimal);
7652
+ const inputAmount = new import_decimal11.default(path.inputAmount).div(10 ** path.fromDecimal);
7128
7653
  const rate = outputAmount.div(inputAmount);
7129
7654
  impactValue = impactValue.add(this.calculateSingleImpact(rate, cprice));
7130
7655
  }
@@ -7186,13 +7711,13 @@ var SwapModule = class {
7186
7711
  continue;
7187
7712
  }
7188
7713
  if (params.byAmountIn) {
7189
- const amount = new import_bn18.default(valueData[i].parsedJson.data.amount_out);
7714
+ const amount = new import_bn19.default(valueData[i].parsedJson.data.amount_out);
7190
7715
  if (amount.gt(tempMaxAmount)) {
7191
7716
  tempIndex = i;
7192
7717
  tempMaxAmount = amount;
7193
7718
  }
7194
7719
  } else {
7195
- const amount = new import_bn18.default(valueData[i].parsedJson.data.amount_out);
7720
+ const amount = new import_bn19.default(valueData[i].parsedJson.data.amount_out);
7196
7721
  if (amount.lt(tempMaxAmount)) {
7197
7722
  tempIndex = i;
7198
7723
  tempMaxAmount = amount;
@@ -7256,7 +7781,7 @@ var SwapModule = class {
7256
7781
  return this.transformSwapData(params, valueData[0].parsedJson.data);
7257
7782
  }
7258
7783
  transformSwapData(params, data) {
7259
- const estimatedAmountIn = data.amount_in && data.fee_amount ? new import_bn18.default(data.amount_in).add(new import_bn18.default(data.fee_amount)).toString() : "";
7784
+ const estimatedAmountIn = data.amount_in && data.fee_amount ? new import_bn19.default(data.amount_in).add(new import_bn19.default(data.fee_amount)).toString() : "";
7260
7785
  return {
7261
7786
  poolAddress: params.pool.poolAddress,
7262
7787
  currentSqrtPrice: params.currentSqrtPrice,
@@ -7273,7 +7798,7 @@ var SwapModule = class {
7273
7798
  transformSwapWithMultiPoolData(params, jsonData) {
7274
7799
  const { data } = jsonData;
7275
7800
  console.log("json data. ", data);
7276
- const estimatedAmountIn = data.amount_in && data.fee_amount ? new import_bn18.default(data.amount_in).add(new import_bn18.default(data.fee_amount)).toString() : "";
7801
+ const estimatedAmountIn = data.amount_in && data.fee_amount ? new import_bn19.default(data.amount_in).add(new import_bn19.default(data.fee_amount)).toString() : "";
7277
7802
  return {
7278
7803
  poolAddress: params.poolAddress,
7279
7804
  estimatedAmountIn,
@@ -8786,8 +9311,8 @@ var TokenModule = class {
8786
9311
  };
8787
9312
 
8788
9313
  // src/modules/routerModuleV2.ts
8789
- var import_bn19 = __toESM(require("bn.js"));
8790
- var import_decimal9 = __toESM(require("decimal.js"));
9314
+ var import_bn20 = __toESM(require("bn.js"));
9315
+ var import_decimal12 = __toESM(require("decimal.js"));
8791
9316
  var import_uuid = require("uuid");
8792
9317
  var import_axios = __toESM(require("axios"));
8793
9318
  var RouterModuleV2 = class {
@@ -8804,7 +9329,7 @@ var RouterModuleV2 = class {
8804
9329
  if (label === "Magma") {
8805
9330
  return TickMath.sqrtPriceX64ToPrice(currentSqrtPrice, decimalA, decimalB);
8806
9331
  }
8807
- return new import_decimal9.default(currentSqrtPrice.toString()).div(new import_decimal9.default(10).pow(new import_decimal9.default(decimalB + 9 - decimalA)));
9332
+ return new import_decimal12.default(currentSqrtPrice.toString()).div(new import_decimal12.default(10).pow(new import_decimal12.default(decimalB + 9 - decimalA)));
8808
9333
  }
8809
9334
  parseJsonResult(data) {
8810
9335
  const result = {
@@ -8830,12 +9355,12 @@ var RouterModuleV2 = class {
8830
9355
  outputAmount: basePath.output_amount,
8831
9356
  inputAmount: basePath.input_amount,
8832
9357
  feeRate: basePath.fee_rate,
8833
- currentSqrtPrice: new import_bn19.default(basePath.current_sqrt_price.toString()),
8834
- afterSqrtPrice: basePath.label === "Magma" ? new import_bn19.default(basePath.after_sqrt_price.toString()) : ZERO,
9358
+ currentSqrtPrice: new import_bn20.default(basePath.current_sqrt_price.toString()),
9359
+ afterSqrtPrice: basePath.label === "Magma" ? new import_bn20.default(basePath.after_sqrt_price.toString()) : ZERO,
8835
9360
  fromDecimal: basePath.from_decimal,
8836
9361
  toDecimal: basePath.to_decimal,
8837
9362
  currentPrice: this.calculatePrice(
8838
- new import_bn19.default(basePath.current_sqrt_price.toString()),
9363
+ new import_bn20.default(basePath.current_sqrt_price.toString()),
8839
9364
  basePath.from_decimal,
8840
9365
  basePath.to_decimal,
8841
9366
  basePath.direction,
@@ -8918,7 +9443,7 @@ var RouterModuleV2 = class {
8918
9443
  const priceResult = await this.sdk.Router.priceUseV1(
8919
9444
  from,
8920
9445
  to,
8921
- new import_bn19.default(amount),
9446
+ new import_bn20.default(amount),
8922
9447
  byAmountIn,
8923
9448
  priceSplitPoint,
8924
9449
  partner,
@@ -8930,7 +9455,7 @@ var RouterModuleV2 = class {
8930
9455
  if (path.poolAddress.length > 1) {
8931
9456
  const fromDecimal0 = this.sdk.Router.tokenInfo(path.coinType[0]).decimals;
8932
9457
  const toDecimal0 = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
8933
- 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);
9458
+ const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new import_bn20.default(priceResult.currentSqrtPrice[0]), fromDecimal0, toDecimal0) : TickMath.sqrtPriceX64ToPrice(new import_bn20.default(priceResult.currentSqrtPrice[0]), toDecimal0, fromDecimal0);
8934
9459
  const path0 = {
8935
9460
  direction: path.a2b[0],
8936
9461
  label: "Magma",
@@ -8947,7 +9472,7 @@ var RouterModuleV2 = class {
8947
9472
  };
8948
9473
  const fromDecimal1 = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
8949
9474
  const toDecimal1 = this.sdk.Router.tokenInfo(path.coinType[2]).decimals;
8950
- 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);
9475
+ const currentPrice1 = path.a2b[1] ? TickMath.sqrtPriceX64ToPrice(new import_bn20.default(priceResult.currentSqrtPrice[1]), fromDecimal1, toDecimal1) : TickMath.sqrtPriceX64ToPrice(new import_bn20.default(priceResult.currentSqrtPrice[1]), toDecimal1, fromDecimal1);
8951
9476
  const path1 = {
8952
9477
  direction: path.a2b[1],
8953
9478
  label: "Magma",
@@ -8966,7 +9491,7 @@ var RouterModuleV2 = class {
8966
9491
  } else {
8967
9492
  const fromDecimal = this.sdk.Router.tokenInfo(path.coinType[0]).decimals;
8968
9493
  const toDecimal = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
8969
- 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);
9494
+ const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new import_bn20.default(priceResult.currentSqrtPrice[0]), fromDecimal, toDecimal) : TickMath.sqrtPriceX64ToPrice(new import_bn20.default(priceResult.currentSqrtPrice[0]), toDecimal, fromDecimal);
8970
9495
  const path0 = {
8971
9496
  direction: path.a2b[0],
8972
9497
  label: "Magma",
@@ -9051,7 +9576,7 @@ var RouterModuleV2 = class {
9051
9576
  const priceResult = await this.sdk.Router.priceUseV1(
9052
9577
  from,
9053
9578
  to,
9054
- new import_bn19.default(amount),
9579
+ new import_bn20.default(amount),
9055
9580
  byAmountIn,
9056
9581
  priceSplitPoint,
9057
9582
  partner,
@@ -9063,7 +9588,7 @@ var RouterModuleV2 = class {
9063
9588
  if (path.poolAddress.length > 1) {
9064
9589
  const fromDecimal0 = this.sdk.Router.tokenInfo(path.coinType[0]).decimals;
9065
9590
  const toDecimal0 = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
9066
- 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);
9591
+ const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new import_bn20.default(priceResult.currentSqrtPrice[0]), fromDecimal0, toDecimal0) : TickMath.sqrtPriceX64ToPrice(new import_bn20.default(priceResult.currentSqrtPrice[0]), toDecimal0, fromDecimal0);
9067
9592
  const path0 = {
9068
9593
  direction: path.a2b[0],
9069
9594
  label: "Magma",
@@ -9080,7 +9605,7 @@ var RouterModuleV2 = class {
9080
9605
  };
9081
9606
  const fromDecimal1 = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
9082
9607
  const toDecimal1 = this.sdk.Router.tokenInfo(path.coinType[2]).decimals;
9083
- 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);
9608
+ const currentPrice1 = path.a2b[1] ? TickMath.sqrtPriceX64ToPrice(new import_bn20.default(priceResult.currentSqrtPrice[1]), fromDecimal1, toDecimal1) : TickMath.sqrtPriceX64ToPrice(new import_bn20.default(priceResult.currentSqrtPrice[1]), toDecimal1, fromDecimal1);
9084
9609
  const path1 = {
9085
9610
  direction: path.a2b[1],
9086
9611
  label: "Magma",
@@ -9099,7 +9624,7 @@ var RouterModuleV2 = class {
9099
9624
  } else {
9100
9625
  const fromDecimal = this.sdk.Router.tokenInfo(path.coinType[0]).decimals;
9101
9626
  const toDecimal = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
9102
- 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);
9627
+ const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new import_bn20.default(priceResult.currentSqrtPrice[0]), fromDecimal, toDecimal) : TickMath.sqrtPriceX64ToPrice(new import_bn20.default(priceResult.currentSqrtPrice[0]), toDecimal, fromDecimal);
9103
9628
  const path0 = {
9104
9629
  direction: path.a2b[0],
9105
9630
  label: "Magma",
@@ -9972,6 +10497,21 @@ var GaugeModule = class {
9972
10497
  });
9973
10498
  return tx;
9974
10499
  }
10500
+ async getAllRewardByPositions(paramsList) {
10501
+ const tx = new import_transactions11.Transaction();
10502
+ const { integrate } = this.sdk.sdkOptions;
10503
+ const { magma_token } = getPackagerConfigs(this.sdk.sdkOptions.magma_config);
10504
+ paramsList.forEach((params) => {
10505
+ const typeArguments = [params.coinTypeA, params.coinTypeB, magma_token];
10506
+ const args = [tx.object(params.gaugeId), tx.object(params.poolId), tx.object(params.positionId), tx.object(CLOCK_ADDRESS)];
10507
+ tx.moveCall({
10508
+ target: `${integrate.published_at}::${Gauge}::get_reward_by_position`,
10509
+ arguments: args,
10510
+ typeArguments
10511
+ });
10512
+ });
10513
+ return tx;
10514
+ }
9975
10515
  async getEpochRewardByPool(pool, incentive_tokens) {
9976
10516
  const tx = new import_transactions11.Transaction();
9977
10517
  const { integrate, simulationAccount } = this.sdk.sdkOptions;
@@ -10004,67 +10544,959 @@ var GaugeModule = class {
10004
10544
  }
10005
10545
  };
10006
10546
 
10007
- // src/sdk.ts
10008
- var MagmaClmmSDK = class {
10547
+ // src/modules/dlmm.ts
10548
+ var import_transactions12 = require("@mysten/sui/transactions");
10549
+ var import_calc_dlmm3 = require("@magmaprotocol/calc_dlmm");
10550
+ var import_decimal13 = __toESM(require("decimal.js"));
10551
+ var DlmmModule = class {
10552
+ _sdk;
10009
10553
  _cache = {};
10010
- /**
10011
- * RPC provider on the SUI chain
10012
- */
10013
- _rpcModule;
10014
- /**
10015
- * Provide interact with clmm pools with a pool router interface.
10016
- */
10017
- _pool;
10018
- /**
10019
- * Provide interact with clmm position with a position router interface.
10020
- */
10021
- _position;
10022
- /**
10023
- * Provide interact with a pool swap router interface.
10024
- */
10025
- _swap;
10026
- /**
10027
- * Provide interact with a lock interface.
10028
- */
10029
- _lock;
10030
- _gauge;
10031
- /**
10032
- * Provide interact with a position rewarder interface.
10033
- */
10034
- _rewarder;
10035
- /**
10036
- * Provide interact with a pool router interface.
10037
- */
10038
- _router;
10039
- /**
10040
- * Provide interact with a pool routerV2 interface.
10041
- */
10042
- _router_v2;
10043
- /**
10044
- * Provide interact with pool and token config (contain token base info for metadat).
10045
- * @deprecated Please use MagmaConfig instead
10046
- */
10047
- _token;
10048
- /**
10049
- * Provide interact with clmm pool and coin and launchpad pool config
10050
- */
10051
- _config;
10052
- /**
10053
- * Provide sdk options
10054
- */
10055
- _sdkOptions;
10056
- /**
10057
- * After connecting the wallet, set the current wallet address to senderAddress.
10058
- */
10059
- _senderAddress = "";
10060
- constructor(options) {
10061
- this._sdkOptions = options;
10062
- this._rpcModule = new RpcModule({
10063
- url: options.fullRpcUrl
10064
- });
10065
- this._swap = new SwapModule(this);
10554
+ constructor(sdk) {
10555
+ this._sdk = sdk;
10556
+ }
10557
+ get sdk() {
10558
+ return this._sdk;
10559
+ }
10560
+ async getPoolInfo(pools) {
10561
+ const objects = await this._sdk.fullClient.batchGetObjects(pools, { showContent: true });
10562
+ const poolList = [];
10563
+ objects.forEach((obj) => {
10564
+ if (obj.error != null || obj.data?.content?.dataType !== "moveObject") {
10565
+ throw new ClmmpoolsError(`Invalid objects. error: ${obj.error}`, "InvalidType" /* InvalidType */);
10566
+ }
10567
+ const fields = getObjectFields(obj);
10568
+ poolList.push({
10569
+ pool_id: fields.id.id,
10570
+ bin_step: fields.bin_step,
10571
+ coin_a: fields.x.fields.name,
10572
+ coin_b: fields.y.fields.name,
10573
+ base_factor: fields.params.fields.base_factor,
10574
+ base_fee: fields.params.fields.base_factor / 1e4 * (fields.bin_step / 1e4),
10575
+ active_index: fields.params.fields.active_index,
10576
+ real_bin_id: (0, import_calc_dlmm3.get_real_id)(fields.params.fields.active_index),
10577
+ coinAmountA: fields.reserve_x,
10578
+ coinAmountB: fields.reserve_y
10579
+ });
10580
+ });
10581
+ return poolList;
10582
+ }
10583
+ // eg: fetch pool active_index
10584
+ async fetchPairParams(params) {
10585
+ const tx = new import_transactions12.Transaction();
10586
+ const { integrate, simulationAccount } = this.sdk.sdkOptions;
10587
+ const typeArguments = [params.coinTypeA, params.coinTypeB];
10588
+ const args = [tx.object(params.pair)];
10589
+ tx.moveCall({
10590
+ target: `${integrate.published_at}::${DlmmScript}::fetch_pair_params`,
10591
+ arguments: args,
10592
+ typeArguments
10593
+ });
10594
+ const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
10595
+ transactionBlock: tx,
10596
+ sender: simulationAccount.address
10597
+ });
10598
+ if (simulateRes.error != null) {
10599
+ throw new Error(`fetchBins error code: ${simulateRes.error ?? "unknown error"}`);
10600
+ }
10601
+ let res = {
10602
+ base_factor: 0,
10603
+ filter_period: 0,
10604
+ decay_period: 0,
10605
+ reduction_factor: 0,
10606
+ variable_fee_control: 0,
10607
+ protocol_share: 0,
10608
+ max_volatility_accumulator: 0,
10609
+ volatility_accumulator: 0,
10610
+ volatility_reference: 0,
10611
+ index_reference: 0,
10612
+ time_of_last_update: 0,
10613
+ oracle_index: 0,
10614
+ active_index: 0
10615
+ };
10616
+ simulateRes.events?.forEach((item) => {
10617
+ console.log(extractStructTagFromType(item.type).name);
10618
+ if (extractStructTagFromType(item.type).name === `EventPairParams`) {
10619
+ res = item.parsedJson.params;
10620
+ }
10621
+ });
10622
+ return res;
10623
+ }
10624
+ // NOTE: x, y should be sorted
10625
+ async createPairPayload(params) {
10626
+ const storage_id = (0, import_calc_dlmm3.get_storage_id_from_real_id)(
10627
+ BinMath.getBinIdFromPrice(params.priceTokenBPerTokenA, params.bin_step, params.coinADecimal, params.coinBDecimal)
10628
+ );
10629
+ const tx = new import_transactions12.Transaction();
10630
+ tx.setSender(this.sdk.senderAddress);
10631
+ const { clmm_pool, dlmm_pool, integrate } = this.sdk.sdkOptions;
10632
+ const { global_config_id } = getPackagerConfigs(clmm_pool);
10633
+ const dlmmConfig = getPackagerConfigs(dlmm_pool);
10634
+ const typeArguments = [params.coinTypeA, params.coinTypeB];
10635
+ const args = [
10636
+ tx.object(dlmmConfig.factory),
10637
+ tx.object(global_config_id),
10638
+ tx.pure.u64(params.base_fee),
10639
+ tx.pure.u16(params.bin_step),
10640
+ tx.pure.u32(storage_id)
10641
+ ];
10642
+ tx.moveCall({
10643
+ target: `${integrate.published_at}::${DlmmScript}::create_pair`,
10644
+ typeArguments,
10645
+ arguments: args
10646
+ });
10647
+ return tx;
10648
+ }
10649
+ // async mintByStrategySingle(params: MintByStrategySingleParams): Promise<Transaction> {}
10650
+ async mintByStrategy(params) {
10651
+ const tx = new import_transactions12.Transaction();
10652
+ const slippage = new import_decimal13.default(params.slippage);
10653
+ const lower_slippage = new import_decimal13.default(1).sub(slippage.div(new import_decimal13.default(1e4)));
10654
+ const upper_slippage = new import_decimal13.default(1).plus(slippage.div(new import_decimal13.default(1e4)));
10655
+ tx.setSender(this.sdk.senderAddress);
10656
+ const { dlmm_pool, integrate } = this.sdk.sdkOptions;
10657
+ const dlmmConfig = getPackagerConfigs(dlmm_pool);
10658
+ const typeArguments = [params.coinTypeA, params.coinTypeB];
10659
+ const price = (0, import_calc_dlmm3.get_price_x128_from_real_id)(params.active_bin, params.bin_step);
10660
+ const min_price = new import_decimal13.default(price).mul(lower_slippage);
10661
+ const max_price = new import_decimal13.default(price).mul(upper_slippage);
10662
+ const active_min = (0, import_calc_dlmm3.get_storage_id_from_real_id)((0, import_calc_dlmm3.get_real_id_from_price_x128)(min_price.toDecimalPlaces(0).toString(), params.bin_step));
10663
+ const active_max = (0, import_calc_dlmm3.get_storage_id_from_real_id)((0, import_calc_dlmm3.get_real_id_from_price_x128)(max_price.toDecimalPlaces(0).toString(), params.bin_step));
10664
+ const allCoins = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress);
10665
+ let primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountATotal), params.coinTypeA, false, true);
10666
+ let primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountBTotal), params.coinTypeB, false, true);
10667
+ let amount_min = 0;
10668
+ let amount_max = 0;
10669
+ if (params.fixCoinA && params.fixCoinB) {
10670
+ primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountATotal), params.coinTypeB, false, true);
10671
+ primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountBTotal), params.coinTypeB, false, true);
10672
+ } else if (params.fixCoinA) {
10673
+ amount_min = new import_decimal13.default(params.amountBTotal).mul(lower_slippage).toDecimalPlaces(0).toNumber();
10674
+ amount_max = new import_decimal13.default(params.amountBTotal).mul(upper_slippage).toDecimalPlaces(0).toNumber();
10675
+ primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amount_max), params.coinTypeB, false, true);
10676
+ } else if (params.fixCoinB) {
10677
+ amount_min = new import_decimal13.default(params.amountATotal).mul(lower_slippage).toDecimalPlaces(0).toNumber();
10678
+ amount_max = new import_decimal13.default(params.amountATotal).mul(upper_slippage).toDecimalPlaces(0).toNumber();
10679
+ primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amount_max), params.coinTypeB, false, true);
10680
+ }
10681
+ if (params.fixCoinA && params.fixCoinB) {
10682
+ } else if (params.fixCoinA) {
10683
+ params.amountBTotal = 0;
10684
+ } else if (params.fixCoinB) {
10685
+ params.amountATotal = 0;
10686
+ }
10687
+ const args = [
10688
+ tx.object(params.pair),
10689
+ tx.object(dlmmConfig.factory),
10690
+ primaryCoinAInputs.targetCoin,
10691
+ primaryCoinBInputs.targetCoin,
10692
+ tx.pure.u64(params.amountATotal),
10693
+ tx.pure.u64(params.amountBTotal),
10694
+ tx.pure.u8(params.strategy),
10695
+ tx.pure.u32((0, import_calc_dlmm3.get_storage_id_from_real_id)(params.min_bin)),
10696
+ tx.pure.u32((0, import_calc_dlmm3.get_storage_id_from_real_id)(params.max_bin)),
10697
+ tx.pure.u32(active_min),
10698
+ tx.pure.u32(active_max),
10699
+ tx.pure.u64(amount_min),
10700
+ tx.pure.u64(amount_max),
10701
+ tx.object(CLOCK_ADDRESS)
10702
+ ];
10703
+ tx.moveCall({
10704
+ target: `${integrate.published_at}::${DlmmScript}::mint_by_strategy`,
10705
+ typeArguments,
10706
+ arguments: args
10707
+ });
10708
+ return tx;
10709
+ }
10710
+ // Create a position by percent
10711
+ async mintPercent(params) {
10712
+ const tx = new import_transactions12.Transaction();
10713
+ tx.setSender(this.sdk.senderAddress);
10714
+ const { dlmm_pool, integrate } = this.sdk.sdkOptions;
10715
+ const dlmmConfig = getPackagerConfigs(dlmm_pool);
10716
+ const typeArguments = [params.coinTypeA, params.coinTypeB];
10717
+ const allCoins = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress);
10718
+ const primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountATotal), params.coinTypeA, false, true);
10719
+ const primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountBTotal), params.coinTypeB, false, true);
10720
+ const args = [
10721
+ tx.object(params.pair),
10722
+ tx.object(dlmmConfig.factory),
10723
+ primaryCoinAInputs.targetCoin,
10724
+ primaryCoinBInputs.targetCoin,
10725
+ tx.pure.u64(params.amountATotal),
10726
+ tx.pure.u64(params.amountBTotal),
10727
+ tx.pure.vector("u32", params.storageIds),
10728
+ tx.pure.vector("u64", params.binsAPercent),
10729
+ tx.pure.vector("u64", params.binsBPercent),
10730
+ tx.pure.address(params.to),
10731
+ tx.object(CLOCK_ADDRESS)
10732
+ ];
10733
+ tx.moveCall({
10734
+ target: `${integrate.published_at}::${DlmmScript}::mint_percent`,
10735
+ typeArguments,
10736
+ arguments: args
10737
+ });
10738
+ return tx;
10739
+ }
10740
+ // Create a position by amount
10741
+ async createPositionByAmount(params) {
10742
+ const tx = new import_transactions12.Transaction();
10743
+ tx.setSender(this.sdk.senderAddress);
10744
+ const { dlmm_pool, integrate } = this.sdk.sdkOptions;
10745
+ const dlmmConfig = getPackagerConfigs(dlmm_pool);
10746
+ const typeArguments = [params.coinTypeA, params.coinTypeB];
10747
+ const allCoins = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress);
10748
+ const primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountATotal), params.coinTypeA, false, true);
10749
+ const primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountBTotal), params.coinTypeB, false, true);
10750
+ const args = [
10751
+ tx.object(params.pair),
10752
+ tx.object(dlmmConfig.factory),
10753
+ primaryCoinAInputs.targetCoin,
10754
+ primaryCoinBInputs.targetCoin,
10755
+ tx.pure.vector("u32", params.storageIds),
10756
+ tx.pure.vector("u64", params.amountsA),
10757
+ tx.pure.vector("u64", params.amountsB),
10758
+ tx.pure.address(params.to),
10759
+ tx.object(CLOCK_ADDRESS)
10760
+ ];
10761
+ tx.moveCall({
10762
+ target: `${integrate.published_at}::${DlmmScript}::mint_amounts`,
10763
+ typeArguments,
10764
+ arguments: args
10765
+ });
10766
+ return tx;
10767
+ }
10768
+ async addLiquidity(params) {
10769
+ if (params.rewards_token.length === 0) {
10770
+ return this._raisePositionByAmounts(params);
10771
+ }
10772
+ return this._raisePositionByAmountsReward(params);
10773
+ }
10774
+ async _raisePositionByAmounts(params) {
10775
+ const tx = new import_transactions12.Transaction();
10776
+ tx.setSender(this.sdk.senderAddress);
10777
+ const { dlmm_pool, integrate } = this.sdk.sdkOptions;
10778
+ const dlmmConfig = getPackagerConfigs(dlmm_pool);
10779
+ const typeArguments = [params.coin_a, params.coin_b];
10780
+ const allCoins = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress);
10781
+ const amountATotal = params.amounts_a.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
10782
+ const amountBTotal = params.amounts_b.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
10783
+ const primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amountATotal), params.coin_a, false, true);
10784
+ const primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amountBTotal), params.coin_b, false, true);
10785
+ const args = [
10786
+ tx.object(params.pool_id),
10787
+ tx.object(dlmmConfig.factory),
10788
+ tx.object(params.position_id),
10789
+ primaryCoinAInputs.targetCoin,
10790
+ primaryCoinBInputs.targetCoin,
10791
+ tx.pure.vector("u64", params.amounts_a),
10792
+ tx.pure.vector("u64", params.amounts_b),
10793
+ tx.pure.address(params.receiver),
10794
+ tx.object(CLOCK_ADDRESS)
10795
+ ];
10796
+ tx.moveCall({
10797
+ target: `${integrate.published_at}::${DlmmScript}::raise_position_by_amounts`,
10798
+ typeArguments,
10799
+ arguments: args
10800
+ });
10801
+ return tx;
10802
+ }
10803
+ async _raisePositionByAmountsReward(params) {
10804
+ const tx = new import_transactions12.Transaction();
10805
+ tx.setSender(this.sdk.senderAddress);
10806
+ const { dlmm_pool, integrate, clmm_pool } = this.sdk.sdkOptions;
10807
+ const dlmmConfig = getPackagerConfigs(dlmm_pool);
10808
+ const clmmConfigs = getPackagerConfigs(clmm_pool);
10809
+ const typeArguments = [params.coin_a, params.coin_b, ...params.rewards_token];
10810
+ const allCoins = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress);
10811
+ const amountATotal = params.amounts_a.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
10812
+ const amountBTotal = params.amounts_b.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
10813
+ const primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amountATotal), params.coin_a, false, true);
10814
+ const primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amountBTotal), params.coin_b, false, true);
10815
+ const args = [
10816
+ tx.object(params.pool_id),
10817
+ tx.object(dlmmConfig.factory),
10818
+ tx.object(clmmConfigs.global_vault_id),
10819
+ tx.object(params.position_id),
10820
+ primaryCoinAInputs.targetCoin,
10821
+ primaryCoinBInputs.targetCoin,
10822
+ tx.pure.vector("u64", params.amounts_a),
10823
+ tx.pure.vector("u64", params.amounts_b),
10824
+ tx.pure.address(params.receiver),
10825
+ tx.object(CLOCK_ADDRESS)
10826
+ ];
10827
+ tx.moveCall({
10828
+ target: `${integrate.published_at}::${DlmmScript}::raise_position_by_amounts_reward${params.rewards_token.length}`,
10829
+ typeArguments,
10830
+ arguments: args
10831
+ });
10832
+ return tx;
10833
+ }
10834
+ async burnPosition(params) {
10835
+ const tx = new import_transactions12.Transaction();
10836
+ tx.setSender(this.sdk.senderAddress);
10837
+ const { integrate, clmm_pool } = this.sdk.sdkOptions;
10838
+ const clmmConfigs = getPackagerConfigs(clmm_pool);
10839
+ const typeArguments = [params.coin_a, params.coin_b, ...params.rewards_token];
10840
+ let args = [tx.object(params.pool_id), tx.object(params.position_id), tx.object(CLOCK_ADDRESS)];
10841
+ let target = `${integrate.published_at}::${DlmmScript}::burn_position`;
10842
+ if (params.rewards_token.length > 0) {
10843
+ args = [tx.object(params.pool_id), tx.object(clmmConfigs.global_vault_id), tx.object(params.position_id), tx.object(CLOCK_ADDRESS)];
10844
+ target = `${integrate.published_at}::${DlmmScript}::burn_position_reward${params.rewards_token.length}`;
10845
+ }
10846
+ tx.moveCall({
10847
+ target,
10848
+ typeArguments,
10849
+ arguments: args
10850
+ });
10851
+ return tx;
10852
+ }
10853
+ async shrinkPosition(params) {
10854
+ const tx = new import_transactions12.Transaction();
10855
+ tx.setSender(this.sdk.senderAddress);
10856
+ const { integrate, clmm_pool } = this.sdk.sdkOptions;
10857
+ const clmmConfigs = getPackagerConfigs(clmm_pool);
10858
+ const typeArguments = [params.coin_a, params.coin_b, ...params.rewards_token];
10859
+ let args = [tx.object(params.pool_id), tx.object(params.position_id), tx.pure.u64(params.delta_percentage), tx.object(CLOCK_ADDRESS)];
10860
+ let target = `${integrate.published_at}::${DlmmScript}::shrink_position`;
10861
+ if (params.rewards_token.length > 0) {
10862
+ args = [
10863
+ tx.object(params.pool_id),
10864
+ tx.object(clmmConfigs.global_vault_id),
10865
+ tx.object(params.position_id),
10866
+ tx.pure.u64(params.delta_percentage),
10867
+ tx.object(CLOCK_ADDRESS)
10868
+ ];
10869
+ target = `${integrate.published_at}::${DlmmScript}::shrink_position_reward${params.rewards_token.length}`;
10870
+ }
10871
+ tx.moveCall({
10872
+ target,
10873
+ typeArguments,
10874
+ arguments: args
10875
+ });
10876
+ return tx;
10877
+ }
10878
+ async collectFeeAndReward(params) {
10879
+ let tx = new import_transactions12.Transaction();
10880
+ tx = await this.collectFees(params);
10881
+ if (params.rewards_token.length > 0) {
10882
+ tx = await this.collectReward(params);
10883
+ }
10884
+ return tx;
10885
+ }
10886
+ async collectReward(params, transaction) {
10887
+ const tx = transaction || new import_transactions12.Transaction();
10888
+ tx.setSender(this.sdk.senderAddress);
10889
+ const { integrate, clmm_pool } = this.sdk.sdkOptions;
10890
+ const clmmConfigs = getPackagerConfigs(clmm_pool);
10891
+ const typeArguments = [params.coin_a, params.coin_b, ...params.rewards_token];
10892
+ const args = [
10893
+ tx.object(params.pool_id),
10894
+ tx.object(clmmConfigs.global_vault_id),
10895
+ tx.object(params.position_id),
10896
+ tx.object(CLOCK_ADDRESS)
10897
+ ];
10898
+ let target = `${integrate.published_at}::${DlmmScript}::collect_reward`;
10899
+ if (params.rewards_token.length > 1) {
10900
+ target = `${integrate.published_at}::${DlmmScript}::collect_reward${params.rewards_token.length}`;
10901
+ }
10902
+ tx.moveCall({
10903
+ target,
10904
+ typeArguments,
10905
+ arguments: args
10906
+ });
10907
+ return tx;
10908
+ }
10909
+ async collectFees(params, transaction) {
10910
+ const tx = transaction || new import_transactions12.Transaction();
10911
+ tx.setSender(this.sdk.senderAddress);
10912
+ const { integrate } = this.sdk.sdkOptions;
10913
+ const typeArguments = [params.coin_a, params.coin_b];
10914
+ const args = [tx.object(params.pool_id), tx.object(params.position_id), tx.object(CLOCK_ADDRESS)];
10915
+ const target = `${integrate.published_at}::${DlmmScript}::collect_fees`;
10916
+ tx.moveCall({
10917
+ target,
10918
+ typeArguments,
10919
+ arguments: args
10920
+ });
10921
+ return tx;
10922
+ }
10923
+ async createPairAddLiquidity(params) {
10924
+ const tx = new import_transactions12.Transaction();
10925
+ tx.setSender(this.sdk.senderAddress);
10926
+ const { clmm_pool, dlmm_pool, integrate } = this.sdk.sdkOptions;
10927
+ const { global_config_id } = getPackagerConfigs(clmm_pool);
10928
+ const dlmmConfig = getPackagerConfigs(dlmm_pool);
10929
+ const typeArguments = [params.coinTypeA, params.coinTypeB];
10930
+ const allCoins = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress);
10931
+ const amountATotal = params.amountsX.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
10932
+ const amountBTotal = params.amountsY.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
10933
+ const primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amountATotal), params.coinTypeA, false, true);
10934
+ const primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amountBTotal), params.coinTypeB, false, true);
10935
+ const storageIds = [];
10936
+ params.realIds.forEach((i) => {
10937
+ storageIds.push((0, import_calc_dlmm3.get_storage_id_from_real_id)(i));
10938
+ });
10939
+ const args = [
10940
+ tx.object(dlmmConfig.factory),
10941
+ tx.object(global_config_id),
10942
+ tx.pure.u64(params.baseFee),
10943
+ tx.pure.u16(params.binStep),
10944
+ tx.pure.u32((0, import_calc_dlmm3.get_storage_id_from_real_id)(params.activeId)),
10945
+ primaryCoinAInputs.targetCoin,
10946
+ primaryCoinBInputs.targetCoin,
10947
+ tx.pure.vector("u32", storageIds),
10948
+ tx.pure.vector("u64", params.amountsX),
10949
+ tx.pure.vector("u64", params.amountsY),
10950
+ tx.pure.address(params.to),
10951
+ tx.object(CLOCK_ADDRESS)
10952
+ ];
10953
+ const target = `${integrate.published_at}::${DlmmScript}::create_pair_add_liquidity`;
10954
+ tx.moveCall({
10955
+ target,
10956
+ typeArguments,
10957
+ arguments: args
10958
+ });
10959
+ return tx;
10960
+ }
10961
+ async swap(params) {
10962
+ const tx = new import_transactions12.Transaction();
10963
+ tx.setSender(this.sdk.senderAddress);
10964
+ const { clmm_pool, integrate } = this.sdk.sdkOptions;
10965
+ const { global_config_id } = getPackagerConfigs(clmm_pool);
10966
+ const typeArguments = [params.coinTypeA, params.coinTypeB];
10967
+ const allCoinAsset = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress);
10968
+ const primaryCoinInputA = TransactionUtil.buildCoinForAmount(
10969
+ tx,
10970
+ allCoinAsset,
10971
+ params.swapForY ? BigInt(params.amountIn) : BigInt(0),
10972
+ params.coinTypeA,
10973
+ false,
10974
+ true
10975
+ );
10976
+ const primaryCoinInputB = TransactionUtil.buildCoinForAmount(
10977
+ tx,
10978
+ allCoinAsset,
10979
+ params.swapForY ? BigInt(0) : BigInt(params.amountIn),
10980
+ params.coinTypeB,
10981
+ false,
10982
+ true
10983
+ );
10984
+ const args = [
10985
+ tx.object(params.pair),
10986
+ tx.object(global_config_id),
10987
+ primaryCoinInputA.targetCoin,
10988
+ primaryCoinInputB.targetCoin,
10989
+ tx.pure.u64(params.amountIn),
10990
+ tx.pure.u64(params.minAmountOut),
10991
+ tx.pure.bool(params.swapForY),
10992
+ tx.pure.address(params.to),
10993
+ tx.object(CLOCK_ADDRESS)
10994
+ ];
10995
+ tx.moveCall({
10996
+ target: `${integrate.published_at}::${DlmmScript}::swap`,
10997
+ typeArguments,
10998
+ arguments: args
10999
+ });
11000
+ return tx;
11001
+ }
11002
+ async fetchBins(params) {
11003
+ const tx = new import_transactions12.Transaction();
11004
+ const { integrate, simulationAccount } = this.sdk.sdkOptions;
11005
+ const typeArguments = [params.coinTypeA, params.coinTypeB];
11006
+ const args = [tx.object(params.pair), tx.pure.u64(params.offset), tx.pure.u64(params.limit)];
11007
+ tx.moveCall({
11008
+ target: `${integrate.published_at}::${DlmmScript}::fetch_bins`,
11009
+ arguments: args,
11010
+ typeArguments
11011
+ });
11012
+ const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
11013
+ transactionBlock: tx,
11014
+ sender: simulationAccount.address
11015
+ });
11016
+ if (simulateRes.error != null) {
11017
+ throw new Error(`fetchBins error code: ${simulateRes.error ?? "unknown error"}`);
11018
+ }
11019
+ let res = [];
11020
+ simulateRes.events?.forEach((item) => {
11021
+ if (extractStructTagFromType(item.type).name === `EventFetchBins`) {
11022
+ const { bins } = item.parsedJson;
11023
+ res = bins;
11024
+ }
11025
+ });
11026
+ return res;
11027
+ }
11028
+ /**
11029
+ * Gets a list of positions for the given account address.
11030
+ * @param accountAddress The account address to get positions for.
11031
+ * @param assignPoolIds An array of pool IDs to filter the positions by.
11032
+ * @returns array of Position objects.
11033
+ */
11034
+ async getUserPositionById(positionId, showDisplay = true) {
11035
+ let position;
11036
+ const ownerRes = await this._sdk.fullClient.getObject({
11037
+ id: positionId,
11038
+ options: { showContent: true, showType: true, showDisplay, showOwner: true }
11039
+ });
11040
+ const type = extractStructTagFromType(ownerRes.data.type);
11041
+ if (type.full_address === this.buildPositionType()) {
11042
+ position = this.buildPosition(ownerRes);
11043
+ } else {
11044
+ throw new ClmmpoolsError(`Dlmm Position not exists. Get Position error:${ownerRes.error}`, "InvalidPositionObject" /* InvalidPositionObject */);
11045
+ }
11046
+ const poolMap = /* @__PURE__ */ new Set();
11047
+ poolMap.add(position.pool);
11048
+ const pool = (await this.getPoolInfo(Array.from(poolMap)))[0];
11049
+ const _params = [];
11050
+ _params.push({
11051
+ pool_id: pool.pool_id,
11052
+ coin_a: pool.coin_a,
11053
+ coin_b: pool.coin_b
11054
+ });
11055
+ const pool_reward_coins = await this.getPairRewarders(_params);
11056
+ const positionLiquidity = await this.getPositionLiquidity({
11057
+ pair: position.pool,
11058
+ positionId: position.pos_object_id,
11059
+ coinTypeA: pool.coin_a,
11060
+ coinTypeB: pool.coin_b
11061
+ });
11062
+ const rewards_token = pool_reward_coins.get(position.pool) || [];
11063
+ let positionRewards = { position_id: position.pos_object_id, reward: [], amount: [] };
11064
+ if (rewards_token.length > 0) {
11065
+ positionRewards = await this.getEarnedRewards({
11066
+ pool_id: position.pool,
11067
+ position_id: position.pos_object_id,
11068
+ coin_a: pool.coin_a,
11069
+ coin_b: pool.coin_b,
11070
+ rewards_token: pool_reward_coins.get(position.pool) || []
11071
+ });
11072
+ }
11073
+ const positionFees = await this.getEarnedFees({
11074
+ pool_id: position.pool,
11075
+ position_id: position.pos_object_id,
11076
+ coin_a: pool.coin_a,
11077
+ coin_b: pool.coin_b
11078
+ });
11079
+ return {
11080
+ position,
11081
+ liquidity: positionLiquidity,
11082
+ rewards: positionRewards,
11083
+ fees: positionFees,
11084
+ contractPool: pool
11085
+ };
11086
+ }
11087
+ /**
11088
+ * Gets a list of positions for the given account address.
11089
+ * @param accountAddress The account address to get positions for.
11090
+ * @param assignPoolIds An array of pool IDs to filter the positions by.
11091
+ * @returns array of Position objects.
11092
+ */
11093
+ async getUserPositions(accountAddress, assignPoolIds = [], showDisplay = true) {
11094
+ const allPosition = [];
11095
+ const ownerRes = await this._sdk.fullClient.getOwnedObjectsByPage(accountAddress, {
11096
+ options: { showType: true, showContent: true, showDisplay, showOwner: true },
11097
+ filter: { Package: this._sdk.sdkOptions.dlmm_pool.package_id }
11098
+ });
11099
+ const hasAssignPoolIds = assignPoolIds.length > 0;
11100
+ for (const item of ownerRes.data) {
11101
+ const type = extractStructTagFromType(item.data.type);
11102
+ if (type.full_address === this.buildPositionType()) {
11103
+ const position = this.buildPosition(item);
11104
+ const cacheKey = `${position.pos_object_id}_getPositionList`;
11105
+ this.updateCache(cacheKey, position, cacheTime24h);
11106
+ if (hasAssignPoolIds) {
11107
+ if (assignPoolIds.includes(position.pool)) {
11108
+ allPosition.push(position);
11109
+ }
11110
+ } else {
11111
+ allPosition.push(position);
11112
+ }
11113
+ }
11114
+ }
11115
+ const poolMap = /* @__PURE__ */ new Set();
11116
+ for (const item of allPosition) {
11117
+ poolMap.add(item.pool);
11118
+ }
11119
+ const poolList = await this.getPoolInfo(Array.from(poolMap));
11120
+ this.updateCache(`${DlmmScript}_positionList_poolList`, poolList, cacheTime24h);
11121
+ const _params = [];
11122
+ for (const pool of poolList) {
11123
+ _params.push({
11124
+ pool_id: pool.pool_id,
11125
+ coin_a: pool.coin_a,
11126
+ coin_b: pool.coin_b
11127
+ });
11128
+ }
11129
+ const pool_reward_coins = await this.getPairRewarders(_params);
11130
+ const out = [];
11131
+ for (const item of allPosition) {
11132
+ const pool = poolList.find((pool2) => pool2.pool_id === item.pool);
11133
+ const positionLiquidity = await this.getPositionLiquidity({
11134
+ pair: item.pool,
11135
+ positionId: item.pos_object_id,
11136
+ coinTypeA: pool.coin_a,
11137
+ coinTypeB: pool.coin_b
11138
+ });
11139
+ const rewards_token = pool_reward_coins.get(item.pool) || [];
11140
+ let positionRewards = { position_id: item.pos_object_id, reward: [], amount: [] };
11141
+ if (rewards_token.length > 0) {
11142
+ positionRewards = await this.getEarnedRewards({
11143
+ pool_id: item.pool,
11144
+ position_id: item.pos_object_id,
11145
+ coin_a: pool.coin_a,
11146
+ coin_b: pool.coin_b,
11147
+ rewards_token: pool_reward_coins.get(item.pool) || []
11148
+ });
11149
+ }
11150
+ const positionFees = await this.getEarnedFees({
11151
+ pool_id: item.pool,
11152
+ position_id: item.pos_object_id,
11153
+ coin_a: pool.coin_a,
11154
+ coin_b: pool.coin_b
11155
+ });
11156
+ out.push({
11157
+ position: item,
11158
+ liquidity: positionLiquidity,
11159
+ rewards: positionRewards,
11160
+ fees: positionFees,
11161
+ contractPool: pool
11162
+ });
11163
+ }
11164
+ return out;
11165
+ }
11166
+ buildPosition(object) {
11167
+ if (object.error != null || object.data?.content?.dataType !== "moveObject") {
11168
+ throw new ClmmpoolsError(`Dlmm Position not exists. Get Position error:${object.error}`, "InvalidPositionObject" /* InvalidPositionObject */);
11169
+ }
11170
+ const fields = getObjectFields(object);
11171
+ const ownerWarp = getObjectOwner(object);
11172
+ return {
11173
+ pos_object_id: fields.id.id,
11174
+ owner: ownerWarp.AddressOwner,
11175
+ pool: fields.pair_id,
11176
+ bin_real_ids: fields.bin_ids.map((id) => (0, import_calc_dlmm3.get_real_id)(id)),
11177
+ type: ""
11178
+ };
11179
+ }
11180
+ // return [coin_a, coin_b]
11181
+ async getPoolCoins(pools) {
11182
+ const res = await this._sdk.fullClient.multiGetObjects({ ids: pools, options: { showContent: true } });
11183
+ const poolCoins = /* @__PURE__ */ new Map();
11184
+ res.forEach((item) => {
11185
+ if (item.error != null || item.data?.content?.dataType !== "moveObject") {
11186
+ throw new Error(`Failed to get poolCoins with err: ${item.error}`);
11187
+ }
11188
+ const type = getObjectType(item);
11189
+ const poolTypeFields = extractStructTagFromType(type);
11190
+ poolCoins.set(item.data.objectId, poolTypeFields.type_arguments);
11191
+ });
11192
+ return poolCoins;
11193
+ }
11194
+ buildPositionType() {
11195
+ return `${this._sdk.sdkOptions.dlmm_pool.package_id}::dlmm_position::Position`;
11196
+ }
11197
+ async getPositionLiquidity(params) {
11198
+ const tx = new import_transactions12.Transaction();
11199
+ const { integrate, simulationAccount } = this.sdk.sdkOptions;
11200
+ const typeArguments = [params.coinTypeA, params.coinTypeB];
11201
+ const args = [tx.object(params.pair), tx.object(params.positionId)];
11202
+ tx.moveCall({
11203
+ target: `${integrate.published_at}::${DlmmScript}::position_liquidity`,
11204
+ arguments: args,
11205
+ typeArguments
11206
+ });
11207
+ const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
11208
+ transactionBlock: tx,
11209
+ sender: simulationAccount.address
11210
+ });
11211
+ if (simulateRes.error != null) {
11212
+ throw new Error(`fetchBins error code: ${simulateRes.error ?? "unknown error"}`);
11213
+ }
11214
+ const out = {
11215
+ shares: 0,
11216
+ liquidity: 0,
11217
+ x_equivalent: 0,
11218
+ y_equivalent: 0,
11219
+ bin_real_ids: [],
11220
+ bin_x_eq: [],
11221
+ bin_y_eq: [],
11222
+ bin_liquidity: []
11223
+ };
11224
+ simulateRes.events?.forEach((item) => {
11225
+ if (extractStructTagFromType(item.type).name === `EventPositionLiquidity`) {
11226
+ out.shares = item.parsedJson.shares;
11227
+ out.liquidity = item.parsedJson.liquidity;
11228
+ out.x_equivalent = item.parsedJson.x_equivalent;
11229
+ out.y_equivalent = item.parsedJson.y_equivalent;
11230
+ out.bin_real_ids = item.parsedJson.bin_ids.map((id) => (0, import_calc_dlmm3.get_real_id)(id));
11231
+ out.bin_x_eq = item.parsedJson.bin_x_eq;
11232
+ out.bin_y_eq = item.parsedJson.bin_y_eq;
11233
+ out.bin_liquidity = item.parsedJson.bin_liquidity;
11234
+ }
11235
+ });
11236
+ return out;
11237
+ }
11238
+ async getPairLiquidity(params) {
11239
+ const tx = new import_transactions12.Transaction();
11240
+ const { integrate, simulationAccount } = this.sdk.sdkOptions;
11241
+ const typeArguments = [params.coinTypeA, params.coinTypeB];
11242
+ const args = [tx.object(params.pair)];
11243
+ tx.moveCall({
11244
+ target: `${integrate.published_at}::${DlmmScript}::pair_liquidity`,
11245
+ arguments: args,
11246
+ typeArguments
11247
+ });
11248
+ const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
11249
+ transactionBlock: tx,
11250
+ sender: simulationAccount.address
11251
+ });
11252
+ if (simulateRes.error != null) {
11253
+ throw new Error(`fetchBins error code: ${simulateRes.error ?? "unknown error"}`);
11254
+ }
11255
+ const out = {
11256
+ shares: 0,
11257
+ liquidity: 0,
11258
+ x: 0,
11259
+ y: 0,
11260
+ bin_ids: [],
11261
+ bin_x: [],
11262
+ bin_y: []
11263
+ };
11264
+ simulateRes.events?.forEach((item) => {
11265
+ if (extractStructTagFromType(item.type).name === `EventPositionLiquidity`) {
11266
+ out.shares = item.parsedJson.shares;
11267
+ out.liquidity = item.parsedJson.liquidity;
11268
+ out.x = item.parsedJson.x;
11269
+ out.y = item.parsedJson.y;
11270
+ out.bin_ids = item.bin_ids;
11271
+ out.bin_x = item.bin_x;
11272
+ out.bin_y = item.bin_y;
11273
+ }
11274
+ });
11275
+ return out;
11276
+ }
11277
+ async getEarnedFees(params) {
11278
+ const tx = new import_transactions12.Transaction();
11279
+ const { integrate, simulationAccount } = this.sdk.sdkOptions;
11280
+ const typeArguments = [params.coin_a, params.coin_b];
11281
+ const args = [tx.object(params.pool_id), tx.object(params.position_id)];
11282
+ tx.moveCall({
11283
+ target: `${integrate.published_at}::${DlmmScript}::earned_fees`,
11284
+ arguments: args,
11285
+ typeArguments
11286
+ });
11287
+ const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
11288
+ transactionBlock: tx,
11289
+ sender: simulationAccount.address
11290
+ });
11291
+ const out = {
11292
+ position_id: "",
11293
+ x: "",
11294
+ y: "",
11295
+ fee_x: 0,
11296
+ fee_y: 0
11297
+ };
11298
+ if (simulateRes.error != null) {
11299
+ throw new Error(`fetchPairRewards error code: ${simulateRes.error ?? "unknown error"}`);
11300
+ }
11301
+ simulateRes.events?.forEach((item) => {
11302
+ if (extractStructTagFromType(item.type).name === `EventPositionLiquidity`) {
11303
+ out.position_id = item.parsedJson.position_id;
11304
+ out.x = item.parsedJson.x;
11305
+ out.y = item.parsedJson.y;
11306
+ out.fee_x = item.parsedJson.fee_x;
11307
+ out.fee_y = item.parsedJson.fee_y;
11308
+ }
11309
+ });
11310
+ return out;
11311
+ }
11312
+ async getEarnedRewards(params) {
11313
+ const tx = new import_transactions12.Transaction();
11314
+ const { integrate, simulationAccount } = this.sdk.sdkOptions;
11315
+ const typeArguments = [params.coin_a, params.coin_b, ...params.rewards_token];
11316
+ const args = [tx.object(params.pool_id), tx.object(params.position_id), tx.object(CLOCK_ADDRESS)];
11317
+ let target = `${integrate.published_at}::${DlmmScript}::earned_rewards`;
11318
+ if (params.rewards_token.length > 1) {
11319
+ target = `${integrate.published_at}::${DlmmScript}::earned_rewards${params.rewards_token.length}`;
11320
+ }
11321
+ tx.moveCall({
11322
+ target,
11323
+ arguments: args,
11324
+ typeArguments
11325
+ });
11326
+ const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
11327
+ transactionBlock: tx,
11328
+ sender: simulationAccount.address
11329
+ });
11330
+ const out = {
11331
+ position_id: "",
11332
+ reward: [],
11333
+ amount: []
11334
+ };
11335
+ if (simulateRes.error != null) {
11336
+ throw new Error(`getEarnedRewards error code: ${simulateRes.error ?? "unknown error"}`);
11337
+ }
11338
+ simulateRes.events?.forEach((item) => {
11339
+ if (extractStructTagFromType(item.type).name === `DlmmEventEarnedRewards`) {
11340
+ out.position_id = item.parsedJson.position_id;
11341
+ out.reward = [item.parsedJson.reward];
11342
+ out.amount = [item.parsedJson.amount];
11343
+ } else if (extractStructTagFromType(item.type).name === `DlmmEventEarnedRewards2`) {
11344
+ out.position_id = item.parsedJson.position_id;
11345
+ out.reward = [item.parsedJson.reward1, item.parsedJson.reward2];
11346
+ out.amount = [item.parsedJson.amount1, item.parsedJson.amount2];
11347
+ } else if (extractStructTagFromType(item.type).name === `EventEarnedRewards3`) {
11348
+ out.position_id = item.parsedJson.position_id;
11349
+ out.reward = [item.parsedJson.reward1, item.parsedJson.reward2, item.parsedJson.reward3];
11350
+ out.amount = [item.parsedJson.amount1, item.parsedJson.amount2, item.parsedJson.amount3];
11351
+ }
11352
+ });
11353
+ return out;
11354
+ }
11355
+ // return pool_id => reward_tokens
11356
+ async getPairRewarders(params) {
11357
+ let tx = new import_transactions12.Transaction();
11358
+ for (const param of params) {
11359
+ tx = await this._getPairRewarders(param, tx);
11360
+ }
11361
+ return this._parsePairRewarders(tx);
11362
+ }
11363
+ async _getPairRewarders(params, tx) {
11364
+ tx = tx || new import_transactions12.Transaction();
11365
+ const { integrate } = this.sdk.sdkOptions;
11366
+ const typeArguments = [params.coin_a, params.coin_b];
11367
+ const args = [tx.object(params.pool_id)];
11368
+ tx.moveCall({
11369
+ target: `${integrate.published_at}::${DlmmScript}::get_pair_rewarders`,
11370
+ arguments: args,
11371
+ typeArguments
11372
+ });
11373
+ return tx;
11374
+ }
11375
+ async _parsePairRewarders(tx) {
11376
+ const { simulationAccount } = this.sdk.sdkOptions;
11377
+ const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
11378
+ transactionBlock: tx,
11379
+ sender: simulationAccount.address
11380
+ });
11381
+ const out = /* @__PURE__ */ new Map();
11382
+ if (simulateRes.error != null) {
11383
+ throw new Error(`fetchBins error code: ${simulateRes.error ?? "unknown error"}`);
11384
+ }
11385
+ simulateRes.events?.forEach((item) => {
11386
+ if (extractStructTagFromType(item.type).name === `EventPairRewardTypes`) {
11387
+ const pairRewards = {
11388
+ pair_id: "",
11389
+ tokens: []
11390
+ };
11391
+ pairRewards.pair_id = item.parsedJson.pair_id;
11392
+ item.parsedJson.tokens.forEach((token) => {
11393
+ pairRewards.tokens.push(token.name);
11394
+ });
11395
+ out.set(pairRewards.pair_id, pairRewards.tokens);
11396
+ }
11397
+ });
11398
+ return out;
11399
+ }
11400
+ /**
11401
+ * Updates the cache for the given key.
11402
+ *
11403
+ * @param key The key of the cache entry to update.
11404
+ * @param data The data to store in the cache.
11405
+ * @param time The time in minutes after which the cache entry should expire.
11406
+ */
11407
+ updateCache(key, data, time = cacheTime5min) {
11408
+ let cacheData = this._cache[key];
11409
+ if (cacheData) {
11410
+ cacheData.overdueTime = getFutureTime(time);
11411
+ cacheData.value = data;
11412
+ } else {
11413
+ cacheData = new CachedContent(data, getFutureTime(time));
11414
+ }
11415
+ this._cache[key] = cacheData;
11416
+ }
11417
+ /**
11418
+ * Gets the cache entry for the given key.
11419
+ *
11420
+ * @param key The key of the cache entry to get.
11421
+ * @param forceRefresh Whether to force a refresh of the cache entry.
11422
+ * @returns The cache entry for the given key, or undefined if the cache entry does not exist or is expired.
11423
+ */
11424
+ getCache(key, forceRefresh = false) {
11425
+ const cacheData = this._cache[key];
11426
+ const isValid = cacheData?.isValid();
11427
+ if (!forceRefresh && isValid) {
11428
+ return cacheData.value;
11429
+ }
11430
+ if (!isValid) {
11431
+ delete this._cache[key];
11432
+ }
11433
+ return void 0;
11434
+ }
11435
+ };
11436
+
11437
+ // src/sdk.ts
11438
+ var MagmaClmmSDK = class {
11439
+ _cache = {};
11440
+ /**
11441
+ * RPC provider on the SUI chain
11442
+ */
11443
+ _rpcModule;
11444
+ /**
11445
+ * Provide interact with clmm pools with a pool router interface.
11446
+ */
11447
+ _pool;
11448
+ /**
11449
+ * Provide interact with clmm position with a position router interface.
11450
+ */
11451
+ _position;
11452
+ /**
11453
+ * Provide interact with a pool swap router interface.
11454
+ */
11455
+ _swap;
11456
+ /**
11457
+ * Provide interact with a lock interface.
11458
+ */
11459
+ _lock;
11460
+ _gauge;
11461
+ _dlmm;
11462
+ /**
11463
+ * Provide interact with a position rewarder interface.
11464
+ */
11465
+ _rewarder;
11466
+ /**
11467
+ * Provide interact with a pool router interface.
11468
+ */
11469
+ _router;
11470
+ /**
11471
+ * Provide interact with a pool routerV2 interface.
11472
+ */
11473
+ _router_v2;
11474
+ /**
11475
+ * Provide interact with pool and token config (contain token base info for metadat).
11476
+ * @deprecated Please use MagmaConfig instead
11477
+ */
11478
+ _token;
11479
+ /**
11480
+ * Provide interact with clmm pool and coin and launchpad pool config
11481
+ */
11482
+ _config;
11483
+ /**
11484
+ * Provide sdk options
11485
+ */
11486
+ _sdkOptions;
11487
+ /**
11488
+ * After connecting the wallet, set the current wallet address to senderAddress.
11489
+ */
11490
+ _senderAddress = "";
11491
+ constructor(options) {
11492
+ this._sdkOptions = options;
11493
+ this._rpcModule = new RpcModule({
11494
+ url: options.fullRpcUrl
11495
+ });
11496
+ this._swap = new SwapModule(this);
10066
11497
  this._lock = new LockModule(this);
10067
11498
  this._gauge = new GaugeModule(this);
11499
+ this._dlmm = new DlmmModule(this);
10068
11500
  this._pool = new PoolModule(this);
10069
11501
  this._position = new PositionModule(this);
10070
11502
  this._rewarder = new RewarderModule(this);
@@ -10102,6 +11534,9 @@ var MagmaClmmSDK = class {
10102
11534
  get Gauge() {
10103
11535
  return this._gauge;
10104
11536
  }
11537
+ get Dlmm() {
11538
+ return this._dlmm;
11539
+ }
10105
11540
  /**
10106
11541
  * Getter for the fullClient property.
10107
11542
  * @returns {RpcModule} The fullClient property value.
@@ -10275,6 +11710,7 @@ var main_default = MagmaClmmSDK;
10275
11710
  var SDKConfig = {
10276
11711
  clmmConfig: {
10277
11712
  pools_id: "0xfa145b9de10fe858be81edd1c6cdffcf27be9d016de02a1345eb1009a68ba8b2",
11713
+ // clmm and dlmm both use this global_config
10278
11714
  global_config_id: "0x4c4e1402401f72c7d8533d0ed8d5f8949da363c7a3319ccef261ffe153d32f8a",
10279
11715
  global_vault_id: "0xa7e1102f222b6eb81ccc8a126e7feb2353342be9df6f6646a77c4519da29c071",
10280
11716
  admin_cap_id: "0x89c1a321291d15ddae5a086c9abc533dff697fde3d89e0ca836c41af73e36a75"
@@ -10294,7 +11730,11 @@ var SDKConfig = {
10294
11730
  distribution_cfg: "0xaff8d151ac29317201151f97d28c546b3c5923d8cfc5499f40dea61c4022c949",
10295
11731
  magma_token: "0x7161c6c6bb65f852797c8f7f5c4f8d57adaf796e1b840921f9e23fabeadfd54e::magma::MAGMA",
10296
11732
  minter_id: "0x4fa5766cd83b33b215b139fec27ac344040f3bbd84fcbee7b61fc671aadc51fa"
10297
- }
11733
+ },
11734
+ dlmmConfig: {
11735
+ factory: ""
11736
+ },
11737
+ gaugeConfig: {}
10298
11738
  };
10299
11739
  var clmmMainnet = {
10300
11740
  fullRpcUrl: (0, import_client2.getFullnodeUrl)("mainnet"),
@@ -10311,6 +11751,11 @@ var clmmMainnet = {
10311
11751
  published_at: "0x4a35d3dfef55ed3631b7158544c6322a23bc434fe4fca1234cb680ce0505f82d",
10312
11752
  config: SDKConfig.clmmConfig
10313
11753
  },
11754
+ dlmm_pool: {
11755
+ package_id: "",
11756
+ published_at: "",
11757
+ config: SDKConfig.dlmmConfig
11758
+ },
10314
11759
  distribution: {
10315
11760
  package_id: "0xee4a1f231dc45a303389998fe26c4e39278cf68b404b32e4f0b9769129b8267b",
10316
11761
  published_at: "0xee4a1f231dc45a303389998fe26c4e39278cf68b404b32e4f0b9769129b8267b"
@@ -10364,6 +11809,9 @@ var SDKConfig2 = {
10364
11809
  distribution_cfg: "0x94e23846c975e2faf89a61bfc2b10ad64decab9069eb1f9fc39752b010868c74",
10365
11810
  magma_token: "0x45ac2371c33ca0df8dc784d62c8ce5126d42edd8c56820396524dff2ae0619b1::magma_token::MAGMA_TOKEN",
10366
11811
  minter_id: "0x89435d6b2a510ba50ca23303f10e91ec058f138a88f69a43fe03cd22edb214c5"
11812
+ },
11813
+ dlmmConfig: {
11814
+ factory: ""
10367
11815
  }
10368
11816
  };
10369
11817
  var clmmTestnet = {
@@ -10378,6 +11826,11 @@ var clmmTestnet = {
10378
11826
  published_at: "0x23e0b5ab4aa63d0e6fd98fa5e247bcf9b36ad716b479d39e56b2ba9ff631e09d",
10379
11827
  config: SDKConfig2.clmmConfig
10380
11828
  },
11829
+ dlmm_pool: {
11830
+ package_id: "",
11831
+ published_at: "",
11832
+ config: SDKConfig2.dlmmConfig
11833
+ },
10381
11834
  distribution: {
10382
11835
  package_id: "0x45ac2371c33ca0df8dc784d62c8ce5126d42edd8c56820396524dff2ae0619b1",
10383
11836
  published_at: "0x45ac2371c33ca0df8dc784d62c8ce5126d42edd8c56820396524dff2ae0619b1"
@@ -10426,6 +11879,7 @@ var src_default = MagmaClmmSDK;
10426
11879
  0 && (module.exports = {
10427
11880
  AMM_SWAP_MODULE,
10428
11881
  AmountSpecified,
11882
+ BinMath,
10429
11883
  CLOCK_ADDRESS,
10430
11884
  CachedContent,
10431
11885
  ClmmExpectSwapModule,
@@ -10453,6 +11907,7 @@ var src_default = MagmaClmmSDK;
10453
11907
  DeepbookCustodianV2Moudle,
10454
11908
  DeepbookEndpointsV2Moudle,
10455
11909
  DeepbookUtils,
11910
+ DlmmScript,
10456
11911
  FEE_RATE_DENOMINATOR,
10457
11912
  GAS_SYMBOL,
10458
11913
  GAS_TYPE_ARG,
@@ -10480,6 +11935,7 @@ var src_default = MagmaClmmSDK;
10480
11935
  SUI_SYSTEM_STATE_OBJECT_ID,
10481
11936
  SplitSwap,
10482
11937
  SplitUnit,
11938
+ StrategyType,
10483
11939
  SwapDirection,
10484
11940
  SwapModule,
10485
11941
  SwapUtils,
@@ -10501,6 +11957,10 @@ var src_default = MagmaClmmSDK;
10501
11957
  adjustForSlippage,
10502
11958
  asIntN,
10503
11959
  asUintN,
11960
+ autoFillXByStrategy,
11961
+ autoFillXByWeight,
11962
+ autoFillYByStrategy,
11963
+ autoFillYByWeight,
10504
11964
  bufferToHex,
10505
11965
  buildClmmPositionName,
10506
11966
  buildNFT,
@@ -10538,12 +11998,14 @@ var src_default = MagmaClmmSDK;
10538
11998
  getAmountUnfixedDelta,
10539
11999
  getCoinAFromLiquidity,
10540
12000
  getCoinBFromLiquidity,
12001
+ getCoinXYForLiquidity,
10541
12002
  getDefaultSuiInputType,
10542
12003
  getDeltaA,
10543
12004
  getDeltaB,
10544
12005
  getDeltaDownFromOutput,
10545
12006
  getDeltaUpFromInput,
10546
12007
  getFutureTime,
12008
+ getLiquidityAndCoinYByCoinX,
10547
12009
  getLiquidityFromCoinA,
10548
12010
  getLiquidityFromCoinB,
10549
12011
  getLowerSqrtPriceFromCoinA,
@@ -10567,6 +12029,7 @@ var src_default = MagmaClmmSDK;
10567
12029
  getObjectType,
10568
12030
  getObjectVersion,
10569
12031
  getPackagerConfigs,
12032
+ getPriceOfBinByBinId,
10570
12033
  getRewardInTickRange,
10571
12034
  getSuiObjectData,
10572
12035
  getTickDataFromUrlData,
@@ -10590,10 +12053,15 @@ var src_default = MagmaClmmSDK;
10590
12053
  shortAddress,
10591
12054
  shortString,
10592
12055
  tickScore,
12056
+ toAmountAskSide,
12057
+ toAmountBidSide,
12058
+ toAmountBothSide,
12059
+ toAmountsBothSideByStrategy,
10593
12060
  toBuffer,
10594
12061
  toCoinAmount,
10595
12062
  toDecimalsAmount,
10596
12063
  transClmmpoolDataWithoutTicks,
10597
- utf8to16
12064
+ utf8to16,
12065
+ withLiquiditySlippage
10598
12066
  });
10599
12067
  //# sourceMappingURL=index.js.map