@aspan/sdk 0.3.1 → 0.4.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.js CHANGED
@@ -25,6 +25,7 @@ __export(index_exports, {
25
25
  AspanRouterClient: () => AspanRouterClient,
26
26
  AspanRouterReadClient: () => AspanRouterReadClient,
27
27
  BPS_PRECISION: () => BPS_PRECISION,
28
+ BSC_ADDRESSES: () => BSC_ADDRESSES,
28
29
  DiamondABI: () => DiamondABI,
29
30
  PRECISION: () => PRECISION,
30
31
  PRICE_PRECISION: () => PRICE_PRECISION,
@@ -521,6 +522,30 @@ var DiamondABI = [
521
522
  outputs: [{ name: "", type: "bool", internalType: "bool" }],
522
523
  stateMutability: "view"
523
524
  },
525
+ {
526
+ type: "function",
527
+ name: "bootstrap",
528
+ inputs: [
529
+ { name: "_lstToken", type: "address", internalType: "address" },
530
+ { name: "_lstAmount", type: "uint256", internalType: "uint256" }
531
+ ],
532
+ outputs: [{ name: "xBNBAmount", type: "uint256", internalType: "uint256" }],
533
+ stateMutability: "nonpayable"
534
+ },
535
+ {
536
+ type: "function",
537
+ name: "isBootstrapped",
538
+ inputs: [],
539
+ outputs: [{ name: "", type: "bool", internalType: "bool" }],
540
+ stateMutability: "view"
541
+ },
542
+ {
543
+ type: "function",
544
+ name: "getBootstrapXBNBAmount",
545
+ inputs: [],
546
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
547
+ stateMutability: "view"
548
+ },
524
549
  // ============ StabilityModeFacet ============
525
550
  {
526
551
  type: "function",
@@ -553,6 +578,13 @@ var DiamondABI = [
553
578
  ],
554
579
  stateMutability: "nonpayable"
555
580
  },
581
+ {
582
+ type: "function",
583
+ name: "cleanXbnb",
584
+ inputs: [{ name: "_xBNBAmount", type: "uint256", internalType: "uint256" }],
585
+ outputs: [],
586
+ stateMutability: "nonpayable"
587
+ },
556
588
  // ============ StabilityModeFacet Events ============
557
589
  {
558
590
  type: "event",
@@ -572,6 +604,48 @@ var DiamondABI = [
572
604
  inputs: [],
573
605
  outputs: [{ name: "", type: "address", internalType: "address" }],
574
606
  stateMutability: "view"
607
+ },
608
+ // ============ Fee Manager ============
609
+ {
610
+ type: "function",
611
+ name: "setFeeManager",
612
+ inputs: [{ name: "_feeManager", type: "address", internalType: "address" }],
613
+ outputs: [],
614
+ stateMutability: "nonpayable"
615
+ },
616
+ {
617
+ type: "function",
618
+ name: "getFeeManager",
619
+ inputs: [],
620
+ outputs: [{ name: "", type: "address", internalType: "address" }],
621
+ stateMutability: "view"
622
+ },
623
+ {
624
+ type: "function",
625
+ name: "setFeeTiers",
626
+ inputs: [{
627
+ name: "_tiers",
628
+ type: "tuple[]",
629
+ internalType: "struct LibAppStorage.FeeTier[]",
630
+ components: [
631
+ { name: "minCR", type: "uint256", internalType: "uint256" },
632
+ { name: "apUSDMintFee", type: "uint16", internalType: "uint16" },
633
+ { name: "apUSDRedeemFee", type: "uint16", internalType: "uint16" },
634
+ { name: "xBNBMintFee", type: "uint16", internalType: "uint16" },
635
+ { name: "xBNBRedeemFee", type: "uint16", internalType: "uint16" },
636
+ { name: "apUSDMintDisabled", type: "bool", internalType: "bool" }
637
+ ]
638
+ }],
639
+ outputs: [],
640
+ stateMutability: "nonpayable"
641
+ },
642
+ {
643
+ type: "event",
644
+ name: "FeeManagerSet",
645
+ inputs: [
646
+ { name: "feeManager", type: "address", indexed: true, internalType: "address" }
647
+ ],
648
+ anonymous: false
575
649
  }
576
650
  ];
577
651
 
@@ -1216,6 +1290,29 @@ var AspanReadClient = class _AspanReadClient {
1216
1290
  functionName: "isPaused"
1217
1291
  });
1218
1292
  }
1293
+ // ============ Bootstrap View Functions ============
1294
+ /**
1295
+ * Check if xBNB liquidity has been bootstrapped
1296
+ * @returns true if bootstrap has been called
1297
+ */
1298
+ async isBootstrapped() {
1299
+ return this.publicClient.readContract({
1300
+ address: this.diamondAddress,
1301
+ abi: DiamondABI,
1302
+ functionName: "isBootstrapped"
1303
+ });
1304
+ }
1305
+ /**
1306
+ * Get the amount of xBNB locked in bootstrap (burned to dead address)
1307
+ * @returns xBNB amount in wei
1308
+ */
1309
+ async getBootstrapXBNBAmount() {
1310
+ return this.publicClient.readContract({
1311
+ address: this.diamondAddress,
1312
+ abi: DiamondABI,
1313
+ functionName: "getBootstrapXBNBAmount"
1314
+ });
1315
+ }
1219
1316
  // ============ Stability Mode View Functions ============
1220
1317
  async getStabilityMode() {
1221
1318
  try {
@@ -1415,6 +1512,75 @@ var AspanClient = class extends AspanReadClient {
1415
1512
  functionName: "harvestYield"
1416
1513
  });
1417
1514
  }
1515
+ // ============ Risk Management Functions ============
1516
+ /**
1517
+ * Trigger Stability Mode 2 forced conversion
1518
+ * @description Anyone can call when CR < 130%. Burns apUSD from stability pool
1519
+ * and mints xBNB to compensate stakers.
1520
+ * @param targetCR Target CR to restore to (in BPS, e.g., 14000 = 140%)
1521
+ * @returns Transaction hash
1522
+ */
1523
+ async triggerStabilityMode2(targetCR = 14000n) {
1524
+ return this.walletClient.writeContract({
1525
+ chain: this.chain,
1526
+ account: this.walletClient.account,
1527
+ address: this.diamondAddress,
1528
+ abi: DiamondABI,
1529
+ functionName: "triggerStabilityMode2",
1530
+ args: [targetCR]
1531
+ });
1532
+ }
1533
+ /**
1534
+ * Clean underwater xBNB (burn without getting LST back)
1535
+ * @description Only works when xBNB is underwater (price = 0)
1536
+ * @param xBNBAmount Amount of xBNB to clean (burn)
1537
+ * @returns Transaction hash
1538
+ */
1539
+ async cleanXbnb(xBNBAmount) {
1540
+ return this.walletClient.writeContract({
1541
+ chain: this.chain,
1542
+ account: this.walletClient.account,
1543
+ address: this.diamondAddress,
1544
+ abi: DiamondABI,
1545
+ functionName: "cleanXbnb",
1546
+ args: [xBNBAmount]
1547
+ });
1548
+ }
1549
+ // ============ Fee Management Functions ============
1550
+ /**
1551
+ * Set fee tiers (requires feeManager or owner role)
1552
+ * @param tiers Array of fee tier configurations
1553
+ * @returns Transaction hash
1554
+ */
1555
+ async setFeeTiers(tiers) {
1556
+ return this.walletClient.writeContract({
1557
+ chain: this.chain,
1558
+ account: this.walletClient.account,
1559
+ address: this.diamondAddress,
1560
+ abi: DiamondABI,
1561
+ functionName: "setFeeTiers",
1562
+ args: [tiers]
1563
+ });
1564
+ }
1565
+ // ============ Admin Functions ============
1566
+ /**
1567
+ * Bootstrap xBNB liquidity (owner only)
1568
+ * @description Initializes xBNB supply by minting to dead address, preventing extreme initial prices.
1569
+ * Similar to Uniswap V2's MINIMUM_LIQUIDITY. Can only be called once.
1570
+ * @param lstToken LST token address to deposit
1571
+ * @param lstAmount Amount of LST to deposit for bootstrap
1572
+ * @returns Transaction hash
1573
+ */
1574
+ async bootstrap(lstToken, lstAmount) {
1575
+ return this.walletClient.writeContract({
1576
+ chain: this.chain,
1577
+ account: this.walletClient.account,
1578
+ address: this.diamondAddress,
1579
+ abi: DiamondABI,
1580
+ functionName: "bootstrap",
1581
+ args: [lstToken, lstAmount]
1582
+ });
1583
+ }
1418
1584
  // ============ Transaction Helpers ============
1419
1585
  /**
1420
1586
  * Wait for transaction confirmation
@@ -1462,11 +1628,11 @@ var import_chains2 = require("viem/chains");
1462
1628
 
1463
1629
  // src/abi/router.ts
1464
1630
  var RouterABI = [
1465
- // ============ Core Swap+Mint Functions ============
1466
- // swapAndMintApUSD
1631
+ // ============ Core Functions ============
1632
+ // swapAndMint - unified swap + mint
1467
1633
  {
1468
1634
  type: "function",
1469
- name: "swapAndMintApUSD",
1635
+ name: "swapAndMint",
1470
1636
  inputs: [
1471
1637
  {
1472
1638
  name: "swapParams",
@@ -1492,45 +1658,26 @@ var RouterABI = [
1492
1658
  ],
1493
1659
  outputs: [
1494
1660
  { name: "lstAmount", type: "uint256" },
1495
- { name: "apUSDAmount", type: "uint256" }
1661
+ { name: "mintedAmount", type: "uint256" }
1496
1662
  ],
1497
1663
  stateMutability: "payable"
1498
1664
  },
1499
- // swapAndMintXBNB
1665
+ // swapAndMintDefault - simplified version using default LST
1500
1666
  {
1501
1667
  type: "function",
1502
- name: "swapAndMintXBNB",
1668
+ name: "swapAndMintDefault",
1503
1669
  inputs: [
1504
- {
1505
- name: "swapParams",
1506
- type: "tuple",
1507
- components: [
1508
- { name: "inputToken", type: "address" },
1509
- { name: "inputAmount", type: "uint256" },
1510
- { name: "targetLST", type: "address" },
1511
- { name: "minLSTOut", type: "uint256" },
1512
- { name: "poolFee", type: "uint24" }
1513
- ]
1514
- },
1515
- {
1516
- name: "mintParams",
1517
- type: "tuple",
1518
- components: [
1519
- { name: "mintXBNB", type: "bool" },
1520
- { name: "minMintOut", type: "uint256" },
1521
- { name: "recipient", type: "address" },
1522
- { name: "deadline", type: "uint256" }
1523
- ]
1524
- }
1525
- ],
1526
- outputs: [
1527
- { name: "lstAmount", type: "uint256" },
1528
- { name: "xBNBAmount", type: "uint256" }
1670
+ { name: "inputToken", type: "address" },
1671
+ { name: "inputAmount", type: "uint256" },
1672
+ { name: "mintXBNB", type: "bool" },
1673
+ { name: "minMintOut", type: "uint256" },
1674
+ { name: "deadline", type: "uint256" }
1529
1675
  ],
1676
+ outputs: [{ name: "mintedAmount", type: "uint256" }],
1530
1677
  stateMutability: "payable"
1531
1678
  },
1532
1679
  // ============ Stake+Mint Functions ============
1533
- // stakeAndMint
1680
+ // stakeAndMint - stake BNB directly to LST and mint
1534
1681
  {
1535
1682
  type: "function",
1536
1683
  name: "stakeAndMint",
@@ -1546,144 +1693,59 @@ var RouterABI = [
1546
1693
  ],
1547
1694
  stateMutability: "payable"
1548
1695
  },
1549
- // stakeAndMintApUSD (simplified)
1550
- {
1551
- type: "function",
1552
- name: "stakeAndMintApUSD",
1553
- inputs: [{ name: "minMintOut", type: "uint256" }],
1554
- outputs: [{ name: "apUSDAmount", type: "uint256" }],
1555
- stateMutability: "payable"
1556
- },
1557
- // stakeAndMintXBNB (simplified)
1558
- {
1559
- type: "function",
1560
- name: "stakeAndMintXBNB",
1561
- inputs: [{ name: "minMintOut", type: "uint256" }],
1562
- outputs: [{ name: "xBNBAmount", type: "uint256" }],
1563
- stateMutability: "payable"
1564
- },
1565
- // ============ Simplified Swap+Mint Functions ============
1566
- // swapAndMintApUSDDefault
1567
- {
1568
- type: "function",
1569
- name: "swapAndMintApUSDDefault",
1570
- inputs: [
1571
- { name: "inputToken", type: "address" },
1572
- { name: "inputAmount", type: "uint256" },
1573
- { name: "minMintOut", type: "uint256" },
1574
- { name: "deadline", type: "uint256" }
1575
- ],
1576
- outputs: [{ name: "apUSDAmount", type: "uint256" }],
1577
- stateMutability: "payable"
1578
- },
1579
- // swapAndMintXBNBDefault
1580
- {
1581
- type: "function",
1582
- name: "swapAndMintXBNBDefault",
1583
- inputs: [
1584
- { name: "inputToken", type: "address" },
1585
- { name: "inputAmount", type: "uint256" },
1586
- { name: "minMintOut", type: "uint256" },
1587
- { name: "deadline", type: "uint256" }
1588
- ],
1589
- outputs: [{ name: "xBNBAmount", type: "uint256" }],
1590
- stateMutability: "payable"
1591
- },
1592
1696
  // ============ Direct Mint/Redeem Functions ============
1593
- // mintApUSD
1697
+ // mint - unified mint function
1594
1698
  {
1595
1699
  type: "function",
1596
- name: "mintApUSD",
1700
+ name: "mint",
1597
1701
  inputs: [
1598
1702
  { name: "lst", type: "address" },
1599
1703
  { name: "lstAmount", type: "uint256" },
1704
+ { name: "mintXBNB", type: "bool" },
1600
1705
  { name: "minOut", type: "uint256" }
1601
1706
  ],
1602
- outputs: [{ name: "apUSDAmount", type: "uint256" }],
1707
+ outputs: [{ name: "mintedAmount", type: "uint256" }],
1603
1708
  stateMutability: "nonpayable"
1604
1709
  },
1605
- // mintXBNB
1710
+ // redeem - unified redeem function
1606
1711
  {
1607
1712
  type: "function",
1608
- name: "mintXBNB",
1713
+ name: "redeem",
1609
1714
  inputs: [
1610
1715
  { name: "lst", type: "address" },
1611
- { name: "lstAmount", type: "uint256" },
1612
- { name: "minOut", type: "uint256" }
1613
- ],
1614
- outputs: [{ name: "xBNBAmount", type: "uint256" }],
1615
- stateMutability: "nonpayable"
1616
- },
1617
- // redeemApUSD
1618
- {
1619
- type: "function",
1620
- name: "redeemApUSD",
1621
- inputs: [
1622
- { name: "lst", type: "address" },
1623
- { name: "apUSDAmount", type: "uint256" },
1716
+ { name: "redeemXBNB", type: "bool" },
1717
+ { name: "amount", type: "uint256" },
1624
1718
  { name: "minOut", type: "uint256" }
1625
1719
  ],
1626
1720
  outputs: [{ name: "lstAmount", type: "uint256" }],
1627
1721
  stateMutability: "nonpayable"
1628
1722
  },
1629
- // redeemXBNB
1630
- {
1631
- type: "function",
1632
- name: "redeemXBNB",
1633
- inputs: [
1634
- { name: "lst", type: "address" },
1635
- { name: "xBNBAmount", type: "uint256" },
1636
- { name: "minOut", type: "uint256" }
1637
- ],
1638
- outputs: [{ name: "lstAmount", type: "uint256" }],
1639
- stateMutability: "nonpayable"
1640
- },
1641
- // ============ Redeem + Swap Functions (V3 path) ============
1642
- // redeemApUSDAndSwap
1643
- {
1644
- type: "function",
1645
- name: "redeemApUSDAndSwap",
1646
- inputs: [
1647
- { name: "lst", type: "address" },
1648
- { name: "apUSDAmount", type: "uint256" },
1649
- { name: "path", type: "bytes" },
1650
- { name: "minOut", type: "uint256" },
1651
- { name: "deadline", type: "uint256" }
1652
- ],
1653
- outputs: [{ name: "outputAmount", type: "uint256" }],
1654
- stateMutability: "nonpayable"
1655
- },
1656
- // redeemXBNBAndSwap
1723
+ // ============ Redeem + Swap Functions ============
1724
+ // redeemAndSwap - unified redeem and swap via V3 path
1657
1725
  {
1658
1726
  type: "function",
1659
- name: "redeemXBNBAndSwap",
1727
+ name: "redeemAndSwap",
1660
1728
  inputs: [
1661
1729
  { name: "lst", type: "address" },
1662
- { name: "xBNBAmount", type: "uint256" },
1730
+ { name: "redeemXBNB", type: "bool" },
1731
+ { name: "amount", type: "uint256" },
1663
1732
  { name: "path", type: "bytes" },
1664
1733
  { name: "minOut", type: "uint256" },
1665
- { name: "deadline", type: "uint256" }
1734
+ { name: "deadline", type: "uint256" },
1735
+ { name: "unwrapBNB", type: "bool" }
1666
1736
  ],
1667
1737
  outputs: [{ name: "outputAmount", type: "uint256" }],
1668
1738
  stateMutability: "nonpayable"
1669
1739
  },
1670
1740
  // ============ Native Unstake Functions ============
1671
- // redeemApUSDAndRequestUnstake
1741
+ // redeemAndRequestUnstake - unified unstake request
1672
1742
  {
1673
1743
  type: "function",
1674
- name: "redeemApUSDAndRequestUnstake",
1675
- inputs: [{ name: "apUSDAmount", type: "uint256" }],
1676
- outputs: [
1677
- { name: "requestIndex", type: "uint256" },
1678
- { name: "slisBNBAmount", type: "uint256" }
1744
+ name: "redeemAndRequestUnstake",
1745
+ inputs: [
1746
+ { name: "redeemXBNB", type: "bool" },
1747
+ { name: "amount", type: "uint256" }
1679
1748
  ],
1680
- stateMutability: "nonpayable"
1681
- },
1682
- // redeemXBNBAndRequestUnstake
1683
- {
1684
- type: "function",
1685
- name: "redeemXBNBAndRequestUnstake",
1686
- inputs: [{ name: "xBNBAmount", type: "uint256" }],
1687
1749
  outputs: [
1688
1750
  { name: "requestIndex", type: "uint256" },
1689
1751
  { name: "slisBNBAmount", type: "uint256" }
@@ -1730,43 +1792,25 @@ var RouterABI = [
1730
1792
  outputs: [{ type: "bool" }],
1731
1793
  stateMutability: "view"
1732
1794
  },
1733
- // Preview functions
1734
- {
1735
- type: "function",
1736
- name: "previewMintApUSD",
1737
- inputs: [
1738
- { name: "lst", type: "address" },
1739
- { name: "lstAmount", type: "uint256" }
1740
- ],
1741
- outputs: [{ name: "apUSDAmount", type: "uint256" }],
1742
- stateMutability: "view"
1743
- },
1744
- {
1745
- type: "function",
1746
- name: "previewMintXBNB",
1747
- inputs: [
1748
- { name: "lst", type: "address" },
1749
- { name: "lstAmount", type: "uint256" }
1750
- ],
1751
- outputs: [{ name: "xBNBAmount", type: "uint256" }],
1752
- stateMutability: "view"
1753
- },
1795
+ // Preview functions - unified
1754
1796
  {
1755
1797
  type: "function",
1756
- name: "previewRedeemApUSD",
1798
+ name: "previewMint",
1757
1799
  inputs: [
1758
1800
  { name: "lst", type: "address" },
1759
- { name: "apUSDAmount", type: "uint256" }
1801
+ { name: "lstAmount", type: "uint256" },
1802
+ { name: "mintXBNB", type: "bool" }
1760
1803
  ],
1761
- outputs: [{ name: "lstAmount", type: "uint256" }],
1804
+ outputs: [{ name: "mintedAmount", type: "uint256" }],
1762
1805
  stateMutability: "view"
1763
1806
  },
1764
1807
  {
1765
1808
  type: "function",
1766
- name: "previewRedeemXBNB",
1809
+ name: "previewRedeem",
1767
1810
  inputs: [
1768
1811
  { name: "lst", type: "address" },
1769
- { name: "xBNBAmount", type: "uint256" }
1812
+ { name: "redeemXBNB", type: "bool" },
1813
+ { name: "amount", type: "uint256" }
1770
1814
  ],
1771
1815
  outputs: [{ name: "lstAmount", type: "uint256" }],
1772
1816
  stateMutability: "view"
@@ -1848,9 +1892,9 @@ var RouterABI = [
1848
1892
  name: "SwapAndMint",
1849
1893
  inputs: [
1850
1894
  { name: "user", type: "address", indexed: true },
1851
- { name: "inputToken", type: "address", indexed: false },
1895
+ { name: "inputToken", type: "address", indexed: true },
1852
1896
  { name: "inputAmount", type: "uint256", indexed: false },
1853
- { name: "lst", type: "address", indexed: false },
1897
+ { name: "targetLST", type: "address", indexed: true },
1854
1898
  { name: "lstAmount", type: "uint256", indexed: false },
1855
1899
  { name: "mintedToken", type: "address", indexed: false },
1856
1900
  { name: "mintedAmount", type: "uint256", indexed: false }
@@ -1862,20 +1906,28 @@ var RouterABI = [
1862
1906
  inputs: [
1863
1907
  { name: "user", type: "address", indexed: true },
1864
1908
  { name: "bnbAmount", type: "uint256", indexed: false },
1865
- { name: "lst", type: "address", indexed: false },
1909
+ { name: "targetLST", type: "address", indexed: true },
1866
1910
  { name: "lstAmount", type: "uint256", indexed: false },
1867
- { name: "mintedToken", type: "address", indexed: false },
1911
+ { name: "mintedToken", type: "address", indexed: true },
1868
1912
  { name: "mintedAmount", type: "uint256", indexed: false }
1869
1913
  ]
1870
1914
  },
1915
+ {
1916
+ type: "event",
1917
+ name: "DefaultLSTUpdated",
1918
+ inputs: [
1919
+ { name: "oldLST", type: "address", indexed: true },
1920
+ { name: "newLST", type: "address", indexed: true }
1921
+ ]
1922
+ },
1871
1923
  {
1872
1924
  type: "event",
1873
1925
  name: "Mint",
1874
1926
  inputs: [
1875
1927
  { name: "user", type: "address", indexed: true },
1876
- { name: "lst", type: "address", indexed: false },
1928
+ { name: "lst", type: "address", indexed: true },
1877
1929
  { name: "lstAmount", type: "uint256", indexed: false },
1878
- { name: "mintedToken", type: "address", indexed: false },
1930
+ { name: "mintedToken", type: "address", indexed: true },
1879
1931
  { name: "mintedAmount", type: "uint256", indexed: false }
1880
1932
  ]
1881
1933
  },
@@ -1884,9 +1936,9 @@ var RouterABI = [
1884
1936
  name: "Redeem",
1885
1937
  inputs: [
1886
1938
  { name: "user", type: "address", indexed: true },
1887
- { name: "redeemedToken", type: "address", indexed: false },
1939
+ { name: "redeemedToken", type: "address", indexed: true },
1888
1940
  { name: "redeemedAmount", type: "uint256", indexed: false },
1889
- { name: "lst", type: "address", indexed: false },
1941
+ { name: "lst", type: "address", indexed: true },
1890
1942
  { name: "lstAmount", type: "uint256", indexed: false }
1891
1943
  ]
1892
1944
  },
@@ -1899,7 +1951,7 @@ var RouterABI = [
1899
1951
  { name: "redeemedAmount", type: "uint256", indexed: false },
1900
1952
  { name: "lst", type: "address", indexed: false },
1901
1953
  { name: "lstAmount", type: "uint256", indexed: false },
1902
- { name: "outputToken", type: "address", indexed: false },
1954
+ { name: "outputToken", type: "address", indexed: true },
1903
1955
  { name: "outputAmount", type: "uint256", indexed: false }
1904
1956
  ]
1905
1957
  },
@@ -1908,7 +1960,7 @@ var RouterABI = [
1908
1960
  name: "UnstakeRequested",
1909
1961
  inputs: [
1910
1962
  { name: "user", type: "address", indexed: true },
1911
- { name: "requestIndex", type: "uint256", indexed: false },
1963
+ { name: "requestIndex", type: "uint256", indexed: true },
1912
1964
  { name: "redeemedToken", type: "address", indexed: false },
1913
1965
  { name: "redeemedAmount", type: "uint256", indexed: false },
1914
1966
  { name: "slisBNBAmount", type: "uint256", indexed: false }
@@ -1919,18 +1971,10 @@ var RouterABI = [
1919
1971
  name: "UnstakeClaimed",
1920
1972
  inputs: [
1921
1973
  { name: "user", type: "address", indexed: true },
1922
- { name: "requestIndex", type: "uint256", indexed: false },
1974
+ { name: "requestIndex", type: "uint256", indexed: true },
1923
1975
  { name: "bnbAmount", type: "uint256", indexed: false }
1924
1976
  ]
1925
1977
  },
1926
- {
1927
- type: "event",
1928
- name: "DefaultLSTUpdated",
1929
- inputs: [
1930
- { name: "oldLST", type: "address", indexed: false },
1931
- { name: "newLST", type: "address", indexed: false }
1932
- ]
1933
- },
1934
1978
  {
1935
1979
  type: "event",
1936
1980
  name: "OwnershipTransferred",
@@ -1952,7 +1996,7 @@ var RouterABI = [
1952
1996
  { type: "error", name: "SwapFailed", inputs: [] },
1953
1997
  { type: "error", name: "UnsupportedInputToken", inputs: [] },
1954
1998
  { type: "error", name: "UnsupportedLST", inputs: [] },
1955
- { type: "error", name: "V3PoolNotFound", inputs: [] },
1999
+ { type: "error", name: "UnsupportedSwapPath", inputs: [] },
1956
2000
  { type: "error", name: "WithdrawalAlreadyClaimed", inputs: [] },
1957
2001
  { type: "error", name: "WithdrawalNotClaimable", inputs: [] },
1958
2002
  { type: "error", name: "ZeroAmount", inputs: [] },
@@ -2021,47 +2065,31 @@ var AspanRouterReadClient = class {
2021
2065
  });
2022
2066
  }
2023
2067
  /**
2024
- * Preview apUSD mint output for a given LST amount
2025
- */
2026
- async previewMintApUSD(lst, lstAmount) {
2027
- return this.publicClient.readContract({
2028
- address: this.routerAddress,
2029
- abi: RouterABI,
2030
- functionName: "previewMintApUSD",
2031
- args: [lst, lstAmount]
2032
- });
2033
- }
2034
- /**
2035
- * Preview xBNB mint output for a given LST amount
2036
- */
2037
- async previewMintXBNB(lst, lstAmount) {
2038
- return this.publicClient.readContract({
2039
- address: this.routerAddress,
2040
- abi: RouterABI,
2041
- functionName: "previewMintXBNB",
2042
- args: [lst, lstAmount]
2043
- });
2044
- }
2045
- /**
2046
- * Preview LST output for redeeming apUSD
2068
+ * Preview mint output for a given LST amount
2069
+ * @param lst LST token address
2070
+ * @param lstAmount Amount of LST
2071
+ * @param mintXBNB true = preview xBNB mint, false = preview apUSD mint
2047
2072
  */
2048
- async previewRedeemApUSD(lst, apUSDAmount) {
2073
+ async previewMint(lst, lstAmount, mintXBNB) {
2049
2074
  return this.publicClient.readContract({
2050
2075
  address: this.routerAddress,
2051
2076
  abi: RouterABI,
2052
- functionName: "previewRedeemApUSD",
2053
- args: [lst, apUSDAmount]
2077
+ functionName: "previewMint",
2078
+ args: [lst, lstAmount, mintXBNB]
2054
2079
  });
2055
2080
  }
2056
2081
  /**
2057
- * Preview LST output for redeeming xBNB
2082
+ * Preview redeem output
2083
+ * @param lst LST token to receive
2084
+ * @param redeemXBNB true = redeem xBNB, false = redeem apUSD
2085
+ * @param amount Amount of apUSD/xBNB to redeem
2058
2086
  */
2059
- async previewRedeemXBNB(lst, xBNBAmount) {
2087
+ async previewRedeem(lst, redeemXBNB, amount) {
2060
2088
  return this.publicClient.readContract({
2061
2089
  address: this.routerAddress,
2062
2090
  abi: RouterABI,
2063
- functionName: "previewRedeemXBNB",
2064
- args: [lst, xBNBAmount]
2091
+ functionName: "previewRedeem",
2092
+ args: [lst, redeemXBNB, amount]
2065
2093
  });
2066
2094
  }
2067
2095
  /**
@@ -2167,16 +2195,18 @@ var AspanRouterClient = class extends AspanRouterReadClient {
2167
2195
  }
2168
2196
  // ============ Core Functions ============
2169
2197
  /**
2170
- * Swap input token to LST and mint apUSD
2198
+ * Swap input token to LST and mint apUSD or xBNB
2199
+ * @param params.swapParams Swap configuration
2200
+ * @param params.mintParams Mint configuration (mintXBNB determines output token)
2171
2201
  */
2172
- async swapAndMintApUSD(params) {
2202
+ async swapAndMint(params) {
2173
2203
  const value = params.swapParams.inputToken === import_viem2.zeroAddress ? params.swapParams.inputAmount : 0n;
2174
2204
  return this.walletClient.writeContract({
2175
2205
  chain: this.chain,
2176
2206
  account: this.walletClient.account,
2177
2207
  address: this.routerAddress,
2178
2208
  abi: RouterABI,
2179
- functionName: "swapAndMintApUSD",
2209
+ functionName: "swapAndMint",
2180
2210
  args: [
2181
2211
  {
2182
2212
  inputToken: params.swapParams.inputToken,
@@ -2186,8 +2216,7 @@ var AspanRouterClient = class extends AspanRouterReadClient {
2186
2216
  poolFee: params.swapParams.poolFee
2187
2217
  },
2188
2218
  {
2189
- mintXBNB: false,
2190
- // swapAndMintApUSD always mints apUSD
2219
+ mintXBNB: params.mintParams.mintXBNB,
2191
2220
  minMintOut: params.mintParams.minMintOut,
2192
2221
  recipient: params.mintParams.recipient,
2193
2222
  deadline: params.mintParams.deadline
@@ -2197,37 +2226,30 @@ var AspanRouterClient = class extends AspanRouterReadClient {
2197
2226
  });
2198
2227
  }
2199
2228
  /**
2200
- * Swap input token to LST and mint xBNB
2229
+ * Swap input token and mint using default LST (simplified)
2230
+ * @param params.mintXBNB true = mint xBNB, false = mint apUSD
2201
2231
  */
2202
- async swapAndMintXBNB(params) {
2203
- const value = params.swapParams.inputToken === import_viem2.zeroAddress ? params.swapParams.inputAmount : 0n;
2232
+ async swapAndMintDefault(params) {
2233
+ const value = params.inputToken === import_viem2.zeroAddress ? params.value ?? params.inputAmount : 0n;
2204
2234
  return this.walletClient.writeContract({
2205
2235
  chain: this.chain,
2206
2236
  account: this.walletClient.account,
2207
2237
  address: this.routerAddress,
2208
2238
  abi: RouterABI,
2209
- functionName: "swapAndMintXBNB",
2239
+ functionName: "swapAndMintDefault",
2210
2240
  args: [
2211
- {
2212
- inputToken: params.swapParams.inputToken,
2213
- inputAmount: params.swapParams.inputAmount,
2214
- targetLST: params.swapParams.targetLST,
2215
- minLSTOut: params.swapParams.minLSTOut,
2216
- poolFee: params.swapParams.poolFee
2217
- },
2218
- {
2219
- mintXBNB: true,
2220
- // swapAndMintXBNB always mints xBNB
2221
- minMintOut: params.mintParams.minMintOut,
2222
- recipient: params.mintParams.recipient,
2223
- deadline: params.mintParams.deadline
2224
- }
2241
+ params.inputToken,
2242
+ params.inputAmount,
2243
+ params.mintXBNB,
2244
+ params.minMintOut,
2245
+ params.deadline
2225
2246
  ],
2226
2247
  value
2227
2248
  });
2228
2249
  }
2229
2250
  /**
2230
2251
  * Stake native BNB directly to LST and mint
2252
+ * @param params.isXBNB true = mint xBNB, false = mint apUSD
2231
2253
  */
2232
2254
  async stakeAndMint(params) {
2233
2255
  return this.walletClient.writeContract({
@@ -2245,194 +2267,73 @@ var AspanRouterClient = class extends AspanRouterReadClient {
2245
2267
  value: params.value
2246
2268
  });
2247
2269
  }
2248
- // ============ Simplified Functions ============
2249
- /**
2250
- * Swap input token and mint apUSD using default LST
2251
- */
2252
- async swapAndMintApUSDDefault(params) {
2253
- const value = params.inputToken === import_viem2.zeroAddress ? params.value ?? params.inputAmount : 0n;
2254
- return this.walletClient.writeContract({
2255
- chain: this.chain,
2256
- account: this.walletClient.account,
2257
- address: this.routerAddress,
2258
- abi: RouterABI,
2259
- functionName: "swapAndMintApUSDDefault",
2260
- args: [
2261
- params.inputToken,
2262
- params.inputAmount,
2263
- params.minMintOut,
2264
- params.deadline
2265
- ],
2266
- value
2267
- });
2268
- }
2269
- /**
2270
- * Swap input token and mint xBNB using default LST
2271
- */
2272
- async swapAndMintXBNBDefault(params) {
2273
- const value = params.inputToken === import_viem2.zeroAddress ? params.value ?? params.inputAmount : 0n;
2274
- return this.walletClient.writeContract({
2275
- chain: this.chain,
2276
- account: this.walletClient.account,
2277
- address: this.routerAddress,
2278
- abi: RouterABI,
2279
- functionName: "swapAndMintXBNBDefault",
2280
- args: [
2281
- params.inputToken,
2282
- params.inputAmount,
2283
- params.minMintOut,
2284
- params.deadline
2285
- ],
2286
- value
2287
- });
2288
- }
2289
- /**
2290
- * Stake native BNB and mint apUSD using default LST
2291
- */
2292
- async stakeAndMintApUSD(minMintOut, value) {
2293
- return this.walletClient.writeContract({
2294
- chain: this.chain,
2295
- account: this.walletClient.account,
2296
- address: this.routerAddress,
2297
- abi: RouterABI,
2298
- functionName: "stakeAndMintApUSD",
2299
- args: [minMintOut],
2300
- value
2301
- });
2302
- }
2303
- /**
2304
- * Stake native BNB and mint xBNB using default LST
2305
- */
2306
- async stakeAndMintXBNB(minMintOut, value) {
2307
- return this.walletClient.writeContract({
2308
- chain: this.chain,
2309
- account: this.walletClient.account,
2310
- address: this.routerAddress,
2311
- abi: RouterABI,
2312
- functionName: "stakeAndMintXBNB",
2313
- args: [minMintOut],
2314
- value
2315
- });
2316
- }
2317
2270
  // ============ Direct Mint/Redeem Functions ============
2318
2271
  /**
2319
- * Mint apUSD by providing LST directly (no swap)
2272
+ * Mint apUSD or xBNB by providing LST directly (no swap)
2273
+ * @param params.mintXBNB true = mint xBNB, false = mint apUSD
2320
2274
  */
2321
- async mintApUSD(params) {
2275
+ async mint(params) {
2322
2276
  return this.walletClient.writeContract({
2323
2277
  chain: this.chain,
2324
2278
  account: this.walletClient.account,
2325
2279
  address: this.routerAddress,
2326
2280
  abi: RouterABI,
2327
- functionName: "mintApUSD",
2328
- args: [params.lst, params.lstAmount, params.minOut ?? 0n]
2281
+ functionName: "mint",
2282
+ args: [params.lst, params.lstAmount, params.mintXBNB, params.minOut ?? 0n]
2329
2283
  });
2330
2284
  }
2331
2285
  /**
2332
- * Mint xBNB by providing LST directly (no swap)
2286
+ * Redeem apUSD or xBNB for LST (no swap)
2287
+ * @param params.redeemXBNB true = redeem xBNB, false = redeem apUSD
2333
2288
  */
2334
- async mintXBNB(params) {
2289
+ async redeem(params) {
2335
2290
  return this.walletClient.writeContract({
2336
2291
  chain: this.chain,
2337
2292
  account: this.walletClient.account,
2338
2293
  address: this.routerAddress,
2339
2294
  abi: RouterABI,
2340
- functionName: "mintXBNB",
2341
- args: [params.lst, params.lstAmount, params.minOut ?? 0n]
2342
- });
2343
- }
2344
- /**
2345
- * Redeem apUSD for LST (no swap)
2346
- */
2347
- async redeemApUSD(params) {
2348
- return this.walletClient.writeContract({
2349
- chain: this.chain,
2350
- account: this.walletClient.account,
2351
- address: this.routerAddress,
2352
- abi: RouterABI,
2353
- functionName: "redeemApUSD",
2354
- args: [params.lst, params.apUSDAmount, params.minOut ?? 0n]
2355
- });
2356
- }
2357
- /**
2358
- * Redeem xBNB for LST (no swap)
2359
- */
2360
- async redeemXBNB(params) {
2361
- return this.walletClient.writeContract({
2362
- chain: this.chain,
2363
- account: this.walletClient.account,
2364
- address: this.routerAddress,
2365
- abi: RouterABI,
2366
- functionName: "redeemXBNB",
2367
- args: [params.lst, params.xBNBAmount, params.minOut ?? 0n]
2295
+ functionName: "redeem",
2296
+ args: [params.lst, params.redeemXBNB, params.amount, params.minOut ?? 0n]
2368
2297
  });
2369
2298
  }
2370
2299
  // ============ Redeem and Swap Functions ============
2371
2300
  /**
2372
- * Redeem apUSD and swap LST to output token via V3 path
2373
- * @param params.path - PancakeSwap V3 encoded path (use encodeV3Path helper)
2301
+ * Redeem apUSD/xBNB and swap LST to output token via V3 path
2302
+ * @param params.redeemXBNB true = redeem xBNB, false = redeem apUSD
2303
+ * @param params.path PancakeSwap V3 encoded path (use encodeV3Path helper)
2304
+ * @param params.unwrapBNB If true and output is WBNB, unwrap to native BNB
2374
2305
  */
2375
- async redeemApUSDAndSwap(params) {
2306
+ async redeemAndSwap(params) {
2376
2307
  return this.walletClient.writeContract({
2377
2308
  chain: this.chain,
2378
2309
  account: this.walletClient.account,
2379
2310
  address: this.routerAddress,
2380
2311
  abi: RouterABI,
2381
- functionName: "redeemApUSDAndSwap",
2312
+ functionName: "redeemAndSwap",
2382
2313
  args: [
2383
2314
  params.lst,
2315
+ params.redeemXBNB,
2384
2316
  params.amount,
2385
2317
  params.path,
2386
2318
  params.minOut,
2387
- params.deadline
2388
- ]
2389
- });
2390
- }
2391
- /**
2392
- * Redeem xBNB and swap LST to output token via V3 path
2393
- * @param params.path - PancakeSwap V3 encoded path (use encodeV3Path helper)
2394
- */
2395
- async redeemXBNBAndSwap(params) {
2396
- return this.walletClient.writeContract({
2397
- chain: this.chain,
2398
- account: this.walletClient.account,
2399
- address: this.routerAddress,
2400
- abi: RouterABI,
2401
- functionName: "redeemXBNBAndSwap",
2402
- args: [
2403
- params.lst,
2404
- params.amount,
2405
- params.path,
2406
- params.minOut,
2407
- params.deadline
2319
+ params.deadline,
2320
+ params.unwrapBNB
2408
2321
  ]
2409
2322
  });
2410
2323
  }
2411
2324
  // ============ Native Unstake Functions ============
2412
2325
  /**
2413
- * Redeem apUSD and request native unstake from Lista (starts unbonding period)
2326
+ * Redeem apUSD/xBNB and request native unstake from Lista (starts unbonding period)
2327
+ * @param params.redeemXBNB true = redeem xBNB, false = redeem apUSD
2414
2328
  */
2415
- async redeemApUSDAndRequestUnstake(apUSDAmount) {
2329
+ async redeemAndRequestUnstake(params) {
2416
2330
  return this.walletClient.writeContract({
2417
2331
  chain: this.chain,
2418
2332
  account: this.walletClient.account,
2419
2333
  address: this.routerAddress,
2420
2334
  abi: RouterABI,
2421
- functionName: "redeemApUSDAndRequestUnstake",
2422
- args: [apUSDAmount]
2423
- });
2424
- }
2425
- /**
2426
- * Redeem xBNB and request native unstake from Lista (starts unbonding period)
2427
- */
2428
- async redeemXBNBAndRequestUnstake(xBNBAmount) {
2429
- return this.walletClient.writeContract({
2430
- chain: this.chain,
2431
- account: this.walletClient.account,
2432
- address: this.routerAddress,
2433
- abi: RouterABI,
2434
- functionName: "redeemXBNBAndRequestUnstake",
2435
- args: [xBNBAmount]
2335
+ functionName: "redeemAndRequestUnstake",
2336
+ args: [params.redeemXBNB, params.amount]
2436
2337
  });
2437
2338
  }
2438
2339
  /**
@@ -2504,6 +2405,21 @@ function encodeV3Path(tokens, fees) {
2504
2405
  var PRECISION = 10n ** 18n;
2505
2406
  var BPS_PRECISION = 10000n;
2506
2407
  var PRICE_PRECISION = 10n ** 8n;
2408
+ var BSC_ADDRESSES = {
2409
+ diamond: "0x6a11B30d3a70727d5477D6d8090e144443fA1c78",
2410
+ router: "0x813d3D1A3154950E2f1d8718305426a335A974A9",
2411
+ apUSD: "0x4570047eeB5aDb4081c5d470494EB5134e34A287",
2412
+ xBNB: "0x0A0c9CD826e747D99F90D63e780B3727Da4D0d43",
2413
+ sApUSD: "0x73407A291c007a47CC926EcD5CaC256A1E2d00cF",
2414
+ // LSTs
2415
+ slisBNB: "0xB0b84D294e0C75A6abe60171b70edEb2EFd14A1B",
2416
+ asBNB: "0x77734e70b6E88b4d82fE632a168EDf6e700912b6",
2417
+ wclisBNB: "0x448f7c2fa4e5135a4a5B50879602cf3CD428e108",
2418
+ // Stablecoins
2419
+ USDT: "0x55d398326f99059fF775485246999027B3197955",
2420
+ USDC: "0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d",
2421
+ WBNB: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c"
2422
+ };
2507
2423
  function formatAmount(amount, decimals = 4) {
2508
2424
  const divisor = 10n ** BigInt(18 - decimals);
2509
2425
  const scaled = amount / divisor;
@@ -2542,6 +2458,7 @@ function calculateAPY(previousRate, currentRate, periodDays) {
2542
2458
  AspanRouterClient,
2543
2459
  AspanRouterReadClient,
2544
2460
  BPS_PRECISION,
2461
+ BSC_ADDRESSES,
2545
2462
  DiamondABI,
2546
2463
  PRECISION,
2547
2464
  PRICE_PRECISION,