@magmaprotocol/magma-clmm-sdk 0.5.39 → 0.5.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +197 -2
- package/dist/index.js +1098 -148
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1081 -144
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -92,6 +92,7 @@ __export(src_exports, {
|
|
|
92
92
|
SUI_SYSTEM_STATE_OBJECT_ID: () => SUI_SYSTEM_STATE_OBJECT_ID,
|
|
93
93
|
SplitSwap: () => SplitSwap,
|
|
94
94
|
SplitUnit: () => SplitUnit,
|
|
95
|
+
StrategyType: () => StrategyType,
|
|
95
96
|
SwapDirection: () => SwapDirection,
|
|
96
97
|
SwapModule: () => SwapModule,
|
|
97
98
|
SwapUtils: () => SwapUtils,
|
|
@@ -113,6 +114,10 @@ __export(src_exports, {
|
|
|
113
114
|
adjustForSlippage: () => adjustForSlippage,
|
|
114
115
|
asIntN: () => asIntN,
|
|
115
116
|
asUintN: () => asUintN,
|
|
117
|
+
autoFillXByStrategy: () => autoFillXByStrategy,
|
|
118
|
+
autoFillXByWeight: () => autoFillXByWeight,
|
|
119
|
+
autoFillYByStrategy: () => autoFillYByStrategy,
|
|
120
|
+
autoFillYByWeight: () => autoFillYByWeight,
|
|
116
121
|
bufferToHex: () => bufferToHex,
|
|
117
122
|
buildClmmPositionName: () => buildClmmPositionName,
|
|
118
123
|
buildNFT: () => buildNFT,
|
|
@@ -151,12 +156,14 @@ __export(src_exports, {
|
|
|
151
156
|
getAmountUnfixedDelta: () => getAmountUnfixedDelta,
|
|
152
157
|
getCoinAFromLiquidity: () => getCoinAFromLiquidity,
|
|
153
158
|
getCoinBFromLiquidity: () => getCoinBFromLiquidity,
|
|
159
|
+
getCoinXYForLiquidity: () => getCoinXYForLiquidity,
|
|
154
160
|
getDefaultSuiInputType: () => getDefaultSuiInputType,
|
|
155
161
|
getDeltaA: () => getDeltaA,
|
|
156
162
|
getDeltaB: () => getDeltaB,
|
|
157
163
|
getDeltaDownFromOutput: () => getDeltaDownFromOutput,
|
|
158
164
|
getDeltaUpFromInput: () => getDeltaUpFromInput,
|
|
159
165
|
getFutureTime: () => getFutureTime,
|
|
166
|
+
getLiquidityAndCoinYByCoinX: () => getLiquidityAndCoinYByCoinX,
|
|
160
167
|
getLiquidityFromCoinA: () => getLiquidityFromCoinA,
|
|
161
168
|
getLiquidityFromCoinB: () => getLiquidityFromCoinB,
|
|
162
169
|
getLowerSqrtPriceFromCoinA: () => getLowerSqrtPriceFromCoinA,
|
|
@@ -180,6 +187,7 @@ __export(src_exports, {
|
|
|
180
187
|
getObjectType: () => getObjectType,
|
|
181
188
|
getObjectVersion: () => getObjectVersion,
|
|
182
189
|
getPackagerConfigs: () => getPackagerConfigs,
|
|
190
|
+
getPriceOfBinByBinId: () => getPriceOfBinByBinId,
|
|
183
191
|
getRewardInTickRange: () => getRewardInTickRange,
|
|
184
192
|
getSuiObjectData: () => getSuiObjectData,
|
|
185
193
|
getTickDataFromUrlData: () => getTickDataFromUrlData,
|
|
@@ -203,11 +211,16 @@ __export(src_exports, {
|
|
|
203
211
|
shortAddress: () => shortAddress,
|
|
204
212
|
shortString: () => shortString,
|
|
205
213
|
tickScore: () => tickScore,
|
|
214
|
+
toAmountAskSide: () => toAmountAskSide,
|
|
215
|
+
toAmountBidSide: () => toAmountBidSide,
|
|
216
|
+
toAmountBothSide: () => toAmountBothSide,
|
|
217
|
+
toAmountsBothSideByStrategy: () => toAmountsBothSideByStrategy,
|
|
206
218
|
toBuffer: () => toBuffer,
|
|
207
219
|
toCoinAmount: () => toCoinAmount,
|
|
208
220
|
toDecimalsAmount: () => toDecimalsAmount,
|
|
209
221
|
transClmmpoolDataWithoutTicks: () => transClmmpoolDataWithoutTicks,
|
|
210
|
-
utf8to16: () => utf8to16
|
|
222
|
+
utf8to16: () => utf8to16,
|
|
223
|
+
withLiquiditySlippage: () => withLiquiditySlippage
|
|
211
224
|
});
|
|
212
225
|
module.exports = __toCommonJS(src_exports);
|
|
213
226
|
|
|
@@ -243,7 +256,7 @@ var CachedContent = class {
|
|
|
243
256
|
};
|
|
244
257
|
|
|
245
258
|
// src/utils/common.ts
|
|
246
|
-
var
|
|
259
|
+
var import_bn13 = __toESM(require("bn.js"));
|
|
247
260
|
var import_bcs = require("@mysten/bcs");
|
|
248
261
|
var import_ed25519 = require("@mysten/sui/keypairs/ed25519");
|
|
249
262
|
var import_secp256k1 = require("@mysten/sui/keypairs/secp256k1");
|
|
@@ -1798,8 +1811,660 @@ function collectFeesQuote(param) {
|
|
|
1798
1811
|
return updateFees(param.position, fee_growth_inside_a, fee_growth_inside_b);
|
|
1799
1812
|
}
|
|
1800
1813
|
|
|
1801
|
-
// src/math/
|
|
1814
|
+
// src/math/dlmmStrategy.ts
|
|
1815
|
+
var import_bn10 = __toESM(require("bn.js"));
|
|
1816
|
+
|
|
1817
|
+
// src/math/dlmmWeightToAmounts.ts
|
|
1802
1818
|
var import_bn9 = __toESM(require("bn.js"));
|
|
1819
|
+
var import_decimal6 = __toESM(require("decimal.js"));
|
|
1820
|
+
var import_calc_dlmm = require("@magmaprotocol/calc_dlmm");
|
|
1821
|
+
function getPriceOfBinByBinId(binId, binStep) {
|
|
1822
|
+
const twoDec = new import_decimal6.default(2);
|
|
1823
|
+
const price = new import_decimal6.default((0, import_calc_dlmm.get_price_from_real_id)(binId, binStep));
|
|
1824
|
+
return price.div(twoDec.pow(128));
|
|
1825
|
+
}
|
|
1826
|
+
function autoFillYByWeight(activeId, binStep, amountX, amountXInActiveBin, amountYInActiveBin, distributions) {
|
|
1827
|
+
const activeBins = distributions.filter((element) => {
|
|
1828
|
+
return element.binId === activeId;
|
|
1829
|
+
});
|
|
1830
|
+
if (activeBins.length === 1) {
|
|
1831
|
+
const p0 = getPriceOfBinByBinId(activeId, binStep);
|
|
1832
|
+
let wx0 = new import_decimal6.default(0);
|
|
1833
|
+
let wy0 = new import_decimal6.default(0);
|
|
1834
|
+
const activeBin = activeBins[0];
|
|
1835
|
+
if (amountXInActiveBin.isZero() && amountYInActiveBin.isZero()) {
|
|
1836
|
+
wx0 = new import_decimal6.default(activeBin.weight).div(p0.mul(new import_decimal6.default(2)));
|
|
1837
|
+
wy0 = new import_decimal6.default(activeBin.weight).div(new import_decimal6.default(2));
|
|
1838
|
+
} else {
|
|
1839
|
+
const amountXInActiveBinDec = new import_decimal6.default(amountXInActiveBin.toString());
|
|
1840
|
+
const amountYInActiveBinDec = new import_decimal6.default(amountYInActiveBin.toString());
|
|
1841
|
+
if (!amountXInActiveBin.isZero()) {
|
|
1842
|
+
wx0 = new import_decimal6.default(activeBin.weight).div(p0.add(amountYInActiveBinDec.div(amountXInActiveBinDec)));
|
|
1843
|
+
}
|
|
1844
|
+
if (!amountYInActiveBin.isZero()) {
|
|
1845
|
+
wy0 = new import_decimal6.default(activeBin.weight).div(new import_decimal6.default(1).add(p0.mul(amountXInActiveBinDec).div(amountYInActiveBinDec)));
|
|
1846
|
+
}
|
|
1847
|
+
}
|
|
1848
|
+
let totalWeightX2 = wx0;
|
|
1849
|
+
let totalWeightY2 = wy0;
|
|
1850
|
+
distributions.forEach((element) => {
|
|
1851
|
+
if (element.binId < activeId) {
|
|
1852
|
+
totalWeightY2 = totalWeightY2.add(new import_decimal6.default(element.weight));
|
|
1853
|
+
}
|
|
1854
|
+
if (element.binId > activeId) {
|
|
1855
|
+
const price = getPriceOfBinByBinId(element.binId, binStep);
|
|
1856
|
+
const weighPerPrice = new import_decimal6.default(element.weight).div(price);
|
|
1857
|
+
totalWeightX2 = totalWeightX2.add(weighPerPrice);
|
|
1858
|
+
}
|
|
1859
|
+
});
|
|
1860
|
+
const kx2 = totalWeightX2.isZero() ? new import_decimal6.default(1) : new import_decimal6.default(amountX.toString()).div(totalWeightX2);
|
|
1861
|
+
const amountY2 = kx2.mul(totalWeightY2);
|
|
1862
|
+
return new import_bn9.default(amountY2.floor().toString());
|
|
1863
|
+
}
|
|
1864
|
+
let totalWeightX = new import_decimal6.default(0);
|
|
1865
|
+
let totalWeightY = new import_decimal6.default(0);
|
|
1866
|
+
distributions.forEach((element) => {
|
|
1867
|
+
if (element.binId < activeId) {
|
|
1868
|
+
totalWeightY = totalWeightY.add(new import_decimal6.default(element.weight));
|
|
1869
|
+
} else {
|
|
1870
|
+
const price = getPriceOfBinByBinId(element.binId, binStep);
|
|
1871
|
+
const weighPerPrice = new import_decimal6.default(element.weight).div(price);
|
|
1872
|
+
totalWeightX = totalWeightX.add(weighPerPrice);
|
|
1873
|
+
}
|
|
1874
|
+
});
|
|
1875
|
+
const kx = totalWeightX.isZero() ? new import_decimal6.default(1) : new import_decimal6.default(amountX.toString()).div(totalWeightX);
|
|
1876
|
+
const amountY = kx.mul(totalWeightY);
|
|
1877
|
+
return new import_bn9.default(amountY.floor().toString());
|
|
1878
|
+
}
|
|
1879
|
+
function autoFillXByWeight(activeId, binStep, amountY, amountXInActiveBin, amountYInActiveBin, distributions) {
|
|
1880
|
+
const activeBins = distributions.filter((element) => {
|
|
1881
|
+
return element.binId === activeId;
|
|
1882
|
+
});
|
|
1883
|
+
if (activeBins.length === 1) {
|
|
1884
|
+
const p0 = getPriceOfBinByBinId(activeId, binStep);
|
|
1885
|
+
let wx0 = new import_decimal6.default(0);
|
|
1886
|
+
let wy0 = new import_decimal6.default(0);
|
|
1887
|
+
const activeBin = activeBins[0];
|
|
1888
|
+
if (amountXInActiveBin.isZero() && amountYInActiveBin.isZero()) {
|
|
1889
|
+
wx0 = new import_decimal6.default(activeBin.weight).div(p0.mul(new import_decimal6.default(2)));
|
|
1890
|
+
wy0 = new import_decimal6.default(activeBin.weight).div(new import_decimal6.default(2));
|
|
1891
|
+
} else {
|
|
1892
|
+
const amountXInActiveBinDec = new import_decimal6.default(amountXInActiveBin.toString());
|
|
1893
|
+
const amountYInActiveBinDec = new import_decimal6.default(amountYInActiveBin.toString());
|
|
1894
|
+
if (!amountXInActiveBin.isZero()) {
|
|
1895
|
+
wx0 = new import_decimal6.default(activeBin.weight).div(p0.add(amountYInActiveBinDec.div(amountXInActiveBinDec)));
|
|
1896
|
+
}
|
|
1897
|
+
if (!amountYInActiveBin.isZero()) {
|
|
1898
|
+
wy0 = new import_decimal6.default(activeBin.weight).div(new import_decimal6.default(1).add(p0.mul(amountXInActiveBinDec).div(amountYInActiveBinDec)));
|
|
1899
|
+
}
|
|
1900
|
+
}
|
|
1901
|
+
let totalWeightX2 = wx0;
|
|
1902
|
+
let totalWeightY2 = wy0;
|
|
1903
|
+
distributions.forEach((element) => {
|
|
1904
|
+
if (element.binId < activeId) {
|
|
1905
|
+
totalWeightY2 = totalWeightY2.add(new import_decimal6.default(element.weight));
|
|
1906
|
+
}
|
|
1907
|
+
if (element.binId > activeId) {
|
|
1908
|
+
const price = getPriceOfBinByBinId(element.binId, binStep);
|
|
1909
|
+
const weighPerPrice = new import_decimal6.default(element.weight).div(price);
|
|
1910
|
+
totalWeightX2 = totalWeightX2.add(weighPerPrice);
|
|
1911
|
+
}
|
|
1912
|
+
});
|
|
1913
|
+
const ky2 = totalWeightY2.isZero() ? new import_decimal6.default(1) : new import_decimal6.default(amountY.toString()).div(totalWeightY2);
|
|
1914
|
+
const amountX2 = ky2.mul(totalWeightX2);
|
|
1915
|
+
return new import_bn9.default(amountX2.floor().toString());
|
|
1916
|
+
}
|
|
1917
|
+
let totalWeightX = new import_decimal6.default(0);
|
|
1918
|
+
let totalWeightY = new import_decimal6.default(0);
|
|
1919
|
+
distributions.forEach((element) => {
|
|
1920
|
+
if (element.binId < activeId) {
|
|
1921
|
+
totalWeightY = totalWeightY.add(new import_decimal6.default(element.weight));
|
|
1922
|
+
} else {
|
|
1923
|
+
const price = getPriceOfBinByBinId(element.binId, binStep);
|
|
1924
|
+
const weighPerPrice = new import_decimal6.default(element.weight).div(price);
|
|
1925
|
+
totalWeightX = totalWeightX.add(weighPerPrice);
|
|
1926
|
+
}
|
|
1927
|
+
});
|
|
1928
|
+
const ky = totalWeightY.isZero() ? new import_decimal6.default(1) : new import_decimal6.default(amountY.toString()).div(totalWeightY);
|
|
1929
|
+
const amountX = ky.mul(totalWeightX);
|
|
1930
|
+
return new import_bn9.default(amountX.floor().toString());
|
|
1931
|
+
}
|
|
1932
|
+
function toAmountBidSide(activeId, totalAmount, distributions) {
|
|
1933
|
+
const totalWeight = distributions.reduce((sum, el) => {
|
|
1934
|
+
return el.binId > activeId ? sum : sum.add(el.weight);
|
|
1935
|
+
}, new import_decimal6.default(0));
|
|
1936
|
+
if (totalWeight.cmp(new import_decimal6.default(0)) !== 1) {
|
|
1937
|
+
throw Error("Invalid parameteres");
|
|
1938
|
+
}
|
|
1939
|
+
return distributions.map((bin) => {
|
|
1940
|
+
if (bin.binId > activeId) {
|
|
1941
|
+
return {
|
|
1942
|
+
binId: bin.binId,
|
|
1943
|
+
amount: new import_bn9.default(0)
|
|
1944
|
+
};
|
|
1945
|
+
}
|
|
1946
|
+
return {
|
|
1947
|
+
binId: bin.binId,
|
|
1948
|
+
amount: new import_bn9.default(new import_decimal6.default(totalAmount.toString()).mul(new import_decimal6.default(bin.weight).div(totalWeight)).floor().toString())
|
|
1949
|
+
};
|
|
1950
|
+
});
|
|
1951
|
+
}
|
|
1952
|
+
function toAmountAskSide(activeId, binStep, totalAmount, distributions) {
|
|
1953
|
+
const totalWeight = distributions.reduce((sum, el) => {
|
|
1954
|
+
if (el.binId < activeId) {
|
|
1955
|
+
return sum;
|
|
1956
|
+
}
|
|
1957
|
+
const price = getPriceOfBinByBinId(el.binId, binStep);
|
|
1958
|
+
const weightPerPrice = new import_decimal6.default(el.weight).div(price);
|
|
1959
|
+
return sum.add(weightPerPrice);
|
|
1960
|
+
}, new import_decimal6.default(0));
|
|
1961
|
+
if (totalWeight.cmp(new import_decimal6.default(0)) !== 1) {
|
|
1962
|
+
throw Error("Invalid parameteres");
|
|
1963
|
+
}
|
|
1964
|
+
return distributions.map((bin) => {
|
|
1965
|
+
if (bin.binId < activeId) {
|
|
1966
|
+
return {
|
|
1967
|
+
binId: bin.binId,
|
|
1968
|
+
amount: new import_bn9.default(0)
|
|
1969
|
+
};
|
|
1970
|
+
}
|
|
1971
|
+
const price = getPriceOfBinByBinId(bin.binId, binStep);
|
|
1972
|
+
const weightPerPrice = new import_decimal6.default(bin.weight).div(price);
|
|
1973
|
+
return {
|
|
1974
|
+
binId: bin.binId,
|
|
1975
|
+
amount: new import_bn9.default(new import_decimal6.default(totalAmount.toString()).mul(weightPerPrice).div(totalWeight).floor().toString())
|
|
1976
|
+
};
|
|
1977
|
+
});
|
|
1978
|
+
}
|
|
1979
|
+
function toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, distributions) {
|
|
1980
|
+
if (activeId > distributions[distributions.length - 1].binId) {
|
|
1981
|
+
const amounts = toAmountBidSide(activeId, amountY, distributions);
|
|
1982
|
+
return amounts.map((bin) => {
|
|
1983
|
+
return {
|
|
1984
|
+
binId: bin.binId,
|
|
1985
|
+
amountX: new import_bn9.default(0),
|
|
1986
|
+
amountY: bin.amount
|
|
1987
|
+
};
|
|
1988
|
+
});
|
|
1989
|
+
}
|
|
1990
|
+
if (activeId < distributions[0].binId) {
|
|
1991
|
+
const amounts = toAmountAskSide(activeId, binStep, amountX, distributions);
|
|
1992
|
+
return amounts.map((bin) => {
|
|
1993
|
+
return {
|
|
1994
|
+
binId: bin.binId,
|
|
1995
|
+
amountX: bin.amount,
|
|
1996
|
+
amountY: new import_bn9.default(0)
|
|
1997
|
+
};
|
|
1998
|
+
});
|
|
1999
|
+
}
|
|
2000
|
+
const activeBins = distributions.filter((element) => {
|
|
2001
|
+
return element.binId === activeId;
|
|
2002
|
+
});
|
|
2003
|
+
if (activeBins.length === 1) {
|
|
2004
|
+
const p0 = getPriceOfBinByBinId(activeId, binStep);
|
|
2005
|
+
let wx0 = new import_decimal6.default(0);
|
|
2006
|
+
let wy0 = new import_decimal6.default(0);
|
|
2007
|
+
const activeBin = activeBins[0];
|
|
2008
|
+
if (amountXInActiveBin.isZero() && amountYInActiveBin.isZero()) {
|
|
2009
|
+
wx0 = new import_decimal6.default(activeBin.weight).div(p0.mul(new import_decimal6.default(2)));
|
|
2010
|
+
wy0 = new import_decimal6.default(activeBin.weight).div(new import_decimal6.default(2));
|
|
2011
|
+
} else {
|
|
2012
|
+
const amountXInActiveBinDec = new import_decimal6.default(amountXInActiveBin.toString());
|
|
2013
|
+
const amountYInActiveBinDec = new import_decimal6.default(amountYInActiveBin.toString());
|
|
2014
|
+
if (!amountXInActiveBin.isZero()) {
|
|
2015
|
+
wx0 = new import_decimal6.default(activeBin.weight).div(p0.add(amountYInActiveBinDec.div(amountXInActiveBinDec)));
|
|
2016
|
+
}
|
|
2017
|
+
if (!amountYInActiveBin.isZero()) {
|
|
2018
|
+
wy0 = new import_decimal6.default(activeBin.weight).div(new import_decimal6.default(1).add(p0.mul(amountXInActiveBinDec).div(amountYInActiveBinDec)));
|
|
2019
|
+
}
|
|
2020
|
+
}
|
|
2021
|
+
let totalWeightX2 = wx0;
|
|
2022
|
+
let totalWeightY2 = wy0;
|
|
2023
|
+
distributions.forEach((element) => {
|
|
2024
|
+
if (element.binId < activeId) {
|
|
2025
|
+
totalWeightY2 = totalWeightY2.add(new import_decimal6.default(element.weight));
|
|
2026
|
+
}
|
|
2027
|
+
if (element.binId > activeId) {
|
|
2028
|
+
const price = getPriceOfBinByBinId(element.binId, binStep);
|
|
2029
|
+
const weighPerPrice = new import_decimal6.default(element.weight).div(price);
|
|
2030
|
+
totalWeightX2 = totalWeightX2.add(weighPerPrice);
|
|
2031
|
+
}
|
|
2032
|
+
});
|
|
2033
|
+
const kx2 = new import_decimal6.default(amountX.toString()).div(totalWeightX2);
|
|
2034
|
+
const ky2 = new import_decimal6.default(amountY.toString()).div(totalWeightY2);
|
|
2035
|
+
const k2 = kx2.lessThan(ky2) ? kx2 : ky2;
|
|
2036
|
+
return distributions.map((bin) => {
|
|
2037
|
+
if (bin.binId < activeId) {
|
|
2038
|
+
const amount = k2.mul(new import_decimal6.default(bin.weight));
|
|
2039
|
+
return {
|
|
2040
|
+
binId: bin.binId,
|
|
2041
|
+
amountX: new import_bn9.default(0),
|
|
2042
|
+
amountY: new import_bn9.default(amount.floor().toString())
|
|
2043
|
+
};
|
|
2044
|
+
}
|
|
2045
|
+
if (bin.binId > activeId) {
|
|
2046
|
+
const price = getPriceOfBinByBinId(bin.binId, binStep);
|
|
2047
|
+
const weighPerPrice = new import_decimal6.default(bin.weight).div(price);
|
|
2048
|
+
const amount = k2.mul(weighPerPrice);
|
|
2049
|
+
return {
|
|
2050
|
+
binId: bin.binId,
|
|
2051
|
+
amountX: new import_bn9.default(amount.floor().toString()),
|
|
2052
|
+
amountY: new import_bn9.default(0)
|
|
2053
|
+
};
|
|
2054
|
+
}
|
|
2055
|
+
const amountXActiveBin = k2.mul(wx0);
|
|
2056
|
+
const amountYActiveBin = k2.mul(wy0);
|
|
2057
|
+
return {
|
|
2058
|
+
binId: bin.binId,
|
|
2059
|
+
amountX: new import_bn9.default(amountXActiveBin.floor().toString()),
|
|
2060
|
+
amountY: new import_bn9.default(amountYActiveBin.floor().toString())
|
|
2061
|
+
};
|
|
2062
|
+
});
|
|
2063
|
+
}
|
|
2064
|
+
let totalWeightX = new import_decimal6.default(0);
|
|
2065
|
+
let totalWeightY = new import_decimal6.default(0);
|
|
2066
|
+
distributions.forEach((element) => {
|
|
2067
|
+
if (element.binId < activeId) {
|
|
2068
|
+
totalWeightY = totalWeightY.add(new import_decimal6.default(element.weight));
|
|
2069
|
+
} else {
|
|
2070
|
+
const price = getPriceOfBinByBinId(element.binId, binStep);
|
|
2071
|
+
const weighPerPrice = new import_decimal6.default(element.weight).div(price);
|
|
2072
|
+
totalWeightX = totalWeightX.add(weighPerPrice);
|
|
2073
|
+
}
|
|
2074
|
+
});
|
|
2075
|
+
const kx = new import_decimal6.default(amountX.toString()).div(totalWeightX);
|
|
2076
|
+
const ky = new import_decimal6.default(amountY.toString()).div(totalWeightY);
|
|
2077
|
+
const k = kx.lessThan(ky) ? kx : ky;
|
|
2078
|
+
return distributions.map((bin) => {
|
|
2079
|
+
if (bin.binId < activeId) {
|
|
2080
|
+
const amount2 = k.mul(new import_decimal6.default(bin.weight));
|
|
2081
|
+
return {
|
|
2082
|
+
binId: bin.binId,
|
|
2083
|
+
amountX: new import_bn9.default(0),
|
|
2084
|
+
amountY: new import_bn9.default(amount2.floor().toString())
|
|
2085
|
+
};
|
|
2086
|
+
}
|
|
2087
|
+
const price = getPriceOfBinByBinId(bin.binId, binStep);
|
|
2088
|
+
const weighPerPrice = new import_decimal6.default(bin.weight).div(price);
|
|
2089
|
+
const amount = k.mul(weighPerPrice);
|
|
2090
|
+
return {
|
|
2091
|
+
binId: bin.binId,
|
|
2092
|
+
amountX: new import_bn9.default(amount.floor().toString()),
|
|
2093
|
+
amountY: new import_bn9.default(0)
|
|
2094
|
+
};
|
|
2095
|
+
});
|
|
2096
|
+
}
|
|
2097
|
+
|
|
2098
|
+
// src/math/dlmmStrategy.ts
|
|
2099
|
+
var StrategyType = /* @__PURE__ */ ((StrategyType2) => {
|
|
2100
|
+
StrategyType2[StrategyType2["Spot"] = 0] = "Spot";
|
|
2101
|
+
StrategyType2[StrategyType2["Curve"] = 1] = "Curve";
|
|
2102
|
+
StrategyType2[StrategyType2["BidAsk"] = 2] = "BidAsk";
|
|
2103
|
+
return StrategyType2;
|
|
2104
|
+
})(StrategyType || {});
|
|
2105
|
+
function toWeightDecendingOrder(minBinId, maxBinId) {
|
|
2106
|
+
const distributions = [];
|
|
2107
|
+
for (let i = minBinId; i <= maxBinId; i++) {
|
|
2108
|
+
distributions.push({
|
|
2109
|
+
binId: i,
|
|
2110
|
+
weight: maxBinId - i + 1
|
|
2111
|
+
});
|
|
2112
|
+
}
|
|
2113
|
+
return distributions;
|
|
2114
|
+
}
|
|
2115
|
+
function toWeightAscendingOrder(minBinId, maxBinId) {
|
|
2116
|
+
const distributions = [];
|
|
2117
|
+
for (let i = minBinId; i <= maxBinId; i++) {
|
|
2118
|
+
distributions.push({
|
|
2119
|
+
binId: i,
|
|
2120
|
+
weight: i - minBinId + 1
|
|
2121
|
+
});
|
|
2122
|
+
}
|
|
2123
|
+
return distributions;
|
|
2124
|
+
}
|
|
2125
|
+
function toWeightSpotBalanced(minBinId, maxBinId) {
|
|
2126
|
+
const distributions = [];
|
|
2127
|
+
for (let i = minBinId; i <= maxBinId; i++) {
|
|
2128
|
+
distributions.push({
|
|
2129
|
+
binId: i,
|
|
2130
|
+
weight: 1
|
|
2131
|
+
});
|
|
2132
|
+
}
|
|
2133
|
+
return distributions;
|
|
2134
|
+
}
|
|
2135
|
+
var DEFAULT_MAX_WEIGHT = 2e3;
|
|
2136
|
+
var DEFAULT_MIN_WEIGHT = 200;
|
|
2137
|
+
function toWeightCurve(minBinId, maxBinId, activeId) {
|
|
2138
|
+
if (activeId < minBinId || activeId > maxBinId) {
|
|
2139
|
+
throw new ClmmpoolsError("Invalid strategy params", "InvalidParams" /* InvalidParams */);
|
|
2140
|
+
}
|
|
2141
|
+
const maxWeight = DEFAULT_MAX_WEIGHT;
|
|
2142
|
+
const minWeight = DEFAULT_MIN_WEIGHT;
|
|
2143
|
+
const diffWeight = maxWeight - minWeight;
|
|
2144
|
+
const diffMinWeight = activeId > minBinId ? Math.floor(diffWeight / (activeId - minBinId)) : 0;
|
|
2145
|
+
const diffMaxWeight = maxBinId > activeId ? Math.floor(diffWeight / (maxBinId - activeId)) : 0;
|
|
2146
|
+
const distributions = [];
|
|
2147
|
+
for (let i = minBinId; i <= maxBinId; i++) {
|
|
2148
|
+
if (i < activeId) {
|
|
2149
|
+
distributions.push({
|
|
2150
|
+
binId: i,
|
|
2151
|
+
weight: maxWeight - (activeId - i) * diffMinWeight
|
|
2152
|
+
});
|
|
2153
|
+
} else if (i > activeId) {
|
|
2154
|
+
distributions.push({
|
|
2155
|
+
binId: i,
|
|
2156
|
+
weight: maxWeight - (i - activeId) * diffMaxWeight
|
|
2157
|
+
});
|
|
2158
|
+
} else {
|
|
2159
|
+
distributions.push({
|
|
2160
|
+
binId: i,
|
|
2161
|
+
weight: maxWeight
|
|
2162
|
+
});
|
|
2163
|
+
}
|
|
2164
|
+
}
|
|
2165
|
+
return distributions;
|
|
2166
|
+
}
|
|
2167
|
+
function toWeightBidAsk(minBinId, maxBinId, activeId) {
|
|
2168
|
+
if (activeId < minBinId || activeId > maxBinId) {
|
|
2169
|
+
throw new ClmmpoolsError("Invalid strategy params", "InvalidParams" /* InvalidParams */);
|
|
2170
|
+
}
|
|
2171
|
+
const maxWeight = DEFAULT_MAX_WEIGHT;
|
|
2172
|
+
const minWeight = DEFAULT_MIN_WEIGHT;
|
|
2173
|
+
const diffWeight = maxWeight - minWeight;
|
|
2174
|
+
const diffMinWeight = activeId > minBinId ? Math.floor(diffWeight / (activeId - minBinId)) : 0;
|
|
2175
|
+
const diffMaxWeight = maxBinId > activeId ? Math.floor(diffWeight / (maxBinId - activeId)) : 0;
|
|
2176
|
+
const distributions = [];
|
|
2177
|
+
for (let i = minBinId; i <= maxBinId; i++) {
|
|
2178
|
+
if (i < activeId) {
|
|
2179
|
+
distributions.push({
|
|
2180
|
+
binId: i,
|
|
2181
|
+
weight: minWeight + (activeId - i) * diffMinWeight
|
|
2182
|
+
});
|
|
2183
|
+
} else if (i > activeId) {
|
|
2184
|
+
distributions.push({
|
|
2185
|
+
binId: i,
|
|
2186
|
+
weight: minWeight + (i - activeId) * diffMaxWeight
|
|
2187
|
+
});
|
|
2188
|
+
} else {
|
|
2189
|
+
distributions.push({
|
|
2190
|
+
binId: i,
|
|
2191
|
+
weight: minWeight
|
|
2192
|
+
});
|
|
2193
|
+
}
|
|
2194
|
+
}
|
|
2195
|
+
return distributions;
|
|
2196
|
+
}
|
|
2197
|
+
function autoFillYByStrategy(activeId, binStep, amountX, amountXInActiveBin, amountYInActiveBin, minBinId, maxBinId, strategyType) {
|
|
2198
|
+
switch (strategyType) {
|
|
2199
|
+
case 0 /* Spot */: {
|
|
2200
|
+
const weights = toWeightSpotBalanced(minBinId, maxBinId);
|
|
2201
|
+
return autoFillYByWeight(activeId, binStep, amountX, amountXInActiveBin, amountYInActiveBin, weights);
|
|
2202
|
+
}
|
|
2203
|
+
case 1 /* Curve */: {
|
|
2204
|
+
const weights = toWeightCurve(minBinId, maxBinId, activeId);
|
|
2205
|
+
return autoFillYByWeight(activeId, binStep, amountX, amountXInActiveBin, amountYInActiveBin, weights);
|
|
2206
|
+
}
|
|
2207
|
+
case 2 /* BidAsk */: {
|
|
2208
|
+
const weights = toWeightBidAsk(minBinId, maxBinId, activeId);
|
|
2209
|
+
return autoFillYByWeight(activeId, binStep, amountX, amountXInActiveBin, amountYInActiveBin, weights);
|
|
2210
|
+
}
|
|
2211
|
+
default:
|
|
2212
|
+
throw new Error(`Unsupported strategy type: ${strategyType}`);
|
|
2213
|
+
}
|
|
2214
|
+
}
|
|
2215
|
+
function autoFillXByStrategy(activeId, binStep, amountY, amountXInActiveBin, amountYInActiveBin, minBinId, maxBinId, strategyType) {
|
|
2216
|
+
switch (strategyType) {
|
|
2217
|
+
case 0 /* Spot */: {
|
|
2218
|
+
const weights = toWeightSpotBalanced(minBinId, maxBinId);
|
|
2219
|
+
return autoFillXByWeight(activeId, binStep, amountY, amountXInActiveBin, amountYInActiveBin, weights);
|
|
2220
|
+
}
|
|
2221
|
+
case 1 /* Curve */: {
|
|
2222
|
+
const weights = toWeightCurve(minBinId, maxBinId, activeId);
|
|
2223
|
+
return autoFillXByWeight(activeId, binStep, amountY, amountXInActiveBin, amountYInActiveBin, weights);
|
|
2224
|
+
}
|
|
2225
|
+
case 2 /* BidAsk */: {
|
|
2226
|
+
const weights = toWeightBidAsk(minBinId, maxBinId, activeId);
|
|
2227
|
+
return autoFillXByWeight(activeId, binStep, amountY, amountXInActiveBin, amountYInActiveBin, weights);
|
|
2228
|
+
}
|
|
2229
|
+
default:
|
|
2230
|
+
throw new Error(`Unsupported strategy type: ${strategyType}`);
|
|
2231
|
+
}
|
|
2232
|
+
}
|
|
2233
|
+
function toAmountsBothSideByStrategy(activeId, binStep, minBinId, maxBinId, amountX, amountY, amountXInActiveBin, amountYInActiveBin, strategyType) {
|
|
2234
|
+
const isSingleSideX = amountY.isZero();
|
|
2235
|
+
switch (strategyType) {
|
|
2236
|
+
case 0 /* Spot */: {
|
|
2237
|
+
if (activeId < minBinId || activeId > maxBinId) {
|
|
2238
|
+
const weights = toWeightSpotBalanced(minBinId, maxBinId);
|
|
2239
|
+
return toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights);
|
|
2240
|
+
}
|
|
2241
|
+
const amountsInBin = [];
|
|
2242
|
+
if (!isSingleSideX) {
|
|
2243
|
+
if (minBinId <= activeId) {
|
|
2244
|
+
const weights = toWeightSpotBalanced(minBinId, activeId);
|
|
2245
|
+
const amounts = toAmountBidSide(activeId, amountY, weights);
|
|
2246
|
+
for (const bin of amounts) {
|
|
2247
|
+
amountsInBin.push({
|
|
2248
|
+
binId: bin.binId,
|
|
2249
|
+
amountX: new import_bn10.default(0),
|
|
2250
|
+
amountY: bin.amount
|
|
2251
|
+
});
|
|
2252
|
+
}
|
|
2253
|
+
}
|
|
2254
|
+
if (activeId < maxBinId) {
|
|
2255
|
+
const weights = toWeightSpotBalanced(activeId + 1, maxBinId);
|
|
2256
|
+
const amounts = toAmountAskSide(activeId, binStep, amountX, weights);
|
|
2257
|
+
for (const bin of amounts) {
|
|
2258
|
+
amountsInBin.push({
|
|
2259
|
+
binId: bin.binId,
|
|
2260
|
+
amountX: bin.amount,
|
|
2261
|
+
amountY: new import_bn10.default(0)
|
|
2262
|
+
});
|
|
2263
|
+
}
|
|
2264
|
+
}
|
|
2265
|
+
} else {
|
|
2266
|
+
if (minBinId < activeId) {
|
|
2267
|
+
const weights = toWeightSpotBalanced(minBinId, activeId - 1);
|
|
2268
|
+
const amountsIntoBidSide = toAmountBidSide(activeId, amountY, weights);
|
|
2269
|
+
for (const bin of amountsIntoBidSide) {
|
|
2270
|
+
amountsInBin.push({
|
|
2271
|
+
binId: bin.binId,
|
|
2272
|
+
amountX: new import_bn10.default(0),
|
|
2273
|
+
amountY: bin.amount
|
|
2274
|
+
});
|
|
2275
|
+
}
|
|
2276
|
+
}
|
|
2277
|
+
if (activeId <= maxBinId) {
|
|
2278
|
+
const weights = toWeightSpotBalanced(activeId, maxBinId);
|
|
2279
|
+
const amountsIntoAskSide = toAmountAskSide(activeId, binStep, amountX, weights);
|
|
2280
|
+
for (const bin of amountsIntoAskSide) {
|
|
2281
|
+
amountsInBin.push({
|
|
2282
|
+
binId: bin.binId,
|
|
2283
|
+
amountX: bin.amount,
|
|
2284
|
+
amountY: new import_bn10.default(0)
|
|
2285
|
+
});
|
|
2286
|
+
}
|
|
2287
|
+
}
|
|
2288
|
+
}
|
|
2289
|
+
return amountsInBin;
|
|
2290
|
+
}
|
|
2291
|
+
case 1 /* Curve */: {
|
|
2292
|
+
if (activeId < minBinId) {
|
|
2293
|
+
const weights = toWeightDecendingOrder(minBinId, maxBinId);
|
|
2294
|
+
return toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights);
|
|
2295
|
+
}
|
|
2296
|
+
if (activeId > maxBinId) {
|
|
2297
|
+
const weights = toWeightAscendingOrder(minBinId, maxBinId);
|
|
2298
|
+
return toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights);
|
|
2299
|
+
}
|
|
2300
|
+
const amountsInBin = [];
|
|
2301
|
+
if (!isSingleSideX) {
|
|
2302
|
+
if (minBinId <= activeId) {
|
|
2303
|
+
const weights = toWeightAscendingOrder(minBinId, activeId);
|
|
2304
|
+
const amounts = toAmountBidSide(activeId, amountY, weights);
|
|
2305
|
+
for (const bin of amounts) {
|
|
2306
|
+
amountsInBin.push({
|
|
2307
|
+
binId: bin.binId,
|
|
2308
|
+
amountX: new import_bn10.default(0),
|
|
2309
|
+
amountY: bin.amount
|
|
2310
|
+
});
|
|
2311
|
+
}
|
|
2312
|
+
}
|
|
2313
|
+
if (activeId < maxBinId) {
|
|
2314
|
+
const weights = toWeightDecendingOrder(activeId + 1, maxBinId);
|
|
2315
|
+
const amounts = toAmountAskSide(activeId, binStep, amountX, weights);
|
|
2316
|
+
for (const bin of amounts) {
|
|
2317
|
+
amountsInBin.push({
|
|
2318
|
+
binId: bin.binId,
|
|
2319
|
+
amountX: bin.amount,
|
|
2320
|
+
amountY: new import_bn10.default(0)
|
|
2321
|
+
});
|
|
2322
|
+
}
|
|
2323
|
+
}
|
|
2324
|
+
} else {
|
|
2325
|
+
if (minBinId < activeId) {
|
|
2326
|
+
const weights = toWeightAscendingOrder(minBinId, activeId - 1);
|
|
2327
|
+
const amountsIntoBidSide = toAmountBidSide(activeId, amountY, weights);
|
|
2328
|
+
for (const bin of amountsIntoBidSide) {
|
|
2329
|
+
amountsInBin.push({
|
|
2330
|
+
binId: bin.binId,
|
|
2331
|
+
amountX: new import_bn10.default(0),
|
|
2332
|
+
amountY: bin.amount
|
|
2333
|
+
});
|
|
2334
|
+
}
|
|
2335
|
+
}
|
|
2336
|
+
if (activeId <= maxBinId) {
|
|
2337
|
+
const weights = toWeightDecendingOrder(activeId, maxBinId);
|
|
2338
|
+
const amountsIntoAskSide = toAmountAskSide(activeId, binStep, amountX, weights);
|
|
2339
|
+
for (const bin of amountsIntoAskSide) {
|
|
2340
|
+
amountsInBin.push({
|
|
2341
|
+
binId: bin.binId,
|
|
2342
|
+
amountX: bin.amount,
|
|
2343
|
+
amountY: new import_bn10.default(0)
|
|
2344
|
+
});
|
|
2345
|
+
}
|
|
2346
|
+
}
|
|
2347
|
+
}
|
|
2348
|
+
return amountsInBin;
|
|
2349
|
+
}
|
|
2350
|
+
case 2 /* BidAsk */: {
|
|
2351
|
+
if (activeId < minBinId) {
|
|
2352
|
+
const weights = toWeightAscendingOrder(minBinId, maxBinId);
|
|
2353
|
+
return toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights);
|
|
2354
|
+
}
|
|
2355
|
+
if (activeId > maxBinId) {
|
|
2356
|
+
const weights = toWeightDecendingOrder(minBinId, maxBinId);
|
|
2357
|
+
return toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights);
|
|
2358
|
+
}
|
|
2359
|
+
const amountsInBin = [];
|
|
2360
|
+
if (!isSingleSideX) {
|
|
2361
|
+
if (minBinId <= activeId) {
|
|
2362
|
+
const weights = toWeightDecendingOrder(minBinId, activeId);
|
|
2363
|
+
const amounts = toAmountBidSide(activeId, amountY, weights);
|
|
2364
|
+
for (const bin of amounts) {
|
|
2365
|
+
amountsInBin.push({
|
|
2366
|
+
binId: bin.binId,
|
|
2367
|
+
amountX: new import_bn10.default(0),
|
|
2368
|
+
amountY: bin.amount
|
|
2369
|
+
});
|
|
2370
|
+
}
|
|
2371
|
+
}
|
|
2372
|
+
if (activeId < maxBinId) {
|
|
2373
|
+
const weights = toWeightAscendingOrder(activeId + 1, maxBinId);
|
|
2374
|
+
const amounts = toAmountAskSide(activeId, binStep, amountX, weights);
|
|
2375
|
+
for (const bin of amounts) {
|
|
2376
|
+
amountsInBin.push({
|
|
2377
|
+
binId: bin.binId,
|
|
2378
|
+
amountX: bin.amount,
|
|
2379
|
+
amountY: new import_bn10.default(0)
|
|
2380
|
+
});
|
|
2381
|
+
}
|
|
2382
|
+
}
|
|
2383
|
+
} else {
|
|
2384
|
+
if (minBinId < activeId) {
|
|
2385
|
+
const weights = toWeightDecendingOrder(minBinId, activeId - 1);
|
|
2386
|
+
const amountsIntoBidSide = toAmountBidSide(activeId, amountY, weights);
|
|
2387
|
+
for (const bin of amountsIntoBidSide) {
|
|
2388
|
+
amountsInBin.push({
|
|
2389
|
+
binId: bin.binId,
|
|
2390
|
+
amountX: new import_bn10.default(0),
|
|
2391
|
+
amountY: bin.amount
|
|
2392
|
+
});
|
|
2393
|
+
}
|
|
2394
|
+
}
|
|
2395
|
+
if (activeId <= maxBinId) {
|
|
2396
|
+
const weights = toWeightAscendingOrder(activeId, maxBinId);
|
|
2397
|
+
const amountsIntoAskSide = toAmountAskSide(activeId, binStep, amountX, weights);
|
|
2398
|
+
for (const bin of amountsIntoAskSide) {
|
|
2399
|
+
amountsInBin.push({
|
|
2400
|
+
binId: bin.binId,
|
|
2401
|
+
amountX: bin.amount,
|
|
2402
|
+
amountY: new import_bn10.default(0)
|
|
2403
|
+
});
|
|
2404
|
+
}
|
|
2405
|
+
}
|
|
2406
|
+
}
|
|
2407
|
+
return amountsInBin;
|
|
2408
|
+
}
|
|
2409
|
+
default:
|
|
2410
|
+
throw new Error(`Unsupported strategy type: ${strategyType}`);
|
|
2411
|
+
}
|
|
2412
|
+
}
|
|
2413
|
+
|
|
2414
|
+
// src/math/LiquidityHelper.ts
|
|
2415
|
+
var import_decimal8 = __toESM(require("decimal.js"));
|
|
2416
|
+
|
|
2417
|
+
// src/utils/numbers.ts
|
|
2418
|
+
var import_decimal7 = __toESM(require("decimal.js"));
|
|
2419
|
+
function d(value) {
|
|
2420
|
+
if (import_decimal7.default.isDecimal(value)) {
|
|
2421
|
+
return value;
|
|
2422
|
+
}
|
|
2423
|
+
return new import_decimal7.default(value === void 0 ? 0 : value);
|
|
2424
|
+
}
|
|
2425
|
+
function decimalsMultiplier(decimals) {
|
|
2426
|
+
return d(10).pow(d(decimals).abs());
|
|
2427
|
+
}
|
|
2428
|
+
|
|
2429
|
+
// src/math/LiquidityHelper.ts
|
|
2430
|
+
function withLiquiditySlippage(value, slippage, mode) {
|
|
2431
|
+
return d(value)[mode](d(value).mul(slippage)).toDP(0);
|
|
2432
|
+
}
|
|
2433
|
+
function getLiquidityAndCoinYByCoinX(coinInVal, reserveInSize, reserveOutSize, lpSupply) {
|
|
2434
|
+
if (coinInVal.lessThanOrEqualTo(0)) {
|
|
2435
|
+
throw new ClmmpoolsError("coinInVal is less than zero", "InvalidCoinAmount" /* InvalidCoinAmount */);
|
|
2436
|
+
}
|
|
2437
|
+
if (reserveInSize.lessThanOrEqualTo(0) || reserveOutSize.lessThanOrEqualTo(0)) {
|
|
2438
|
+
return -1;
|
|
2439
|
+
}
|
|
2440
|
+
const coinYAmount = coinInVal.mul(reserveOutSize).div(reserveInSize);
|
|
2441
|
+
const sqrtSupply = lpSupply;
|
|
2442
|
+
const lpX = coinInVal.div(reserveInSize).mul(sqrtSupply);
|
|
2443
|
+
const lpY = coinYAmount.div(reserveOutSize).mul(sqrtSupply);
|
|
2444
|
+
const lpAmount = import_decimal8.default.min(lpX, lpY);
|
|
2445
|
+
return {
|
|
2446
|
+
coinYAmount,
|
|
2447
|
+
lpAmount
|
|
2448
|
+
};
|
|
2449
|
+
}
|
|
2450
|
+
function getCoinXYForLiquidity(liquidity, reserveInSize, reserveOutSize, lpSuply) {
|
|
2451
|
+
if (liquidity.lessThanOrEqualTo(0)) {
|
|
2452
|
+
throw new ClmmpoolsError("liquidity can't be equal or less than zero", "InvalidLiquidityAmount" /* InvalidLiquidityAmount */);
|
|
2453
|
+
}
|
|
2454
|
+
if (reserveInSize.lessThanOrEqualTo(0) || reserveOutSize.lessThanOrEqualTo(0)) {
|
|
2455
|
+
throw new ClmmpoolsError("reserveInSize or reserveOutSize can not be equal or less than zero", "InvalidReserveAmount" /* InvalidReserveAmount */);
|
|
2456
|
+
}
|
|
2457
|
+
const sqrtSupply = lpSuply;
|
|
2458
|
+
const coinXAmount = liquidity.div(sqrtSupply).mul(reserveInSize);
|
|
2459
|
+
const coinYAmount = liquidity.div(sqrtSupply).mul(reserveOutSize);
|
|
2460
|
+
return {
|
|
2461
|
+
coinXAmount,
|
|
2462
|
+
coinYAmount
|
|
2463
|
+
};
|
|
2464
|
+
}
|
|
2465
|
+
|
|
2466
|
+
// src/math/percentage.ts
|
|
2467
|
+
var import_bn11 = __toESM(require("bn.js"));
|
|
1803
2468
|
var Percentage = class {
|
|
1804
2469
|
numerator;
|
|
1805
2470
|
denominator;
|
|
@@ -1827,8 +2492,8 @@ var Percentage = class {
|
|
|
1827
2492
|
* @returns
|
|
1828
2493
|
*/
|
|
1829
2494
|
static fromFraction(numerator, denominator) {
|
|
1830
|
-
const num = typeof numerator === "number" ? new
|
|
1831
|
-
const denom = typeof denominator === "number" ? new
|
|
2495
|
+
const num = typeof numerator === "number" ? new import_bn11.default(numerator.toString()) : numerator;
|
|
2496
|
+
const denom = typeof denominator === "number" ? new import_bn11.default(denominator.toString()) : denominator;
|
|
1832
2497
|
return new Percentage(num, denom);
|
|
1833
2498
|
}
|
|
1834
2499
|
};
|
|
@@ -1928,7 +2593,7 @@ function adjustForCoinSlippage(tokenAmount, slippage, adjustUp) {
|
|
|
1928
2593
|
}
|
|
1929
2594
|
|
|
1930
2595
|
// src/math/SplitSwap.ts
|
|
1931
|
-
var
|
|
2596
|
+
var import_bn12 = __toESM(require("bn.js"));
|
|
1932
2597
|
var SplitUnit = /* @__PURE__ */ ((SplitUnit2) => {
|
|
1933
2598
|
SplitUnit2[SplitUnit2["FIVE"] = 5] = "FIVE";
|
|
1934
2599
|
SplitUnit2[SplitUnit2["TEN"] = 10] = "TEN";
|
|
@@ -1986,7 +2651,7 @@ function updateSplitSwapResult(maxIndex, currentIndex, splitSwapResult, stepResu
|
|
|
1986
2651
|
return splitSwapResult;
|
|
1987
2652
|
}
|
|
1988
2653
|
function computeSplitSwap(a2b, byAmountIn, amounts, poolData, swapTicks) {
|
|
1989
|
-
let currentLiquidity = new
|
|
2654
|
+
let currentLiquidity = new import_bn12.default(poolData.liquidity);
|
|
1990
2655
|
let { currentSqrtPrice } = poolData;
|
|
1991
2656
|
let splitSwapResult = {
|
|
1992
2657
|
amountInArray: [],
|
|
@@ -2049,7 +2714,7 @@ function computeSplitSwap(a2b, byAmountIn, amounts, poolData, swapTicks) {
|
|
|
2049
2714
|
targetSqrtPrice,
|
|
2050
2715
|
currentLiquidity,
|
|
2051
2716
|
remainerAmount,
|
|
2052
|
-
new
|
|
2717
|
+
new import_bn12.default(poolData.feeRate),
|
|
2053
2718
|
byAmountIn
|
|
2054
2719
|
);
|
|
2055
2720
|
tempStepResult = stepResult;
|
|
@@ -2061,7 +2726,7 @@ function computeSplitSwap(a2b, byAmountIn, amounts, poolData, swapTicks) {
|
|
|
2061
2726
|
splitSwapResult.amountOutArray[i] = splitSwapResult.amountOutArray[i].add(stepResult.amountOut);
|
|
2062
2727
|
splitSwapResult.feeAmountArray[i] = splitSwapResult.feeAmountArray[i].add(stepResult.feeAmount);
|
|
2063
2728
|
if (stepResult.nextSqrtPrice.eq(tick.sqrtPrice)) {
|
|
2064
|
-
signedLiquidityChange = a2b ? tick.liquidityNet.mul(new
|
|
2729
|
+
signedLiquidityChange = a2b ? tick.liquidityNet.mul(new import_bn12.default(-1)) : tick.liquidityNet;
|
|
2065
2730
|
currentLiquidity = signedLiquidityChange.gt(ZERO) ? currentLiquidity.add(signedLiquidityChange) : currentLiquidity.sub(signedLiquidityChange.abs());
|
|
2066
2731
|
currentSqrtPrice = tick.sqrtPrice;
|
|
2067
2732
|
} else {
|
|
@@ -2086,7 +2751,7 @@ function computeSplitSwap(a2b, byAmountIn, amounts, poolData, swapTicks) {
|
|
|
2086
2751
|
break;
|
|
2087
2752
|
}
|
|
2088
2753
|
if (tempStepResult.nextSqrtPrice.eq(tick.sqrtPrice)) {
|
|
2089
|
-
signedLiquidityChange = a2b ? tick.liquidityNet.mul(new
|
|
2754
|
+
signedLiquidityChange = a2b ? tick.liquidityNet.mul(new import_bn12.default(-1)) : tick.liquidityNet;
|
|
2090
2755
|
currentLiquidity = signedLiquidityChange.gt(ZERO) ? currentLiquidity.add(signedLiquidityChange) : currentLiquidity.sub(signedLiquidityChange.abs());
|
|
2091
2756
|
currentSqrtPrice = tick.sqrtPrice;
|
|
2092
2757
|
} else {
|
|
@@ -2141,18 +2806,6 @@ var SplitSwap = class {
|
|
|
2141
2806
|
}
|
|
2142
2807
|
};
|
|
2143
2808
|
|
|
2144
|
-
// src/utils/numbers.ts
|
|
2145
|
-
var import_decimal6 = __toESM(require("decimal.js"));
|
|
2146
|
-
function d(value) {
|
|
2147
|
-
if (import_decimal6.default.isDecimal(value)) {
|
|
2148
|
-
return value;
|
|
2149
|
-
}
|
|
2150
|
-
return new import_decimal6.default(value === void 0 ? 0 : value);
|
|
2151
|
-
}
|
|
2152
|
-
function decimalsMultiplier(decimals) {
|
|
2153
|
-
return d(10).pow(d(decimals).abs());
|
|
2154
|
-
}
|
|
2155
|
-
|
|
2156
2809
|
// src/utils/objects.ts
|
|
2157
2810
|
function getSuiObjectData(resp) {
|
|
2158
2811
|
return resp.data;
|
|
@@ -2306,7 +2959,7 @@ function buildPool(objects) {
|
|
|
2306
2959
|
const rewarders = [];
|
|
2307
2960
|
fields.rewarder_manager.fields.rewarders.forEach((item) => {
|
|
2308
2961
|
const { emissions_per_second } = item.fields;
|
|
2309
|
-
const emissionSeconds = MathUtil.fromX64(new
|
|
2962
|
+
const emissionSeconds = MathUtil.fromX64(new import_bn13.default(emissions_per_second));
|
|
2310
2963
|
const emissionsEveryDay = Math.floor(emissionSeconds.toNumber() * 60 * 60 * 24);
|
|
2311
2964
|
rewarders.push({
|
|
2312
2965
|
emissions_per_second,
|
|
@@ -2498,11 +3151,11 @@ function buildTickData(objects) {
|
|
|
2498
3151
|
const possition = {
|
|
2499
3152
|
objectId: getObjectId(objects),
|
|
2500
3153
|
index: asIntN(BigInt(valueItem.index.fields.bits)),
|
|
2501
|
-
sqrtPrice: new
|
|
2502
|
-
liquidityNet: new
|
|
2503
|
-
liquidityGross: new
|
|
2504
|
-
feeGrowthOutsideA: new
|
|
2505
|
-
feeGrowthOutsideB: new
|
|
3154
|
+
sqrtPrice: new import_bn13.default(valueItem.sqrt_price),
|
|
3155
|
+
liquidityNet: new import_bn13.default(valueItem.liquidity_net.fields.bits),
|
|
3156
|
+
liquidityGross: new import_bn13.default(valueItem.liquidity_gross),
|
|
3157
|
+
feeGrowthOutsideA: new import_bn13.default(valueItem.fee_growth_outside_a),
|
|
3158
|
+
feeGrowthOutsideB: new import_bn13.default(valueItem.fee_growth_outside_b),
|
|
2506
3159
|
rewardersGrowthOutside: valueItem.rewards_growth_outside
|
|
2507
3160
|
};
|
|
2508
3161
|
return possition;
|
|
@@ -2512,11 +3165,11 @@ function buildTickDataByEvent(fields) {
|
|
|
2512
3165
|
throw new ClmmpoolsError(`Invalid tick fields.`, "InvalidTickFields" /* InvalidTickFields */);
|
|
2513
3166
|
}
|
|
2514
3167
|
const index = asIntN(BigInt(fields.index.bits));
|
|
2515
|
-
const sqrtPrice = new
|
|
2516
|
-
const liquidityNet = new
|
|
2517
|
-
const liquidityGross = new
|
|
2518
|
-
const feeGrowthOutsideA = new
|
|
2519
|
-
const feeGrowthOutsideB = new
|
|
3168
|
+
const sqrtPrice = new import_bn13.default(fields.sqrt_price);
|
|
3169
|
+
const liquidityNet = new import_bn13.default(fields.liquidity_net.bits);
|
|
3170
|
+
const liquidityGross = new import_bn13.default(fields.liquidity_gross);
|
|
3171
|
+
const feeGrowthOutsideA = new import_bn13.default(fields.fee_growth_outside_a);
|
|
3172
|
+
const feeGrowthOutsideB = new import_bn13.default(fields.fee_growth_outside_b);
|
|
2520
3173
|
const rewardersGrowthOutside = fields.rewards_growth_outside || [];
|
|
2521
3174
|
const tick = {
|
|
2522
3175
|
objectId: "",
|
|
@@ -2535,7 +3188,7 @@ function buildClmmPositionName(pool_index, position_index) {
|
|
|
2535
3188
|
}
|
|
2536
3189
|
|
|
2537
3190
|
// src/utils/tick.ts
|
|
2538
|
-
var
|
|
3191
|
+
var import_bn14 = __toESM(require("bn.js"));
|
|
2539
3192
|
var TickUtil = class {
|
|
2540
3193
|
/**
|
|
2541
3194
|
* Get min tick index.
|
|
@@ -2575,22 +3228,22 @@ function getRewardInTickRange(pool, tickLower, tickUpper, tickLowerIndex, tickUp
|
|
|
2575
3228
|
let rewarder_growth_below = growthGlobal[i];
|
|
2576
3229
|
if (tickLower !== null) {
|
|
2577
3230
|
if (pool.current_tick_index < tickLowerIndex) {
|
|
2578
|
-
rewarder_growth_below = growthGlobal[i].sub(new
|
|
3231
|
+
rewarder_growth_below = growthGlobal[i].sub(new import_bn14.default(tickLower.rewardersGrowthOutside[i]));
|
|
2579
3232
|
} else {
|
|
2580
3233
|
rewarder_growth_below = tickLower.rewardersGrowthOutside[i];
|
|
2581
3234
|
}
|
|
2582
3235
|
}
|
|
2583
|
-
let rewarder_growth_above = new
|
|
3236
|
+
let rewarder_growth_above = new import_bn14.default(0);
|
|
2584
3237
|
if (tickUpper !== null) {
|
|
2585
3238
|
if (pool.current_tick_index >= tickUpperIndex) {
|
|
2586
|
-
rewarder_growth_above = growthGlobal[i].sub(new
|
|
3239
|
+
rewarder_growth_above = growthGlobal[i].sub(new import_bn14.default(tickUpper.rewardersGrowthOutside[i]));
|
|
2587
3240
|
} else {
|
|
2588
3241
|
rewarder_growth_above = tickUpper.rewardersGrowthOutside[i];
|
|
2589
3242
|
}
|
|
2590
3243
|
}
|
|
2591
3244
|
const rewGrowthInside = MathUtil.subUnderflowU128(
|
|
2592
|
-
MathUtil.subUnderflowU128(new
|
|
2593
|
-
new
|
|
3245
|
+
MathUtil.subUnderflowU128(new import_bn14.default(growthGlobal[i]), new import_bn14.default(rewarder_growth_below)),
|
|
3246
|
+
new import_bn14.default(rewarder_growth_above)
|
|
2594
3247
|
);
|
|
2595
3248
|
rewarderGrowthInside.push(rewGrowthInside);
|
|
2596
3249
|
}
|
|
@@ -2598,8 +3251,8 @@ function getRewardInTickRange(pool, tickLower, tickUpper, tickLowerIndex, tickUp
|
|
|
2598
3251
|
}
|
|
2599
3252
|
|
|
2600
3253
|
// src/utils/transaction-util.ts
|
|
2601
|
-
var
|
|
2602
|
-
var
|
|
3254
|
+
var import_bn15 = __toESM(require("bn.js"));
|
|
3255
|
+
var import_decimal9 = __toESM(require("decimal.js"));
|
|
2603
3256
|
var import_transactions = require("@mysten/sui/transactions");
|
|
2604
3257
|
function findAdjustCoin(coinPair) {
|
|
2605
3258
|
const isAdjustCoinA = CoinAssist.isSuiCoin(coinPair.coinTypeA);
|
|
@@ -2607,7 +3260,7 @@ function findAdjustCoin(coinPair) {
|
|
|
2607
3260
|
return { isAdjustCoinA, isAdjustCoinB };
|
|
2608
3261
|
}
|
|
2609
3262
|
function reverSlippageAmount(slippageAmount, slippage) {
|
|
2610
|
-
return
|
|
3263
|
+
return import_decimal9.default.ceil(d(slippageAmount).div(1 + slippage)).toString();
|
|
2611
3264
|
}
|
|
2612
3265
|
async function printTransaction(tx, isPrint = true) {
|
|
2613
3266
|
console.log(`inputs`, tx.blockData.inputs);
|
|
@@ -2907,7 +3560,7 @@ var _TransactionUtil = class {
|
|
|
2907
3560
|
const liquidityInput = ClmmPoolUtil.estLiquidityAndcoinAmountFromOneAmounts(
|
|
2908
3561
|
Number(params.tick_lower),
|
|
2909
3562
|
Number(params.tick_upper),
|
|
2910
|
-
new
|
|
3563
|
+
new import_bn15.default(coinAmount),
|
|
2911
3564
|
params.fix_amount_a,
|
|
2912
3565
|
true,
|
|
2913
3566
|
slippage,
|
|
@@ -2981,12 +3634,12 @@ var _TransactionUtil = class {
|
|
|
2981
3634
|
max_amount_a = params.amount_a;
|
|
2982
3635
|
min_amount_a = params.amount_a;
|
|
2983
3636
|
max_amount_b = params.amount_b;
|
|
2984
|
-
min_amount_b = new
|
|
3637
|
+
min_amount_b = new import_decimal9.default(params.amount_b).div(new import_decimal9.default(1).plus(new import_decimal9.default(params.slippage))).mul(new import_decimal9.default(1).minus(new import_decimal9.default(params.slippage))).toDecimalPlaces(0).toNumber();
|
|
2985
3638
|
} else {
|
|
2986
3639
|
max_amount_b = params.amount_b;
|
|
2987
3640
|
min_amount_b = params.amount_b;
|
|
2988
3641
|
max_amount_a = params.amount_a;
|
|
2989
|
-
min_amount_a = new
|
|
3642
|
+
min_amount_a = new import_decimal9.default(params.amount_a).div(new import_decimal9.default(1).plus(new import_decimal9.default(params.slippage))).mul(new import_decimal9.default(1).minus(new import_decimal9.default(params.slippage))).toDecimalPlaces(0).toNumber();
|
|
2990
3643
|
}
|
|
2991
3644
|
const args = params.is_open ? [
|
|
2992
3645
|
tx.object(clmmConfig.global_config_id),
|
|
@@ -3975,7 +4628,7 @@ var _TransactionUtil = class {
|
|
|
3975
4628
|
const basePath = splitPath.basePaths[i];
|
|
3976
4629
|
a2b.push(basePath.direction);
|
|
3977
4630
|
poolAddress.push(basePath.poolAddress);
|
|
3978
|
-
rawAmountLimit.push(new
|
|
4631
|
+
rawAmountLimit.push(new import_bn15.default(basePath.inputAmount.toString()));
|
|
3979
4632
|
if (i === 0) {
|
|
3980
4633
|
coinType.push(basePath.fromCoin, basePath.toCoin);
|
|
3981
4634
|
} else {
|
|
@@ -3983,8 +4636,8 @@ var _TransactionUtil = class {
|
|
|
3983
4636
|
}
|
|
3984
4637
|
}
|
|
3985
4638
|
const onePath = {
|
|
3986
|
-
amountIn: new
|
|
3987
|
-
amountOut: new
|
|
4639
|
+
amountIn: new import_bn15.default(splitPath.inputAmount.toString()),
|
|
4640
|
+
amountOut: new import_bn15.default(splitPath.outputAmount.toString()),
|
|
3988
4641
|
poolAddress,
|
|
3989
4642
|
a2b,
|
|
3990
4643
|
rawAmountLimit,
|
|
@@ -4341,9 +4994,9 @@ var TxBlock = class {
|
|
|
4341
4994
|
};
|
|
4342
4995
|
|
|
4343
4996
|
// src/utils/deepbook-utils.ts
|
|
4344
|
-
var
|
|
4997
|
+
var import_bn16 = __toESM(require("bn.js"));
|
|
4345
4998
|
var import_transactions3 = require("@mysten/sui/transactions");
|
|
4346
|
-
var FLOAT_SCALING = new
|
|
4999
|
+
var FLOAT_SCALING = new import_bn16.default(1e9);
|
|
4347
5000
|
var DeepbookUtils = class {
|
|
4348
5001
|
static createAccountCap(senderAddress, sdkOptions, tx, isTransfer = false) {
|
|
4349
5002
|
if (senderAddress.length === 0) {
|
|
@@ -4489,9 +5142,9 @@ var DeepbookUtils = class {
|
|
|
4489
5142
|
static async preSwap(sdk, pool, a2b, amountIn) {
|
|
4490
5143
|
let isExceed = false;
|
|
4491
5144
|
let amountOut = ZERO;
|
|
4492
|
-
let remainAmount = new
|
|
5145
|
+
let remainAmount = new import_bn16.default(amountIn);
|
|
4493
5146
|
let feeAmount = ZERO;
|
|
4494
|
-
const initAmountIn = new
|
|
5147
|
+
const initAmountIn = new import_bn16.default(amountIn);
|
|
4495
5148
|
if (a2b) {
|
|
4496
5149
|
let bids = await this.getPoolBids(sdk, pool.poolID, pool.baseAsset, pool.quoteAsset);
|
|
4497
5150
|
if (bids === null) {
|
|
@@ -4501,16 +5154,16 @@ var DeepbookUtils = class {
|
|
|
4501
5154
|
return b.price - a.price;
|
|
4502
5155
|
});
|
|
4503
5156
|
for (let i = 0; i < bids.length; i += 1) {
|
|
4504
|
-
const curBidAmount = new
|
|
4505
|
-
const curBidPrice = new
|
|
4506
|
-
const fee = curBidAmount.mul(new
|
|
5157
|
+
const curBidAmount = new import_bn16.default(bids[i].quantity);
|
|
5158
|
+
const curBidPrice = new import_bn16.default(bids[i].price);
|
|
5159
|
+
const fee = curBidAmount.mul(new import_bn16.default(curBidPrice)).mul(new import_bn16.default(pool.takerFeeRate)).div(FLOAT_SCALING).div(FLOAT_SCALING);
|
|
4507
5160
|
if (remainAmount.gt(curBidAmount)) {
|
|
4508
5161
|
remainAmount = remainAmount.sub(curBidAmount);
|
|
4509
5162
|
amountOut = amountOut.add(curBidAmount.mul(curBidPrice).div(FLOAT_SCALING).sub(fee));
|
|
4510
5163
|
feeAmount = feeAmount.add(fee);
|
|
4511
5164
|
} else {
|
|
4512
|
-
const curOut = remainAmount.mul(new
|
|
4513
|
-
const curFee = curOut.mul(new
|
|
5165
|
+
const curOut = remainAmount.mul(new import_bn16.default(bids[i].price)).div(FLOAT_SCALING);
|
|
5166
|
+
const curFee = curOut.mul(new import_bn16.default(pool.takerFeeRate)).div(FLOAT_SCALING);
|
|
4514
5167
|
amountOut = amountOut.add(curOut.sub(curFee));
|
|
4515
5168
|
remainAmount = remainAmount.sub(remainAmount);
|
|
4516
5169
|
feeAmount = feeAmount.add(curFee);
|
|
@@ -4525,15 +5178,15 @@ var DeepbookUtils = class {
|
|
|
4525
5178
|
isExceed = true;
|
|
4526
5179
|
}
|
|
4527
5180
|
for (let i = 0; i < asks.length; i += 1) {
|
|
4528
|
-
const curAskAmount = new
|
|
4529
|
-
const fee = curAskAmount.mul(new
|
|
5181
|
+
const curAskAmount = new import_bn16.default(asks[i].price).mul(new import_bn16.default(asks[i].quantity)).div(new import_bn16.default(1e9));
|
|
5182
|
+
const fee = curAskAmount.mul(new import_bn16.default(pool.takerFeeRate)).div(FLOAT_SCALING);
|
|
4530
5183
|
const curAskAmountWithFee = curAskAmount.add(fee);
|
|
4531
5184
|
if (remainAmount.gt(curAskAmount)) {
|
|
4532
|
-
amountOut = amountOut.add(new
|
|
5185
|
+
amountOut = amountOut.add(new import_bn16.default(asks[i].quantity));
|
|
4533
5186
|
remainAmount = remainAmount.sub(curAskAmountWithFee);
|
|
4534
5187
|
feeAmount = feeAmount.add(fee);
|
|
4535
5188
|
} else {
|
|
4536
|
-
const splitNums = new
|
|
5189
|
+
const splitNums = new import_bn16.default(asks[i].quantity).div(new import_bn16.default(pool.lotSize));
|
|
4537
5190
|
const splitAmount = curAskAmountWithFee.div(splitNums);
|
|
4538
5191
|
const swapSplitNum = remainAmount.div(splitAmount);
|
|
4539
5192
|
amountOut = amountOut.add(swapSplitNum.muln(pool.lotSize));
|
|
@@ -5394,7 +6047,7 @@ var PoolModule = class {
|
|
|
5394
6047
|
};
|
|
5395
6048
|
|
|
5396
6049
|
// src/modules/positionModule.ts
|
|
5397
|
-
var
|
|
6050
|
+
var import_bn17 = __toESM(require("bn.js"));
|
|
5398
6051
|
var import_transactions5 = require("@mysten/sui/transactions");
|
|
5399
6052
|
var import_utils15 = require("@mysten/sui/utils");
|
|
5400
6053
|
var PositionModule = class {
|
|
@@ -5616,8 +6269,8 @@ var PositionModule = class {
|
|
|
5616
6269
|
for (let i = 0; i < valueData.length; i += 1) {
|
|
5617
6270
|
const { parsedJson } = valueData[i];
|
|
5618
6271
|
const posRrewarderResult = {
|
|
5619
|
-
feeOwedA: new
|
|
5620
|
-
feeOwedB: new
|
|
6272
|
+
feeOwedA: new import_bn17.default(parsedJson.fee_owned_a),
|
|
6273
|
+
feeOwedB: new import_bn17.default(parsedJson.fee_owned_b),
|
|
5621
6274
|
position_id: parsedJson.position_id
|
|
5622
6275
|
};
|
|
5623
6276
|
result.push(posRrewarderResult);
|
|
@@ -5993,7 +6646,7 @@ var PositionModule = class {
|
|
|
5993
6646
|
};
|
|
5994
6647
|
|
|
5995
6648
|
// src/modules/rewarderModule.ts
|
|
5996
|
-
var
|
|
6649
|
+
var import_bn18 = __toESM(require("bn.js"));
|
|
5997
6650
|
var import_transactions6 = require("@mysten/sui/transactions");
|
|
5998
6651
|
var RewarderModule = class {
|
|
5999
6652
|
_sdk;
|
|
@@ -6019,7 +6672,7 @@ var RewarderModule = class {
|
|
|
6019
6672
|
}
|
|
6020
6673
|
const emissionsEveryDay = [];
|
|
6021
6674
|
for (const rewarderInfo of rewarderInfos) {
|
|
6022
|
-
const emissionSeconds = MathUtil.fromX64(new
|
|
6675
|
+
const emissionSeconds = MathUtil.fromX64(new import_bn18.default(rewarderInfo.emissions_per_second));
|
|
6023
6676
|
emissionsEveryDay.push({
|
|
6024
6677
|
emissions: Math.floor(emissionSeconds.toNumber() * 60 * 60 * 24),
|
|
6025
6678
|
coin_address: rewarderInfo.coinAddress
|
|
@@ -6038,20 +6691,20 @@ var RewarderModule = class {
|
|
|
6038
6691
|
const currentPool = await this.sdk.Pool.getPool(poolID);
|
|
6039
6692
|
const lastTime = currentPool.rewarder_last_updated_time;
|
|
6040
6693
|
currentPool.rewarder_last_updated_time = currentTime.toString();
|
|
6041
|
-
if (Number(currentPool.liquidity) === 0 || currentTime.eq(new
|
|
6694
|
+
if (Number(currentPool.liquidity) === 0 || currentTime.eq(new import_bn18.default(lastTime))) {
|
|
6042
6695
|
return currentPool;
|
|
6043
6696
|
}
|
|
6044
|
-
const timeDelta = currentTime.div(new
|
|
6697
|
+
const timeDelta = currentTime.div(new import_bn18.default(1e3)).sub(new import_bn18.default(lastTime)).add(new import_bn18.default(15));
|
|
6045
6698
|
const rewarderInfos = currentPool.rewarder_infos;
|
|
6046
6699
|
for (let i = 0; i < rewarderInfos.length; i += 1) {
|
|
6047
6700
|
const rewarderInfo = rewarderInfos[i];
|
|
6048
6701
|
const rewarderGrowthDelta = MathUtil.checkMulDivFloor(
|
|
6049
6702
|
timeDelta,
|
|
6050
|
-
new
|
|
6051
|
-
new
|
|
6703
|
+
new import_bn18.default(rewarderInfo.emissions_per_second),
|
|
6704
|
+
new import_bn18.default(currentPool.liquidity),
|
|
6052
6705
|
128
|
|
6053
6706
|
);
|
|
6054
|
-
this.growthGlobal[i] = new
|
|
6707
|
+
this.growthGlobal[i] = new import_bn18.default(rewarderInfo.growth_global).add(new import_bn18.default(rewarderGrowthDelta));
|
|
6055
6708
|
}
|
|
6056
6709
|
return currentPool;
|
|
6057
6710
|
}
|
|
@@ -6066,7 +6719,7 @@ var RewarderModule = class {
|
|
|
6066
6719
|
*/
|
|
6067
6720
|
async posRewardersAmount(poolID, positionHandle, positionID) {
|
|
6068
6721
|
const currentTime = Date.parse((/* @__PURE__ */ new Date()).toString());
|
|
6069
|
-
const pool = await this.updatePoolRewarder(poolID, new
|
|
6722
|
+
const pool = await this.updatePoolRewarder(poolID, new import_bn18.default(currentTime));
|
|
6070
6723
|
const position = await this.sdk.Position.getPositionRewarders(positionHandle, positionID);
|
|
6071
6724
|
if (position === void 0) {
|
|
6072
6725
|
return [];
|
|
@@ -6087,7 +6740,7 @@ var RewarderModule = class {
|
|
|
6087
6740
|
*/
|
|
6088
6741
|
async poolRewardersAmount(accountAddress, poolID) {
|
|
6089
6742
|
const currentTime = Date.parse((/* @__PURE__ */ new Date()).toString());
|
|
6090
|
-
const pool = await this.updatePoolRewarder(poolID, new
|
|
6743
|
+
const pool = await this.updatePoolRewarder(poolID, new import_bn18.default(currentTime));
|
|
6091
6744
|
const positions = await this.sdk.Position.getPositionList(accountAddress, [poolID]);
|
|
6092
6745
|
const tickDatas = await this.getPoolLowerAndUpperTicks(pool.ticks_handle, positions);
|
|
6093
6746
|
const rewarderAmount = [ZERO, ZERO, ZERO];
|
|
@@ -6114,38 +6767,38 @@ var RewarderModule = class {
|
|
|
6114
6767
|
const growthInside = [];
|
|
6115
6768
|
const AmountOwed = [];
|
|
6116
6769
|
if (rewardersInside.length > 0) {
|
|
6117
|
-
let growthDelta0 = MathUtil.subUnderflowU128(rewardersInside[0], new
|
|
6118
|
-
if (growthDelta0.gt(new
|
|
6770
|
+
let growthDelta0 = MathUtil.subUnderflowU128(rewardersInside[0], new import_bn18.default(position.reward_growth_inside_0));
|
|
6771
|
+
if (growthDelta0.gt(new import_bn18.default("3402823669209384634633745948738404"))) {
|
|
6119
6772
|
growthDelta0 = ONE;
|
|
6120
6773
|
}
|
|
6121
|
-
const amountOwed_0 = MathUtil.checkMulShiftRight(new
|
|
6774
|
+
const amountOwed_0 = MathUtil.checkMulShiftRight(new import_bn18.default(position.liquidity), growthDelta0, 64, 128);
|
|
6122
6775
|
growthInside.push(rewardersInside[0]);
|
|
6123
6776
|
AmountOwed.push({
|
|
6124
|
-
amount_owed: new
|
|
6777
|
+
amount_owed: new import_bn18.default(position.reward_amount_owed_0).add(amountOwed_0),
|
|
6125
6778
|
coin_address: pool.rewarder_infos[0].coinAddress
|
|
6126
6779
|
});
|
|
6127
6780
|
}
|
|
6128
6781
|
if (rewardersInside.length > 1) {
|
|
6129
|
-
let growthDelta_1 = MathUtil.subUnderflowU128(rewardersInside[1], new
|
|
6130
|
-
if (growthDelta_1.gt(new
|
|
6782
|
+
let growthDelta_1 = MathUtil.subUnderflowU128(rewardersInside[1], new import_bn18.default(position.reward_growth_inside_1));
|
|
6783
|
+
if (growthDelta_1.gt(new import_bn18.default("3402823669209384634633745948738404"))) {
|
|
6131
6784
|
growthDelta_1 = ONE;
|
|
6132
6785
|
}
|
|
6133
|
-
const amountOwed_1 = MathUtil.checkMulShiftRight(new
|
|
6786
|
+
const amountOwed_1 = MathUtil.checkMulShiftRight(new import_bn18.default(position.liquidity), growthDelta_1, 64, 128);
|
|
6134
6787
|
growthInside.push(rewardersInside[1]);
|
|
6135
6788
|
AmountOwed.push({
|
|
6136
|
-
amount_owed: new
|
|
6789
|
+
amount_owed: new import_bn18.default(position.reward_amount_owed_1).add(amountOwed_1),
|
|
6137
6790
|
coin_address: pool.rewarder_infos[1].coinAddress
|
|
6138
6791
|
});
|
|
6139
6792
|
}
|
|
6140
6793
|
if (rewardersInside.length > 2) {
|
|
6141
|
-
let growthDelta_2 = MathUtil.subUnderflowU128(rewardersInside[2], new
|
|
6142
|
-
if (growthDelta_2.gt(new
|
|
6794
|
+
let growthDelta_2 = MathUtil.subUnderflowU128(rewardersInside[2], new import_bn18.default(position.reward_growth_inside_2));
|
|
6795
|
+
if (growthDelta_2.gt(new import_bn18.default("3402823669209384634633745948738404"))) {
|
|
6143
6796
|
growthDelta_2 = ONE;
|
|
6144
6797
|
}
|
|
6145
|
-
const amountOwed_2 = MathUtil.checkMulShiftRight(new
|
|
6798
|
+
const amountOwed_2 = MathUtil.checkMulShiftRight(new import_bn18.default(position.liquidity), growthDelta_2, 64, 128);
|
|
6146
6799
|
growthInside.push(rewardersInside[2]);
|
|
6147
6800
|
AmountOwed.push({
|
|
6148
|
-
amount_owed: new
|
|
6801
|
+
amount_owed: new import_bn18.default(position.reward_amount_owed_2).add(amountOwed_2),
|
|
6149
6802
|
coin_address: pool.rewarder_infos[2].coinAddress
|
|
6150
6803
|
});
|
|
6151
6804
|
}
|
|
@@ -6259,8 +6912,8 @@ var RewarderModule = class {
|
|
|
6259
6912
|
for (let i = 0; i < valueData.length; i += 1) {
|
|
6260
6913
|
const { parsedJson } = valueData[i];
|
|
6261
6914
|
const posRrewarderResult = {
|
|
6262
|
-
feeOwedA: new
|
|
6263
|
-
feeOwedB: new
|
|
6915
|
+
feeOwedA: new import_bn18.default(parsedJson.fee_owned_a),
|
|
6916
|
+
feeOwedB: new import_bn18.default(parsedJson.fee_owned_b),
|
|
6264
6917
|
position_id: parsedJson.position_id
|
|
6265
6918
|
};
|
|
6266
6919
|
result.push(posRrewarderResult);
|
|
@@ -6323,7 +6976,7 @@ var RewarderModule = class {
|
|
|
6323
6976
|
};
|
|
6324
6977
|
for (let j = 0; j < params[i].rewarderInfo.length; j += 1) {
|
|
6325
6978
|
posRrewarderResult.rewarderAmountOwed.push({
|
|
6326
|
-
amount_owed: new
|
|
6979
|
+
amount_owed: new import_bn18.default(valueData[i].parsedJson.data[j]),
|
|
6327
6980
|
coin_address: params[i].rewarderInfo[j].coinAddress
|
|
6328
6981
|
});
|
|
6329
6982
|
}
|
|
@@ -6512,7 +7165,7 @@ var RewarderModule = class {
|
|
|
6512
7165
|
};
|
|
6513
7166
|
|
|
6514
7167
|
// src/modules/routerModule.ts
|
|
6515
|
-
var
|
|
7168
|
+
var import_bn19 = __toESM(require("bn.js"));
|
|
6516
7169
|
var import_cc_graph = require("@syntsugar/cc-graph");
|
|
6517
7170
|
var import_transactions7 = require("@mysten/sui/transactions");
|
|
6518
7171
|
function _pairSymbol(base, quote) {
|
|
@@ -6794,8 +7447,8 @@ var RouterModule = class {
|
|
|
6794
7447
|
if (swapWithMultiPoolParams != null) {
|
|
6795
7448
|
const preSwapResult2 = await this.sdk.Swap.preSwapWithMultiPool(swapWithMultiPoolParams);
|
|
6796
7449
|
const onePath2 = {
|
|
6797
|
-
amountIn: new
|
|
6798
|
-
amountOut: new
|
|
7450
|
+
amountIn: new import_bn19.default(preSwapResult2.estimatedAmountIn),
|
|
7451
|
+
amountOut: new import_bn19.default(preSwapResult2.estimatedAmountOut),
|
|
6799
7452
|
poolAddress: [preSwapResult2.poolAddress],
|
|
6800
7453
|
a2b: [preSwapResult2.aToB],
|
|
6801
7454
|
rawAmountLimit: byAmountIn ? [preSwapResult2.estimatedAmountOut] : [preSwapResult2.estimatedAmountIn],
|
|
@@ -6808,8 +7461,8 @@ var RouterModule = class {
|
|
|
6808
7461
|
priceSlippagePoint
|
|
6809
7462
|
};
|
|
6810
7463
|
const result2 = {
|
|
6811
|
-
amountIn: new
|
|
6812
|
-
amountOut: new
|
|
7464
|
+
amountIn: new import_bn19.default(preSwapResult2.estimatedAmountIn),
|
|
7465
|
+
amountOut: new import_bn19.default(preSwapResult2.estimatedAmountOut),
|
|
6813
7466
|
paths: [onePath2],
|
|
6814
7467
|
a2b: preSwapResult2.aToB,
|
|
6815
7468
|
b2c: void 0,
|
|
@@ -6831,8 +7484,8 @@ var RouterModule = class {
|
|
|
6831
7484
|
if (swapWithMultiPoolParams != null) {
|
|
6832
7485
|
const preSwapResult2 = await this.sdk.Swap.preSwapWithMultiPool(swapWithMultiPoolParams);
|
|
6833
7486
|
const onePath2 = {
|
|
6834
|
-
amountIn: new
|
|
6835
|
-
amountOut: new
|
|
7487
|
+
amountIn: new import_bn19.default(preSwapResult2.estimatedAmountIn),
|
|
7488
|
+
amountOut: new import_bn19.default(preSwapResult2.estimatedAmountOut),
|
|
6836
7489
|
poolAddress: [preSwapResult2.poolAddress],
|
|
6837
7490
|
a2b: [preSwapResult2.aToB],
|
|
6838
7491
|
rawAmountLimit: byAmountIn ? [preSwapResult2.estimatedAmountOut] : [preSwapResult2.estimatedAmountIn],
|
|
@@ -6845,8 +7498,8 @@ var RouterModule = class {
|
|
|
6845
7498
|
priceSlippagePoint
|
|
6846
7499
|
};
|
|
6847
7500
|
const result3 = {
|
|
6848
|
-
amountIn: new
|
|
6849
|
-
amountOut: new
|
|
7501
|
+
amountIn: new import_bn19.default(preSwapResult2.estimatedAmountIn),
|
|
7502
|
+
amountOut: new import_bn19.default(preSwapResult2.estimatedAmountOut),
|
|
6850
7503
|
paths: [onePath2],
|
|
6851
7504
|
a2b: preSwapResult2.aToB,
|
|
6852
7505
|
b2c: void 0,
|
|
@@ -6927,8 +7580,8 @@ var RouterModule = class {
|
|
|
6927
7580
|
if (swapWithMultiPoolParams != null) {
|
|
6928
7581
|
const preSwapResult = await this.sdk.Swap.preSwapWithMultiPool(swapWithMultiPoolParams);
|
|
6929
7582
|
const onePath = {
|
|
6930
|
-
amountIn: new
|
|
6931
|
-
amountOut: new
|
|
7583
|
+
amountIn: new import_bn19.default(preSwapResult.estimatedAmountIn),
|
|
7584
|
+
amountOut: new import_bn19.default(preSwapResult.estimatedAmountOut),
|
|
6932
7585
|
poolAddress: [preSwapResult.poolAddress],
|
|
6933
7586
|
a2b: [preSwapResult.aToB],
|
|
6934
7587
|
rawAmountLimit: byAmountIn ? [preSwapResult.estimatedAmountOut] : [preSwapResult.estimatedAmountIn],
|
|
@@ -6941,8 +7594,8 @@ var RouterModule = class {
|
|
|
6941
7594
|
priceSlippagePoint
|
|
6942
7595
|
};
|
|
6943
7596
|
const result = {
|
|
6944
|
-
amountIn: new
|
|
6945
|
-
amountOut: new
|
|
7597
|
+
amountIn: new import_bn19.default(preSwapResult.estimatedAmountIn),
|
|
7598
|
+
amountOut: new import_bn19.default(preSwapResult.estimatedAmountOut),
|
|
6946
7599
|
paths: [onePath],
|
|
6947
7600
|
a2b: preSwapResult.aToB,
|
|
6948
7601
|
b2c: void 0,
|
|
@@ -7026,13 +7679,13 @@ var RouterModule = class {
|
|
|
7026
7679
|
continue;
|
|
7027
7680
|
}
|
|
7028
7681
|
if (params[0].byAmountIn) {
|
|
7029
|
-
const amount = new
|
|
7682
|
+
const amount = new import_bn19.default(valueData[i].parsedJson.data.amount_out);
|
|
7030
7683
|
if (amount.gt(tempMaxAmount)) {
|
|
7031
7684
|
tempIndex = i;
|
|
7032
7685
|
tempMaxAmount = amount;
|
|
7033
7686
|
}
|
|
7034
7687
|
} else {
|
|
7035
|
-
const amount = params[i].stepNums > 1 ? new
|
|
7688
|
+
const amount = params[i].stepNums > 1 ? new import_bn19.default(valueData[i].parsedJson.data.amount_in) : new import_bn19.default(valueData[i].parsedJson.data.amount_in).add(new import_bn19.default(valueData[i].parsedJson.data.fee_amount));
|
|
7036
7689
|
if (amount.lt(tempMaxAmount)) {
|
|
7037
7690
|
tempIndex = i;
|
|
7038
7691
|
tempMaxAmount = amount;
|
|
@@ -7102,8 +7755,8 @@ var RouterModule = class {
|
|
|
7102
7755
|
};
|
|
7103
7756
|
|
|
7104
7757
|
// src/modules/swapModule.ts
|
|
7105
|
-
var
|
|
7106
|
-
var
|
|
7758
|
+
var import_bn20 = __toESM(require("bn.js"));
|
|
7759
|
+
var import_decimal10 = __toESM(require("decimal.js"));
|
|
7107
7760
|
var import_transactions8 = require("@mysten/sui/transactions");
|
|
7108
7761
|
var AMM_SWAP_MODULE = "amm_swap";
|
|
7109
7762
|
var POOL_STRUCT = "Pool";
|
|
@@ -7121,14 +7774,14 @@ var SwapModule = class {
|
|
|
7121
7774
|
const pathCount = item.basePaths.length;
|
|
7122
7775
|
if (pathCount > 0) {
|
|
7123
7776
|
const path = item.basePaths[0];
|
|
7124
|
-
const feeRate = path.label === "Magma" ? new
|
|
7777
|
+
const feeRate = path.label === "Magma" ? new import_decimal10.default(path.feeRate).div(10 ** 6) : new import_decimal10.default(path.feeRate).div(10 ** 9);
|
|
7125
7778
|
const feeAmount = d(path.inputAmount).div(10 ** path.fromDecimal).mul(feeRate);
|
|
7126
7779
|
fee = fee.add(feeAmount);
|
|
7127
7780
|
if (pathCount > 1) {
|
|
7128
7781
|
const path2 = item.basePaths[1];
|
|
7129
|
-
const price1 = path.direction ? path.currentPrice : new
|
|
7130
|
-
const price2 = path2.direction ? path2.currentPrice : new
|
|
7131
|
-
const feeRate2 = path2.label === "Magma" ? new
|
|
7782
|
+
const price1 = path.direction ? path.currentPrice : new import_decimal10.default(1).div(path.currentPrice);
|
|
7783
|
+
const price2 = path2.direction ? path2.currentPrice : new import_decimal10.default(1).div(path2.currentPrice);
|
|
7784
|
+
const feeRate2 = path2.label === "Magma" ? new import_decimal10.default(path2.feeRate).div(10 ** 6) : new import_decimal10.default(path2.feeRate).div(10 ** 9);
|
|
7132
7785
|
const feeAmount2 = d(path2.outputAmount).div(10 ** path2.toDecimal).mul(feeRate2);
|
|
7133
7786
|
const fee2 = feeAmount2.div(price1.mul(price2));
|
|
7134
7787
|
fee = fee.add(fee2);
|
|
@@ -7146,17 +7799,17 @@ var SwapModule = class {
|
|
|
7146
7799
|
const outputAmount = d(path.outputAmount).div(10 ** path.toDecimal);
|
|
7147
7800
|
const inputAmount = d(path.inputAmount).div(10 ** path.fromDecimal);
|
|
7148
7801
|
const rate = outputAmount.div(inputAmount);
|
|
7149
|
-
const cprice = path.direction ? new
|
|
7802
|
+
const cprice = path.direction ? new import_decimal10.default(path.currentPrice) : new import_decimal10.default(1).div(path.currentPrice);
|
|
7150
7803
|
impactValue = impactValue.add(this.calculateSingleImpact(rate, cprice));
|
|
7151
7804
|
}
|
|
7152
7805
|
if (pathCount === 2) {
|
|
7153
7806
|
const path = item.basePaths[0];
|
|
7154
7807
|
const path2 = item.basePaths[1];
|
|
7155
|
-
const cprice1 = path.direction ? new
|
|
7156
|
-
const cprice2 = path2.direction ? new
|
|
7808
|
+
const cprice1 = path.direction ? new import_decimal10.default(path.currentPrice) : new import_decimal10.default(1).div(path.currentPrice);
|
|
7809
|
+
const cprice2 = path2.direction ? new import_decimal10.default(path2.currentPrice) : new import_decimal10.default(1).div(path2.currentPrice);
|
|
7157
7810
|
const cprice = cprice1.mul(cprice2);
|
|
7158
|
-
const outputAmount = new
|
|
7159
|
-
const inputAmount = new
|
|
7811
|
+
const outputAmount = new import_decimal10.default(path2.outputAmount).div(10 ** path2.toDecimal);
|
|
7812
|
+
const inputAmount = new import_decimal10.default(path.inputAmount).div(10 ** path.fromDecimal);
|
|
7160
7813
|
const rate = outputAmount.div(inputAmount);
|
|
7161
7814
|
impactValue = impactValue.add(this.calculateSingleImpact(rate, cprice));
|
|
7162
7815
|
}
|
|
@@ -7218,13 +7871,13 @@ var SwapModule = class {
|
|
|
7218
7871
|
continue;
|
|
7219
7872
|
}
|
|
7220
7873
|
if (params.byAmountIn) {
|
|
7221
|
-
const amount = new
|
|
7874
|
+
const amount = new import_bn20.default(valueData[i].parsedJson.data.amount_out);
|
|
7222
7875
|
if (amount.gt(tempMaxAmount)) {
|
|
7223
7876
|
tempIndex = i;
|
|
7224
7877
|
tempMaxAmount = amount;
|
|
7225
7878
|
}
|
|
7226
7879
|
} else {
|
|
7227
|
-
const amount = new
|
|
7880
|
+
const amount = new import_bn20.default(valueData[i].parsedJson.data.amount_out);
|
|
7228
7881
|
if (amount.lt(tempMaxAmount)) {
|
|
7229
7882
|
tempIndex = i;
|
|
7230
7883
|
tempMaxAmount = amount;
|
|
@@ -7288,7 +7941,7 @@ var SwapModule = class {
|
|
|
7288
7941
|
return this.transformSwapData(params, valueData[0].parsedJson.data);
|
|
7289
7942
|
}
|
|
7290
7943
|
transformSwapData(params, data) {
|
|
7291
|
-
const estimatedAmountIn = data.amount_in && data.fee_amount ? new
|
|
7944
|
+
const estimatedAmountIn = data.amount_in && data.fee_amount ? new import_bn20.default(data.amount_in).add(new import_bn20.default(data.fee_amount)).toString() : "";
|
|
7292
7945
|
return {
|
|
7293
7946
|
poolAddress: params.pool.poolAddress,
|
|
7294
7947
|
currentSqrtPrice: params.currentSqrtPrice,
|
|
@@ -7305,7 +7958,7 @@ var SwapModule = class {
|
|
|
7305
7958
|
transformSwapWithMultiPoolData(params, jsonData) {
|
|
7306
7959
|
const { data } = jsonData;
|
|
7307
7960
|
console.log("json data. ", data);
|
|
7308
|
-
const estimatedAmountIn = data.amount_in && data.fee_amount ? new
|
|
7961
|
+
const estimatedAmountIn = data.amount_in && data.fee_amount ? new import_bn20.default(data.amount_in).add(new import_bn20.default(data.fee_amount)).toString() : "";
|
|
7309
7962
|
return {
|
|
7310
7963
|
poolAddress: params.poolAddress,
|
|
7311
7964
|
estimatedAmountIn,
|
|
@@ -8818,8 +9471,8 @@ var TokenModule = class {
|
|
|
8818
9471
|
};
|
|
8819
9472
|
|
|
8820
9473
|
// src/modules/routerModuleV2.ts
|
|
8821
|
-
var
|
|
8822
|
-
var
|
|
9474
|
+
var import_bn21 = __toESM(require("bn.js"));
|
|
9475
|
+
var import_decimal11 = __toESM(require("decimal.js"));
|
|
8823
9476
|
var import_uuid = require("uuid");
|
|
8824
9477
|
var import_axios = __toESM(require("axios"));
|
|
8825
9478
|
var RouterModuleV2 = class {
|
|
@@ -8836,7 +9489,7 @@ var RouterModuleV2 = class {
|
|
|
8836
9489
|
if (label === "Magma") {
|
|
8837
9490
|
return TickMath.sqrtPriceX64ToPrice(currentSqrtPrice, decimalA, decimalB);
|
|
8838
9491
|
}
|
|
8839
|
-
return new
|
|
9492
|
+
return new import_decimal11.default(currentSqrtPrice.toString()).div(new import_decimal11.default(10).pow(new import_decimal11.default(decimalB + 9 - decimalA)));
|
|
8840
9493
|
}
|
|
8841
9494
|
parseJsonResult(data) {
|
|
8842
9495
|
const result = {
|
|
@@ -8862,12 +9515,12 @@ var RouterModuleV2 = class {
|
|
|
8862
9515
|
outputAmount: basePath.output_amount,
|
|
8863
9516
|
inputAmount: basePath.input_amount,
|
|
8864
9517
|
feeRate: basePath.fee_rate,
|
|
8865
|
-
currentSqrtPrice: new
|
|
8866
|
-
afterSqrtPrice: basePath.label === "Magma" ? new
|
|
9518
|
+
currentSqrtPrice: new import_bn21.default(basePath.current_sqrt_price.toString()),
|
|
9519
|
+
afterSqrtPrice: basePath.label === "Magma" ? new import_bn21.default(basePath.after_sqrt_price.toString()) : ZERO,
|
|
8867
9520
|
fromDecimal: basePath.from_decimal,
|
|
8868
9521
|
toDecimal: basePath.to_decimal,
|
|
8869
9522
|
currentPrice: this.calculatePrice(
|
|
8870
|
-
new
|
|
9523
|
+
new import_bn21.default(basePath.current_sqrt_price.toString()),
|
|
8871
9524
|
basePath.from_decimal,
|
|
8872
9525
|
basePath.to_decimal,
|
|
8873
9526
|
basePath.direction,
|
|
@@ -8950,7 +9603,7 @@ var RouterModuleV2 = class {
|
|
|
8950
9603
|
const priceResult = await this.sdk.Router.priceUseV1(
|
|
8951
9604
|
from,
|
|
8952
9605
|
to,
|
|
8953
|
-
new
|
|
9606
|
+
new import_bn21.default(amount),
|
|
8954
9607
|
byAmountIn,
|
|
8955
9608
|
priceSplitPoint,
|
|
8956
9609
|
partner,
|
|
@@ -8962,7 +9615,7 @@ var RouterModuleV2 = class {
|
|
|
8962
9615
|
if (path.poolAddress.length > 1) {
|
|
8963
9616
|
const fromDecimal0 = this.sdk.Router.tokenInfo(path.coinType[0]).decimals;
|
|
8964
9617
|
const toDecimal0 = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
|
|
8965
|
-
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new
|
|
9618
|
+
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new import_bn21.default(priceResult.currentSqrtPrice[0]), fromDecimal0, toDecimal0) : TickMath.sqrtPriceX64ToPrice(new import_bn21.default(priceResult.currentSqrtPrice[0]), toDecimal0, fromDecimal0);
|
|
8966
9619
|
const path0 = {
|
|
8967
9620
|
direction: path.a2b[0],
|
|
8968
9621
|
label: "Magma",
|
|
@@ -8979,7 +9632,7 @@ var RouterModuleV2 = class {
|
|
|
8979
9632
|
};
|
|
8980
9633
|
const fromDecimal1 = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
|
|
8981
9634
|
const toDecimal1 = this.sdk.Router.tokenInfo(path.coinType[2]).decimals;
|
|
8982
|
-
const currentPrice1 = path.a2b[1] ? TickMath.sqrtPriceX64ToPrice(new
|
|
9635
|
+
const currentPrice1 = path.a2b[1] ? TickMath.sqrtPriceX64ToPrice(new import_bn21.default(priceResult.currentSqrtPrice[1]), fromDecimal1, toDecimal1) : TickMath.sqrtPriceX64ToPrice(new import_bn21.default(priceResult.currentSqrtPrice[1]), toDecimal1, fromDecimal1);
|
|
8983
9636
|
const path1 = {
|
|
8984
9637
|
direction: path.a2b[1],
|
|
8985
9638
|
label: "Magma",
|
|
@@ -8998,7 +9651,7 @@ var RouterModuleV2 = class {
|
|
|
8998
9651
|
} else {
|
|
8999
9652
|
const fromDecimal = this.sdk.Router.tokenInfo(path.coinType[0]).decimals;
|
|
9000
9653
|
const toDecimal = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
|
|
9001
|
-
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new
|
|
9654
|
+
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new import_bn21.default(priceResult.currentSqrtPrice[0]), fromDecimal, toDecimal) : TickMath.sqrtPriceX64ToPrice(new import_bn21.default(priceResult.currentSqrtPrice[0]), toDecimal, fromDecimal);
|
|
9002
9655
|
const path0 = {
|
|
9003
9656
|
direction: path.a2b[0],
|
|
9004
9657
|
label: "Magma",
|
|
@@ -9083,7 +9736,7 @@ var RouterModuleV2 = class {
|
|
|
9083
9736
|
const priceResult = await this.sdk.Router.priceUseV1(
|
|
9084
9737
|
from,
|
|
9085
9738
|
to,
|
|
9086
|
-
new
|
|
9739
|
+
new import_bn21.default(amount),
|
|
9087
9740
|
byAmountIn,
|
|
9088
9741
|
priceSplitPoint,
|
|
9089
9742
|
partner,
|
|
@@ -9095,7 +9748,7 @@ var RouterModuleV2 = class {
|
|
|
9095
9748
|
if (path.poolAddress.length > 1) {
|
|
9096
9749
|
const fromDecimal0 = this.sdk.Router.tokenInfo(path.coinType[0]).decimals;
|
|
9097
9750
|
const toDecimal0 = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
|
|
9098
|
-
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new
|
|
9751
|
+
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new import_bn21.default(priceResult.currentSqrtPrice[0]), fromDecimal0, toDecimal0) : TickMath.sqrtPriceX64ToPrice(new import_bn21.default(priceResult.currentSqrtPrice[0]), toDecimal0, fromDecimal0);
|
|
9099
9752
|
const path0 = {
|
|
9100
9753
|
direction: path.a2b[0],
|
|
9101
9754
|
label: "Magma",
|
|
@@ -9112,7 +9765,7 @@ var RouterModuleV2 = class {
|
|
|
9112
9765
|
};
|
|
9113
9766
|
const fromDecimal1 = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
|
|
9114
9767
|
const toDecimal1 = this.sdk.Router.tokenInfo(path.coinType[2]).decimals;
|
|
9115
|
-
const currentPrice1 = path.a2b[1] ? TickMath.sqrtPriceX64ToPrice(new
|
|
9768
|
+
const currentPrice1 = path.a2b[1] ? TickMath.sqrtPriceX64ToPrice(new import_bn21.default(priceResult.currentSqrtPrice[1]), fromDecimal1, toDecimal1) : TickMath.sqrtPriceX64ToPrice(new import_bn21.default(priceResult.currentSqrtPrice[1]), toDecimal1, fromDecimal1);
|
|
9116
9769
|
const path1 = {
|
|
9117
9770
|
direction: path.a2b[1],
|
|
9118
9771
|
label: "Magma",
|
|
@@ -9131,7 +9784,7 @@ var RouterModuleV2 = class {
|
|
|
9131
9784
|
} else {
|
|
9132
9785
|
const fromDecimal = this.sdk.Router.tokenInfo(path.coinType[0]).decimals;
|
|
9133
9786
|
const toDecimal = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
|
|
9134
|
-
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new
|
|
9787
|
+
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new import_bn21.default(priceResult.currentSqrtPrice[0]), fromDecimal, toDecimal) : TickMath.sqrtPriceX64ToPrice(new import_bn21.default(priceResult.currentSqrtPrice[0]), toDecimal, fromDecimal);
|
|
9135
9788
|
const path0 = {
|
|
9136
9789
|
direction: path.a2b[0],
|
|
9137
9790
|
label: "Magma",
|
|
@@ -10019,6 +10672,20 @@ var GaugeModule = class {
|
|
|
10019
10672
|
});
|
|
10020
10673
|
return tx;
|
|
10021
10674
|
}
|
|
10675
|
+
async testTeacherCap() {
|
|
10676
|
+
const tx = new import_transactions11.Transaction();
|
|
10677
|
+
tx.moveCall({
|
|
10678
|
+
target: `0xd1bf0385f6d298d3b6f140869c28700e85709d570984200cd82c8164401c5e49::hello_world::call_func1`,
|
|
10679
|
+
arguments: [tx.object("0xe1af009a9212aa4bf936ff51794d39e8a75dfbd8e65e3265d3a8e93b4c9256bf")],
|
|
10680
|
+
typeArguments: []
|
|
10681
|
+
});
|
|
10682
|
+
tx.moveCall({
|
|
10683
|
+
target: `0xd1bf0385f6d298d3b6f140869c28700e85709d570984200cd82c8164401c5e49::hello_world::call_func2`,
|
|
10684
|
+
arguments: [tx.object("0xe1af009a9212aa4bf936ff51794d39e8a75dfbd8e65e3265d3a8e93b4c9256bf")],
|
|
10685
|
+
typeArguments: []
|
|
10686
|
+
});
|
|
10687
|
+
return tx;
|
|
10688
|
+
}
|
|
10022
10689
|
async getEpochRewardByPool(pool, incentive_tokens) {
|
|
10023
10690
|
const tx = new import_transactions11.Transaction();
|
|
10024
10691
|
const { integrate, simulationAccount } = this.sdk.sdkOptions;
|
|
@@ -10053,8 +10720,8 @@ var GaugeModule = class {
|
|
|
10053
10720
|
|
|
10054
10721
|
// src/modules/dlmm.ts
|
|
10055
10722
|
var import_transactions12 = require("@mysten/sui/transactions");
|
|
10056
|
-
var
|
|
10057
|
-
var
|
|
10723
|
+
var import_decimal12 = __toESM(require("decimal.js"));
|
|
10724
|
+
var import_calc_dlmm2 = require("@magmaprotocol/calc_dlmm");
|
|
10058
10725
|
var DlmmModule = class {
|
|
10059
10726
|
_sdk;
|
|
10060
10727
|
constructor(sdk) {
|
|
@@ -10126,12 +10793,12 @@ var DlmmModule = class {
|
|
|
10126
10793
|
}
|
|
10127
10794
|
// params price: input (b/(10^b_decimal))/(a/(10^a_decimal))
|
|
10128
10795
|
price_to_storage_id(price, bin_step, tokenADecimal, tokenBDecimal) {
|
|
10129
|
-
const priceDec = new
|
|
10130
|
-
const tenDec = new
|
|
10131
|
-
const twoDec = new
|
|
10796
|
+
const priceDec = new import_decimal12.default(price);
|
|
10797
|
+
const tenDec = new import_decimal12.default(10);
|
|
10798
|
+
const twoDec = new import_decimal12.default(2);
|
|
10132
10799
|
const price_x128 = priceDec.mul(tenDec.pow(tokenBDecimal)).div(tenDec.pow(tokenADecimal)).mul(twoDec.pow(128));
|
|
10133
|
-
const active_id = (0,
|
|
10134
|
-
return (0,
|
|
10800
|
+
const active_id = (0, import_calc_dlmm2.get_real_id_from_price)(price_x128.toFixed(0).toString(), bin_step);
|
|
10801
|
+
return (0, import_calc_dlmm2.get_storage_id_from_real_id)(active_id);
|
|
10135
10802
|
}
|
|
10136
10803
|
// NOTE: x, y should be sorted
|
|
10137
10804
|
async createPairPayload(params) {
|
|
@@ -10212,6 +10879,153 @@ var DlmmModule = class {
|
|
|
10212
10879
|
});
|
|
10213
10880
|
return tx;
|
|
10214
10881
|
}
|
|
10882
|
+
async addLiquidity(params) {
|
|
10883
|
+
if (params.rewards_token.length === 0) {
|
|
10884
|
+
return this._raisePositionByAmounts(params);
|
|
10885
|
+
}
|
|
10886
|
+
return this._raisePositionByAmountsReward(params);
|
|
10887
|
+
}
|
|
10888
|
+
async _raisePositionByAmounts(params) {
|
|
10889
|
+
const tx = new import_transactions12.Transaction();
|
|
10890
|
+
tx.setSender(this.sdk.senderAddress);
|
|
10891
|
+
const { dlmm_pool, integrate } = this.sdk.sdkOptions;
|
|
10892
|
+
const dlmmConfig = getPackagerConfigs(dlmm_pool);
|
|
10893
|
+
const typeArguments = [params.coin_a, params.coin_b];
|
|
10894
|
+
const allCoins = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress);
|
|
10895
|
+
const amountATotal = params.amounts_a.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
|
|
10896
|
+
const amountBTotal = params.amounts_b.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
|
|
10897
|
+
const primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amountATotal), params.coin_a, false, true);
|
|
10898
|
+
const primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amountBTotal), params.coin_b, false, true);
|
|
10899
|
+
const args = [
|
|
10900
|
+
tx.object(params.pool_id),
|
|
10901
|
+
tx.object(dlmmConfig.factory),
|
|
10902
|
+
tx.object(params.position_id),
|
|
10903
|
+
primaryCoinAInputs.targetCoin,
|
|
10904
|
+
primaryCoinBInputs.targetCoin,
|
|
10905
|
+
tx.pure.vector("u64", params.amounts_a),
|
|
10906
|
+
tx.pure.vector("u64", params.amounts_b),
|
|
10907
|
+
tx.pure.address(params.receiver),
|
|
10908
|
+
tx.object(CLOCK_ADDRESS)
|
|
10909
|
+
];
|
|
10910
|
+
tx.moveCall({
|
|
10911
|
+
target: `${integrate.published_at}::${DlmmScript}::raise_position_by_amounts`,
|
|
10912
|
+
typeArguments,
|
|
10913
|
+
arguments: args
|
|
10914
|
+
});
|
|
10915
|
+
return tx;
|
|
10916
|
+
}
|
|
10917
|
+
async _raisePositionByAmountsReward(params) {
|
|
10918
|
+
const tx = new import_transactions12.Transaction();
|
|
10919
|
+
tx.setSender(this.sdk.senderAddress);
|
|
10920
|
+
const { dlmm_pool, integrate, clmm_pool } = this.sdk.sdkOptions;
|
|
10921
|
+
const dlmmConfig = getPackagerConfigs(dlmm_pool);
|
|
10922
|
+
const clmmConfigs = getPackagerConfigs(clmm_pool);
|
|
10923
|
+
const typeArguments = [params.coin_a, params.coin_b, ...params.rewards_token];
|
|
10924
|
+
const allCoins = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress);
|
|
10925
|
+
const amountATotal = params.amounts_a.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
|
|
10926
|
+
const amountBTotal = params.amounts_b.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
|
|
10927
|
+
const primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amountATotal), params.coin_a, false, true);
|
|
10928
|
+
const primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amountBTotal), params.coin_b, false, true);
|
|
10929
|
+
const args = [
|
|
10930
|
+
tx.object(params.pool_id),
|
|
10931
|
+
tx.object(dlmmConfig.factory),
|
|
10932
|
+
tx.object(clmmConfigs.global_vault_id),
|
|
10933
|
+
tx.object(params.position_id),
|
|
10934
|
+
primaryCoinAInputs.targetCoin,
|
|
10935
|
+
primaryCoinBInputs.targetCoin,
|
|
10936
|
+
tx.pure.vector("u64", params.amounts_a),
|
|
10937
|
+
tx.pure.vector("u64", params.amounts_b),
|
|
10938
|
+
tx.pure.address(params.receiver),
|
|
10939
|
+
tx.object(CLOCK_ADDRESS)
|
|
10940
|
+
];
|
|
10941
|
+
tx.moveCall({
|
|
10942
|
+
target: `${integrate.published_at}::${DlmmScript}::raise_position_by_amounts_reward${params.rewards_token.length}`,
|
|
10943
|
+
typeArguments,
|
|
10944
|
+
arguments: args
|
|
10945
|
+
});
|
|
10946
|
+
return tx;
|
|
10947
|
+
}
|
|
10948
|
+
async burnPosition(params) {
|
|
10949
|
+
const tx = new import_transactions12.Transaction();
|
|
10950
|
+
tx.setSender(this.sdk.senderAddress);
|
|
10951
|
+
const { integrate, clmm_pool } = this.sdk.sdkOptions;
|
|
10952
|
+
const clmmConfigs = getPackagerConfigs(clmm_pool);
|
|
10953
|
+
const typeArguments = [params.coin_a, params.coin_b, ...params.rewards_token];
|
|
10954
|
+
let args = [tx.object(params.pool_id), tx.object(params.position_id), tx.object(CLOCK_ADDRESS)];
|
|
10955
|
+
let target = `${integrate.published_at}::${DlmmScript}::burn_position`;
|
|
10956
|
+
if (params.rewards_token.length > 0) {
|
|
10957
|
+
args = [tx.object(params.pool_id), tx.object(clmmConfigs.global_vault_id), tx.object(params.position_id), tx.object(CLOCK_ADDRESS)];
|
|
10958
|
+
target = `${integrate.published_at}::${DlmmScript}::burn_position_reward${params.rewards_token.length}`;
|
|
10959
|
+
}
|
|
10960
|
+
tx.moveCall({
|
|
10961
|
+
target,
|
|
10962
|
+
typeArguments,
|
|
10963
|
+
arguments: args
|
|
10964
|
+
});
|
|
10965
|
+
return tx;
|
|
10966
|
+
}
|
|
10967
|
+
async shrinkPosition(params) {
|
|
10968
|
+
const tx = new import_transactions12.Transaction();
|
|
10969
|
+
tx.setSender(this.sdk.senderAddress);
|
|
10970
|
+
const { integrate, clmm_pool } = this.sdk.sdkOptions;
|
|
10971
|
+
const clmmConfigs = getPackagerConfigs(clmm_pool);
|
|
10972
|
+
const typeArguments = [params.coin_a, params.coin_b, ...params.rewards_token];
|
|
10973
|
+
let args = [tx.object(params.pool_id), tx.object(params.position_id), tx.pure.u64(params.delta_percentage), tx.object(CLOCK_ADDRESS)];
|
|
10974
|
+
let target = `${integrate.published_at}::${DlmmScript}::shrink_position`;
|
|
10975
|
+
if (params.rewards_token.length > 0) {
|
|
10976
|
+
args = [
|
|
10977
|
+
tx.object(params.pool_id),
|
|
10978
|
+
tx.object(clmmConfigs.global_vault_id),
|
|
10979
|
+
tx.object(params.position_id),
|
|
10980
|
+
tx.pure.u64(params.delta_percentage),
|
|
10981
|
+
tx.object(CLOCK_ADDRESS)
|
|
10982
|
+
];
|
|
10983
|
+
target = `${integrate.published_at}::${DlmmScript}::shrink_position_reward${params.rewards_token.length}`;
|
|
10984
|
+
}
|
|
10985
|
+
tx.moveCall({
|
|
10986
|
+
target,
|
|
10987
|
+
typeArguments,
|
|
10988
|
+
arguments: args
|
|
10989
|
+
});
|
|
10990
|
+
return tx;
|
|
10991
|
+
}
|
|
10992
|
+
async collectReward(params) {
|
|
10993
|
+
const tx = new import_transactions12.Transaction();
|
|
10994
|
+
tx.setSender(this.sdk.senderAddress);
|
|
10995
|
+
const { integrate, clmm_pool } = this.sdk.sdkOptions;
|
|
10996
|
+
const clmmConfigs = getPackagerConfigs(clmm_pool);
|
|
10997
|
+
const typeArguments = [params.coin_a, params.coin_b, ...params.rewards_token];
|
|
10998
|
+
const args = [
|
|
10999
|
+
tx.object(params.pool_id),
|
|
11000
|
+
tx.object(clmmConfigs.global_vault_id),
|
|
11001
|
+
tx.object(params.position_id),
|
|
11002
|
+
tx.object(CLOCK_ADDRESS)
|
|
11003
|
+
];
|
|
11004
|
+
let target = `${integrate.published_at}::${DlmmScript}::collect_reward`;
|
|
11005
|
+
if (params.rewards_token.length > 1) {
|
|
11006
|
+
target = `${integrate.published_at}::${DlmmScript}::collect_reward${params.rewards_token.length}`;
|
|
11007
|
+
}
|
|
11008
|
+
tx.moveCall({
|
|
11009
|
+
target,
|
|
11010
|
+
typeArguments,
|
|
11011
|
+
arguments: args
|
|
11012
|
+
});
|
|
11013
|
+
return tx;
|
|
11014
|
+
}
|
|
11015
|
+
async collectFees(params) {
|
|
11016
|
+
const tx = new import_transactions12.Transaction();
|
|
11017
|
+
tx.setSender(this.sdk.senderAddress);
|
|
11018
|
+
const { integrate } = this.sdk.sdkOptions;
|
|
11019
|
+
const typeArguments = [params.coin_a, params.coin_b];
|
|
11020
|
+
const args = [tx.object(params.pool_id), tx.object(params.position_id), tx.object(CLOCK_ADDRESS)];
|
|
11021
|
+
const target = `${integrate.published_at}::${DlmmScript}::collect_fees`;
|
|
11022
|
+
tx.moveCall({
|
|
11023
|
+
target,
|
|
11024
|
+
typeArguments,
|
|
11025
|
+
arguments: args
|
|
11026
|
+
});
|
|
11027
|
+
return tx;
|
|
11028
|
+
}
|
|
10215
11029
|
async swap(params) {
|
|
10216
11030
|
const tx = new import_transactions12.Transaction();
|
|
10217
11031
|
tx.setSender(this.sdk.senderAddress);
|
|
@@ -10253,9 +11067,11 @@ var DlmmModule = class {
|
|
|
10253
11067
|
if (simulateRes.error != null) {
|
|
10254
11068
|
throw new Error(`fetchBins error code: ${simulateRes.error ?? "unknown error"}`);
|
|
10255
11069
|
}
|
|
10256
|
-
|
|
11070
|
+
let res = [];
|
|
10257
11071
|
simulateRes.events?.forEach((item) => {
|
|
10258
11072
|
if (extractStructTagFromType(item.type).name === `EventFetchBins`) {
|
|
11073
|
+
const { bins } = item.parsedJson;
|
|
11074
|
+
res = bins;
|
|
10259
11075
|
}
|
|
10260
11076
|
});
|
|
10261
11077
|
return res;
|
|
@@ -10293,7 +11109,7 @@ var DlmmModule = class {
|
|
|
10293
11109
|
out.liquidity = item.parsedJson.liquidity;
|
|
10294
11110
|
out.x_equivalent = item.parsedJson.x_equivalent;
|
|
10295
11111
|
out.y_equivalent = item.parsedJson.y_equivalent;
|
|
10296
|
-
out.bin_ids = item.parsedJson.
|
|
11112
|
+
out.bin_ids = item.parsedJson.bin_ids;
|
|
10297
11113
|
out.bin_x_eq = item.parsedJson.bin_x_eq;
|
|
10298
11114
|
out.bin_y_eq = item.parsedJson.bin_y_eq;
|
|
10299
11115
|
out.bin_liquidity = item.parsedJson.bin_liquidity;
|
|
@@ -10340,6 +11156,127 @@ var DlmmModule = class {
|
|
|
10340
11156
|
});
|
|
10341
11157
|
return out;
|
|
10342
11158
|
}
|
|
11159
|
+
async getEarnedFees(params) {
|
|
11160
|
+
const tx = new import_transactions12.Transaction();
|
|
11161
|
+
const { integrate, simulationAccount } = this.sdk.sdkOptions;
|
|
11162
|
+
const typeArguments = [params.coin_a, params.coin_b];
|
|
11163
|
+
const args = [tx.object(params.pool_id), tx.object(params.position_id)];
|
|
11164
|
+
tx.moveCall({
|
|
11165
|
+
target: `${integrate.published_at}::${DlmmScript}::earned_fees`,
|
|
11166
|
+
arguments: args,
|
|
11167
|
+
typeArguments
|
|
11168
|
+
});
|
|
11169
|
+
const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
|
|
11170
|
+
transactionBlock: tx,
|
|
11171
|
+
sender: simulationAccount.address
|
|
11172
|
+
});
|
|
11173
|
+
const out = {
|
|
11174
|
+
position_id: "",
|
|
11175
|
+
x: "",
|
|
11176
|
+
y: "",
|
|
11177
|
+
fee_x: 0,
|
|
11178
|
+
fee_y: 0
|
|
11179
|
+
};
|
|
11180
|
+
if (simulateRes.error != null) {
|
|
11181
|
+
throw new Error(`fetchBins error code: ${simulateRes.error ?? "unknown error"}`);
|
|
11182
|
+
}
|
|
11183
|
+
simulateRes.events?.forEach((item) => {
|
|
11184
|
+
if (extractStructTagFromType(item.type).name === `EventPositionLiquidity`) {
|
|
11185
|
+
out.position_id = item.parsedJson.position_id;
|
|
11186
|
+
out.x = item.parsedJson.x;
|
|
11187
|
+
out.y = item.parsedJson.y;
|
|
11188
|
+
out.fee_x = item.parsedJson.fee_x;
|
|
11189
|
+
out.fee_y = item.parsedJson.fee_y;
|
|
11190
|
+
}
|
|
11191
|
+
});
|
|
11192
|
+
return out;
|
|
11193
|
+
}
|
|
11194
|
+
async getEarnedRewards(params) {
|
|
11195
|
+
const tx = new import_transactions12.Transaction();
|
|
11196
|
+
const { integrate, simulationAccount } = this.sdk.sdkOptions;
|
|
11197
|
+
const typeArguments = [params.coin_a, params.coin_b, ...params.rewards_token];
|
|
11198
|
+
const args = [tx.object(params.pool_id), tx.object(params.position_id)];
|
|
11199
|
+
let target = `${integrate.published_at}::${DlmmScript}::earned_rewards`;
|
|
11200
|
+
if (params.rewards_token.length > 1) {
|
|
11201
|
+
target = `${integrate.published_at}::${DlmmScript}::earned_rewards${params.rewards_token.length}`;
|
|
11202
|
+
}
|
|
11203
|
+
tx.moveCall({
|
|
11204
|
+
target,
|
|
11205
|
+
arguments: args,
|
|
11206
|
+
typeArguments
|
|
11207
|
+
});
|
|
11208
|
+
const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
|
|
11209
|
+
transactionBlock: tx,
|
|
11210
|
+
sender: simulationAccount.address
|
|
11211
|
+
});
|
|
11212
|
+
const out = {
|
|
11213
|
+
position_id: "",
|
|
11214
|
+
reward: [],
|
|
11215
|
+
amount: []
|
|
11216
|
+
};
|
|
11217
|
+
if (simulateRes.error != null) {
|
|
11218
|
+
throw new Error(`fetchBins error code: ${simulateRes.error ?? "unknown error"}`);
|
|
11219
|
+
}
|
|
11220
|
+
simulateRes.events?.forEach((item) => {
|
|
11221
|
+
if (extractStructTagFromType(item.type).name === `DlmmEventEarnedRewards`) {
|
|
11222
|
+
out.position_id = item.parsedJson.position_id;
|
|
11223
|
+
out.reward = [item.parsedJson.reward];
|
|
11224
|
+
out.amount = [item.parsedJson.amount];
|
|
11225
|
+
} else if (extractStructTagFromType(item.type).name === `DlmmEventEarnedRewards2`) {
|
|
11226
|
+
out.position_id = item.parsedJson.position_id;
|
|
11227
|
+
out.reward = [item.parsedJson.reward1, item.parsedJson.reward2];
|
|
11228
|
+
out.amount = [item.parsedJson.amount1, item.parsedJson.amount2];
|
|
11229
|
+
} else if (extractStructTagFromType(item.type).name === `EventEarnedRewards3`) {
|
|
11230
|
+
out.position_id = item.parsedJson.position_id;
|
|
11231
|
+
out.reward = [item.parsedJson.reward1, item.parsedJson.reward2, item.parsedJson.reward3];
|
|
11232
|
+
out.amount = [item.parsedJson.amount1, item.parsedJson.amount2, item.parsedJson.amount3];
|
|
11233
|
+
}
|
|
11234
|
+
});
|
|
11235
|
+
return out;
|
|
11236
|
+
}
|
|
11237
|
+
async getPairRewarders(params) {
|
|
11238
|
+
let tx = new import_transactions12.Transaction();
|
|
11239
|
+
for (const param of params) {
|
|
11240
|
+
tx = await this._getPairRewarders(param, tx);
|
|
11241
|
+
}
|
|
11242
|
+
return this._parsePairRewarders(tx);
|
|
11243
|
+
}
|
|
11244
|
+
async _getPairRewarders(params, tx) {
|
|
11245
|
+
tx = tx || new import_transactions12.Transaction();
|
|
11246
|
+
const { integrate } = this.sdk.sdkOptions;
|
|
11247
|
+
const typeArguments = [params.coin_a, params.coin_b];
|
|
11248
|
+
const args = [tx.object(params.pool_id)];
|
|
11249
|
+
tx.moveCall({
|
|
11250
|
+
target: `${integrate.published_at}::${DlmmScript}::get_pair_rewarders`,
|
|
11251
|
+
arguments: args,
|
|
11252
|
+
typeArguments
|
|
11253
|
+
});
|
|
11254
|
+
return tx;
|
|
11255
|
+
}
|
|
11256
|
+
async _parsePairRewarders(tx) {
|
|
11257
|
+
const { simulationAccount } = this.sdk.sdkOptions;
|
|
11258
|
+
const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
|
|
11259
|
+
transactionBlock: tx,
|
|
11260
|
+
sender: simulationAccount.address
|
|
11261
|
+
});
|
|
11262
|
+
const out = /* @__PURE__ */ new Map();
|
|
11263
|
+
if (simulateRes.error != null) {
|
|
11264
|
+
throw new Error(`fetchBins error code: ${simulateRes.error ?? "unknown error"}`);
|
|
11265
|
+
}
|
|
11266
|
+
simulateRes.events?.forEach((item) => {
|
|
11267
|
+
if (extractStructTagFromType(item.type).name === `EventPairRewardTypes`) {
|
|
11268
|
+
const pairRewards = {
|
|
11269
|
+
pair_id: "",
|
|
11270
|
+
tokens: []
|
|
11271
|
+
};
|
|
11272
|
+
pairRewards.pair_id = item.parsedJson.pair_id;
|
|
11273
|
+
item.parsedJson.tokens.contents.forEach((token) => {
|
|
11274
|
+
pairRewards.tokens.push(token.name);
|
|
11275
|
+
});
|
|
11276
|
+
}
|
|
11277
|
+
});
|
|
11278
|
+
return out;
|
|
11279
|
+
}
|
|
10343
11280
|
};
|
|
10344
11281
|
|
|
10345
11282
|
// src/sdk.ts
|
|
@@ -10619,7 +11556,7 @@ var SDKConfig = {
|
|
|
10619
11556
|
clmmConfig: {
|
|
10620
11557
|
pools_id: "0xfa145b9de10fe858be81edd1c6cdffcf27be9d016de02a1345eb1009a68ba8b2",
|
|
10621
11558
|
// clmm and dlmm both use this global_config
|
|
10622
|
-
global_config_id: "
|
|
11559
|
+
global_config_id: "0x4e39044c21fe04e27c67b110dec37807ad439516a1701cf2e0dc842e9e20f1f3",
|
|
10623
11560
|
global_vault_id: "0xa7e1102f222b6eb81ccc8a126e7feb2353342be9df6f6646a77c4519da29c071",
|
|
10624
11561
|
admin_cap_id: "0x89c1a321291d15ddae5a086c9abc533dff697fde3d89e0ca836c41af73e36a75"
|
|
10625
11562
|
},
|
|
@@ -10640,7 +11577,7 @@ var SDKConfig = {
|
|
|
10640
11577
|
minter_id: "0x4fa5766cd83b33b215b139fec27ac344040f3bbd84fcbee7b61fc671aadc51fa"
|
|
10641
11578
|
},
|
|
10642
11579
|
dlmmConfig: {
|
|
10643
|
-
factory: ""
|
|
11580
|
+
factory: "0xb7d4f7281bc604981e2caaa5d2af875b66f9422fcdbf6e310d8ed16b854a5d3e"
|
|
10644
11581
|
},
|
|
10645
11582
|
gaugeConfig: {}
|
|
10646
11583
|
};
|
|
@@ -10660,8 +11597,8 @@ var clmmMainnet = {
|
|
|
10660
11597
|
config: SDKConfig.clmmConfig
|
|
10661
11598
|
},
|
|
10662
11599
|
dlmm_pool: {
|
|
10663
|
-
package_id: "",
|
|
10664
|
-
published_at: "",
|
|
11600
|
+
package_id: "0xb3a44310c59536782d1b5c29d01a066798750ff0c15242a7f3eb7e55d188cfc3",
|
|
11601
|
+
published_at: "0xb3a44310c59536782d1b5c29d01a066798750ff0c15242a7f3eb7e55d188cfc3",
|
|
10665
11602
|
config: SDKConfig.dlmmConfig
|
|
10666
11603
|
},
|
|
10667
11604
|
distribution: {
|
|
@@ -10669,8 +11606,8 @@ var clmmMainnet = {
|
|
|
10669
11606
|
published_at: "0xee4a1f231dc45a303389998fe26c4e39278cf68b404b32e4f0b9769129b8267b"
|
|
10670
11607
|
},
|
|
10671
11608
|
integrate: {
|
|
10672
|
-
package_id: "
|
|
10673
|
-
published_at: "
|
|
11609
|
+
package_id: "0x228638b6ea17788e34971afee4b4580dbc4dcaa847ef62604d858ef5d3beb5a6",
|
|
11610
|
+
published_at: "0x228638b6ea17788e34971afee4b4580dbc4dcaa847ef62604d858ef5d3beb5a6"
|
|
10674
11611
|
},
|
|
10675
11612
|
deepbook: {
|
|
10676
11613
|
package_id: "0x000000000000000000000000000000000000000000000000000000000000dee9",
|
|
@@ -10842,6 +11779,7 @@ var src_default = MagmaClmmSDK;
|
|
|
10842
11779
|
SUI_SYSTEM_STATE_OBJECT_ID,
|
|
10843
11780
|
SplitSwap,
|
|
10844
11781
|
SplitUnit,
|
|
11782
|
+
StrategyType,
|
|
10845
11783
|
SwapDirection,
|
|
10846
11784
|
SwapModule,
|
|
10847
11785
|
SwapUtils,
|
|
@@ -10863,6 +11801,10 @@ var src_default = MagmaClmmSDK;
|
|
|
10863
11801
|
adjustForSlippage,
|
|
10864
11802
|
asIntN,
|
|
10865
11803
|
asUintN,
|
|
11804
|
+
autoFillXByStrategy,
|
|
11805
|
+
autoFillXByWeight,
|
|
11806
|
+
autoFillYByStrategy,
|
|
11807
|
+
autoFillYByWeight,
|
|
10866
11808
|
bufferToHex,
|
|
10867
11809
|
buildClmmPositionName,
|
|
10868
11810
|
buildNFT,
|
|
@@ -10900,12 +11842,14 @@ var src_default = MagmaClmmSDK;
|
|
|
10900
11842
|
getAmountUnfixedDelta,
|
|
10901
11843
|
getCoinAFromLiquidity,
|
|
10902
11844
|
getCoinBFromLiquidity,
|
|
11845
|
+
getCoinXYForLiquidity,
|
|
10903
11846
|
getDefaultSuiInputType,
|
|
10904
11847
|
getDeltaA,
|
|
10905
11848
|
getDeltaB,
|
|
10906
11849
|
getDeltaDownFromOutput,
|
|
10907
11850
|
getDeltaUpFromInput,
|
|
10908
11851
|
getFutureTime,
|
|
11852
|
+
getLiquidityAndCoinYByCoinX,
|
|
10909
11853
|
getLiquidityFromCoinA,
|
|
10910
11854
|
getLiquidityFromCoinB,
|
|
10911
11855
|
getLowerSqrtPriceFromCoinA,
|
|
@@ -10929,6 +11873,7 @@ var src_default = MagmaClmmSDK;
|
|
|
10929
11873
|
getObjectType,
|
|
10930
11874
|
getObjectVersion,
|
|
10931
11875
|
getPackagerConfigs,
|
|
11876
|
+
getPriceOfBinByBinId,
|
|
10932
11877
|
getRewardInTickRange,
|
|
10933
11878
|
getSuiObjectData,
|
|
10934
11879
|
getTickDataFromUrlData,
|
|
@@ -10952,10 +11897,15 @@ var src_default = MagmaClmmSDK;
|
|
|
10952
11897
|
shortAddress,
|
|
10953
11898
|
shortString,
|
|
10954
11899
|
tickScore,
|
|
11900
|
+
toAmountAskSide,
|
|
11901
|
+
toAmountBidSide,
|
|
11902
|
+
toAmountBothSide,
|
|
11903
|
+
toAmountsBothSideByStrategy,
|
|
10955
11904
|
toBuffer,
|
|
10956
11905
|
toCoinAmount,
|
|
10957
11906
|
toDecimalsAmount,
|
|
10958
11907
|
transClmmpoolDataWithoutTicks,
|
|
10959
|
-
utf8to16
|
|
11908
|
+
utf8to16,
|
|
11909
|
+
withLiquiditySlippage
|
|
10960
11910
|
});
|
|
10961
11911
|
//# sourceMappingURL=index.js.map
|