@magmaprotocol/magma-clmm-sdk 0.5.77 → 0.5.78
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/README.md +10 -6
- package/dist/index.d.ts +428 -2
- package/dist/index.js +1660 -200
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1648 -198
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -1
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
|
|
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,476 @@ function collectFeesQuote(param) {
|
|
|
1796
1812
|
return updateFees(param.position, fee_growth_inside_a, fee_growth_inside_b);
|
|
1797
1813
|
}
|
|
1798
1814
|
|
|
1799
|
-
// src/math/
|
|
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) {
|
|
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) {
|
|
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 toWeightSpotBalanced(minBinId, maxBinId) {
|
|
2104
|
+
const distributions = [];
|
|
2105
|
+
for (let i = minBinId; i <= maxBinId; i++) {
|
|
2106
|
+
distributions.push({
|
|
2107
|
+
binId: i,
|
|
2108
|
+
weight: 1
|
|
2109
|
+
});
|
|
2110
|
+
}
|
|
2111
|
+
return distributions;
|
|
2112
|
+
}
|
|
2113
|
+
var DEFAULT_MAX_WEIGHT = 2e3;
|
|
2114
|
+
var DEFAULT_MIN_WEIGHT = 200;
|
|
2115
|
+
function toWeightCurve(minBinId, maxBinId, activeId) {
|
|
2116
|
+
if (activeId < minBinId || activeId > maxBinId) {
|
|
2117
|
+
throw new ClmmpoolsError("Invalid strategy params", "InvalidParams" /* InvalidParams */);
|
|
2118
|
+
}
|
|
2119
|
+
const maxWeight = DEFAULT_MAX_WEIGHT;
|
|
2120
|
+
const minWeight = DEFAULT_MIN_WEIGHT;
|
|
2121
|
+
const diffWeight = maxWeight - minWeight;
|
|
2122
|
+
const diffMinWeight = activeId > minBinId ? Math.floor(diffWeight / (activeId - minBinId)) : 0;
|
|
2123
|
+
const diffMaxWeight = maxBinId > activeId ? Math.floor(diffWeight / (maxBinId - activeId)) : 0;
|
|
2124
|
+
const distributions = [];
|
|
2125
|
+
for (let i = minBinId; i <= maxBinId; i++) {
|
|
2126
|
+
if (i < activeId) {
|
|
2127
|
+
distributions.push({
|
|
2128
|
+
binId: i,
|
|
2129
|
+
weight: maxWeight - (activeId - i) * diffMinWeight
|
|
2130
|
+
});
|
|
2131
|
+
} else if (i > activeId) {
|
|
2132
|
+
distributions.push({
|
|
2133
|
+
binId: i,
|
|
2134
|
+
weight: maxWeight - (i - activeId) * diffMaxWeight
|
|
2135
|
+
});
|
|
2136
|
+
} else {
|
|
2137
|
+
distributions.push({
|
|
2138
|
+
binId: i,
|
|
2139
|
+
weight: maxWeight
|
|
2140
|
+
});
|
|
2141
|
+
}
|
|
2142
|
+
}
|
|
2143
|
+
return distributions;
|
|
2144
|
+
}
|
|
2145
|
+
function toWeightBidAsk(minBinId, maxBinId, activeId) {
|
|
2146
|
+
if (activeId < minBinId || activeId > maxBinId) {
|
|
2147
|
+
throw new ClmmpoolsError("Invalid strategy params", "InvalidParams" /* InvalidParams */);
|
|
2148
|
+
}
|
|
2149
|
+
const maxWeight = DEFAULT_MAX_WEIGHT;
|
|
2150
|
+
const minWeight = DEFAULT_MIN_WEIGHT;
|
|
2151
|
+
const diffWeight = maxWeight - minWeight;
|
|
2152
|
+
const diffMinWeight = activeId > minBinId ? Math.floor(diffWeight / (activeId - minBinId)) : 0;
|
|
2153
|
+
const diffMaxWeight = maxBinId > activeId ? Math.floor(diffWeight / (maxBinId - activeId)) : 0;
|
|
2154
|
+
const distributions = [];
|
|
2155
|
+
for (let i = minBinId; i <= maxBinId; i++) {
|
|
2156
|
+
if (i < activeId) {
|
|
2157
|
+
distributions.push({
|
|
2158
|
+
binId: i,
|
|
2159
|
+
weight: minWeight + (activeId - i) * diffMinWeight
|
|
2160
|
+
});
|
|
2161
|
+
} else if (i > activeId) {
|
|
2162
|
+
distributions.push({
|
|
2163
|
+
binId: i,
|
|
2164
|
+
weight: minWeight + (i - activeId) * diffMaxWeight
|
|
2165
|
+
});
|
|
2166
|
+
} else {
|
|
2167
|
+
distributions.push({
|
|
2168
|
+
binId: i,
|
|
2169
|
+
weight: minWeight
|
|
2170
|
+
});
|
|
2171
|
+
}
|
|
2172
|
+
}
|
|
2173
|
+
return distributions;
|
|
2174
|
+
}
|
|
2175
|
+
function autoFillYByStrategy(activeId, binStep, amountX, amountXInActiveBin, amountYInActiveBin, minBinId, maxBinId, strategyType) {
|
|
2176
|
+
switch (strategyType) {
|
|
2177
|
+
case 1 /* Spot */: {
|
|
2178
|
+
const weights = toWeightSpotBalanced(minBinId, maxBinId);
|
|
2179
|
+
return autoFillYByWeight(activeId, binStep, amountX, amountXInActiveBin, amountYInActiveBin, weights);
|
|
2180
|
+
}
|
|
2181
|
+
case 2 /* Curve */: {
|
|
2182
|
+
const weights = toWeightCurve(minBinId, maxBinId, activeId);
|
|
2183
|
+
return autoFillYByWeight(activeId, binStep, amountX, amountXInActiveBin, amountYInActiveBin, weights);
|
|
2184
|
+
}
|
|
2185
|
+
case 3 /* BidAsk */: {
|
|
2186
|
+
const weights = toWeightBidAsk(minBinId, maxBinId, activeId);
|
|
2187
|
+
return autoFillYByWeight(activeId, binStep, amountX, amountXInActiveBin, amountYInActiveBin, weights);
|
|
2188
|
+
}
|
|
2189
|
+
default:
|
|
2190
|
+
throw new Error(`Unsupported strategy type: ${strategyType}`);
|
|
2191
|
+
}
|
|
2192
|
+
}
|
|
2193
|
+
function autoFillXByStrategy(activeId, binStep, amountY, amountXInActiveBin, amountYInActiveBin, minBinId, maxBinId, strategyType) {
|
|
2194
|
+
switch (strategyType) {
|
|
2195
|
+
case 1 /* Spot */: {
|
|
2196
|
+
const weights = toWeightSpotBalanced(minBinId, maxBinId);
|
|
2197
|
+
return autoFillXByWeight(activeId, binStep, amountY, amountXInActiveBin, amountYInActiveBin, weights);
|
|
2198
|
+
}
|
|
2199
|
+
case 2 /* Curve */: {
|
|
2200
|
+
const weights = toWeightCurve(minBinId, maxBinId, activeId);
|
|
2201
|
+
return autoFillXByWeight(activeId, binStep, amountY, amountXInActiveBin, amountYInActiveBin, weights);
|
|
2202
|
+
}
|
|
2203
|
+
case 3 /* BidAsk */: {
|
|
2204
|
+
const weights = toWeightBidAsk(minBinId, maxBinId, activeId);
|
|
2205
|
+
return autoFillXByWeight(activeId, binStep, amountY, amountXInActiveBin, amountYInActiveBin, weights);
|
|
2206
|
+
}
|
|
2207
|
+
default:
|
|
2208
|
+
throw new Error(`Unsupported strategy type: ${strategyType}`);
|
|
2209
|
+
}
|
|
2210
|
+
}
|
|
2211
|
+
function toAmountsBothSideByStrategy(activeId, binStep, minBinId, maxBinId, amountX, amountY, amountXInActiveBin, amountYInActiveBin, strategyType) {
|
|
2212
|
+
const isSingleSideX = amountY.isZero();
|
|
2213
|
+
switch (strategyType) {
|
|
2214
|
+
case 1 /* Spot */: {
|
|
2215
|
+
const weights = toWeightSpotBalanced(minBinId, maxBinId);
|
|
2216
|
+
return toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights);
|
|
2217
|
+
}
|
|
2218
|
+
case 2 /* Curve */: {
|
|
2219
|
+
const weights = toWeightCurve(minBinId, maxBinId, activeId);
|
|
2220
|
+
return toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights);
|
|
2221
|
+
}
|
|
2222
|
+
case 3 /* BidAsk */: {
|
|
2223
|
+
const weights = toWeightBidAsk(minBinId, maxBinId, activeId);
|
|
2224
|
+
return toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights);
|
|
2225
|
+
}
|
|
2226
|
+
default:
|
|
2227
|
+
throw new Error(`Unsupported strategy type: ${strategyType}`);
|
|
2228
|
+
}
|
|
2229
|
+
}
|
|
2230
|
+
|
|
2231
|
+
// src/math/LiquidityHelper.ts
|
|
2232
|
+
var import_decimal8 = __toESM(require("decimal.js"));
|
|
2233
|
+
|
|
2234
|
+
// src/utils/numbers.ts
|
|
2235
|
+
var import_decimal7 = __toESM(require("decimal.js"));
|
|
2236
|
+
function d(value) {
|
|
2237
|
+
if (import_decimal7.default.isDecimal(value)) {
|
|
2238
|
+
return value;
|
|
2239
|
+
}
|
|
2240
|
+
return new import_decimal7.default(value === void 0 ? 0 : value);
|
|
2241
|
+
}
|
|
2242
|
+
function decimalsMultiplier(decimals) {
|
|
2243
|
+
return d(10).pow(d(decimals).abs());
|
|
2244
|
+
}
|
|
2245
|
+
|
|
2246
|
+
// src/math/LiquidityHelper.ts
|
|
2247
|
+
function withLiquiditySlippage(value, slippage, mode) {
|
|
2248
|
+
return d(value)[mode](d(value).mul(slippage)).toDP(0);
|
|
2249
|
+
}
|
|
2250
|
+
function getLiquidityAndCoinYByCoinX(coinInVal, reserveInSize, reserveOutSize, lpSupply) {
|
|
2251
|
+
if (coinInVal.lessThanOrEqualTo(0)) {
|
|
2252
|
+
throw new ClmmpoolsError("coinInVal is less than zero", "InvalidCoinAmount" /* InvalidCoinAmount */);
|
|
2253
|
+
}
|
|
2254
|
+
if (reserveInSize.lessThanOrEqualTo(0) || reserveOutSize.lessThanOrEqualTo(0)) {
|
|
2255
|
+
return -1;
|
|
2256
|
+
}
|
|
2257
|
+
const coinYAmount = coinInVal.mul(reserveOutSize).div(reserveInSize);
|
|
2258
|
+
const sqrtSupply = lpSupply;
|
|
2259
|
+
const lpX = coinInVal.div(reserveInSize).mul(sqrtSupply);
|
|
2260
|
+
const lpY = coinYAmount.div(reserveOutSize).mul(sqrtSupply);
|
|
2261
|
+
const lpAmount = import_decimal8.default.min(lpX, lpY);
|
|
2262
|
+
return {
|
|
2263
|
+
coinYAmount,
|
|
2264
|
+
lpAmount
|
|
2265
|
+
};
|
|
2266
|
+
}
|
|
2267
|
+
function getCoinXYForLiquidity(liquidity, reserveInSize, reserveOutSize, lpSuply) {
|
|
2268
|
+
if (liquidity.lessThanOrEqualTo(0)) {
|
|
2269
|
+
throw new ClmmpoolsError("liquidity can't be equal or less than zero", "InvalidLiquidityAmount" /* InvalidLiquidityAmount */);
|
|
2270
|
+
}
|
|
2271
|
+
if (reserveInSize.lessThanOrEqualTo(0) || reserveOutSize.lessThanOrEqualTo(0)) {
|
|
2272
|
+
throw new ClmmpoolsError("reserveInSize or reserveOutSize can not be equal or less than zero", "InvalidReserveAmount" /* InvalidReserveAmount */);
|
|
2273
|
+
}
|
|
2274
|
+
const sqrtSupply = lpSuply;
|
|
2275
|
+
const coinXAmount = liquidity.div(sqrtSupply).mul(reserveInSize);
|
|
2276
|
+
const coinYAmount = liquidity.div(sqrtSupply).mul(reserveOutSize);
|
|
2277
|
+
return {
|
|
2278
|
+
coinXAmount,
|
|
2279
|
+
coinYAmount
|
|
2280
|
+
};
|
|
2281
|
+
}
|
|
2282
|
+
|
|
2283
|
+
// src/math/percentage.ts
|
|
2284
|
+
var import_bn10 = __toESM(require("bn.js"));
|
|
1801
2285
|
var Percentage = class {
|
|
1802
2286
|
numerator;
|
|
1803
2287
|
denominator;
|
|
@@ -1825,8 +2309,8 @@ var Percentage = class {
|
|
|
1825
2309
|
* @returns
|
|
1826
2310
|
*/
|
|
1827
2311
|
static fromFraction(numerator, denominator) {
|
|
1828
|
-
const num = typeof numerator === "number" ? new
|
|
1829
|
-
const denom = typeof denominator === "number" ? new
|
|
2312
|
+
const num = typeof numerator === "number" ? new import_bn10.default(numerator.toString()) : numerator;
|
|
2313
|
+
const denom = typeof denominator === "number" ? new import_bn10.default(denominator.toString()) : denominator;
|
|
1830
2314
|
return new Percentage(num, denom);
|
|
1831
2315
|
}
|
|
1832
2316
|
};
|
|
@@ -1926,7 +2410,7 @@ function adjustForCoinSlippage(tokenAmount, slippage, adjustUp) {
|
|
|
1926
2410
|
}
|
|
1927
2411
|
|
|
1928
2412
|
// src/math/SplitSwap.ts
|
|
1929
|
-
var
|
|
2413
|
+
var import_bn11 = __toESM(require("bn.js"));
|
|
1930
2414
|
var SplitUnit = /* @__PURE__ */ ((SplitUnit2) => {
|
|
1931
2415
|
SplitUnit2[SplitUnit2["FIVE"] = 5] = "FIVE";
|
|
1932
2416
|
SplitUnit2[SplitUnit2["TEN"] = 10] = "TEN";
|
|
@@ -1984,7 +2468,7 @@ function updateSplitSwapResult(maxIndex, currentIndex, splitSwapResult, stepResu
|
|
|
1984
2468
|
return splitSwapResult;
|
|
1985
2469
|
}
|
|
1986
2470
|
function computeSplitSwap(a2b, byAmountIn, amounts, poolData, swapTicks) {
|
|
1987
|
-
let currentLiquidity = new
|
|
2471
|
+
let currentLiquidity = new import_bn11.default(poolData.liquidity);
|
|
1988
2472
|
let { currentSqrtPrice } = poolData;
|
|
1989
2473
|
let splitSwapResult = {
|
|
1990
2474
|
amountInArray: [],
|
|
@@ -2047,7 +2531,7 @@ function computeSplitSwap(a2b, byAmountIn, amounts, poolData, swapTicks) {
|
|
|
2047
2531
|
targetSqrtPrice,
|
|
2048
2532
|
currentLiquidity,
|
|
2049
2533
|
remainerAmount,
|
|
2050
|
-
new
|
|
2534
|
+
new import_bn11.default(poolData.feeRate),
|
|
2051
2535
|
byAmountIn
|
|
2052
2536
|
);
|
|
2053
2537
|
tempStepResult = stepResult;
|
|
@@ -2059,7 +2543,7 @@ function computeSplitSwap(a2b, byAmountIn, amounts, poolData, swapTicks) {
|
|
|
2059
2543
|
splitSwapResult.amountOutArray[i] = splitSwapResult.amountOutArray[i].add(stepResult.amountOut);
|
|
2060
2544
|
splitSwapResult.feeAmountArray[i] = splitSwapResult.feeAmountArray[i].add(stepResult.feeAmount);
|
|
2061
2545
|
if (stepResult.nextSqrtPrice.eq(tick.sqrtPrice)) {
|
|
2062
|
-
signedLiquidityChange = a2b ? tick.liquidityNet.mul(new
|
|
2546
|
+
signedLiquidityChange = a2b ? tick.liquidityNet.mul(new import_bn11.default(-1)) : tick.liquidityNet;
|
|
2063
2547
|
currentLiquidity = signedLiquidityChange.gt(ZERO) ? currentLiquidity.add(signedLiquidityChange) : currentLiquidity.sub(signedLiquidityChange.abs());
|
|
2064
2548
|
currentSqrtPrice = tick.sqrtPrice;
|
|
2065
2549
|
} else {
|
|
@@ -2084,7 +2568,7 @@ function computeSplitSwap(a2b, byAmountIn, amounts, poolData, swapTicks) {
|
|
|
2084
2568
|
break;
|
|
2085
2569
|
}
|
|
2086
2570
|
if (tempStepResult.nextSqrtPrice.eq(tick.sqrtPrice)) {
|
|
2087
|
-
signedLiquidityChange = a2b ? tick.liquidityNet.mul(new
|
|
2571
|
+
signedLiquidityChange = a2b ? tick.liquidityNet.mul(new import_bn11.default(-1)) : tick.liquidityNet;
|
|
2088
2572
|
currentLiquidity = signedLiquidityChange.gt(ZERO) ? currentLiquidity.add(signedLiquidityChange) : currentLiquidity.sub(signedLiquidityChange.abs());
|
|
2089
2573
|
currentSqrtPrice = tick.sqrtPrice;
|
|
2090
2574
|
} else {
|
|
@@ -2139,17 +2623,22 @@ var SplitSwap = class {
|
|
|
2139
2623
|
}
|
|
2140
2624
|
};
|
|
2141
2625
|
|
|
2142
|
-
// src/
|
|
2143
|
-
var
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2626
|
+
// src/math/bin.ts
|
|
2627
|
+
var import_decimal9 = __toESM(require("decimal.js"));
|
|
2628
|
+
var import_calc_dlmm2 = require("@magmaprotocol/calc_dlmm");
|
|
2629
|
+
var BinMath = class {
|
|
2630
|
+
static getPriceOfBinByBinId(binId, binStep, decimalsA, decimalsB) {
|
|
2631
|
+
const twoDec = new import_decimal9.default(2);
|
|
2632
|
+
const price = new import_decimal9.default((0, import_calc_dlmm2.get_price_x128_from_real_id)(binId, binStep));
|
|
2633
|
+
return price.div(twoDec.pow(128)).mul(import_decimal9.default.pow(10, decimalsA - decimalsB));
|
|
2634
|
+
}
|
|
2635
|
+
static getBinIdFromPrice(price, binStep, decimalsA, decimalsB) {
|
|
2636
|
+
const twoDec = new import_decimal9.default(2);
|
|
2637
|
+
const tenDec = new import_decimal9.default(10);
|
|
2638
|
+
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);
|
|
2639
|
+
return realid;
|
|
2147
2640
|
}
|
|
2148
|
-
|
|
2149
|
-
}
|
|
2150
|
-
function decimalsMultiplier(decimals) {
|
|
2151
|
-
return d(10).pow(d(decimals).abs());
|
|
2152
|
-
}
|
|
2641
|
+
};
|
|
2153
2642
|
|
|
2154
2643
|
// src/utils/objects.ts
|
|
2155
2644
|
function getSuiObjectData(resp) {
|
|
@@ -2304,7 +2793,7 @@ function buildPool(objects) {
|
|
|
2304
2793
|
const rewarders = [];
|
|
2305
2794
|
fields.rewarder_manager.fields.rewarders.forEach((item) => {
|
|
2306
2795
|
const { emissions_per_second } = item.fields;
|
|
2307
|
-
const emissionSeconds = MathUtil.fromX64(new
|
|
2796
|
+
const emissionSeconds = MathUtil.fromX64(new import_bn12.default(emissions_per_second));
|
|
2308
2797
|
const emissionsEveryDay = Math.floor(emissionSeconds.toNumber() * 60 * 60 * 24);
|
|
2309
2798
|
rewarders.push({
|
|
2310
2799
|
emissions_per_second,
|
|
@@ -2496,11 +2985,11 @@ function buildTickData(objects) {
|
|
|
2496
2985
|
const possition = {
|
|
2497
2986
|
objectId: getObjectId(objects),
|
|
2498
2987
|
index: asIntN(BigInt(valueItem.index.fields.bits)),
|
|
2499
|
-
sqrtPrice: new
|
|
2500
|
-
liquidityNet: new
|
|
2501
|
-
liquidityGross: new
|
|
2502
|
-
feeGrowthOutsideA: new
|
|
2503
|
-
feeGrowthOutsideB: new
|
|
2988
|
+
sqrtPrice: new import_bn12.default(valueItem.sqrt_price),
|
|
2989
|
+
liquidityNet: new import_bn12.default(valueItem.liquidity_net.fields.bits),
|
|
2990
|
+
liquidityGross: new import_bn12.default(valueItem.liquidity_gross),
|
|
2991
|
+
feeGrowthOutsideA: new import_bn12.default(valueItem.fee_growth_outside_a),
|
|
2992
|
+
feeGrowthOutsideB: new import_bn12.default(valueItem.fee_growth_outside_b),
|
|
2504
2993
|
rewardersGrowthOutside: valueItem.rewards_growth_outside
|
|
2505
2994
|
};
|
|
2506
2995
|
return possition;
|
|
@@ -2510,11 +2999,11 @@ function buildTickDataByEvent(fields) {
|
|
|
2510
2999
|
throw new ClmmpoolsError(`Invalid tick fields.`, "InvalidTickFields" /* InvalidTickFields */);
|
|
2511
3000
|
}
|
|
2512
3001
|
const index = asIntN(BigInt(fields.index.bits));
|
|
2513
|
-
const sqrtPrice = new
|
|
2514
|
-
const liquidityNet = new
|
|
2515
|
-
const liquidityGross = new
|
|
2516
|
-
const feeGrowthOutsideA = new
|
|
2517
|
-
const feeGrowthOutsideB = new
|
|
3002
|
+
const sqrtPrice = new import_bn12.default(fields.sqrt_price);
|
|
3003
|
+
const liquidityNet = new import_bn12.default(fields.liquidity_net.bits);
|
|
3004
|
+
const liquidityGross = new import_bn12.default(fields.liquidity_gross);
|
|
3005
|
+
const feeGrowthOutsideA = new import_bn12.default(fields.fee_growth_outside_a);
|
|
3006
|
+
const feeGrowthOutsideB = new import_bn12.default(fields.fee_growth_outside_b);
|
|
2518
3007
|
const rewardersGrowthOutside = fields.rewards_growth_outside || [];
|
|
2519
3008
|
const tick = {
|
|
2520
3009
|
objectId: "",
|
|
@@ -2533,7 +3022,7 @@ function buildClmmPositionName(pool_index, position_index) {
|
|
|
2533
3022
|
}
|
|
2534
3023
|
|
|
2535
3024
|
// src/utils/tick.ts
|
|
2536
|
-
var
|
|
3025
|
+
var import_bn13 = __toESM(require("bn.js"));
|
|
2537
3026
|
var TickUtil = class {
|
|
2538
3027
|
/**
|
|
2539
3028
|
* Get min tick index.
|
|
@@ -2573,22 +3062,22 @@ function getRewardInTickRange(pool, tickLower, tickUpper, tickLowerIndex, tickUp
|
|
|
2573
3062
|
let rewarder_growth_below = growthGlobal[i];
|
|
2574
3063
|
if (tickLower !== null) {
|
|
2575
3064
|
if (pool.current_tick_index < tickLowerIndex) {
|
|
2576
|
-
rewarder_growth_below = growthGlobal[i].sub(new
|
|
3065
|
+
rewarder_growth_below = growthGlobal[i].sub(new import_bn13.default(tickLower.rewardersGrowthOutside[i]));
|
|
2577
3066
|
} else {
|
|
2578
3067
|
rewarder_growth_below = tickLower.rewardersGrowthOutside[i];
|
|
2579
3068
|
}
|
|
2580
3069
|
}
|
|
2581
|
-
let rewarder_growth_above = new
|
|
3070
|
+
let rewarder_growth_above = new import_bn13.default(0);
|
|
2582
3071
|
if (tickUpper !== null) {
|
|
2583
3072
|
if (pool.current_tick_index >= tickUpperIndex) {
|
|
2584
|
-
rewarder_growth_above = growthGlobal[i].sub(new
|
|
3073
|
+
rewarder_growth_above = growthGlobal[i].sub(new import_bn13.default(tickUpper.rewardersGrowthOutside[i]));
|
|
2585
3074
|
} else {
|
|
2586
3075
|
rewarder_growth_above = tickUpper.rewardersGrowthOutside[i];
|
|
2587
3076
|
}
|
|
2588
3077
|
}
|
|
2589
3078
|
const rewGrowthInside = MathUtil.subUnderflowU128(
|
|
2590
|
-
MathUtil.subUnderflowU128(new
|
|
2591
|
-
new
|
|
3079
|
+
MathUtil.subUnderflowU128(new import_bn13.default(growthGlobal[i]), new import_bn13.default(rewarder_growth_below)),
|
|
3080
|
+
new import_bn13.default(rewarder_growth_above)
|
|
2592
3081
|
);
|
|
2593
3082
|
rewarderGrowthInside.push(rewGrowthInside);
|
|
2594
3083
|
}
|
|
@@ -2596,8 +3085,8 @@ function getRewardInTickRange(pool, tickLower, tickUpper, tickLowerIndex, tickUp
|
|
|
2596
3085
|
}
|
|
2597
3086
|
|
|
2598
3087
|
// src/utils/transaction-util.ts
|
|
2599
|
-
var
|
|
2600
|
-
var
|
|
3088
|
+
var import_bn14 = __toESM(require("bn.js"));
|
|
3089
|
+
var import_decimal10 = __toESM(require("decimal.js"));
|
|
2601
3090
|
var import_transactions = require("@mysten/sui/transactions");
|
|
2602
3091
|
function findAdjustCoin(coinPair) {
|
|
2603
3092
|
const isAdjustCoinA = CoinAssist.isSuiCoin(coinPair.coinTypeA);
|
|
@@ -2605,7 +3094,7 @@ function findAdjustCoin(coinPair) {
|
|
|
2605
3094
|
return { isAdjustCoinA, isAdjustCoinB };
|
|
2606
3095
|
}
|
|
2607
3096
|
function reverSlippageAmount(slippageAmount, slippage) {
|
|
2608
|
-
return
|
|
3097
|
+
return import_decimal10.default.ceil(d(slippageAmount).div(1 + slippage)).toString();
|
|
2609
3098
|
}
|
|
2610
3099
|
async function printTransaction(tx, isPrint = true) {
|
|
2611
3100
|
console.log(`inputs`, tx.blockData.inputs);
|
|
@@ -2905,7 +3394,7 @@ var _TransactionUtil = class {
|
|
|
2905
3394
|
const liquidityInput = ClmmPoolUtil.estLiquidityAndcoinAmountFromOneAmounts(
|
|
2906
3395
|
Number(params.tick_lower),
|
|
2907
3396
|
Number(params.tick_upper),
|
|
2908
|
-
new
|
|
3397
|
+
new import_bn14.default(coinAmount),
|
|
2909
3398
|
params.fix_amount_a,
|
|
2910
3399
|
true,
|
|
2911
3400
|
slippage,
|
|
@@ -2979,12 +3468,12 @@ var _TransactionUtil = class {
|
|
|
2979
3468
|
max_amount_a = params.amount_a;
|
|
2980
3469
|
min_amount_a = params.amount_a;
|
|
2981
3470
|
max_amount_b = params.amount_b;
|
|
2982
|
-
min_amount_b = new
|
|
3471
|
+
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
3472
|
} else {
|
|
2984
3473
|
max_amount_b = params.amount_b;
|
|
2985
3474
|
min_amount_b = params.amount_b;
|
|
2986
3475
|
max_amount_a = params.amount_a;
|
|
2987
|
-
min_amount_a = new
|
|
3476
|
+
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
3477
|
}
|
|
2989
3478
|
const args = params.is_open ? [
|
|
2990
3479
|
tx.object(clmmConfig.global_config_id),
|
|
@@ -3973,7 +4462,7 @@ var _TransactionUtil = class {
|
|
|
3973
4462
|
const basePath = splitPath.basePaths[i];
|
|
3974
4463
|
a2b.push(basePath.direction);
|
|
3975
4464
|
poolAddress.push(basePath.poolAddress);
|
|
3976
|
-
rawAmountLimit.push(new
|
|
4465
|
+
rawAmountLimit.push(new import_bn14.default(basePath.inputAmount.toString()));
|
|
3977
4466
|
if (i === 0) {
|
|
3978
4467
|
coinType.push(basePath.fromCoin, basePath.toCoin);
|
|
3979
4468
|
} else {
|
|
@@ -3981,8 +4470,8 @@ var _TransactionUtil = class {
|
|
|
3981
4470
|
}
|
|
3982
4471
|
}
|
|
3983
4472
|
const onePath = {
|
|
3984
|
-
amountIn: new
|
|
3985
|
-
amountOut: new
|
|
4473
|
+
amountIn: new import_bn14.default(splitPath.inputAmount.toString()),
|
|
4474
|
+
amountOut: new import_bn14.default(splitPath.outputAmount.toString()),
|
|
3986
4475
|
poolAddress,
|
|
3987
4476
|
a2b,
|
|
3988
4477
|
rawAmountLimit,
|
|
@@ -4339,9 +4828,9 @@ var TxBlock = class {
|
|
|
4339
4828
|
};
|
|
4340
4829
|
|
|
4341
4830
|
// src/utils/deepbook-utils.ts
|
|
4342
|
-
var
|
|
4831
|
+
var import_bn15 = __toESM(require("bn.js"));
|
|
4343
4832
|
var import_transactions3 = require("@mysten/sui/transactions");
|
|
4344
|
-
var FLOAT_SCALING = new
|
|
4833
|
+
var FLOAT_SCALING = new import_bn15.default(1e9);
|
|
4345
4834
|
var DeepbookUtils = class {
|
|
4346
4835
|
static createAccountCap(senderAddress, sdkOptions, tx, isTransfer = false) {
|
|
4347
4836
|
if (senderAddress.length === 0) {
|
|
@@ -4487,9 +4976,9 @@ var DeepbookUtils = class {
|
|
|
4487
4976
|
static async preSwap(sdk, pool, a2b, amountIn) {
|
|
4488
4977
|
let isExceed = false;
|
|
4489
4978
|
let amountOut = ZERO;
|
|
4490
|
-
let remainAmount = new
|
|
4979
|
+
let remainAmount = new import_bn15.default(amountIn);
|
|
4491
4980
|
let feeAmount = ZERO;
|
|
4492
|
-
const initAmountIn = new
|
|
4981
|
+
const initAmountIn = new import_bn15.default(amountIn);
|
|
4493
4982
|
if (a2b) {
|
|
4494
4983
|
let bids = await this.getPoolBids(sdk, pool.poolID, pool.baseAsset, pool.quoteAsset);
|
|
4495
4984
|
if (bids === null) {
|
|
@@ -4499,16 +4988,16 @@ var DeepbookUtils = class {
|
|
|
4499
4988
|
return b.price - a.price;
|
|
4500
4989
|
});
|
|
4501
4990
|
for (let i = 0; i < bids.length; i += 1) {
|
|
4502
|
-
const curBidAmount = new
|
|
4503
|
-
const curBidPrice = new
|
|
4504
|
-
const fee = curBidAmount.mul(new
|
|
4991
|
+
const curBidAmount = new import_bn15.default(bids[i].quantity);
|
|
4992
|
+
const curBidPrice = new import_bn15.default(bids[i].price);
|
|
4993
|
+
const fee = curBidAmount.mul(new import_bn15.default(curBidPrice)).mul(new import_bn15.default(pool.takerFeeRate)).div(FLOAT_SCALING).div(FLOAT_SCALING);
|
|
4505
4994
|
if (remainAmount.gt(curBidAmount)) {
|
|
4506
4995
|
remainAmount = remainAmount.sub(curBidAmount);
|
|
4507
4996
|
amountOut = amountOut.add(curBidAmount.mul(curBidPrice).div(FLOAT_SCALING).sub(fee));
|
|
4508
4997
|
feeAmount = feeAmount.add(fee);
|
|
4509
4998
|
} else {
|
|
4510
|
-
const curOut = remainAmount.mul(new
|
|
4511
|
-
const curFee = curOut.mul(new
|
|
4999
|
+
const curOut = remainAmount.mul(new import_bn15.default(bids[i].price)).div(FLOAT_SCALING);
|
|
5000
|
+
const curFee = curOut.mul(new import_bn15.default(pool.takerFeeRate)).div(FLOAT_SCALING);
|
|
4512
5001
|
amountOut = amountOut.add(curOut.sub(curFee));
|
|
4513
5002
|
remainAmount = remainAmount.sub(remainAmount);
|
|
4514
5003
|
feeAmount = feeAmount.add(curFee);
|
|
@@ -4523,15 +5012,15 @@ var DeepbookUtils = class {
|
|
|
4523
5012
|
isExceed = true;
|
|
4524
5013
|
}
|
|
4525
5014
|
for (let i = 0; i < asks.length; i += 1) {
|
|
4526
|
-
const curAskAmount = new
|
|
4527
|
-
const fee = curAskAmount.mul(new
|
|
5015
|
+
const curAskAmount = new import_bn15.default(asks[i].price).mul(new import_bn15.default(asks[i].quantity)).div(new import_bn15.default(1e9));
|
|
5016
|
+
const fee = curAskAmount.mul(new import_bn15.default(pool.takerFeeRate)).div(FLOAT_SCALING);
|
|
4528
5017
|
const curAskAmountWithFee = curAskAmount.add(fee);
|
|
4529
5018
|
if (remainAmount.gt(curAskAmount)) {
|
|
4530
|
-
amountOut = amountOut.add(new
|
|
5019
|
+
amountOut = amountOut.add(new import_bn15.default(asks[i].quantity));
|
|
4531
5020
|
remainAmount = remainAmount.sub(curAskAmountWithFee);
|
|
4532
5021
|
feeAmount = feeAmount.add(fee);
|
|
4533
5022
|
} else {
|
|
4534
|
-
const splitNums = new
|
|
5023
|
+
const splitNums = new import_bn15.default(asks[i].quantity).div(new import_bn15.default(pool.lotSize));
|
|
4535
5024
|
const splitAmount = curAskAmountWithFee.div(splitNums);
|
|
4536
5025
|
const swapSplitNum = remainAmount.div(splitAmount);
|
|
4537
5026
|
amountOut = amountOut.add(swapSplitNum.muln(pool.lotSize));
|
|
@@ -5392,7 +5881,7 @@ var PoolModule = class {
|
|
|
5392
5881
|
};
|
|
5393
5882
|
|
|
5394
5883
|
// src/modules/positionModule.ts
|
|
5395
|
-
var
|
|
5884
|
+
var import_bn16 = __toESM(require("bn.js"));
|
|
5396
5885
|
var import_transactions5 = require("@mysten/sui/transactions");
|
|
5397
5886
|
var import_utils15 = require("@mysten/sui/utils");
|
|
5398
5887
|
var PositionModule = class {
|
|
@@ -5614,8 +6103,8 @@ var PositionModule = class {
|
|
|
5614
6103
|
for (let i = 0; i < valueData.length; i += 1) {
|
|
5615
6104
|
const { parsedJson } = valueData[i];
|
|
5616
6105
|
const posRrewarderResult = {
|
|
5617
|
-
feeOwedA: new
|
|
5618
|
-
feeOwedB: new
|
|
6106
|
+
feeOwedA: new import_bn16.default(parsedJson.fee_owned_a),
|
|
6107
|
+
feeOwedB: new import_bn16.default(parsedJson.fee_owned_b),
|
|
5619
6108
|
position_id: parsedJson.position_id
|
|
5620
6109
|
};
|
|
5621
6110
|
result.push(posRrewarderResult);
|
|
@@ -5991,7 +6480,7 @@ var PositionModule = class {
|
|
|
5991
6480
|
};
|
|
5992
6481
|
|
|
5993
6482
|
// src/modules/rewarderModule.ts
|
|
5994
|
-
var
|
|
6483
|
+
var import_bn17 = __toESM(require("bn.js"));
|
|
5995
6484
|
var import_transactions6 = require("@mysten/sui/transactions");
|
|
5996
6485
|
var RewarderModule = class {
|
|
5997
6486
|
_sdk;
|
|
@@ -6017,7 +6506,7 @@ var RewarderModule = class {
|
|
|
6017
6506
|
}
|
|
6018
6507
|
const emissionsEveryDay = [];
|
|
6019
6508
|
for (const rewarderInfo of rewarderInfos) {
|
|
6020
|
-
const emissionSeconds = MathUtil.fromX64(new
|
|
6509
|
+
const emissionSeconds = MathUtil.fromX64(new import_bn17.default(rewarderInfo.emissions_per_second));
|
|
6021
6510
|
emissionsEveryDay.push({
|
|
6022
6511
|
emissions: Math.floor(emissionSeconds.toNumber() * 60 * 60 * 24),
|
|
6023
6512
|
coin_address: rewarderInfo.coinAddress
|
|
@@ -6036,20 +6525,20 @@ var RewarderModule = class {
|
|
|
6036
6525
|
const currentPool = await this.sdk.Pool.getPool(poolID);
|
|
6037
6526
|
const lastTime = currentPool.rewarder_last_updated_time;
|
|
6038
6527
|
currentPool.rewarder_last_updated_time = currentTime.toString();
|
|
6039
|
-
if (Number(currentPool.liquidity) === 0 || currentTime.eq(new
|
|
6528
|
+
if (Number(currentPool.liquidity) === 0 || currentTime.eq(new import_bn17.default(lastTime))) {
|
|
6040
6529
|
return currentPool;
|
|
6041
6530
|
}
|
|
6042
|
-
const timeDelta = currentTime.div(new
|
|
6531
|
+
const timeDelta = currentTime.div(new import_bn17.default(1e3)).sub(new import_bn17.default(lastTime)).add(new import_bn17.default(15));
|
|
6043
6532
|
const rewarderInfos = currentPool.rewarder_infos;
|
|
6044
6533
|
for (let i = 0; i < rewarderInfos.length; i += 1) {
|
|
6045
6534
|
const rewarderInfo = rewarderInfos[i];
|
|
6046
6535
|
const rewarderGrowthDelta = MathUtil.checkMulDivFloor(
|
|
6047
6536
|
timeDelta,
|
|
6048
|
-
new
|
|
6049
|
-
new
|
|
6537
|
+
new import_bn17.default(rewarderInfo.emissions_per_second),
|
|
6538
|
+
new import_bn17.default(currentPool.liquidity),
|
|
6050
6539
|
128
|
|
6051
6540
|
);
|
|
6052
|
-
this.growthGlobal[i] = new
|
|
6541
|
+
this.growthGlobal[i] = new import_bn17.default(rewarderInfo.growth_global).add(new import_bn17.default(rewarderGrowthDelta));
|
|
6053
6542
|
}
|
|
6054
6543
|
return currentPool;
|
|
6055
6544
|
}
|
|
@@ -6064,7 +6553,7 @@ var RewarderModule = class {
|
|
|
6064
6553
|
*/
|
|
6065
6554
|
async posRewardersAmount(poolID, positionHandle, positionID) {
|
|
6066
6555
|
const currentTime = Date.parse((/* @__PURE__ */ new Date()).toString());
|
|
6067
|
-
const pool = await this.updatePoolRewarder(poolID, new
|
|
6556
|
+
const pool = await this.updatePoolRewarder(poolID, new import_bn17.default(currentTime));
|
|
6068
6557
|
const position = await this.sdk.Position.getPositionRewarders(positionHandle, positionID);
|
|
6069
6558
|
if (position === void 0) {
|
|
6070
6559
|
return [];
|
|
@@ -6085,7 +6574,7 @@ var RewarderModule = class {
|
|
|
6085
6574
|
*/
|
|
6086
6575
|
async poolRewardersAmount(accountAddress, poolID) {
|
|
6087
6576
|
const currentTime = Date.parse((/* @__PURE__ */ new Date()).toString());
|
|
6088
|
-
const pool = await this.updatePoolRewarder(poolID, new
|
|
6577
|
+
const pool = await this.updatePoolRewarder(poolID, new import_bn17.default(currentTime));
|
|
6089
6578
|
const positions = await this.sdk.Position.getPositionList(accountAddress, [poolID]);
|
|
6090
6579
|
const tickDatas = await this.getPoolLowerAndUpperTicks(pool.ticks_handle, positions);
|
|
6091
6580
|
const rewarderAmount = [ZERO, ZERO, ZERO];
|
|
@@ -6112,38 +6601,38 @@ var RewarderModule = class {
|
|
|
6112
6601
|
const growthInside = [];
|
|
6113
6602
|
const AmountOwed = [];
|
|
6114
6603
|
if (rewardersInside.length > 0) {
|
|
6115
|
-
let growthDelta0 = MathUtil.subUnderflowU128(rewardersInside[0], new
|
|
6116
|
-
if (growthDelta0.gt(new
|
|
6604
|
+
let growthDelta0 = MathUtil.subUnderflowU128(rewardersInside[0], new import_bn17.default(position.reward_growth_inside_0));
|
|
6605
|
+
if (growthDelta0.gt(new import_bn17.default("3402823669209384634633745948738404"))) {
|
|
6117
6606
|
growthDelta0 = ONE;
|
|
6118
6607
|
}
|
|
6119
|
-
const amountOwed_0 = MathUtil.checkMulShiftRight(new
|
|
6608
|
+
const amountOwed_0 = MathUtil.checkMulShiftRight(new import_bn17.default(position.liquidity), growthDelta0, 64, 128);
|
|
6120
6609
|
growthInside.push(rewardersInside[0]);
|
|
6121
6610
|
AmountOwed.push({
|
|
6122
|
-
amount_owed: new
|
|
6611
|
+
amount_owed: new import_bn17.default(position.reward_amount_owed_0).add(amountOwed_0),
|
|
6123
6612
|
coin_address: pool.rewarder_infos[0].coinAddress
|
|
6124
6613
|
});
|
|
6125
6614
|
}
|
|
6126
6615
|
if (rewardersInside.length > 1) {
|
|
6127
|
-
let growthDelta_1 = MathUtil.subUnderflowU128(rewardersInside[1], new
|
|
6128
|
-
if (growthDelta_1.gt(new
|
|
6616
|
+
let growthDelta_1 = MathUtil.subUnderflowU128(rewardersInside[1], new import_bn17.default(position.reward_growth_inside_1));
|
|
6617
|
+
if (growthDelta_1.gt(new import_bn17.default("3402823669209384634633745948738404"))) {
|
|
6129
6618
|
growthDelta_1 = ONE;
|
|
6130
6619
|
}
|
|
6131
|
-
const amountOwed_1 = MathUtil.checkMulShiftRight(new
|
|
6620
|
+
const amountOwed_1 = MathUtil.checkMulShiftRight(new import_bn17.default(position.liquidity), growthDelta_1, 64, 128);
|
|
6132
6621
|
growthInside.push(rewardersInside[1]);
|
|
6133
6622
|
AmountOwed.push({
|
|
6134
|
-
amount_owed: new
|
|
6623
|
+
amount_owed: new import_bn17.default(position.reward_amount_owed_1).add(amountOwed_1),
|
|
6135
6624
|
coin_address: pool.rewarder_infos[1].coinAddress
|
|
6136
6625
|
});
|
|
6137
6626
|
}
|
|
6138
6627
|
if (rewardersInside.length > 2) {
|
|
6139
|
-
let growthDelta_2 = MathUtil.subUnderflowU128(rewardersInside[2], new
|
|
6140
|
-
if (growthDelta_2.gt(new
|
|
6628
|
+
let growthDelta_2 = MathUtil.subUnderflowU128(rewardersInside[2], new import_bn17.default(position.reward_growth_inside_2));
|
|
6629
|
+
if (growthDelta_2.gt(new import_bn17.default("3402823669209384634633745948738404"))) {
|
|
6141
6630
|
growthDelta_2 = ONE;
|
|
6142
6631
|
}
|
|
6143
|
-
const amountOwed_2 = MathUtil.checkMulShiftRight(new
|
|
6632
|
+
const amountOwed_2 = MathUtil.checkMulShiftRight(new import_bn17.default(position.liquidity), growthDelta_2, 64, 128);
|
|
6144
6633
|
growthInside.push(rewardersInside[2]);
|
|
6145
6634
|
AmountOwed.push({
|
|
6146
|
-
amount_owed: new
|
|
6635
|
+
amount_owed: new import_bn17.default(position.reward_amount_owed_2).add(amountOwed_2),
|
|
6147
6636
|
coin_address: pool.rewarder_infos[2].coinAddress
|
|
6148
6637
|
});
|
|
6149
6638
|
}
|
|
@@ -6257,8 +6746,8 @@ var RewarderModule = class {
|
|
|
6257
6746
|
for (let i = 0; i < valueData.length; i += 1) {
|
|
6258
6747
|
const { parsedJson } = valueData[i];
|
|
6259
6748
|
const posRrewarderResult = {
|
|
6260
|
-
feeOwedA: new
|
|
6261
|
-
feeOwedB: new
|
|
6749
|
+
feeOwedA: new import_bn17.default(parsedJson.fee_owned_a),
|
|
6750
|
+
feeOwedB: new import_bn17.default(parsedJson.fee_owned_b),
|
|
6262
6751
|
position_id: parsedJson.position_id
|
|
6263
6752
|
};
|
|
6264
6753
|
result.push(posRrewarderResult);
|
|
@@ -6321,7 +6810,7 @@ var RewarderModule = class {
|
|
|
6321
6810
|
};
|
|
6322
6811
|
for (let j = 0; j < params[i].rewarderInfo.length; j += 1) {
|
|
6323
6812
|
posRrewarderResult.rewarderAmountOwed.push({
|
|
6324
|
-
amount_owed: new
|
|
6813
|
+
amount_owed: new import_bn17.default(valueData[i].parsedJson.data[j]),
|
|
6325
6814
|
coin_address: params[i].rewarderInfo[j].coinAddress
|
|
6326
6815
|
});
|
|
6327
6816
|
}
|
|
@@ -6392,21 +6881,45 @@ var RewarderModule = class {
|
|
|
6392
6881
|
* @param tx
|
|
6393
6882
|
* @returns
|
|
6394
6883
|
*/
|
|
6395
|
-
async batchCollectRewardePayload(params, tx) {
|
|
6884
|
+
async batchCollectRewardePayload(params, tx, inputCoinA, inputCoinB) {
|
|
6396
6885
|
if (!checkInvalidSuiAddress(this._sdk.senderAddress)) {
|
|
6397
6886
|
throw new ClmmpoolsError("this config sdk senderAddress is not set right", "InvalidSendAddress" /* InvalidSendAddress */);
|
|
6398
6887
|
}
|
|
6399
6888
|
const allCoinAsset = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress, null);
|
|
6400
6889
|
tx = tx || new import_transactions6.Transaction();
|
|
6401
|
-
const
|
|
6890
|
+
const coinIdMaps = {};
|
|
6402
6891
|
params.forEach((item) => {
|
|
6403
6892
|
const coinTypeA = normalizeCoinType(item.coinTypeA);
|
|
6404
6893
|
const coinTypeB = normalizeCoinType(item.coinTypeB);
|
|
6405
6894
|
if (item.collect_fee) {
|
|
6406
|
-
|
|
6407
|
-
|
|
6408
|
-
|
|
6409
|
-
|
|
6895
|
+
let coinAInput = coinIdMaps[coinTypeA];
|
|
6896
|
+
if (coinAInput == null) {
|
|
6897
|
+
if (inputCoinA == null) {
|
|
6898
|
+
coinAInput = TransactionUtil.buildCoinForAmount(tx, allCoinAsset, BigInt(0), coinTypeA, false);
|
|
6899
|
+
} else {
|
|
6900
|
+
coinAInput = {
|
|
6901
|
+
targetCoin: inputCoinA,
|
|
6902
|
+
remainCoins: [],
|
|
6903
|
+
isMintZeroCoin: false,
|
|
6904
|
+
tragetCoinAmount: "0"
|
|
6905
|
+
};
|
|
6906
|
+
}
|
|
6907
|
+
coinIdMaps[coinTypeA] = coinAInput;
|
|
6908
|
+
}
|
|
6909
|
+
let coinBInput = coinIdMaps[coinTypeB];
|
|
6910
|
+
if (coinBInput == null) {
|
|
6911
|
+
if (inputCoinB == null) {
|
|
6912
|
+
coinBInput = TransactionUtil.buildCoinForAmount(tx, allCoinAsset, BigInt(0), coinTypeB, false);
|
|
6913
|
+
} else {
|
|
6914
|
+
coinBInput = {
|
|
6915
|
+
targetCoin: inputCoinB,
|
|
6916
|
+
remainCoins: [],
|
|
6917
|
+
isMintZeroCoin: false,
|
|
6918
|
+
tragetCoinAmount: "0"
|
|
6919
|
+
};
|
|
6920
|
+
}
|
|
6921
|
+
coinIdMaps[coinTypeB] = coinBInput;
|
|
6922
|
+
}
|
|
6410
6923
|
tx = this._sdk.Position.createCollectFeeNoSendPaylod(
|
|
6411
6924
|
{
|
|
6412
6925
|
pool_id: item.pool_id,
|
|
@@ -6422,14 +6935,20 @@ var RewarderModule = class {
|
|
|
6422
6935
|
const primaryCoinInputs = [];
|
|
6423
6936
|
item.rewarder_coin_types.forEach((type) => {
|
|
6424
6937
|
const coinType = normalizeCoinType(type);
|
|
6425
|
-
|
|
6938
|
+
let coinInput = coinIdMaps[type];
|
|
6939
|
+
if (coinInput === void 0) {
|
|
6940
|
+
coinInput = TransactionUtil.buildCoinForAmount(tx, allCoinAsset, BigInt(0), coinType, false);
|
|
6941
|
+
coinIdMaps[coinType] = coinInput;
|
|
6942
|
+
}
|
|
6426
6943
|
primaryCoinInputs.push(coinInput.targetCoin);
|
|
6427
|
-
coinIdList.push({ coin: coinInput, coin_addr: coinType });
|
|
6428
6944
|
});
|
|
6429
6945
|
tx = this.createCollectRewarderNoSendPaylod(item, tx, primaryCoinInputs);
|
|
6430
6946
|
});
|
|
6431
|
-
|
|
6432
|
-
|
|
6947
|
+
Object.keys(coinIdMaps).forEach((key) => {
|
|
6948
|
+
const value = coinIdMaps[key];
|
|
6949
|
+
if (value.isMintZeroCoin) {
|
|
6950
|
+
TransactionUtil.buildTransferCoin(this._sdk, tx, value.targetCoin, key, this._sdk.senderAddress);
|
|
6951
|
+
}
|
|
6433
6952
|
});
|
|
6434
6953
|
return tx;
|
|
6435
6954
|
}
|
|
@@ -6480,7 +6999,7 @@ var RewarderModule = class {
|
|
|
6480
6999
|
};
|
|
6481
7000
|
|
|
6482
7001
|
// src/modules/routerModule.ts
|
|
6483
|
-
var
|
|
7002
|
+
var import_bn18 = __toESM(require("bn.js"));
|
|
6484
7003
|
var import_cc_graph = require("@syntsugar/cc-graph");
|
|
6485
7004
|
var import_transactions7 = require("@mysten/sui/transactions");
|
|
6486
7005
|
function _pairSymbol(base, quote) {
|
|
@@ -6762,8 +7281,8 @@ var RouterModule = class {
|
|
|
6762
7281
|
if (swapWithMultiPoolParams != null) {
|
|
6763
7282
|
const preSwapResult2 = await this.sdk.Swap.preSwapWithMultiPool(swapWithMultiPoolParams);
|
|
6764
7283
|
const onePath2 = {
|
|
6765
|
-
amountIn: new
|
|
6766
|
-
amountOut: new
|
|
7284
|
+
amountIn: new import_bn18.default(preSwapResult2.estimatedAmountIn),
|
|
7285
|
+
amountOut: new import_bn18.default(preSwapResult2.estimatedAmountOut),
|
|
6767
7286
|
poolAddress: [preSwapResult2.poolAddress],
|
|
6768
7287
|
a2b: [preSwapResult2.aToB],
|
|
6769
7288
|
rawAmountLimit: byAmountIn ? [preSwapResult2.estimatedAmountOut] : [preSwapResult2.estimatedAmountIn],
|
|
@@ -6776,8 +7295,8 @@ var RouterModule = class {
|
|
|
6776
7295
|
priceSlippagePoint
|
|
6777
7296
|
};
|
|
6778
7297
|
const result2 = {
|
|
6779
|
-
amountIn: new
|
|
6780
|
-
amountOut: new
|
|
7298
|
+
amountIn: new import_bn18.default(preSwapResult2.estimatedAmountIn),
|
|
7299
|
+
amountOut: new import_bn18.default(preSwapResult2.estimatedAmountOut),
|
|
6781
7300
|
paths: [onePath2],
|
|
6782
7301
|
a2b: preSwapResult2.aToB,
|
|
6783
7302
|
b2c: void 0,
|
|
@@ -6799,8 +7318,8 @@ var RouterModule = class {
|
|
|
6799
7318
|
if (swapWithMultiPoolParams != null) {
|
|
6800
7319
|
const preSwapResult2 = await this.sdk.Swap.preSwapWithMultiPool(swapWithMultiPoolParams);
|
|
6801
7320
|
const onePath2 = {
|
|
6802
|
-
amountIn: new
|
|
6803
|
-
amountOut: new
|
|
7321
|
+
amountIn: new import_bn18.default(preSwapResult2.estimatedAmountIn),
|
|
7322
|
+
amountOut: new import_bn18.default(preSwapResult2.estimatedAmountOut),
|
|
6804
7323
|
poolAddress: [preSwapResult2.poolAddress],
|
|
6805
7324
|
a2b: [preSwapResult2.aToB],
|
|
6806
7325
|
rawAmountLimit: byAmountIn ? [preSwapResult2.estimatedAmountOut] : [preSwapResult2.estimatedAmountIn],
|
|
@@ -6813,8 +7332,8 @@ var RouterModule = class {
|
|
|
6813
7332
|
priceSlippagePoint
|
|
6814
7333
|
};
|
|
6815
7334
|
const result3 = {
|
|
6816
|
-
amountIn: new
|
|
6817
|
-
amountOut: new
|
|
7335
|
+
amountIn: new import_bn18.default(preSwapResult2.estimatedAmountIn),
|
|
7336
|
+
amountOut: new import_bn18.default(preSwapResult2.estimatedAmountOut),
|
|
6818
7337
|
paths: [onePath2],
|
|
6819
7338
|
a2b: preSwapResult2.aToB,
|
|
6820
7339
|
b2c: void 0,
|
|
@@ -6895,8 +7414,8 @@ var RouterModule = class {
|
|
|
6895
7414
|
if (swapWithMultiPoolParams != null) {
|
|
6896
7415
|
const preSwapResult = await this.sdk.Swap.preSwapWithMultiPool(swapWithMultiPoolParams);
|
|
6897
7416
|
const onePath = {
|
|
6898
|
-
amountIn: new
|
|
6899
|
-
amountOut: new
|
|
7417
|
+
amountIn: new import_bn18.default(preSwapResult.estimatedAmountIn),
|
|
7418
|
+
amountOut: new import_bn18.default(preSwapResult.estimatedAmountOut),
|
|
6900
7419
|
poolAddress: [preSwapResult.poolAddress],
|
|
6901
7420
|
a2b: [preSwapResult.aToB],
|
|
6902
7421
|
rawAmountLimit: byAmountIn ? [preSwapResult.estimatedAmountOut] : [preSwapResult.estimatedAmountIn],
|
|
@@ -6909,8 +7428,8 @@ var RouterModule = class {
|
|
|
6909
7428
|
priceSlippagePoint
|
|
6910
7429
|
};
|
|
6911
7430
|
const result = {
|
|
6912
|
-
amountIn: new
|
|
6913
|
-
amountOut: new
|
|
7431
|
+
amountIn: new import_bn18.default(preSwapResult.estimatedAmountIn),
|
|
7432
|
+
amountOut: new import_bn18.default(preSwapResult.estimatedAmountOut),
|
|
6914
7433
|
paths: [onePath],
|
|
6915
7434
|
a2b: preSwapResult.aToB,
|
|
6916
7435
|
b2c: void 0,
|
|
@@ -6994,13 +7513,13 @@ var RouterModule = class {
|
|
|
6994
7513
|
continue;
|
|
6995
7514
|
}
|
|
6996
7515
|
if (params[0].byAmountIn) {
|
|
6997
|
-
const amount = new
|
|
7516
|
+
const amount = new import_bn18.default(valueData[i].parsedJson.data.amount_out);
|
|
6998
7517
|
if (amount.gt(tempMaxAmount)) {
|
|
6999
7518
|
tempIndex = i;
|
|
7000
7519
|
tempMaxAmount = amount;
|
|
7001
7520
|
}
|
|
7002
7521
|
} else {
|
|
7003
|
-
const amount = params[i].stepNums > 1 ? new
|
|
7522
|
+
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
7523
|
if (amount.lt(tempMaxAmount)) {
|
|
7005
7524
|
tempIndex = i;
|
|
7006
7525
|
tempMaxAmount = amount;
|
|
@@ -7070,8 +7589,8 @@ var RouterModule = class {
|
|
|
7070
7589
|
};
|
|
7071
7590
|
|
|
7072
7591
|
// src/modules/swapModule.ts
|
|
7073
|
-
var
|
|
7074
|
-
var
|
|
7592
|
+
var import_bn19 = __toESM(require("bn.js"));
|
|
7593
|
+
var import_decimal11 = __toESM(require("decimal.js"));
|
|
7075
7594
|
var import_transactions8 = require("@mysten/sui/transactions");
|
|
7076
7595
|
var AMM_SWAP_MODULE = "amm_swap";
|
|
7077
7596
|
var POOL_STRUCT = "Pool";
|
|
@@ -7089,14 +7608,14 @@ var SwapModule = class {
|
|
|
7089
7608
|
const pathCount = item.basePaths.length;
|
|
7090
7609
|
if (pathCount > 0) {
|
|
7091
7610
|
const path = item.basePaths[0];
|
|
7092
|
-
const feeRate = path.label === "Magma" ? new
|
|
7611
|
+
const feeRate = path.label === "Magma" ? new import_decimal11.default(path.feeRate).div(10 ** 6) : new import_decimal11.default(path.feeRate).div(10 ** 9);
|
|
7093
7612
|
const feeAmount = d(path.inputAmount).div(10 ** path.fromDecimal).mul(feeRate);
|
|
7094
7613
|
fee = fee.add(feeAmount);
|
|
7095
7614
|
if (pathCount > 1) {
|
|
7096
7615
|
const path2 = item.basePaths[1];
|
|
7097
|
-
const price1 = path.direction ? path.currentPrice : new
|
|
7098
|
-
const price2 = path2.direction ? path2.currentPrice : new
|
|
7099
|
-
const feeRate2 = path2.label === "Magma" ? new
|
|
7616
|
+
const price1 = path.direction ? path.currentPrice : new import_decimal11.default(1).div(path.currentPrice);
|
|
7617
|
+
const price2 = path2.direction ? path2.currentPrice : new import_decimal11.default(1).div(path2.currentPrice);
|
|
7618
|
+
const feeRate2 = path2.label === "Magma" ? new import_decimal11.default(path2.feeRate).div(10 ** 6) : new import_decimal11.default(path2.feeRate).div(10 ** 9);
|
|
7100
7619
|
const feeAmount2 = d(path2.outputAmount).div(10 ** path2.toDecimal).mul(feeRate2);
|
|
7101
7620
|
const fee2 = feeAmount2.div(price1.mul(price2));
|
|
7102
7621
|
fee = fee.add(fee2);
|
|
@@ -7114,17 +7633,17 @@ var SwapModule = class {
|
|
|
7114
7633
|
const outputAmount = d(path.outputAmount).div(10 ** path.toDecimal);
|
|
7115
7634
|
const inputAmount = d(path.inputAmount).div(10 ** path.fromDecimal);
|
|
7116
7635
|
const rate = outputAmount.div(inputAmount);
|
|
7117
|
-
const cprice = path.direction ? new
|
|
7636
|
+
const cprice = path.direction ? new import_decimal11.default(path.currentPrice) : new import_decimal11.default(1).div(path.currentPrice);
|
|
7118
7637
|
impactValue = impactValue.add(this.calculateSingleImpact(rate, cprice));
|
|
7119
7638
|
}
|
|
7120
7639
|
if (pathCount === 2) {
|
|
7121
7640
|
const path = item.basePaths[0];
|
|
7122
7641
|
const path2 = item.basePaths[1];
|
|
7123
|
-
const cprice1 = path.direction ? new
|
|
7124
|
-
const cprice2 = path2.direction ? new
|
|
7642
|
+
const cprice1 = path.direction ? new import_decimal11.default(path.currentPrice) : new import_decimal11.default(1).div(path.currentPrice);
|
|
7643
|
+
const cprice2 = path2.direction ? new import_decimal11.default(path2.currentPrice) : new import_decimal11.default(1).div(path2.currentPrice);
|
|
7125
7644
|
const cprice = cprice1.mul(cprice2);
|
|
7126
|
-
const outputAmount = new
|
|
7127
|
-
const inputAmount = new
|
|
7645
|
+
const outputAmount = new import_decimal11.default(path2.outputAmount).div(10 ** path2.toDecimal);
|
|
7646
|
+
const inputAmount = new import_decimal11.default(path.inputAmount).div(10 ** path.fromDecimal);
|
|
7128
7647
|
const rate = outputAmount.div(inputAmount);
|
|
7129
7648
|
impactValue = impactValue.add(this.calculateSingleImpact(rate, cprice));
|
|
7130
7649
|
}
|
|
@@ -7186,13 +7705,13 @@ var SwapModule = class {
|
|
|
7186
7705
|
continue;
|
|
7187
7706
|
}
|
|
7188
7707
|
if (params.byAmountIn) {
|
|
7189
|
-
const amount = new
|
|
7708
|
+
const amount = new import_bn19.default(valueData[i].parsedJson.data.amount_out);
|
|
7190
7709
|
if (amount.gt(tempMaxAmount)) {
|
|
7191
7710
|
tempIndex = i;
|
|
7192
7711
|
tempMaxAmount = amount;
|
|
7193
7712
|
}
|
|
7194
7713
|
} else {
|
|
7195
|
-
const amount = new
|
|
7714
|
+
const amount = new import_bn19.default(valueData[i].parsedJson.data.amount_out);
|
|
7196
7715
|
if (amount.lt(tempMaxAmount)) {
|
|
7197
7716
|
tempIndex = i;
|
|
7198
7717
|
tempMaxAmount = amount;
|
|
@@ -7256,7 +7775,7 @@ var SwapModule = class {
|
|
|
7256
7775
|
return this.transformSwapData(params, valueData[0].parsedJson.data);
|
|
7257
7776
|
}
|
|
7258
7777
|
transformSwapData(params, data) {
|
|
7259
|
-
const estimatedAmountIn = data.amount_in && data.fee_amount ? new
|
|
7778
|
+
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
7779
|
return {
|
|
7261
7780
|
poolAddress: params.pool.poolAddress,
|
|
7262
7781
|
currentSqrtPrice: params.currentSqrtPrice,
|
|
@@ -7273,7 +7792,7 @@ var SwapModule = class {
|
|
|
7273
7792
|
transformSwapWithMultiPoolData(params, jsonData) {
|
|
7274
7793
|
const { data } = jsonData;
|
|
7275
7794
|
console.log("json data. ", data);
|
|
7276
|
-
const estimatedAmountIn = data.amount_in && data.fee_amount ? new
|
|
7795
|
+
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
7796
|
return {
|
|
7278
7797
|
poolAddress: params.poolAddress,
|
|
7279
7798
|
estimatedAmountIn,
|
|
@@ -8786,8 +9305,8 @@ var TokenModule = class {
|
|
|
8786
9305
|
};
|
|
8787
9306
|
|
|
8788
9307
|
// src/modules/routerModuleV2.ts
|
|
8789
|
-
var
|
|
8790
|
-
var
|
|
9308
|
+
var import_bn20 = __toESM(require("bn.js"));
|
|
9309
|
+
var import_decimal12 = __toESM(require("decimal.js"));
|
|
8791
9310
|
var import_uuid = require("uuid");
|
|
8792
9311
|
var import_axios = __toESM(require("axios"));
|
|
8793
9312
|
var RouterModuleV2 = class {
|
|
@@ -8804,7 +9323,7 @@ var RouterModuleV2 = class {
|
|
|
8804
9323
|
if (label === "Magma") {
|
|
8805
9324
|
return TickMath.sqrtPriceX64ToPrice(currentSqrtPrice, decimalA, decimalB);
|
|
8806
9325
|
}
|
|
8807
|
-
return new
|
|
9326
|
+
return new import_decimal12.default(currentSqrtPrice.toString()).div(new import_decimal12.default(10).pow(new import_decimal12.default(decimalB + 9 - decimalA)));
|
|
8808
9327
|
}
|
|
8809
9328
|
parseJsonResult(data) {
|
|
8810
9329
|
const result = {
|
|
@@ -8830,12 +9349,12 @@ var RouterModuleV2 = class {
|
|
|
8830
9349
|
outputAmount: basePath.output_amount,
|
|
8831
9350
|
inputAmount: basePath.input_amount,
|
|
8832
9351
|
feeRate: basePath.fee_rate,
|
|
8833
|
-
currentSqrtPrice: new
|
|
8834
|
-
afterSqrtPrice: basePath.label === "Magma" ? new
|
|
9352
|
+
currentSqrtPrice: new import_bn20.default(basePath.current_sqrt_price.toString()),
|
|
9353
|
+
afterSqrtPrice: basePath.label === "Magma" ? new import_bn20.default(basePath.after_sqrt_price.toString()) : ZERO,
|
|
8835
9354
|
fromDecimal: basePath.from_decimal,
|
|
8836
9355
|
toDecimal: basePath.to_decimal,
|
|
8837
9356
|
currentPrice: this.calculatePrice(
|
|
8838
|
-
new
|
|
9357
|
+
new import_bn20.default(basePath.current_sqrt_price.toString()),
|
|
8839
9358
|
basePath.from_decimal,
|
|
8840
9359
|
basePath.to_decimal,
|
|
8841
9360
|
basePath.direction,
|
|
@@ -8918,7 +9437,7 @@ var RouterModuleV2 = class {
|
|
|
8918
9437
|
const priceResult = await this.sdk.Router.priceUseV1(
|
|
8919
9438
|
from,
|
|
8920
9439
|
to,
|
|
8921
|
-
new
|
|
9440
|
+
new import_bn20.default(amount),
|
|
8922
9441
|
byAmountIn,
|
|
8923
9442
|
priceSplitPoint,
|
|
8924
9443
|
partner,
|
|
@@ -8930,7 +9449,7 @@ var RouterModuleV2 = class {
|
|
|
8930
9449
|
if (path.poolAddress.length > 1) {
|
|
8931
9450
|
const fromDecimal0 = this.sdk.Router.tokenInfo(path.coinType[0]).decimals;
|
|
8932
9451
|
const toDecimal0 = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
|
|
8933
|
-
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new
|
|
9452
|
+
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
9453
|
const path0 = {
|
|
8935
9454
|
direction: path.a2b[0],
|
|
8936
9455
|
label: "Magma",
|
|
@@ -8947,7 +9466,7 @@ var RouterModuleV2 = class {
|
|
|
8947
9466
|
};
|
|
8948
9467
|
const fromDecimal1 = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
|
|
8949
9468
|
const toDecimal1 = this.sdk.Router.tokenInfo(path.coinType[2]).decimals;
|
|
8950
|
-
const currentPrice1 = path.a2b[1] ? TickMath.sqrtPriceX64ToPrice(new
|
|
9469
|
+
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
9470
|
const path1 = {
|
|
8952
9471
|
direction: path.a2b[1],
|
|
8953
9472
|
label: "Magma",
|
|
@@ -8966,7 +9485,7 @@ var RouterModuleV2 = class {
|
|
|
8966
9485
|
} else {
|
|
8967
9486
|
const fromDecimal = this.sdk.Router.tokenInfo(path.coinType[0]).decimals;
|
|
8968
9487
|
const toDecimal = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
|
|
8969
|
-
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new
|
|
9488
|
+
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
9489
|
const path0 = {
|
|
8971
9490
|
direction: path.a2b[0],
|
|
8972
9491
|
label: "Magma",
|
|
@@ -9051,7 +9570,7 @@ var RouterModuleV2 = class {
|
|
|
9051
9570
|
const priceResult = await this.sdk.Router.priceUseV1(
|
|
9052
9571
|
from,
|
|
9053
9572
|
to,
|
|
9054
|
-
new
|
|
9573
|
+
new import_bn20.default(amount),
|
|
9055
9574
|
byAmountIn,
|
|
9056
9575
|
priceSplitPoint,
|
|
9057
9576
|
partner,
|
|
@@ -9063,7 +9582,7 @@ var RouterModuleV2 = class {
|
|
|
9063
9582
|
if (path.poolAddress.length > 1) {
|
|
9064
9583
|
const fromDecimal0 = this.sdk.Router.tokenInfo(path.coinType[0]).decimals;
|
|
9065
9584
|
const toDecimal0 = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
|
|
9066
|
-
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new
|
|
9585
|
+
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
9586
|
const path0 = {
|
|
9068
9587
|
direction: path.a2b[0],
|
|
9069
9588
|
label: "Magma",
|
|
@@ -9080,7 +9599,7 @@ var RouterModuleV2 = class {
|
|
|
9080
9599
|
};
|
|
9081
9600
|
const fromDecimal1 = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
|
|
9082
9601
|
const toDecimal1 = this.sdk.Router.tokenInfo(path.coinType[2]).decimals;
|
|
9083
|
-
const currentPrice1 = path.a2b[1] ? TickMath.sqrtPriceX64ToPrice(new
|
|
9602
|
+
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
9603
|
const path1 = {
|
|
9085
9604
|
direction: path.a2b[1],
|
|
9086
9605
|
label: "Magma",
|
|
@@ -9099,7 +9618,7 @@ var RouterModuleV2 = class {
|
|
|
9099
9618
|
} else {
|
|
9100
9619
|
const fromDecimal = this.sdk.Router.tokenInfo(path.coinType[0]).decimals;
|
|
9101
9620
|
const toDecimal = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
|
|
9102
|
-
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new
|
|
9621
|
+
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
9622
|
const path0 = {
|
|
9104
9623
|
direction: path.a2b[0],
|
|
9105
9624
|
label: "Magma",
|
|
@@ -9972,6 +10491,21 @@ var GaugeModule = class {
|
|
|
9972
10491
|
});
|
|
9973
10492
|
return tx;
|
|
9974
10493
|
}
|
|
10494
|
+
async getAllRewardByPositions(paramsList) {
|
|
10495
|
+
const tx = new import_transactions11.Transaction();
|
|
10496
|
+
const { integrate } = this.sdk.sdkOptions;
|
|
10497
|
+
const { magma_token } = getPackagerConfigs(this.sdk.sdkOptions.magma_config);
|
|
10498
|
+
paramsList.forEach((params) => {
|
|
10499
|
+
const typeArguments = [params.coinTypeA, params.coinTypeB, magma_token];
|
|
10500
|
+
const args = [tx.object(params.gaugeId), tx.object(params.poolId), tx.object(params.positionId), tx.object(CLOCK_ADDRESS)];
|
|
10501
|
+
tx.moveCall({
|
|
10502
|
+
target: `${integrate.published_at}::${Gauge}::get_reward_by_position`,
|
|
10503
|
+
arguments: args,
|
|
10504
|
+
typeArguments
|
|
10505
|
+
});
|
|
10506
|
+
});
|
|
10507
|
+
return tx;
|
|
10508
|
+
}
|
|
9975
10509
|
async getEpochRewardByPool(pool, incentive_tokens) {
|
|
9976
10510
|
const tx = new import_transactions11.Transaction();
|
|
9977
10511
|
const { integrate, simulationAccount } = this.sdk.sdkOptions;
|
|
@@ -10004,67 +10538,957 @@ var GaugeModule = class {
|
|
|
10004
10538
|
}
|
|
10005
10539
|
};
|
|
10006
10540
|
|
|
10007
|
-
// src/
|
|
10008
|
-
var
|
|
10541
|
+
// src/modules/dlmm.ts
|
|
10542
|
+
var import_transactions12 = require("@mysten/sui/transactions");
|
|
10543
|
+
var import_calc_dlmm3 = require("@magmaprotocol/calc_dlmm");
|
|
10544
|
+
var import_decimal13 = __toESM(require("decimal.js"));
|
|
10545
|
+
var DlmmModule = class {
|
|
10546
|
+
_sdk;
|
|
10009
10547
|
_cache = {};
|
|
10010
|
-
|
|
10011
|
-
|
|
10012
|
-
|
|
10013
|
-
|
|
10014
|
-
|
|
10015
|
-
|
|
10016
|
-
|
|
10017
|
-
|
|
10018
|
-
|
|
10019
|
-
|
|
10020
|
-
|
|
10021
|
-
|
|
10022
|
-
|
|
10023
|
-
|
|
10024
|
-
|
|
10025
|
-
|
|
10026
|
-
|
|
10027
|
-
|
|
10028
|
-
|
|
10029
|
-
|
|
10030
|
-
|
|
10031
|
-
|
|
10032
|
-
|
|
10033
|
-
|
|
10034
|
-
|
|
10035
|
-
|
|
10036
|
-
|
|
10037
|
-
|
|
10038
|
-
|
|
10039
|
-
|
|
10040
|
-
|
|
10041
|
-
|
|
10042
|
-
|
|
10043
|
-
|
|
10044
|
-
|
|
10045
|
-
|
|
10046
|
-
|
|
10047
|
-
|
|
10048
|
-
|
|
10049
|
-
|
|
10050
|
-
|
|
10051
|
-
|
|
10052
|
-
|
|
10053
|
-
|
|
10054
|
-
|
|
10055
|
-
|
|
10056
|
-
|
|
10057
|
-
|
|
10058
|
-
|
|
10059
|
-
|
|
10060
|
-
|
|
10061
|
-
|
|
10062
|
-
|
|
10063
|
-
|
|
10064
|
-
|
|
10065
|
-
|
|
10548
|
+
constructor(sdk) {
|
|
10549
|
+
this._sdk = sdk;
|
|
10550
|
+
}
|
|
10551
|
+
get sdk() {
|
|
10552
|
+
return this._sdk;
|
|
10553
|
+
}
|
|
10554
|
+
async getPoolInfo(pools) {
|
|
10555
|
+
const objects = await this._sdk.fullClient.batchGetObjects(pools, { showContent: true });
|
|
10556
|
+
const poolList = [];
|
|
10557
|
+
objects.forEach((obj) => {
|
|
10558
|
+
if (obj.error != null || obj.data?.content?.dataType !== "moveObject") {
|
|
10559
|
+
throw new ClmmpoolsError(`Invalid objects. error: ${obj.error}`, "InvalidType" /* InvalidType */);
|
|
10560
|
+
}
|
|
10561
|
+
const fields = getObjectFields(obj);
|
|
10562
|
+
poolList.push({
|
|
10563
|
+
pool_id: fields.id.id,
|
|
10564
|
+
bin_step: fields.bin_step,
|
|
10565
|
+
coin_a: fields.x.fields.name,
|
|
10566
|
+
coin_b: fields.y.fields.name,
|
|
10567
|
+
base_factor: fields.params.fields.base_factor,
|
|
10568
|
+
base_fee: fields.params.fields.base_factor / 1e4 * (fields.bin_step / 1e4),
|
|
10569
|
+
active_index: fields.params.fields.active_index,
|
|
10570
|
+
real_bin_id: (0, import_calc_dlmm3.get_real_id)(fields.params.fields.active_index),
|
|
10571
|
+
coinAmountA: fields.reserve_x,
|
|
10572
|
+
coinAmountB: fields.reserve_y
|
|
10573
|
+
});
|
|
10574
|
+
});
|
|
10575
|
+
return poolList;
|
|
10576
|
+
}
|
|
10577
|
+
// eg: fetch pool active_index
|
|
10578
|
+
async fetchPairParams(params) {
|
|
10579
|
+
const tx = new import_transactions12.Transaction();
|
|
10580
|
+
const { integrate, simulationAccount } = this.sdk.sdkOptions;
|
|
10581
|
+
const typeArguments = [params.coinTypeA, params.coinTypeB];
|
|
10582
|
+
const args = [tx.object(params.pair)];
|
|
10583
|
+
tx.moveCall({
|
|
10584
|
+
target: `${integrate.published_at}::${DlmmScript}::fetch_pair_params`,
|
|
10585
|
+
arguments: args,
|
|
10586
|
+
typeArguments
|
|
10587
|
+
});
|
|
10588
|
+
const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
|
|
10589
|
+
transactionBlock: tx,
|
|
10590
|
+
sender: simulationAccount.address
|
|
10591
|
+
});
|
|
10592
|
+
if (simulateRes.error != null) {
|
|
10593
|
+
throw new Error(`fetchBins error code: ${simulateRes.error ?? "unknown error"}`);
|
|
10594
|
+
}
|
|
10595
|
+
let res = {
|
|
10596
|
+
base_factor: 0,
|
|
10597
|
+
filter_period: 0,
|
|
10598
|
+
decay_period: 0,
|
|
10599
|
+
reduction_factor: 0,
|
|
10600
|
+
variable_fee_control: 0,
|
|
10601
|
+
protocol_share: 0,
|
|
10602
|
+
max_volatility_accumulator: 0,
|
|
10603
|
+
volatility_accumulator: 0,
|
|
10604
|
+
volatility_reference: 0,
|
|
10605
|
+
index_reference: 0,
|
|
10606
|
+
time_of_last_update: 0,
|
|
10607
|
+
oracle_index: 0,
|
|
10608
|
+
active_index: 0
|
|
10609
|
+
};
|
|
10610
|
+
simulateRes.events?.forEach((item) => {
|
|
10611
|
+
console.log(extractStructTagFromType(item.type).name);
|
|
10612
|
+
if (extractStructTagFromType(item.type).name === `EventPairParams`) {
|
|
10613
|
+
res = item.parsedJson.params;
|
|
10614
|
+
}
|
|
10615
|
+
});
|
|
10616
|
+
return res;
|
|
10617
|
+
}
|
|
10618
|
+
// NOTE: x, y should be sorted
|
|
10619
|
+
async createPairPayload(params) {
|
|
10620
|
+
const storage_id = (0, import_calc_dlmm3.get_storage_id_from_real_id)(
|
|
10621
|
+
BinMath.getBinIdFromPrice(params.priceTokenBPerTokenA, params.bin_step, params.coinADecimal, params.coinBDecimal)
|
|
10622
|
+
);
|
|
10623
|
+
const tx = new import_transactions12.Transaction();
|
|
10624
|
+
tx.setSender(this.sdk.senderAddress);
|
|
10625
|
+
const { clmm_pool, dlmm_pool, integrate } = this.sdk.sdkOptions;
|
|
10626
|
+
const { global_config_id } = getPackagerConfigs(clmm_pool);
|
|
10627
|
+
const dlmmConfig = getPackagerConfigs(dlmm_pool);
|
|
10628
|
+
const typeArguments = [params.coinTypeA, params.coinTypeB];
|
|
10629
|
+
const args = [
|
|
10630
|
+
tx.object(dlmmConfig.factory),
|
|
10631
|
+
tx.object(global_config_id),
|
|
10632
|
+
tx.pure.u64(params.base_fee),
|
|
10633
|
+
tx.pure.u16(params.bin_step),
|
|
10634
|
+
tx.pure.u32(storage_id)
|
|
10635
|
+
];
|
|
10636
|
+
tx.moveCall({
|
|
10637
|
+
target: `${integrate.published_at}::${DlmmScript}::create_pair`,
|
|
10638
|
+
typeArguments,
|
|
10639
|
+
arguments: args
|
|
10640
|
+
});
|
|
10641
|
+
return tx;
|
|
10642
|
+
}
|
|
10643
|
+
// async mintByStrategySingle(params: MintByStrategySingleParams): Promise<Transaction> {}
|
|
10644
|
+
async mintByStrategy(params) {
|
|
10645
|
+
const tx = new import_transactions12.Transaction();
|
|
10646
|
+
const slippage = new import_decimal13.default(params.slippage);
|
|
10647
|
+
const lower_slippage = new import_decimal13.default(1).sub(slippage.div(new import_decimal13.default(1e4)));
|
|
10648
|
+
const upper_slippage = new import_decimal13.default(1).plus(slippage.div(new import_decimal13.default(1e4)));
|
|
10649
|
+
tx.setSender(this.sdk.senderAddress);
|
|
10650
|
+
const { dlmm_pool, integrate } = this.sdk.sdkOptions;
|
|
10651
|
+
const dlmmConfig = getPackagerConfigs(dlmm_pool);
|
|
10652
|
+
const typeArguments = [params.coinTypeA, params.coinTypeB];
|
|
10653
|
+
const price = (0, import_calc_dlmm3.get_price_x128_from_real_id)(params.active_bin, params.bin_step);
|
|
10654
|
+
const min_price = new import_decimal13.default(price).mul(lower_slippage);
|
|
10655
|
+
const max_price = new import_decimal13.default(price).mul(upper_slippage);
|
|
10656
|
+
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));
|
|
10657
|
+
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));
|
|
10658
|
+
const allCoins = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress);
|
|
10659
|
+
let primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountATotal), params.coinTypeA, false, true);
|
|
10660
|
+
let primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountBTotal), params.coinTypeB, false, true);
|
|
10661
|
+
let amount_min = 0;
|
|
10662
|
+
let amount_max = 0;
|
|
10663
|
+
if (params.fixCoinA) {
|
|
10664
|
+
amount_min = new import_decimal13.default(params.amountBTotal).mul(lower_slippage).toDecimalPlaces(0).toNumber();
|
|
10665
|
+
amount_max = new import_decimal13.default(params.amountBTotal).mul(upper_slippage).toDecimalPlaces(0).toNumber();
|
|
10666
|
+
primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amount_max), params.coinTypeB, false, true);
|
|
10667
|
+
}
|
|
10668
|
+
if (params.fixCoinB) {
|
|
10669
|
+
amount_min = new import_decimal13.default(params.amountATotal).mul(lower_slippage).toDecimalPlaces(0).toNumber();
|
|
10670
|
+
amount_max = new import_decimal13.default(params.amountATotal).mul(upper_slippage).toDecimalPlaces(0).toNumber();
|
|
10671
|
+
primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amount_max), params.coinTypeB, false, true);
|
|
10672
|
+
}
|
|
10673
|
+
if (params.fixCoinA && params.fixCoinB) {
|
|
10674
|
+
} else if (params.fixCoinA) {
|
|
10675
|
+
params.amountBTotal = 0;
|
|
10676
|
+
} else if (params.fixCoinB) {
|
|
10677
|
+
params.amountATotal = 0;
|
|
10678
|
+
}
|
|
10679
|
+
const args = [
|
|
10680
|
+
tx.object(params.pair),
|
|
10681
|
+
tx.object(dlmmConfig.factory),
|
|
10682
|
+
primaryCoinAInputs.targetCoin,
|
|
10683
|
+
primaryCoinBInputs.targetCoin,
|
|
10684
|
+
tx.pure.u64(params.amountATotal),
|
|
10685
|
+
tx.pure.u64(params.amountBTotal),
|
|
10686
|
+
tx.pure.u8(params.strategy),
|
|
10687
|
+
tx.pure.u32((0, import_calc_dlmm3.get_storage_id_from_real_id)(params.min_bin)),
|
|
10688
|
+
tx.pure.u32((0, import_calc_dlmm3.get_storage_id_from_real_id)(params.max_bin)),
|
|
10689
|
+
tx.pure.u32(active_min),
|
|
10690
|
+
tx.pure.u32(active_max),
|
|
10691
|
+
tx.pure.u64(amount_min),
|
|
10692
|
+
tx.pure.u64(amount_max),
|
|
10693
|
+
tx.object(CLOCK_ADDRESS)
|
|
10694
|
+
];
|
|
10695
|
+
tx.moveCall({
|
|
10696
|
+
target: `${integrate.published_at}::${DlmmScript}::mint_by_strategy`,
|
|
10697
|
+
typeArguments,
|
|
10698
|
+
arguments: args
|
|
10699
|
+
});
|
|
10700
|
+
return tx;
|
|
10701
|
+
}
|
|
10702
|
+
// Create a position by percent
|
|
10703
|
+
async mintPercent(params) {
|
|
10704
|
+
const tx = new import_transactions12.Transaction();
|
|
10705
|
+
tx.setSender(this.sdk.senderAddress);
|
|
10706
|
+
const { dlmm_pool, integrate } = this.sdk.sdkOptions;
|
|
10707
|
+
const dlmmConfig = getPackagerConfigs(dlmm_pool);
|
|
10708
|
+
const typeArguments = [params.coinTypeA, params.coinTypeB];
|
|
10709
|
+
const allCoins = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress);
|
|
10710
|
+
const primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountATotal), params.coinTypeA, false, true);
|
|
10711
|
+
const primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountBTotal), params.coinTypeB, false, true);
|
|
10712
|
+
const args = [
|
|
10713
|
+
tx.object(params.pair),
|
|
10714
|
+
tx.object(dlmmConfig.factory),
|
|
10715
|
+
primaryCoinAInputs.targetCoin,
|
|
10716
|
+
primaryCoinBInputs.targetCoin,
|
|
10717
|
+
tx.pure.u64(params.amountATotal),
|
|
10718
|
+
tx.pure.u64(params.amountBTotal),
|
|
10719
|
+
tx.pure.vector("u32", params.storageIds),
|
|
10720
|
+
tx.pure.vector("u64", params.binsAPercent),
|
|
10721
|
+
tx.pure.vector("u64", params.binsBPercent),
|
|
10722
|
+
tx.pure.address(params.to),
|
|
10723
|
+
tx.object(CLOCK_ADDRESS)
|
|
10724
|
+
];
|
|
10725
|
+
tx.moveCall({
|
|
10726
|
+
target: `${integrate.published_at}::${DlmmScript}::mint_percent`,
|
|
10727
|
+
typeArguments,
|
|
10728
|
+
arguments: args
|
|
10729
|
+
});
|
|
10730
|
+
return tx;
|
|
10731
|
+
}
|
|
10732
|
+
// Create a position by amount
|
|
10733
|
+
async createPositionByAmount(params) {
|
|
10734
|
+
const tx = new import_transactions12.Transaction();
|
|
10735
|
+
tx.setSender(this.sdk.senderAddress);
|
|
10736
|
+
const { dlmm_pool, integrate } = this.sdk.sdkOptions;
|
|
10737
|
+
const dlmmConfig = getPackagerConfigs(dlmm_pool);
|
|
10738
|
+
const typeArguments = [params.coinTypeA, params.coinTypeB];
|
|
10739
|
+
const allCoins = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress);
|
|
10740
|
+
const primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountATotal), params.coinTypeA, false, true);
|
|
10741
|
+
const primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountBTotal), params.coinTypeB, false, true);
|
|
10742
|
+
const args = [
|
|
10743
|
+
tx.object(params.pair),
|
|
10744
|
+
tx.object(dlmmConfig.factory),
|
|
10745
|
+
primaryCoinAInputs.targetCoin,
|
|
10746
|
+
primaryCoinBInputs.targetCoin,
|
|
10747
|
+
tx.pure.vector("u32", params.storageIds),
|
|
10748
|
+
tx.pure.vector("u64", params.amountsA),
|
|
10749
|
+
tx.pure.vector("u64", params.amountsB),
|
|
10750
|
+
tx.pure.address(params.to),
|
|
10751
|
+
tx.object(CLOCK_ADDRESS)
|
|
10752
|
+
];
|
|
10753
|
+
tx.moveCall({
|
|
10754
|
+
target: `${integrate.published_at}::${DlmmScript}::mint_amounts`,
|
|
10755
|
+
typeArguments,
|
|
10756
|
+
arguments: args
|
|
10757
|
+
});
|
|
10758
|
+
return tx;
|
|
10759
|
+
}
|
|
10760
|
+
async addLiquidity(params) {
|
|
10761
|
+
if (params.rewards_token.length === 0) {
|
|
10762
|
+
return this._raisePositionByAmounts(params);
|
|
10763
|
+
}
|
|
10764
|
+
return this._raisePositionByAmountsReward(params);
|
|
10765
|
+
}
|
|
10766
|
+
async _raisePositionByAmounts(params) {
|
|
10767
|
+
const tx = new import_transactions12.Transaction();
|
|
10768
|
+
tx.setSender(this.sdk.senderAddress);
|
|
10769
|
+
const { dlmm_pool, integrate } = this.sdk.sdkOptions;
|
|
10770
|
+
const dlmmConfig = getPackagerConfigs(dlmm_pool);
|
|
10771
|
+
const typeArguments = [params.coin_a, params.coin_b];
|
|
10772
|
+
const allCoins = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress);
|
|
10773
|
+
const amountATotal = params.amounts_a.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
|
|
10774
|
+
const amountBTotal = params.amounts_b.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
|
|
10775
|
+
const primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amountATotal), params.coin_a, false, true);
|
|
10776
|
+
const primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amountBTotal), params.coin_b, false, true);
|
|
10777
|
+
const args = [
|
|
10778
|
+
tx.object(params.pool_id),
|
|
10779
|
+
tx.object(dlmmConfig.factory),
|
|
10780
|
+
tx.object(params.position_id),
|
|
10781
|
+
primaryCoinAInputs.targetCoin,
|
|
10782
|
+
primaryCoinBInputs.targetCoin,
|
|
10783
|
+
tx.pure.vector("u64", params.amounts_a),
|
|
10784
|
+
tx.pure.vector("u64", params.amounts_b),
|
|
10785
|
+
tx.pure.address(params.receiver),
|
|
10786
|
+
tx.object(CLOCK_ADDRESS)
|
|
10787
|
+
];
|
|
10788
|
+
tx.moveCall({
|
|
10789
|
+
target: `${integrate.published_at}::${DlmmScript}::raise_position_by_amounts`,
|
|
10790
|
+
typeArguments,
|
|
10791
|
+
arguments: args
|
|
10792
|
+
});
|
|
10793
|
+
return tx;
|
|
10794
|
+
}
|
|
10795
|
+
async _raisePositionByAmountsReward(params) {
|
|
10796
|
+
const tx = new import_transactions12.Transaction();
|
|
10797
|
+
tx.setSender(this.sdk.senderAddress);
|
|
10798
|
+
const { dlmm_pool, integrate, clmm_pool } = this.sdk.sdkOptions;
|
|
10799
|
+
const dlmmConfig = getPackagerConfigs(dlmm_pool);
|
|
10800
|
+
const clmmConfigs = getPackagerConfigs(clmm_pool);
|
|
10801
|
+
const typeArguments = [params.coin_a, params.coin_b, ...params.rewards_token];
|
|
10802
|
+
const allCoins = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress);
|
|
10803
|
+
const amountATotal = params.amounts_a.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
|
|
10804
|
+
const amountBTotal = params.amounts_b.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
|
|
10805
|
+
const primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amountATotal), params.coin_a, false, true);
|
|
10806
|
+
const primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amountBTotal), params.coin_b, false, true);
|
|
10807
|
+
const args = [
|
|
10808
|
+
tx.object(params.pool_id),
|
|
10809
|
+
tx.object(dlmmConfig.factory),
|
|
10810
|
+
tx.object(clmmConfigs.global_vault_id),
|
|
10811
|
+
tx.object(params.position_id),
|
|
10812
|
+
primaryCoinAInputs.targetCoin,
|
|
10813
|
+
primaryCoinBInputs.targetCoin,
|
|
10814
|
+
tx.pure.vector("u64", params.amounts_a),
|
|
10815
|
+
tx.pure.vector("u64", params.amounts_b),
|
|
10816
|
+
tx.pure.address(params.receiver),
|
|
10817
|
+
tx.object(CLOCK_ADDRESS)
|
|
10818
|
+
];
|
|
10819
|
+
tx.moveCall({
|
|
10820
|
+
target: `${integrate.published_at}::${DlmmScript}::raise_position_by_amounts_reward${params.rewards_token.length}`,
|
|
10821
|
+
typeArguments,
|
|
10822
|
+
arguments: args
|
|
10823
|
+
});
|
|
10824
|
+
return tx;
|
|
10825
|
+
}
|
|
10826
|
+
async burnPosition(params) {
|
|
10827
|
+
const tx = new import_transactions12.Transaction();
|
|
10828
|
+
tx.setSender(this.sdk.senderAddress);
|
|
10829
|
+
const { integrate, clmm_pool } = this.sdk.sdkOptions;
|
|
10830
|
+
const clmmConfigs = getPackagerConfigs(clmm_pool);
|
|
10831
|
+
const typeArguments = [params.coin_a, params.coin_b, ...params.rewards_token];
|
|
10832
|
+
let args = [tx.object(params.pool_id), tx.object(params.position_id), tx.object(CLOCK_ADDRESS)];
|
|
10833
|
+
let target = `${integrate.published_at}::${DlmmScript}::burn_position`;
|
|
10834
|
+
if (params.rewards_token.length > 0) {
|
|
10835
|
+
args = [tx.object(params.pool_id), tx.object(clmmConfigs.global_vault_id), tx.object(params.position_id), tx.object(CLOCK_ADDRESS)];
|
|
10836
|
+
target = `${integrate.published_at}::${DlmmScript}::burn_position_reward${params.rewards_token.length}`;
|
|
10837
|
+
}
|
|
10838
|
+
tx.moveCall({
|
|
10839
|
+
target,
|
|
10840
|
+
typeArguments,
|
|
10841
|
+
arguments: args
|
|
10842
|
+
});
|
|
10843
|
+
return tx;
|
|
10844
|
+
}
|
|
10845
|
+
async shrinkPosition(params) {
|
|
10846
|
+
const tx = new import_transactions12.Transaction();
|
|
10847
|
+
tx.setSender(this.sdk.senderAddress);
|
|
10848
|
+
const { integrate, clmm_pool } = this.sdk.sdkOptions;
|
|
10849
|
+
const clmmConfigs = getPackagerConfigs(clmm_pool);
|
|
10850
|
+
const typeArguments = [params.coin_a, params.coin_b, ...params.rewards_token];
|
|
10851
|
+
let args = [tx.object(params.pool_id), tx.object(params.position_id), tx.pure.u64(params.delta_percentage), tx.object(CLOCK_ADDRESS)];
|
|
10852
|
+
let target = `${integrate.published_at}::${DlmmScript}::shrink_position`;
|
|
10853
|
+
if (params.rewards_token.length > 0) {
|
|
10854
|
+
args = [
|
|
10855
|
+
tx.object(params.pool_id),
|
|
10856
|
+
tx.object(clmmConfigs.global_vault_id),
|
|
10857
|
+
tx.object(params.position_id),
|
|
10858
|
+
tx.pure.u64(params.delta_percentage),
|
|
10859
|
+
tx.object(CLOCK_ADDRESS)
|
|
10860
|
+
];
|
|
10861
|
+
target = `${integrate.published_at}::${DlmmScript}::shrink_position_reward${params.rewards_token.length}`;
|
|
10862
|
+
}
|
|
10863
|
+
tx.moveCall({
|
|
10864
|
+
target,
|
|
10865
|
+
typeArguments,
|
|
10866
|
+
arguments: args
|
|
10867
|
+
});
|
|
10868
|
+
return tx;
|
|
10869
|
+
}
|
|
10870
|
+
async collectFeeAndReward(params) {
|
|
10871
|
+
let tx = new import_transactions12.Transaction();
|
|
10872
|
+
tx = await this.collectFees(params);
|
|
10873
|
+
if (params.rewards_token.length > 0) {
|
|
10874
|
+
tx = await this.collectReward(params);
|
|
10875
|
+
}
|
|
10876
|
+
return tx;
|
|
10877
|
+
}
|
|
10878
|
+
async collectReward(params, transaction) {
|
|
10879
|
+
const tx = transaction || new import_transactions12.Transaction();
|
|
10880
|
+
tx.setSender(this.sdk.senderAddress);
|
|
10881
|
+
const { integrate, clmm_pool } = this.sdk.sdkOptions;
|
|
10882
|
+
const clmmConfigs = getPackagerConfigs(clmm_pool);
|
|
10883
|
+
const typeArguments = [params.coin_a, params.coin_b, ...params.rewards_token];
|
|
10884
|
+
const args = [
|
|
10885
|
+
tx.object(params.pool_id),
|
|
10886
|
+
tx.object(clmmConfigs.global_vault_id),
|
|
10887
|
+
tx.object(params.position_id),
|
|
10888
|
+
tx.object(CLOCK_ADDRESS)
|
|
10889
|
+
];
|
|
10890
|
+
let target = `${integrate.published_at}::${DlmmScript}::collect_reward`;
|
|
10891
|
+
if (params.rewards_token.length > 1) {
|
|
10892
|
+
target = `${integrate.published_at}::${DlmmScript}::collect_reward${params.rewards_token.length}`;
|
|
10893
|
+
}
|
|
10894
|
+
tx.moveCall({
|
|
10895
|
+
target,
|
|
10896
|
+
typeArguments,
|
|
10897
|
+
arguments: args
|
|
10898
|
+
});
|
|
10899
|
+
return tx;
|
|
10900
|
+
}
|
|
10901
|
+
async collectFees(params, transaction) {
|
|
10902
|
+
const tx = transaction || new import_transactions12.Transaction();
|
|
10903
|
+
tx.setSender(this.sdk.senderAddress);
|
|
10904
|
+
const { integrate } = this.sdk.sdkOptions;
|
|
10905
|
+
const typeArguments = [params.coin_a, params.coin_b];
|
|
10906
|
+
const args = [tx.object(params.pool_id), tx.object(params.position_id), tx.object(CLOCK_ADDRESS)];
|
|
10907
|
+
const target = `${integrate.published_at}::${DlmmScript}::collect_fees`;
|
|
10908
|
+
tx.moveCall({
|
|
10909
|
+
target,
|
|
10910
|
+
typeArguments,
|
|
10911
|
+
arguments: args
|
|
10912
|
+
});
|
|
10913
|
+
return tx;
|
|
10914
|
+
}
|
|
10915
|
+
async createPairAddLiquidity(params) {
|
|
10916
|
+
const tx = new import_transactions12.Transaction();
|
|
10917
|
+
tx.setSender(this.sdk.senderAddress);
|
|
10918
|
+
const { clmm_pool, dlmm_pool, integrate } = this.sdk.sdkOptions;
|
|
10919
|
+
const { global_config_id } = getPackagerConfigs(clmm_pool);
|
|
10920
|
+
const dlmmConfig = getPackagerConfigs(dlmm_pool);
|
|
10921
|
+
const typeArguments = [params.coinTypeA, params.coinTypeB];
|
|
10922
|
+
const allCoins = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress);
|
|
10923
|
+
const amountATotal = params.amountsX.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
|
|
10924
|
+
const amountBTotal = params.amountsY.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
|
|
10925
|
+
const primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amountATotal), params.coinTypeA, false, true);
|
|
10926
|
+
const primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amountBTotal), params.coinTypeB, false, true);
|
|
10927
|
+
const storageIds = [];
|
|
10928
|
+
params.realIds.forEach((i) => {
|
|
10929
|
+
storageIds.push((0, import_calc_dlmm3.get_storage_id_from_real_id)(i));
|
|
10930
|
+
});
|
|
10931
|
+
const args = [
|
|
10932
|
+
tx.object(dlmmConfig.factory),
|
|
10933
|
+
tx.object(global_config_id),
|
|
10934
|
+
tx.pure.u64(params.baseFee),
|
|
10935
|
+
tx.pure.u16(params.binStep),
|
|
10936
|
+
tx.pure.u32((0, import_calc_dlmm3.get_storage_id_from_real_id)(params.activeId)),
|
|
10937
|
+
primaryCoinAInputs.targetCoin,
|
|
10938
|
+
primaryCoinBInputs.targetCoin,
|
|
10939
|
+
tx.pure.vector("u32", storageIds),
|
|
10940
|
+
tx.pure.vector("u64", params.amountsX),
|
|
10941
|
+
tx.pure.vector("u64", params.amountsY),
|
|
10942
|
+
tx.pure.address(params.to),
|
|
10943
|
+
tx.object(CLOCK_ADDRESS)
|
|
10944
|
+
];
|
|
10945
|
+
const target = `${integrate.published_at}::${DlmmScript}::create_pair_add_liquidity`;
|
|
10946
|
+
tx.moveCall({
|
|
10947
|
+
target,
|
|
10948
|
+
typeArguments,
|
|
10949
|
+
arguments: args
|
|
10950
|
+
});
|
|
10951
|
+
return tx;
|
|
10952
|
+
}
|
|
10953
|
+
async swap(params) {
|
|
10954
|
+
const tx = new import_transactions12.Transaction();
|
|
10955
|
+
tx.setSender(this.sdk.senderAddress);
|
|
10956
|
+
const { clmm_pool, integrate } = this.sdk.sdkOptions;
|
|
10957
|
+
const { global_config_id } = getPackagerConfigs(clmm_pool);
|
|
10958
|
+
const typeArguments = [params.coinTypeA, params.coinTypeB];
|
|
10959
|
+
const allCoinAsset = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress);
|
|
10960
|
+
const primaryCoinInputA = TransactionUtil.buildCoinForAmount(
|
|
10961
|
+
tx,
|
|
10962
|
+
allCoinAsset,
|
|
10963
|
+
params.swapForY ? BigInt(params.amountIn) : BigInt(0),
|
|
10964
|
+
params.coinTypeA,
|
|
10965
|
+
false,
|
|
10966
|
+
true
|
|
10967
|
+
);
|
|
10968
|
+
const primaryCoinInputB = TransactionUtil.buildCoinForAmount(
|
|
10969
|
+
tx,
|
|
10970
|
+
allCoinAsset,
|
|
10971
|
+
params.swapForY ? BigInt(0) : BigInt(params.amountIn),
|
|
10972
|
+
params.coinTypeB,
|
|
10973
|
+
false,
|
|
10974
|
+
true
|
|
10975
|
+
);
|
|
10976
|
+
const args = [
|
|
10977
|
+
tx.object(params.pair),
|
|
10978
|
+
tx.object(global_config_id),
|
|
10979
|
+
primaryCoinInputA.targetCoin,
|
|
10980
|
+
primaryCoinInputB.targetCoin,
|
|
10981
|
+
tx.pure.u64(params.amountIn),
|
|
10982
|
+
tx.pure.u64(params.minAmountOut),
|
|
10983
|
+
tx.pure.bool(params.swapForY),
|
|
10984
|
+
tx.pure.address(params.to),
|
|
10985
|
+
tx.object(CLOCK_ADDRESS)
|
|
10986
|
+
];
|
|
10987
|
+
tx.moveCall({
|
|
10988
|
+
target: `${integrate.published_at}::${DlmmScript}::swap`,
|
|
10989
|
+
typeArguments,
|
|
10990
|
+
arguments: args
|
|
10991
|
+
});
|
|
10992
|
+
return tx;
|
|
10993
|
+
}
|
|
10994
|
+
async fetchBins(params) {
|
|
10995
|
+
const tx = new import_transactions12.Transaction();
|
|
10996
|
+
const { integrate, simulationAccount } = this.sdk.sdkOptions;
|
|
10997
|
+
const typeArguments = [params.coinTypeA, params.coinTypeB];
|
|
10998
|
+
const args = [tx.object(params.pair), tx.pure.u64(params.offset), tx.pure.u64(params.limit)];
|
|
10999
|
+
tx.moveCall({
|
|
11000
|
+
target: `${integrate.published_at}::${DlmmScript}::fetch_bins`,
|
|
11001
|
+
arguments: args,
|
|
11002
|
+
typeArguments
|
|
11003
|
+
});
|
|
11004
|
+
const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
|
|
11005
|
+
transactionBlock: tx,
|
|
11006
|
+
sender: simulationAccount.address
|
|
11007
|
+
});
|
|
11008
|
+
if (simulateRes.error != null) {
|
|
11009
|
+
throw new Error(`fetchBins error code: ${simulateRes.error ?? "unknown error"}`);
|
|
11010
|
+
}
|
|
11011
|
+
let res = [];
|
|
11012
|
+
simulateRes.events?.forEach((item) => {
|
|
11013
|
+
if (extractStructTagFromType(item.type).name === `EventFetchBins`) {
|
|
11014
|
+
const { bins } = item.parsedJson;
|
|
11015
|
+
res = bins;
|
|
11016
|
+
}
|
|
11017
|
+
});
|
|
11018
|
+
return res;
|
|
11019
|
+
}
|
|
11020
|
+
/**
|
|
11021
|
+
* Gets a list of positions for the given account address.
|
|
11022
|
+
* @param accountAddress The account address to get positions for.
|
|
11023
|
+
* @param assignPoolIds An array of pool IDs to filter the positions by.
|
|
11024
|
+
* @returns array of Position objects.
|
|
11025
|
+
*/
|
|
11026
|
+
async getUserPositionById(positionId, showDisplay = true) {
|
|
11027
|
+
let position;
|
|
11028
|
+
const ownerRes = await this._sdk.fullClient.getObject({
|
|
11029
|
+
id: positionId,
|
|
11030
|
+
options: { showContent: true, showType: true, showDisplay, showOwner: true }
|
|
11031
|
+
});
|
|
11032
|
+
const type = extractStructTagFromType(ownerRes.data.type);
|
|
11033
|
+
if (type.full_address === this.buildPositionType()) {
|
|
11034
|
+
position = this.buildPosition(ownerRes);
|
|
11035
|
+
} else {
|
|
11036
|
+
throw new ClmmpoolsError(`Dlmm Position not exists. Get Position error:${ownerRes.error}`, "InvalidPositionObject" /* InvalidPositionObject */);
|
|
11037
|
+
}
|
|
11038
|
+
const poolMap = /* @__PURE__ */ new Set();
|
|
11039
|
+
poolMap.add(position.pool);
|
|
11040
|
+
const pool = (await this.getPoolInfo(Array.from(poolMap)))[0];
|
|
11041
|
+
const _params = [];
|
|
11042
|
+
_params.push({
|
|
11043
|
+
pool_id: pool.pool_id,
|
|
11044
|
+
coin_a: pool.coin_a,
|
|
11045
|
+
coin_b: pool.coin_b
|
|
11046
|
+
});
|
|
11047
|
+
const pool_reward_coins = await this.getPairRewarders(_params);
|
|
11048
|
+
const positionLiquidity = await this.getPositionLiquidity({
|
|
11049
|
+
pair: position.pool,
|
|
11050
|
+
positionId: position.pos_object_id,
|
|
11051
|
+
coinTypeA: pool.coin_a,
|
|
11052
|
+
coinTypeB: pool.coin_b
|
|
11053
|
+
});
|
|
11054
|
+
const rewards_token = pool_reward_coins.get(position.pool) || [];
|
|
11055
|
+
let positionRewards = { position_id: position.pos_object_id, reward: [], amount: [] };
|
|
11056
|
+
if (rewards_token.length > 0) {
|
|
11057
|
+
positionRewards = await this.getEarnedRewards({
|
|
11058
|
+
pool_id: position.pool,
|
|
11059
|
+
position_id: position.pos_object_id,
|
|
11060
|
+
coin_a: pool.coin_a,
|
|
11061
|
+
coin_b: pool.coin_b,
|
|
11062
|
+
rewards_token: pool_reward_coins.get(position.pool) || []
|
|
11063
|
+
});
|
|
11064
|
+
}
|
|
11065
|
+
const positionFees = await this.getEarnedFees({
|
|
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
|
+
});
|
|
11071
|
+
return {
|
|
11072
|
+
position,
|
|
11073
|
+
liquidity: positionLiquidity,
|
|
11074
|
+
rewards: positionRewards,
|
|
11075
|
+
fees: positionFees,
|
|
11076
|
+
contractPool: pool
|
|
11077
|
+
};
|
|
11078
|
+
}
|
|
11079
|
+
/**
|
|
11080
|
+
* Gets a list of positions for the given account address.
|
|
11081
|
+
* @param accountAddress The account address to get positions for.
|
|
11082
|
+
* @param assignPoolIds An array of pool IDs to filter the positions by.
|
|
11083
|
+
* @returns array of Position objects.
|
|
11084
|
+
*/
|
|
11085
|
+
async getUserPositions(accountAddress, assignPoolIds = [], showDisplay = true) {
|
|
11086
|
+
const allPosition = [];
|
|
11087
|
+
const ownerRes = await this._sdk.fullClient.getOwnedObjectsByPage(accountAddress, {
|
|
11088
|
+
options: { showType: true, showContent: true, showDisplay, showOwner: true },
|
|
11089
|
+
filter: { Package: this._sdk.sdkOptions.dlmm_pool.package_id }
|
|
11090
|
+
});
|
|
11091
|
+
const hasAssignPoolIds = assignPoolIds.length > 0;
|
|
11092
|
+
for (const item of ownerRes.data) {
|
|
11093
|
+
const type = extractStructTagFromType(item.data.type);
|
|
11094
|
+
if (type.full_address === this.buildPositionType()) {
|
|
11095
|
+
const position = this.buildPosition(item);
|
|
11096
|
+
const cacheKey = `${position.pos_object_id}_getPositionList`;
|
|
11097
|
+
this.updateCache(cacheKey, position, cacheTime24h);
|
|
11098
|
+
if (hasAssignPoolIds) {
|
|
11099
|
+
if (assignPoolIds.includes(position.pool)) {
|
|
11100
|
+
allPosition.push(position);
|
|
11101
|
+
}
|
|
11102
|
+
} else {
|
|
11103
|
+
allPosition.push(position);
|
|
11104
|
+
}
|
|
11105
|
+
}
|
|
11106
|
+
}
|
|
11107
|
+
const poolMap = /* @__PURE__ */ new Set();
|
|
11108
|
+
for (const item of allPosition) {
|
|
11109
|
+
poolMap.add(item.pool);
|
|
11110
|
+
}
|
|
11111
|
+
const poolList = await this.getPoolInfo(Array.from(poolMap));
|
|
11112
|
+
this.updateCache(`${DlmmScript}_positionList_poolList`, poolList, cacheTime24h);
|
|
11113
|
+
const _params = [];
|
|
11114
|
+
for (const pool of poolList) {
|
|
11115
|
+
_params.push({
|
|
11116
|
+
pool_id: pool.pool_id,
|
|
11117
|
+
coin_a: pool.coin_a,
|
|
11118
|
+
coin_b: pool.coin_b
|
|
11119
|
+
});
|
|
11120
|
+
}
|
|
11121
|
+
const pool_reward_coins = await this.getPairRewarders(_params);
|
|
11122
|
+
const out = [];
|
|
11123
|
+
for (const item of allPosition) {
|
|
11124
|
+
const pool = poolList.find((pool2) => pool2.pool_id === item.pool);
|
|
11125
|
+
const positionLiquidity = await this.getPositionLiquidity({
|
|
11126
|
+
pair: item.pool,
|
|
11127
|
+
positionId: item.pos_object_id,
|
|
11128
|
+
coinTypeA: pool.coin_a,
|
|
11129
|
+
coinTypeB: pool.coin_b
|
|
11130
|
+
});
|
|
11131
|
+
const rewards_token = pool_reward_coins.get(item.pool) || [];
|
|
11132
|
+
let positionRewards = { position_id: item.pos_object_id, reward: [], amount: [] };
|
|
11133
|
+
if (rewards_token.length > 0) {
|
|
11134
|
+
positionRewards = await this.getEarnedRewards({
|
|
11135
|
+
pool_id: item.pool,
|
|
11136
|
+
position_id: item.pos_object_id,
|
|
11137
|
+
coin_a: pool.coin_a,
|
|
11138
|
+
coin_b: pool.coin_b,
|
|
11139
|
+
rewards_token: pool_reward_coins.get(item.pool) || []
|
|
11140
|
+
});
|
|
11141
|
+
}
|
|
11142
|
+
const positionFees = await this.getEarnedFees({
|
|
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
|
+
});
|
|
11148
|
+
out.push({
|
|
11149
|
+
position: item,
|
|
11150
|
+
liquidity: positionLiquidity,
|
|
11151
|
+
rewards: positionRewards,
|
|
11152
|
+
fees: positionFees,
|
|
11153
|
+
contractPool: pool
|
|
11154
|
+
});
|
|
11155
|
+
}
|
|
11156
|
+
return out;
|
|
11157
|
+
}
|
|
11158
|
+
buildPosition(object) {
|
|
11159
|
+
if (object.error != null || object.data?.content?.dataType !== "moveObject") {
|
|
11160
|
+
throw new ClmmpoolsError(`Dlmm Position not exists. Get Position error:${object.error}`, "InvalidPositionObject" /* InvalidPositionObject */);
|
|
11161
|
+
}
|
|
11162
|
+
const fields = getObjectFields(object);
|
|
11163
|
+
const ownerWarp = getObjectOwner(object);
|
|
11164
|
+
return {
|
|
11165
|
+
pos_object_id: fields.id.id,
|
|
11166
|
+
owner: ownerWarp.AddressOwner,
|
|
11167
|
+
pool: fields.pair_id,
|
|
11168
|
+
bin_real_ids: fields.bin_ids.map((id) => (0, import_calc_dlmm3.get_real_id)(id)),
|
|
11169
|
+
type: ""
|
|
11170
|
+
};
|
|
11171
|
+
}
|
|
11172
|
+
// return [coin_a, coin_b]
|
|
11173
|
+
async getPoolCoins(pools) {
|
|
11174
|
+
const res = await this._sdk.fullClient.multiGetObjects({ ids: pools, options: { showContent: true } });
|
|
11175
|
+
const poolCoins = /* @__PURE__ */ new Map();
|
|
11176
|
+
res.forEach((item) => {
|
|
11177
|
+
if (item.error != null || item.data?.content?.dataType !== "moveObject") {
|
|
11178
|
+
throw new Error(`Failed to get poolCoins with err: ${item.error}`);
|
|
11179
|
+
}
|
|
11180
|
+
const type = getObjectType(item);
|
|
11181
|
+
const poolTypeFields = extractStructTagFromType(type);
|
|
11182
|
+
poolCoins.set(item.data.objectId, poolTypeFields.type_arguments);
|
|
11183
|
+
});
|
|
11184
|
+
return poolCoins;
|
|
11185
|
+
}
|
|
11186
|
+
buildPositionType() {
|
|
11187
|
+
return `${this._sdk.sdkOptions.dlmm_pool.package_id}::dlmm_position::Position`;
|
|
11188
|
+
}
|
|
11189
|
+
async getPositionLiquidity(params) {
|
|
11190
|
+
const tx = new import_transactions12.Transaction();
|
|
11191
|
+
const { integrate, simulationAccount } = this.sdk.sdkOptions;
|
|
11192
|
+
const typeArguments = [params.coinTypeA, params.coinTypeB];
|
|
11193
|
+
const args = [tx.object(params.pair), tx.object(params.positionId)];
|
|
11194
|
+
tx.moveCall({
|
|
11195
|
+
target: `${integrate.published_at}::${DlmmScript}::position_liquidity`,
|
|
11196
|
+
arguments: args,
|
|
11197
|
+
typeArguments
|
|
11198
|
+
});
|
|
11199
|
+
const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
|
|
11200
|
+
transactionBlock: tx,
|
|
11201
|
+
sender: simulationAccount.address
|
|
11202
|
+
});
|
|
11203
|
+
if (simulateRes.error != null) {
|
|
11204
|
+
throw new Error(`fetchBins error code: ${simulateRes.error ?? "unknown error"}`);
|
|
11205
|
+
}
|
|
11206
|
+
const out = {
|
|
11207
|
+
shares: 0,
|
|
11208
|
+
liquidity: 0,
|
|
11209
|
+
x_equivalent: 0,
|
|
11210
|
+
y_equivalent: 0,
|
|
11211
|
+
bin_real_ids: [],
|
|
11212
|
+
bin_x_eq: [],
|
|
11213
|
+
bin_y_eq: [],
|
|
11214
|
+
bin_liquidity: []
|
|
11215
|
+
};
|
|
11216
|
+
simulateRes.events?.forEach((item) => {
|
|
11217
|
+
if (extractStructTagFromType(item.type).name === `EventPositionLiquidity`) {
|
|
11218
|
+
out.shares = item.parsedJson.shares;
|
|
11219
|
+
out.liquidity = item.parsedJson.liquidity;
|
|
11220
|
+
out.x_equivalent = item.parsedJson.x_equivalent;
|
|
11221
|
+
out.y_equivalent = item.parsedJson.y_equivalent;
|
|
11222
|
+
out.bin_real_ids = item.parsedJson.bin_ids.map((id) => (0, import_calc_dlmm3.get_real_id)(id));
|
|
11223
|
+
out.bin_x_eq = item.parsedJson.bin_x_eq;
|
|
11224
|
+
out.bin_y_eq = item.parsedJson.bin_y_eq;
|
|
11225
|
+
out.bin_liquidity = item.parsedJson.bin_liquidity;
|
|
11226
|
+
}
|
|
11227
|
+
});
|
|
11228
|
+
return out;
|
|
11229
|
+
}
|
|
11230
|
+
async getPairLiquidity(params) {
|
|
11231
|
+
const tx = new import_transactions12.Transaction();
|
|
11232
|
+
const { integrate, simulationAccount } = this.sdk.sdkOptions;
|
|
11233
|
+
const typeArguments = [params.coinTypeA, params.coinTypeB];
|
|
11234
|
+
const args = [tx.object(params.pair)];
|
|
11235
|
+
tx.moveCall({
|
|
11236
|
+
target: `${integrate.published_at}::${DlmmScript}::pair_liquidity`,
|
|
11237
|
+
arguments: args,
|
|
11238
|
+
typeArguments
|
|
11239
|
+
});
|
|
11240
|
+
const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
|
|
11241
|
+
transactionBlock: tx,
|
|
11242
|
+
sender: simulationAccount.address
|
|
11243
|
+
});
|
|
11244
|
+
if (simulateRes.error != null) {
|
|
11245
|
+
throw new Error(`fetchBins error code: ${simulateRes.error ?? "unknown error"}`);
|
|
11246
|
+
}
|
|
11247
|
+
const out = {
|
|
11248
|
+
shares: 0,
|
|
11249
|
+
liquidity: 0,
|
|
11250
|
+
x: 0,
|
|
11251
|
+
y: 0,
|
|
11252
|
+
bin_ids: [],
|
|
11253
|
+
bin_x: [],
|
|
11254
|
+
bin_y: []
|
|
11255
|
+
};
|
|
11256
|
+
simulateRes.events?.forEach((item) => {
|
|
11257
|
+
if (extractStructTagFromType(item.type).name === `EventPositionLiquidity`) {
|
|
11258
|
+
out.shares = item.parsedJson.shares;
|
|
11259
|
+
out.liquidity = item.parsedJson.liquidity;
|
|
11260
|
+
out.x = item.parsedJson.x;
|
|
11261
|
+
out.y = item.parsedJson.y;
|
|
11262
|
+
out.bin_ids = item.bin_ids;
|
|
11263
|
+
out.bin_x = item.bin_x;
|
|
11264
|
+
out.bin_y = item.bin_y;
|
|
11265
|
+
}
|
|
11266
|
+
});
|
|
11267
|
+
return out;
|
|
11268
|
+
}
|
|
11269
|
+
async getEarnedFees(params) {
|
|
11270
|
+
const tx = new import_transactions12.Transaction();
|
|
11271
|
+
const { integrate, simulationAccount } = this.sdk.sdkOptions;
|
|
11272
|
+
const typeArguments = [params.coin_a, params.coin_b];
|
|
11273
|
+
const args = [tx.object(params.pool_id), tx.object(params.position_id)];
|
|
11274
|
+
tx.moveCall({
|
|
11275
|
+
target: `${integrate.published_at}::${DlmmScript}::earned_fees`,
|
|
11276
|
+
arguments: args,
|
|
11277
|
+
typeArguments
|
|
11278
|
+
});
|
|
11279
|
+
const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
|
|
11280
|
+
transactionBlock: tx,
|
|
11281
|
+
sender: simulationAccount.address
|
|
11282
|
+
});
|
|
11283
|
+
const out = {
|
|
11284
|
+
position_id: "",
|
|
11285
|
+
x: "",
|
|
11286
|
+
y: "",
|
|
11287
|
+
fee_x: 0,
|
|
11288
|
+
fee_y: 0
|
|
11289
|
+
};
|
|
11290
|
+
if (simulateRes.error != null) {
|
|
11291
|
+
throw new Error(`fetchPairRewards error code: ${simulateRes.error ?? "unknown error"}`);
|
|
11292
|
+
}
|
|
11293
|
+
simulateRes.events?.forEach((item) => {
|
|
11294
|
+
if (extractStructTagFromType(item.type).name === `EventPositionLiquidity`) {
|
|
11295
|
+
out.position_id = item.parsedJson.position_id;
|
|
11296
|
+
out.x = item.parsedJson.x;
|
|
11297
|
+
out.y = item.parsedJson.y;
|
|
11298
|
+
out.fee_x = item.parsedJson.fee_x;
|
|
11299
|
+
out.fee_y = item.parsedJson.fee_y;
|
|
11300
|
+
}
|
|
11301
|
+
});
|
|
11302
|
+
return out;
|
|
11303
|
+
}
|
|
11304
|
+
async getEarnedRewards(params) {
|
|
11305
|
+
const tx = new import_transactions12.Transaction();
|
|
11306
|
+
const { integrate, simulationAccount } = this.sdk.sdkOptions;
|
|
11307
|
+
const typeArguments = [params.coin_a, params.coin_b, ...params.rewards_token];
|
|
11308
|
+
const args = [tx.object(params.pool_id), tx.object(params.position_id), tx.object(CLOCK_ADDRESS)];
|
|
11309
|
+
let target = `${integrate.published_at}::${DlmmScript}::earned_rewards`;
|
|
11310
|
+
if (params.rewards_token.length > 1) {
|
|
11311
|
+
target = `${integrate.published_at}::${DlmmScript}::earned_rewards${params.rewards_token.length}`;
|
|
11312
|
+
}
|
|
11313
|
+
tx.moveCall({
|
|
11314
|
+
target,
|
|
11315
|
+
arguments: args,
|
|
11316
|
+
typeArguments
|
|
11317
|
+
});
|
|
11318
|
+
const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
|
|
11319
|
+
transactionBlock: tx,
|
|
11320
|
+
sender: simulationAccount.address
|
|
11321
|
+
});
|
|
11322
|
+
const out = {
|
|
11323
|
+
position_id: "",
|
|
11324
|
+
reward: [],
|
|
11325
|
+
amount: []
|
|
11326
|
+
};
|
|
11327
|
+
if (simulateRes.error != null) {
|
|
11328
|
+
throw new Error(`getEarnedRewards error code: ${simulateRes.error ?? "unknown error"}`);
|
|
11329
|
+
}
|
|
11330
|
+
simulateRes.events?.forEach((item) => {
|
|
11331
|
+
if (extractStructTagFromType(item.type).name === `DlmmEventEarnedRewards`) {
|
|
11332
|
+
out.position_id = item.parsedJson.position_id;
|
|
11333
|
+
out.reward = [item.parsedJson.reward];
|
|
11334
|
+
out.amount = [item.parsedJson.amount];
|
|
11335
|
+
} else if (extractStructTagFromType(item.type).name === `DlmmEventEarnedRewards2`) {
|
|
11336
|
+
out.position_id = item.parsedJson.position_id;
|
|
11337
|
+
out.reward = [item.parsedJson.reward1, item.parsedJson.reward2];
|
|
11338
|
+
out.amount = [item.parsedJson.amount1, item.parsedJson.amount2];
|
|
11339
|
+
} else if (extractStructTagFromType(item.type).name === `EventEarnedRewards3`) {
|
|
11340
|
+
out.position_id = item.parsedJson.position_id;
|
|
11341
|
+
out.reward = [item.parsedJson.reward1, item.parsedJson.reward2, item.parsedJson.reward3];
|
|
11342
|
+
out.amount = [item.parsedJson.amount1, item.parsedJson.amount2, item.parsedJson.amount3];
|
|
11343
|
+
}
|
|
11344
|
+
});
|
|
11345
|
+
return out;
|
|
11346
|
+
}
|
|
11347
|
+
// return pool_id => reward_tokens
|
|
11348
|
+
async getPairRewarders(params) {
|
|
11349
|
+
let tx = new import_transactions12.Transaction();
|
|
11350
|
+
for (const param of params) {
|
|
11351
|
+
tx = await this._getPairRewarders(param, tx);
|
|
11352
|
+
}
|
|
11353
|
+
return this._parsePairRewarders(tx);
|
|
11354
|
+
}
|
|
11355
|
+
async _getPairRewarders(params, tx) {
|
|
11356
|
+
tx = tx || new import_transactions12.Transaction();
|
|
11357
|
+
const { integrate } = this.sdk.sdkOptions;
|
|
11358
|
+
const typeArguments = [params.coin_a, params.coin_b];
|
|
11359
|
+
const args = [tx.object(params.pool_id)];
|
|
11360
|
+
tx.moveCall({
|
|
11361
|
+
target: `${integrate.published_at}::${DlmmScript}::get_pair_rewarders`,
|
|
11362
|
+
arguments: args,
|
|
11363
|
+
typeArguments
|
|
11364
|
+
});
|
|
11365
|
+
return tx;
|
|
11366
|
+
}
|
|
11367
|
+
async _parsePairRewarders(tx) {
|
|
11368
|
+
const { simulationAccount } = this.sdk.sdkOptions;
|
|
11369
|
+
const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
|
|
11370
|
+
transactionBlock: tx,
|
|
11371
|
+
sender: simulationAccount.address
|
|
11372
|
+
});
|
|
11373
|
+
const out = /* @__PURE__ */ new Map();
|
|
11374
|
+
if (simulateRes.error != null) {
|
|
11375
|
+
throw new Error(`fetchBins error code: ${simulateRes.error ?? "unknown error"}`);
|
|
11376
|
+
}
|
|
11377
|
+
simulateRes.events?.forEach((item) => {
|
|
11378
|
+
if (extractStructTagFromType(item.type).name === `EventPairRewardTypes`) {
|
|
11379
|
+
const pairRewards = {
|
|
11380
|
+
pair_id: "",
|
|
11381
|
+
tokens: []
|
|
11382
|
+
};
|
|
11383
|
+
pairRewards.pair_id = item.parsedJson.pair_id;
|
|
11384
|
+
item.parsedJson.tokens.forEach((token) => {
|
|
11385
|
+
pairRewards.tokens.push(token.name);
|
|
11386
|
+
});
|
|
11387
|
+
out.set(pairRewards.pair_id, pairRewards.tokens);
|
|
11388
|
+
}
|
|
11389
|
+
});
|
|
11390
|
+
return out;
|
|
11391
|
+
}
|
|
11392
|
+
/**
|
|
11393
|
+
* Updates the cache for the given key.
|
|
11394
|
+
*
|
|
11395
|
+
* @param key The key of the cache entry to update.
|
|
11396
|
+
* @param data The data to store in the cache.
|
|
11397
|
+
* @param time The time in minutes after which the cache entry should expire.
|
|
11398
|
+
*/
|
|
11399
|
+
updateCache(key, data, time = cacheTime5min) {
|
|
11400
|
+
let cacheData = this._cache[key];
|
|
11401
|
+
if (cacheData) {
|
|
11402
|
+
cacheData.overdueTime = getFutureTime(time);
|
|
11403
|
+
cacheData.value = data;
|
|
11404
|
+
} else {
|
|
11405
|
+
cacheData = new CachedContent(data, getFutureTime(time));
|
|
11406
|
+
}
|
|
11407
|
+
this._cache[key] = cacheData;
|
|
11408
|
+
}
|
|
11409
|
+
/**
|
|
11410
|
+
* Gets the cache entry for the given key.
|
|
11411
|
+
*
|
|
11412
|
+
* @param key The key of the cache entry to get.
|
|
11413
|
+
* @param forceRefresh Whether to force a refresh of the cache entry.
|
|
11414
|
+
* @returns The cache entry for the given key, or undefined if the cache entry does not exist or is expired.
|
|
11415
|
+
*/
|
|
11416
|
+
getCache(key, forceRefresh = false) {
|
|
11417
|
+
const cacheData = this._cache[key];
|
|
11418
|
+
const isValid = cacheData?.isValid();
|
|
11419
|
+
if (!forceRefresh && isValid) {
|
|
11420
|
+
return cacheData.value;
|
|
11421
|
+
}
|
|
11422
|
+
if (!isValid) {
|
|
11423
|
+
delete this._cache[key];
|
|
11424
|
+
}
|
|
11425
|
+
return void 0;
|
|
11426
|
+
}
|
|
11427
|
+
};
|
|
11428
|
+
|
|
11429
|
+
// src/sdk.ts
|
|
11430
|
+
var MagmaClmmSDK = class {
|
|
11431
|
+
_cache = {};
|
|
11432
|
+
/**
|
|
11433
|
+
* RPC provider on the SUI chain
|
|
11434
|
+
*/
|
|
11435
|
+
_rpcModule;
|
|
11436
|
+
/**
|
|
11437
|
+
* Provide interact with clmm pools with a pool router interface.
|
|
11438
|
+
*/
|
|
11439
|
+
_pool;
|
|
11440
|
+
/**
|
|
11441
|
+
* Provide interact with clmm position with a position router interface.
|
|
11442
|
+
*/
|
|
11443
|
+
_position;
|
|
11444
|
+
/**
|
|
11445
|
+
* Provide interact with a pool swap router interface.
|
|
11446
|
+
*/
|
|
11447
|
+
_swap;
|
|
11448
|
+
/**
|
|
11449
|
+
* Provide interact with a lock interface.
|
|
11450
|
+
*/
|
|
11451
|
+
_lock;
|
|
11452
|
+
_gauge;
|
|
11453
|
+
_dlmm;
|
|
11454
|
+
/**
|
|
11455
|
+
* Provide interact with a position rewarder interface.
|
|
11456
|
+
*/
|
|
11457
|
+
_rewarder;
|
|
11458
|
+
/**
|
|
11459
|
+
* Provide interact with a pool router interface.
|
|
11460
|
+
*/
|
|
11461
|
+
_router;
|
|
11462
|
+
/**
|
|
11463
|
+
* Provide interact with a pool routerV2 interface.
|
|
11464
|
+
*/
|
|
11465
|
+
_router_v2;
|
|
11466
|
+
/**
|
|
11467
|
+
* Provide interact with pool and token config (contain token base info for metadat).
|
|
11468
|
+
* @deprecated Please use MagmaConfig instead
|
|
11469
|
+
*/
|
|
11470
|
+
_token;
|
|
11471
|
+
/**
|
|
11472
|
+
* Provide interact with clmm pool and coin and launchpad pool config
|
|
11473
|
+
*/
|
|
11474
|
+
_config;
|
|
11475
|
+
/**
|
|
11476
|
+
* Provide sdk options
|
|
11477
|
+
*/
|
|
11478
|
+
_sdkOptions;
|
|
11479
|
+
/**
|
|
11480
|
+
* After connecting the wallet, set the current wallet address to senderAddress.
|
|
11481
|
+
*/
|
|
11482
|
+
_senderAddress = "";
|
|
11483
|
+
constructor(options) {
|
|
11484
|
+
this._sdkOptions = options;
|
|
11485
|
+
this._rpcModule = new RpcModule({
|
|
11486
|
+
url: options.fullRpcUrl
|
|
11487
|
+
});
|
|
11488
|
+
this._swap = new SwapModule(this);
|
|
10066
11489
|
this._lock = new LockModule(this);
|
|
10067
11490
|
this._gauge = new GaugeModule(this);
|
|
11491
|
+
this._dlmm = new DlmmModule(this);
|
|
10068
11492
|
this._pool = new PoolModule(this);
|
|
10069
11493
|
this._position = new PositionModule(this);
|
|
10070
11494
|
this._rewarder = new RewarderModule(this);
|
|
@@ -10102,6 +11526,9 @@ var MagmaClmmSDK = class {
|
|
|
10102
11526
|
get Gauge() {
|
|
10103
11527
|
return this._gauge;
|
|
10104
11528
|
}
|
|
11529
|
+
get Dlmm() {
|
|
11530
|
+
return this._dlmm;
|
|
11531
|
+
}
|
|
10105
11532
|
/**
|
|
10106
11533
|
* Getter for the fullClient property.
|
|
10107
11534
|
* @returns {RpcModule} The fullClient property value.
|
|
@@ -10275,6 +11702,7 @@ var main_default = MagmaClmmSDK;
|
|
|
10275
11702
|
var SDKConfig = {
|
|
10276
11703
|
clmmConfig: {
|
|
10277
11704
|
pools_id: "0xfa145b9de10fe858be81edd1c6cdffcf27be9d016de02a1345eb1009a68ba8b2",
|
|
11705
|
+
// clmm and dlmm both use this global_config
|
|
10278
11706
|
global_config_id: "0x4c4e1402401f72c7d8533d0ed8d5f8949da363c7a3319ccef261ffe153d32f8a",
|
|
10279
11707
|
global_vault_id: "0xa7e1102f222b6eb81ccc8a126e7feb2353342be9df6f6646a77c4519da29c071",
|
|
10280
11708
|
admin_cap_id: "0x89c1a321291d15ddae5a086c9abc533dff697fde3d89e0ca836c41af73e36a75"
|
|
@@ -10294,7 +11722,11 @@ var SDKConfig = {
|
|
|
10294
11722
|
distribution_cfg: "0xaff8d151ac29317201151f97d28c546b3c5923d8cfc5499f40dea61c4022c949",
|
|
10295
11723
|
magma_token: "0x7161c6c6bb65f852797c8f7f5c4f8d57adaf796e1b840921f9e23fabeadfd54e::magma::MAGMA",
|
|
10296
11724
|
minter_id: "0x4fa5766cd83b33b215b139fec27ac344040f3bbd84fcbee7b61fc671aadc51fa"
|
|
10297
|
-
}
|
|
11725
|
+
},
|
|
11726
|
+
dlmmConfig: {
|
|
11727
|
+
factory: ""
|
|
11728
|
+
},
|
|
11729
|
+
gaugeConfig: {}
|
|
10298
11730
|
};
|
|
10299
11731
|
var clmmMainnet = {
|
|
10300
11732
|
fullRpcUrl: (0, import_client2.getFullnodeUrl)("mainnet"),
|
|
@@ -10311,6 +11743,11 @@ var clmmMainnet = {
|
|
|
10311
11743
|
published_at: "0x4a35d3dfef55ed3631b7158544c6322a23bc434fe4fca1234cb680ce0505f82d",
|
|
10312
11744
|
config: SDKConfig.clmmConfig
|
|
10313
11745
|
},
|
|
11746
|
+
dlmm_pool: {
|
|
11747
|
+
package_id: "",
|
|
11748
|
+
published_at: "",
|
|
11749
|
+
config: SDKConfig.dlmmConfig
|
|
11750
|
+
},
|
|
10314
11751
|
distribution: {
|
|
10315
11752
|
package_id: "0xee4a1f231dc45a303389998fe26c4e39278cf68b404b32e4f0b9769129b8267b",
|
|
10316
11753
|
published_at: "0xee4a1f231dc45a303389998fe26c4e39278cf68b404b32e4f0b9769129b8267b"
|
|
@@ -10364,6 +11801,9 @@ var SDKConfig2 = {
|
|
|
10364
11801
|
distribution_cfg: "0x94e23846c975e2faf89a61bfc2b10ad64decab9069eb1f9fc39752b010868c74",
|
|
10365
11802
|
magma_token: "0x45ac2371c33ca0df8dc784d62c8ce5126d42edd8c56820396524dff2ae0619b1::magma_token::MAGMA_TOKEN",
|
|
10366
11803
|
minter_id: "0x89435d6b2a510ba50ca23303f10e91ec058f138a88f69a43fe03cd22edb214c5"
|
|
11804
|
+
},
|
|
11805
|
+
dlmmConfig: {
|
|
11806
|
+
factory: ""
|
|
10367
11807
|
}
|
|
10368
11808
|
};
|
|
10369
11809
|
var clmmTestnet = {
|
|
@@ -10378,6 +11818,11 @@ var clmmTestnet = {
|
|
|
10378
11818
|
published_at: "0x23e0b5ab4aa63d0e6fd98fa5e247bcf9b36ad716b479d39e56b2ba9ff631e09d",
|
|
10379
11819
|
config: SDKConfig2.clmmConfig
|
|
10380
11820
|
},
|
|
11821
|
+
dlmm_pool: {
|
|
11822
|
+
package_id: "",
|
|
11823
|
+
published_at: "",
|
|
11824
|
+
config: SDKConfig2.dlmmConfig
|
|
11825
|
+
},
|
|
10381
11826
|
distribution: {
|
|
10382
11827
|
package_id: "0x45ac2371c33ca0df8dc784d62c8ce5126d42edd8c56820396524dff2ae0619b1",
|
|
10383
11828
|
published_at: "0x45ac2371c33ca0df8dc784d62c8ce5126d42edd8c56820396524dff2ae0619b1"
|
|
@@ -10426,6 +11871,7 @@ var src_default = MagmaClmmSDK;
|
|
|
10426
11871
|
0 && (module.exports = {
|
|
10427
11872
|
AMM_SWAP_MODULE,
|
|
10428
11873
|
AmountSpecified,
|
|
11874
|
+
BinMath,
|
|
10429
11875
|
CLOCK_ADDRESS,
|
|
10430
11876
|
CachedContent,
|
|
10431
11877
|
ClmmExpectSwapModule,
|
|
@@ -10453,6 +11899,7 @@ var src_default = MagmaClmmSDK;
|
|
|
10453
11899
|
DeepbookCustodianV2Moudle,
|
|
10454
11900
|
DeepbookEndpointsV2Moudle,
|
|
10455
11901
|
DeepbookUtils,
|
|
11902
|
+
DlmmScript,
|
|
10456
11903
|
FEE_RATE_DENOMINATOR,
|
|
10457
11904
|
GAS_SYMBOL,
|
|
10458
11905
|
GAS_TYPE_ARG,
|
|
@@ -10480,6 +11927,7 @@ var src_default = MagmaClmmSDK;
|
|
|
10480
11927
|
SUI_SYSTEM_STATE_OBJECT_ID,
|
|
10481
11928
|
SplitSwap,
|
|
10482
11929
|
SplitUnit,
|
|
11930
|
+
StrategyType,
|
|
10483
11931
|
SwapDirection,
|
|
10484
11932
|
SwapModule,
|
|
10485
11933
|
SwapUtils,
|
|
@@ -10501,6 +11949,10 @@ var src_default = MagmaClmmSDK;
|
|
|
10501
11949
|
adjustForSlippage,
|
|
10502
11950
|
asIntN,
|
|
10503
11951
|
asUintN,
|
|
11952
|
+
autoFillXByStrategy,
|
|
11953
|
+
autoFillXByWeight,
|
|
11954
|
+
autoFillYByStrategy,
|
|
11955
|
+
autoFillYByWeight,
|
|
10504
11956
|
bufferToHex,
|
|
10505
11957
|
buildClmmPositionName,
|
|
10506
11958
|
buildNFT,
|
|
@@ -10538,12 +11990,14 @@ var src_default = MagmaClmmSDK;
|
|
|
10538
11990
|
getAmountUnfixedDelta,
|
|
10539
11991
|
getCoinAFromLiquidity,
|
|
10540
11992
|
getCoinBFromLiquidity,
|
|
11993
|
+
getCoinXYForLiquidity,
|
|
10541
11994
|
getDefaultSuiInputType,
|
|
10542
11995
|
getDeltaA,
|
|
10543
11996
|
getDeltaB,
|
|
10544
11997
|
getDeltaDownFromOutput,
|
|
10545
11998
|
getDeltaUpFromInput,
|
|
10546
11999
|
getFutureTime,
|
|
12000
|
+
getLiquidityAndCoinYByCoinX,
|
|
10547
12001
|
getLiquidityFromCoinA,
|
|
10548
12002
|
getLiquidityFromCoinB,
|
|
10549
12003
|
getLowerSqrtPriceFromCoinA,
|
|
@@ -10567,6 +12021,7 @@ var src_default = MagmaClmmSDK;
|
|
|
10567
12021
|
getObjectType,
|
|
10568
12022
|
getObjectVersion,
|
|
10569
12023
|
getPackagerConfigs,
|
|
12024
|
+
getPriceOfBinByBinId,
|
|
10570
12025
|
getRewardInTickRange,
|
|
10571
12026
|
getSuiObjectData,
|
|
10572
12027
|
getTickDataFromUrlData,
|
|
@@ -10590,10 +12045,15 @@ var src_default = MagmaClmmSDK;
|
|
|
10590
12045
|
shortAddress,
|
|
10591
12046
|
shortString,
|
|
10592
12047
|
tickScore,
|
|
12048
|
+
toAmountAskSide,
|
|
12049
|
+
toAmountBidSide,
|
|
12050
|
+
toAmountBothSide,
|
|
12051
|
+
toAmountsBothSideByStrategy,
|
|
10593
12052
|
toBuffer,
|
|
10594
12053
|
toCoinAmount,
|
|
10595
12054
|
toDecimalsAmount,
|
|
10596
12055
|
transClmmpoolDataWithoutTicks,
|
|
10597
|
-
utf8to16
|
|
12056
|
+
utf8to16,
|
|
12057
|
+
withLiquiditySlippage
|
|
10598
12058
|
});
|
|
10599
12059
|
//# sourceMappingURL=index.js.map
|