@magmaprotocol/magma-clmm-sdk 0.5.76 → 0.5.77
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -10
- package/dist/index.d.ts +1 -423
- package/dist/index.js +188 -1615
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +187 -1604
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -2
package/dist/index.mjs
CHANGED
|
@@ -37,7 +37,7 @@ var CachedContent = class {
|
|
|
37
37
|
};
|
|
38
38
|
|
|
39
39
|
// src/utils/common.ts
|
|
40
|
-
import
|
|
40
|
+
import BN11 from "bn.js";
|
|
41
41
|
import { fromB64, fromHEX } from "@mysten/bcs";
|
|
42
42
|
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
|
|
43
43
|
import { Secp256k1Keypair } from "@mysten/sui/keypairs/secp256k1";
|
|
@@ -303,7 +303,6 @@ var Voter = "voter";
|
|
|
303
303
|
var RewardDistributor = "reward_distributor";
|
|
304
304
|
var Gauge = "gauge";
|
|
305
305
|
var Minter = "minter";
|
|
306
|
-
var DlmmScript = "dlmm_script";
|
|
307
306
|
var CoinInfoAddress = "0x1::coin::CoinInfo";
|
|
308
307
|
var CoinStoreAddress = "0x1::coin::CoinStore";
|
|
309
308
|
var DeepbookCustodianV2Moudle = "custodian_v2";
|
|
@@ -1592,476 +1591,8 @@ function collectFeesQuote(param) {
|
|
|
1592
1591
|
return updateFees(param.position, fee_growth_inside_a, fee_growth_inside_b);
|
|
1593
1592
|
}
|
|
1594
1593
|
|
|
1595
|
-
// src/math/dlmmWeightToAmounts.ts
|
|
1596
|
-
import BN9 from "bn.js";
|
|
1597
|
-
import Decimal3 from "decimal.js";
|
|
1598
|
-
import { get_price_x128_from_real_id } from "@magmaprotocol/calc_dlmm";
|
|
1599
|
-
function getPriceOfBinByBinId(binId, binStep) {
|
|
1600
|
-
const twoDec = new Decimal3(2);
|
|
1601
|
-
const price = new Decimal3(get_price_x128_from_real_id(binId, binStep));
|
|
1602
|
-
return price.div(twoDec.pow(128));
|
|
1603
|
-
}
|
|
1604
|
-
function autoFillYByWeight(activeId, binStep, amountX, amountXInActiveBin, amountYInActiveBin, distributions) {
|
|
1605
|
-
const activeBins = distributions.filter((element) => {
|
|
1606
|
-
return element.binId === activeId;
|
|
1607
|
-
});
|
|
1608
|
-
if (activeBins.length === 1) {
|
|
1609
|
-
const p0 = getPriceOfBinByBinId(activeId, binStep);
|
|
1610
|
-
let wx0 = new Decimal3(0);
|
|
1611
|
-
let wy0 = new Decimal3(0);
|
|
1612
|
-
const activeBin = activeBins[0];
|
|
1613
|
-
if (amountXInActiveBin.isZero() && amountYInActiveBin.isZero()) {
|
|
1614
|
-
wx0 = new Decimal3(activeBin.weight).div(p0.mul(new Decimal3(2)));
|
|
1615
|
-
wy0 = new Decimal3(activeBin.weight).div(new Decimal3(2));
|
|
1616
|
-
} else {
|
|
1617
|
-
const amountXInActiveBinDec = new Decimal3(amountXInActiveBin.toString());
|
|
1618
|
-
const amountYInActiveBinDec = new Decimal3(amountYInActiveBin.toString());
|
|
1619
|
-
if (!amountXInActiveBin.isZero()) {
|
|
1620
|
-
wx0 = new Decimal3(activeBin.weight).div(p0.add(amountYInActiveBinDec.div(amountXInActiveBinDec)));
|
|
1621
|
-
}
|
|
1622
|
-
if (!amountYInActiveBin.isZero()) {
|
|
1623
|
-
wy0 = new Decimal3(activeBin.weight).div(new Decimal3(1).add(p0.mul(amountXInActiveBinDec).div(amountYInActiveBinDec)));
|
|
1624
|
-
}
|
|
1625
|
-
}
|
|
1626
|
-
let totalWeightX2 = wx0;
|
|
1627
|
-
let totalWeightY2 = wy0;
|
|
1628
|
-
distributions.forEach((element) => {
|
|
1629
|
-
if (element.binId < activeId) {
|
|
1630
|
-
totalWeightY2 = totalWeightY2.add(new Decimal3(element.weight));
|
|
1631
|
-
}
|
|
1632
|
-
if (element.binId > activeId) {
|
|
1633
|
-
const price = getPriceOfBinByBinId(element.binId, binStep);
|
|
1634
|
-
const weighPerPrice = new Decimal3(element.weight).div(price);
|
|
1635
|
-
totalWeightX2 = totalWeightX2.add(weighPerPrice);
|
|
1636
|
-
}
|
|
1637
|
-
});
|
|
1638
|
-
const kx2 = totalWeightX2.isZero() ? new Decimal3(1) : new Decimal3(amountX.toString()).div(totalWeightX2);
|
|
1639
|
-
const amountY2 = kx2.mul(totalWeightY2);
|
|
1640
|
-
return new BN9(amountY2.floor().toString());
|
|
1641
|
-
}
|
|
1642
|
-
let totalWeightX = new Decimal3(0);
|
|
1643
|
-
let totalWeightY = new Decimal3(0);
|
|
1644
|
-
distributions.forEach((element) => {
|
|
1645
|
-
if (element.binId < activeId) {
|
|
1646
|
-
totalWeightY = totalWeightY.add(new Decimal3(element.weight));
|
|
1647
|
-
} else {
|
|
1648
|
-
const price = getPriceOfBinByBinId(element.binId, binStep);
|
|
1649
|
-
const weighPerPrice = new Decimal3(element.weight).div(price);
|
|
1650
|
-
totalWeightX = totalWeightX.add(weighPerPrice);
|
|
1651
|
-
}
|
|
1652
|
-
});
|
|
1653
|
-
const kx = totalWeightX.isZero() ? new Decimal3(1) : new Decimal3(amountX.toString()).div(totalWeightX);
|
|
1654
|
-
const amountY = kx.mul(totalWeightY);
|
|
1655
|
-
return new BN9(amountY.floor().toString());
|
|
1656
|
-
}
|
|
1657
|
-
function autoFillXByWeight(activeId, binStep, amountY, amountXInActiveBin, amountYInActiveBin, distributions) {
|
|
1658
|
-
const activeBins = distributions.filter((element) => {
|
|
1659
|
-
return element.binId === activeId;
|
|
1660
|
-
});
|
|
1661
|
-
if (activeBins.length === 1) {
|
|
1662
|
-
const p0 = getPriceOfBinByBinId(activeId, binStep);
|
|
1663
|
-
let wx0 = new Decimal3(0);
|
|
1664
|
-
let wy0 = new Decimal3(0);
|
|
1665
|
-
const activeBin = activeBins[0];
|
|
1666
|
-
if (amountXInActiveBin.isZero() && amountYInActiveBin.isZero()) {
|
|
1667
|
-
wx0 = new Decimal3(activeBin.weight).div(p0.mul(new Decimal3(2)));
|
|
1668
|
-
wy0 = new Decimal3(activeBin.weight).div(new Decimal3(2));
|
|
1669
|
-
} else {
|
|
1670
|
-
const amountXInActiveBinDec = new Decimal3(amountXInActiveBin.toString());
|
|
1671
|
-
const amountYInActiveBinDec = new Decimal3(amountYInActiveBin.toString());
|
|
1672
|
-
if (!amountXInActiveBin.isZero()) {
|
|
1673
|
-
wx0 = new Decimal3(activeBin.weight).div(p0.add(amountYInActiveBinDec.div(amountXInActiveBinDec)));
|
|
1674
|
-
}
|
|
1675
|
-
if (!amountYInActiveBin.isZero()) {
|
|
1676
|
-
wy0 = new Decimal3(activeBin.weight).div(new Decimal3(1).add(p0.mul(amountXInActiveBinDec).div(amountYInActiveBinDec)));
|
|
1677
|
-
}
|
|
1678
|
-
}
|
|
1679
|
-
let totalWeightX2 = wx0;
|
|
1680
|
-
let totalWeightY2 = wy0;
|
|
1681
|
-
distributions.forEach((element) => {
|
|
1682
|
-
if (element.binId < activeId) {
|
|
1683
|
-
totalWeightY2 = totalWeightY2.add(new Decimal3(element.weight));
|
|
1684
|
-
}
|
|
1685
|
-
if (element.binId > activeId) {
|
|
1686
|
-
const price = getPriceOfBinByBinId(element.binId, binStep);
|
|
1687
|
-
const weighPerPrice = new Decimal3(element.weight).div(price);
|
|
1688
|
-
totalWeightX2 = totalWeightX2.add(weighPerPrice);
|
|
1689
|
-
}
|
|
1690
|
-
});
|
|
1691
|
-
const ky2 = totalWeightY2.isZero() ? new Decimal3(1) : new Decimal3(amountY.toString()).div(totalWeightY2);
|
|
1692
|
-
const amountX2 = ky2.mul(totalWeightX2);
|
|
1693
|
-
return new BN9(amountX2.floor().toString());
|
|
1694
|
-
}
|
|
1695
|
-
let totalWeightX = new Decimal3(0);
|
|
1696
|
-
let totalWeightY = new Decimal3(0);
|
|
1697
|
-
distributions.forEach((element) => {
|
|
1698
|
-
if (element.binId < activeId) {
|
|
1699
|
-
totalWeightY = totalWeightY.add(new Decimal3(element.weight));
|
|
1700
|
-
} else {
|
|
1701
|
-
const price = getPriceOfBinByBinId(element.binId, binStep);
|
|
1702
|
-
const weighPerPrice = new Decimal3(element.weight).div(price);
|
|
1703
|
-
totalWeightX = totalWeightX.add(weighPerPrice);
|
|
1704
|
-
}
|
|
1705
|
-
});
|
|
1706
|
-
const ky = totalWeightY.isZero() ? new Decimal3(1) : new Decimal3(amountY.toString()).div(totalWeightY);
|
|
1707
|
-
const amountX = ky.mul(totalWeightX);
|
|
1708
|
-
return new BN9(amountX.floor().toString());
|
|
1709
|
-
}
|
|
1710
|
-
function toAmountBidSide(activeId, totalAmount, distributions) {
|
|
1711
|
-
const totalWeight = distributions.reduce((sum, el) => {
|
|
1712
|
-
return el.binId > activeId ? sum : sum.add(el.weight);
|
|
1713
|
-
}, new Decimal3(0));
|
|
1714
|
-
if (totalWeight.cmp(new Decimal3(0)) !== 1) {
|
|
1715
|
-
throw Error("Invalid parameteres");
|
|
1716
|
-
}
|
|
1717
|
-
return distributions.map((bin) => {
|
|
1718
|
-
if (bin.binId > activeId) {
|
|
1719
|
-
return {
|
|
1720
|
-
binId: bin.binId,
|
|
1721
|
-
amount: new BN9(0)
|
|
1722
|
-
};
|
|
1723
|
-
}
|
|
1724
|
-
return {
|
|
1725
|
-
binId: bin.binId,
|
|
1726
|
-
amount: new BN9(new Decimal3(totalAmount.toString()).mul(new Decimal3(bin.weight).div(totalWeight)).floor().toString())
|
|
1727
|
-
};
|
|
1728
|
-
});
|
|
1729
|
-
}
|
|
1730
|
-
function toAmountAskSide(activeId, binStep, totalAmount, distributions) {
|
|
1731
|
-
const totalWeight = distributions.reduce((sum, el) => {
|
|
1732
|
-
if (el.binId < activeId) {
|
|
1733
|
-
return sum;
|
|
1734
|
-
}
|
|
1735
|
-
const price = getPriceOfBinByBinId(el.binId, binStep);
|
|
1736
|
-
const weightPerPrice = new Decimal3(el.weight).div(price);
|
|
1737
|
-
return sum.add(weightPerPrice);
|
|
1738
|
-
}, new Decimal3(0));
|
|
1739
|
-
if (totalWeight.cmp(new Decimal3(0)) !== 1) {
|
|
1740
|
-
throw Error("Invalid parameteres");
|
|
1741
|
-
}
|
|
1742
|
-
return distributions.map((bin) => {
|
|
1743
|
-
if (bin.binId < activeId) {
|
|
1744
|
-
return {
|
|
1745
|
-
binId: bin.binId,
|
|
1746
|
-
amount: new BN9(0)
|
|
1747
|
-
};
|
|
1748
|
-
}
|
|
1749
|
-
const price = getPriceOfBinByBinId(bin.binId, binStep);
|
|
1750
|
-
const weightPerPrice = new Decimal3(bin.weight).div(price);
|
|
1751
|
-
return {
|
|
1752
|
-
binId: bin.binId,
|
|
1753
|
-
amount: new BN9(new Decimal3(totalAmount.toString()).mul(weightPerPrice).div(totalWeight).floor().toString())
|
|
1754
|
-
};
|
|
1755
|
-
});
|
|
1756
|
-
}
|
|
1757
|
-
function toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, distributions) {
|
|
1758
|
-
if (activeId > distributions[distributions.length - 1].binId) {
|
|
1759
|
-
const amounts = toAmountBidSide(activeId, amountY, distributions);
|
|
1760
|
-
return amounts.map((bin) => {
|
|
1761
|
-
return {
|
|
1762
|
-
binId: bin.binId,
|
|
1763
|
-
amountX: new BN9(0),
|
|
1764
|
-
amountY: bin.amount
|
|
1765
|
-
};
|
|
1766
|
-
});
|
|
1767
|
-
}
|
|
1768
|
-
if (activeId < distributions[0].binId) {
|
|
1769
|
-
const amounts = toAmountAskSide(activeId, binStep, amountX, distributions);
|
|
1770
|
-
return amounts.map((bin) => {
|
|
1771
|
-
return {
|
|
1772
|
-
binId: bin.binId,
|
|
1773
|
-
amountX: bin.amount,
|
|
1774
|
-
amountY: new BN9(0)
|
|
1775
|
-
};
|
|
1776
|
-
});
|
|
1777
|
-
}
|
|
1778
|
-
const activeBins = distributions.filter((element) => {
|
|
1779
|
-
return element.binId === activeId;
|
|
1780
|
-
});
|
|
1781
|
-
if (activeBins.length === 1) {
|
|
1782
|
-
const p0 = getPriceOfBinByBinId(activeId, binStep);
|
|
1783
|
-
let wx0 = new Decimal3(0);
|
|
1784
|
-
let wy0 = new Decimal3(0);
|
|
1785
|
-
const activeBin = activeBins[0];
|
|
1786
|
-
if (amountXInActiveBin.isZero() && amountYInActiveBin.isZero()) {
|
|
1787
|
-
wx0 = new Decimal3(activeBin.weight).div(p0.mul(new Decimal3(2)));
|
|
1788
|
-
wy0 = new Decimal3(activeBin.weight).div(new Decimal3(2));
|
|
1789
|
-
} else {
|
|
1790
|
-
const amountXInActiveBinDec = new Decimal3(amountXInActiveBin.toString());
|
|
1791
|
-
const amountYInActiveBinDec = new Decimal3(amountYInActiveBin.toString());
|
|
1792
|
-
if (!amountXInActiveBin.isZero()) {
|
|
1793
|
-
wx0 = new Decimal3(activeBin.weight).div(p0.add(amountYInActiveBinDec.div(amountXInActiveBinDec)));
|
|
1794
|
-
}
|
|
1795
|
-
if (!amountYInActiveBin.isZero()) {
|
|
1796
|
-
wy0 = new Decimal3(activeBin.weight).div(new Decimal3(1).add(p0.mul(amountXInActiveBinDec).div(amountYInActiveBinDec)));
|
|
1797
|
-
}
|
|
1798
|
-
}
|
|
1799
|
-
let totalWeightX2 = wx0;
|
|
1800
|
-
let totalWeightY2 = wy0;
|
|
1801
|
-
distributions.forEach((element) => {
|
|
1802
|
-
if (element.binId < activeId) {
|
|
1803
|
-
totalWeightY2 = totalWeightY2.add(new Decimal3(element.weight));
|
|
1804
|
-
}
|
|
1805
|
-
if (element.binId > activeId) {
|
|
1806
|
-
const price = getPriceOfBinByBinId(element.binId, binStep);
|
|
1807
|
-
const weighPerPrice = new Decimal3(element.weight).div(price);
|
|
1808
|
-
totalWeightX2 = totalWeightX2.add(weighPerPrice);
|
|
1809
|
-
}
|
|
1810
|
-
});
|
|
1811
|
-
const kx2 = new Decimal3(amountX.toString()).div(totalWeightX2);
|
|
1812
|
-
const ky2 = new Decimal3(amountY.toString()).div(totalWeightY2);
|
|
1813
|
-
const k2 = kx2.lessThan(ky2) ? kx2 : ky2;
|
|
1814
|
-
return distributions.map((bin) => {
|
|
1815
|
-
if (bin.binId < activeId) {
|
|
1816
|
-
const amount = k2.mul(new Decimal3(bin.weight));
|
|
1817
|
-
return {
|
|
1818
|
-
binId: bin.binId,
|
|
1819
|
-
amountX: new BN9(0),
|
|
1820
|
-
amountY: new BN9(amount.floor().toString())
|
|
1821
|
-
};
|
|
1822
|
-
}
|
|
1823
|
-
if (bin.binId > activeId) {
|
|
1824
|
-
const price = getPriceOfBinByBinId(bin.binId, binStep);
|
|
1825
|
-
const weighPerPrice = new Decimal3(bin.weight).div(price);
|
|
1826
|
-
const amount = k2.mul(weighPerPrice);
|
|
1827
|
-
return {
|
|
1828
|
-
binId: bin.binId,
|
|
1829
|
-
amountX: new BN9(amount.floor().toString()),
|
|
1830
|
-
amountY: new BN9(0)
|
|
1831
|
-
};
|
|
1832
|
-
}
|
|
1833
|
-
const amountXActiveBin = k2.mul(wx0);
|
|
1834
|
-
const amountYActiveBin = k2.mul(wy0);
|
|
1835
|
-
return {
|
|
1836
|
-
binId: bin.binId,
|
|
1837
|
-
amountX: new BN9(amountXActiveBin.floor().toString()),
|
|
1838
|
-
amountY: new BN9(amountYActiveBin.floor().toString())
|
|
1839
|
-
};
|
|
1840
|
-
});
|
|
1841
|
-
}
|
|
1842
|
-
let totalWeightX = new Decimal3(0);
|
|
1843
|
-
let totalWeightY = new Decimal3(0);
|
|
1844
|
-
distributions.forEach((element) => {
|
|
1845
|
-
if (element.binId < activeId) {
|
|
1846
|
-
totalWeightY = totalWeightY.add(new Decimal3(element.weight));
|
|
1847
|
-
} else {
|
|
1848
|
-
const price = getPriceOfBinByBinId(element.binId, binStep);
|
|
1849
|
-
const weighPerPrice = new Decimal3(element.weight).div(price);
|
|
1850
|
-
totalWeightX = totalWeightX.add(weighPerPrice);
|
|
1851
|
-
}
|
|
1852
|
-
});
|
|
1853
|
-
const kx = new Decimal3(amountX.toString()).div(totalWeightX);
|
|
1854
|
-
const ky = new Decimal3(amountY.toString()).div(totalWeightY);
|
|
1855
|
-
const k = kx.lessThan(ky) ? kx : ky;
|
|
1856
|
-
return distributions.map((bin) => {
|
|
1857
|
-
if (bin.binId < activeId) {
|
|
1858
|
-
const amount2 = k.mul(new Decimal3(bin.weight));
|
|
1859
|
-
return {
|
|
1860
|
-
binId: bin.binId,
|
|
1861
|
-
amountX: new BN9(0),
|
|
1862
|
-
amountY: new BN9(amount2.floor().toString())
|
|
1863
|
-
};
|
|
1864
|
-
}
|
|
1865
|
-
const price = getPriceOfBinByBinId(bin.binId, binStep);
|
|
1866
|
-
const weighPerPrice = new Decimal3(bin.weight).div(price);
|
|
1867
|
-
const amount = k.mul(weighPerPrice);
|
|
1868
|
-
return {
|
|
1869
|
-
binId: bin.binId,
|
|
1870
|
-
amountX: new BN9(amount.floor().toString()),
|
|
1871
|
-
amountY: new BN9(0)
|
|
1872
|
-
};
|
|
1873
|
-
});
|
|
1874
|
-
}
|
|
1875
|
-
|
|
1876
|
-
// src/math/dlmmStrategy.ts
|
|
1877
|
-
var StrategyType = /* @__PURE__ */ ((StrategyType2) => {
|
|
1878
|
-
StrategyType2[StrategyType2["Spot"] = 1] = "Spot";
|
|
1879
|
-
StrategyType2[StrategyType2["Curve"] = 2] = "Curve";
|
|
1880
|
-
StrategyType2[StrategyType2["BidAsk"] = 3] = "BidAsk";
|
|
1881
|
-
return StrategyType2;
|
|
1882
|
-
})(StrategyType || {});
|
|
1883
|
-
function toWeightSpotBalanced(minBinId, maxBinId) {
|
|
1884
|
-
const distributions = [];
|
|
1885
|
-
for (let i = minBinId; i <= maxBinId; i++) {
|
|
1886
|
-
distributions.push({
|
|
1887
|
-
binId: i,
|
|
1888
|
-
weight: 1
|
|
1889
|
-
});
|
|
1890
|
-
}
|
|
1891
|
-
return distributions;
|
|
1892
|
-
}
|
|
1893
|
-
var DEFAULT_MAX_WEIGHT = 2e3;
|
|
1894
|
-
var DEFAULT_MIN_WEIGHT = 200;
|
|
1895
|
-
function toWeightCurve(minBinId, maxBinId, activeId) {
|
|
1896
|
-
if (activeId < minBinId || activeId > maxBinId) {
|
|
1897
|
-
throw new ClmmpoolsError("Invalid strategy params", "InvalidParams" /* InvalidParams */);
|
|
1898
|
-
}
|
|
1899
|
-
const maxWeight = DEFAULT_MAX_WEIGHT;
|
|
1900
|
-
const minWeight = DEFAULT_MIN_WEIGHT;
|
|
1901
|
-
const diffWeight = maxWeight - minWeight;
|
|
1902
|
-
const diffMinWeight = activeId > minBinId ? Math.floor(diffWeight / (activeId - minBinId)) : 0;
|
|
1903
|
-
const diffMaxWeight = maxBinId > activeId ? Math.floor(diffWeight / (maxBinId - activeId)) : 0;
|
|
1904
|
-
const distributions = [];
|
|
1905
|
-
for (let i = minBinId; i <= maxBinId; i++) {
|
|
1906
|
-
if (i < activeId) {
|
|
1907
|
-
distributions.push({
|
|
1908
|
-
binId: i,
|
|
1909
|
-
weight: maxWeight - (activeId - i) * diffMinWeight
|
|
1910
|
-
});
|
|
1911
|
-
} else if (i > activeId) {
|
|
1912
|
-
distributions.push({
|
|
1913
|
-
binId: i,
|
|
1914
|
-
weight: maxWeight - (i - activeId) * diffMaxWeight
|
|
1915
|
-
});
|
|
1916
|
-
} else {
|
|
1917
|
-
distributions.push({
|
|
1918
|
-
binId: i,
|
|
1919
|
-
weight: maxWeight
|
|
1920
|
-
});
|
|
1921
|
-
}
|
|
1922
|
-
}
|
|
1923
|
-
return distributions;
|
|
1924
|
-
}
|
|
1925
|
-
function toWeightBidAsk(minBinId, maxBinId, activeId) {
|
|
1926
|
-
if (activeId < minBinId || activeId > maxBinId) {
|
|
1927
|
-
throw new ClmmpoolsError("Invalid strategy params", "InvalidParams" /* InvalidParams */);
|
|
1928
|
-
}
|
|
1929
|
-
const maxWeight = DEFAULT_MAX_WEIGHT;
|
|
1930
|
-
const minWeight = DEFAULT_MIN_WEIGHT;
|
|
1931
|
-
const diffWeight = maxWeight - minWeight;
|
|
1932
|
-
const diffMinWeight = activeId > minBinId ? Math.floor(diffWeight / (activeId - minBinId)) : 0;
|
|
1933
|
-
const diffMaxWeight = maxBinId > activeId ? Math.floor(diffWeight / (maxBinId - activeId)) : 0;
|
|
1934
|
-
const distributions = [];
|
|
1935
|
-
for (let i = minBinId; i <= maxBinId; i++) {
|
|
1936
|
-
if (i < activeId) {
|
|
1937
|
-
distributions.push({
|
|
1938
|
-
binId: i,
|
|
1939
|
-
weight: minWeight + (activeId - i) * diffMinWeight
|
|
1940
|
-
});
|
|
1941
|
-
} else if (i > activeId) {
|
|
1942
|
-
distributions.push({
|
|
1943
|
-
binId: i,
|
|
1944
|
-
weight: minWeight + (i - activeId) * diffMaxWeight
|
|
1945
|
-
});
|
|
1946
|
-
} else {
|
|
1947
|
-
distributions.push({
|
|
1948
|
-
binId: i,
|
|
1949
|
-
weight: minWeight
|
|
1950
|
-
});
|
|
1951
|
-
}
|
|
1952
|
-
}
|
|
1953
|
-
return distributions;
|
|
1954
|
-
}
|
|
1955
|
-
function autoFillYByStrategy(activeId, binStep, amountX, amountXInActiveBin, amountYInActiveBin, minBinId, maxBinId, strategyType) {
|
|
1956
|
-
switch (strategyType) {
|
|
1957
|
-
case 1 /* Spot */: {
|
|
1958
|
-
const weights = toWeightSpotBalanced(minBinId, maxBinId);
|
|
1959
|
-
return autoFillYByWeight(activeId, binStep, amountX, amountXInActiveBin, amountYInActiveBin, weights);
|
|
1960
|
-
}
|
|
1961
|
-
case 2 /* Curve */: {
|
|
1962
|
-
const weights = toWeightCurve(minBinId, maxBinId, activeId);
|
|
1963
|
-
return autoFillYByWeight(activeId, binStep, amountX, amountXInActiveBin, amountYInActiveBin, weights);
|
|
1964
|
-
}
|
|
1965
|
-
case 3 /* BidAsk */: {
|
|
1966
|
-
const weights = toWeightBidAsk(minBinId, maxBinId, activeId);
|
|
1967
|
-
return autoFillYByWeight(activeId, binStep, amountX, amountXInActiveBin, amountYInActiveBin, weights);
|
|
1968
|
-
}
|
|
1969
|
-
default:
|
|
1970
|
-
throw new Error(`Unsupported strategy type: ${strategyType}`);
|
|
1971
|
-
}
|
|
1972
|
-
}
|
|
1973
|
-
function autoFillXByStrategy(activeId, binStep, amountY, amountXInActiveBin, amountYInActiveBin, minBinId, maxBinId, strategyType) {
|
|
1974
|
-
switch (strategyType) {
|
|
1975
|
-
case 1 /* Spot */: {
|
|
1976
|
-
const weights = toWeightSpotBalanced(minBinId, maxBinId);
|
|
1977
|
-
return autoFillXByWeight(activeId, binStep, amountY, amountXInActiveBin, amountYInActiveBin, weights);
|
|
1978
|
-
}
|
|
1979
|
-
case 2 /* Curve */: {
|
|
1980
|
-
const weights = toWeightCurve(minBinId, maxBinId, activeId);
|
|
1981
|
-
return autoFillXByWeight(activeId, binStep, amountY, amountXInActiveBin, amountYInActiveBin, weights);
|
|
1982
|
-
}
|
|
1983
|
-
case 3 /* BidAsk */: {
|
|
1984
|
-
const weights = toWeightBidAsk(minBinId, maxBinId, activeId);
|
|
1985
|
-
return autoFillXByWeight(activeId, binStep, amountY, amountXInActiveBin, amountYInActiveBin, weights);
|
|
1986
|
-
}
|
|
1987
|
-
default:
|
|
1988
|
-
throw new Error(`Unsupported strategy type: ${strategyType}`);
|
|
1989
|
-
}
|
|
1990
|
-
}
|
|
1991
|
-
function toAmountsBothSideByStrategy(activeId, binStep, minBinId, maxBinId, amountX, amountY, amountXInActiveBin, amountYInActiveBin, strategyType) {
|
|
1992
|
-
const isSingleSideX = amountY.isZero();
|
|
1993
|
-
switch (strategyType) {
|
|
1994
|
-
case 1 /* Spot */: {
|
|
1995
|
-
const weights = toWeightSpotBalanced(minBinId, maxBinId);
|
|
1996
|
-
return toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights);
|
|
1997
|
-
}
|
|
1998
|
-
case 2 /* Curve */: {
|
|
1999
|
-
const weights = toWeightCurve(minBinId, maxBinId, activeId);
|
|
2000
|
-
return toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights);
|
|
2001
|
-
}
|
|
2002
|
-
case 3 /* BidAsk */: {
|
|
2003
|
-
const weights = toWeightBidAsk(minBinId, maxBinId, activeId);
|
|
2004
|
-
return toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights);
|
|
2005
|
-
}
|
|
2006
|
-
default:
|
|
2007
|
-
throw new Error(`Unsupported strategy type: ${strategyType}`);
|
|
2008
|
-
}
|
|
2009
|
-
}
|
|
2010
|
-
|
|
2011
|
-
// src/math/LiquidityHelper.ts
|
|
2012
|
-
import Decimal5 from "decimal.js";
|
|
2013
|
-
|
|
2014
|
-
// src/utils/numbers.ts
|
|
2015
|
-
import Decimal4 from "decimal.js";
|
|
2016
|
-
function d(value) {
|
|
2017
|
-
if (Decimal4.isDecimal(value)) {
|
|
2018
|
-
return value;
|
|
2019
|
-
}
|
|
2020
|
-
return new Decimal4(value === void 0 ? 0 : value);
|
|
2021
|
-
}
|
|
2022
|
-
function decimalsMultiplier(decimals) {
|
|
2023
|
-
return d(10).pow(d(decimals).abs());
|
|
2024
|
-
}
|
|
2025
|
-
|
|
2026
|
-
// src/math/LiquidityHelper.ts
|
|
2027
|
-
function withLiquiditySlippage(value, slippage, mode) {
|
|
2028
|
-
return d(value)[mode](d(value).mul(slippage)).toDP(0);
|
|
2029
|
-
}
|
|
2030
|
-
function getLiquidityAndCoinYByCoinX(coinInVal, reserveInSize, reserveOutSize, lpSupply) {
|
|
2031
|
-
if (coinInVal.lessThanOrEqualTo(0)) {
|
|
2032
|
-
throw new ClmmpoolsError("coinInVal is less than zero", "InvalidCoinAmount" /* InvalidCoinAmount */);
|
|
2033
|
-
}
|
|
2034
|
-
if (reserveInSize.lessThanOrEqualTo(0) || reserveOutSize.lessThanOrEqualTo(0)) {
|
|
2035
|
-
return -1;
|
|
2036
|
-
}
|
|
2037
|
-
const coinYAmount = coinInVal.mul(reserveOutSize).div(reserveInSize);
|
|
2038
|
-
const sqrtSupply = lpSupply;
|
|
2039
|
-
const lpX = coinInVal.div(reserveInSize).mul(sqrtSupply);
|
|
2040
|
-
const lpY = coinYAmount.div(reserveOutSize).mul(sqrtSupply);
|
|
2041
|
-
const lpAmount = Decimal5.min(lpX, lpY);
|
|
2042
|
-
return {
|
|
2043
|
-
coinYAmount,
|
|
2044
|
-
lpAmount
|
|
2045
|
-
};
|
|
2046
|
-
}
|
|
2047
|
-
function getCoinXYForLiquidity(liquidity, reserveInSize, reserveOutSize, lpSuply) {
|
|
2048
|
-
if (liquidity.lessThanOrEqualTo(0)) {
|
|
2049
|
-
throw new ClmmpoolsError("liquidity can't be equal or less than zero", "InvalidLiquidityAmount" /* InvalidLiquidityAmount */);
|
|
2050
|
-
}
|
|
2051
|
-
if (reserveInSize.lessThanOrEqualTo(0) || reserveOutSize.lessThanOrEqualTo(0)) {
|
|
2052
|
-
throw new ClmmpoolsError("reserveInSize or reserveOutSize can not be equal or less than zero", "InvalidReserveAmount" /* InvalidReserveAmount */);
|
|
2053
|
-
}
|
|
2054
|
-
const sqrtSupply = lpSuply;
|
|
2055
|
-
const coinXAmount = liquidity.div(sqrtSupply).mul(reserveInSize);
|
|
2056
|
-
const coinYAmount = liquidity.div(sqrtSupply).mul(reserveOutSize);
|
|
2057
|
-
return {
|
|
2058
|
-
coinXAmount,
|
|
2059
|
-
coinYAmount
|
|
2060
|
-
};
|
|
2061
|
-
}
|
|
2062
|
-
|
|
2063
1594
|
// src/math/percentage.ts
|
|
2064
|
-
import
|
|
1595
|
+
import BN9 from "bn.js";
|
|
2065
1596
|
var Percentage = class {
|
|
2066
1597
|
numerator;
|
|
2067
1598
|
denominator;
|
|
@@ -2089,8 +1620,8 @@ var Percentage = class {
|
|
|
2089
1620
|
* @returns
|
|
2090
1621
|
*/
|
|
2091
1622
|
static fromFraction(numerator, denominator) {
|
|
2092
|
-
const num = typeof numerator === "number" ? new
|
|
2093
|
-
const denom = typeof denominator === "number" ? new
|
|
1623
|
+
const num = typeof numerator === "number" ? new BN9(numerator.toString()) : numerator;
|
|
1624
|
+
const denom = typeof denominator === "number" ? new BN9(denominator.toString()) : denominator;
|
|
2094
1625
|
return new Percentage(num, denom);
|
|
2095
1626
|
}
|
|
2096
1627
|
};
|
|
@@ -2190,7 +1721,7 @@ function adjustForCoinSlippage(tokenAmount, slippage, adjustUp) {
|
|
|
2190
1721
|
}
|
|
2191
1722
|
|
|
2192
1723
|
// src/math/SplitSwap.ts
|
|
2193
|
-
import
|
|
1724
|
+
import BN10 from "bn.js";
|
|
2194
1725
|
var SplitUnit = /* @__PURE__ */ ((SplitUnit2) => {
|
|
2195
1726
|
SplitUnit2[SplitUnit2["FIVE"] = 5] = "FIVE";
|
|
2196
1727
|
SplitUnit2[SplitUnit2["TEN"] = 10] = "TEN";
|
|
@@ -2248,7 +1779,7 @@ function updateSplitSwapResult(maxIndex, currentIndex, splitSwapResult, stepResu
|
|
|
2248
1779
|
return splitSwapResult;
|
|
2249
1780
|
}
|
|
2250
1781
|
function computeSplitSwap(a2b, byAmountIn, amounts, poolData, swapTicks) {
|
|
2251
|
-
let currentLiquidity = new
|
|
1782
|
+
let currentLiquidity = new BN10(poolData.liquidity);
|
|
2252
1783
|
let { currentSqrtPrice } = poolData;
|
|
2253
1784
|
let splitSwapResult = {
|
|
2254
1785
|
amountInArray: [],
|
|
@@ -2311,7 +1842,7 @@ function computeSplitSwap(a2b, byAmountIn, amounts, poolData, swapTicks) {
|
|
|
2311
1842
|
targetSqrtPrice,
|
|
2312
1843
|
currentLiquidity,
|
|
2313
1844
|
remainerAmount,
|
|
2314
|
-
new
|
|
1845
|
+
new BN10(poolData.feeRate),
|
|
2315
1846
|
byAmountIn
|
|
2316
1847
|
);
|
|
2317
1848
|
tempStepResult = stepResult;
|
|
@@ -2323,7 +1854,7 @@ function computeSplitSwap(a2b, byAmountIn, amounts, poolData, swapTicks) {
|
|
|
2323
1854
|
splitSwapResult.amountOutArray[i] = splitSwapResult.amountOutArray[i].add(stepResult.amountOut);
|
|
2324
1855
|
splitSwapResult.feeAmountArray[i] = splitSwapResult.feeAmountArray[i].add(stepResult.feeAmount);
|
|
2325
1856
|
if (stepResult.nextSqrtPrice.eq(tick.sqrtPrice)) {
|
|
2326
|
-
signedLiquidityChange = a2b ? tick.liquidityNet.mul(new
|
|
1857
|
+
signedLiquidityChange = a2b ? tick.liquidityNet.mul(new BN10(-1)) : tick.liquidityNet;
|
|
2327
1858
|
currentLiquidity = signedLiquidityChange.gt(ZERO) ? currentLiquidity.add(signedLiquidityChange) : currentLiquidity.sub(signedLiquidityChange.abs());
|
|
2328
1859
|
currentSqrtPrice = tick.sqrtPrice;
|
|
2329
1860
|
} else {
|
|
@@ -2348,7 +1879,7 @@ function computeSplitSwap(a2b, byAmountIn, amounts, poolData, swapTicks) {
|
|
|
2348
1879
|
break;
|
|
2349
1880
|
}
|
|
2350
1881
|
if (tempStepResult.nextSqrtPrice.eq(tick.sqrtPrice)) {
|
|
2351
|
-
signedLiquidityChange = a2b ? tick.liquidityNet.mul(new
|
|
1882
|
+
signedLiquidityChange = a2b ? tick.liquidityNet.mul(new BN10(-1)) : tick.liquidityNet;
|
|
2352
1883
|
currentLiquidity = signedLiquidityChange.gt(ZERO) ? currentLiquidity.add(signedLiquidityChange) : currentLiquidity.sub(signedLiquidityChange.abs());
|
|
2353
1884
|
currentSqrtPrice = tick.sqrtPrice;
|
|
2354
1885
|
} else {
|
|
@@ -2403,22 +1934,17 @@ var SplitSwap = class {
|
|
|
2403
1934
|
}
|
|
2404
1935
|
};
|
|
2405
1936
|
|
|
2406
|
-
// src/
|
|
2407
|
-
import
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
const twoDec = new Decimal6(2);
|
|
2412
|
-
const price = new Decimal6(get_price_x128_from_real_id2(binId, binStep));
|
|
2413
|
-
return price.div(twoDec.pow(128)).mul(Decimal6.pow(10, decimalsA - decimalsB));
|
|
2414
|
-
}
|
|
2415
|
-
static getBinIdFromPrice(price, binStep, decimalsA, decimalsB) {
|
|
2416
|
-
const twoDec = new Decimal6(2);
|
|
2417
|
-
const tenDec = new Decimal6(10);
|
|
2418
|
-
const realid = get_real_id_from_price_x128(new Decimal6(price).mul(tenDec.pow(decimalsB - decimalsA)).mul(twoDec.pow(128)).toDecimalPlaces(0).toString(), binStep);
|
|
2419
|
-
return realid;
|
|
1937
|
+
// src/utils/numbers.ts
|
|
1938
|
+
import Decimal3 from "decimal.js";
|
|
1939
|
+
function d(value) {
|
|
1940
|
+
if (Decimal3.isDecimal(value)) {
|
|
1941
|
+
return value;
|
|
2420
1942
|
}
|
|
2421
|
-
|
|
1943
|
+
return new Decimal3(value === void 0 ? 0 : value);
|
|
1944
|
+
}
|
|
1945
|
+
function decimalsMultiplier(decimals) {
|
|
1946
|
+
return d(10).pow(d(decimals).abs());
|
|
1947
|
+
}
|
|
2422
1948
|
|
|
2423
1949
|
// src/utils/objects.ts
|
|
2424
1950
|
function getSuiObjectData(resp) {
|
|
@@ -2573,7 +2099,7 @@ function buildPool(objects) {
|
|
|
2573
2099
|
const rewarders = [];
|
|
2574
2100
|
fields.rewarder_manager.fields.rewarders.forEach((item) => {
|
|
2575
2101
|
const { emissions_per_second } = item.fields;
|
|
2576
|
-
const emissionSeconds = MathUtil.fromX64(new
|
|
2102
|
+
const emissionSeconds = MathUtil.fromX64(new BN11(emissions_per_second));
|
|
2577
2103
|
const emissionsEveryDay = Math.floor(emissionSeconds.toNumber() * 60 * 60 * 24);
|
|
2578
2104
|
rewarders.push({
|
|
2579
2105
|
emissions_per_second,
|
|
@@ -2765,11 +2291,11 @@ function buildTickData(objects) {
|
|
|
2765
2291
|
const possition = {
|
|
2766
2292
|
objectId: getObjectId(objects),
|
|
2767
2293
|
index: asIntN(BigInt(valueItem.index.fields.bits)),
|
|
2768
|
-
sqrtPrice: new
|
|
2769
|
-
liquidityNet: new
|
|
2770
|
-
liquidityGross: new
|
|
2771
|
-
feeGrowthOutsideA: new
|
|
2772
|
-
feeGrowthOutsideB: new
|
|
2294
|
+
sqrtPrice: new BN11(valueItem.sqrt_price),
|
|
2295
|
+
liquidityNet: new BN11(valueItem.liquidity_net.fields.bits),
|
|
2296
|
+
liquidityGross: new BN11(valueItem.liquidity_gross),
|
|
2297
|
+
feeGrowthOutsideA: new BN11(valueItem.fee_growth_outside_a),
|
|
2298
|
+
feeGrowthOutsideB: new BN11(valueItem.fee_growth_outside_b),
|
|
2773
2299
|
rewardersGrowthOutside: valueItem.rewards_growth_outside
|
|
2774
2300
|
};
|
|
2775
2301
|
return possition;
|
|
@@ -2779,11 +2305,11 @@ function buildTickDataByEvent(fields) {
|
|
|
2779
2305
|
throw new ClmmpoolsError(`Invalid tick fields.`, "InvalidTickFields" /* InvalidTickFields */);
|
|
2780
2306
|
}
|
|
2781
2307
|
const index = asIntN(BigInt(fields.index.bits));
|
|
2782
|
-
const sqrtPrice = new
|
|
2783
|
-
const liquidityNet = new
|
|
2784
|
-
const liquidityGross = new
|
|
2785
|
-
const feeGrowthOutsideA = new
|
|
2786
|
-
const feeGrowthOutsideB = new
|
|
2308
|
+
const sqrtPrice = new BN11(fields.sqrt_price);
|
|
2309
|
+
const liquidityNet = new BN11(fields.liquidity_net.bits);
|
|
2310
|
+
const liquidityGross = new BN11(fields.liquidity_gross);
|
|
2311
|
+
const feeGrowthOutsideA = new BN11(fields.fee_growth_outside_a);
|
|
2312
|
+
const feeGrowthOutsideB = new BN11(fields.fee_growth_outside_b);
|
|
2787
2313
|
const rewardersGrowthOutside = fields.rewards_growth_outside || [];
|
|
2788
2314
|
const tick = {
|
|
2789
2315
|
objectId: "",
|
|
@@ -2802,7 +2328,7 @@ function buildClmmPositionName(pool_index, position_index) {
|
|
|
2802
2328
|
}
|
|
2803
2329
|
|
|
2804
2330
|
// src/utils/tick.ts
|
|
2805
|
-
import
|
|
2331
|
+
import BN12 from "bn.js";
|
|
2806
2332
|
var TickUtil = class {
|
|
2807
2333
|
/**
|
|
2808
2334
|
* Get min tick index.
|
|
@@ -2842,22 +2368,22 @@ function getRewardInTickRange(pool, tickLower, tickUpper, tickLowerIndex, tickUp
|
|
|
2842
2368
|
let rewarder_growth_below = growthGlobal[i];
|
|
2843
2369
|
if (tickLower !== null) {
|
|
2844
2370
|
if (pool.current_tick_index < tickLowerIndex) {
|
|
2845
|
-
rewarder_growth_below = growthGlobal[i].sub(new
|
|
2371
|
+
rewarder_growth_below = growthGlobal[i].sub(new BN12(tickLower.rewardersGrowthOutside[i]));
|
|
2846
2372
|
} else {
|
|
2847
2373
|
rewarder_growth_below = tickLower.rewardersGrowthOutside[i];
|
|
2848
2374
|
}
|
|
2849
2375
|
}
|
|
2850
|
-
let rewarder_growth_above = new
|
|
2376
|
+
let rewarder_growth_above = new BN12(0);
|
|
2851
2377
|
if (tickUpper !== null) {
|
|
2852
2378
|
if (pool.current_tick_index >= tickUpperIndex) {
|
|
2853
|
-
rewarder_growth_above = growthGlobal[i].sub(new
|
|
2379
|
+
rewarder_growth_above = growthGlobal[i].sub(new BN12(tickUpper.rewardersGrowthOutside[i]));
|
|
2854
2380
|
} else {
|
|
2855
2381
|
rewarder_growth_above = tickUpper.rewardersGrowthOutside[i];
|
|
2856
2382
|
}
|
|
2857
2383
|
}
|
|
2858
2384
|
const rewGrowthInside = MathUtil.subUnderflowU128(
|
|
2859
|
-
MathUtil.subUnderflowU128(new
|
|
2860
|
-
new
|
|
2385
|
+
MathUtil.subUnderflowU128(new BN12(growthGlobal[i]), new BN12(rewarder_growth_below)),
|
|
2386
|
+
new BN12(rewarder_growth_above)
|
|
2861
2387
|
);
|
|
2862
2388
|
rewarderGrowthInside.push(rewGrowthInside);
|
|
2863
2389
|
}
|
|
@@ -2865,8 +2391,8 @@ function getRewardInTickRange(pool, tickLower, tickUpper, tickLowerIndex, tickUp
|
|
|
2865
2391
|
}
|
|
2866
2392
|
|
|
2867
2393
|
// src/utils/transaction-util.ts
|
|
2868
|
-
import
|
|
2869
|
-
import
|
|
2394
|
+
import BN13 from "bn.js";
|
|
2395
|
+
import Decimal4 from "decimal.js";
|
|
2870
2396
|
import { Transaction } from "@mysten/sui/transactions";
|
|
2871
2397
|
function findAdjustCoin(coinPair) {
|
|
2872
2398
|
const isAdjustCoinA = CoinAssist.isSuiCoin(coinPair.coinTypeA);
|
|
@@ -2874,7 +2400,7 @@ function findAdjustCoin(coinPair) {
|
|
|
2874
2400
|
return { isAdjustCoinA, isAdjustCoinB };
|
|
2875
2401
|
}
|
|
2876
2402
|
function reverSlippageAmount(slippageAmount, slippage) {
|
|
2877
|
-
return
|
|
2403
|
+
return Decimal4.ceil(d(slippageAmount).div(1 + slippage)).toString();
|
|
2878
2404
|
}
|
|
2879
2405
|
async function printTransaction(tx, isPrint = true) {
|
|
2880
2406
|
console.log(`inputs`, tx.blockData.inputs);
|
|
@@ -3174,7 +2700,7 @@ var _TransactionUtil = class {
|
|
|
3174
2700
|
const liquidityInput = ClmmPoolUtil.estLiquidityAndcoinAmountFromOneAmounts(
|
|
3175
2701
|
Number(params.tick_lower),
|
|
3176
2702
|
Number(params.tick_upper),
|
|
3177
|
-
new
|
|
2703
|
+
new BN13(coinAmount),
|
|
3178
2704
|
params.fix_amount_a,
|
|
3179
2705
|
true,
|
|
3180
2706
|
slippage,
|
|
@@ -3248,12 +2774,12 @@ var _TransactionUtil = class {
|
|
|
3248
2774
|
max_amount_a = params.amount_a;
|
|
3249
2775
|
min_amount_a = params.amount_a;
|
|
3250
2776
|
max_amount_b = params.amount_b;
|
|
3251
|
-
min_amount_b = new
|
|
2777
|
+
min_amount_b = new Decimal4(params.amount_b).div(new Decimal4(1).plus(new Decimal4(params.slippage))).mul(new Decimal4(1).minus(new Decimal4(params.slippage))).toDecimalPlaces(0).toNumber();
|
|
3252
2778
|
} else {
|
|
3253
2779
|
max_amount_b = params.amount_b;
|
|
3254
2780
|
min_amount_b = params.amount_b;
|
|
3255
2781
|
max_amount_a = params.amount_a;
|
|
3256
|
-
min_amount_a = new
|
|
2782
|
+
min_amount_a = new Decimal4(params.amount_a).div(new Decimal4(1).plus(new Decimal4(params.slippage))).mul(new Decimal4(1).minus(new Decimal4(params.slippage))).toDecimalPlaces(0).toNumber();
|
|
3257
2783
|
}
|
|
3258
2784
|
const args = params.is_open ? [
|
|
3259
2785
|
tx.object(clmmConfig.global_config_id),
|
|
@@ -4242,7 +3768,7 @@ var _TransactionUtil = class {
|
|
|
4242
3768
|
const basePath = splitPath.basePaths[i];
|
|
4243
3769
|
a2b.push(basePath.direction);
|
|
4244
3770
|
poolAddress.push(basePath.poolAddress);
|
|
4245
|
-
rawAmountLimit.push(new
|
|
3771
|
+
rawAmountLimit.push(new BN13(basePath.inputAmount.toString()));
|
|
4246
3772
|
if (i === 0) {
|
|
4247
3773
|
coinType.push(basePath.fromCoin, basePath.toCoin);
|
|
4248
3774
|
} else {
|
|
@@ -4250,8 +3776,8 @@ var _TransactionUtil = class {
|
|
|
4250
3776
|
}
|
|
4251
3777
|
}
|
|
4252
3778
|
const onePath = {
|
|
4253
|
-
amountIn: new
|
|
4254
|
-
amountOut: new
|
|
3779
|
+
amountIn: new BN13(splitPath.inputAmount.toString()),
|
|
3780
|
+
amountOut: new BN13(splitPath.outputAmount.toString()),
|
|
4255
3781
|
poolAddress,
|
|
4256
3782
|
a2b,
|
|
4257
3783
|
rawAmountLimit,
|
|
@@ -4608,9 +4134,9 @@ var TxBlock = class {
|
|
|
4608
4134
|
};
|
|
4609
4135
|
|
|
4610
4136
|
// src/utils/deepbook-utils.ts
|
|
4611
|
-
import
|
|
4137
|
+
import BN14 from "bn.js";
|
|
4612
4138
|
import { Transaction as Transaction3 } from "@mysten/sui/transactions";
|
|
4613
|
-
var FLOAT_SCALING = new
|
|
4139
|
+
var FLOAT_SCALING = new BN14(1e9);
|
|
4614
4140
|
var DeepbookUtils = class {
|
|
4615
4141
|
static createAccountCap(senderAddress, sdkOptions, tx, isTransfer = false) {
|
|
4616
4142
|
if (senderAddress.length === 0) {
|
|
@@ -4756,9 +4282,9 @@ var DeepbookUtils = class {
|
|
|
4756
4282
|
static async preSwap(sdk, pool, a2b, amountIn) {
|
|
4757
4283
|
let isExceed = false;
|
|
4758
4284
|
let amountOut = ZERO;
|
|
4759
|
-
let remainAmount = new
|
|
4285
|
+
let remainAmount = new BN14(amountIn);
|
|
4760
4286
|
let feeAmount = ZERO;
|
|
4761
|
-
const initAmountIn = new
|
|
4287
|
+
const initAmountIn = new BN14(amountIn);
|
|
4762
4288
|
if (a2b) {
|
|
4763
4289
|
let bids = await this.getPoolBids(sdk, pool.poolID, pool.baseAsset, pool.quoteAsset);
|
|
4764
4290
|
if (bids === null) {
|
|
@@ -4768,16 +4294,16 @@ var DeepbookUtils = class {
|
|
|
4768
4294
|
return b.price - a.price;
|
|
4769
4295
|
});
|
|
4770
4296
|
for (let i = 0; i < bids.length; i += 1) {
|
|
4771
|
-
const curBidAmount = new
|
|
4772
|
-
const curBidPrice = new
|
|
4773
|
-
const fee = curBidAmount.mul(new
|
|
4297
|
+
const curBidAmount = new BN14(bids[i].quantity);
|
|
4298
|
+
const curBidPrice = new BN14(bids[i].price);
|
|
4299
|
+
const fee = curBidAmount.mul(new BN14(curBidPrice)).mul(new BN14(pool.takerFeeRate)).div(FLOAT_SCALING).div(FLOAT_SCALING);
|
|
4774
4300
|
if (remainAmount.gt(curBidAmount)) {
|
|
4775
4301
|
remainAmount = remainAmount.sub(curBidAmount);
|
|
4776
4302
|
amountOut = amountOut.add(curBidAmount.mul(curBidPrice).div(FLOAT_SCALING).sub(fee));
|
|
4777
4303
|
feeAmount = feeAmount.add(fee);
|
|
4778
4304
|
} else {
|
|
4779
|
-
const curOut = remainAmount.mul(new
|
|
4780
|
-
const curFee = curOut.mul(new
|
|
4305
|
+
const curOut = remainAmount.mul(new BN14(bids[i].price)).div(FLOAT_SCALING);
|
|
4306
|
+
const curFee = curOut.mul(new BN14(pool.takerFeeRate)).div(FLOAT_SCALING);
|
|
4781
4307
|
amountOut = amountOut.add(curOut.sub(curFee));
|
|
4782
4308
|
remainAmount = remainAmount.sub(remainAmount);
|
|
4783
4309
|
feeAmount = feeAmount.add(curFee);
|
|
@@ -4792,15 +4318,15 @@ var DeepbookUtils = class {
|
|
|
4792
4318
|
isExceed = true;
|
|
4793
4319
|
}
|
|
4794
4320
|
for (let i = 0; i < asks.length; i += 1) {
|
|
4795
|
-
const curAskAmount = new
|
|
4796
|
-
const fee = curAskAmount.mul(new
|
|
4321
|
+
const curAskAmount = new BN14(asks[i].price).mul(new BN14(asks[i].quantity)).div(new BN14(1e9));
|
|
4322
|
+
const fee = curAskAmount.mul(new BN14(pool.takerFeeRate)).div(FLOAT_SCALING);
|
|
4797
4323
|
const curAskAmountWithFee = curAskAmount.add(fee);
|
|
4798
4324
|
if (remainAmount.gt(curAskAmount)) {
|
|
4799
|
-
amountOut = amountOut.add(new
|
|
4325
|
+
amountOut = amountOut.add(new BN14(asks[i].quantity));
|
|
4800
4326
|
remainAmount = remainAmount.sub(curAskAmountWithFee);
|
|
4801
4327
|
feeAmount = feeAmount.add(fee);
|
|
4802
4328
|
} else {
|
|
4803
|
-
const splitNums = new
|
|
4329
|
+
const splitNums = new BN14(asks[i].quantity).div(new BN14(pool.lotSize));
|
|
4804
4330
|
const splitAmount = curAskAmountWithFee.div(splitNums);
|
|
4805
4331
|
const swapSplitNum = remainAmount.div(splitAmount);
|
|
4806
4332
|
amountOut = amountOut.add(swapSplitNum.muln(pool.lotSize));
|
|
@@ -5661,7 +5187,7 @@ var PoolModule = class {
|
|
|
5661
5187
|
};
|
|
5662
5188
|
|
|
5663
5189
|
// src/modules/positionModule.ts
|
|
5664
|
-
import
|
|
5190
|
+
import BN15 from "bn.js";
|
|
5665
5191
|
import { Transaction as Transaction5 } from "@mysten/sui/transactions";
|
|
5666
5192
|
import { isValidSuiObjectId } from "@mysten/sui/utils";
|
|
5667
5193
|
var PositionModule = class {
|
|
@@ -5883,8 +5409,8 @@ var PositionModule = class {
|
|
|
5883
5409
|
for (let i = 0; i < valueData.length; i += 1) {
|
|
5884
5410
|
const { parsedJson } = valueData[i];
|
|
5885
5411
|
const posRrewarderResult = {
|
|
5886
|
-
feeOwedA: new
|
|
5887
|
-
feeOwedB: new
|
|
5412
|
+
feeOwedA: new BN15(parsedJson.fee_owned_a),
|
|
5413
|
+
feeOwedB: new BN15(parsedJson.fee_owned_b),
|
|
5888
5414
|
position_id: parsedJson.position_id
|
|
5889
5415
|
};
|
|
5890
5416
|
result.push(posRrewarderResult);
|
|
@@ -6260,7 +5786,7 @@ var PositionModule = class {
|
|
|
6260
5786
|
};
|
|
6261
5787
|
|
|
6262
5788
|
// src/modules/rewarderModule.ts
|
|
6263
|
-
import
|
|
5789
|
+
import BN16 from "bn.js";
|
|
6264
5790
|
import { Transaction as Transaction6 } from "@mysten/sui/transactions";
|
|
6265
5791
|
var RewarderModule = class {
|
|
6266
5792
|
_sdk;
|
|
@@ -6286,7 +5812,7 @@ var RewarderModule = class {
|
|
|
6286
5812
|
}
|
|
6287
5813
|
const emissionsEveryDay = [];
|
|
6288
5814
|
for (const rewarderInfo of rewarderInfos) {
|
|
6289
|
-
const emissionSeconds = MathUtil.fromX64(new
|
|
5815
|
+
const emissionSeconds = MathUtil.fromX64(new BN16(rewarderInfo.emissions_per_second));
|
|
6290
5816
|
emissionsEveryDay.push({
|
|
6291
5817
|
emissions: Math.floor(emissionSeconds.toNumber() * 60 * 60 * 24),
|
|
6292
5818
|
coin_address: rewarderInfo.coinAddress
|
|
@@ -6305,20 +5831,20 @@ var RewarderModule = class {
|
|
|
6305
5831
|
const currentPool = await this.sdk.Pool.getPool(poolID);
|
|
6306
5832
|
const lastTime = currentPool.rewarder_last_updated_time;
|
|
6307
5833
|
currentPool.rewarder_last_updated_time = currentTime.toString();
|
|
6308
|
-
if (Number(currentPool.liquidity) === 0 || currentTime.eq(new
|
|
5834
|
+
if (Number(currentPool.liquidity) === 0 || currentTime.eq(new BN16(lastTime))) {
|
|
6309
5835
|
return currentPool;
|
|
6310
5836
|
}
|
|
6311
|
-
const timeDelta = currentTime.div(new
|
|
5837
|
+
const timeDelta = currentTime.div(new BN16(1e3)).sub(new BN16(lastTime)).add(new BN16(15));
|
|
6312
5838
|
const rewarderInfos = currentPool.rewarder_infos;
|
|
6313
5839
|
for (let i = 0; i < rewarderInfos.length; i += 1) {
|
|
6314
5840
|
const rewarderInfo = rewarderInfos[i];
|
|
6315
5841
|
const rewarderGrowthDelta = MathUtil.checkMulDivFloor(
|
|
6316
5842
|
timeDelta,
|
|
6317
|
-
new
|
|
6318
|
-
new
|
|
5843
|
+
new BN16(rewarderInfo.emissions_per_second),
|
|
5844
|
+
new BN16(currentPool.liquidity),
|
|
6319
5845
|
128
|
|
6320
5846
|
);
|
|
6321
|
-
this.growthGlobal[i] = new
|
|
5847
|
+
this.growthGlobal[i] = new BN16(rewarderInfo.growth_global).add(new BN16(rewarderGrowthDelta));
|
|
6322
5848
|
}
|
|
6323
5849
|
return currentPool;
|
|
6324
5850
|
}
|
|
@@ -6333,7 +5859,7 @@ var RewarderModule = class {
|
|
|
6333
5859
|
*/
|
|
6334
5860
|
async posRewardersAmount(poolID, positionHandle, positionID) {
|
|
6335
5861
|
const currentTime = Date.parse((/* @__PURE__ */ new Date()).toString());
|
|
6336
|
-
const pool = await this.updatePoolRewarder(poolID, new
|
|
5862
|
+
const pool = await this.updatePoolRewarder(poolID, new BN16(currentTime));
|
|
6337
5863
|
const position = await this.sdk.Position.getPositionRewarders(positionHandle, positionID);
|
|
6338
5864
|
if (position === void 0) {
|
|
6339
5865
|
return [];
|
|
@@ -6354,7 +5880,7 @@ var RewarderModule = class {
|
|
|
6354
5880
|
*/
|
|
6355
5881
|
async poolRewardersAmount(accountAddress, poolID) {
|
|
6356
5882
|
const currentTime = Date.parse((/* @__PURE__ */ new Date()).toString());
|
|
6357
|
-
const pool = await this.updatePoolRewarder(poolID, new
|
|
5883
|
+
const pool = await this.updatePoolRewarder(poolID, new BN16(currentTime));
|
|
6358
5884
|
const positions = await this.sdk.Position.getPositionList(accountAddress, [poolID]);
|
|
6359
5885
|
const tickDatas = await this.getPoolLowerAndUpperTicks(pool.ticks_handle, positions);
|
|
6360
5886
|
const rewarderAmount = [ZERO, ZERO, ZERO];
|
|
@@ -6381,38 +5907,38 @@ var RewarderModule = class {
|
|
|
6381
5907
|
const growthInside = [];
|
|
6382
5908
|
const AmountOwed = [];
|
|
6383
5909
|
if (rewardersInside.length > 0) {
|
|
6384
|
-
let growthDelta0 = MathUtil.subUnderflowU128(rewardersInside[0], new
|
|
6385
|
-
if (growthDelta0.gt(new
|
|
5910
|
+
let growthDelta0 = MathUtil.subUnderflowU128(rewardersInside[0], new BN16(position.reward_growth_inside_0));
|
|
5911
|
+
if (growthDelta0.gt(new BN16("3402823669209384634633745948738404"))) {
|
|
6386
5912
|
growthDelta0 = ONE;
|
|
6387
5913
|
}
|
|
6388
|
-
const amountOwed_0 = MathUtil.checkMulShiftRight(new
|
|
5914
|
+
const amountOwed_0 = MathUtil.checkMulShiftRight(new BN16(position.liquidity), growthDelta0, 64, 128);
|
|
6389
5915
|
growthInside.push(rewardersInside[0]);
|
|
6390
5916
|
AmountOwed.push({
|
|
6391
|
-
amount_owed: new
|
|
5917
|
+
amount_owed: new BN16(position.reward_amount_owed_0).add(amountOwed_0),
|
|
6392
5918
|
coin_address: pool.rewarder_infos[0].coinAddress
|
|
6393
5919
|
});
|
|
6394
5920
|
}
|
|
6395
5921
|
if (rewardersInside.length > 1) {
|
|
6396
|
-
let growthDelta_1 = MathUtil.subUnderflowU128(rewardersInside[1], new
|
|
6397
|
-
if (growthDelta_1.gt(new
|
|
5922
|
+
let growthDelta_1 = MathUtil.subUnderflowU128(rewardersInside[1], new BN16(position.reward_growth_inside_1));
|
|
5923
|
+
if (growthDelta_1.gt(new BN16("3402823669209384634633745948738404"))) {
|
|
6398
5924
|
growthDelta_1 = ONE;
|
|
6399
5925
|
}
|
|
6400
|
-
const amountOwed_1 = MathUtil.checkMulShiftRight(new
|
|
5926
|
+
const amountOwed_1 = MathUtil.checkMulShiftRight(new BN16(position.liquidity), growthDelta_1, 64, 128);
|
|
6401
5927
|
growthInside.push(rewardersInside[1]);
|
|
6402
5928
|
AmountOwed.push({
|
|
6403
|
-
amount_owed: new
|
|
5929
|
+
amount_owed: new BN16(position.reward_amount_owed_1).add(amountOwed_1),
|
|
6404
5930
|
coin_address: pool.rewarder_infos[1].coinAddress
|
|
6405
5931
|
});
|
|
6406
5932
|
}
|
|
6407
5933
|
if (rewardersInside.length > 2) {
|
|
6408
|
-
let growthDelta_2 = MathUtil.subUnderflowU128(rewardersInside[2], new
|
|
6409
|
-
if (growthDelta_2.gt(new
|
|
5934
|
+
let growthDelta_2 = MathUtil.subUnderflowU128(rewardersInside[2], new BN16(position.reward_growth_inside_2));
|
|
5935
|
+
if (growthDelta_2.gt(new BN16("3402823669209384634633745948738404"))) {
|
|
6410
5936
|
growthDelta_2 = ONE;
|
|
6411
5937
|
}
|
|
6412
|
-
const amountOwed_2 = MathUtil.checkMulShiftRight(new
|
|
5938
|
+
const amountOwed_2 = MathUtil.checkMulShiftRight(new BN16(position.liquidity), growthDelta_2, 64, 128);
|
|
6413
5939
|
growthInside.push(rewardersInside[2]);
|
|
6414
5940
|
AmountOwed.push({
|
|
6415
|
-
amount_owed: new
|
|
5941
|
+
amount_owed: new BN16(position.reward_amount_owed_2).add(amountOwed_2),
|
|
6416
5942
|
coin_address: pool.rewarder_infos[2].coinAddress
|
|
6417
5943
|
});
|
|
6418
5944
|
}
|
|
@@ -6526,8 +6052,8 @@ var RewarderModule = class {
|
|
|
6526
6052
|
for (let i = 0; i < valueData.length; i += 1) {
|
|
6527
6053
|
const { parsedJson } = valueData[i];
|
|
6528
6054
|
const posRrewarderResult = {
|
|
6529
|
-
feeOwedA: new
|
|
6530
|
-
feeOwedB: new
|
|
6055
|
+
feeOwedA: new BN16(parsedJson.fee_owned_a),
|
|
6056
|
+
feeOwedB: new BN16(parsedJson.fee_owned_b),
|
|
6531
6057
|
position_id: parsedJson.position_id
|
|
6532
6058
|
};
|
|
6533
6059
|
result.push(posRrewarderResult);
|
|
@@ -6590,7 +6116,7 @@ var RewarderModule = class {
|
|
|
6590
6116
|
};
|
|
6591
6117
|
for (let j = 0; j < params[i].rewarderInfo.length; j += 1) {
|
|
6592
6118
|
posRrewarderResult.rewarderAmountOwed.push({
|
|
6593
|
-
amount_owed: new
|
|
6119
|
+
amount_owed: new BN16(valueData[i].parsedJson.data[j]),
|
|
6594
6120
|
coin_address: params[i].rewarderInfo[j].coinAddress
|
|
6595
6121
|
});
|
|
6596
6122
|
}
|
|
@@ -6749,7 +6275,7 @@ var RewarderModule = class {
|
|
|
6749
6275
|
};
|
|
6750
6276
|
|
|
6751
6277
|
// src/modules/routerModule.ts
|
|
6752
|
-
import
|
|
6278
|
+
import BN17 from "bn.js";
|
|
6753
6279
|
import { Graph, GraphEdge, GraphVertex } from "@syntsugar/cc-graph";
|
|
6754
6280
|
import { Transaction as Transaction7 } from "@mysten/sui/transactions";
|
|
6755
6281
|
function _pairSymbol(base, quote) {
|
|
@@ -7031,8 +6557,8 @@ var RouterModule = class {
|
|
|
7031
6557
|
if (swapWithMultiPoolParams != null) {
|
|
7032
6558
|
const preSwapResult2 = await this.sdk.Swap.preSwapWithMultiPool(swapWithMultiPoolParams);
|
|
7033
6559
|
const onePath2 = {
|
|
7034
|
-
amountIn: new
|
|
7035
|
-
amountOut: new
|
|
6560
|
+
amountIn: new BN17(preSwapResult2.estimatedAmountIn),
|
|
6561
|
+
amountOut: new BN17(preSwapResult2.estimatedAmountOut),
|
|
7036
6562
|
poolAddress: [preSwapResult2.poolAddress],
|
|
7037
6563
|
a2b: [preSwapResult2.aToB],
|
|
7038
6564
|
rawAmountLimit: byAmountIn ? [preSwapResult2.estimatedAmountOut] : [preSwapResult2.estimatedAmountIn],
|
|
@@ -7045,8 +6571,8 @@ var RouterModule = class {
|
|
|
7045
6571
|
priceSlippagePoint
|
|
7046
6572
|
};
|
|
7047
6573
|
const result2 = {
|
|
7048
|
-
amountIn: new
|
|
7049
|
-
amountOut: new
|
|
6574
|
+
amountIn: new BN17(preSwapResult2.estimatedAmountIn),
|
|
6575
|
+
amountOut: new BN17(preSwapResult2.estimatedAmountOut),
|
|
7050
6576
|
paths: [onePath2],
|
|
7051
6577
|
a2b: preSwapResult2.aToB,
|
|
7052
6578
|
b2c: void 0,
|
|
@@ -7068,8 +6594,8 @@ var RouterModule = class {
|
|
|
7068
6594
|
if (swapWithMultiPoolParams != null) {
|
|
7069
6595
|
const preSwapResult2 = await this.sdk.Swap.preSwapWithMultiPool(swapWithMultiPoolParams);
|
|
7070
6596
|
const onePath2 = {
|
|
7071
|
-
amountIn: new
|
|
7072
|
-
amountOut: new
|
|
6597
|
+
amountIn: new BN17(preSwapResult2.estimatedAmountIn),
|
|
6598
|
+
amountOut: new BN17(preSwapResult2.estimatedAmountOut),
|
|
7073
6599
|
poolAddress: [preSwapResult2.poolAddress],
|
|
7074
6600
|
a2b: [preSwapResult2.aToB],
|
|
7075
6601
|
rawAmountLimit: byAmountIn ? [preSwapResult2.estimatedAmountOut] : [preSwapResult2.estimatedAmountIn],
|
|
@@ -7082,8 +6608,8 @@ var RouterModule = class {
|
|
|
7082
6608
|
priceSlippagePoint
|
|
7083
6609
|
};
|
|
7084
6610
|
const result3 = {
|
|
7085
|
-
amountIn: new
|
|
7086
|
-
amountOut: new
|
|
6611
|
+
amountIn: new BN17(preSwapResult2.estimatedAmountIn),
|
|
6612
|
+
amountOut: new BN17(preSwapResult2.estimatedAmountOut),
|
|
7087
6613
|
paths: [onePath2],
|
|
7088
6614
|
a2b: preSwapResult2.aToB,
|
|
7089
6615
|
b2c: void 0,
|
|
@@ -7164,8 +6690,8 @@ var RouterModule = class {
|
|
|
7164
6690
|
if (swapWithMultiPoolParams != null) {
|
|
7165
6691
|
const preSwapResult = await this.sdk.Swap.preSwapWithMultiPool(swapWithMultiPoolParams);
|
|
7166
6692
|
const onePath = {
|
|
7167
|
-
amountIn: new
|
|
7168
|
-
amountOut: new
|
|
6693
|
+
amountIn: new BN17(preSwapResult.estimatedAmountIn),
|
|
6694
|
+
amountOut: new BN17(preSwapResult.estimatedAmountOut),
|
|
7169
6695
|
poolAddress: [preSwapResult.poolAddress],
|
|
7170
6696
|
a2b: [preSwapResult.aToB],
|
|
7171
6697
|
rawAmountLimit: byAmountIn ? [preSwapResult.estimatedAmountOut] : [preSwapResult.estimatedAmountIn],
|
|
@@ -7178,8 +6704,8 @@ var RouterModule = class {
|
|
|
7178
6704
|
priceSlippagePoint
|
|
7179
6705
|
};
|
|
7180
6706
|
const result = {
|
|
7181
|
-
amountIn: new
|
|
7182
|
-
amountOut: new
|
|
6707
|
+
amountIn: new BN17(preSwapResult.estimatedAmountIn),
|
|
6708
|
+
amountOut: new BN17(preSwapResult.estimatedAmountOut),
|
|
7183
6709
|
paths: [onePath],
|
|
7184
6710
|
a2b: preSwapResult.aToB,
|
|
7185
6711
|
b2c: void 0,
|
|
@@ -7263,13 +6789,13 @@ var RouterModule = class {
|
|
|
7263
6789
|
continue;
|
|
7264
6790
|
}
|
|
7265
6791
|
if (params[0].byAmountIn) {
|
|
7266
|
-
const amount = new
|
|
6792
|
+
const amount = new BN17(valueData[i].parsedJson.data.amount_out);
|
|
7267
6793
|
if (amount.gt(tempMaxAmount)) {
|
|
7268
6794
|
tempIndex = i;
|
|
7269
6795
|
tempMaxAmount = amount;
|
|
7270
6796
|
}
|
|
7271
6797
|
} else {
|
|
7272
|
-
const amount = params[i].stepNums > 1 ? new
|
|
6798
|
+
const amount = params[i].stepNums > 1 ? new BN17(valueData[i].parsedJson.data.amount_in) : new BN17(valueData[i].parsedJson.data.amount_in).add(new BN17(valueData[i].parsedJson.data.fee_amount));
|
|
7273
6799
|
if (amount.lt(tempMaxAmount)) {
|
|
7274
6800
|
tempIndex = i;
|
|
7275
6801
|
tempMaxAmount = amount;
|
|
@@ -7339,8 +6865,8 @@ var RouterModule = class {
|
|
|
7339
6865
|
};
|
|
7340
6866
|
|
|
7341
6867
|
// src/modules/swapModule.ts
|
|
7342
|
-
import
|
|
7343
|
-
import
|
|
6868
|
+
import BN18 from "bn.js";
|
|
6869
|
+
import Decimal5 from "decimal.js";
|
|
7344
6870
|
import { Transaction as Transaction8 } from "@mysten/sui/transactions";
|
|
7345
6871
|
var AMM_SWAP_MODULE = "amm_swap";
|
|
7346
6872
|
var POOL_STRUCT = "Pool";
|
|
@@ -7358,14 +6884,14 @@ var SwapModule = class {
|
|
|
7358
6884
|
const pathCount = item.basePaths.length;
|
|
7359
6885
|
if (pathCount > 0) {
|
|
7360
6886
|
const path = item.basePaths[0];
|
|
7361
|
-
const feeRate = path.label === "Magma" ? new
|
|
6887
|
+
const feeRate = path.label === "Magma" ? new Decimal5(path.feeRate).div(10 ** 6) : new Decimal5(path.feeRate).div(10 ** 9);
|
|
7362
6888
|
const feeAmount = d(path.inputAmount).div(10 ** path.fromDecimal).mul(feeRate);
|
|
7363
6889
|
fee = fee.add(feeAmount);
|
|
7364
6890
|
if (pathCount > 1) {
|
|
7365
6891
|
const path2 = item.basePaths[1];
|
|
7366
|
-
const price1 = path.direction ? path.currentPrice : new
|
|
7367
|
-
const price2 = path2.direction ? path2.currentPrice : new
|
|
7368
|
-
const feeRate2 = path2.label === "Magma" ? new
|
|
6892
|
+
const price1 = path.direction ? path.currentPrice : new Decimal5(1).div(path.currentPrice);
|
|
6893
|
+
const price2 = path2.direction ? path2.currentPrice : new Decimal5(1).div(path2.currentPrice);
|
|
6894
|
+
const feeRate2 = path2.label === "Magma" ? new Decimal5(path2.feeRate).div(10 ** 6) : new Decimal5(path2.feeRate).div(10 ** 9);
|
|
7369
6895
|
const feeAmount2 = d(path2.outputAmount).div(10 ** path2.toDecimal).mul(feeRate2);
|
|
7370
6896
|
const fee2 = feeAmount2.div(price1.mul(price2));
|
|
7371
6897
|
fee = fee.add(fee2);
|
|
@@ -7383,17 +6909,17 @@ var SwapModule = class {
|
|
|
7383
6909
|
const outputAmount = d(path.outputAmount).div(10 ** path.toDecimal);
|
|
7384
6910
|
const inputAmount = d(path.inputAmount).div(10 ** path.fromDecimal);
|
|
7385
6911
|
const rate = outputAmount.div(inputAmount);
|
|
7386
|
-
const cprice = path.direction ? new
|
|
6912
|
+
const cprice = path.direction ? new Decimal5(path.currentPrice) : new Decimal5(1).div(path.currentPrice);
|
|
7387
6913
|
impactValue = impactValue.add(this.calculateSingleImpact(rate, cprice));
|
|
7388
6914
|
}
|
|
7389
6915
|
if (pathCount === 2) {
|
|
7390
6916
|
const path = item.basePaths[0];
|
|
7391
6917
|
const path2 = item.basePaths[1];
|
|
7392
|
-
const cprice1 = path.direction ? new
|
|
7393
|
-
const cprice2 = path2.direction ? new
|
|
6918
|
+
const cprice1 = path.direction ? new Decimal5(path.currentPrice) : new Decimal5(1).div(path.currentPrice);
|
|
6919
|
+
const cprice2 = path2.direction ? new Decimal5(path2.currentPrice) : new Decimal5(1).div(path2.currentPrice);
|
|
7394
6920
|
const cprice = cprice1.mul(cprice2);
|
|
7395
|
-
const outputAmount = new
|
|
7396
|
-
const inputAmount = new
|
|
6921
|
+
const outputAmount = new Decimal5(path2.outputAmount).div(10 ** path2.toDecimal);
|
|
6922
|
+
const inputAmount = new Decimal5(path.inputAmount).div(10 ** path.fromDecimal);
|
|
7397
6923
|
const rate = outputAmount.div(inputAmount);
|
|
7398
6924
|
impactValue = impactValue.add(this.calculateSingleImpact(rate, cprice));
|
|
7399
6925
|
}
|
|
@@ -7455,13 +6981,13 @@ var SwapModule = class {
|
|
|
7455
6981
|
continue;
|
|
7456
6982
|
}
|
|
7457
6983
|
if (params.byAmountIn) {
|
|
7458
|
-
const amount = new
|
|
6984
|
+
const amount = new BN18(valueData[i].parsedJson.data.amount_out);
|
|
7459
6985
|
if (amount.gt(tempMaxAmount)) {
|
|
7460
6986
|
tempIndex = i;
|
|
7461
6987
|
tempMaxAmount = amount;
|
|
7462
6988
|
}
|
|
7463
6989
|
} else {
|
|
7464
|
-
const amount = new
|
|
6990
|
+
const amount = new BN18(valueData[i].parsedJson.data.amount_out);
|
|
7465
6991
|
if (amount.lt(tempMaxAmount)) {
|
|
7466
6992
|
tempIndex = i;
|
|
7467
6993
|
tempMaxAmount = amount;
|
|
@@ -7525,7 +7051,7 @@ var SwapModule = class {
|
|
|
7525
7051
|
return this.transformSwapData(params, valueData[0].parsedJson.data);
|
|
7526
7052
|
}
|
|
7527
7053
|
transformSwapData(params, data) {
|
|
7528
|
-
const estimatedAmountIn = data.amount_in && data.fee_amount ? new
|
|
7054
|
+
const estimatedAmountIn = data.amount_in && data.fee_amount ? new BN18(data.amount_in).add(new BN18(data.fee_amount)).toString() : "";
|
|
7529
7055
|
return {
|
|
7530
7056
|
poolAddress: params.pool.poolAddress,
|
|
7531
7057
|
currentSqrtPrice: params.currentSqrtPrice,
|
|
@@ -7542,7 +7068,7 @@ var SwapModule = class {
|
|
|
7542
7068
|
transformSwapWithMultiPoolData(params, jsonData) {
|
|
7543
7069
|
const { data } = jsonData;
|
|
7544
7070
|
console.log("json data. ", data);
|
|
7545
|
-
const estimatedAmountIn = data.amount_in && data.fee_amount ? new
|
|
7071
|
+
const estimatedAmountIn = data.amount_in && data.fee_amount ? new BN18(data.amount_in).add(new BN18(data.fee_amount)).toString() : "";
|
|
7546
7072
|
return {
|
|
7547
7073
|
poolAddress: params.poolAddress,
|
|
7548
7074
|
estimatedAmountIn,
|
|
@@ -9055,8 +8581,8 @@ var TokenModule = class {
|
|
|
9055
8581
|
};
|
|
9056
8582
|
|
|
9057
8583
|
// src/modules/routerModuleV2.ts
|
|
9058
|
-
import
|
|
9059
|
-
import
|
|
8584
|
+
import BN19 from "bn.js";
|
|
8585
|
+
import Decimal6 from "decimal.js";
|
|
9060
8586
|
import { v4 as uuidv4 } from "uuid";
|
|
9061
8587
|
import axios from "axios";
|
|
9062
8588
|
var RouterModuleV2 = class {
|
|
@@ -9073,7 +8599,7 @@ var RouterModuleV2 = class {
|
|
|
9073
8599
|
if (label === "Magma") {
|
|
9074
8600
|
return TickMath.sqrtPriceX64ToPrice(currentSqrtPrice, decimalA, decimalB);
|
|
9075
8601
|
}
|
|
9076
|
-
return new
|
|
8602
|
+
return new Decimal6(currentSqrtPrice.toString()).div(new Decimal6(10).pow(new Decimal6(decimalB + 9 - decimalA)));
|
|
9077
8603
|
}
|
|
9078
8604
|
parseJsonResult(data) {
|
|
9079
8605
|
const result = {
|
|
@@ -9099,12 +8625,12 @@ var RouterModuleV2 = class {
|
|
|
9099
8625
|
outputAmount: basePath.output_amount,
|
|
9100
8626
|
inputAmount: basePath.input_amount,
|
|
9101
8627
|
feeRate: basePath.fee_rate,
|
|
9102
|
-
currentSqrtPrice: new
|
|
9103
|
-
afterSqrtPrice: basePath.label === "Magma" ? new
|
|
8628
|
+
currentSqrtPrice: new BN19(basePath.current_sqrt_price.toString()),
|
|
8629
|
+
afterSqrtPrice: basePath.label === "Magma" ? new BN19(basePath.after_sqrt_price.toString()) : ZERO,
|
|
9104
8630
|
fromDecimal: basePath.from_decimal,
|
|
9105
8631
|
toDecimal: basePath.to_decimal,
|
|
9106
8632
|
currentPrice: this.calculatePrice(
|
|
9107
|
-
new
|
|
8633
|
+
new BN19(basePath.current_sqrt_price.toString()),
|
|
9108
8634
|
basePath.from_decimal,
|
|
9109
8635
|
basePath.to_decimal,
|
|
9110
8636
|
basePath.direction,
|
|
@@ -9187,7 +8713,7 @@ var RouterModuleV2 = class {
|
|
|
9187
8713
|
const priceResult = await this.sdk.Router.priceUseV1(
|
|
9188
8714
|
from,
|
|
9189
8715
|
to,
|
|
9190
|
-
new
|
|
8716
|
+
new BN19(amount),
|
|
9191
8717
|
byAmountIn,
|
|
9192
8718
|
priceSplitPoint,
|
|
9193
8719
|
partner,
|
|
@@ -9199,7 +8725,7 @@ var RouterModuleV2 = class {
|
|
|
9199
8725
|
if (path.poolAddress.length > 1) {
|
|
9200
8726
|
const fromDecimal0 = this.sdk.Router.tokenInfo(path.coinType[0]).decimals;
|
|
9201
8727
|
const toDecimal0 = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
|
|
9202
|
-
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new
|
|
8728
|
+
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new BN19(priceResult.currentSqrtPrice[0]), fromDecimal0, toDecimal0) : TickMath.sqrtPriceX64ToPrice(new BN19(priceResult.currentSqrtPrice[0]), toDecimal0, fromDecimal0);
|
|
9203
8729
|
const path0 = {
|
|
9204
8730
|
direction: path.a2b[0],
|
|
9205
8731
|
label: "Magma",
|
|
@@ -9216,7 +8742,7 @@ var RouterModuleV2 = class {
|
|
|
9216
8742
|
};
|
|
9217
8743
|
const fromDecimal1 = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
|
|
9218
8744
|
const toDecimal1 = this.sdk.Router.tokenInfo(path.coinType[2]).decimals;
|
|
9219
|
-
const currentPrice1 = path.a2b[1] ? TickMath.sqrtPriceX64ToPrice(new
|
|
8745
|
+
const currentPrice1 = path.a2b[1] ? TickMath.sqrtPriceX64ToPrice(new BN19(priceResult.currentSqrtPrice[1]), fromDecimal1, toDecimal1) : TickMath.sqrtPriceX64ToPrice(new BN19(priceResult.currentSqrtPrice[1]), toDecimal1, fromDecimal1);
|
|
9220
8746
|
const path1 = {
|
|
9221
8747
|
direction: path.a2b[1],
|
|
9222
8748
|
label: "Magma",
|
|
@@ -9235,7 +8761,7 @@ var RouterModuleV2 = class {
|
|
|
9235
8761
|
} else {
|
|
9236
8762
|
const fromDecimal = this.sdk.Router.tokenInfo(path.coinType[0]).decimals;
|
|
9237
8763
|
const toDecimal = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
|
|
9238
|
-
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new
|
|
8764
|
+
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new BN19(priceResult.currentSqrtPrice[0]), fromDecimal, toDecimal) : TickMath.sqrtPriceX64ToPrice(new BN19(priceResult.currentSqrtPrice[0]), toDecimal, fromDecimal);
|
|
9239
8765
|
const path0 = {
|
|
9240
8766
|
direction: path.a2b[0],
|
|
9241
8767
|
label: "Magma",
|
|
@@ -9320,7 +8846,7 @@ var RouterModuleV2 = class {
|
|
|
9320
8846
|
const priceResult = await this.sdk.Router.priceUseV1(
|
|
9321
8847
|
from,
|
|
9322
8848
|
to,
|
|
9323
|
-
new
|
|
8849
|
+
new BN19(amount),
|
|
9324
8850
|
byAmountIn,
|
|
9325
8851
|
priceSplitPoint,
|
|
9326
8852
|
partner,
|
|
@@ -9332,7 +8858,7 @@ var RouterModuleV2 = class {
|
|
|
9332
8858
|
if (path.poolAddress.length > 1) {
|
|
9333
8859
|
const fromDecimal0 = this.sdk.Router.tokenInfo(path.coinType[0]).decimals;
|
|
9334
8860
|
const toDecimal0 = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
|
|
9335
|
-
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new
|
|
8861
|
+
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new BN19(priceResult.currentSqrtPrice[0]), fromDecimal0, toDecimal0) : TickMath.sqrtPriceX64ToPrice(new BN19(priceResult.currentSqrtPrice[0]), toDecimal0, fromDecimal0);
|
|
9336
8862
|
const path0 = {
|
|
9337
8863
|
direction: path.a2b[0],
|
|
9338
8864
|
label: "Magma",
|
|
@@ -9349,7 +8875,7 @@ var RouterModuleV2 = class {
|
|
|
9349
8875
|
};
|
|
9350
8876
|
const fromDecimal1 = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
|
|
9351
8877
|
const toDecimal1 = this.sdk.Router.tokenInfo(path.coinType[2]).decimals;
|
|
9352
|
-
const currentPrice1 = path.a2b[1] ? TickMath.sqrtPriceX64ToPrice(new
|
|
8878
|
+
const currentPrice1 = path.a2b[1] ? TickMath.sqrtPriceX64ToPrice(new BN19(priceResult.currentSqrtPrice[1]), fromDecimal1, toDecimal1) : TickMath.sqrtPriceX64ToPrice(new BN19(priceResult.currentSqrtPrice[1]), toDecimal1, fromDecimal1);
|
|
9353
8879
|
const path1 = {
|
|
9354
8880
|
direction: path.a2b[1],
|
|
9355
8881
|
label: "Magma",
|
|
@@ -9368,7 +8894,7 @@ var RouterModuleV2 = class {
|
|
|
9368
8894
|
} else {
|
|
9369
8895
|
const fromDecimal = this.sdk.Router.tokenInfo(path.coinType[0]).decimals;
|
|
9370
8896
|
const toDecimal = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
|
|
9371
|
-
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new
|
|
8897
|
+
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new BN19(priceResult.currentSqrtPrice[0]), fromDecimal, toDecimal) : TickMath.sqrtPriceX64ToPrice(new BN19(priceResult.currentSqrtPrice[0]), toDecimal, fromDecimal);
|
|
9372
8898
|
const path0 = {
|
|
9373
8899
|
direction: path.a2b[0],
|
|
9374
8900
|
label: "Magma",
|
|
@@ -10243,21 +9769,6 @@ var GaugeModule = class {
|
|
|
10243
9769
|
});
|
|
10244
9770
|
return tx;
|
|
10245
9771
|
}
|
|
10246
|
-
async getAllRewardByPositions(paramsList) {
|
|
10247
|
-
const tx = new Transaction11();
|
|
10248
|
-
const { integrate } = this.sdk.sdkOptions;
|
|
10249
|
-
const { magma_token } = getPackagerConfigs(this.sdk.sdkOptions.magma_config);
|
|
10250
|
-
paramsList.forEach((params) => {
|
|
10251
|
-
const typeArguments = [params.coinTypeA, params.coinTypeB, magma_token];
|
|
10252
|
-
const args = [tx.object(params.gaugeId), tx.object(params.poolId), tx.object(params.positionId), tx.object(CLOCK_ADDRESS)];
|
|
10253
|
-
tx.moveCall({
|
|
10254
|
-
target: `${integrate.published_at}::${Gauge}::get_reward_by_position`,
|
|
10255
|
-
arguments: args,
|
|
10256
|
-
typeArguments
|
|
10257
|
-
});
|
|
10258
|
-
});
|
|
10259
|
-
return tx;
|
|
10260
|
-
}
|
|
10261
9772
|
async getEpochRewardByPool(pool, incentive_tokens) {
|
|
10262
9773
|
const tx = new Transaction11();
|
|
10263
9774
|
const { integrate, simulationAccount } = this.sdk.sdkOptions;
|
|
@@ -10290,959 +9801,67 @@ var GaugeModule = class {
|
|
|
10290
9801
|
}
|
|
10291
9802
|
};
|
|
10292
9803
|
|
|
10293
|
-
// src/
|
|
10294
|
-
|
|
10295
|
-
import {
|
|
10296
|
-
get_price_x128_from_real_id as get_price_x128_from_real_id3,
|
|
10297
|
-
get_real_id,
|
|
10298
|
-
get_real_id_from_price_x128 as get_real_id_from_price_x1282,
|
|
10299
|
-
get_storage_id_from_real_id
|
|
10300
|
-
} from "@magmaprotocol/calc_dlmm";
|
|
10301
|
-
import Decimal10 from "decimal.js";
|
|
10302
|
-
var DlmmModule = class {
|
|
10303
|
-
_sdk;
|
|
9804
|
+
// src/sdk.ts
|
|
9805
|
+
var MagmaClmmSDK = class {
|
|
10304
9806
|
_cache = {};
|
|
10305
|
-
|
|
10306
|
-
|
|
10307
|
-
|
|
10308
|
-
|
|
10309
|
-
|
|
10310
|
-
|
|
10311
|
-
|
|
10312
|
-
|
|
10313
|
-
|
|
10314
|
-
|
|
10315
|
-
|
|
10316
|
-
|
|
10317
|
-
|
|
10318
|
-
|
|
10319
|
-
|
|
10320
|
-
|
|
10321
|
-
|
|
10322
|
-
|
|
10323
|
-
|
|
10324
|
-
|
|
10325
|
-
|
|
10326
|
-
|
|
10327
|
-
|
|
10328
|
-
|
|
10329
|
-
|
|
10330
|
-
|
|
10331
|
-
|
|
10332
|
-
|
|
10333
|
-
|
|
10334
|
-
|
|
10335
|
-
|
|
10336
|
-
|
|
10337
|
-
|
|
10338
|
-
|
|
10339
|
-
|
|
10340
|
-
|
|
10341
|
-
|
|
10342
|
-
|
|
10343
|
-
|
|
10344
|
-
|
|
10345
|
-
|
|
10346
|
-
|
|
10347
|
-
|
|
10348
|
-
|
|
10349
|
-
|
|
10350
|
-
|
|
10351
|
-
|
|
10352
|
-
|
|
10353
|
-
|
|
10354
|
-
|
|
10355
|
-
|
|
10356
|
-
|
|
10357
|
-
|
|
10358
|
-
|
|
10359
|
-
index_reference: 0,
|
|
10360
|
-
time_of_last_update: 0,
|
|
10361
|
-
oracle_index: 0,
|
|
10362
|
-
active_index: 0
|
|
10363
|
-
};
|
|
10364
|
-
simulateRes.events?.forEach((item) => {
|
|
10365
|
-
console.log(extractStructTagFromType(item.type).name);
|
|
10366
|
-
if (extractStructTagFromType(item.type).name === `EventPairParams`) {
|
|
10367
|
-
res = item.parsedJson.params;
|
|
10368
|
-
}
|
|
10369
|
-
});
|
|
10370
|
-
return res;
|
|
10371
|
-
}
|
|
10372
|
-
// NOTE: x, y should be sorted
|
|
10373
|
-
async createPairPayload(params) {
|
|
10374
|
-
const storage_id = get_storage_id_from_real_id(
|
|
10375
|
-
BinMath.getBinIdFromPrice(params.priceTokenBPerTokenA, params.bin_step, params.coinADecimal, params.coinBDecimal)
|
|
10376
|
-
);
|
|
10377
|
-
const tx = new Transaction12();
|
|
10378
|
-
tx.setSender(this.sdk.senderAddress);
|
|
10379
|
-
const { clmm_pool, dlmm_pool, integrate } = this.sdk.sdkOptions;
|
|
10380
|
-
const { global_config_id } = getPackagerConfigs(clmm_pool);
|
|
10381
|
-
const dlmmConfig = getPackagerConfigs(dlmm_pool);
|
|
10382
|
-
const typeArguments = [params.coinTypeA, params.coinTypeB];
|
|
10383
|
-
const args = [
|
|
10384
|
-
tx.object(dlmmConfig.factory),
|
|
10385
|
-
tx.object(global_config_id),
|
|
10386
|
-
tx.pure.u64(params.base_fee),
|
|
10387
|
-
tx.pure.u16(params.bin_step),
|
|
10388
|
-
tx.pure.u32(storage_id)
|
|
10389
|
-
];
|
|
10390
|
-
tx.moveCall({
|
|
10391
|
-
target: `${integrate.published_at}::${DlmmScript}::create_pair`,
|
|
10392
|
-
typeArguments,
|
|
10393
|
-
arguments: args
|
|
10394
|
-
});
|
|
10395
|
-
return tx;
|
|
10396
|
-
}
|
|
10397
|
-
// async mintByStrategySingle(params: MintByStrategySingleParams): Promise<Transaction> {}
|
|
10398
|
-
async mintByStrategy(params) {
|
|
10399
|
-
const tx = new Transaction12();
|
|
10400
|
-
const slippage = new Decimal10(params.slippage);
|
|
10401
|
-
const lower_slippage = new Decimal10(1).sub(slippage.div(new Decimal10(1e4)));
|
|
10402
|
-
const upper_slippage = new Decimal10(1).plus(slippage.div(new Decimal10(1e4)));
|
|
10403
|
-
tx.setSender(this.sdk.senderAddress);
|
|
10404
|
-
const { dlmm_pool, integrate } = this.sdk.sdkOptions;
|
|
10405
|
-
const dlmmConfig = getPackagerConfigs(dlmm_pool);
|
|
10406
|
-
const typeArguments = [params.coinTypeA, params.coinTypeB];
|
|
10407
|
-
const price = get_price_x128_from_real_id3(params.active_bin, params.bin_step);
|
|
10408
|
-
const min_price = new Decimal10(price).mul(lower_slippage);
|
|
10409
|
-
const max_price = new Decimal10(price).mul(upper_slippage);
|
|
10410
|
-
const active_min = get_storage_id_from_real_id(get_real_id_from_price_x1282(min_price.toDecimalPlaces(0).toString(), params.bin_step));
|
|
10411
|
-
const active_max = get_storage_id_from_real_id(get_real_id_from_price_x1282(max_price.toDecimalPlaces(0).toString(), params.bin_step));
|
|
10412
|
-
const allCoins = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress);
|
|
10413
|
-
let primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountATotal), params.coinTypeA, false, true);
|
|
10414
|
-
let primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountBTotal), params.coinTypeB, false, true);
|
|
10415
|
-
let amount_min = 0;
|
|
10416
|
-
let amount_max = 0;
|
|
10417
|
-
if (params.fixCoinA) {
|
|
10418
|
-
amount_min = new Decimal10(params.amountBTotal).mul(lower_slippage).toDecimalPlaces(0).toNumber();
|
|
10419
|
-
amount_max = new Decimal10(params.amountBTotal).mul(upper_slippage).toDecimalPlaces(0).toNumber();
|
|
10420
|
-
primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amount_max), params.coinTypeB, false, true);
|
|
10421
|
-
}
|
|
10422
|
-
if (params.fixCoinB) {
|
|
10423
|
-
amount_min = new Decimal10(params.amountATotal).mul(lower_slippage).toDecimalPlaces(0).toNumber();
|
|
10424
|
-
amount_max = new Decimal10(params.amountATotal).mul(upper_slippage).toDecimalPlaces(0).toNumber();
|
|
10425
|
-
primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amount_max), params.coinTypeB, false, true);
|
|
10426
|
-
}
|
|
10427
|
-
if (params.fixCoinA && params.fixCoinB) {
|
|
10428
|
-
} else if (params.fixCoinA) {
|
|
10429
|
-
params.amountBTotal = 0;
|
|
10430
|
-
} else if (params.fixCoinB) {
|
|
10431
|
-
params.amountATotal = 0;
|
|
10432
|
-
}
|
|
10433
|
-
const args = [
|
|
10434
|
-
tx.object(params.pair),
|
|
10435
|
-
tx.object(dlmmConfig.factory),
|
|
10436
|
-
primaryCoinAInputs.targetCoin,
|
|
10437
|
-
primaryCoinBInputs.targetCoin,
|
|
10438
|
-
tx.pure.u64(params.amountATotal),
|
|
10439
|
-
tx.pure.u64(params.amountBTotal),
|
|
10440
|
-
tx.pure.u8(params.strategy),
|
|
10441
|
-
tx.pure.u32(get_storage_id_from_real_id(params.min_bin)),
|
|
10442
|
-
tx.pure.u32(get_storage_id_from_real_id(params.max_bin)),
|
|
10443
|
-
tx.pure.u32(active_min),
|
|
10444
|
-
tx.pure.u32(active_max),
|
|
10445
|
-
tx.pure.u64(amount_min),
|
|
10446
|
-
tx.pure.u64(amount_max),
|
|
10447
|
-
tx.object(CLOCK_ADDRESS)
|
|
10448
|
-
];
|
|
10449
|
-
tx.moveCall({
|
|
10450
|
-
target: `${integrate.published_at}::${DlmmScript}::mint_by_strategy`,
|
|
10451
|
-
typeArguments,
|
|
10452
|
-
arguments: args
|
|
10453
|
-
});
|
|
10454
|
-
return tx;
|
|
10455
|
-
}
|
|
10456
|
-
// Create a position by percent
|
|
10457
|
-
async mintPercent(params) {
|
|
10458
|
-
const tx = new Transaction12();
|
|
10459
|
-
tx.setSender(this.sdk.senderAddress);
|
|
10460
|
-
const { dlmm_pool, integrate } = this.sdk.sdkOptions;
|
|
10461
|
-
const dlmmConfig = getPackagerConfigs(dlmm_pool);
|
|
10462
|
-
const typeArguments = [params.coinTypeA, params.coinTypeB];
|
|
10463
|
-
const allCoins = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress);
|
|
10464
|
-
const primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountATotal), params.coinTypeA, false, true);
|
|
10465
|
-
const primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountBTotal), params.coinTypeB, false, true);
|
|
10466
|
-
const args = [
|
|
10467
|
-
tx.object(params.pair),
|
|
10468
|
-
tx.object(dlmmConfig.factory),
|
|
10469
|
-
primaryCoinAInputs.targetCoin,
|
|
10470
|
-
primaryCoinBInputs.targetCoin,
|
|
10471
|
-
tx.pure.u64(params.amountATotal),
|
|
10472
|
-
tx.pure.u64(params.amountBTotal),
|
|
10473
|
-
tx.pure.vector("u32", params.storageIds),
|
|
10474
|
-
tx.pure.vector("u64", params.binsAPercent),
|
|
10475
|
-
tx.pure.vector("u64", params.binsBPercent),
|
|
10476
|
-
tx.pure.address(params.to),
|
|
10477
|
-
tx.object(CLOCK_ADDRESS)
|
|
10478
|
-
];
|
|
10479
|
-
tx.moveCall({
|
|
10480
|
-
target: `${integrate.published_at}::${DlmmScript}::mint_percent`,
|
|
10481
|
-
typeArguments,
|
|
10482
|
-
arguments: args
|
|
10483
|
-
});
|
|
10484
|
-
return tx;
|
|
10485
|
-
}
|
|
10486
|
-
// Create a position by amount
|
|
10487
|
-
async createPositionByAmount(params) {
|
|
10488
|
-
const tx = new Transaction12();
|
|
10489
|
-
tx.setSender(this.sdk.senderAddress);
|
|
10490
|
-
const { dlmm_pool, integrate } = this.sdk.sdkOptions;
|
|
10491
|
-
const dlmmConfig = getPackagerConfigs(dlmm_pool);
|
|
10492
|
-
const typeArguments = [params.coinTypeA, params.coinTypeB];
|
|
10493
|
-
const allCoins = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress);
|
|
10494
|
-
const primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountATotal), params.coinTypeA, false, true);
|
|
10495
|
-
const primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountBTotal), params.coinTypeB, false, true);
|
|
10496
|
-
const args = [
|
|
10497
|
-
tx.object(params.pair),
|
|
10498
|
-
tx.object(dlmmConfig.factory),
|
|
10499
|
-
primaryCoinAInputs.targetCoin,
|
|
10500
|
-
primaryCoinBInputs.targetCoin,
|
|
10501
|
-
tx.pure.vector("u32", params.storageIds),
|
|
10502
|
-
tx.pure.vector("u64", params.amountsA),
|
|
10503
|
-
tx.pure.vector("u64", params.amountsB),
|
|
10504
|
-
tx.pure.address(params.to),
|
|
10505
|
-
tx.object(CLOCK_ADDRESS)
|
|
10506
|
-
];
|
|
10507
|
-
tx.moveCall({
|
|
10508
|
-
target: `${integrate.published_at}::${DlmmScript}::mint_amounts`,
|
|
10509
|
-
typeArguments,
|
|
10510
|
-
arguments: args
|
|
10511
|
-
});
|
|
10512
|
-
return tx;
|
|
10513
|
-
}
|
|
10514
|
-
async addLiquidity(params) {
|
|
10515
|
-
if (params.rewards_token.length === 0) {
|
|
10516
|
-
return this._raisePositionByAmounts(params);
|
|
10517
|
-
}
|
|
10518
|
-
return this._raisePositionByAmountsReward(params);
|
|
10519
|
-
}
|
|
10520
|
-
async _raisePositionByAmounts(params) {
|
|
10521
|
-
const tx = new Transaction12();
|
|
10522
|
-
tx.setSender(this.sdk.senderAddress);
|
|
10523
|
-
const { dlmm_pool, integrate } = this.sdk.sdkOptions;
|
|
10524
|
-
const dlmmConfig = getPackagerConfigs(dlmm_pool);
|
|
10525
|
-
const typeArguments = [params.coin_a, params.coin_b];
|
|
10526
|
-
const allCoins = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress);
|
|
10527
|
-
const amountATotal = params.amounts_a.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
|
|
10528
|
-
const amountBTotal = params.amounts_b.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
|
|
10529
|
-
const primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amountATotal), params.coin_a, false, true);
|
|
10530
|
-
const primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amountBTotal), params.coin_b, false, true);
|
|
10531
|
-
const args = [
|
|
10532
|
-
tx.object(params.pool_id),
|
|
10533
|
-
tx.object(dlmmConfig.factory),
|
|
10534
|
-
tx.object(params.position_id),
|
|
10535
|
-
primaryCoinAInputs.targetCoin,
|
|
10536
|
-
primaryCoinBInputs.targetCoin,
|
|
10537
|
-
tx.pure.vector("u64", params.amounts_a),
|
|
10538
|
-
tx.pure.vector("u64", params.amounts_b),
|
|
10539
|
-
tx.pure.address(params.receiver),
|
|
10540
|
-
tx.object(CLOCK_ADDRESS)
|
|
10541
|
-
];
|
|
10542
|
-
tx.moveCall({
|
|
10543
|
-
target: `${integrate.published_at}::${DlmmScript}::raise_position_by_amounts`,
|
|
10544
|
-
typeArguments,
|
|
10545
|
-
arguments: args
|
|
10546
|
-
});
|
|
10547
|
-
return tx;
|
|
10548
|
-
}
|
|
10549
|
-
async _raisePositionByAmountsReward(params) {
|
|
10550
|
-
const tx = new Transaction12();
|
|
10551
|
-
tx.setSender(this.sdk.senderAddress);
|
|
10552
|
-
const { dlmm_pool, integrate, clmm_pool } = this.sdk.sdkOptions;
|
|
10553
|
-
const dlmmConfig = getPackagerConfigs(dlmm_pool);
|
|
10554
|
-
const clmmConfigs = getPackagerConfigs(clmm_pool);
|
|
10555
|
-
const typeArguments = [params.coin_a, params.coin_b, ...params.rewards_token];
|
|
10556
|
-
const allCoins = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress);
|
|
10557
|
-
const amountATotal = params.amounts_a.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
|
|
10558
|
-
const amountBTotal = params.amounts_b.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
|
|
10559
|
-
const primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amountATotal), params.coin_a, false, true);
|
|
10560
|
-
const primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amountBTotal), params.coin_b, false, true);
|
|
10561
|
-
const args = [
|
|
10562
|
-
tx.object(params.pool_id),
|
|
10563
|
-
tx.object(dlmmConfig.factory),
|
|
10564
|
-
tx.object(clmmConfigs.global_vault_id),
|
|
10565
|
-
tx.object(params.position_id),
|
|
10566
|
-
primaryCoinAInputs.targetCoin,
|
|
10567
|
-
primaryCoinBInputs.targetCoin,
|
|
10568
|
-
tx.pure.vector("u64", params.amounts_a),
|
|
10569
|
-
tx.pure.vector("u64", params.amounts_b),
|
|
10570
|
-
tx.pure.address(params.receiver),
|
|
10571
|
-
tx.object(CLOCK_ADDRESS)
|
|
10572
|
-
];
|
|
10573
|
-
tx.moveCall({
|
|
10574
|
-
target: `${integrate.published_at}::${DlmmScript}::raise_position_by_amounts_reward${params.rewards_token.length}`,
|
|
10575
|
-
typeArguments,
|
|
10576
|
-
arguments: args
|
|
10577
|
-
});
|
|
10578
|
-
return tx;
|
|
10579
|
-
}
|
|
10580
|
-
async burnPosition(params) {
|
|
10581
|
-
const tx = new Transaction12();
|
|
10582
|
-
tx.setSender(this.sdk.senderAddress);
|
|
10583
|
-
const { integrate, clmm_pool } = this.sdk.sdkOptions;
|
|
10584
|
-
const clmmConfigs = getPackagerConfigs(clmm_pool);
|
|
10585
|
-
const typeArguments = [params.coin_a, params.coin_b, ...params.rewards_token];
|
|
10586
|
-
let args = [tx.object(params.pool_id), tx.object(params.position_id), tx.object(CLOCK_ADDRESS)];
|
|
10587
|
-
let target = `${integrate.published_at}::${DlmmScript}::burn_position`;
|
|
10588
|
-
if (params.rewards_token.length > 0) {
|
|
10589
|
-
args = [tx.object(params.pool_id), tx.object(clmmConfigs.global_vault_id), tx.object(params.position_id), tx.object(CLOCK_ADDRESS)];
|
|
10590
|
-
target = `${integrate.published_at}::${DlmmScript}::burn_position_reward${params.rewards_token.length}`;
|
|
10591
|
-
}
|
|
10592
|
-
tx.moveCall({
|
|
10593
|
-
target,
|
|
10594
|
-
typeArguments,
|
|
10595
|
-
arguments: args
|
|
10596
|
-
});
|
|
10597
|
-
return tx;
|
|
10598
|
-
}
|
|
10599
|
-
async shrinkPosition(params) {
|
|
10600
|
-
const tx = new Transaction12();
|
|
10601
|
-
tx.setSender(this.sdk.senderAddress);
|
|
10602
|
-
const { integrate, clmm_pool } = this.sdk.sdkOptions;
|
|
10603
|
-
const clmmConfigs = getPackagerConfigs(clmm_pool);
|
|
10604
|
-
const typeArguments = [params.coin_a, params.coin_b, ...params.rewards_token];
|
|
10605
|
-
let args = [tx.object(params.pool_id), tx.object(params.position_id), tx.pure.u64(params.delta_percentage), tx.object(CLOCK_ADDRESS)];
|
|
10606
|
-
let target = `${integrate.published_at}::${DlmmScript}::shrink_position`;
|
|
10607
|
-
if (params.rewards_token.length > 0) {
|
|
10608
|
-
args = [
|
|
10609
|
-
tx.object(params.pool_id),
|
|
10610
|
-
tx.object(clmmConfigs.global_vault_id),
|
|
10611
|
-
tx.object(params.position_id),
|
|
10612
|
-
tx.pure.u64(params.delta_percentage),
|
|
10613
|
-
tx.object(CLOCK_ADDRESS)
|
|
10614
|
-
];
|
|
10615
|
-
target = `${integrate.published_at}::${DlmmScript}::shrink_position_reward${params.rewards_token.length}`;
|
|
10616
|
-
}
|
|
10617
|
-
tx.moveCall({
|
|
10618
|
-
target,
|
|
10619
|
-
typeArguments,
|
|
10620
|
-
arguments: args
|
|
10621
|
-
});
|
|
10622
|
-
return tx;
|
|
10623
|
-
}
|
|
10624
|
-
async collectFeeAndReward(params) {
|
|
10625
|
-
let tx = new Transaction12();
|
|
10626
|
-
tx = await this.collectFees(params);
|
|
10627
|
-
if (params.rewards_token.length > 0) {
|
|
10628
|
-
tx = await this.collectReward(params);
|
|
10629
|
-
}
|
|
10630
|
-
return tx;
|
|
10631
|
-
}
|
|
10632
|
-
async collectReward(params, transaction) {
|
|
10633
|
-
const tx = transaction || new Transaction12();
|
|
10634
|
-
tx.setSender(this.sdk.senderAddress);
|
|
10635
|
-
const { integrate, clmm_pool } = this.sdk.sdkOptions;
|
|
10636
|
-
const clmmConfigs = getPackagerConfigs(clmm_pool);
|
|
10637
|
-
const typeArguments = [params.coin_a, params.coin_b, ...params.rewards_token];
|
|
10638
|
-
const args = [
|
|
10639
|
-
tx.object(params.pool_id),
|
|
10640
|
-
tx.object(clmmConfigs.global_vault_id),
|
|
10641
|
-
tx.object(params.position_id),
|
|
10642
|
-
tx.object(CLOCK_ADDRESS)
|
|
10643
|
-
];
|
|
10644
|
-
let target = `${integrate.published_at}::${DlmmScript}::collect_reward`;
|
|
10645
|
-
if (params.rewards_token.length > 1) {
|
|
10646
|
-
target = `${integrate.published_at}::${DlmmScript}::collect_reward${params.rewards_token.length}`;
|
|
10647
|
-
}
|
|
10648
|
-
tx.moveCall({
|
|
10649
|
-
target,
|
|
10650
|
-
typeArguments,
|
|
10651
|
-
arguments: args
|
|
10652
|
-
});
|
|
10653
|
-
return tx;
|
|
10654
|
-
}
|
|
10655
|
-
async collectFees(params, transaction) {
|
|
10656
|
-
const tx = transaction || new Transaction12();
|
|
10657
|
-
tx.setSender(this.sdk.senderAddress);
|
|
10658
|
-
const { integrate } = this.sdk.sdkOptions;
|
|
10659
|
-
const typeArguments = [params.coin_a, params.coin_b];
|
|
10660
|
-
const args = [tx.object(params.pool_id), tx.object(params.position_id), tx.object(CLOCK_ADDRESS)];
|
|
10661
|
-
const target = `${integrate.published_at}::${DlmmScript}::collect_fees`;
|
|
10662
|
-
tx.moveCall({
|
|
10663
|
-
target,
|
|
10664
|
-
typeArguments,
|
|
10665
|
-
arguments: args
|
|
10666
|
-
});
|
|
10667
|
-
return tx;
|
|
10668
|
-
}
|
|
10669
|
-
async createPairAddLiquidity(params) {
|
|
10670
|
-
const tx = new Transaction12();
|
|
10671
|
-
tx.setSender(this.sdk.senderAddress);
|
|
10672
|
-
const { clmm_pool, dlmm_pool, integrate } = this.sdk.sdkOptions;
|
|
10673
|
-
const { global_config_id } = getPackagerConfigs(clmm_pool);
|
|
10674
|
-
const dlmmConfig = getPackagerConfigs(dlmm_pool);
|
|
10675
|
-
const typeArguments = [params.coinTypeA, params.coinTypeB];
|
|
10676
|
-
const allCoins = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress);
|
|
10677
|
-
const amountATotal = params.amountsX.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
|
|
10678
|
-
const amountBTotal = params.amountsY.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
|
|
10679
|
-
const primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amountATotal), params.coinTypeA, false, true);
|
|
10680
|
-
const primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amountBTotal), params.coinTypeB, false, true);
|
|
10681
|
-
const storageIds = [];
|
|
10682
|
-
params.realIds.forEach((i) => {
|
|
10683
|
-
storageIds.push(get_storage_id_from_real_id(i));
|
|
10684
|
-
});
|
|
10685
|
-
const args = [
|
|
10686
|
-
tx.object(dlmmConfig.factory),
|
|
10687
|
-
tx.object(global_config_id),
|
|
10688
|
-
tx.pure.u64(params.baseFee),
|
|
10689
|
-
tx.pure.u16(params.binStep),
|
|
10690
|
-
tx.pure.u32(get_storage_id_from_real_id(params.activeId)),
|
|
10691
|
-
primaryCoinAInputs.targetCoin,
|
|
10692
|
-
primaryCoinBInputs.targetCoin,
|
|
10693
|
-
tx.pure.vector("u32", storageIds),
|
|
10694
|
-
tx.pure.vector("u64", params.amountsX),
|
|
10695
|
-
tx.pure.vector("u64", params.amountsY),
|
|
10696
|
-
tx.pure.address(params.to),
|
|
10697
|
-
tx.object(CLOCK_ADDRESS)
|
|
10698
|
-
];
|
|
10699
|
-
const target = `${integrate.published_at}::${DlmmScript}::create_pair_add_liquidity`;
|
|
10700
|
-
tx.moveCall({
|
|
10701
|
-
target,
|
|
10702
|
-
typeArguments,
|
|
10703
|
-
arguments: args
|
|
10704
|
-
});
|
|
10705
|
-
return tx;
|
|
10706
|
-
}
|
|
10707
|
-
async swap(params) {
|
|
10708
|
-
const tx = new Transaction12();
|
|
10709
|
-
tx.setSender(this.sdk.senderAddress);
|
|
10710
|
-
const { clmm_pool, integrate } = this.sdk.sdkOptions;
|
|
10711
|
-
const { global_config_id } = getPackagerConfigs(clmm_pool);
|
|
10712
|
-
const typeArguments = [params.coinTypeA, params.coinTypeB];
|
|
10713
|
-
const allCoinAsset = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress);
|
|
10714
|
-
const primaryCoinInputA = TransactionUtil.buildCoinForAmount(
|
|
10715
|
-
tx,
|
|
10716
|
-
allCoinAsset,
|
|
10717
|
-
params.swapForY ? BigInt(params.amountIn) : BigInt(0),
|
|
10718
|
-
params.coinTypeA,
|
|
10719
|
-
false,
|
|
10720
|
-
true
|
|
10721
|
-
);
|
|
10722
|
-
const primaryCoinInputB = TransactionUtil.buildCoinForAmount(
|
|
10723
|
-
tx,
|
|
10724
|
-
allCoinAsset,
|
|
10725
|
-
params.swapForY ? BigInt(0) : BigInt(params.amountIn),
|
|
10726
|
-
params.coinTypeB,
|
|
10727
|
-
false,
|
|
10728
|
-
true
|
|
10729
|
-
);
|
|
10730
|
-
const args = [
|
|
10731
|
-
tx.object(params.pair),
|
|
10732
|
-
tx.object(global_config_id),
|
|
10733
|
-
primaryCoinInputA.targetCoin,
|
|
10734
|
-
primaryCoinInputB.targetCoin,
|
|
10735
|
-
tx.pure.u64(params.amountIn),
|
|
10736
|
-
tx.pure.u64(params.minAmountOut),
|
|
10737
|
-
tx.pure.bool(params.swapForY),
|
|
10738
|
-
tx.pure.address(params.to),
|
|
10739
|
-
tx.object(CLOCK_ADDRESS)
|
|
10740
|
-
];
|
|
10741
|
-
tx.moveCall({
|
|
10742
|
-
target: `${integrate.published_at}::${DlmmScript}::swap`,
|
|
10743
|
-
typeArguments,
|
|
10744
|
-
arguments: args
|
|
10745
|
-
});
|
|
10746
|
-
return tx;
|
|
10747
|
-
}
|
|
10748
|
-
async fetchBins(params) {
|
|
10749
|
-
const tx = new Transaction12();
|
|
10750
|
-
const { integrate, simulationAccount } = this.sdk.sdkOptions;
|
|
10751
|
-
const typeArguments = [params.coinTypeA, params.coinTypeB];
|
|
10752
|
-
const args = [tx.object(params.pair), tx.pure.u64(params.offset), tx.pure.u64(params.limit)];
|
|
10753
|
-
tx.moveCall({
|
|
10754
|
-
target: `${integrate.published_at}::${DlmmScript}::fetch_bins`,
|
|
10755
|
-
arguments: args,
|
|
10756
|
-
typeArguments
|
|
10757
|
-
});
|
|
10758
|
-
const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
|
|
10759
|
-
transactionBlock: tx,
|
|
10760
|
-
sender: simulationAccount.address
|
|
10761
|
-
});
|
|
10762
|
-
if (simulateRes.error != null) {
|
|
10763
|
-
throw new Error(`fetchBins error code: ${simulateRes.error ?? "unknown error"}`);
|
|
10764
|
-
}
|
|
10765
|
-
let res = [];
|
|
10766
|
-
simulateRes.events?.forEach((item) => {
|
|
10767
|
-
if (extractStructTagFromType(item.type).name === `EventFetchBins`) {
|
|
10768
|
-
const { bins } = item.parsedJson;
|
|
10769
|
-
res = bins;
|
|
10770
|
-
}
|
|
10771
|
-
});
|
|
10772
|
-
return res;
|
|
10773
|
-
}
|
|
10774
|
-
/**
|
|
10775
|
-
* Gets a list of positions for the given account address.
|
|
10776
|
-
* @param accountAddress The account address to get positions for.
|
|
10777
|
-
* @param assignPoolIds An array of pool IDs to filter the positions by.
|
|
10778
|
-
* @returns array of Position objects.
|
|
10779
|
-
*/
|
|
10780
|
-
async getUserPositionById(positionId, showDisplay = true) {
|
|
10781
|
-
let position;
|
|
10782
|
-
const ownerRes = await this._sdk.fullClient.getObject({
|
|
10783
|
-
id: positionId,
|
|
10784
|
-
options: { showContent: true, showType: true, showDisplay, showOwner: true }
|
|
10785
|
-
});
|
|
10786
|
-
const type = extractStructTagFromType(ownerRes.data.type);
|
|
10787
|
-
if (type.full_address === this.buildPositionType()) {
|
|
10788
|
-
position = this.buildPosition(ownerRes);
|
|
10789
|
-
} else {
|
|
10790
|
-
throw new ClmmpoolsError(`Dlmm Position not exists. Get Position error:${ownerRes.error}`, "InvalidPositionObject" /* InvalidPositionObject */);
|
|
10791
|
-
}
|
|
10792
|
-
const poolMap = /* @__PURE__ */ new Set();
|
|
10793
|
-
poolMap.add(position.pool);
|
|
10794
|
-
const pool = (await this.getPoolInfo(Array.from(poolMap)))[0];
|
|
10795
|
-
const _params = [];
|
|
10796
|
-
_params.push({
|
|
10797
|
-
pool_id: pool.pool_id,
|
|
10798
|
-
coin_a: pool.coin_a,
|
|
10799
|
-
coin_b: pool.coin_b
|
|
10800
|
-
});
|
|
10801
|
-
const pool_reward_coins = await this.getPairRewarders(_params);
|
|
10802
|
-
const positionLiquidity = await this.getPositionLiquidity({
|
|
10803
|
-
pair: position.pool,
|
|
10804
|
-
positionId: position.pos_object_id,
|
|
10805
|
-
coinTypeA: pool.coin_a,
|
|
10806
|
-
coinTypeB: pool.coin_b
|
|
10807
|
-
});
|
|
10808
|
-
const rewards_token = pool_reward_coins.get(position.pool) || [];
|
|
10809
|
-
let positionRewards = { position_id: position.pos_object_id, reward: [], amount: [] };
|
|
10810
|
-
if (rewards_token.length > 0) {
|
|
10811
|
-
positionRewards = await this.getEarnedRewards({
|
|
10812
|
-
pool_id: position.pool,
|
|
10813
|
-
position_id: position.pos_object_id,
|
|
10814
|
-
coin_a: pool.coin_a,
|
|
10815
|
-
coin_b: pool.coin_b,
|
|
10816
|
-
rewards_token: pool_reward_coins.get(position.pool) || []
|
|
10817
|
-
});
|
|
10818
|
-
}
|
|
10819
|
-
const positionFees = await this.getEarnedFees({
|
|
10820
|
-
pool_id: position.pool,
|
|
10821
|
-
position_id: position.pos_object_id,
|
|
10822
|
-
coin_a: pool.coin_a,
|
|
10823
|
-
coin_b: pool.coin_b
|
|
10824
|
-
});
|
|
10825
|
-
return {
|
|
10826
|
-
position,
|
|
10827
|
-
liquidity: positionLiquidity,
|
|
10828
|
-
rewards: positionRewards,
|
|
10829
|
-
fees: positionFees,
|
|
10830
|
-
contractPool: pool
|
|
10831
|
-
};
|
|
10832
|
-
}
|
|
10833
|
-
/**
|
|
10834
|
-
* Gets a list of positions for the given account address.
|
|
10835
|
-
* @param accountAddress The account address to get positions for.
|
|
10836
|
-
* @param assignPoolIds An array of pool IDs to filter the positions by.
|
|
10837
|
-
* @returns array of Position objects.
|
|
10838
|
-
*/
|
|
10839
|
-
async getUserPositions(accountAddress, assignPoolIds = [], showDisplay = true) {
|
|
10840
|
-
const allPosition = [];
|
|
10841
|
-
const ownerRes = await this._sdk.fullClient.getOwnedObjectsByPage(accountAddress, {
|
|
10842
|
-
options: { showType: true, showContent: true, showDisplay, showOwner: true },
|
|
10843
|
-
filter: { Package: this._sdk.sdkOptions.dlmm_pool.package_id }
|
|
10844
|
-
});
|
|
10845
|
-
const hasAssignPoolIds = assignPoolIds.length > 0;
|
|
10846
|
-
for (const item of ownerRes.data) {
|
|
10847
|
-
const type = extractStructTagFromType(item.data.type);
|
|
10848
|
-
if (type.full_address === this.buildPositionType()) {
|
|
10849
|
-
const position = this.buildPosition(item);
|
|
10850
|
-
const cacheKey = `${position.pos_object_id}_getPositionList`;
|
|
10851
|
-
this.updateCache(cacheKey, position, cacheTime24h);
|
|
10852
|
-
if (hasAssignPoolIds) {
|
|
10853
|
-
if (assignPoolIds.includes(position.pool)) {
|
|
10854
|
-
allPosition.push(position);
|
|
10855
|
-
}
|
|
10856
|
-
} else {
|
|
10857
|
-
allPosition.push(position);
|
|
10858
|
-
}
|
|
10859
|
-
}
|
|
10860
|
-
}
|
|
10861
|
-
const poolMap = /* @__PURE__ */ new Set();
|
|
10862
|
-
for (const item of allPosition) {
|
|
10863
|
-
poolMap.add(item.pool);
|
|
10864
|
-
}
|
|
10865
|
-
const poolList = await this.getPoolInfo(Array.from(poolMap));
|
|
10866
|
-
this.updateCache(`${DlmmScript}_positionList_poolList`, poolList, cacheTime24h);
|
|
10867
|
-
const _params = [];
|
|
10868
|
-
for (const pool of poolList) {
|
|
10869
|
-
_params.push({
|
|
10870
|
-
pool_id: pool.pool_id,
|
|
10871
|
-
coin_a: pool.coin_a,
|
|
10872
|
-
coin_b: pool.coin_b
|
|
10873
|
-
});
|
|
10874
|
-
}
|
|
10875
|
-
const pool_reward_coins = await this.getPairRewarders(_params);
|
|
10876
|
-
const out = [];
|
|
10877
|
-
for (const item of allPosition) {
|
|
10878
|
-
const pool = poolList.find((pool2) => pool2.pool_id === item.pool);
|
|
10879
|
-
const positionLiquidity = await this.getPositionLiquidity({
|
|
10880
|
-
pair: item.pool,
|
|
10881
|
-
positionId: item.pos_object_id,
|
|
10882
|
-
coinTypeA: pool.coin_a,
|
|
10883
|
-
coinTypeB: pool.coin_b
|
|
10884
|
-
});
|
|
10885
|
-
const rewards_token = pool_reward_coins.get(item.pool) || [];
|
|
10886
|
-
let positionRewards = { position_id: item.pos_object_id, reward: [], amount: [] };
|
|
10887
|
-
if (rewards_token.length > 0) {
|
|
10888
|
-
positionRewards = await this.getEarnedRewards({
|
|
10889
|
-
pool_id: item.pool,
|
|
10890
|
-
position_id: item.pos_object_id,
|
|
10891
|
-
coin_a: pool.coin_a,
|
|
10892
|
-
coin_b: pool.coin_b,
|
|
10893
|
-
rewards_token: pool_reward_coins.get(item.pool) || []
|
|
10894
|
-
});
|
|
10895
|
-
}
|
|
10896
|
-
const positionFees = await this.getEarnedFees({
|
|
10897
|
-
pool_id: item.pool,
|
|
10898
|
-
position_id: item.pos_object_id,
|
|
10899
|
-
coin_a: pool.coin_a,
|
|
10900
|
-
coin_b: pool.coin_b
|
|
10901
|
-
});
|
|
10902
|
-
out.push({
|
|
10903
|
-
position: item,
|
|
10904
|
-
liquidity: positionLiquidity,
|
|
10905
|
-
rewards: positionRewards,
|
|
10906
|
-
fees: positionFees,
|
|
10907
|
-
contractPool: pool
|
|
10908
|
-
});
|
|
10909
|
-
}
|
|
10910
|
-
return out;
|
|
10911
|
-
}
|
|
10912
|
-
buildPosition(object) {
|
|
10913
|
-
if (object.error != null || object.data?.content?.dataType !== "moveObject") {
|
|
10914
|
-
throw new ClmmpoolsError(`Dlmm Position not exists. Get Position error:${object.error}`, "InvalidPositionObject" /* InvalidPositionObject */);
|
|
10915
|
-
}
|
|
10916
|
-
const fields = getObjectFields(object);
|
|
10917
|
-
const ownerWarp = getObjectOwner(object);
|
|
10918
|
-
return {
|
|
10919
|
-
pos_object_id: fields.id.id,
|
|
10920
|
-
owner: ownerWarp.AddressOwner,
|
|
10921
|
-
pool: fields.pair_id,
|
|
10922
|
-
bin_real_ids: fields.bin_ids.map((id) => get_real_id(id)),
|
|
10923
|
-
type: ""
|
|
10924
|
-
};
|
|
10925
|
-
}
|
|
10926
|
-
// return [coin_a, coin_b]
|
|
10927
|
-
async getPoolCoins(pools) {
|
|
10928
|
-
const res = await this._sdk.fullClient.multiGetObjects({ ids: pools, options: { showContent: true } });
|
|
10929
|
-
const poolCoins = /* @__PURE__ */ new Map();
|
|
10930
|
-
res.forEach((item) => {
|
|
10931
|
-
if (item.error != null || item.data?.content?.dataType !== "moveObject") {
|
|
10932
|
-
throw new Error(`Failed to get poolCoins with err: ${item.error}`);
|
|
10933
|
-
}
|
|
10934
|
-
const type = getObjectType(item);
|
|
10935
|
-
const poolTypeFields = extractStructTagFromType(type);
|
|
10936
|
-
poolCoins.set(item.data.objectId, poolTypeFields.type_arguments);
|
|
10937
|
-
});
|
|
10938
|
-
return poolCoins;
|
|
10939
|
-
}
|
|
10940
|
-
buildPositionType() {
|
|
10941
|
-
return `${this._sdk.sdkOptions.dlmm_pool.package_id}::dlmm_position::Position`;
|
|
10942
|
-
}
|
|
10943
|
-
async getPositionLiquidity(params) {
|
|
10944
|
-
const tx = new Transaction12();
|
|
10945
|
-
const { integrate, simulationAccount } = this.sdk.sdkOptions;
|
|
10946
|
-
const typeArguments = [params.coinTypeA, params.coinTypeB];
|
|
10947
|
-
const args = [tx.object(params.pair), tx.object(params.positionId)];
|
|
10948
|
-
tx.moveCall({
|
|
10949
|
-
target: `${integrate.published_at}::${DlmmScript}::position_liquidity`,
|
|
10950
|
-
arguments: args,
|
|
10951
|
-
typeArguments
|
|
10952
|
-
});
|
|
10953
|
-
const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
|
|
10954
|
-
transactionBlock: tx,
|
|
10955
|
-
sender: simulationAccount.address
|
|
10956
|
-
});
|
|
10957
|
-
if (simulateRes.error != null) {
|
|
10958
|
-
throw new Error(`fetchBins error code: ${simulateRes.error ?? "unknown error"}`);
|
|
10959
|
-
}
|
|
10960
|
-
const out = {
|
|
10961
|
-
shares: 0,
|
|
10962
|
-
liquidity: 0,
|
|
10963
|
-
x_equivalent: 0,
|
|
10964
|
-
y_equivalent: 0,
|
|
10965
|
-
bin_real_ids: [],
|
|
10966
|
-
bin_x_eq: [],
|
|
10967
|
-
bin_y_eq: [],
|
|
10968
|
-
bin_liquidity: []
|
|
10969
|
-
};
|
|
10970
|
-
simulateRes.events?.forEach((item) => {
|
|
10971
|
-
if (extractStructTagFromType(item.type).name === `EventPositionLiquidity`) {
|
|
10972
|
-
out.shares = item.parsedJson.shares;
|
|
10973
|
-
out.liquidity = item.parsedJson.liquidity;
|
|
10974
|
-
out.x_equivalent = item.parsedJson.x_equivalent;
|
|
10975
|
-
out.y_equivalent = item.parsedJson.y_equivalent;
|
|
10976
|
-
out.bin_real_ids = item.parsedJson.bin_ids.map((id) => get_real_id(id));
|
|
10977
|
-
out.bin_x_eq = item.parsedJson.bin_x_eq;
|
|
10978
|
-
out.bin_y_eq = item.parsedJson.bin_y_eq;
|
|
10979
|
-
out.bin_liquidity = item.parsedJson.bin_liquidity;
|
|
10980
|
-
}
|
|
10981
|
-
});
|
|
10982
|
-
return out;
|
|
10983
|
-
}
|
|
10984
|
-
async getPairLiquidity(params) {
|
|
10985
|
-
const tx = new Transaction12();
|
|
10986
|
-
const { integrate, simulationAccount } = this.sdk.sdkOptions;
|
|
10987
|
-
const typeArguments = [params.coinTypeA, params.coinTypeB];
|
|
10988
|
-
const args = [tx.object(params.pair)];
|
|
10989
|
-
tx.moveCall({
|
|
10990
|
-
target: `${integrate.published_at}::${DlmmScript}::pair_liquidity`,
|
|
10991
|
-
arguments: args,
|
|
10992
|
-
typeArguments
|
|
10993
|
-
});
|
|
10994
|
-
const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
|
|
10995
|
-
transactionBlock: tx,
|
|
10996
|
-
sender: simulationAccount.address
|
|
10997
|
-
});
|
|
10998
|
-
if (simulateRes.error != null) {
|
|
10999
|
-
throw new Error(`fetchBins error code: ${simulateRes.error ?? "unknown error"}`);
|
|
11000
|
-
}
|
|
11001
|
-
const out = {
|
|
11002
|
-
shares: 0,
|
|
11003
|
-
liquidity: 0,
|
|
11004
|
-
x: 0,
|
|
11005
|
-
y: 0,
|
|
11006
|
-
bin_ids: [],
|
|
11007
|
-
bin_x: [],
|
|
11008
|
-
bin_y: []
|
|
11009
|
-
};
|
|
11010
|
-
simulateRes.events?.forEach((item) => {
|
|
11011
|
-
if (extractStructTagFromType(item.type).name === `EventPositionLiquidity`) {
|
|
11012
|
-
out.shares = item.parsedJson.shares;
|
|
11013
|
-
out.liquidity = item.parsedJson.liquidity;
|
|
11014
|
-
out.x = item.parsedJson.x;
|
|
11015
|
-
out.y = item.parsedJson.y;
|
|
11016
|
-
out.bin_ids = item.bin_ids;
|
|
11017
|
-
out.bin_x = item.bin_x;
|
|
11018
|
-
out.bin_y = item.bin_y;
|
|
11019
|
-
}
|
|
11020
|
-
});
|
|
11021
|
-
return out;
|
|
11022
|
-
}
|
|
11023
|
-
async getEarnedFees(params) {
|
|
11024
|
-
const tx = new Transaction12();
|
|
11025
|
-
const { integrate, simulationAccount } = this.sdk.sdkOptions;
|
|
11026
|
-
const typeArguments = [params.coin_a, params.coin_b];
|
|
11027
|
-
const args = [tx.object(params.pool_id), tx.object(params.position_id)];
|
|
11028
|
-
tx.moveCall({
|
|
11029
|
-
target: `${integrate.published_at}::${DlmmScript}::earned_fees`,
|
|
11030
|
-
arguments: args,
|
|
11031
|
-
typeArguments
|
|
11032
|
-
});
|
|
11033
|
-
const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
|
|
11034
|
-
transactionBlock: tx,
|
|
11035
|
-
sender: simulationAccount.address
|
|
11036
|
-
});
|
|
11037
|
-
const out = {
|
|
11038
|
-
position_id: "",
|
|
11039
|
-
x: "",
|
|
11040
|
-
y: "",
|
|
11041
|
-
fee_x: 0,
|
|
11042
|
-
fee_y: 0
|
|
11043
|
-
};
|
|
11044
|
-
if (simulateRes.error != null) {
|
|
11045
|
-
throw new Error(`fetchPairRewards error code: ${simulateRes.error ?? "unknown error"}`);
|
|
11046
|
-
}
|
|
11047
|
-
simulateRes.events?.forEach((item) => {
|
|
11048
|
-
if (extractStructTagFromType(item.type).name === `EventPositionLiquidity`) {
|
|
11049
|
-
out.position_id = item.parsedJson.position_id;
|
|
11050
|
-
out.x = item.parsedJson.x;
|
|
11051
|
-
out.y = item.parsedJson.y;
|
|
11052
|
-
out.fee_x = item.parsedJson.fee_x;
|
|
11053
|
-
out.fee_y = item.parsedJson.fee_y;
|
|
11054
|
-
}
|
|
11055
|
-
});
|
|
11056
|
-
return out;
|
|
11057
|
-
}
|
|
11058
|
-
async getEarnedRewards(params) {
|
|
11059
|
-
const tx = new Transaction12();
|
|
11060
|
-
const { integrate, simulationAccount } = this.sdk.sdkOptions;
|
|
11061
|
-
const typeArguments = [params.coin_a, params.coin_b, ...params.rewards_token];
|
|
11062
|
-
const args = [tx.object(params.pool_id), tx.object(params.position_id), tx.object(CLOCK_ADDRESS)];
|
|
11063
|
-
let target = `${integrate.published_at}::${DlmmScript}::earned_rewards`;
|
|
11064
|
-
if (params.rewards_token.length > 1) {
|
|
11065
|
-
target = `${integrate.published_at}::${DlmmScript}::earned_rewards${params.rewards_token.length}`;
|
|
11066
|
-
}
|
|
11067
|
-
tx.moveCall({
|
|
11068
|
-
target,
|
|
11069
|
-
arguments: args,
|
|
11070
|
-
typeArguments
|
|
11071
|
-
});
|
|
11072
|
-
const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
|
|
11073
|
-
transactionBlock: tx,
|
|
11074
|
-
sender: simulationAccount.address
|
|
11075
|
-
});
|
|
11076
|
-
const out = {
|
|
11077
|
-
position_id: "",
|
|
11078
|
-
reward: [],
|
|
11079
|
-
amount: []
|
|
11080
|
-
};
|
|
11081
|
-
if (simulateRes.error != null) {
|
|
11082
|
-
throw new Error(`getEarnedRewards error code: ${simulateRes.error ?? "unknown error"}`);
|
|
11083
|
-
}
|
|
11084
|
-
simulateRes.events?.forEach((item) => {
|
|
11085
|
-
if (extractStructTagFromType(item.type).name === `DlmmEventEarnedRewards`) {
|
|
11086
|
-
out.position_id = item.parsedJson.position_id;
|
|
11087
|
-
out.reward = [item.parsedJson.reward];
|
|
11088
|
-
out.amount = [item.parsedJson.amount];
|
|
11089
|
-
} else if (extractStructTagFromType(item.type).name === `DlmmEventEarnedRewards2`) {
|
|
11090
|
-
out.position_id = item.parsedJson.position_id;
|
|
11091
|
-
out.reward = [item.parsedJson.reward1, item.parsedJson.reward2];
|
|
11092
|
-
out.amount = [item.parsedJson.amount1, item.parsedJson.amount2];
|
|
11093
|
-
} else if (extractStructTagFromType(item.type).name === `EventEarnedRewards3`) {
|
|
11094
|
-
out.position_id = item.parsedJson.position_id;
|
|
11095
|
-
out.reward = [item.parsedJson.reward1, item.parsedJson.reward2, item.parsedJson.reward3];
|
|
11096
|
-
out.amount = [item.parsedJson.amount1, item.parsedJson.amount2, item.parsedJson.amount3];
|
|
11097
|
-
}
|
|
11098
|
-
});
|
|
11099
|
-
return out;
|
|
11100
|
-
}
|
|
11101
|
-
// return pool_id => reward_tokens
|
|
11102
|
-
async getPairRewarders(params) {
|
|
11103
|
-
let tx = new Transaction12();
|
|
11104
|
-
for (const param of params) {
|
|
11105
|
-
tx = await this._getPairRewarders(param, tx);
|
|
11106
|
-
}
|
|
11107
|
-
return this._parsePairRewarders(tx);
|
|
11108
|
-
}
|
|
11109
|
-
async _getPairRewarders(params, tx) {
|
|
11110
|
-
tx = tx || new Transaction12();
|
|
11111
|
-
const { integrate } = this.sdk.sdkOptions;
|
|
11112
|
-
const typeArguments = [params.coin_a, params.coin_b];
|
|
11113
|
-
const args = [tx.object(params.pool_id)];
|
|
11114
|
-
tx.moveCall({
|
|
11115
|
-
target: `${integrate.published_at}::${DlmmScript}::get_pair_rewarders`,
|
|
11116
|
-
arguments: args,
|
|
11117
|
-
typeArguments
|
|
11118
|
-
});
|
|
11119
|
-
return tx;
|
|
11120
|
-
}
|
|
11121
|
-
async _parsePairRewarders(tx) {
|
|
11122
|
-
const { simulationAccount } = this.sdk.sdkOptions;
|
|
11123
|
-
const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
|
|
11124
|
-
transactionBlock: tx,
|
|
11125
|
-
sender: simulationAccount.address
|
|
11126
|
-
});
|
|
11127
|
-
const out = /* @__PURE__ */ new Map();
|
|
11128
|
-
if (simulateRes.error != null) {
|
|
11129
|
-
throw new Error(`fetchBins error code: ${simulateRes.error ?? "unknown error"}`);
|
|
11130
|
-
}
|
|
11131
|
-
simulateRes.events?.forEach((item) => {
|
|
11132
|
-
if (extractStructTagFromType(item.type).name === `EventPairRewardTypes`) {
|
|
11133
|
-
const pairRewards = {
|
|
11134
|
-
pair_id: "",
|
|
11135
|
-
tokens: []
|
|
11136
|
-
};
|
|
11137
|
-
pairRewards.pair_id = item.parsedJson.pair_id;
|
|
11138
|
-
item.parsedJson.tokens.forEach((token) => {
|
|
11139
|
-
pairRewards.tokens.push(token.name);
|
|
11140
|
-
});
|
|
11141
|
-
out.set(pairRewards.pair_id, pairRewards.tokens);
|
|
11142
|
-
}
|
|
11143
|
-
});
|
|
11144
|
-
return out;
|
|
11145
|
-
}
|
|
11146
|
-
/**
|
|
11147
|
-
* Updates the cache for the given key.
|
|
11148
|
-
*
|
|
11149
|
-
* @param key The key of the cache entry to update.
|
|
11150
|
-
* @param data The data to store in the cache.
|
|
11151
|
-
* @param time The time in minutes after which the cache entry should expire.
|
|
11152
|
-
*/
|
|
11153
|
-
updateCache(key, data, time = cacheTime5min) {
|
|
11154
|
-
let cacheData = this._cache[key];
|
|
11155
|
-
if (cacheData) {
|
|
11156
|
-
cacheData.overdueTime = getFutureTime(time);
|
|
11157
|
-
cacheData.value = data;
|
|
11158
|
-
} else {
|
|
11159
|
-
cacheData = new CachedContent(data, getFutureTime(time));
|
|
11160
|
-
}
|
|
11161
|
-
this._cache[key] = cacheData;
|
|
11162
|
-
}
|
|
11163
|
-
/**
|
|
11164
|
-
* Gets the cache entry for the given key.
|
|
11165
|
-
*
|
|
11166
|
-
* @param key The key of the cache entry to get.
|
|
11167
|
-
* @param forceRefresh Whether to force a refresh of the cache entry.
|
|
11168
|
-
* @returns The cache entry for the given key, or undefined if the cache entry does not exist or is expired.
|
|
11169
|
-
*/
|
|
11170
|
-
getCache(key, forceRefresh = false) {
|
|
11171
|
-
const cacheData = this._cache[key];
|
|
11172
|
-
const isValid = cacheData?.isValid();
|
|
11173
|
-
if (!forceRefresh && isValid) {
|
|
11174
|
-
return cacheData.value;
|
|
11175
|
-
}
|
|
11176
|
-
if (!isValid) {
|
|
11177
|
-
delete this._cache[key];
|
|
11178
|
-
}
|
|
11179
|
-
return void 0;
|
|
11180
|
-
}
|
|
11181
|
-
};
|
|
11182
|
-
|
|
11183
|
-
// src/sdk.ts
|
|
11184
|
-
var MagmaClmmSDK = class {
|
|
11185
|
-
_cache = {};
|
|
11186
|
-
/**
|
|
11187
|
-
* RPC provider on the SUI chain
|
|
11188
|
-
*/
|
|
11189
|
-
_rpcModule;
|
|
11190
|
-
/**
|
|
11191
|
-
* Provide interact with clmm pools with a pool router interface.
|
|
11192
|
-
*/
|
|
11193
|
-
_pool;
|
|
11194
|
-
/**
|
|
11195
|
-
* Provide interact with clmm position with a position router interface.
|
|
11196
|
-
*/
|
|
11197
|
-
_position;
|
|
11198
|
-
/**
|
|
11199
|
-
* Provide interact with a pool swap router interface.
|
|
11200
|
-
*/
|
|
11201
|
-
_swap;
|
|
11202
|
-
/**
|
|
11203
|
-
* Provide interact with a lock interface.
|
|
11204
|
-
*/
|
|
11205
|
-
_lock;
|
|
11206
|
-
_gauge;
|
|
11207
|
-
_dlmm;
|
|
11208
|
-
/**
|
|
11209
|
-
* Provide interact with a position rewarder interface.
|
|
11210
|
-
*/
|
|
11211
|
-
_rewarder;
|
|
11212
|
-
/**
|
|
11213
|
-
* Provide interact with a pool router interface.
|
|
11214
|
-
*/
|
|
11215
|
-
_router;
|
|
11216
|
-
/**
|
|
11217
|
-
* Provide interact with a pool routerV2 interface.
|
|
11218
|
-
*/
|
|
11219
|
-
_router_v2;
|
|
11220
|
-
/**
|
|
11221
|
-
* Provide interact with pool and token config (contain token base info for metadat).
|
|
11222
|
-
* @deprecated Please use MagmaConfig instead
|
|
11223
|
-
*/
|
|
11224
|
-
_token;
|
|
11225
|
-
/**
|
|
11226
|
-
* Provide interact with clmm pool and coin and launchpad pool config
|
|
11227
|
-
*/
|
|
11228
|
-
_config;
|
|
11229
|
-
/**
|
|
11230
|
-
* Provide sdk options
|
|
11231
|
-
*/
|
|
11232
|
-
_sdkOptions;
|
|
11233
|
-
/**
|
|
11234
|
-
* After connecting the wallet, set the current wallet address to senderAddress.
|
|
11235
|
-
*/
|
|
11236
|
-
_senderAddress = "";
|
|
11237
|
-
constructor(options) {
|
|
11238
|
-
this._sdkOptions = options;
|
|
11239
|
-
this._rpcModule = new RpcModule({
|
|
11240
|
-
url: options.fullRpcUrl
|
|
9807
|
+
/**
|
|
9808
|
+
* RPC provider on the SUI chain
|
|
9809
|
+
*/
|
|
9810
|
+
_rpcModule;
|
|
9811
|
+
/**
|
|
9812
|
+
* Provide interact with clmm pools with a pool router interface.
|
|
9813
|
+
*/
|
|
9814
|
+
_pool;
|
|
9815
|
+
/**
|
|
9816
|
+
* Provide interact with clmm position with a position router interface.
|
|
9817
|
+
*/
|
|
9818
|
+
_position;
|
|
9819
|
+
/**
|
|
9820
|
+
* Provide interact with a pool swap router interface.
|
|
9821
|
+
*/
|
|
9822
|
+
_swap;
|
|
9823
|
+
/**
|
|
9824
|
+
* Provide interact with a lock interface.
|
|
9825
|
+
*/
|
|
9826
|
+
_lock;
|
|
9827
|
+
_gauge;
|
|
9828
|
+
/**
|
|
9829
|
+
* Provide interact with a position rewarder interface.
|
|
9830
|
+
*/
|
|
9831
|
+
_rewarder;
|
|
9832
|
+
/**
|
|
9833
|
+
* Provide interact with a pool router interface.
|
|
9834
|
+
*/
|
|
9835
|
+
_router;
|
|
9836
|
+
/**
|
|
9837
|
+
* Provide interact with a pool routerV2 interface.
|
|
9838
|
+
*/
|
|
9839
|
+
_router_v2;
|
|
9840
|
+
/**
|
|
9841
|
+
* Provide interact with pool and token config (contain token base info for metadat).
|
|
9842
|
+
* @deprecated Please use MagmaConfig instead
|
|
9843
|
+
*/
|
|
9844
|
+
_token;
|
|
9845
|
+
/**
|
|
9846
|
+
* Provide interact with clmm pool and coin and launchpad pool config
|
|
9847
|
+
*/
|
|
9848
|
+
_config;
|
|
9849
|
+
/**
|
|
9850
|
+
* Provide sdk options
|
|
9851
|
+
*/
|
|
9852
|
+
_sdkOptions;
|
|
9853
|
+
/**
|
|
9854
|
+
* After connecting the wallet, set the current wallet address to senderAddress.
|
|
9855
|
+
*/
|
|
9856
|
+
_senderAddress = "";
|
|
9857
|
+
constructor(options) {
|
|
9858
|
+
this._sdkOptions = options;
|
|
9859
|
+
this._rpcModule = new RpcModule({
|
|
9860
|
+
url: options.fullRpcUrl
|
|
11241
9861
|
});
|
|
11242
9862
|
this._swap = new SwapModule(this);
|
|
11243
9863
|
this._lock = new LockModule(this);
|
|
11244
9864
|
this._gauge = new GaugeModule(this);
|
|
11245
|
-
this._dlmm = new DlmmModule(this);
|
|
11246
9865
|
this._pool = new PoolModule(this);
|
|
11247
9866
|
this._position = new PositionModule(this);
|
|
11248
9867
|
this._rewarder = new RewarderModule(this);
|
|
@@ -11280,9 +9899,6 @@ var MagmaClmmSDK = class {
|
|
|
11280
9899
|
get Gauge() {
|
|
11281
9900
|
return this._gauge;
|
|
11282
9901
|
}
|
|
11283
|
-
get Dlmm() {
|
|
11284
|
-
return this._dlmm;
|
|
11285
|
-
}
|
|
11286
9902
|
/**
|
|
11287
9903
|
* Getter for the fullClient property.
|
|
11288
9904
|
* @returns {RpcModule} The fullClient property value.
|
|
@@ -11456,7 +10072,6 @@ var main_default = MagmaClmmSDK;
|
|
|
11456
10072
|
var SDKConfig = {
|
|
11457
10073
|
clmmConfig: {
|
|
11458
10074
|
pools_id: "0xfa145b9de10fe858be81edd1c6cdffcf27be9d016de02a1345eb1009a68ba8b2",
|
|
11459
|
-
// clmm and dlmm both use this global_config
|
|
11460
10075
|
global_config_id: "0x4c4e1402401f72c7d8533d0ed8d5f8949da363c7a3319ccef261ffe153d32f8a",
|
|
11461
10076
|
global_vault_id: "0xa7e1102f222b6eb81ccc8a126e7feb2353342be9df6f6646a77c4519da29c071",
|
|
11462
10077
|
admin_cap_id: "0x89c1a321291d15ddae5a086c9abc533dff697fde3d89e0ca836c41af73e36a75"
|
|
@@ -11476,11 +10091,7 @@ var SDKConfig = {
|
|
|
11476
10091
|
distribution_cfg: "0xaff8d151ac29317201151f97d28c546b3c5923d8cfc5499f40dea61c4022c949",
|
|
11477
10092
|
magma_token: "0x7161c6c6bb65f852797c8f7f5c4f8d57adaf796e1b840921f9e23fabeadfd54e::magma::MAGMA",
|
|
11478
10093
|
minter_id: "0x4fa5766cd83b33b215b139fec27ac344040f3bbd84fcbee7b61fc671aadc51fa"
|
|
11479
|
-
}
|
|
11480
|
-
dlmmConfig: {
|
|
11481
|
-
factory: ""
|
|
11482
|
-
},
|
|
11483
|
-
gaugeConfig: {}
|
|
10094
|
+
}
|
|
11484
10095
|
};
|
|
11485
10096
|
var clmmMainnet = {
|
|
11486
10097
|
fullRpcUrl: getFullnodeUrl("mainnet"),
|
|
@@ -11497,11 +10108,6 @@ var clmmMainnet = {
|
|
|
11497
10108
|
published_at: "0x4a35d3dfef55ed3631b7158544c6322a23bc434fe4fca1234cb680ce0505f82d",
|
|
11498
10109
|
config: SDKConfig.clmmConfig
|
|
11499
10110
|
},
|
|
11500
|
-
dlmm_pool: {
|
|
11501
|
-
package_id: "",
|
|
11502
|
-
published_at: "",
|
|
11503
|
-
config: SDKConfig.dlmmConfig
|
|
11504
|
-
},
|
|
11505
10111
|
distribution: {
|
|
11506
10112
|
package_id: "0xee4a1f231dc45a303389998fe26c4e39278cf68b404b32e4f0b9769129b8267b",
|
|
11507
10113
|
published_at: "0xee4a1f231dc45a303389998fe26c4e39278cf68b404b32e4f0b9769129b8267b"
|
|
@@ -11555,9 +10161,6 @@ var SDKConfig2 = {
|
|
|
11555
10161
|
distribution_cfg: "0x94e23846c975e2faf89a61bfc2b10ad64decab9069eb1f9fc39752b010868c74",
|
|
11556
10162
|
magma_token: "0x45ac2371c33ca0df8dc784d62c8ce5126d42edd8c56820396524dff2ae0619b1::magma_token::MAGMA_TOKEN",
|
|
11557
10163
|
minter_id: "0x89435d6b2a510ba50ca23303f10e91ec058f138a88f69a43fe03cd22edb214c5"
|
|
11558
|
-
},
|
|
11559
|
-
dlmmConfig: {
|
|
11560
|
-
factory: ""
|
|
11561
10164
|
}
|
|
11562
10165
|
};
|
|
11563
10166
|
var clmmTestnet = {
|
|
@@ -11572,11 +10175,6 @@ var clmmTestnet = {
|
|
|
11572
10175
|
published_at: "0x23e0b5ab4aa63d0e6fd98fa5e247bcf9b36ad716b479d39e56b2ba9ff631e09d",
|
|
11573
10176
|
config: SDKConfig2.clmmConfig
|
|
11574
10177
|
},
|
|
11575
|
-
dlmm_pool: {
|
|
11576
|
-
package_id: "",
|
|
11577
|
-
published_at: "",
|
|
11578
|
-
config: SDKConfig2.dlmmConfig
|
|
11579
|
-
},
|
|
11580
10178
|
distribution: {
|
|
11581
10179
|
package_id: "0x45ac2371c33ca0df8dc784d62c8ce5126d42edd8c56820396524dff2ae0619b1",
|
|
11582
10180
|
published_at: "0x45ac2371c33ca0df8dc784d62c8ce5126d42edd8c56820396524dff2ae0619b1"
|
|
@@ -11624,7 +10222,6 @@ var src_default = MagmaClmmSDK;
|
|
|
11624
10222
|
export {
|
|
11625
10223
|
AMM_SWAP_MODULE,
|
|
11626
10224
|
AmountSpecified,
|
|
11627
|
-
BinMath,
|
|
11628
10225
|
CLOCK_ADDRESS,
|
|
11629
10226
|
CachedContent,
|
|
11630
10227
|
ClmmExpectSwapModule,
|
|
@@ -11652,7 +10249,6 @@ export {
|
|
|
11652
10249
|
DeepbookCustodianV2Moudle,
|
|
11653
10250
|
DeepbookEndpointsV2Moudle,
|
|
11654
10251
|
DeepbookUtils,
|
|
11655
|
-
DlmmScript,
|
|
11656
10252
|
FEE_RATE_DENOMINATOR,
|
|
11657
10253
|
GAS_SYMBOL,
|
|
11658
10254
|
GAS_TYPE_ARG,
|
|
@@ -11680,7 +10276,6 @@ export {
|
|
|
11680
10276
|
SUI_SYSTEM_STATE_OBJECT_ID,
|
|
11681
10277
|
SplitSwap,
|
|
11682
10278
|
SplitUnit,
|
|
11683
|
-
StrategyType,
|
|
11684
10279
|
SwapDirection,
|
|
11685
10280
|
SwapModule,
|
|
11686
10281
|
SwapUtils,
|
|
@@ -11702,10 +10297,6 @@ export {
|
|
|
11702
10297
|
adjustForSlippage,
|
|
11703
10298
|
asIntN,
|
|
11704
10299
|
asUintN,
|
|
11705
|
-
autoFillXByStrategy,
|
|
11706
|
-
autoFillXByWeight,
|
|
11707
|
-
autoFillYByStrategy,
|
|
11708
|
-
autoFillYByWeight,
|
|
11709
10300
|
bufferToHex,
|
|
11710
10301
|
buildClmmPositionName,
|
|
11711
10302
|
buildNFT,
|
|
@@ -11744,14 +10335,12 @@ export {
|
|
|
11744
10335
|
getAmountUnfixedDelta,
|
|
11745
10336
|
getCoinAFromLiquidity,
|
|
11746
10337
|
getCoinBFromLiquidity,
|
|
11747
|
-
getCoinXYForLiquidity,
|
|
11748
10338
|
getDefaultSuiInputType,
|
|
11749
10339
|
getDeltaA,
|
|
11750
10340
|
getDeltaB,
|
|
11751
10341
|
getDeltaDownFromOutput,
|
|
11752
10342
|
getDeltaUpFromInput,
|
|
11753
10343
|
getFutureTime,
|
|
11754
|
-
getLiquidityAndCoinYByCoinX,
|
|
11755
10344
|
getLiquidityFromCoinA,
|
|
11756
10345
|
getLiquidityFromCoinB,
|
|
11757
10346
|
getLowerSqrtPriceFromCoinA,
|
|
@@ -11775,7 +10364,6 @@ export {
|
|
|
11775
10364
|
getObjectType,
|
|
11776
10365
|
getObjectVersion,
|
|
11777
10366
|
getPackagerConfigs,
|
|
11778
|
-
getPriceOfBinByBinId,
|
|
11779
10367
|
getRewardInTickRange,
|
|
11780
10368
|
getSuiObjectData,
|
|
11781
10369
|
getTickDataFromUrlData,
|
|
@@ -11799,15 +10387,10 @@ export {
|
|
|
11799
10387
|
shortAddress,
|
|
11800
10388
|
shortString,
|
|
11801
10389
|
tickScore,
|
|
11802
|
-
toAmountAskSide,
|
|
11803
|
-
toAmountBidSide,
|
|
11804
|
-
toAmountBothSide,
|
|
11805
|
-
toAmountsBothSideByStrategy,
|
|
11806
10390
|
toBuffer,
|
|
11807
10391
|
toCoinAmount,
|
|
11808
10392
|
toDecimalsAmount,
|
|
11809
10393
|
transClmmpoolDataWithoutTicks,
|
|
11810
|
-
utf8to16
|
|
11811
|
-
withLiquiditySlippage
|
|
10394
|
+
utf8to16
|
|
11812
10395
|
};
|
|
11813
10396
|
//# sourceMappingURL=index.mjs.map
|