@aspan/sdk 0.4.0 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -26,25 +26,37 @@ __export(index_exports, {
26
26
  AspanRouterReadClient: () => AspanRouterReadClient,
27
27
  BPS_PRECISION: () => BPS_PRECISION,
28
28
  BSC_ADDRESSES: () => BSC_ADDRESSES,
29
+ CHAIN_IDS: () => CHAIN_IDS,
29
30
  DiamondABI: () => DiamondABI,
31
+ PHAROS_ADDRESSES: () => PHAROS_ADDRESSES,
30
32
  PRECISION: () => PRECISION,
31
33
  PRICE_PRECISION: () => PRICE_PRECISION,
32
34
  RouterABI: () => RouterABI,
33
35
  calculateAPY: () => calculateAPY,
34
36
  createAspanClient: () => createAspanClient,
37
+ createAspanPharosClient: () => createAspanPharosClient,
38
+ createAspanPharosReadClient: () => createAspanPharosReadClient,
35
39
  createAspanReadClient: () => createAspanReadClient,
40
+ createAspanReadClientForChain: () => createAspanReadClientForChain,
36
41
  createAspanTestnetClient: () => createAspanTestnetClient,
37
42
  createAspanTestnetReadClient: () => createAspanTestnetReadClient,
43
+ createAspanWriteClientForChain: () => createAspanWriteClientForChain,
38
44
  createRouterClient: () => createRouterClient,
45
+ createRouterPharosClient: () => createRouterPharosClient,
46
+ createRouterPharosReadClient: () => createRouterPharosReadClient,
39
47
  createRouterReadClient: () => createRouterReadClient,
48
+ createRouterReadClientForChain: () => createRouterReadClientForChain,
40
49
  createRouterTestnetClient: () => createRouterTestnetClient,
41
50
  createRouterTestnetReadClient: () => createRouterTestnetReadClient,
51
+ createRouterWriteClientForChain: () => createRouterWriteClientForChain,
42
52
  encodeV3Path: () => encodeV3Path,
43
53
  formatAmount: () => formatAmount,
44
54
  formatCR: () => formatCR,
45
55
  formatFeeBPS: () => formatFeeBPS,
46
56
  formatPriceUSD: () => formatPriceUSD,
47
- parseAmount: () => parseAmount
57
+ getChainById: () => getChainById,
58
+ parseAmount: () => parseAmount,
59
+ pharosTestnet: () => pharosTestnet
48
60
  });
49
61
  module.exports = __toCommonJS(index_exports);
50
62
 
@@ -522,6 +534,30 @@ var DiamondABI = [
522
534
  outputs: [{ name: "", type: "bool", internalType: "bool" }],
523
535
  stateMutability: "view"
524
536
  },
537
+ {
538
+ type: "function",
539
+ name: "bootstrap",
540
+ inputs: [
541
+ { name: "_lstToken", type: "address", internalType: "address" },
542
+ { name: "_lstAmount", type: "uint256", internalType: "uint256" }
543
+ ],
544
+ outputs: [{ name: "xBNBAmount", type: "uint256", internalType: "uint256" }],
545
+ stateMutability: "nonpayable"
546
+ },
547
+ {
548
+ type: "function",
549
+ name: "isBootstrapped",
550
+ inputs: [],
551
+ outputs: [{ name: "", type: "bool", internalType: "bool" }],
552
+ stateMutability: "view"
553
+ },
554
+ {
555
+ type: "function",
556
+ name: "getBootstrapXBNBAmount",
557
+ inputs: [],
558
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
559
+ stateMutability: "view"
560
+ },
525
561
  // ============ StabilityModeFacet ============
526
562
  {
527
563
  type: "function",
@@ -554,6 +590,13 @@ var DiamondABI = [
554
590
  ],
555
591
  stateMutability: "nonpayable"
556
592
  },
593
+ {
594
+ type: "function",
595
+ name: "cleanXbnb",
596
+ inputs: [{ name: "_xBNBAmount", type: "uint256", internalType: "uint256" }],
597
+ outputs: [],
598
+ stateMutability: "nonpayable"
599
+ },
557
600
  // ============ StabilityModeFacet Events ============
558
601
  {
559
602
  type: "event",
@@ -573,10 +616,78 @@ var DiamondABI = [
573
616
  inputs: [],
574
617
  outputs: [{ name: "", type: "address", internalType: "address" }],
575
618
  stateMutability: "view"
619
+ },
620
+ // ============ Fee Manager ============
621
+ {
622
+ type: "function",
623
+ name: "setFeeManager",
624
+ inputs: [{ name: "_feeManager", type: "address", internalType: "address" }],
625
+ outputs: [],
626
+ stateMutability: "nonpayable"
627
+ },
628
+ {
629
+ type: "function",
630
+ name: "getFeeManager",
631
+ inputs: [],
632
+ outputs: [{ name: "", type: "address", internalType: "address" }],
633
+ stateMutability: "view"
634
+ },
635
+ {
636
+ type: "function",
637
+ name: "setFeeTiers",
638
+ inputs: [{
639
+ name: "_tiers",
640
+ type: "tuple[]",
641
+ internalType: "struct LibAppStorage.FeeTier[]",
642
+ components: [
643
+ { name: "minCR", type: "uint256", internalType: "uint256" },
644
+ { name: "apUSDMintFee", type: "uint16", internalType: "uint16" },
645
+ { name: "apUSDRedeemFee", type: "uint16", internalType: "uint16" },
646
+ { name: "xBNBMintFee", type: "uint16", internalType: "uint16" },
647
+ { name: "xBNBRedeemFee", type: "uint16", internalType: "uint16" },
648
+ { name: "apUSDMintDisabled", type: "bool", internalType: "bool" }
649
+ ]
650
+ }],
651
+ outputs: [],
652
+ stateMutability: "nonpayable"
653
+ },
654
+ {
655
+ type: "event",
656
+ name: "FeeManagerSet",
657
+ inputs: [
658
+ { name: "feeManager", type: "address", indexed: true, internalType: "address" }
659
+ ],
660
+ anonymous: false
576
661
  }
577
662
  ];
578
663
 
579
664
  // src/client.ts
665
+ var pharosTestnet = {
666
+ id: 688689,
667
+ name: "Pharos Atlantic Testnet",
668
+ nativeCurrency: { name: "PHRS", symbol: "PHRS", decimals: 18 },
669
+ rpcUrls: {
670
+ default: { http: ["https://atlantic.dplabs-internal.com"] }
671
+ },
672
+ blockExplorers: {
673
+ default: { name: "Pharos Explorer", url: "https://atlantic.pharosscan.xyz" }
674
+ }
675
+ };
676
+ var CHAIN_IDS = {
677
+ BSC: 56,
678
+ BSC_TESTNET: 97,
679
+ PHAROS: 688689
680
+ };
681
+ var CHAIN_MAP = {
682
+ [CHAIN_IDS.BSC]: import_chains.bsc,
683
+ [CHAIN_IDS.BSC_TESTNET]: import_chains.bscTestnet,
684
+ [CHAIN_IDS.PHAROS]: pharosTestnet
685
+ };
686
+ function getChainById(chainId) {
687
+ const chain = CHAIN_MAP[chainId];
688
+ if (!chain) throw new Error(`[Aspan SDK] Unsupported chainId: ${chainId}`);
689
+ return chain;
690
+ }
580
691
  var AspanReadClient = class _AspanReadClient {
581
692
  publicClient;
582
693
  diamondAddress;
@@ -1217,6 +1328,29 @@ var AspanReadClient = class _AspanReadClient {
1217
1328
  functionName: "isPaused"
1218
1329
  });
1219
1330
  }
1331
+ // ============ Bootstrap View Functions ============
1332
+ /**
1333
+ * Check if xBNB liquidity has been bootstrapped
1334
+ * @returns true if bootstrap has been called
1335
+ */
1336
+ async isBootstrapped() {
1337
+ return this.publicClient.readContract({
1338
+ address: this.diamondAddress,
1339
+ abi: DiamondABI,
1340
+ functionName: "isBootstrapped"
1341
+ });
1342
+ }
1343
+ /**
1344
+ * Get the amount of xBNB locked in bootstrap (burned to dead address)
1345
+ * @returns xBNB amount in wei
1346
+ */
1347
+ async getBootstrapXBNBAmount() {
1348
+ return this.publicClient.readContract({
1349
+ address: this.diamondAddress,
1350
+ abi: DiamondABI,
1351
+ functionName: "getBootstrapXBNBAmount"
1352
+ });
1353
+ }
1220
1354
  // ============ Stability Mode View Functions ============
1221
1355
  async getStabilityMode() {
1222
1356
  try {
@@ -1416,6 +1550,75 @@ var AspanClient = class extends AspanReadClient {
1416
1550
  functionName: "harvestYield"
1417
1551
  });
1418
1552
  }
1553
+ // ============ Risk Management Functions ============
1554
+ /**
1555
+ * Trigger Stability Mode 2 forced conversion
1556
+ * @description Anyone can call when CR < 130%. Burns apUSD from stability pool
1557
+ * and mints xBNB to compensate stakers.
1558
+ * @param targetCR Target CR to restore to (in BPS, e.g., 14000 = 140%)
1559
+ * @returns Transaction hash
1560
+ */
1561
+ async triggerStabilityMode2(targetCR = 14000n) {
1562
+ return this.walletClient.writeContract({
1563
+ chain: this.chain,
1564
+ account: this.walletClient.account,
1565
+ address: this.diamondAddress,
1566
+ abi: DiamondABI,
1567
+ functionName: "triggerStabilityMode2",
1568
+ args: [targetCR]
1569
+ });
1570
+ }
1571
+ /**
1572
+ * Clean underwater xBNB (burn without getting LST back)
1573
+ * @description Only works when xBNB is underwater (price = 0)
1574
+ * @param xBNBAmount Amount of xBNB to clean (burn)
1575
+ * @returns Transaction hash
1576
+ */
1577
+ async cleanXbnb(xBNBAmount) {
1578
+ return this.walletClient.writeContract({
1579
+ chain: this.chain,
1580
+ account: this.walletClient.account,
1581
+ address: this.diamondAddress,
1582
+ abi: DiamondABI,
1583
+ functionName: "cleanXbnb",
1584
+ args: [xBNBAmount]
1585
+ });
1586
+ }
1587
+ // ============ Fee Management Functions ============
1588
+ /**
1589
+ * Set fee tiers (requires feeManager or owner role)
1590
+ * @param tiers Array of fee tier configurations
1591
+ * @returns Transaction hash
1592
+ */
1593
+ async setFeeTiers(tiers) {
1594
+ return this.walletClient.writeContract({
1595
+ chain: this.chain,
1596
+ account: this.walletClient.account,
1597
+ address: this.diamondAddress,
1598
+ abi: DiamondABI,
1599
+ functionName: "setFeeTiers",
1600
+ args: [tiers]
1601
+ });
1602
+ }
1603
+ // ============ Admin Functions ============
1604
+ /**
1605
+ * Bootstrap xBNB liquidity (owner only)
1606
+ * @description Initializes xBNB supply by minting to dead address, preventing extreme initial prices.
1607
+ * Similar to Uniswap V2's MINIMUM_LIQUIDITY. Can only be called once.
1608
+ * @param lstToken LST token address to deposit
1609
+ * @param lstAmount Amount of LST to deposit for bootstrap
1610
+ * @returns Transaction hash
1611
+ */
1612
+ async bootstrap(lstToken, lstAmount) {
1613
+ return this.walletClient.writeContract({
1614
+ chain: this.chain,
1615
+ account: this.walletClient.account,
1616
+ address: this.diamondAddress,
1617
+ abi: DiamondABI,
1618
+ functionName: "bootstrap",
1619
+ args: [lstToken, lstAmount]
1620
+ });
1621
+ }
1419
1622
  // ============ Transaction Helpers ============
1420
1623
  /**
1421
1624
  * Wait for transaction confirmation
@@ -1456,6 +1659,29 @@ function createAspanTestnetClient(diamondAddress, account, rpcUrl) {
1456
1659
  rpcUrl
1457
1660
  });
1458
1661
  }
1662
+ function createAspanPharosReadClient(diamondAddress, rpcUrl) {
1663
+ return new AspanReadClient({
1664
+ diamondAddress,
1665
+ chain: pharosTestnet,
1666
+ rpcUrl
1667
+ });
1668
+ }
1669
+ function createAspanPharosClient(diamondAddress, account, rpcUrl) {
1670
+ return new AspanClient({
1671
+ diamondAddress,
1672
+ account,
1673
+ chain: pharosTestnet,
1674
+ rpcUrl
1675
+ });
1676
+ }
1677
+ function createAspanReadClientForChain(diamondAddress, chainId = CHAIN_IDS.BSC, rpcUrl) {
1678
+ const chain = getChainById(chainId);
1679
+ return new AspanReadClient({ diamondAddress, chain, rpcUrl });
1680
+ }
1681
+ function createAspanWriteClientForChain(diamondAddress, chainId = CHAIN_IDS.BSC, walletClient, rpcUrl) {
1682
+ const chain = getChainById(chainId);
1683
+ return new AspanClient({ diamondAddress, chain, walletClient, rpcUrl });
1684
+ }
1459
1685
 
1460
1686
  // src/router.ts
1461
1687
  var import_viem2 = require("viem");
@@ -2222,6 +2448,29 @@ function createRouterTestnetClient(routerAddress, account, rpcUrl) {
2222
2448
  rpcUrl
2223
2449
  });
2224
2450
  }
2451
+ function createRouterPharosReadClient(routerAddress, rpcUrl) {
2452
+ return new AspanRouterReadClient({
2453
+ routerAddress,
2454
+ chain: pharosTestnet,
2455
+ rpcUrl
2456
+ });
2457
+ }
2458
+ function createRouterPharosClient(routerAddress, account, rpcUrl) {
2459
+ return new AspanRouterClient({
2460
+ routerAddress,
2461
+ account,
2462
+ chain: pharosTestnet,
2463
+ rpcUrl
2464
+ });
2465
+ }
2466
+ function createRouterReadClientForChain(routerAddress, chainId = CHAIN_IDS.BSC, rpcUrl) {
2467
+ const chain = getChainById(chainId);
2468
+ return new AspanRouterReadClient({ routerAddress, chain, rpcUrl });
2469
+ }
2470
+ function createRouterWriteClientForChain(routerAddress, chainId = CHAIN_IDS.BSC, walletClient, rpcUrl) {
2471
+ const chain = getChainById(chainId);
2472
+ return new AspanRouterClient({ routerAddress, chain, walletClient, rpcUrl });
2473
+ }
2225
2474
 
2226
2475
  // src/types.ts
2227
2476
  function encodeV3Path(tokens, fees) {
@@ -2241,20 +2490,29 @@ var PRECISION = 10n ** 18n;
2241
2490
  var BPS_PRECISION = 10000n;
2242
2491
  var PRICE_PRECISION = 10n ** 8n;
2243
2492
  var BSC_ADDRESSES = {
2244
- diamond: "0x10d25Ae0690533e0BA9E64EC7ae77dbD4fE8A46f",
2245
- router: "0x813d3D1A3154950E2f1d8718305426a335A974A9",
2246
- apUSD: "0x1977097E2E5697A6DD91b6732F368a14F50f6B3d",
2247
- xBNB: "0xB78eB4d5928bAb158Eb23c3154544084cD2661d5",
2248
- sApUSD: "0xE2BE739C4aA4126ee72D612d9548C38B1B0e5A1b",
2493
+ diamond: "0x6a11B30d3a70727d5477D6d8090e144443fA1c78",
2494
+ router: "0x29dd49b2e98674ee7531f17e4d40a7725918c3f6",
2495
+ apUSD: "0x4570047eeB5aDb4081c5d470494EB5134e34A287",
2496
+ xBNB: "0x0A0c9CD826e747D99F90D63e780B3727Da4D0d43",
2497
+ sApUSD: "0x73407A291c007a47CC926EcD5CaC256A1E2d00cF",
2249
2498
  // LSTs
2250
2499
  slisBNB: "0xB0b84D294e0C75A6abe60171b70edEb2EFd14A1B",
2251
2500
  asBNB: "0x77734e70b6E88b4d82fE632a168EDf6e700912b6",
2252
- wclisBNB: "0x439faaC2229559121C4Ad4fd8B3FE13Dff038046",
2501
+ wclisBNB: "0x448f7c2fa4e5135a4a5B50879602cf3CD428e108",
2253
2502
  // Stablecoins
2254
2503
  USDT: "0x55d398326f99059fF775485246999027B3197955",
2255
2504
  USDC: "0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d",
2256
2505
  WBNB: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c"
2257
2506
  };
2507
+ var PHAROS_ADDRESSES = {
2508
+ diamond: "0x67011Ce4B5E534FA78dD9922559B7005197DBcc8",
2509
+ apUSD: "0x82ac96db027772cE8a770e099370b5D7941B3ae4",
2510
+ xBNB: "0xFF43b2f50b2c6c588d14Ea4565Ee5Eb93e438576",
2511
+ sApUSD: "0xFA4B826CfD5faaAfA48E4963d8a7d6Cf9889A9A8",
2512
+ mockLST: "0xc7BB55759e8e04AfAA620De96E9E133B1FAd3e18",
2513
+ mockPriceFeed: "0xa2B41DDE7a7BB0A897DE476Ea441fB27A6978682",
2514
+ mockExchangeRate: "0xffA1938e072Ea3b144EA7e61662dd8B0818D82B9"
2515
+ };
2258
2516
  function formatAmount(amount, decimals = 4) {
2259
2517
  const divisor = 10n ** BigInt(18 - decimals);
2260
2518
  const scaled = amount / divisor;
@@ -2294,23 +2552,35 @@ function calculateAPY(previousRate, currentRate, periodDays) {
2294
2552
  AspanRouterReadClient,
2295
2553
  BPS_PRECISION,
2296
2554
  BSC_ADDRESSES,
2555
+ CHAIN_IDS,
2297
2556
  DiamondABI,
2557
+ PHAROS_ADDRESSES,
2298
2558
  PRECISION,
2299
2559
  PRICE_PRECISION,
2300
2560
  RouterABI,
2301
2561
  calculateAPY,
2302
2562
  createAspanClient,
2563
+ createAspanPharosClient,
2564
+ createAspanPharosReadClient,
2303
2565
  createAspanReadClient,
2566
+ createAspanReadClientForChain,
2304
2567
  createAspanTestnetClient,
2305
2568
  createAspanTestnetReadClient,
2569
+ createAspanWriteClientForChain,
2306
2570
  createRouterClient,
2571
+ createRouterPharosClient,
2572
+ createRouterPharosReadClient,
2307
2573
  createRouterReadClient,
2574
+ createRouterReadClientForChain,
2308
2575
  createRouterTestnetClient,
2309
2576
  createRouterTestnetReadClient,
2577
+ createRouterWriteClientForChain,
2310
2578
  encodeV3Path,
2311
2579
  formatAmount,
2312
2580
  formatCR,
2313
2581
  formatFeeBPS,
2314
2582
  formatPriceUSD,
2315
- parseAmount
2583
+ getChainById,
2584
+ parseAmount,
2585
+ pharosTestnet
2316
2586
  });