@magmaprotocol/magma-clmm-sdk 0.5.39 → 0.5.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +197 -2
- package/dist/index.js +1098 -148
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1081 -144
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -37,7 +37,7 @@ var CachedContent = class {
|
|
|
37
37
|
};
|
|
38
38
|
|
|
39
39
|
// src/utils/common.ts
|
|
40
|
-
import
|
|
40
|
+
import BN13 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";
|
|
@@ -1592,8 +1592,660 @@ function collectFeesQuote(param) {
|
|
|
1592
1592
|
return updateFees(param.position, fee_growth_inside_a, fee_growth_inside_b);
|
|
1593
1593
|
}
|
|
1594
1594
|
|
|
1595
|
-
// src/math/
|
|
1595
|
+
// src/math/dlmmStrategy.ts
|
|
1596
|
+
import BN10 from "bn.js";
|
|
1597
|
+
|
|
1598
|
+
// src/math/dlmmWeightToAmounts.ts
|
|
1596
1599
|
import BN9 from "bn.js";
|
|
1600
|
+
import Decimal3 from "decimal.js";
|
|
1601
|
+
import { get_price_from_real_id } from "@magmaprotocol/calc_dlmm";
|
|
1602
|
+
function getPriceOfBinByBinId(binId, binStep) {
|
|
1603
|
+
const twoDec = new Decimal3(2);
|
|
1604
|
+
const price = new Decimal3(get_price_from_real_id(binId, binStep));
|
|
1605
|
+
return price.div(twoDec.pow(128));
|
|
1606
|
+
}
|
|
1607
|
+
function autoFillYByWeight(activeId, binStep, amountX, amountXInActiveBin, amountYInActiveBin, distributions) {
|
|
1608
|
+
const activeBins = distributions.filter((element) => {
|
|
1609
|
+
return element.binId === activeId;
|
|
1610
|
+
});
|
|
1611
|
+
if (activeBins.length === 1) {
|
|
1612
|
+
const p0 = getPriceOfBinByBinId(activeId, binStep);
|
|
1613
|
+
let wx0 = new Decimal3(0);
|
|
1614
|
+
let wy0 = new Decimal3(0);
|
|
1615
|
+
const activeBin = activeBins[0];
|
|
1616
|
+
if (amountXInActiveBin.isZero() && amountYInActiveBin.isZero()) {
|
|
1617
|
+
wx0 = new Decimal3(activeBin.weight).div(p0.mul(new Decimal3(2)));
|
|
1618
|
+
wy0 = new Decimal3(activeBin.weight).div(new Decimal3(2));
|
|
1619
|
+
} else {
|
|
1620
|
+
const amountXInActiveBinDec = new Decimal3(amountXInActiveBin.toString());
|
|
1621
|
+
const amountYInActiveBinDec = new Decimal3(amountYInActiveBin.toString());
|
|
1622
|
+
if (!amountXInActiveBin.isZero()) {
|
|
1623
|
+
wx0 = new Decimal3(activeBin.weight).div(p0.add(amountYInActiveBinDec.div(amountXInActiveBinDec)));
|
|
1624
|
+
}
|
|
1625
|
+
if (!amountYInActiveBin.isZero()) {
|
|
1626
|
+
wy0 = new Decimal3(activeBin.weight).div(new Decimal3(1).add(p0.mul(amountXInActiveBinDec).div(amountYInActiveBinDec)));
|
|
1627
|
+
}
|
|
1628
|
+
}
|
|
1629
|
+
let totalWeightX2 = wx0;
|
|
1630
|
+
let totalWeightY2 = wy0;
|
|
1631
|
+
distributions.forEach((element) => {
|
|
1632
|
+
if (element.binId < activeId) {
|
|
1633
|
+
totalWeightY2 = totalWeightY2.add(new Decimal3(element.weight));
|
|
1634
|
+
}
|
|
1635
|
+
if (element.binId > activeId) {
|
|
1636
|
+
const price = getPriceOfBinByBinId(element.binId, binStep);
|
|
1637
|
+
const weighPerPrice = new Decimal3(element.weight).div(price);
|
|
1638
|
+
totalWeightX2 = totalWeightX2.add(weighPerPrice);
|
|
1639
|
+
}
|
|
1640
|
+
});
|
|
1641
|
+
const kx2 = totalWeightX2.isZero() ? new Decimal3(1) : new Decimal3(amountX.toString()).div(totalWeightX2);
|
|
1642
|
+
const amountY2 = kx2.mul(totalWeightY2);
|
|
1643
|
+
return new BN9(amountY2.floor().toString());
|
|
1644
|
+
}
|
|
1645
|
+
let totalWeightX = new Decimal3(0);
|
|
1646
|
+
let totalWeightY = new Decimal3(0);
|
|
1647
|
+
distributions.forEach((element) => {
|
|
1648
|
+
if (element.binId < activeId) {
|
|
1649
|
+
totalWeightY = totalWeightY.add(new Decimal3(element.weight));
|
|
1650
|
+
} else {
|
|
1651
|
+
const price = getPriceOfBinByBinId(element.binId, binStep);
|
|
1652
|
+
const weighPerPrice = new Decimal3(element.weight).div(price);
|
|
1653
|
+
totalWeightX = totalWeightX.add(weighPerPrice);
|
|
1654
|
+
}
|
|
1655
|
+
});
|
|
1656
|
+
const kx = totalWeightX.isZero() ? new Decimal3(1) : new Decimal3(amountX.toString()).div(totalWeightX);
|
|
1657
|
+
const amountY = kx.mul(totalWeightY);
|
|
1658
|
+
return new BN9(amountY.floor().toString());
|
|
1659
|
+
}
|
|
1660
|
+
function autoFillXByWeight(activeId, binStep, amountY, amountXInActiveBin, amountYInActiveBin, distributions) {
|
|
1661
|
+
const activeBins = distributions.filter((element) => {
|
|
1662
|
+
return element.binId === activeId;
|
|
1663
|
+
});
|
|
1664
|
+
if (activeBins.length === 1) {
|
|
1665
|
+
const p0 = getPriceOfBinByBinId(activeId, binStep);
|
|
1666
|
+
let wx0 = new Decimal3(0);
|
|
1667
|
+
let wy0 = new Decimal3(0);
|
|
1668
|
+
const activeBin = activeBins[0];
|
|
1669
|
+
if (amountXInActiveBin.isZero() && amountYInActiveBin.isZero()) {
|
|
1670
|
+
wx0 = new Decimal3(activeBin.weight).div(p0.mul(new Decimal3(2)));
|
|
1671
|
+
wy0 = new Decimal3(activeBin.weight).div(new Decimal3(2));
|
|
1672
|
+
} else {
|
|
1673
|
+
const amountXInActiveBinDec = new Decimal3(amountXInActiveBin.toString());
|
|
1674
|
+
const amountYInActiveBinDec = new Decimal3(amountYInActiveBin.toString());
|
|
1675
|
+
if (!amountXInActiveBin.isZero()) {
|
|
1676
|
+
wx0 = new Decimal3(activeBin.weight).div(p0.add(amountYInActiveBinDec.div(amountXInActiveBinDec)));
|
|
1677
|
+
}
|
|
1678
|
+
if (!amountYInActiveBin.isZero()) {
|
|
1679
|
+
wy0 = new Decimal3(activeBin.weight).div(new Decimal3(1).add(p0.mul(amountXInActiveBinDec).div(amountYInActiveBinDec)));
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1682
|
+
let totalWeightX2 = wx0;
|
|
1683
|
+
let totalWeightY2 = wy0;
|
|
1684
|
+
distributions.forEach((element) => {
|
|
1685
|
+
if (element.binId < activeId) {
|
|
1686
|
+
totalWeightY2 = totalWeightY2.add(new Decimal3(element.weight));
|
|
1687
|
+
}
|
|
1688
|
+
if (element.binId > activeId) {
|
|
1689
|
+
const price = getPriceOfBinByBinId(element.binId, binStep);
|
|
1690
|
+
const weighPerPrice = new Decimal3(element.weight).div(price);
|
|
1691
|
+
totalWeightX2 = totalWeightX2.add(weighPerPrice);
|
|
1692
|
+
}
|
|
1693
|
+
});
|
|
1694
|
+
const ky2 = totalWeightY2.isZero() ? new Decimal3(1) : new Decimal3(amountY.toString()).div(totalWeightY2);
|
|
1695
|
+
const amountX2 = ky2.mul(totalWeightX2);
|
|
1696
|
+
return new BN9(amountX2.floor().toString());
|
|
1697
|
+
}
|
|
1698
|
+
let totalWeightX = new Decimal3(0);
|
|
1699
|
+
let totalWeightY = new Decimal3(0);
|
|
1700
|
+
distributions.forEach((element) => {
|
|
1701
|
+
if (element.binId < activeId) {
|
|
1702
|
+
totalWeightY = totalWeightY.add(new Decimal3(element.weight));
|
|
1703
|
+
} else {
|
|
1704
|
+
const price = getPriceOfBinByBinId(element.binId, binStep);
|
|
1705
|
+
const weighPerPrice = new Decimal3(element.weight).div(price);
|
|
1706
|
+
totalWeightX = totalWeightX.add(weighPerPrice);
|
|
1707
|
+
}
|
|
1708
|
+
});
|
|
1709
|
+
const ky = totalWeightY.isZero() ? new Decimal3(1) : new Decimal3(amountY.toString()).div(totalWeightY);
|
|
1710
|
+
const amountX = ky.mul(totalWeightX);
|
|
1711
|
+
return new BN9(amountX.floor().toString());
|
|
1712
|
+
}
|
|
1713
|
+
function toAmountBidSide(activeId, totalAmount, distributions) {
|
|
1714
|
+
const totalWeight = distributions.reduce((sum, el) => {
|
|
1715
|
+
return el.binId > activeId ? sum : sum.add(el.weight);
|
|
1716
|
+
}, new Decimal3(0));
|
|
1717
|
+
if (totalWeight.cmp(new Decimal3(0)) !== 1) {
|
|
1718
|
+
throw Error("Invalid parameteres");
|
|
1719
|
+
}
|
|
1720
|
+
return distributions.map((bin) => {
|
|
1721
|
+
if (bin.binId > activeId) {
|
|
1722
|
+
return {
|
|
1723
|
+
binId: bin.binId,
|
|
1724
|
+
amount: new BN9(0)
|
|
1725
|
+
};
|
|
1726
|
+
}
|
|
1727
|
+
return {
|
|
1728
|
+
binId: bin.binId,
|
|
1729
|
+
amount: new BN9(new Decimal3(totalAmount.toString()).mul(new Decimal3(bin.weight).div(totalWeight)).floor().toString())
|
|
1730
|
+
};
|
|
1731
|
+
});
|
|
1732
|
+
}
|
|
1733
|
+
function toAmountAskSide(activeId, binStep, totalAmount, distributions) {
|
|
1734
|
+
const totalWeight = distributions.reduce((sum, el) => {
|
|
1735
|
+
if (el.binId < activeId) {
|
|
1736
|
+
return sum;
|
|
1737
|
+
}
|
|
1738
|
+
const price = getPriceOfBinByBinId(el.binId, binStep);
|
|
1739
|
+
const weightPerPrice = new Decimal3(el.weight).div(price);
|
|
1740
|
+
return sum.add(weightPerPrice);
|
|
1741
|
+
}, new Decimal3(0));
|
|
1742
|
+
if (totalWeight.cmp(new Decimal3(0)) !== 1) {
|
|
1743
|
+
throw Error("Invalid parameteres");
|
|
1744
|
+
}
|
|
1745
|
+
return distributions.map((bin) => {
|
|
1746
|
+
if (bin.binId < activeId) {
|
|
1747
|
+
return {
|
|
1748
|
+
binId: bin.binId,
|
|
1749
|
+
amount: new BN9(0)
|
|
1750
|
+
};
|
|
1751
|
+
}
|
|
1752
|
+
const price = getPriceOfBinByBinId(bin.binId, binStep);
|
|
1753
|
+
const weightPerPrice = new Decimal3(bin.weight).div(price);
|
|
1754
|
+
return {
|
|
1755
|
+
binId: bin.binId,
|
|
1756
|
+
amount: new BN9(new Decimal3(totalAmount.toString()).mul(weightPerPrice).div(totalWeight).floor().toString())
|
|
1757
|
+
};
|
|
1758
|
+
});
|
|
1759
|
+
}
|
|
1760
|
+
function toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, distributions) {
|
|
1761
|
+
if (activeId > distributions[distributions.length - 1].binId) {
|
|
1762
|
+
const amounts = toAmountBidSide(activeId, amountY, distributions);
|
|
1763
|
+
return amounts.map((bin) => {
|
|
1764
|
+
return {
|
|
1765
|
+
binId: bin.binId,
|
|
1766
|
+
amountX: new BN9(0),
|
|
1767
|
+
amountY: bin.amount
|
|
1768
|
+
};
|
|
1769
|
+
});
|
|
1770
|
+
}
|
|
1771
|
+
if (activeId < distributions[0].binId) {
|
|
1772
|
+
const amounts = toAmountAskSide(activeId, binStep, amountX, distributions);
|
|
1773
|
+
return amounts.map((bin) => {
|
|
1774
|
+
return {
|
|
1775
|
+
binId: bin.binId,
|
|
1776
|
+
amountX: bin.amount,
|
|
1777
|
+
amountY: new BN9(0)
|
|
1778
|
+
};
|
|
1779
|
+
});
|
|
1780
|
+
}
|
|
1781
|
+
const activeBins = distributions.filter((element) => {
|
|
1782
|
+
return element.binId === activeId;
|
|
1783
|
+
});
|
|
1784
|
+
if (activeBins.length === 1) {
|
|
1785
|
+
const p0 = getPriceOfBinByBinId(activeId, binStep);
|
|
1786
|
+
let wx0 = new Decimal3(0);
|
|
1787
|
+
let wy0 = new Decimal3(0);
|
|
1788
|
+
const activeBin = activeBins[0];
|
|
1789
|
+
if (amountXInActiveBin.isZero() && amountYInActiveBin.isZero()) {
|
|
1790
|
+
wx0 = new Decimal3(activeBin.weight).div(p0.mul(new Decimal3(2)));
|
|
1791
|
+
wy0 = new Decimal3(activeBin.weight).div(new Decimal3(2));
|
|
1792
|
+
} else {
|
|
1793
|
+
const amountXInActiveBinDec = new Decimal3(amountXInActiveBin.toString());
|
|
1794
|
+
const amountYInActiveBinDec = new Decimal3(amountYInActiveBin.toString());
|
|
1795
|
+
if (!amountXInActiveBin.isZero()) {
|
|
1796
|
+
wx0 = new Decimal3(activeBin.weight).div(p0.add(amountYInActiveBinDec.div(amountXInActiveBinDec)));
|
|
1797
|
+
}
|
|
1798
|
+
if (!amountYInActiveBin.isZero()) {
|
|
1799
|
+
wy0 = new Decimal3(activeBin.weight).div(new Decimal3(1).add(p0.mul(amountXInActiveBinDec).div(amountYInActiveBinDec)));
|
|
1800
|
+
}
|
|
1801
|
+
}
|
|
1802
|
+
let totalWeightX2 = wx0;
|
|
1803
|
+
let totalWeightY2 = wy0;
|
|
1804
|
+
distributions.forEach((element) => {
|
|
1805
|
+
if (element.binId < activeId) {
|
|
1806
|
+
totalWeightY2 = totalWeightY2.add(new Decimal3(element.weight));
|
|
1807
|
+
}
|
|
1808
|
+
if (element.binId > activeId) {
|
|
1809
|
+
const price = getPriceOfBinByBinId(element.binId, binStep);
|
|
1810
|
+
const weighPerPrice = new Decimal3(element.weight).div(price);
|
|
1811
|
+
totalWeightX2 = totalWeightX2.add(weighPerPrice);
|
|
1812
|
+
}
|
|
1813
|
+
});
|
|
1814
|
+
const kx2 = new Decimal3(amountX.toString()).div(totalWeightX2);
|
|
1815
|
+
const ky2 = new Decimal3(amountY.toString()).div(totalWeightY2);
|
|
1816
|
+
const k2 = kx2.lessThan(ky2) ? kx2 : ky2;
|
|
1817
|
+
return distributions.map((bin) => {
|
|
1818
|
+
if (bin.binId < activeId) {
|
|
1819
|
+
const amount = k2.mul(new Decimal3(bin.weight));
|
|
1820
|
+
return {
|
|
1821
|
+
binId: bin.binId,
|
|
1822
|
+
amountX: new BN9(0),
|
|
1823
|
+
amountY: new BN9(amount.floor().toString())
|
|
1824
|
+
};
|
|
1825
|
+
}
|
|
1826
|
+
if (bin.binId > activeId) {
|
|
1827
|
+
const price = getPriceOfBinByBinId(bin.binId, binStep);
|
|
1828
|
+
const weighPerPrice = new Decimal3(bin.weight).div(price);
|
|
1829
|
+
const amount = k2.mul(weighPerPrice);
|
|
1830
|
+
return {
|
|
1831
|
+
binId: bin.binId,
|
|
1832
|
+
amountX: new BN9(amount.floor().toString()),
|
|
1833
|
+
amountY: new BN9(0)
|
|
1834
|
+
};
|
|
1835
|
+
}
|
|
1836
|
+
const amountXActiveBin = k2.mul(wx0);
|
|
1837
|
+
const amountYActiveBin = k2.mul(wy0);
|
|
1838
|
+
return {
|
|
1839
|
+
binId: bin.binId,
|
|
1840
|
+
amountX: new BN9(amountXActiveBin.floor().toString()),
|
|
1841
|
+
amountY: new BN9(amountYActiveBin.floor().toString())
|
|
1842
|
+
};
|
|
1843
|
+
});
|
|
1844
|
+
}
|
|
1845
|
+
let totalWeightX = new Decimal3(0);
|
|
1846
|
+
let totalWeightY = new Decimal3(0);
|
|
1847
|
+
distributions.forEach((element) => {
|
|
1848
|
+
if (element.binId < activeId) {
|
|
1849
|
+
totalWeightY = totalWeightY.add(new Decimal3(element.weight));
|
|
1850
|
+
} else {
|
|
1851
|
+
const price = getPriceOfBinByBinId(element.binId, binStep);
|
|
1852
|
+
const weighPerPrice = new Decimal3(element.weight).div(price);
|
|
1853
|
+
totalWeightX = totalWeightX.add(weighPerPrice);
|
|
1854
|
+
}
|
|
1855
|
+
});
|
|
1856
|
+
const kx = new Decimal3(amountX.toString()).div(totalWeightX);
|
|
1857
|
+
const ky = new Decimal3(amountY.toString()).div(totalWeightY);
|
|
1858
|
+
const k = kx.lessThan(ky) ? kx : ky;
|
|
1859
|
+
return distributions.map((bin) => {
|
|
1860
|
+
if (bin.binId < activeId) {
|
|
1861
|
+
const amount2 = k.mul(new Decimal3(bin.weight));
|
|
1862
|
+
return {
|
|
1863
|
+
binId: bin.binId,
|
|
1864
|
+
amountX: new BN9(0),
|
|
1865
|
+
amountY: new BN9(amount2.floor().toString())
|
|
1866
|
+
};
|
|
1867
|
+
}
|
|
1868
|
+
const price = getPriceOfBinByBinId(bin.binId, binStep);
|
|
1869
|
+
const weighPerPrice = new Decimal3(bin.weight).div(price);
|
|
1870
|
+
const amount = k.mul(weighPerPrice);
|
|
1871
|
+
return {
|
|
1872
|
+
binId: bin.binId,
|
|
1873
|
+
amountX: new BN9(amount.floor().toString()),
|
|
1874
|
+
amountY: new BN9(0)
|
|
1875
|
+
};
|
|
1876
|
+
});
|
|
1877
|
+
}
|
|
1878
|
+
|
|
1879
|
+
// src/math/dlmmStrategy.ts
|
|
1880
|
+
var StrategyType = /* @__PURE__ */ ((StrategyType2) => {
|
|
1881
|
+
StrategyType2[StrategyType2["Spot"] = 0] = "Spot";
|
|
1882
|
+
StrategyType2[StrategyType2["Curve"] = 1] = "Curve";
|
|
1883
|
+
StrategyType2[StrategyType2["BidAsk"] = 2] = "BidAsk";
|
|
1884
|
+
return StrategyType2;
|
|
1885
|
+
})(StrategyType || {});
|
|
1886
|
+
function toWeightDecendingOrder(minBinId, maxBinId) {
|
|
1887
|
+
const distributions = [];
|
|
1888
|
+
for (let i = minBinId; i <= maxBinId; i++) {
|
|
1889
|
+
distributions.push({
|
|
1890
|
+
binId: i,
|
|
1891
|
+
weight: maxBinId - i + 1
|
|
1892
|
+
});
|
|
1893
|
+
}
|
|
1894
|
+
return distributions;
|
|
1895
|
+
}
|
|
1896
|
+
function toWeightAscendingOrder(minBinId, maxBinId) {
|
|
1897
|
+
const distributions = [];
|
|
1898
|
+
for (let i = minBinId; i <= maxBinId; i++) {
|
|
1899
|
+
distributions.push({
|
|
1900
|
+
binId: i,
|
|
1901
|
+
weight: i - minBinId + 1
|
|
1902
|
+
});
|
|
1903
|
+
}
|
|
1904
|
+
return distributions;
|
|
1905
|
+
}
|
|
1906
|
+
function toWeightSpotBalanced(minBinId, maxBinId) {
|
|
1907
|
+
const distributions = [];
|
|
1908
|
+
for (let i = minBinId; i <= maxBinId; i++) {
|
|
1909
|
+
distributions.push({
|
|
1910
|
+
binId: i,
|
|
1911
|
+
weight: 1
|
|
1912
|
+
});
|
|
1913
|
+
}
|
|
1914
|
+
return distributions;
|
|
1915
|
+
}
|
|
1916
|
+
var DEFAULT_MAX_WEIGHT = 2e3;
|
|
1917
|
+
var DEFAULT_MIN_WEIGHT = 200;
|
|
1918
|
+
function toWeightCurve(minBinId, maxBinId, activeId) {
|
|
1919
|
+
if (activeId < minBinId || activeId > maxBinId) {
|
|
1920
|
+
throw new ClmmpoolsError("Invalid strategy params", "InvalidParams" /* InvalidParams */);
|
|
1921
|
+
}
|
|
1922
|
+
const maxWeight = DEFAULT_MAX_WEIGHT;
|
|
1923
|
+
const minWeight = DEFAULT_MIN_WEIGHT;
|
|
1924
|
+
const diffWeight = maxWeight - minWeight;
|
|
1925
|
+
const diffMinWeight = activeId > minBinId ? Math.floor(diffWeight / (activeId - minBinId)) : 0;
|
|
1926
|
+
const diffMaxWeight = maxBinId > activeId ? Math.floor(diffWeight / (maxBinId - activeId)) : 0;
|
|
1927
|
+
const distributions = [];
|
|
1928
|
+
for (let i = minBinId; i <= maxBinId; i++) {
|
|
1929
|
+
if (i < activeId) {
|
|
1930
|
+
distributions.push({
|
|
1931
|
+
binId: i,
|
|
1932
|
+
weight: maxWeight - (activeId - i) * diffMinWeight
|
|
1933
|
+
});
|
|
1934
|
+
} else if (i > activeId) {
|
|
1935
|
+
distributions.push({
|
|
1936
|
+
binId: i,
|
|
1937
|
+
weight: maxWeight - (i - activeId) * diffMaxWeight
|
|
1938
|
+
});
|
|
1939
|
+
} else {
|
|
1940
|
+
distributions.push({
|
|
1941
|
+
binId: i,
|
|
1942
|
+
weight: maxWeight
|
|
1943
|
+
});
|
|
1944
|
+
}
|
|
1945
|
+
}
|
|
1946
|
+
return distributions;
|
|
1947
|
+
}
|
|
1948
|
+
function toWeightBidAsk(minBinId, maxBinId, activeId) {
|
|
1949
|
+
if (activeId < minBinId || activeId > maxBinId) {
|
|
1950
|
+
throw new ClmmpoolsError("Invalid strategy params", "InvalidParams" /* InvalidParams */);
|
|
1951
|
+
}
|
|
1952
|
+
const maxWeight = DEFAULT_MAX_WEIGHT;
|
|
1953
|
+
const minWeight = DEFAULT_MIN_WEIGHT;
|
|
1954
|
+
const diffWeight = maxWeight - minWeight;
|
|
1955
|
+
const diffMinWeight = activeId > minBinId ? Math.floor(diffWeight / (activeId - minBinId)) : 0;
|
|
1956
|
+
const diffMaxWeight = maxBinId > activeId ? Math.floor(diffWeight / (maxBinId - activeId)) : 0;
|
|
1957
|
+
const distributions = [];
|
|
1958
|
+
for (let i = minBinId; i <= maxBinId; i++) {
|
|
1959
|
+
if (i < activeId) {
|
|
1960
|
+
distributions.push({
|
|
1961
|
+
binId: i,
|
|
1962
|
+
weight: minWeight + (activeId - i) * diffMinWeight
|
|
1963
|
+
});
|
|
1964
|
+
} else if (i > activeId) {
|
|
1965
|
+
distributions.push({
|
|
1966
|
+
binId: i,
|
|
1967
|
+
weight: minWeight + (i - activeId) * diffMaxWeight
|
|
1968
|
+
});
|
|
1969
|
+
} else {
|
|
1970
|
+
distributions.push({
|
|
1971
|
+
binId: i,
|
|
1972
|
+
weight: minWeight
|
|
1973
|
+
});
|
|
1974
|
+
}
|
|
1975
|
+
}
|
|
1976
|
+
return distributions;
|
|
1977
|
+
}
|
|
1978
|
+
function autoFillYByStrategy(activeId, binStep, amountX, amountXInActiveBin, amountYInActiveBin, minBinId, maxBinId, strategyType) {
|
|
1979
|
+
switch (strategyType) {
|
|
1980
|
+
case 0 /* Spot */: {
|
|
1981
|
+
const weights = toWeightSpotBalanced(minBinId, maxBinId);
|
|
1982
|
+
return autoFillYByWeight(activeId, binStep, amountX, amountXInActiveBin, amountYInActiveBin, weights);
|
|
1983
|
+
}
|
|
1984
|
+
case 1 /* Curve */: {
|
|
1985
|
+
const weights = toWeightCurve(minBinId, maxBinId, activeId);
|
|
1986
|
+
return autoFillYByWeight(activeId, binStep, amountX, amountXInActiveBin, amountYInActiveBin, weights);
|
|
1987
|
+
}
|
|
1988
|
+
case 2 /* BidAsk */: {
|
|
1989
|
+
const weights = toWeightBidAsk(minBinId, maxBinId, activeId);
|
|
1990
|
+
return autoFillYByWeight(activeId, binStep, amountX, amountXInActiveBin, amountYInActiveBin, weights);
|
|
1991
|
+
}
|
|
1992
|
+
default:
|
|
1993
|
+
throw new Error(`Unsupported strategy type: ${strategyType}`);
|
|
1994
|
+
}
|
|
1995
|
+
}
|
|
1996
|
+
function autoFillXByStrategy(activeId, binStep, amountY, amountXInActiveBin, amountYInActiveBin, minBinId, maxBinId, strategyType) {
|
|
1997
|
+
switch (strategyType) {
|
|
1998
|
+
case 0 /* Spot */: {
|
|
1999
|
+
const weights = toWeightSpotBalanced(minBinId, maxBinId);
|
|
2000
|
+
return autoFillXByWeight(activeId, binStep, amountY, amountXInActiveBin, amountYInActiveBin, weights);
|
|
2001
|
+
}
|
|
2002
|
+
case 1 /* Curve */: {
|
|
2003
|
+
const weights = toWeightCurve(minBinId, maxBinId, activeId);
|
|
2004
|
+
return autoFillXByWeight(activeId, binStep, amountY, amountXInActiveBin, amountYInActiveBin, weights);
|
|
2005
|
+
}
|
|
2006
|
+
case 2 /* BidAsk */: {
|
|
2007
|
+
const weights = toWeightBidAsk(minBinId, maxBinId, activeId);
|
|
2008
|
+
return autoFillXByWeight(activeId, binStep, amountY, amountXInActiveBin, amountYInActiveBin, weights);
|
|
2009
|
+
}
|
|
2010
|
+
default:
|
|
2011
|
+
throw new Error(`Unsupported strategy type: ${strategyType}`);
|
|
2012
|
+
}
|
|
2013
|
+
}
|
|
2014
|
+
function toAmountsBothSideByStrategy(activeId, binStep, minBinId, maxBinId, amountX, amountY, amountXInActiveBin, amountYInActiveBin, strategyType) {
|
|
2015
|
+
const isSingleSideX = amountY.isZero();
|
|
2016
|
+
switch (strategyType) {
|
|
2017
|
+
case 0 /* Spot */: {
|
|
2018
|
+
if (activeId < minBinId || activeId > maxBinId) {
|
|
2019
|
+
const weights = toWeightSpotBalanced(minBinId, maxBinId);
|
|
2020
|
+
return toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights);
|
|
2021
|
+
}
|
|
2022
|
+
const amountsInBin = [];
|
|
2023
|
+
if (!isSingleSideX) {
|
|
2024
|
+
if (minBinId <= activeId) {
|
|
2025
|
+
const weights = toWeightSpotBalanced(minBinId, activeId);
|
|
2026
|
+
const amounts = toAmountBidSide(activeId, amountY, weights);
|
|
2027
|
+
for (const bin of amounts) {
|
|
2028
|
+
amountsInBin.push({
|
|
2029
|
+
binId: bin.binId,
|
|
2030
|
+
amountX: new BN10(0),
|
|
2031
|
+
amountY: bin.amount
|
|
2032
|
+
});
|
|
2033
|
+
}
|
|
2034
|
+
}
|
|
2035
|
+
if (activeId < maxBinId) {
|
|
2036
|
+
const weights = toWeightSpotBalanced(activeId + 1, maxBinId);
|
|
2037
|
+
const amounts = toAmountAskSide(activeId, binStep, amountX, weights);
|
|
2038
|
+
for (const bin of amounts) {
|
|
2039
|
+
amountsInBin.push({
|
|
2040
|
+
binId: bin.binId,
|
|
2041
|
+
amountX: bin.amount,
|
|
2042
|
+
amountY: new BN10(0)
|
|
2043
|
+
});
|
|
2044
|
+
}
|
|
2045
|
+
}
|
|
2046
|
+
} else {
|
|
2047
|
+
if (minBinId < activeId) {
|
|
2048
|
+
const weights = toWeightSpotBalanced(minBinId, activeId - 1);
|
|
2049
|
+
const amountsIntoBidSide = toAmountBidSide(activeId, amountY, weights);
|
|
2050
|
+
for (const bin of amountsIntoBidSide) {
|
|
2051
|
+
amountsInBin.push({
|
|
2052
|
+
binId: bin.binId,
|
|
2053
|
+
amountX: new BN10(0),
|
|
2054
|
+
amountY: bin.amount
|
|
2055
|
+
});
|
|
2056
|
+
}
|
|
2057
|
+
}
|
|
2058
|
+
if (activeId <= maxBinId) {
|
|
2059
|
+
const weights = toWeightSpotBalanced(activeId, maxBinId);
|
|
2060
|
+
const amountsIntoAskSide = toAmountAskSide(activeId, binStep, amountX, weights);
|
|
2061
|
+
for (const bin of amountsIntoAskSide) {
|
|
2062
|
+
amountsInBin.push({
|
|
2063
|
+
binId: bin.binId,
|
|
2064
|
+
amountX: bin.amount,
|
|
2065
|
+
amountY: new BN10(0)
|
|
2066
|
+
});
|
|
2067
|
+
}
|
|
2068
|
+
}
|
|
2069
|
+
}
|
|
2070
|
+
return amountsInBin;
|
|
2071
|
+
}
|
|
2072
|
+
case 1 /* Curve */: {
|
|
2073
|
+
if (activeId < minBinId) {
|
|
2074
|
+
const weights = toWeightDecendingOrder(minBinId, maxBinId);
|
|
2075
|
+
return toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights);
|
|
2076
|
+
}
|
|
2077
|
+
if (activeId > maxBinId) {
|
|
2078
|
+
const weights = toWeightAscendingOrder(minBinId, maxBinId);
|
|
2079
|
+
return toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights);
|
|
2080
|
+
}
|
|
2081
|
+
const amountsInBin = [];
|
|
2082
|
+
if (!isSingleSideX) {
|
|
2083
|
+
if (minBinId <= activeId) {
|
|
2084
|
+
const weights = toWeightAscendingOrder(minBinId, activeId);
|
|
2085
|
+
const amounts = toAmountBidSide(activeId, amountY, weights);
|
|
2086
|
+
for (const bin of amounts) {
|
|
2087
|
+
amountsInBin.push({
|
|
2088
|
+
binId: bin.binId,
|
|
2089
|
+
amountX: new BN10(0),
|
|
2090
|
+
amountY: bin.amount
|
|
2091
|
+
});
|
|
2092
|
+
}
|
|
2093
|
+
}
|
|
2094
|
+
if (activeId < maxBinId) {
|
|
2095
|
+
const weights = toWeightDecendingOrder(activeId + 1, maxBinId);
|
|
2096
|
+
const amounts = toAmountAskSide(activeId, binStep, amountX, weights);
|
|
2097
|
+
for (const bin of amounts) {
|
|
2098
|
+
amountsInBin.push({
|
|
2099
|
+
binId: bin.binId,
|
|
2100
|
+
amountX: bin.amount,
|
|
2101
|
+
amountY: new BN10(0)
|
|
2102
|
+
});
|
|
2103
|
+
}
|
|
2104
|
+
}
|
|
2105
|
+
} else {
|
|
2106
|
+
if (minBinId < activeId) {
|
|
2107
|
+
const weights = toWeightAscendingOrder(minBinId, activeId - 1);
|
|
2108
|
+
const amountsIntoBidSide = toAmountBidSide(activeId, amountY, weights);
|
|
2109
|
+
for (const bin of amountsIntoBidSide) {
|
|
2110
|
+
amountsInBin.push({
|
|
2111
|
+
binId: bin.binId,
|
|
2112
|
+
amountX: new BN10(0),
|
|
2113
|
+
amountY: bin.amount
|
|
2114
|
+
});
|
|
2115
|
+
}
|
|
2116
|
+
}
|
|
2117
|
+
if (activeId <= maxBinId) {
|
|
2118
|
+
const weights = toWeightDecendingOrder(activeId, maxBinId);
|
|
2119
|
+
const amountsIntoAskSide = toAmountAskSide(activeId, binStep, amountX, weights);
|
|
2120
|
+
for (const bin of amountsIntoAskSide) {
|
|
2121
|
+
amountsInBin.push({
|
|
2122
|
+
binId: bin.binId,
|
|
2123
|
+
amountX: bin.amount,
|
|
2124
|
+
amountY: new BN10(0)
|
|
2125
|
+
});
|
|
2126
|
+
}
|
|
2127
|
+
}
|
|
2128
|
+
}
|
|
2129
|
+
return amountsInBin;
|
|
2130
|
+
}
|
|
2131
|
+
case 2 /* BidAsk */: {
|
|
2132
|
+
if (activeId < minBinId) {
|
|
2133
|
+
const weights = toWeightAscendingOrder(minBinId, maxBinId);
|
|
2134
|
+
return toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights);
|
|
2135
|
+
}
|
|
2136
|
+
if (activeId > maxBinId) {
|
|
2137
|
+
const weights = toWeightDecendingOrder(minBinId, maxBinId);
|
|
2138
|
+
return toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights);
|
|
2139
|
+
}
|
|
2140
|
+
const amountsInBin = [];
|
|
2141
|
+
if (!isSingleSideX) {
|
|
2142
|
+
if (minBinId <= activeId) {
|
|
2143
|
+
const weights = toWeightDecendingOrder(minBinId, activeId);
|
|
2144
|
+
const amounts = toAmountBidSide(activeId, amountY, weights);
|
|
2145
|
+
for (const bin of amounts) {
|
|
2146
|
+
amountsInBin.push({
|
|
2147
|
+
binId: bin.binId,
|
|
2148
|
+
amountX: new BN10(0),
|
|
2149
|
+
amountY: bin.amount
|
|
2150
|
+
});
|
|
2151
|
+
}
|
|
2152
|
+
}
|
|
2153
|
+
if (activeId < maxBinId) {
|
|
2154
|
+
const weights = toWeightAscendingOrder(activeId + 1, maxBinId);
|
|
2155
|
+
const amounts = toAmountAskSide(activeId, binStep, amountX, weights);
|
|
2156
|
+
for (const bin of amounts) {
|
|
2157
|
+
amountsInBin.push({
|
|
2158
|
+
binId: bin.binId,
|
|
2159
|
+
amountX: bin.amount,
|
|
2160
|
+
amountY: new BN10(0)
|
|
2161
|
+
});
|
|
2162
|
+
}
|
|
2163
|
+
}
|
|
2164
|
+
} else {
|
|
2165
|
+
if (minBinId < activeId) {
|
|
2166
|
+
const weights = toWeightDecendingOrder(minBinId, activeId - 1);
|
|
2167
|
+
const amountsIntoBidSide = toAmountBidSide(activeId, amountY, weights);
|
|
2168
|
+
for (const bin of amountsIntoBidSide) {
|
|
2169
|
+
amountsInBin.push({
|
|
2170
|
+
binId: bin.binId,
|
|
2171
|
+
amountX: new BN10(0),
|
|
2172
|
+
amountY: bin.amount
|
|
2173
|
+
});
|
|
2174
|
+
}
|
|
2175
|
+
}
|
|
2176
|
+
if (activeId <= maxBinId) {
|
|
2177
|
+
const weights = toWeightAscendingOrder(activeId, maxBinId);
|
|
2178
|
+
const amountsIntoAskSide = toAmountAskSide(activeId, binStep, amountX, weights);
|
|
2179
|
+
for (const bin of amountsIntoAskSide) {
|
|
2180
|
+
amountsInBin.push({
|
|
2181
|
+
binId: bin.binId,
|
|
2182
|
+
amountX: bin.amount,
|
|
2183
|
+
amountY: new BN10(0)
|
|
2184
|
+
});
|
|
2185
|
+
}
|
|
2186
|
+
}
|
|
2187
|
+
}
|
|
2188
|
+
return amountsInBin;
|
|
2189
|
+
}
|
|
2190
|
+
default:
|
|
2191
|
+
throw new Error(`Unsupported strategy type: ${strategyType}`);
|
|
2192
|
+
}
|
|
2193
|
+
}
|
|
2194
|
+
|
|
2195
|
+
// src/math/LiquidityHelper.ts
|
|
2196
|
+
import Decimal5 from "decimal.js";
|
|
2197
|
+
|
|
2198
|
+
// src/utils/numbers.ts
|
|
2199
|
+
import Decimal4 from "decimal.js";
|
|
2200
|
+
function d(value) {
|
|
2201
|
+
if (Decimal4.isDecimal(value)) {
|
|
2202
|
+
return value;
|
|
2203
|
+
}
|
|
2204
|
+
return new Decimal4(value === void 0 ? 0 : value);
|
|
2205
|
+
}
|
|
2206
|
+
function decimalsMultiplier(decimals) {
|
|
2207
|
+
return d(10).pow(d(decimals).abs());
|
|
2208
|
+
}
|
|
2209
|
+
|
|
2210
|
+
// src/math/LiquidityHelper.ts
|
|
2211
|
+
function withLiquiditySlippage(value, slippage, mode) {
|
|
2212
|
+
return d(value)[mode](d(value).mul(slippage)).toDP(0);
|
|
2213
|
+
}
|
|
2214
|
+
function getLiquidityAndCoinYByCoinX(coinInVal, reserveInSize, reserveOutSize, lpSupply) {
|
|
2215
|
+
if (coinInVal.lessThanOrEqualTo(0)) {
|
|
2216
|
+
throw new ClmmpoolsError("coinInVal is less than zero", "InvalidCoinAmount" /* InvalidCoinAmount */);
|
|
2217
|
+
}
|
|
2218
|
+
if (reserveInSize.lessThanOrEqualTo(0) || reserveOutSize.lessThanOrEqualTo(0)) {
|
|
2219
|
+
return -1;
|
|
2220
|
+
}
|
|
2221
|
+
const coinYAmount = coinInVal.mul(reserveOutSize).div(reserveInSize);
|
|
2222
|
+
const sqrtSupply = lpSupply;
|
|
2223
|
+
const lpX = coinInVal.div(reserveInSize).mul(sqrtSupply);
|
|
2224
|
+
const lpY = coinYAmount.div(reserveOutSize).mul(sqrtSupply);
|
|
2225
|
+
const lpAmount = Decimal5.min(lpX, lpY);
|
|
2226
|
+
return {
|
|
2227
|
+
coinYAmount,
|
|
2228
|
+
lpAmount
|
|
2229
|
+
};
|
|
2230
|
+
}
|
|
2231
|
+
function getCoinXYForLiquidity(liquidity, reserveInSize, reserveOutSize, lpSuply) {
|
|
2232
|
+
if (liquidity.lessThanOrEqualTo(0)) {
|
|
2233
|
+
throw new ClmmpoolsError("liquidity can't be equal or less than zero", "InvalidLiquidityAmount" /* InvalidLiquidityAmount */);
|
|
2234
|
+
}
|
|
2235
|
+
if (reserveInSize.lessThanOrEqualTo(0) || reserveOutSize.lessThanOrEqualTo(0)) {
|
|
2236
|
+
throw new ClmmpoolsError("reserveInSize or reserveOutSize can not be equal or less than zero", "InvalidReserveAmount" /* InvalidReserveAmount */);
|
|
2237
|
+
}
|
|
2238
|
+
const sqrtSupply = lpSuply;
|
|
2239
|
+
const coinXAmount = liquidity.div(sqrtSupply).mul(reserveInSize);
|
|
2240
|
+
const coinYAmount = liquidity.div(sqrtSupply).mul(reserveOutSize);
|
|
2241
|
+
return {
|
|
2242
|
+
coinXAmount,
|
|
2243
|
+
coinYAmount
|
|
2244
|
+
};
|
|
2245
|
+
}
|
|
2246
|
+
|
|
2247
|
+
// src/math/percentage.ts
|
|
2248
|
+
import BN11 from "bn.js";
|
|
1597
2249
|
var Percentage = class {
|
|
1598
2250
|
numerator;
|
|
1599
2251
|
denominator;
|
|
@@ -1621,8 +2273,8 @@ var Percentage = class {
|
|
|
1621
2273
|
* @returns
|
|
1622
2274
|
*/
|
|
1623
2275
|
static fromFraction(numerator, denominator) {
|
|
1624
|
-
const num = typeof numerator === "number" ? new
|
|
1625
|
-
const denom = typeof denominator === "number" ? new
|
|
2276
|
+
const num = typeof numerator === "number" ? new BN11(numerator.toString()) : numerator;
|
|
2277
|
+
const denom = typeof denominator === "number" ? new BN11(denominator.toString()) : denominator;
|
|
1626
2278
|
return new Percentage(num, denom);
|
|
1627
2279
|
}
|
|
1628
2280
|
};
|
|
@@ -1722,7 +2374,7 @@ function adjustForCoinSlippage(tokenAmount, slippage, adjustUp) {
|
|
|
1722
2374
|
}
|
|
1723
2375
|
|
|
1724
2376
|
// src/math/SplitSwap.ts
|
|
1725
|
-
import
|
|
2377
|
+
import BN12 from "bn.js";
|
|
1726
2378
|
var SplitUnit = /* @__PURE__ */ ((SplitUnit2) => {
|
|
1727
2379
|
SplitUnit2[SplitUnit2["FIVE"] = 5] = "FIVE";
|
|
1728
2380
|
SplitUnit2[SplitUnit2["TEN"] = 10] = "TEN";
|
|
@@ -1780,7 +2432,7 @@ function updateSplitSwapResult(maxIndex, currentIndex, splitSwapResult, stepResu
|
|
|
1780
2432
|
return splitSwapResult;
|
|
1781
2433
|
}
|
|
1782
2434
|
function computeSplitSwap(a2b, byAmountIn, amounts, poolData, swapTicks) {
|
|
1783
|
-
let currentLiquidity = new
|
|
2435
|
+
let currentLiquidity = new BN12(poolData.liquidity);
|
|
1784
2436
|
let { currentSqrtPrice } = poolData;
|
|
1785
2437
|
let splitSwapResult = {
|
|
1786
2438
|
amountInArray: [],
|
|
@@ -1843,7 +2495,7 @@ function computeSplitSwap(a2b, byAmountIn, amounts, poolData, swapTicks) {
|
|
|
1843
2495
|
targetSqrtPrice,
|
|
1844
2496
|
currentLiquidity,
|
|
1845
2497
|
remainerAmount,
|
|
1846
|
-
new
|
|
2498
|
+
new BN12(poolData.feeRate),
|
|
1847
2499
|
byAmountIn
|
|
1848
2500
|
);
|
|
1849
2501
|
tempStepResult = stepResult;
|
|
@@ -1855,7 +2507,7 @@ function computeSplitSwap(a2b, byAmountIn, amounts, poolData, swapTicks) {
|
|
|
1855
2507
|
splitSwapResult.amountOutArray[i] = splitSwapResult.amountOutArray[i].add(stepResult.amountOut);
|
|
1856
2508
|
splitSwapResult.feeAmountArray[i] = splitSwapResult.feeAmountArray[i].add(stepResult.feeAmount);
|
|
1857
2509
|
if (stepResult.nextSqrtPrice.eq(tick.sqrtPrice)) {
|
|
1858
|
-
signedLiquidityChange = a2b ? tick.liquidityNet.mul(new
|
|
2510
|
+
signedLiquidityChange = a2b ? tick.liquidityNet.mul(new BN12(-1)) : tick.liquidityNet;
|
|
1859
2511
|
currentLiquidity = signedLiquidityChange.gt(ZERO) ? currentLiquidity.add(signedLiquidityChange) : currentLiquidity.sub(signedLiquidityChange.abs());
|
|
1860
2512
|
currentSqrtPrice = tick.sqrtPrice;
|
|
1861
2513
|
} else {
|
|
@@ -1880,7 +2532,7 @@ function computeSplitSwap(a2b, byAmountIn, amounts, poolData, swapTicks) {
|
|
|
1880
2532
|
break;
|
|
1881
2533
|
}
|
|
1882
2534
|
if (tempStepResult.nextSqrtPrice.eq(tick.sqrtPrice)) {
|
|
1883
|
-
signedLiquidityChange = a2b ? tick.liquidityNet.mul(new
|
|
2535
|
+
signedLiquidityChange = a2b ? tick.liquidityNet.mul(new BN12(-1)) : tick.liquidityNet;
|
|
1884
2536
|
currentLiquidity = signedLiquidityChange.gt(ZERO) ? currentLiquidity.add(signedLiquidityChange) : currentLiquidity.sub(signedLiquidityChange.abs());
|
|
1885
2537
|
currentSqrtPrice = tick.sqrtPrice;
|
|
1886
2538
|
} else {
|
|
@@ -1935,18 +2587,6 @@ var SplitSwap = class {
|
|
|
1935
2587
|
}
|
|
1936
2588
|
};
|
|
1937
2589
|
|
|
1938
|
-
// src/utils/numbers.ts
|
|
1939
|
-
import Decimal3 from "decimal.js";
|
|
1940
|
-
function d(value) {
|
|
1941
|
-
if (Decimal3.isDecimal(value)) {
|
|
1942
|
-
return value;
|
|
1943
|
-
}
|
|
1944
|
-
return new Decimal3(value === void 0 ? 0 : value);
|
|
1945
|
-
}
|
|
1946
|
-
function decimalsMultiplier(decimals) {
|
|
1947
|
-
return d(10).pow(d(decimals).abs());
|
|
1948
|
-
}
|
|
1949
|
-
|
|
1950
2590
|
// src/utils/objects.ts
|
|
1951
2591
|
function getSuiObjectData(resp) {
|
|
1952
2592
|
return resp.data;
|
|
@@ -2100,7 +2740,7 @@ function buildPool(objects) {
|
|
|
2100
2740
|
const rewarders = [];
|
|
2101
2741
|
fields.rewarder_manager.fields.rewarders.forEach((item) => {
|
|
2102
2742
|
const { emissions_per_second } = item.fields;
|
|
2103
|
-
const emissionSeconds = MathUtil.fromX64(new
|
|
2743
|
+
const emissionSeconds = MathUtil.fromX64(new BN13(emissions_per_second));
|
|
2104
2744
|
const emissionsEveryDay = Math.floor(emissionSeconds.toNumber() * 60 * 60 * 24);
|
|
2105
2745
|
rewarders.push({
|
|
2106
2746
|
emissions_per_second,
|
|
@@ -2292,11 +2932,11 @@ function buildTickData(objects) {
|
|
|
2292
2932
|
const possition = {
|
|
2293
2933
|
objectId: getObjectId(objects),
|
|
2294
2934
|
index: asIntN(BigInt(valueItem.index.fields.bits)),
|
|
2295
|
-
sqrtPrice: new
|
|
2296
|
-
liquidityNet: new
|
|
2297
|
-
liquidityGross: new
|
|
2298
|
-
feeGrowthOutsideA: new
|
|
2299
|
-
feeGrowthOutsideB: new
|
|
2935
|
+
sqrtPrice: new BN13(valueItem.sqrt_price),
|
|
2936
|
+
liquidityNet: new BN13(valueItem.liquidity_net.fields.bits),
|
|
2937
|
+
liquidityGross: new BN13(valueItem.liquidity_gross),
|
|
2938
|
+
feeGrowthOutsideA: new BN13(valueItem.fee_growth_outside_a),
|
|
2939
|
+
feeGrowthOutsideB: new BN13(valueItem.fee_growth_outside_b),
|
|
2300
2940
|
rewardersGrowthOutside: valueItem.rewards_growth_outside
|
|
2301
2941
|
};
|
|
2302
2942
|
return possition;
|
|
@@ -2306,11 +2946,11 @@ function buildTickDataByEvent(fields) {
|
|
|
2306
2946
|
throw new ClmmpoolsError(`Invalid tick fields.`, "InvalidTickFields" /* InvalidTickFields */);
|
|
2307
2947
|
}
|
|
2308
2948
|
const index = asIntN(BigInt(fields.index.bits));
|
|
2309
|
-
const sqrtPrice = new
|
|
2310
|
-
const liquidityNet = new
|
|
2311
|
-
const liquidityGross = new
|
|
2312
|
-
const feeGrowthOutsideA = new
|
|
2313
|
-
const feeGrowthOutsideB = new
|
|
2949
|
+
const sqrtPrice = new BN13(fields.sqrt_price);
|
|
2950
|
+
const liquidityNet = new BN13(fields.liquidity_net.bits);
|
|
2951
|
+
const liquidityGross = new BN13(fields.liquidity_gross);
|
|
2952
|
+
const feeGrowthOutsideA = new BN13(fields.fee_growth_outside_a);
|
|
2953
|
+
const feeGrowthOutsideB = new BN13(fields.fee_growth_outside_b);
|
|
2314
2954
|
const rewardersGrowthOutside = fields.rewards_growth_outside || [];
|
|
2315
2955
|
const tick = {
|
|
2316
2956
|
objectId: "",
|
|
@@ -2329,7 +2969,7 @@ function buildClmmPositionName(pool_index, position_index) {
|
|
|
2329
2969
|
}
|
|
2330
2970
|
|
|
2331
2971
|
// src/utils/tick.ts
|
|
2332
|
-
import
|
|
2972
|
+
import BN14 from "bn.js";
|
|
2333
2973
|
var TickUtil = class {
|
|
2334
2974
|
/**
|
|
2335
2975
|
* Get min tick index.
|
|
@@ -2369,22 +3009,22 @@ function getRewardInTickRange(pool, tickLower, tickUpper, tickLowerIndex, tickUp
|
|
|
2369
3009
|
let rewarder_growth_below = growthGlobal[i];
|
|
2370
3010
|
if (tickLower !== null) {
|
|
2371
3011
|
if (pool.current_tick_index < tickLowerIndex) {
|
|
2372
|
-
rewarder_growth_below = growthGlobal[i].sub(new
|
|
3012
|
+
rewarder_growth_below = growthGlobal[i].sub(new BN14(tickLower.rewardersGrowthOutside[i]));
|
|
2373
3013
|
} else {
|
|
2374
3014
|
rewarder_growth_below = tickLower.rewardersGrowthOutside[i];
|
|
2375
3015
|
}
|
|
2376
3016
|
}
|
|
2377
|
-
let rewarder_growth_above = new
|
|
3017
|
+
let rewarder_growth_above = new BN14(0);
|
|
2378
3018
|
if (tickUpper !== null) {
|
|
2379
3019
|
if (pool.current_tick_index >= tickUpperIndex) {
|
|
2380
|
-
rewarder_growth_above = growthGlobal[i].sub(new
|
|
3020
|
+
rewarder_growth_above = growthGlobal[i].sub(new BN14(tickUpper.rewardersGrowthOutside[i]));
|
|
2381
3021
|
} else {
|
|
2382
3022
|
rewarder_growth_above = tickUpper.rewardersGrowthOutside[i];
|
|
2383
3023
|
}
|
|
2384
3024
|
}
|
|
2385
3025
|
const rewGrowthInside = MathUtil.subUnderflowU128(
|
|
2386
|
-
MathUtil.subUnderflowU128(new
|
|
2387
|
-
new
|
|
3026
|
+
MathUtil.subUnderflowU128(new BN14(growthGlobal[i]), new BN14(rewarder_growth_below)),
|
|
3027
|
+
new BN14(rewarder_growth_above)
|
|
2388
3028
|
);
|
|
2389
3029
|
rewarderGrowthInside.push(rewGrowthInside);
|
|
2390
3030
|
}
|
|
@@ -2392,8 +3032,8 @@ function getRewardInTickRange(pool, tickLower, tickUpper, tickLowerIndex, tickUp
|
|
|
2392
3032
|
}
|
|
2393
3033
|
|
|
2394
3034
|
// src/utils/transaction-util.ts
|
|
2395
|
-
import
|
|
2396
|
-
import
|
|
3035
|
+
import BN15 from "bn.js";
|
|
3036
|
+
import Decimal6 from "decimal.js";
|
|
2397
3037
|
import { Transaction } from "@mysten/sui/transactions";
|
|
2398
3038
|
function findAdjustCoin(coinPair) {
|
|
2399
3039
|
const isAdjustCoinA = CoinAssist.isSuiCoin(coinPair.coinTypeA);
|
|
@@ -2401,7 +3041,7 @@ function findAdjustCoin(coinPair) {
|
|
|
2401
3041
|
return { isAdjustCoinA, isAdjustCoinB };
|
|
2402
3042
|
}
|
|
2403
3043
|
function reverSlippageAmount(slippageAmount, slippage) {
|
|
2404
|
-
return
|
|
3044
|
+
return Decimal6.ceil(d(slippageAmount).div(1 + slippage)).toString();
|
|
2405
3045
|
}
|
|
2406
3046
|
async function printTransaction(tx, isPrint = true) {
|
|
2407
3047
|
console.log(`inputs`, tx.blockData.inputs);
|
|
@@ -2701,7 +3341,7 @@ var _TransactionUtil = class {
|
|
|
2701
3341
|
const liquidityInput = ClmmPoolUtil.estLiquidityAndcoinAmountFromOneAmounts(
|
|
2702
3342
|
Number(params.tick_lower),
|
|
2703
3343
|
Number(params.tick_upper),
|
|
2704
|
-
new
|
|
3344
|
+
new BN15(coinAmount),
|
|
2705
3345
|
params.fix_amount_a,
|
|
2706
3346
|
true,
|
|
2707
3347
|
slippage,
|
|
@@ -2775,12 +3415,12 @@ var _TransactionUtil = class {
|
|
|
2775
3415
|
max_amount_a = params.amount_a;
|
|
2776
3416
|
min_amount_a = params.amount_a;
|
|
2777
3417
|
max_amount_b = params.amount_b;
|
|
2778
|
-
min_amount_b = new
|
|
3418
|
+
min_amount_b = new Decimal6(params.amount_b).div(new Decimal6(1).plus(new Decimal6(params.slippage))).mul(new Decimal6(1).minus(new Decimal6(params.slippage))).toDecimalPlaces(0).toNumber();
|
|
2779
3419
|
} else {
|
|
2780
3420
|
max_amount_b = params.amount_b;
|
|
2781
3421
|
min_amount_b = params.amount_b;
|
|
2782
3422
|
max_amount_a = params.amount_a;
|
|
2783
|
-
min_amount_a = new
|
|
3423
|
+
min_amount_a = new Decimal6(params.amount_a).div(new Decimal6(1).plus(new Decimal6(params.slippage))).mul(new Decimal6(1).minus(new Decimal6(params.slippage))).toDecimalPlaces(0).toNumber();
|
|
2784
3424
|
}
|
|
2785
3425
|
const args = params.is_open ? [
|
|
2786
3426
|
tx.object(clmmConfig.global_config_id),
|
|
@@ -3769,7 +4409,7 @@ var _TransactionUtil = class {
|
|
|
3769
4409
|
const basePath = splitPath.basePaths[i];
|
|
3770
4410
|
a2b.push(basePath.direction);
|
|
3771
4411
|
poolAddress.push(basePath.poolAddress);
|
|
3772
|
-
rawAmountLimit.push(new
|
|
4412
|
+
rawAmountLimit.push(new BN15(basePath.inputAmount.toString()));
|
|
3773
4413
|
if (i === 0) {
|
|
3774
4414
|
coinType.push(basePath.fromCoin, basePath.toCoin);
|
|
3775
4415
|
} else {
|
|
@@ -3777,8 +4417,8 @@ var _TransactionUtil = class {
|
|
|
3777
4417
|
}
|
|
3778
4418
|
}
|
|
3779
4419
|
const onePath = {
|
|
3780
|
-
amountIn: new
|
|
3781
|
-
amountOut: new
|
|
4420
|
+
amountIn: new BN15(splitPath.inputAmount.toString()),
|
|
4421
|
+
amountOut: new BN15(splitPath.outputAmount.toString()),
|
|
3782
4422
|
poolAddress,
|
|
3783
4423
|
a2b,
|
|
3784
4424
|
rawAmountLimit,
|
|
@@ -4135,9 +4775,9 @@ var TxBlock = class {
|
|
|
4135
4775
|
};
|
|
4136
4776
|
|
|
4137
4777
|
// src/utils/deepbook-utils.ts
|
|
4138
|
-
import
|
|
4778
|
+
import BN16 from "bn.js";
|
|
4139
4779
|
import { Transaction as Transaction3 } from "@mysten/sui/transactions";
|
|
4140
|
-
var FLOAT_SCALING = new
|
|
4780
|
+
var FLOAT_SCALING = new BN16(1e9);
|
|
4141
4781
|
var DeepbookUtils = class {
|
|
4142
4782
|
static createAccountCap(senderAddress, sdkOptions, tx, isTransfer = false) {
|
|
4143
4783
|
if (senderAddress.length === 0) {
|
|
@@ -4283,9 +4923,9 @@ var DeepbookUtils = class {
|
|
|
4283
4923
|
static async preSwap(sdk, pool, a2b, amountIn) {
|
|
4284
4924
|
let isExceed = false;
|
|
4285
4925
|
let amountOut = ZERO;
|
|
4286
|
-
let remainAmount = new
|
|
4926
|
+
let remainAmount = new BN16(amountIn);
|
|
4287
4927
|
let feeAmount = ZERO;
|
|
4288
|
-
const initAmountIn = new
|
|
4928
|
+
const initAmountIn = new BN16(amountIn);
|
|
4289
4929
|
if (a2b) {
|
|
4290
4930
|
let bids = await this.getPoolBids(sdk, pool.poolID, pool.baseAsset, pool.quoteAsset);
|
|
4291
4931
|
if (bids === null) {
|
|
@@ -4295,16 +4935,16 @@ var DeepbookUtils = class {
|
|
|
4295
4935
|
return b.price - a.price;
|
|
4296
4936
|
});
|
|
4297
4937
|
for (let i = 0; i < bids.length; i += 1) {
|
|
4298
|
-
const curBidAmount = new
|
|
4299
|
-
const curBidPrice = new
|
|
4300
|
-
const fee = curBidAmount.mul(new
|
|
4938
|
+
const curBidAmount = new BN16(bids[i].quantity);
|
|
4939
|
+
const curBidPrice = new BN16(bids[i].price);
|
|
4940
|
+
const fee = curBidAmount.mul(new BN16(curBidPrice)).mul(new BN16(pool.takerFeeRate)).div(FLOAT_SCALING).div(FLOAT_SCALING);
|
|
4301
4941
|
if (remainAmount.gt(curBidAmount)) {
|
|
4302
4942
|
remainAmount = remainAmount.sub(curBidAmount);
|
|
4303
4943
|
amountOut = amountOut.add(curBidAmount.mul(curBidPrice).div(FLOAT_SCALING).sub(fee));
|
|
4304
4944
|
feeAmount = feeAmount.add(fee);
|
|
4305
4945
|
} else {
|
|
4306
|
-
const curOut = remainAmount.mul(new
|
|
4307
|
-
const curFee = curOut.mul(new
|
|
4946
|
+
const curOut = remainAmount.mul(new BN16(bids[i].price)).div(FLOAT_SCALING);
|
|
4947
|
+
const curFee = curOut.mul(new BN16(pool.takerFeeRate)).div(FLOAT_SCALING);
|
|
4308
4948
|
amountOut = amountOut.add(curOut.sub(curFee));
|
|
4309
4949
|
remainAmount = remainAmount.sub(remainAmount);
|
|
4310
4950
|
feeAmount = feeAmount.add(curFee);
|
|
@@ -4319,15 +4959,15 @@ var DeepbookUtils = class {
|
|
|
4319
4959
|
isExceed = true;
|
|
4320
4960
|
}
|
|
4321
4961
|
for (let i = 0; i < asks.length; i += 1) {
|
|
4322
|
-
const curAskAmount = new
|
|
4323
|
-
const fee = curAskAmount.mul(new
|
|
4962
|
+
const curAskAmount = new BN16(asks[i].price).mul(new BN16(asks[i].quantity)).div(new BN16(1e9));
|
|
4963
|
+
const fee = curAskAmount.mul(new BN16(pool.takerFeeRate)).div(FLOAT_SCALING);
|
|
4324
4964
|
const curAskAmountWithFee = curAskAmount.add(fee);
|
|
4325
4965
|
if (remainAmount.gt(curAskAmount)) {
|
|
4326
|
-
amountOut = amountOut.add(new
|
|
4966
|
+
amountOut = amountOut.add(new BN16(asks[i].quantity));
|
|
4327
4967
|
remainAmount = remainAmount.sub(curAskAmountWithFee);
|
|
4328
4968
|
feeAmount = feeAmount.add(fee);
|
|
4329
4969
|
} else {
|
|
4330
|
-
const splitNums = new
|
|
4970
|
+
const splitNums = new BN16(asks[i].quantity).div(new BN16(pool.lotSize));
|
|
4331
4971
|
const splitAmount = curAskAmountWithFee.div(splitNums);
|
|
4332
4972
|
const swapSplitNum = remainAmount.div(splitAmount);
|
|
4333
4973
|
amountOut = amountOut.add(swapSplitNum.muln(pool.lotSize));
|
|
@@ -5188,7 +5828,7 @@ var PoolModule = class {
|
|
|
5188
5828
|
};
|
|
5189
5829
|
|
|
5190
5830
|
// src/modules/positionModule.ts
|
|
5191
|
-
import
|
|
5831
|
+
import BN17 from "bn.js";
|
|
5192
5832
|
import { Transaction as Transaction5 } from "@mysten/sui/transactions";
|
|
5193
5833
|
import { isValidSuiObjectId } from "@mysten/sui/utils";
|
|
5194
5834
|
var PositionModule = class {
|
|
@@ -5410,8 +6050,8 @@ var PositionModule = class {
|
|
|
5410
6050
|
for (let i = 0; i < valueData.length; i += 1) {
|
|
5411
6051
|
const { parsedJson } = valueData[i];
|
|
5412
6052
|
const posRrewarderResult = {
|
|
5413
|
-
feeOwedA: new
|
|
5414
|
-
feeOwedB: new
|
|
6053
|
+
feeOwedA: new BN17(parsedJson.fee_owned_a),
|
|
6054
|
+
feeOwedB: new BN17(parsedJson.fee_owned_b),
|
|
5415
6055
|
position_id: parsedJson.position_id
|
|
5416
6056
|
};
|
|
5417
6057
|
result.push(posRrewarderResult);
|
|
@@ -5787,7 +6427,7 @@ var PositionModule = class {
|
|
|
5787
6427
|
};
|
|
5788
6428
|
|
|
5789
6429
|
// src/modules/rewarderModule.ts
|
|
5790
|
-
import
|
|
6430
|
+
import BN18 from "bn.js";
|
|
5791
6431
|
import { Transaction as Transaction6 } from "@mysten/sui/transactions";
|
|
5792
6432
|
var RewarderModule = class {
|
|
5793
6433
|
_sdk;
|
|
@@ -5813,7 +6453,7 @@ var RewarderModule = class {
|
|
|
5813
6453
|
}
|
|
5814
6454
|
const emissionsEveryDay = [];
|
|
5815
6455
|
for (const rewarderInfo of rewarderInfos) {
|
|
5816
|
-
const emissionSeconds = MathUtil.fromX64(new
|
|
6456
|
+
const emissionSeconds = MathUtil.fromX64(new BN18(rewarderInfo.emissions_per_second));
|
|
5817
6457
|
emissionsEveryDay.push({
|
|
5818
6458
|
emissions: Math.floor(emissionSeconds.toNumber() * 60 * 60 * 24),
|
|
5819
6459
|
coin_address: rewarderInfo.coinAddress
|
|
@@ -5832,20 +6472,20 @@ var RewarderModule = class {
|
|
|
5832
6472
|
const currentPool = await this.sdk.Pool.getPool(poolID);
|
|
5833
6473
|
const lastTime = currentPool.rewarder_last_updated_time;
|
|
5834
6474
|
currentPool.rewarder_last_updated_time = currentTime.toString();
|
|
5835
|
-
if (Number(currentPool.liquidity) === 0 || currentTime.eq(new
|
|
6475
|
+
if (Number(currentPool.liquidity) === 0 || currentTime.eq(new BN18(lastTime))) {
|
|
5836
6476
|
return currentPool;
|
|
5837
6477
|
}
|
|
5838
|
-
const timeDelta = currentTime.div(new
|
|
6478
|
+
const timeDelta = currentTime.div(new BN18(1e3)).sub(new BN18(lastTime)).add(new BN18(15));
|
|
5839
6479
|
const rewarderInfos = currentPool.rewarder_infos;
|
|
5840
6480
|
for (let i = 0; i < rewarderInfos.length; i += 1) {
|
|
5841
6481
|
const rewarderInfo = rewarderInfos[i];
|
|
5842
6482
|
const rewarderGrowthDelta = MathUtil.checkMulDivFloor(
|
|
5843
6483
|
timeDelta,
|
|
5844
|
-
new
|
|
5845
|
-
new
|
|
6484
|
+
new BN18(rewarderInfo.emissions_per_second),
|
|
6485
|
+
new BN18(currentPool.liquidity),
|
|
5846
6486
|
128
|
|
5847
6487
|
);
|
|
5848
|
-
this.growthGlobal[i] = new
|
|
6488
|
+
this.growthGlobal[i] = new BN18(rewarderInfo.growth_global).add(new BN18(rewarderGrowthDelta));
|
|
5849
6489
|
}
|
|
5850
6490
|
return currentPool;
|
|
5851
6491
|
}
|
|
@@ -5860,7 +6500,7 @@ var RewarderModule = class {
|
|
|
5860
6500
|
*/
|
|
5861
6501
|
async posRewardersAmount(poolID, positionHandle, positionID) {
|
|
5862
6502
|
const currentTime = Date.parse((/* @__PURE__ */ new Date()).toString());
|
|
5863
|
-
const pool = await this.updatePoolRewarder(poolID, new
|
|
6503
|
+
const pool = await this.updatePoolRewarder(poolID, new BN18(currentTime));
|
|
5864
6504
|
const position = await this.sdk.Position.getPositionRewarders(positionHandle, positionID);
|
|
5865
6505
|
if (position === void 0) {
|
|
5866
6506
|
return [];
|
|
@@ -5881,7 +6521,7 @@ var RewarderModule = class {
|
|
|
5881
6521
|
*/
|
|
5882
6522
|
async poolRewardersAmount(accountAddress, poolID) {
|
|
5883
6523
|
const currentTime = Date.parse((/* @__PURE__ */ new Date()).toString());
|
|
5884
|
-
const pool = await this.updatePoolRewarder(poolID, new
|
|
6524
|
+
const pool = await this.updatePoolRewarder(poolID, new BN18(currentTime));
|
|
5885
6525
|
const positions = await this.sdk.Position.getPositionList(accountAddress, [poolID]);
|
|
5886
6526
|
const tickDatas = await this.getPoolLowerAndUpperTicks(pool.ticks_handle, positions);
|
|
5887
6527
|
const rewarderAmount = [ZERO, ZERO, ZERO];
|
|
@@ -5908,38 +6548,38 @@ var RewarderModule = class {
|
|
|
5908
6548
|
const growthInside = [];
|
|
5909
6549
|
const AmountOwed = [];
|
|
5910
6550
|
if (rewardersInside.length > 0) {
|
|
5911
|
-
let growthDelta0 = MathUtil.subUnderflowU128(rewardersInside[0], new
|
|
5912
|
-
if (growthDelta0.gt(new
|
|
6551
|
+
let growthDelta0 = MathUtil.subUnderflowU128(rewardersInside[0], new BN18(position.reward_growth_inside_0));
|
|
6552
|
+
if (growthDelta0.gt(new BN18("3402823669209384634633745948738404"))) {
|
|
5913
6553
|
growthDelta0 = ONE;
|
|
5914
6554
|
}
|
|
5915
|
-
const amountOwed_0 = MathUtil.checkMulShiftRight(new
|
|
6555
|
+
const amountOwed_0 = MathUtil.checkMulShiftRight(new BN18(position.liquidity), growthDelta0, 64, 128);
|
|
5916
6556
|
growthInside.push(rewardersInside[0]);
|
|
5917
6557
|
AmountOwed.push({
|
|
5918
|
-
amount_owed: new
|
|
6558
|
+
amount_owed: new BN18(position.reward_amount_owed_0).add(amountOwed_0),
|
|
5919
6559
|
coin_address: pool.rewarder_infos[0].coinAddress
|
|
5920
6560
|
});
|
|
5921
6561
|
}
|
|
5922
6562
|
if (rewardersInside.length > 1) {
|
|
5923
|
-
let growthDelta_1 = MathUtil.subUnderflowU128(rewardersInside[1], new
|
|
5924
|
-
if (growthDelta_1.gt(new
|
|
6563
|
+
let growthDelta_1 = MathUtil.subUnderflowU128(rewardersInside[1], new BN18(position.reward_growth_inside_1));
|
|
6564
|
+
if (growthDelta_1.gt(new BN18("3402823669209384634633745948738404"))) {
|
|
5925
6565
|
growthDelta_1 = ONE;
|
|
5926
6566
|
}
|
|
5927
|
-
const amountOwed_1 = MathUtil.checkMulShiftRight(new
|
|
6567
|
+
const amountOwed_1 = MathUtil.checkMulShiftRight(new BN18(position.liquidity), growthDelta_1, 64, 128);
|
|
5928
6568
|
growthInside.push(rewardersInside[1]);
|
|
5929
6569
|
AmountOwed.push({
|
|
5930
|
-
amount_owed: new
|
|
6570
|
+
amount_owed: new BN18(position.reward_amount_owed_1).add(amountOwed_1),
|
|
5931
6571
|
coin_address: pool.rewarder_infos[1].coinAddress
|
|
5932
6572
|
});
|
|
5933
6573
|
}
|
|
5934
6574
|
if (rewardersInside.length > 2) {
|
|
5935
|
-
let growthDelta_2 = MathUtil.subUnderflowU128(rewardersInside[2], new
|
|
5936
|
-
if (growthDelta_2.gt(new
|
|
6575
|
+
let growthDelta_2 = MathUtil.subUnderflowU128(rewardersInside[2], new BN18(position.reward_growth_inside_2));
|
|
6576
|
+
if (growthDelta_2.gt(new BN18("3402823669209384634633745948738404"))) {
|
|
5937
6577
|
growthDelta_2 = ONE;
|
|
5938
6578
|
}
|
|
5939
|
-
const amountOwed_2 = MathUtil.checkMulShiftRight(new
|
|
6579
|
+
const amountOwed_2 = MathUtil.checkMulShiftRight(new BN18(position.liquidity), growthDelta_2, 64, 128);
|
|
5940
6580
|
growthInside.push(rewardersInside[2]);
|
|
5941
6581
|
AmountOwed.push({
|
|
5942
|
-
amount_owed: new
|
|
6582
|
+
amount_owed: new BN18(position.reward_amount_owed_2).add(amountOwed_2),
|
|
5943
6583
|
coin_address: pool.rewarder_infos[2].coinAddress
|
|
5944
6584
|
});
|
|
5945
6585
|
}
|
|
@@ -6053,8 +6693,8 @@ var RewarderModule = class {
|
|
|
6053
6693
|
for (let i = 0; i < valueData.length; i += 1) {
|
|
6054
6694
|
const { parsedJson } = valueData[i];
|
|
6055
6695
|
const posRrewarderResult = {
|
|
6056
|
-
feeOwedA: new
|
|
6057
|
-
feeOwedB: new
|
|
6696
|
+
feeOwedA: new BN18(parsedJson.fee_owned_a),
|
|
6697
|
+
feeOwedB: new BN18(parsedJson.fee_owned_b),
|
|
6058
6698
|
position_id: parsedJson.position_id
|
|
6059
6699
|
};
|
|
6060
6700
|
result.push(posRrewarderResult);
|
|
@@ -6117,7 +6757,7 @@ var RewarderModule = class {
|
|
|
6117
6757
|
};
|
|
6118
6758
|
for (let j = 0; j < params[i].rewarderInfo.length; j += 1) {
|
|
6119
6759
|
posRrewarderResult.rewarderAmountOwed.push({
|
|
6120
|
-
amount_owed: new
|
|
6760
|
+
amount_owed: new BN18(valueData[i].parsedJson.data[j]),
|
|
6121
6761
|
coin_address: params[i].rewarderInfo[j].coinAddress
|
|
6122
6762
|
});
|
|
6123
6763
|
}
|
|
@@ -6306,7 +6946,7 @@ var RewarderModule = class {
|
|
|
6306
6946
|
};
|
|
6307
6947
|
|
|
6308
6948
|
// src/modules/routerModule.ts
|
|
6309
|
-
import
|
|
6949
|
+
import BN19 from "bn.js";
|
|
6310
6950
|
import { Graph, GraphEdge, GraphVertex } from "@syntsugar/cc-graph";
|
|
6311
6951
|
import { Transaction as Transaction7 } from "@mysten/sui/transactions";
|
|
6312
6952
|
function _pairSymbol(base, quote) {
|
|
@@ -6588,8 +7228,8 @@ var RouterModule = class {
|
|
|
6588
7228
|
if (swapWithMultiPoolParams != null) {
|
|
6589
7229
|
const preSwapResult2 = await this.sdk.Swap.preSwapWithMultiPool(swapWithMultiPoolParams);
|
|
6590
7230
|
const onePath2 = {
|
|
6591
|
-
amountIn: new
|
|
6592
|
-
amountOut: new
|
|
7231
|
+
amountIn: new BN19(preSwapResult2.estimatedAmountIn),
|
|
7232
|
+
amountOut: new BN19(preSwapResult2.estimatedAmountOut),
|
|
6593
7233
|
poolAddress: [preSwapResult2.poolAddress],
|
|
6594
7234
|
a2b: [preSwapResult2.aToB],
|
|
6595
7235
|
rawAmountLimit: byAmountIn ? [preSwapResult2.estimatedAmountOut] : [preSwapResult2.estimatedAmountIn],
|
|
@@ -6602,8 +7242,8 @@ var RouterModule = class {
|
|
|
6602
7242
|
priceSlippagePoint
|
|
6603
7243
|
};
|
|
6604
7244
|
const result2 = {
|
|
6605
|
-
amountIn: new
|
|
6606
|
-
amountOut: new
|
|
7245
|
+
amountIn: new BN19(preSwapResult2.estimatedAmountIn),
|
|
7246
|
+
amountOut: new BN19(preSwapResult2.estimatedAmountOut),
|
|
6607
7247
|
paths: [onePath2],
|
|
6608
7248
|
a2b: preSwapResult2.aToB,
|
|
6609
7249
|
b2c: void 0,
|
|
@@ -6625,8 +7265,8 @@ var RouterModule = class {
|
|
|
6625
7265
|
if (swapWithMultiPoolParams != null) {
|
|
6626
7266
|
const preSwapResult2 = await this.sdk.Swap.preSwapWithMultiPool(swapWithMultiPoolParams);
|
|
6627
7267
|
const onePath2 = {
|
|
6628
|
-
amountIn: new
|
|
6629
|
-
amountOut: new
|
|
7268
|
+
amountIn: new BN19(preSwapResult2.estimatedAmountIn),
|
|
7269
|
+
amountOut: new BN19(preSwapResult2.estimatedAmountOut),
|
|
6630
7270
|
poolAddress: [preSwapResult2.poolAddress],
|
|
6631
7271
|
a2b: [preSwapResult2.aToB],
|
|
6632
7272
|
rawAmountLimit: byAmountIn ? [preSwapResult2.estimatedAmountOut] : [preSwapResult2.estimatedAmountIn],
|
|
@@ -6639,8 +7279,8 @@ var RouterModule = class {
|
|
|
6639
7279
|
priceSlippagePoint
|
|
6640
7280
|
};
|
|
6641
7281
|
const result3 = {
|
|
6642
|
-
amountIn: new
|
|
6643
|
-
amountOut: new
|
|
7282
|
+
amountIn: new BN19(preSwapResult2.estimatedAmountIn),
|
|
7283
|
+
amountOut: new BN19(preSwapResult2.estimatedAmountOut),
|
|
6644
7284
|
paths: [onePath2],
|
|
6645
7285
|
a2b: preSwapResult2.aToB,
|
|
6646
7286
|
b2c: void 0,
|
|
@@ -6721,8 +7361,8 @@ var RouterModule = class {
|
|
|
6721
7361
|
if (swapWithMultiPoolParams != null) {
|
|
6722
7362
|
const preSwapResult = await this.sdk.Swap.preSwapWithMultiPool(swapWithMultiPoolParams);
|
|
6723
7363
|
const onePath = {
|
|
6724
|
-
amountIn: new
|
|
6725
|
-
amountOut: new
|
|
7364
|
+
amountIn: new BN19(preSwapResult.estimatedAmountIn),
|
|
7365
|
+
amountOut: new BN19(preSwapResult.estimatedAmountOut),
|
|
6726
7366
|
poolAddress: [preSwapResult.poolAddress],
|
|
6727
7367
|
a2b: [preSwapResult.aToB],
|
|
6728
7368
|
rawAmountLimit: byAmountIn ? [preSwapResult.estimatedAmountOut] : [preSwapResult.estimatedAmountIn],
|
|
@@ -6735,8 +7375,8 @@ var RouterModule = class {
|
|
|
6735
7375
|
priceSlippagePoint
|
|
6736
7376
|
};
|
|
6737
7377
|
const result = {
|
|
6738
|
-
amountIn: new
|
|
6739
|
-
amountOut: new
|
|
7378
|
+
amountIn: new BN19(preSwapResult.estimatedAmountIn),
|
|
7379
|
+
amountOut: new BN19(preSwapResult.estimatedAmountOut),
|
|
6740
7380
|
paths: [onePath],
|
|
6741
7381
|
a2b: preSwapResult.aToB,
|
|
6742
7382
|
b2c: void 0,
|
|
@@ -6820,13 +7460,13 @@ var RouterModule = class {
|
|
|
6820
7460
|
continue;
|
|
6821
7461
|
}
|
|
6822
7462
|
if (params[0].byAmountIn) {
|
|
6823
|
-
const amount = new
|
|
7463
|
+
const amount = new BN19(valueData[i].parsedJson.data.amount_out);
|
|
6824
7464
|
if (amount.gt(tempMaxAmount)) {
|
|
6825
7465
|
tempIndex = i;
|
|
6826
7466
|
tempMaxAmount = amount;
|
|
6827
7467
|
}
|
|
6828
7468
|
} else {
|
|
6829
|
-
const amount = params[i].stepNums > 1 ? new
|
|
7469
|
+
const amount = params[i].stepNums > 1 ? new BN19(valueData[i].parsedJson.data.amount_in) : new BN19(valueData[i].parsedJson.data.amount_in).add(new BN19(valueData[i].parsedJson.data.fee_amount));
|
|
6830
7470
|
if (amount.lt(tempMaxAmount)) {
|
|
6831
7471
|
tempIndex = i;
|
|
6832
7472
|
tempMaxAmount = amount;
|
|
@@ -6896,8 +7536,8 @@ var RouterModule = class {
|
|
|
6896
7536
|
};
|
|
6897
7537
|
|
|
6898
7538
|
// src/modules/swapModule.ts
|
|
6899
|
-
import
|
|
6900
|
-
import
|
|
7539
|
+
import BN20 from "bn.js";
|
|
7540
|
+
import Decimal7 from "decimal.js";
|
|
6901
7541
|
import { Transaction as Transaction8 } from "@mysten/sui/transactions";
|
|
6902
7542
|
var AMM_SWAP_MODULE = "amm_swap";
|
|
6903
7543
|
var POOL_STRUCT = "Pool";
|
|
@@ -6915,14 +7555,14 @@ var SwapModule = class {
|
|
|
6915
7555
|
const pathCount = item.basePaths.length;
|
|
6916
7556
|
if (pathCount > 0) {
|
|
6917
7557
|
const path = item.basePaths[0];
|
|
6918
|
-
const feeRate = path.label === "Magma" ? new
|
|
7558
|
+
const feeRate = path.label === "Magma" ? new Decimal7(path.feeRate).div(10 ** 6) : new Decimal7(path.feeRate).div(10 ** 9);
|
|
6919
7559
|
const feeAmount = d(path.inputAmount).div(10 ** path.fromDecimal).mul(feeRate);
|
|
6920
7560
|
fee = fee.add(feeAmount);
|
|
6921
7561
|
if (pathCount > 1) {
|
|
6922
7562
|
const path2 = item.basePaths[1];
|
|
6923
|
-
const price1 = path.direction ? path.currentPrice : new
|
|
6924
|
-
const price2 = path2.direction ? path2.currentPrice : new
|
|
6925
|
-
const feeRate2 = path2.label === "Magma" ? new
|
|
7563
|
+
const price1 = path.direction ? path.currentPrice : new Decimal7(1).div(path.currentPrice);
|
|
7564
|
+
const price2 = path2.direction ? path2.currentPrice : new Decimal7(1).div(path2.currentPrice);
|
|
7565
|
+
const feeRate2 = path2.label === "Magma" ? new Decimal7(path2.feeRate).div(10 ** 6) : new Decimal7(path2.feeRate).div(10 ** 9);
|
|
6926
7566
|
const feeAmount2 = d(path2.outputAmount).div(10 ** path2.toDecimal).mul(feeRate2);
|
|
6927
7567
|
const fee2 = feeAmount2.div(price1.mul(price2));
|
|
6928
7568
|
fee = fee.add(fee2);
|
|
@@ -6940,17 +7580,17 @@ var SwapModule = class {
|
|
|
6940
7580
|
const outputAmount = d(path.outputAmount).div(10 ** path.toDecimal);
|
|
6941
7581
|
const inputAmount = d(path.inputAmount).div(10 ** path.fromDecimal);
|
|
6942
7582
|
const rate = outputAmount.div(inputAmount);
|
|
6943
|
-
const cprice = path.direction ? new
|
|
7583
|
+
const cprice = path.direction ? new Decimal7(path.currentPrice) : new Decimal7(1).div(path.currentPrice);
|
|
6944
7584
|
impactValue = impactValue.add(this.calculateSingleImpact(rate, cprice));
|
|
6945
7585
|
}
|
|
6946
7586
|
if (pathCount === 2) {
|
|
6947
7587
|
const path = item.basePaths[0];
|
|
6948
7588
|
const path2 = item.basePaths[1];
|
|
6949
|
-
const cprice1 = path.direction ? new
|
|
6950
|
-
const cprice2 = path2.direction ? new
|
|
7589
|
+
const cprice1 = path.direction ? new Decimal7(path.currentPrice) : new Decimal7(1).div(path.currentPrice);
|
|
7590
|
+
const cprice2 = path2.direction ? new Decimal7(path2.currentPrice) : new Decimal7(1).div(path2.currentPrice);
|
|
6951
7591
|
const cprice = cprice1.mul(cprice2);
|
|
6952
|
-
const outputAmount = new
|
|
6953
|
-
const inputAmount = new
|
|
7592
|
+
const outputAmount = new Decimal7(path2.outputAmount).div(10 ** path2.toDecimal);
|
|
7593
|
+
const inputAmount = new Decimal7(path.inputAmount).div(10 ** path.fromDecimal);
|
|
6954
7594
|
const rate = outputAmount.div(inputAmount);
|
|
6955
7595
|
impactValue = impactValue.add(this.calculateSingleImpact(rate, cprice));
|
|
6956
7596
|
}
|
|
@@ -7012,13 +7652,13 @@ var SwapModule = class {
|
|
|
7012
7652
|
continue;
|
|
7013
7653
|
}
|
|
7014
7654
|
if (params.byAmountIn) {
|
|
7015
|
-
const amount = new
|
|
7655
|
+
const amount = new BN20(valueData[i].parsedJson.data.amount_out);
|
|
7016
7656
|
if (amount.gt(tempMaxAmount)) {
|
|
7017
7657
|
tempIndex = i;
|
|
7018
7658
|
tempMaxAmount = amount;
|
|
7019
7659
|
}
|
|
7020
7660
|
} else {
|
|
7021
|
-
const amount = new
|
|
7661
|
+
const amount = new BN20(valueData[i].parsedJson.data.amount_out);
|
|
7022
7662
|
if (amount.lt(tempMaxAmount)) {
|
|
7023
7663
|
tempIndex = i;
|
|
7024
7664
|
tempMaxAmount = amount;
|
|
@@ -7082,7 +7722,7 @@ var SwapModule = class {
|
|
|
7082
7722
|
return this.transformSwapData(params, valueData[0].parsedJson.data);
|
|
7083
7723
|
}
|
|
7084
7724
|
transformSwapData(params, data) {
|
|
7085
|
-
const estimatedAmountIn = data.amount_in && data.fee_amount ? new
|
|
7725
|
+
const estimatedAmountIn = data.amount_in && data.fee_amount ? new BN20(data.amount_in).add(new BN20(data.fee_amount)).toString() : "";
|
|
7086
7726
|
return {
|
|
7087
7727
|
poolAddress: params.pool.poolAddress,
|
|
7088
7728
|
currentSqrtPrice: params.currentSqrtPrice,
|
|
@@ -7099,7 +7739,7 @@ var SwapModule = class {
|
|
|
7099
7739
|
transformSwapWithMultiPoolData(params, jsonData) {
|
|
7100
7740
|
const { data } = jsonData;
|
|
7101
7741
|
console.log("json data. ", data);
|
|
7102
|
-
const estimatedAmountIn = data.amount_in && data.fee_amount ? new
|
|
7742
|
+
const estimatedAmountIn = data.amount_in && data.fee_amount ? new BN20(data.amount_in).add(new BN20(data.fee_amount)).toString() : "";
|
|
7103
7743
|
return {
|
|
7104
7744
|
poolAddress: params.poolAddress,
|
|
7105
7745
|
estimatedAmountIn,
|
|
@@ -8612,8 +9252,8 @@ var TokenModule = class {
|
|
|
8612
9252
|
};
|
|
8613
9253
|
|
|
8614
9254
|
// src/modules/routerModuleV2.ts
|
|
8615
|
-
import
|
|
8616
|
-
import
|
|
9255
|
+
import BN21 from "bn.js";
|
|
9256
|
+
import Decimal8 from "decimal.js";
|
|
8617
9257
|
import { v4 as uuidv4 } from "uuid";
|
|
8618
9258
|
import axios from "axios";
|
|
8619
9259
|
var RouterModuleV2 = class {
|
|
@@ -8630,7 +9270,7 @@ var RouterModuleV2 = class {
|
|
|
8630
9270
|
if (label === "Magma") {
|
|
8631
9271
|
return TickMath.sqrtPriceX64ToPrice(currentSqrtPrice, decimalA, decimalB);
|
|
8632
9272
|
}
|
|
8633
|
-
return new
|
|
9273
|
+
return new Decimal8(currentSqrtPrice.toString()).div(new Decimal8(10).pow(new Decimal8(decimalB + 9 - decimalA)));
|
|
8634
9274
|
}
|
|
8635
9275
|
parseJsonResult(data) {
|
|
8636
9276
|
const result = {
|
|
@@ -8656,12 +9296,12 @@ var RouterModuleV2 = class {
|
|
|
8656
9296
|
outputAmount: basePath.output_amount,
|
|
8657
9297
|
inputAmount: basePath.input_amount,
|
|
8658
9298
|
feeRate: basePath.fee_rate,
|
|
8659
|
-
currentSqrtPrice: new
|
|
8660
|
-
afterSqrtPrice: basePath.label === "Magma" ? new
|
|
9299
|
+
currentSqrtPrice: new BN21(basePath.current_sqrt_price.toString()),
|
|
9300
|
+
afterSqrtPrice: basePath.label === "Magma" ? new BN21(basePath.after_sqrt_price.toString()) : ZERO,
|
|
8661
9301
|
fromDecimal: basePath.from_decimal,
|
|
8662
9302
|
toDecimal: basePath.to_decimal,
|
|
8663
9303
|
currentPrice: this.calculatePrice(
|
|
8664
|
-
new
|
|
9304
|
+
new BN21(basePath.current_sqrt_price.toString()),
|
|
8665
9305
|
basePath.from_decimal,
|
|
8666
9306
|
basePath.to_decimal,
|
|
8667
9307
|
basePath.direction,
|
|
@@ -8744,7 +9384,7 @@ var RouterModuleV2 = class {
|
|
|
8744
9384
|
const priceResult = await this.sdk.Router.priceUseV1(
|
|
8745
9385
|
from,
|
|
8746
9386
|
to,
|
|
8747
|
-
new
|
|
9387
|
+
new BN21(amount),
|
|
8748
9388
|
byAmountIn,
|
|
8749
9389
|
priceSplitPoint,
|
|
8750
9390
|
partner,
|
|
@@ -8756,7 +9396,7 @@ var RouterModuleV2 = class {
|
|
|
8756
9396
|
if (path.poolAddress.length > 1) {
|
|
8757
9397
|
const fromDecimal0 = this.sdk.Router.tokenInfo(path.coinType[0]).decimals;
|
|
8758
9398
|
const toDecimal0 = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
|
|
8759
|
-
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new
|
|
9399
|
+
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new BN21(priceResult.currentSqrtPrice[0]), fromDecimal0, toDecimal0) : TickMath.sqrtPriceX64ToPrice(new BN21(priceResult.currentSqrtPrice[0]), toDecimal0, fromDecimal0);
|
|
8760
9400
|
const path0 = {
|
|
8761
9401
|
direction: path.a2b[0],
|
|
8762
9402
|
label: "Magma",
|
|
@@ -8773,7 +9413,7 @@ var RouterModuleV2 = class {
|
|
|
8773
9413
|
};
|
|
8774
9414
|
const fromDecimal1 = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
|
|
8775
9415
|
const toDecimal1 = this.sdk.Router.tokenInfo(path.coinType[2]).decimals;
|
|
8776
|
-
const currentPrice1 = path.a2b[1] ? TickMath.sqrtPriceX64ToPrice(new
|
|
9416
|
+
const currentPrice1 = path.a2b[1] ? TickMath.sqrtPriceX64ToPrice(new BN21(priceResult.currentSqrtPrice[1]), fromDecimal1, toDecimal1) : TickMath.sqrtPriceX64ToPrice(new BN21(priceResult.currentSqrtPrice[1]), toDecimal1, fromDecimal1);
|
|
8777
9417
|
const path1 = {
|
|
8778
9418
|
direction: path.a2b[1],
|
|
8779
9419
|
label: "Magma",
|
|
@@ -8792,7 +9432,7 @@ var RouterModuleV2 = class {
|
|
|
8792
9432
|
} else {
|
|
8793
9433
|
const fromDecimal = this.sdk.Router.tokenInfo(path.coinType[0]).decimals;
|
|
8794
9434
|
const toDecimal = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
|
|
8795
|
-
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new
|
|
9435
|
+
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new BN21(priceResult.currentSqrtPrice[0]), fromDecimal, toDecimal) : TickMath.sqrtPriceX64ToPrice(new BN21(priceResult.currentSqrtPrice[0]), toDecimal, fromDecimal);
|
|
8796
9436
|
const path0 = {
|
|
8797
9437
|
direction: path.a2b[0],
|
|
8798
9438
|
label: "Magma",
|
|
@@ -8877,7 +9517,7 @@ var RouterModuleV2 = class {
|
|
|
8877
9517
|
const priceResult = await this.sdk.Router.priceUseV1(
|
|
8878
9518
|
from,
|
|
8879
9519
|
to,
|
|
8880
|
-
new
|
|
9520
|
+
new BN21(amount),
|
|
8881
9521
|
byAmountIn,
|
|
8882
9522
|
priceSplitPoint,
|
|
8883
9523
|
partner,
|
|
@@ -8889,7 +9529,7 @@ var RouterModuleV2 = class {
|
|
|
8889
9529
|
if (path.poolAddress.length > 1) {
|
|
8890
9530
|
const fromDecimal0 = this.sdk.Router.tokenInfo(path.coinType[0]).decimals;
|
|
8891
9531
|
const toDecimal0 = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
|
|
8892
|
-
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new
|
|
9532
|
+
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new BN21(priceResult.currentSqrtPrice[0]), fromDecimal0, toDecimal0) : TickMath.sqrtPriceX64ToPrice(new BN21(priceResult.currentSqrtPrice[0]), toDecimal0, fromDecimal0);
|
|
8893
9533
|
const path0 = {
|
|
8894
9534
|
direction: path.a2b[0],
|
|
8895
9535
|
label: "Magma",
|
|
@@ -8906,7 +9546,7 @@ var RouterModuleV2 = class {
|
|
|
8906
9546
|
};
|
|
8907
9547
|
const fromDecimal1 = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
|
|
8908
9548
|
const toDecimal1 = this.sdk.Router.tokenInfo(path.coinType[2]).decimals;
|
|
8909
|
-
const currentPrice1 = path.a2b[1] ? TickMath.sqrtPriceX64ToPrice(new
|
|
9549
|
+
const currentPrice1 = path.a2b[1] ? TickMath.sqrtPriceX64ToPrice(new BN21(priceResult.currentSqrtPrice[1]), fromDecimal1, toDecimal1) : TickMath.sqrtPriceX64ToPrice(new BN21(priceResult.currentSqrtPrice[1]), toDecimal1, fromDecimal1);
|
|
8910
9550
|
const path1 = {
|
|
8911
9551
|
direction: path.a2b[1],
|
|
8912
9552
|
label: "Magma",
|
|
@@ -8925,7 +9565,7 @@ var RouterModuleV2 = class {
|
|
|
8925
9565
|
} else {
|
|
8926
9566
|
const fromDecimal = this.sdk.Router.tokenInfo(path.coinType[0]).decimals;
|
|
8927
9567
|
const toDecimal = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
|
|
8928
|
-
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new
|
|
9568
|
+
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new BN21(priceResult.currentSqrtPrice[0]), fromDecimal, toDecimal) : TickMath.sqrtPriceX64ToPrice(new BN21(priceResult.currentSqrtPrice[0]), toDecimal, fromDecimal);
|
|
8929
9569
|
const path0 = {
|
|
8930
9570
|
direction: path.a2b[0],
|
|
8931
9571
|
label: "Magma",
|
|
@@ -9815,6 +10455,20 @@ var GaugeModule = class {
|
|
|
9815
10455
|
});
|
|
9816
10456
|
return tx;
|
|
9817
10457
|
}
|
|
10458
|
+
async testTeacherCap() {
|
|
10459
|
+
const tx = new Transaction11();
|
|
10460
|
+
tx.moveCall({
|
|
10461
|
+
target: `0xd1bf0385f6d298d3b6f140869c28700e85709d570984200cd82c8164401c5e49::hello_world::call_func1`,
|
|
10462
|
+
arguments: [tx.object("0xe1af009a9212aa4bf936ff51794d39e8a75dfbd8e65e3265d3a8e93b4c9256bf")],
|
|
10463
|
+
typeArguments: []
|
|
10464
|
+
});
|
|
10465
|
+
tx.moveCall({
|
|
10466
|
+
target: `0xd1bf0385f6d298d3b6f140869c28700e85709d570984200cd82c8164401c5e49::hello_world::call_func2`,
|
|
10467
|
+
arguments: [tx.object("0xe1af009a9212aa4bf936ff51794d39e8a75dfbd8e65e3265d3a8e93b4c9256bf")],
|
|
10468
|
+
typeArguments: []
|
|
10469
|
+
});
|
|
10470
|
+
return tx;
|
|
10471
|
+
}
|
|
9818
10472
|
async getEpochRewardByPool(pool, incentive_tokens) {
|
|
9819
10473
|
const tx = new Transaction11();
|
|
9820
10474
|
const { integrate, simulationAccount } = this.sdk.sdkOptions;
|
|
@@ -9849,7 +10503,7 @@ var GaugeModule = class {
|
|
|
9849
10503
|
|
|
9850
10504
|
// src/modules/dlmm.ts
|
|
9851
10505
|
import { Transaction as Transaction12 } from "@mysten/sui/transactions";
|
|
9852
|
-
import
|
|
10506
|
+
import Decimal9 from "decimal.js";
|
|
9853
10507
|
import { get_real_id_from_price, get_storage_id_from_real_id } from "@magmaprotocol/calc_dlmm";
|
|
9854
10508
|
var DlmmModule = class {
|
|
9855
10509
|
_sdk;
|
|
@@ -9922,9 +10576,9 @@ var DlmmModule = class {
|
|
|
9922
10576
|
}
|
|
9923
10577
|
// params price: input (b/(10^b_decimal))/(a/(10^a_decimal))
|
|
9924
10578
|
price_to_storage_id(price, bin_step, tokenADecimal, tokenBDecimal) {
|
|
9925
|
-
const priceDec = new
|
|
9926
|
-
const tenDec = new
|
|
9927
|
-
const twoDec = new
|
|
10579
|
+
const priceDec = new Decimal9(price);
|
|
10580
|
+
const tenDec = new Decimal9(10);
|
|
10581
|
+
const twoDec = new Decimal9(2);
|
|
9928
10582
|
const price_x128 = priceDec.mul(tenDec.pow(tokenBDecimal)).div(tenDec.pow(tokenADecimal)).mul(twoDec.pow(128));
|
|
9929
10583
|
const active_id = get_real_id_from_price(price_x128.toFixed(0).toString(), bin_step);
|
|
9930
10584
|
return get_storage_id_from_real_id(active_id);
|
|
@@ -10008,6 +10662,153 @@ var DlmmModule = class {
|
|
|
10008
10662
|
});
|
|
10009
10663
|
return tx;
|
|
10010
10664
|
}
|
|
10665
|
+
async addLiquidity(params) {
|
|
10666
|
+
if (params.rewards_token.length === 0) {
|
|
10667
|
+
return this._raisePositionByAmounts(params);
|
|
10668
|
+
}
|
|
10669
|
+
return this._raisePositionByAmountsReward(params);
|
|
10670
|
+
}
|
|
10671
|
+
async _raisePositionByAmounts(params) {
|
|
10672
|
+
const tx = new Transaction12();
|
|
10673
|
+
tx.setSender(this.sdk.senderAddress);
|
|
10674
|
+
const { dlmm_pool, integrate } = this.sdk.sdkOptions;
|
|
10675
|
+
const dlmmConfig = getPackagerConfigs(dlmm_pool);
|
|
10676
|
+
const typeArguments = [params.coin_a, params.coin_b];
|
|
10677
|
+
const allCoins = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress);
|
|
10678
|
+
const amountATotal = params.amounts_a.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
|
|
10679
|
+
const amountBTotal = params.amounts_b.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
|
|
10680
|
+
const primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amountATotal), params.coin_a, false, true);
|
|
10681
|
+
const primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amountBTotal), params.coin_b, false, true);
|
|
10682
|
+
const args = [
|
|
10683
|
+
tx.object(params.pool_id),
|
|
10684
|
+
tx.object(dlmmConfig.factory),
|
|
10685
|
+
tx.object(params.position_id),
|
|
10686
|
+
primaryCoinAInputs.targetCoin,
|
|
10687
|
+
primaryCoinBInputs.targetCoin,
|
|
10688
|
+
tx.pure.vector("u64", params.amounts_a),
|
|
10689
|
+
tx.pure.vector("u64", params.amounts_b),
|
|
10690
|
+
tx.pure.address(params.receiver),
|
|
10691
|
+
tx.object(CLOCK_ADDRESS)
|
|
10692
|
+
];
|
|
10693
|
+
tx.moveCall({
|
|
10694
|
+
target: `${integrate.published_at}::${DlmmScript}::raise_position_by_amounts`,
|
|
10695
|
+
typeArguments,
|
|
10696
|
+
arguments: args
|
|
10697
|
+
});
|
|
10698
|
+
return tx;
|
|
10699
|
+
}
|
|
10700
|
+
async _raisePositionByAmountsReward(params) {
|
|
10701
|
+
const tx = new Transaction12();
|
|
10702
|
+
tx.setSender(this.sdk.senderAddress);
|
|
10703
|
+
const { dlmm_pool, integrate, clmm_pool } = this.sdk.sdkOptions;
|
|
10704
|
+
const dlmmConfig = getPackagerConfigs(dlmm_pool);
|
|
10705
|
+
const clmmConfigs = getPackagerConfigs(clmm_pool);
|
|
10706
|
+
const typeArguments = [params.coin_a, params.coin_b, ...params.rewards_token];
|
|
10707
|
+
const allCoins = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress);
|
|
10708
|
+
const amountATotal = params.amounts_a.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
|
|
10709
|
+
const amountBTotal = params.amounts_b.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
|
|
10710
|
+
const primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amountATotal), params.coin_a, false, true);
|
|
10711
|
+
const primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amountBTotal), params.coin_b, false, true);
|
|
10712
|
+
const args = [
|
|
10713
|
+
tx.object(params.pool_id),
|
|
10714
|
+
tx.object(dlmmConfig.factory),
|
|
10715
|
+
tx.object(clmmConfigs.global_vault_id),
|
|
10716
|
+
tx.object(params.position_id),
|
|
10717
|
+
primaryCoinAInputs.targetCoin,
|
|
10718
|
+
primaryCoinBInputs.targetCoin,
|
|
10719
|
+
tx.pure.vector("u64", params.amounts_a),
|
|
10720
|
+
tx.pure.vector("u64", params.amounts_b),
|
|
10721
|
+
tx.pure.address(params.receiver),
|
|
10722
|
+
tx.object(CLOCK_ADDRESS)
|
|
10723
|
+
];
|
|
10724
|
+
tx.moveCall({
|
|
10725
|
+
target: `${integrate.published_at}::${DlmmScript}::raise_position_by_amounts_reward${params.rewards_token.length}`,
|
|
10726
|
+
typeArguments,
|
|
10727
|
+
arguments: args
|
|
10728
|
+
});
|
|
10729
|
+
return tx;
|
|
10730
|
+
}
|
|
10731
|
+
async burnPosition(params) {
|
|
10732
|
+
const tx = new Transaction12();
|
|
10733
|
+
tx.setSender(this.sdk.senderAddress);
|
|
10734
|
+
const { integrate, clmm_pool } = this.sdk.sdkOptions;
|
|
10735
|
+
const clmmConfigs = getPackagerConfigs(clmm_pool);
|
|
10736
|
+
const typeArguments = [params.coin_a, params.coin_b, ...params.rewards_token];
|
|
10737
|
+
let args = [tx.object(params.pool_id), tx.object(params.position_id), tx.object(CLOCK_ADDRESS)];
|
|
10738
|
+
let target = `${integrate.published_at}::${DlmmScript}::burn_position`;
|
|
10739
|
+
if (params.rewards_token.length > 0) {
|
|
10740
|
+
args = [tx.object(params.pool_id), tx.object(clmmConfigs.global_vault_id), tx.object(params.position_id), tx.object(CLOCK_ADDRESS)];
|
|
10741
|
+
target = `${integrate.published_at}::${DlmmScript}::burn_position_reward${params.rewards_token.length}`;
|
|
10742
|
+
}
|
|
10743
|
+
tx.moveCall({
|
|
10744
|
+
target,
|
|
10745
|
+
typeArguments,
|
|
10746
|
+
arguments: args
|
|
10747
|
+
});
|
|
10748
|
+
return tx;
|
|
10749
|
+
}
|
|
10750
|
+
async shrinkPosition(params) {
|
|
10751
|
+
const tx = new Transaction12();
|
|
10752
|
+
tx.setSender(this.sdk.senderAddress);
|
|
10753
|
+
const { integrate, clmm_pool } = this.sdk.sdkOptions;
|
|
10754
|
+
const clmmConfigs = getPackagerConfigs(clmm_pool);
|
|
10755
|
+
const typeArguments = [params.coin_a, params.coin_b, ...params.rewards_token];
|
|
10756
|
+
let args = [tx.object(params.pool_id), tx.object(params.position_id), tx.pure.u64(params.delta_percentage), tx.object(CLOCK_ADDRESS)];
|
|
10757
|
+
let target = `${integrate.published_at}::${DlmmScript}::shrink_position`;
|
|
10758
|
+
if (params.rewards_token.length > 0) {
|
|
10759
|
+
args = [
|
|
10760
|
+
tx.object(params.pool_id),
|
|
10761
|
+
tx.object(clmmConfigs.global_vault_id),
|
|
10762
|
+
tx.object(params.position_id),
|
|
10763
|
+
tx.pure.u64(params.delta_percentage),
|
|
10764
|
+
tx.object(CLOCK_ADDRESS)
|
|
10765
|
+
];
|
|
10766
|
+
target = `${integrate.published_at}::${DlmmScript}::shrink_position_reward${params.rewards_token.length}`;
|
|
10767
|
+
}
|
|
10768
|
+
tx.moveCall({
|
|
10769
|
+
target,
|
|
10770
|
+
typeArguments,
|
|
10771
|
+
arguments: args
|
|
10772
|
+
});
|
|
10773
|
+
return tx;
|
|
10774
|
+
}
|
|
10775
|
+
async collectReward(params) {
|
|
10776
|
+
const tx = new Transaction12();
|
|
10777
|
+
tx.setSender(this.sdk.senderAddress);
|
|
10778
|
+
const { integrate, clmm_pool } = this.sdk.sdkOptions;
|
|
10779
|
+
const clmmConfigs = getPackagerConfigs(clmm_pool);
|
|
10780
|
+
const typeArguments = [params.coin_a, params.coin_b, ...params.rewards_token];
|
|
10781
|
+
const args = [
|
|
10782
|
+
tx.object(params.pool_id),
|
|
10783
|
+
tx.object(clmmConfigs.global_vault_id),
|
|
10784
|
+
tx.object(params.position_id),
|
|
10785
|
+
tx.object(CLOCK_ADDRESS)
|
|
10786
|
+
];
|
|
10787
|
+
let target = `${integrate.published_at}::${DlmmScript}::collect_reward`;
|
|
10788
|
+
if (params.rewards_token.length > 1) {
|
|
10789
|
+
target = `${integrate.published_at}::${DlmmScript}::collect_reward${params.rewards_token.length}`;
|
|
10790
|
+
}
|
|
10791
|
+
tx.moveCall({
|
|
10792
|
+
target,
|
|
10793
|
+
typeArguments,
|
|
10794
|
+
arguments: args
|
|
10795
|
+
});
|
|
10796
|
+
return tx;
|
|
10797
|
+
}
|
|
10798
|
+
async collectFees(params) {
|
|
10799
|
+
const tx = new Transaction12();
|
|
10800
|
+
tx.setSender(this.sdk.senderAddress);
|
|
10801
|
+
const { integrate } = this.sdk.sdkOptions;
|
|
10802
|
+
const typeArguments = [params.coin_a, params.coin_b];
|
|
10803
|
+
const args = [tx.object(params.pool_id), tx.object(params.position_id), tx.object(CLOCK_ADDRESS)];
|
|
10804
|
+
const target = `${integrate.published_at}::${DlmmScript}::collect_fees`;
|
|
10805
|
+
tx.moveCall({
|
|
10806
|
+
target,
|
|
10807
|
+
typeArguments,
|
|
10808
|
+
arguments: args
|
|
10809
|
+
});
|
|
10810
|
+
return tx;
|
|
10811
|
+
}
|
|
10011
10812
|
async swap(params) {
|
|
10012
10813
|
const tx = new Transaction12();
|
|
10013
10814
|
tx.setSender(this.sdk.senderAddress);
|
|
@@ -10049,9 +10850,11 @@ var DlmmModule = class {
|
|
|
10049
10850
|
if (simulateRes.error != null) {
|
|
10050
10851
|
throw new Error(`fetchBins error code: ${simulateRes.error ?? "unknown error"}`);
|
|
10051
10852
|
}
|
|
10052
|
-
|
|
10853
|
+
let res = [];
|
|
10053
10854
|
simulateRes.events?.forEach((item) => {
|
|
10054
10855
|
if (extractStructTagFromType(item.type).name === `EventFetchBins`) {
|
|
10856
|
+
const { bins } = item.parsedJson;
|
|
10857
|
+
res = bins;
|
|
10055
10858
|
}
|
|
10056
10859
|
});
|
|
10057
10860
|
return res;
|
|
@@ -10089,7 +10892,7 @@ var DlmmModule = class {
|
|
|
10089
10892
|
out.liquidity = item.parsedJson.liquidity;
|
|
10090
10893
|
out.x_equivalent = item.parsedJson.x_equivalent;
|
|
10091
10894
|
out.y_equivalent = item.parsedJson.y_equivalent;
|
|
10092
|
-
out.bin_ids = item.parsedJson.
|
|
10895
|
+
out.bin_ids = item.parsedJson.bin_ids;
|
|
10093
10896
|
out.bin_x_eq = item.parsedJson.bin_x_eq;
|
|
10094
10897
|
out.bin_y_eq = item.parsedJson.bin_y_eq;
|
|
10095
10898
|
out.bin_liquidity = item.parsedJson.bin_liquidity;
|
|
@@ -10136,6 +10939,127 @@ var DlmmModule = class {
|
|
|
10136
10939
|
});
|
|
10137
10940
|
return out;
|
|
10138
10941
|
}
|
|
10942
|
+
async getEarnedFees(params) {
|
|
10943
|
+
const tx = new Transaction12();
|
|
10944
|
+
const { integrate, simulationAccount } = this.sdk.sdkOptions;
|
|
10945
|
+
const typeArguments = [params.coin_a, params.coin_b];
|
|
10946
|
+
const args = [tx.object(params.pool_id), tx.object(params.position_id)];
|
|
10947
|
+
tx.moveCall({
|
|
10948
|
+
target: `${integrate.published_at}::${DlmmScript}::earned_fees`,
|
|
10949
|
+
arguments: args,
|
|
10950
|
+
typeArguments
|
|
10951
|
+
});
|
|
10952
|
+
const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
|
|
10953
|
+
transactionBlock: tx,
|
|
10954
|
+
sender: simulationAccount.address
|
|
10955
|
+
});
|
|
10956
|
+
const out = {
|
|
10957
|
+
position_id: "",
|
|
10958
|
+
x: "",
|
|
10959
|
+
y: "",
|
|
10960
|
+
fee_x: 0,
|
|
10961
|
+
fee_y: 0
|
|
10962
|
+
};
|
|
10963
|
+
if (simulateRes.error != null) {
|
|
10964
|
+
throw new Error(`fetchBins error code: ${simulateRes.error ?? "unknown error"}`);
|
|
10965
|
+
}
|
|
10966
|
+
simulateRes.events?.forEach((item) => {
|
|
10967
|
+
if (extractStructTagFromType(item.type).name === `EventPositionLiquidity`) {
|
|
10968
|
+
out.position_id = item.parsedJson.position_id;
|
|
10969
|
+
out.x = item.parsedJson.x;
|
|
10970
|
+
out.y = item.parsedJson.y;
|
|
10971
|
+
out.fee_x = item.parsedJson.fee_x;
|
|
10972
|
+
out.fee_y = item.parsedJson.fee_y;
|
|
10973
|
+
}
|
|
10974
|
+
});
|
|
10975
|
+
return out;
|
|
10976
|
+
}
|
|
10977
|
+
async getEarnedRewards(params) {
|
|
10978
|
+
const tx = new Transaction12();
|
|
10979
|
+
const { integrate, simulationAccount } = this.sdk.sdkOptions;
|
|
10980
|
+
const typeArguments = [params.coin_a, params.coin_b, ...params.rewards_token];
|
|
10981
|
+
const args = [tx.object(params.pool_id), tx.object(params.position_id)];
|
|
10982
|
+
let target = `${integrate.published_at}::${DlmmScript}::earned_rewards`;
|
|
10983
|
+
if (params.rewards_token.length > 1) {
|
|
10984
|
+
target = `${integrate.published_at}::${DlmmScript}::earned_rewards${params.rewards_token.length}`;
|
|
10985
|
+
}
|
|
10986
|
+
tx.moveCall({
|
|
10987
|
+
target,
|
|
10988
|
+
arguments: args,
|
|
10989
|
+
typeArguments
|
|
10990
|
+
});
|
|
10991
|
+
const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
|
|
10992
|
+
transactionBlock: tx,
|
|
10993
|
+
sender: simulationAccount.address
|
|
10994
|
+
});
|
|
10995
|
+
const out = {
|
|
10996
|
+
position_id: "",
|
|
10997
|
+
reward: [],
|
|
10998
|
+
amount: []
|
|
10999
|
+
};
|
|
11000
|
+
if (simulateRes.error != null) {
|
|
11001
|
+
throw new Error(`fetchBins error code: ${simulateRes.error ?? "unknown error"}`);
|
|
11002
|
+
}
|
|
11003
|
+
simulateRes.events?.forEach((item) => {
|
|
11004
|
+
if (extractStructTagFromType(item.type).name === `DlmmEventEarnedRewards`) {
|
|
11005
|
+
out.position_id = item.parsedJson.position_id;
|
|
11006
|
+
out.reward = [item.parsedJson.reward];
|
|
11007
|
+
out.amount = [item.parsedJson.amount];
|
|
11008
|
+
} else if (extractStructTagFromType(item.type).name === `DlmmEventEarnedRewards2`) {
|
|
11009
|
+
out.position_id = item.parsedJson.position_id;
|
|
11010
|
+
out.reward = [item.parsedJson.reward1, item.parsedJson.reward2];
|
|
11011
|
+
out.amount = [item.parsedJson.amount1, item.parsedJson.amount2];
|
|
11012
|
+
} else if (extractStructTagFromType(item.type).name === `EventEarnedRewards3`) {
|
|
11013
|
+
out.position_id = item.parsedJson.position_id;
|
|
11014
|
+
out.reward = [item.parsedJson.reward1, item.parsedJson.reward2, item.parsedJson.reward3];
|
|
11015
|
+
out.amount = [item.parsedJson.amount1, item.parsedJson.amount2, item.parsedJson.amount3];
|
|
11016
|
+
}
|
|
11017
|
+
});
|
|
11018
|
+
return out;
|
|
11019
|
+
}
|
|
11020
|
+
async getPairRewarders(params) {
|
|
11021
|
+
let tx = new Transaction12();
|
|
11022
|
+
for (const param of params) {
|
|
11023
|
+
tx = await this._getPairRewarders(param, tx);
|
|
11024
|
+
}
|
|
11025
|
+
return this._parsePairRewarders(tx);
|
|
11026
|
+
}
|
|
11027
|
+
async _getPairRewarders(params, tx) {
|
|
11028
|
+
tx = tx || new Transaction12();
|
|
11029
|
+
const { integrate } = this.sdk.sdkOptions;
|
|
11030
|
+
const typeArguments = [params.coin_a, params.coin_b];
|
|
11031
|
+
const args = [tx.object(params.pool_id)];
|
|
11032
|
+
tx.moveCall({
|
|
11033
|
+
target: `${integrate.published_at}::${DlmmScript}::get_pair_rewarders`,
|
|
11034
|
+
arguments: args,
|
|
11035
|
+
typeArguments
|
|
11036
|
+
});
|
|
11037
|
+
return tx;
|
|
11038
|
+
}
|
|
11039
|
+
async _parsePairRewarders(tx) {
|
|
11040
|
+
const { simulationAccount } = this.sdk.sdkOptions;
|
|
11041
|
+
const simulateRes = await this.sdk.fullClient.devInspectTransactionBlock({
|
|
11042
|
+
transactionBlock: tx,
|
|
11043
|
+
sender: simulationAccount.address
|
|
11044
|
+
});
|
|
11045
|
+
const out = /* @__PURE__ */ new Map();
|
|
11046
|
+
if (simulateRes.error != null) {
|
|
11047
|
+
throw new Error(`fetchBins error code: ${simulateRes.error ?? "unknown error"}`);
|
|
11048
|
+
}
|
|
11049
|
+
simulateRes.events?.forEach((item) => {
|
|
11050
|
+
if (extractStructTagFromType(item.type).name === `EventPairRewardTypes`) {
|
|
11051
|
+
const pairRewards = {
|
|
11052
|
+
pair_id: "",
|
|
11053
|
+
tokens: []
|
|
11054
|
+
};
|
|
11055
|
+
pairRewards.pair_id = item.parsedJson.pair_id;
|
|
11056
|
+
item.parsedJson.tokens.contents.forEach((token) => {
|
|
11057
|
+
pairRewards.tokens.push(token.name);
|
|
11058
|
+
});
|
|
11059
|
+
}
|
|
11060
|
+
});
|
|
11061
|
+
return out;
|
|
11062
|
+
}
|
|
10139
11063
|
};
|
|
10140
11064
|
|
|
10141
11065
|
// src/sdk.ts
|
|
@@ -10415,7 +11339,7 @@ var SDKConfig = {
|
|
|
10415
11339
|
clmmConfig: {
|
|
10416
11340
|
pools_id: "0xfa145b9de10fe858be81edd1c6cdffcf27be9d016de02a1345eb1009a68ba8b2",
|
|
10417
11341
|
// clmm and dlmm both use this global_config
|
|
10418
|
-
global_config_id: "
|
|
11342
|
+
global_config_id: "0x4e39044c21fe04e27c67b110dec37807ad439516a1701cf2e0dc842e9e20f1f3",
|
|
10419
11343
|
global_vault_id: "0xa7e1102f222b6eb81ccc8a126e7feb2353342be9df6f6646a77c4519da29c071",
|
|
10420
11344
|
admin_cap_id: "0x89c1a321291d15ddae5a086c9abc533dff697fde3d89e0ca836c41af73e36a75"
|
|
10421
11345
|
},
|
|
@@ -10436,7 +11360,7 @@ var SDKConfig = {
|
|
|
10436
11360
|
minter_id: "0x4fa5766cd83b33b215b139fec27ac344040f3bbd84fcbee7b61fc671aadc51fa"
|
|
10437
11361
|
},
|
|
10438
11362
|
dlmmConfig: {
|
|
10439
|
-
factory: ""
|
|
11363
|
+
factory: "0xb7d4f7281bc604981e2caaa5d2af875b66f9422fcdbf6e310d8ed16b854a5d3e"
|
|
10440
11364
|
},
|
|
10441
11365
|
gaugeConfig: {}
|
|
10442
11366
|
};
|
|
@@ -10456,8 +11380,8 @@ var clmmMainnet = {
|
|
|
10456
11380
|
config: SDKConfig.clmmConfig
|
|
10457
11381
|
},
|
|
10458
11382
|
dlmm_pool: {
|
|
10459
|
-
package_id: "",
|
|
10460
|
-
published_at: "",
|
|
11383
|
+
package_id: "0xb3a44310c59536782d1b5c29d01a066798750ff0c15242a7f3eb7e55d188cfc3",
|
|
11384
|
+
published_at: "0xb3a44310c59536782d1b5c29d01a066798750ff0c15242a7f3eb7e55d188cfc3",
|
|
10461
11385
|
config: SDKConfig.dlmmConfig
|
|
10462
11386
|
},
|
|
10463
11387
|
distribution: {
|
|
@@ -10465,8 +11389,8 @@ var clmmMainnet = {
|
|
|
10465
11389
|
published_at: "0xee4a1f231dc45a303389998fe26c4e39278cf68b404b32e4f0b9769129b8267b"
|
|
10466
11390
|
},
|
|
10467
11391
|
integrate: {
|
|
10468
|
-
package_id: "
|
|
10469
|
-
published_at: "
|
|
11392
|
+
package_id: "0x228638b6ea17788e34971afee4b4580dbc4dcaa847ef62604d858ef5d3beb5a6",
|
|
11393
|
+
published_at: "0x228638b6ea17788e34971afee4b4580dbc4dcaa847ef62604d858ef5d3beb5a6"
|
|
10470
11394
|
},
|
|
10471
11395
|
deepbook: {
|
|
10472
11396
|
package_id: "0x000000000000000000000000000000000000000000000000000000000000dee9",
|
|
@@ -10637,6 +11561,7 @@ export {
|
|
|
10637
11561
|
SUI_SYSTEM_STATE_OBJECT_ID,
|
|
10638
11562
|
SplitSwap,
|
|
10639
11563
|
SplitUnit,
|
|
11564
|
+
StrategyType,
|
|
10640
11565
|
SwapDirection,
|
|
10641
11566
|
SwapModule,
|
|
10642
11567
|
SwapUtils,
|
|
@@ -10658,6 +11583,10 @@ export {
|
|
|
10658
11583
|
adjustForSlippage,
|
|
10659
11584
|
asIntN,
|
|
10660
11585
|
asUintN,
|
|
11586
|
+
autoFillXByStrategy,
|
|
11587
|
+
autoFillXByWeight,
|
|
11588
|
+
autoFillYByStrategy,
|
|
11589
|
+
autoFillYByWeight,
|
|
10661
11590
|
bufferToHex,
|
|
10662
11591
|
buildClmmPositionName,
|
|
10663
11592
|
buildNFT,
|
|
@@ -10696,12 +11625,14 @@ export {
|
|
|
10696
11625
|
getAmountUnfixedDelta,
|
|
10697
11626
|
getCoinAFromLiquidity,
|
|
10698
11627
|
getCoinBFromLiquidity,
|
|
11628
|
+
getCoinXYForLiquidity,
|
|
10699
11629
|
getDefaultSuiInputType,
|
|
10700
11630
|
getDeltaA,
|
|
10701
11631
|
getDeltaB,
|
|
10702
11632
|
getDeltaDownFromOutput,
|
|
10703
11633
|
getDeltaUpFromInput,
|
|
10704
11634
|
getFutureTime,
|
|
11635
|
+
getLiquidityAndCoinYByCoinX,
|
|
10705
11636
|
getLiquidityFromCoinA,
|
|
10706
11637
|
getLiquidityFromCoinB,
|
|
10707
11638
|
getLowerSqrtPriceFromCoinA,
|
|
@@ -10725,6 +11656,7 @@ export {
|
|
|
10725
11656
|
getObjectType,
|
|
10726
11657
|
getObjectVersion,
|
|
10727
11658
|
getPackagerConfigs,
|
|
11659
|
+
getPriceOfBinByBinId,
|
|
10728
11660
|
getRewardInTickRange,
|
|
10729
11661
|
getSuiObjectData,
|
|
10730
11662
|
getTickDataFromUrlData,
|
|
@@ -10748,10 +11680,15 @@ export {
|
|
|
10748
11680
|
shortAddress,
|
|
10749
11681
|
shortString,
|
|
10750
11682
|
tickScore,
|
|
11683
|
+
toAmountAskSide,
|
|
11684
|
+
toAmountBidSide,
|
|
11685
|
+
toAmountBothSide,
|
|
11686
|
+
toAmountsBothSideByStrategy,
|
|
10751
11687
|
toBuffer,
|
|
10752
11688
|
toCoinAmount,
|
|
10753
11689
|
toDecimalsAmount,
|
|
10754
11690
|
transClmmpoolDataWithoutTicks,
|
|
10755
|
-
utf8to16
|
|
11691
|
+
utf8to16,
|
|
11692
|
+
withLiquiditySlippage
|
|
10756
11693
|
};
|
|
10757
11694
|
//# sourceMappingURL=index.mjs.map
|