@aspan/sdk 0.1.4

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 ADDED
@@ -0,0 +1,1451 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ AspanClient: () => AspanClient,
24
+ AspanReadClient: () => AspanReadClient,
25
+ BPS_PRECISION: () => BPS_PRECISION,
26
+ DiamondABI: () => DiamondABI,
27
+ PRECISION: () => PRECISION,
28
+ PRICE_PRECISION: () => PRICE_PRECISION,
29
+ calculateAPY: () => calculateAPY,
30
+ createAspanClient: () => createAspanClient,
31
+ createAspanReadClient: () => createAspanReadClient,
32
+ createAspanTestnetClient: () => createAspanTestnetClient,
33
+ createAspanTestnetReadClient: () => createAspanTestnetReadClient,
34
+ formatAmount: () => formatAmount,
35
+ formatCR: () => formatCR,
36
+ formatFeeBPS: () => formatFeeBPS,
37
+ formatPriceUSD: () => formatPriceUSD,
38
+ parseAmount: () => parseAmount
39
+ });
40
+ module.exports = __toCommonJS(index_exports);
41
+
42
+ // src/client.ts
43
+ var import_viem = require("viem");
44
+ var import_chains = require("viem/chains");
45
+
46
+ // src/abi/diamond.ts
47
+ var DiamondABI = [
48
+ // ============ PoolFacet ============
49
+ {
50
+ type: "function",
51
+ name: "mintApUSD",
52
+ inputs: [
53
+ { name: "_lstToken", type: "address", internalType: "address" },
54
+ { name: "_lstAmount", type: "uint256", internalType: "uint256" }
55
+ ],
56
+ outputs: [{ name: "apUSDAmount", type: "uint256", internalType: "uint256" }],
57
+ stateMutability: "nonpayable"
58
+ },
59
+ {
60
+ type: "function",
61
+ name: "redeemApUSD",
62
+ inputs: [
63
+ { name: "_lstToken", type: "address", internalType: "address" },
64
+ { name: "_apUSDAmount", type: "uint256", internalType: "uint256" }
65
+ ],
66
+ outputs: [{ name: "lstAmount", type: "uint256", internalType: "uint256" }],
67
+ stateMutability: "nonpayable"
68
+ },
69
+ {
70
+ type: "function",
71
+ name: "mintXBNB",
72
+ inputs: [
73
+ { name: "_lstToken", type: "address", internalType: "address" },
74
+ { name: "_lstAmount", type: "uint256", internalType: "uint256" }
75
+ ],
76
+ outputs: [{ name: "xBNBAmount", type: "uint256", internalType: "uint256" }],
77
+ stateMutability: "nonpayable"
78
+ },
79
+ {
80
+ type: "function",
81
+ name: "redeemXBNB",
82
+ inputs: [
83
+ { name: "_lstToken", type: "address", internalType: "address" },
84
+ { name: "_xBNBAmount", type: "uint256", internalType: "uint256" }
85
+ ],
86
+ outputs: [{ name: "lstAmount", type: "uint256", internalType: "uint256" }],
87
+ stateMutability: "nonpayable"
88
+ },
89
+ {
90
+ type: "function",
91
+ name: "getXBNBPriceBNB",
92
+ inputs: [],
93
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
94
+ stateMutability: "view"
95
+ },
96
+ {
97
+ type: "function",
98
+ name: "getXBNBPriceUSD",
99
+ inputs: [],
100
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
101
+ stateMutability: "view"
102
+ },
103
+ {
104
+ type: "function",
105
+ name: "getTVLInBNB",
106
+ inputs: [],
107
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
108
+ stateMutability: "view"
109
+ },
110
+ {
111
+ type: "function",
112
+ name: "getTVLInUSD",
113
+ inputs: [],
114
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
115
+ stateMutability: "view"
116
+ },
117
+ {
118
+ type: "function",
119
+ name: "getCollateralRatio",
120
+ inputs: [],
121
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
122
+ stateMutability: "view"
123
+ },
124
+ {
125
+ type: "function",
126
+ name: "getCurrentFees",
127
+ inputs: [],
128
+ outputs: [
129
+ { name: "currentCR", type: "uint256", internalType: "uint256" },
130
+ { name: "tierMinCR", type: "uint256", internalType: "uint256" },
131
+ { name: "apUSDMintFee", type: "uint16", internalType: "uint16" },
132
+ { name: "apUSDRedeemFee", type: "uint16", internalType: "uint16" },
133
+ { name: "xBNBMintFee", type: "uint16", internalType: "uint16" },
134
+ { name: "xBNBRedeemFee", type: "uint16", internalType: "uint16" },
135
+ { name: "apUSDMintDisabled", type: "bool", internalType: "bool" }
136
+ ],
137
+ stateMutability: "view"
138
+ },
139
+ {
140
+ type: "function",
141
+ name: "getEffectiveLeverage",
142
+ inputs: [],
143
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
144
+ stateMutability: "view"
145
+ },
146
+ {
147
+ type: "function",
148
+ name: "getApUSDSupply",
149
+ inputs: [],
150
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
151
+ stateMutability: "view"
152
+ },
153
+ {
154
+ type: "function",
155
+ name: "getXBNBSupply",
156
+ inputs: [],
157
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
158
+ stateMutability: "view"
159
+ },
160
+ {
161
+ type: "function",
162
+ name: "getLSTCollateral",
163
+ inputs: [{ name: "_lstToken", type: "address", internalType: "address" }],
164
+ outputs: [{ name: "amount", type: "uint256", internalType: "uint256" }],
165
+ stateMutability: "view"
166
+ },
167
+ // ============ PoolFacet Events ============
168
+ {
169
+ type: "event",
170
+ name: "ApUSDMinted",
171
+ inputs: [
172
+ { name: "user", type: "address", indexed: true, internalType: "address" },
173
+ { name: "lstToken", type: "address", indexed: true, internalType: "address" },
174
+ { name: "lstAmount", type: "uint256", indexed: false, internalType: "uint256" },
175
+ { name: "apUSDAmount", type: "uint256", indexed: false, internalType: "uint256" },
176
+ { name: "feeBPS", type: "uint256", indexed: false, internalType: "uint256" }
177
+ ],
178
+ anonymous: false
179
+ },
180
+ {
181
+ type: "event",
182
+ name: "ApUSDRedeemed",
183
+ inputs: [
184
+ { name: "user", type: "address", indexed: true, internalType: "address" },
185
+ { name: "lstToken", type: "address", indexed: true, internalType: "address" },
186
+ { name: "apUSDAmount", type: "uint256", indexed: false, internalType: "uint256" },
187
+ { name: "lstAmount", type: "uint256", indexed: false, internalType: "uint256" },
188
+ { name: "feeBPS", type: "uint256", indexed: false, internalType: "uint256" }
189
+ ],
190
+ anonymous: false
191
+ },
192
+ {
193
+ type: "event",
194
+ name: "XBNBMinted",
195
+ inputs: [
196
+ { name: "user", type: "address", indexed: true, internalType: "address" },
197
+ { name: "lstToken", type: "address", indexed: true, internalType: "address" },
198
+ { name: "lstAmount", type: "uint256", indexed: false, internalType: "uint256" },
199
+ { name: "xBNBAmount", type: "uint256", indexed: false, internalType: "uint256" },
200
+ { name: "feeBPS", type: "uint256", indexed: false, internalType: "uint256" }
201
+ ],
202
+ anonymous: false
203
+ },
204
+ {
205
+ type: "event",
206
+ name: "XBNBRedeemed",
207
+ inputs: [
208
+ { name: "user", type: "address", indexed: true, internalType: "address" },
209
+ { name: "lstToken", type: "address", indexed: true, internalType: "address" },
210
+ { name: "xBNBAmount", type: "uint256", indexed: false, internalType: "uint256" },
211
+ { name: "lstAmount", type: "uint256", indexed: false, internalType: "uint256" },
212
+ { name: "feeBPS", type: "uint256", indexed: false, internalType: "uint256" }
213
+ ],
214
+ anonymous: false
215
+ },
216
+ // ============ OracleFacet ============
217
+ {
218
+ type: "function",
219
+ name: "getBNBPriceUSD",
220
+ inputs: [],
221
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
222
+ stateMutability: "view"
223
+ },
224
+ {
225
+ type: "function",
226
+ name: "getLSTPriceUSD",
227
+ inputs: [{ name: "_lstToken", type: "address", internalType: "address" }],
228
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
229
+ stateMutability: "view"
230
+ },
231
+ {
232
+ type: "function",
233
+ name: "getLSTInfo",
234
+ inputs: [{ name: "_lstToken", type: "address", internalType: "address" }],
235
+ outputs: [
236
+ { name: "isAccepted", type: "bool", internalType: "bool" },
237
+ { name: "priceFeed", type: "address", internalType: "address" },
238
+ { name: "manualPriceUSD", type: "uint256", internalType: "uint256" },
239
+ { name: "collateralAmount", type: "uint256", internalType: "uint256" },
240
+ { name: "decimals", type: "uint8", internalType: "uint8" },
241
+ { name: "exchangeRateProvider", type: "address", internalType: "address" },
242
+ { name: "useIntrinsicValue", type: "bool", internalType: "bool" }
243
+ ],
244
+ stateMutability: "view"
245
+ },
246
+ {
247
+ type: "function",
248
+ name: "getSupportedLSTs",
249
+ inputs: [],
250
+ outputs: [{ name: "", type: "address[]", internalType: "address[]" }],
251
+ stateMutability: "view"
252
+ },
253
+ {
254
+ type: "function",
255
+ name: "isLSTSupported",
256
+ inputs: [{ name: "_lstToken", type: "address", internalType: "address" }],
257
+ outputs: [{ name: "", type: "bool", internalType: "bool" }],
258
+ stateMutability: "view"
259
+ },
260
+ {
261
+ type: "function",
262
+ name: "bnbPriceFeed",
263
+ inputs: [],
264
+ outputs: [{ name: "", type: "address", internalType: "address" }],
265
+ stateMutability: "view"
266
+ },
267
+ {
268
+ type: "function",
269
+ name: "getOracleBounds",
270
+ inputs: [{ name: "_priceFeed", type: "address", internalType: "address" }],
271
+ outputs: [
272
+ { name: "minPrice", type: "uint256", internalType: "uint256" },
273
+ { name: "maxPrice", type: "uint256", internalType: "uint256" }
274
+ ],
275
+ stateMutability: "view"
276
+ },
277
+ // ============ StabilityPoolFacet ============
278
+ {
279
+ type: "function",
280
+ name: "deposit",
281
+ inputs: [{ name: "_apUSDAmount", type: "uint256", internalType: "uint256" }],
282
+ outputs: [{ name: "shares", type: "uint256", internalType: "uint256" }],
283
+ stateMutability: "nonpayable"
284
+ },
285
+ {
286
+ type: "function",
287
+ name: "withdraw",
288
+ inputs: [{ name: "_shares", type: "uint256", internalType: "uint256" }],
289
+ outputs: [{ name: "assets", type: "uint256", internalType: "uint256" }],
290
+ stateMutability: "nonpayable"
291
+ },
292
+ {
293
+ type: "function",
294
+ name: "withdrawAssets",
295
+ inputs: [{ name: "_assets", type: "uint256", internalType: "uint256" }],
296
+ outputs: [{ name: "shares", type: "uint256", internalType: "uint256" }],
297
+ stateMutability: "nonpayable"
298
+ },
299
+ {
300
+ type: "function",
301
+ name: "getShares",
302
+ inputs: [{ name: "_user", type: "address", internalType: "address" }],
303
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
304
+ stateMutability: "view"
305
+ },
306
+ {
307
+ type: "function",
308
+ name: "getBalance",
309
+ inputs: [{ name: "_user", type: "address", internalType: "address" }],
310
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
311
+ stateMutability: "view"
312
+ },
313
+ {
314
+ type: "function",
315
+ name: "getExchangeRate",
316
+ inputs: [],
317
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
318
+ stateMutability: "view"
319
+ },
320
+ {
321
+ type: "function",
322
+ name: "getTotalStaked",
323
+ inputs: [],
324
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
325
+ stateMutability: "view"
326
+ },
327
+ {
328
+ type: "function",
329
+ name: "previewDeposit",
330
+ inputs: [{ name: "_assets", type: "uint256", internalType: "uint256" }],
331
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
332
+ stateMutability: "view"
333
+ },
334
+ {
335
+ type: "function",
336
+ name: "previewRedeem",
337
+ inputs: [{ name: "_shares", type: "uint256", internalType: "uint256" }],
338
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
339
+ stateMutability: "view"
340
+ },
341
+ {
342
+ type: "function",
343
+ name: "getPendingYield",
344
+ inputs: [],
345
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
346
+ stateMutability: "view"
347
+ },
348
+ {
349
+ type: "function",
350
+ name: "harvestYield",
351
+ inputs: [],
352
+ outputs: [{ name: "yieldAmount", type: "uint256", internalType: "uint256" }],
353
+ stateMutability: "nonpayable"
354
+ },
355
+ // ============ StabilityPoolFacet Events ============
356
+ {
357
+ type: "event",
358
+ name: "Deposited",
359
+ inputs: [
360
+ { name: "user", type: "address", indexed: true, internalType: "address" },
361
+ { name: "apUSDAmount", type: "uint256", indexed: false, internalType: "uint256" },
362
+ { name: "sharesReceived", type: "uint256", indexed: false, internalType: "uint256" }
363
+ ],
364
+ anonymous: false
365
+ },
366
+ {
367
+ type: "event",
368
+ name: "Withdrawn",
369
+ inputs: [
370
+ { name: "user", type: "address", indexed: true, internalType: "address" },
371
+ { name: "sharesRedeemed", type: "uint256", indexed: false, internalType: "uint256" },
372
+ { name: "apUSDReceived", type: "uint256", indexed: false, internalType: "uint256" }
373
+ ],
374
+ anonymous: false
375
+ },
376
+ {
377
+ type: "event",
378
+ name: "YieldHarvested",
379
+ inputs: [
380
+ { name: "yieldUSD", type: "uint256", indexed: false, internalType: "uint256" }
381
+ ],
382
+ anonymous: false
383
+ },
384
+ // ============ YieldFacet ============
385
+ {
386
+ type: "function",
387
+ name: "getTotalYieldGenerated",
388
+ inputs: [],
389
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
390
+ stateMutability: "view"
391
+ },
392
+ {
393
+ type: "function",
394
+ name: "getLSTYieldInfo",
395
+ inputs: [{ name: "_lstToken", type: "address", internalType: "address" }],
396
+ outputs: [
397
+ { name: "lastExchangeRate", type: "uint256", internalType: "uint256" },
398
+ { name: "lastUpdateTimestamp", type: "uint256", internalType: "uint256" }
399
+ ],
400
+ stateMutability: "view"
401
+ },
402
+ {
403
+ type: "function",
404
+ name: "getMinHarvestInterval",
405
+ inputs: [],
406
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
407
+ stateMutability: "view"
408
+ },
409
+ {
410
+ type: "function",
411
+ name: "getLastHarvestTimestamp",
412
+ inputs: [],
413
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
414
+ stateMutability: "view"
415
+ },
416
+ {
417
+ type: "function",
418
+ name: "previewHarvest",
419
+ inputs: [],
420
+ outputs: [{ name: "totalYieldUSD", type: "uint256", internalType: "uint256" }],
421
+ stateMutability: "view"
422
+ },
423
+ // ============ ConfigFacet ============
424
+ {
425
+ type: "function",
426
+ name: "getTokens",
427
+ inputs: [],
428
+ outputs: [
429
+ { name: "apUSD", type: "address", internalType: "address" },
430
+ { name: "xBNB", type: "address", internalType: "address" }
431
+ ],
432
+ stateMutability: "view"
433
+ },
434
+ {
435
+ type: "function",
436
+ name: "getSApUSD",
437
+ inputs: [],
438
+ outputs: [{ name: "", type: "address", internalType: "address" }],
439
+ stateMutability: "view"
440
+ },
441
+ {
442
+ type: "function",
443
+ name: "getStabilityPool",
444
+ inputs: [],
445
+ outputs: [{ name: "", type: "address", internalType: "address" }],
446
+ stateMutability: "view"
447
+ },
448
+ {
449
+ type: "function",
450
+ name: "getTreasury",
451
+ inputs: [],
452
+ outputs: [{ name: "", type: "address", internalType: "address" }],
453
+ stateMutability: "view"
454
+ },
455
+ {
456
+ type: "function",
457
+ name: "getFeeTierCount",
458
+ inputs: [],
459
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
460
+ stateMutability: "view"
461
+ },
462
+ {
463
+ type: "function",
464
+ name: "getFeeTier",
465
+ inputs: [{ name: "_index", type: "uint256", internalType: "uint256" }],
466
+ outputs: [
467
+ { name: "minCR", type: "uint256", internalType: "uint256" },
468
+ { name: "apUSDMintFee", type: "uint16", internalType: "uint16" },
469
+ { name: "apUSDRedeemFee", type: "uint16", internalType: "uint16" },
470
+ { name: "xBNBMintFee", type: "uint16", internalType: "uint16" },
471
+ { name: "xBNBRedeemFee", type: "uint16", internalType: "uint16" },
472
+ { name: "apUSDMintDisabled", type: "bool", internalType: "bool" }
473
+ ],
474
+ stateMutability: "view"
475
+ },
476
+ {
477
+ type: "function",
478
+ name: "getCurrentFeeTier",
479
+ inputs: [],
480
+ outputs: [
481
+ { name: "minCR", type: "uint256", internalType: "uint256" },
482
+ { name: "apUSDMintFee", type: "uint16", internalType: "uint16" },
483
+ { name: "apUSDRedeemFee", type: "uint16", internalType: "uint16" },
484
+ { name: "xBNBMintFee", type: "uint16", internalType: "uint16" },
485
+ { name: "xBNBRedeemFee", type: "uint16", internalType: "uint16" },
486
+ { name: "apUSDMintDisabled", type: "bool", internalType: "bool" },
487
+ { name: "currentCR", type: "uint256", internalType: "uint256" }
488
+ ],
489
+ stateMutability: "view"
490
+ },
491
+ {
492
+ type: "function",
493
+ name: "getMaxPriceAge",
494
+ inputs: [],
495
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
496
+ stateMutability: "view"
497
+ },
498
+ {
499
+ type: "function",
500
+ name: "getMinDepositPeriod",
501
+ inputs: [],
502
+ outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
503
+ stateMutability: "view"
504
+ },
505
+ {
506
+ type: "function",
507
+ name: "isPaused",
508
+ inputs: [],
509
+ outputs: [{ name: "", type: "bool", internalType: "bool" }],
510
+ stateMutability: "view"
511
+ },
512
+ // ============ StabilityModeFacet ============
513
+ {
514
+ type: "function",
515
+ name: "getStabilityMode",
516
+ inputs: [],
517
+ outputs: [
518
+ { name: "mode", type: "uint8", internalType: "uint8" },
519
+ { name: "currentCR", type: "uint256", internalType: "uint256" }
520
+ ],
521
+ stateMutability: "view"
522
+ },
523
+ {
524
+ type: "function",
525
+ name: "canTriggerStabilityMode2",
526
+ inputs: [],
527
+ outputs: [
528
+ { name: "canTrigger", type: "bool", internalType: "bool" },
529
+ { name: "currentCR", type: "uint256", internalType: "uint256" },
530
+ { name: "potentialConversion", type: "uint256", internalType: "uint256" }
531
+ ],
532
+ stateMutability: "view"
533
+ },
534
+ {
535
+ type: "function",
536
+ name: "triggerStabilityMode2",
537
+ inputs: [{ name: "_targetCR", type: "uint256", internalType: "uint256" }],
538
+ outputs: [
539
+ { name: "apUSDBurned", type: "uint256", internalType: "uint256" },
540
+ { name: "xBNBMinted", type: "uint256", internalType: "uint256" }
541
+ ],
542
+ stateMutability: "nonpayable"
543
+ },
544
+ // ============ StabilityModeFacet Events ============
545
+ {
546
+ type: "event",
547
+ name: "StabilityMode2Triggered",
548
+ inputs: [
549
+ { name: "currentCR", type: "uint256", indexed: false, internalType: "uint256" },
550
+ { name: "targetCR", type: "uint256", indexed: false, internalType: "uint256" },
551
+ { name: "apUSDBurned", type: "uint256", indexed: false, internalType: "uint256" },
552
+ { name: "xBNBMinted", type: "uint256", indexed: false, internalType: "uint256" }
553
+ ],
554
+ anonymous: false
555
+ },
556
+ // ============ OwnershipFacet ============
557
+ {
558
+ type: "function",
559
+ name: "owner",
560
+ inputs: [],
561
+ outputs: [{ name: "", type: "address", internalType: "address" }],
562
+ stateMutability: "view"
563
+ }
564
+ ];
565
+
566
+ // src/client.ts
567
+ var AspanReadClient = class _AspanReadClient {
568
+ publicClient;
569
+ diamondAddress;
570
+ chain;
571
+ // Known error signatures for zero supply states
572
+ static ZERO_SUPPLY_ERROR_SIGNATURES = [
573
+ "0x403e7fa6"
574
+ // Custom error when xBNB supply is zero
575
+ ];
576
+ constructor(config) {
577
+ this.diamondAddress = config.diamondAddress;
578
+ this.chain = config.chain ?? import_chains.bsc;
579
+ this.publicClient = (0, import_viem.createPublicClient)({
580
+ chain: this.chain,
581
+ transport: (0, import_viem.http)(config.rpcUrl)
582
+ });
583
+ }
584
+ /**
585
+ * Check if error is a known zero supply error from the contract
586
+ */
587
+ isZeroSupplyError(error) {
588
+ if (error && typeof error === "object" && "message" in error) {
589
+ const message = error.message;
590
+ return _AspanReadClient.ZERO_SUPPLY_ERROR_SIGNATURES.some(
591
+ (sig) => message.includes(sig)
592
+ );
593
+ }
594
+ return false;
595
+ }
596
+ // ============ Protocol Stats ============
597
+ /**
598
+ * Get comprehensive protocol statistics
599
+ */
600
+ async getProtocolStats() {
601
+ const [
602
+ tvlInBNB,
603
+ tvlInUSD,
604
+ collateralRatio,
605
+ apUSDSupply,
606
+ xBNBSupply,
607
+ xBNBPriceBNB,
608
+ xBNBPriceUSD,
609
+ effectiveLeverage
610
+ ] = await Promise.all([
611
+ this.getTVLInBNB(),
612
+ this.getTVLInUSD(),
613
+ this.getCollateralRatio(),
614
+ this.getApUSDSupply(),
615
+ this.getXBNBSupply(),
616
+ this.getXBNBPriceBNB(),
617
+ this.getXBNBPriceUSD(),
618
+ this.getEffectiveLeverage()
619
+ ]);
620
+ return {
621
+ tvlInBNB,
622
+ tvlInUSD,
623
+ collateralRatio,
624
+ apUSDSupply,
625
+ xBNBSupply,
626
+ xBNBPriceBNB,
627
+ xBNBPriceUSD,
628
+ effectiveLeverage
629
+ };
630
+ }
631
+ /**
632
+ * Get stability pool statistics
633
+ */
634
+ async getStabilityPoolStats() {
635
+ const [totalStaked, exchangeRate, pendingYield] = await Promise.all([
636
+ this.getTotalStaked(),
637
+ this.getExchangeRate(),
638
+ this.getPendingYield()
639
+ ]);
640
+ return {
641
+ totalStaked,
642
+ exchangeRate,
643
+ pendingYield
644
+ };
645
+ }
646
+ /**
647
+ * Get yield statistics
648
+ */
649
+ async getYieldStats() {
650
+ const [
651
+ totalYieldGenerated,
652
+ pendingYield,
653
+ lastHarvestTimestamp,
654
+ minHarvestInterval,
655
+ previewedHarvest
656
+ ] = await Promise.all([
657
+ this.getTotalYieldGenerated(),
658
+ this.getPendingYield(),
659
+ this.getLastHarvestTimestamp(),
660
+ this.getMinHarvestInterval(),
661
+ this.previewHarvest()
662
+ ]);
663
+ return {
664
+ totalYieldGenerated,
665
+ pendingYield,
666
+ lastHarvestTimestamp,
667
+ minHarvestInterval,
668
+ previewedHarvest
669
+ };
670
+ }
671
+ // ============ Pool View Functions ============
672
+ async getTVLInBNB() {
673
+ try {
674
+ return await this.publicClient.readContract({
675
+ address: this.diamondAddress,
676
+ abi: DiamondABI,
677
+ functionName: "getTVLInBNB"
678
+ });
679
+ } catch (error) {
680
+ if (this.isZeroSupplyError(error)) {
681
+ return 0n;
682
+ }
683
+ throw error;
684
+ }
685
+ }
686
+ async getTVLInUSD() {
687
+ try {
688
+ return await this.publicClient.readContract({
689
+ address: this.diamondAddress,
690
+ abi: DiamondABI,
691
+ functionName: "getTVLInUSD"
692
+ });
693
+ } catch (error) {
694
+ if (this.isZeroSupplyError(error)) {
695
+ return 0n;
696
+ }
697
+ throw error;
698
+ }
699
+ }
700
+ async getCollateralRatio() {
701
+ try {
702
+ const cr = await this.publicClient.readContract({
703
+ address: this.diamondAddress,
704
+ abi: DiamondABI,
705
+ functionName: "getCollateralRatio"
706
+ });
707
+ if (cr > 10000n * 10n ** 18n) {
708
+ return 0n;
709
+ }
710
+ return cr;
711
+ } catch (error) {
712
+ if (this.isZeroSupplyError(error)) {
713
+ return 0n;
714
+ }
715
+ throw error;
716
+ }
717
+ }
718
+ async getXBNBPriceBNB() {
719
+ try {
720
+ return await this.publicClient.readContract({
721
+ address: this.diamondAddress,
722
+ abi: DiamondABI,
723
+ functionName: "getXBNBPriceBNB"
724
+ });
725
+ } catch (error) {
726
+ if (this.isZeroSupplyError(error)) {
727
+ return 0n;
728
+ }
729
+ throw error;
730
+ }
731
+ }
732
+ async getXBNBPriceUSD() {
733
+ try {
734
+ return await this.publicClient.readContract({
735
+ address: this.diamondAddress,
736
+ abi: DiamondABI,
737
+ functionName: "getXBNBPriceUSD"
738
+ });
739
+ } catch (error) {
740
+ if (this.isZeroSupplyError(error)) {
741
+ return 0n;
742
+ }
743
+ throw error;
744
+ }
745
+ }
746
+ async getEffectiveLeverage() {
747
+ try {
748
+ return await this.publicClient.readContract({
749
+ address: this.diamondAddress,
750
+ abi: DiamondABI,
751
+ functionName: "getEffectiveLeverage"
752
+ });
753
+ } catch (error) {
754
+ if (this.isZeroSupplyError(error)) {
755
+ return 0n;
756
+ }
757
+ throw error;
758
+ }
759
+ }
760
+ async getApUSDSupply() {
761
+ try {
762
+ return await this.publicClient.readContract({
763
+ address: this.diamondAddress,
764
+ abi: DiamondABI,
765
+ functionName: "getApUSDSupply"
766
+ });
767
+ } catch (error) {
768
+ if (this.isZeroSupplyError(error)) {
769
+ return 0n;
770
+ }
771
+ throw error;
772
+ }
773
+ }
774
+ async getXBNBSupply() {
775
+ try {
776
+ return await this.publicClient.readContract({
777
+ address: this.diamondAddress,
778
+ abi: DiamondABI,
779
+ functionName: "getXBNBSupply"
780
+ });
781
+ } catch (error) {
782
+ if (this.isZeroSupplyError(error)) {
783
+ return 0n;
784
+ }
785
+ throw error;
786
+ }
787
+ }
788
+ async getLSTCollateral(lstToken) {
789
+ try {
790
+ return await this.publicClient.readContract({
791
+ address: this.diamondAddress,
792
+ abi: DiamondABI,
793
+ functionName: "getLSTCollateral",
794
+ args: [lstToken]
795
+ });
796
+ } catch (error) {
797
+ if (this.isZeroSupplyError(error)) {
798
+ return 0n;
799
+ }
800
+ throw error;
801
+ }
802
+ }
803
+ async getCurrentFees() {
804
+ try {
805
+ const result = await this.publicClient.readContract({
806
+ address: this.diamondAddress,
807
+ abi: DiamondABI,
808
+ functionName: "getCurrentFees"
809
+ });
810
+ return {
811
+ currentCR: result[0],
812
+ tierMinCR: result[1],
813
+ apUSDMintFee: result[2],
814
+ apUSDRedeemFee: result[3],
815
+ xBNBMintFee: result[4],
816
+ xBNBRedeemFee: result[5],
817
+ apUSDMintDisabled: result[6]
818
+ };
819
+ } catch (error) {
820
+ if (this.isZeroSupplyError(error)) {
821
+ return {
822
+ currentCR: 0n,
823
+ tierMinCR: 0n,
824
+ apUSDMintFee: 0,
825
+ apUSDRedeemFee: 0,
826
+ xBNBMintFee: 0,
827
+ xBNBRedeemFee: 0,
828
+ apUSDMintDisabled: false
829
+ };
830
+ }
831
+ throw error;
832
+ }
833
+ }
834
+ // ============ Oracle View Functions ============
835
+ async getBNBPriceUSD() {
836
+ return this.publicClient.readContract({
837
+ address: this.diamondAddress,
838
+ abi: DiamondABI,
839
+ functionName: "getBNBPriceUSD"
840
+ });
841
+ }
842
+ async getLSTPriceUSD(lstToken) {
843
+ return this.publicClient.readContract({
844
+ address: this.diamondAddress,
845
+ abi: DiamondABI,
846
+ functionName: "getLSTPriceUSD",
847
+ args: [lstToken]
848
+ });
849
+ }
850
+ async getLSTInfo(lstToken) {
851
+ const result = await this.publicClient.readContract({
852
+ address: this.diamondAddress,
853
+ abi: DiamondABI,
854
+ functionName: "getLSTInfo",
855
+ args: [lstToken]
856
+ });
857
+ return {
858
+ isAccepted: result[0],
859
+ priceFeed: result[1],
860
+ manualPriceUSD: result[2],
861
+ collateralAmount: result[3],
862
+ decimals: result[4],
863
+ exchangeRateProvider: result[5],
864
+ useIntrinsicValue: result[6]
865
+ };
866
+ }
867
+ async getSupportedLSTs() {
868
+ return this.publicClient.readContract({
869
+ address: this.diamondAddress,
870
+ abi: DiamondABI,
871
+ functionName: "getSupportedLSTs"
872
+ });
873
+ }
874
+ async isLSTSupported(lstToken) {
875
+ return this.publicClient.readContract({
876
+ address: this.diamondAddress,
877
+ abi: DiamondABI,
878
+ functionName: "isLSTSupported",
879
+ args: [lstToken]
880
+ });
881
+ }
882
+ async getBNBPriceFeed() {
883
+ return this.publicClient.readContract({
884
+ address: this.diamondAddress,
885
+ abi: DiamondABI,
886
+ functionName: "bnbPriceFeed"
887
+ });
888
+ }
889
+ async getOracleBounds(priceFeed) {
890
+ const result = await this.publicClient.readContract({
891
+ address: this.diamondAddress,
892
+ abi: DiamondABI,
893
+ functionName: "getOracleBounds",
894
+ args: [priceFeed]
895
+ });
896
+ return {
897
+ minPrice: result[0],
898
+ maxPrice: result[1]
899
+ };
900
+ }
901
+ // ============ Stability Pool View Functions ============
902
+ async getShares(user) {
903
+ return this.publicClient.readContract({
904
+ address: this.diamondAddress,
905
+ abi: DiamondABI,
906
+ functionName: "getShares",
907
+ args: [user]
908
+ });
909
+ }
910
+ async getBalance(user) {
911
+ return this.publicClient.readContract({
912
+ address: this.diamondAddress,
913
+ abi: DiamondABI,
914
+ functionName: "getBalance",
915
+ args: [user]
916
+ });
917
+ }
918
+ async getUserStabilityPoolPosition(user) {
919
+ const [shares, balance] = await Promise.all([
920
+ this.getShares(user),
921
+ this.getBalance(user)
922
+ ]);
923
+ return { shares, balance };
924
+ }
925
+ async getExchangeRate() {
926
+ try {
927
+ return await this.publicClient.readContract({
928
+ address: this.diamondAddress,
929
+ abi: DiamondABI,
930
+ functionName: "getExchangeRate"
931
+ });
932
+ } catch (error) {
933
+ if (this.isZeroSupplyError(error)) {
934
+ return 10n ** 18n;
935
+ }
936
+ throw error;
937
+ }
938
+ }
939
+ async getTotalStaked() {
940
+ try {
941
+ return await this.publicClient.readContract({
942
+ address: this.diamondAddress,
943
+ abi: DiamondABI,
944
+ functionName: "getTotalStaked"
945
+ });
946
+ } catch (error) {
947
+ if (this.isZeroSupplyError(error)) {
948
+ return 0n;
949
+ }
950
+ throw error;
951
+ }
952
+ }
953
+ async previewDeposit(assets) {
954
+ try {
955
+ return await this.publicClient.readContract({
956
+ address: this.diamondAddress,
957
+ abi: DiamondABI,
958
+ functionName: "previewDeposit",
959
+ args: [assets]
960
+ });
961
+ } catch (error) {
962
+ if (this.isZeroSupplyError(error)) {
963
+ return assets;
964
+ }
965
+ throw error;
966
+ }
967
+ }
968
+ async previewRedeem(shares) {
969
+ try {
970
+ return await this.publicClient.readContract({
971
+ address: this.diamondAddress,
972
+ abi: DiamondABI,
973
+ functionName: "previewRedeem",
974
+ args: [shares]
975
+ });
976
+ } catch (error) {
977
+ if (this.isZeroSupplyError(error)) {
978
+ return shares;
979
+ }
980
+ throw error;
981
+ }
982
+ }
983
+ async getPendingYield() {
984
+ try {
985
+ return await this.publicClient.readContract({
986
+ address: this.diamondAddress,
987
+ abi: DiamondABI,
988
+ functionName: "getPendingYield"
989
+ });
990
+ } catch (error) {
991
+ if (this.isZeroSupplyError(error)) {
992
+ return 0n;
993
+ }
994
+ throw error;
995
+ }
996
+ }
997
+ // ============ Yield View Functions ============
998
+ async getTotalYieldGenerated() {
999
+ try {
1000
+ return await this.publicClient.readContract({
1001
+ address: this.diamondAddress,
1002
+ abi: DiamondABI,
1003
+ functionName: "getTotalYieldGenerated"
1004
+ });
1005
+ } catch (error) {
1006
+ if (this.isZeroSupplyError(error)) {
1007
+ return 0n;
1008
+ }
1009
+ throw error;
1010
+ }
1011
+ }
1012
+ async getLSTYieldInfo(lstToken) {
1013
+ try {
1014
+ const result = await this.publicClient.readContract({
1015
+ address: this.diamondAddress,
1016
+ abi: DiamondABI,
1017
+ functionName: "getLSTYieldInfo",
1018
+ args: [lstToken]
1019
+ });
1020
+ return {
1021
+ lastExchangeRate: result[0],
1022
+ lastUpdateTimestamp: result[1]
1023
+ };
1024
+ } catch (error) {
1025
+ if (this.isZeroSupplyError(error)) {
1026
+ return {
1027
+ lastExchangeRate: 0n,
1028
+ lastUpdateTimestamp: 0n
1029
+ };
1030
+ }
1031
+ throw error;
1032
+ }
1033
+ }
1034
+ async getMinHarvestInterval() {
1035
+ try {
1036
+ return await this.publicClient.readContract({
1037
+ address: this.diamondAddress,
1038
+ abi: DiamondABI,
1039
+ functionName: "getMinHarvestInterval"
1040
+ });
1041
+ } catch (error) {
1042
+ if (this.isZeroSupplyError(error)) {
1043
+ return 0n;
1044
+ }
1045
+ throw error;
1046
+ }
1047
+ }
1048
+ async getLastHarvestTimestamp() {
1049
+ try {
1050
+ return await this.publicClient.readContract({
1051
+ address: this.diamondAddress,
1052
+ abi: DiamondABI,
1053
+ functionName: "getLastHarvestTimestamp"
1054
+ });
1055
+ } catch (error) {
1056
+ if (this.isZeroSupplyError(error)) {
1057
+ return 0n;
1058
+ }
1059
+ throw error;
1060
+ }
1061
+ }
1062
+ async previewHarvest() {
1063
+ try {
1064
+ return await this.publicClient.readContract({
1065
+ address: this.diamondAddress,
1066
+ abi: DiamondABI,
1067
+ functionName: "previewHarvest"
1068
+ });
1069
+ } catch (error) {
1070
+ if (this.isZeroSupplyError(error)) {
1071
+ return 0n;
1072
+ }
1073
+ throw error;
1074
+ }
1075
+ }
1076
+ // ============ Config View Functions ============
1077
+ async getTokens() {
1078
+ const [tokens, sApUSD] = await Promise.all([
1079
+ this.publicClient.readContract({
1080
+ address: this.diamondAddress,
1081
+ abi: DiamondABI,
1082
+ functionName: "getTokens"
1083
+ }),
1084
+ this.getSApUSD()
1085
+ ]);
1086
+ return {
1087
+ apUSD: tokens[0],
1088
+ xBNB: tokens[1],
1089
+ sApUSD
1090
+ };
1091
+ }
1092
+ async getSApUSD() {
1093
+ return this.publicClient.readContract({
1094
+ address: this.diamondAddress,
1095
+ abi: DiamondABI,
1096
+ functionName: "getSApUSD"
1097
+ });
1098
+ }
1099
+ async getStabilityPool() {
1100
+ return this.publicClient.readContract({
1101
+ address: this.diamondAddress,
1102
+ abi: DiamondABI,
1103
+ functionName: "getStabilityPool"
1104
+ });
1105
+ }
1106
+ async getTreasury() {
1107
+ return this.publicClient.readContract({
1108
+ address: this.diamondAddress,
1109
+ abi: DiamondABI,
1110
+ functionName: "getTreasury"
1111
+ });
1112
+ }
1113
+ async getFeeTierCount() {
1114
+ return this.publicClient.readContract({
1115
+ address: this.diamondAddress,
1116
+ abi: DiamondABI,
1117
+ functionName: "getFeeTierCount"
1118
+ });
1119
+ }
1120
+ async getFeeTier(index) {
1121
+ const result = await this.publicClient.readContract({
1122
+ address: this.diamondAddress,
1123
+ abi: DiamondABI,
1124
+ functionName: "getFeeTier",
1125
+ args: [index]
1126
+ });
1127
+ return {
1128
+ minCR: result[0],
1129
+ apUSDMintFee: result[1],
1130
+ apUSDRedeemFee: result[2],
1131
+ xBNBMintFee: result[3],
1132
+ xBNBRedeemFee: result[4],
1133
+ apUSDMintDisabled: result[5]
1134
+ };
1135
+ }
1136
+ async getCurrentFeeTier() {
1137
+ try {
1138
+ const result = await this.publicClient.readContract({
1139
+ address: this.diamondAddress,
1140
+ abi: DiamondABI,
1141
+ functionName: "getCurrentFeeTier"
1142
+ });
1143
+ return {
1144
+ minCR: result[0],
1145
+ apUSDMintFee: result[1],
1146
+ apUSDRedeemFee: result[2],
1147
+ xBNBMintFee: result[3],
1148
+ xBNBRedeemFee: result[4],
1149
+ apUSDMintDisabled: result[5],
1150
+ currentCR: result[6]
1151
+ };
1152
+ } catch (error) {
1153
+ if (this.isZeroSupplyError(error)) {
1154
+ return {
1155
+ minCR: 0n,
1156
+ apUSDMintFee: 0,
1157
+ apUSDRedeemFee: 0,
1158
+ xBNBMintFee: 0,
1159
+ xBNBRedeemFee: 0,
1160
+ apUSDMintDisabled: false,
1161
+ currentCR: 0n
1162
+ };
1163
+ }
1164
+ throw error;
1165
+ }
1166
+ }
1167
+ async getMaxPriceAge() {
1168
+ return this.publicClient.readContract({
1169
+ address: this.diamondAddress,
1170
+ abi: DiamondABI,
1171
+ functionName: "getMaxPriceAge"
1172
+ });
1173
+ }
1174
+ async getMinDepositPeriod() {
1175
+ return this.publicClient.readContract({
1176
+ address: this.diamondAddress,
1177
+ abi: DiamondABI,
1178
+ functionName: "getMinDepositPeriod"
1179
+ });
1180
+ }
1181
+ async isPaused() {
1182
+ return this.publicClient.readContract({
1183
+ address: this.diamondAddress,
1184
+ abi: DiamondABI,
1185
+ functionName: "isPaused"
1186
+ });
1187
+ }
1188
+ // ============ Stability Mode View Functions ============
1189
+ async getStabilityMode() {
1190
+ try {
1191
+ const result = await this.publicClient.readContract({
1192
+ address: this.diamondAddress,
1193
+ abi: DiamondABI,
1194
+ functionName: "getStabilityMode"
1195
+ });
1196
+ return {
1197
+ mode: result[0],
1198
+ currentCR: result[1]
1199
+ };
1200
+ } catch (error) {
1201
+ if (this.isZeroSupplyError(error)) {
1202
+ return {
1203
+ mode: 0,
1204
+ // Normal mode
1205
+ currentCR: 0n
1206
+ };
1207
+ }
1208
+ throw error;
1209
+ }
1210
+ }
1211
+ async canTriggerStabilityMode2() {
1212
+ try {
1213
+ const result = await this.publicClient.readContract({
1214
+ address: this.diamondAddress,
1215
+ abi: DiamondABI,
1216
+ functionName: "canTriggerStabilityMode2"
1217
+ });
1218
+ return {
1219
+ canTrigger: result[0],
1220
+ currentCR: result[1],
1221
+ potentialConversion: result[2]
1222
+ };
1223
+ } catch (error) {
1224
+ if (this.isZeroSupplyError(error)) {
1225
+ return {
1226
+ canTrigger: false,
1227
+ currentCR: 0n,
1228
+ potentialConversion: 0n
1229
+ };
1230
+ }
1231
+ throw error;
1232
+ }
1233
+ }
1234
+ // ============ Ownership View Functions ============
1235
+ async getOwner() {
1236
+ return this.publicClient.readContract({
1237
+ address: this.diamondAddress,
1238
+ abi: DiamondABI,
1239
+ functionName: "owner"
1240
+ });
1241
+ }
1242
+ };
1243
+ var AspanClient = class extends AspanReadClient {
1244
+ walletClient;
1245
+ constructor(config) {
1246
+ super(config);
1247
+ this.walletClient = (0, import_viem.createWalletClient)({
1248
+ account: config.account,
1249
+ chain: this.chain,
1250
+ transport: (0, import_viem.http)(config.rpcUrl)
1251
+ });
1252
+ }
1253
+ // ============ Pool Write Functions ============
1254
+ /**
1255
+ * Mint apUSD by depositing LST
1256
+ * @param params Mint parameters
1257
+ * @returns Transaction hash
1258
+ */
1259
+ async mintApUSD(params) {
1260
+ return this.walletClient.writeContract({
1261
+ address: this.diamondAddress,
1262
+ abi: DiamondABI,
1263
+ functionName: "mintApUSD",
1264
+ args: [params.lstToken, params.lstAmount]
1265
+ });
1266
+ }
1267
+ /**
1268
+ * Redeem apUSD for LST
1269
+ * @param params Redeem parameters
1270
+ * @returns Transaction hash
1271
+ */
1272
+ async redeemApUSD(params) {
1273
+ return this.walletClient.writeContract({
1274
+ address: this.diamondAddress,
1275
+ abi: DiamondABI,
1276
+ functionName: "redeemApUSD",
1277
+ args: [params.lstToken, params.apUSDAmount]
1278
+ });
1279
+ }
1280
+ /**
1281
+ * Mint xBNB by depositing LST
1282
+ * @param params Mint parameters
1283
+ * @returns Transaction hash
1284
+ */
1285
+ async mintXBNB(params) {
1286
+ return this.walletClient.writeContract({
1287
+ address: this.diamondAddress,
1288
+ abi: DiamondABI,
1289
+ functionName: "mintXBNB",
1290
+ args: [params.lstToken, params.lstAmount]
1291
+ });
1292
+ }
1293
+ /**
1294
+ * Redeem xBNB for LST
1295
+ * @param params Redeem parameters
1296
+ * @returns Transaction hash
1297
+ */
1298
+ async redeemXBNB(params) {
1299
+ return this.walletClient.writeContract({
1300
+ address: this.diamondAddress,
1301
+ abi: DiamondABI,
1302
+ functionName: "redeemXBNB",
1303
+ args: [params.lstToken, params.xBNBAmount]
1304
+ });
1305
+ }
1306
+ // ============ Stability Pool Write Functions ============
1307
+ /**
1308
+ * Deposit apUSD to stability pool to earn yield
1309
+ * @param params Deposit parameters
1310
+ * @returns Transaction hash
1311
+ */
1312
+ async deposit(params) {
1313
+ return this.walletClient.writeContract({
1314
+ address: this.diamondAddress,
1315
+ abi: DiamondABI,
1316
+ functionName: "deposit",
1317
+ args: [params.apUSDAmount]
1318
+ });
1319
+ }
1320
+ /**
1321
+ * Withdraw from stability pool by shares
1322
+ * @param params Withdraw parameters
1323
+ * @returns Transaction hash
1324
+ */
1325
+ async withdraw(params) {
1326
+ return this.walletClient.writeContract({
1327
+ address: this.diamondAddress,
1328
+ abi: DiamondABI,
1329
+ functionName: "withdraw",
1330
+ args: [params.shares]
1331
+ });
1332
+ }
1333
+ /**
1334
+ * Withdraw from stability pool by asset amount
1335
+ * @param params Withdraw parameters
1336
+ * @returns Transaction hash
1337
+ */
1338
+ async withdrawAssets(params) {
1339
+ return this.walletClient.writeContract({
1340
+ address: this.diamondAddress,
1341
+ abi: DiamondABI,
1342
+ functionName: "withdrawAssets",
1343
+ args: [params.assets]
1344
+ });
1345
+ }
1346
+ /**
1347
+ * Harvest yield from LSTs
1348
+ * @returns Transaction hash
1349
+ */
1350
+ async harvestYield() {
1351
+ return this.walletClient.writeContract({
1352
+ address: this.diamondAddress,
1353
+ abi: DiamondABI,
1354
+ functionName: "harvestYield"
1355
+ });
1356
+ }
1357
+ // ============ Transaction Helpers ============
1358
+ /**
1359
+ * Wait for transaction confirmation
1360
+ * @param hash Transaction hash
1361
+ * @returns Transaction receipt
1362
+ */
1363
+ async waitForTransaction(hash) {
1364
+ return this.publicClient.waitForTransactionReceipt({ hash });
1365
+ }
1366
+ };
1367
+ function createAspanReadClient(diamondAddress, rpcUrl) {
1368
+ return new AspanReadClient({
1369
+ diamondAddress,
1370
+ chain: import_chains.bsc,
1371
+ rpcUrl
1372
+ });
1373
+ }
1374
+ function createAspanClient(diamondAddress, account, rpcUrl) {
1375
+ return new AspanClient({
1376
+ diamondAddress,
1377
+ account,
1378
+ chain: import_chains.bsc,
1379
+ rpcUrl
1380
+ });
1381
+ }
1382
+ function createAspanTestnetReadClient(diamondAddress, rpcUrl) {
1383
+ return new AspanReadClient({
1384
+ diamondAddress,
1385
+ chain: import_chains.bscTestnet,
1386
+ rpcUrl
1387
+ });
1388
+ }
1389
+ function createAspanTestnetClient(diamondAddress, account, rpcUrl) {
1390
+ return new AspanClient({
1391
+ diamondAddress,
1392
+ account,
1393
+ chain: import_chains.bscTestnet,
1394
+ rpcUrl
1395
+ });
1396
+ }
1397
+
1398
+ // src/index.ts
1399
+ var PRECISION = 10n ** 18n;
1400
+ var BPS_PRECISION = 10000n;
1401
+ var PRICE_PRECISION = 10n ** 8n;
1402
+ function formatAmount(amount, decimals = 4) {
1403
+ const divisor = 10n ** BigInt(18 - decimals);
1404
+ const scaled = amount / divisor;
1405
+ const intPart = scaled / 10n ** BigInt(decimals);
1406
+ const fracPart = scaled % 10n ** BigInt(decimals);
1407
+ return `${intPart}.${fracPart.toString().padStart(decimals, "0")}`;
1408
+ }
1409
+ function parseAmount(amount) {
1410
+ const [intPart, fracPart = ""] = amount.split(".");
1411
+ const paddedFrac = fracPart.padEnd(18, "0").slice(0, 18);
1412
+ return BigInt(intPart) * PRECISION + BigInt(paddedFrac);
1413
+ }
1414
+ function formatFeeBPS(bps) {
1415
+ return `${(bps / 100).toFixed(2)}%`;
1416
+ }
1417
+ function formatCR(cr) {
1418
+ const percentage = cr * 100n / PRECISION;
1419
+ return `${percentage}%`;
1420
+ }
1421
+ function formatPriceUSD(price) {
1422
+ const dollars = price / PRICE_PRECISION;
1423
+ const cents = price % PRICE_PRECISION / 10n ** 6n;
1424
+ return `$${dollars}.${cents.toString().padStart(2, "0")}`;
1425
+ }
1426
+ function calculateAPY(previousRate, currentRate, periodDays) {
1427
+ if (previousRate === 0n || periodDays === 0) return 0;
1428
+ const rateChange = Number((currentRate - previousRate) * 10000n) / Number(previousRate);
1429
+ const dailyRate = rateChange / periodDays;
1430
+ const annualizedRate = dailyRate * 365;
1431
+ return annualizedRate / 100;
1432
+ }
1433
+ // Annotate the CommonJS export names for ESM import in node:
1434
+ 0 && (module.exports = {
1435
+ AspanClient,
1436
+ AspanReadClient,
1437
+ BPS_PRECISION,
1438
+ DiamondABI,
1439
+ PRECISION,
1440
+ PRICE_PRECISION,
1441
+ calculateAPY,
1442
+ createAspanClient,
1443
+ createAspanReadClient,
1444
+ createAspanTestnetClient,
1445
+ createAspanTestnetReadClient,
1446
+ formatAmount,
1447
+ formatCR,
1448
+ formatFeeBPS,
1449
+ formatPriceUSD,
1450
+ parseAmount
1451
+ });