@aspan/sdk 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -43
- package/dist/index.d.mts +252 -248
- package/dist/index.d.ts +252 -248
- package/dist/index.js +144 -258
- package/dist/index.mjs +143 -258
- package/package.json +1 -1
- package/src/__tests__/router.test.ts +378 -0
- package/src/abi/router.ts +123 -202
- package/src/index.ts +3 -2
- package/src/router.ts +7 -91
- package/src/types.ts +27 -11
package/dist/index.js
CHANGED
|
@@ -38,6 +38,7 @@ __export(index_exports, {
|
|
|
38
38
|
createRouterReadClient: () => createRouterReadClient,
|
|
39
39
|
createRouterTestnetClient: () => createRouterTestnetClient,
|
|
40
40
|
createRouterTestnetReadClient: () => createRouterTestnetReadClient,
|
|
41
|
+
encodeV3Path: () => encodeV3Path,
|
|
41
42
|
formatAmount: () => formatAmount,
|
|
42
43
|
formatCR: () => formatCR,
|
|
43
44
|
formatFeeBPS: () => formatFeeBPS,
|
|
@@ -1461,7 +1462,7 @@ var import_chains2 = require("viem/chains");
|
|
|
1461
1462
|
|
|
1462
1463
|
// src/abi/router.ts
|
|
1463
1464
|
var RouterABI = [
|
|
1464
|
-
// ============ Core Functions ============
|
|
1465
|
+
// ============ Core Swap+Mint Functions ============
|
|
1465
1466
|
// swapAndMintApUSD
|
|
1466
1467
|
{
|
|
1467
1468
|
type: "function",
|
|
@@ -1475,15 +1476,13 @@ var RouterABI = [
|
|
|
1475
1476
|
{ name: "inputAmount", type: "uint256" },
|
|
1476
1477
|
{ name: "targetLST", type: "address" },
|
|
1477
1478
|
{ name: "minLSTOut", type: "uint256" },
|
|
1478
|
-
{ name: "poolFee", type: "uint24" }
|
|
1479
|
-
{ name: "useV2", type: "bool" }
|
|
1479
|
+
{ name: "poolFee", type: "uint24" }
|
|
1480
1480
|
]
|
|
1481
1481
|
},
|
|
1482
1482
|
{
|
|
1483
1483
|
name: "mintParams",
|
|
1484
1484
|
type: "tuple",
|
|
1485
1485
|
components: [
|
|
1486
|
-
{ name: "mintXBNB", type: "bool" },
|
|
1487
1486
|
{ name: "minMintOut", type: "uint256" },
|
|
1488
1487
|
{ name: "recipient", type: "address" },
|
|
1489
1488
|
{ name: "deadline", type: "uint256" }
|
|
@@ -1509,15 +1508,13 @@ var RouterABI = [
|
|
|
1509
1508
|
{ name: "inputAmount", type: "uint256" },
|
|
1510
1509
|
{ name: "targetLST", type: "address" },
|
|
1511
1510
|
{ name: "minLSTOut", type: "uint256" },
|
|
1512
|
-
{ name: "poolFee", type: "uint24" }
|
|
1513
|
-
{ name: "useV2", type: "bool" }
|
|
1511
|
+
{ name: "poolFee", type: "uint24" }
|
|
1514
1512
|
]
|
|
1515
1513
|
},
|
|
1516
1514
|
{
|
|
1517
1515
|
name: "mintParams",
|
|
1518
1516
|
type: "tuple",
|
|
1519
1517
|
components: [
|
|
1520
|
-
{ name: "mintXBNB", type: "bool" },
|
|
1521
1518
|
{ name: "minMintOut", type: "uint256" },
|
|
1522
1519
|
{ name: "recipient", type: "address" },
|
|
1523
1520
|
{ name: "deadline", type: "uint256" }
|
|
@@ -1530,6 +1527,7 @@ var RouterABI = [
|
|
|
1530
1527
|
],
|
|
1531
1528
|
stateMutability: "payable"
|
|
1532
1529
|
},
|
|
1530
|
+
// ============ Stake+Mint Functions ============
|
|
1533
1531
|
// stakeAndMint
|
|
1534
1532
|
{
|
|
1535
1533
|
type: "function",
|
|
@@ -1546,7 +1544,23 @@ var RouterABI = [
|
|
|
1546
1544
|
],
|
|
1547
1545
|
stateMutability: "payable"
|
|
1548
1546
|
},
|
|
1549
|
-
//
|
|
1547
|
+
// stakeAndMintApUSD (simplified)
|
|
1548
|
+
{
|
|
1549
|
+
type: "function",
|
|
1550
|
+
name: "stakeAndMintApUSD",
|
|
1551
|
+
inputs: [{ name: "minMintOut", type: "uint256" }],
|
|
1552
|
+
outputs: [{ name: "apUSDAmount", type: "uint256" }],
|
|
1553
|
+
stateMutability: "payable"
|
|
1554
|
+
},
|
|
1555
|
+
// stakeAndMintXBNB (simplified)
|
|
1556
|
+
{
|
|
1557
|
+
type: "function",
|
|
1558
|
+
name: "stakeAndMintXBNB",
|
|
1559
|
+
inputs: [{ name: "minMintOut", type: "uint256" }],
|
|
1560
|
+
outputs: [{ name: "xBNBAmount", type: "uint256" }],
|
|
1561
|
+
stateMutability: "payable"
|
|
1562
|
+
},
|
|
1563
|
+
// ============ Simplified Swap+Mint Functions ============
|
|
1550
1564
|
// swapAndMintApUSDDefault
|
|
1551
1565
|
{
|
|
1552
1566
|
type: "function",
|
|
@@ -1573,22 +1587,6 @@ var RouterABI = [
|
|
|
1573
1587
|
outputs: [{ name: "xBNBAmount", type: "uint256" }],
|
|
1574
1588
|
stateMutability: "payable"
|
|
1575
1589
|
},
|
|
1576
|
-
// stakeAndMintApUSD
|
|
1577
|
-
{
|
|
1578
|
-
type: "function",
|
|
1579
|
-
name: "stakeAndMintApUSD",
|
|
1580
|
-
inputs: [{ name: "minMintOut", type: "uint256" }],
|
|
1581
|
-
outputs: [{ name: "apUSDAmount", type: "uint256" }],
|
|
1582
|
-
stateMutability: "payable"
|
|
1583
|
-
},
|
|
1584
|
-
// stakeAndMintXBNB
|
|
1585
|
-
{
|
|
1586
|
-
type: "function",
|
|
1587
|
-
name: "stakeAndMintXBNB",
|
|
1588
|
-
inputs: [{ name: "minMintOut", type: "uint256" }],
|
|
1589
|
-
outputs: [{ name: "xBNBAmount", type: "uint256" }],
|
|
1590
|
-
stateMutability: "payable"
|
|
1591
|
-
},
|
|
1592
1590
|
// ============ Direct Mint/Redeem Functions ============
|
|
1593
1591
|
// mintApUSD
|
|
1594
1592
|
{
|
|
@@ -1638,7 +1636,7 @@ var RouterABI = [
|
|
|
1638
1636
|
outputs: [{ name: "lstAmount", type: "uint256" }],
|
|
1639
1637
|
stateMutability: "nonpayable"
|
|
1640
1638
|
},
|
|
1641
|
-
// ============ Redeem
|
|
1639
|
+
// ============ Redeem + Swap Functions (V3 path) ============
|
|
1642
1640
|
// redeemApUSDAndSwap
|
|
1643
1641
|
{
|
|
1644
1642
|
type: "function",
|
|
@@ -1646,11 +1644,9 @@ var RouterABI = [
|
|
|
1646
1644
|
inputs: [
|
|
1647
1645
|
{ name: "lst", type: "address" },
|
|
1648
1646
|
{ name: "apUSDAmount", type: "uint256" },
|
|
1649
|
-
{ name: "
|
|
1647
|
+
{ name: "path", type: "bytes" },
|
|
1650
1648
|
{ name: "minOut", type: "uint256" },
|
|
1651
|
-
{ name: "deadline", type: "uint256" }
|
|
1652
|
-
{ name: "useV2", type: "bool" },
|
|
1653
|
-
{ name: "poolFee", type: "uint24" }
|
|
1649
|
+
{ name: "deadline", type: "uint256" }
|
|
1654
1650
|
],
|
|
1655
1651
|
outputs: [{ name: "outputAmount", type: "uint256" }],
|
|
1656
1652
|
stateMutability: "nonpayable"
|
|
@@ -1662,39 +1658,11 @@ var RouterABI = [
|
|
|
1662
1658
|
inputs: [
|
|
1663
1659
|
{ name: "lst", type: "address" },
|
|
1664
1660
|
{ name: "xBNBAmount", type: "uint256" },
|
|
1665
|
-
{ name: "
|
|
1661
|
+
{ name: "path", type: "bytes" },
|
|
1666
1662
|
{ name: "minOut", type: "uint256" },
|
|
1667
|
-
{ name: "deadline", type: "uint256" },
|
|
1668
|
-
{ name: "useV2", type: "bool" },
|
|
1669
|
-
{ name: "poolFee", type: "uint24" }
|
|
1670
|
-
],
|
|
1671
|
-
outputs: [{ name: "outputAmount", type: "uint256" }],
|
|
1672
|
-
stateMutability: "nonpayable"
|
|
1673
|
-
},
|
|
1674
|
-
// redeemApUSDAndUnstake
|
|
1675
|
-
{
|
|
1676
|
-
type: "function",
|
|
1677
|
-
name: "redeemApUSDAndUnstake",
|
|
1678
|
-
inputs: [
|
|
1679
|
-
{ name: "lst", type: "address" },
|
|
1680
|
-
{ name: "apUSDAmount", type: "uint256" },
|
|
1681
|
-
{ name: "minBNBOut", type: "uint256" },
|
|
1682
1663
|
{ name: "deadline", type: "uint256" }
|
|
1683
1664
|
],
|
|
1684
|
-
outputs: [{ name: "
|
|
1685
|
-
stateMutability: "nonpayable"
|
|
1686
|
-
},
|
|
1687
|
-
// redeemXBNBAndUnstake
|
|
1688
|
-
{
|
|
1689
|
-
type: "function",
|
|
1690
|
-
name: "redeemXBNBAndUnstake",
|
|
1691
|
-
inputs: [
|
|
1692
|
-
{ name: "lst", type: "address" },
|
|
1693
|
-
{ name: "xBNBAmount", type: "uint256" },
|
|
1694
|
-
{ name: "minBNBOut", type: "uint256" },
|
|
1695
|
-
{ name: "deadline", type: "uint256" }
|
|
1696
|
-
],
|
|
1697
|
-
outputs: [{ name: "bnbAmount", type: "uint256" }],
|
|
1665
|
+
outputs: [{ name: "outputAmount", type: "uint256" }],
|
|
1698
1666
|
stateMutability: "nonpayable"
|
|
1699
1667
|
},
|
|
1700
1668
|
// ============ Native Unstake Functions ============
|
|
@@ -1729,71 +1697,38 @@ var RouterABI = [
|
|
|
1729
1697
|
stateMutability: "nonpayable"
|
|
1730
1698
|
},
|
|
1731
1699
|
// ============ View Functions ============
|
|
1732
|
-
//
|
|
1733
|
-
{
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
},
|
|
1740
|
-
|
|
1700
|
+
// Token addresses
|
|
1701
|
+
{ type: "function", name: "wbnb", inputs: [], outputs: [{ type: "address" }], stateMutability: "view" },
|
|
1702
|
+
{ type: "function", name: "usdt", inputs: [], outputs: [{ type: "address" }], stateMutability: "view" },
|
|
1703
|
+
{ type: "function", name: "usdc", inputs: [], outputs: [{ type: "address" }], stateMutability: "view" },
|
|
1704
|
+
{ type: "function", name: "slisBNB", inputs: [], outputs: [{ type: "address" }], stateMutability: "view" },
|
|
1705
|
+
{ type: "function", name: "asBNB", inputs: [], outputs: [{ type: "address" }], stateMutability: "view" },
|
|
1706
|
+
{ type: "function", name: "wclisBNB", inputs: [], outputs: [{ type: "address" }], stateMutability: "view" },
|
|
1707
|
+
{ type: "function", name: "apUSD", inputs: [], outputs: [{ type: "address" }], stateMutability: "view" },
|
|
1708
|
+
{ type: "function", name: "xBNB", inputs: [], outputs: [{ type: "address" }], stateMutability: "view" },
|
|
1709
|
+
// Protocol addresses
|
|
1710
|
+
{ type: "function", name: "diamond", inputs: [], outputs: [{ type: "address" }], stateMutability: "view" },
|
|
1711
|
+
{ type: "function", name: "pancakeV3Router", inputs: [], outputs: [{ type: "address" }], stateMutability: "view" },
|
|
1712
|
+
{ type: "function", name: "listaStakeManager", inputs: [], outputs: [{ type: "address" }], stateMutability: "view" },
|
|
1713
|
+
{ type: "function", name: "astherusMinter", inputs: [], outputs: [{ type: "address" }], stateMutability: "view" },
|
|
1714
|
+
{ type: "function", name: "slisBNBProvider", inputs: [], outputs: [{ type: "address" }], stateMutability: "view" },
|
|
1715
|
+
// Configuration
|
|
1716
|
+
{ type: "function", name: "defaultLST", inputs: [], outputs: [{ type: "address" }], stateMutability: "view" },
|
|
1741
1717
|
{
|
|
1742
1718
|
type: "function",
|
|
1743
1719
|
name: "supportedInputTokens",
|
|
1744
1720
|
inputs: [{ name: "token", type: "address" }],
|
|
1745
|
-
outputs: [{
|
|
1721
|
+
outputs: [{ type: "bool" }],
|
|
1746
1722
|
stateMutability: "view"
|
|
1747
1723
|
},
|
|
1748
|
-
// supportedLSTs
|
|
1749
1724
|
{
|
|
1750
1725
|
type: "function",
|
|
1751
1726
|
name: "supportedLSTs",
|
|
1752
1727
|
inputs: [{ name: "lst", type: "address" }],
|
|
1753
|
-
outputs: [{
|
|
1754
|
-
stateMutability: "view"
|
|
1755
|
-
},
|
|
1756
|
-
// diamond
|
|
1757
|
-
{
|
|
1758
|
-
type: "function",
|
|
1759
|
-
name: "diamond",
|
|
1760
|
-
inputs: [],
|
|
1761
|
-
outputs: [{ name: "", type: "address" }],
|
|
1762
|
-
stateMutability: "view"
|
|
1763
|
-
},
|
|
1764
|
-
// getExpectedMintOutput
|
|
1765
|
-
{
|
|
1766
|
-
type: "function",
|
|
1767
|
-
name: "getExpectedMintOutput",
|
|
1768
|
-
inputs: [
|
|
1769
|
-
{ name: "inputToken", type: "address" },
|
|
1770
|
-
{ name: "inputAmount", type: "uint256" },
|
|
1771
|
-
{ name: "targetLST", type: "address" },
|
|
1772
|
-
{ name: "isXBNB", type: "bool" }
|
|
1773
|
-
],
|
|
1774
|
-
outputs: [
|
|
1775
|
-
{ name: "expectedLST", type: "uint256" },
|
|
1776
|
-
{ name: "expectedMint", type: "uint256" }
|
|
1777
|
-
],
|
|
1728
|
+
outputs: [{ type: "bool" }],
|
|
1778
1729
|
stateMutability: "view"
|
|
1779
1730
|
},
|
|
1780
|
-
//
|
|
1781
|
-
{
|
|
1782
|
-
type: "function",
|
|
1783
|
-
name: "getExpectedRedeemOutput",
|
|
1784
|
-
inputs: [
|
|
1785
|
-
{ name: "isXBNB", type: "bool" },
|
|
1786
|
-
{ name: "redeemAmount", type: "uint256" },
|
|
1787
|
-
{ name: "lst", type: "address" },
|
|
1788
|
-
{ name: "outputToken", type: "address" }
|
|
1789
|
-
],
|
|
1790
|
-
outputs: [
|
|
1791
|
-
{ name: "expectedLST", type: "uint256" },
|
|
1792
|
-
{ name: "expectedOutput", type: "uint256" }
|
|
1793
|
-
],
|
|
1794
|
-
stateMutability: "view"
|
|
1795
|
-
},
|
|
1796
|
-
// previewMintApUSD
|
|
1731
|
+
// Preview functions
|
|
1797
1732
|
{
|
|
1798
1733
|
type: "function",
|
|
1799
1734
|
name: "previewMintApUSD",
|
|
@@ -1804,7 +1739,6 @@ var RouterABI = [
|
|
|
1804
1739
|
outputs: [{ name: "apUSDAmount", type: "uint256" }],
|
|
1805
1740
|
stateMutability: "view"
|
|
1806
1741
|
},
|
|
1807
|
-
// previewMintXBNB
|
|
1808
1742
|
{
|
|
1809
1743
|
type: "function",
|
|
1810
1744
|
name: "previewMintXBNB",
|
|
@@ -1815,7 +1749,6 @@ var RouterABI = [
|
|
|
1815
1749
|
outputs: [{ name: "xBNBAmount", type: "uint256" }],
|
|
1816
1750
|
stateMutability: "view"
|
|
1817
1751
|
},
|
|
1818
|
-
// previewRedeemApUSD
|
|
1819
1752
|
{
|
|
1820
1753
|
type: "function",
|
|
1821
1754
|
name: "previewRedeemApUSD",
|
|
@@ -1826,7 +1759,6 @@ var RouterABI = [
|
|
|
1826
1759
|
outputs: [{ name: "lstAmount", type: "uint256" }],
|
|
1827
1760
|
stateMutability: "view"
|
|
1828
1761
|
},
|
|
1829
|
-
// previewRedeemXBNB
|
|
1830
1762
|
{
|
|
1831
1763
|
type: "function",
|
|
1832
1764
|
name: "previewRedeemXBNB",
|
|
@@ -1837,15 +1769,14 @@ var RouterABI = [
|
|
|
1837
1769
|
outputs: [{ name: "lstAmount", type: "uint256" }],
|
|
1838
1770
|
stateMutability: "view"
|
|
1839
1771
|
},
|
|
1840
|
-
//
|
|
1772
|
+
// Withdrawal tracking
|
|
1841
1773
|
{
|
|
1842
1774
|
type: "function",
|
|
1843
1775
|
name: "getUserWithdrawalIndices",
|
|
1844
1776
|
inputs: [{ name: "user", type: "address" }],
|
|
1845
|
-
outputs: [{
|
|
1777
|
+
outputs: [{ type: "uint256[]" }],
|
|
1846
1778
|
stateMutability: "view"
|
|
1847
1779
|
},
|
|
1848
|
-
// getWithdrawalStatus
|
|
1849
1780
|
{
|
|
1850
1781
|
type: "function",
|
|
1851
1782
|
name: "getWithdrawalStatus",
|
|
@@ -1856,116 +1787,107 @@ var RouterABI = [
|
|
|
1856
1787
|
],
|
|
1857
1788
|
stateMutability: "view"
|
|
1858
1789
|
},
|
|
1859
|
-
// Immutable addresses
|
|
1860
1790
|
{
|
|
1861
1791
|
type: "function",
|
|
1862
|
-
name: "
|
|
1863
|
-
inputs: [],
|
|
1864
|
-
outputs: [
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
inputs: [],
|
|
1871
|
-
outputs: [{ name: "", type: "address" }],
|
|
1872
|
-
stateMutability: "view"
|
|
1873
|
-
},
|
|
1874
|
-
{
|
|
1875
|
-
type: "function",
|
|
1876
|
-
name: "usdc",
|
|
1877
|
-
inputs: [],
|
|
1878
|
-
outputs: [{ name: "", type: "address" }],
|
|
1792
|
+
name: "withdrawalRequests",
|
|
1793
|
+
inputs: [{ name: "index", type: "uint256" }],
|
|
1794
|
+
outputs: [
|
|
1795
|
+
{ name: "user", type: "address" },
|
|
1796
|
+
{ name: "listaIdx", type: "uint256" },
|
|
1797
|
+
{ name: "slisBNBAmount", type: "uint256" },
|
|
1798
|
+
{ name: "claimed", type: "bool" }
|
|
1799
|
+
],
|
|
1879
1800
|
stateMutability: "view"
|
|
1880
1801
|
},
|
|
1802
|
+
// ============ Admin Functions ============
|
|
1803
|
+
{ type: "function", name: "owner", inputs: [], outputs: [{ type: "address" }], stateMutability: "view" },
|
|
1881
1804
|
{
|
|
1882
1805
|
type: "function",
|
|
1883
|
-
name: "
|
|
1884
|
-
inputs: [],
|
|
1885
|
-
outputs: [
|
|
1886
|
-
stateMutability: "
|
|
1806
|
+
name: "setDefaultLST",
|
|
1807
|
+
inputs: [{ name: "lst", type: "address" }],
|
|
1808
|
+
outputs: [],
|
|
1809
|
+
stateMutability: "nonpayable"
|
|
1887
1810
|
},
|
|
1888
1811
|
{
|
|
1889
1812
|
type: "function",
|
|
1890
|
-
name: "
|
|
1891
|
-
inputs: [],
|
|
1892
|
-
outputs: [
|
|
1893
|
-
stateMutability: "
|
|
1813
|
+
name: "addSupportedInputToken",
|
|
1814
|
+
inputs: [{ name: "token", type: "address" }],
|
|
1815
|
+
outputs: [],
|
|
1816
|
+
stateMutability: "nonpayable"
|
|
1894
1817
|
},
|
|
1895
1818
|
{
|
|
1896
1819
|
type: "function",
|
|
1897
|
-
name: "
|
|
1898
|
-
inputs: [],
|
|
1899
|
-
outputs: [
|
|
1900
|
-
stateMutability: "
|
|
1820
|
+
name: "addSupportedLST",
|
|
1821
|
+
inputs: [{ name: "lst", type: "address" }],
|
|
1822
|
+
outputs: [],
|
|
1823
|
+
stateMutability: "nonpayable"
|
|
1901
1824
|
},
|
|
1902
1825
|
{
|
|
1903
1826
|
type: "function",
|
|
1904
|
-
name: "
|
|
1905
|
-
inputs: [
|
|
1906
|
-
|
|
1907
|
-
|
|
1827
|
+
name: "rescueTokens",
|
|
1828
|
+
inputs: [
|
|
1829
|
+
{ name: "token", type: "address" },
|
|
1830
|
+
{ name: "amount", type: "uint256" }
|
|
1831
|
+
],
|
|
1832
|
+
outputs: [],
|
|
1833
|
+
stateMutability: "nonpayable"
|
|
1908
1834
|
},
|
|
1909
1835
|
{
|
|
1910
1836
|
type: "function",
|
|
1911
|
-
name: "
|
|
1912
|
-
inputs: [],
|
|
1913
|
-
outputs: [
|
|
1914
|
-
stateMutability: "
|
|
1837
|
+
name: "transferOwnership",
|
|
1838
|
+
inputs: [{ name: "newOwner", type: "address" }],
|
|
1839
|
+
outputs: [],
|
|
1840
|
+
stateMutability: "nonpayable"
|
|
1915
1841
|
},
|
|
1842
|
+
{ type: "function", name: "renounceOwnership", inputs: [], outputs: [], stateMutability: "nonpayable" },
|
|
1916
1843
|
// ============ Events ============
|
|
1917
|
-
// SwapAndMint
|
|
1918
1844
|
{
|
|
1919
1845
|
type: "event",
|
|
1920
1846
|
name: "SwapAndMint",
|
|
1921
1847
|
inputs: [
|
|
1922
1848
|
{ name: "user", type: "address", indexed: true },
|
|
1923
|
-
{ name: "inputToken", type: "address", indexed:
|
|
1849
|
+
{ name: "inputToken", type: "address", indexed: false },
|
|
1924
1850
|
{ name: "inputAmount", type: "uint256", indexed: false },
|
|
1925
|
-
{ name: "
|
|
1851
|
+
{ name: "lst", type: "address", indexed: false },
|
|
1926
1852
|
{ name: "lstAmount", type: "uint256", indexed: false },
|
|
1927
1853
|
{ name: "mintedToken", type: "address", indexed: false },
|
|
1928
1854
|
{ name: "mintedAmount", type: "uint256", indexed: false }
|
|
1929
1855
|
]
|
|
1930
1856
|
},
|
|
1931
|
-
// StakeAndMint
|
|
1932
1857
|
{
|
|
1933
1858
|
type: "event",
|
|
1934
1859
|
name: "StakeAndMint",
|
|
1935
1860
|
inputs: [
|
|
1936
1861
|
{ name: "user", type: "address", indexed: true },
|
|
1937
1862
|
{ name: "bnbAmount", type: "uint256", indexed: false },
|
|
1938
|
-
{ name: "
|
|
1863
|
+
{ name: "lst", type: "address", indexed: false },
|
|
1939
1864
|
{ name: "lstAmount", type: "uint256", indexed: false },
|
|
1940
|
-
{ name: "mintedToken", type: "address", indexed:
|
|
1865
|
+
{ name: "mintedToken", type: "address", indexed: false },
|
|
1941
1866
|
{ name: "mintedAmount", type: "uint256", indexed: false }
|
|
1942
1867
|
]
|
|
1943
1868
|
},
|
|
1944
|
-
// Mint
|
|
1945
1869
|
{
|
|
1946
1870
|
type: "event",
|
|
1947
1871
|
name: "Mint",
|
|
1948
1872
|
inputs: [
|
|
1949
1873
|
{ name: "user", type: "address", indexed: true },
|
|
1950
|
-
{ name: "lst", type: "address", indexed:
|
|
1874
|
+
{ name: "lst", type: "address", indexed: false },
|
|
1951
1875
|
{ name: "lstAmount", type: "uint256", indexed: false },
|
|
1952
|
-
{ name: "mintedToken", type: "address", indexed:
|
|
1876
|
+
{ name: "mintedToken", type: "address", indexed: false },
|
|
1953
1877
|
{ name: "mintedAmount", type: "uint256", indexed: false }
|
|
1954
1878
|
]
|
|
1955
1879
|
},
|
|
1956
|
-
// Redeem
|
|
1957
1880
|
{
|
|
1958
1881
|
type: "event",
|
|
1959
1882
|
name: "Redeem",
|
|
1960
1883
|
inputs: [
|
|
1961
1884
|
{ name: "user", type: "address", indexed: true },
|
|
1962
|
-
{ name: "redeemedToken", type: "address", indexed:
|
|
1885
|
+
{ name: "redeemedToken", type: "address", indexed: false },
|
|
1963
1886
|
{ name: "redeemedAmount", type: "uint256", indexed: false },
|
|
1964
|
-
{ name: "lst", type: "address", indexed:
|
|
1887
|
+
{ name: "lst", type: "address", indexed: false },
|
|
1965
1888
|
{ name: "lstAmount", type: "uint256", indexed: false }
|
|
1966
1889
|
]
|
|
1967
1890
|
},
|
|
1968
|
-
// RedeemAndSwap
|
|
1969
1891
|
{
|
|
1970
1892
|
type: "event",
|
|
1971
1893
|
name: "RedeemAndSwap",
|
|
@@ -1975,57 +1897,69 @@ var RouterABI = [
|
|
|
1975
1897
|
{ name: "redeemedAmount", type: "uint256", indexed: false },
|
|
1976
1898
|
{ name: "lst", type: "address", indexed: false },
|
|
1977
1899
|
{ name: "lstAmount", type: "uint256", indexed: false },
|
|
1978
|
-
{ name: "outputToken", type: "address", indexed:
|
|
1900
|
+
{ name: "outputToken", type: "address", indexed: false },
|
|
1979
1901
|
{ name: "outputAmount", type: "uint256", indexed: false }
|
|
1980
1902
|
]
|
|
1981
1903
|
},
|
|
1982
|
-
// UnstakeRequested
|
|
1983
1904
|
{
|
|
1984
1905
|
type: "event",
|
|
1985
1906
|
name: "UnstakeRequested",
|
|
1986
1907
|
inputs: [
|
|
1987
1908
|
{ name: "user", type: "address", indexed: true },
|
|
1988
|
-
{ name: "requestIndex", type: "uint256", indexed:
|
|
1909
|
+
{ name: "requestIndex", type: "uint256", indexed: false },
|
|
1989
1910
|
{ name: "redeemedToken", type: "address", indexed: false },
|
|
1990
1911
|
{ name: "redeemedAmount", type: "uint256", indexed: false },
|
|
1991
1912
|
{ name: "slisBNBAmount", type: "uint256", indexed: false }
|
|
1992
1913
|
]
|
|
1993
1914
|
},
|
|
1994
|
-
// UnstakeClaimed
|
|
1995
1915
|
{
|
|
1996
1916
|
type: "event",
|
|
1997
1917
|
name: "UnstakeClaimed",
|
|
1998
1918
|
inputs: [
|
|
1999
1919
|
{ name: "user", type: "address", indexed: true },
|
|
2000
|
-
{ name: "requestIndex", type: "uint256", indexed:
|
|
1920
|
+
{ name: "requestIndex", type: "uint256", indexed: false },
|
|
2001
1921
|
{ name: "bnbAmount", type: "uint256", indexed: false }
|
|
2002
1922
|
]
|
|
2003
1923
|
},
|
|
2004
|
-
// DefaultLSTUpdated
|
|
2005
1924
|
{
|
|
2006
1925
|
type: "event",
|
|
2007
1926
|
name: "DefaultLSTUpdated",
|
|
2008
1927
|
inputs: [
|
|
2009
|
-
{ name: "oldLST", type: "address", indexed:
|
|
2010
|
-
{ name: "newLST", type: "address", indexed:
|
|
1928
|
+
{ name: "oldLST", type: "address", indexed: false },
|
|
1929
|
+
{ name: "newLST", type: "address", indexed: false }
|
|
1930
|
+
]
|
|
1931
|
+
},
|
|
1932
|
+
{
|
|
1933
|
+
type: "event",
|
|
1934
|
+
name: "OwnershipTransferred",
|
|
1935
|
+
inputs: [
|
|
1936
|
+
{ name: "previousOwner", type: "address", indexed: true },
|
|
1937
|
+
{ name: "newOwner", type: "address", indexed: true }
|
|
2011
1938
|
]
|
|
2012
1939
|
},
|
|
2013
1940
|
// ============ Errors ============
|
|
2014
|
-
{ type: "error", name: "UnsupportedInputToken", inputs: [] },
|
|
2015
|
-
{ type: "error", name: "UnsupportedLST", inputs: [] },
|
|
2016
1941
|
{ type: "error", name: "DeadlineExpired", inputs: [] },
|
|
1942
|
+
{ type: "error", name: "DefaultLSTNotSet", inputs: [] },
|
|
2017
1943
|
{ type: "error", name: "InsufficientOutput", inputs: [] },
|
|
2018
|
-
{ type: "error", name: "
|
|
1944
|
+
{ type: "error", name: "InvalidPoolFee", inputs: [] },
|
|
2019
1945
|
{ type: "error", name: "InvalidRecipient", inputs: [] },
|
|
2020
|
-
{ type: "error", name: "
|
|
1946
|
+
{ type: "error", name: "InvalidWithdrawalRequest", inputs: [] },
|
|
2021
1947
|
{ type: "error", name: "MintFailed", inputs: [] },
|
|
2022
1948
|
{ type: "error", name: "NativeTransferFailed", inputs: [] },
|
|
2023
|
-
{ type: "error", name: "
|
|
2024
|
-
{ type: "error", name: "
|
|
2025
|
-
{ type: "error", name: "
|
|
2026
|
-
{ type: "error", name: "
|
|
1949
|
+
{ type: "error", name: "OnlySlisBNBSupported", inputs: [] },
|
|
1950
|
+
{ type: "error", name: "SwapFailed", inputs: [] },
|
|
1951
|
+
{ type: "error", name: "UnsupportedInputToken", inputs: [] },
|
|
1952
|
+
{ type: "error", name: "UnsupportedLST", inputs: [] },
|
|
1953
|
+
{ type: "error", name: "V3PoolNotFound", inputs: [] },
|
|
2027
1954
|
{ type: "error", name: "WithdrawalAlreadyClaimed", inputs: [] },
|
|
2028
|
-
{ type: "error", name: "
|
|
1955
|
+
{ type: "error", name: "WithdrawalNotClaimable", inputs: [] },
|
|
1956
|
+
{ type: "error", name: "ZeroAmount", inputs: [] },
|
|
1957
|
+
{ type: "error", name: "ReentrancyGuardReentrantCall", inputs: [] },
|
|
1958
|
+
{ type: "error", name: "OwnableInvalidOwner", inputs: [{ name: "owner", type: "address" }] },
|
|
1959
|
+
{ type: "error", name: "OwnableUnauthorizedAccount", inputs: [{ name: "account", type: "address" }] },
|
|
1960
|
+
{ type: "error", name: "SafeERC20FailedOperation", inputs: [{ name: "token", type: "address" }] },
|
|
1961
|
+
// Receive
|
|
1962
|
+
{ type: "receive", stateMutability: "payable" }
|
|
2029
1963
|
];
|
|
2030
1964
|
|
|
2031
1965
|
// src/router.ts
|
|
@@ -2084,36 +2018,6 @@ var AspanRouterReadClient = class {
|
|
|
2084
2018
|
functionName: "diamond"
|
|
2085
2019
|
});
|
|
2086
2020
|
}
|
|
2087
|
-
/**
|
|
2088
|
-
* Get expected output from a swap and mint operation
|
|
2089
|
-
*/
|
|
2090
|
-
async getExpectedMintOutput(inputToken, inputAmount, targetLST, isXBNB) {
|
|
2091
|
-
const result = await this.publicClient.readContract({
|
|
2092
|
-
address: this.routerAddress,
|
|
2093
|
-
abi: RouterABI,
|
|
2094
|
-
functionName: "getExpectedMintOutput",
|
|
2095
|
-
args: [inputToken, inputAmount, targetLST, isXBNB]
|
|
2096
|
-
});
|
|
2097
|
-
return {
|
|
2098
|
-
expectedLST: result[0],
|
|
2099
|
-
expectedMint: result[1]
|
|
2100
|
-
};
|
|
2101
|
-
}
|
|
2102
|
-
/**
|
|
2103
|
-
* Get expected output from a redeem and swap operation
|
|
2104
|
-
*/
|
|
2105
|
-
async getExpectedRedeemOutput(isXBNB, redeemAmount, lst, outputToken) {
|
|
2106
|
-
const result = await this.publicClient.readContract({
|
|
2107
|
-
address: this.routerAddress,
|
|
2108
|
-
abi: RouterABI,
|
|
2109
|
-
functionName: "getExpectedRedeemOutput",
|
|
2110
|
-
args: [isXBNB, redeemAmount, lst, outputToken]
|
|
2111
|
-
});
|
|
2112
|
-
return {
|
|
2113
|
-
expectedLST: result[0],
|
|
2114
|
-
expectedMint: result[1]
|
|
2115
|
-
};
|
|
2116
|
-
}
|
|
2117
2021
|
/**
|
|
2118
2022
|
* Preview apUSD mint output for a given LST amount
|
|
2119
2023
|
*/
|
|
@@ -2277,11 +2181,9 @@ var AspanRouterClient = class extends AspanRouterReadClient {
|
|
|
2277
2181
|
inputAmount: params.swapParams.inputAmount,
|
|
2278
2182
|
targetLST: params.swapParams.targetLST,
|
|
2279
2183
|
minLSTOut: params.swapParams.minLSTOut,
|
|
2280
|
-
poolFee: params.swapParams.poolFee
|
|
2281
|
-
useV2: params.swapParams.useV2
|
|
2184
|
+
poolFee: params.swapParams.poolFee
|
|
2282
2185
|
},
|
|
2283
2186
|
{
|
|
2284
|
-
mintXBNB: params.mintParams.mintXBNB,
|
|
2285
2187
|
minMintOut: params.mintParams.minMintOut,
|
|
2286
2188
|
recipient: params.mintParams.recipient,
|
|
2287
2189
|
deadline: params.mintParams.deadline
|
|
@@ -2307,11 +2209,9 @@ var AspanRouterClient = class extends AspanRouterReadClient {
|
|
|
2307
2209
|
inputAmount: params.swapParams.inputAmount,
|
|
2308
2210
|
targetLST: params.swapParams.targetLST,
|
|
2309
2211
|
minLSTOut: params.swapParams.minLSTOut,
|
|
2310
|
-
poolFee: params.swapParams.poolFee
|
|
2311
|
-
useV2: params.swapParams.useV2
|
|
2212
|
+
poolFee: params.swapParams.poolFee
|
|
2312
2213
|
},
|
|
2313
2214
|
{
|
|
2314
|
-
mintXBNB: params.mintParams.mintXBNB,
|
|
2315
2215
|
minMintOut: params.mintParams.minMintOut,
|
|
2316
2216
|
recipient: params.mintParams.recipient,
|
|
2317
2217
|
deadline: params.mintParams.deadline
|
|
@@ -2463,7 +2363,8 @@ var AspanRouterClient = class extends AspanRouterReadClient {
|
|
|
2463
2363
|
}
|
|
2464
2364
|
// ============ Redeem and Swap Functions ============
|
|
2465
2365
|
/**
|
|
2466
|
-
* Redeem apUSD and swap LST to output token
|
|
2366
|
+
* Redeem apUSD and swap LST to output token via V3 path
|
|
2367
|
+
* @param params.path - PancakeSwap V3 encoded path (use encodeV3Path helper)
|
|
2467
2368
|
*/
|
|
2468
2369
|
async redeemApUSDAndSwap(params) {
|
|
2469
2370
|
return this.walletClient.writeContract({
|
|
@@ -2475,16 +2376,15 @@ var AspanRouterClient = class extends AspanRouterReadClient {
|
|
|
2475
2376
|
args: [
|
|
2476
2377
|
params.lst,
|
|
2477
2378
|
params.amount,
|
|
2478
|
-
params.
|
|
2379
|
+
params.path,
|
|
2479
2380
|
params.minOut,
|
|
2480
|
-
params.deadline
|
|
2481
|
-
params.useV2,
|
|
2482
|
-
params.poolFee
|
|
2381
|
+
params.deadline
|
|
2483
2382
|
]
|
|
2484
2383
|
});
|
|
2485
2384
|
}
|
|
2486
2385
|
/**
|
|
2487
|
-
* Redeem xBNB and swap LST to output token
|
|
2386
|
+
* Redeem xBNB and swap LST to output token via V3 path
|
|
2387
|
+
* @param params.path - PancakeSwap V3 encoded path (use encodeV3Path helper)
|
|
2488
2388
|
*/
|
|
2489
2389
|
async redeemXBNBAndSwap(params) {
|
|
2490
2390
|
return this.walletClient.writeContract({
|
|
@@ -2496,40 +2396,12 @@ var AspanRouterClient = class extends AspanRouterReadClient {
|
|
|
2496
2396
|
args: [
|
|
2497
2397
|
params.lst,
|
|
2498
2398
|
params.amount,
|
|
2499
|
-
params.
|
|
2399
|
+
params.path,
|
|
2500
2400
|
params.minOut,
|
|
2501
|
-
params.deadline
|
|
2502
|
-
params.useV2,
|
|
2503
|
-
params.poolFee
|
|
2401
|
+
params.deadline
|
|
2504
2402
|
]
|
|
2505
2403
|
});
|
|
2506
2404
|
}
|
|
2507
|
-
/**
|
|
2508
|
-
* Redeem apUSD and instantly unstake LST to native BNB via DEX
|
|
2509
|
-
*/
|
|
2510
|
-
async redeemApUSDAndUnstake(params) {
|
|
2511
|
-
return this.walletClient.writeContract({
|
|
2512
|
-
chain: this.chain,
|
|
2513
|
-
account: this.walletClient.account,
|
|
2514
|
-
address: this.routerAddress,
|
|
2515
|
-
abi: RouterABI,
|
|
2516
|
-
functionName: "redeemApUSDAndUnstake",
|
|
2517
|
-
args: [params.lst, params.amount, params.minBNBOut, params.deadline]
|
|
2518
|
-
});
|
|
2519
|
-
}
|
|
2520
|
-
/**
|
|
2521
|
-
* Redeem xBNB and instantly unstake LST to native BNB via DEX
|
|
2522
|
-
*/
|
|
2523
|
-
async redeemXBNBAndUnstake(params) {
|
|
2524
|
-
return this.walletClient.writeContract({
|
|
2525
|
-
chain: this.chain,
|
|
2526
|
-
account: this.walletClient.account,
|
|
2527
|
-
address: this.routerAddress,
|
|
2528
|
-
abi: RouterABI,
|
|
2529
|
-
functionName: "redeemXBNBAndUnstake",
|
|
2530
|
-
args: [params.lst, params.amount, params.minBNBOut, params.deadline]
|
|
2531
|
-
});
|
|
2532
|
-
}
|
|
2533
2405
|
// ============ Native Unstake Functions ============
|
|
2534
2406
|
/**
|
|
2535
2407
|
* Redeem apUSD and request native unstake from Lista (starts unbonding period)
|
|
@@ -2609,6 +2481,19 @@ function createRouterTestnetClient(routerAddress, account, rpcUrl) {
|
|
|
2609
2481
|
});
|
|
2610
2482
|
}
|
|
2611
2483
|
|
|
2484
|
+
// src/types.ts
|
|
2485
|
+
function encodeV3Path(tokens, fees) {
|
|
2486
|
+
if (tokens.length < 2) throw new Error("Path must have at least 2 tokens");
|
|
2487
|
+
if (fees.length !== tokens.length - 1) throw new Error("Fees length must be tokens.length - 1");
|
|
2488
|
+
let path = tokens[0].toLowerCase().slice(2);
|
|
2489
|
+
for (let i = 0; i < fees.length; i++) {
|
|
2490
|
+
const feeHex = fees[i].toString(16).padStart(6, "0");
|
|
2491
|
+
path += feeHex;
|
|
2492
|
+
path += tokens[i + 1].toLowerCase().slice(2);
|
|
2493
|
+
}
|
|
2494
|
+
return `0x${path}`;
|
|
2495
|
+
}
|
|
2496
|
+
|
|
2612
2497
|
// src/index.ts
|
|
2613
2498
|
var PRECISION = 10n ** 18n;
|
|
2614
2499
|
var BPS_PRECISION = 10000n;
|
|
@@ -2664,6 +2549,7 @@ function calculateAPY(previousRate, currentRate, periodDays) {
|
|
|
2664
2549
|
createRouterReadClient,
|
|
2665
2550
|
createRouterTestnetClient,
|
|
2666
2551
|
createRouterTestnetReadClient,
|
|
2552
|
+
encodeV3Path,
|
|
2667
2553
|
formatAmount,
|
|
2668
2554
|
formatCR,
|
|
2669
2555
|
formatFeeBPS,
|