@magmaprotocol/magma-clmm-sdk 0.5.38 → 0.5.39
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 +1 -117
- package/dist/index.js +140 -806
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +136 -789
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -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";
|
|
@@ -1592,660 +1592,8 @@ function collectFeesQuote(param) {
|
|
|
1592
1592
|
return updateFees(param.position, fee_growth_inside_a, fee_growth_inside_b);
|
|
1593
1593
|
}
|
|
1594
1594
|
|
|
1595
|
-
// src/math/dlmmStrategy.ts
|
|
1596
|
-
import BN10 from "bn.js";
|
|
1597
|
-
|
|
1598
|
-
// src/math/dlmmWeightToAmounts.ts
|
|
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
1595
|
// src/math/percentage.ts
|
|
2248
|
-
import
|
|
1596
|
+
import BN9 from "bn.js";
|
|
2249
1597
|
var Percentage = class {
|
|
2250
1598
|
numerator;
|
|
2251
1599
|
denominator;
|
|
@@ -2273,8 +1621,8 @@ var Percentage = class {
|
|
|
2273
1621
|
* @returns
|
|
2274
1622
|
*/
|
|
2275
1623
|
static fromFraction(numerator, denominator) {
|
|
2276
|
-
const num = typeof numerator === "number" ? new
|
|
2277
|
-
const denom = typeof denominator === "number" ? new
|
|
1624
|
+
const num = typeof numerator === "number" ? new BN9(numerator.toString()) : numerator;
|
|
1625
|
+
const denom = typeof denominator === "number" ? new BN9(denominator.toString()) : denominator;
|
|
2278
1626
|
return new Percentage(num, denom);
|
|
2279
1627
|
}
|
|
2280
1628
|
};
|
|
@@ -2374,7 +1722,7 @@ function adjustForCoinSlippage(tokenAmount, slippage, adjustUp) {
|
|
|
2374
1722
|
}
|
|
2375
1723
|
|
|
2376
1724
|
// src/math/SplitSwap.ts
|
|
2377
|
-
import
|
|
1725
|
+
import BN10 from "bn.js";
|
|
2378
1726
|
var SplitUnit = /* @__PURE__ */ ((SplitUnit2) => {
|
|
2379
1727
|
SplitUnit2[SplitUnit2["FIVE"] = 5] = "FIVE";
|
|
2380
1728
|
SplitUnit2[SplitUnit2["TEN"] = 10] = "TEN";
|
|
@@ -2432,7 +1780,7 @@ function updateSplitSwapResult(maxIndex, currentIndex, splitSwapResult, stepResu
|
|
|
2432
1780
|
return splitSwapResult;
|
|
2433
1781
|
}
|
|
2434
1782
|
function computeSplitSwap(a2b, byAmountIn, amounts, poolData, swapTicks) {
|
|
2435
|
-
let currentLiquidity = new
|
|
1783
|
+
let currentLiquidity = new BN10(poolData.liquidity);
|
|
2436
1784
|
let { currentSqrtPrice } = poolData;
|
|
2437
1785
|
let splitSwapResult = {
|
|
2438
1786
|
amountInArray: [],
|
|
@@ -2495,7 +1843,7 @@ function computeSplitSwap(a2b, byAmountIn, amounts, poolData, swapTicks) {
|
|
|
2495
1843
|
targetSqrtPrice,
|
|
2496
1844
|
currentLiquidity,
|
|
2497
1845
|
remainerAmount,
|
|
2498
|
-
new
|
|
1846
|
+
new BN10(poolData.feeRate),
|
|
2499
1847
|
byAmountIn
|
|
2500
1848
|
);
|
|
2501
1849
|
tempStepResult = stepResult;
|
|
@@ -2507,7 +1855,7 @@ function computeSplitSwap(a2b, byAmountIn, amounts, poolData, swapTicks) {
|
|
|
2507
1855
|
splitSwapResult.amountOutArray[i] = splitSwapResult.amountOutArray[i].add(stepResult.amountOut);
|
|
2508
1856
|
splitSwapResult.feeAmountArray[i] = splitSwapResult.feeAmountArray[i].add(stepResult.feeAmount);
|
|
2509
1857
|
if (stepResult.nextSqrtPrice.eq(tick.sqrtPrice)) {
|
|
2510
|
-
signedLiquidityChange = a2b ? tick.liquidityNet.mul(new
|
|
1858
|
+
signedLiquidityChange = a2b ? tick.liquidityNet.mul(new BN10(-1)) : tick.liquidityNet;
|
|
2511
1859
|
currentLiquidity = signedLiquidityChange.gt(ZERO) ? currentLiquidity.add(signedLiquidityChange) : currentLiquidity.sub(signedLiquidityChange.abs());
|
|
2512
1860
|
currentSqrtPrice = tick.sqrtPrice;
|
|
2513
1861
|
} else {
|
|
@@ -2532,7 +1880,7 @@ function computeSplitSwap(a2b, byAmountIn, amounts, poolData, swapTicks) {
|
|
|
2532
1880
|
break;
|
|
2533
1881
|
}
|
|
2534
1882
|
if (tempStepResult.nextSqrtPrice.eq(tick.sqrtPrice)) {
|
|
2535
|
-
signedLiquidityChange = a2b ? tick.liquidityNet.mul(new
|
|
1883
|
+
signedLiquidityChange = a2b ? tick.liquidityNet.mul(new BN10(-1)) : tick.liquidityNet;
|
|
2536
1884
|
currentLiquidity = signedLiquidityChange.gt(ZERO) ? currentLiquidity.add(signedLiquidityChange) : currentLiquidity.sub(signedLiquidityChange.abs());
|
|
2537
1885
|
currentSqrtPrice = tick.sqrtPrice;
|
|
2538
1886
|
} else {
|
|
@@ -2587,6 +1935,18 @@ var SplitSwap = class {
|
|
|
2587
1935
|
}
|
|
2588
1936
|
};
|
|
2589
1937
|
|
|
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
|
+
|
|
2590
1950
|
// src/utils/objects.ts
|
|
2591
1951
|
function getSuiObjectData(resp) {
|
|
2592
1952
|
return resp.data;
|
|
@@ -2740,7 +2100,7 @@ function buildPool(objects) {
|
|
|
2740
2100
|
const rewarders = [];
|
|
2741
2101
|
fields.rewarder_manager.fields.rewarders.forEach((item) => {
|
|
2742
2102
|
const { emissions_per_second } = item.fields;
|
|
2743
|
-
const emissionSeconds = MathUtil.fromX64(new
|
|
2103
|
+
const emissionSeconds = MathUtil.fromX64(new BN11(emissions_per_second));
|
|
2744
2104
|
const emissionsEveryDay = Math.floor(emissionSeconds.toNumber() * 60 * 60 * 24);
|
|
2745
2105
|
rewarders.push({
|
|
2746
2106
|
emissions_per_second,
|
|
@@ -2932,11 +2292,11 @@ function buildTickData(objects) {
|
|
|
2932
2292
|
const possition = {
|
|
2933
2293
|
objectId: getObjectId(objects),
|
|
2934
2294
|
index: asIntN(BigInt(valueItem.index.fields.bits)),
|
|
2935
|
-
sqrtPrice: new
|
|
2936
|
-
liquidityNet: new
|
|
2937
|
-
liquidityGross: new
|
|
2938
|
-
feeGrowthOutsideA: new
|
|
2939
|
-
feeGrowthOutsideB: new
|
|
2295
|
+
sqrtPrice: new BN11(valueItem.sqrt_price),
|
|
2296
|
+
liquidityNet: new BN11(valueItem.liquidity_net.fields.bits),
|
|
2297
|
+
liquidityGross: new BN11(valueItem.liquidity_gross),
|
|
2298
|
+
feeGrowthOutsideA: new BN11(valueItem.fee_growth_outside_a),
|
|
2299
|
+
feeGrowthOutsideB: new BN11(valueItem.fee_growth_outside_b),
|
|
2940
2300
|
rewardersGrowthOutside: valueItem.rewards_growth_outside
|
|
2941
2301
|
};
|
|
2942
2302
|
return possition;
|
|
@@ -2946,11 +2306,11 @@ function buildTickDataByEvent(fields) {
|
|
|
2946
2306
|
throw new ClmmpoolsError(`Invalid tick fields.`, "InvalidTickFields" /* InvalidTickFields */);
|
|
2947
2307
|
}
|
|
2948
2308
|
const index = asIntN(BigInt(fields.index.bits));
|
|
2949
|
-
const sqrtPrice = new
|
|
2950
|
-
const liquidityNet = new
|
|
2951
|
-
const liquidityGross = new
|
|
2952
|
-
const feeGrowthOutsideA = new
|
|
2953
|
-
const feeGrowthOutsideB = new
|
|
2309
|
+
const sqrtPrice = new BN11(fields.sqrt_price);
|
|
2310
|
+
const liquidityNet = new BN11(fields.liquidity_net.bits);
|
|
2311
|
+
const liquidityGross = new BN11(fields.liquidity_gross);
|
|
2312
|
+
const feeGrowthOutsideA = new BN11(fields.fee_growth_outside_a);
|
|
2313
|
+
const feeGrowthOutsideB = new BN11(fields.fee_growth_outside_b);
|
|
2954
2314
|
const rewardersGrowthOutside = fields.rewards_growth_outside || [];
|
|
2955
2315
|
const tick = {
|
|
2956
2316
|
objectId: "",
|
|
@@ -2969,7 +2329,7 @@ function buildClmmPositionName(pool_index, position_index) {
|
|
|
2969
2329
|
}
|
|
2970
2330
|
|
|
2971
2331
|
// src/utils/tick.ts
|
|
2972
|
-
import
|
|
2332
|
+
import BN12 from "bn.js";
|
|
2973
2333
|
var TickUtil = class {
|
|
2974
2334
|
/**
|
|
2975
2335
|
* Get min tick index.
|
|
@@ -3009,22 +2369,22 @@ function getRewardInTickRange(pool, tickLower, tickUpper, tickLowerIndex, tickUp
|
|
|
3009
2369
|
let rewarder_growth_below = growthGlobal[i];
|
|
3010
2370
|
if (tickLower !== null) {
|
|
3011
2371
|
if (pool.current_tick_index < tickLowerIndex) {
|
|
3012
|
-
rewarder_growth_below = growthGlobal[i].sub(new
|
|
2372
|
+
rewarder_growth_below = growthGlobal[i].sub(new BN12(tickLower.rewardersGrowthOutside[i]));
|
|
3013
2373
|
} else {
|
|
3014
2374
|
rewarder_growth_below = tickLower.rewardersGrowthOutside[i];
|
|
3015
2375
|
}
|
|
3016
2376
|
}
|
|
3017
|
-
let rewarder_growth_above = new
|
|
2377
|
+
let rewarder_growth_above = new BN12(0);
|
|
3018
2378
|
if (tickUpper !== null) {
|
|
3019
2379
|
if (pool.current_tick_index >= tickUpperIndex) {
|
|
3020
|
-
rewarder_growth_above = growthGlobal[i].sub(new
|
|
2380
|
+
rewarder_growth_above = growthGlobal[i].sub(new BN12(tickUpper.rewardersGrowthOutside[i]));
|
|
3021
2381
|
} else {
|
|
3022
2382
|
rewarder_growth_above = tickUpper.rewardersGrowthOutside[i];
|
|
3023
2383
|
}
|
|
3024
2384
|
}
|
|
3025
2385
|
const rewGrowthInside = MathUtil.subUnderflowU128(
|
|
3026
|
-
MathUtil.subUnderflowU128(new
|
|
3027
|
-
new
|
|
2386
|
+
MathUtil.subUnderflowU128(new BN12(growthGlobal[i]), new BN12(rewarder_growth_below)),
|
|
2387
|
+
new BN12(rewarder_growth_above)
|
|
3028
2388
|
);
|
|
3029
2389
|
rewarderGrowthInside.push(rewGrowthInside);
|
|
3030
2390
|
}
|
|
@@ -3032,8 +2392,8 @@ function getRewardInTickRange(pool, tickLower, tickUpper, tickLowerIndex, tickUp
|
|
|
3032
2392
|
}
|
|
3033
2393
|
|
|
3034
2394
|
// src/utils/transaction-util.ts
|
|
3035
|
-
import
|
|
3036
|
-
import
|
|
2395
|
+
import BN13 from "bn.js";
|
|
2396
|
+
import Decimal4 from "decimal.js";
|
|
3037
2397
|
import { Transaction } from "@mysten/sui/transactions";
|
|
3038
2398
|
function findAdjustCoin(coinPair) {
|
|
3039
2399
|
const isAdjustCoinA = CoinAssist.isSuiCoin(coinPair.coinTypeA);
|
|
@@ -3041,7 +2401,7 @@ function findAdjustCoin(coinPair) {
|
|
|
3041
2401
|
return { isAdjustCoinA, isAdjustCoinB };
|
|
3042
2402
|
}
|
|
3043
2403
|
function reverSlippageAmount(slippageAmount, slippage) {
|
|
3044
|
-
return
|
|
2404
|
+
return Decimal4.ceil(d(slippageAmount).div(1 + slippage)).toString();
|
|
3045
2405
|
}
|
|
3046
2406
|
async function printTransaction(tx, isPrint = true) {
|
|
3047
2407
|
console.log(`inputs`, tx.blockData.inputs);
|
|
@@ -3341,7 +2701,7 @@ var _TransactionUtil = class {
|
|
|
3341
2701
|
const liquidityInput = ClmmPoolUtil.estLiquidityAndcoinAmountFromOneAmounts(
|
|
3342
2702
|
Number(params.tick_lower),
|
|
3343
2703
|
Number(params.tick_upper),
|
|
3344
|
-
new
|
|
2704
|
+
new BN13(coinAmount),
|
|
3345
2705
|
params.fix_amount_a,
|
|
3346
2706
|
true,
|
|
3347
2707
|
slippage,
|
|
@@ -3415,12 +2775,12 @@ var _TransactionUtil = class {
|
|
|
3415
2775
|
max_amount_a = params.amount_a;
|
|
3416
2776
|
min_amount_a = params.amount_a;
|
|
3417
2777
|
max_amount_b = params.amount_b;
|
|
3418
|
-
min_amount_b = new
|
|
2778
|
+
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();
|
|
3419
2779
|
} else {
|
|
3420
2780
|
max_amount_b = params.amount_b;
|
|
3421
2781
|
min_amount_b = params.amount_b;
|
|
3422
2782
|
max_amount_a = params.amount_a;
|
|
3423
|
-
min_amount_a = new
|
|
2783
|
+
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();
|
|
3424
2784
|
}
|
|
3425
2785
|
const args = params.is_open ? [
|
|
3426
2786
|
tx.object(clmmConfig.global_config_id),
|
|
@@ -4409,7 +3769,7 @@ var _TransactionUtil = class {
|
|
|
4409
3769
|
const basePath = splitPath.basePaths[i];
|
|
4410
3770
|
a2b.push(basePath.direction);
|
|
4411
3771
|
poolAddress.push(basePath.poolAddress);
|
|
4412
|
-
rawAmountLimit.push(new
|
|
3772
|
+
rawAmountLimit.push(new BN13(basePath.inputAmount.toString()));
|
|
4413
3773
|
if (i === 0) {
|
|
4414
3774
|
coinType.push(basePath.fromCoin, basePath.toCoin);
|
|
4415
3775
|
} else {
|
|
@@ -4417,8 +3777,8 @@ var _TransactionUtil = class {
|
|
|
4417
3777
|
}
|
|
4418
3778
|
}
|
|
4419
3779
|
const onePath = {
|
|
4420
|
-
amountIn: new
|
|
4421
|
-
amountOut: new
|
|
3780
|
+
amountIn: new BN13(splitPath.inputAmount.toString()),
|
|
3781
|
+
amountOut: new BN13(splitPath.outputAmount.toString()),
|
|
4422
3782
|
poolAddress,
|
|
4423
3783
|
a2b,
|
|
4424
3784
|
rawAmountLimit,
|
|
@@ -4775,9 +4135,9 @@ var TxBlock = class {
|
|
|
4775
4135
|
};
|
|
4776
4136
|
|
|
4777
4137
|
// src/utils/deepbook-utils.ts
|
|
4778
|
-
import
|
|
4138
|
+
import BN14 from "bn.js";
|
|
4779
4139
|
import { Transaction as Transaction3 } from "@mysten/sui/transactions";
|
|
4780
|
-
var FLOAT_SCALING = new
|
|
4140
|
+
var FLOAT_SCALING = new BN14(1e9);
|
|
4781
4141
|
var DeepbookUtils = class {
|
|
4782
4142
|
static createAccountCap(senderAddress, sdkOptions, tx, isTransfer = false) {
|
|
4783
4143
|
if (senderAddress.length === 0) {
|
|
@@ -4923,9 +4283,9 @@ var DeepbookUtils = class {
|
|
|
4923
4283
|
static async preSwap(sdk, pool, a2b, amountIn) {
|
|
4924
4284
|
let isExceed = false;
|
|
4925
4285
|
let amountOut = ZERO;
|
|
4926
|
-
let remainAmount = new
|
|
4286
|
+
let remainAmount = new BN14(amountIn);
|
|
4927
4287
|
let feeAmount = ZERO;
|
|
4928
|
-
const initAmountIn = new
|
|
4288
|
+
const initAmountIn = new BN14(amountIn);
|
|
4929
4289
|
if (a2b) {
|
|
4930
4290
|
let bids = await this.getPoolBids(sdk, pool.poolID, pool.baseAsset, pool.quoteAsset);
|
|
4931
4291
|
if (bids === null) {
|
|
@@ -4935,16 +4295,16 @@ var DeepbookUtils = class {
|
|
|
4935
4295
|
return b.price - a.price;
|
|
4936
4296
|
});
|
|
4937
4297
|
for (let i = 0; i < bids.length; i += 1) {
|
|
4938
|
-
const curBidAmount = new
|
|
4939
|
-
const curBidPrice = new
|
|
4940
|
-
const fee = curBidAmount.mul(new
|
|
4298
|
+
const curBidAmount = new BN14(bids[i].quantity);
|
|
4299
|
+
const curBidPrice = new BN14(bids[i].price);
|
|
4300
|
+
const fee = curBidAmount.mul(new BN14(curBidPrice)).mul(new BN14(pool.takerFeeRate)).div(FLOAT_SCALING).div(FLOAT_SCALING);
|
|
4941
4301
|
if (remainAmount.gt(curBidAmount)) {
|
|
4942
4302
|
remainAmount = remainAmount.sub(curBidAmount);
|
|
4943
4303
|
amountOut = amountOut.add(curBidAmount.mul(curBidPrice).div(FLOAT_SCALING).sub(fee));
|
|
4944
4304
|
feeAmount = feeAmount.add(fee);
|
|
4945
4305
|
} else {
|
|
4946
|
-
const curOut = remainAmount.mul(new
|
|
4947
|
-
const curFee = curOut.mul(new
|
|
4306
|
+
const curOut = remainAmount.mul(new BN14(bids[i].price)).div(FLOAT_SCALING);
|
|
4307
|
+
const curFee = curOut.mul(new BN14(pool.takerFeeRate)).div(FLOAT_SCALING);
|
|
4948
4308
|
amountOut = amountOut.add(curOut.sub(curFee));
|
|
4949
4309
|
remainAmount = remainAmount.sub(remainAmount);
|
|
4950
4310
|
feeAmount = feeAmount.add(curFee);
|
|
@@ -4959,15 +4319,15 @@ var DeepbookUtils = class {
|
|
|
4959
4319
|
isExceed = true;
|
|
4960
4320
|
}
|
|
4961
4321
|
for (let i = 0; i < asks.length; i += 1) {
|
|
4962
|
-
const curAskAmount = new
|
|
4963
|
-
const fee = curAskAmount.mul(new
|
|
4322
|
+
const curAskAmount = new BN14(asks[i].price).mul(new BN14(asks[i].quantity)).div(new BN14(1e9));
|
|
4323
|
+
const fee = curAskAmount.mul(new BN14(pool.takerFeeRate)).div(FLOAT_SCALING);
|
|
4964
4324
|
const curAskAmountWithFee = curAskAmount.add(fee);
|
|
4965
4325
|
if (remainAmount.gt(curAskAmount)) {
|
|
4966
|
-
amountOut = amountOut.add(new
|
|
4326
|
+
amountOut = amountOut.add(new BN14(asks[i].quantity));
|
|
4967
4327
|
remainAmount = remainAmount.sub(curAskAmountWithFee);
|
|
4968
4328
|
feeAmount = feeAmount.add(fee);
|
|
4969
4329
|
} else {
|
|
4970
|
-
const splitNums = new
|
|
4330
|
+
const splitNums = new BN14(asks[i].quantity).div(new BN14(pool.lotSize));
|
|
4971
4331
|
const splitAmount = curAskAmountWithFee.div(splitNums);
|
|
4972
4332
|
const swapSplitNum = remainAmount.div(splitAmount);
|
|
4973
4333
|
amountOut = amountOut.add(swapSplitNum.muln(pool.lotSize));
|
|
@@ -5828,7 +5188,7 @@ var PoolModule = class {
|
|
|
5828
5188
|
};
|
|
5829
5189
|
|
|
5830
5190
|
// src/modules/positionModule.ts
|
|
5831
|
-
import
|
|
5191
|
+
import BN15 from "bn.js";
|
|
5832
5192
|
import { Transaction as Transaction5 } from "@mysten/sui/transactions";
|
|
5833
5193
|
import { isValidSuiObjectId } from "@mysten/sui/utils";
|
|
5834
5194
|
var PositionModule = class {
|
|
@@ -6050,8 +5410,8 @@ var PositionModule = class {
|
|
|
6050
5410
|
for (let i = 0; i < valueData.length; i += 1) {
|
|
6051
5411
|
const { parsedJson } = valueData[i];
|
|
6052
5412
|
const posRrewarderResult = {
|
|
6053
|
-
feeOwedA: new
|
|
6054
|
-
feeOwedB: new
|
|
5413
|
+
feeOwedA: new BN15(parsedJson.fee_owned_a),
|
|
5414
|
+
feeOwedB: new BN15(parsedJson.fee_owned_b),
|
|
6055
5415
|
position_id: parsedJson.position_id
|
|
6056
5416
|
};
|
|
6057
5417
|
result.push(posRrewarderResult);
|
|
@@ -6427,7 +5787,7 @@ var PositionModule = class {
|
|
|
6427
5787
|
};
|
|
6428
5788
|
|
|
6429
5789
|
// src/modules/rewarderModule.ts
|
|
6430
|
-
import
|
|
5790
|
+
import BN16 from "bn.js";
|
|
6431
5791
|
import { Transaction as Transaction6 } from "@mysten/sui/transactions";
|
|
6432
5792
|
var RewarderModule = class {
|
|
6433
5793
|
_sdk;
|
|
@@ -6453,7 +5813,7 @@ var RewarderModule = class {
|
|
|
6453
5813
|
}
|
|
6454
5814
|
const emissionsEveryDay = [];
|
|
6455
5815
|
for (const rewarderInfo of rewarderInfos) {
|
|
6456
|
-
const emissionSeconds = MathUtil.fromX64(new
|
|
5816
|
+
const emissionSeconds = MathUtil.fromX64(new BN16(rewarderInfo.emissions_per_second));
|
|
6457
5817
|
emissionsEveryDay.push({
|
|
6458
5818
|
emissions: Math.floor(emissionSeconds.toNumber() * 60 * 60 * 24),
|
|
6459
5819
|
coin_address: rewarderInfo.coinAddress
|
|
@@ -6472,20 +5832,20 @@ var RewarderModule = class {
|
|
|
6472
5832
|
const currentPool = await this.sdk.Pool.getPool(poolID);
|
|
6473
5833
|
const lastTime = currentPool.rewarder_last_updated_time;
|
|
6474
5834
|
currentPool.rewarder_last_updated_time = currentTime.toString();
|
|
6475
|
-
if (Number(currentPool.liquidity) === 0 || currentTime.eq(new
|
|
5835
|
+
if (Number(currentPool.liquidity) === 0 || currentTime.eq(new BN16(lastTime))) {
|
|
6476
5836
|
return currentPool;
|
|
6477
5837
|
}
|
|
6478
|
-
const timeDelta = currentTime.div(new
|
|
5838
|
+
const timeDelta = currentTime.div(new BN16(1e3)).sub(new BN16(lastTime)).add(new BN16(15));
|
|
6479
5839
|
const rewarderInfos = currentPool.rewarder_infos;
|
|
6480
5840
|
for (let i = 0; i < rewarderInfos.length; i += 1) {
|
|
6481
5841
|
const rewarderInfo = rewarderInfos[i];
|
|
6482
5842
|
const rewarderGrowthDelta = MathUtil.checkMulDivFloor(
|
|
6483
5843
|
timeDelta,
|
|
6484
|
-
new
|
|
6485
|
-
new
|
|
5844
|
+
new BN16(rewarderInfo.emissions_per_second),
|
|
5845
|
+
new BN16(currentPool.liquidity),
|
|
6486
5846
|
128
|
|
6487
5847
|
);
|
|
6488
|
-
this.growthGlobal[i] = new
|
|
5848
|
+
this.growthGlobal[i] = new BN16(rewarderInfo.growth_global).add(new BN16(rewarderGrowthDelta));
|
|
6489
5849
|
}
|
|
6490
5850
|
return currentPool;
|
|
6491
5851
|
}
|
|
@@ -6500,7 +5860,7 @@ var RewarderModule = class {
|
|
|
6500
5860
|
*/
|
|
6501
5861
|
async posRewardersAmount(poolID, positionHandle, positionID) {
|
|
6502
5862
|
const currentTime = Date.parse((/* @__PURE__ */ new Date()).toString());
|
|
6503
|
-
const pool = await this.updatePoolRewarder(poolID, new
|
|
5863
|
+
const pool = await this.updatePoolRewarder(poolID, new BN16(currentTime));
|
|
6504
5864
|
const position = await this.sdk.Position.getPositionRewarders(positionHandle, positionID);
|
|
6505
5865
|
if (position === void 0) {
|
|
6506
5866
|
return [];
|
|
@@ -6521,7 +5881,7 @@ var RewarderModule = class {
|
|
|
6521
5881
|
*/
|
|
6522
5882
|
async poolRewardersAmount(accountAddress, poolID) {
|
|
6523
5883
|
const currentTime = Date.parse((/* @__PURE__ */ new Date()).toString());
|
|
6524
|
-
const pool = await this.updatePoolRewarder(poolID, new
|
|
5884
|
+
const pool = await this.updatePoolRewarder(poolID, new BN16(currentTime));
|
|
6525
5885
|
const positions = await this.sdk.Position.getPositionList(accountAddress, [poolID]);
|
|
6526
5886
|
const tickDatas = await this.getPoolLowerAndUpperTicks(pool.ticks_handle, positions);
|
|
6527
5887
|
const rewarderAmount = [ZERO, ZERO, ZERO];
|
|
@@ -6548,38 +5908,38 @@ var RewarderModule = class {
|
|
|
6548
5908
|
const growthInside = [];
|
|
6549
5909
|
const AmountOwed = [];
|
|
6550
5910
|
if (rewardersInside.length > 0) {
|
|
6551
|
-
let growthDelta0 = MathUtil.subUnderflowU128(rewardersInside[0], new
|
|
6552
|
-
if (growthDelta0.gt(new
|
|
5911
|
+
let growthDelta0 = MathUtil.subUnderflowU128(rewardersInside[0], new BN16(position.reward_growth_inside_0));
|
|
5912
|
+
if (growthDelta0.gt(new BN16("3402823669209384634633745948738404"))) {
|
|
6553
5913
|
growthDelta0 = ONE;
|
|
6554
5914
|
}
|
|
6555
|
-
const amountOwed_0 = MathUtil.checkMulShiftRight(new
|
|
5915
|
+
const amountOwed_0 = MathUtil.checkMulShiftRight(new BN16(position.liquidity), growthDelta0, 64, 128);
|
|
6556
5916
|
growthInside.push(rewardersInside[0]);
|
|
6557
5917
|
AmountOwed.push({
|
|
6558
|
-
amount_owed: new
|
|
5918
|
+
amount_owed: new BN16(position.reward_amount_owed_0).add(amountOwed_0),
|
|
6559
5919
|
coin_address: pool.rewarder_infos[0].coinAddress
|
|
6560
5920
|
});
|
|
6561
5921
|
}
|
|
6562
5922
|
if (rewardersInside.length > 1) {
|
|
6563
|
-
let growthDelta_1 = MathUtil.subUnderflowU128(rewardersInside[1], new
|
|
6564
|
-
if (growthDelta_1.gt(new
|
|
5923
|
+
let growthDelta_1 = MathUtil.subUnderflowU128(rewardersInside[1], new BN16(position.reward_growth_inside_1));
|
|
5924
|
+
if (growthDelta_1.gt(new BN16("3402823669209384634633745948738404"))) {
|
|
6565
5925
|
growthDelta_1 = ONE;
|
|
6566
5926
|
}
|
|
6567
|
-
const amountOwed_1 = MathUtil.checkMulShiftRight(new
|
|
5927
|
+
const amountOwed_1 = MathUtil.checkMulShiftRight(new BN16(position.liquidity), growthDelta_1, 64, 128);
|
|
6568
5928
|
growthInside.push(rewardersInside[1]);
|
|
6569
5929
|
AmountOwed.push({
|
|
6570
|
-
amount_owed: new
|
|
5930
|
+
amount_owed: new BN16(position.reward_amount_owed_1).add(amountOwed_1),
|
|
6571
5931
|
coin_address: pool.rewarder_infos[1].coinAddress
|
|
6572
5932
|
});
|
|
6573
5933
|
}
|
|
6574
5934
|
if (rewardersInside.length > 2) {
|
|
6575
|
-
let growthDelta_2 = MathUtil.subUnderflowU128(rewardersInside[2], new
|
|
6576
|
-
if (growthDelta_2.gt(new
|
|
5935
|
+
let growthDelta_2 = MathUtil.subUnderflowU128(rewardersInside[2], new BN16(position.reward_growth_inside_2));
|
|
5936
|
+
if (growthDelta_2.gt(new BN16("3402823669209384634633745948738404"))) {
|
|
6577
5937
|
growthDelta_2 = ONE;
|
|
6578
5938
|
}
|
|
6579
|
-
const amountOwed_2 = MathUtil.checkMulShiftRight(new
|
|
5939
|
+
const amountOwed_2 = MathUtil.checkMulShiftRight(new BN16(position.liquidity), growthDelta_2, 64, 128);
|
|
6580
5940
|
growthInside.push(rewardersInside[2]);
|
|
6581
5941
|
AmountOwed.push({
|
|
6582
|
-
amount_owed: new
|
|
5942
|
+
amount_owed: new BN16(position.reward_amount_owed_2).add(amountOwed_2),
|
|
6583
5943
|
coin_address: pool.rewarder_infos[2].coinAddress
|
|
6584
5944
|
});
|
|
6585
5945
|
}
|
|
@@ -6693,8 +6053,8 @@ var RewarderModule = class {
|
|
|
6693
6053
|
for (let i = 0; i < valueData.length; i += 1) {
|
|
6694
6054
|
const { parsedJson } = valueData[i];
|
|
6695
6055
|
const posRrewarderResult = {
|
|
6696
|
-
feeOwedA: new
|
|
6697
|
-
feeOwedB: new
|
|
6056
|
+
feeOwedA: new BN16(parsedJson.fee_owned_a),
|
|
6057
|
+
feeOwedB: new BN16(parsedJson.fee_owned_b),
|
|
6698
6058
|
position_id: parsedJson.position_id
|
|
6699
6059
|
};
|
|
6700
6060
|
result.push(posRrewarderResult);
|
|
@@ -6757,7 +6117,7 @@ var RewarderModule = class {
|
|
|
6757
6117
|
};
|
|
6758
6118
|
for (let j = 0; j < params[i].rewarderInfo.length; j += 1) {
|
|
6759
6119
|
posRrewarderResult.rewarderAmountOwed.push({
|
|
6760
|
-
amount_owed: new
|
|
6120
|
+
amount_owed: new BN16(valueData[i].parsedJson.data[j]),
|
|
6761
6121
|
coin_address: params[i].rewarderInfo[j].coinAddress
|
|
6762
6122
|
});
|
|
6763
6123
|
}
|
|
@@ -6946,7 +6306,7 @@ var RewarderModule = class {
|
|
|
6946
6306
|
};
|
|
6947
6307
|
|
|
6948
6308
|
// src/modules/routerModule.ts
|
|
6949
|
-
import
|
|
6309
|
+
import BN17 from "bn.js";
|
|
6950
6310
|
import { Graph, GraphEdge, GraphVertex } from "@syntsugar/cc-graph";
|
|
6951
6311
|
import { Transaction as Transaction7 } from "@mysten/sui/transactions";
|
|
6952
6312
|
function _pairSymbol(base, quote) {
|
|
@@ -7228,8 +6588,8 @@ var RouterModule = class {
|
|
|
7228
6588
|
if (swapWithMultiPoolParams != null) {
|
|
7229
6589
|
const preSwapResult2 = await this.sdk.Swap.preSwapWithMultiPool(swapWithMultiPoolParams);
|
|
7230
6590
|
const onePath2 = {
|
|
7231
|
-
amountIn: new
|
|
7232
|
-
amountOut: new
|
|
6591
|
+
amountIn: new BN17(preSwapResult2.estimatedAmountIn),
|
|
6592
|
+
amountOut: new BN17(preSwapResult2.estimatedAmountOut),
|
|
7233
6593
|
poolAddress: [preSwapResult2.poolAddress],
|
|
7234
6594
|
a2b: [preSwapResult2.aToB],
|
|
7235
6595
|
rawAmountLimit: byAmountIn ? [preSwapResult2.estimatedAmountOut] : [preSwapResult2.estimatedAmountIn],
|
|
@@ -7242,8 +6602,8 @@ var RouterModule = class {
|
|
|
7242
6602
|
priceSlippagePoint
|
|
7243
6603
|
};
|
|
7244
6604
|
const result2 = {
|
|
7245
|
-
amountIn: new
|
|
7246
|
-
amountOut: new
|
|
6605
|
+
amountIn: new BN17(preSwapResult2.estimatedAmountIn),
|
|
6606
|
+
amountOut: new BN17(preSwapResult2.estimatedAmountOut),
|
|
7247
6607
|
paths: [onePath2],
|
|
7248
6608
|
a2b: preSwapResult2.aToB,
|
|
7249
6609
|
b2c: void 0,
|
|
@@ -7265,8 +6625,8 @@ var RouterModule = class {
|
|
|
7265
6625
|
if (swapWithMultiPoolParams != null) {
|
|
7266
6626
|
const preSwapResult2 = await this.sdk.Swap.preSwapWithMultiPool(swapWithMultiPoolParams);
|
|
7267
6627
|
const onePath2 = {
|
|
7268
|
-
amountIn: new
|
|
7269
|
-
amountOut: new
|
|
6628
|
+
amountIn: new BN17(preSwapResult2.estimatedAmountIn),
|
|
6629
|
+
amountOut: new BN17(preSwapResult2.estimatedAmountOut),
|
|
7270
6630
|
poolAddress: [preSwapResult2.poolAddress],
|
|
7271
6631
|
a2b: [preSwapResult2.aToB],
|
|
7272
6632
|
rawAmountLimit: byAmountIn ? [preSwapResult2.estimatedAmountOut] : [preSwapResult2.estimatedAmountIn],
|
|
@@ -7279,8 +6639,8 @@ var RouterModule = class {
|
|
|
7279
6639
|
priceSlippagePoint
|
|
7280
6640
|
};
|
|
7281
6641
|
const result3 = {
|
|
7282
|
-
amountIn: new
|
|
7283
|
-
amountOut: new
|
|
6642
|
+
amountIn: new BN17(preSwapResult2.estimatedAmountIn),
|
|
6643
|
+
amountOut: new BN17(preSwapResult2.estimatedAmountOut),
|
|
7284
6644
|
paths: [onePath2],
|
|
7285
6645
|
a2b: preSwapResult2.aToB,
|
|
7286
6646
|
b2c: void 0,
|
|
@@ -7361,8 +6721,8 @@ var RouterModule = class {
|
|
|
7361
6721
|
if (swapWithMultiPoolParams != null) {
|
|
7362
6722
|
const preSwapResult = await this.sdk.Swap.preSwapWithMultiPool(swapWithMultiPoolParams);
|
|
7363
6723
|
const onePath = {
|
|
7364
|
-
amountIn: new
|
|
7365
|
-
amountOut: new
|
|
6724
|
+
amountIn: new BN17(preSwapResult.estimatedAmountIn),
|
|
6725
|
+
amountOut: new BN17(preSwapResult.estimatedAmountOut),
|
|
7366
6726
|
poolAddress: [preSwapResult.poolAddress],
|
|
7367
6727
|
a2b: [preSwapResult.aToB],
|
|
7368
6728
|
rawAmountLimit: byAmountIn ? [preSwapResult.estimatedAmountOut] : [preSwapResult.estimatedAmountIn],
|
|
@@ -7375,8 +6735,8 @@ var RouterModule = class {
|
|
|
7375
6735
|
priceSlippagePoint
|
|
7376
6736
|
};
|
|
7377
6737
|
const result = {
|
|
7378
|
-
amountIn: new
|
|
7379
|
-
amountOut: new
|
|
6738
|
+
amountIn: new BN17(preSwapResult.estimatedAmountIn),
|
|
6739
|
+
amountOut: new BN17(preSwapResult.estimatedAmountOut),
|
|
7380
6740
|
paths: [onePath],
|
|
7381
6741
|
a2b: preSwapResult.aToB,
|
|
7382
6742
|
b2c: void 0,
|
|
@@ -7460,13 +6820,13 @@ var RouterModule = class {
|
|
|
7460
6820
|
continue;
|
|
7461
6821
|
}
|
|
7462
6822
|
if (params[0].byAmountIn) {
|
|
7463
|
-
const amount = new
|
|
6823
|
+
const amount = new BN17(valueData[i].parsedJson.data.amount_out);
|
|
7464
6824
|
if (amount.gt(tempMaxAmount)) {
|
|
7465
6825
|
tempIndex = i;
|
|
7466
6826
|
tempMaxAmount = amount;
|
|
7467
6827
|
}
|
|
7468
6828
|
} else {
|
|
7469
|
-
const amount = params[i].stepNums > 1 ? new
|
|
6829
|
+
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));
|
|
7470
6830
|
if (amount.lt(tempMaxAmount)) {
|
|
7471
6831
|
tempIndex = i;
|
|
7472
6832
|
tempMaxAmount = amount;
|
|
@@ -7536,8 +6896,8 @@ var RouterModule = class {
|
|
|
7536
6896
|
};
|
|
7537
6897
|
|
|
7538
6898
|
// src/modules/swapModule.ts
|
|
7539
|
-
import
|
|
7540
|
-
import
|
|
6899
|
+
import BN18 from "bn.js";
|
|
6900
|
+
import Decimal5 from "decimal.js";
|
|
7541
6901
|
import { Transaction as Transaction8 } from "@mysten/sui/transactions";
|
|
7542
6902
|
var AMM_SWAP_MODULE = "amm_swap";
|
|
7543
6903
|
var POOL_STRUCT = "Pool";
|
|
@@ -7555,14 +6915,14 @@ var SwapModule = class {
|
|
|
7555
6915
|
const pathCount = item.basePaths.length;
|
|
7556
6916
|
if (pathCount > 0) {
|
|
7557
6917
|
const path = item.basePaths[0];
|
|
7558
|
-
const feeRate = path.label === "Magma" ? new
|
|
6918
|
+
const feeRate = path.label === "Magma" ? new Decimal5(path.feeRate).div(10 ** 6) : new Decimal5(path.feeRate).div(10 ** 9);
|
|
7559
6919
|
const feeAmount = d(path.inputAmount).div(10 ** path.fromDecimal).mul(feeRate);
|
|
7560
6920
|
fee = fee.add(feeAmount);
|
|
7561
6921
|
if (pathCount > 1) {
|
|
7562
6922
|
const path2 = item.basePaths[1];
|
|
7563
|
-
const price1 = path.direction ? path.currentPrice : new
|
|
7564
|
-
const price2 = path2.direction ? path2.currentPrice : new
|
|
7565
|
-
const feeRate2 = path2.label === "Magma" ? new
|
|
6923
|
+
const price1 = path.direction ? path.currentPrice : new Decimal5(1).div(path.currentPrice);
|
|
6924
|
+
const price2 = path2.direction ? path2.currentPrice : new Decimal5(1).div(path2.currentPrice);
|
|
6925
|
+
const feeRate2 = path2.label === "Magma" ? new Decimal5(path2.feeRate).div(10 ** 6) : new Decimal5(path2.feeRate).div(10 ** 9);
|
|
7566
6926
|
const feeAmount2 = d(path2.outputAmount).div(10 ** path2.toDecimal).mul(feeRate2);
|
|
7567
6927
|
const fee2 = feeAmount2.div(price1.mul(price2));
|
|
7568
6928
|
fee = fee.add(fee2);
|
|
@@ -7580,17 +6940,17 @@ var SwapModule = class {
|
|
|
7580
6940
|
const outputAmount = d(path.outputAmount).div(10 ** path.toDecimal);
|
|
7581
6941
|
const inputAmount = d(path.inputAmount).div(10 ** path.fromDecimal);
|
|
7582
6942
|
const rate = outputAmount.div(inputAmount);
|
|
7583
|
-
const cprice = path.direction ? new
|
|
6943
|
+
const cprice = path.direction ? new Decimal5(path.currentPrice) : new Decimal5(1).div(path.currentPrice);
|
|
7584
6944
|
impactValue = impactValue.add(this.calculateSingleImpact(rate, cprice));
|
|
7585
6945
|
}
|
|
7586
6946
|
if (pathCount === 2) {
|
|
7587
6947
|
const path = item.basePaths[0];
|
|
7588
6948
|
const path2 = item.basePaths[1];
|
|
7589
|
-
const cprice1 = path.direction ? new
|
|
7590
|
-
const cprice2 = path2.direction ? new
|
|
6949
|
+
const cprice1 = path.direction ? new Decimal5(path.currentPrice) : new Decimal5(1).div(path.currentPrice);
|
|
6950
|
+
const cprice2 = path2.direction ? new Decimal5(path2.currentPrice) : new Decimal5(1).div(path2.currentPrice);
|
|
7591
6951
|
const cprice = cprice1.mul(cprice2);
|
|
7592
|
-
const outputAmount = new
|
|
7593
|
-
const inputAmount = new
|
|
6952
|
+
const outputAmount = new Decimal5(path2.outputAmount).div(10 ** path2.toDecimal);
|
|
6953
|
+
const inputAmount = new Decimal5(path.inputAmount).div(10 ** path.fromDecimal);
|
|
7594
6954
|
const rate = outputAmount.div(inputAmount);
|
|
7595
6955
|
impactValue = impactValue.add(this.calculateSingleImpact(rate, cprice));
|
|
7596
6956
|
}
|
|
@@ -7652,13 +7012,13 @@ var SwapModule = class {
|
|
|
7652
7012
|
continue;
|
|
7653
7013
|
}
|
|
7654
7014
|
if (params.byAmountIn) {
|
|
7655
|
-
const amount = new
|
|
7015
|
+
const amount = new BN18(valueData[i].parsedJson.data.amount_out);
|
|
7656
7016
|
if (amount.gt(tempMaxAmount)) {
|
|
7657
7017
|
tempIndex = i;
|
|
7658
7018
|
tempMaxAmount = amount;
|
|
7659
7019
|
}
|
|
7660
7020
|
} else {
|
|
7661
|
-
const amount = new
|
|
7021
|
+
const amount = new BN18(valueData[i].parsedJson.data.amount_out);
|
|
7662
7022
|
if (amount.lt(tempMaxAmount)) {
|
|
7663
7023
|
tempIndex = i;
|
|
7664
7024
|
tempMaxAmount = amount;
|
|
@@ -7722,7 +7082,7 @@ var SwapModule = class {
|
|
|
7722
7082
|
return this.transformSwapData(params, valueData[0].parsedJson.data);
|
|
7723
7083
|
}
|
|
7724
7084
|
transformSwapData(params, data) {
|
|
7725
|
-
const estimatedAmountIn = data.amount_in && data.fee_amount ? new
|
|
7085
|
+
const estimatedAmountIn = data.amount_in && data.fee_amount ? new BN18(data.amount_in).add(new BN18(data.fee_amount)).toString() : "";
|
|
7726
7086
|
return {
|
|
7727
7087
|
poolAddress: params.pool.poolAddress,
|
|
7728
7088
|
currentSqrtPrice: params.currentSqrtPrice,
|
|
@@ -7739,7 +7099,7 @@ var SwapModule = class {
|
|
|
7739
7099
|
transformSwapWithMultiPoolData(params, jsonData) {
|
|
7740
7100
|
const { data } = jsonData;
|
|
7741
7101
|
console.log("json data. ", data);
|
|
7742
|
-
const estimatedAmountIn = data.amount_in && data.fee_amount ? new
|
|
7102
|
+
const estimatedAmountIn = data.amount_in && data.fee_amount ? new BN18(data.amount_in).add(new BN18(data.fee_amount)).toString() : "";
|
|
7743
7103
|
return {
|
|
7744
7104
|
poolAddress: params.poolAddress,
|
|
7745
7105
|
estimatedAmountIn,
|
|
@@ -9252,8 +8612,8 @@ var TokenModule = class {
|
|
|
9252
8612
|
};
|
|
9253
8613
|
|
|
9254
8614
|
// src/modules/routerModuleV2.ts
|
|
9255
|
-
import
|
|
9256
|
-
import
|
|
8615
|
+
import BN19 from "bn.js";
|
|
8616
|
+
import Decimal6 from "decimal.js";
|
|
9257
8617
|
import { v4 as uuidv4 } from "uuid";
|
|
9258
8618
|
import axios from "axios";
|
|
9259
8619
|
var RouterModuleV2 = class {
|
|
@@ -9270,7 +8630,7 @@ var RouterModuleV2 = class {
|
|
|
9270
8630
|
if (label === "Magma") {
|
|
9271
8631
|
return TickMath.sqrtPriceX64ToPrice(currentSqrtPrice, decimalA, decimalB);
|
|
9272
8632
|
}
|
|
9273
|
-
return new
|
|
8633
|
+
return new Decimal6(currentSqrtPrice.toString()).div(new Decimal6(10).pow(new Decimal6(decimalB + 9 - decimalA)));
|
|
9274
8634
|
}
|
|
9275
8635
|
parseJsonResult(data) {
|
|
9276
8636
|
const result = {
|
|
@@ -9296,12 +8656,12 @@ var RouterModuleV2 = class {
|
|
|
9296
8656
|
outputAmount: basePath.output_amount,
|
|
9297
8657
|
inputAmount: basePath.input_amount,
|
|
9298
8658
|
feeRate: basePath.fee_rate,
|
|
9299
|
-
currentSqrtPrice: new
|
|
9300
|
-
afterSqrtPrice: basePath.label === "Magma" ? new
|
|
8659
|
+
currentSqrtPrice: new BN19(basePath.current_sqrt_price.toString()),
|
|
8660
|
+
afterSqrtPrice: basePath.label === "Magma" ? new BN19(basePath.after_sqrt_price.toString()) : ZERO,
|
|
9301
8661
|
fromDecimal: basePath.from_decimal,
|
|
9302
8662
|
toDecimal: basePath.to_decimal,
|
|
9303
8663
|
currentPrice: this.calculatePrice(
|
|
9304
|
-
new
|
|
8664
|
+
new BN19(basePath.current_sqrt_price.toString()),
|
|
9305
8665
|
basePath.from_decimal,
|
|
9306
8666
|
basePath.to_decimal,
|
|
9307
8667
|
basePath.direction,
|
|
@@ -9384,7 +8744,7 @@ var RouterModuleV2 = class {
|
|
|
9384
8744
|
const priceResult = await this.sdk.Router.priceUseV1(
|
|
9385
8745
|
from,
|
|
9386
8746
|
to,
|
|
9387
|
-
new
|
|
8747
|
+
new BN19(amount),
|
|
9388
8748
|
byAmountIn,
|
|
9389
8749
|
priceSplitPoint,
|
|
9390
8750
|
partner,
|
|
@@ -9396,7 +8756,7 @@ var RouterModuleV2 = class {
|
|
|
9396
8756
|
if (path.poolAddress.length > 1) {
|
|
9397
8757
|
const fromDecimal0 = this.sdk.Router.tokenInfo(path.coinType[0]).decimals;
|
|
9398
8758
|
const toDecimal0 = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
|
|
9399
|
-
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new
|
|
8759
|
+
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new BN19(priceResult.currentSqrtPrice[0]), fromDecimal0, toDecimal0) : TickMath.sqrtPriceX64ToPrice(new BN19(priceResult.currentSqrtPrice[0]), toDecimal0, fromDecimal0);
|
|
9400
8760
|
const path0 = {
|
|
9401
8761
|
direction: path.a2b[0],
|
|
9402
8762
|
label: "Magma",
|
|
@@ -9413,7 +8773,7 @@ var RouterModuleV2 = class {
|
|
|
9413
8773
|
};
|
|
9414
8774
|
const fromDecimal1 = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
|
|
9415
8775
|
const toDecimal1 = this.sdk.Router.tokenInfo(path.coinType[2]).decimals;
|
|
9416
|
-
const currentPrice1 = path.a2b[1] ? TickMath.sqrtPriceX64ToPrice(new
|
|
8776
|
+
const currentPrice1 = path.a2b[1] ? TickMath.sqrtPriceX64ToPrice(new BN19(priceResult.currentSqrtPrice[1]), fromDecimal1, toDecimal1) : TickMath.sqrtPriceX64ToPrice(new BN19(priceResult.currentSqrtPrice[1]), toDecimal1, fromDecimal1);
|
|
9417
8777
|
const path1 = {
|
|
9418
8778
|
direction: path.a2b[1],
|
|
9419
8779
|
label: "Magma",
|
|
@@ -9432,7 +8792,7 @@ var RouterModuleV2 = class {
|
|
|
9432
8792
|
} else {
|
|
9433
8793
|
const fromDecimal = this.sdk.Router.tokenInfo(path.coinType[0]).decimals;
|
|
9434
8794
|
const toDecimal = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
|
|
9435
|
-
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new
|
|
8795
|
+
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new BN19(priceResult.currentSqrtPrice[0]), fromDecimal, toDecimal) : TickMath.sqrtPriceX64ToPrice(new BN19(priceResult.currentSqrtPrice[0]), toDecimal, fromDecimal);
|
|
9436
8796
|
const path0 = {
|
|
9437
8797
|
direction: path.a2b[0],
|
|
9438
8798
|
label: "Magma",
|
|
@@ -9517,7 +8877,7 @@ var RouterModuleV2 = class {
|
|
|
9517
8877
|
const priceResult = await this.sdk.Router.priceUseV1(
|
|
9518
8878
|
from,
|
|
9519
8879
|
to,
|
|
9520
|
-
new
|
|
8880
|
+
new BN19(amount),
|
|
9521
8881
|
byAmountIn,
|
|
9522
8882
|
priceSplitPoint,
|
|
9523
8883
|
partner,
|
|
@@ -9529,7 +8889,7 @@ var RouterModuleV2 = class {
|
|
|
9529
8889
|
if (path.poolAddress.length > 1) {
|
|
9530
8890
|
const fromDecimal0 = this.sdk.Router.tokenInfo(path.coinType[0]).decimals;
|
|
9531
8891
|
const toDecimal0 = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
|
|
9532
|
-
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new
|
|
8892
|
+
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new BN19(priceResult.currentSqrtPrice[0]), fromDecimal0, toDecimal0) : TickMath.sqrtPriceX64ToPrice(new BN19(priceResult.currentSqrtPrice[0]), toDecimal0, fromDecimal0);
|
|
9533
8893
|
const path0 = {
|
|
9534
8894
|
direction: path.a2b[0],
|
|
9535
8895
|
label: "Magma",
|
|
@@ -9546,7 +8906,7 @@ var RouterModuleV2 = class {
|
|
|
9546
8906
|
};
|
|
9547
8907
|
const fromDecimal1 = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
|
|
9548
8908
|
const toDecimal1 = this.sdk.Router.tokenInfo(path.coinType[2]).decimals;
|
|
9549
|
-
const currentPrice1 = path.a2b[1] ? TickMath.sqrtPriceX64ToPrice(new
|
|
8909
|
+
const currentPrice1 = path.a2b[1] ? TickMath.sqrtPriceX64ToPrice(new BN19(priceResult.currentSqrtPrice[1]), fromDecimal1, toDecimal1) : TickMath.sqrtPriceX64ToPrice(new BN19(priceResult.currentSqrtPrice[1]), toDecimal1, fromDecimal1);
|
|
9550
8910
|
const path1 = {
|
|
9551
8911
|
direction: path.a2b[1],
|
|
9552
8912
|
label: "Magma",
|
|
@@ -9565,7 +8925,7 @@ var RouterModuleV2 = class {
|
|
|
9565
8925
|
} else {
|
|
9566
8926
|
const fromDecimal = this.sdk.Router.tokenInfo(path.coinType[0]).decimals;
|
|
9567
8927
|
const toDecimal = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
|
|
9568
|
-
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new
|
|
8928
|
+
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new BN19(priceResult.currentSqrtPrice[0]), fromDecimal, toDecimal) : TickMath.sqrtPriceX64ToPrice(new BN19(priceResult.currentSqrtPrice[0]), toDecimal, fromDecimal);
|
|
9569
8929
|
const path0 = {
|
|
9570
8930
|
direction: path.a2b[0],
|
|
9571
8931
|
label: "Magma",
|
|
@@ -10489,7 +9849,7 @@ var GaugeModule = class {
|
|
|
10489
9849
|
|
|
10490
9850
|
// src/modules/dlmm.ts
|
|
10491
9851
|
import { Transaction as Transaction12 } from "@mysten/sui/transactions";
|
|
10492
|
-
import
|
|
9852
|
+
import Decimal7 from "decimal.js";
|
|
10493
9853
|
import { get_real_id_from_price, get_storage_id_from_real_id } from "@magmaprotocol/calc_dlmm";
|
|
10494
9854
|
var DlmmModule = class {
|
|
10495
9855
|
_sdk;
|
|
@@ -10562,9 +9922,9 @@ var DlmmModule = class {
|
|
|
10562
9922
|
}
|
|
10563
9923
|
// params price: input (b/(10^b_decimal))/(a/(10^a_decimal))
|
|
10564
9924
|
price_to_storage_id(price, bin_step, tokenADecimal, tokenBDecimal) {
|
|
10565
|
-
const priceDec = new
|
|
10566
|
-
const tenDec = new
|
|
10567
|
-
const twoDec = new
|
|
9925
|
+
const priceDec = new Decimal7(price);
|
|
9926
|
+
const tenDec = new Decimal7(10);
|
|
9927
|
+
const twoDec = new Decimal7(2);
|
|
10568
9928
|
const price_x128 = priceDec.mul(tenDec.pow(tokenBDecimal)).div(tenDec.pow(tokenADecimal)).mul(twoDec.pow(128));
|
|
10569
9929
|
const active_id = get_real_id_from_price(price_x128.toFixed(0).toString(), bin_step);
|
|
10570
9930
|
return get_storage_id_from_real_id(active_id);
|
|
@@ -11277,7 +10637,6 @@ export {
|
|
|
11277
10637
|
SUI_SYSTEM_STATE_OBJECT_ID,
|
|
11278
10638
|
SplitSwap,
|
|
11279
10639
|
SplitUnit,
|
|
11280
|
-
StrategyType,
|
|
11281
10640
|
SwapDirection,
|
|
11282
10641
|
SwapModule,
|
|
11283
10642
|
SwapUtils,
|
|
@@ -11299,10 +10658,6 @@ export {
|
|
|
11299
10658
|
adjustForSlippage,
|
|
11300
10659
|
asIntN,
|
|
11301
10660
|
asUintN,
|
|
11302
|
-
autoFillXByStrategy,
|
|
11303
|
-
autoFillXByWeight,
|
|
11304
|
-
autoFillYByStrategy,
|
|
11305
|
-
autoFillYByWeight,
|
|
11306
10661
|
bufferToHex,
|
|
11307
10662
|
buildClmmPositionName,
|
|
11308
10663
|
buildNFT,
|
|
@@ -11341,14 +10696,12 @@ export {
|
|
|
11341
10696
|
getAmountUnfixedDelta,
|
|
11342
10697
|
getCoinAFromLiquidity,
|
|
11343
10698
|
getCoinBFromLiquidity,
|
|
11344
|
-
getCoinXYForLiquidity,
|
|
11345
10699
|
getDefaultSuiInputType,
|
|
11346
10700
|
getDeltaA,
|
|
11347
10701
|
getDeltaB,
|
|
11348
10702
|
getDeltaDownFromOutput,
|
|
11349
10703
|
getDeltaUpFromInput,
|
|
11350
10704
|
getFutureTime,
|
|
11351
|
-
getLiquidityAndCoinYByCoinX,
|
|
11352
10705
|
getLiquidityFromCoinA,
|
|
11353
10706
|
getLiquidityFromCoinB,
|
|
11354
10707
|
getLowerSqrtPriceFromCoinA,
|
|
@@ -11372,7 +10725,6 @@ export {
|
|
|
11372
10725
|
getObjectType,
|
|
11373
10726
|
getObjectVersion,
|
|
11374
10727
|
getPackagerConfigs,
|
|
11375
|
-
getPriceOfBinByBinId,
|
|
11376
10728
|
getRewardInTickRange,
|
|
11377
10729
|
getSuiObjectData,
|
|
11378
10730
|
getTickDataFromUrlData,
|
|
@@ -11396,15 +10748,10 @@ export {
|
|
|
11396
10748
|
shortAddress,
|
|
11397
10749
|
shortString,
|
|
11398
10750
|
tickScore,
|
|
11399
|
-
toAmountAskSide,
|
|
11400
|
-
toAmountBidSide,
|
|
11401
|
-
toAmountBothSide,
|
|
11402
|
-
toAmountsBothSideByStrategy,
|
|
11403
10751
|
toBuffer,
|
|
11404
10752
|
toCoinAmount,
|
|
11405
10753
|
toDecimalsAmount,
|
|
11406
10754
|
transClmmpoolDataWithoutTicks,
|
|
11407
|
-
utf8to16
|
|
11408
|
-
withLiquiditySlippage
|
|
10755
|
+
utf8to16
|
|
11409
10756
|
};
|
|
11410
10757
|
//# sourceMappingURL=index.mjs.map
|