@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.mjs CHANGED
@@ -476,6 +476,30 @@ var DiamondABI = [
476
476
  outputs: [{ name: "", type: "bool", internalType: "bool" }],
477
477
  stateMutability: "view"
478
478
  },
479
+ {
480
+ type: "function",
481
+ name: "bootstrap",
482
+ inputs: [
483
+ { name: "_lstToken", type: "address", internalType: "address" },
484
+ { name: "_lstAmount", type: "uint256", internalType: "uint256" }
485
+ ],
486
+ outputs: [{ name: "xBNBAmount", type: "uint256", internalType: "uint256" }],
487
+ stateMutability: "nonpayable"
488
+ },
489
+ {
490
+ type: "function",
491
+ name: "isBootstrapped",
492
+ inputs: [],
493
+ outputs: [{ name: "", type: "bool", internalType: "bool" }],
494
+ stateMutability: "view"
495
+ },
496
+ {
497
+ type: "function",
498
+ name: "getBootstrapXBNBAmount",
499
+ inputs: [],
500
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
501
+ stateMutability: "view"
502
+ },
479
503
  // ============ StabilityModeFacet ============
480
504
  {
481
505
  type: "function",
@@ -508,6 +532,13 @@ var DiamondABI = [
508
532
  ],
509
533
  stateMutability: "nonpayable"
510
534
  },
535
+ {
536
+ type: "function",
537
+ name: "cleanXbnb",
538
+ inputs: [{ name: "_xBNBAmount", type: "uint256", internalType: "uint256" }],
539
+ outputs: [],
540
+ stateMutability: "nonpayable"
541
+ },
511
542
  // ============ StabilityModeFacet Events ============
512
543
  {
513
544
  type: "event",
@@ -527,6 +558,48 @@ var DiamondABI = [
527
558
  inputs: [],
528
559
  outputs: [{ name: "", type: "address", internalType: "address" }],
529
560
  stateMutability: "view"
561
+ },
562
+ // ============ Fee Manager ============
563
+ {
564
+ type: "function",
565
+ name: "setFeeManager",
566
+ inputs: [{ name: "_feeManager", type: "address", internalType: "address" }],
567
+ outputs: [],
568
+ stateMutability: "nonpayable"
569
+ },
570
+ {
571
+ type: "function",
572
+ name: "getFeeManager",
573
+ inputs: [],
574
+ outputs: [{ name: "", type: "address", internalType: "address" }],
575
+ stateMutability: "view"
576
+ },
577
+ {
578
+ type: "function",
579
+ name: "setFeeTiers",
580
+ inputs: [{
581
+ name: "_tiers",
582
+ type: "tuple[]",
583
+ internalType: "struct LibAppStorage.FeeTier[]",
584
+ components: [
585
+ { name: "minCR", type: "uint256", internalType: "uint256" },
586
+ { name: "apUSDMintFee", type: "uint16", internalType: "uint16" },
587
+ { name: "apUSDRedeemFee", type: "uint16", internalType: "uint16" },
588
+ { name: "xBNBMintFee", type: "uint16", internalType: "uint16" },
589
+ { name: "xBNBRedeemFee", type: "uint16", internalType: "uint16" },
590
+ { name: "apUSDMintDisabled", type: "bool", internalType: "bool" }
591
+ ]
592
+ }],
593
+ outputs: [],
594
+ stateMutability: "nonpayable"
595
+ },
596
+ {
597
+ type: "event",
598
+ name: "FeeManagerSet",
599
+ inputs: [
600
+ { name: "feeManager", type: "address", indexed: true, internalType: "address" }
601
+ ],
602
+ anonymous: false
530
603
  }
531
604
  ];
532
605
 
@@ -1171,6 +1244,29 @@ var AspanReadClient = class _AspanReadClient {
1171
1244
  functionName: "isPaused"
1172
1245
  });
1173
1246
  }
1247
+ // ============ Bootstrap View Functions ============
1248
+ /**
1249
+ * Check if xBNB liquidity has been bootstrapped
1250
+ * @returns true if bootstrap has been called
1251
+ */
1252
+ async isBootstrapped() {
1253
+ return this.publicClient.readContract({
1254
+ address: this.diamondAddress,
1255
+ abi: DiamondABI,
1256
+ functionName: "isBootstrapped"
1257
+ });
1258
+ }
1259
+ /**
1260
+ * Get the amount of xBNB locked in bootstrap (burned to dead address)
1261
+ * @returns xBNB amount in wei
1262
+ */
1263
+ async getBootstrapXBNBAmount() {
1264
+ return this.publicClient.readContract({
1265
+ address: this.diamondAddress,
1266
+ abi: DiamondABI,
1267
+ functionName: "getBootstrapXBNBAmount"
1268
+ });
1269
+ }
1174
1270
  // ============ Stability Mode View Functions ============
1175
1271
  async getStabilityMode() {
1176
1272
  try {
@@ -1370,6 +1466,75 @@ var AspanClient = class extends AspanReadClient {
1370
1466
  functionName: "harvestYield"
1371
1467
  });
1372
1468
  }
1469
+ // ============ Risk Management Functions ============
1470
+ /**
1471
+ * Trigger Stability Mode 2 forced conversion
1472
+ * @description Anyone can call when CR < 130%. Burns apUSD from stability pool
1473
+ * and mints xBNB to compensate stakers.
1474
+ * @param targetCR Target CR to restore to (in BPS, e.g., 14000 = 140%)
1475
+ * @returns Transaction hash
1476
+ */
1477
+ async triggerStabilityMode2(targetCR = 14000n) {
1478
+ return this.walletClient.writeContract({
1479
+ chain: this.chain,
1480
+ account: this.walletClient.account,
1481
+ address: this.diamondAddress,
1482
+ abi: DiamondABI,
1483
+ functionName: "triggerStabilityMode2",
1484
+ args: [targetCR]
1485
+ });
1486
+ }
1487
+ /**
1488
+ * Clean underwater xBNB (burn without getting LST back)
1489
+ * @description Only works when xBNB is underwater (price = 0)
1490
+ * @param xBNBAmount Amount of xBNB to clean (burn)
1491
+ * @returns Transaction hash
1492
+ */
1493
+ async cleanXbnb(xBNBAmount) {
1494
+ return this.walletClient.writeContract({
1495
+ chain: this.chain,
1496
+ account: this.walletClient.account,
1497
+ address: this.diamondAddress,
1498
+ abi: DiamondABI,
1499
+ functionName: "cleanXbnb",
1500
+ args: [xBNBAmount]
1501
+ });
1502
+ }
1503
+ // ============ Fee Management Functions ============
1504
+ /**
1505
+ * Set fee tiers (requires feeManager or owner role)
1506
+ * @param tiers Array of fee tier configurations
1507
+ * @returns Transaction hash
1508
+ */
1509
+ async setFeeTiers(tiers) {
1510
+ return this.walletClient.writeContract({
1511
+ chain: this.chain,
1512
+ account: this.walletClient.account,
1513
+ address: this.diamondAddress,
1514
+ abi: DiamondABI,
1515
+ functionName: "setFeeTiers",
1516
+ args: [tiers]
1517
+ });
1518
+ }
1519
+ // ============ Admin Functions ============
1520
+ /**
1521
+ * Bootstrap xBNB liquidity (owner only)
1522
+ * @description Initializes xBNB supply by minting to dead address, preventing extreme initial prices.
1523
+ * Similar to Uniswap V2's MINIMUM_LIQUIDITY. Can only be called once.
1524
+ * @param lstToken LST token address to deposit
1525
+ * @param lstAmount Amount of LST to deposit for bootstrap
1526
+ * @returns Transaction hash
1527
+ */
1528
+ async bootstrap(lstToken, lstAmount) {
1529
+ return this.walletClient.writeContract({
1530
+ chain: this.chain,
1531
+ account: this.walletClient.account,
1532
+ address: this.diamondAddress,
1533
+ abi: DiamondABI,
1534
+ functionName: "bootstrap",
1535
+ args: [lstToken, lstAmount]
1536
+ });
1537
+ }
1373
1538
  // ============ Transaction Helpers ============
1374
1539
  /**
1375
1540
  * Wait for transaction confirmation
@@ -1422,11 +1587,11 @@ import { bsc as bsc2, bscTestnet as bscTestnet2 } from "viem/chains";
1422
1587
 
1423
1588
  // src/abi/router.ts
1424
1589
  var RouterABI = [
1425
- // ============ Core Swap+Mint Functions ============
1426
- // swapAndMintApUSD
1590
+ // ============ Core Functions ============
1591
+ // swapAndMint - unified swap + mint
1427
1592
  {
1428
1593
  type: "function",
1429
- name: "swapAndMintApUSD",
1594
+ name: "swapAndMint",
1430
1595
  inputs: [
1431
1596
  {
1432
1597
  name: "swapParams",
@@ -1452,45 +1617,26 @@ var RouterABI = [
1452
1617
  ],
1453
1618
  outputs: [
1454
1619
  { name: "lstAmount", type: "uint256" },
1455
- { name: "apUSDAmount", type: "uint256" }
1620
+ { name: "mintedAmount", type: "uint256" }
1456
1621
  ],
1457
1622
  stateMutability: "payable"
1458
1623
  },
1459
- // swapAndMintXBNB
1624
+ // swapAndMintDefault - simplified version using default LST
1460
1625
  {
1461
1626
  type: "function",
1462
- name: "swapAndMintXBNB",
1627
+ name: "swapAndMintDefault",
1463
1628
  inputs: [
1464
- {
1465
- name: "swapParams",
1466
- type: "tuple",
1467
- components: [
1468
- { name: "inputToken", type: "address" },
1469
- { name: "inputAmount", type: "uint256" },
1470
- { name: "targetLST", type: "address" },
1471
- { name: "minLSTOut", type: "uint256" },
1472
- { name: "poolFee", type: "uint24" }
1473
- ]
1474
- },
1475
- {
1476
- name: "mintParams",
1477
- type: "tuple",
1478
- components: [
1479
- { name: "mintXBNB", type: "bool" },
1480
- { name: "minMintOut", type: "uint256" },
1481
- { name: "recipient", type: "address" },
1482
- { name: "deadline", type: "uint256" }
1483
- ]
1484
- }
1485
- ],
1486
- outputs: [
1487
- { name: "lstAmount", type: "uint256" },
1488
- { name: "xBNBAmount", type: "uint256" }
1629
+ { name: "inputToken", type: "address" },
1630
+ { name: "inputAmount", type: "uint256" },
1631
+ { name: "mintXBNB", type: "bool" },
1632
+ { name: "minMintOut", type: "uint256" },
1633
+ { name: "deadline", type: "uint256" }
1489
1634
  ],
1635
+ outputs: [{ name: "mintedAmount", type: "uint256" }],
1490
1636
  stateMutability: "payable"
1491
1637
  },
1492
1638
  // ============ Stake+Mint Functions ============
1493
- // stakeAndMint
1639
+ // stakeAndMint - stake BNB directly to LST and mint
1494
1640
  {
1495
1641
  type: "function",
1496
1642
  name: "stakeAndMint",
@@ -1506,144 +1652,59 @@ var RouterABI = [
1506
1652
  ],
1507
1653
  stateMutability: "payable"
1508
1654
  },
1509
- // stakeAndMintApUSD (simplified)
1510
- {
1511
- type: "function",
1512
- name: "stakeAndMintApUSD",
1513
- inputs: [{ name: "minMintOut", type: "uint256" }],
1514
- outputs: [{ name: "apUSDAmount", type: "uint256" }],
1515
- stateMutability: "payable"
1516
- },
1517
- // stakeAndMintXBNB (simplified)
1518
- {
1519
- type: "function",
1520
- name: "stakeAndMintXBNB",
1521
- inputs: [{ name: "minMintOut", type: "uint256" }],
1522
- outputs: [{ name: "xBNBAmount", type: "uint256" }],
1523
- stateMutability: "payable"
1524
- },
1525
- // ============ Simplified Swap+Mint Functions ============
1526
- // swapAndMintApUSDDefault
1527
- {
1528
- type: "function",
1529
- name: "swapAndMintApUSDDefault",
1530
- inputs: [
1531
- { name: "inputToken", type: "address" },
1532
- { name: "inputAmount", type: "uint256" },
1533
- { name: "minMintOut", type: "uint256" },
1534
- { name: "deadline", type: "uint256" }
1535
- ],
1536
- outputs: [{ name: "apUSDAmount", type: "uint256" }],
1537
- stateMutability: "payable"
1538
- },
1539
- // swapAndMintXBNBDefault
1540
- {
1541
- type: "function",
1542
- name: "swapAndMintXBNBDefault",
1543
- inputs: [
1544
- { name: "inputToken", type: "address" },
1545
- { name: "inputAmount", type: "uint256" },
1546
- { name: "minMintOut", type: "uint256" },
1547
- { name: "deadline", type: "uint256" }
1548
- ],
1549
- outputs: [{ name: "xBNBAmount", type: "uint256" }],
1550
- stateMutability: "payable"
1551
- },
1552
1655
  // ============ Direct Mint/Redeem Functions ============
1553
- // mintApUSD
1656
+ // mint - unified mint function
1554
1657
  {
1555
1658
  type: "function",
1556
- name: "mintApUSD",
1659
+ name: "mint",
1557
1660
  inputs: [
1558
1661
  { name: "lst", type: "address" },
1559
1662
  { name: "lstAmount", type: "uint256" },
1663
+ { name: "mintXBNB", type: "bool" },
1560
1664
  { name: "minOut", type: "uint256" }
1561
1665
  ],
1562
- outputs: [{ name: "apUSDAmount", type: "uint256" }],
1666
+ outputs: [{ name: "mintedAmount", type: "uint256" }],
1563
1667
  stateMutability: "nonpayable"
1564
1668
  },
1565
- // mintXBNB
1669
+ // redeem - unified redeem function
1566
1670
  {
1567
1671
  type: "function",
1568
- name: "mintXBNB",
1672
+ name: "redeem",
1569
1673
  inputs: [
1570
1674
  { name: "lst", type: "address" },
1571
- { name: "lstAmount", type: "uint256" },
1572
- { name: "minOut", type: "uint256" }
1573
- ],
1574
- outputs: [{ name: "xBNBAmount", type: "uint256" }],
1575
- stateMutability: "nonpayable"
1576
- },
1577
- // redeemApUSD
1578
- {
1579
- type: "function",
1580
- name: "redeemApUSD",
1581
- inputs: [
1582
- { name: "lst", type: "address" },
1583
- { name: "apUSDAmount", type: "uint256" },
1675
+ { name: "redeemXBNB", type: "bool" },
1676
+ { name: "amount", type: "uint256" },
1584
1677
  { name: "minOut", type: "uint256" }
1585
1678
  ],
1586
1679
  outputs: [{ name: "lstAmount", type: "uint256" }],
1587
1680
  stateMutability: "nonpayable"
1588
1681
  },
1589
- // redeemXBNB
1590
- {
1591
- type: "function",
1592
- name: "redeemXBNB",
1593
- inputs: [
1594
- { name: "lst", type: "address" },
1595
- { name: "xBNBAmount", type: "uint256" },
1596
- { name: "minOut", type: "uint256" }
1597
- ],
1598
- outputs: [{ name: "lstAmount", type: "uint256" }],
1599
- stateMutability: "nonpayable"
1600
- },
1601
- // ============ Redeem + Swap Functions (V3 path) ============
1602
- // redeemApUSDAndSwap
1603
- {
1604
- type: "function",
1605
- name: "redeemApUSDAndSwap",
1606
- inputs: [
1607
- { name: "lst", type: "address" },
1608
- { name: "apUSDAmount", type: "uint256" },
1609
- { name: "path", type: "bytes" },
1610
- { name: "minOut", type: "uint256" },
1611
- { name: "deadline", type: "uint256" }
1612
- ],
1613
- outputs: [{ name: "outputAmount", type: "uint256" }],
1614
- stateMutability: "nonpayable"
1615
- },
1616
- // redeemXBNBAndSwap
1682
+ // ============ Redeem + Swap Functions ============
1683
+ // redeemAndSwap - unified redeem and swap via V3 path
1617
1684
  {
1618
1685
  type: "function",
1619
- name: "redeemXBNBAndSwap",
1686
+ name: "redeemAndSwap",
1620
1687
  inputs: [
1621
1688
  { name: "lst", type: "address" },
1622
- { name: "xBNBAmount", type: "uint256" },
1689
+ { name: "redeemXBNB", type: "bool" },
1690
+ { name: "amount", type: "uint256" },
1623
1691
  { name: "path", type: "bytes" },
1624
1692
  { name: "minOut", type: "uint256" },
1625
- { name: "deadline", type: "uint256" }
1693
+ { name: "deadline", type: "uint256" },
1694
+ { name: "unwrapBNB", type: "bool" }
1626
1695
  ],
1627
1696
  outputs: [{ name: "outputAmount", type: "uint256" }],
1628
1697
  stateMutability: "nonpayable"
1629
1698
  },
1630
1699
  // ============ Native Unstake Functions ============
1631
- // redeemApUSDAndRequestUnstake
1700
+ // redeemAndRequestUnstake - unified unstake request
1632
1701
  {
1633
1702
  type: "function",
1634
- name: "redeemApUSDAndRequestUnstake",
1635
- inputs: [{ name: "apUSDAmount", type: "uint256" }],
1636
- outputs: [
1637
- { name: "requestIndex", type: "uint256" },
1638
- { name: "slisBNBAmount", type: "uint256" }
1703
+ name: "redeemAndRequestUnstake",
1704
+ inputs: [
1705
+ { name: "redeemXBNB", type: "bool" },
1706
+ { name: "amount", type: "uint256" }
1639
1707
  ],
1640
- stateMutability: "nonpayable"
1641
- },
1642
- // redeemXBNBAndRequestUnstake
1643
- {
1644
- type: "function",
1645
- name: "redeemXBNBAndRequestUnstake",
1646
- inputs: [{ name: "xBNBAmount", type: "uint256" }],
1647
1708
  outputs: [
1648
1709
  { name: "requestIndex", type: "uint256" },
1649
1710
  { name: "slisBNBAmount", type: "uint256" }
@@ -1690,43 +1751,25 @@ var RouterABI = [
1690
1751
  outputs: [{ type: "bool" }],
1691
1752
  stateMutability: "view"
1692
1753
  },
1693
- // Preview functions
1694
- {
1695
- type: "function",
1696
- name: "previewMintApUSD",
1697
- inputs: [
1698
- { name: "lst", type: "address" },
1699
- { name: "lstAmount", type: "uint256" }
1700
- ],
1701
- outputs: [{ name: "apUSDAmount", type: "uint256" }],
1702
- stateMutability: "view"
1703
- },
1704
- {
1705
- type: "function",
1706
- name: "previewMintXBNB",
1707
- inputs: [
1708
- { name: "lst", type: "address" },
1709
- { name: "lstAmount", type: "uint256" }
1710
- ],
1711
- outputs: [{ name: "xBNBAmount", type: "uint256" }],
1712
- stateMutability: "view"
1713
- },
1754
+ // Preview functions - unified
1714
1755
  {
1715
1756
  type: "function",
1716
- name: "previewRedeemApUSD",
1757
+ name: "previewMint",
1717
1758
  inputs: [
1718
1759
  { name: "lst", type: "address" },
1719
- { name: "apUSDAmount", type: "uint256" }
1760
+ { name: "lstAmount", type: "uint256" },
1761
+ { name: "mintXBNB", type: "bool" }
1720
1762
  ],
1721
- outputs: [{ name: "lstAmount", type: "uint256" }],
1763
+ outputs: [{ name: "mintedAmount", type: "uint256" }],
1722
1764
  stateMutability: "view"
1723
1765
  },
1724
1766
  {
1725
1767
  type: "function",
1726
- name: "previewRedeemXBNB",
1768
+ name: "previewRedeem",
1727
1769
  inputs: [
1728
1770
  { name: "lst", type: "address" },
1729
- { name: "xBNBAmount", type: "uint256" }
1771
+ { name: "redeemXBNB", type: "bool" },
1772
+ { name: "amount", type: "uint256" }
1730
1773
  ],
1731
1774
  outputs: [{ name: "lstAmount", type: "uint256" }],
1732
1775
  stateMutability: "view"
@@ -1808,9 +1851,9 @@ var RouterABI = [
1808
1851
  name: "SwapAndMint",
1809
1852
  inputs: [
1810
1853
  { name: "user", type: "address", indexed: true },
1811
- { name: "inputToken", type: "address", indexed: false },
1854
+ { name: "inputToken", type: "address", indexed: true },
1812
1855
  { name: "inputAmount", type: "uint256", indexed: false },
1813
- { name: "lst", type: "address", indexed: false },
1856
+ { name: "targetLST", type: "address", indexed: true },
1814
1857
  { name: "lstAmount", type: "uint256", indexed: false },
1815
1858
  { name: "mintedToken", type: "address", indexed: false },
1816
1859
  { name: "mintedAmount", type: "uint256", indexed: false }
@@ -1822,20 +1865,28 @@ var RouterABI = [
1822
1865
  inputs: [
1823
1866
  { name: "user", type: "address", indexed: true },
1824
1867
  { name: "bnbAmount", type: "uint256", indexed: false },
1825
- { name: "lst", type: "address", indexed: false },
1868
+ { name: "targetLST", type: "address", indexed: true },
1826
1869
  { name: "lstAmount", type: "uint256", indexed: false },
1827
- { name: "mintedToken", type: "address", indexed: false },
1870
+ { name: "mintedToken", type: "address", indexed: true },
1828
1871
  { name: "mintedAmount", type: "uint256", indexed: false }
1829
1872
  ]
1830
1873
  },
1874
+ {
1875
+ type: "event",
1876
+ name: "DefaultLSTUpdated",
1877
+ inputs: [
1878
+ { name: "oldLST", type: "address", indexed: true },
1879
+ { name: "newLST", type: "address", indexed: true }
1880
+ ]
1881
+ },
1831
1882
  {
1832
1883
  type: "event",
1833
1884
  name: "Mint",
1834
1885
  inputs: [
1835
1886
  { name: "user", type: "address", indexed: true },
1836
- { name: "lst", type: "address", indexed: false },
1887
+ { name: "lst", type: "address", indexed: true },
1837
1888
  { name: "lstAmount", type: "uint256", indexed: false },
1838
- { name: "mintedToken", type: "address", indexed: false },
1889
+ { name: "mintedToken", type: "address", indexed: true },
1839
1890
  { name: "mintedAmount", type: "uint256", indexed: false }
1840
1891
  ]
1841
1892
  },
@@ -1844,9 +1895,9 @@ var RouterABI = [
1844
1895
  name: "Redeem",
1845
1896
  inputs: [
1846
1897
  { name: "user", type: "address", indexed: true },
1847
- { name: "redeemedToken", type: "address", indexed: false },
1898
+ { name: "redeemedToken", type: "address", indexed: true },
1848
1899
  { name: "redeemedAmount", type: "uint256", indexed: false },
1849
- { name: "lst", type: "address", indexed: false },
1900
+ { name: "lst", type: "address", indexed: true },
1850
1901
  { name: "lstAmount", type: "uint256", indexed: false }
1851
1902
  ]
1852
1903
  },
@@ -1859,7 +1910,7 @@ var RouterABI = [
1859
1910
  { name: "redeemedAmount", type: "uint256", indexed: false },
1860
1911
  { name: "lst", type: "address", indexed: false },
1861
1912
  { name: "lstAmount", type: "uint256", indexed: false },
1862
- { name: "outputToken", type: "address", indexed: false },
1913
+ { name: "outputToken", type: "address", indexed: true },
1863
1914
  { name: "outputAmount", type: "uint256", indexed: false }
1864
1915
  ]
1865
1916
  },
@@ -1868,7 +1919,7 @@ var RouterABI = [
1868
1919
  name: "UnstakeRequested",
1869
1920
  inputs: [
1870
1921
  { name: "user", type: "address", indexed: true },
1871
- { name: "requestIndex", type: "uint256", indexed: false },
1922
+ { name: "requestIndex", type: "uint256", indexed: true },
1872
1923
  { name: "redeemedToken", type: "address", indexed: false },
1873
1924
  { name: "redeemedAmount", type: "uint256", indexed: false },
1874
1925
  { name: "slisBNBAmount", type: "uint256", indexed: false }
@@ -1879,18 +1930,10 @@ var RouterABI = [
1879
1930
  name: "UnstakeClaimed",
1880
1931
  inputs: [
1881
1932
  { name: "user", type: "address", indexed: true },
1882
- { name: "requestIndex", type: "uint256", indexed: false },
1933
+ { name: "requestIndex", type: "uint256", indexed: true },
1883
1934
  { name: "bnbAmount", type: "uint256", indexed: false }
1884
1935
  ]
1885
1936
  },
1886
- {
1887
- type: "event",
1888
- name: "DefaultLSTUpdated",
1889
- inputs: [
1890
- { name: "oldLST", type: "address", indexed: false },
1891
- { name: "newLST", type: "address", indexed: false }
1892
- ]
1893
- },
1894
1937
  {
1895
1938
  type: "event",
1896
1939
  name: "OwnershipTransferred",
@@ -1912,7 +1955,7 @@ var RouterABI = [
1912
1955
  { type: "error", name: "SwapFailed", inputs: [] },
1913
1956
  { type: "error", name: "UnsupportedInputToken", inputs: [] },
1914
1957
  { type: "error", name: "UnsupportedLST", inputs: [] },
1915
- { type: "error", name: "V3PoolNotFound", inputs: [] },
1958
+ { type: "error", name: "UnsupportedSwapPath", inputs: [] },
1916
1959
  { type: "error", name: "WithdrawalAlreadyClaimed", inputs: [] },
1917
1960
  { type: "error", name: "WithdrawalNotClaimable", inputs: [] },
1918
1961
  { type: "error", name: "ZeroAmount", inputs: [] },
@@ -1981,47 +2024,31 @@ var AspanRouterReadClient = class {
1981
2024
  });
1982
2025
  }
1983
2026
  /**
1984
- * Preview apUSD mint output for a given LST amount
1985
- */
1986
- async previewMintApUSD(lst, lstAmount) {
1987
- return this.publicClient.readContract({
1988
- address: this.routerAddress,
1989
- abi: RouterABI,
1990
- functionName: "previewMintApUSD",
1991
- args: [lst, lstAmount]
1992
- });
1993
- }
1994
- /**
1995
- * Preview xBNB mint output for a given LST amount
1996
- */
1997
- async previewMintXBNB(lst, lstAmount) {
1998
- return this.publicClient.readContract({
1999
- address: this.routerAddress,
2000
- abi: RouterABI,
2001
- functionName: "previewMintXBNB",
2002
- args: [lst, lstAmount]
2003
- });
2004
- }
2005
- /**
2006
- * Preview LST output for redeeming apUSD
2027
+ * Preview mint output for a given LST amount
2028
+ * @param lst LST token address
2029
+ * @param lstAmount Amount of LST
2030
+ * @param mintXBNB true = preview xBNB mint, false = preview apUSD mint
2007
2031
  */
2008
- async previewRedeemApUSD(lst, apUSDAmount) {
2032
+ async previewMint(lst, lstAmount, mintXBNB) {
2009
2033
  return this.publicClient.readContract({
2010
2034
  address: this.routerAddress,
2011
2035
  abi: RouterABI,
2012
- functionName: "previewRedeemApUSD",
2013
- args: [lst, apUSDAmount]
2036
+ functionName: "previewMint",
2037
+ args: [lst, lstAmount, mintXBNB]
2014
2038
  });
2015
2039
  }
2016
2040
  /**
2017
- * Preview LST output for redeeming xBNB
2041
+ * Preview redeem output
2042
+ * @param lst LST token to receive
2043
+ * @param redeemXBNB true = redeem xBNB, false = redeem apUSD
2044
+ * @param amount Amount of apUSD/xBNB to redeem
2018
2045
  */
2019
- async previewRedeemXBNB(lst, xBNBAmount) {
2046
+ async previewRedeem(lst, redeemXBNB, amount) {
2020
2047
  return this.publicClient.readContract({
2021
2048
  address: this.routerAddress,
2022
2049
  abi: RouterABI,
2023
- functionName: "previewRedeemXBNB",
2024
- args: [lst, xBNBAmount]
2050
+ functionName: "previewRedeem",
2051
+ args: [lst, redeemXBNB, amount]
2025
2052
  });
2026
2053
  }
2027
2054
  /**
@@ -2127,16 +2154,18 @@ var AspanRouterClient = class extends AspanRouterReadClient {
2127
2154
  }
2128
2155
  // ============ Core Functions ============
2129
2156
  /**
2130
- * Swap input token to LST and mint apUSD
2157
+ * Swap input token to LST and mint apUSD or xBNB
2158
+ * @param params.swapParams Swap configuration
2159
+ * @param params.mintParams Mint configuration (mintXBNB determines output token)
2131
2160
  */
2132
- async swapAndMintApUSD(params) {
2161
+ async swapAndMint(params) {
2133
2162
  const value = params.swapParams.inputToken === zeroAddress ? params.swapParams.inputAmount : 0n;
2134
2163
  return this.walletClient.writeContract({
2135
2164
  chain: this.chain,
2136
2165
  account: this.walletClient.account,
2137
2166
  address: this.routerAddress,
2138
2167
  abi: RouterABI,
2139
- functionName: "swapAndMintApUSD",
2168
+ functionName: "swapAndMint",
2140
2169
  args: [
2141
2170
  {
2142
2171
  inputToken: params.swapParams.inputToken,
@@ -2146,8 +2175,7 @@ var AspanRouterClient = class extends AspanRouterReadClient {
2146
2175
  poolFee: params.swapParams.poolFee
2147
2176
  },
2148
2177
  {
2149
- mintXBNB: false,
2150
- // swapAndMintApUSD always mints apUSD
2178
+ mintXBNB: params.mintParams.mintXBNB,
2151
2179
  minMintOut: params.mintParams.minMintOut,
2152
2180
  recipient: params.mintParams.recipient,
2153
2181
  deadline: params.mintParams.deadline
@@ -2157,37 +2185,30 @@ var AspanRouterClient = class extends AspanRouterReadClient {
2157
2185
  });
2158
2186
  }
2159
2187
  /**
2160
- * Swap input token to LST and mint xBNB
2188
+ * Swap input token and mint using default LST (simplified)
2189
+ * @param params.mintXBNB true = mint xBNB, false = mint apUSD
2161
2190
  */
2162
- async swapAndMintXBNB(params) {
2163
- const value = params.swapParams.inputToken === zeroAddress ? params.swapParams.inputAmount : 0n;
2191
+ async swapAndMintDefault(params) {
2192
+ const value = params.inputToken === zeroAddress ? params.value ?? params.inputAmount : 0n;
2164
2193
  return this.walletClient.writeContract({
2165
2194
  chain: this.chain,
2166
2195
  account: this.walletClient.account,
2167
2196
  address: this.routerAddress,
2168
2197
  abi: RouterABI,
2169
- functionName: "swapAndMintXBNB",
2198
+ functionName: "swapAndMintDefault",
2170
2199
  args: [
2171
- {
2172
- inputToken: params.swapParams.inputToken,
2173
- inputAmount: params.swapParams.inputAmount,
2174
- targetLST: params.swapParams.targetLST,
2175
- minLSTOut: params.swapParams.minLSTOut,
2176
- poolFee: params.swapParams.poolFee
2177
- },
2178
- {
2179
- mintXBNB: true,
2180
- // swapAndMintXBNB always mints xBNB
2181
- minMintOut: params.mintParams.minMintOut,
2182
- recipient: params.mintParams.recipient,
2183
- deadline: params.mintParams.deadline
2184
- }
2200
+ params.inputToken,
2201
+ params.inputAmount,
2202
+ params.mintXBNB,
2203
+ params.minMintOut,
2204
+ params.deadline
2185
2205
  ],
2186
2206
  value
2187
2207
  });
2188
2208
  }
2189
2209
  /**
2190
2210
  * Stake native BNB directly to LST and mint
2211
+ * @param params.isXBNB true = mint xBNB, false = mint apUSD
2191
2212
  */
2192
2213
  async stakeAndMint(params) {
2193
2214
  return this.walletClient.writeContract({
@@ -2205,194 +2226,73 @@ var AspanRouterClient = class extends AspanRouterReadClient {
2205
2226
  value: params.value
2206
2227
  });
2207
2228
  }
2208
- // ============ Simplified Functions ============
2209
- /**
2210
- * Swap input token and mint apUSD using default LST
2211
- */
2212
- async swapAndMintApUSDDefault(params) {
2213
- const value = params.inputToken === zeroAddress ? params.value ?? params.inputAmount : 0n;
2214
- return this.walletClient.writeContract({
2215
- chain: this.chain,
2216
- account: this.walletClient.account,
2217
- address: this.routerAddress,
2218
- abi: RouterABI,
2219
- functionName: "swapAndMintApUSDDefault",
2220
- args: [
2221
- params.inputToken,
2222
- params.inputAmount,
2223
- params.minMintOut,
2224
- params.deadline
2225
- ],
2226
- value
2227
- });
2228
- }
2229
- /**
2230
- * Swap input token and mint xBNB using default LST
2231
- */
2232
- async swapAndMintXBNBDefault(params) {
2233
- const value = params.inputToken === zeroAddress ? params.value ?? params.inputAmount : 0n;
2234
- return this.walletClient.writeContract({
2235
- chain: this.chain,
2236
- account: this.walletClient.account,
2237
- address: this.routerAddress,
2238
- abi: RouterABI,
2239
- functionName: "swapAndMintXBNBDefault",
2240
- args: [
2241
- params.inputToken,
2242
- params.inputAmount,
2243
- params.minMintOut,
2244
- params.deadline
2245
- ],
2246
- value
2247
- });
2248
- }
2249
- /**
2250
- * Stake native BNB and mint apUSD using default LST
2251
- */
2252
- async stakeAndMintApUSD(minMintOut, value) {
2253
- return this.walletClient.writeContract({
2254
- chain: this.chain,
2255
- account: this.walletClient.account,
2256
- address: this.routerAddress,
2257
- abi: RouterABI,
2258
- functionName: "stakeAndMintApUSD",
2259
- args: [minMintOut],
2260
- value
2261
- });
2262
- }
2263
- /**
2264
- * Stake native BNB and mint xBNB using default LST
2265
- */
2266
- async stakeAndMintXBNB(minMintOut, value) {
2267
- return this.walletClient.writeContract({
2268
- chain: this.chain,
2269
- account: this.walletClient.account,
2270
- address: this.routerAddress,
2271
- abi: RouterABI,
2272
- functionName: "stakeAndMintXBNB",
2273
- args: [minMintOut],
2274
- value
2275
- });
2276
- }
2277
2229
  // ============ Direct Mint/Redeem Functions ============
2278
2230
  /**
2279
- * Mint apUSD by providing LST directly (no swap)
2231
+ * Mint apUSD or xBNB by providing LST directly (no swap)
2232
+ * @param params.mintXBNB true = mint xBNB, false = mint apUSD
2280
2233
  */
2281
- async mintApUSD(params) {
2234
+ async mint(params) {
2282
2235
  return this.walletClient.writeContract({
2283
2236
  chain: this.chain,
2284
2237
  account: this.walletClient.account,
2285
2238
  address: this.routerAddress,
2286
2239
  abi: RouterABI,
2287
- functionName: "mintApUSD",
2288
- args: [params.lst, params.lstAmount, params.minOut ?? 0n]
2240
+ functionName: "mint",
2241
+ args: [params.lst, params.lstAmount, params.mintXBNB, params.minOut ?? 0n]
2289
2242
  });
2290
2243
  }
2291
2244
  /**
2292
- * Mint xBNB by providing LST directly (no swap)
2245
+ * Redeem apUSD or xBNB for LST (no swap)
2246
+ * @param params.redeemXBNB true = redeem xBNB, false = redeem apUSD
2293
2247
  */
2294
- async mintXBNB(params) {
2248
+ async redeem(params) {
2295
2249
  return this.walletClient.writeContract({
2296
2250
  chain: this.chain,
2297
2251
  account: this.walletClient.account,
2298
2252
  address: this.routerAddress,
2299
2253
  abi: RouterABI,
2300
- functionName: "mintXBNB",
2301
- args: [params.lst, params.lstAmount, params.minOut ?? 0n]
2302
- });
2303
- }
2304
- /**
2305
- * Redeem apUSD for LST (no swap)
2306
- */
2307
- async redeemApUSD(params) {
2308
- return this.walletClient.writeContract({
2309
- chain: this.chain,
2310
- account: this.walletClient.account,
2311
- address: this.routerAddress,
2312
- abi: RouterABI,
2313
- functionName: "redeemApUSD",
2314
- args: [params.lst, params.apUSDAmount, params.minOut ?? 0n]
2315
- });
2316
- }
2317
- /**
2318
- * Redeem xBNB for LST (no swap)
2319
- */
2320
- async redeemXBNB(params) {
2321
- return this.walletClient.writeContract({
2322
- chain: this.chain,
2323
- account: this.walletClient.account,
2324
- address: this.routerAddress,
2325
- abi: RouterABI,
2326
- functionName: "redeemXBNB",
2327
- args: [params.lst, params.xBNBAmount, params.minOut ?? 0n]
2254
+ functionName: "redeem",
2255
+ args: [params.lst, params.redeemXBNB, params.amount, params.minOut ?? 0n]
2328
2256
  });
2329
2257
  }
2330
2258
  // ============ Redeem and Swap Functions ============
2331
2259
  /**
2332
- * Redeem apUSD and swap LST to output token via V3 path
2333
- * @param params.path - PancakeSwap V3 encoded path (use encodeV3Path helper)
2260
+ * Redeem apUSD/xBNB and swap LST to output token via V3 path
2261
+ * @param params.redeemXBNB true = redeem xBNB, false = redeem apUSD
2262
+ * @param params.path PancakeSwap V3 encoded path (use encodeV3Path helper)
2263
+ * @param params.unwrapBNB If true and output is WBNB, unwrap to native BNB
2334
2264
  */
2335
- async redeemApUSDAndSwap(params) {
2265
+ async redeemAndSwap(params) {
2336
2266
  return this.walletClient.writeContract({
2337
2267
  chain: this.chain,
2338
2268
  account: this.walletClient.account,
2339
2269
  address: this.routerAddress,
2340
2270
  abi: RouterABI,
2341
- functionName: "redeemApUSDAndSwap",
2271
+ functionName: "redeemAndSwap",
2342
2272
  args: [
2343
2273
  params.lst,
2274
+ params.redeemXBNB,
2344
2275
  params.amount,
2345
2276
  params.path,
2346
2277
  params.minOut,
2347
- params.deadline
2348
- ]
2349
- });
2350
- }
2351
- /**
2352
- * Redeem xBNB and swap LST to output token via V3 path
2353
- * @param params.path - PancakeSwap V3 encoded path (use encodeV3Path helper)
2354
- */
2355
- async redeemXBNBAndSwap(params) {
2356
- return this.walletClient.writeContract({
2357
- chain: this.chain,
2358
- account: this.walletClient.account,
2359
- address: this.routerAddress,
2360
- abi: RouterABI,
2361
- functionName: "redeemXBNBAndSwap",
2362
- args: [
2363
- params.lst,
2364
- params.amount,
2365
- params.path,
2366
- params.minOut,
2367
- params.deadline
2278
+ params.deadline,
2279
+ params.unwrapBNB
2368
2280
  ]
2369
2281
  });
2370
2282
  }
2371
2283
  // ============ Native Unstake Functions ============
2372
2284
  /**
2373
- * Redeem apUSD and request native unstake from Lista (starts unbonding period)
2285
+ * Redeem apUSD/xBNB and request native unstake from Lista (starts unbonding period)
2286
+ * @param params.redeemXBNB true = redeem xBNB, false = redeem apUSD
2374
2287
  */
2375
- async redeemApUSDAndRequestUnstake(apUSDAmount) {
2288
+ async redeemAndRequestUnstake(params) {
2376
2289
  return this.walletClient.writeContract({
2377
2290
  chain: this.chain,
2378
2291
  account: this.walletClient.account,
2379
2292
  address: this.routerAddress,
2380
2293
  abi: RouterABI,
2381
- functionName: "redeemApUSDAndRequestUnstake",
2382
- args: [apUSDAmount]
2383
- });
2384
- }
2385
- /**
2386
- * Redeem xBNB and request native unstake from Lista (starts unbonding period)
2387
- */
2388
- async redeemXBNBAndRequestUnstake(xBNBAmount) {
2389
- return this.walletClient.writeContract({
2390
- chain: this.chain,
2391
- account: this.walletClient.account,
2392
- address: this.routerAddress,
2393
- abi: RouterABI,
2394
- functionName: "redeemXBNBAndRequestUnstake",
2395
- args: [xBNBAmount]
2294
+ functionName: "redeemAndRequestUnstake",
2295
+ args: [params.redeemXBNB, params.amount]
2396
2296
  });
2397
2297
  }
2398
2298
  /**
@@ -2464,6 +2364,21 @@ function encodeV3Path(tokens, fees) {
2464
2364
  var PRECISION = 10n ** 18n;
2465
2365
  var BPS_PRECISION = 10000n;
2466
2366
  var PRICE_PRECISION = 10n ** 8n;
2367
+ var BSC_ADDRESSES = {
2368
+ diamond: "0x6a11B30d3a70727d5477D6d8090e144443fA1c78",
2369
+ router: "0x813d3D1A3154950E2f1d8718305426a335A974A9",
2370
+ apUSD: "0x4570047eeB5aDb4081c5d470494EB5134e34A287",
2371
+ xBNB: "0x0A0c9CD826e747D99F90D63e780B3727Da4D0d43",
2372
+ sApUSD: "0x73407A291c007a47CC926EcD5CaC256A1E2d00cF",
2373
+ // LSTs
2374
+ slisBNB: "0xB0b84D294e0C75A6abe60171b70edEb2EFd14A1B",
2375
+ asBNB: "0x77734e70b6E88b4d82fE632a168EDf6e700912b6",
2376
+ wclisBNB: "0x448f7c2fa4e5135a4a5B50879602cf3CD428e108",
2377
+ // Stablecoins
2378
+ USDT: "0x55d398326f99059fF775485246999027B3197955",
2379
+ USDC: "0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d",
2380
+ WBNB: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c"
2381
+ };
2467
2382
  function formatAmount(amount, decimals = 4) {
2468
2383
  const divisor = 10n ** BigInt(18 - decimals);
2469
2384
  const scaled = amount / divisor;
@@ -2501,6 +2416,7 @@ export {
2501
2416
  AspanRouterClient,
2502
2417
  AspanRouterReadClient,
2503
2418
  BPS_PRECISION,
2419
+ BSC_ADDRESSES,
2504
2420
  DiamondABI,
2505
2421
  PRECISION,
2506
2422
  PRICE_PRECISION,