@aspan/sdk 0.1.8 → 0.2.1

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.mjs CHANGED
@@ -1411,6 +1411,1165 @@ function createAspanTestnetClient(diamondAddress, account, rpcUrl) {
1411
1411
  });
1412
1412
  }
1413
1413
 
1414
+ // src/router.ts
1415
+ import {
1416
+ createPublicClient as createPublicClient2,
1417
+ createWalletClient as createWalletClient2,
1418
+ http as http2,
1419
+ zeroAddress
1420
+ } from "viem";
1421
+ import { bsc as bsc2, bscTestnet as bscTestnet2 } from "viem/chains";
1422
+
1423
+ // src/abi/router.ts
1424
+ var RouterABI = [
1425
+ // ============ Core Functions ============
1426
+ // swapAndMintApUSD
1427
+ {
1428
+ type: "function",
1429
+ name: "swapAndMintApUSD",
1430
+ inputs: [
1431
+ {
1432
+ name: "swapParams",
1433
+ type: "tuple",
1434
+ components: [
1435
+ { name: "inputToken", type: "address" },
1436
+ { name: "inputAmount", type: "uint256" },
1437
+ { name: "targetLST", type: "address" },
1438
+ { name: "minLSTOut", type: "uint256" },
1439
+ { name: "poolFee", type: "uint24" },
1440
+ { name: "useV2", type: "bool" }
1441
+ ]
1442
+ },
1443
+ {
1444
+ name: "mintParams",
1445
+ type: "tuple",
1446
+ components: [
1447
+ { name: "mintXBNB", type: "bool" },
1448
+ { name: "minMintOut", type: "uint256" },
1449
+ { name: "recipient", type: "address" },
1450
+ { name: "deadline", type: "uint256" }
1451
+ ]
1452
+ }
1453
+ ],
1454
+ outputs: [
1455
+ { name: "lstAmount", type: "uint256" },
1456
+ { name: "apUSDAmount", type: "uint256" }
1457
+ ],
1458
+ stateMutability: "payable"
1459
+ },
1460
+ // swapAndMintXBNB
1461
+ {
1462
+ type: "function",
1463
+ name: "swapAndMintXBNB",
1464
+ inputs: [
1465
+ {
1466
+ name: "swapParams",
1467
+ type: "tuple",
1468
+ components: [
1469
+ { name: "inputToken", type: "address" },
1470
+ { name: "inputAmount", type: "uint256" },
1471
+ { name: "targetLST", type: "address" },
1472
+ { name: "minLSTOut", type: "uint256" },
1473
+ { name: "poolFee", type: "uint24" },
1474
+ { name: "useV2", type: "bool" }
1475
+ ]
1476
+ },
1477
+ {
1478
+ name: "mintParams",
1479
+ type: "tuple",
1480
+ components: [
1481
+ { name: "mintXBNB", type: "bool" },
1482
+ { name: "minMintOut", type: "uint256" },
1483
+ { name: "recipient", type: "address" },
1484
+ { name: "deadline", type: "uint256" }
1485
+ ]
1486
+ }
1487
+ ],
1488
+ outputs: [
1489
+ { name: "lstAmount", type: "uint256" },
1490
+ { name: "xBNBAmount", type: "uint256" }
1491
+ ],
1492
+ stateMutability: "payable"
1493
+ },
1494
+ // stakeAndMint
1495
+ {
1496
+ type: "function",
1497
+ name: "stakeAndMint",
1498
+ inputs: [
1499
+ { name: "targetLST", type: "address" },
1500
+ { name: "isXBNB", type: "bool" },
1501
+ { name: "minMintOut", type: "uint256" },
1502
+ { name: "deadline", type: "uint256" }
1503
+ ],
1504
+ outputs: [
1505
+ { name: "lstAmount", type: "uint256" },
1506
+ { name: "mintedAmount", type: "uint256" }
1507
+ ],
1508
+ stateMutability: "payable"
1509
+ },
1510
+ // ============ Simplified Functions ============
1511
+ // swapAndMintApUSDDefault
1512
+ {
1513
+ type: "function",
1514
+ name: "swapAndMintApUSDDefault",
1515
+ inputs: [
1516
+ { name: "inputToken", type: "address" },
1517
+ { name: "inputAmount", type: "uint256" },
1518
+ { name: "minMintOut", type: "uint256" },
1519
+ { name: "deadline", type: "uint256" }
1520
+ ],
1521
+ outputs: [{ name: "apUSDAmount", type: "uint256" }],
1522
+ stateMutability: "payable"
1523
+ },
1524
+ // swapAndMintXBNBDefault
1525
+ {
1526
+ type: "function",
1527
+ name: "swapAndMintXBNBDefault",
1528
+ inputs: [
1529
+ { name: "inputToken", type: "address" },
1530
+ { name: "inputAmount", type: "uint256" },
1531
+ { name: "minMintOut", type: "uint256" },
1532
+ { name: "deadline", type: "uint256" }
1533
+ ],
1534
+ outputs: [{ name: "xBNBAmount", type: "uint256" }],
1535
+ stateMutability: "payable"
1536
+ },
1537
+ // stakeAndMintApUSD
1538
+ {
1539
+ type: "function",
1540
+ name: "stakeAndMintApUSD",
1541
+ inputs: [{ name: "minMintOut", type: "uint256" }],
1542
+ outputs: [{ name: "apUSDAmount", type: "uint256" }],
1543
+ stateMutability: "payable"
1544
+ },
1545
+ // stakeAndMintXBNB
1546
+ {
1547
+ type: "function",
1548
+ name: "stakeAndMintXBNB",
1549
+ inputs: [{ name: "minMintOut", type: "uint256" }],
1550
+ outputs: [{ name: "xBNBAmount", type: "uint256" }],
1551
+ stateMutability: "payable"
1552
+ },
1553
+ // ============ Direct Mint/Redeem Functions ============
1554
+ // mintApUSD
1555
+ {
1556
+ type: "function",
1557
+ name: "mintApUSD",
1558
+ inputs: [
1559
+ { name: "lst", type: "address" },
1560
+ { name: "lstAmount", type: "uint256" },
1561
+ { name: "minOut", type: "uint256" }
1562
+ ],
1563
+ outputs: [{ name: "apUSDAmount", type: "uint256" }],
1564
+ stateMutability: "nonpayable"
1565
+ },
1566
+ // mintXBNB
1567
+ {
1568
+ type: "function",
1569
+ name: "mintXBNB",
1570
+ inputs: [
1571
+ { name: "lst", type: "address" },
1572
+ { name: "lstAmount", type: "uint256" },
1573
+ { name: "minOut", type: "uint256" }
1574
+ ],
1575
+ outputs: [{ name: "xBNBAmount", type: "uint256" }],
1576
+ stateMutability: "nonpayable"
1577
+ },
1578
+ // redeemApUSD
1579
+ {
1580
+ type: "function",
1581
+ name: "redeemApUSD",
1582
+ inputs: [
1583
+ { name: "lst", type: "address" },
1584
+ { name: "apUSDAmount", type: "uint256" },
1585
+ { name: "minOut", type: "uint256" }
1586
+ ],
1587
+ outputs: [{ name: "lstAmount", type: "uint256" }],
1588
+ stateMutability: "nonpayable"
1589
+ },
1590
+ // redeemXBNB
1591
+ {
1592
+ type: "function",
1593
+ name: "redeemXBNB",
1594
+ inputs: [
1595
+ { name: "lst", type: "address" },
1596
+ { name: "xBNBAmount", type: "uint256" },
1597
+ { name: "minOut", type: "uint256" }
1598
+ ],
1599
+ outputs: [{ name: "lstAmount", type: "uint256" }],
1600
+ stateMutability: "nonpayable"
1601
+ },
1602
+ // ============ Redeem and Swap Functions ============
1603
+ // redeemApUSDAndSwap
1604
+ {
1605
+ type: "function",
1606
+ name: "redeemApUSDAndSwap",
1607
+ inputs: [
1608
+ { name: "lst", type: "address" },
1609
+ { name: "apUSDAmount", type: "uint256" },
1610
+ { name: "outputToken", type: "address" },
1611
+ { name: "minOut", type: "uint256" },
1612
+ { name: "deadline", type: "uint256" },
1613
+ { name: "useV2", type: "bool" },
1614
+ { name: "poolFee", type: "uint24" }
1615
+ ],
1616
+ outputs: [{ name: "outputAmount", type: "uint256" }],
1617
+ stateMutability: "nonpayable"
1618
+ },
1619
+ // redeemXBNBAndSwap
1620
+ {
1621
+ type: "function",
1622
+ name: "redeemXBNBAndSwap",
1623
+ inputs: [
1624
+ { name: "lst", type: "address" },
1625
+ { name: "xBNBAmount", type: "uint256" },
1626
+ { name: "outputToken", type: "address" },
1627
+ { name: "minOut", type: "uint256" },
1628
+ { name: "deadline", type: "uint256" },
1629
+ { name: "useV2", type: "bool" },
1630
+ { name: "poolFee", type: "uint24" }
1631
+ ],
1632
+ outputs: [{ name: "outputAmount", type: "uint256" }],
1633
+ stateMutability: "nonpayable"
1634
+ },
1635
+ // redeemApUSDAndUnstake
1636
+ {
1637
+ type: "function",
1638
+ name: "redeemApUSDAndUnstake",
1639
+ inputs: [
1640
+ { name: "lst", type: "address" },
1641
+ { name: "apUSDAmount", type: "uint256" },
1642
+ { name: "minBNBOut", type: "uint256" },
1643
+ { name: "deadline", type: "uint256" }
1644
+ ],
1645
+ outputs: [{ name: "bnbAmount", type: "uint256" }],
1646
+ stateMutability: "nonpayable"
1647
+ },
1648
+ // redeemXBNBAndUnstake
1649
+ {
1650
+ type: "function",
1651
+ name: "redeemXBNBAndUnstake",
1652
+ inputs: [
1653
+ { name: "lst", type: "address" },
1654
+ { name: "xBNBAmount", type: "uint256" },
1655
+ { name: "minBNBOut", type: "uint256" },
1656
+ { name: "deadline", type: "uint256" }
1657
+ ],
1658
+ outputs: [{ name: "bnbAmount", type: "uint256" }],
1659
+ stateMutability: "nonpayable"
1660
+ },
1661
+ // ============ Native Unstake Functions ============
1662
+ // redeemApUSDAndRequestUnstake
1663
+ {
1664
+ type: "function",
1665
+ name: "redeemApUSDAndRequestUnstake",
1666
+ inputs: [{ name: "apUSDAmount", type: "uint256" }],
1667
+ outputs: [
1668
+ { name: "requestIndex", type: "uint256" },
1669
+ { name: "slisBNBAmount", type: "uint256" }
1670
+ ],
1671
+ stateMutability: "nonpayable"
1672
+ },
1673
+ // redeemXBNBAndRequestUnstake
1674
+ {
1675
+ type: "function",
1676
+ name: "redeemXBNBAndRequestUnstake",
1677
+ inputs: [{ name: "xBNBAmount", type: "uint256" }],
1678
+ outputs: [
1679
+ { name: "requestIndex", type: "uint256" },
1680
+ { name: "slisBNBAmount", type: "uint256" }
1681
+ ],
1682
+ stateMutability: "nonpayable"
1683
+ },
1684
+ // claimUnstake
1685
+ {
1686
+ type: "function",
1687
+ name: "claimUnstake",
1688
+ inputs: [{ name: "requestIndex", type: "uint256" }],
1689
+ outputs: [{ name: "bnbAmount", type: "uint256" }],
1690
+ stateMutability: "nonpayable"
1691
+ },
1692
+ // ============ View Functions ============
1693
+ // defaultLST
1694
+ {
1695
+ type: "function",
1696
+ name: "defaultLST",
1697
+ inputs: [],
1698
+ outputs: [{ name: "", type: "address" }],
1699
+ stateMutability: "view"
1700
+ },
1701
+ // supportedInputTokens
1702
+ {
1703
+ type: "function",
1704
+ name: "supportedInputTokens",
1705
+ inputs: [{ name: "token", type: "address" }],
1706
+ outputs: [{ name: "", type: "bool" }],
1707
+ stateMutability: "view"
1708
+ },
1709
+ // supportedLSTs
1710
+ {
1711
+ type: "function",
1712
+ name: "supportedLSTs",
1713
+ inputs: [{ name: "lst", type: "address" }],
1714
+ outputs: [{ name: "", type: "bool" }],
1715
+ stateMutability: "view"
1716
+ },
1717
+ // diamond
1718
+ {
1719
+ type: "function",
1720
+ name: "diamond",
1721
+ inputs: [],
1722
+ outputs: [{ name: "", type: "address" }],
1723
+ stateMutability: "view"
1724
+ },
1725
+ // getExpectedMintOutput
1726
+ {
1727
+ type: "function",
1728
+ name: "getExpectedMintOutput",
1729
+ inputs: [
1730
+ { name: "inputToken", type: "address" },
1731
+ { name: "inputAmount", type: "uint256" },
1732
+ { name: "targetLST", type: "address" },
1733
+ { name: "isXBNB", type: "bool" }
1734
+ ],
1735
+ outputs: [
1736
+ { name: "expectedLST", type: "uint256" },
1737
+ { name: "expectedMint", type: "uint256" }
1738
+ ],
1739
+ stateMutability: "view"
1740
+ },
1741
+ // getExpectedRedeemOutput
1742
+ {
1743
+ type: "function",
1744
+ name: "getExpectedRedeemOutput",
1745
+ inputs: [
1746
+ { name: "isXBNB", type: "bool" },
1747
+ { name: "redeemAmount", type: "uint256" },
1748
+ { name: "lst", type: "address" },
1749
+ { name: "outputToken", type: "address" }
1750
+ ],
1751
+ outputs: [
1752
+ { name: "expectedLST", type: "uint256" },
1753
+ { name: "expectedOutput", type: "uint256" }
1754
+ ],
1755
+ stateMutability: "view"
1756
+ },
1757
+ // previewMintApUSD
1758
+ {
1759
+ type: "function",
1760
+ name: "previewMintApUSD",
1761
+ inputs: [
1762
+ { name: "lst", type: "address" },
1763
+ { name: "lstAmount", type: "uint256" }
1764
+ ],
1765
+ outputs: [{ name: "apUSDAmount", type: "uint256" }],
1766
+ stateMutability: "view"
1767
+ },
1768
+ // previewMintXBNB
1769
+ {
1770
+ type: "function",
1771
+ name: "previewMintXBNB",
1772
+ inputs: [
1773
+ { name: "lst", type: "address" },
1774
+ { name: "lstAmount", type: "uint256" }
1775
+ ],
1776
+ outputs: [{ name: "xBNBAmount", type: "uint256" }],
1777
+ stateMutability: "view"
1778
+ },
1779
+ // previewRedeemApUSD
1780
+ {
1781
+ type: "function",
1782
+ name: "previewRedeemApUSD",
1783
+ inputs: [
1784
+ { name: "lst", type: "address" },
1785
+ { name: "apUSDAmount", type: "uint256" }
1786
+ ],
1787
+ outputs: [{ name: "lstAmount", type: "uint256" }],
1788
+ stateMutability: "view"
1789
+ },
1790
+ // previewRedeemXBNB
1791
+ {
1792
+ type: "function",
1793
+ name: "previewRedeemXBNB",
1794
+ inputs: [
1795
+ { name: "lst", type: "address" },
1796
+ { name: "xBNBAmount", type: "uint256" }
1797
+ ],
1798
+ outputs: [{ name: "lstAmount", type: "uint256" }],
1799
+ stateMutability: "view"
1800
+ },
1801
+ // getUserWithdrawalIndices
1802
+ {
1803
+ type: "function",
1804
+ name: "getUserWithdrawalIndices",
1805
+ inputs: [{ name: "user", type: "address" }],
1806
+ outputs: [{ name: "", type: "uint256[]" }],
1807
+ stateMutability: "view"
1808
+ },
1809
+ // getWithdrawalStatus
1810
+ {
1811
+ type: "function",
1812
+ name: "getWithdrawalStatus",
1813
+ inputs: [{ name: "requestIndex", type: "uint256" }],
1814
+ outputs: [
1815
+ { name: "isClaimable", type: "bool" },
1816
+ { name: "bnbAmount", type: "uint256" }
1817
+ ],
1818
+ stateMutability: "view"
1819
+ },
1820
+ // Immutable addresses
1821
+ {
1822
+ type: "function",
1823
+ name: "wbnb",
1824
+ inputs: [],
1825
+ outputs: [{ name: "", type: "address" }],
1826
+ stateMutability: "view"
1827
+ },
1828
+ {
1829
+ type: "function",
1830
+ name: "usdt",
1831
+ inputs: [],
1832
+ outputs: [{ name: "", type: "address" }],
1833
+ stateMutability: "view"
1834
+ },
1835
+ {
1836
+ type: "function",
1837
+ name: "usdc",
1838
+ inputs: [],
1839
+ outputs: [{ name: "", type: "address" }],
1840
+ stateMutability: "view"
1841
+ },
1842
+ {
1843
+ type: "function",
1844
+ name: "slisBNB",
1845
+ inputs: [],
1846
+ outputs: [{ name: "", type: "address" }],
1847
+ stateMutability: "view"
1848
+ },
1849
+ {
1850
+ type: "function",
1851
+ name: "asBNB",
1852
+ inputs: [],
1853
+ outputs: [{ name: "", type: "address" }],
1854
+ stateMutability: "view"
1855
+ },
1856
+ {
1857
+ type: "function",
1858
+ name: "wclisBNB",
1859
+ inputs: [],
1860
+ outputs: [{ name: "", type: "address" }],
1861
+ stateMutability: "view"
1862
+ },
1863
+ {
1864
+ type: "function",
1865
+ name: "apUSD",
1866
+ inputs: [],
1867
+ outputs: [{ name: "", type: "address" }],
1868
+ stateMutability: "view"
1869
+ },
1870
+ {
1871
+ type: "function",
1872
+ name: "xBNB",
1873
+ inputs: [],
1874
+ outputs: [{ name: "", type: "address" }],
1875
+ stateMutability: "view"
1876
+ },
1877
+ // ============ Events ============
1878
+ // SwapAndMint
1879
+ {
1880
+ type: "event",
1881
+ name: "SwapAndMint",
1882
+ inputs: [
1883
+ { name: "user", type: "address", indexed: true },
1884
+ { name: "inputToken", type: "address", indexed: true },
1885
+ { name: "inputAmount", type: "uint256", indexed: false },
1886
+ { name: "targetLST", type: "address", indexed: true },
1887
+ { name: "lstAmount", type: "uint256", indexed: false },
1888
+ { name: "mintedToken", type: "address", indexed: false },
1889
+ { name: "mintedAmount", type: "uint256", indexed: false }
1890
+ ]
1891
+ },
1892
+ // StakeAndMint
1893
+ {
1894
+ type: "event",
1895
+ name: "StakeAndMint",
1896
+ inputs: [
1897
+ { name: "user", type: "address", indexed: true },
1898
+ { name: "bnbAmount", type: "uint256", indexed: false },
1899
+ { name: "targetLST", type: "address", indexed: true },
1900
+ { name: "lstAmount", type: "uint256", indexed: false },
1901
+ { name: "mintedToken", type: "address", indexed: true },
1902
+ { name: "mintedAmount", type: "uint256", indexed: false }
1903
+ ]
1904
+ },
1905
+ // Mint
1906
+ {
1907
+ type: "event",
1908
+ name: "Mint",
1909
+ inputs: [
1910
+ { name: "user", type: "address", indexed: true },
1911
+ { name: "lst", type: "address", indexed: true },
1912
+ { name: "lstAmount", type: "uint256", indexed: false },
1913
+ { name: "mintedToken", type: "address", indexed: true },
1914
+ { name: "mintedAmount", type: "uint256", indexed: false }
1915
+ ]
1916
+ },
1917
+ // Redeem
1918
+ {
1919
+ type: "event",
1920
+ name: "Redeem",
1921
+ inputs: [
1922
+ { name: "user", type: "address", indexed: true },
1923
+ { name: "redeemedToken", type: "address", indexed: true },
1924
+ { name: "redeemedAmount", type: "uint256", indexed: false },
1925
+ { name: "lst", type: "address", indexed: true },
1926
+ { name: "lstAmount", type: "uint256", indexed: false }
1927
+ ]
1928
+ },
1929
+ // RedeemAndSwap
1930
+ {
1931
+ type: "event",
1932
+ name: "RedeemAndSwap",
1933
+ inputs: [
1934
+ { name: "user", type: "address", indexed: true },
1935
+ { name: "redeemedToken", type: "address", indexed: false },
1936
+ { name: "redeemedAmount", type: "uint256", indexed: false },
1937
+ { name: "lst", type: "address", indexed: false },
1938
+ { name: "lstAmount", type: "uint256", indexed: false },
1939
+ { name: "outputToken", type: "address", indexed: true },
1940
+ { name: "outputAmount", type: "uint256", indexed: false }
1941
+ ]
1942
+ },
1943
+ // UnstakeRequested
1944
+ {
1945
+ type: "event",
1946
+ name: "UnstakeRequested",
1947
+ inputs: [
1948
+ { name: "user", type: "address", indexed: true },
1949
+ { name: "requestIndex", type: "uint256", indexed: true },
1950
+ { name: "redeemedToken", type: "address", indexed: false },
1951
+ { name: "redeemedAmount", type: "uint256", indexed: false },
1952
+ { name: "slisBNBAmount", type: "uint256", indexed: false }
1953
+ ]
1954
+ },
1955
+ // UnstakeClaimed
1956
+ {
1957
+ type: "event",
1958
+ name: "UnstakeClaimed",
1959
+ inputs: [
1960
+ { name: "user", type: "address", indexed: true },
1961
+ { name: "requestIndex", type: "uint256", indexed: true },
1962
+ { name: "bnbAmount", type: "uint256", indexed: false }
1963
+ ]
1964
+ },
1965
+ // DefaultLSTUpdated
1966
+ {
1967
+ type: "event",
1968
+ name: "DefaultLSTUpdated",
1969
+ inputs: [
1970
+ { name: "oldLST", type: "address", indexed: true },
1971
+ { name: "newLST", type: "address", indexed: true }
1972
+ ]
1973
+ },
1974
+ // ============ Errors ============
1975
+ { type: "error", name: "UnsupportedInputToken", inputs: [] },
1976
+ { type: "error", name: "UnsupportedLST", inputs: [] },
1977
+ { type: "error", name: "DeadlineExpired", inputs: [] },
1978
+ { type: "error", name: "InsufficientOutput", inputs: [] },
1979
+ { type: "error", name: "ZeroAmount", inputs: [] },
1980
+ { type: "error", name: "InvalidRecipient", inputs: [] },
1981
+ { type: "error", name: "SwapFailed", inputs: [] },
1982
+ { type: "error", name: "MintFailed", inputs: [] },
1983
+ { type: "error", name: "NativeTransferFailed", inputs: [] },
1984
+ { type: "error", name: "InvalidPoolFee", inputs: [] },
1985
+ { type: "error", name: "DefaultLSTNotSet", inputs: [] },
1986
+ { type: "error", name: "InvalidWithdrawalRequest", inputs: [] },
1987
+ { type: "error", name: "WithdrawalNotClaimable", inputs: [] },
1988
+ { type: "error", name: "WithdrawalAlreadyClaimed", inputs: [] },
1989
+ { type: "error", name: "OnlySlisBNBSupported", inputs: [] }
1990
+ ];
1991
+
1992
+ // src/router.ts
1993
+ var AspanRouterReadClient = class {
1994
+ publicClient;
1995
+ routerAddress;
1996
+ chain;
1997
+ constructor(config) {
1998
+ this.routerAddress = config.routerAddress;
1999
+ this.chain = config.chain ?? bsc2;
2000
+ this.publicClient = createPublicClient2({
2001
+ chain: this.chain,
2002
+ transport: http2(config.rpcUrl)
2003
+ });
2004
+ }
2005
+ // ============ View Functions ============
2006
+ /**
2007
+ * Get the default LST address
2008
+ */
2009
+ async getDefaultLST() {
2010
+ return this.publicClient.readContract({
2011
+ address: this.routerAddress,
2012
+ abi: RouterABI,
2013
+ functionName: "defaultLST"
2014
+ });
2015
+ }
2016
+ /**
2017
+ * Check if an input token is supported
2018
+ */
2019
+ async isSupportedInputToken(token) {
2020
+ return this.publicClient.readContract({
2021
+ address: this.routerAddress,
2022
+ abi: RouterABI,
2023
+ functionName: "supportedInputTokens",
2024
+ args: [token]
2025
+ });
2026
+ }
2027
+ /**
2028
+ * Check if an LST is supported
2029
+ */
2030
+ async isSupportedLST(lst) {
2031
+ return this.publicClient.readContract({
2032
+ address: this.routerAddress,
2033
+ abi: RouterABI,
2034
+ functionName: "supportedLSTs",
2035
+ args: [lst]
2036
+ });
2037
+ }
2038
+ /**
2039
+ * Get the Diamond contract address
2040
+ */
2041
+ async getDiamond() {
2042
+ return this.publicClient.readContract({
2043
+ address: this.routerAddress,
2044
+ abi: RouterABI,
2045
+ functionName: "diamond"
2046
+ });
2047
+ }
2048
+ /**
2049
+ * Get expected output from a swap and mint operation
2050
+ */
2051
+ async getExpectedMintOutput(inputToken, inputAmount, targetLST, isXBNB) {
2052
+ const result = await this.publicClient.readContract({
2053
+ address: this.routerAddress,
2054
+ abi: RouterABI,
2055
+ functionName: "getExpectedMintOutput",
2056
+ args: [inputToken, inputAmount, targetLST, isXBNB]
2057
+ });
2058
+ return {
2059
+ expectedLST: result[0],
2060
+ expectedMint: result[1]
2061
+ };
2062
+ }
2063
+ /**
2064
+ * Get expected output from a redeem and swap operation
2065
+ */
2066
+ async getExpectedRedeemOutput(isXBNB, redeemAmount, lst, outputToken) {
2067
+ const result = await this.publicClient.readContract({
2068
+ address: this.routerAddress,
2069
+ abi: RouterABI,
2070
+ functionName: "getExpectedRedeemOutput",
2071
+ args: [isXBNB, redeemAmount, lst, outputToken]
2072
+ });
2073
+ return {
2074
+ expectedLST: result[0],
2075
+ expectedMint: result[1]
2076
+ };
2077
+ }
2078
+ /**
2079
+ * Preview apUSD mint output for a given LST amount
2080
+ */
2081
+ async previewMintApUSD(lst, lstAmount) {
2082
+ return this.publicClient.readContract({
2083
+ address: this.routerAddress,
2084
+ abi: RouterABI,
2085
+ functionName: "previewMintApUSD",
2086
+ args: [lst, lstAmount]
2087
+ });
2088
+ }
2089
+ /**
2090
+ * Preview xBNB mint output for a given LST amount
2091
+ */
2092
+ async previewMintXBNB(lst, lstAmount) {
2093
+ return this.publicClient.readContract({
2094
+ address: this.routerAddress,
2095
+ abi: RouterABI,
2096
+ functionName: "previewMintXBNB",
2097
+ args: [lst, lstAmount]
2098
+ });
2099
+ }
2100
+ /**
2101
+ * Preview LST output for redeeming apUSD
2102
+ */
2103
+ async previewRedeemApUSD(lst, apUSDAmount) {
2104
+ return this.publicClient.readContract({
2105
+ address: this.routerAddress,
2106
+ abi: RouterABI,
2107
+ functionName: "previewRedeemApUSD",
2108
+ args: [lst, apUSDAmount]
2109
+ });
2110
+ }
2111
+ /**
2112
+ * Preview LST output for redeeming xBNB
2113
+ */
2114
+ async previewRedeemXBNB(lst, xBNBAmount) {
2115
+ return this.publicClient.readContract({
2116
+ address: this.routerAddress,
2117
+ abi: RouterABI,
2118
+ functionName: "previewRedeemXBNB",
2119
+ args: [lst, xBNBAmount]
2120
+ });
2121
+ }
2122
+ /**
2123
+ * Get user's withdrawal request indices
2124
+ */
2125
+ async getUserWithdrawalIndices(user) {
2126
+ const result = await this.publicClient.readContract({
2127
+ address: this.routerAddress,
2128
+ abi: RouterABI,
2129
+ functionName: "getUserWithdrawalIndices",
2130
+ args: [user]
2131
+ });
2132
+ return [...result];
2133
+ }
2134
+ /**
2135
+ * Get withdrawal request status
2136
+ */
2137
+ async getWithdrawalStatus(requestIndex) {
2138
+ const result = await this.publicClient.readContract({
2139
+ address: this.routerAddress,
2140
+ abi: RouterABI,
2141
+ functionName: "getWithdrawalStatus",
2142
+ args: [requestIndex]
2143
+ });
2144
+ return {
2145
+ isClaimable: result[0],
2146
+ bnbAmount: result[1]
2147
+ };
2148
+ }
2149
+ // ============ Token Address Getters ============
2150
+ async getWBNB() {
2151
+ return this.publicClient.readContract({
2152
+ address: this.routerAddress,
2153
+ abi: RouterABI,
2154
+ functionName: "wbnb"
2155
+ });
2156
+ }
2157
+ async getUSDT() {
2158
+ return this.publicClient.readContract({
2159
+ address: this.routerAddress,
2160
+ abi: RouterABI,
2161
+ functionName: "usdt"
2162
+ });
2163
+ }
2164
+ async getUSDC() {
2165
+ return this.publicClient.readContract({
2166
+ address: this.routerAddress,
2167
+ abi: RouterABI,
2168
+ functionName: "usdc"
2169
+ });
2170
+ }
2171
+ async getSlisBNB() {
2172
+ return this.publicClient.readContract({
2173
+ address: this.routerAddress,
2174
+ abi: RouterABI,
2175
+ functionName: "slisBNB"
2176
+ });
2177
+ }
2178
+ async getAsBNB() {
2179
+ return this.publicClient.readContract({
2180
+ address: this.routerAddress,
2181
+ abi: RouterABI,
2182
+ functionName: "asBNB"
2183
+ });
2184
+ }
2185
+ async getWclisBNB() {
2186
+ return this.publicClient.readContract({
2187
+ address: this.routerAddress,
2188
+ abi: RouterABI,
2189
+ functionName: "wclisBNB"
2190
+ });
2191
+ }
2192
+ async getApUSD() {
2193
+ return this.publicClient.readContract({
2194
+ address: this.routerAddress,
2195
+ abi: RouterABI,
2196
+ functionName: "apUSD"
2197
+ });
2198
+ }
2199
+ async getXBNB() {
2200
+ return this.publicClient.readContract({
2201
+ address: this.routerAddress,
2202
+ abi: RouterABI,
2203
+ functionName: "xBNB"
2204
+ });
2205
+ }
2206
+ };
2207
+ var AspanRouterClient = class extends AspanRouterReadClient {
2208
+ walletClient;
2209
+ constructor(config) {
2210
+ super(config);
2211
+ if (config.walletClient) {
2212
+ this.walletClient = config.walletClient;
2213
+ } else if (config.account) {
2214
+ this.walletClient = createWalletClient2({
2215
+ account: config.account,
2216
+ chain: this.chain,
2217
+ transport: http2(config.rpcUrl)
2218
+ });
2219
+ } else {
2220
+ throw new Error("Either walletClient or account must be provided");
2221
+ }
2222
+ }
2223
+ // ============ Core Functions ============
2224
+ /**
2225
+ * Swap input token to LST and mint apUSD
2226
+ */
2227
+ async swapAndMintApUSD(params) {
2228
+ const value = params.swapParams.inputToken === zeroAddress ? params.swapParams.inputAmount : 0n;
2229
+ return this.walletClient.writeContract({
2230
+ chain: this.chain,
2231
+ account: this.walletClient.account,
2232
+ address: this.routerAddress,
2233
+ abi: RouterABI,
2234
+ functionName: "swapAndMintApUSD",
2235
+ args: [
2236
+ {
2237
+ inputToken: params.swapParams.inputToken,
2238
+ inputAmount: params.swapParams.inputAmount,
2239
+ targetLST: params.swapParams.targetLST,
2240
+ minLSTOut: params.swapParams.minLSTOut,
2241
+ poolFee: params.swapParams.poolFee,
2242
+ useV2: params.swapParams.useV2
2243
+ },
2244
+ {
2245
+ mintXBNB: params.mintParams.mintXBNB,
2246
+ minMintOut: params.mintParams.minMintOut,
2247
+ recipient: params.mintParams.recipient,
2248
+ deadline: params.mintParams.deadline
2249
+ }
2250
+ ],
2251
+ value
2252
+ });
2253
+ }
2254
+ /**
2255
+ * Swap input token to LST and mint xBNB
2256
+ */
2257
+ async swapAndMintXBNB(params) {
2258
+ const value = params.swapParams.inputToken === zeroAddress ? params.swapParams.inputAmount : 0n;
2259
+ return this.walletClient.writeContract({
2260
+ chain: this.chain,
2261
+ account: this.walletClient.account,
2262
+ address: this.routerAddress,
2263
+ abi: RouterABI,
2264
+ functionName: "swapAndMintXBNB",
2265
+ args: [
2266
+ {
2267
+ inputToken: params.swapParams.inputToken,
2268
+ inputAmount: params.swapParams.inputAmount,
2269
+ targetLST: params.swapParams.targetLST,
2270
+ minLSTOut: params.swapParams.minLSTOut,
2271
+ poolFee: params.swapParams.poolFee,
2272
+ useV2: params.swapParams.useV2
2273
+ },
2274
+ {
2275
+ mintXBNB: params.mintParams.mintXBNB,
2276
+ minMintOut: params.mintParams.minMintOut,
2277
+ recipient: params.mintParams.recipient,
2278
+ deadline: params.mintParams.deadline
2279
+ }
2280
+ ],
2281
+ value
2282
+ });
2283
+ }
2284
+ /**
2285
+ * Stake native BNB directly to LST and mint
2286
+ */
2287
+ async stakeAndMint(params) {
2288
+ return this.walletClient.writeContract({
2289
+ chain: this.chain,
2290
+ account: this.walletClient.account,
2291
+ address: this.routerAddress,
2292
+ abi: RouterABI,
2293
+ functionName: "stakeAndMint",
2294
+ args: [
2295
+ params.targetLST,
2296
+ params.isXBNB,
2297
+ params.minMintOut,
2298
+ params.deadline
2299
+ ],
2300
+ value: params.value
2301
+ });
2302
+ }
2303
+ // ============ Simplified Functions ============
2304
+ /**
2305
+ * Swap input token and mint apUSD using default LST
2306
+ */
2307
+ async swapAndMintApUSDDefault(params) {
2308
+ const value = params.inputToken === zeroAddress ? params.value ?? params.inputAmount : 0n;
2309
+ return this.walletClient.writeContract({
2310
+ chain: this.chain,
2311
+ account: this.walletClient.account,
2312
+ address: this.routerAddress,
2313
+ abi: RouterABI,
2314
+ functionName: "swapAndMintApUSDDefault",
2315
+ args: [
2316
+ params.inputToken,
2317
+ params.inputAmount,
2318
+ params.minMintOut,
2319
+ params.deadline
2320
+ ],
2321
+ value
2322
+ });
2323
+ }
2324
+ /**
2325
+ * Swap input token and mint xBNB using default LST
2326
+ */
2327
+ async swapAndMintXBNBDefault(params) {
2328
+ const value = params.inputToken === zeroAddress ? params.value ?? params.inputAmount : 0n;
2329
+ return this.walletClient.writeContract({
2330
+ chain: this.chain,
2331
+ account: this.walletClient.account,
2332
+ address: this.routerAddress,
2333
+ abi: RouterABI,
2334
+ functionName: "swapAndMintXBNBDefault",
2335
+ args: [
2336
+ params.inputToken,
2337
+ params.inputAmount,
2338
+ params.minMintOut,
2339
+ params.deadline
2340
+ ],
2341
+ value
2342
+ });
2343
+ }
2344
+ /**
2345
+ * Stake native BNB and mint apUSD using default LST
2346
+ */
2347
+ async stakeAndMintApUSD(minMintOut, value) {
2348
+ return this.walletClient.writeContract({
2349
+ chain: this.chain,
2350
+ account: this.walletClient.account,
2351
+ address: this.routerAddress,
2352
+ abi: RouterABI,
2353
+ functionName: "stakeAndMintApUSD",
2354
+ args: [minMintOut],
2355
+ value
2356
+ });
2357
+ }
2358
+ /**
2359
+ * Stake native BNB and mint xBNB using default LST
2360
+ */
2361
+ async stakeAndMintXBNB(minMintOut, value) {
2362
+ return this.walletClient.writeContract({
2363
+ chain: this.chain,
2364
+ account: this.walletClient.account,
2365
+ address: this.routerAddress,
2366
+ abi: RouterABI,
2367
+ functionName: "stakeAndMintXBNB",
2368
+ args: [minMintOut],
2369
+ value
2370
+ });
2371
+ }
2372
+ // ============ Direct Mint/Redeem Functions ============
2373
+ /**
2374
+ * Mint apUSD by providing LST directly (no swap)
2375
+ */
2376
+ async mintApUSD(params) {
2377
+ return this.walletClient.writeContract({
2378
+ chain: this.chain,
2379
+ account: this.walletClient.account,
2380
+ address: this.routerAddress,
2381
+ abi: RouterABI,
2382
+ functionName: "mintApUSD",
2383
+ args: [params.lst, params.lstAmount, params.minOut ?? 0n]
2384
+ });
2385
+ }
2386
+ /**
2387
+ * Mint xBNB by providing LST directly (no swap)
2388
+ */
2389
+ async mintXBNB(params) {
2390
+ return this.walletClient.writeContract({
2391
+ chain: this.chain,
2392
+ account: this.walletClient.account,
2393
+ address: this.routerAddress,
2394
+ abi: RouterABI,
2395
+ functionName: "mintXBNB",
2396
+ args: [params.lst, params.lstAmount, params.minOut ?? 0n]
2397
+ });
2398
+ }
2399
+ /**
2400
+ * Redeem apUSD for LST (no swap)
2401
+ */
2402
+ async redeemApUSD(params) {
2403
+ return this.walletClient.writeContract({
2404
+ chain: this.chain,
2405
+ account: this.walletClient.account,
2406
+ address: this.routerAddress,
2407
+ abi: RouterABI,
2408
+ functionName: "redeemApUSD",
2409
+ args: [params.lst, params.apUSDAmount, params.minOut ?? 0n]
2410
+ });
2411
+ }
2412
+ /**
2413
+ * Redeem xBNB for LST (no swap)
2414
+ */
2415
+ async redeemXBNB(params) {
2416
+ return this.walletClient.writeContract({
2417
+ chain: this.chain,
2418
+ account: this.walletClient.account,
2419
+ address: this.routerAddress,
2420
+ abi: RouterABI,
2421
+ functionName: "redeemXBNB",
2422
+ args: [params.lst, params.xBNBAmount, params.minOut ?? 0n]
2423
+ });
2424
+ }
2425
+ // ============ Redeem and Swap Functions ============
2426
+ /**
2427
+ * Redeem apUSD and swap LST to output token
2428
+ */
2429
+ async redeemApUSDAndSwap(params) {
2430
+ return this.walletClient.writeContract({
2431
+ chain: this.chain,
2432
+ account: this.walletClient.account,
2433
+ address: this.routerAddress,
2434
+ abi: RouterABI,
2435
+ functionName: "redeemApUSDAndSwap",
2436
+ args: [
2437
+ params.lst,
2438
+ params.amount,
2439
+ params.outputToken,
2440
+ params.minOut,
2441
+ params.deadline,
2442
+ params.useV2,
2443
+ params.poolFee
2444
+ ]
2445
+ });
2446
+ }
2447
+ /**
2448
+ * Redeem xBNB and swap LST to output token
2449
+ */
2450
+ async redeemXBNBAndSwap(params) {
2451
+ return this.walletClient.writeContract({
2452
+ chain: this.chain,
2453
+ account: this.walletClient.account,
2454
+ address: this.routerAddress,
2455
+ abi: RouterABI,
2456
+ functionName: "redeemXBNBAndSwap",
2457
+ args: [
2458
+ params.lst,
2459
+ params.amount,
2460
+ params.outputToken,
2461
+ params.minOut,
2462
+ params.deadline,
2463
+ params.useV2,
2464
+ params.poolFee
2465
+ ]
2466
+ });
2467
+ }
2468
+ /**
2469
+ * Redeem apUSD and instantly unstake LST to native BNB via DEX
2470
+ */
2471
+ async redeemApUSDAndUnstake(params) {
2472
+ return this.walletClient.writeContract({
2473
+ chain: this.chain,
2474
+ account: this.walletClient.account,
2475
+ address: this.routerAddress,
2476
+ abi: RouterABI,
2477
+ functionName: "redeemApUSDAndUnstake",
2478
+ args: [params.lst, params.amount, params.minBNBOut, params.deadline]
2479
+ });
2480
+ }
2481
+ /**
2482
+ * Redeem xBNB and instantly unstake LST to native BNB via DEX
2483
+ */
2484
+ async redeemXBNBAndUnstake(params) {
2485
+ return this.walletClient.writeContract({
2486
+ chain: this.chain,
2487
+ account: this.walletClient.account,
2488
+ address: this.routerAddress,
2489
+ abi: RouterABI,
2490
+ functionName: "redeemXBNBAndUnstake",
2491
+ args: [params.lst, params.amount, params.minBNBOut, params.deadline]
2492
+ });
2493
+ }
2494
+ // ============ Native Unstake Functions ============
2495
+ /**
2496
+ * Redeem apUSD and request native unstake from Lista (starts unbonding period)
2497
+ */
2498
+ async redeemApUSDAndRequestUnstake(apUSDAmount) {
2499
+ return this.walletClient.writeContract({
2500
+ chain: this.chain,
2501
+ account: this.walletClient.account,
2502
+ address: this.routerAddress,
2503
+ abi: RouterABI,
2504
+ functionName: "redeemApUSDAndRequestUnstake",
2505
+ args: [apUSDAmount]
2506
+ });
2507
+ }
2508
+ /**
2509
+ * Redeem xBNB and request native unstake from Lista (starts unbonding period)
2510
+ */
2511
+ async redeemXBNBAndRequestUnstake(xBNBAmount) {
2512
+ return this.walletClient.writeContract({
2513
+ chain: this.chain,
2514
+ account: this.walletClient.account,
2515
+ address: this.routerAddress,
2516
+ abi: RouterABI,
2517
+ functionName: "redeemXBNBAndRequestUnstake",
2518
+ args: [xBNBAmount]
2519
+ });
2520
+ }
2521
+ /**
2522
+ * Claim BNB after unbonding period completes
2523
+ */
2524
+ async claimUnstake(requestIndex) {
2525
+ return this.walletClient.writeContract({
2526
+ chain: this.chain,
2527
+ account: this.walletClient.account,
2528
+ address: this.routerAddress,
2529
+ abi: RouterABI,
2530
+ functionName: "claimUnstake",
2531
+ args: [requestIndex]
2532
+ });
2533
+ }
2534
+ // ============ Transaction Helpers ============
2535
+ /**
2536
+ * Wait for transaction confirmation
2537
+ */
2538
+ async waitForTransaction(hash) {
2539
+ return this.publicClient.waitForTransactionReceipt({ hash });
2540
+ }
2541
+ };
2542
+ function createRouterReadClient(routerAddress, rpcUrl) {
2543
+ return new AspanRouterReadClient({
2544
+ routerAddress,
2545
+ chain: bsc2,
2546
+ rpcUrl
2547
+ });
2548
+ }
2549
+ function createRouterClient(routerAddress, account, rpcUrl) {
2550
+ return new AspanRouterClient({
2551
+ routerAddress,
2552
+ account,
2553
+ chain: bsc2,
2554
+ rpcUrl
2555
+ });
2556
+ }
2557
+ function createRouterTestnetReadClient(routerAddress, rpcUrl) {
2558
+ return new AspanRouterReadClient({
2559
+ routerAddress,
2560
+ chain: bscTestnet2,
2561
+ rpcUrl
2562
+ });
2563
+ }
2564
+ function createRouterTestnetClient(routerAddress, account, rpcUrl) {
2565
+ return new AspanRouterClient({
2566
+ routerAddress,
2567
+ account,
2568
+ chain: bscTestnet2,
2569
+ rpcUrl
2570
+ });
2571
+ }
2572
+
1414
2573
  // src/index.ts
1415
2574
  var PRECISION = 10n ** 18n;
1416
2575
  var BPS_PRECISION = 10000n;
@@ -1449,15 +2608,22 @@ function calculateAPY(previousRate, currentRate, periodDays) {
1449
2608
  export {
1450
2609
  AspanClient,
1451
2610
  AspanReadClient,
2611
+ AspanRouterClient,
2612
+ AspanRouterReadClient,
1452
2613
  BPS_PRECISION,
1453
2614
  DiamondABI,
1454
2615
  PRECISION,
1455
2616
  PRICE_PRECISION,
2617
+ RouterABI,
1456
2618
  calculateAPY,
1457
2619
  createAspanClient,
1458
2620
  createAspanReadClient,
1459
2621
  createAspanTestnetClient,
1460
2622
  createAspanTestnetReadClient,
2623
+ createRouterClient,
2624
+ createRouterReadClient,
2625
+ createRouterTestnetClient,
2626
+ createRouterTestnetReadClient,
1461
2627
  formatAmount,
1462
2628
  formatCR,
1463
2629
  formatFeeBPS,